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 D0CC63851C00 for ; Fri, 7 Jul 2023 15:43:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D0CC63851C00 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=1688744588; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ICqSaI8zux/zSOpa+M17tz4kmvm1yr7+JjvrCkyTjUs=; b=gyQiQOU7WGx8f85V//+3c6j1SRBCVweKvtIwjHr0eCCWLjzlqW98T/s0Vlp5RoPTH7h91o myqo+HTJsxy8zpSxPeKpl/IIxDMac8/AVQ6VCfInkwFk3ApxekvJq80tSDMKgrJM4muy1Y 35poKthI0regFsjJp/LAO1qgAHnsreg= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-669-5ukRaZqnOPC09EVYcLdSzQ-1; Fri, 07 Jul 2023 11:43:07 -0400 X-MC-Unique: 5ukRaZqnOPC09EVYcLdSzQ-1 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-4fbcdca90dcso1446080e87.2 for ; Fri, 07 Jul 2023 08:43:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688744585; x=1691336585; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ICqSaI8zux/zSOpa+M17tz4kmvm1yr7+JjvrCkyTjUs=; b=geIZ1HWY+uLBwqBmfoKL0An7QH1piwjGBlKG6PN88zWffy382sQYo5ySkDluSEEpRK MlIFvccN7koNy+GVcQ6IIrftZNA+Rv8K4Jllm7GBrCOO7MqfOxHWNslraaGCuxMgElbE CSeFIcFcbToMuD0Z3qk021F7cl764AupZvsW1nXCBoqh8JKABcbwH5o15AD76uSB0cLL VO4QwJO43lOA83amzlTv37WIXpZ00Udaoy/QuHyuBd0j+d8ZWujJrHJAGcY2LprzWWje XvfOEWpjZ1iPYn+jlox+JNl1cOiTSICbAk2ypnQf40kFkQP2lio6SCMIOEObGQFG+3Ts MAmg== X-Gm-Message-State: ABy/qLZkZmI3hFogb3ftX+8dO6nsq2uY13/aTnylQzYvONSxJ2skUUVu FTekKk64b6OmBZm+8A55xRgz4t17sKHnJ4R0Ye5djthHdHZ3JMenvzyY8hfVpZvqR9liHK55u1f mvThHrdTKKp0ZIL81LgFAP611Zjo+0g== X-Received: by 2002:a05:6512:ac4:b0:4f9:5ff6:c06a with SMTP id n4-20020a0565120ac400b004f95ff6c06amr4573025lfu.67.1688744585298; Fri, 07 Jul 2023 08:43:05 -0700 (PDT) X-Google-Smtp-Source: APBJJlFmN0i/8FX8HkC0mxAj5ng/qYLaBitHu74OXBf7H35TWXmLzrb/KTfzwpQSIweHkwPHJ7cujw== X-Received: by 2002:a05:6512:ac4:b0:4f9:5ff6:c06a with SMTP id n4-20020a0565120ac400b004f95ff6c06amr4573009lfu.67.1688744584887; Fri, 07 Jul 2023 08:43:04 -0700 (PDT) Received: from localhost (2.72.115.87.dyn.plus.net. [87.115.72.2]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c025200b003fbca942499sm2777324wmj.14.2023.07.07.08.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 08:43:04 -0700 (PDT) From: Andrew Burgess To: Pedro Alves , gdb-patches@sourceware.org Subject: Re: [PATCHv5 01/11] gdb: include breakpoint number in testing condition error message In-Reply-To: <3012ae0b-ac62-1b19-e56a-00129205393b@palves.net> References: <24b51a1fbfc6f8b8cc52e3f90d4f36c1d44aaa6b.1678987897.git.aburgess@redhat.com> <3012ae0b-ac62-1b19-e56a-00129205393b@palves.net> Date: Fri, 07 Jul 2023 16:43:03 +0100 Message-ID: <87sf9zk9rs.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.9 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_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 List-Id: Pedro Alves writes: > Hi, > > On 2023-03-16 17:36, Andrew Burgess via Gdb-patches wrote: > >> 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) >> > > Reading this, I was thinking that we should print the breakpoint location number > as well. We do print it when presenting breakpoint stops nowadays, like: > > (top-gdb) b printf > Breakpoint 3 at 0xee680 (2 locations) > (top-gdb) r > ... > Breakpoint 3.1, ui_file::printf ... > ... > > Did you consider that and decided against? I didn't find any mention of it in previous > discussions. No, this was just an oversight, and would I think be a great improvement. The patch below implements this idea. Let me know what you think. Thanks, Andrew --- commit ead767dcb1f5023ed1ce98001672a63cc3737bdb Author: Andrew Burgess Date: Fri Jul 7 16:36:26 2023 +0100 gdb: include location number in breakpoint error message This commit improves the output of this previous commit: commit 2dc3457a454a35d0617dc1f9cc1db77468471f95 Date: Fri Oct 14 13:22:55 2022 +0100 gdb: include breakpoint number in testing condition error message The earlier commit extended the error message: Error in testing breakpoint condition: to include the breakpoint number, e.g.: Error in testing breakpoint condition 3: This commit extends takes this further, and includes the location number if the breakpoint has multiple locations, so we might now see: Error in testing breakpoint condition 3.2: Just as with how GDB reports a normal breakpoint stop, if a breakpoint only has a single location then the location number is not included, this keeps things nice and consistent. I've extended one of the tests to cover the new functionality. diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index da6c8de9d14..d898167b7e1 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -5544,9 +5544,17 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread) } catch (const gdb_exception_error &ex) { - exception_fprintf (gdb_stderr, ex, - "Error in testing condition for breakpoint %d:\n", - b->number); + int locno = bpstat_locno (bs); + if (locno != 0) + exception_fprintf + (gdb_stderr, ex, + "Error in testing condition for breakpoint %d.%d:\n", + b->number, locno); + else + 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 diff --git a/gdb/testsuite/gdb.base/bp-cond-failure.c b/gdb/testsuite/gdb.base/bp-cond-failure.c index 2a9974b47ce..8c226edd8b4 100644 --- a/gdb/testsuite/gdb.base/bp-cond-failure.c +++ b/gdb/testsuite/gdb.base/bp-cond-failure.c @@ -15,16 +15,26 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -int +static inline int __attribute__((__always_inline__)) foo () { - return 0; /* Breakpoint here. */ + return 0; /* Multi-location breakpoint here. */ +} + +static int __attribute__((noinline)) +bar () +{ + int res = foo (); /* Single-location breakpoint here. */ + + return res; } int main () { - int res = foo (); + int res = bar (); + + res = foo (); return res; } diff --git a/gdb/testsuite/gdb.base/bp-cond-failure.exp b/gdb/testsuite/gdb.base/bp-cond-failure.exp index cb572203772..bc7d8d13b9f 100644 --- a/gdb/testsuite/gdb.base/bp-cond-failure.exp +++ b/gdb/testsuite/gdb.base/bp-cond-failure.exp @@ -44,10 +44,7 @@ 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 access_type } { +proc run_test { cond_eval access_type lineno nloc } { clean_restart ${::binfile} if { ![runto_main] } { @@ -59,17 +56,23 @@ proc run_test { cond_eval access_type } { } # Setup the conditional breakpoint and record its number. - gdb_breakpoint "${::srcfile}:${::bp_line} if (*(${access_type} *) 0) == 0" + gdb_breakpoint "${::srcfile}:${lineno} if (*(${access_type} *) 0) == 0" set bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*"] + if { $nloc > 1 } { + set bp_num_pattern "${bp_num}.1" + } else { + set bp_num_pattern "${bp_num}" + } + gdb_test "continue" \ [multi_line \ "Continuing\\." \ - "Error in testing condition for breakpoint ${bp_num}:" \ + "Error in testing condition for breakpoint ${bp_num_pattern}:" \ "Cannot access memory at address 0x0" \ "" \ - "Breakpoint ${bp_num}, foo \\(\\) at \[^\r\n\]+:${::bp_line}" \ - "${::decimal}\\s+\[^\r\n\]+Breakpoint here\[^\r\n\]+"] + "Breakpoint ${bp_num_pattern}, \(foo\|bar\) \\(\\) at \[^\r\n\]+:${lineno}" \ + "${::decimal}\\s+\[^\r\n\]+ breakpoint here\\. \[^\r\n\]+"] } # If we're using a remote target then conditions could be evaulated @@ -97,8 +100,19 @@ gdb_test_multiple "show breakpoint condition-evaluation" "" { } } +# Where the breakpoint will be placed. +set bp_line_multi_loc [gdb_get_line_number "Multi-location breakpoint here"] +set bp_line_single_loc [gdb_get_line_number "Single-location breakpoint here"] + + + foreach_with_prefix access_type { "char" "short" "int" "long long" } { foreach_with_prefix cond_eval $cond_eval_modes { - run_test $cond_eval $access_type + with_test_prefix "multi-loc" { + run_test $cond_eval $access_type $bp_line_multi_loc 2 + } + with_test_prefix "single-loc" { + run_test $cond_eval $access_type $bp_line_single_loc 1 + } } }