• Home
  • Raw
  • Download

Lines Matching refs:tcp

127 static int detach(struct tcb *tcp, int sig);
362 newoutf(struct tcb *tcp) in newoutf() argument
368 sprintf(name, "%.512s.%u", outfname, tcp->pid); in newoutf()
371 tcp->outf = fp; in newoutf()
380 struct tcb *tcp; in startup_attach() local
409 tcp = tcbtab[tcbi]; in startup_attach()
410 if (!(tcp->flags & TCB_INUSE) || !(tcp->flags & TCB_ATTACHED)) in startup_attach()
413 if (tcp->flags & TCB_CLONE_THREAD) in startup_attach()
417 tcp->outf = outf; in startup_attach()
418 if (newoutf(tcp) < 0) in startup_attach()
422 if (proc_open(tcp, 1) < 0) { in startup_attach()
424 droptcb(tcp); in startup_attach()
433 sprintf(procdir, "/proc/%d/task", tcp->pid); in startup_attach()
449 tcp = alloctcb(tid); in startup_attach()
450 tcp->flags |= TCB_ATTACHED|TCB_CLONE_THREAD|TCB_FOLLOWFORK; in startup_attach()
453 tcp->parent = tcbtab[tcbi]; in startup_attach()
466 droptcb(tcp); in startup_attach()
479 if (ptrace(PTRACE_ATTACH, tcp->pid, (char *) 1, 0) < 0) { in startup_attach()
481 droptcb(tcp); in startup_attach()
491 tcp->flags &= ~TCB_ATTACHED; in startup_attach()
503 tcp->pid); in startup_attach()
517 struct tcb *tcp; in startup_child() local
679 tcp = alloctcb(daemonized_tracer ? getppid() : pid); in startup_child()
682 tcp->flags |= TCB_ATTACHED; in startup_child()
685 if (proc_open(tcp, 0) < 0) { in startup_child()
767 struct tcb *tcp; in main() local
786 for (tcp = tcbtab[0]; tcp < &tcbtab[0][tcbtabsize]; ++tcp) in main()
787 tcbtab[tcp - tcbtab[0]] = &tcbtab[0][tcp - tcbtab[0]]; in main()
888 tcp = alloc_tcb(pid, 0); in main()
889 tcp->flags |= TCB_ATTACHED; in main()
1107 struct tcb *tcp; in alloc_tcb() local
1113 tcp = tcbtab[i]; in alloc_tcb()
1114 if ((tcp->flags & TCB_INUSE) == 0) { in alloc_tcb()
1115 tcp->pid = pid; in alloc_tcb()
1116 tcp->parent = NULL; in alloc_tcb()
1117 tcp->nchildren = 0; in alloc_tcb()
1118 tcp->nzombies = 0; in alloc_tcb()
1120 tcp->nclone_threads = 0; in alloc_tcb()
1121 tcp->nclone_waiting = 0; in alloc_tcb()
1123 tcp->flags = TCB_INUSE | TCB_STARTUP; in alloc_tcb()
1124 tcp->outf = outf; /* Initialise to current out file */ in alloc_tcb()
1125 tcp->curcol = 0; in alloc_tcb()
1126 tcp->stime.tv_sec = 0; in alloc_tcb()
1127 tcp->stime.tv_usec = 0; in alloc_tcb()
1128 tcp->pfd = -1; in alloc_tcb()
1131 newoutf(tcp); in alloc_tcb()
1132 return tcp; in alloc_tcb()
1142 proc_open(struct tcb *tcp, int attaching) in proc_open() argument
1158 sprintf(proc, "/proc/%d/ctl", tcp->pid); in proc_open()
1159 if ((tcp->pfd = open(proc, O_WRONLY|O_EXCL)) < 0) { in proc_open()
1163 if (set_cloexec_flag(tcp->pfd) < 0) { in proc_open()
1166 sprintf(proc, "/proc/%d/status", tcp->pid); in proc_open()
1167 if ((tcp->pfd_stat = open(proc, O_RDONLY|O_EXCL)) < 0) { in proc_open()
1171 if (set_cloexec_flag(tcp->pfd_stat) < 0) { in proc_open()
1174 sprintf(proc, "/proc/%d/as", tcp->pid); in proc_open()
1175 if ((tcp->pfd_as = open(proc, O_RDONLY|O_EXCL)) < 0) { in proc_open()
1179 if (set_cloexec_flag(tcp->pfd_as) < 0) { in proc_open()
1185 sprintf(proc, "/proc/%d", tcp->pid); in proc_open()
1186 tcp->pfd = open(proc, O_RDWR|O_EXCL); in proc_open()
1188 sprintf(proc, "/proc/%d/mem", tcp->pid); in proc_open()
1189 tcp->pfd = open(proc, O_RDWR); in proc_open()
1191 if (tcp->pfd < 0) { in proc_open()
1195 if (set_cloexec_flag(tcp->pfd) < 0) { in proc_open()
1200 sprintf(proc, "/proc/%d/regs", tcp->pid); in proc_open()
1201 if ((tcp->pfd_reg = open(proc, O_RDONLY)) < 0) { in proc_open()
1206 sprintf(proc, "/proc/%d/status", tcp->pid); in proc_open()
1207 if ((tcp->pfd_status = open(proc, O_RDONLY)) < 0) { in proc_open()
1212 tcp->pfd_status = -1; in proc_open()
1221 if (IOCTL_STATUS (tcp) < 0) { in proc_open()
1225 if (tcp->status.PR_FLAGS & PR_ASLEEP) in proc_open()
1231 if (IOCTL(tcp->pfd, PIOCSTOP, (char *)NULL) < 0) { in proc_open()
1239 if (IOCTL(tcp->pfd, PIOCSET, &arg) < 0) { in proc_open()
1245 if (IOCTL(tcp->pfd, followfork ? PIOCSET : PIOCRESET, &arg) < 0) { in proc_open()
1251 if (ioctl(tcp->pfd, PIOCSRLC) < 0) { in proc_open()
1255 if (ioctl(tcp->pfd, followfork ? PIOCSFORK : PIOCRFORK) < 0) { in proc_open()
1261 if (ioctl(tcp->pfd, PIOCGFL, &arg) < 0) { in proc_open()
1266 if (ioctl(tcp->pfd, PIOCSFL, arg) < 0) { in proc_open()
1295 if (IOCTL(tcp->pfd, PIOCSENTRY, &syscalls) < 0) { in proc_open()
1300 if (IOCTL(tcp->pfd, PIOCSEXIT, &syscalls) < 0) { in proc_open()
1310 if (IOCTL(tcp->pfd, PIOCSTRACE, &signals) < 0) { in proc_open()
1320 if (IOCTL(tcp->pfd, PIOCSFAULT, &faults) < 0) { in proc_open()
1327 if(ioctl(tcp->pfd, PIOCBIS, arg) < 0) { in proc_open()
1338 kill(tcp->pid, SIGINT); in proc_open()
1343 if (IOCTL (tcp->pfd, PIOCRUN, &arg) < 0) { in proc_open()
1351 kill(tcp->pid, SIGCONT); in proc_open()
1355 if (IOCTL_WSTOP (tcp) < 0) { in proc_open()
1359 if (tcp->status.PR_WHY == PR_SYSENTRY) { in proc_open()
1360 tcp->flags &= ~TCB_INSYSCALL; in proc_open()
1361 get_scno(tcp); in proc_open()
1362 if (known_scno(tcp) == SYS_execve) in proc_open()
1368 if (IOCTL(tcp->pfd, PIOCRUN, &arg) < 0) { in proc_open()
1370 if (IOCTL(tcp->pfd, PIOCRUN, 0) < 0) { in proc_open()
1378 if (tcp->status.PR_WHY == PR_SIGNALLED && in proc_open()
1379 tcp->status.PR_WHAT == SIGSTOP) in proc_open()
1380 kill(tcp->pid, SIGCONT); in proc_open()
1396 sprintf(proc, "/proc/%d/status", tcp->pid); in proc_open()
1405 tcp->flags &= ~(TCB_INSYSCALL|TCB_STARTUP); in proc_open()
1406 tcp->status.PR_WHY = PR_SYSENTRY; in proc_open()
1407 trace_syscall(tcp); in proc_open()
1416 proc_poller(tcp->pfd); in proc_open()
1420 proc_poller(tcp->pfd); in proc_open()
1422 last_pfd = tcp->pfd; in proc_open()
1438 struct tcb *tcp = tcbtab[i]; in pid2tcb() local
1439 if (tcp->pid == pid && (tcp->flags & TCB_INUSE)) in pid2tcb()
1440 return tcp; in pid2tcb()
1452 struct tcb *tcp; in first_used_tcb() local
1454 tcp = tcbtab[i]; in first_used_tcb()
1455 if (tcp->flags & TCB_INUSE) in first_used_tcb()
1456 return tcp; in first_used_tcb()
1468 struct tcb *tcp = tcbtab[i]; local
1469 if (tcp->pfd != pfd)
1471 if (tcp->flags & TCB_INUSE)
1472 return tcp;
1480 droptcb(tcp) in droptcb() argument
1481 struct tcb *tcp; in droptcb()
1483 if (tcp->pid == 0)
1486 if (tcp->nclone_threads > 0) {
1491 tcp->flags |= TCB_EXITING;
1496 tcp->pid = 0;
1498 if (tcp->parent != NULL) {
1499 tcp->parent->nchildren--;
1501 if (tcp->flags & TCB_CLONE_THREAD)
1502 tcp->parent->nclone_threads--;
1504 tcp->parent->nzombies++;
1510 if ((tcp->flags & TCB_CLONE_THREAD) &&
1511 tcp->parent->nclone_threads == 0 &&
1512 (tcp->parent->flags & TCB_EXITING))
1513 droptcb(tcp->parent);
1515 tcp->parent = NULL;
1518 tcp->flags = 0;
1519 if (tcp->pfd != -1) {
1520 close(tcp->pfd);
1521 tcp->pfd = -1;
1523 if (tcp->pfd_reg != -1) {
1524 close(tcp->pfd_reg);
1525 tcp->pfd_reg = -1;
1527 if (tcp->pfd_status != -1) {
1528 close(tcp->pfd_status);
1529 tcp->pfd_status = -1;
1537 if (outfname && followfork > 1 && tcp->outf)
1538 fclose(tcp->outf);
1540 tcp->outf = 0;
1546 resume(tcp) in resume() argument
1547 struct tcb *tcp; in resume()
1549 if (tcp == NULL)
1552 if (!(tcp->flags & TCB_SUSPENDED)) {
1553 fprintf(stderr, "PANIC: pid %u not suspended\n", tcp->pid);
1556 tcp->flags &= ~TCB_SUSPENDED;
1558 if (tcp->flags & TCB_CLONE_THREAD)
1559 tcp->parent->nclone_waiting--;
1562 if (ptrace_restart(PTRACE_SYSCALL, tcp, 0) < 0)
1566 fprintf(stderr, "Process %u resumed\n", tcp->pid);
1571 resume_from_tcp (struct tcb *tcp) in resume_from_tcp() argument
1592 if (tcp->parent && in resume_from_tcp()
1593 (tcp->parent->flags & TCB_SUSPENDED) && in resume_from_tcp()
1594 (tcp->parent->waitpid <= 0 || tcp->parent->waitpid == tcp->pid)) { in resume_from_tcp()
1595 error = resume(tcp->parent); in resume_from_tcp()
1599 if (tcp->parent && tcp->parent->nclone_waiting > 0) { in resume_from_tcp()
1606 if (t->parent == tcp->parent && t != tcp in resume_from_tcp()
1609 && t->waitpid == tcp->pid) { in resume_from_tcp()
1619 if (t->parent == tcp->parent && t != tcp in resume_from_tcp()
1643 detach(tcp, sig) in detach() argument
1644 struct tcb *tcp; in detach()
1654 if ((tcp->flags & TCB_CLONE_THREAD) &&
1655 tcp->parent->nclone_threads == 1 &&
1656 (tcp->parent->flags & TCB_EXITING))
1657 zombie = tcp->parent;
1660 if (tcp->flags & TCB_BPTSET)
1661 clearbpt(tcp);
1678 catch_sigstop = (tcp->flags & TCB_STARTUP);
1679 if ((error = ptrace(PTRACE_DETACH, tcp->pid, (char *) 1, sig)) == 0) {
1686 else if (my_tgkill((tcp->flags & TCB_CLONE_THREAD ? tcp->parent->pid
1687 : tcp->pid),
1688 tcp->pid, 0) < 0) {
1692 else if (!catch_sigstop && my_tgkill((tcp->flags & TCB_CLONE_THREAD
1693 ? tcp->parent->pid : tcp->pid),
1694 tcp->pid, SIGSTOP) < 0) {
1703 if (wait4(tcp->pid, &status, __WALL, NULL) < 0) {
1712 if (waitpid(tcp->pid, &status, 0) < 0) {
1719 if (wait4(tcp->pid, &status, __WCLONE,
1735 ptrace_restart(PTRACE_DETACH, tcp, sig);
1738 error = ptrace_restart(PTRACE_CONT, tcp,
1749 if (sig && kill(tcp->pid, sig) < 0)
1752 error = ptrace_restart(PTRACE_DETACH, tcp, sig);
1756 error |= resume_from_tcp (tcp);
1760 fprintf(stderr, "Process %u detached\n", tcp->pid);
1762 droptcb(tcp);
1791 struct tcb *tcp; in cleanup() local
1794 tcp = tcbtab[i]; in cleanup()
1795 if (!(tcp->flags & TCB_INUSE)) in cleanup()
1799 "cleanup: looking at pid %u\n", tcp->pid); in cleanup()
1801 (!outfname || followfork < 2 || tcp_last == tcp)) { in cleanup()
1805 if (tcp->flags & TCB_ATTACHED) in cleanup()
1806 detach(tcp, 0); in cleanup()
1808 kill(tcp->pid, SIGCONT); in cleanup()
1809 kill(tcp->pid, SIGTERM); in cleanup()
1889 struct tcb *tcp = tcbtab[i]; in rebuild_pollv() local
1890 if (!(tcp->flags & TCB_INUSE)) in rebuild_pollv()
1892 pollv[j].fd = tcp->pfd; in rebuild_pollv()
2037 struct tcb *tcp; in choose_pfd() local
2048 tcp = pfd2tcb(pollv[last].fd); in choose_pfd()
2049 if (tcp && (tcp->flags & TCB_INSYSCALL)) in choose_pfd()
2057 tcp = pfd2tcb(pollv[j].fd); in choose_pfd()
2058 if (!tcp) { in choose_pfd()
2062 droptcb(tcp); in choose_pfd()
2080 struct tcb *tcp; in trace() local
2098 tcp = first_used_tcb(); in trace()
2099 if (!tcp) in trace()
2101 pfd = tcp->pfd; in trace()
2118 tcp = in_syscall; in trace()
2120 pv.fd = tcp->pfd; in trace()
2152 if ((tcp = pfd2tcb(pfd)) == NULL) { in trace()
2162 ioctl_result = IOCTL_WSTOP (tcp); in trace()
2168 ioctl_result = IOCTL_STATUS (tcp); in trace()
2170 ioctl_result = IOCTL_WSTOP (tcp); in trace()
2198 droptcb(tcp); in trace()
2207 if ((tcp->flags & TCB_STARTUP) && (tcp->status.PR_WHY == PR_SYSEXIT)) { in trace()
2209 IOCTL (tcp->pfd, PIOCRUN, 0); in trace()
2215 tcp->flags &= ~TCB_STARTUP; in trace()
2218 outf = tcp->outf; in trace()
2219 curcol = tcp->curcol; in trace()
2227 if ((len = pread(tcp->pfd_status, buf, sizeof(buf) - 1, 0)) > 0) { in trace()
2235 stime.tv_sec = tcp->status.pr_stime.tv_sec; in trace()
2236 stime.tv_usec = tcp->status.pr_stime.tv_nsec/1000; in trace()
2238 tv_sub(&tcp->dtime, &stime, &tcp->stime); in trace()
2239 tcp->stime = stime; in trace()
2241 what = tcp->status.PR_WHAT; in trace()
2242 switch (tcp->status.PR_WHY) { in trace()
2245 if (tcp->status.PR_FLAGS & PR_ASLEEP) { in trace()
2246 tcp->status.PR_WHY = PR_SYSENTRY; in trace()
2247 if (trace_syscall(tcp) < 0) { in trace()
2256 in_syscall = tcp; in trace()
2259 if (trace_syscall(tcp) < 0) { in trace()
2267 printleader(tcp); in trace()
2272 if (tcp->status.PR_INFO.si_signo == what) { in trace()
2273 printleader(tcp); in trace()
2275 printsiginfo(&tcp->status.PR_INFO, 1); in trace()
2284 printleader(tcp); in trace()
2294 fprintf(stderr, "odd stop %d\n", tcp->status.PR_WHY); in trace()
2299 tcp->curcol = curcol; in trace()
2302 if (IOCTL (tcp->pfd, PIOCRUN, &arg) < 0) in trace()
2304 if (IOCTL (tcp->pfd, PIOCRUN, 0) < 0) in trace()
2324 handle_group_exit(struct tcb *tcp, int sig) in handle_group_exit() argument
2330 if (tcp->flags & TCB_CLONE_THREAD) in handle_group_exit()
2331 leader = tcp->parent; in handle_group_exit()
2334 if (leader != NULL && leader != tcp in handle_group_exit()
2336 && !(tcp->flags & TCB_STARTUP) in handle_group_exit()
2340 tcp->pid, leader ? leader->pid : -1); in handle_group_exit()
2344 resume_from_tcp(tcp); in handle_group_exit()
2346 droptcb(tcp); /* Already died. */ in handle_group_exit()
2350 tcp->flags |= TCB_EXITING | TCB_GROUP_EXITING; in handle_group_exit()
2351 if (tcp->flags & TCB_ATTACHED) { in handle_group_exit()
2352 detach(tcp, sig); in handle_group_exit()
2353 if (leader != NULL && leader != tcp) in handle_group_exit()
2356 if (ptrace_restart(PTRACE_CONT, tcp, sig) < 0) { in handle_group_exit()
2362 if (leader != tcp) in handle_group_exit()
2363 droptcb(tcp); in handle_group_exit()
2377 handle_ptrace_event(int status, struct tcb *tcp) in handle_ptrace_event() argument
2384 if (do_ptrace(PTRACE_GETEVENTMSG, tcp, NULL, &childpid) < 0) { in handle_ptrace_event()
2394 return handle_new_child(tcp, childpid, 0); in handle_ptrace_event()
2406 struct tcb *tcp; in trace() local
2476 if ((tcp = pid2tcb(pid)) == NULL) { in trace()
2488 tcp = alloctcb(pid); in trace()
2489 tcp->flags |= TCB_ATTACHED | TCB_SUSPENDED; in trace()
2507 outf = tcp->outf; in trace()
2508 curcol = tcp->curcol; in trace()
2511 tv_sub(&tcp->dtime, &ru.ru_stime, &tcp->stime); in trace()
2512 tcp->stime = ru.ru_stime; in trace()
2516 if (tcp->flags & TCB_SUSPENDED) { in trace()
2532 printleader(tcp); in trace()
2542 handle_group_exit(tcp, -1); in trace()
2544 droptcb(tcp); in trace()
2553 if ((tcp->flags & (TCB_ATTACHED|TCB_STARTUP)) == TCB_ATTACHED in trace()
2555 && !(tcp->parent && (tcp->parent->flags & TCB_GROUP_EXITING)) in trace()
2556 && !(tcp->flags & TCB_GROUP_EXITING) in trace()
2563 if (tcp == tcp_last) { in trace()
2564 if ((tcp->flags & (TCB_INSYSCALL|TCB_REPRINT)) == TCB_INSYSCALL) in trace()
2570 handle_group_exit(tcp, -1); in trace()
2572 droptcb(tcp); in trace()
2578 droptcb(tcp); in trace()
2586 if (handle_ptrace_event(status, tcp) != 1) in trace()
2598 if ((tcp->flags & TCB_STARTUP) && in trace()
2605 tcp->flags &= ~TCB_STARTUP; in trace()
2606 if (tcp->flags & TCB_BPTSET) { in trace()
2611 if (clearbpt(tcp) < 0) /* Pretty fatal */ { in trace()
2612 droptcb(tcp); in trace()
2618 if (followfork && (tcp->parent == NULL) && ptrace_setoptions) in trace()
2619 if (ptrace(PTRACE_SETOPTIONS, tcp->pid, in trace()
2629 (tcp->flags & TCB_SIGTRAPPED)) { in trace()
2634 tcp->flags &= ~(TCB_INSYSCALL | TCB_SIGTRAPPED); in trace()
2635 if (ptrace_restart(PTRACE_SYSCALL, tcp, 0) < 0) { in trace()
2648 upeek(tcp, PT_CR_IPSR, &psr); in trace()
2649 upeek(tcp, PT_CR_IIP, &pc); in trace()
2659 printleader(tcp); in trace()
2662 printsiginfo(&si, verbose(tcp)); in trace()
2673 if (((tcp->flags & TCB_ATTACHED) || in trace()
2674 tcp->nclone_threads > 0) && in trace()
2675 !sigishandled(tcp, WSTOPSIG(status))) { in trace()
2677 handle_group_exit(tcp, WSTOPSIG(status)); in trace()
2679 detach(tcp, WSTOPSIG(status)); in trace()
2683 if (ptrace_restart(PTRACE_SYSCALL, tcp, WSTOPSIG(status)) < 0) { in trace()
2687 tcp->flags &= ~TCB_SUSPENDED; in trace()
2693 if (trace_syscall(tcp) < 0 && !tcp->ptrace_errno) { in trace()
2701 if (tcp->flags & TCB_ATTACHED) { in trace()
2710 detach(tcp, 0); in trace()
2713 tcp->pid, (char *) 1, SIGTERM); in trace()
2714 droptcb(tcp); in trace()
2718 if (tcp->flags & TCB_EXITING) { in trace()
2720 if (tcp->flags & TCB_GROUP_EXITING) { in trace()
2721 if (handle_group_exit(tcp, 0) < 0) in trace()
2726 if (tcp->flags & TCB_ATTACHED) in trace()
2727 detach(tcp, 0); in trace()
2728 else if (ptrace_restart(PTRACE_CONT, tcp, 0) < 0) { in trace()
2734 if (tcp->flags & TCB_SUSPENDED) { in trace()
2741 tcp->curcol = curcol; in trace()
2742 if (ptrace_restart(PTRACE_SYSCALL, tcp, 0) < 0) { in trace()
2774 printleader(tcp) in printleader() argument
2775 struct tcb *tcp; in printleader()
2785 } else if (!outfname || followfork < 2 || tcp_last == tcp) {
2792 tprintf("%-5d ", tcp->pid);
2794 tprintf("[pid %5u] ", tcp->pid);
2823 printcall(tcp);