📄 process.c
字号:
char *fmt;struct tcb *tcp;long addr;{ int count; char *cp; for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) { addr += sizeof(char *); } tprintf(fmt, count, count == 1 ? "" : "s");}intsys_execv(tcp)struct tcb *tcp;{ if (entering(tcp)) { printpath(tcp, tcp->u_arg[0]); if (!verbose(tcp)) tprintf(", %#lx", tcp->u_arg[1]);#if 0 else if (abbrev(tcp)) printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);#endif else { tprintf(", ["); printargv(tcp, tcp->u_arg[1]); tprintf("]"); } } return 0;}intsys_execve(tcp)struct tcb *tcp;{ if (entering(tcp)) { printpath(tcp, tcp->u_arg[0]); if (!verbose(tcp)) tprintf(", %#lx", tcp->u_arg[1]);#if 0 else if (abbrev(tcp)) printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);#endif else { tprintf(", ["); printargv(tcp, tcp->u_arg[1]); tprintf("]"); } if (!verbose(tcp)) tprintf(", %#lx", tcp->u_arg[2]); else if (abbrev(tcp)) printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]); else { tprintf(", ["); printargv(tcp, tcp->u_arg[2]); tprintf("]"); } }#ifdef LINUX#if defined(ALPHA) || defined(SPARC) || defined(POWERPC) || defined(HPPA) tcp->flags |= TCB_WAITEXECVE;#endif /* ALPHA || SPARC || POWERPC */#endif /* LINUX */ return 0;}intinternal_exec(tcp)struct tcb *tcp;{#ifdef SUNOS4 if (exiting(tcp) && !syserror(tcp) && followfork) fixvfork(tcp);#endif /* SUNOS4 */ return 0;}#ifdef LINUX#ifndef __WCLONE#define __WCLONE 0x8000000#endif#endif /* LINUX */static struct xlat wait4_options[] = { { WNOHANG, "WNOHANG" },#ifndef WSTOPPED { WUNTRACED, "WUNTRACED" },#endif#ifdef WEXITED { WEXITED, "WEXITED" },#endif#ifdef WTRAPPED { WTRAPPED, "WTRAPPED" },#endif#ifdef WSTOPPED { WSTOPPED, "WSTOPPED" },#endif#ifdef WCONTINUED { WCONTINUED, "WCONTINUED" },#endif#ifdef WNOWAIT { WNOWAIT, "WNOWAIT" },#endif#ifdef __WCLONE { __WCLONE, "__WCLONE" },#endif { 0, NULL },};static intprintstatus(status)int status;{ int exited = 0; /* * Here is a tricky presentation problem. This solution * is still not entirely satisfactory but since there * are no wait status constructors it will have to do. */ if (WIFSTOPPED(status)) tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]", signame(WSTOPSIG(status))); else if WIFSIGNALED(status) tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]", signame(WTERMSIG(status)), WCOREDUMP(status) ? " && WCOREDUMP(s)" : ""); else if WIFEXITED(status) { tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]", WEXITSTATUS(status)); exited = 1; } else tprintf("[%#x]", status); return exited;}static intprintwaitn(tcp, n, bitness)struct tcb *tcp;int n;int bitness;{ int status; int exited = 0; if (entering(tcp)) { tprintf("%ld, ", tcp->u_arg[0]); } else { /* status */ if (!tcp->u_arg[1]) tprintf("NULL"); else if (syserror(tcp) || tcp->u_rval == 0) tprintf("%#lx", tcp->u_arg[1]); else if (umove(tcp, tcp->u_arg[1], &status) < 0) tprintf("[?]"); else exited = printstatus(status); /* options */ tprintf(", "); if (!printflags(wait4_options, tcp->u_arg[2])) tprintf("0"); if (n == 4) { tprintf(", "); /* usage */ if (!tcp->u_arg[3]) tprintf("NULL");#ifdef LINUX else if (tcp->u_rval > 0) {#ifdef LINUX_64BIT if (bitness) printrusage32(tcp, tcp->u_arg[3]); else#endif printrusage(tcp, tcp->u_arg[3]); }#endif /* LINUX */#ifdef SUNOS4 else if (tcp->u_rval > 0 && exited) printrusage(tcp, tcp->u_arg[3]);#endif /* SUNOS4 */ else tprintf("%#lx", tcp->u_arg[3]); } } return 0;}intinternal_wait(tcp)struct tcb *tcp;{ if (entering(tcp)) { /* WTA: fix bug with hanging children */ if (!(tcp->u_arg[2] & WNOHANG) && tcp->nchildren > 0) { /* There are traced children */ tcp->flags |= TCB_SUSPENDED; tcp->waitpid = tcp->u_arg[0]; } } return 0;}#ifdef SVR4intsys_wait(tcp)struct tcb *tcp;{ if (exiting(tcp)) { /* The library wrapper stuffs this into the user variable. */ if (!syserror(tcp)) printstatus(getrval2(tcp)); } return 0;}#endif /* SVR4 */#ifdef FREEBSDintsys_wait(tcp)struct tcb *tcp;{ int status; if (exiting(tcp)) { if (!syserror(tcp)) { if (umove(tcp, tcp->u_arg[0], &status) < 0) tprintf("%#lx", tcp->u_arg[0]); else printstatus(status); } } return 0;}#endifintsys_waitpid(tcp)struct tcb *tcp;{ return printwaitn(tcp, 3, 0);}intsys_wait4(tcp)struct tcb *tcp;{ return printwaitn(tcp, 4, 0);}#ifdef ALPHAintsys_osf_wait4(tcp)struct tcb *tcp;{ return printwaitn(tcp, 4, 1);}#endif#ifdef SVR4static struct xlat waitid_types[] = { { P_PID, "P_PID" }, { P_PPID, "P_PPID" }, { P_PGID, "P_PGID" }, { P_SID, "P_SID" }, { P_CID, "P_CID" }, { P_UID, "P_UID" }, { P_GID, "P_GID" }, { P_ALL, "P_ALL" },#ifdef P_LWPID { P_LWPID, "P_LWPID" },#endif { 0, NULL },};static struct xlat siginfo_codes[] = {#ifdef SI_NOINFO { SI_NOINFO, "SI_NOINFO" },#endif#ifdef SI_USER { SI_USER, "SI_USER" },#endif#ifdef SI_LWP { SI_LWP, "SI_LWP" },#endif#ifdef SI_QUEUE { SI_QUEUE, "SI_QUEUE" },#endif#ifdef SI_TIMER { SI_TIMER, "SI_TIMER" },#endif#ifdef SI_ASYNCIO { SI_ASYNCIO, "SI_ASYNCIO" },#endif#ifdef SI_MESGQ { SI_MESGQ, "SI_MESGQ" },#endif { 0, NULL },};static struct xlat sigtrap_codes[] = { { TRAP_BRKPT, "TRAP_BRKPT" }, { TRAP_TRACE, "TRAP_TRACE" }, { 0, NULL },};static struct xlat sigcld_codes[] = { { CLD_EXITED, "CLD_EXITED" }, { CLD_KILLED, "CLD_KILLED" }, { CLD_DUMPED, "CLD_DUMPED" }, { CLD_TRAPPED, "CLD_TRAPPED" }, { CLD_STOPPED, "CLD_STOPPED" }, { CLD_CONTINUED,"CLD_CONTINUED" }, { 0, NULL },};static struct xlat sigpoll_codes[] = { { POLL_IN, "POLL_IN" }, { POLL_OUT, "POLL_OUT" }, { POLL_MSG, "POLL_MSG" }, { POLL_ERR, "POLL_ERR" }, { POLL_PRI, "POLL_PRI" }, { POLL_HUP, "POLL_HUP" }, { 0, NULL },};static struct xlat sigprof_codes[] = {#ifdef PROF_SIG { PROF_SIG, "PROF_SIG" },#endif { 0, NULL },};static struct xlat sigill_codes[] = { { ILL_ILLOPC, "ILL_ILLOPC" }, { ILL_ILLOPN, "ILL_ILLOPN" }, { ILL_ILLADR, "ILL_ILLADR" }, { ILL_ILLTRP, "ILL_ILLTRP" }, { ILL_PRVOPC, "ILL_PRVOPC" }, { ILL_PRVREG, "ILL_PRVREG" }, { ILL_COPROC, "ILL_COPROC" }, { ILL_BADSTK, "ILL_BADSTK" }, { 0, NULL },};static struct xlat sigemt_codes[] = {#ifdef EMT_TAGOVF { EMT_TAGOVF, "EMT_TAGOVF" },#endif { 0, NULL },};static struct xlat sigfpe_codes[] = { { FPE_INTDIV, "FPE_INTDIV" }, { FPE_INTOVF, "FPE_INTOVF" }, { FPE_FLTDIV, "FPE_FLTDIV" }, { FPE_FLTOVF, "FPE_FLTOVF" }, { FPE_FLTUND, "FPE_FLTUND" }, { FPE_FLTRES, "FPE_FLTRES" }, { FPE_FLTINV, "FPE_FLTINV" }, { FPE_FLTSUB, "FPE_FLTSUB" }, { 0, NULL },};static struct xlat sigsegv_codes[] = { { SEGV_MAPERR, "SEGV_MAPERR" }, { SEGV_ACCERR, "SEGV_ACCERR" }, { 0, NULL },};static struct xlat sigbus_codes[] = { { BUS_ADRALN, "BUS_ADRALN" }, { BUS_ADRERR, "BUS_ADRERR" }, { BUS_OBJERR, "BUS_OBJERR" }, { 0, NULL },};voidprintsiginfo(sip)siginfo_t *sip;{ char *code; tprintf("{si_signo="); printsignal(sip->si_signo); code = xlookup(siginfo_codes, sip->si_code); if (!code) { switch (sip->si_signo) { case SIGTRAP: code = xlookup(sigtrap_codes, sip->si_code); break; case SIGCHLD: code = xlookup(sigcld_codes, sip->si_code); break; case SIGPOLL: code = xlookup(sigpoll_codes, sip->si_code); break; case SIGPROF: code = xlookup(sigprof_codes, sip->si_code); break; case SIGILL: code = xlookup(sigill_codes, sip->si_code); break; case SIGEMT: code = xlookup(sigemt_codes, sip->si_code); break; case SIGFPE: code = xlookup(sigfpe_codes, sip->si_code); break; case SIGSEGV: code = xlookup(sigsegv_codes, sip->si_code); break; case SIGBUS: code = xlookup(sigbus_codes, sip->si_code); break; } } if (code) tprintf(", si_code=%s", code); else tprintf(", si_code=%#x", sip->si_code);#ifdef SI_NOINFO if (sip->si_code != SI_NOINFO) {#endif if (sip->si_errno) { if (sip->si_errno < 0 || sip->si_errno >= nerrnos) tprintf(", si_errno=%d", sip->si_errno); else tprintf(", si_errno=%s", errnoent[sip->si_errno]); } if (SI_FROMUSER(sip)) {#ifdef SI_QUEUE tprintf(", si_pid=%ld, si_uid=%ld", sip->si_pid, sip->si_uid); switch (sip->si_code) { case SI_QUEUE:#ifdef SI_TIMER case SI_TIMER:#endif /* SI_QUEUE */ case SI_ASYNCIO:#ifdef SI_MESGQ case SI_MESGQ:#endif /* SI_MESGQ */ tprintf(", si_value=%d", sip->si_value.sival_int); break; }#endif /* SI_QUEUE */ } else { switch (sip->si_signo) { case SIGCHLD: tprintf(", si_pid=%ld, si_status=", sip->si_pid); if (sip->si_code == CLD_EXITED) tprintf("%d", sip->si_status); else printsignal(sip->si_status); break; case SIGILL: case SIGFPE: case SIGSEGV: case SIGBUS: tprintf(", si_addr=%#lx", (unsigned long) sip->si_addr); break; case SIGPOLL: switch (sip->si_code) { case POLL_IN: case POLL_OUT: case POLL_MSG: tprintf(", si_band=%ld", (long) sip->si_band); break; } break; } } tprintf(", ...");#ifdef SI_NOINFO }#endif tprintf("}");}intsys_waitid(tcp)struct tcb *tcp;{ siginfo_t si; int exited; if (entering(tcp)) { printxval(waitid_types, tcp->u_arg[0], "P_???"); tprintf(", %ld, ", tcp->u_arg[1]); if (tcp->nchildren > 0) { /* There are traced children */ tcp->flags |= TCB_SUSPENDED; tcp->waitpid = tcp->u_arg[0]; } } else { /* siginfo */ exited = 0; if (!tcp->u_arg[2]) tprintf("NULL"); else if (syserror(tcp)) tprintf("%#lx", tcp->u_arg[2]); else if (umove(tcp, tcp->u_arg[2], &si) < 0) tprintf("{???}"); else printsiginfo(&si); /* options */ tprintf(", "); if (!printflags(wait4_options, tcp->u_arg[3])) tprintf("0"); } return 0;}#endif /* SVR4 */intsys_alarm(tcp)struct tcb *tcp;{ if (entering(tcp)) tprintf("%lu", tcp->u_arg[0]); return 0;}intsys_uname(tcp)struct tcb *tcp;{ struct utsname uname; if (exiting(tcp)) { if (syserror(tcp) || !verbose(tcp)) tprintf("%#lx", tcp->u_arg[0]); else if (umove(tcp, tcp->u_arg[0], &uname) < 0) tprintf("{...}"); else if (!abbrev(tcp)) { tprintf("{sysname=\"%s\", nodename=\"%s\", ", uname.sysname, uname.nodename); tprintf("release=\"%s\", version=\"%s\", ", uname.release, uname.version); tprintf("machine=\"%s\"", uname.machine);#ifdef LINUX#ifndef __GLIBC__ tprintf(", domainname=\"%s\"", uname.domainname);#endif /* __GLIBC__ */#endif /* LINUX */ tprintf("}"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -