Remove a cleanup from call_function_by_hand_dummy
authorTom Tromey <tom@tromey.com>
Fri, 16 Feb 2018 23:11:29 +0000 (16:11 -0700)
committerTom Tromey <tom@tromey.com>
Wed, 21 Feb 2018 15:54:49 +0000 (08:54 -0700)
This removes a cleanup from call_function_by_hand_dummy, replacing
manual allocation with std::vector.

Regression tested by the buildbot.

gdb/ChangeLog
2018-02-21  Tom Tromey  <tom@tromey.com>

* infcall.c (call_function_by_hand_dummy): Use std::vector.

gdb/ChangeLog
gdb/infcall.c

index e58bc38..fae9db0 100644 (file)
@@ -1,3 +1,7 @@
+2018-02-21  Tom Tromey  <tom@tromey.com>
+
+       * infcall.c (call_function_by_hand_dummy): Use std::vector.
+
 2018-02-21  Yao Qi  <yao.qi@linaro.org>
 
        * avr-tdep.c (avr_read_pc): Change parameter type to
index 8b75297..b7f4a17 100644 (file)
@@ -39,6 +39,7 @@
 #include "top.h"
 #include "interps.h"
 #include "thread-fsm.h"
+#include <algorithm>
 
 /* If we can't find a function's name from its address,
    we print this instead.  */
@@ -732,7 +733,6 @@ call_function_by_hand_dummy (struct value *function,
   struct type *ftype = check_typedef (value_type (function));
   CORE_ADDR bp_addr;
   struct frame_id dummy_id;
-  struct cleanup *args_cleanup;
   struct frame_info *frame;
   struct gdbarch *gdbarch;
   struct cleanup *terminate_bp_cleanup;
@@ -1054,21 +1054,16 @@ call_function_by_hand_dummy (struct value *function,
        }
     }
 
+  std::vector<struct value *> new_args;
   if (hidden_first_param_p)
     {
-      struct value **new_args;
-
       /* Add the new argument to the front of the argument list.  */
-      new_args = XNEWVEC (struct value *, nargs + 1);
-      new_args[0] = value_from_pointer (lookup_pointer_type (values_type),
-                                       struct_addr);
-      memcpy (&new_args[1], &args[0], sizeof (struct value *) * nargs);
-      args = new_args;
+      new_args.push_back
+       (value_from_pointer (lookup_pointer_type (values_type), struct_addr));
+      std::copy (&args[0], &args[nargs], std::back_inserter (new_args));
+      args = new_args.data ();
       nargs++;
-      args_cleanup = make_cleanup (xfree, args);
     }
-  else
-    args_cleanup = make_cleanup (null_cleanup, NULL);
 
   /* Create the dummy stack frame.  Pass in the call dummy address as,
      presumably, the ABI code knows where, in the call dummy, the
@@ -1077,8 +1072,6 @@ call_function_by_hand_dummy (struct value *function,
                                bp_addr, nargs, args,
                                sp, struct_return, struct_addr);
 
-  do_cleanups (args_cleanup);
-
   /* Set up a frame ID for the dummy frame so we can pass it to
      set_momentary_breakpoint.  We need to give the breakpoint a frame
      ID so that the breakpoint code can correctly re-identify the