From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gproxy3-pub.mail.unifiedlayer.com (gproxy3-pub.mail.unifiedlayer.com [69.89.30.42]) by sourceware.org (Postfix) with ESMTPS id 384673857C46 for ; Tue, 18 Jan 2022 19:40:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 384673857C46 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 progateway5.mail.pro1.eigbox.com (Postfix) with ESMTP id 9854E10047820 for ; Tue, 18 Jan 2022 19:40:12 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id 9uKynA7cznAlU9uKyn1WOV; Tue, 18 Jan 2022 19:40:12 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=QIOt+iHL c=1 sm=1 tr=0 ts=61e7179c 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=_VA0NcPm1zJOIHLBLzkA: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=c23EIzmLVfD+Ncr7G2+Qu681+Qf1R4F6eulGUvFGDd4=; b=pp7UnBImAxIE6IQ12h965v6rOP JdOPKDj8oO6zEo03eLu6iLYVjajpdTxyWjpFtnMkw5ZnTnUTVNhoO9+XNC8WbCib7h/RiToPn9hm2 EVDCqMsfLeFIOZ7ID6SBDmnyE; Received: from 75-166-134-30.hlrn.qwest.net ([75.166.134.30]:40582 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 1n9uKx-0015NP-QG; Tue, 18 Jan 2022 12:40:11 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 06/36] Add a vtable-based breakpoint ops Date: Tue, 18 Jan 2022 12:39:37 -0700 Message-Id: <20220118194007.2853108-7-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: 1n9uKx-0015NP-QG X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-134-30.hlrn.qwest.net (prentzel.Home) [75.166.134.30]:40582 X-Source-Auth: tom+tromey.com X-Email-Count: 7 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, 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:15 -0000 This adds methods to struct breakpoint. Each method has a similar signature to a corresponding function in breakpoint_ops, with the exceptions of create_sals_from_location and create_breakpoints_sal, which can't be virtual methods on breakpoint -- they are only used during the construction of breakpoints. Then, this adds a new vtable_breakpoint_ops structure and populates it with functions that simply forward a call from breakpoint_ops to the corresponding virtual method. These are all done with lambdas, because they are just a stepping stone -- by the end of the series, this structure will be deleted. --- gdb/breakpoint.c | 110 +++++++++++++++++++++++++++++++++++++++++++++ gdb/breakpoint.h | 113 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 223 insertions(+) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 5b3e91c1841..069d3a9049a 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -11504,6 +11504,12 @@ base_breakpoint_allocate_location (struct breakpoint *self) return new bp_location (self); } +struct bp_location * +breakpoint::allocate_location () +{ + return new bp_location (this); +} + static void base_breakpoint_re_set (struct breakpoint *b) { @@ -11519,6 +11525,12 @@ base_breakpoint_insert_location (struct bp_location *bl) internal_error_pure_virtual_called (); } +int +breakpoint::insert_location (struct bp_location *bl) +{ + internal_error_pure_virtual_called (); +} + static int base_breakpoint_remove_location (struct bp_location *bl, enum remove_bp_reason reason) @@ -11526,6 +11538,13 @@ base_breakpoint_remove_location (struct bp_location *bl, internal_error_pure_virtual_called (); } +int +breakpoint::remove_location (struct bp_location *bl, + enum remove_bp_reason reason) +{ + internal_error_pure_virtual_called (); +} + static int base_breakpoint_breakpoint_hit (const struct bp_location *bl, const address_space *aspace, @@ -11535,6 +11554,15 @@ base_breakpoint_breakpoint_hit (const struct bp_location *bl, internal_error_pure_virtual_called (); } +int +breakpoint::breakpoint_hit (const struct bp_location *bl, + const address_space *aspace, + CORE_ADDR bp_addr, + const target_waitstatus &ws) +{ + internal_error_pure_virtual_called (); +} + static void base_breakpoint_check_status (bpstat *bs) { @@ -11550,6 +11578,12 @@ base_breakpoint_works_in_software_mode (const struct breakpoint *b) internal_error_pure_virtual_called (); } +int +breakpoint::works_in_software_mode () const +{ + internal_error_pure_virtual_called (); +} + /* A "resources_needed" breakpoint_ops method that just internal errors. */ @@ -11559,12 +11593,24 @@ base_breakpoint_resources_needed (const struct bp_location *bl) internal_error_pure_virtual_called (); } +int +breakpoint::resources_needed (const struct bp_location *bl) +{ + internal_error_pure_virtual_called (); +} + static enum print_stop_action base_breakpoint_print_it (bpstat *bs) { internal_error_pure_virtual_called (); } +enum print_stop_action +breakpoint::print_it (bpstat *bs) +{ + internal_error_pure_virtual_called (); +} + static bool base_breakpoint_print_one (struct breakpoint *, struct bp_location **) { @@ -11584,12 +11630,24 @@ base_breakpoint_print_mention (struct breakpoint *b) internal_error_pure_virtual_called (); } +void +breakpoint::print_mention () +{ + internal_error_pure_virtual_called (); +} + static void base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) { internal_error_pure_virtual_called (); } +void +breakpoint::print_recreate (struct ui_file *fp) +{ + internal_error_pure_virtual_called (); +} + static void base_breakpoint_create_sals_from_location (struct event_location *location, @@ -11623,6 +11681,13 @@ base_breakpoint_decode_location (struct breakpoint *b, internal_error_pure_virtual_called (); } +std::vector +breakpoint::decode_location (struct event_location *location, + struct program_space *search_pspace) +{ + internal_error_pure_virtual_called (); +} + /* The default 'explains_signal' method. */ static int @@ -11661,6 +11726,51 @@ struct breakpoint_ops base_breakpoint_ops = base_breakpoint_after_condition_true, }; +struct breakpoint_ops vtable_breakpoint_ops = +{ + [] (struct breakpoint *b) { return b->allocate_location (); }, + [] (struct breakpoint *b) { b->re_set (); }, + [] (struct bp_location *l) + { + return l->owner->insert_location (l); + }, + [] (struct bp_location *l, enum remove_bp_reason reason) + { + return l->owner->remove_location (l, reason); + }, + [] (const struct bp_location *bl, + const address_space *aspace, + CORE_ADDR bp_addr, + const target_waitstatus &ws) + { + return bl->owner->breakpoint_hit (bl, aspace, bp_addr, ws); + }, + [] (struct bpstat *bs) { bs->breakpoint_at->check_status (bs); }, + [] (const struct bp_location *bl) + { return bl->owner->resources_needed (bl); }, + [] (const struct breakpoint *b) + { return b->works_in_software_mode (); }, + [] (struct bpstat *bs) + { return bs->breakpoint_at->print_it (bs); }, + [] (struct breakpoint *b, struct bp_location **bl) + { return b->print_one (bl); }, + [] (const struct breakpoint *b, struct ui_out *out) + { b->print_one_detail (out); }, + [] (struct breakpoint *b) { b->print_mention (); }, + [] (struct breakpoint *b, struct ui_file *fp) + { b->print_recreate (fp); }, + create_sals_from_location_default, + create_breakpoints_sal_default, + [] (struct breakpoint *b, + struct event_location *location, + struct program_space *search_pspace) + { return b->decode_location (location, search_pspace); }, + [] (struct breakpoint *b, enum gdb_signal s) + { return b->explains_signal (s); }, + [] (struct bpstat *bs) + { bs->breakpoint_at->after_condition_true (bs); } +}; + /* Default breakpoint_ops methods. */ static void diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 99f81b28c30..83c37251e0d 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -723,6 +723,118 @@ struct breakpoint { virtual ~breakpoint () = default; + /* Allocate a location for this breakpoint. */ + virtual struct bp_location *allocate_location (); + + /* Reevaluate a breakpoint. This is necessary after symbols change + (e.g., an executable or DSO was loaded, or the inferior just + started). */ + virtual void re_set () + { + /* Nothing to re-set. */ + } + + /* Insert the breakpoint or watchpoint or activate the catchpoint. + Return 0 for success, 1 if the breakpoint, watchpoint or + catchpoint type is not supported, -1 for failure. */ + virtual int insert_location (struct bp_location *); + + /* Remove the breakpoint/catchpoint that was previously inserted + with the "insert" method above. Return 0 for success, 1 if the + breakpoint, watchpoint or catchpoint type is not supported, + -1 for failure. */ + virtual int remove_location (struct bp_location *, + enum remove_bp_reason reason); + + /* Return true if it the target has stopped due to hitting + breakpoint location BL. This function does not check if we + should stop, only if BL explains the stop. ASPACE is the address + space in which the event occurred, BP_ADDR is the address at + which the inferior stopped, and WS is the target_waitstatus + describing the event. */ + virtual int breakpoint_hit (const struct bp_location *bl, + const address_space *aspace, + CORE_ADDR bp_addr, + const target_waitstatus &ws); + + /* Check internal conditions of the breakpoint referred to by BS. + If we should not stop for this breakpoint, set BS->stop to 0. */ + virtual void check_status (struct bpstat *bs) + { + /* Always stop. */ + } + + /* Tell how many hardware resources (debug registers) are needed + for this breakpoint. If this function is not provided, then + the breakpoint or watchpoint needs one debug register. */ + virtual int resources_needed (const struct bp_location *); + + /* Tell whether we can downgrade from a hardware watchpoint to a software + one. If not, the user will not be able to enable the watchpoint when + there are not enough hardware resources available. */ + virtual int works_in_software_mode () const; + + /* The normal print routine for this breakpoint, called when we + hit it. */ + virtual enum print_stop_action print_it (struct bpstat *bs); + + /* Display information about this breakpoint, for "info + breakpoints". Returns false if this method should use the + default behavior. */ + virtual bool print_one (struct bp_location **) + { + return false; + } + + /* Display extra information about this breakpoint, below the normal + breakpoint description in "info breakpoints". + + In the example below, the "address range" line was printed + by print_one_detail_ranged_breakpoint. + + (gdb) info breakpoints + Num Type Disp Enb Address What + 2 hw breakpoint keep y in main at test-watch.c:70 + address range: [0x10000458, 0x100004c7] + + */ + virtual void print_one_detail (struct ui_out *) const + { + /* Nothing. */ + } + + /* Display information about this breakpoint after setting it + (roughly speaking; this is called from "mention"). */ + virtual void print_mention (); + + /* Print to FP the CLI command that recreates this breakpoint. */ + virtual void print_recreate (struct ui_file *fp); + + /* Given the location (second parameter), this method decodes it and + returns the SAL locations related to it. For ordinary + breakpoints, it calls `decode_line_full'. If SEARCH_PSPACE is + not NULL, symbol search is restricted to just that program space. + + This function is called inside `location_to_sals'. */ + virtual std::vector decode_location + (struct event_location *location, + struct program_space *search_pspace); + + /* Return true if this breakpoint explains a signal. See + bpstat_explains_signal. */ + virtual int explains_signal (enum gdb_signal) + { + return 1; + } + + /* Called after evaluating the breakpoint's condition, + and only if it evaluated true. */ + virtual void after_condition_true (struct bpstat *bs) + { + /* Nothing to do. */ + } + + /* Return a range of this breakpoint's locations. */ bp_location_range locations (); @@ -1317,6 +1429,7 @@ 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 dprintf_breakpoint_ops; +extern struct breakpoint_ops vtable_breakpoint_ops; extern void initialize_breakpoint_ops (void); -- 2.31.1