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 42FEF3858D39 for ; Wed, 8 Feb 2023 15:23:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 42FEF3858D39 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=1675869817; 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=QVGPM7c7kDUIEBxvjBRYm5lR90tv6mFdHD10HmQyOJ4=; b=EAYneXCz7aoXbTi/bJwGWtjAB5/m9YdB8W/NRffIe8Bnlb3p54nvkSdi7gWkOy8iZxFqSm CQM8LcM788EqGvs1ZqQUHs0B/T4zH7gVGsymzweJwiHnr+g9Sjnq5UIahN2kllEeyJpTe3 d1qQgjpVLJcLR3nkkmFop5Ot86J9AV8= 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-587-WZiLMzgIPUOv2mJEDEF_vA-1; Wed, 08 Feb 2023 10:23:36 -0500 X-MC-Unique: WZiLMzgIPUOv2mJEDEF_vA-1 Received: by mail-qk1-f198.google.com with SMTP id g6-20020ae9e106000000b00720f9e6e3e2so12449820qkm.13 for ; Wed, 08 Feb 2023 07:23:36 -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=QVGPM7c7kDUIEBxvjBRYm5lR90tv6mFdHD10HmQyOJ4=; b=p6uOgOIeO119NGypgMtvmGhQQCj+PORK8PnYCJozwDMXHwme61w7xeXkNN1gGkh5mr Plfrxtt5HyxHCQ7Q5w+GkbpqKu56KIJOIcXzGMsvR10ciHrLz9p8+tsW9df68ZEDI3Zi 9RljysnwMhlhz9NtI8iM1BHkqu5OkS0Iw+eKZVN1nm2trZaq8vUxrHXKCxwHbgLGGzax U7DaTGsW2/r/fealfshGhiJYgc0DivboFvc/VTvAPmlGRh0c16JoxNGbwLHx88bqRiWy jR0HKxcqRhKM9DLDM9vejaoSC2LFwrMxItdKa5JGWeAONdlzdie0g6IuscrCV9kAHT8Z lh1g== X-Gm-Message-State: AO0yUKVsYmm0RrRtWvqZsv+Io8HQ8lUYyWRYvm/SvZOce6yE+RPPFlKG auGQsYTGCKHKawiVdDtc8nVwvejkrMgpK+voHpvTaPwAmei8gPKYk67x2W/r5VyHKr51W2jnNAE /oT84UN90Ric/iyKzu1GhakzcsP9/dTR7xVc/v7LFI+2rrFJsCkjpt3d5lPGpZ4AgYBluyXRNsO d5Vfc= X-Received: by 2002:a05:6214:1c09:b0:56b:377e:88a7 with SMTP id u9-20020a0562141c0900b0056b377e88a7mr14985152qvc.21.1675869815982; Wed, 08 Feb 2023 07:23:35 -0800 (PST) X-Google-Smtp-Source: AK7set9oeYUS02O1xrWU0ubEQWIzLkoAsCYn3GWj24cG2SJFyAlyVCofMuQvNzqU671FU1Lw9JE+sQ== X-Received: by 2002:a05:6214:1c09:b0:56b:377e:88a7 with SMTP id u9-20020a0562141c0900b0056b377e88a7mr14985110qvc.21.1675869815647; Wed, 08 Feb 2023 07:23:35 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id u20-20020ae9c014000000b00720750365b9sm11627921qkk.129.2023.02.08.07.23.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 07:23:35 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/3] gdb: don't print global thread-id to CLI in describe_other_breakpoints Date: Wed, 8 Feb 2023 15:23:28 +0000 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 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: I noticed that describe_other_breakpoints was printing the global thread-id to the CLI. For CLI output we should be printing the inferior local thread-id (e.g. "2.1"). This can be seen in the following GDB session: (gdb) info threads Id Target Id Frame 1.1 Thread 4065742.4065742 "bp-thread-speci" main () at /tmp/bp-thread-specific.c:27 * 2.1 Thread 4065743.4065743 "bp-thread-speci" main () at /tmp/bp-thread-specific.c:27 (gdb) break foo thread 2.1 Breakpoint 3 at 0x40110a: foo. (2 locations) (gdb) break foo thread 1.1 Note: breakpoint 3 (thread 2) also set at pc 0x40110a. Note: breakpoint 3 (thread 2) also set at pc 0x40110a. Breakpoint 4 at 0x40110a: foo. (2 locations) Notice that GDB says: Note: breakpoint 3 (thread 2) also set at pc 0x40110a. The 'thread 2' in here is using the global thread-id, we should instead say 'thread 2.1' which corresponds to how the user specified the breakpoint. This commit fixes this issue and adds a test. --- gdb/breakpoint.c | 5 +- gdb/testsuite/gdb.multi/bp-thread-specific.c | 28 +++++++++ .../gdb.multi/bp-thread-specific.exp | 61 +++++++++++++++++++ 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.multi/bp-thread-specific.c create mode 100644 gdb/testsuite/gdb.multi/bp-thread-specific.exp diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index adf38e7d722..701555a060e 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -7045,7 +7045,10 @@ describe_other_breakpoints (struct gdbarch *gdbarch, if (b->thread == -1 && thread != -1) gdb_printf (" (all threads)"); else if (b->thread != -1) - gdb_printf (" (thread %d)", b->thread); + { + struct thread_info *thr = find_thread_global_id (b->thread); + gdb_printf (" (thread %s)", print_thread_id (thr)); + } gdb_printf ("%s%s ", ((b->enable_state == bp_disabled || b->enable_state == bp_call_disabled) diff --git a/gdb/testsuite/gdb.multi/bp-thread-specific.c b/gdb/testsuite/gdb.multi/bp-thread-specific.c new file mode 100644 index 00000000000..51b6492085f --- /dev/null +++ b/gdb/testsuite/gdb.multi/bp-thread-specific.c @@ -0,0 +1,28 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 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 . */ + +int +foo () +{ + return 0; +} + +int +main () +{ + return foo (); +} diff --git a/gdb/testsuite/gdb.multi/bp-thread-specific.exp b/gdb/testsuite/gdb.multi/bp-thread-specific.exp new file mode 100644 index 00000000000..777fcf85ab0 --- /dev/null +++ b/gdb/testsuite/gdb.multi/bp-thread-specific.exp @@ -0,0 +1,61 @@ +# Copyright 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 that GDB uses the correct thread-id when describing multiple +# thread specific breakpoints at the same location. + +# The plain remote target can't do multiple inferiors. +require !use_gdb_stub + +standard_testfile + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile]} { + return -1 +} + +if {![runto_main]} { + return -1 +} + +gdb_test "add-inferior -exec ${binfile}" "Added inferior 2.*" "add inferior 2" +gdb_test "inferior 2" + +if {![runto_main]} { + return -1 +} + +gdb_test "info threads" \ + [multi_line \ + " Id\\s+Target Id\\s+Frame\\s*" \ + " 1\\.1\\s+\[^\r\n\]+" \ + "\\* 2\\.1\\s+\[^\r\n\]+"] \ + "check we have the expected threads" + +# Set the first breakpoint. Currently this is going to insert at two +# locations ('foo' in both inferiors) even though only one of those +# locations will ever trigger ('foo' in inferior 2). +gdb_test "break foo thread 2.1" \ + "Breakpoint $decimal at $hex: foo\\. \\(2 locations\\)" + +set bpnum [get_integer_valueof "\$bpnum" "INVALID"] + +# Now set another breakpoint that will be at the same location as the +# earlier breakpoint. Check that the thread-id used when describing +# the earlier breakpoints is correct. +gdb_test "break foo thread 1.1" \ + [multi_line \ + "Note: breakpoint $bpnum \\(thread 2.1\\) also set at pc $hex\\." \ + "Note: breakpoint $bpnum \\(thread 2.1\\) also set at pc $hex\\." \ + "Breakpoint $decimal at $hex: foo\\. \\(2 locations\\)"] -- 2.25.4