From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1551) id CC8F0383088C; Fri, 20 May 2022 19:44:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC8F0383088C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pedro Alves To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Make sure momentary breakpoints are always thread-specific X-Act-Checkin: binutils-gdb X-Git-Author: Pedro Alves X-Git-Refname: refs/heads/master X-Git-Oldrev: f9703051465a03bace3cc17b80fcd12c19a60821 X-Git-Newrev: 7ab979957c6dd6fddd86b396e9e885ec09002e8e Message-Id: <20220520194409.CC8F0383088C@sourceware.org> Date: Fri, 20 May 2022 19:44:09 +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, 20 May 2022 19:44:09 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D7ab979957c6d= d6fddd86b396e9e885ec09002e8e commit 7ab979957c6dd6fddd86b396e9e885ec09002e8e Author: Pedro Alves Date: Thu May 12 20:20:03 2022 +0100 Make sure momentary breakpoints are always thread-specific =20 This adds a new ctor to momentary_breakpoints with a few parameters that are always necessary for momentary breakpoints. =20 In particular, I noticed that set_std_terminate_breakpoint doesn't make the breakpoint be thread specific, which looks like a bug to me. =20 The point of that breakpoint is to intercept std::terminate calls that happen as result of the called thread throwing an exception that won't be caught by the dummy frame. If some other thread calls std::terminate, IMO, it's no different from some other thread calling exit/_exit, for example. =20 Change-Id: Ifc5ff4a6d6e58b8c4854d00b86725382d38a1a02 Diff: --- gdb/breakpoint.c | 83 +++++++++++++++++++++++++++++++---------------------= ---- 1 file changed, 46 insertions(+), 37 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 9006311b4bf..89ff9cfb8c7 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -118,7 +118,7 @@ static breakpoint *add_to_breakpoint_chain (std::unique= _ptr &&b); static struct breakpoint * momentary_breakpoint_from_master (struct breakpoint *orig, enum bptype type, - int loc_enabled); + int loc_enabled, int thread); =20 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); =20 @@ -305,7 +305,25 @@ struct internal_breakpoint : public base_breakpoint breakpoints". */ struct momentary_breakpoint : public base_breakpoint { - using base_breakpoint::base_breakpoint; + momentary_breakpoint (struct gdbarch *gdbarch_, enum bptype bptype, + program_space *pspace_, + const struct frame_id &frame_id_, + int thread_) + : base_breakpoint (gdbarch_, bptype) + { + /* If FRAME_ID is valid, it should be a real frame, not an inlined + or tail-called one. */ + gdb_assert (!frame_id_artificial_p (frame_id)); + + /* Momentary breakpoints are always thread-specific. */ + gdb_assert (thread_ > 0); + + pspace =3D pspace_; + enable_state =3D bp_enabled; + disposition =3D disp_donttouch; + frame_id =3D frame_id_; + thread =3D thread_; + } =20 void re_set () override; void check_status (struct bpstat *bs) override; @@ -7293,12 +7311,9 @@ set_longjmp_breakpoint (struct thread_info *tp, stru= ct frame_id frame) || b->type =3D=3D bp_exception_master)) { enum bptype type =3D b->type =3D=3D bp_longjmp_master ? bp_longjmp : bp_e= xception; - struct breakpoint *clone; - /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again after their removal. */ - clone =3D momentary_breakpoint_from_master (b, type, 1); - clone->thread =3D thread; + momentary_breakpoint_from_master (b, type, 1, thread); } =20 tp->initiating_frame =3D frame; @@ -7340,11 +7355,10 @@ set_longjmp_breakpoint_for_call_dummy (void) for (breakpoint *b : all_breakpoints ()) if (b->pspace =3D=3D current_program_space && b->type =3D=3D bp_longjm= p_master) { - struct breakpoint *new_b; - - new_b =3D momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, - 1); - new_b->thread =3D inferior_thread ()->global_num; + int thread =3D inferior_thread ()->global_num; + breakpoint *new_b + =3D momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, + 1, thread); =20 /* Link NEW_B into the chain of RETVAL breakpoints. */ =20 @@ -7473,7 +7487,8 @@ set_std_terminate_breakpoint (void) if (b->pspace =3D=3D current_program_space && b->type =3D=3D bp_std_terminate_master) { - momentary_breakpoint_from_master (b, bp_std_terminate, 1); + momentary_breakpoint_from_master (b, bp_std_terminate, 1, + inferior_thread ()->global_num); } } =20 @@ -7877,13 +7892,17 @@ enable_breakpoints_after_startup (void) =20 /* Allocate a new momentary breakpoint. */ =20 +template static momentary_breakpoint * -new_momentary_breakpoint (struct gdbarch *gdbarch, enum bptype type) +new_momentary_breakpoint (struct gdbarch *gdbarch, enum bptype type, + Arg&&... args) { if (type =3D=3D bp_longjmp || type =3D=3D bp_exception) - return new longjmp_breakpoint (gdbarch, type); + return new longjmp_breakpoint (gdbarch, type, + std::forward (args)...); else - return new momentary_breakpoint (gdbarch, type); + return new momentary_breakpoint (gdbarch, type, + std::forward (args)...); } =20 /* Set a momentary breakpoint of type TYPE at address specified by @@ -7899,15 +7918,10 @@ set_momentary_breakpoint (struct gdbarch *gdbarch, = struct symtab_and_line sal, gdb_assert (!frame_id_artificial_p (frame_id)); =20 std::unique_ptr b - (new_momentary_breakpoint (gdbarch, type)); + (new_momentary_breakpoint (gdbarch, type, sal.pspace, frame_id, + inferior_thread ()->global_num)); =20 b->add_location (sal); - b->pspace =3D sal.pspace; - b->enable_state =3D bp_enabled; - b->disposition =3D disp_donttouch; - b->frame_id =3D frame_id; - - b->thread =3D inferior_thread ()->global_num; =20 breakpoint_up bp (add_to_breakpoint_chain (std::move (b))); =20 @@ -7923,10 +7937,12 @@ set_momentary_breakpoint (struct gdbarch *gdbarch, = struct symtab_and_line sal, static struct breakpoint * momentary_breakpoint_from_master (struct breakpoint *orig, enum bptype type, - int loc_enabled) + int loc_enabled, + int thread) { std::unique_ptr copy - (new_momentary_breakpoint (orig->gdbarch, type)); + (new_momentary_breakpoint (orig->gdbarch, type, orig->pspace, + orig->frame_id, thread)); copy->loc =3D copy->allocate_location (); set_breakpoint_location_function (copy->loc); =20 @@ -7939,12 +7955,6 @@ momentary_breakpoint_from_master (struct breakpoint = *orig, copy->loc->line_number =3D orig->loc->line_number; copy->loc->symtab =3D orig->loc->symtab; copy->loc->enabled =3D loc_enabled; - copy->frame_id =3D orig->frame_id; - copy->thread =3D orig->thread; - copy->pspace =3D orig->pspace; - - copy->enable_state =3D bp_enabled; - copy->disposition =3D disp_donttouch; =20 breakpoint *b =3D add_to_breakpoint_chain (std::move (copy)); update_global_location_list_nothrow (UGLL_DONT_INSERT); @@ -7961,7 +7971,8 @@ clone_momentary_breakpoint (struct breakpoint *orig) if (orig =3D=3D NULL) return NULL; =20 - return momentary_breakpoint_from_master (orig, orig->type, 0); + return momentary_breakpoint_from_master (orig, orig->type, 0, + orig->thread); } =20 breakpoint_up @@ -13385,12 +13396,10 @@ insert_single_step_breakpoint (struct gdbarch *gd= barch, if (tp->control.single_step_breakpoints =3D=3D NULL) { std::unique_ptr b - (new momentary_breakpoint (gdbarch, bp_single_step)); - - b->disposition =3D disp_donttouch; - - b->thread =3D tp->global_num; - gdb_assert (b->thread !=3D 0); + (new momentary_breakpoint (gdbarch, bp_single_step, + current_program_space, + null_frame_id, + tp->global_num)); =20 tp->control.single_step_breakpoints =3D add_to_breakpoint_chain (std::move (b));