From d9eaeb59a428f57acfe2877e3d21df5fac59fbe3 Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Tue, 11 Sep 2012 21:26:16 +0000 Subject: [PATCH] Name of symbol missing when printing global variable's address The build_address_symbolic funnction filters out data symbols if their size is set to zero. But the problem is that the COFF symbol table (for instance) does not provide any size information, leaving the size to its default value of zero, thus always triggering the filter. This shows up when trying to print the address of a global variable when debugging a Windows executable, for instance. gdb/ChangeLog: * symtab.h (struct minimal_symbol) [has_size]: New field. (MSYMBOL_SIZE): Adjust to forbid macro from being used as lvalue. (SET_MSYMBOL_SIZE, MSYMBOL_HAS_SIZE): New macros. * printcmd.c (build_address_symbolic): Only filter out zero-sized minimal symbols if the symbol's size is actually known. * minsyms.c (prim_record_minimal_symbol_full): Adjust setting of msymbol's size field. Add comment. * elfread.c (elf_symtab_read, elf_rel_plt_read): Use SET_MSYMBOL_SIZE to set the minimal symbol size. --- gdb/ChangeLog | 12 ++++++++++++ gdb/elfread.c | 6 +++--- gdb/minsyms.c | 4 +++- gdb/printcmd.c | 1 + gdb/symtab.h | 14 +++++++++++++- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 449d4fbf68..333eb6e0e8 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,15 @@ +2012-09-11 Joel Brobecker + + * symtab.h (struct minimal_symbol) [has_size]: New field. + (MSYMBOL_SIZE): Adjust to forbid macro from being used as lvalue. + (SET_MSYMBOL_SIZE, MSYMBOL_HAS_SIZE): New macros. + * printcmd.c (build_address_symbolic): Only filter out zero-sized + minimal symbols if the symbol's size is actually known. + * minsyms.c (prim_record_minimal_symbol_full): Adjust setting + of msymbol's size field. Add comment. + * elfread.c (elf_symtab_read, elf_rel_plt_read): Use + SET_MSYMBOL_SIZE to set the minimal symbol size. + 2012-09-11 Joel Brobecker * minsyms.c (install_minimal_symbols): Use memset to fill entire diff --git a/gdb/elfread.c b/gdb/elfread.c index f3967d72b4..516cbd0e3a 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -570,7 +570,7 @@ elf_symtab_read (struct objfile *objfile, int type, elf_sym = (elf_symbol_type *) sym->udata.p; if (elf_sym) - MSYMBOL_SIZE(msym) = elf_sym->internal_elf_sym.st_size; + SET_MSYMBOL_SIZE (msym, elf_sym->internal_elf_sym.st_size); msym->filename = filesymname; gdbarch_elf_make_msymbol_special (gdbarch, sym, msym); @@ -594,7 +594,7 @@ elf_symtab_read (struct objfile *objfile, int type, sym->section, objfile); if (mtramp) { - MSYMBOL_SIZE (mtramp) = MSYMBOL_SIZE (msym); + SET_MSYMBOL_SIZE (mtramp, MSYMBOL_SIZE (msym)); mtramp->created_by_gdb = 1; mtramp->filename = filesymname; gdbarch_elf_make_msymbol_special (gdbarch, sym, mtramp); @@ -689,7 +689,7 @@ elf_rel_plt_read (struct objfile *objfile, asymbol **dyn_symbol_table) 1, address, mst_slot_got_plt, got_plt, objfile); if (msym) - MSYMBOL_SIZE (msym) = ptr_size; + SET_MSYMBOL_SIZE (msym, ptr_size); } do_cleanups (back_to); diff --git a/gdb/minsyms.c b/gdb/minsyms.c index b6df4eae2d..a3a376cf3b 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -937,7 +937,9 @@ prim_record_minimal_symbol_full (const char *name, int name_len, int copy_name, MSYMBOL_TYPE (msymbol) = ms_type; MSYMBOL_TARGET_FLAG_1 (msymbol) = 0; MSYMBOL_TARGET_FLAG_2 (msymbol) = 0; - MSYMBOL_SIZE (msymbol) = 0; + /* Do not use the SET_MSYMBOL_SIZE macro to initialize the size, + as it would also set the has_size flag. */ + msymbol->size = 0; /* The hash pointers must be cleared! If they're not, add_minsym_to_hash_table will NOT add this msymbol to the hash table. */ diff --git a/gdb/printcmd.c b/gdb/printcmd.c index d5b5b63122..9e8cd659ca 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -680,6 +680,7 @@ build_address_symbolic (struct gdbarch *gdbarch, } if (msymbol != NULL + && MSYMBOL_HAS_SIZE (msymbol) && MSYMBOL_SIZE (msymbol) == 0 && MSYMBOL_TYPE (msymbol) != mst_text && MSYMBOL_TYPE (msymbol) != mst_text_gnu_ifunc diff --git a/gdb/symtab.h b/gdb/symtab.h index 76120a37a9..041d8cf199 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -348,6 +348,11 @@ struct minimal_symbol unsigned int target_flag_1 : 1; unsigned int target_flag_2 : 1; + /* Nonzero iff the size of the minimal symbol has been set. + Symbol size information can sometimes not be determined, because + the object file format may not carry that piece of information. */ + unsigned int has_size : 1; + /* Minimal symbols with the same hash key are kept on a linked list. This is the link. */ @@ -361,7 +366,14 @@ struct minimal_symbol #define MSYMBOL_TARGET_FLAG_1(msymbol) (msymbol)->target_flag_1 #define MSYMBOL_TARGET_FLAG_2(msymbol) (msymbol)->target_flag_2 -#define MSYMBOL_SIZE(msymbol) (msymbol)->size +#define MSYMBOL_SIZE(msymbol) ((msymbol)->size + 0) +#define SET_MSYMBOL_SIZE(msymbol, sz) \ + do \ + { \ + (msymbol)->size = sz; \ + (msymbol)->has_size = 1; \ + } while (0) +#define MSYMBOL_HAS_SIZE(msymbol) ((msymbol)->has_size + 0) #define MSYMBOL_TYPE(msymbol) (msymbol)->type #include "minsyms.h" -- 2.34.1