aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.gitignore2
-rw-r--r--Makefile12
-rw-r--r--common.h2
-rw-r--r--consts.c29
-rw-r--r--sctrace.c8
5 files changed, 46 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index aebf3a8..4ca6f7f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,4 @@
*.o
*.su
/sctrace
-/list-errnos.h
+/list-*.h
diff --git a/Makefile b/Makefile
index 3631779..251e7ed 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/common.h b/common.h
index d3df014..43b3d24 100644
--- a/common.h
+++ b/common.h
@@ -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);
diff --git a/consts.c b/consts.c
index 567a6e7..4e68230 100644
--- a/consts.c
+++ b/consts.c
@@ -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;
+}
diff --git a/sctrace.c b/sctrace.c
index 970d6c4..75b5507 100644
--- a/sctrace.c
+++ b/sctrace.c
@@ -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);