code cleanup

This commit is contained in:
Stefani Seibold 2018-04-18 12:47:43 +02:00
parent 31e24c9426
commit badc8d24fd
4 changed files with 14 additions and 15 deletions

View File

@ -48,7 +48,6 @@ void _debug(int level, const char *file, const char *function, int line, const c
fprintf(stderr, "DEBUG: %s():%s@%d - %s\n", function, file, line, buf); fprintf(stderr, "DEBUG: %s():%s@%d - %s\n", function, file, line, buf);
// fflush(debug_file);
free(buf); free(buf);
} }

View File

@ -456,7 +456,7 @@ int handle_event(struct task *task)
break; break;
case EVENT_BREAKPOINT: case EVENT_BREAKPOINT:
ret = handle_breakpoint(task); ret = handle_breakpoint(task);
goto out1; goto out2;
case EVENT_NEW: case EVENT_NEW:
ret = handle_new(task); ret = handle_new(task);
break; break;

View File

@ -90,7 +90,7 @@ struct options_t {
int lflag; /* long dump */ int lflag; /* long dump */
}; };
struct options_t options; extern struct options_t options;
char **process_options(int argc, char **argv); char **process_options(int argc, char **argv);

View File

@ -77,7 +77,7 @@ static int trace_setup(struct task *task, int status, int signum)
if (!WIFSTOPPED(status)) { if (!WIFSTOPPED(status)) {
if (unlikely(options.verbose)) if (unlikely(options.verbose))
fprintf(stderr, "!!!pid=%d not stopped\n", task->pid); fprintf(stderr, "!!!%s: pid=%d not stopped\n", __func__, task->pid);
return -1; return -1;
} }
@ -93,7 +93,7 @@ static int trace_setup(struct task *task, int status, int signum)
task->event.e_un.signum = sig; task->event.e_un.signum = sig;
if (unlikely(options.verbose)) if (unlikely(options.verbose))
fprintf(stderr, "!!!pid=%d unexpected trace signal (got:%d expected:%d)\n", task->pid, sig, signum); fprintf(stderr, "!!!%s: pid=%d unexpected trace signal (got:%d expected:%d)\n", __func__, task->pid, sig, signum);
return -1; return -1;
} }
@ -178,7 +178,7 @@ static int _process_event(struct task *task, int status)
if (!WIFSTOPPED(status)) { if (!WIFSTOPPED(status)) {
if (unlikely(options.verbose)) if (unlikely(options.verbose))
fprintf(stderr, "!!!not WIFSTOPPED pid=%d\n", task->pid); fprintf(stderr, "!!!%s: not WIFSTOPPED pid=%d\n", __func__, task->pid);
return -1; return -1;
} }
@ -192,7 +192,7 @@ static int _process_event(struct task *task, int status)
if (!task->bad) { if (!task->bad) {
if (unlikely(options.verbose)) if (unlikely(options.verbose))
fprintf(stderr, "!!!unexpected state for pid=%d, expected signal SIGSTOP (%d %d)\n", task->pid, sig, status >> 16); fprintf(stderr, "!!!%s: unexpected state for pid=%d, expected signal SIGSTOP (%d %d)\n", __func__, task->pid, sig, status >> 16);
task->bad = 1; task->bad = 1;
} }
} }
@ -228,7 +228,7 @@ static int _process_event(struct task *task, int status)
} }
default: default:
if (unlikely(options.verbose)) if (unlikely(options.verbose))
fprintf(stderr, "!!!PTRACE_EVENT_????? pid=%d %d\n", task->pid, status >> 16); fprintf(stderr, "!!!%s: PTRACE_EVENT_????? pid=%d %d\n", __func__, task->pid, status >> 16);
break; break;
} }
@ -341,7 +341,7 @@ static struct task * process_event(struct task *task, int status)
void trace_me(void) void trace_me(void)
{ {
debug(DEBUG_PROCESS, "pid=%d", getpid()); debug(DEBUG_TRACE, "pid=%d", getpid());
prctl(PR_SET_PDEATHSIG, SIGKILL); prctl(PR_SET_PDEATHSIG, SIGKILL);
@ -405,7 +405,7 @@ void stop_task(struct task *task)
int trace_attach(struct task *task) int trace_attach(struct task *task)
{ {
debug(DEBUG_PROCESS, "pid=%d", task->pid); debug(DEBUG_TRACE, "pid=%d", task->pid);
assert(task->attached == 0); assert(task->attached == 0);
@ -425,7 +425,7 @@ int trace_set_options(struct task *task)
{ {
long options = PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK | PTRACE_O_TRACECLONE | PTRACE_O_TRACEEXEC | PTRACE_O_TRACEEXIT; long options = PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK | PTRACE_O_TRACECLONE | PTRACE_O_TRACEEXEC | PTRACE_O_TRACEEXIT;
debug(DEBUG_PROCESS, "pid=%d", task->pid); debug(DEBUG_TRACE, "pid=%d", task->pid);
if (unlikely(ptrace(PTRACE_SETOPTIONS, task->pid, 0, (void *)options) == -1)) { if (unlikely(ptrace(PTRACE_SETOPTIONS, task->pid, 0, (void *)options) == -1)) {
if (errno != ESRCH) if (errno != ESRCH)
@ -437,13 +437,13 @@ int trace_set_options(struct task *task)
int continue_task(struct task *task, int signum) int continue_task(struct task *task, int signum)
{ {
debug(DEBUG_PROCESS, "continue task pid=%d", task->pid); debug(DEBUG_TRACE, "continue task pid=%d", task->pid);
assert(task->leader != NULL); assert(task->leader != NULL);
assert(task->stopped); assert(task->stopped);
if (unlikely(options.verbose && signum >= 0x80)) if (unlikely(options.verbose && signum >= 0x80))
fprintf(stderr, "!!!signum >= 0x80 pid=%d: %d\n", task->pid, signum); fprintf(stderr, "!!!%s: signum >= 0x80 pid=%d: %d\n", __func__, task->pid, signum);
task->leader->threads_stopped--; task->leader->threads_stopped--;
task->stopped = 0; task->stopped = 0;
@ -605,8 +605,6 @@ struct task *wait_event(void)
} }
if (unlikely(task->stopped)) { if (unlikely(task->stopped)) {
fprintf(stderr, "!!!%s: pid=%d already stopped (%u)\n", __func__, task->pid, task->event.type);
if (WIFSIGNALED(status)) { if (WIFSIGNALED(status)) {
if (unlikely(options.verbose)) if (unlikely(options.verbose))
fprintf(stderr, "!!!%s: exit signal for stopped pid=%d\n", __func__, task->pid); fprintf(stderr, "!!!%s: exit signal for stopped pid=%d\n", __func__, task->pid);
@ -640,6 +638,8 @@ struct task *wait_event(void)
task->event.type = EVENT_ABOUT_EXIT; task->event.type = EVENT_ABOUT_EXIT;
return NULL; return NULL;
} }
fprintf(stderr, "!!!%s: pid=%d already stopped (%u)\n", __func__, task->pid, task->event.type);
} }
task = process_event(task, status); task = process_event(task, status);