From patchwork Sat Dec 7 16:46:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Barrett X-Patchwork-Id: 36583 Received: (qmail 75572 invoked by alias); 7 Dec 2019 16:46:26 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 75564 invoked by uid 89); 7 Dec 2019 16:46:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.1 spammy=probes, H*RU:sk:server2, H*r:sk:server2, HX-Spam-Relays-External:sk:server2 X-HELO: mail.bob131.so Received: from server2.bob131.so (HELO mail.bob131.so) (128.199.153.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 07 Dec 2019 16:46:23 +0000 Received: from internal.mail.bob131.so (localhost [127.0.0.1]) by mail.bob131.so (Postfix) with ESMTP id D27D952C27 for ; Sat, 7 Dec 2019 16:46:20 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.bob131.so D27D952C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bob131.so; s=default; t=1575737180; bh=9db7HvaPpoyWiaWiLMYxJWx4mQIApfaqaxDt4xDU12U=; h=Date:From:To:Subject:From; b=nfwtQTOdr9fpBe7++R1sh56dV72yUHtLp9CmUDnIC00xb+tMnzhP/UfHkrjIWEkCP nobP0DfUpDS516aolgTxpGHaKBYJIMiZFPA9FEdIjEgzQ453LqQOgGFjjv7LgjXEcn m3xl9cY/FUtcfOvZOcL/+Jc5S9u9dhb58fZ5N0HSyJ4Ay2O6bj6QVcb5IEpYOtLeQx CR16INL1esMNvPW+37hT/5Gd1ps7ffSz3iq5LLLkhqI7sALwszo7Q1PXI45V8/B7he LnsJ0On1DWb86U45Bvbt8bhQVoivUcmt4IxKR2TYlvIrIF4scQBzNvajdb32HhPRd+ bqJdcpKq4wEcg== Date: Sun, 8 Dec 2019 03:46:18 +1100 From: George Barrett To: gdb-patches@sourceware.org Subject: [PATCH] Fix Python probe breakpoints Message-ID: MIME-Version: 1.0 Content-Disposition: inline The documentation for the `spec' variant of the gdb.Breakpoint constructor states that the accepted format is the same as the break command. However, using the -probe qualifier at the beginning of the breakpoint specifier causes a GDB internal error as it attempts to decode a probe location in the wrong code path. Without this functionality, there doesn't appear to be another way to set breakpoints on probe points from Python scripts. This patch changes the constructor to test whether the parsed breakpoint location is a probe, and if so it uses the probe-specific breakpoint ops instead. gdb/ChangeLog: 2019-12-08 George Barrett Fix Python probe breakpoints. * breakpoint.c: Make bkpt_probe_breakpoint_ops non-static. * breakpoint.h: Add declaration for bkpt_probe_breakpoint_ops. * python/py-breakpoint.c: Use probe ops if the specifier is a probe specifier. gdb/testsuite/ChangeLog: 2019-12-08 George Barrett Test Python probe breakpoints. * gdb.python/py-breakpoint.c: Add probe point. * gdb.python/py-breakpoint.exp: Add probe specifier test. --- gdb/breakpoint.c | 2 +- gdb/breakpoint.h | 1 + gdb/python/py-breakpoint.c | 5 ++++- gdb/testsuite/gdb.python/py-breakpoint.c | 7 +++++++ gdb/testsuite/gdb.python/py-breakpoint.exp | 22 ++++++++++++++++++++++ 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 583f46d852..0e3f6d954a 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -244,7 +244,7 @@ static struct breakpoint_ops momentary_breakpoint_ops; struct breakpoint_ops bkpt_breakpoint_ops; /* Breakpoints set on probes. */ -static struct breakpoint_ops bkpt_probe_breakpoint_ops; +struct breakpoint_ops bkpt_probe_breakpoint_ops; /* Dynamic printf class type. */ struct breakpoint_ops dprintf_breakpoint_ops; diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index a9d689d02a..47ca1174ab 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -1307,6 +1307,7 @@ extern void tbreak_command (const char *, int); extern struct breakpoint_ops base_breakpoint_ops; extern struct breakpoint_ops bkpt_breakpoint_ops; extern struct breakpoint_ops tracepoint_breakpoint_ops; +extern struct breakpoint_ops bkpt_probe_breakpoint_ops; extern struct breakpoint_ops dprintf_breakpoint_ops; extern void initialize_breakpoint_ops (void); diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 4170737416..ddd8eeecae 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -834,7 +834,10 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) temporary_bp, bp_breakpoint, 0, AUTO_BOOLEAN_TRUE, - &bkpt_breakpoint_ops, + (event_location_type (location.get ()) + == PROBE_LOCATION + ? &bkpt_probe_breakpoint_ops + : &bkpt_breakpoint_ops), 0, 1, internal_bp, 0); break; } diff --git a/gdb/testsuite/gdb.python/py-breakpoint.c b/gdb/testsuite/gdb.python/py-breakpoint.c index d102a5f306..bf5bec1200 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint.c +++ b/gdb/testsuite/gdb.python/py-breakpoint.c @@ -15,6 +15,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifdef USE_PROBES +#include +#endif + int result = 0; namespace foo_ns @@ -46,6 +50,9 @@ int main (int argc, char *argv[]) { result += multiply (foo); /* Break at multiply. */ result += add (bar); /* Break at add. */ +#ifdef USE_PROBES + STAP_PROBE1 (test, result_updated, result); +#endif } return 0; /* Break at end. */ diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp index 625977c0ad..9e3cb475af 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint.exp +++ b/gdb/testsuite/gdb.python/py-breakpoint.exp @@ -695,6 +695,27 @@ proc_with_prefix test_bkpt_qualified {} { "-q in spec string and qualified false" } +proc_with_prefix test_bkpt_probe {} { + global decimal hex testfile srcfile + + if { [prepare_for_testing "failed to prepare" ${testfile}-probes \ + ${srcfile} {debug c++ additional_flags=-DUSE_PROBES}] } { + untested "breakpoint probe test failed" + return -1 + } + + if ![runto_main] then { + fail "cannot run to main." + return 0 + } + + delete_breakpoints + gdb_test \ + "python gdb.Breakpoint(\"-probe test:result_updated\")" \ + "Breakpoint $decimal at $hex" \ + "-probe in spec string" +} + test_bkpt_basic test_bkpt_deletion test_bkpt_cond_and_cmds @@ -708,3 +729,4 @@ test_bkpt_pending test_bkpt_events test_bkpt_explicit_loc test_bkpt_qualified +test_bkpt_probe