From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2G0AILhxKWrZvj8AWB0awg (envelope-from ) for ; Wed, 10 Jun 2026 10:16:24 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=smtpout1 header.b=BAD+ARlS; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 6EC121E070; Wed, 10 Jun 2026 10:16:24 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 743A81E070 for ; Wed, 10 Jun 2026 10:16:23 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 991EA4B78D4F for ; Wed, 10 Jun 2026 14:16:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 991EA4B78D4F Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=smtpout1 header.b=BAD+ARlS Received: from smtpout.efficios.com (smtpout.efficios.com [158.69.130.18]) by sourceware.org (Postfix) with ESMTPS id C58954446B45 for ; Wed, 10 Jun 2026 14:15:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C58954446B45 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C58954446B45 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=158.69.130.18 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1781100929; cv=none; b=Uc04bymH7AzRUD8q4A77XvM6OqSOJ2uMMzFae8JHC/1h/BNC6yZLAzz1Y6phqoKCyhDU1qHol7gcrgw8dVhtJvE5WOWGZnTuBQ/ySqE+NHPBhFjlunPqGASqdLvrBqV6Uj7ZKF8yfauGwH9r8FW3oE4wy+XBuzkBAtXckWSwMVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1781100929; c=relaxed/simple; bh=bUJWFKXI9K5x4DxeuR/p+jTL5+xcGq9bun2tXMQ/2dc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=OlFYd3TxhmuTge9w6DdAN3vP6Lc1ZL4D8t71Ta1v0Z7iZKQ8c3mqG1S1RV7rmq+7dDuWLDNlGzAryS+/mhrwyapp/4Ivul3hqfTHOYmDABiY66ROWKeF4cz4kgZS4laG1dqjp2RLFYKBjd8aeimFyiegx6IzCE1Crj1sP8z1l2U= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=smtpout1 header.b=BAD+ARlS DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C58954446B45 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=smtpout1; t=1781100929; bh=RY8E5S2DK5dF5N+ggEKjGFbsCQv9Y56n6qEIy4AL9g0=; h=From:To:Cc:Subject:Date:From; b=BAD+ARlSMQsu+cPESaf7eXG7VWoLZLqzQh4zU5buIVNiwNpnUwwrTO901SUkTshyd TB5P6uex1mbP0ID+rmDqvLEiLN3U8Hf/YDHoXi68DdW/IGLFCfPhxgUQBaGjKHpLNO 6YrRP2ZNovRXFs465Wmk1EVTo+BRgZSrp/8w1SRAyEDR+yJy8z1uGhqp3f22mRJ3qP /ry5MLbDN4EN5SLjPXlYKs1tRzh84E4V7q7eQS1RZXCczt1rur41qA5nphiGmMGXPk C7qWhXOevklP790wvbTfGMzJ3L0hxghl19N8ukYy33gn8ftNKF9FaYeh7lYJ9IzpgK XFAkVTBaSQqgQ== Received: from smtpout01.internal.efficios.com (mtl.efficios.com [216.120.195.104]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4gb78x1nB5zJ1C for ; Wed, 10 Jun 2026 10:15:29 -0400 (EDT) Received: from sebastien-framework.internal.efficios.com (unknown [172.24.0.11]) by smtpout01.internal.efficios.com (Postfix) with ESMTP id 36CDB128B; Wed, 10 Jun 2026 10:15:29 -0400 (EDT) From: =?UTF-8?q?S=C3=A9bastien=20Darche?= To: gdb-patches@sourceware.org Cc: =?UTF-8?q?S=C3=A9bastien=20Darche?= Subject: [PATCH v2] gdb/breakpoint: remove assertion when printing internal breakpoints without locspecs Date: Wed, 10 Jun 2026 10:15:09 -0400 Message-ID: <20260610141509.12950-1-sdarche@efficios.com> X-Mailer: git-send-email 2.54.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org When debugging gdb with `set debug breakpoint on`, gdb would crash if the inferior happened to unload (through dlclose ()) a shared library that contains jit debugging symbols: ../../gdb/breakpoint.c:6473: internal-error: print_breakpoint_location: Assertion `b->locspec != nullptr || (!user_breakpoint_p (b) && (b->type == bp_shlib_event || b->type == bp_thread_event))' failed. A problem internal to GDB has been detected [...] This assertion was added in commit 5770f68 ("gdb: handle empty locspec when printing breakpoints"). The assumption for this assert is that the user may not call any (gdb-)debugging command between the time a shared library is marked (bp_location->shlib_disabled is set) and the breakpoint is actually removed. This would be true if the user called `maint info breakpoints` as explained in the original commit message. However, if `set debug breakpoint on` is called, gdb prints debugging info as the shared library is being unloaded. The ~jiter_objfile_data dtor deletes the breakpoint, which calls remove_breakpoint_1 on the bp_location in the recently unloaded shared object. Since `debug breakpoint` is enabled, we go through print_breakpoint_location with the bp_location's shlib_disabled flag set, which results in the assert above. This commit removes the assertion as it is not true in all cases. I've also included a minimal test case that loads a shared library with a __jit_debug_register_code symbol. The test fails with the assert. Change-Id: Ia19c84f194a6f0c10315548c7f423bfd86ef0266 --- gdb/breakpoint.c | 17 ------- gdb/testsuite/gdb.base/jit-unload-solib.c | 21 ++++++++ gdb/testsuite/gdb.base/jit-unload.c | 45 ++++++++++++++++ gdb/testsuite/gdb.base/jit-unload.exp | 62 +++++++++++++++++++++++ 4 files changed, 128 insertions(+), 17 deletions(-) create mode 100644 gdb/testsuite/gdb.base/jit-unload-solib.c create mode 100644 gdb/testsuite/gdb.base/jit-unload.c create mode 100644 gdb/testsuite/gdb.base/jit-unload.exp diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 101dc57ee6b..85c4ffc3171 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -6457,23 +6457,6 @@ print_breakpoint_location (const breakpoint *b, const bp_location *loc) } else { - /* Internal breakpoints don't have a locspec string, but can become - pending if the shared library the breakpoint is in is unloaded. - For most internal breakpoint types though, after unloading the - shared library, the breakpoint will be deleted and never recreated - (see internal_breakpoint::re_set). But for two internal - breakpoint types bp_shlib_event and bp_thread_event this is not - true. Usually we don't expect the libraries that contain these - breakpoints to ever be unloaded, but a buggy inferior might do - such a thing, in which case GDB should be prepared to handle this - case. - - If these two breakpoint types become pending then there will be no - locspec string. */ - gdb_assert (b->locspec != nullptr - || (!user_breakpoint_p (b) - && (b->type == bp_shlib_event - || b->type == bp_thread_event))); const char *locspec_str = (b->locspec != nullptr ? b->locspec->to_string () : ""); uiout->field_string ("pending", locspec_str); diff --git a/gdb/testsuite/gdb.base/jit-unload-solib.c b/gdb/testsuite/gdb.base/jit-unload-solib.c new file mode 100644 index 00000000000..3cf2c580320 --- /dev/null +++ b/gdb/testsuite/gdb.base/jit-unload-solib.c @@ -0,0 +1,21 @@ +/* This test program is part of GDB, the GNU debugger. + + Copyright 2026 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 . */ + +/* This simulates a JIT library. */ + + +#include "jit-protocol.h" diff --git a/gdb/testsuite/gdb.base/jit-unload.c b/gdb/testsuite/gdb.base/jit-unload.c new file mode 100644 index 00000000000..92dfa16c055 --- /dev/null +++ b/gdb/testsuite/gdb.base/jit-unload.c @@ -0,0 +1,45 @@ +/* This test program is part of GDB, the GNU debugger. + + Copyright 2026 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 . */ + +/* Simulate loading of a library JIT code. */ + +#include +#include + +#ifdef __WIN32__ +#include +#define dlopen(name, mode) LoadLibrary (TEXT (name)) +#define dlclose(handle) FreeLibrary (handle) +#else +#include +#endif + + +int +main (void) +{ + void *handle = dlopen (SHLIB_NAME, RTLD_NOW); + + if (handle == NULL) + { + fprintf (stderr, "%s\n", dlerror ()); + exit (1); + } + + dlclose (handle); + return 0; +} diff --git a/gdb/testsuite/gdb.base/jit-unload.exp b/gdb/testsuite/gdb.base/jit-unload.exp new file mode 100644 index 00000000000..a5f9adbd76c --- /dev/null +++ b/gdb/testsuite/gdb.base/jit-unload.exp @@ -0,0 +1,62 @@ +# Copyright 2026 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 . + +# This test checks that gdb does not assert when unloading a shared library +# that defines a __jit_debug_register_code if `set debug breakpoint on` is set. + +require allow_shlib_tests + +standard_testfile .c -solib.c +set lib_testfile ${testfile}-lib +set lib_binfile [standard_output_file $lib_testfile] + +if { [build_executable "build shlib" $lib_testfile $srcfile2 \ + {debug shlib}] == -1 } { + return +} + +set lib_testfile_on_target [gdb_download_shlib $lib_binfile] + +set options [list \ + debug \ + shlib_load \ + additional_flags=-DSHLIB_NAME=\"${lib_testfile_on_target}\"] + +if { [prepare_for_testing "build main file" $testfile $srcfile \ + $options] == -1 } { + return +} + +if { ![runto_main] } { + return +} + +gdb_test_no_output "set debug breakpoint on" + +set saw_exit false +gdb_test_multiple "continue" unload { + -re "^\\\[Inferior $decimal \[^\r\n\]+ exited normally\\\]\r\n" { + set saw_exit true + exp_continue + } + + -re "^$gdb_prompt $" { + gdb_assert ${saw_exit} $gdb_test_name + } + + -re "^\[^\r\n\]*\r\n" { + exp_continue + } +} -- 2.54.0