From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) by sourceware.org (Postfix) with ESMTPS id 543293858C00 for ; Fri, 15 Sep 2023 18:36:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 543293858C00 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-il1-x136.google.com with SMTP id e9e14a558f8ab-34f6c725d94so7780395ab.0 for ; Fri, 15 Sep 2023 11:36:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1694802964; x=1695407764; darn=sourceware.org; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=wASJ7aGH54NMzJic2FGjyGLCF86YY4m+hCyrDwM03f0=; b=g8Ymm/Z2OYsCxMZMVFvyOuwwODPYGMWq5neJWr0B5YM+JeMWifsML0dTb2MiUzjW4c 3E1ptMk4/meTPvM5w3kdQNlBceXjjQVLQ3yjRk91kHuXjEpdfSchJcR6V/4Eeaj8teen pF28Ou2hydn+pyfJJG2v9tqZOk+bFtcXEs7V+EcHLWjzXOOkR8npNUerxlIksG3oTKdW e8FvjltqJrWxyaHqIxFJtv9I7mRuPG3YPhZfskjjco7gxG1H1fAmMl8gbYuI/xJWZLA9 0AtHwd73jIXZI4Vh62ume4T8ZJ/WqEO9o8JF9yO+JyKl2igE7owbpEX2uVj+TpZS3UM0 2eFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694802964; x=1695407764; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wASJ7aGH54NMzJic2FGjyGLCF86YY4m+hCyrDwM03f0=; b=r53veFha8fyZuVDfDfOJpre+m9c0/zRkuv5QE+goA5OiZShOmeUjaRBF6eOmHCQ670 0ue1NMit325lybUv/b4oRo/OWlO2wzfawgXNBUnAGL9ycOq9NCPwo502JTLXrw1+GD7t Tgp/Y1hcX16/aemKZc4+GVoW1jnDIMUO6nA1uWvEJQ+ZNEteRVoWnwhvDvr5CvlOwNwx iUhQVhMlz7CuhfUNnDruIW0CMxn/snhobgXNQIDW1R+Abu9/HPB2rI7peJhvP9dFUEIe kKn2STLn8eJII+0rTPKjnSOU0fX504K/vfH3nmua041BncEmeISI8SmS4jy6C/uZz5Cr 1FJQ== X-Gm-Message-State: AOJu0Yz2KhCyDWNA4Ojv7nJVA8cZprahh3YzAtmlMxZMy/vYf/jfcxf9 qQWZkcSKUCp3ZZRvtBOdTwHQY75knqk2ZW/zdpK1Uw== X-Google-Smtp-Source: AGHT+IHw7srPC5x4WVXts4bL+r/PVodPKoB3a16wXDg7z/342ra3aGeykfKKqGTD6Wx0vgnavQaDvA== X-Received: by 2002:a05:6e02:13e9:b0:34c:d0d6:512f with SMTP id w9-20020a056e0213e900b0034cd0d6512fmr2725816ilj.7.1694802964408; Fri, 15 Sep 2023 11:36:04 -0700 (PDT) Received: from localhost.localdomain (71-211-130-31.hlrn.qwest.net. [71.211.130.31]) by smtp.gmail.com with ESMTPSA id w25-20020a02cf99000000b0042b0a6d899fsm1235997jar.60.2023.09.15.11.36.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 11:36:03 -0700 (PDT) From: Tom Tromey Date: Fri, 15 Sep 2023 12:36:02 -0600 Subject: [PATCH 2/4] Use gdb::checked_static_cast for tracepoints MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230915-watchpoint-casts-v1-2-a4ff35c9644e@adacore.com> References: <20230915-watchpoint-casts-v1-0-a4ff35c9644e@adacore.com> In-Reply-To: <20230915-watchpoint-casts-v1-0-a4ff35c9644e@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This replaces some casts to 'tracepoint *' with checked_static_cast. Some functions are changed to accept a 'tracepoint *' now, for better type safety. --- gdb/breakpoint.c | 33 +++++++++++++++++++-------------- gdb/mi/mi-cmd-break.c | 10 +++++++--- gdb/remote.c | 11 +++++------ gdb/target-debug.h | 2 ++ gdb/target-delegates.c | 16 ++++++++-------- gdb/target.c | 2 +- gdb/target.h | 4 ++-- gdb/tracefile-tfile.c | 4 ++-- gdb/tracepoint.c | 28 +++++++++++++++++----------- gdb/tracepoint.h | 4 ++-- 10 files changed, 65 insertions(+), 49 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index c0d86f38c73..134ad76ce9a 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -1433,7 +1433,7 @@ validate_commands_for_breakpoint (struct breakpoint *b, { if (is_tracepoint (b)) { - struct tracepoint *t = (struct tracepoint *) b; + struct tracepoint *t = gdb::checked_static_cast (b); struct command_line *c; struct command_line *while_stepping = 0; @@ -1471,7 +1471,7 @@ validate_commands_for_breakpoint (struct breakpoint *b, while_stepping = c; } - validate_actionline (c->line, b); + validate_actionline (c->line, t); } if (while_stepping) { @@ -1645,7 +1645,9 @@ commands_command_1 (const char *arg, int from_tty, auto do_validate = [=] (const char *line) { - validate_actionline (line, b); + struct tracepoint *t + = gdb::checked_static_cast (b); + validate_actionline (line, t); }; gdb::function_view validator; if (is_tracepoint (b)) @@ -6762,7 +6764,7 @@ print_one_breakpoint_location (struct breakpoint *b, if (!part_of_multiple && is_tracepoint (b)) { - struct tracepoint *tp = (struct tracepoint *) b; + struct tracepoint *tp = gdb::checked_static_cast (b); if (tp->traceframe_usage) { @@ -6794,7 +6796,7 @@ print_one_breakpoint_location (struct breakpoint *b, if (is_tracepoint (b)) { - struct tracepoint *t = (struct tracepoint *) b; + struct tracepoint *t = gdb::checked_static_cast (b); if (!part_of_multiple && t->pass_count) { @@ -12811,9 +12813,8 @@ ambiguous_names_p (const bp_location_range &locs) precisely because it confuses tools). */ static struct symtab_and_line -update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) +update_static_tracepoint (struct tracepoint *tp, struct symtab_and_line sal) { - struct tracepoint *tp = (struct tracepoint *) b; struct static_tracepoint_marker marker; CORE_ADDR pc; @@ -12825,7 +12826,7 @@ update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) { if (tp->static_trace_marker_id != marker.str_id) warning (_("static tracepoint %d changed probed marker from %s to %s"), - b->number, tp->static_trace_marker_id.c_str (), + tp->number, tp->static_trace_marker_id.c_str (), marker.str_id.c_str ()); tp->static_trace_marker_id = std::move (marker.str_id); @@ -12856,7 +12857,7 @@ update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) warning (_("marker for static tracepoint %d (%s) not " "found at previous line number"), - b->number, tp->static_trace_marker_id.c_str ()); + tp->number, tp->static_trace_marker_id.c_str ()); symtab_and_line sal2 = find_pc_line (tpmarker->address, 0); sym = find_pc_sect_function (tpmarker->address, NULL); @@ -12882,17 +12883,17 @@ update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) uiout->field_signed ("line", sal2.line); uiout->text ("\n"); - b->first_loc ().line_number = sal2.line; - b->first_loc ().symtab = sym != NULL ? sal2.symtab : NULL; + tp->first_loc ().line_number = sal2.line; + tp->first_loc ().symtab = sym != NULL ? sal2.symtab : NULL; std::unique_ptr els (new explicit_location_spec ()); els->source_filename = xstrdup (symtab_to_filename_for_display (sal2.symtab)); - els->line_offset.offset = b->first_loc ().line_number; + els->line_offset.offset = tp->first_loc ().line_number; els->line_offset.sign = LINE_OFFSET_NONE; - b->locspec = std::move (els); + tp->locspec = std::move (els); /* Might be nice to check if function changed, and warn if so. */ @@ -13153,7 +13154,11 @@ code_breakpoint::location_spec_to_sals (location_spec *locspec, } if (type == bp_static_tracepoint) - sals[0] = update_static_tracepoint (this, sals[0]); + { + struct tracepoint *t + = gdb::checked_static_cast (this); + sals[0] = update_static_tracepoint (t, sals[0]); + } *found = 1; } diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c index 975bc1c5dde..2294ea3723b 100644 --- a/gdb/mi/mi-cmd-break.c +++ b/gdb/mi/mi-cmd-break.c @@ -585,11 +585,15 @@ mi_cmd_break_commands (const char *command, const char *const *argv, int argc) }; if (is_tracepoint (b)) - break_command = read_command_lines_1 (reader, 1, - [=] (const char *line) + { + struct tracepoint *t + = gdb::checked_static_cast (b); + break_command = read_command_lines_1 (reader, 1, + [=] (const char *line) { - validate_actionline (line, b); + validate_actionline (line, t); }); + } else break_command = read_command_lines_1 (reader, 1, 0); diff --git a/gdb/remote.c b/gdb/remote.c index ba81c5b0b6f..38b4145be30 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -911,7 +911,7 @@ class remote_target : public process_stratum_target int get_trace_status (struct trace_status *ts) override; - void get_tracepoint_status (struct breakpoint *tp, struct uploaded_tp *utp) + void get_tracepoint_status (struct tracepoint *tp, struct uploaded_tp *utp) override; void trace_stop () override; @@ -13256,7 +13256,7 @@ remote_target::download_tracepoint (struct bp_location *loc) std::vector stepping_actions; char *pkt; struct breakpoint *b = loc->owner; - struct tracepoint *t = (struct tracepoint *) b; + struct tracepoint *t = gdb::checked_static_cast (b); struct remote_state *rs = get_remote_state (); int ret; const char *err_msg = _("Tracepoint packet too large for target."); @@ -13675,12 +13675,11 @@ remote_target::get_trace_status (struct trace_status *ts) } void -remote_target::get_tracepoint_status (struct breakpoint *bp, +remote_target::get_tracepoint_status (struct tracepoint *tp, struct uploaded_tp *utp) { struct remote_state *rs = get_remote_state (); char *reply; - struct tracepoint *tp = (struct tracepoint *) bp; size_t size = get_remote_packet_size (); if (tp) @@ -13700,7 +13699,7 @@ remote_target::get_tracepoint_status (struct breakpoint *bp, if (reply && *reply) { if (*reply == 'V') - parse_tracepoint_status (reply + 1, bp, utp); + parse_tracepoint_status (reply + 1, tp, utp); } } } @@ -13715,7 +13714,7 @@ remote_target::get_tracepoint_status (struct breakpoint *bp, if (reply && *reply) { if (*reply == 'V') - parse_tracepoint_status (reply + 1, bp, utp); + parse_tracepoint_status (reply + 1, tp, utp); } } } diff --git a/gdb/target-debug.h b/gdb/target-debug.h index a028d2ba5f4..2eccc7840d6 100644 --- a/gdb/target-debug.h +++ b/gdb/target-debug.h @@ -126,6 +126,8 @@ target_debug_do_print (host_address_to_string (X)) #define target_debug_print_struct_breakpoint_p(X) \ target_debug_do_print (host_address_to_string (X)) +#define target_debug_print_struct_tracepoint_p(X) \ + target_debug_do_print (host_address_to_string (X)) #define target_debug_print_struct_uploaded_tp_p(X) \ target_debug_do_print (host_address_to_string (X)) #define target_debug_print_struct_uploaded_tp_pp(X) \ diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c index 8b066249624..909f2725035 100644 --- a/gdb/target-delegates.c +++ b/gdb/target-delegates.c @@ -143,7 +143,7 @@ struct dummy_target : public target_ops void trace_set_readonly_regions () override; void trace_start () override; int get_trace_status (struct trace_status *arg0) override; - void get_tracepoint_status (struct breakpoint *arg0, struct uploaded_tp *arg1) override; + void get_tracepoint_status (struct tracepoint *arg0, struct uploaded_tp *arg1) override; void trace_stop () override; int trace_find (enum trace_find_type arg0, int arg1, CORE_ADDR arg2, CORE_ADDR arg3, int *arg4) override; bool get_trace_state_variable_value (int arg0, LONGEST *arg1) override; @@ -318,7 +318,7 @@ struct debug_target : public target_ops void trace_set_readonly_regions () override; void trace_start () override; int get_trace_status (struct trace_status *arg0) override; - void get_tracepoint_status (struct breakpoint *arg0, struct uploaded_tp *arg1) override; + void get_tracepoint_status (struct tracepoint *arg0, struct uploaded_tp *arg1) override; void trace_stop () override; int trace_find (enum trace_find_type arg0, int arg1, CORE_ADDR arg2, CORE_ADDR arg3, int *arg4) override; bool get_trace_state_variable_value (int arg0, LONGEST *arg1) override; @@ -3216,24 +3216,24 @@ debug_target::get_trace_status (struct trace_status *arg0) } void -target_ops::get_tracepoint_status (struct breakpoint *arg0, struct uploaded_tp *arg1) +target_ops::get_tracepoint_status (struct tracepoint *arg0, struct uploaded_tp *arg1) { this->beneath ()->get_tracepoint_status (arg0, arg1); } void -dummy_target::get_tracepoint_status (struct breakpoint *arg0, struct uploaded_tp *arg1) +dummy_target::get_tracepoint_status (struct tracepoint *arg0, struct uploaded_tp *arg1) { tcomplain (); } void -debug_target::get_tracepoint_status (struct breakpoint *arg0, struct uploaded_tp *arg1) +debug_target::get_tracepoint_status (struct tracepoint *arg0, struct uploaded_tp *arg1) { gdb_printf (gdb_stdlog, "-> %s->get_tracepoint_status (...)\n", this->beneath ()->shortname ()); this->beneath ()->get_tracepoint_status (arg0, arg1); gdb_printf (gdb_stdlog, "<- %s->get_tracepoint_status (", this->beneath ()->shortname ()); - target_debug_print_struct_breakpoint_p (arg0); + target_debug_print_struct_tracepoint_p (arg0); gdb_puts (", ", gdb_stdlog); target_debug_print_struct_uploaded_tp_p (arg1); gdb_puts (")\n", gdb_stdlog); @@ -4553,9 +4553,9 @@ dummy_target::fetch_x86_xsave_layout () x86_xsave_layout debug_target::fetch_x86_xsave_layout () { - x86_xsave_layout result; gdb_printf (gdb_stdlog, "-> %s->fetch_x86_xsave_layout (...)\n", this->beneath ()->shortname ()); - result = this->beneath ()->fetch_x86_xsave_layout (); + x86_xsave_layout result + = this->beneath ()->fetch_x86_xsave_layout (); gdb_printf (gdb_stdlog, "<- %s->fetch_x86_xsave_layout (", this->beneath ()->shortname ()); gdb_puts (") = ", gdb_stdlog); target_debug_print_x86_xsave_layout (result); diff --git a/gdb/target.c b/gdb/target.c index 68d7fe2bb56..8cb4fa1736d 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -667,7 +667,7 @@ target_get_trace_status (trace_status *ts) } void -target_get_tracepoint_status (breakpoint *tp, uploaded_tp *utp) +target_get_tracepoint_status (tracepoint *tp, uploaded_tp *utp) { return current_inferior ()->top_target ()->get_tracepoint_status (tp, utp); } diff --git a/gdb/target.h b/gdb/target.h index aa07075f9f2..18388a32d19 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -1043,7 +1043,7 @@ struct target_ops virtual int get_trace_status (struct trace_status *ts) TARGET_DEFAULT_RETURN (-1); - virtual void get_tracepoint_status (struct breakpoint *tp, + virtual void get_tracepoint_status (struct tracepoint *tp, struct uploaded_tp *utp) TARGET_DEFAULT_NORETURN (tcomplain ()); @@ -2255,7 +2255,7 @@ extern void target_trace_set_readonly_regions (); extern int target_get_trace_status (trace_status *ts); -extern void target_get_tracepoint_status (breakpoint *tp, uploaded_tp *utp); +extern void target_get_tracepoint_status (tracepoint *tp, uploaded_tp *utp); extern void target_trace_stop (); diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c index 3440f375021..1158a8beeb2 100644 --- a/gdb/tracefile-tfile.c +++ b/gdb/tracefile-tfile.c @@ -67,7 +67,7 @@ class tfile_target final : public tracefile_target bool get_trace_state_variable_value (int tsv, LONGEST *val) override; traceframe_info_up traceframe_info () override; - void get_tracepoint_status (struct breakpoint *tp, + void get_tracepoint_status (struct tracepoint *tp, struct uploaded_tp *utp) override; }; @@ -633,7 +633,7 @@ tfile_target::files_info () } void -tfile_target::get_tracepoint_status (struct breakpoint *tp, struct uploaded_tp *utp) +tfile_target::get_tracepoint_status (struct tracepoint *tp, struct uploaded_tp *utp) { /* Other bits of trace status were collected as part of opening the trace files, so nothing to do here. */ diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index 205380476b3..9cec91f0fd4 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -157,7 +157,7 @@ static std::string trace_stop_notes; struct collection_list; -static counted_command_line all_tracepoint_actions (struct breakpoint *); +static counted_command_line all_tracepoint_actions (struct tracepoint *); static struct trace_status trace_status; @@ -626,12 +626,11 @@ finalize_tracepoint_aexpr (struct agent_expr *aexpr) /* worker function */ void -validate_actionline (const char *line, struct breakpoint *b) +validate_actionline (const char *line, struct tracepoint *t) { struct cmd_list_element *c; const char *tmp_p; const char *p; - struct tracepoint *t = (struct tracepoint *) b; /* If EOF is typed, *line is NULL. */ if (line == NULL) @@ -1479,7 +1478,9 @@ encode_actions (struct bp_location *tloc, gdbarch_virtual_frame_pointer (tloc->gdbarch, tloc->address, &frame_reg, &frame_offset); - counted_command_line actions = all_tracepoint_actions (tloc->owner); + struct tracepoint *t + = gdb::checked_static_cast (tloc->owner); + counted_command_line actions = all_tracepoint_actions (t); encode_actions_1 (actions.get (), tloc, frame_reg, frame_offset, tracepoint_list, stepping_list); encode_actions_1 (breakpoint_commands (tloc->owner), tloc, @@ -1884,8 +1885,12 @@ tstatus_command (const char *args, int from_tty) (long int) (ts->stop_time % 1000000)); /* Now report any per-tracepoint status available. */ - for (breakpoint &t : all_tracepoints ()) - target_get_tracepoint_status (&t, NULL); + for (breakpoint &b : all_tracepoints ()) + { + struct tracepoint *t + = gdb::checked_static_cast (&b); + target_get_tracepoint_status (t, nullptr); + } } /* Report the trace status to uiout, in a way suitable for MI, and not @@ -2751,7 +2756,7 @@ get_traceframe_location (int *stepping_frame_p) /* Return the default collect actions of a tracepoint T. */ static counted_command_line -all_tracepoint_actions (struct breakpoint *t) +all_tracepoint_actions (struct tracepoint *t) { counted_command_line actions (nullptr, command_lines_deleter ()); @@ -2794,7 +2799,9 @@ tdump_command (const char *args, int from_tty) select_frame (get_current_frame ()); - counted_command_line actions = all_tracepoint_actions (loc->owner); + struct tracepoint *t + = gdb::checked_static_cast (loc->owner); + counted_command_line actions = all_tracepoint_actions (t); trace_dump_actions (actions.get (), 0, stepping_frame, from_tty); trace_dump_actions (breakpoint_commands (loc->owner), 0, stepping_frame, @@ -3059,7 +3066,7 @@ merge_uploaded_tracepoints (struct uploaded_tp **uploaded_tps) /* Mark this location as already inserted. */ loc->inserted = 1; - t = (struct tracepoint *) loc->owner; + t = gdb::checked_static_cast (loc->owner); gdb_printf (_("Assuming tracepoint %d is same " "as target's tracepoint %d at %s.\n"), loc->owner->number, utp->number, @@ -3368,11 +3375,10 @@ Status line: '%s'\n"), p, line); } void -parse_tracepoint_status (const char *p, struct breakpoint *bp, +parse_tracepoint_status (const char *p, struct tracepoint *tp, struct uploaded_tp *utp) { ULONGEST uval; - struct tracepoint *tp = (struct tracepoint *) bp; p = unpack_varlen_hex (p, &uval); if (tp) diff --git a/gdb/tracepoint.h b/gdb/tracepoint.h index a637d6b71d3..60b51390002 100644 --- a/gdb/tracepoint.h +++ b/gdb/tracepoint.h @@ -354,7 +354,7 @@ extern void encode_actions_rsp (struct bp_location *tloc, std::vector *tdp_actions, std::vector *stepping_actions); -extern void validate_actionline (const char *, struct breakpoint *); +extern void validate_actionline (const char *, struct tracepoint *); extern void validate_trace_state_variable_name (const char *name); extern struct trace_state_variable *find_trace_state_variable (const char *name); @@ -369,7 +369,7 @@ extern int encode_source_string (int num, ULONGEST addr, extern void parse_trace_status (const char *line, struct trace_status *ts); -extern void parse_tracepoint_status (const char *p, struct breakpoint *tp, +extern void parse_tracepoint_status (const char *p, struct tracepoint *tp, struct uploaded_tp *utp); extern void parse_tracepoint_definition (const char *line, -- 2.40.1