diff options
author | Pedro Alves <palves@redhat.com> | 2013-02-19 19:27:21 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2013-02-19 19:27:21 +0000 |
commit | 40e397df34d493fc1e3455316af74d4d983dd80b (patch) | |
tree | a163292a918687d5f982a7b6e46ab5edd7130631 | |
parent | 5c111e376966558968049df5839776067729d3c8 (diff) | |
download | gdb-40e397df34d493fc1e3455316af74d4d983dd80b.zip gdb-40e397df34d493fc1e3455316af74d4d983dd80b.tar.gz gdb-40e397df34d493fc1e3455316af74d4d983dd80b.tar.bz2 |
Harmonize this monitor_load with generic_load.
Harmonize this old-looking code with generic_load, which fixes several
issues.
2013-02-19 Pedro Alves <palves@redhat.com>
PR gdb/15161
Harmonize with generic_load.
* monitor.c: Include "readline/readline.h".
(monitor_load): Rename parameter 'file' to 'args'. Use build_argv
instead of sscanf. Use CORE_ADDR/strtoulst instead of unsigned
long/strtol for the 'load_offset' local. Error out if no argument
is given or if too many arguments are given. Tilde expand the
passed in file name.
-rw-r--r-- | gdb/ChangeLog | 13 | ||||
-rw-r--r-- | gdb/monitor.c | 44 |
2 files changed, 46 insertions, 11 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 0775823..2789036 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,16 @@ +2013-02-19 Pedro Alves <palves@redhat.com> + + PR gdb/15161 + + Harmonize with generic_load. + + * monitor.c: Include "readline/readline.h". + (monitor_load): Rename parameter 'file' to 'args'. Use build_argv + instead of sscanf. Use CORE_ADDR/strtoulst instead of unsigned + long/strtol for the 'load_offset' local. Error out if no argument + is given or if too many arguments are given. Tilde expand the + passed in file name. + 2013-02-19 Kai Tietz <ktietz@redhat.com> PR gdb/15161 diff --git a/gdb/monitor.c b/gdb/monitor.c index d56179a..f4ec12c 100644 --- a/gdb/monitor.c +++ b/gdb/monitor.c @@ -54,6 +54,7 @@ #include "srec.h" #include "regcache.h" #include "gdbthread.h" +#include "readline/readline.h" static char *dev_name; static struct target_ops *targ_ops; @@ -2175,35 +2176,56 @@ monitor_wait_srec_ack (void) /* monitor_load -- download a file. */ static void -monitor_load (char *file, int from_tty) +monitor_load (char *args, int from_tty) { monitor_debug ("MON load\n"); if (current_monitor->load_routine) - current_monitor->load_routine (monitor_desc, file, hashmark); + current_monitor->load_routine (monitor_desc, args, hashmark); else { /* The default is ascii S-records. */ - int n; - unsigned long load_offset; - char buf[128]; + CORE_ADDR load_offset = 0; + char **argv; + struct cleanup *old_cleanups; + char *filename; + + if (args == NULL) + error_no_arg (_("file to load")); + + argv = gdb_buildargv (args); + old_cleanups = make_cleanup_freeargv (argv); + + filename = tilde_expand (argv[0]); + make_cleanup (xfree, filename); /* Enable user to specify address for downloading as 2nd arg to load. */ - n = sscanf (file, "%s 0x%lx", buf, &load_offset); - if (n > 1) - file = buf; - else - load_offset = 0; + if (argv[1] != NULL) + { + const char *endptr; + + load_offset = strtoulst (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]); + + if (argv[2] != NULL) + error (_("Too many parameters.")); + } monitor_printf (current_monitor->load); if (current_monitor->loadresp) monitor_expect (current_monitor->loadresp, NULL, 0); - load_srec (monitor_desc, file, (bfd_vma) load_offset, + load_srec (monitor_desc, filename, load_offset, 32, SREC_ALL, hashmark, current_monitor->flags & MO_SREC_ACK ? monitor_wait_srec_ack : NULL); monitor_expect_prompt (NULL, 0); + + do_cleanups (old_cleanups); } /* Finally, make the PC point at the start address. */ |