]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/record: minor clean, remove some unneeded arguments
authorAndrew Burgess <aburgess@redhat.com>
Mon, 15 Apr 2024 13:02:15 +0000 (14:02 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Wed, 17 Apr 2024 12:35:22 +0000 (13:35 +0100)
I spotted that the two functions:

  record_full_open_1
  record_full_core_open_1

both took two arguments, neither of which are used.

I stumbled onto this while reviewing how filename_completer is used.
The 'record full restore' command uses filename_completer and invokes
the cmd_record_full_restore function.

The cmd_record_full_restore function calls core_file_command and then
record_full_open, which then calls one of the above functions.

As 'record full restore' takes a filename, this is passed to
cmd_record_full_restore, which forwards the filename to both
core_file_command and record_full_open.  However, record_full_open
never actually uses the filename that is passed in.

The record_full_open function is also used for 'target record-full'.

I propose that record_full_open should no longer expect to see any
user supplied arguments passed in (it doesn't use any).  In fact, I've
added a check that if we do get any user supplied arguments we'll
throw an error.

Now that we know record_full_open isn't being passed any user
arguments we can stop passing the arguments to record_full_open_1 and
record_full_core_open_1, this will make no user visible difference as
these arguments were not used.

It is possible that a user was previously doing:

  (gdb) target record-full blah blah blah

And this previously would work fine, the 'blah blah blah' was
ignored.  Now this will give an error.  Other than this case there
should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/NEWS
gdb/record-full.c
gdb/testsuite/gdb.base/record-full-error.exp [new file with mode: 0644]

index feb3a37393a60230033db5e43d2b325df0a3bfa6..942453c7064039d8d920e322e7fd96cb0b99b741 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -36,6 +36,10 @@ set unwindonsignal on|off
 show unwindonsignal
   These commands are now aliases for the new set/show unwind-on-signal.
 
+target record-full
+  This command now gives an error if any unexpected arguments are
+  found after the command.
+
 * New commands
 
 info missing-debug-handler
index 4c3667f48bad415e9baef577d79ea5ad556930c4..2e67cf5b4280f9fb5c9aac9519c199f77c5aae12 100644 (file)
@@ -910,7 +910,7 @@ record_full_async_inferior_event_handler (gdb_client_data data)
 /* Open the process record target for 'core' files.  */
 
 static void
-record_full_core_open_1 (const char *name, int from_tty)
+record_full_core_open_1 ()
 {
   regcache *regcache = get_thread_regcache (inferior_thread ());
   int regnum = gdbarch_num_regs (regcache->arch ());
@@ -933,7 +933,7 @@ record_full_core_open_1 (const char *name, int from_tty)
 /* Open the process record target for 'live' processes.  */
 
 static void
-record_full_open_1 (const char *name, int from_tty)
+record_full_open_1 ()
 {
   if (record_debug)
     gdb_printf (gdb_stdlog, "Process record: record_full_open_1\n");
@@ -957,11 +957,14 @@ static void record_full_init_record_breakpoints (void);
 /* Open the process record target.  */
 
 static void
-record_full_open (const char *name, int from_tty)
+record_full_open (const char *args, int from_tty)
 {
   if (record_debug)
     gdb_printf (gdb_stdlog, "Process record: record_full_open\n");
 
+  if (args != nullptr)
+    error (_("Trailing junk: '%s'"), args);
+
   record_preopen ();
 
   /* Reset */
@@ -971,9 +974,9 @@ record_full_open (const char *name, int from_tty)
   record_full_list->next = NULL;
 
   if (current_program_space->core_bfd ())
-    record_full_core_open_1 (name, from_tty);
+    record_full_core_open_1 ();
   else
-    record_full_open_1 (name, from_tty);
+    record_full_open_1 ();
 
   /* Register extra event sources in the event loop.  */
   record_full_async_inferior_event_token
@@ -2520,7 +2523,7 @@ static void
 cmd_record_full_restore (const char *args, int from_tty)
 {
   core_file_command (args, from_tty);
-  record_full_open (args, from_tty);
+  record_full_open (nullptr, from_tty);
 }
 
 /* Save the execution log to a file.  We use a modified elf corefile
diff --git a/gdb/testsuite/gdb.base/record-full-error.exp b/gdb/testsuite/gdb.base/record-full-error.exp
new file mode 100644 (file)
index 0000000..0ec2dab
--- /dev/null
@@ -0,0 +1,24 @@
+# This testcase is part of GDB, the GNU debugger.
+#
+# Copyright 2024 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 an error when passing unexpected arguments to 'target
+# record-full'.
+
+gdb_start
+
+gdb_test "target record-full blah" \
+    "Trailing junk: 'blah'"