along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
+#include "byte-vector.h"
#include "gdbcore.h"
#include "inferior.h"
#include "regcache.h"
}
#ifdef HAVE_KINFO_GETVMMAP
+/* Deleter for std::unique_ptr that invokes free. */
+
+template <typename T>
+struct free_deleter
+{
+ void operator() (T *ptr) const { free (ptr); }
+};
+
/* Iterate over all the memory regions in the current inferior,
calling FUNC for each memory region. OBFD is passed as the last
argument to FUNC. */
find_memory_region_ftype func, void *obfd)
{
pid_t pid = ptid_get_pid (inferior_ptid);
- struct kinfo_vmentry *vmentl, *kve;
+ struct kinfo_vmentry *kve;
uint64_t size;
- struct cleanup *cleanup;
int i, nitems;
- vmentl = kinfo_getvmmap (pid, &nitems);
+ std::unique_ptr<struct kinfo_vmentry, free_deleter<struct kinfo_vmentry>>
+ vmentl (kinfo_getvmmap (pid, &nitems));
if (vmentl == NULL)
perror_with_name (_("Couldn't fetch VM map entries."));
- cleanup = make_cleanup (free, vmentl);
- for (i = 0; i < nitems; i++)
+ for (i = 0, kve = vmentl.get (); i < nitems; i++, kve++)
{
- kve = &vmentl[i];
-
/* Skip unreadable segments and those where MAP_NOCORE has been set. */
if (!(kve->kve_protection & KVME_PROT_READ)
|| kve->kve_flags & KVME_FLAG_NOCOREDUMP)
kve->kve_protection & KVME_PROT_WRITE,
kve->kve_protection & KVME_PROT_EXEC, 1, obfd);
}
- do_cleanups (cleanup);
return 0;
}
#else
find_memory_region_ftype func, void *obfd)
{
pid_t pid = ptid_get_pid (inferior_ptid);
- char *mapfilename;
unsigned long start, end, size;
char protection[4];
int read, write, exec;
- struct cleanup *cleanup;
- mapfilename = xstrprintf ("/proc/%ld/map", (long) pid);
- cleanup = make_cleanup (xfree, mapfilename);
- gdb_file_up mapfile (fopen (mapfilename, "r"));
+ std::string mapfilename = string_printf ("/proc/%ld/map", (long) pid);
+ gdb_file_up mapfile (fopen (mapfilename.c_str (), "r"));
if (mapfile == NULL)
- error (_("Couldn't open %s."), mapfilename);
+ error (_("Couldn't open %s."), mapfilename.c_str ());
if (info_verbose)
fprintf_filtered (gdb_stdout,
- "Reading memory regions from %s\n", mapfilename);
+ "Reading memory regions from %s\n", mapfilename.c_str ());
/* Now iterate until end-of-file. */
while (fbsd_read_mapping (mapfile.get (), &start, &end, &protection[0]))
func (start, size, read, write, exec, 1, obfd);
}
- do_cleanups (cleanup);
return 0;
}
#endif
#endif
case TARGET_OBJECT_AUXV:
{
- struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
- unsigned char *buf;
+ gdb::byte_vector buf_storage;
+ gdb_byte *buf;
size_t buflen;
int mib[4];
else
{
buflen = offset + len;
- buf = XCNEWVEC (unsigned char, buflen);
- cleanup = make_cleanup (xfree, buf);
+ buf_storage.resize (buflen);
+ buf = buf_storage.data ();
}
if (sysctl (mib, 4, buf, &buflen, NULL, 0) == 0)
{
else
buflen = 0;
}
- do_cleanups (cleanup);
*xfered_len = buflen;
return (buflen == 0) ? TARGET_XFER_EOF : TARGET_XFER_OK;
}
- do_cleanups (cleanup);
return TARGET_XFER_E_IO;
}
default:
static void
fbsd_add_threads (pid_t pid)
{
- struct cleanup *cleanup;
- lwpid_t *lwps;
int i, nlwps;
gdb_assert (!in_thread_list (pid_to_ptid (pid)));
if (nlwps == -1)
perror_with_name (("ptrace"));
- lwps = XCNEWVEC (lwpid_t, nlwps);
- cleanup = make_cleanup (xfree, lwps);
+ gdb::unique_xmalloc_ptr<lwpid_t> lwps (XCNEWVEC (lwpid_t, nlwps));
- nlwps = ptrace (PT_GETLWPLIST, pid, (caddr_t) lwps, nlwps);
+ nlwps = ptrace (PT_GETLWPLIST, pid, (caddr_t) lwps.get (), nlwps);
if (nlwps == -1)
perror_with_name (("ptrace"));
for (i = 0; i < nlwps; i++)
{
- ptid_t ptid = ptid_build (pid, lwps[i], 0);
+ lwpid_t lwp = lwps.get ()[i];
+ ptid_t ptid = ptid_build (pid, lwp, 0);
if (!in_thread_list (ptid))
{
/* Don't add exited threads. Note that this is only called
when attaching to a multi-threaded process. */
- if (ptrace (PT_LWPINFO, lwps[i], (caddr_t) &pl, sizeof pl) == -1)
+ if (ptrace (PT_LWPINFO, lwp, (caddr_t) &pl, sizeof pl) == -1)
perror_with_name (("ptrace"));
if (pl.pl_flags & PL_FLAG_EXITED)
continue;
if (debug_fbsd_lwp)
fprintf_unfiltered (gdb_stdlog,
"FLWP: adding thread for LWP %u\n",
- lwps[i]);
+ lwp);
add_thread (ptid);
}
}
- do_cleanups (cleanup);
}
/* Implement the "to_update_thread_list" target_ops method. */