Re: Improving GDB's mechanism to check if function is GC'ed

Taimoor
2015-06-09T06:16:16Z

ping.

Yao,

As you implemented current GC'ing mechanism, Can you kindly take a look
at below mentioned problem and proposed solution.

Thanks,
Taimoor

On 06/02/2015 06:38 PM, Taimoor wrote:
> Hi,
>
> GDB currently uses following mechanism to check if function is GC'ed by
> the linker:
> For any function whose address is 0x0, if 'textlow' field of partial
> symbol table is not zero, function is considered to be GC'ed by the
> linker. Below is the code doing this:
>
> case DW_LNE_set_address:
> address = read_address (abfd, line_ptr, cu, &bytes_read);
>
> /* If address < lowpc then it's not a usable value, it's
> outside the pc range of the CU. However, we restrict
> the test to only address values of zero to preserve
> GDB's previous behaviour which is to handle the specific
> case of a function being GC'd by the linker. */
> if (address == 0 && address < lowpc)
> {
> /* This line table is for a function which has been
> GCd by the linker. Ignore it. PR gdb/12528 */
>
>
> This change was done in
> https://sourceware.org/ml/gdb-patches/2014-08/msg00468.html
>
> This does not work for cases where symbols are manually loaded using
> add-symbol-file command. For any incrementally loaded objfile whose
> symbols are added using add-symbol-file command can have function at 0x0
> in debug info and can have its lowpc non-zero because of add-symbol-file
> command that allows user to provide section addresses.
>
> Current Problem
> ===============
>
> We are currently using GDB to debug Nucleus based bare-metal system that
> also allows to dynamically load and unload Nucleus process modules
> during system execution.
> We currently load symbols of a modules using add-symbol-file whenever a
> module is loaded at runtime. It is very common to have functions at
> address 0x0 in debug information and then lowpc in symbol table to be
> non-zero as it depends on section addresses given in add-symbol-file
> command.
>
> With above mentioned GC'ing mechanism, GDB assumes that all these
> functions are GC'ed by linker. Because of this breakpoints do not work
> properly in debug session.
>
> Possible Solution
> =================
>
> * Modify GC checking mechanism to mark any function GC'ed using above
> mentioned mechanism only if objfile is not dynamically loaded. So, for
> any function with address 0x0, it'll be marked GC'ed only if lowpc is
> not zero and objfile is main symbol file.
>
> For this I have made following modifications in if condition:
>
> if (address == 0 && address < lowpc
> && (objfile->flags & OBJF_MAINLINE))
> {
>
> I have regression tested this change and it seems to work fine.
> Only downside that it is possible (though not common) to load main
> symbol file using add-symbol-file command. In that case, GDB will not
> check for GC'ed functions.
>
> Attached is patch to better highlight this solution.
>
> I am open to any other suggestions to improve this GC'ing mechanism and
> solving this problem.
>
> Thanks,
> Taimoor