From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 3/3] gdb: don't use the global thread-id in the saved breakpoints file
Date: Wed, 8 Feb 2023 15:23:30 +0000 [thread overview]
Message-ID: <be46fe0bc0e6658400ff50d36290d5c5ccc7e2dd.1675869497.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1675869497.git.aburgess@redhat.com>
I noticed that breakpoint::print_recreate_thread was printing the
global thread-id. This function is used to implement the 'save
breakpoints' command, and should be writing out suitable CLI commands
for recreating the current breakpoints. The CLI does not use global
thread-ids, but instead uses the inferior specific thread-ids,
e.g. "2.1".
This commit updates breakpoint::print_recreate_thread to use the
print_thread_id function, and adds a test for this change.
---
gdb/breakpoint.c | 5 +-
.../gdb.multi/bp-thread-specific.exp | 46 +++++++++++++++++++
2 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 6b576859592..6e3c76305e7 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -14120,7 +14120,10 @@ void
breakpoint::print_recreate_thread (struct ui_file *fp) const
{
if (thread != -1)
- gdb_printf (fp, " thread %d", thread);
+ {
+ struct thread_info *thr = find_thread_global_id (thread);
+ gdb_printf (fp, " thread %s", print_thread_id (thr));
+ }
if (task != 0)
gdb_printf (fp, " task %d", task);
diff --git a/gdb/testsuite/gdb.multi/bp-thread-specific.exp b/gdb/testsuite/gdb.multi/bp-thread-specific.exp
index 777fcf85ab0..6a7cd044af4 100644
--- a/gdb/testsuite/gdb.multi/bp-thread-specific.exp
+++ b/gdb/testsuite/gdb.multi/bp-thread-specific.exp
@@ -15,6 +15,9 @@
# Check that GDB uses the correct thread-id when describing multiple
# thread specific breakpoints at the same location.
+#
+# Also check that the correct thread-ids are used in the saved
+# breakpoints file.
# The plain remote target can't do multiple inferiors.
require !use_gdb_stub
@@ -59,3 +62,46 @@ gdb_test "break foo thread 1.1" \
"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\\)"]
+
+# Save the breakpoints into a file.
+if {[is_remote host]} {
+ set bps bps
+} else {
+ set bps [standard_output_file bps]
+}
+
+remote_file host delete "$bps"
+gdb_test "save breakpoint $bps" "" "save breakpoint to bps"
+
+if {[is_remote host]} {
+ set bps [remote_upload host bps [standard_output_file bps]]
+}
+
+# Now dig through the saved breakpoints file and check that the
+# thread-ids were written out correctly. First open the saved
+# breakpoints and read them into a list.
+set fh [open $bps]
+set lines [split [read $fh] "\n"]
+close $fh
+
+# Except the list created from the saved breakpoints file will have a
+# blank line entry at the end, so remove it now.
+gdb_assert {[string equal [lindex $lines end] ""]} \
+ "check last item was an empty line"
+set lines [lrange $lines 0 end-1]
+
+# These are the lines we expect in the saved breakpoints file, in the
+# order that we expect them. These are strings, not regexps.
+set expected_results \
+ [list \
+ "break -qualified main" \
+ "break foo thread 2.1" \
+ "break foo thread 1.1"]
+
+# Now check that the files contents (in LINES) matches the
+# EXPECTED_RESULTS.
+gdb_assert {[llength $lines] == [llength $expected_results]} \
+ "correct number of lines in saved breakpoints file"
+foreach a $lines b $expected_results {
+ gdb_assert {[string equal $a $b]} "line '$b'"
+}
--
2.25.4
next prev parent reply other threads:[~2023-02-08 15:23 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-08 15:23 [PATCH 0/3] Avoid printing global thread-id in CLI command output Andrew Burgess
2023-02-08 15:23 ` [PATCH 1/3] gdb: don't print global thread-id to CLI in describe_other_breakpoints Andrew Burgess
2023-02-08 17:55 ` Pedro Alves
2023-02-11 17:41 ` Andrew Burgess
2023-02-08 15:23 ` [PATCH 2/3] gdb: show task number " Andrew Burgess
2023-02-08 17:55 ` Pedro Alves
2023-02-11 17:42 ` Andrew Burgess
2023-02-08 15:23 ` Andrew Burgess [this message]
2023-02-08 17:55 ` [PATCH 3/3] gdb: don't use the global thread-id in the saved breakpoints file Pedro Alves
2023-02-10 19:22 ` Andrew Burgess
2023-02-17 17:49 ` Pedro Alves
2023-02-27 19:45 ` Andrew Burgess
2023-03-16 17:06 ` Andrew Burgess
2023-03-17 18:01 ` Pedro Alves
2023-03-20 10:38 ` Andrew Burgess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=be46fe0bc0e6658400ff50d36290d5c5ccc7e2dd.1675869497.git.aburgess@redhat.com \
--to=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).