From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id rGHxJbAipGpifAAAWB0awg (envelope-from ) for ; Fri, 11 Sep 2026 11:48:00 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=iag2GG6P; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 870F31E091; Fri, 11 Sep 2026 11:48:00 -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 [IPv6:2620:52:6:3111::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 9F2811E091 for ; Fri, 11 Sep 2026 11:47:59 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 356B148F3413 for ; Fri, 11 Sep 2026 15:47:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 356B148F3413 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=iag2GG6P Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 944B948F5266 for ; Fri, 11 Sep 2026 15:47:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 944B948F5266 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 944B948F5266 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789141654; cv=none; b=RsT7zUlPaOVId/VWJW04157HGf5VQqHV3LkqvOL+xaY8/sMzeSun/AoqdZq3EjsdgODzNoUZxUBuUkPabVYKHJG61EHWCcFO30g/n70ePxQBkovnXesipLtkpnJTtbohwMCz4EzgQdNvxT3oHHeoOS710jrNSUbF/ig0UPXY9EU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789141654; c=relaxed/simple; bh=twCo3DHtiL4IwKpiWnpASHRxnMxB4JwiAAtJ1y7xYtE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=moKT1VE8VFVdbilprvgjKOjjt/GkkAmkRXT+FeJiHav5l2GiCsGClsX+Aj4Tchp5RNwO5+2xwbIM0lklGNfX+K8AAlbYVQcbW4ubq4Jfr3/rmWSnsfx6qXeRvouUGtN9X8BhOhVAWY2GDbMs95XK81goUFAFEE07i1k3eViKJmQ= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=iag2GG6P DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 944B948F5266 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-2d91ff7d9acso9076315ad.3 for ; Fri, 11 Sep 2026 08:47:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1789141649; x=1789746449; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=Z27JRfCFL6bqSkQExhdvEmy1eHla9QsUt/adw3s45g0=; b=iag2GG6PD8W+6hVlmtS6BosahMK4oWdUFi/cGjqJukk93AyK5eGod2N2F2aMyU8tN5 c5YmHqd2Ato1tyfQWE7tVVO7bjRZLe1uJfoc+h5gCqwDr1YYh3jcllqIkGMhq4HxBMYn KFcPSS9aNlM0IvdE+VPEO5+du0CD1PW/dkY4MibAHfQVC8O9xzS57nwHt+/rjHM3TPnO 4iMUlHLV0jQXcsTT4R+4AG76GBT0AzgJhs67n4mMQOG9Q7hQS7SIGCn9Dc12e87ZiRUk TqWDGibAPq7nxwwQGVpzAMU1U2tdAUDJ9v6rLnYc9HQQk8AmJuE1ZAmlOHGzhfRgVmt2 UktQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789141649; x=1789746449; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Z27JRfCFL6bqSkQExhdvEmy1eHla9QsUt/adw3s45g0=; b=Hgk7yMoauCqyfzjBwY3xewkVlLm2ICYC/EI9at6rtsf6ajv2wva1iabtU5MqCL+b/4 W7GwnbdYNwwaYX0vlNZXv+P2vfTVuZoReW2M7lZFORXkVCPe0SNCb6+eLvIoS5kR+8WJ HjKW/hwqUyQ0AQiwtBMdU4jjYF/SaePzkDgYEo2cBtnaDYQx8vevljGdX6RxIY2RK8Zz cn/uzc+B0tvhD0inljOyaZNu/iUDSvcUxJLY1eTh5nm8IbrApZB5bymM45/0KXjCsq+v gj3aecc8EN0dMndbn+tQypHMG9/q6yM+tDVtUQtXc40pDrT6K+Kqb1IaSA1WdNp6yi2g IT3g== X-Gm-Message-State: AFuF++luJJ3JCrm8xvLpL2V2tQwMYfDyNjEr6ttS0QytXgf3dsYWgFeT gVYtR8+GZ3wdciRDuPGk37UnmUJeDOlD9mmpjq3J3yRBY1hOh1gS4GtOurV93gdWE10n06LL3Sc nhHOojA== X-Gm-Gg: AYBFou39oP1bWF6bO7rYCqODsMroy1uVAeDUNjAdxLiIEh18HA8ifaEJVmcn3gIXs4W shsTbTlsWcGKlykJFFDxYOOJu93wl46q5Aj7dNCsNoefTLEFGTB2qpxK1rxNlGDhY6K1bvVhnvF TQlTQEVhMaWy/LT6gSCdvN0o+QsMtF12RzynKMm/92P9aLy4pFJuFS0sIitiq/j7VtO3InyJJHZ Tu4qWYhStMZgkZ4YjcfTiv7l+FxR8XPESJersEJvykTvFa2+2r0C5G30zCW/pN6D16ri80f7B5H ZPUJItzqLHbcT07eMD1ESv3ic7GzvdzNhxh2gV5Larch1BPGMIsyd0LM90XCrMWQfMwUIY7K40w 9+coOIZq7i1PEomx7M+0xk88v56M1tmD/TKByRx2zFW3NxMuWp1jHVVNLkN0M++pumE9sD/B1Ip 8DobjV5GQSdQ8Wpw2Qd7hNW+RVziPBvskZ9U/l5ncXJ/gFs6vvAmb5eBA7PL57rPolzyrxNdEqP FzIEeWKVXvIl8Q= X-Received: by 2002:a17:902:ce8b:b0:2d7:2edd:d140 with SMTP id d9443c01a7336-2dd2a1c3e42mr85032515ad.3.1789141649139; Fri, 11 Sep 2026 08:47:29 -0700 (PDT) Received: from bapiya (97-122-117-2.hlrn.qwest.net. [97.122.117.2]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2dd46670232sm917825ad.64.2026.09.11.08.47.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 08:47:28 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Rewrite bplocpy_repr Date: Fri, 11 Sep 2026 09:47:26 -0600 Message-ID: <20260911154726.667576-1-tromey@adacore.com> X-Mailer: git-send-email 2.55.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 A user pointed out that printing the repr() of a watchpoint location will cause gdb to crash. See the new test in py-breakpoint.exp. Rather than try to fix this directly, it seemed better to me to have this function call bp_location::to_string. This call omits a bit of useful information so the enabled state is still handled in bplocpy_repr. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34595 --- gdb/python/py-breakpoint.c | 32 +++++++++----------- gdb/testsuite/gdb.python/py-bp-locations.exp | 11 ++----- gdb/testsuite/gdb.python/py-breakpoint.exp | 2 ++ 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index ecb42cee5f9..561a6c478ac 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -1752,27 +1752,23 @@ bplocpy_repr (PyObject *py_self) || self->owner->bp != self->bp_loc->owner) return gdb_py_invalid_object_repr (py_self); - const auto enabled = self->bp_loc->enabled ? "enabled" : "disabled"; - + /* For most things we just defer to bp_location::to_string, but that + doesn't include the enabled/disabled information, which is kind + of handy here. */ + const auto enabled = self->bp_loc->enabled ? "enabled " : "disabled "; std::string str (enabled); - str += string_printf (" address=%s", - paddress (self->bp_loc->owner->gdbarch, - self->bp_loc->address)); - - if (self->bp_loc->requested_address != self->bp_loc->address) - str += string_printf (" requested_address=%s", - paddress (self->bp_loc->owner->gdbarch, - self->bp_loc->requested_address)); - if (self->bp_loc->symtab != nullptr) - str += string_printf (" source=%s:%d", self->bp_loc->symtab->filename (), - self->bp_loc->line_number); - - const auto fn_name = self->bp_loc->function_name.get (); - if (fn_name != nullptr) + try { - str += " in "; - str += fn_name; + str += self->bp_loc->to_string (); + } + catch (const gdb_exception_error &ignore) + { + return gdb_py_invalid_object_repr (py_self); + } + catch (const gdb_exception &except) + { + return gdbpy_handle_gdb_exception (nullptr, except); } return PyUnicode_FromFormat ("<%s %s>", diff --git a/gdb/testsuite/gdb.python/py-bp-locations.exp b/gdb/testsuite/gdb.python/py-bp-locations.exp index 879306ea0f2..29b610a3364 100644 --- a/gdb/testsuite/gdb.python/py-bp-locations.exp +++ b/gdb/testsuite/gdb.python/py-bp-locations.exp @@ -32,10 +32,10 @@ if {![runto_main]} { } # Build a regexp string that represents the __repr__ of a -# gdb.BreakpointLocation object. Accepts arguments -enabled, -address, +# gdb.BreakpointLocation object. Accepts arguments -enabled, # -source, -line, and -func. proc build_bpl_regexp { args } { - parse_args [list {enabled True} [list address "$::hex"] {source ".*"} \ + parse_args [list {enabled True} {source ".*"} \ [list line "$::decimal"] {func ""}] set pattern "" + append pattern " in ${func} at ${source}:${line}>" return $pattern } diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp index 8b19a11b1f6..49a7a6de7d9 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint.exp +++ b/gdb/testsuite/gdb.python/py-breakpoint.exp @@ -388,6 +388,8 @@ proc_with_prefix test_watchpoints { } { gdb_test "continue" \ ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*main.*" \ "Test watchpoint write" + + gdb_test "python print(repr(wp1.locations\[0\]))" } proc_with_prefix test_bkpt_internal { } { base-commit: 0855b93cfb911a4feab76a31bb1914982b3e6979 -- 2.55.0