| Message ID | 20251222132340.53858-1-ssbssa@yahoo.de |
|---|---|
| State | New |
| Headers |
Return-Path: <gdb-patches-bounces~patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id BCADA4BA2E1C for <patchwork@sourceware.org>; Mon, 22 Dec 2025 13:24:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BCADA4BA2E1C Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=yahoo.de header.i=@yahoo.de header.a=rsa-sha256 header.s=s2048 header.b=ZAaA0zdL X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from sonic310-57.consmr.mail.ir2.yahoo.com (sonic310-57.consmr.mail.ir2.yahoo.com [77.238.177.30]) by sourceware.org (Postfix) with ESMTPS id 395F64BA2E04 for <gdb-patches@sourceware.org>; Mon, 22 Dec 2025 13:23:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 395F64BA2E04 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=yahoo.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=yahoo.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 395F64BA2E04 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=77.238.177.30 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1766409839; cv=none; b=In9KVjvpyajJqOFx/51w0kflaGvBewWDODmCUji+gCliID1aX/0KHliEuj18G0+yzJZnCVjbNfR4ikL9XrpW70IUPHO2Oc+mFujhsFsXNRXwqmHAsTuIRLko4ccQSGaEK34oHycznJDgRk/UOji7ZZWQSx54yxic8OR99R/16qE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1766409839; c=relaxed/simple; bh=VnCMTbhwG8hWwsdqEBl7U6Y8fbOIJpys0WHQF/ndJIQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=BenGi3vFkyus14g6a4lXrp5NutmBaS/lgjT7Rqbd1vCCoEVywPuG0ds7eohVhtuJE2fEBBjxCB9h/hvY0iRYCzwMbmNa4tvmT2nuNfd2K1/2qerPhwvaJZolIbwOBt1WzTgRlCGLXNvFJDrMbpS8lA0hnVnCMfd9A8LBzrf1/tg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 395F64BA2E04 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s2048; t=1766409838; bh=nKMGTqebhW4E/Ftx0Jlo/uabRuGHMhKn8shkzztIfTA=; h=From:To:Subject:Date:References:From:Subject:Reply-To; b=ZAaA0zdLT32hoCpV0/wKrNluXA19THCETFDcTaiQ1k7N0zGVVfirvn9Jlq0PTgMIeoaVOV2WE2ZHrlEqRk4qfsRNK8ecjIb4HQYdw35SYNlf/Rgk7ArcezuoomOGzGBuu2YkLZfuiFKpp0sWJO9LaJ16ycT2IWBVEfVdGf8yOAJjtxdwwDBo3EznEQ78oX2uo7MVqjGWJeoaasN5gT0GHnaa/8dErRPt+fWHYZucEg1cfc3dWZFbBawAxwCzQfk0EyhJGuhMYQCzQhJ7t9NVcS7DqtcGXOtWEXxxBcRFayEuB4F36ClXXpCvsycHRFOf68W2vrbgk5ELFh9+yRGeCg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1766409838; bh=7sJbHIEoEjW7HgW/geH/xbXbvLNgN4bXwaMkSC1N9nX=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=P7ha0ce/l4bxnLEAtcNAEn2ARqzOFbmKPwOXATaKlMKawYSeOGVh639R1n8D6iJw3ToNXkZa1Tw0ZPo6SflFaJxWe+AQVU+LWCFaMuilHeozJRUAziMiKTJy2S/n+cqqs6yIKXuqZF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JJR2mPIKyV3HZzAUiNXDLVEQXb30mwt3qD1ka1 zvb9SpBml5PP909So1.Ug6NDdpUEv7JB3IoT.hHHd9EVw2397rSl22kToplQL0XzqsbqazeLzMjs bKAcYF7pUPwrYh.P7Sc0Ua63vd_BZO_jrPk.e4dM3CKE5.40otSit8M1Qs11Xq6akuGQWMSB0vzu XtzusTKpKd53gXJu5NYn0BF1dbxSImBhOPSO0p5e6w3XRGZN7UNsP1xCBh7dqoESAZgxIoj0jhbg pHhtdZGSouG9Ojik2MIuxP8oa_AV180rb7JpdRAnDO15yOHsek2Q.Cc8P0XyagvuMmvnxbxkI.lJ DIuIRbhyMvi0Mmg7f4f2_QZwMsrVZ1MAqWgIqiQ-- X-Sonic-MF: <ssbssa@yahoo.de> X-Sonic-ID: 9eb83ad1-52b6-4d61-ab58-4cb473fc2cbd Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.ir2.yahoo.com with HTTP; Mon, 22 Dec 2025 13:23:58 +0000 Received: by hermes--production-ir2-7679c5bc-9t954 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID f50f86a921379e107ea85839e11c4a9d; Mon, 22 Dec 2025 13:23:56 +0000 (UTC) From: Hannes Domani <ssbssa@yahoo.de> To: gdb-patches@sourceware.org Subject: [PATCH] Forget the last displayed sal when obfiles are purged Date: Mon, 22 Dec 2025 14:23:40 +0100 Message-ID: <20251222132340.53858-1-ssbssa@yahoo.de> X-Mailer: git-send-email 2.52.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit References: <20251222132340.53858-1-ssbssa.ref@yahoo.de> X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED, WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list <gdb-patches.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=subscribe> Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org |
| Series |
Forget the last displayed sal when obfiles are purged
|
|
Commit Message
Hannes Domani
Dec. 22, 2025, 1:23 p.m. UTC
When creating a new line-breakpoint after rerunning with a disabled
breakpoint in a solib, you currently get this use-after-free crash:
(gdb) break solib_main
Breakpoint 1 at 0x1030
(gdb) run
Starting program: /home/src/lappy/binutils-gdb.git/build/gdb/testsuite/outputs/gdb.base/solib-breakpoints-rerun/solib-breakpoints-rerun
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/../lib/libthread_db.so.1".
Breakpoint 1, solib_main (arg=100) at /home/src/lappy/binutils-gdb.git/build/gdb/testsuite/../../../gdb/testsuite/gdb.base/solib1.c:7
7 int ans = arg*arg; /* HERE */
(gdb) disable
(gdb) set confirm off
(gdb) run
Starting program: /home/src/lappy/binutils-gdb.git/build/gdb/testsuite/outputs/gdb.base/solib-breakpoints-rerun/solib-breakpoints-rerun
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/../lib/libthread_db.so.1".
[Inferior 1 (process 50868) exited normally]
(gdb) break 18
=================================================================
==50836==ERROR: AddressSanitizer: heap-use-after-free on address 0x7d65a543d488 at pc 0x55f022334c29 bp 0x7ffe9c7f45f0 sp 0x7ffe9c7f45e0
READ of size 8 at 0x7d65a543d488 thread T0
#0 0x55f022334c28 in symtab::filename() const ../../gdb/symtab.h:1747
#1 0x55f023a32b7d in create_sals_line_offset ../../gdb/linespec.c:2013
#2 0x55f023a37937 in convert_linespec_to_sals ../../gdb/linespec.c:2294
#3 0x55f023a3cf79 in parse_linespec ../../gdb/linespec.c:2652
#4 0x55f023a415b2 in location_spec_to_sals ../../gdb/linespec.c:3050
#5 0x55f023a423b0 in decode_line_full(location_spec*, int, program_space*, symtab*, int, linespec_result*, char const*, char const*) ../../gdb/linespec.c:3126
#6 0x55f022826e1b in parse_breakpoint_sals ../../gdb/breakpoint.c:9069
#7 0x55f0228291c2 in create_breakpoint(gdbarch*, location_spec*, char const*, int, int, char const*, bool, int, int, bptype, int, auto_boolean, breakpoint_ops const*, int, int, int, unsigned int) ../../gdb/breakpoint.c:9312
#8 0x55f02282c298 in break_command_1 ../../gdb/breakpoint.c:9471
#9 0x55f02282d0bb in break_command(char const*, int) ../../gdb/breakpoint.c:9541
#10 0x55f022b05f56 in do_simple_func ../../gdb/cli/cli-decode.c:94
0x7d65a543d488 is located 904 bytes inside of 4064-byte region [0x7d65a543d100,0x7d65a543e0e0)
freed by thread T0 here:
#0 0x7f55aa91f79d in free /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:51
#1 0x55f0221f6403 in xfree<void> ../../gdb/../gdbsupport/gdb-xfree.h:37
#2 0x55f027b64851 in call_freefun ../../libiberty/obstack.c:103
#3 0x55f027b66283 in _obstack_free ../../libiberty/obstack.c:280
#4 0x55f0221f7a07 in auto_obstack::~auto_obstack() ../../gdb/../gdbsupport/gdb_obstack.h:126
#5 0x55f023f3dd83 in objfile::~objfile() ../../gdb/objfiles.c:509
#6 0x55f023f511d8 in std::default_delete<objfile>::operator()(objfile*) const /usr/include/c++/15.2.1/bits/unique_ptr.h:93
#7 0x55f023f4b8cd in std::unique_ptr<objfile, std::default_delete<objfile> >::~unique_ptr() /usr/include/c++/15.2.1/bits/unique_ptr.h:399
#8 0x55f0240b6dab in owning_intrusive_list<objfile, intrusive_base_node<objfile> >::erase(intrusive_list_iterator<objfile, intrusive_base_node<objfile> >) ../../gdb/../gdbsupport/owning_intrusive_list.h:113
#9 0x55f0240adb68 in program_space::remove_objfile(objfile*) ../../gdb/progspace.c:202
#10 0x55f023f3cfcf in objfile::unlink() ../../gdb/objfiles.c:409
#11 0x55f023f40faf in objfile_purge_solibs(program_space*) ../../gdb/objfiles.c:687
#12 0x55f02487ec19 in no_shared_libraries(program_space*) ../../gdb/solib.c:1359
#13 0x55f024b37e1e in target_pre_inferior() ../../gdb/target.c:2474
#14 0x55f0238ac7cd in run_command_1 ../../gdb/infcmd.c:381
#15 0x55f0238ae438 in run_command ../../gdb/infcmd.c:510
#16 0x55f022b05f56 in do_simple_func ../../gdb/cli/cli-decode.c:94
previously allocated by thread T0 here:
#0 0x7f55aa920cb5 in malloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:67
#1 0x55f02241d780 in xmalloc ../../gdb/alloc.c:52
#2 0x55f027b6461f in call_chunkfun ../../libiberty/obstack.c:94
#3 0x55f027b649d1 in _obstack_begin_worker ../../libiberty/obstack.c:141
#4 0x55f027b650c5 in _obstack_begin ../../libiberty/obstack.c:164
#5 0x55f0221f775a in auto_obstack::auto_obstack() ../../gdb/../gdbsupport/gdb_obstack.h:123
#6 0x55f023f39c91 in objfile::objfile(gdb::ref_ptr<bfd, gdb_bfd_ref_policy>, program_space*, char const*, enum_flags<objfile_flag>) ../../gdb/objfiles.c:257
#7 0x55f023f3ccaa in objfile::make(gdb::ref_ptr<bfd, gdb_bfd_ref_policy>, program_space*, char const*, enum_flags<objfile_flag>, objfile*) ../../gdb/objfiles.c:392
#8 0x55f02498b1d2 in symbol_file_add_with_addrs ../../gdb/symfile.c:1069
#9 0x55f02498c099 in symbol_file_add_from_bfd(gdb::ref_ptr<bfd, gdb_bfd_ref_policy> const&, char const*, enum_flags<symfile_add_flag>, std::vector<other_sections, std::allocator<other_sections> >*, enum_flags<objfile_flag>, objfile*) ../../gdb/symfile.c:1156
#10 0x55f02487255b in solib_read_symbols(solib&, enum_flags<symfile_add_flag>) ../../gdb/solib.c:660
#11 0x55f024876c0c in solib_add(char const*, int, int) ../../gdb/solib.c:993
#12 0x55f02487f1f8 in handle_solib_event() ../../gdb/solib.c:1399
#13 0x55f0227df91f in bpstat_stop_status(address_space const*, unsigned long, thread_info*, target_waitstatus const&, bpstat*) ../../gdb/breakpoint.c:5962
#14 0x55f023944fa8 in handle_signal_stop ../../gdb/infrun.c:7130
#15 0x55f02393e2a1 in handle_inferior_event ../../gdb/infrun.c:6574
#16 0x55f0239279f2 in fetch_inferior_event() ../../gdb/infrun.c:4713
#17 0x55f023885fe3 in inferior_event_handler(inferior_event_type) ../../gdb/inf-loop.c:42
#18 0x55f023af706e in handle_target_event ../../gdb/linux-nat.c:4449
#19 0x55f027c2d2f0 in handle_file_event ../../gdbsupport/event-loop.cc:551
#20 0x55f027c2e4ff in gdb_wait_for_event ../../gdbsupport/event-loop.cc:672
It happened because last_displayed_symtab_info of stack.c still contained
a reference to a symtab that was already freed in the 2nd run.
This fixes it by clearing last_displayed_symtab_info when the solibs are
purged, now setting of the 2nd breakpoint works:
(gdb) break 18
Breakpoint 2 at 0x555555555141: file /home/src/lappy/binutils-gdb.git/build/gdb/testsuite/../../../gdb/testsuite/gdb.base/so-impl-ld.c, line 18.
(gdb)
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32668
---
gdb/objfiles.c | 3 ++
.../gdb.base/solib-breakpoints-rerun.exp | 49 +++++++++++++++++++
2 files changed, 52 insertions(+)
create mode 100644 gdb/testsuite/gdb.base/solib-breakpoints-rerun.exp
Comments
Hannes Domani <ssbssa@yahoo.de> writes: > When creating a new line-breakpoint after rerunning with a disabled > breakpoint in a solib, you currently get this use-after-free crash: > > (gdb) break solib_main > Breakpoint 1 at 0x1030 > (gdb) run > Starting program: /home/src/lappy/binutils-gdb.git/build/gdb/testsuite/outputs/gdb.base/solib-breakpoints-rerun/solib-breakpoints-rerun > [Thread debugging using libthread_db enabled] > Using host libthread_db library "/usr/lib/../lib/libthread_db.so.1". > > Breakpoint 1, solib_main (arg=100) at /home/src/lappy/binutils-gdb.git/build/gdb/testsuite/../../../gdb/testsuite/gdb.base/solib1.c:7 > 7 int ans = arg*arg; /* HERE */ > (gdb) disable > (gdb) set confirm off > (gdb) run > Starting program: /home/src/lappy/binutils-gdb.git/build/gdb/testsuite/outputs/gdb.base/solib-breakpoints-rerun/solib-breakpoints-rerun > [Thread debugging using libthread_db enabled] > Using host libthread_db library "/usr/lib/../lib/libthread_db.so.1". > [Inferior 1 (process 50868) exited normally] > (gdb) break 18 > ================================================================= > ==50836==ERROR: AddressSanitizer: heap-use-after-free on address 0x7d65a543d488 at pc 0x55f022334c29 bp 0x7ffe9c7f45f0 sp 0x7ffe9c7f45e0 > READ of size 8 at 0x7d65a543d488 thread T0 > #0 0x55f022334c28 in symtab::filename() const ../../gdb/symtab.h:1747 > #1 0x55f023a32b7d in create_sals_line_offset ../../gdb/linespec.c:2013 > #2 0x55f023a37937 in convert_linespec_to_sals ../../gdb/linespec.c:2294 > #3 0x55f023a3cf79 in parse_linespec ../../gdb/linespec.c:2652 > #4 0x55f023a415b2 in location_spec_to_sals ../../gdb/linespec.c:3050 > #5 0x55f023a423b0 in decode_line_full(location_spec*, int, program_space*, symtab*, int, linespec_result*, char const*, char const*) ../../gdb/linespec.c:3126 > #6 0x55f022826e1b in parse_breakpoint_sals ../../gdb/breakpoint.c:9069 > #7 0x55f0228291c2 in create_breakpoint(gdbarch*, location_spec*, char const*, int, int, char const*, bool, int, int, bptype, int, auto_boolean, breakpoint_ops const*, int, int, int, unsigned int) ../../gdb/breakpoint.c:9312 > #8 0x55f02282c298 in break_command_1 ../../gdb/breakpoint.c:9471 > #9 0x55f02282d0bb in break_command(char const*, int) ../../gdb/breakpoint.c:9541 > #10 0x55f022b05f56 in do_simple_func ../../gdb/cli/cli-decode.c:94 > > 0x7d65a543d488 is located 904 bytes inside of 4064-byte region [0x7d65a543d100,0x7d65a543e0e0) > freed by thread T0 here: > #0 0x7f55aa91f79d in free /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:51 > #1 0x55f0221f6403 in xfree<void> ../../gdb/../gdbsupport/gdb-xfree.h:37 > #2 0x55f027b64851 in call_freefun ../../libiberty/obstack.c:103 > #3 0x55f027b66283 in _obstack_free ../../libiberty/obstack.c:280 > #4 0x55f0221f7a07 in auto_obstack::~auto_obstack() ../../gdb/../gdbsupport/gdb_obstack.h:126 > #5 0x55f023f3dd83 in objfile::~objfile() ../../gdb/objfiles.c:509 > #6 0x55f023f511d8 in std::default_delete<objfile>::operator()(objfile*) const /usr/include/c++/15.2.1/bits/unique_ptr.h:93 > #7 0x55f023f4b8cd in std::unique_ptr<objfile, std::default_delete<objfile> >::~unique_ptr() /usr/include/c++/15.2.1/bits/unique_ptr.h:399 > #8 0x55f0240b6dab in owning_intrusive_list<objfile, intrusive_base_node<objfile> >::erase(intrusive_list_iterator<objfile, intrusive_base_node<objfile> >) ../../gdb/../gdbsupport/owning_intrusive_list.h:113 > #9 0x55f0240adb68 in program_space::remove_objfile(objfile*) ../../gdb/progspace.c:202 > #10 0x55f023f3cfcf in objfile::unlink() ../../gdb/objfiles.c:409 > #11 0x55f023f40faf in objfile_purge_solibs(program_space*) ../../gdb/objfiles.c:687 > #12 0x55f02487ec19 in no_shared_libraries(program_space*) ../../gdb/solib.c:1359 > #13 0x55f024b37e1e in target_pre_inferior() ../../gdb/target.c:2474 > #14 0x55f0238ac7cd in run_command_1 ../../gdb/infcmd.c:381 > #15 0x55f0238ae438 in run_command ../../gdb/infcmd.c:510 > #16 0x55f022b05f56 in do_simple_func ../../gdb/cli/cli-decode.c:94 > > previously allocated by thread T0 here: > #0 0x7f55aa920cb5 in malloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:67 > #1 0x55f02241d780 in xmalloc ../../gdb/alloc.c:52 > #2 0x55f027b6461f in call_chunkfun ../../libiberty/obstack.c:94 > #3 0x55f027b649d1 in _obstack_begin_worker ../../libiberty/obstack.c:141 > #4 0x55f027b650c5 in _obstack_begin ../../libiberty/obstack.c:164 > #5 0x55f0221f775a in auto_obstack::auto_obstack() ../../gdb/../gdbsupport/gdb_obstack.h:123 > #6 0x55f023f39c91 in objfile::objfile(gdb::ref_ptr<bfd, gdb_bfd_ref_policy>, program_space*, char const*, enum_flags<objfile_flag>) ../../gdb/objfiles.c:257 > #7 0x55f023f3ccaa in objfile::make(gdb::ref_ptr<bfd, gdb_bfd_ref_policy>, program_space*, char const*, enum_flags<objfile_flag>, objfile*) ../../gdb/objfiles.c:392 > #8 0x55f02498b1d2 in symbol_file_add_with_addrs ../../gdb/symfile.c:1069 > #9 0x55f02498c099 in symbol_file_add_from_bfd(gdb::ref_ptr<bfd, gdb_bfd_ref_policy> const&, char const*, enum_flags<symfile_add_flag>, std::vector<other_sections, std::allocator<other_sections> >*, enum_flags<objfile_flag>, objfile*) ../../gdb/symfile.c:1156 > #10 0x55f02487255b in solib_read_symbols(solib&, enum_flags<symfile_add_flag>) ../../gdb/solib.c:660 > #11 0x55f024876c0c in solib_add(char const*, int, int) ../../gdb/solib.c:993 > #12 0x55f02487f1f8 in handle_solib_event() ../../gdb/solib.c:1399 > #13 0x55f0227df91f in bpstat_stop_status(address_space const*, unsigned long, thread_info*, target_waitstatus const&, bpstat*) ../../gdb/breakpoint.c:5962 > #14 0x55f023944fa8 in handle_signal_stop ../../gdb/infrun.c:7130 > #15 0x55f02393e2a1 in handle_inferior_event ../../gdb/infrun.c:6574 > #16 0x55f0239279f2 in fetch_inferior_event() ../../gdb/infrun.c:4713 > #17 0x55f023885fe3 in inferior_event_handler(inferior_event_type) ../../gdb/inf-loop.c:42 > #18 0x55f023af706e in handle_target_event ../../gdb/linux-nat.c:4449 > #19 0x55f027c2d2f0 in handle_file_event ../../gdbsupport/event-loop.cc:551 > #20 0x55f027c2e4ff in gdb_wait_for_event ../../gdbsupport/event-loop.cc:672 > > It happened because last_displayed_symtab_info of stack.c still contained > a reference to a symtab that was already freed in the 2nd run. > This fixes it by clearing last_displayed_symtab_info when the solibs are > purged, now setting of the 2nd breakpoint works: > > (gdb) break 18 > Breakpoint 2 at 0x555555555141: file /home/src/lappy/binutils-gdb.git/build/gdb/testsuite/../../../gdb/testsuite/gdb.base/so-impl-ld.c, line 18. > (gdb) > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32668 > --- > gdb/objfiles.c | 3 ++ > .../gdb.base/solib-breakpoints-rerun.exp | 49 +++++++++++++++++++ > 2 files changed, 52 insertions(+) > create mode 100644 gdb/testsuite/gdb.base/solib-breakpoints-rerun.exp > > diff --git a/gdb/objfiles.c b/gdb/objfiles.c > index 5c5b04c6458..247f0765391 100644 > --- a/gdb/objfiles.c > +++ b/gdb/objfiles.c > @@ -47,6 +47,7 @@ > #include "gdb_bfd.h" > #include "btrace.h" > #include "gdbsupport/pathstuff.h" > +#include "stack.h" > > #include <algorithm> > > @@ -685,6 +686,8 @@ objfile_purge_solibs (program_space *pspace) > if (!(objf.flags & OBJF_USERLOADED) && (objf.flags & OBJF_SHARED)) > objf.unlink (); > } > + > + clear_last_displayed_sal (); In objfile::~objfile we have this code: /* Check to see if the current_source_symtab belongs to this objfile, and if so, call clear_current_source_symtab_and_line. */ clear_current_source_symtab_and_line (this); I know we have both a last displayed symtab, and a current symtab, so I guess you're handling the "other" one, though I don't have time to check right now. I wonder if it would be better to handle the last displayed symtab at the same time as the current symtab? Also, the clear_current_source_symtab_and_line call seems to only clear things if this was the objfile that was removed, which should avoid clearing it unnecessarily maybe? Would like to hear your thoughts. > } > > /* See objfiles.h. */ > diff --git a/gdb/testsuite/gdb.base/solib-breakpoints-rerun.exp b/gdb/testsuite/gdb.base/solib-breakpoints-rerun.exp > new file mode 100644 > index 00000000000..2769d1630fc > --- /dev/null > +++ b/gdb/testsuite/gdb.base/solib-breakpoints-rerun.exp > @@ -0,0 +1,49 @@ > +# Copyright 2025 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see <http://www.gnu.org/licenses/>. > + > +# Test setting new line-breakpoint after re-running with disabled > +# breakpoint inside solib. > + > +require !use_gdb_stub > +require allow_shlib_tests > + > +standard_testfile so-impl-ld.c > +set libfile "solib1" > +set libsrc $srcdir/$subdir/$libfile.c > +set lib_sl [standard_output_file $libfile.sl] > + > +set lib_opts {debug shlib} > +set exec_opts [list debug shlib=$lib_sl] > + > +if { [build_executable "build shlib" $lib_sl $libsrc $lib_opts] != 0 } { > + return > +} > + > +if { [prepare_for_testing "prepare" $testfile $srcfile $exec_opts] != 0 } { > + return > +} > + > +gdb_test "break solib_main" "Breakpoint $decimal at .*" You could use 'gdb_breakpoint solib_main' here. > + > +gdb_test "run" "Breakpoint $decimal, solib_main.*" "run with breakpoint" > + > +gdb_test "disable" "" You could use 'delete_breakpoints' here I think. Thanks, Andrew > + > +gdb_test "set confirm off" "" > +gdb_test "run" "\[Inferior $decimal \\(\[^\r\n\]*\\) exited normally\]" \ > + "run with disabled breakpoint" > + > +set bp_location [gdb_get_line_number "result = solib_main"] > +gdb_test "break $bp_location" "Breakpoint $decimal at .*" > -- > 2.52.0
diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 5c5b04c6458..247f0765391 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -47,6 +47,7 @@ #include "gdb_bfd.h" #include "btrace.h" #include "gdbsupport/pathstuff.h" +#include "stack.h" #include <algorithm> @@ -685,6 +686,8 @@ objfile_purge_solibs (program_space *pspace) if (!(objf.flags & OBJF_USERLOADED) && (objf.flags & OBJF_SHARED)) objf.unlink (); } + + clear_last_displayed_sal (); } /* See objfiles.h. */ diff --git a/gdb/testsuite/gdb.base/solib-breakpoints-rerun.exp b/gdb/testsuite/gdb.base/solib-breakpoints-rerun.exp new file mode 100644 index 00000000000..2769d1630fc --- /dev/null +++ b/gdb/testsuite/gdb.base/solib-breakpoints-rerun.exp @@ -0,0 +1,49 @@ +# Copyright 2025 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Test setting new line-breakpoint after re-running with disabled +# breakpoint inside solib. + +require !use_gdb_stub +require allow_shlib_tests + +standard_testfile so-impl-ld.c +set libfile "solib1" +set libsrc $srcdir/$subdir/$libfile.c +set lib_sl [standard_output_file $libfile.sl] + +set lib_opts {debug shlib} +set exec_opts [list debug shlib=$lib_sl] + +if { [build_executable "build shlib" $lib_sl $libsrc $lib_opts] != 0 } { + return +} + +if { [prepare_for_testing "prepare" $testfile $srcfile $exec_opts] != 0 } { + return +} + +gdb_test "break solib_main" "Breakpoint $decimal at .*" + +gdb_test "run" "Breakpoint $decimal, solib_main.*" "run with breakpoint" + +gdb_test "disable" "" + +gdb_test "set confirm off" "" +gdb_test "run" "\[Inferior $decimal \\(\[^\r\n\]*\\) exited normally\]" \ + "run with disabled breakpoint" + +set bp_location [gdb_get_line_number "result = solib_main"] +gdb_test "break $bp_location" "Breakpoint $decimal at .*"