public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/30008] New: gdb fails to get line numbers with gold/mold with --gdb-index
@ 2023-01-17  6:25 rui314 at gmail dot com
  2023-01-17 18:20 ` [Bug gdb/30008] " simon.marchi at polymtl dot ca
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: rui314 at gmail dot com @ 2023-01-17  6:25 UTC (permalink / raw)
  To: gdb-prs

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.

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

* [Bug gdb/30008] gdb fails to get line numbers with gold/mold with --gdb-index
  2023-01-17  6:25 [Bug gdb/30008] New: gdb fails to get line numbers with gold/mold with --gdb-index rui314 at gmail dot com
@ 2023-01-17 18:20 ` simon.marchi at polymtl dot ca
  2023-01-18  0:48 ` rui314 at gmail dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: simon.marchi at polymtl dot ca @ 2023-01-17 18:20 UTC (permalink / raw)
  To: gdb-prs

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

Simon Marchi <simon.marchi at polymtl dot ca> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simon.marchi at polymtl dot ca

--- Comment #1 from Simon Marchi <simon.marchi at polymtl dot ca> ---
I didn't manage to reproduce.  I tried to build mold on Ubuntu 22.04, one build
with -fuse-ld=bfd and one build with -fuse-ld=gold.  Both show me the filenames
when breaking on parse_nonpositional_args.

Can you give the exact gdb version you tried, and version of all relevant tools
(if they come from a distro, which distro)?

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

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

* [Bug gdb/30008] gdb fails to get line numbers with gold/mold with --gdb-index
  2023-01-17  6:25 [Bug gdb/30008] New: gdb fails to get line numbers with gold/mold with --gdb-index rui314 at gmail dot com
  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
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rui314 at gmail dot com @ 2023-01-18  0:48 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #2 from Rui Ueyama <rui314 at gmail dot com> ---
I'm using "GNU gold (GNU Binutils for Ubuntu 2.38) 1.16" on Ubuntu 22.04.

You may want to apply the following patch to ensure you are using gold with
`--gdb-index`.

```
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3e0ae9ed..091835c5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -55,6 +55,8 @@ if(MOLD_USE_MOLD)
   add_link_options(-fuse-ld=mold -Wl,--gdb-index)
 endif()

+add_link_options(-fuse-ld=gold -Wl,--gdb-index)
+
 add_executable(mold)
 target_compile_features(mold PRIVATE cxx_std_20)
 target_link_libraries(mold PRIVATE ${CMAKE_DL_LIBS})
```

With this patch, I can reproduce the issue with the following commands:

$ git clone git@github.com:rui314/mold.git
$ cd mold
$ patch -p1 < patch.diff
$ mkdir build; cd build
$ cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=clang++-14 ..
$ cmake --build .
$ gdb ./mold -nx -batch -ex 'b parse_nonpositional_args' -ex 'run --no-fork
--no-threads' -ex bt -ex c -ex quit

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

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

* [Bug gdb/30008] gdb fails to get line numbers with gold/mold with --gdb-index
  2023-01-17  6:25 [Bug gdb/30008] New: gdb fails to get line numbers with gold/mold with --gdb-index rui314 at gmail dot com
  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
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: tromey at sourceware dot org @ 2023-02-15 15:56 UTC (permalink / raw)
  To: gdb-prs

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

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tromey at sourceware dot org

--- Comment #3 from Tom Tromey <tromey at sourceware dot org> ---
I set my ld to gold, just to be sure.

murgatroyd. /bin/ld --version
GNU gold (version 2.37-37.fc36) 1.16

Then I tried the instructions in comment #2 and I get:

Breakpoint 1.1, mold::elf::parse_nonpositional_args<mold::elf::X86_64>
(ctx=...) at /home/tromey/gdb/PRs/pr-30008-mold/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/tromey/gdb/PRs/pr-30008-mold/mold/elf/cmdline.cc:395
#1  0x000000000064297e in mold::elf::elf_main<mold::elf::X86_64> (argc=3,
argv=0x7fffffffe368) at
/home/tromey/gdb/PRs/pr-30008-mold/mold/elf/elf-main.cc:391
#2  0x000000000063e2eb in mold::elf::main (argc=3, argv=0x7fffffffe368) at
/home/tromey/gdb/PRs/pr-30008-mold/mold/elf/elf-main.cc:762
#3  0x0000000001c14637 in main (argc=3, argv=0x7fffffffe368) at
/home/tromey/gdb/PRs/pr-30008-mold/mold/common/main.cc:155


So I think it is working for me as well.

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

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

* [Bug gdb/30008] gdb fails to get line numbers with gold/mold with --gdb-index
  2023-01-17  6:25 [Bug gdb/30008] New: gdb fails to get line numbers with gold/mold with --gdb-index rui314 at gmail dot com
                   ` (2 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: simon.marchi at polymtl dot ca @ 2023-02-15 16:28 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #4 from Simon Marchi <simon.marchi at polymtl dot ca> ---
I think I missed the "gdb index" part when testing.

I tried again on Arch Linux now, and I get the same output as OP:

#0  0x0000555555671db4 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  0x00005555558adf2d in int mold::elf::elf_main<mold::elf::X86_64>(int,
char**) ()
#2  0x00005555558a945b in mold::elf::main(int, char**) ()
#3  0x0000555556fedaf5 in main (argc=3, argv=0x7fffffffdea8) at
/home/smarchi/src/mold/common/main.cc:155

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

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

* [Bug gdb/30008] gdb fails to get line numbers with gold/mold with --gdb-index
  2023-01-17  6:25 [Bug gdb/30008] New: gdb fails to get line numbers with gold/mold with --gdb-index rui314 at gmail dot com
                   ` (3 preceding siblings ...)
  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
  6 siblings, 0 replies; 8+ messages in thread
From: tromey at sourceware dot org @ 2023-02-15 18:15 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #5 from Tom Tromey <tromey at sourceware dot org> ---
I can reproduce it using the mold from the original report.

I wonder if gdb-index is a red herring here.
The issue maybe seems to be not finding the PC in the blockvector map.
However I don't think this has anything to do with the index.
(I didn't try stripping out the index.)

I do notice the index doesn't have an address map, which is weird.

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

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

* [Bug gdb/30008] gdb fails to get line numbers with gold/mold with --gdb-index
  2023-01-17  6:25 [Bug gdb/30008] New: gdb fails to get line numbers with gold/mold with --gdb-index rui314 at gmail dot com
                   ` (4 preceding siblings ...)
  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
  6 siblings, 0 replies; 8+ messages in thread
From: rui314 at gmail dot com @ 2023-02-16  0:07 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #6 from Rui Ueyama <rui314 at gmail dot com> ---
If I remove `.gdb_index` using the objcopy command, gdb can correctly display
line numbers in stack trace, so I believe this has something to do with
gdb-index.

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

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

* [Bug gdb/30008] gdb fails to get line numbers with gold/mold with --gdb-index
  2023-01-17  6:25 [Bug gdb/30008] New: gdb fails to get line numbers with gold/mold with --gdb-index rui314 at gmail dot com
                   ` (5 preceding siblings ...)
  2023-02-16  0:07 ` rui314 at gmail dot com
@ 2023-02-16  2:32 ` sam at gentoo dot org
  6 siblings, 0 replies; 8+ messages in thread
From: sam at gentoo dot org @ 2023-02-16  2:32 UTC (permalink / raw)
  To: gdb-prs

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

Sam James <sam at gentoo dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sam at gentoo dot org

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

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

end of thread, other threads:[~2023-02-16  2:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-17  6:25 [Bug gdb/30008] New: gdb fails to get line numbers with gold/mold with --gdb-index rui314 at gmail dot com
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

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).