From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id B95603858C2F for ; Tue, 31 Jan 2023 17:49:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B95603858C2F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675187347; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tUvZyh2yI8B2Rv+7QC1Ypn6Du0lP2qP2i7TbHhDYjkI=; b=Zw2vVu486ncjJUtCVlWf3dqcCoe6GOV3RsntB0FbdV4W1ohs16/ybdoKTHGlq3VNKcrTVY aoi0E3vPO0vIAX4Vhi9CkUM56CrghEGInLMWeNsuPwSdMnjJyqY8Y+z1pTemhJL8IrsgPC /8duZayfa24B47A9BQl+GUaQA4x+4JQ= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-397-IigXy5dcMDiF6c5if-5RRQ-1; Tue, 31 Jan 2023 12:27:36 -0500 X-MC-Unique: IigXy5dcMDiF6c5if-5RRQ-1 Received: by mail-qk1-f198.google.com with SMTP id q21-20020a05620a0d9500b0070572ccdbf9so9551911qkl.10 for ; Tue, 31 Jan 2023 09:27:35 -0800 (PST) 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=tUvZyh2yI8B2Rv+7QC1Ypn6Du0lP2qP2i7TbHhDYjkI=; b=wmPyFY9AapKzvL3y6v4TTS0SvIeR8zYEgLu0THwx1wnjYFI88xvyRszGEravXHaSgv 82xHClFVvjC1qT5Ak5IA84kZzfwPoystSmtMV2Mzccnyrv9l19PrcIRCSsQz0Cp3ODxs ynLFpZZA1QkRKM3zQMG+Lnk//vvY7S+3CasKbLSG1l86i+OpGPgpanRwU+TH8vVypLad azBE+SR5lEODzK/GTORu0rArT2b4PqgYWGjEbPxnobsZYqLyYVSzDVAXKicM5Fu65xYu vCRvIbUBj6m1z6mvC2nzre6Zk0LkuKGdAKkgdhOeTrqWF4/Vtb+3REooo8l6fOPFWiFv MMjw== X-Gm-Message-State: AO0yUKWqRhgM0Dh+uLbCpAY4AV0WH5pX2spM9EQw2/3q3Dt5pxAo7C8/ firoLOIM0Ba18m/YeCQZmibOBlTX0NNDJZpIz5k0MNzp1MBcur4p9Az0uoFYP6Gb4mMRBPxzb1l 4oAzX8bEOEOREBC0V8qdLdG+R7Sh9CPfZcCDjOaNJQUzzx+AaYGbmGP4Br17fdteK1CSZ8P4TNA == X-Received: by 2002:ac8:5f91:0:b0:3b8:6c10:f52 with SMTP id j17-20020ac85f91000000b003b86c100f52mr12774269qta.46.1675186055352; Tue, 31 Jan 2023 09:27:35 -0800 (PST) X-Google-Smtp-Source: AK7set9KTEbnbVBaz8jXleaxxWtZAcgyLiB/YmekFGFoCoCoEzMjFbJOeqNafqCnsKIGwfZZYqBV2w== X-Received: by 2002:ac8:5f91:0:b0:3b8:6c10:f52 with SMTP id j17-20020ac85f91000000b003b86c100f52mr12774226qta.46.1675186054915; Tue, 31 Jan 2023 09:27:34 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id s1-20020ac85281000000b003b63238615fsm10105061qtn.46.2023.01.31.09.27.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 09:27:34 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 07/13] gdb: don't always print breakpoint location after failed condition check Date: Tue, 31 Jan 2023 17:27:12 +0000 Message-Id: <6a271d2d74565861813fcd7d3c0c8edb0b4e6375.1675185990.git.aburgess@redhat.com> 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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. While it is true that GDB stopped as a result of hitting breakpoint 1, I think the message GDB currently prints might give the impression that GDB 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 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 eecaeefed3e..c4fec7e8e55 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -5533,6 +5533,7 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread) else within_current_scope = false; } + CORE_ADDR pc_before_check = get_frame_pc (get_selected_frame (nullptr)); if (within_current_scope) { try @@ -5544,6 +5545,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 214a64f8de3..5ad179a089d 100644 --- a/gdb/testsuite/gdb.base/infcall-failure.exp +++ b/gdb/testsuite/gdb.base/infcall-failure.exp @@ -78,10 +78,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 @@ -168,7 +164,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\\."] -- 2.25.4