From e13184e7cb12538ea6197bcde52a59e80fc41332 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Fri, 12 Sep 2014 20:52:30 +0200 Subject: [PATCH] trans/crash: add --verbose Verbosely log application crashes to stderr. * trans/crash.c (verbose): New variable. (S_crash_dump_task): Verbosely log application crashes to stderr. (options): Add --verbose. (parse_opt): Parse --verbose. --- trans/crash.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/trans/crash.c b/trans/crash.c index 4a59d45..1778f08 100644 --- a/trans/crash.c +++ b/trans/crash.c @@ -70,6 +70,7 @@ enum crash_action #define CRASH_ORPHANS_DEFAULT crash_corefile static enum crash_action crash_how, crash_orphans_how; +static int verbose; /* This is defined in ../exec/elfcore.c, or we could have @@ -175,6 +176,24 @@ S_crash_dump_task (mach_port_t port, } } + if (verbose) + { + pid_t pid; + char *args; + size_t args_len; + err = proc_task2pid (procserver, task, &pid); + + if (! err) + err = proc_getprocargs (procserver, pid, &args, &args_len); + + if (! err) + { + error (0, 0, "%s(%d) received signal %d: %s", + args, pid, signo, strsignal (signo)); + vm_deallocate (mach_task_self (), (vm_address_t) args, args_len); + } + } + switch (how) { default: /* NOTREACHED */ @@ -439,6 +458,7 @@ static const struct argp_option options[] = {0,0,0,0,"These options specify the disposition of a crashing process:", 1}, {"action", 'a', "ACTION", 0, "Action taken on crashing processes", 1}, {"orphan-action", 'O', "ACTION", 0, "Action taken on crashing orphans", 1}, + {"verbose", 'v', NULL, 0, "Log crashes to stderr", 1}, {0,0,0,0,"These options are synonyms for --action=OPTION:", 2}, {"suspend", 's', 0, 0, "Suspend the process", 2}, @@ -489,6 +509,7 @@ parse_opt (int opt, char *arg, struct argp_state *state) case 's': crash_how = crash_suspend; break; case 'k': crash_how = crash_kill; break; case 'c': crash_how = crash_corefile; break; + case 'v': verbose = 1; break; case ARGP_KEY_SUCCESS: if (crash_orphans_how == crash_unspecified) @@ -531,6 +552,9 @@ trivfs_append_args (struct trivfs_control *fsys, err = argz_add (argz, argz_len, opt); } + if (!err && verbose) + err = argz_add (argz, argz_len, "--verbose"); + return err; } -- 2.1.0