aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog24
-rw-r--r--gdb/defs.h2
-rw-r--r--gdb/exec.c5
-rw-r--r--gdb/infrun.c15
-rw-r--r--gdb/interps.c19
-rw-r--r--gdb/linux-nat.c6
-rw-r--r--gdb/procfs.c6
-rw-r--r--gdb/remote-mips.c3
-rw-r--r--gdb/remote-sim.c13
-rw-r--r--gdb/remote.c24
-rw-r--r--gdb/ser-mingw.c7
-rw-r--r--gdb/source.c11
-rw-r--r--gdb/stack.c2
-rw-r--r--gdb/symfile.c17
-rw-r--r--gdb/symmisc.c15
-rw-r--r--gdb/utils.c14
16 files changed, 96 insertions, 87 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 960ea3b..168ea50 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,27 @@
+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.
+
2008-10-02 Jan Kratochvil <jan.kratochvil@redhat.com>
Replace TYPE_ARRAY_{UPPER,LOWER}_BOUND_TYPE by a bit if {un,}defined.
diff --git a/gdb/defs.h b/gdb/defs.h
index 23a6599..5b718a3 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -405,6 +405,8 @@ ULONGEST strtoulst (const char *num, const char **trailer, int base);
char *ldirname (const char *filename);
+char **gdb_buildargv (const char *);
+
/* From demangle.c */
extern void set_demangling_style (char *);
diff --git a/gdb/exec.c b/gdb/exec.c
index 94e0a0d..3b9ecfa 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -302,10 +302,7 @@ exec_file_command (char *args, int from_tty)
/* 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++)
diff --git a/gdb/infrun.c b/gdb/infrun.c
index abaceee..4eb4b2c 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -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_tty)
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)
{
diff --git a/gdb/interps.c b/gdb/interps.c
index 3bb7811..73bc51c 100644
--- a/gdb/interps.c
+++ b/gdb/interps.c
@@ -371,20 +371,15 @@ interpreter_exec_cmd (char *args, int from_tty)
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> ... ]"));
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index a0dc634..f76eaec 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -3591,10 +3591,8 @@ linux_nat_info_proc_cmd (char *args, int from_tty)
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)
{
diff --git a/gdb/procfs.c b/gdb/procfs.c
index 7529146..bee5b87 100644
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -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)
{
diff --git a/gdb/remote-mips.c b/gdb/remote-mips.c
index bde8614..a996124 100644
--- a/gdb/remote-mips.c
+++ b/gdb/remote-mips.c
@@ -1490,8 +1490,7 @@ device is attached to the target board (e.g., /dev/ttya).\n"
/* 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]);
diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index b337769..be89db9 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -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, char *args, char **env, int from_tty)
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 ();
diff --git a/gdb/remote.c b/gdb/remote.c
index 9dacd17..d7dc46b 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -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_tty)
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_tty)
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 from_tty)
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"));
diff --git a/gdb/ser-mingw.c b/gdb/ser-mingw.c
index 98b8368..6a883aa 100644
--- a/gdb/ser-mingw.c
+++ b/gdb/ser-mingw.c
@@ -818,12 +818,15 @@ pipe_windows_open (struct serial *scb, const char *name)
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);
diff --git a/gdb/source.c b/gdb/source.c
index 9493fd1..a5f434f 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -428,12 +428,9 @@ add_path (char *dirname, char **which_path, int parse_separators)
/* 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, int from_tty)
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, int from_tty)
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)
diff --git a/gdb/stack.c b/gdb/stack.c
index 2efe3e5..2c3c0bb 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -1282,7 +1282,7 @@ backtrace_command (char *arg, int from_tty)
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++)
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 92fa9da..d9aff2f 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1483,14 +1483,11 @@ symbol_file_command (char *args, int from_tty)
}
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 from_tty)
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. */
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 048d9e0..a9cf5f5 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -526,10 +526,7 @@ maintenance_print_symbols (char *args, int from_tty)
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, int from_tty)
{
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, int from_tty)
{
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)
diff --git a/gdb/utils.c b/gdb/utils.c
index ce05909..3d35390 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -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;
+}