From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from progateway7-pub.mail.pro1.eigbox.com (gproxy5-pub.mail.unifiedlayer.com [67.222.38.55]) by sourceware.org (Postfix) with ESMTPS id ED04B3857C4C for ; Tue, 18 Jan 2022 19:40:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ED04B3857C4C 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 progateway7.mail.pro1.eigbox.com (Postfix) with ESMTP id 645A010047573 for ; Tue, 18 Jan 2022 19:40:13 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id 9uKynA7dHnAlU9uKzn1WOp; Tue, 18 Jan 2022 19:40:13 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=QIOt+iHL c=1 sm=1 tr=0 ts=61e7179d 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=HVea7nDDR6QnRQqMBCAA: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=44MUDYZFTLQooN/S7FQcbeDbsBbLmCxGYFJCiDGcNAU=; b=vdcCTLQr4bsrHUaZbFJ/TJVZfw 2kQicQ+/Pjdn8Uca5i3uD0578IygkkOt7fBAF7iQRsNEzVnd3PG9oy20rOzpfy9+XyQgQImAjWN/u 7rzuW8CSsW4Q5FImtWMItjgp3; 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 1n9uKy-0015NP-Dp; Tue, 18 Jan 2022 12:40:12 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 08/36] Convert break-catch-syscall to vtable ops Date: Tue, 18 Jan 2022 12:39:39 -0700 Message-Id: <20220118194007.2853108-9-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: 1n9uKy-0015NP-Dp 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: 9 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:16 -0000 This converts break-catch-syscall.c to use vtable_breakpoint_ops. --- gdb/break-catch-syscall.c | 156 ++++++++++++++++---------------------- 1 file changed, 64 insertions(+), 92 deletions(-) diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c index 7c797898940..1af4f6d074b 100644 --- a/gdb/break-catch-syscall.c +++ b/gdb/break-catch-syscall.c @@ -32,12 +32,23 @@ #include "cli/cli-style.h" #include "cli/cli-decode.h" -/* An instance of this type is used to represent a syscall catchpoint. - A breakpoint is really of this type iff its ops pointer points to - CATCH_SYSCALL_BREAKPOINT_OPS. */ +/* An instance of this type is used to represent a syscall + catchpoint. */ struct syscall_catchpoint : public breakpoint { + 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; + enum print_stop_action print_it (struct bpstat *bs) override; + bool print_one (struct bp_location **) override; + void print_mention () override; + void print_recreate (struct ui_file *fp) override; + /* Syscall numbers used for the 'catch syscall' feature. If no syscall has been specified for filtering, it is empty. Otherwise, it holds a list of all syscalls to be caught. */ @@ -76,23 +87,21 @@ get_catch_syscall_inferior_data (struct inferior *inf) return inf_data; } -/* Implement the "insert" breakpoint_ops method for syscall - catchpoints. */ +/* Implement the "insert" method for syscall catchpoints. */ -static int -insert_catch_syscall (struct bp_location *bl) +int +syscall_catchpoint::insert_location (struct bp_location *bl) { - struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; struct inferior *inf = current_inferior (); struct catch_syscall_inferior_data *inf_data = get_catch_syscall_inferior_data (inf); ++inf_data->total_syscalls_count; - if (c->syscalls_to_be_caught.empty ()) + if (syscalls_to_be_caught.empty ()) ++inf_data->any_syscall_count; else { - for (int iter : c->syscalls_to_be_caught) + for (int iter : syscalls_to_be_caught) { if (iter >= inf_data->syscalls_counts.size ()) inf_data->syscalls_counts.resize (iter + 1); @@ -106,23 +115,22 @@ insert_catch_syscall (struct bp_location *bl) inf_data->syscalls_counts); } -/* Implement the "remove" breakpoint_ops method for syscall - catchpoints. */ +/* Implement the "remove" method for syscall catchpoints. */ -static int -remove_catch_syscall (struct bp_location *bl, enum remove_bp_reason reason) +int +syscall_catchpoint::remove_location (struct bp_location *bl, + enum remove_bp_reason reason) { - struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; struct inferior *inf = current_inferior (); struct catch_syscall_inferior_data *inf_data = get_catch_syscall_inferior_data (inf); --inf_data->total_syscalls_count; - if (c->syscalls_to_be_caught.empty ()) + if (syscalls_to_be_caught.empty ()) --inf_data->any_syscall_count; else { - for (int iter : c->syscalls_to_be_caught) + for (int iter : syscalls_to_be_caught) { if (iter >= inf_data->syscalls_counts.size ()) /* Shouldn't happen. */ @@ -137,20 +145,18 @@ remove_catch_syscall (struct bp_location *bl, enum remove_bp_reason reason) inf_data->syscalls_counts); } -/* Implement the "breakpoint_hit" breakpoint_ops method for syscall - catchpoints. */ +/* Implement the "breakpoint_hit" method for syscall catchpoints. */ -static int -breakpoint_hit_catch_syscall (const struct bp_location *bl, - const address_space *aspace, CORE_ADDR bp_addr, - const target_waitstatus &ws) +int +syscall_catchpoint::breakpoint_hit (const struct bp_location *bl, + const address_space *aspace, + CORE_ADDR bp_addr, + const target_waitstatus &ws) { /* We must check if we are catching specific syscalls in this breakpoint. If we are, then we must guarantee that the called syscall is the same syscall we are catching. */ int syscall_number = 0; - const struct syscall_catchpoint *c - = (const struct syscall_catchpoint *) bl->owner; if (ws.kind () != TARGET_WAITKIND_SYSCALL_ENTRY && ws.kind () != TARGET_WAITKIND_SYSCALL_RETURN) @@ -159,9 +165,9 @@ breakpoint_hit_catch_syscall (const struct bp_location *bl, syscall_number = ws.syscall_number (); /* Now, checking if the syscall is the same. */ - if (!c->syscalls_to_be_caught.empty ()) + if (!syscalls_to_be_caught.empty ()) { - for (int iter : c->syscalls_to_be_caught) + for (int iter : syscalls_to_be_caught) if (syscall_number == iter) return 1; @@ -171,11 +177,10 @@ breakpoint_hit_catch_syscall (const struct bp_location *bl, return 1; } -/* Implement the "print_it" breakpoint_ops method for syscall - catchpoints. */ +/* Implement the "print_it" method for syscall catchpoints. */ -static enum print_stop_action -print_it_catch_syscall (bpstat *bs) +enum print_stop_action +syscall_catchpoint::print_it (bpstat *bs) { struct ui_out *uiout = current_uiout; struct breakpoint *b = bs->breakpoint_at; @@ -223,17 +228,14 @@ print_it_catch_syscall (bpstat *bs) return PRINT_SRC_AND_LOC; } -/* Implement the "print_one" breakpoint_ops method for syscall - catchpoints. */ +/* Implement the "print_one" method for syscall catchpoints. */ -static bool -print_one_catch_syscall (struct breakpoint *b, - struct bp_location **last_loc) +bool +syscall_catchpoint::print_one (struct bp_location **last_loc) { - struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; struct value_print_options opts; struct ui_out *uiout = current_uiout; - struct gdbarch *gdbarch = b->loc->gdbarch; + struct gdbarch *gdbarch = loc->gdbarch; get_user_print_options (&opts); /* Field 4, the address, is omitted (which makes the columns not @@ -243,17 +245,17 @@ print_one_catch_syscall (struct breakpoint *b, uiout->field_skip ("addr"); annotate_field (5); - if (c->syscalls_to_be_caught.size () > 1) + if (syscalls_to_be_caught.size () > 1) uiout->text ("syscalls \""); else uiout->text ("syscall \""); - if (!c->syscalls_to_be_caught.empty ()) + if (!syscalls_to_be_caught.empty ()) { std::string text; bool first = true; - for (int iter : c->syscalls_to_be_caught) + for (int iter : syscalls_to_be_caught) { struct syscall s; get_syscall_by_number (gdbarch, iter, &s); @@ -279,23 +281,21 @@ print_one_catch_syscall (struct breakpoint *b, return true; } -/* Implement the "print_mention" breakpoint_ops method for syscall - catchpoints. */ +/* Implement the "print_mention" method for syscall catchpoints. */ -static void -print_mention_catch_syscall (struct breakpoint *b) +void +syscall_catchpoint::print_mention () { - struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; - struct gdbarch *gdbarch = b->loc->gdbarch; + struct gdbarch *gdbarch = loc->gdbarch; - if (!c->syscalls_to_be_caught.empty ()) + if (!syscalls_to_be_caught.empty ()) { - if (c->syscalls_to_be_caught.size () > 1) - printf_filtered (_("Catchpoint %d (syscalls"), b->number); + if (syscalls_to_be_caught.size () > 1) + printf_filtered (_("Catchpoint %d (syscalls"), number); else - printf_filtered (_("Catchpoint %d (syscall"), b->number); + printf_filtered (_("Catchpoint %d (syscall"), number); - for (int iter : c->syscalls_to_be_caught) + for (int iter : syscalls_to_be_caught) { struct syscall s; get_syscall_by_number (gdbarch, iter, &s); @@ -309,21 +309,19 @@ print_mention_catch_syscall (struct breakpoint *b) } else printf_filtered (_("Catchpoint %d (any syscall)"), - b->number); + number); } -/* Implement the "print_recreate" breakpoint_ops method for syscall - catchpoints. */ +/* Implement the "print_recreate" method for syscall catchpoints. */ -static void -print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) +void +syscall_catchpoint::print_recreate (struct ui_file *fp) { - struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; - struct gdbarch *gdbarch = b->loc->gdbarch; + struct gdbarch *gdbarch = loc->gdbarch; fprintf_unfiltered (fp, "catch syscall"); - for (int iter : c->syscalls_to_be_caught) + for (int iter : syscalls_to_be_caught) { struct syscall s; @@ -334,29 +332,25 @@ print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) fprintf_unfiltered (fp, " %d", s.number); } - print_recreate_thread (b, fp); + print_recreate_thread (this, fp); } -/* The breakpoint_ops structure to be used in syscall catchpoints. */ - -static struct breakpoint_ops catch_syscall_breakpoint_ops; - /* Returns non-zero if 'b' is a syscall catchpoint. */ static int syscall_catchpoint_p (struct breakpoint *b) { - return (b->ops == &catch_syscall_breakpoint_ops); + return dynamic_cast (b) != nullptr; } static void -create_syscall_event_catchpoint (int tempflag, std::vector &&filter, - const struct breakpoint_ops *ops) +create_syscall_event_catchpoint (int tempflag, std::vector &&filter) { struct gdbarch *gdbarch = get_current_arch (); std::unique_ptr c (new syscall_catchpoint ()); - init_catchpoint (c.get (), gdbarch, tempflag, NULL, ops); + init_catchpoint (c.get (), gdbarch, tempflag, nullptr, + &vtable_breakpoint_ops); c->syscalls_to_be_caught = std::move (filter); install_breakpoint (0, std::move (c), 1); @@ -457,8 +451,7 @@ this architecture yet.")); if (arg != NULL) filter = catch_syscall_split_args (arg); - create_syscall_event_catchpoint (tempflag, std::move (filter), - &catch_syscall_breakpoint_ops); + create_syscall_event_catchpoint (tempflag, std::move (filter)); } @@ -579,31 +572,10 @@ clear_syscall_counts (struct inferior *inf) inf_data->syscalls_counts.clear (); } -static void -initialize_syscall_catchpoint_ops (void) -{ - struct breakpoint_ops *ops; - - initialize_breakpoint_ops (); - - /* Syscall catchpoints. */ - ops = &catch_syscall_breakpoint_ops; - *ops = base_breakpoint_ops; - ops->insert_location = insert_catch_syscall; - ops->remove_location = remove_catch_syscall; - ops->breakpoint_hit = breakpoint_hit_catch_syscall; - ops->print_it = print_it_catch_syscall; - ops->print_one = print_one_catch_syscall; - ops->print_mention = print_mention_catch_syscall; - ops->print_recreate = print_recreate_catch_syscall; -} - void _initialize_break_catch_syscall (); void _initialize_break_catch_syscall () { - initialize_syscall_catchpoint_ops (); - gdb::observers::inferior_exit.attach (clear_syscall_counts, "break-catch-syscall"); -- 2.31.1