aboutsummaryrefslogtreecommitdiff
path: root/gdb/symtab.h
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2017-08-21 11:34:32 +0100
committerPedro Alves <palves@redhat.com>2017-08-21 11:34:32 +0100
commitbf223d3e808e6fec9ee165d3d48beb74837796de (patch)
treee416f6364d2ff65dfde7465d28bc0bf692b4540f /gdb/symtab.h
parentc973d0aa4a2c737ab527ae44a617f1c357e07364 (diff)
downloadgdb-bf223d3e808e6fec9ee165d3d48beb74837796de.zip
gdb-bf223d3e808e6fec9ee165d3d48beb74837796de.tar.gz
gdb-bf223d3e808e6fec9ee165d3d48beb74837796de.tar.bz2
Handle function aliases better (PR gdb/19487, errno printing)
(Ref: https://sourceware.org/ml/gdb/2017-06/msg00048.html) This patch improves GDB support for function aliases defined with __attribute__ alias. For example, in the test added by this commit, there is no reference to "func_alias" in the debug info at all, only to "func"'s definition: $ nm ./testsuite/outputs/gdb.base/symbol-alias/symbol-alias | grep " func" 00000000004005ae t func 00000000004005ae T func_alias $ readelf -w ./testsuite/outputs/gdb.base/symbol-alias/symbol-alias | grep func -B 1 -A 8 <1><db>: Abbrev Number: 5 (DW_TAG_subprogram) <dc> DW_AT_name : (indirect string, offset: 0x111): func <e0> DW_AT_decl_file : 1 <e1> DW_AT_decl_line : 27 <e2> DW_AT_prototyped : 1 <e2> DW_AT_type : <0xf8> <e6> DW_AT_low_pc : 0x4005ae <ee> DW_AT_high_pc : 0xb <f6> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa) <f8> DW_AT_GNU_all_call_sites: 1 So all GDB knows about "func_alias" is from the minsym (elf symbol): (gdb) p func_alias $1 = {<text variable, no debug info>} 0x4005ae <func> (gdb) ptype func_alias type = int () (gdb) p func $2 = {struct S *(void)} 0x4005ae <func> (gdb) ptype func type = struct S { int field1; int field2; } *(void) The result is that calling func_alias from the command line produces incorrect results. This is similar (though not exactly the same) to the glibc errno/__errno_location/__GI___errno_location situation. On glibc, errno is defined like this: extern int *__errno_location (void); #define errno (*__errno_location ()) with __GI___errno_location being an internal alias for __errno_location. On my system's libc (F23), I do see debug info for __errno_location, in the form of name vs linkage name: <1><95a5>: Abbrev Number: 18 (DW_TAG_subprogram) <95a6> DW_AT_external : 1 <95a6> DW_AT_name : (indirect string, offset: 0x2c26): __errno_location <95aa> DW_AT_decl_file : 1 <95ab> DW_AT_decl_line : 24 <95ac> DW_AT_linkage_name: (indirect string, offset: 0x2c21): __GI___errno_location <95b0> DW_AT_prototyped : 1 <95b0> DW_AT_type : <0x9206> <95b4> DW_AT_low_pc : 0x20f40 <95bc> DW_AT_high_pc : 0x11 <95c4> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa) <95c6> DW_AT_GNU_all_call_sites: 1 however that doesn't matter in practice, because GDB doesn't record demangled names anyway, and so we end up with the exact same situation covered by the testcase. So the fix is to make the expression parser find a debug symbol for the same address as the just-found minsym, when a lookup by name didn't find a debug symbol by name. We now get: (gdb) p func_alias $1 = {struct S *(void)} 0x4005ae <func> (gdb) p __errno_location $2 = {int *(void)} 0x7ffff6e92830 <__errno_location> I've made the test exercise variable aliases too, for completeness. Those already work correctly, because unlike for function aliases, GCC emits debug information for variable aliases. Tested on GNU/Linux. gdb/ChangeLog: 2017-08-21 Pedro Alves <palves@redhat.com> PR gdb/19487 * c-exp.y (variable production): Handle function aliases. * minsyms.c (msymbol_is_text): New function. * minsyms.h (msymbol_is_text): Declare. * symtab.c (find_function_alias_target): New function. * symtab.h (find_function_alias_target): Declare. gdb/testsuite/ChangeLog: 2017-08-21 Pedro Alves <palves@redhat.com> PR gdb/19487 * gdb.base/symbol-alias.c: New. * gdb.base/symbol-alias2.c: New. * gdb.base/symbol-alias.exp: New.
Diffstat (limited to 'gdb/symtab.h')
-rw-r--r--gdb/symtab.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 35949f0..8cbf4d6 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1556,6 +1556,13 @@ extern CORE_ADDR skip_prologue_using_sal (struct gdbarch *gdbarch,
extern struct symbol *fixup_symbol_section (struct symbol *,
struct objfile *);
+/* If MSYMBOL is an text symbol, look for a function debug symbol with
+ the same address. Returns NULL if not found. This is necessary in
+ case a function is an alias to some other function, because debug
+ information is only emitted for the alias target function's
+ definition, not for the alias. */
+extern symbol *find_function_alias_target (bound_minimal_symbol msymbol);
+
/* Symbol searching */
/* Note: struct symbol_search, search_symbols, et.al. are declared here,
instead of making them local to symtab.c, for gdbtk's sake. */