Ticket #1436: newpatch.2

File newpatch.2, 3.0 KB (added by absabs, 16 years ago)
Line 
1--- .svn/text-base/strace.cpp.svn-base 2007-09-01 23:43:50.410947385 +0800
2+++ strace.cpp 2008-01-11 13:03:59.898650227 +0800
3@@ -8,6 +8,7 @@
4 #include <stdlib.h>
5 #include <string.h>
6 #include <errno.h>
7+#include <signal.h>
8
9 #include <map>
10 #include <string>
11@@ -84,7 +85,39 @@
12 static const char *kTerminalTextRed = "\33[31m";
13 static const char *kTerminalTextMagenta = "\33[35m";
14
15+static const char *signalname[] = {
16+ /* 0 */"SIG0",
17+ /* 1 */"SIGHUP",
18+ /* 2 */"SIGINT",
19+ /* 3 */"SIGQUIT",
20+ /* 4 */"SIGILL",
21+ /* 5 */"SIGCHLD",
22+ /* 6 */"SIGABRT",
23+ /* 7 */"SIGPIPE",
24+ /* 8 */"SIGFPE",
25+ /* 9 */"SIGKILL",
26+ /* 10 */"SIGSTOP",
27+ /* 11 */"SIGSEGV",
28+ /* 12 */"SIGCONT",
29+ /* 13 */"SIGTSTP",
30+ /* 14 */"SIGALRM",
31+ /* 15 */"SIGTERM",
32+ /* 16 */"SIGTTIN",
33+ /* 17 */"SIGTTOU",
34+ /* 18 */"SIGUSR1",
35+ /* 19 */"SIGUSR2",
36+ /* 20 */"SIGWINCH",
37+ /* 21 */"SIGKILLTHR",
38+ /* 22 */"SIGTRAP",
39+ /* 23 */"SIGPOLL",
40+ /* 24 */"SIGPROF",
41+ /* 25 */"SIGSYS",
42+ /* 26 */"SIGURG",
43+ /* 27 */"SIGVTALRM",
44+ /* 28 */"SIGXCPU",
45+ /* 29 */"SIGXFSZ",
46
47+};
48 // command line args
49 static int sArgc;
50 static const char *const *sArgv;
51@@ -432,6 +465,45 @@
52 _kern_debug_output(buffer);
53 }
54
55+static
56+const char *
57+signame(int signal)
58+{
59+ static char buf[32];
60+ if (signal >= 0 && signal < NSIG)
61+ return signalname[signal];
62+ else {
63+ sprintf(buf, "%d", signal);
64+ return buf;
65+ }
66+}
67+
68+// print_signal
69+static
70+void
71+print_signal(FILE *outputFile, debug_signal_received &message,
72+ bool colorize)
73+{
74+ char buffer[4096], *string = buffer;
75+ int32 length = (int32)sizeof(buffer);
76+ int signalNumber = message.signal;
77+
78+ // print syscall name
79+ if (colorize) {
80+ print_to_string(&string, &length, "--- %s%s (%s) %s ---\n",
81+ kTerminalTextRed, signame(signalNumber),
82+ strsignal(signalNumber), kTerminalTextNormal);
83+ } else {
84+ print_to_string(&string, &length, "--- %s (%s) ---\n",
85+ signame(signalNumber), strsignal(signalNumber));
86+ }
87+
88+ // output either to file or serial debug line
89+ if (outputFile != NULL)
90+ fwrite(buffer, sizeof(buffer) - length, 1, outputFile);
91+ else
92+ _kern_debug_output(buffer);
93+}
94
95 // main
96 int
97@@ -597,6 +669,7 @@
98
99 // set team debugging flags
100 int32 teamDebugFlags = (traceTeam ? B_TEAM_DEBUG_POST_SYSCALL : 0);
101+ teamDebugFlags |= B_TEAM_DEBUG_SIGNALS;
102 set_team_debugging_flags(nubPort, teamDebugFlags);
103
104 // set thread debugging flags
105@@ -642,13 +715,18 @@
106 break;
107 }
108
109+ case B_DEBUGGER_MESSAGE_SIGNAL_RECEIVED:
110+ {
111+ print_signal(outputFile, message.signal_received,
112+ colorize);
113+ break;
114+ }
115 case B_DEBUGGER_MESSAGE_THREAD_DEBUGGED:
116 case B_DEBUGGER_MESSAGE_DEBUGGER_CALL:
117 case B_DEBUGGER_MESSAGE_BREAKPOINT_HIT:
118 case B_DEBUGGER_MESSAGE_WATCHPOINT_HIT:
119 case B_DEBUGGER_MESSAGE_SINGLE_STEP:
120 case B_DEBUGGER_MESSAGE_PRE_SYSCALL:
121- case B_DEBUGGER_MESSAGE_SIGNAL_RECEIVED:
122 case B_DEBUGGER_MESSAGE_EXCEPTION_OCCURRED:
123 case B_DEBUGGER_MESSAGE_TEAM_CREATED:
124 case B_DEBUGGER_MESSAGE_THREAD_CREATED: