From: Pedro Alves Date: Tue, 19 Feb 2013 19:27:21 +0000 (+0000) Subject: Harmonize this monitor_load with generic_load. X-Git-Tag: sid-snapshot-20130301~73 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=40e397df34d493fc1e3455316af74d4d983dd80b;p=platform%2Fupstream%2Fbinutils.git Harmonize this monitor_load with generic_load. Harmonize this old-looking code with generic_load, which fixes several issues. 2013-02-19 Pedro Alves 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. --- 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 + + 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 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. */