--- crash-4.0-4.12/task.c 2007-12-12 19:48:09.000000000 +0100 +++ crash-4.0-4.12.args/task.c 2008-01-07 05:52:09.000000000 +0100 @@ -35,6 +35,7 @@ static void child_list(ulong); static void show_task_times(struct task_context *, ulong); static void show_task_args(struct task_context *); +static void show_args(struct task_context *); static void show_task_rlimit(struct task_context *); static void show_tgid_list(ulong); static int compare_start_time(const void *, const void *); @@ -2467,7 +2468,7 @@ BZERO(&psinfo, sizeof(struct psinfo)); flag = 0; - while ((c = getopt(argcnt, args, "gstcpkular")) != EOF) { + while ((c = getopt(argcnt, args, "fgstcpkular")) != EOF) { switch(c) { case 'k': @@ -2480,6 +2481,10 @@ flag &= ~PS_KERNEL; break; + case 'f': + flag |= PS_ARGS; + break; + /* * The a, t, c, p, g and l flags are all mutually-exclusive. */ @@ -2637,7 +2642,9 @@ fprintf(fp, "%6ld ", (tm->rss * PAGESIZE())/1024); \ if (is_kernel_thread(tc->task)) \ fprintf(fp, "[%s]\n", tc->comm); \ - else \ + else if(flag & PS_ARGS) \ + show_args(tc); \ + else \ fprintf(fp, "%s\n", tc->comm); static void @@ -2863,6 +2870,93 @@ FREEBUF(buf); } +/* + * Show the argv strings pointed to by mm_struct->arg_start + * it is a derived from show_task_args. + */ +static void +show_args(struct task_context *tc) +{ + ulong arg_start, arg_end, env_start, env_end; + char *buf, *bufptr, *p1; + char *as, *ae; + physaddr_t paddr; + ulong uvaddr, size, cnt; + int c; + + if (!tc || !tc->mm_struct) { /* probably a kernel thread */ + error(INFO, "no user stack\n\n"); + return; + } + + if (!task_mm(tc->task, TRUE)) + return; + + if (INVALID_MEMBER(mm_struct_arg_start)) { + MEMBER_OFFSET_INIT(mm_struct_arg_start, "mm_struct", "arg_start"); + MEMBER_OFFSET_INIT(mm_struct_arg_end, "mm_struct", "arg_end"); + MEMBER_OFFSET_INIT(mm_struct_env_start, "mm_struct", "env_start"); + MEMBER_OFFSET_INIT(mm_struct_env_end, "mm_struct", "env_end"); + } + + arg_start = ULONG(tt->mm_struct + OFFSET(mm_struct_arg_start)); + arg_end = ULONG(tt->mm_struct + OFFSET(mm_struct_arg_end)); + + if (CRASHDEBUG(1)) { + fprintf(fp, "arg_start: %lx arg_end: %lx (%ld)\n", + arg_start, arg_end, arg_end - arg_start); + } + + buf = GETBUF(arg_end - arg_start + 1); + + uvaddr = arg_start; + size = arg_end - arg_start; + bufptr = buf; + + while (size > 0) { + if (!uvtop(tc, uvaddr, &paddr, 0)) { + error(INFO, "cannot access user stack address: %lx\n\n", + uvaddr); + goto bailout; + } + + cnt = PAGESIZE() - PAGEOFFSET(uvaddr); + + if (cnt > size) + cnt = size; + + if (!readmem(paddr, PHYSADDR, bufptr, cnt, + "user stack contents", RETURN_ON_ERROR|QUIET)) { + error(INFO, "cannot access user stack address: %lx\n\n", + uvaddr); + goto bailout; + } + + uvaddr += cnt; + bufptr += cnt; + size -= cnt; + } + + as = buf; + ae = &buf[arg_end - arg_start]; + + for (p1 = as, c = 0; p1 < ae; p1++) { + if (*p1 == NULLCHAR) { + if (c) + fprintf(fp, " "); + c = 0; + } else { + fprintf(fp, "%c", *p1); + c++; + } + } + + fprintf(fp, "\n"); + +bailout: + FREEBUF(buf); +} + char *rlim_names[] = { /* 0 */ "CPU", /* 1 */ "FSIZE", --- crash-4.0-4.12/defs.h 2007-12-12 19:48:09.000000000 +0100 +++ crash-4.0-4.12.args/defs.h 2008-01-06 16:53:38.000000000 +0100 @@ -2938,6 +2938,7 @@ #define PS_ARGV_ENVP (0x800) #define PS_TGID_LIST (0x1000) #define PS_RLIMIT (0x2000) +#define PS_ARGS (0x4000) #define PS_EXCLUSIVE (PS_TGID_LIST|PS_ARGV_ENVP|PS_TIMES|PS_CHILD_LIST|PS_PPID_LIST|PS_LAST_RUN|PS_RLIMIT)