Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Allow spaces in filenames to load command
@ 2005-12-06 17:06 Andrew STUBBS
  2005-12-06 18:23 ` Jim Blandy
  0 siblings, 1 reply; 11+ messages in thread
From: Andrew STUBBS @ 2005-12-06 17:06 UTC (permalink / raw)
  To: GDB Patches

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

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

[-- Attachment #2: load.patch --]
[-- Type: text/plain, Size: 2320 bytes --]

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);

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2006-02-21 18:23 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-06 17:06 [PATCH] Allow spaces in filenames to load command Andrew STUBBS
2005-12-06 18:23 ` Jim Blandy
2005-12-06 20:28   ` Andrew STUBBS
2005-12-07 17:44     ` Jim Blandy
2005-12-07 19:35       ` Jim Blandy
2005-12-07 23:25         ` Andrew STUBBS
2005-12-08  0:19           ` Andrew STUBBS
2006-02-20 17:07             ` Daniel Jacobowitz
2006-02-20 20:03               ` Jim Blandy
2006-02-20 20:38                 ` Daniel Jacobowitz
2006-02-21 18:27                   ` Andrew STUBBS

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox