FYI: copy argument text in gdb.execute

Tom Tromey tromey@redhat.com
Mon Nov 9 18:27:00 GMT 2009


I'm checking this in.

This fixes the bug recently reported on the gdb list.
execute_gdb_command must copy its argument text in case the called gdb
command modifies it.

Tom

2009-11-09  Tom Tromey  <tromey@redhat.com>

	* python/python.c (execute_gdb_command): Copy the argument text.

Index: python/python.c
===================================================================
RCS file: /cvs/src/src/gdb/python/python.c,v
retrieving revision 1.19
diff -u -r1.19 python.c
--- python/python.c	2 Jul 2009 17:04:23 -0000	1.19
+++ python/python.c	9 Nov 2009 18:25:25 -0000
@@ -309,7 +309,11 @@
 
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
-      execute_command (arg, from_tty);
+      /* Copy the argument text in case the command modifies it.  */
+      char *copy = xstrdup (arg);
+      struct cleanup *cleanup = make_cleanup (xfree, copy);
+      execute_command (copy, from_tty);
+      do_cleanups (cleanup);
     }
   GDB_PY_HANDLE_EXCEPTION (except);
 



More information about the Gdb-patches mailing list