From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BE0913858C83; Tue, 17 Jan 2023 06:25:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE0913858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673936750; bh=4nkvafgtyN/Xlfcblwcxg8ouH1QmyqUEzTtjPGmZkts=; h=From:To:Subject:Date:From; b=HTILC3E8hV2ntCgOHA6dr6+/TTCSxUmsMvj29ijuo8fp5BdKI3a/MRRPd2KgY05cW goFA4/aiZ+IvdYTHX9Q9FoziT55+NAYU92S4UDQw/dHkmeq3cm0c4YepiszWFYGJdQ mSFJZGYQBB1ITMgS/vXkNvGBFsWgNGIJ3brQGifs= From: "rui314 at gmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: gdb X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rui314 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D30008 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 rep= ort 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/m= old) 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 exam= le, we have `parse_nonpositional_args`, `parse_nonpositional_args`, etc in the same executable. When I set a breakpoint at just `parse_nonpositional_args`, gdb fails to ob= tain 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::allocator >, std::allocator, std::allocator > > > mold::elf::parse_nonpositional_args(mold::elf::Context&) () #0 0x000055555566d4e4 in std::vector, std::allocator >, std::allocator, std::allocator > > > mold::elf::parse_nonpositional_args(mold::elf::Context&) () #1 0x0000555555886568 in int mold::elf::elf_main(int, char**) () #2 0x000055555588212b in mold::elf::main(int, char**) () #3 0x0000555556dba344 in main (argc=3D3, argv=3D0x7fffffffe178) 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`), gdb can obtain its line num= ber without problems. ruiu@blue:~/mold/build-gold$ gdb ./mold -nx -batch -ex 'b parse_nonpositional_args' -ex 'run --no-fork --no-thread= s' -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 (ctx= =3D...) at /home/ruiu/mold/elf/cmdline.cc:395 395 std::span args =3D ctx.cmdline_args; #0 mold::elf::parse_nonpositional_args (ctx=3D...) at /home/ruiu/mold/elf/cmdline.cc:395 #1 0x0000555555886568 in mold::elf::elf_main (argc=3D3, argv=3D0x7fffffffe178) at /home/ruiu/mold/elf/elf-main.cc:387 #2 0x000055555588212b in mold::elf::main (argc=3D3, argv=3D0x7fffffffe178)= at /home/ruiu/mold/elf/elf-main.cc:758 #3 0x0000555556dba344 in main (argc=3D3, argv=3D0x7fffffffe178) 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= =3Dsharing --=20 You are receiving this mail because: You are on the CC list for the bug.=