diff options
author | Mattias Andrée <maandree@kth.se> | 2020-05-31 00:23:22 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2020-05-31 00:23:22 +0200 |
commit | 4383640bfe4c40c055824d9c42ed8809bb3163b4 (patch) | |
tree | df194cbc3764320a88e25e1f77855aaaed4631ea | |
parent | Work around valgrind issue (diff) | |
download | sctrace-4383640bfe4c40c055824d9c42ed8809bb3163b4.tar.gz sctrace-4383640bfe4c40c055824d9c42ed8809bb3163b4.tar.bz2 sctrace-4383640bfe4c40c055824d9c42ed8809bb3163b4.tar.xz |
Print signal names
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | common.h | 2 | ||||
-rw-r--r-- | consts.c | 29 | ||||
-rw-r--r-- | sctrace.c | 8 |
5 files changed, 46 insertions, 7 deletions
@@ -3,4 +3,4 @@ *.o *.su /sctrace -/list-errnos.h +/list-*.h @@ -14,7 +14,8 @@ OBJ =\ HDR =\ arg.h\ common.h\ - list-errnos.h + list-errnos.h\ + list-signums.h all: sctrace $(OBJ): $(@:.o=.c) $(HDR) @@ -32,6 +33,13 @@ list-errnos.h: | sed -n '/^[ \t]*#[ \t]*define[ \t].*[ \t][0-9]*[ \t]*$$/s/^[ \t#]*define[ \t]*\([^ \t]*\).*$$/_(\1)/p' \ | sort | uniq | tr '\n' '#' | sed 's/#_/\\\n\t_/g' | tr '#' '\n' >> $@ +list-signums.h: + printf '#define LIST_SIGNUMS(_)\\\n\t' > $@ + cat /usr/include/bits/signum.h /usr/include/bits/signum-generic.h \ + | sed 's/\/\/.*$$//' | tr -d '$$' | sed 's/\*\//\$$/g' | sed 's/\/\*[^$$]*\$$//g' \ + | sed -n '/^[ \t]*#[ \t]*define[ \t][^_]*[ \t][0-9]*[ \t]*$$/s/^[ \t#]*define[ \t]*\([^ \t]*\).*$$/_(\1)/p' \ + | sort | uniq | tr '\n' '#' | sed 's/#_/\\\n\t_/g' | tr '#' '\n' >> $@ + install: sctrace mkdir -p -- "$(DESTDIR)$(PREFIX)/bin" cp -- sctrace "$(DESTDIR)$(PREFIX)/bin" @@ -40,7 +48,7 @@ uninstall: -rm -f -- "$(DESTDIR)$(PREFIX)/bin/sctrace" clean: - -rm -f -- *.o list-errnos.h sctrace + -rm -f -- *.o list-*.h sctrace .SUFFIXES: .SUFFIXES: .c .o @@ -26,6 +26,7 @@ #include "arg.h" #include "list-errnos.h" +#include "list-signums.h" #ifndef ERESTARTSYS @@ -97,6 +98,7 @@ struct process { /* consts.c */ const char *get_errno_name(int err); +const char *get_signum_name(int sig); /* memory.c */ char *get_string(pid_t pid, unsigned long int addr, size_t *lenp, const char **errorp); @@ -26,3 +26,32 @@ get_errno_name(int err) sprintf(buf, "%i", err); return buf; } + + +const char * +get_signum_name(int sig) +{ + static char buf[3 * sizeof(sig) + 2]; + int above_low, below_high; + +#define X(N) if (sig == N) return #N; + LIST_SIGNUMS(X) +#undef X + + if (__SIGRTMIN <= sig && sig <= __SIGRTMAX) { + above_low = sig - __SIGRTMIN; + below_high = __SIGRTMAX - sig; + if (!above_low) + return "__SIGRTMIN"; + if (!below_high) + return "__SIGRTMAX"; + if (above_low <= below_high) + sprintf(buf, "__SIGRTMIN+%i", above_low); + else + sprintf(buf, "__SIGRTMAX-%i", below_high); + return buf; + } + + sprintf(buf, "%i", sig); + return buf; +} @@ -216,8 +216,8 @@ have_outfp: } } else if (WIFSIGNALED(status)) { - tprintf(proc, "\nProcess terminated by signal %i (%s)\n", WTERMSIG(status), strsignal(WTERMSIG(status))); - /* TODO print signal name */ + tprintf(proc, "\nProcess terminated by signal %i (%s: %s)\n", WTERMSIG(status), + get_signum_name(WTERMSIG(status)), strsignal(WTERMSIG(status))); } else if (WIFSTOPPED(status)) { if (WSTOPSIG(status) == (SIGTRAP | 0x80)) { @@ -268,8 +268,8 @@ have_outfp: } } else { print_signal: - tprintf(proc, "\nProcess stopped by signal %i (%s)\n", WSTOPSIG(status), strsignal(WSTOPSIG(status))); - /* TODO print signal name */ + tprintf(proc, "\nProcess stopped by signal %i (%s: %s)\n", WSTOPSIG(status), + get_signum_name(WSTOPSIG(status)), strsignal(WSTOPSIG(status))); /* TODO handle signals properly */ if (ptrace(PTRACE_SYSCALL, proc->pid, NULL, 0)) eprintf("ptrace PTRACE_SYSCALL %ju NULL 0", (uintmax_t)proc->pid); |