From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by sourceware.org (Postfix) with ESMTPS id C282A3856DE0 for ; Mon, 16 May 2022 18:41:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C282A3856DE0 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f48.google.com with SMTP id f2so14686098wrc.0 for ; Mon, 16 May 2022 11:41:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IxvrFg/cfkTMyDIxIx7uhsYPh2zQ44iRC+5KITsvPJ8=; b=Qzbex3kp1ESMb3Ojh6yadVYnsApoRZ/KKXSoeYFtP0Cd46m+48GAPG3akl8RXHM3A5 Gpynuf0v3wDMN8CCGvPC7HQDdZxtTqMRWb7RpdtdDrbaxlJG/zlK22jjsYrbDNuQEyn4 AxyNCB/EV/6QewUe3ge0Ard6LFdLA/y2lo896sFohaSwBJy8v2z5MJ/LbEFV0QnUKFXo 4DEq1BJvxWx3kSKmIlhLhHxJHj8qcaiB6OWBSyeQarLAtnVQE+fwObO9kVG6ZI/7ZUXn M0Jhjhx1tKysMIyKs2wkMp0zyQxiKe0Sb/RbBd3ONbGmYgcdlRg9ZcWIGEbwCP3PpLBL XlCQ== X-Gm-Message-State: AOAM532CiE17Bo5nOV/4voTVFmDksyUdnxwqLoc2xV23fBng1XyJzu78 D8HhS7ZtQMZ7hF7rdTEklg9hePRvhcQ= X-Google-Smtp-Source: ABdhPJx8jXz6z373x0ah1xypLJyu5luUj/iTB6F44Arm8u5sVT2WnV+90Cgs9pAMJb1Wt7S8uTdi/w== X-Received: by 2002:a05:6000:1acd:b0:20c:811c:9f39 with SMTP id i13-20020a0560001acd00b0020c811c9f39mr15209320wry.482.1652726478080; Mon, 16 May 2022 11:41:18 -0700 (PDT) Received: from localhost ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id j38-20020a05600c1c2600b00395f15d993fsm74134wms.5.2022.05.16.11.41.16 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 May 2022 11:41:17 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 21/23] Make sure momentary breakpoints are always thread-specific Date: Mon, 16 May 2022 19:40:28 +0100 Message-Id: <20220516184030.665489-22-pedro@palves.net> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220516184030.665489-1-pedro@palves.net> References: <20220516184030.665489-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Mon, 16 May 2022 18:41:21 -0000 This adds a new ctor to momentary_breakpoints with a few parameters that are always necessary for momentary breakpoints. In particular, I noticed that set_std_terminate_breakpoint doesn't make the breakpoint be thread specific, which looks like a bug to me. 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. Change-Id: Ifc5ff4a6d6e58b8c4854d00b86725382d38a1a02 --- gdb/breakpoint.c | 83 +++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 37 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 4f664cbd7aa..f4642c2d8e7 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); static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); @@ -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 = pspace_; + enable_state = bp_enabled; + disposition = disp_donttouch; + frame_id = frame_id_; + thread = thread_; + } void re_set () override; void check_status (struct bpstat *bs) override; @@ -7293,12 +7311,9 @@ set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) || b->type == bp_exception_master)) { enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; - struct breakpoint *clone; - /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again after their removal. */ - clone = momentary_breakpoint_from_master (b, type, 1); - clone->thread = thread; + momentary_breakpoint_from_master (b, type, 1, thread); } tp->initiating_frame = frame; @@ -7340,11 +7355,10 @@ set_longjmp_breakpoint_for_call_dummy (void) for (breakpoint *b : all_breakpoints ()) if (b->pspace == current_program_space && b->type == bp_longjmp_master) { - struct breakpoint *new_b; - - new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, - 1); - new_b->thread = inferior_thread ()->global_num; + int thread = inferior_thread ()->global_num; + breakpoint *new_b + = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, + 1, thread); /* Link NEW_B into the chain of RETVAL breakpoints. */ @@ -7473,7 +7487,8 @@ set_std_terminate_breakpoint (void) if (b->pspace == current_program_space && b->type == 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); } } @@ -7877,13 +7892,17 @@ enable_breakpoints_after_startup (void) /* Allocate a new momentary breakpoint. */ +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 == bp_longjmp || type == 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)...); } /* 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)); std::unique_ptr b - (new_momentary_breakpoint (gdbarch, type)); + (new_momentary_breakpoint (gdbarch, type, sal.pspace, frame_id, + inferior_thread ()->global_num)); b->add_location (sal); - b->pspace = sal.pspace; - b->enable_state = bp_enabled; - b->disposition = disp_donttouch; - b->frame_id = frame_id; - - b->thread = inferior_thread ()->global_num; breakpoint_up bp (add_to_breakpoint_chain (std::move (b))); @@ -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 = copy->allocate_location (); set_breakpoint_location_function (copy->loc); @@ -7939,12 +7955,6 @@ momentary_breakpoint_from_master (struct breakpoint *orig, copy->loc->line_number = orig->loc->line_number; copy->loc->symtab = orig->loc->symtab; copy->loc->enabled = loc_enabled; - copy->frame_id = orig->frame_id; - copy->thread = orig->thread; - copy->pspace = orig->pspace; - - copy->enable_state = bp_enabled; - copy->disposition = disp_donttouch; breakpoint *b = 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 == NULL) return NULL; - return momentary_breakpoint_from_master (orig, orig->type, 0); + return momentary_breakpoint_from_master (orig, orig->type, 0, + orig->thread); } breakpoint_up @@ -13389,12 +13400,10 @@ insert_single_step_breakpoint (struct gdbarch *gdbarch, if (tp->control.single_step_breakpoints == NULL) { std::unique_ptr b - (new momentary_breakpoint (gdbarch, bp_single_step)); - - b->disposition = disp_donttouch; - - b->thread = tp->global_num; - gdb_assert (b->thread != 0); + (new momentary_breakpoint (gdbarch, bp_single_step, + current_program_space, + null_frame_id, + tp->global_num)); tp->control.single_step_breakpoints = add_to_breakpoint_chain (std::move (b)); -- 2.36.0