From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by sourceware.org (Postfix) with ESMTPS id 07CC83858C50 for ; Tue, 29 Mar 2022 21:28:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 07CC83858C50 Received: by mail-lf1-x134.google.com with SMTP id p15so32525996lfk.8 for ; Tue, 29 Mar 2022 14:28:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SR72v+L5I7Fn5w572+gRJ+ekRalgY8Os8v0gbOO8wcw=; b=1ZWEBKQyypCsbXtrLrj9lqfyulJv0rg36S1VYXQbO7AZgOyecKrHZDJEofy5hnG5Ap jB18QWWGZve7PTxIE6XZ+OLz7kvh+XIw4IFETRUSYJqBqNkHnSCm8CGITiQ5oL2Un7A/ vYuYCdjfbBygMiQrbBeTYb88Fk1rt+2NpMLgeOAgDjwbD7BpJ9IFkkOg7KCCb4RWPdIE gW4lqhNg9GcbI0dDWkeRseJ5TOIcCXbgODlkQGFkL+5VKT26Ep/WDM7LGRESoKeFSE0h sBQ76WiTw+LSdHulCB+2LPnsudufhvlPDsMeyP3e3rQSK8thgBXS7mfAhofg99r5chJ2 jAbA== X-Gm-Message-State: AOAM531pjXhLoppM8SQD3ZjnSaZY7FMGi4wZEXyVN3bHLxVl7GbCtenU nk0g2qZLBIVSn59Upfi7LO7EKdW2Kzc= X-Google-Smtp-Source: ABdhPJw5p/AV+d/ZhsyL6lh+PfDGd4u4FHspSWtsKjsdqYCTIhhCDwSzVUo/SO96dPWy+GAAhJm2Wg== X-Received: by 2002:ac2:5def:0:b0:44a:73e5:3f86 with SMTP id z15-20020ac25def000000b0044a73e53f86mr4333301lfq.361.1648589305457; Tue, 29 Mar 2022 14:28:25 -0700 (PDT) Received: from cx-desktop.. (78-73-77-63-no2450.tbcn.telia.com. [78.73.77.63]) by smtp.gmail.com with ESMTPSA id bj15-20020a2eaa8f000000b00246233c02a5sm2182971ljb.44.2022.03.29.14.28.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 14:28:25 -0700 (PDT) From: Simon Farre To: gdb-patches@sourceware.org Cc: Simon Farre Subject: [PATCH 2/2] gdb/python: add gdb.Breakpoint.addresses property Date: Tue, 29 Mar 2022 23:27:17 +0200 Message-Id: <20220329212717.1184271-2-simon.farre.cx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220329212717.1184271-1-simon.farre.cx@gmail.com> References: <20220329212717.1184271-1-simon.farre.cx@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Mar 2022 21:28:28 -0000 Currently it's not possible from the Python API to know where a breakpoint has been installed in memory. This attribute returns a list of the addresses where this breakpoint has been installed. This reflects the same information shown by the command `info b`. If the breakpoint is pending it will return None, but also if the breakpoint is not of type "breakpoint" or "watchpoint" it will also return none. The rationale for this patch is for IDE or debug adapters as they are called, for instance for VSCode, to be able to fetch breakpoint related data directly from Python, but also useful for plugins that need to query information about breakpoints. --- gdb/NEWS | 5 +++++ gdb/doc/python.texi | 6 ++++++ gdb/python/py-breakpoint.c | 26 ++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index 9e7e41d3bd6..1410c7027e8 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -21,6 +21,11 @@ Breakpoint was installed. This is the information displayed by the 'info breakpoints' command. + ** Added attribute Breakpoint.addresses + This returns a list of addresses (as longs) where the + breakpoint was installed. This is the same address information + displayed by the 'info breakpoint' command + *** Changes in GDB 12 * DBX mode is deprecated, and will be removed in GDB 13 diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 0d842af6229..3511b8b00a4 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -6074,6 +6074,12 @@ breakpoint or is of a type that doesn't have a source location related to it it returns @code{None}. This attribute is not writable. @end defvar +@defvar Breakpoint.addresses +This attribute holds the address(es) where the breakpoint was installed. +If the breakpoint is a pending breakpoint, it returns @code{None}. +This attribute is not writable. +@end defvar + @node Finish Breakpoints in Python @subsubsection Finish Breakpoints diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 1b9ac6957a5..19c7cec815c 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -721,6 +721,30 @@ static PyObject* bppy_get_source_locations(PyObject *self, void* closure) return list.release(); } +/* Python function to get all addresses where this breakpoint is set */ + +static PyObject* bppy_get_addresses(PyObject *self, void* closure) +{ + gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self; + struct breakpoint* bp = self_bp->bp; + + BPPY_REQUIRE_VALID (self_bp); + + if (pending_breakpoint_p(bp)) + Py_RETURN_NONE; + + if (!is_breakpoint(bp) && !is_watchpoint(bp)) + Py_RETURN_NONE; + + gdbpy_ref<> list (PyList_New (0)); + + for (const bp_location* it = bp->loc; it != nullptr; it = it->next) + if(PyList_Append(list.get(), PyLong_FromLong(it->address)) != 0) + return nullptr; + + return list.release(); +} + /* Internal function to validate the Python parameters/keywords provided to bppy_init. */ @@ -1295,6 +1319,8 @@ or None if no condition set."}, "Whether this breakpoint is a pending breakpoint."}, { "source_locations", bppy_get_source_locations, NULL, "Source file locations where this breakpoint is installed"}, + { "addresses", bppy_get_addresses, NULL, + "Get addresses of where this breakpoint is set" }, { NULL } /* Sentinel. */ }; -- 2.32.0