X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Fnto-procfs.c;h=5ff01560e0b1c683427d58963bb7418432bc2513;hb=6873858b7e464e114f9a877e216949ad8350b4cf;hp=2fd2dcf79a920e60a7816ddf17f4a245f62c53d7;hpb=6bd6f3b6569945700386847f624dc9e8b7f57450;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c index 2fd2dcf79a..5ff01560e0 100644 --- a/gdb/nto-procfs.c +++ b/gdb/nto-procfs.c @@ -43,6 +43,7 @@ #include "solib.h" #include "inf-child.h" #include "common/filestuff.h" +#include "common/scoped_fd.h" #define NULL_PID 0 #define _DEBUG_FLAG_TRACE (_DEBUG_FLAG_TRACE_EXEC|_DEBUG_FLAG_TRACE_RD|\ @@ -113,9 +114,8 @@ procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty) { char *endstr; char buffer[50]; - int fd, total_size; + int total_size; procfs_sysinfo *sysinfo; - struct cleanup *cleanups; char nto_procfs_path[PATH_MAX]; /* Offer to kill previous inferiors before opening this target. */ @@ -158,17 +158,16 @@ procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty) snprintf (nto_procfs_path, PATH_MAX - 1, "%s%s", (nodestr != NULL) ? nodestr : "", "/proc"); - fd = open (nto_procfs_path, O_RDONLY); - if (fd == -1) + scoped_fd fd (open (nto_procfs_path, O_RDONLY)); + if (fd.get () == -1) { printf_filtered ("Error opening %s : %d (%s)\n", nto_procfs_path, errno, safe_strerror (errno)); error (_("Invalid procfs arg")); } - cleanups = make_cleanup_close (fd); sysinfo = (void *) buffer; - if (devctl (fd, DCMD_PROC_SYSINFO, sysinfo, sizeof buffer, 0) != EOK) + if (devctl (fd.get (), DCMD_PROC_SYSINFO, sysinfo, sizeof buffer, 0) != EOK) { printf_filtered ("Error getting size: %d (%s)\n", errno, safe_strerror (errno)); @@ -186,7 +185,8 @@ procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty) } else { - if (devctl (fd, DCMD_PROC_SYSINFO, sysinfo, total_size, 0) != EOK) + if (devctl (fd.get (), DCMD_PROC_SYSINFO, sysinfo, total_size, 0) + != EOK) { printf_filtered ("Error getting sysinfo: %d (%s)\n", errno, safe_strerror (errno)); @@ -201,7 +201,6 @@ procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty) } } } - do_cleanups (cleanups); inf_child_open_target (ops, arg, from_tty); printf_filtered ("Debugging using %s\n", nto_procfs_path); @@ -377,9 +376,6 @@ procfs_pidlist (const char *args, int from_tty) do { - int fd; - struct cleanup *inner_cleanup; - /* Get the right pid and procfs path for the pid. */ do { @@ -397,17 +393,16 @@ procfs_pidlist (const char *args, int from_tty) while (pid == 0); /* Open the procfs path. */ - fd = open (buf, O_RDONLY); - if (fd == -1) + scoped_fd fd (open (buf, O_RDONLY)); + if (fd.get () == -1) { fprintf_unfiltered (gdb_stderr, "failed to open %s - %d (%s)\n", buf, errno, safe_strerror (errno)); continue; } - inner_cleanup = make_cleanup_close (fd); pidinfo = (procfs_info *) buf; - if (devctl (fd, DCMD_PROC_INFO, pidinfo, sizeof (buf), 0) != EOK) + if (devctl (fd.get (), DCMD_PROC_INFO, pidinfo, sizeof (buf), 0) != EOK) { fprintf_unfiltered (gdb_stderr, "devctl DCMD_PROC_INFO failed - %d (%s)\n", @@ -417,7 +412,8 @@ procfs_pidlist (const char *args, int from_tty) num_threads = pidinfo->num_threads; info = (procfs_debuginfo *) buf; - if (devctl (fd, DCMD_PROC_MAPDEBUG_BASE, info, sizeof (buf), 0) != EOK) + if (devctl (fd.get (), DCMD_PROC_MAPDEBUG_BASE, info, sizeof (buf), 0) + != EOK) strcpy (name, "unavailable"); else strcpy (name, info->path); @@ -427,7 +423,7 @@ procfs_pidlist (const char *args, int from_tty) for (status->tid = 1; status->tid <= num_threads; status->tid++) { const int err - = devctl (fd, DCMD_PROC_TIDSTATUS, status, sizeof (buf), 0); + = devctl (fd.get (), DCMD_PROC_TIDSTATUS, status, sizeof (buf), 0); printf_filtered ("%s - %d", name, pid); if (err == EOK && status->tid != 0) printf_filtered ("/%d\n", status->tid); @@ -437,8 +433,6 @@ procfs_pidlist (const char *args, int from_tty) break; } } - - do_cleanups (inner_cleanup); } while (dirp != NULL); @@ -732,7 +726,7 @@ nto_handle_sigint (int signo) /* If this doesn't work, try more severe steps. */ signal (signo, nto_handle_sigint_twice); - target_interrupt (inferior_ptid); + target_interrupt (); } static ptid_t @@ -943,7 +937,7 @@ procfs_xfer_partial (struct target_ops *ops, enum target_object object, on signals, etc. We'd better not have left any breakpoints in the program or it'll die when it hits one. */ static void -procfs_detach (struct target_ops *ops, int from_tty) +procfs_detach (struct target_ops *ops, inferior *inf, int from_tty) { int pid; @@ -1275,7 +1269,7 @@ procfs_create_inferior (struct target_ops *ops, const char *exec_file, } static void -procfs_interrupt (struct target_ops *self, ptid_t ptid) +procfs_interrupt (struct target_ops *self) { devctl (ctl_fd, DCMD_PROC_STOP, NULL, 0, 0); }