2005-12-05 Andrew Stubbs * 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);