[06/16] gdb: remove inferior::{argc,argv}

Message ID 20210714045520.1623120-7-simon.marchi@polymtl.ca
State New
Headers show
Series
  • Bunch of commands related cleanups
Related show

Commit Message

Simon Marchi via Gdb-patches July 14, 2021, 4:55 a.m.
There are currently two states that the inferior args can be stored.
The main one is the `args` field, where they are stored as a single
string.  The other one is the `argc`/`argv` fields.

This last one is only used for arguments passed in GDB's
command line.  And the only outcome is that when get_inferior_args is
called, `argc`/`argv` are serialized into `args`.  So really,
`argc`/`argv` is just a staging area before moving the arguments in
`args`.

Simplify this by only keeping the `args` field.  Change
set_inferior_args_vector to immediately serialize the arguments into
`args`, work that would be done in get_inferior_args later anyway.

The only time where this work would be "wasted" is when the user passes
some arguments on the command line, but does not end up running the
program.  But that just seems unlikely.  And it's not that much work.

Change-Id: Ica0b9859397c095f6530350c8fb3c36905f2044a
---
 gdb/infcmd.c   | 24 +++++-------------------
 gdb/inferior.h |  9 ---------
 2 files changed, 5 insertions(+), 28 deletions(-)

-- 
2.32.0

Patch

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index a7b520cdd169..05115958a8f8 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -127,16 +127,8 @@  show_inferior_tty_command (struct ui_file *file, int from_tty,
 const char *
 get_inferior_args (void)
 {
-  if (current_inferior ()->argc != 0)
-    {
-      gdb::array_view<char * const> args (current_inferior ()->argv,
-					  current_inferior ()->argc);
-      std::string n = construct_inferior_arguments (args);
-      set_inferior_args (n.c_str ());
-    }
-
-  if (current_inferior ()->args == NULL)
-    current_inferior ()->args = make_unique_xstrdup ("");
+  if (current_inferior ()->args == nullptr)
+    return "";
 
   return current_inferior ()->args.get ();
 }
@@ -151,16 +143,14 @@  set_inferior_args (const char *newargs)
     current_inferior ()->args = make_unique_xstrdup (newargs);
   else
     current_inferior ()->args.reset ();
-
-  current_inferior ()->argc = 0;
-  current_inferior ()->argv = 0;
 }
 
 void
 set_inferior_args_vector (int argc, char **argv)
 {
-  current_inferior ()->argc = argc;
-  current_inferior ()->argv = argv;
+  gdb::array_view<char * const> args (argv, argc);
+  std::string n = construct_inferior_arguments (args);
+  set_inferior_args (n.c_str ());
 }
 
 /* Notice when `set args' is run.  */
@@ -490,15 +480,11 @@  run_command_1 (const char *args, int from_tty, enum run_how run_how)
       if (exec_file)
 	uiout->field_string ("execfile", exec_file);
       uiout->spaces (1);
-      /* We call get_inferior_args() because we might need to compute
-	 the value now.  */
       uiout->field_string ("infargs", get_inferior_args ());
       uiout->text ("\n");
       uiout->flush ();
     }
 
-  /* We call get_inferior_args() because we might need to compute
-     the value now.  */
   run_target->create_inferior (exec_file,
 			       std::string (get_inferior_args ()),
 			       current_inferior ()->environment.envp (),
diff --git a/gdb/inferior.h b/gdb/inferior.h
index 6662a3bde463..af03887d63b3 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -478,15 +478,6 @@  class inferior : public refcounted_object,
   /* The arguments string to use when running.  */
   gdb::unique_xmalloc_ptr<char> args;
 
-  /* The size of elements in argv.  */
-  int argc = 0;
-
-  /* The vector version of arguments.  If ARGC is nonzero,
-     then we must compute ARGS from this (via the target).
-     This is always coming from main's argv and therefore
-     should never be freed.  */
-  char **argv = NULL;
-
   /* The current working directory that will be used when starting
      this inferior.  */
   gdb::unique_xmalloc_ptr<char> cwd;