From patchwork Mon Nov 28 11:25:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 61148 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 B72623857365 for ; Mon, 28 Nov 2022 11:26:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B72623857365 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669634801; bh=VWfsnpYMxgevKRVUj10nnQ6mpzJDV9Vo5VLTylsO0W0=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=yoX9SJSetf8SzgYDeGwUR6PwCqSq6rs9nioBSfFlKhhnMNdLKWVJM6Des2jiJ9rXN vOLoTiq6pAchygiPJOJt9CGTnHslvRfuMkLQWzdOMf0JBEODgEKhLhvPRXKvfNdV+i fG9yRPvxtfHzWAP+tmD3m0OAEJSc1P/8/4Gbzc4g= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id C8E9A3857C4F for ; Mon, 28 Nov 2022 11:25:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C8E9A3857C4F Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-55-y09zF2knOIu50jr3NHQonQ-1; Mon, 28 Nov 2022 06:25:47 -0500 X-MC-Unique: y09zF2knOIu50jr3NHQonQ-1 Received: by mail-wr1-f70.google.com with SMTP id v2-20020adfa1c2000000b002420d780a32so760646wrv.14 for ; Mon, 28 Nov 2022 03:25:47 -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=VWfsnpYMxgevKRVUj10nnQ6mpzJDV9Vo5VLTylsO0W0=; b=tNKzMMld3TBepOpmQdh2l8I9uKShm5eX6r1W+tC+h8Yo4Ml9+E+wgoL5mhdqyVims7 b6T8WjfcwDNF7o0gFYluOQLg6rSEfiasq6mNnlLCrSq+VX5Df/WXWHvIjn6KyLQeCyYC TRXs17gTtaD8H98PQHELKbTOc8adAZ8T/NjyYhzCCizHqN1YnQaeIvhogE6uVnSwoI7m /bMTSROZ1TAIuYIDhGPENET9EAzBcHIdHgA6yClGiGlCqF0cPBhfYYD21pTxLxk9CQM5 xKt8ER3FVQEhiXfyZ3bR1xh92pugRAUC2xrHd+BPf3+38das1X/ZaHH1aol3BA5HUvk+ N/qQ== X-Gm-Message-State: ANoB5plHseEJBkUbqAwtRp1UldNTeI+poyektr79lsK+jXkBofAp44HK s1B2RFd1cY6PBza/elSUm5IAW9W7A+DRa4rQR2tIggbRftj842GyEV63OijfKo/lCe/4r4Oh5gG 44kB6sgzVonPsqTynzVCgW6oqDDANUqqonOlTC619WgP3blnT4kxlmxuRZqbwiUpdwXRSAh8euQ == X-Received: by 2002:a05:600c:35c4:b0:3cf:9668:e8f8 with SMTP id r4-20020a05600c35c400b003cf9668e8f8mr28133172wmq.195.1669634745914; Mon, 28 Nov 2022 03:25:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf5zMIQUMgIaXKc/ej98LM6Rk7qhSSIbjSczeq3wftzmmRjPClkVh3D01T4Je8oEir64vX3uWA== X-Received: by 2002:a05:600c:35c4:b0:3cf:9668:e8f8 with SMTP id r4-20020a05600c35c400b003cf9668e8f8mr28133143wmq.195.1669634745580; Mon, 28 Nov 2022 03:25:45 -0800 (PST) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id b6-20020a05600010c600b0024217e7aaa7sm2462065wrx.50.2022.11.28.03.25.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 03:25:45 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 3/6] gdb: fix display of thread condition for multi-location breakpoints Date: Mon, 28 Nov 2022 11:25:35 +0000 Message-Id: <685ac9c3cc26e43c47b1a5fd3a59f7e97c5eca2b.1669634536.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 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 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" If a breakpoint with multiple locations has a thread condition, then the 'info breakpoints' output is a little messed up, here's an example of the current output: (gdb) break foo thread 1 Breakpoint 2 at 0x401114: foo. (3 locations) (gdb) break bar thread 1 Breakpoint 3 at 0x40110a: file /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c, line 32. (gdb) info breakpoints Num Type Disp Enb Address What 2 breakpoint keep y thread 1 stop only in thread 1 2.1 y 0x0000000000401114 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 2.2 y 0x0000000000401146 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 2.3 y 0x0000000000401168 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 3 breakpoint keep y 0x000000000040110a in bar at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:32 thread 1 stop only in thread 1 Notice that, at the end of the location for breakpoint 3, the 'thread 1' condition is printed. In contrast, for breakpoint 2, the 'thread 1' appears randomly, in the "What" column, though slightly offset. I believe this is a bug in GDB, in the function print_one_breakpoint_location, due to checking the local variable part_of_multiple, instead of header_of_multiple. If I fix this oversight, then the output is now: (gdb) break foo thread 1 Breakpoint 2 at 0x401114: foo. (3 locations) (gdb) break bar thread 1 Breakpoint 3 at 0x40110a: file /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c, line 32. (gdb) info breakpoints Num Type Disp Enb Address What 2 breakpoint keep y stop only in thread 1 2.1 y 0x0000000000401114 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 thread 1 2.2 y 0x0000000000401146 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 thread 1 2.3 y 0x0000000000401168 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 thread 1 3 breakpoint keep y 0x000000000040110a in bar at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:32 thread 1 stop only in thread 1 The 'thread 1' condition is now displayed at the end of each location, which makes the output the same for single location breakpoints and multi-location breakpoints. --- gdb/breakpoint.c | 2 +- gdb/testsuite/gdb.base/thread-bp-multi-loc.c | 44 ++++++++++ .../gdb.base/thread-bp-multi-loc.exp | 88 +++++++++++++++++++ 3 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.base/thread-bp-multi-loc.c create mode 100644 gdb/testsuite/gdb.base/thread-bp-multi-loc.exp diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index f0276a963c0..2ec8ca364b6 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -6467,7 +6467,7 @@ print_one_breakpoint_location (struct breakpoint *b, output_thread_groups (uiout, "thread-groups", inf_nums, mi_only); } - if (!part_of_multiple) + if (!header_of_multiple) { if (b->thread != -1) { diff --git a/gdb/testsuite/gdb.base/thread-bp-multi-loc.c b/gdb/testsuite/gdb.base/thread-bp-multi-loc.c new file mode 100644 index 00000000000..cab009c39ec --- /dev/null +++ b/gdb/testsuite/gdb.base/thread-bp-multi-loc.c @@ -0,0 +1,44 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022 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 . */ + +volatile int global_var = 0; + +__attribute__((__always_inline__)) static inline void +foo (void) +{ + int i; + + for (i = 0; i < 10; ++i) + global_var = i; +} + +static void +bar (void) +{ + global_var = 0; + foo (); +} + +int +main (void) +{ + global_var = 0; + foo (); + bar (); + foo (); + return 0; +} diff --git a/gdb/testsuite/gdb.base/thread-bp-multi-loc.exp b/gdb/testsuite/gdb.base/thread-bp-multi-loc.exp new file mode 100644 index 00000000000..9abff5866d9 --- /dev/null +++ b/gdb/testsuite/gdb.base/thread-bp-multi-loc.exp @@ -0,0 +1,88 @@ +# Copyright 2022 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 . + +# Create a multi-location breakpoint with a thread condition, then check the +# output of 'info breakpoints' to ensure that the thread condition is +# displayed correctly. + +standard_testfile + +if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { + return +} + +if ![runto_main] then { + return +} + +gdb_test_no_output "with confirm off -- delete breakpoints" + +set bp_number "" +gdb_test_multiple "break foo thread 1" "" { + -re "^break foo thread 1\r\n" { + exp_continue + } + -re "^Breakpoint ($decimal) at $hex: foo\[^\r\n\]+3 locations\[^\r\n\]+\r\n" { + set bp_number $expect_out(1,string) + exp_continue + } + -re "^$gdb_prompt $" { + gdb_assert { ![string eq $bp_number ""] } + } +} + +if { $bp_number == "" } { + unresolved "breakpoint not placed correctly" + return +} + +set saw_header false +set saw_cond false +set loc_count 0 +gdb_test_multiple "info breakpoints" "" { + -re "^info breakpoints\r\n" { + exp_continue + } + + -re "^Num\\s+\[^\r\n\]+\r\n" { + exp_continue + } + + -re "^$bp_number\\s+breakpoint\\s+keep\\s+y\\s+\\s*\r\n" { + set saw_header true + exp_continue + } + + -re "^\\s+stop only in thread 1\r\n" { + set saw_cond true + exp_continue + } + + -re "^$bp_number\\.\[123\]\\s+\[^\r\n\]+ thread 1\r\n" { + incr loc_count + exp_continue + } + + -re "^$gdb_prompt $" { + with_test_prefix $gdb_test_name { + gdb_assert { $saw_header } \ + "saw header line" + gdb_assert { $saw_cond } \ + "saw b/p condition line" + gdb_assert { $loc_count == 3 } \ + "saw all three locations" + } + } +}