X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Fprocfs.c;h=ccc5e26064bf3620947219d32e166381e2c15667;hb=e46d79a76ea748165a3ecd1102dd10498d089a49;hp=9e3d037b695b7537f25805f85ff0bdda36246614;hpb=42a4f53d2bf8938c2aeda9f52be7a20534b214a9;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/procfs.c b/gdb/procfs.c index 9e3d037b69..ccc5e26064 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -31,14 +31,14 @@ #include "regcache.h" #include "inf-child.h" #include "nat/fork-inferior.h" -#include "filestuff.h" +#include "gdbarch.h" #define _STRUCTURED_PROC 1 /* Should be done by configure script. */ #include #include #include -#include "gdb_wait.h" +#include "gdbsupport/gdb_wait.h" #include #include #include "gdb_bfd.h" @@ -46,8 +46,8 @@ #include "auxv.h" #include "procfs.h" #include "observable.h" -#include "common/scoped_fd.h" -#include "common/pathstuff.h" +#include "gdbsupport/scoped_fd.h" +#include "gdbsupport/pathstuff.h" /* This module provides the interface between GDB and the /proc file system, which is used on many versions of Unix @@ -119,7 +119,7 @@ public: ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) override; - void pass_signals (int, unsigned char *) override; + void pass_signals (gdb::array_view) override; void files_info () override; @@ -127,7 +127,7 @@ public: bool thread_alive (ptid_t ptid) override; - const char *pid_to_str (ptid_t) override; + std::string pid_to_str (ptid_t) override; char *pid_to_exec_file (int pid) override; @@ -385,7 +385,7 @@ open_procinfo_files (procinfo *pi, int which) several. Here is some rationale: There are several file descriptors that may need to be open - for any given process or LWP. The ones we're intereted in are: + for any given process or LWP. The ones we're interested in are: - control (ctl) write-only change the state - status (status) read-only query the state - address space (as) read/write access memory @@ -838,7 +838,7 @@ proc_unset_run_on_last_close (procinfo *pi) } /* Reset inherit_on_fork flag. If the process forks a child while we - are registered for events in the parent, then we will NOT recieve + are registered for events in the parent, then we will NOT receive events from the child. Returns non-zero for success, zero for failure. */ @@ -909,7 +909,12 @@ proc_wait_for_stop (procinfo *pi) procfs_ctl_t cmd = PCWSTOP; + set_sigint_trap (); + win = (write (pi->ctl_fd, (char *) &cmd, sizeof (cmd)) == sizeof (cmd)); + + clear_sigint_trap (); + /* We been runnin' and we stopped -- need to update status. */ pi->status_valid = 0; @@ -1865,7 +1870,6 @@ procfs_debug_inferior (procinfo *pi) void procfs_target::attach (const char *args, int from_tty) { - char *exec_file; int pid; pid = parse_pid_to_attach (args); @@ -1875,14 +1879,14 @@ procfs_target::attach (const char *args, int from_tty) if (from_tty) { - exec_file = get_exec_file (0); + const char *exec_file = get_exec_file (0); if (exec_file) printf_filtered (_("Attaching to program `%s', %s\n"), - exec_file, target_pid_to_str (ptid_t (pid))); + exec_file, target_pid_to_str (ptid_t (pid)).c_str ()); else printf_filtered (_("Attaching to %s\n"), - target_pid_to_str (ptid_t (pid))); + target_pid_to_str (ptid_t (pid)).c_str ()); fflush (stdout); } @@ -1905,8 +1909,7 @@ procfs_target::detach (inferior *inf, int from_tty) exec_file = ""; printf_filtered (_("Detaching from program: %s, %s\n"), exec_file, - target_pid_to_str (ptid_t (pid))); - gdb_flush (gdb_stdout); + target_pid_to_str (ptid_t (pid)).c_str ()); } do_detach (); @@ -2059,7 +2062,7 @@ procfs_target::fetch_registers (struct regcache *regcache, int regnum) if (pi == NULL) error (_("procfs: fetch_registers failed to find procinfo for %s"), - target_pid_to_str (ptid)); + target_pid_to_str (ptid).c_str ()); gregs = proc_get_gregs (pi); if (gregs == NULL) @@ -2108,7 +2111,7 @@ procfs_target::store_registers (struct regcache *regcache, int regnum) if (pi == NULL) error (_("procfs: store_registers: failed to find procinfo for %s"), - target_pid_to_str (ptid)); + target_pid_to_str (ptid).c_str ()); gregs = proc_get_gregs (pi); if (gregs == NULL) @@ -2281,7 +2284,7 @@ wait_again: { if (print_thread_events) printf_unfiltered (_("[%s exited]\n"), - target_pid_to_str (retval)); + target_pid_to_str (retval).c_str ()); delete_thread (find_thread_ptid (retval)); status->kind = TARGET_WAITKIND_SPURIOUS; return retval; @@ -2402,7 +2405,7 @@ wait_again: { if (print_thread_events) printf_unfiltered (_("[%s exited]\n"), - target_pid_to_str (retval)); + target_pid_to_str (retval).c_str ()); delete_thread (find_thread_ptid (retval)); status->kind = TARGET_WAITKIND_SPURIOUS; return retval; @@ -2472,40 +2475,12 @@ wait_again: wstat = (what << 8) | 0177; break; case PR_FAULTED: - switch (what) { - case FLTWATCH: - wstat = (SIGTRAP << 8) | 0177; - break; - /* FIXME: use si_signo where possible. */ - case FLTPRIV: - case FLTILL: - wstat = (SIGILL << 8) | 0177; - break; - case FLTBPT: - case FLTTRACE: - wstat = (SIGTRAP << 8) | 0177; - break; - case FLTSTACK: - case FLTACCESS: - case FLTBOUNDS: - wstat = (SIGSEGV << 8) | 0177; - break; - case FLTIOVF: - case FLTIZDIV: - case FLTFPE: - wstat = (SIGFPE << 8) | 0177; - break; - case FLTPAGE: /* Recoverable page fault */ - default: /* FIXME: use si_signo if possible for - fault. */ - retval = ptid_t (-1); - printf_filtered ("procfs:%d -- ", __LINE__); - printf_filtered (_("child stopped for unknown reason:\n")); - proc_prettyprint_why (why, what, 1); - error (_("... giving up...")); - break; + { + int signo = pi->prstatus.pr_lwp.pr_info.si_signo; + if (signo != 0) + wstat = (signo << 8) | 0177; } - break; /* case PR_FAULTED: */ + break; default: /* switch (why) unmatched */ printf_filtered ("procfs:%d -- ", __LINE__); printf_filtered (_("child stopped for unknown reason:\n")); @@ -2615,7 +2590,7 @@ procfs_xfer_memory (gdb_byte *readbuf, const gdb_byte *writebuf, File descriptors are also cached. As they are a limited resource, we cannot hold onto them indefinitely. However, as they are expensive to open, we don't want to throw them away - indescriminately either. As a compromise, we will keep the file + indiscriminately either. As a compromise, we will keep the file descriptors for the parent process, but discard any file descriptors we may have accumulated for the threads. @@ -2772,7 +2747,7 @@ procfs_target::resume (ptid_t ptid, int step, enum gdb_signal signo) /* Set up to trace signals in the child process. */ void -procfs_target::pass_signals (int numsigs, unsigned char *pass_signals) +procfs_target::pass_signals (gdb::array_view pass_signals) { sigset_t signals; procinfo *pi = find_procinfo_or_die (inferior_ptid.pid (), 0); @@ -2783,7 +2758,7 @@ procfs_target::pass_signals (int numsigs, unsigned char *pass_signals) for (signo = 0; signo < NSIG; signo++) { int target_signo = gdb_signal_from_host (signo); - if (target_signo < numsigs && pass_signals[target_signo]) + if (target_signo < pass_signals.size () && pass_signals[target_signo]) prdelset (&signals, signo); } @@ -2800,7 +2775,7 @@ procfs_target::files_info () printf_filtered (_("\tUsing the running image of %s %s via /proc.\n"), inf->attach_flag? "attached": "child", - target_pid_to_str (inferior_ptid)); + target_pid_to_str (inferior_ptid).c_str ()); } /* Make it die. Wait for it to die. Clean up after it. Note: this @@ -3185,20 +3160,15 @@ procfs_target::thread_alive (ptid_t ptid) return true; } -/* Convert PTID to a string. Returns the string in a static - buffer. */ +/* Convert PTID to a string. */ -const char * +std::string procfs_target::pid_to_str (ptid_t ptid) { - static char buf[80]; - if (ptid.lwp () == 0) - xsnprintf (buf, sizeof (buf), "process %d", ptid.pid ()); + return string_printf ("process %d", ptid.pid ()); else - xsnprintf (buf, sizeof (buf), "LWP %ld", ptid.lwp ()); - - return buf; + return string_printf ("LWP %ld", ptid.lwp ()); } /* Accepts an integer PID; Returns a string representing a file that