Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH] [gdb/breakpoints] Don't ignore <file> in rbreak <file>:<regexp>
Date: Tue, 28 Apr 2026 12:46:57 +0200	[thread overview]
Message-ID: <20260428104657.1402486-1-tdevries@suse.de> (raw)

PR breakpoints/34112 reports that "rbreak <file>:<regexp>" sets breakpoints in
files other than <file>.

This is a regression since commit c4c093a31f6 ("Make
global_symbol_searcher::filenames private"), which did:
...
   if (file_name != nullptr)
-    spec.filenames.push_back (file_name);
+    spec.add_filename (std::move (file_name));
...

The std::move nullifies file_name, so a subsequent file_name check:
...
	  if (file_name != nullptr)
...
now always evaluates to false.

Fix this by:
- introducing a variable bool file_name_p, initialized before the
  std::move, and
- using that instead.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34112
---
 gdb/symtab.c                      |  9 +++++++--
 gdb/testsuite/gdb.base/rbreak-2.c | 28 ++++++++++++++++++++++++++
 gdb/testsuite/gdb.base/rbreak.c   | 30 ++++++++++++++++++++++++++++
 gdb/testsuite/gdb.base/rbreak.exp | 33 +++++++++++++++++++++++++++++++
 4 files changed, 98 insertions(+), 2 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/rbreak-2.c
 create mode 100644 gdb/testsuite/gdb.base/rbreak.c
 create mode 100644 gdb/testsuite/gdb.base/rbreak.exp

diff --git a/gdb/symtab.c b/gdb/symtab.c
index 357b8e63b19..3c10e1fd750 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -5440,8 +5440,13 @@ rbreak_command (const char *regexp, int from_tty)
 	}
     }
 
+  /* Compute this property now.  We want to use the property after
+     std::move (file_name), but at that point we can no longer compute it
+     because the std::move nullifies file_name.  */
+  bool file_name_p = file_name != nullptr;
+
   global_symbol_searcher spec (SEARCH_FUNCTION_DOMAIN, regexp);
-  if (file_name != nullptr)
+  if (file_name_p)
     spec.add_filename (std::move (file_name));
   std::vector<symbol_search> symbols = spec.search ();
 
@@ -5454,7 +5459,7 @@ rbreak_command (const char *regexp, int from_tty)
       std::string name;
       if (p.msymbol.minsym == nullptr)
 	{
-	  if (file_name != nullptr)
+	  if (file_name_p)
 	    {
 	      struct symtab *symtab = p.symbol->symtab ();
 	      const char *fullname = symtab_to_fullname (symtab);
diff --git a/gdb/testsuite/gdb.base/rbreak-2.c b/gdb/testsuite/gdb.base/rbreak-2.c
new file mode 100644
index 00000000000..f0d30df2f3c
--- /dev/null
+++ b/gdb/testsuite/gdb.base/rbreak-2.c
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2026 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 <http://www.gnu.org/licenses/>.  */
+
+static int
+foo (void)
+{
+  return 0;
+}
+
+int
+bar (void)
+{
+  return foo ();
+}
diff --git a/gdb/testsuite/gdb.base/rbreak.c b/gdb/testsuite/gdb.base/rbreak.c
new file mode 100644
index 00000000000..9df951f3397
--- /dev/null
+++ b/gdb/testsuite/gdb.base/rbreak.c
@@ -0,0 +1,30 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2026 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 <http://www.gnu.org/licenses/>.  */
+
+static int
+foo (void)
+{
+  return 1;
+}
+
+extern int bar (void);
+
+int
+main (void)
+{
+  return foo () + bar ();
+}
diff --git a/gdb/testsuite/gdb.base/rbreak.exp b/gdb/testsuite/gdb.base/rbreak.exp
new file mode 100644
index 00000000000..16c7e83cd49
--- /dev/null
+++ b/gdb/testsuite/gdb.base/rbreak.exp
@@ -0,0 +1,33 @@
+#   Copyright 2026 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 <http://www.gnu.org/licenses/>.
+
+# Check rbreak <file>:<regexp> command.
+
+standard_testfile .c -2.c
+
+if { [prepare_for_testing "failed to prepare" $testfile \
+	  [list $srcfile $srcfile2]] } {
+    return -1
+}
+
+# Regression test for PR34112.  Check that "rbreak $srcfile:foo" doesn't set
+# a breakpoint on $srcfile2:foo.
+set re_line \
+    [quotemeta \
+	 "Breakpoint @DECIMAL at @HEX: file @...$srcfile, line @DECIMAL."]
+gdb_test "rbreak $srcfile:foo" \
+    [multi_line \
+	 $re_line \
+	 ".*"]

base-commit: 986e397e3a42f114c8dd81f544782f040210dac2
-- 
2.51.0


             reply	other threads:[~2026-04-28 10:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-28 10:46 Tom de Vries [this message]
2026-04-28 13:52 ` Tom Tromey

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=20260428104657.1402486-1-tdevries@suse.de \
    --to=tdevries@suse.de \
    --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