Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew STUBBS <andrew.stubbs@st.com>
To: GDB Patches <gdb-patches@sourceware.org>
Subject: [PATCH] Allow spaces in filenames to load command
Date: Tue, 06 Dec 2005 17:06:00 -0000	[thread overview]
Message-ID: <43949300.1040203@st.com> (raw)

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

             reply	other threads:[~2005-12-05 19:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-06 17:06 Andrew STUBBS [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=43949300.1040203@st.com \
    --to=andrew.stubbs@st.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox