From patchwork Mon Dec 9 21:28:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Barrett X-Patchwork-Id: 36677 Received: (qmail 77643 invoked by alias); 9 Dec 2019 21:28:48 -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 77601 invoked by uid 89); 9 Dec 2019 21:28:47 -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= 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; Mon, 09 Dec 2019 21:28:45 +0000 Received: from internal.mail.bob131.so (localhost [127.0.0.1]) by mail.bob131.so (Postfix) with ESMTP id 6C7EC52C27 for ; Mon, 9 Dec 2019 21:28:42 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.bob131.so 6C7EC52C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bob131.so; s=default; t=1575926922; bh=zZjs5Fmg6MBoNgRNmNO7t63ii8x6HPyDs+/qiMXnmp8=; h=Date:From:To:Subject:From; b=fkXP2nWhWlpQjs4suAJ9rbv+5ZAg2SL2jNbeRJ+9oRa2fHx8w/IwmAHOqaNqAEMpD mHGUmtZdOkEMBoo+UAykavYXUt45eWEgDkXe98vPQCPghdl2IkgaUe3xfICQpiQCPT PK01PjZekARoAtETZLlac45OBbnLLPVBZDiBHsnp0RvOg7lG6D6tnEKM6PuXndMzgw +HLuWC3C9lgJgoHXsU4Qv7QEQb28eKSmvJwG00CoF9Xt8bgBBR9qq1ny9RBDb3LRF5 HOMicoTRMJ8rI7WRywA42SUiSJVDJwlg779YvXUm5xilZBtwP6mlQieixC6WpTSyg1 FgxUjuBt3KRnw== Date: Tue, 10 Dec 2019 08:28:39 +1100 From: George Barrett To: gdb-patches@sourceware.org Subject: [PATCH v2] Fix scripted probe breakpoints Message-ID: MIME-Version: 1.0 Content-Disposition: inline The documentation for make-breakpoint from the Guile API and the `spec' variant of the gdb.Breakpoint constructor from the Python API state that the format acceptable for location strings is the same as that accepted by the break command. However, using the -probe qualifier at the beginning of the location string 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 or Guile scripts. This patch introduces a new helper function that returns a breakpoint_ops instance appropriate for a parsed location and updates the Guile and Python bindings to use said function, rather than the current hard-coded use of bkpt_breakpoint_ops. Since this logic is duplicated in the handling of the `break' and `trace' commands, those are also updated to call into the new helper function. gdb/ChangeLog: 2019-12-10 George Barrett Fix scripted probe breakpoints. * breakpoint.c (tracepoint_probe_breakpoint_ops): Move declaration forward. (breakpoint_ops_for_event_location_type) (breakpoint_ops_for_event_location): Add function definitions. (break_command_1, trace_command): Use breakpoint_ops_for_event_location. * breakpoint.h (breakpoint_ops_for_event_location): Add function declarations. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Use breakpoint_ops_for_event_location. * python/py-breakpoint.c (bppy_init): Use breakpoint_ops_for_event_location. gdb/testsuite/ChangeLog: 2019-12-10 George Barrett Test scripted probe breakpoints. * gdb.guile/scm-breakpoint.c (main): Add probe point. * gdb.python/py-breakpoint.c (main): Likewise. * gdb.guile/scm-breakpoint.exp (test_bkpt_probe): Add probe specifier test. * gdb.python/py-breakpoint.exp (test_bkpt_probe): Likewise. --- gdb/breakpoint.c | 62 +++++++++++++++------- gdb/breakpoint.h | 9 ++++ gdb/guile/scm-breakpoint.c | 4 +- gdb/python/py-breakpoint.c | 5 +- gdb/testsuite/gdb.guile/scm-breakpoint.c | 7 +++ gdb/testsuite/gdb.guile/scm-breakpoint.exp | 23 ++++++++ gdb/testsuite/gdb.python/py-breakpoint.c | 7 +++ gdb/testsuite/gdb.python/py-breakpoint.exp | 20 +++++++ 8 files changed, 116 insertions(+), 21 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 583f46d852..2aa3500a6c 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -246,6 +246,9 @@ struct breakpoint_ops bkpt_breakpoint_ops; /* Breakpoints set on probes. */ static struct breakpoint_ops bkpt_probe_breakpoint_ops; +/* Tracepoints set on probes. */ +static struct breakpoint_ops tracepoint_probe_breakpoint_ops; + /* Dynamic printf class type. */ struct breakpoint_ops dprintf_breakpoint_ops; @@ -9163,6 +9166,41 @@ decode_static_tracepoint_spec (const char **arg_p) return sals; } +/* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and + according to IS_TRACEPOINT. */ + +static const struct breakpoint_ops * +breakpoint_ops_for_event_location_type (enum event_location_type location_type, + bool is_tracepoint) +{ + if (is_tracepoint) + { + if (location_type == PROBE_LOCATION) + return &tracepoint_probe_breakpoint_ops; + else + return &tracepoint_breakpoint_ops; + } + else + { + if (location_type == PROBE_LOCATION) + return &bkpt_probe_breakpoint_ops; + else + return &bkpt_breakpoint_ops; + } +} + +/* See breakpoint.h. */ + +const struct breakpoint_ops * +breakpoint_ops_for_event_location (const struct event_location *location, + bool is_tracepoint) +{ + if (location) + return breakpoint_ops_for_event_location_type + (event_location_type (location), is_tracepoint); + return is_tracepoint ? &tracepoint_breakpoint_ops : &bkpt_breakpoint_ops; +} + /* See breakpoint.h. */ int @@ -9344,16 +9382,10 @@ break_command_1 (const char *arg, int flag, int from_tty) enum bptype type_wanted = (flag & BP_HARDWAREFLAG ? bp_hardware_breakpoint : bp_breakpoint); - struct breakpoint_ops *ops; event_location_up location = string_to_event_location (&arg, current_language); - - /* Matching breakpoints on probes. */ - if (location != NULL - && event_location_type (location.get ()) == PROBE_LOCATION) - ops = &bkpt_probe_breakpoint_ops; - else - ops = &bkpt_breakpoint_ops; + const struct breakpoint_ops *ops = breakpoint_ops_for_event_location + (location.get (), false /* is_tracepoint */); create_breakpoint (get_current_arch (), location.get (), @@ -12802,8 +12834,7 @@ tracepoint_decode_location (struct breakpoint *b, struct breakpoint_ops tracepoint_breakpoint_ops; -/* The breakpoint_ops structure to be use on tracepoints placed in a - static probe. */ +/* Virtual table for tracepoints on static probes. */ static void tracepoint_probe_create_sals_from_location @@ -12824,8 +12855,6 @@ tracepoint_probe_decode_location (struct breakpoint *b, return bkpt_probe_decode_location (b, location, search_pspace); } -static struct breakpoint_ops tracepoint_probe_breakpoint_ops; - /* Dprintf breakpoint_ops methods. */ static void @@ -14467,15 +14496,10 @@ set_tracepoint_count (int num) static void trace_command (const char *arg, int from_tty) { - struct breakpoint_ops *ops; - event_location_up location = string_to_event_location (&arg, current_language); - if (location != NULL - && event_location_type (location.get ()) == PROBE_LOCATION) - ops = &tracepoint_probe_breakpoint_ops; - else - ops = &tracepoint_breakpoint_ops; + const struct breakpoint_ops *ops = breakpoint_ops_for_event_location + (location.get (), true /* is_tracepoint */); create_breakpoint (get_current_arch (), location.get (), diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index a9d689d02a..071ae79d68 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -1352,6 +1352,15 @@ extern void init_catchpoint (struct breakpoint *b, extern void install_breakpoint (int internal, std::unique_ptr &&b, int update_gll); +/* Returns the breakpoint ops appropriate for use with with LOCATION and + according to IS_TRACEPOINT. Use this to ensure, for example, that you pass + the correct ops to create_breakpoint for probe locations. If LOCATION is + null, returns bkpt_breakpoint_ops (or tracepoint_breakpoint_ops, if + IS_TRACEPOINT is non-zero). */ + +extern const struct breakpoint_ops *breakpoint_ops_for_event_location + (const struct event_location *location, bool is_tracepoint); + /* Flags that can be passed down to create_breakpoint, etc., to affect breakpoint creation in several ways. */ diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c index a75daa0001..a6404d544b 100644 --- a/gdb/guile/scm-breakpoint.c +++ b/gdb/guile/scm-breakpoint.c @@ -437,13 +437,15 @@ gdbscm_register_breakpoint_x (SCM self) { case bp_breakpoint: { + const breakpoint_ops *ops = + breakpoint_ops_for_event_location (eloc.get (), false); create_breakpoint (get_current_arch (), eloc.get (), NULL, -1, NULL, 0, 0, bp_breakpoint, 0, AUTO_BOOLEAN_TRUE, - &bkpt_breakpoint_ops, + ops, 0, 1, internal, 0); break; } diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 4170737416..32494aec72 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -828,13 +828,16 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) location = new_explicit_location (&explicit_loc); } + const struct breakpoint_ops *ops = + breakpoint_ops_for_event_location (location.get (), false); + create_breakpoint (python_gdbarch, location.get (), NULL, -1, NULL, 0, temporary_bp, bp_breakpoint, 0, AUTO_BOOLEAN_TRUE, - &bkpt_breakpoint_ops, + ops, 0, 1, internal_bp, 0); break; } diff --git a/gdb/testsuite/gdb.guile/scm-breakpoint.c b/gdb/testsuite/gdb.guile/scm-breakpoint.c index 1670041677..ed7dbdba91 100644 --- a/gdb/testsuite/gdb.guile/scm-breakpoint.c +++ b/gdb/testsuite/gdb.guile/scm-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; int multiply (int i) @@ -38,6 +42,9 @@ int main (int argc, char *argv[]) { result += multiply (foo); /* Break at multiply. */ result += add (bar); /* Break at add. */ +#ifdef USE_PROBES + DTRACE_PROBE1 (test, result_updated, result); +#endif } return 0; /* Break at end. */ diff --git a/gdb/testsuite/gdb.guile/scm-breakpoint.exp b/gdb/testsuite/gdb.guile/scm-breakpoint.exp index 47bc80c2c8..183ad1671f 100644 --- a/gdb/testsuite/gdb.guile/scm-breakpoint.exp +++ b/gdb/testsuite/gdb.guile/scm-breakpoint.exp @@ -499,6 +499,28 @@ proc test_bkpt_address {} { ".*Breakpoint ($decimal)+ at .*$srcfile, line ($decimal)+\." } +proc test_bkpt_probe {} { + global decimal hex testfile srcfile + + if { [prepare_for_testing "failed to prepare" ${testfile}-probes \ + ${srcfile} {additional_flags=-DUSE_PROBES}] } { + return -1 + } + + if ![gdb_guile_runto_main] then { + return + } + + gdb_scm_test_silent_cmd \ + "guile (define bp1 (make-breakpoint \"-probe test:result_updated\"))" \ + "create probe breakpoint" + + gdb_test \ + "guile (register-breakpoint! bp1)" \ + "Breakpoint $decimal at $hex" \ + "register probe breakpoint" +} + test_bkpt_basic test_bkpt_deletion test_bkpt_cond_and_cmds @@ -508,3 +530,4 @@ test_bkpt_internal test_bkpt_eval_funcs test_bkpt_registration test_bkpt_address +test_bkpt_probe diff --git a/gdb/testsuite/gdb.python/py-breakpoint.c b/gdb/testsuite/gdb.python/py-breakpoint.c index d102a5f306..12adc99a1b 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 + DTRACE_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..95f2b2905d 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint.exp +++ b/gdb/testsuite/gdb.python/py-breakpoint.exp @@ -695,6 +695,25 @@ 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}] } { + return -1 + } + + if ![runto_main] then { + fail "cannot run to main." + return 0 + } + + 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 +727,4 @@ test_bkpt_pending test_bkpt_events test_bkpt_explicit_loc test_bkpt_qualified +test_bkpt_probe