From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 16668385842B; Fri, 29 Apr 2022 22:22:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 16668385842B Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Convert break-catch-syscall to vtable ops X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: c3ee64d0d812c88579d3a81de0cf5da0dcb7828e X-Git-Newrev: 3aca48d3b44720aaa23fe969f8b460aad2034aea Message-Id: <20220429222230.16668385842B@sourceware.org> Date: Fri, 29 Apr 2022 22:22:30 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Apr 2022 22:22:30 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D3aca48d3b447= 20aaa23fe969f8b460aad2034aea commit 3aca48d3b44720aaa23fe969f8b460aad2034aea Author: Tom Tromey Date: Fri Jan 14 18:48:32 2022 -0700 Convert break-catch-syscall to vtable ops =20 This converts break-catch-syscall.c to use vtable_breakpoint_ops. Diff: --- gdb/break-catch-syscall.c | 157 +++++++++++++++++++-----------------------= ---- 1 file changed, 64 insertions(+), 93 deletions(-) diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c index 2b09e64ba60..2566a20f3fb 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" =20 -/* 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. */ =20 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; } =20 -/* Implement the "insert" breakpoint_ops method for syscall - catchpoints. */ +/* Implement the "insert" method for syscall catchpoints. */ =20 -static int -insert_catch_syscall (struct bp_location *bl) +int +syscall_catchpoint::insert_location (struct bp_location *bl) { - struct syscall_catchpoint *c =3D (struct syscall_catchpoint *) bl->owner; struct inferior *inf =3D current_inferior (); struct catch_syscall_inferior_data *inf_data =3D get_catch_syscall_inferior_data (inf); =20 ++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 >=3D 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); } =20 -/* Implement the "remove" breakpoint_ops method for syscall - catchpoints. */ +/* Implement the "remove" method for syscall catchpoints. */ =20 -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 =3D (struct syscall_catchpoint *) bl->owner; struct inferior *inf =3D current_inferior (); struct catch_syscall_inferior_data *inf_data =3D get_catch_syscall_inferior_data (inf); =20 --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 >=3D inf_data->syscalls_counts.size ()) /* Shouldn't happen. */ @@ -137,20 +145,18 @@ remove_catch_syscall (struct bp_location *bl, enum re= move_bp_reason reason) inf_data->syscalls_counts); } =20 -/* Implement the "breakpoint_hit" breakpoint_ops method for syscall - catchpoints. */ +/* Implement the "breakpoint_hit" method for syscall catchpoints. */ =20 -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 =3D 0; - const struct syscall_catchpoint *c - =3D (const struct syscall_catchpoint *) bl->owner; =20 if (ws.kind () !=3D TARGET_WAITKIND_SYSCALL_ENTRY && ws.kind () !=3D TARGET_WAITKIND_SYSCALL_RETURN) @@ -159,9 +165,9 @@ breakpoint_hit_catch_syscall (const struct bp_location = *bl, syscall_number =3D ws.syscall_number (); =20 /* 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 =3D=3D iter) return 1; =20 @@ -171,11 +177,10 @@ breakpoint_hit_catch_syscall (const struct bp_locatio= n *bl, return 1; } =20 -/* Implement the "print_it" breakpoint_ops method for syscall - catchpoints. */ +/* Implement the "print_it" method for syscall catchpoints. */ =20 -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 =3D current_uiout; struct breakpoint *b =3D bs->breakpoint_at; @@ -223,17 +228,14 @@ print_it_catch_syscall (bpstat *bs) return PRINT_SRC_AND_LOC; } =20 -/* Implement the "print_one" breakpoint_ops method for syscall - catchpoints. */ +/* Implement the "print_one" method for syscall catchpoints. */ =20 -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 =3D (struct syscall_catchpoint *) b; struct value_print_options opts; struct ui_out *uiout =3D current_uiout; - struct gdbarch *gdbarch =3D b->loc->gdbarch; + struct gdbarch *gdbarch =3D loc->gdbarch; =20 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); =20 - if (c->syscalls_to_be_caught.size () > 1) + if (syscalls_to_be_caught.size () > 1) uiout->text ("syscalls \""); else uiout->text ("syscall \""); =20 - if (!c->syscalls_to_be_caught.empty ()) + if (!syscalls_to_be_caught.empty ()) { std::string text; =20 bool first =3D 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; } =20 -/* Implement the "print_mention" breakpoint_ops method for syscall - catchpoints. */ +/* Implement the "print_mention" method for syscall catchpoints. */ =20 -static void -print_mention_catch_syscall (struct breakpoint *b) +void +syscall_catchpoint::print_mention () { - struct syscall_catchpoint *c =3D (struct syscall_catchpoint *) b; - struct gdbarch *gdbarch =3D b->loc->gdbarch; + struct gdbarch *gdbarch =3D loc->gdbarch; =20 - if (!c->syscalls_to_be_caught.empty ()) + if (!syscalls_to_be_caught.empty ()) { - if (c->syscalls_to_be_caught.size () > 1) - gdb_printf (_("Catchpoint %d (syscalls"), b->number); + if (syscalls_to_be_caught.size () > 1) + gdb_printf (_("Catchpoint %d (syscalls"), number); else - gdb_printf (_("Catchpoint %d (syscall"), b->number); + gdb_printf (_("Catchpoint %d (syscall"), number); =20 - 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); @@ -308,22 +308,19 @@ print_mention_catch_syscall (struct breakpoint *b) gdb_printf (")"); } else - gdb_printf (_("Catchpoint %d (any syscall)"), - b->number); + gdb_printf (_("Catchpoint %d (any syscall)"), number); } =20 -/* Implement the "print_recreate" breakpoint_ops method for syscall - catchpoints. */ +/* Implement the "print_recreate" method for syscall catchpoints. */ =20 -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 =3D (struct syscall_catchpoint *) b; - struct gdbarch *gdbarch =3D b->loc->gdbarch; + struct gdbarch *gdbarch =3D loc->gdbarch; =20 gdb_printf (fp, "catch syscall"); =20 - for (int iter : c->syscalls_to_be_caught) + for (int iter : syscalls_to_be_caught) { struct syscall s; =20 @@ -334,29 +331,25 @@ print_recreate_catch_syscall (struct breakpoint *b, s= truct ui_file *fp) gdb_printf (fp, " %d", s.number); } =20 - print_recreate_thread (b, fp); + print_recreate_thread (this, fp); } =20 -/* 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. */ =20 static int syscall_catchpoint_p (struct breakpoint *b) { - return (b->ops =3D=3D &catch_syscall_breakpoint_ops); + return dynamic_cast (b) !=3D nullptr; } =20 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 =3D get_current_arch (); =20 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 =3D std::move (filter); =20 install_breakpoint (0, std::move (c), 1); @@ -457,8 +450,7 @@ this architecture yet.")); if (arg !=3D NULL) filter =3D catch_syscall_split_args (arg); =20 - create_syscall_event_catchpoint (tempflag, std::move (filter), - &catch_syscall_breakpoint_ops); + create_syscall_event_catchpoint (tempflag, std::move (filter)); } =20 =20 @@ -579,31 +571,10 @@ clear_syscall_counts (struct inferior *inf) inf_data->syscalls_counts.clear (); } =20 -static void -initialize_syscall_catchpoint_ops (void) -{ - struct breakpoint_ops *ops; - - initialize_breakpoint_ops (); - - /* Syscall catchpoints. */ - ops =3D &catch_syscall_breakpoint_ops; - *ops =3D base_breakpoint_ops; - ops->insert_location =3D insert_catch_syscall; - ops->remove_location =3D remove_catch_syscall; - ops->breakpoint_hit =3D breakpoint_hit_catch_syscall; - ops->print_it =3D print_it_catch_syscall; - ops->print_one =3D print_one_catch_syscall; - ops->print_mention =3D print_mention_catch_syscall; - ops->print_recreate =3D 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");