This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA] Nullified garbage-collected global variables
Tom Tromey (tromey@redhat.com):
> >>>>> "Jerome" == Jerome Guitton <guitton@adacore.com> writes:
>
> Jerome> * dwarf2read.c (add_partial_symbol): Do not add a global variable if
> Jerome> its adress is null. Add comment to explain why.
>
> I am not totally sure about this. The patch itself looks reasonable,
> but I have a couple of questions.
>
> Do you need to apply the same treatment to full symbols? What happens
> if the psymtab is expanded for some other reason and a full symbol of
> this sort is then created? Or is that already impossible?
>
> What about has_section_at_zero?
Here is a new patch that should fix these issues. I have tested it on
x86-linux, no regression.
OK to apply?
gdb/ChangeLog:
* dwarf2read.c (add_partial_symbol): Do not add a global variable if
its adress is null. Add comment to explain why.
(new_symbol): Ditto.
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 288d777..15926c6 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -3427,7 +3427,10 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
Don't enter into the minimal symbol tables as there is
a minimal symbol table entry from the ELF symbols already.
Enter into partial symbol table if it has a location
- descriptor or a type.
+ descriptor or a type. A global variable may also have been
+ stripped out by the linker if unused, in which case its
+ address will be nullified; do not add such variables into
+ partial symbol table then.
If the location descriptor is missing, new_symbol will create
a LOC_UNRESOLVED symbol, the address of the variable will then
be determined from the minimal symbol table whenever the variable
@@ -3438,7 +3441,9 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
if (pdi->locdesc)
addr = decode_locdesc (pdi->locdesc, cu);
- if (pdi->locdesc || pdi->has_type)
+ if ((pdi->locdesc
+ && (addr || dwarf2_per_objfile->has_section_at_zero))
+ || (!pdi->locdesc && pdi->has_type))
psym = add_psymbol_to_list (actual_name, strlen (actual_name),
built_actual_name,
VAR_DOMAIN, LOC_STATIC,
@@ -9860,7 +9865,16 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
{
var_decode_location (attr, sym, cu);
attr2 = dwarf2_attr (die, DW_AT_external, cu);
- if (attr2 && (DW_UNSND (attr2) != 0))
+ if (SYMBOL_CLASS (sym) == LOC_STATIC
+ && SYMBOL_VALUE_ADDRESS (sym) == 0
+ && !dwarf2_per_objfile->has_section_at_zero)
+ {
+ /* When a static variable is eliminated by the linker,
+ the corresponding debug information is not stripped
+ out, but the variable address is set to null;
+ do not add such variables into symbol table. */
+ }
+ else if (attr2 && (DW_UNSND (attr2) != 0))
{
struct pending **list_to_add;