From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id A287E3858405; Fri, 29 Apr 2022 22:23:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A287E3858405 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-throw to vtable ops X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 2b5ab5b8514550782e1ee3107f4b3e0984a5a6a9 X-Git-Newrev: 5bd3caf1b2f95139764916e2a6e07a95453b717f Message-Id: <20220429222310.A287E3858405@sourceware.org> Date: Fri, 29 Apr 2022 22:23:10 +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:23:10 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D5bd3caf1b2f9= 5139764916e2a6e07a95453b717f commit 5bd3caf1b2f95139764916e2a6e07a95453b717f Author: Tom Tromey Date: Fri Jan 14 18:52:13 2022 -0700 Convert break-catch-throw to vtable ops =20 This converts break-catch-throw.c to use vtable_breakpoint_ops. Diff: --- gdb/break-catch-throw.c | 138 +++++++++++++++++++-------------------------= ---- 1 file changed, 53 insertions(+), 85 deletions(-) diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c index 62a404f33ac..f9bcc8d0b74 100644 --- a/gdb/break-catch-throw.c +++ b/gdb/break-catch-throw.c @@ -63,12 +63,26 @@ static const struct exception_names exception_functions= [] =3D { "-probe-stap libstdcxx:catch", "__cxa_begin_catch" } }; =20 -static struct breakpoint_ops gnu_v3_exception_catchpoint_ops; - /* The type of an exception catchpoint. */ =20 struct exception_catchpoint : public base_breakpoint { + void re_set () 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; + void print_one_detail (struct ui_out *) const override; + void check_status (struct bpstat *bs) override; + struct bp_location *allocate_location () override; + + /* FIXME this is temporary - until ordinary breakpoints have been + converted. */ + int resources_needed (const struct bp_location *) override + { + return 1; + } + /* The kind of exception catchpoint. */ =20 enum exception_event_kind kind; @@ -89,7 +103,7 @@ struct exception_catchpoint : public base_breakpoint bool is_exception_catchpoint (breakpoint *bp) { - return bp->ops =3D=3D &gnu_v3_exception_catchpoint_ops; + return dynamic_cast (bp) !=3D nullptr; } =20 =0C @@ -130,27 +144,16 @@ fetch_probe_arguments (struct value **arg0, struct va= lue **arg1) =20 =0C =20 -/* A helper function that returns a value indicating the kind of the - exception catchpoint B. */ - -static enum exception_event_kind -classify_exception_breakpoint (struct breakpoint *b) -{ - struct exception_catchpoint *cp =3D (struct exception_catchpoint *) b; - - return cp->kind; -} - /* Implement the 'check_status' method. */ =20 -static void -check_status_exception_catchpoint (struct bpstat *bs) +void +exception_catchpoint::check_status (struct bpstat *bs) { struct exception_catchpoint *self =3D (struct exception_catchpoint *) bs->breakpoint_at; std::string type_name; =20 - bkpt_breakpoint_ops.check_status (bs); + this->breakpoint::check_status (bs); if (bs->stop =3D=3D 0) return; =20 @@ -185,11 +188,10 @@ check_status_exception_catchpoint (struct bpstat *bs) =20 /* Implement the 're_set' method. */ =20 -static void -re_set_exception_catchpoint (struct breakpoint *self) +void +exception_catchpoint::re_set () { std::vector sals; - enum exception_event_kind kind =3D classify_exception_breakpoint (self); struct program_space *filter_pspace =3D current_program_space; =20 /* We first try to use the probe interface. */ @@ -211,8 +213,7 @@ re_set_exception_catchpoint (struct breakpoint *self) explicit_loc.function_name =3D ASTRDUP (exception_functions[kind].function); event_location_up location =3D new_explicit_location (&explicit_loc); - sals =3D self->ops->decode_location (self, location.get (), - filter_pspace); + sals =3D this->decode_location (location.get (), filter_pspace); } catch (const gdb_exception_error &ex) { @@ -223,24 +224,22 @@ re_set_exception_catchpoint (struct breakpoint *self) } } =20 - update_breakpoint_locations (self, filter_pspace, sals, {}); + update_breakpoint_locations (this, filter_pspace, sals, {}); } =20 -static enum print_stop_action -print_it_exception_catchpoint (bpstat *bs) +enum print_stop_action +exception_catchpoint::print_it (bpstat *bs) { struct ui_out *uiout =3D current_uiout; - struct breakpoint *b =3D bs->breakpoint_at; int bp_temp; - enum exception_event_kind kind =3D classify_exception_breakpoint (b); =20 - annotate_catchpoint (b->number); + annotate_catchpoint (number); maybe_print_thread_hit_breakpoint (uiout); =20 - bp_temp =3D b->disposition =3D=3D disp_del; + bp_temp =3D disposition =3D=3D disp_del; uiout->text (bp_temp ? "Temporary catchpoint " : "Catchpoint "); - uiout->field_signed ("bkptno", b->number); + uiout->field_signed ("bkptno", number); uiout->text ((kind =3D=3D EX_EVENT_THROW ? " (exception thrown), " : (kind =3D=3D EX_EVENT_CATCH ? " (exception caught), " : " (exception rethrown), "))); @@ -248,18 +247,16 @@ print_it_exception_catchpoint (bpstat *bs) { uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); - uiout->field_string ("disp", bpdisp_text (b->disposition)); + uiout->field_string ("disp", bpdisp_text (disposition)); } return PRINT_SRC_AND_LOC; } =20 -static bool -print_one_exception_catchpoint (struct breakpoint *b,=20 - struct bp_location **last_loc) +bool +exception_catchpoint::print_one (struct bp_location **last_loc) { struct value_print_options opts; struct ui_out *uiout =3D current_uiout; - enum exception_event_kind kind =3D classify_exception_breakpoint (b); =20 get_user_print_options (&opts); =20 @@ -293,48 +290,41 @@ print_one_exception_catchpoint (struct breakpoint *b, =20 /* Implement the 'print_one_detail' method. */ =20 -static void -print_one_detail_exception_catchpoint (const struct breakpoint *b, - struct ui_out *uiout) +void +exception_catchpoint::print_one_detail (struct ui_out *uiout) const { - const struct exception_catchpoint *cp - =3D (const struct exception_catchpoint *) b; - - if (!cp->exception_rx.empty ()) + if (!exception_rx.empty ()) { uiout->text (_("\tmatching: ")); - uiout->field_string ("regexp", cp->exception_rx); + uiout->field_string ("regexp", exception_rx); uiout->text ("\n"); } } =20 -static void -print_mention_exception_catchpoint (struct breakpoint *b) +void +exception_catchpoint::print_mention () { struct ui_out *uiout =3D current_uiout; int bp_temp; - enum exception_event_kind kind =3D classify_exception_breakpoint (b); =20 - bp_temp =3D b->disposition =3D=3D disp_del; + bp_temp =3D disposition =3D=3D disp_del; uiout->message ("%s %d %s", (bp_temp ? _("Temporary catchpoint ") : _("Catchpoint")), - b->number, + number, (kind =3D=3D EX_EVENT_THROW ? _("(throw)") : (kind =3D=3D EX_EVENT_CATCH ? _("(catch)") : _("(rethrow)")))); } =20 -/* Implement the "print_recreate" breakpoint_ops method for throw and - catch catchpoints. */ +/* Implement the "print_recreate" method for throw and catch + catchpoints. */ =20 -static void -print_recreate_exception_catchpoint (struct breakpoint *b,=20 - struct ui_file *fp) +void +exception_catchpoint::print_recreate (struct ui_file *fp) { int bp_temp; - enum exception_event_kind kind =3D classify_exception_breakpoint (b); =20 - bp_temp =3D b->disposition =3D=3D disp_del; + bp_temp =3D disposition =3D=3D disp_del; gdb_printf (fp, bp_temp ? "tcatch " : "catch "); switch (kind) { @@ -348,16 +338,16 @@ print_recreate_exception_catchpoint (struct breakpoin= t *b, gdb_printf (fp, "rethrow"); break; } - print_recreate_thread (b, fp); + print_recreate_thread (this, fp); } =20 -/* Implement the "allocate_location" breakpoint_ops method for throw - and catch catchpoints. */ +/* Implement the "allocate_location" method for throw and catch + catchpoints. */ =20 -static bp_location * -allocate_location_exception_catchpoint (breakpoint *self) +bp_location * +exception_catchpoint::allocate_location () { - return new bp_location (self, bp_loc_software_breakpoint); + return new bp_location (this, bp_loc_software_breakpoint); } =20 static void @@ -376,12 +366,12 @@ handle_gnu_v3_exceptions (int tempflag, std::string &= &except_rx, std::unique_ptr cp (new exception_catchpoint ()); =20 init_catchpoint (cp.get (), get_current_arch (), tempflag, cond_string, - &gnu_v3_exception_catchpoint_ops); + &vtable_breakpoint_ops); cp->kind =3D ex_event; cp->exception_rx =3D std::move (except_rx); cp->pattern =3D std::move (pattern); =20 - re_set_exception_catchpoint (cp.get ()); + cp->re_set (); =20 install_breakpoint (0, std::move (cp), 1); } @@ -516,32 +506,10 @@ static const struct internalvar_funcs exception_funcs= =3D =20 =0C =20 -static void -initialize_throw_catchpoint_ops (void) -{ - struct breakpoint_ops *ops; - - initialize_breakpoint_ops (); - - /* GNU v3 exception catchpoints. */ - ops =3D &gnu_v3_exception_catchpoint_ops; - *ops =3D bkpt_breakpoint_ops; - ops->re_set =3D re_set_exception_catchpoint; - ops->print_it =3D print_it_exception_catchpoint; - ops->print_one =3D print_one_exception_catchpoint; - ops->print_mention =3D print_mention_exception_catchpoint; - ops->print_recreate =3D print_recreate_exception_catchpoint; - ops->print_one_detail =3D print_one_detail_exception_catchpoint; - ops->check_status =3D check_status_exception_catchpoint; - ops->allocate_location =3D allocate_location_exception_catchpoint; -} - void _initialize_break_catch_throw (); void _initialize_break_catch_throw () { - initialize_throw_catchpoint_ops (); - /* Add catch and tcatch sub-commands. */ add_catch_command ("catch", _("\ Catch an exception, when caught."),