aboutsummaryrefslogtreecommitdiff
path: root/gdb/symtab.c
diff options
context:
space:
mode:
authorBernd Edlinger <bernd.edlinger@hotmail.de>2024-04-09 09:27:53 +0000
committerBernd Edlinger <bernd.edlinger@hotmail.de>2024-04-24 16:00:38 +0200
commit730f5068f5fb6613e4faa2efc2309cd107562cbd (patch)
tree1e7695f73b6b0e95b41de5489b8b9fecb867c38d /gdb/symtab.c
parent63ddc8af5d7d3ad909aad66291f23507ba987bb4 (diff)
downloadgdb-730f5068f5fb6613e4faa2efc2309cd107562cbd.zip
gdb-730f5068f5fb6613e4faa2efc2309cd107562cbd.tar.gz
gdb-730f5068f5fb6613e4faa2efc2309cd107562cbd.tar.bz2
Handle two-linetable function in find_epilogue_using_linetable
Consider the following test-case: ... $ cat hello.c int main() { printf("hello "); #include "world.inc" $ cat world.inc printf("world\n"); return 0; } $ gcc -g hello.c ... The line table for the compilation unit, consisting just of function main, is translated into these two gdb line tables, one for hello.c and one for world.inc: ... compunit_symtab: hello.c symtab: hello.c INDEX LINE REL-ADDRESS UNREL-ADDRESS IS-STMT PROLOGUE-END EPILOGUE-BEGIN 0 3 0x400557 0x400557 Y 1 4 0x40055b 0x40055b Y 2 END 0x40056a 0x40056a Y compunit_symtab: hello.c symtab: world.inc INDEX LINE REL-ADDRESS UNREL-ADDRESS IS-STMT PROLOGUE-END EPILOGUE-BEGIN 0 1 0x40056a 0x40056a Y 1 2 0x400574 0x400574 Y 2 3 0x400579 0x400579 Y 3 END 0x40057b 0x40057b Y ... The epilogue of main starts at 0x400579: ... 400579: 5d pop %rbp 40057a: c3 ret ... Now, say we have an epilogue_begin marker in the line table at 0x400579. We won't find it using find_epilogue_using_linetable, because it does: ... const struct symtab_and_line sal = find_pc_line (start_pc, 0); ... which gets us the line table for hello.c. Fix this by using "find_pc_line (end_pc - 1, 0)" instead. Tested on x86_64-linux. Co-Authored-By: Tom de Vries <tdevries@suse.de> PR symtab/31622 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31622
Diffstat (limited to 'gdb/symtab.c')
-rw-r--r--gdb/symtab.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 06b32c0..6d3732a 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4159,8 +4159,15 @@ find_epilogue_using_linetable (CORE_ADDR func_addr)
/* While the standard allows for multiple points marked with epilogue_begin
in the same function, for performance reasons, this function will only
- find the last address that sets this flag for a given block. */
- const struct symtab_and_line sal = find_pc_line (start_pc, 0);
+ find the last address that sets this flag for a given block.
+
+ The lines of a function can be described by several line tables in case
+ there are different files involved. There's a corner case where a
+ function epilogue is in a different file than a function start, and using
+ start_pc as argument to find_pc_line will mean we won't find the
+ epilogue. Instead, use "end_pc - 1" to maximize our chances of picking
+ the line table containing an epilogue. */
+ const struct symtab_and_line sal = find_pc_line (end_pc - 1, 0);
if (sal.symtab != nullptr && sal.symtab->language () != language_asm)
{
struct objfile *objfile = sal.symtab->compunit ()->objfile ();