From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id B04A13858405; Fri, 29 Apr 2022 22:24:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B04A13858405 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] Remove most fields from breakpoint_ops X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: b3316ff1532571a111dcc27f4545640aafbdaffd X-Git-Newrev: c47614fef9fa278399e0d2818d42b73f0e0a26ec Message-Id: <20220429222426.B04A13858405@sourceware.org> Date: Fri, 29 Apr 2022 22:24:26 +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:24:26 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dc47614fef9fa= 278399e0d2818d42b73f0e0a26ec commit c47614fef9fa278399e0d2818d42b73f0e0a26ec Author: Tom Tromey Date: Sun Jan 16 19:13:55 2022 -0700 Remove most fields from breakpoint_ops =20 At this point, all implementations of breakpoints use the vtable. So, we can now remove most function pointers from breakpoint_ops and switch to using methods directly in the callers. Only the two "static virtual" methods remain in breakpoint_ops. Diff: --- gdb/break-catch-load.c | 2 +- gdb/breakpoint.c | 239 ++++++---------------------------------------= ---- gdb/breakpoint.h | 93 ------------------- 3 files changed, 30 insertions(+), 304 deletions(-) diff --git a/gdb/break-catch-load.c b/gdb/break-catch-load.c index 699fbc19365..7c927396e3a 100644 --- a/gdb/break-catch-load.c +++ b/gdb/break-catch-load.c @@ -92,7 +92,7 @@ solib_catchpoint::breakpoint_hit (const struct bp_locatio= n *bl, =20 for (bp_location *other_bl : other->locations ()) { - if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) + if (other->breakpoint_hit (other_bl, aspace, bp_addr, ws)) return 1; } } diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index c1459161707..6446aac8ace 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -1970,7 +1970,7 @@ update_watchpoint (struct watchpoint *b, int reparse) the target gains execution, through breakpoint_re_set. */ if (!can_use_hw_watchpoints) { - if (b->ops->works_in_software_mode (b)) + if (b->works_in_software_mode ()) b->type =3D bp_watchpoint; else error (_("Can't set read/access watchpoint when " @@ -2129,7 +2129,7 @@ update_watchpoint (struct watchpoint *b, int reparse) =3D target_can_use_hardware_watchpoint (type, i, other_type_used); if (target_resources_ok <=3D 0) { - int sw_mode =3D b->ops->works_in_software_mode (b); + int sw_mode =3D b->works_in_software_mode (); =20 if (target_resources_ok =3D=3D 0 && !sw_mode) error (_("Target does not support this type of " @@ -2150,7 +2150,7 @@ update_watchpoint (struct watchpoint *b, int reparse) b->type =3D type; } } - else if (!b->ops->works_in_software_mode (b)) + else if (!b->works_in_software_mode ()) { if (!can_use_hw_watchpoints) error (_("Can't set read/access watchpoint when " @@ -2694,7 +2694,7 @@ insert_bp_location (struct bp_location *bl, { int val; =20 - val =3D bl->owner->ops->insert_location (bl); + val =3D bl->owner->insert_location (bl); if (val) bp_excpt =3D gdb_exception {RETURN_ERROR, GENERIC_ERROR}; } @@ -2757,7 +2757,7 @@ insert_bp_location (struct bp_location *bl, { int val; =20 - val =3D bl->owner->ops->insert_location (bl); + val =3D bl->owner->insert_location (bl); if (val) bp_excpt =3D gdb_exception {RETURN_ERROR, GENERIC_ERROR}; } @@ -2871,10 +2871,7 @@ insert_bp_location (struct bp_location *bl, { int val; =20 - gdb_assert (bl->owner->ops !=3D NULL - && bl->owner->ops->insert_location !=3D NULL); - - val =3D bl->owner->ops->insert_location (bl); + val =3D bl->owner->insert_location (bl); =20 /* If trying to set a read-watchpoint, and it turns out it's not supported, try emulating one with an access watchpoint. */ @@ -2899,7 +2896,7 @@ insert_bp_location (struct bp_location *bl, if (val =3D=3D 1) { bl->watchpoint_type =3D hw_access; - val =3D bl->owner->ops->insert_location (bl); + val =3D bl->owner->insert_location (bl); =20 if (val) /* Back to the original value. */ @@ -2914,10 +2911,7 @@ insert_bp_location (struct bp_location *bl, { int val; =20 - gdb_assert (bl->owner->ops !=3D NULL - && bl->owner->ops->insert_location !=3D NULL); - - val =3D bl->owner->ops->insert_location (bl); + val =3D bl->owner->insert_location (bl); if (val) { bl->owner->enable_state =3D bp_disabled; @@ -3891,7 +3885,7 @@ remove_breakpoint_1 (struct bp_location *bl, enum rem= ove_bp_reason reason) && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) val =3D 0; else - val =3D bl->owner->ops->remove_location (bl, reason); + val =3D bl->owner->remove_location (bl, reason); } else { @@ -3926,7 +3920,7 @@ remove_breakpoint_1 (struct bp_location *bl, enum rem= ove_bp_reason reason) wrong code with the saved shadow contents. */ if (bl->loc_type =3D=3D bp_loc_hardware_breakpoint || section_is_mapped (bl->section)) - val =3D bl->owner->ops->remove_location (bl, reason); + val =3D bl->owner->remove_location (bl, reason); else val =3D 0; } @@ -3960,11 +3954,8 @@ remove_breakpoint_1 (struct bp_location *bl, enum re= move_bp_reason reason) } else if (bl->loc_type =3D=3D bp_loc_hardware_watchpoint) { - gdb_assert (bl->owner->ops !=3D NULL - && bl->owner->ops->remove_location !=3D NULL); - bl->inserted =3D (reason =3D=3D DETACH_BREAKPOINT); - bl->owner->ops->remove_location (bl, reason); + bl->owner->remove_location (bl, reason); =20 /* Failure to remove any of the hardware watchpoints comes here. */ if (reason =3D=3D REMOVE_BREAKPOINT && bl->inserted) @@ -3975,10 +3966,7 @@ remove_breakpoint_1 (struct bp_location *bl, enum re= move_bp_reason reason) && breakpoint_enabled (bl->owner) && !bl->duplicate) { - gdb_assert (bl->owner->ops !=3D NULL - && bl->owner->ops->remove_location !=3D NULL); - - val =3D bl->owner->ops->remove_location (bl, reason); + val =3D bl->owner->remove_location (bl, reason); if (val) return val; =20 @@ -4418,8 +4406,7 @@ bpstat_explains_signal (bpstat *bsp, enum gdb_signal = sig) } else { - if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, - sig)) + if (bsp->breakpoint_at->explains_signal (sig)) return true; } } @@ -4707,7 +4694,7 @@ print_bp_stop_message (bpstat *bs) return PRINT_UNKNOWN; =20 /* Normal case. Call the breakpoint's print_it method. */ - return b->ops->print_it (bs); + return b->print_it (bs); } break; =20 @@ -5073,8 +5060,8 @@ watchpoint_check (bpstat *bs) watch after that (since the garbage may or may not equal the first value assigned). */ /* We print all the stop information in - breakpoint_ops->print_it, but in this case, by the time we - call breakpoint_ops->print_it this bp will be deleted + breakpointprint_it, but in this case, by the time we + call breakpoint->print_it this bp will be deleted already. So we have no choice but print the information here. */ =20 @@ -5113,7 +5100,7 @@ bpstat_check_location (const struct bp_location *bl, /* BL is from an existing breakpoint. */ gdb_assert (b !=3D NULL); =20 - return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); + return b->breakpoint_hit (bl, aspace, bp_addr, ws); } =20 /* Determine if the watched values have actually changed, and we @@ -5561,7 +5548,7 @@ bpstat_stop_status (const address_space *aspace, continue; =20 b =3D bs->breakpoint_at; - b->ops->check_status (bs); + b->check_status (bs); if (bs->stop) { bpstat_check_breakpoint_conditions (bs, thread); @@ -5586,7 +5573,7 @@ bpstat_stop_status (const address_space *aspace, ? bs->commands.get () : NULL)) bs->print =3D 0; =20 - b->ops->after_condition_true (bs); + b->after_condition_true (bs); } =20 } @@ -6221,7 +6208,7 @@ print_one_breakpoint_location (struct breakpoint *b, =20 /* 5 and 6 */ bool result =3D false; - if (!raw_loc && b->ops !=3D NULL && b->ops->print_one (b, last_loc)) + if (!raw_loc && b->print_one (last_loc)) result =3D true; else { @@ -6304,7 +6291,7 @@ print_one_breakpoint_location (struct breakpoint *b, uiout->text ("\n"); =20 if (!part_of_multiple) - b->ops->print_one_detail (b, uiout); + b->print_one_detail (uiout); =20 if (part_of_multiple && frame_id_p (b->frame_id)) { @@ -7191,7 +7178,7 @@ bp_location::bp_location (breakpoint *owner) static struct bp_location * allocate_bp_location (struct breakpoint *bpt) { - return bpt->ops->allocate_location (bpt); + return bpt->allocate_location (); } =20 /* Decrement reference count. If the reference count reaches 0, @@ -7874,7 +7861,7 @@ hw_breakpoint_used_count (void) { /* Special types of hardware breakpoints may use more than one register. */ - i +=3D b->ops->resources_needed (bl); + i +=3D b->resources_needed (bl); } =20 return i; @@ -7895,7 +7882,7 @@ hw_watchpoint_use_count (struct breakpoint *b) { /* Special types of hardware watchpoints may use more than one register. */ - i +=3D b->ops->resources_needed (bl); + i +=3D b->resources_needed (bl); } =20 return i; @@ -8082,7 +8069,7 @@ set_momentary_breakpoint_at_pc (struct gdbarch *gdbar= ch, CORE_ADDR pc, static void mention (struct breakpoint *b) { - b->ops->print_mention (b); + b->print_mention (); current_uiout->text ("\n"); } =0C @@ -11472,7 +11459,7 @@ bpstat_remove_breakpoint_callback (struct thread_in= fo *th, void *data) return 0; } =20 -/* Helper for breakpoint and tracepoint breakpoint_ops->mention +/* Helper for breakpoint and tracepoint breakpoint->mention callbacks. */ =20 static void @@ -11553,46 +11540,21 @@ bp_location_range breakpoint::locations () return bp_location_range (this->loc); } =20 -static struct bp_location * -base_breakpoint_allocate_location (struct breakpoint *self) -{ - return new bp_location (self); -} - struct bp_location * breakpoint::allocate_location () { return new bp_location (this); } =20 -static void -base_breakpoint_re_set (struct breakpoint *b) -{ - /* Nothing to re-set. */ -} - #define internal_error_pure_virtual_called() \ gdb_assert_not_reached ("pure virtual function called") =20 -static int -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 (); } =20 -static int -base_breakpoint_remove_location (struct bp_location *bl, - enum remove_bp_reason reason) -{ - internal_error_pure_virtual_called (); -} - int breakpoint::remove_location (struct bp_location *bl, enum remove_bp_reason reason) @@ -11600,15 +11562,6 @@ breakpoint::remove_location (struct bp_location *b= l, internal_error_pure_virtual_called (); } =20 -static int -base_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 (); -} - int breakpoint::breakpoint_hit (const struct bp_location *bl, const address_space *aspace, @@ -11618,85 +11571,30 @@ breakpoint::breakpoint_hit (const struct bp_locat= ion *bl, internal_error_pure_virtual_called (); } =20 -static void -base_breakpoint_check_status (bpstat *bs) -{ - /* Always stop. */ -} - -/* A "works_in_software_mode" breakpoint_ops method that just internal - errors. */ - -static int -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 (); } =20 -/* A "resources_needed" breakpoint_ops method that just internal - errors. */ - -static int -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 (); } =20 -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 (); } =20 -static bool -base_breakpoint_print_one (struct breakpoint *, struct bp_location **) -{ - return false; -} - -static void -base_breakpoint_print_one_detail (const struct breakpoint *self, - struct ui_out *uiout) -{ - /* nothing */ -} - -static void -base_breakpoint_print_mention (struct breakpoint *b) -{ - internal_error_pure_virtual_called (); -} - void breakpoint::print_mention () { internal_error_pure_virtual_called (); } =20 -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) { @@ -11728,14 +11626,6 @@ base_breakpoint_create_breakpoints_sal (struct gdb= arch *gdbarch, internal_error_pure_virtual_called (); } =20 -static std::vector -base_breakpoint_decode_location (struct breakpoint *b, - struct event_location *location, - struct program_space *search_pspace) -{ - internal_error_pure_virtual_called (); -} - std::vector breakpoint::decode_location (struct event_location *location, struct program_space *search_pspace) @@ -11743,87 +11633,16 @@ breakpoint::decode_location (struct event_locatio= n *location, internal_error_pure_virtual_called (); } =20 -/* The default 'explains_signal' method. */ - -static int -base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) -{ - return 1; -} - -/* The default "after_condition_true" method. */ - -static void -base_breakpoint_after_condition_true (struct bpstat *bs) -{ - /* Nothing to do. */ -} - struct breakpoint_ops base_breakpoint_ops =3D { - base_breakpoint_allocate_location, - base_breakpoint_re_set, - base_breakpoint_insert_location, - base_breakpoint_remove_location, - base_breakpoint_breakpoint_hit, - base_breakpoint_check_status, - base_breakpoint_resources_needed, - base_breakpoint_works_in_software_mode, - base_breakpoint_print_it, - base_breakpoint_print_one, - base_breakpoint_print_one_detail, - base_breakpoint_print_mention, - base_breakpoint_print_recreate, base_breakpoint_create_sals_from_location, base_breakpoint_create_breakpoints_sal, - base_breakpoint_decode_location, - base_breakpoint_explains_signal, - base_breakpoint_after_condition_true, }; =20 struct breakpoint_ops vtable_breakpoint_ops =3D { - [] (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); } }; =20 /* Default breakpoint_ops methods. */ @@ -12990,7 +12809,7 @@ location_to_sals (struct breakpoint *b, struct even= t_location *location, =20 try { - sals =3D b->ops->decode_location (b, location, search_pspace); + sals =3D b->decode_location (location, search_pspace); } catch (gdb_exception_error &e) { @@ -13158,7 +12977,7 @@ breakpoint_re_set_one (breakpoint *b) input_radix =3D b->input_radix; set_language (b->language); =20 - b->ops->re_set (b); + b->re_set (); } =20 /* Re-set breakpoint locations for the current program space. @@ -14350,7 +14169,7 @@ save_breakpoints (const char *filename, int from_tt= y, if (filter && !filter (tp)) continue; =20 - tp->ops->print_recreate (tp, &fp); + tp->print_recreate (&fp); =20 /* Note, we can't rely on tp->number for anything, as we can't assume the recreated breakpoint numbers will match. Use $bpnum diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 8b92dc47878..93c2a64387d 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -561,80 +561,6 @@ enum print_stop_action =20 struct breakpoint_ops { - /* Allocate a location for this breakpoint. */ - struct bp_location * (*allocate_location) (struct breakpoint *); - - /* Reevaluate a breakpoint. This is necessary after symbols change - (e.g., an executable or DSO was loaded, or the inferior just - started). */ - void (*re_set) (struct breakpoint *self); - - /* 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. */ - 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. */ - int (*remove_location) (struct bp_location *, enum remove_bp_reason reas= on); - - /* 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. */ - 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. */ - void (*check_status) (struct bpstat *bs); - - /* 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. */ - 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. */ - int (*works_in_software_mode) (const struct breakpoint *); - - /* The normal print routine for this breakpoint, called when we - hit it. */ - 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. */ - bool (*print_one) (struct breakpoint *, struct bp_location **); - - /* 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] - - */ - void (*print_one_detail) (const struct breakpoint *, struct ui_out *); - - /* Display information about this breakpoint after setting it - (roughly speaking; this is called from "mention"). */ - void (*print_mention) (struct breakpoint *); - - /* Print to FP the CLI command that recreates this breakpoint. */ - void (*print_recreate) (struct breakpoint *, struct ui_file *fp); - /* Create SALs from location, storing the result in linespec_result. =20 For an explanation about the arguments, see the function @@ -659,25 +585,6 @@ struct breakpoint_ops enum bptype, enum bpdisp, int, int, int, const struct breakpoint_ops *, int, int, int, unsigned); - - /* 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'. */ - std::vector (*decode_location) - (struct breakpoint *b, - struct event_location *location, - struct program_space *search_pspace); - - /* Return true if this breakpoint explains a signal. See - bpstat_explains_signal. */ - int (*explains_signal) (struct breakpoint *, enum gdb_signal); - - /* Called after evaluating the breakpoint's condition, - and only if it evaluated true. */ - void (*after_condition_true) (struct bpstat *bs); }; =20 /* Helper for breakpoint_ops->print_recreate implementations. Prints