summaryrefslogtreecommitdiff
path: root/gdb/symfile.c
diff options
context:
space:
mode:
authorAndrew Stubbs <andrew.stubbs@st.com>2006-02-21 18:22:27 +0000
committerAndrew Stubbs <andrew.stubbs@st.com>2006-02-21 18:22:27 +0000
commit61fa8fd5271543aa20ffb4f314bf47515bc34185 (patch)
treed0f510fa423185f86029d10e3acabfcda8862f4f /gdb/symfile.c
parent391160bb75bc51d310bd99d9880f666b2ac2517f (diff)
downloadgdb-61fa8fd5271543aa20ffb4f314bf47515bc34185.tar.gz
2006-02-21 Andrew Stubbs <andrew.stubbs@st.com>
* symfile.c (generic_load): Use buildargv() and tilde_expand() to parse file names with quoting, spaces and tildes properly. (load_command): Quote all special characters before calling target_load() such that buildargv() doesn't break file names. (_initialize_symfile): Mention the load offset in the help for the load command. * remote-sim.c: Include readline.h. (gdbsim_load): Use buildargv and tilde_expand() to parse file names with quoting, spaces and tildes properly. * target.h (target_load): Comment the parameters better. * Makefile.in (remote_sim.o): Add readline.h dependency. testsuite/ * gdb.base/help.exp (help load): Update expected results.
Diffstat (limited to 'gdb/symfile.c')
-rw-r--r--gdb/symfile.c77
1 files changed, 60 insertions, 17 deletions
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 2a35e34afb1..c7168c04057 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1467,7 +1467,42 @@ static void
load_command (char *arg, int from_tty)
{
if (arg == NULL)
- arg = get_exec_file (1);
+ {
+ char *parg;
+ int count = 0;
+
+ parg = arg = get_exec_file (1);
+
+ /* Count how many \ " ' tab space there are in the name. */
+ while ((parg = strpbrk (parg, "\\\"'\t ")))
+ {
+ parg++;
+ count++;
+ }
+
+ if (count)
+ {
+ /* We need to quote this string so buildargv can pull it apart. */
+ char *temp = xmalloc (strlen (arg) + count + 1 );
+ char *ptemp = temp;
+ char *prev;
+
+ make_cleanup (xfree, temp);
+
+ prev = parg = arg;
+ while ((parg = strpbrk (parg, "\\\"'\t ")))
+ {
+ strncpy (ptemp, prev, parg - prev);
+ ptemp += parg - prev;
+ prev = parg++;
+ *ptemp++ = '\\';
+ }
+ strcpy (ptemp, prev);
+
+ arg = temp;
+ }
+ }
+
target_load (arg, from_tty);
/* After re-loading the executable, we don't really know which
@@ -1614,33 +1649,40 @@ generic_load (char *args, int from_tty)
bfd *loadfile_bfd;
struct timeval start_time, end_time;
char *filename;
- struct cleanup *old_cleanups;
- char *offptr;
+ struct cleanup *old_cleanups = make_cleanup (null_cleanup, 0);
struct load_section_data cbdata;
CORE_ADDR entry;
+ char **argv;
cbdata.load_offset = 0; /* Offset to add to vma for each section. */
cbdata.write_count = 0; /* Number of writes needed. */
cbdata.data_count = 0; /* Number of bytes written to target memory. */
cbdata.total_size = 0; /* Total size of all bfd sectors. */
- /* Parse the input argument - the user can specify a load offset as
- a second argument. */
- filename = xmalloc (strlen (args) + 1);
- old_cleanups = make_cleanup (xfree, filename);
- strcpy (filename, args);
- offptr = strchr (filename, ' ');
- if (offptr != NULL)
+ argv = buildargv (args);
+
+ if (argv == NULL)
+ nomem(0);
+
+ make_cleanup_freeargv (argv);
+
+ filename = tilde_expand (argv[0]);
+ make_cleanup (xfree, filename);
+
+ if (argv[1] != NULL)
{
char *endptr;
- cbdata.load_offset = strtoul (offptr, &endptr, 0);
- if (offptr == endptr)
- error (_("Invalid download offset:%s."), offptr);
- *offptr = '\0';
+ cbdata.load_offset = strtoul (argv[1], &endptr, 0);
+
+ /* If the last word was not a valid number then
+ treat it as a file name with spaces in. */
+ if (argv[1] == endptr)
+ error (_("Invalid download offset:%s."), argv[1]);
+
+ if (argv[2] != NULL)
+ error (_("Too many parameters."));
}
- else
- cbdata.load_offset = 0;
/* Open the file for loading. */
loadfile_bfd = bfd_openr (filename, gnutarget);
@@ -3724,7 +3766,8 @@ Load the symbols from shared objects in the dynamic linker's link map."),
c = add_cmd ("load", class_files, load_command, _("\
Dynamically load FILE into the running program, and record its symbols\n\
-for access from GDB."), &cmdlist);
+for access from GDB.\n\
+A load OFFSET may also be given."), &cmdlist);
set_cmd_completer (c, filename_completer);
add_setshow_boolean_cmd ("symbol-reloading", class_support,