public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug symtab/31622] New: [gdb/symtab] find_epilogue_using_linetable fails to find entry in function with two linetables
@ 2024-04-09  6:59 vries at gcc dot gnu.org
  2024-04-09  7:00 ` [Bug symtab/31622] " vries at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2024-04-09  6:59 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31622

            Bug ID: 31622
           Summary: [gdb/symtab] find_epilogue_using_linetable fails to
                    find entry in function with two linetables
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: symtab
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

Bernd Edlinger reported the following problem and fix in
find_epilogue_using_linetable (
https://sourceware.org/pipermail/gdb-patches/2024-April/207928.html ).

This came up in a discussion for a patch for PR31268, but it's an independent
issue.

Consider the following test-case:
...
$ cat hello.c 
#include <stdio.h>
int main()
{
  printf("hello ");
  #include "world.inc"
/*** End of hello.c ***/

$ cat world.inc 
  printf("world\n");
  return 0;
}
/*** End of world.inc ***/

$ gcc -g -o hello hello.c
...

The corresponding disassembly for main is:
...
0000000000400557 <main>:
  400557:       55                      push   %rbp
  400558:       48 89 e5                mov    %rsp,%rbp
  40055b:       bf 24 06 40 00          mov    $0x400624,%edi
  400560:       b8 00 00 00 00          mov    $0x0,%eax
  400565:       e8 f6 fe ff ff          call   400460 <printf@plt>
  40056a:       bf 2b 06 40 00          mov    $0x40062b,%edi
  40056f:       e8 dc fe ff ff          call   400450 <puts@plt>
  400574:       b8 00 00 00 00          mov    $0x0,%eax
  400579:       5d                      pop    %rbp
  40057a:       c3                      ret
...

And the corresponding line table is:
...
hello.c:
File name                Line number    Starting address    View    Stmt
hello.c                            3            0x400557               x
hello.c                            4            0x40055b               x

./world.inc:[++]
world.inc                          1            0x40056a               x
world.inc                          2            0x400574               x
world.inc                          3            0x400579               x
world.inc                          -            0x40057b
...

Now, say we have an epilogue_begin marker at 0x400579 in world.inc.

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.

Proposed patch:
...
-  const struct symtab_and_line sal = find_pc_line (start_pc, 0);
+  const struct symtab_and_line sal = find_pc_line (end_pc - 1, 0);
...
which gets us the linetable for world.inc instead.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-04-24 21:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-09  6:59 [Bug symtab/31622] New: [gdb/symtab] find_epilogue_using_linetable fails to find entry in function with two linetables vries at gcc dot gnu.org
2024-04-09  7:00 ` [Bug symtab/31622] " vries at gcc dot gnu.org
2024-04-10  8:08 ` vries at gcc dot gnu.org
2024-04-24 14:27 ` cvs-commit at gcc dot gnu.org
2024-04-24 15:20 ` bernd.edlinger at hotmail dot de
2024-04-24 21:13 ` vries at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).