Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Paul Pluzhnikov" <ppluzhnikov@google.com>
To: "Joel Brobecker" <brobecker@adacore.com>
Cc: "Tom Tromey" <tromey@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [patch] Re: GDB aborts on missing command args. Which way to fix?
Date: Fri, 03 Oct 2008 16:39:00 -0000	[thread overview]
Message-ID: <8ac60eac0810030938i33a0671dx2d2ea3e2e82368bc@mail.gmail.com> (raw)
In-Reply-To: <20081003070352.GR3665@adacore.com>

[-- Attachment #1: Type: text/plain, Size: 216 bytes --]

On Fri, Oct 3, 2008 at 12:03 AM, Joel Brobecker <brobecker@adacore.com> wrote:

> Your patch is pre-approved with the corrections mentioned above.

Thanks for the review. Checked in as attached.

-- 
Paul Pluzhnikov

[-- Attachment #2: gdb-buildargv-20081003.txt --]
[-- Type: text/plain, Size: 15473 bytes --]

2008-10-03  Paul Pluzhnikov  <ppluzhnikov@google.com>
	
	* utils.c, defs.h (gdb_buildargv): New fn. Wrap buildargv
	and check for out-of-memory condition.
	* exec.c (exec_file_command): Call it.
	* infrun.c (handle_command, xdb_handle_command): Likewise.
	* interps.c (interpreter_exec_cmd): Likewise.
	* linux-nat.c (linux_nat_info_proc_cmd): Likewise.
	* procfs.c (info_proc_cmd): Likewise.
	* remote-mips.c (common_open): Likewise.
	* remote-sim.c (gdbsim_kill, gdbsim_create_inferior)
	(gdbsim_open): Likewise.
	* remote.c (extended_remote_run, remote_put_command)
	(remote_get_command, remote_delete_command): Likewise.
	* ser-mingw.c (pipe_windows_open): Likesise.
	* source.c (add_path, show_substitute_path_command)
	(unset_substitute_path_command, set_substitute_path_command):
	Likewise.
	* stack.c (backtrace_command): Likewise.
	* symfile.c (symbol_file_command, generic_load)
	(add_symbol_file_command): Likesise.
	* symmisc.c (maintenance_print_symbols, maintenance_print_psymbols)
	(maintenance_print_msymbols): Likewise.

Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.237
diff -u -p -u -r1.237 defs.h
--- defs.h	14 Sep 2008 06:37:18 -0000	1.237
+++ defs.h	3 Oct 2008 16:28:34 -0000
@@ -405,6 +405,8 @@ ULONGEST strtoulst (const char *num, con
 
 char *ldirname (const char *filename);
 
+char **gdb_buildargv (const char *);
+
 /* From demangle.c */
 
 extern void set_demangling_style (char *);
Index: exec.c
===================================================================
RCS file: /cvs/src/src/gdb/exec.c,v
retrieving revision 1.77
diff -u -p -u -r1.77 exec.c
--- exec.c	5 Sep 2008 11:37:17 -0000	1.77
+++ exec.c	3 Oct 2008 16:28:34 -0000
@@ -302,10 +302,7 @@ exec_file_command (char *args, int from_
       /* Scan through the args and pick up the first non option arg
          as the filename.  */
 
-      argv = buildargv (args);
-      if (argv == NULL)
-        nomem (0);
-
+      argv = gdb_buildargv (args);
       make_cleanup_freeargv (argv);
 
       for (; (*argv != NULL) && (**argv == '-'); argv++)
Index: infrun.c
===================================================================
RCS file: /cvs/src/src/gdb/infrun.c,v
retrieving revision 1.323
diff -u -p -u -r1.323 infrun.c
--- infrun.c	2 Oct 2008 15:48:06 -0000	1.323
+++ infrun.c	3 Oct 2008 16:28:35 -0000
@@ -4070,11 +4070,7 @@ handle_command (char *args, int from_tty
 
   /* Break the command line up into args. */
 
-  argv = buildargv (args);
-  if (argv == NULL)
-    {
-      nomem (0);
-    }
+  argv = gdb_buildargv (args);
   old_chain = make_cleanup_freeargv (argv);
 
   /* Walk through the args, looking for signal oursigs, signal names, and
@@ -4231,13 +4227,12 @@ xdb_handle_command (char *args, int from
   char **argv;
   struct cleanup *old_chain;
 
+  if (args == NULL)
+    error_no_arg (_("xdb command"));
+
   /* Break the command line up into args. */
 
-  argv = buildargv (args);
-  if (argv == NULL)
-    {
-      nomem (0);
-    }
+  argv = gdb_buildargv (args);
   old_chain = make_cleanup_freeargv (argv);
   if (argv[1] != (char *) NULL)
     {
Index: interps.c
===================================================================
RCS file: /cvs/src/src/gdb/interps.c,v
retrieving revision 1.28
diff -u -p -u -r1.28 interps.c
--- interps.c	28 Jul 2008 17:53:52 -0000	1.28
+++ interps.c	3 Oct 2008 16:28:35 -0000
@@ -371,20 +371,15 @@ interpreter_exec_cmd (char *args, int fr
   unsigned int i;
   int old_quiet, use_quiet;
 
-  prules = buildargv (args);
-  if (prules == NULL)
-    {
-      error (_("unable to parse arguments"));
-    }
+  if (args == NULL)
+    error_no_arg (_("interpreter-exec command"));
+
+  prules = gdb_buildargv (args);
+  make_cleanup_freeargv (prules);
 
   nrules = 0;
-  if (prules != NULL)
-    {
-      for (trule = prules; *trule != NULL; trule++)
-	{
-	  nrules++;
-	}
-    }
+  for (trule = prules; *trule != NULL; trule++)
+    nrules++;
 
   if (nrules < 2)
     error (_("usage: interpreter-exec <interpreter> [ <command> ... ]"));
Index: linux-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/linux-nat.c,v
retrieving revision 1.106
diff -u -p -u -r1.106 linux-nat.c
--- linux-nat.c	25 Sep 2008 14:13:44 -0000	1.106
+++ linux-nat.c	3 Oct 2008 16:28:35 -0000
@@ -3591,10 +3591,8 @@ linux_nat_info_proc_cmd (char *args, int
   if (args)
     {
       /* Break up 'args' into an argv array.  */
-      if ((argv = buildargv (args)) == NULL)
-	nomem (0);
-      else
-	make_cleanup_freeargv (argv);
+      argv = gdb_buildargv (args);
+      make_cleanup_freeargv (argv);
     }
   while (argv != NULL && *argv != NULL)
     {
Index: procfs.c
===================================================================
RCS file: /cvs/src/src/gdb/procfs.c,v
retrieving revision 1.94
diff -u -p -u -r1.94 procfs.c
--- procfs.c	22 Sep 2008 15:21:30 -0000	1.94
+++ procfs.c	3 Oct 2008 16:28:35 -0000
@@ -5853,10 +5853,8 @@ info_proc_cmd (char *args, int from_tty)
   old_chain = make_cleanup (null_cleanup, 0);
   if (args)
     {
-      if ((argv = buildargv (args)) == NULL)
-	nomem (0);
-      else
-	make_cleanup_freeargv (argv);
+      argv = gdb_buildargv (args);
+      make_cleanup_freeargv (argv);
     }
   while (argv != NULL && *argv != NULL)
     {
Index: remote-mips.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-mips.c,v
retrieving revision 1.90
diff -u -p -u -r1.90 remote-mips.c
--- remote-mips.c	4 Sep 2008 22:49:30 -0000	1.90
+++ remote-mips.c	3 Oct 2008 16:28:35 -0000
@@ -1490,8 +1490,7 @@ device is attached to the target board (
 
   /* Parse the serial port name, the optional TFTP name, and the
      optional local TFTP name.  */
-  if ((argv = buildargv (name)) == NULL)
-    nomem (0);
+  argv = gdb_buildargv (name);
   make_cleanup_freeargv (argv);
 
   serial_port_name = xstrdup (argv[0]);
Index: remote-sim.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-sim.c,v
retrieving revision 1.76
diff -u -p -u -r1.76 remote-sim.c
--- remote-sim.c	24 Sep 2008 16:37:24 -0000	1.76
+++ remote-sim.c	3 Oct 2008 16:28:35 -0000
@@ -406,12 +406,13 @@ gdbsim_kill (void)
 static void
 gdbsim_load (char *args, int fromtty)
 {
-  char **argv = buildargv (args);
+  char **argv;
   char *prog;
 
-  if (argv == NULL)
-    nomem (0);
+  if (args == NULL)
+      error_no_arg (_("program to load"));
 
+  argv = gdb_buildargv (args);
   make_cleanup_freeargv (argv);
 
   prog = tilde_expand (argv[0]);
@@ -472,7 +473,7 @@ gdbsim_create_inferior (char *exec_file,
       strcat (arg_buf, exec_file);
       strcat (arg_buf, " ");
       strcat (arg_buf, args);
-      argv = buildargv (arg_buf);
+      argv = gdb_buildargv (arg_buf);
       make_cleanup_freeargv (argv);
     }
   else
@@ -546,9 +547,7 @@ gdbsim_open (char *args, int from_tty)
       strcat (arg_buf, " ");	/* 1 */
       strcat (arg_buf, args);
     }
-  argv = buildargv (arg_buf);
-  if (argv == NULL)
-    error (_("Insufficient memory available to allocate simulator arg list."));
+  argv = gdb_buildargv (arg_buf);
   make_cleanup_freeargv (argv);
 
   init_callbacks ();
Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.310
diff -u -p -u -r1.310 remote.c
--- remote.c	22 Sep 2008 15:21:30 -0000	1.310
+++ remote.c	3 Oct 2008 16:28:35 -0000
@@ -5546,13 +5546,14 @@ extended_remote_run (char *args)
     error (_("Remote file name too long for run packet"));
   len += 2 * bin2hex ((gdb_byte *) remote_exec_file, rs->buf + len, 0);
 
+  gdb_assert (args != NULL);
   if (*args)
     {
       struct cleanup *back_to;
       int i;
       char **argv;
 
-      argv = buildargv (args);
+      argv = gdb_buildargv (args);
       back_to = make_cleanup ((void (*) (void *)) freeargv, argv);
       for (i = 0; argv[i] != NULL; i++)
 	{
@@ -7491,9 +7492,10 @@ remote_put_command (char *args, int from
   struct cleanup *back_to;
   char **argv;
 
-  argv = buildargv (args);
-  if (argv == NULL)
-    nomem (0);
+  if (args == NULL)
+    error_no_arg (_("file to put"));
+
+  argv = gdb_buildargv (args);
   back_to = make_cleanup_freeargv (argv);
   if (argv[0] == NULL || argv[1] == NULL || argv[2] != NULL)
     error (_("Invalid parameters to remote put"));
@@ -7509,9 +7511,10 @@ remote_get_command (char *args, int from
   struct cleanup *back_to;
   char **argv;
 
-  argv = buildargv (args);
-  if (argv == NULL)
-    nomem (0);
+  if (args == NULL)
+    error_no_arg (_("file to get"));
+
+  argv = gdb_buildargv (args);
   back_to = make_cleanup_freeargv (argv);
   if (argv[0] == NULL || argv[1] == NULL || argv[2] != NULL)
     error (_("Invalid parameters to remote get"));
@@ -7527,9 +7530,10 @@ remote_delete_command (char *args, int f
   struct cleanup *back_to;
   char **argv;
 
-  argv = buildargv (args);
-  if (argv == NULL)
-    nomem (0);
+  if (args == NULL)
+    error_no_arg (_("file to delete"));
+
+  argv = gdb_buildargv (args);
   back_to = make_cleanup_freeargv (argv);
   if (argv[0] == NULL || argv[1] != NULL)
     error (_("Invalid parameters to remote delete"));
Index: ser-mingw.c
===================================================================
RCS file: /cvs/src/src/gdb/ser-mingw.c,v
retrieving revision 1.14
diff -u -p -u -r1.14 ser-mingw.c
--- ser-mingw.c	3 Sep 2008 23:54:19 -0000	1.14
+++ ser-mingw.c	3 Oct 2008 16:28:35 -0000
@@ -818,12 +818,15 @@ pipe_windows_open (struct serial *scb, c
   struct pipe_state *ps;
   FILE *pex_stderr;
 
-  char **argv = buildargv (name);
+  if (name == NULL)
+    error_no_arg (_("child command"));
+
+  char **argv = gdb_buildargv (name);
   struct cleanup *back_to = make_cleanup_freeargv (argv);
+
   if (! argv[0] || argv[0][0] == '\0')
     error ("missing child command");
 
-
   ps = make_pipe_state ();
   make_cleanup (cleanup_pipe_state, ps);
 
Index: source.c
===================================================================
RCS file: /cvs/src/src/gdb/source.c,v
retrieving revision 1.91
diff -u -p -u -r1.91 source.c
--- source.c	11 Sep 2008 14:21:49 -0000	1.91
+++ source.c	3 Oct 2008 16:28:35 -0000
@@ -428,12 +428,9 @@ add_path (char *dirname, char **which_pa
       /* This will properly parse the space and tab separators
 	 and any quotes that may exist. DIRNAME_SEPARATOR will
 	 be dealt with later.  */
-      argv = buildargv (dirname);
+      argv = gdb_buildargv (dirname);
       make_cleanup_freeargv (argv);
 
-      if (argv == NULL)
-	nomem (0);
-
       arg = argv[0];
     }
   else
@@ -1813,7 +1810,7 @@ show_substitute_path_command (char *args
   char **argv;
   char *from = NULL;
   
-  argv = buildargv (args);
+  argv = gdb_buildargv (args);
   make_cleanup_freeargv (argv);
 
   /* We expect zero or one argument.  */
@@ -1846,7 +1843,7 @@ static void
 unset_substitute_path_command (char *args, int from_tty)
 {
   struct substitute_path_rule *rule = substitute_path_rules;
-  char **argv = buildargv (args);
+  char **argv = gdb_buildargv (args);
   char *from = NULL;
   int rule_found = 0;
 
@@ -1899,7 +1896,7 @@ set_substitute_path_command (char *args,
   char **argv;
   struct substitute_path_rule *rule;
   
-  argv = buildargv (args);
+  argv = gdb_buildargv (args);
   make_cleanup_freeargv (argv);
 
   if (argv == NULL || argv[0] == NULL || argv [1] == NULL)
Index: stack.c
===================================================================
RCS file: /cvs/src/src/gdb/stack.c,v
retrieving revision 1.179
diff -u -p -u -r1.179 stack.c
--- stack.c	25 Sep 2008 16:04:11 -0000	1.179
+++ stack.c	3 Oct 2008 16:28:35 -0000
@@ -1282,7 +1282,7 @@ backtrace_command (char *arg, int from_t
       char **argv;
       int i;
 
-      argv = buildargv (arg);
+      argv = gdb_buildargv (arg);
       old_chain = make_cleanup_freeargv (argv);
       argc = 0;
       for (i = 0; argv[i]; i++)
Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.217
diff -u -p -u -r1.217 symfile.c
--- symfile.c	1 Oct 2008 17:21:06 -0000	1.217
+++ symfile.c	3 Oct 2008 16:28:35 -0000
@@ -1483,14 +1483,11 @@ symbol_file_command (char *args, int fro
     }
   else
     {
-      char **argv = buildargv (args);
+      char **argv = gdb_buildargv (args);
       int flags = OBJF_USERLOADED;
       struct cleanup *cleanups;
       char *name = NULL;
 
-      if (argv == NULL)
-	nomem (0);
-
       cleanups = make_cleanup_freeargv (argv);
       while (*argv != NULL)
 	{
@@ -1924,11 +1921,10 @@ generic_load (char *args, int from_tty)
 
   make_cleanup (clear_memory_write_data, &cbdata.requests);
 
-  argv = buildargv (args);
-
-  if (argv == NULL)
-    nomem(0);
+  if (args == NULL)
+    error_no_arg (_("file to load"));
 
+  argv = gdb_buildargv (args);
   make_cleanup_freeargv (argv);
 
   filename = tilde_expand (argv[0]);
@@ -2117,12 +2113,9 @@ add_symbol_file_command (char *args, int
   if (args == NULL)
     error (_("add-symbol-file takes a file name and an address"));
 
-  argv = buildargv (args);
+  argv = gdb_buildargv (args);
   make_cleanup_freeargv (argv);
 
-  if (argv == NULL)
-    nomem (0);
-
   for (arg = argv[0], argcnt = 0; arg != NULL; arg = argv[++argcnt])
     {
       /* Process the argument. */
Index: symmisc.c
===================================================================
RCS file: /cvs/src/src/gdb/symmisc.c,v
retrieving revision 1.57
diff -u -p -u -r1.57 symmisc.c
--- symmisc.c	1 Oct 2008 16:56:52 -0000	1.57
+++ symmisc.c	3 Oct 2008 16:28:35 -0000
@@ -526,10 +526,7 @@ maintenance_print_symbols (char *args, i
       error (_("\
 Arguments missing: an output file name and an optional symbol file name"));
     }
-  else if ((argv = buildargv (args)) == NULL)
-    {
-      nomem (0);
-    }
+  argv = gdb_buildargv (args);
   cleanups = make_cleanup_freeargv (argv);
 
   if (argv[0] != NULL)
@@ -739,10 +736,7 @@ maintenance_print_psymbols (char *args, 
     {
       error (_("print-psymbols takes an output file name and optional symbol file name"));
     }
-  else if ((argv = buildargv (args)) == NULL)
-    {
-      nomem (0);
-    }
+  argv = gdb_buildargv (args);
   cleanups = make_cleanup_freeargv (argv);
 
   if (argv[0] != NULL)
@@ -878,10 +872,7 @@ maintenance_print_msymbols (char *args, 
     {
       error (_("print-msymbols takes an output file name and optional symbol file name"));
     }
-  else if ((argv = buildargv (args)) == NULL)
-    {
-      nomem (0);
-    }
+  argv = gdb_buildargv (args);
   cleanups = make_cleanup_freeargv (argv);
 
   if (argv[0] != NULL)
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.195
diff -u -p -u -r1.195 utils.c
--- utils.c	8 Sep 2008 21:57:42 -0000	1.195
+++ utils.c	3 Oct 2008 16:28:35 -0000
@@ -3349,3 +3349,17 @@ ldirname (const char *filename)
   dirname[base - filename] = '\0';
   return dirname;
 }
+
+/* Call libiberty's buildargv, and return the result.
+   If buildargv fails due to out-of-memory, call nomem.
+   Therefore, the returned value is guaranteed to be non-NULL,
+   unless the parameter itself is NULL.  */
+
+char **
+gdb_buildargv (const char *s)
+{
+  char **argv = buildargv (s);
+  if (s != NULL && argv == NULL)
+    nomem (0);
+  return argv;
+}

      reply	other threads:[~2008-10-03 16:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-16 17:50 Paul Pluzhnikov
2008-09-19 21:52 ` Tom Tromey
2008-09-19 22:02   ` Daniel Jacobowitz
2008-09-26 23:22     ` [patch] " Paul Pluzhnikov
2008-10-03  7:04       ` Joel Brobecker
2008-10-03 16:39         ` Paul Pluzhnikov [this message]

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=8ac60eac0810030938i33a0671dx2d2ea3e2e82368bc@mail.gmail.com \
    --to=ppluzhnikov@google.com \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /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