From patchwork Fri Oct 21 08:43:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 59265 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AF1B538515D9 for ; Fri, 21 Oct 2022 08:45:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AF1B538515D9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666341938; bh=z7dP9i6n3f6pAN54dLl9QQBX5wHwWkrIYe77t8fVhps=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=DZqcoicy3dTcZIFJcBfLJWxp5UtkFETdheSwKwG6klcPutf/2BpDkTdXvH50MvRsw Na9Xonh6lTvxCQbcvcFWI6A0LaX34cVMR2ZEL4za3FQ6ZmAp8EgU3aO1ifG+Ya9TU0 gAgeX/svW75JK8GCdU/561mJMhNRa5ZKy95IK0uY= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 7B8633854177 for ; Fri, 21 Oct 2022 08:44:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7B8633854177 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-508-uJMgO49jMC2ZWk8Dc48_OA-1; Fri, 21 Oct 2022 04:44:02 -0400 X-MC-Unique: uJMgO49jMC2ZWk8Dc48_OA-1 Received: by mail-wm1-f70.google.com with SMTP id i203-20020a1c3bd4000000b003c6d18a7ee5so1149990wma.6 for ; Fri, 21 Oct 2022 01:44:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z7dP9i6n3f6pAN54dLl9QQBX5wHwWkrIYe77t8fVhps=; b=yL+O1AJ+KdkPwNY0KqVnURAoy8Ap9Hkh/HvsWD9CMHpp/WZDrCxUNZbtbIBndg6zHd i33Z1sCcwj4gPKO1bDbq5yyA3RecbirG3CI/Qok1+pl3oO8pneGy+mrfnEdMY5Ln3ZW3 YL44AD1abSgutrzCaORySmguM0Fra1tVcmmchYIVO+eQ4jwqxsTB2CtIjnhZ/9opCaRk UIDp1kNJ5mvKVOt0TjZnlylA6oA8TV1Xjmz3apZLVmFQooGGJfXhTy6OCmGi0It/CU8+ VhMdML5jPVLpbp/tgd8xYU8nvvRp1rC6g10S60rf6B5nF9/BW0RwAElmD1/Xdg3Py85q eONQ== X-Gm-Message-State: ACrzQf1mAR9OusxBkZo14MeXGmnhiRgOtJyiFPUSGeL5x4O7TdhTkIdQ DFlITn8kPErkv703DhCRlqsWrSn34vZo0sVEvyXjW5y82r7J48UjpAPja4dh17IwAEZOAP+Z00h joNYAWiGLWhYwNGnJP/ZoczeikI4hd6XUXRrmL2Ed3tlvfGWn/cFLVI/GZ52mNAPZuaFpoglUHw == X-Received: by 2002:adf:dc51:0:b0:235:4db8:2d3b with SMTP id m17-20020adfdc51000000b002354db82d3bmr5488669wrj.589.1666341841520; Fri, 21 Oct 2022 01:44:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5fzlrpZHjJ3GvovbHZfOQK13L6rTAyDvZnlr6S6/p20a5E8DC30eCTAEY7m/HAT50Kxs1BIw== X-Received: by 2002:adf:dc51:0:b0:235:4db8:2d3b with SMTP id m17-20020adfdc51000000b002354db82d3bmr5488659wrj.589.1666341841194; Fri, 21 Oct 2022 01:44:01 -0700 (PDT) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id p63-20020a1c2942000000b003c6c5a5a651sm1837355wmp.28.2022.10.21.01.44.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 01:44:00 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 08/12] gdb: don't always print breakpoint location after failed condition check Date: Fri, 21 Oct 2022 09:43:44 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Consider the following session: (gdb) list some_func 1 int 2 some_func () 3 { 4 int *p = 0; 5 return *p; 6 } 7 8 void 9 foo () 10 { (gdb) break foo if (some_func ()) Breakpoint 1 at 0x40111e: file bpcond.c, line 11. (gdb) r Starting program: /tmp/bpcond Program received signal SIGSEGV, Segmentation fault. 0x0000000000401116 in some_func () at bpcond.c:5 5 return *p; Error in testing condition for breakpoint 1: The program being debugged stopped while in a function called from GDB. Evaluation of the expression containing the function (some_func) will be abandoned. When the function is done executing, GDB will silently stop. Breakpoint 1, 0x0000000000401116 in some_func () at bpcond.c:5 5 return *p; (gdb) What happens here is the breakpoint condition includes a call to an inferior function, and the inferior function segfaults. We can see that GDB reports the segfault, and then gives an error message that indicates that an inferior function call was interrupted. After this GDB appears to report that it is stopped at Breakpoint 1, inside some_func. I find this second stop report a little confusing. Yes, GDB has stopped as a result of hitting breakpoint 1, but, I think the message as it currently is might give the impression that the thread is actually stopped at a location of breakpoint 1, which is not the case. Also, I find the second stop message draws attention away from the "Program received signal SIGSEGV, Segmentation fault" stop message, and this second stop might be thought of as replacing in someway the earlier message. In short, I think that the in the situation above, I think things would be clearer if the second stop message were not reported at all, so the output should (I think) look like this: (gdb) list some_func 1 int 2 some_func () 3 { 4 int *p = 0; 5 return *p; 6 } 7 8 void 9 foo () 10 { (gdb) break foo if (some_func ()) Breakpoint 1 at 0x40111e: file bpcond.c, line 11. (gdb) r Starting program: /tmp/bpcond Program received signal SIGSEGV, Segmentation fault. 0x0000000000401116 in some_func () at bpcond.c:5 5 return *p; Error in testing condition for breakpoint 1: The program being debugged stopped while in a function called from GDB. Evaluation of the expression containing the function (some_func) will be abandoned. When the function is done executing, GDB will silently stop. (gdb) The user can still find the number of the breakpoint that triggered the initial stop in this line: Error in testing condition for breakpoint 1: But there's now only one stop reason reported, the SIGSEGV, which I think is much clearer. To achieve this change I set the bpstat::print field when: (a) a breakpoint condition evaluation failed, and (b) the $pc of the thread changed during condition evaluation. I've updated the existing tests that checked the error message printed when a breakpoint condition evaluation failed. --- gdb/breakpoint.c | 12 ++++++++++++ gdb/testsuite/gdb.base/infcall-failure.exp | 18 ++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 4f5a27a6fe8..606b2d191f4 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -5403,6 +5403,7 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread) else within_current_scope = 0; } + CORE_ADDR pc_before_check = get_frame_pc (get_selected_frame (nullptr)); if (within_current_scope) { try @@ -5414,6 +5415,17 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread) exception_fprintf (gdb_stderr, ex, "Error in testing condition for breakpoint %d:\n", b->number); + + /* If the pc value changed as a result of evaluating the + condition then we probably stopped within an inferior + function call due to some unexpected stop, e.g. the thread + hit another breakpoint, or the thread received an + unexpected signal. In this case we don't want to also + print the information about this breakpoint. */ + CORE_ADDR pc_after_check + = get_frame_pc (get_selected_frame (nullptr)); + if (pc_before_check != pc_after_check) + bs->print = 0; } } else diff --git a/gdb/testsuite/gdb.base/infcall-failure.exp b/gdb/testsuite/gdb.base/infcall-failure.exp index 2dcdda34b4d..8fa2c407fc5 100644 --- a/gdb/testsuite/gdb.base/infcall-failure.exp +++ b/gdb/testsuite/gdb.base/infcall-failure.exp @@ -79,10 +79,7 @@ proc_with_prefix run_cond_hits_breakpoint_test { async_p non_stop_p } { "The program being debugged stopped while in a function called from GDB\\." \ "Evaluation of the expression containing the function" \ "\\(func_bp\\) will be abandoned\\." \ - "When the function is done executing, GDB will silently stop\\." \ - "" \ - "Breakpoint ${bp_1_num}, \[^\r\n\]+" \ - "${::decimal}\\s+\[^\r\n\]+Second breakpoint\[^\r\n\]+"] + "When the function is done executing, GDB will silently stop\\."] } # Start GDB according to ASYNC_P and NON_STOP_P, then call an inferior @@ -138,13 +135,12 @@ proc_with_prefix run_cond_hits_segfault_test { async_p non_stop_p } { "${::hex} in func_segfault \\(\\) at \[^\r\n\]+:${::segv_line}" \ "${::decimal}\\s+\[^\r\n\]+Segfault here\[^\r\n\]+" \ "Error in testing condition for breakpoint ${bp_1_num}:" \ - "The program being debugged stopped while in a function called from GDB\\." \ + "The program being debugged was signaled while in a function called from GDB\\." \ + "GDB remains in the frame where the signal was received\\." \ + "To change this behavior use \"set unwindonsignal on\"\\." \ "Evaluation of the expression containing the function" \ "\\(func_segfault\\) will be abandoned\\." \ - "When the function is done executing, GDB will silently stop\\." \ - "" \ - "Breakpoint ${bp_1_num}, \[^\r\n\]+" \ - "${::decimal}\\s+\[^\r\n\]+Segfault here\[^\r\n\]+"] + "When the function is done executing, GDB will silently stop\\."] } # Start GDB according to ASYNC_P and NON_STOP_P, then call an inferior @@ -167,7 +163,9 @@ proc_with_prefix run_call_hits_segfault_test { async_p non_stop_p } { "Program received signal SIGSEGV, Segmentation fault\\." \ "${::hex} in func_segfault \\(\\) at \[^\r\n\]+:${::segv_line}" \ "${::decimal}\\s+\[^\r\n\]+Segfault here\[^\r\n\]+" \ - "The program being debugged stopped while in a function called from GDB\\." \ + "The program being debugged was signaled while in a function called from GDB\\." \ + "GDB remains in the frame where the signal was received\\." \ + "To change this behavior use \"set unwindonsignal on\"\\." \ "Evaluation of the expression containing the function" \ "\\(func_segfault\\) will be abandoned\\." \ "When the function is done executing, GDB will silently stop\\."]