This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Allow spaces in filenames to load command
- From: Andrew STUBBS <andrew dot stubbs at st dot com>
- To: GDB Patches <gdb-patches at sourceware dot org>
- Date: Mon, 05 Dec 2005 19:20:32 +0000
- Subject: [PATCH] Allow spaces in filenames to load command
Hi,
I have been having trouble using GDB when there are spaces in the
executable filename (including in parent directories). This is quite
common on Windows.
The load command attempts to interpret everything after the first space
as a load offset - a number - and rejects the command of it won't parse.
This even happens when the filename is passed on the GDB command line.
The attached patch used buildargv() and tilde_expand() to give this
filename the same treatment as exec_file and symbol_file.
A quick search of gnats shows that this is bug #535.
OK?
Andrew Stubbs
2005-12-05 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.
Index: src/gdb/symfile.c
===================================================================
--- src.orig/gdb/symfile.c 2005-12-02 16:15:22.000000000 +0000
+++ src/gdb/symfile.c 2005-12-05 18:46:48.000000000 +0000
@@ -1615,8 +1615,7 @@ 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;
@@ -1625,23 +1624,36 @@ generic_load (char *args, int from_tty)
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)
- {
- char *endptr;
-
- cbdata.load_offset = strtoul (offptr, &endptr, 0);
- if (offptr == endptr)
- error (_("Invalid download offset:%s."), offptr);
- *offptr = '\0';
- }
+ /* Do we have args from the user or from the default? */
+ if (exec_bfd && args == get_exec_file (1))
+ /* The string is ONLY the file name. */
+ filename = args;
else
- cbdata.load_offset = 0;
+ {
+ /* We have args from the user so the filename may be quoted
+ and there may be an offset argument. */
+ char **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 (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]);
+ }
+ }
/* Open the file for loading. */
loadfile_bfd = bfd_openr (filename, gnutarget);