Remove cleanup from ppc-linux-nat.c
authorTom Tromey <tom@tromey.com>
Thu, 12 Oct 2017 22:24:13 +0000 (16:24 -0600)
committerTom Tromey <tom@tromey.com>
Mon, 16 Oct 2017 22:10:20 +0000 (16:10 -0600)
This removes a cleanup from ppc-linux-nat.c, by using
unique_xmalloc_ptr.  It also slightly simplifies the code by using
XDUP rather than XNEW and memcpy.

ChangeLog
2017-10-16  Tom Tromey  <tom@tromey.com>

* ppc-linux-nat.c (hwdebug_insert_point): Use
gdb::unique_xmalloc_ptr, XDUP.

gdb/ChangeLog
gdb/ppc-linux-nat.c

index 248b5d8f897ea0ab33b718aeef6296e9db4c1096..adca69334cde646cda808020e3ed1b227860df4b 100644 (file)
@@ -1,3 +1,8 @@
+2017-10-16  Tom Tromey  <tom@tromey.com>
+
+       * ppc-linux-nat.c (hwdebug_insert_point): Use
+       gdb::unique_xmalloc_ptr, XDUP.
+
 2017-10-16  Tom Tromey  <tom@tromey.com>
 
        * probe.c (parse_probes): Use std::string.
index 45c8903ef68d219765d6450ae1b783fe5473a14b..7c8ab6c67b4076e26acd82dcabe0e2a8b19c07b4 100644 (file)
@@ -1541,16 +1541,13 @@ hwdebug_insert_point (struct ppc_hw_breakpoint *b, int tid)
 {
   int i;
   long slot;
-  struct ppc_hw_breakpoint *p = XNEW (struct ppc_hw_breakpoint);
+  gdb::unique_xmalloc_ptr<ppc_hw_breakpoint> p (XDUP (ppc_hw_breakpoint, b));
   struct hw_break_tuple *hw_breaks;
-  struct cleanup *c = make_cleanup (xfree, p);
   struct thread_points *t;
   struct hw_break_tuple *tuple;
 
-  memcpy (p, b, sizeof (struct ppc_hw_breakpoint));
-
   errno = 0;
-  slot = ptrace (PPC_PTRACE_SETHWDEBUG, tid, 0, p);
+  slot = ptrace (PPC_PTRACE_SETHWDEBUG, tid, 0, p.get ());
   if (slot < 0)
     perror_with_name (_("Unexpected error setting breakpoint or watchpoint"));
 
@@ -1564,13 +1561,11 @@ hwdebug_insert_point (struct ppc_hw_breakpoint *b, int tid)
     if (hw_breaks[i].hw_break == NULL)
       {
        hw_breaks[i].slot = slot;
-       hw_breaks[i].hw_break = p;
+       hw_breaks[i].hw_break = p.release ();
        break;
       }
 
   gdb_assert (i != max_slots_number);
-
-  discard_cleanups (c);
 }
 
 /* This function is a generic wrapper that is responsible for removing a
This page took 0.032752 seconds and 4 git commands to generate.