/* * Print a list of traced processes and their call status. We must not * interfere with actual process output, so perform out-of-band printing * (with info lines rather than lines prefixed by each process's PID). */ static void list_info(void) { struct trace_proc *proc; int no_call, in_call; put_newline(); for (proc = proc_next(NULL); proc != NULL; proc = proc_next(proc)) { /* * When attaching to an existing process, there is no way to * find out whether the process is in a system call or not. */ no_call = (proc->trace_flags & TF_NOCALL); in_call = (proc->trace_flags & TF_INCALL); assert(!in_call || !no_call); put_fmt(NULL, "Tracing %s (pid %d), %s%s%s", proc->name, proc->pid, no_call ? "call status unknown" : (in_call ? "in a " : "not in a call"), in_call ? call_name(proc) : "", in_call ? " call" : ""); put_newline(); } }
/* * Either we have just started or attached to the given process, it the process * has performed a successful execve() call. Obtain the new process name, and * print a banner for it. */ static void new_exec(struct trace_proc * proc) { /* Failure to obtain the process name is worrisome, but not fatal.. */ if (kernel_get_name(proc->pid, proc->name, sizeof(proc->name)) < 0) strlcpy(proc->name, "<unknown>", sizeof(proc->name)); put_newline(); put_fmt(proc, "Tracing %s (pid %d)", proc->name, proc->pid); put_newline(); }
PUBLIC void param_help (PCHAR appname, PCHAR par_text) { UINT i,max,len; PCHAR oper; char buffer[4096]; max = 0; for (i=0;i < params.p_count;i++) { len = strlen (params.p_info[i].p_tag); if (len > max) max = len; } if (isnull (par_text)) par_text = PAR_HELP_PARAMS; len = printf (PAR_HELP_MASK,appname); str_puttext (par_text,0,len,0); put_newline (); for (i=0;i < params.p_count;i++) { switch (params.p_info[i].p_type) { case pt_int: oper = PAR_HELP_VAL; sprintf (buffer,"%s (default %ld)",params.p_info[i].p_help, (LONG) params.p_info[i].p_default.u_int); break; case pt_char: oper = PAR_HELP_CHR; sprintf (buffer,"%s (default '%c')",params.p_info[i].p_help, params.p_info[i].p_default.u_char); break; case pt_str: oper = PAR_HELP_STR; sprintf (buffer,"%s (default '%s')",params.p_info[i].p_help, params.p_info[i].p_default.u_str); break; default: oper = PAR_HELP_EMPTY; sprintf (buffer,params.p_info[i].p_help); } len = printf ("%*s%-*s %-6s",PAR_HELP_LEFT,PAR_HELP_EMPTY, max,params.p_info[i].p_tag,oper); str_puttext (buffer,0,len,0); put_newline (); } put_newline (); }
/* * A process has terminated or is being detached. Print the resulting status. */ static void discard_proc(struct trace_proc * proc, int status) { const char *signame; /* * The exit() calls are of type no-return, meaning they are expected * not to return. However, calls of this type may in fact return an * error, in which case the error must be printed. Thus, such calls * are not actually finished until the end of the call-leave phase. * For exit() calls, a successful call will never get to the call-leave * phase. The result is that such calls will end up being shown as * suspended, which is unintuitive. To counter this, we pretend that a * clean process exit is in fact preceded by a call-leave event, thus * allowing the call to be printed without suspension. An example: * * 3| exit(0) <..> * 2| setsid() = 2 * [A] 3| exit(0) * 3| Process exited normally with code 0 * * The [A] line is the result of the following code. */ if (WIFEXITED(status) && (proc->trace_flags & TF_INCALL)) call_leave(proc, TRUE /*skip*/); put_newline(); if (WIFEXITED(status)) { put_fmt(proc, "Process exited normally with code %d", WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { if ((signame = get_signal_name(WTERMSIG(status))) != NULL) put_fmt(proc, "Process terminated from signal %s", signame); else put_fmt(proc, "Process terminated from signal %d", WTERMSIG(status)); } else if (WIFSTOPPED(status)) put_text(proc, "Process detached"); else put_fmt(proc, "Bogus wait result (%04x)", status); put_newline(); proc_del(proc); }
static void put_sep(proc_entry *t, proc_entry *s, int level){ unsigned int i; int isfirst = 0; int islast = 0; /* last */ for (i = t->childs.len - 1; i >= 0; --i){ if (t->childs.s[i]->count == 0) continue; if (t->childs.s[i] == s) {islast = 1; break;} break; } /* first */ for(i = 0; i < t->childs.len; ++i){ if (!t->childs.s[i]->count) continue; if (t->childs.s[i] == s) {isfirst = 1; break;} break; } if (isfirst){ if (islast){ put_str("---"); return; } else{ put_str("-");putx("+");put_str("-"); return; } } put_newline(t); if (islast){ put_str("`-"); return; } else{ putx("|");put_str("-"); return; } }