public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "vries at gcc dot gnu.org" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug symtab/31622] New: [gdb/symtab] find_epilogue_using_linetable fails to find entry in function with two linetables
Date: Tue, 09 Apr 2024 06:59:17 +0000	[thread overview]
Message-ID: <bug-31622-4717@http.sourceware.org/bugzilla/> (raw)

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.

             reply	other threads:[~2024-04-09  6:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-09  6:59 vries at gcc dot gnu.org [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-31622-4717@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).