public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "rui314 at gmail dot com" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug gdb/30008] New: gdb fails to get line numbers with gold/mold with --gdb-index
Date: Tue, 17 Jan 2023 06:25:50 +0000	[thread overview]
Message-ID: <bug-30008-4717@http.sourceware.org/bugzilla/> (raw)

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

            Bug ID: 30008
           Summary: gdb fails to get line numbers with gold/mold with
                    --gdb-index
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: rui314 at gmail dot com
  Target Milestone: ---

I found this gdb's odd behavior when I was debugging a mold-generated
executable, but I could reproduce the same issue with GNU gold, so I'll report
it as a gdb issue. If it is actually a linker's issue, please let me know so
that I can fix it on the linker side. Since the GDB index is a gdb-specific
feature and not very documented well, it is very hard for me to debug this
issue.

So, here is the issue. I built the mold linker (https://github.com/rui314/mold)
with GNU ld and ran it under gdb. Almost all functions in mold are actually C++
templates that takes a target type as a type parameter. Therefore, for examle,
we have `parse_nonpositional_args<mold::elf::X86_64>`,
`parse_nonpositional_args<mold::elf::ARM32>`, etc in the same executable.

When I set a breakpoint at just `parse_nonpositional_args`, gdb fails to obtain
its line number, as shown below.


ruiu@blue:~/mold/build-gold$ gdb ./mold -nx -batch -ex 'b
parse_nonpositional_args' -ex 'run --no-fork --no-threads' -ex bt -ex c -ex bt
-ex quit

Breakpoint 1 at 0x1194e4 (16 locations)
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, 0x000055555566d4e4 in
std::vector<std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> > > >
mold::elf::parse_nonpositional_args<mold::elf::X86_64>(mold::elf::Context<mold::elf::X86_64>&)
()
#0  0x000055555566d4e4 in std::vector<std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > > >
mold::elf::parse_nonpositional_args<mold::elf::X86_64>(mold::elf::Context<mold::elf::X86_64>&)
()
#1  0x0000555555886568 in int mold::elf::elf_main<mold::elf::X86_64>(int,
char**) ()
#2  0x000055555588212b in mold::elf::main(int, char**) ()
#3  0x0000555556dba344 in main (argc=3, argv=0x7fffffffe178) at
/home/ruiu/mold/common/main.cc:155
mold: fatal: -m option is missing
[Inferior 1 (process 3523615) exited with code 01]
No stack.



However, if I specify the exact name of the function (in this case
`parse_nonpositional_args<mold::elf::X86_64>`), gdb can obtain its line number
without problems.


ruiu@blue:~/mold/build-gold$ gdb ./mold -nx -batch -ex 'b
parse_nonpositional_args<mold::elf::X86_64>' -ex 'run --no-fork --no-threads'
-ex bt -ex c -ex bt -ex quit

Breakpoint 1 at 0x119504: file /home/ruiu/mold/elf/cmdline.cc, line 395.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, mold::elf::parse_nonpositional_args<mold::elf::X86_64> (ctx=...)
at /home/ruiu/mold/elf/cmdline.cc:395
395       std::span<std::string_view> args = ctx.cmdline_args;
#0  mold::elf::parse_nonpositional_args<mold::elf::X86_64> (ctx=...) at
/home/ruiu/mold/elf/cmdline.cc:395
#1  0x0000555555886568 in mold::elf::elf_main<mold::elf::X86_64> (argc=3,
argv=0x7fffffffe178) at /home/ruiu/mold/elf/elf-main.cc:387
#2  0x000055555588212b in mold::elf::main (argc=3, argv=0x7fffffffe178) at
/home/ruiu/mold/elf/elf-main.cc:758
#3  0x0000555556dba344 in main (argc=3, argv=0x7fffffffe178) at
/home/ruiu/mold/common/main.cc:155
mold: fatal: -m option is missing
[Inferior 1 (process 3524620) exited with code 01]
No stack.


Why does gdb behave differently for the above two test cases?

Uploaded a gold-linked mold executable here:
https://drive.google.com/file/d/1YuLUCJFJV-cJ9zQ7NRxvSSqYgoShCF_N/view?usp=sharing

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

             reply	other threads:[~2023-01-17  6:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-17  6:25 rui314 at gmail dot com [this message]
2023-01-17 18:20 ` [Bug gdb/30008] " simon.marchi at polymtl dot ca
2023-01-18  0:48 ` rui314 at gmail dot com
2023-02-15 15:56 ` tromey at sourceware dot org
2023-02-15 16:28 ` simon.marchi at polymtl dot ca
2023-02-15 18:15 ` tromey at sourceware dot org
2023-02-16  0:07 ` rui314 at gmail dot com
2023-02-16  2:32 ` sam at gentoo dot 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-30008-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).