This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch gdb]: Fix PR gdb/15161 part 2 of 3


On 02/19/2013 05:19 PM, Kai Tietz wrote:

> -	load_offset = 0;
> +      pb = file;
> +      n = 0;
> +      /* Read until first space.  */
> +      while (*pb != 0 && *pb != 0x20)
> +        {
> +	  if (n < 127)
> +	    {
> +	      *d++ = *pb++;
> +	      ++n;
> +	    }
> +	  else
> +	    ++pb;
> +	}
> +      *d = 0;
> +
> +      while (isspace (pb[0])
> +        ++pb;
> +
> +      if (*pb != 0)
> +        {
> +	  load_offset = (CORE_ADDR) strtoulst (pb, NULL, 0);
> +	  file = buf;
> +	}

Hmm, no, sorry, that's way more hair than I imagined just
to make this code lump along.  I'd rather byte the bullet and
harmonize this old-looking code with generic_load, like
the below, which fixes several other issues, and completely
removes the 127-chars artificial limition.

"Tested" by building with --enable-targets=all.

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.
---

 gdb/monitor.c |   44 +++++++++++++++++++++++++++++++++-----------
 1 file changed, 33 insertions(+), 11 deletions(-)

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.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]