Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mark Mitchell <mark@codesourcery.com>
To: gdb-patches@sources.redhat.com
Subject: PATCH: PowerPC simulator doesn't handle spaces in filenames
Date: Tue, 24 Jan 2006 05:59:00 -0000	[thread overview]
Message-ID: <200601240559.k0O5xhER007274@sethra.codesourcery.com> (raw)


The PowerPC simulator simulates bits of openprom functionality.  In
particular, it feeds the program file name into the openprom device
tree.  However, filenames containing a space or backslash (both of
which are very common on Windows, but can also occur on UNIX), were
not quoted.  (Here, quoting means enclosing the entire filename in
double-quotes, and protecting backslashes by double-quoting them.)

Tested by verifying that I could run a PowerPC program with a space
and/or backslash in its name, on both x86_64-unknown-linux-gnu and
i686-mingw32. 

OK?

--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

2006-01-23  Mark Mitchell  <mark@codesourcery.com>

	* emul_netbsd.c (emul_netbsd_create): Quote file-name property.
	* emul_unix.c (emul_unix_create): Likewise.
	* tree.c (libiberty.h): Include it.
	(tree_quote_property): New function.
	* tree.h (tree_quote_property): Declare.

Index: emul_netbsd.c
===================================================================
RCS file: /cvs/src/src/sim/ppc/emul_netbsd.c,v
retrieving revision 1.6
diff -c -5 -p -r1.6 emul_netbsd.c
*** emul_netbsd.c	28 Nov 2005 23:19:39 -0000	1.6
--- emul_netbsd.c	24 Jan 2006 05:50:57 -0000
*************** emul_netbsd_create(device *root,
*** 1381,1390 ****
--- 1381,1391 ----
    unsigned_word top_of_stack;
    unsigned stack_size;
    int elf_binary;
    os_emul_data *bsd_data;
    device *vm;
+   char *filename;
  
    /* check that this emulation is really for us */
    if (name != NULL && strcmp(name, "netbsd") != 0)
      return NULL;
    if (image == NULL)
*************** emul_netbsd_create(device *root,
*** 1415,1426 ****
    vm = tree_parse(root, "/openprom/vm");
    tree_parse(vm, "./stack-base 0x%lx",
  	     (unsigned long)(top_of_stack - stack_size));
    tree_parse(vm, "./nr-bytes 0x%x", stack_size);
  
    tree_parse(root, "/openprom/vm/map-binary/file-name %s",
! 	     bfd_get_filename(image));
  
    /* finish the init */
    tree_parse(root, "/openprom/init/register/pc 0x%lx",
  	     (unsigned long)bfd_get_start_address(image));
    tree_parse(root, "/openprom/init/register/sp 0x%lx",
--- 1416,1429 ----
    vm = tree_parse(root, "/openprom/vm");
    tree_parse(vm, "./stack-base 0x%lx",
  	     (unsigned long)(top_of_stack - stack_size));
    tree_parse(vm, "./nr-bytes 0x%x", stack_size);
  
+   filename = tree_quote_property (bfd_get_filename(image));
    tree_parse(root, "/openprom/vm/map-binary/file-name %s",
! 	     filename);
!   free (filename);
  
    /* finish the init */
    tree_parse(root, "/openprom/init/register/pc 0x%lx",
  	     (unsigned long)bfd_get_start_address(image));
    tree_parse(root, "/openprom/init/register/sp 0x%lx",
Index: emul_unix.c
===================================================================
RCS file: /cvs/src/src/sim/ppc/emul_unix.c,v
retrieving revision 1.2
diff -c -5 -p -r1.2 emul_unix.c
*** emul_unix.c	28 Nov 2005 23:19:39 -0000	1.2
--- emul_unix.c	24 Jan 2006 05:50:57 -0000
*************** emul_unix_create(device *root,
*** 949,958 ****
--- 949,959 ----
    unsigned_word top_of_stack;
    unsigned stack_size;
    int elf_binary;
    os_emul_data *data;
    device *vm;
+   char *filename;
  
    /* merge any emulation specific entries into the device tree */
  
    /* establish a few defaults */
    if (image->xvec->flavour == bfd_target_elf_flavour) {
*************** emul_unix_create(device *root,
*** 977,988 ****
  		  (unsigned long)(top_of_stack - stack_size));
    tree_parse(vm, "./stack-base 0x%lx",
  	     (unsigned long)(top_of_stack - stack_size));
    tree_parse(vm, "./nr-bytes 0x%x", stack_size);
  
    tree_parse(root, "/openprom/vm/map-binary/file-name %s",
! 	     bfd_get_filename(image));
  
    /* finish the init */
    tree_parse(root, "/openprom/init/register/pc 0x%lx",
  	     (unsigned long)bfd_get_start_address(image));
    tree_parse(root, "/openprom/init/register/sp 0x%lx",
--- 978,991 ----
  		  (unsigned long)(top_of_stack - stack_size));
    tree_parse(vm, "./stack-base 0x%lx",
  	     (unsigned long)(top_of_stack - stack_size));
    tree_parse(vm, "./nr-bytes 0x%x", stack_size);
  
+   filename = tree_quote_property (bfd_get_filename(image));
    tree_parse(root, "/openprom/vm/map-binary/file-name %s",
! 	     filename);
!   free (filename);
  
    /* finish the init */
    tree_parse(root, "/openprom/init/register/pc 0x%lx",
  	     (unsigned long)bfd_get_start_address(image));
    tree_parse(root, "/openprom/init/register/sp 0x%lx",
Index: tree.c
===================================================================
RCS file: /cvs/src/src/sim/ppc/tree.c,v
retrieving revision 1.4
diff -c -5 -p -r1.4 tree.c
*** tree.c	25 Mar 2005 20:40:02 -0000	1.4
--- tree.c	24 Jan 2006 05:50:59 -0000
***************
*** 43,52 ****
--- 43,53 ----
  #endif
  #endif
  
  #include <ctype.h>
  
+ #include "libiberty.h"
  
  /* manipulate/lookup device names */
  
  typedef struct _name_specifier {
    /* components in the full length name */
*************** parse_integer_property(device *current,
*** 623,632 ****
--- 624,677 ----
      device_add_array_property(current, property_name, words,
                                sizeof(words[0]) * nr_entries);
    }
  }
  
+ /* PROPERTY_VALUE is a raw property value.  Quote it as required by
+    parse_string_property.  It is the caller's responsibility to free
+    the memory returned.  */
+ 
+ EXTERN_TREE\
+ (char *)
+ tree_quote_property(const char *property_value)
+ {
+   char *p;
+   char *ret;
+   const char *chp;
+   int backslashes;
+ 
+   /* Count backslashes in PROPERTY_VALUE.  */
+   backslashes = 0;
+   for (chp = property_value; *chp; ++chp)
+     if (*chp == '\\')
+       ++backslashes;
+   
+   ret = (char *) xmalloc (strlen (property_value) 
+ 			  + 2 /* quotes */
+ 			  + backslashes
+ 			  + 1 /* terminator */);
+ 
+   p = ret;
+   /* Add the opening quote.  */
+   *p++ = '"';
+   /* Copy the value.  */
+   for (chp = property_value; *chp; ++chp)
+     if (*chp == '\\')
+       {
+ 	/* Double backslashes.  */
+ 	*p++ = '\\';
+ 	*p++ = '\\';
+       }
+     else
+       *p++ = *chp;
+   /* Add the closing quote.  */
+   *p++ = '"';
+   /* Terminate the string.  */
+   *p++ = '\0';
+ 
+   return ret;
+ }
  
  /* <string> ... */
  
  STATIC_INLINE_TREE\
  (void)
Index: tree.h
===================================================================
RCS file: /cvs/src/src/sim/ppc/tree.h,v
retrieving revision 1.1.1.1
diff -c -5 -p -r1.1.1.1 tree.h
*** tree.h	16 Apr 1999 01:35:12 -0000	1.1.1.1
--- tree.h	24 Jan 2006 05:50:59 -0000
***************
*** 40,49 ****
--- 40,53 ----
     initialized they will be restored to their initial value.
  
     */
  
  EXTERN_TREE\
+ (char*) tree_quote_property
+ (const char *property_value);
+ 
+ EXTERN_TREE\
  (device *) tree_parse
  (device *root,
   const char *fmt,
   ...) __attribute__ ((format (printf, 2, 3)));
  


             reply	other threads:[~2006-01-24  5:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-24  5:59 Mark Mitchell [this message]
2006-01-24 21:24 ` Daniel Jacobowitz
2006-01-25  6:23   ` Mark Mitchell
2006-02-02  1:44     ` Daniel Jacobowitz
2006-02-02  6:50       ` Mark Mitchell

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=200601240559.k0O5xhER007274@sethra.codesourcery.com \
    --to=mark@codesourcery.com \
    --cc=gdb-patches@sources.redhat.com \
    /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