From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from outbound-ss-761.bluehost.com (outbound-ss-761.bluehost.com [74.220.211.250]) by sourceware.org (Postfix) with ESMTPS id 91C123857C60 for ; Tue, 18 Jan 2022 19:40:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 91C123857C60 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw10.mail.unifiedlayer.com (unknown [10.0.90.125]) by progateway8.mail.pro1.eigbox.com (Postfix) with ESMTP id F038910052AE9 for ; Tue, 18 Jan 2022 19:40:14 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id 9uL0nA7e3nAlU9uL0n1WPV; Tue, 18 Jan 2022 19:40:14 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=QIOt+iHL c=1 sm=1 tr=0 ts=61e7179e a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=DghFqjY3_ZEA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=jOcpiVt20PkyiKvmeIYA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=B9X7b7t8PJ/c6Qxb9QjLqazIF7Pv+QYKO6X+y6b3/V8=; b=en0lIkSXV55hYiEBzVFgDWj4Y9 j2rv9onwqkegY5YV0TqaKkgWJC+mgWereG2LHc1uYbBGrxCQ9RxqGHpyD9Lf47ZlnI+shsn6stjPy WRt3oWruaipy1EJhJ18HqWbcA; Received: from 75-166-134-30.hlrn.qwest.net ([75.166.134.30]:40584 helo=prentzel.Home) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n9uL0-0015TE-49; Tue, 18 Jan 2022 12:40:14 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 12/36] Convert watchpoints to vtable ops Date: Tue, 18 Jan 2022 12:39:43 -0700 Message-Id: <20220118194007.2853108-13-tom@tromey.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220118194007.2853108-1-tom@tromey.com> References: <20220118194007.2853108-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.134.30 X-Source-L: No X-Exim-ID: 1n9uL0-0015TE-49 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-134-30.hlrn.qwest.net (prentzel.Home) [75.166.134.30]:40584 X-Source-Auth: tom+tromey.com X-Email-Count: 13 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3031.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP 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, 18 Jan 2022 19:40:18 -0000 This converts watchpoints and masked watchpoints. to use vtable_breakpoint_ops. For masked watchpoints, a new subclass must be introduced, and watch_command_1 is changed to create one. --- gdb/breakpoint.c | 280 ++++++++++++++++++++--------------------------- gdb/breakpoint.h | 16 +++ 2 files changed, 132 insertions(+), 164 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 069d3a9049a..49e67d8eb9e 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -9418,13 +9418,11 @@ watchpoint_exp_is_const (const struct expression *exp) return exp->op->constant_p (); } -/* Implement the "re_set" breakpoint_ops method for watchpoints. */ +/* Implement the "re_set" method for watchpoints. */ -static void -re_set_watchpoint (struct breakpoint *b) +void +watchpoint::re_set () { - struct watchpoint *w = (struct watchpoint *) b; - /* Watchpoint can be either on expression using entirely global variables, or it can be on local variables. @@ -9446,44 +9444,42 @@ re_set_watchpoint (struct breakpoint *b) I'm not sure we'll ever be called in this case. If a local watchpoint's frame id is still valid, then - w->exp_valid_block is likewise valid, and we can safely use it. + exp_valid_block is likewise valid, and we can safely use it. Don't do anything about disabled watchpoints, since they will be reevaluated again when enabled. */ - update_watchpoint (w, 1 /* reparse */); + update_watchpoint (this, 1 /* reparse */); } -/* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ +/* Implement the "insert" method for hardware watchpoints. */ -static int -insert_watchpoint (struct bp_location *bl) +int +watchpoint::insert_location (struct bp_location *bl) { - struct watchpoint *w = (struct watchpoint *) bl->owner; - int length = w->exact ? 1 : bl->length; + int length = exact ? 1 : bl->length; return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, - w->cond_exp.get ()); + cond_exp.get ()); } -/* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ +/* Implement the "remove" method for hardware watchpoints. */ -static int -remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) +int +watchpoint::remove_location (struct bp_location *bl, + enum remove_bp_reason reason) { - struct watchpoint *w = (struct watchpoint *) bl->owner; - int length = w->exact ? 1 : bl->length; + int length = exact ? 1 : bl->length; return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, - w->cond_exp.get ()); + cond_exp.get ()); } -static int -breakpoint_hit_watchpoint (const struct bp_location *bl, - const address_space *aspace, CORE_ADDR bp_addr, - const target_waitstatus &ws) +int +watchpoint::breakpoint_hit (const struct bp_location *bl, + const address_space *aspace, CORE_ADDR bp_addr, + const target_waitstatus &ws) { struct breakpoint *b = bl->owner; - struct watchpoint *w = (struct watchpoint *) b; /* Continuable hardware watchpoints are treated as non-existent if the reason we stopped wasn't a hardware watchpoint (we didn't stop on @@ -9492,54 +9488,51 @@ breakpoint_hit_watchpoint (const struct bp_location *bl, been defined. Also skip watchpoints which we know did not trigger (did not match the data address). */ if (is_hardware_watchpoint (b) - && w->watchpoint_triggered == watch_triggered_no) + && watchpoint_triggered == watch_triggered_no) return 0; return 1; } -static void -check_status_watchpoint (bpstat *bs) +void +watchpoint::check_status (bpstat *bs) { gdb_assert (is_watchpoint (bs->breakpoint_at)); bpstat_check_watchpoint (bs); } -/* Implement the "resources_needed" breakpoint_ops method for - hardware watchpoints. */ +/* Implement the "resources_needed" method for hardware + watchpoints. */ -static int -resources_needed_watchpoint (const struct bp_location *bl) +int +watchpoint::resources_needed (const struct bp_location *bl) { - struct watchpoint *w = (struct watchpoint *) bl->owner; - int length = w->exact? 1 : bl->length; + int length = exact? 1 : bl->length; return target_region_ok_for_hw_watchpoint (bl->address, length); } -/* Implement the "works_in_software_mode" breakpoint_ops method for - hardware watchpoints. */ +/* Implement the "works_in_software_mode" method for hardware + watchpoints. */ -static int -works_in_software_mode_watchpoint (const struct breakpoint *b) +int +watchpoint::works_in_software_mode () const { /* Read and access watchpoints only work with hardware support. */ - return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; + return type == bp_watchpoint || type == bp_hardware_watchpoint; } -static enum print_stop_action -print_it_watchpoint (bpstat *bs) +enum print_stop_action +watchpoint::print_it (bpstat *bs) { struct breakpoint *b; enum print_stop_action result; - struct watchpoint *w; struct ui_out *uiout = current_uiout; gdb_assert (bs->bp_location_at != NULL); b = bs->breakpoint_at; - w = (struct watchpoint *) b; annotate_watchpoint (b->number); maybe_print_thread_hit_breakpoint (uiout); @@ -9560,7 +9553,7 @@ print_it_watchpoint (bpstat *bs) watchpoint_value_print (bs->old_val.get (), &stb); uiout->field_stream ("old", stb); uiout->text ("\nNew value = "); - watchpoint_value_print (w->val.get (), &stb); + watchpoint_value_print (val.get (), &stb); uiout->field_stream ("new", stb); uiout->text ("\n"); /* More than one watchpoint may have been triggered. */ @@ -9574,7 +9567,7 @@ print_it_watchpoint (bpstat *bs) mention (b); tuple_emitter.emplace (uiout, "value"); uiout->text ("\nValue = "); - watchpoint_value_print (w->val.get (), &stb); + watchpoint_value_print (val.get (), &stb); uiout->field_stream ("value", stb); uiout->text ("\n"); result = PRINT_UNKNOWN; @@ -9604,7 +9597,7 @@ print_it_watchpoint (bpstat *bs) tuple_emitter.emplace (uiout, "value"); uiout->text ("\nValue = "); } - watchpoint_value_print (w->val.get (), &stb); + watchpoint_value_print (val.get (), &stb); uiout->field_stream ("new", stb); uiout->text ("\n"); result = PRINT_UNKNOWN; @@ -9616,17 +9609,15 @@ print_it_watchpoint (bpstat *bs) return result; } -/* Implement the "print_mention" breakpoint_ops method for hardware - watchpoints. */ +/* Implement the "print_mention" method for hardware watchpoints. */ -static void -print_mention_watchpoint (struct breakpoint *b) +void +watchpoint::print_mention () { - struct watchpoint *w = (struct watchpoint *) b; struct ui_out *uiout = current_uiout; const char *tuple_name; - switch (b->type) + switch (type) { case bp_watchpoint: uiout->text ("Watchpoint "); @@ -9650,20 +9641,17 @@ print_mention_watchpoint (struct breakpoint *b) } ui_out_emit_tuple tuple_emitter (uiout, tuple_name); - uiout->field_signed ("number", b->number); + uiout->field_signed ("number", number); uiout->text (": "); - uiout->field_string ("exp", w->exp_string.get ()); + uiout->field_string ("exp", exp_string.get ()); } -/* Implement the "print_recreate" breakpoint_ops method for - watchpoints. */ +/* Implement the "print_recreate" method for watchpoints. */ -static void -print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) +void +watchpoint::print_recreate (struct ui_file *fp) { - struct watchpoint *w = (struct watchpoint *) b; - - switch (b->type) + switch (type) { case bp_watchpoint: case bp_hardware_watchpoint: @@ -9680,77 +9668,78 @@ print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) _("Invalid watchpoint type.")); } - fprintf_unfiltered (fp, " %s", w->exp_string.get ()); - print_recreate_thread (b, fp); + fprintf_unfiltered (fp, " %s", exp_string.get ()); + print_recreate_thread (this, fp); } -/* Implement the "explains_signal" breakpoint_ops method for - watchpoints. */ +/* Implement the "explains_signal" method for watchpoints. */ -static int -explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) +int +watchpoint::explains_signal (enum gdb_signal sig) { /* A software watchpoint cannot cause a signal other than GDB_SIGNAL_TRAP. */ - if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) + if (type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) return 0; return 1; } -/* The breakpoint_ops structure to be used in hardware watchpoints. */ - -static struct breakpoint_ops watchpoint_breakpoint_ops; +struct masked_watchpoint : public watchpoint +{ + int insert_location (struct bp_location *) override; + int remove_location (struct bp_location *, + enum remove_bp_reason reason) override; + int resources_needed (const struct bp_location *) override; + int works_in_software_mode () const override; + enum print_stop_action print_it (struct bpstat *bs) override; + void print_one_detail (struct ui_out *) const override; + void print_mention () override; + void print_recreate (struct ui_file *fp) override; +}; -/* Implement the "insert" breakpoint_ops method for - masked hardware watchpoints. */ +/* Implement the "insert" method for masked hardware watchpoints. */ -static int -insert_masked_watchpoint (struct bp_location *bl) +int +masked_watchpoint::insert_location (struct bp_location *bl) { - struct watchpoint *w = (struct watchpoint *) bl->owner; - - return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, + return target_insert_mask_watchpoint (bl->address, hw_wp_mask, bl->watchpoint_type); } -/* Implement the "remove" breakpoint_ops method for - masked hardware watchpoints. */ +/* Implement the "remove" method for masked hardware watchpoints. */ -static int -remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) +int +masked_watchpoint::remove_location (struct bp_location *bl, + enum remove_bp_reason reason) { - struct watchpoint *w = (struct watchpoint *) bl->owner; - - return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, + return target_remove_mask_watchpoint (bl->address, hw_wp_mask, bl->watchpoint_type); } -/* Implement the "resources_needed" breakpoint_ops method for - masked hardware watchpoints. */ +/* Implement the "resources_needed" method for masked hardware + watchpoints. */ -static int -resources_needed_masked_watchpoint (const struct bp_location *bl) +int +masked_watchpoint::resources_needed (const struct bp_location *bl) { - struct watchpoint *w = (struct watchpoint *) bl->owner; - - return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); + return target_masked_watch_num_registers (bl->address, hw_wp_mask); } -/* Implement the "works_in_software_mode" breakpoint_ops method for - masked hardware watchpoints. */ +/* Implement the "works_in_software_mode" method for masked hardware + watchpoints. */ -static int -works_in_software_mode_masked_watchpoint (const struct breakpoint *b) +int +masked_watchpoint::works_in_software_mode () const { return 0; } -/* Implement the "print_it" breakpoint_ops method for - masked hardware watchpoints. */ +/* Implement the "print_it" method for masked hardware + watchpoints. */ -static enum print_stop_action -print_it_masked_watchpoint (bpstat *bs) +enum print_stop_action +masked_watchpoint::print_it (bpstat *bs) { struct breakpoint *b = bs->breakpoint_at; struct ui_out *uiout = current_uiout; @@ -9796,34 +9785,30 @@ address and value which triggered this watchpoint.\n")); return PRINT_UNKNOWN; } -/* Implement the "print_one_detail" breakpoint_ops method for - masked hardware watchpoints. */ +/* Implement the "print_one_detail" method for masked hardware + watchpoints. */ -static void -print_one_detail_masked_watchpoint (const struct breakpoint *b, - struct ui_out *uiout) +void +masked_watchpoint::print_one_detail (struct ui_out *uiout) const { - struct watchpoint *w = (struct watchpoint *) b; - /* Masked watchpoints have only one location. */ - gdb_assert (b->loc && b->loc->next == NULL); + gdb_assert (loc && loc->next == NULL); uiout->text ("\tmask "); - uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask); + uiout->field_core_addr ("mask", loc->gdbarch, hw_wp_mask); uiout->text ("\n"); } -/* Implement the "print_mention" breakpoint_ops method for - masked hardware watchpoints. */ +/* Implement the "print_mention" method for masked hardware + watchpoints. */ -static void -print_mention_masked_watchpoint (struct breakpoint *b) +void +masked_watchpoint::print_mention () { - struct watchpoint *w = (struct watchpoint *) b; struct ui_out *uiout = current_uiout; const char *tuple_name; - switch (b->type) + switch (type) { case bp_hardware_watchpoint: uiout->text ("Masked hardware watchpoint "); @@ -9843,20 +9828,18 @@ print_mention_masked_watchpoint (struct breakpoint *b) } ui_out_emit_tuple tuple_emitter (uiout, tuple_name); - uiout->field_signed ("number", b->number); + uiout->field_signed ("number", number); uiout->text (": "); - uiout->field_string ("exp", w->exp_string.get ()); + uiout->field_string ("exp", exp_string.get ()); } -/* Implement the "print_recreate" breakpoint_ops method for - masked hardware watchpoints. */ +/* Implement the "print_recreate" method for masked hardware + watchpoints. */ -static void -print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) +void +masked_watchpoint::print_recreate (struct ui_file *fp) { - struct watchpoint *w = (struct watchpoint *) b; - - switch (b->type) + switch (type) { case bp_hardware_watchpoint: fprintf_unfiltered (fp, "watch"); @@ -9872,21 +9855,17 @@ print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) _("Invalid hardware watchpoint type.")); } - fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string.get (), - phex (w->hw_wp_mask, sizeof (CORE_ADDR))); - print_recreate_thread (b, fp); + fprintf_unfiltered (fp, " %s mask 0x%s", exp_string.get (), + phex (hw_wp_mask, sizeof (CORE_ADDR))); + print_recreate_thread (this, fp); } -/* The breakpoint_ops structure to be used in masked hardware watchpoints. */ - -static struct breakpoint_ops masked_watchpoint_breakpoint_ops; - /* Tell whether the given watchpoint is a masked hardware watchpoint. */ static bool is_masked_watchpoint (const struct breakpoint *b) { - return b->ops == &masked_watchpoint_breakpoint_ops; + return dynamic_cast (b) != nullptr; } /* accessflag: hw_write: watch write, @@ -10142,14 +10121,14 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, else bp_type = bp_hardware_watchpoint; - std::unique_ptr w (new watchpoint ()); - + std::unique_ptr w; if (use_mask) - init_raw_breakpoint_without_location (w.get (), NULL, bp_type, - &masked_watchpoint_breakpoint_ops); + w.reset (new masked_watchpoint ()); else - init_raw_breakpoint_without_location (w.get (), NULL, bp_type, - &watchpoint_breakpoint_ops); + w.reset (new watchpoint ()); + init_raw_breakpoint_without_location (w.get (), nullptr, bp_type, + &vtable_breakpoint_ops); + w->thread = thread; w->task = task; w->disposition = disp_donttouch; @@ -14596,33 +14575,6 @@ initialize_breakpoint_ops (void) ops->create_sals_from_location = bkpt_probe_create_sals_from_location; ops->decode_location = bkpt_probe_decode_location; - /* Watchpoints. */ - ops = &watchpoint_breakpoint_ops; - *ops = base_breakpoint_ops; - ops->re_set = re_set_watchpoint; - ops->insert_location = insert_watchpoint; - ops->remove_location = remove_watchpoint; - ops->breakpoint_hit = breakpoint_hit_watchpoint; - ops->check_status = check_status_watchpoint; - ops->resources_needed = resources_needed_watchpoint; - ops->works_in_software_mode = works_in_software_mode_watchpoint; - ops->print_it = print_it_watchpoint; - ops->print_mention = print_mention_watchpoint; - ops->print_recreate = print_recreate_watchpoint; - ops->explains_signal = explains_signal_watchpoint; - - /* Masked watchpoints. */ - ops = &masked_watchpoint_breakpoint_ops; - *ops = watchpoint_breakpoint_ops; - ops->insert_location = insert_masked_watchpoint; - ops->remove_location = remove_masked_watchpoint; - ops->resources_needed = resources_needed_masked_watchpoint; - ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; - ops->print_it = print_it_masked_watchpoint; - ops->print_one_detail = print_one_detail_masked_watchpoint; - ops->print_mention = print_mention_masked_watchpoint; - ops->print_recreate = print_recreate_masked_watchpoint; - /* Tracepoints. */ ops = &tracepoint_breakpoint_ops; *ops = base_breakpoint_ops; diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 83c37251e0d..3546a114d9f 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -944,6 +944,22 @@ struct breakpoint struct watchpoint : public breakpoint { + void re_set () override; + int insert_location (struct bp_location *) override; + int remove_location (struct bp_location *, + enum remove_bp_reason reason) override; + int breakpoint_hit (const struct bp_location *bl, + const address_space *aspace, + CORE_ADDR bp_addr, + const target_waitstatus &ws) override; + void check_status (struct bpstat *bs) override; + int resources_needed (const struct bp_location *) override; + int works_in_software_mode () const override; + enum print_stop_action print_it (struct bpstat *bs) override; + void print_mention () override; + void print_recreate (struct ui_file *fp) override; + int explains_signal (enum gdb_signal) override; + /* String form of exp to use for displaying to the user (malloc'd), or NULL if none. */ gdb::unique_xmalloc_ptr exp_string; -- 2.31.1