From 1986bccdb576b7758273dfa5ec8274c6be55f268 Mon Sep 17 00:00:00 2001 From: Andrew Stubbs Date: Tue, 21 Feb 2006 18:22:27 +0000 Subject: [PATCH] 2006-02-21 Andrew Stubbs * 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. --- gdb/Makefile.in | 3 +- gdb/remote-sim.c | 16 ++++++- gdb/symfile.c | 77 +++++++++++++++++++++++++-------- gdb/target.h | 9 +++- gdb/testsuite/ChangeLog | 4 ++ gdb/testsuite/gdb.base/help.exp | 2 +- 6 files changed, 90 insertions(+), 21 deletions(-) diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 779c9d07668..acba593b0eb 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -2477,7 +2477,8 @@ remote-sds.o: remote-sds.c $(defs_h) $(gdb_string_h) $(frame_h) \ remote-sim.o: remote-sim.c $(defs_h) $(inferior_h) $(value_h) \ $(gdb_string_h) $(terminal_h) $(target_h) $(gdbcore_h) \ $(gdb_callback_h) $(gdb_remote_sim_h) $(remote_utils_h) $(command_h) \ - $(regcache_h) $(gdb_assert_h) $(sim_regno_h) $(arch_utils_h) + $(regcache_h) $(gdb_assert_h) $(sim_regno_h) $(arch_utils_h) \ + $(readline_h) remote-st.o: remote-st.c $(defs_h) $(gdbcore_h) $(target_h) $(gdb_string_h) \ $(serial_h) $(regcache_h) remote-utils.o: remote-utils.c $(defs_h) $(gdb_string_h) $(gdbcmd_h) \ diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c index 2133f3e1ffd..e96018df7f8 100644 --- a/gdb/remote-sim.c +++ b/gdb/remote-sim.c @@ -43,6 +43,7 @@ #include "gdb_assert.h" #include "sim-regno.h" #include "arch-utils.h" +#include "readline/readline.h" /* Prototypes */ @@ -391,8 +392,21 @@ gdbsim_kill (void) GDB's symbol tables to match. */ static void -gdbsim_load (char *prog, int fromtty) +gdbsim_load (char *args, int fromtty) { + char **argv = buildargv (args); + char *prog; + + if (argv == NULL) + nomem (0); + + make_cleanup_freeargv (argv); + + prog = tilde_expand (argv[0]); + + if (argv[1] != NULL) + error (_("GDB sim does not yet support a load offset.")); + if (sr_get_debug ()) printf_filtered ("gdbsim_load: prog \"%s\"\n", prog); 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, diff --git a/gdb/target.h b/gdb/target.h index 95e5defc9ff..b804b05df43 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -680,7 +680,14 @@ extern void print_section_info (struct target_ops *, bfd *); /* Load an executable file into the target process. This is expected to not only bring new code into the target process, but also to - update GDB's symbol tables to match. */ + update GDB's symbol tables to match. + + ARG contains command-line arguments, to be broken down with + buildargv (). The first non-switch argument is the filename to + load, FILE; the second is a number (as parsed by strtoul (..., ..., + 0)), which is an offset to apply to the load addresses of FILE's + sections. The target may define switches, or other non-switch + arguments, as it pleases. */ extern void target_load (char *arg, int from_tty); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 5bebba03772..46fca9f9399 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2006-02-21 Andrew Stubbs + + * gdb.base/help.exp (help load): Update expected results. + 2006-02-19 Fred Fish * gdb.base/pc-fp.exp (get_valueofx): Don't print environment diff --git a/gdb/testsuite/gdb.base/help.exp b/gdb/testsuite/gdb.base/help.exp index 8715cdc9b1f..f4c6d36de6f 100644 --- a/gdb/testsuite/gdb.base/help.exp +++ b/gdb/testsuite/gdb.base/help.exp @@ -277,7 +277,7 @@ gdb_test "help l" "List specified function or line\.\[\r\n\]+With no argument, l # test help list gdb_test "help list" "List specified function or line\.\[\r\n\]+With no argument, lists ten more lines after or around previous listing\.\[\r\n\]+\"list -\" lists the ten lines before a previous ten-line listing\.\[\r\n\]+One argument specifies a line, and ten lines are listed around that line\.\[\r\n\]+Two arguments with comma between specify starting and ending lines to list\.\[\r\n\]+Lines can be specified in these ways:\[\r\n\]+ LINENUM, to list around that line in current file,\[\r\n\]+ FILE:LINENUM, to list around that line in that file,\[\r\n\]+ FUNCTION, to list around beginning of that function,\[\r\n\]+ FILE:FUNCTION, to distinguish among like-named static functions\.\[\r\n\]+ \[*\]ADDRESS, to list around the line containing that address\.\[\r\n\]+With two args if one is empty it stands for ten lines away from the other arg\." "help list" # test help load -gdb_test "help load" "Dynamically load FILE into the running program, and record its symbols\[\r\n\]+for access from GDB\." "help load" +gdb_test "help load" "Dynamically load FILE into the running program, and record its symbols\[\r\n\]+for access from GDB\.\[\r\n\]+A load OFFSET may also be given\." "help load" # test help make gdb_test "help make" "Run the ``make'' program using the rest of the line as arguments\." "help make" # test help next "n" abbreviation -- 2.39.5