diff options
Diffstat (limited to 'gdb/nat')
-rw-r--r-- | gdb/nat/linux-waitpid.c | 28 | ||||
-rw-r--r-- | gdb/nat/linux-waitpid.h | 4 |
2 files changed, 32 insertions, 0 deletions
diff --git a/gdb/nat/linux-waitpid.c b/gdb/nat/linux-waitpid.c index 433efe7..e9e69db 100644 --- a/gdb/nat/linux-waitpid.c +++ b/gdb/nat/linux-waitpid.c @@ -28,6 +28,8 @@ #include "nat/linux-waitpid.h" #include "gdb_wait.h" +#include <string.h> + /* Print debugging output based on the format string FORMAT and its parameters. */ @@ -47,6 +49,32 @@ linux_debug (const char *format, ...) #endif } +/* Convert wait status STATUS to a string. Used for printing debug + messages only. */ + +char * +status_to_str (int status) +{ + static char buf[64]; + + if (WIFSTOPPED (status)) + { + if (WSTOPSIG (status) == SYSCALL_SIGTRAP) + snprintf (buf, sizeof (buf), "%s (stopped at syscall)", + strsignal (SIGTRAP)); + else + snprintf (buf, sizeof (buf), "%s (stopped)", + strsignal (WSTOPSIG (status))); + } + else if (WIFSIGNALED (status)) + snprintf (buf, sizeof (buf), "%s (terminated)", + strsignal (WTERMSIG (status))); + else + snprintf (buf, sizeof (buf), "%d (exited)", WEXITSTATUS (status)); + + return buf; +} + /* Wrapper function for waitpid which handles EINTR, and emulates __WALL for systems where that is not available. */ diff --git a/gdb/nat/linux-waitpid.h b/gdb/nat/linux-waitpid.h index ae90e50..cac38db 100644 --- a/gdb/nat/linux-waitpid.h +++ b/gdb/nat/linux-waitpid.h @@ -24,4 +24,8 @@ __WALL for systems where that is not available. */ extern int my_waitpid (int pid, int *status, int flags); +/* Convert wait status STATUS to a string. Used for printing debug + messages only. */ +extern char *status_to_str (int status); + #endif /* LINUX_WAITPID_H */ |