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 DE0BC3858C78 for ; Thu, 16 Mar 2023 17:37:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE0BC3858C78 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=1678988235; 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=otfXOdbch5UuxEXD5hmpYp2/5PDphe7imTs6MGGPZqg=; b=XPY/dO+KI7zjjDB9yEFGRv/a1WkLDcWEhtOUC9xlEq6QsJR2EylcyTkxYsyRcurTXKLggb YrfjnSSemoVJhyO6E0lAPI8YchRtYtkZKfFMmfAuu5+Yf/nbWVoLMDHmZdOI4iClJsjTeO u5xTTs9v8S6Ar948lqQeZ4x15fVE9bw= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-115-6JgAiQ_zMOeEFM_p9KCJ3Q-1; Thu, 16 Mar 2023 13:37:14 -0400 X-MC-Unique: 6JgAiQ_zMOeEFM_p9KCJ3Q-1 Received: by mail-ed1-f71.google.com with SMTP id fi8-20020a056402550800b004a26cc7f6cbso4088483edb.4 for ; Thu, 16 Mar 2023 10:37:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678988232; 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=otfXOdbch5UuxEXD5hmpYp2/5PDphe7imTs6MGGPZqg=; b=Q6xxYnfUuOHIPVjw2sAqnvhCvh3JFxAV3lWRsZN0WrUZKViEt0cMJT3xYlSjX6aYgi EcoBj2ofWFqVBdySrRJjv56n5NjMq/8riI4K5IIZ6jMoxAQue6QTZjDoUgwIazdXpuBZ 2olTZNDADSs4KYHPNB4/8qm8a7TDEbavyRsmB6fjYh32e9RG4mYSvBbv/XR9ns4msHeU MVCjvLXZsGp73ngd08D02SQHNI5CiclV3l0JS4WfwtrYcVYPmtRlGMZC/7kc6pHumuTn F2fbkSBlOfT/zhWgLu1RrYaLmAR3jqrmbxwxZslPGIsx2Qkk+2tSLUNZ2xymDwqeAyu7 zENw== X-Gm-Message-State: AO0yUKUTDn/r2pSVaIh7YMf0YI3zpVcs9gjwCdHgiyTuEvP8fhaXESGk tn7j63l2GVtyFrFm0g/ilTk7+XzcJNHY+HT2zjTEV8+um0IS0+3aL/WRvinoW0g8DHpFRIFikmp lE9FOw/Rhp9XFPzit+XuZ8v7xszX407DBQIujNpex4j8AjxsuZM/9Vk6TL1JEnq6BYk1fafl3qr mqly4s2w== X-Received: by 2002:a17:906:60d2:b0:877:8a55:2a26 with SMTP id f18-20020a17090660d200b008778a552a26mr9161193ejk.60.1678988232271; Thu, 16 Mar 2023 10:37:12 -0700 (PDT) X-Google-Smtp-Source: AK7set+w5jtCAhTkEi0Rgb6Wgl1YSFUwBJHfAd8kUyDEa8NnjSC11rEASEa8YsaI9Z6cA5pux0uX3A== X-Received: by 2002:a17:906:60d2:b0:877:8a55:2a26 with SMTP id f18-20020a17090660d200b008778a552a26mr9161174ejk.60.1678988231849; Thu, 16 Mar 2023 10:37:11 -0700 (PDT) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id d20-20020a1709063ed400b008d1693c212csm4054306ejj.8.2023.03.16.10.37.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 10:37:11 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv5 01/11] gdb: include breakpoint number in testing condition error message Date: Thu, 16 Mar 2023 17:36:56 +0000 Message-Id: <24b51a1fbfc6f8b8cc52e3f90d4f36c1d44aaa6b.1678987897.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.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,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: When GDB fails to test the condition of a conditional breakpoint, for whatever reason, the error message looks like this: (gdb) break foo if (*(int *) 0) == 1 Breakpoint 1 at 0x40111e: file bpcond.c, line 11. (gdb) r Starting program: /tmp/bpcond Error in testing breakpoint condition: Cannot access memory at address 0x0 Breakpoint 1, foo () at bpcond.c:11 11 int a = 32; (gdb) The line I'm interested in for this commit is this one: Error in testing breakpoint condition: In the case above we can figure out that the problematic breakpoint was #1 because in the final line of the message GDB reports the stop a breakpoint #1. However, in the next few patches I plan to change this. In some cases I don't think it makes sense for GDB to report the stop as being at breakpoint #1, consider this case: (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 breakpoint condition: 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 (some_func) will be abandoned. When the function is done executing, GDB will silently stop. Program received signal SIGSEGV, Segmentation fault. Breakpoint 1, 0x0000000000401116 in some_func () at bpcond.c:5 5 return *p; (gdb) Notice that, the final lines of output report the stop as being at breakpoint #1, even though we are actually located within some_func. I find this behaviour confusing, and propose that this should be changed. However, if I make that change then every reference to breakpoint #1 will be lost from the error message. So, in this commit, in preparation for the later commits, I propose to change the 'Error in testing breakpoint condition:' line to this: Error in testing condition for breakpoint NUMBER: where NUMBER will be filled in as appropriate. Here's the first example with the updated error: (gdb) break foo if (*(int *) 0) == 0 Breakpoint 1 at 0x40111e: file bpcond.c, line 11. (gdb) r Starting program: /tmp/bpcond Error in testing condition for breakpoint 1: Cannot access memory at address 0x0 Breakpoint 1, foo () at bpcond.c:11 11 int a = 32; (gdb) The breakpoint number does now appear twice in the output, but I don't see that as a negative. This commit just changes the one line of the error, and updates the few tests that either included the old error in comments, or actually checked for the error in the expected output. As the only test that checked the line I modified is a Python test, I've added a new test that doesn't rely on Python that checks the error message in detail. While working on the new test, I spotted that it would fail when run with native-gdbserver and native-extended-gdbserver target boards. This turns out to be due to a gdbserver bug. To avoid cluttering this commit I've added a work around to the new test script so that the test passes for the remote boards, in the next few commits I will fix gdbserver, and update the test script to remove the work around. --- gdb/breakpoint.c | 3 +- gdb/testsuite/gdb.base/bp-cond-failure.c | 30 +++++ gdb/testsuite/gdb.base/bp-cond-failure.exp | 112 ++++++++++++++++++ .../gdb.base/catch-signal-siginfo-cond.exp | 2 +- gdb/testsuite/gdb.base/gnu-ifunc.exp | 2 +- .../gdb.python/py-finish-breakpoint.exp | 2 +- 6 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 gdb/testsuite/gdb.base/bp-cond-failure.c create mode 100644 gdb/testsuite/gdb.base/bp-cond-failure.exp diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index abee22cd162..dcd42e6b2e2 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -5543,7 +5543,8 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread) catch (const gdb_exception_error &ex) { exception_fprintf (gdb_stderr, ex, - "Error in testing breakpoint condition:\n"); + "Error in testing condition for breakpoint %d:\n", + b->number); } } else diff --git a/gdb/testsuite/gdb.base/bp-cond-failure.c b/gdb/testsuite/gdb.base/bp-cond-failure.c new file mode 100644 index 00000000000..2a9974b47ce --- /dev/null +++ b/gdb/testsuite/gdb.base/bp-cond-failure.c @@ -0,0 +1,30 @@ +/* Copyright 2022-2023 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int +foo () +{ + return 0; /* Breakpoint here. */ +} + +int +main () +{ + int res = foo (); + + return res; +} diff --git a/gdb/testsuite/gdb.base/bp-cond-failure.exp b/gdb/testsuite/gdb.base/bp-cond-failure.exp new file mode 100644 index 00000000000..b528ccce4ad --- /dev/null +++ b/gdb/testsuite/gdb.base/bp-cond-failure.exp @@ -0,0 +1,112 @@ +# Copyright 2022-2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Check the format of the error message given when a breakpoint +# condition fails. +# +# In this case the breakpoint condition does not make use of inferior +# function calls, instead, the expression used for the breakpoint +# condition will throw an error when evaluated. +# +# We check that the correct breakpoint number appears in the error +# message, and that the error is reported at the correct source +# location. + +standard_testfile + +if { [prepare_for_testing "failed to prepare" ${binfile} "${srcfile}" \ + {debug}] == -1 } { + return +} + +# Run to main so that we connect to the target if using 'target +# remote'. This means that the is_address_zero_readable, and the +# 'show breakpoint condition-evaluation' checks below will be +# performed with the remote connection in place. +if { ![runto_main] } { + return -1 +} + +# This test relies on reading address zero triggering a SIGSEGV. +if { [is_address_zero_readable] } { + return +} + +# Where the breakpoint will be placed. +set bp_line [gdb_get_line_number "Breakpoint here"] + +proc run_test { cond_eval } { + clean_restart ${::binfile} + + if { ![runto_main] } { + return -1 + } + + if { $cond_eval ne "auto" } { + gdb_test_no_output "set breakpoint condition-evaluation ${cond_eval}" + } + + # Setup the conditional breakpoint and record its number. + gdb_breakpoint "${::srcfile}:${::bp_line} if (*(int *) 0) == 0" + set bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*"] + + gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + "Error in testing condition for breakpoint ${bp_num}:" \ + "Cannot access memory at address 0x0" \ + "" \ + "Breakpoint ${bp_num}, foo \\(\\) at \[^\r\n\]+:${::bp_line}" \ + "${::decimal}\\s+\[^\r\n\]+Breakpoint here\[^\r\n\]+"] +} + +# If we're using a remote target then conditions could be evaulated +# locally on the host, or on the remote target. Otherwise, conditions +# are always evaluated locally. +# +# Using "auto" will select the target if the target supports condition +# evaluation, otherwise, the local host will be used. +# +# So, we always include "auto", but then we look at the output of +# 'show breakpoint condition-evaluation', if this tells us that "auto" +# is using the target, then we specifically add "host" to the list of +# modes to check. + +set cond_eval_modes { "auto" } + +gdb_test_multiple "show breakpoint condition-evaluation" "" { + -re -wrap "Breakpoint condition evaluation mode is auto \\(currently target\\)\\." { + + ## NOTE: Instead of testing with "auto" and "host" in this + ## case we only test with "host". This is because a GDB bug + ## prevents the "auto" (a.k.a. target) mode from working. + ## + ## Don't worry, this will be fixed in a later commit, and this + ## comment will be removed at that time. + ## + ## lappend cond_eval_modes "host" + + set cond_eval_modes { "host" } + pass $gdb_test_name + } + + -re -wrap "Breakpoint condition evaluation mode is auto \\(currently host\\)\\." { + pass $gdb_test_name + } +} + +foreach_with_prefix cond_eval $cond_eval_modes { + run_test $cond_eval +} diff --git a/gdb/testsuite/gdb.base/catch-signal-siginfo-cond.exp b/gdb/testsuite/gdb.base/catch-signal-siginfo-cond.exp index 7a9452f2d55..86c322372c2 100644 --- a/gdb/testsuite/gdb.base/catch-signal-siginfo-cond.exp +++ b/gdb/testsuite/gdb.base/catch-signal-siginfo-cond.exp @@ -18,7 +18,7 @@ # # (gdb) continue # Continuing. -# Error in testing breakpoint condition: +# Error in testing condition for breakpoint NUM: # Selected thread is running. # # Catchpoint 3 (signal SIGUSR1), 0x0000003615e35877 in __GI_raise (sig=10) at raise.c:56 diff --git a/gdb/testsuite/gdb.base/gnu-ifunc.exp b/gdb/testsuite/gdb.base/gnu-ifunc.exp index 0a435806409..22462bea233 100644 --- a/gdb/testsuite/gdb.base/gnu-ifunc.exp +++ b/gdb/testsuite/gdb.base/gnu-ifunc.exp @@ -281,7 +281,7 @@ proc misc_tests {resolver_attr resolver_debug final_debug} { # Also test a former patch regression: # Continuing. - # Error in testing breakpoint condition: + # Error in testing condition for breakpoint NUM: # Attempt to take address of value not located in memory. # # Breakpoint 2, main () at ./gdb.base/gnu-ifunc.c:33 diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint.exp b/gdb/testsuite/gdb.python/py-finish-breakpoint.exp index b6bd7a63c8f..e5a46874afd 100644 --- a/gdb/testsuite/gdb.python/py-finish-breakpoint.exp +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint.exp @@ -188,7 +188,7 @@ with_test_prefix "finish in normal frame" { gdb_test "python TestBreakpoint()" "TestBreakpoint init" "set BP in condition" gdb_test "continue" \ - "test don't stop: 1.*test don't stop: 2.*test stop.*Error in testing breakpoint condition.*The program being debugged stopped while in a function called from GDB.*" \ + "test don't stop: 1.*test don't stop: 2.*test stop.*Error in testing condition for breakpoint ${::decimal}.*The program being debugged stopped while in a function called from GDB.*" \ "stop in condition function" gdb_test "continue" "Continuing.*" "finish condition evaluation" -- 2.25.4