Lines Matching refs:tcp

124 static int detach(struct tcb *tcp, int sig);
359 newoutf(struct tcb *tcp)
365 sprintf(name, "%.512s.%u", outfname, tcp->pid);
368 tcp->outf = fp;
377 struct tcb *tcp;
406 tcp = tcbtab[tcbi];
407 if (!(tcp->flags & TCB_INUSE) || !(tcp->flags & TCB_ATTACHED))
410 if (tcp->flags & TCB_CLONE_THREAD)
414 tcp->outf = outf;
415 if (newoutf(tcp) < 0)
419 if (proc_open(tcp, 1) < 0) {
421 droptcb(tcp);
430 sprintf(procdir, "/proc/%d/task", tcp->pid);
446 tcp = alloctcb(tid);
447 tcp->flags |= TCB_ATTACHED|TCB_CLONE_THREAD|TCB_FOLLOWFORK;
450 tcp->parent = tcbtab[tcbi];
463 droptcb(tcp);
476 if (ptrace(PTRACE_ATTACH, tcp->pid, (char *) 1, 0) < 0) {
478 droptcb(tcp);
488 tcp->flags &= ~TCB_ATTACHED;
500 tcp->pid);
514 struct tcb *tcp;
676 tcp = alloctcb(daemonized_tracer ? getppid() : pid);
679 tcp->flags |= TCB_ATTACHED;
682 if (proc_open(tcp, 0) < 0) {
764 struct tcb *tcp;
783 for (tcp = tcbtab[0]; tcp < &tcbtab[0][tcbtabsize]; ++tcp)
784 tcbtab[tcp - tcbtab[0]] = &tcbtab[0][tcp - tcbtab[0]];
885 tcp = alloc_tcb(pid, 0);
886 tcp->flags |= TCB_ATTACHED;
1104 struct tcb *tcp;
1110 tcp = tcbtab[i];
1111 if ((tcp->flags & TCB_INUSE) == 0) {
1112 tcp->pid = pid;
1113 tcp->parent = NULL;
1114 tcp->nchildren = 0;
1115 tcp->nzombies = 0;
1117 tcp->nclone_threads = 0;
1118 tcp->nclone_waiting = 0;
1120 tcp->flags = TCB_INUSE | TCB_STARTUP;
1121 tcp->outf = outf; /* Initialise to current out file */
1122 tcp->curcol = 0;
1123 tcp->stime.tv_sec = 0;
1124 tcp->stime.tv_usec = 0;
1125 tcp->pfd = -1;
1128 newoutf(tcp);
1129 return tcp;
1139 proc_open(struct tcb *tcp, int attaching)
1155 sprintf(proc, "/proc/%d/ctl", tcp->pid);
1156 if ((tcp->pfd = open(proc, O_WRONLY|O_EXCL)) < 0) {
1160 if (set_cloexec_flag(tcp->pfd) < 0) {
1163 sprintf(proc, "/proc/%d/status", tcp->pid);
1164 if ((tcp->pfd_stat = open(proc, O_RDONLY|O_EXCL)) < 0) {
1168 if (set_cloexec_flag(tcp->pfd_stat) < 0) {
1171 sprintf(proc, "/proc/%d/as", tcp->pid);
1172 if ((tcp->pfd_as = open(proc, O_RDONLY|O_EXCL)) < 0) {
1176 if (set_cloexec_flag(tcp->pfd_as) < 0) {
1182 sprintf(proc, "/proc/%d", tcp->pid);
1183 tcp->pfd = open(proc, O_RDWR|O_EXCL);
1185 sprintf(proc, "/proc/%d/mem", tcp->pid);
1186 tcp->pfd = open(proc, O_RDWR);
1188 if (tcp->pfd < 0) {
1192 if (set_cloexec_flag(tcp->pfd) < 0) {
1197 sprintf(proc, "/proc/%d/regs", tcp->pid);
1198 if ((tcp->pfd_reg = open(proc, O_RDONLY)) < 0) {
1203 sprintf(proc, "/proc/%d/status", tcp->pid);
1204 if ((tcp->pfd_status = open(proc, O_RDONLY)) < 0) {
1209 tcp->pfd_status = -1;
1218 if (IOCTL_STATUS (tcp) < 0) {
1222 if (tcp->status.PR_FLAGS & PR_ASLEEP)
1228 if (IOCTL(tcp->pfd, PIOCSTOP, (char *)NULL) < 0) {
1236 if (IOCTL(tcp->pfd, PIOCSET, &arg) < 0) {
1242 if (IOCTL(tcp->pfd, followfork ? PIOCSET : PIOCRESET, &arg) < 0) {
1248 if (ioctl(tcp->pfd, PIOCSRLC) < 0) {
1252 if (ioctl(tcp->pfd, followfork ? PIOCSFORK : PIOCRFORK) < 0) {
1258 if (ioctl(tcp->pfd, PIOCGFL, &arg) < 0) {
1263 if (ioctl(tcp->pfd, PIOCSFL, arg) < 0) {
1292 if (IOCTL(tcp->pfd, PIOCSENTRY, &syscalls) < 0) {
1297 if (IOCTL(tcp->pfd, PIOCSEXIT, &syscalls) < 0) {
1307 if (IOCTL(tcp->pfd, PIOCSTRACE, &signals) < 0) {
1317 if (IOCTL(tcp->pfd, PIOCSFAULT, &faults) < 0) {
1324 if(ioctl(tcp->pfd, PIOCBIS, arg) < 0) {
1335 kill(tcp->pid, SIGINT);
1340 if (IOCTL (tcp->pfd, PIOCRUN, &arg) < 0) {
1348 kill(tcp->pid, SIGCONT);
1352 if (IOCTL_WSTOP (tcp) < 0) {
1356 if (tcp->status.PR_WHY == PR_SYSENTRY) {
1357 tcp->flags &= ~TCB_INSYSCALL;
1358 get_scno(tcp);
1359 if (known_scno(tcp) == SYS_execve)
1365 if (IOCTL(tcp->pfd, PIOCRUN, &arg) < 0) {
1367 if (IOCTL(tcp->pfd, PIOCRUN, 0) < 0) {
1375 if (tcp->status.PR_WHY == PR_SIGNALLED &&
1376 tcp->status.PR_WHAT == SIGSTOP)
1377 kill(tcp->pid, SIGCONT);
1393 sprintf(proc, "/proc/%d/status", tcp->pid);
1402 tcp->flags &= ~(TCB_INSYSCALL|TCB_STARTUP);
1403 tcp->status.PR_WHY = PR_SYSENTRY;
1404 trace_syscall(tcp);
1413 proc_poller(tcp->pfd);
1417 proc_poller(tcp->pfd);
1419 last_pfd = tcp->pfd;
1435 struct tcb *tcp = tcbtab[i];
1436 if (tcp->pid == pid && (tcp->flags & TCB_INUSE))
1437 return tcp;
1449 struct tcb *tcp;
1451 tcp = tcbtab[i];
1452 if (tcp->flags & TCB_INUSE)
1453 return tcp;
1465 struct tcb *tcp = tcbtab[i];
1466 if (tcp->pfd != pfd)
1468 if (tcp->flags & TCB_INUSE)
1469 return tcp;
1477 droptcb(tcp)
1478 struct tcb *tcp;
1480 if (tcp->pid == 0)
1483 if (tcp->nclone_threads > 0) {
1488 tcp->flags |= TCB_EXITING;
1493 tcp->pid = 0;
1495 if (tcp->parent != NULL) {
1496 tcp->parent->nchildren--;
1498 if (tcp->flags & TCB_CLONE_THREAD)
1499 tcp->parent->nclone_threads--;
1501 tcp->parent->nzombies++;
1503 /* Update `tcp->parent->parent->nchildren' and the other fields
1507 if ((tcp->flags & TCB_CLONE_THREAD) &&
1508 tcp->parent->nclone_threads == 0 &&
1509 (tcp->parent->flags & TCB_EXITING))
1510 droptcb(tcp->parent);
1512 tcp->parent = NULL;
1515 tcp->flags = 0;
1516 if (tcp->pfd != -1) {
1517 close(tcp->pfd);
1518 tcp->pfd = -1;
1520 if (tcp->pfd_reg != -1) {
1521 close(tcp->pfd_reg);
1522 tcp->pfd_reg = -1;
1524 if (tcp->pfd_status != -1) {
1525 close(tcp->pfd_status);
1526 tcp->pfd_status = -1;
1534 if (outfname && followfork > 1 && tcp->outf)
1535 fclose(tcp->outf);
1537 tcp->outf = 0;
1543 resume(tcp)
1544 struct tcb *tcp;
1546 if (tcp == NULL)
1549 if (!(tcp->flags & TCB_SUSPENDED)) {
1550 fprintf(stderr, "PANIC: pid %u not suspended\n", tcp->pid);
1553 tcp->flags &= ~TCB_SUSPENDED;
1555 if (tcp->flags & TCB_CLONE_THREAD)
1556 tcp->parent->nclone_waiting--;
1559 if (ptrace_restart(PTRACE_SYSCALL, tcp, 0) < 0)
1563 fprintf(stderr, "Process %u resumed\n", tcp->pid);
1568 resume_from_tcp (struct tcb *tcp)
1577 or if it's waiting for tcp->pid's pgrp. It makes a
1585 (t->waitpid == 0 && getpgid (tcp->pid) == getpgid (t->pid))
1589 if (tcp->parent &&
1590 (tcp->parent->flags & TCB_SUSPENDED) &&
1591 (tcp->parent->waitpid <= 0 || tcp->parent->waitpid == tcp->pid)) {
1592 error = resume(tcp->parent);
1596 if (tcp->parent && tcp->parent->nclone_waiting > 0) {
1603 if (t->parent == tcp->parent && t != tcp
1606 && t->waitpid == tcp->pid) {
1616 if (t->parent == tcp->parent && t != tcp
1640 detach(tcp, sig)
1641 struct tcb *tcp;
1651 if ((tcp->flags & TCB_CLONE_THREAD) &&
1652 tcp->parent->nclone_threads == 1 &&
1653 (tcp->parent->flags & TCB_EXITING))
1654 zombie = tcp->parent;
1657 if (tcp->flags & TCB_BPTSET)
1658 clearbpt(tcp);
1675 catch_sigstop = (tcp->flags & TCB_STARTUP);
1676 if ((error = ptrace(PTRACE_DETACH, tcp->pid, (char *) 1, sig)) == 0) {
1683 else if (my_tgkill((tcp->flags & TCB_CLONE_THREAD ? tcp->parent->pid
1684 : tcp->pid),
1685 tcp->pid, 0) < 0) {
1689 else if (!catch_sigstop && my_tgkill((tcp->flags & TCB_CLONE_THREAD
1690 ? tcp->parent->pid : tcp->pid),
1691 tcp->pid, SIGSTOP) < 0) {
1700 if (wait4(tcp->pid, &status, __WALL, NULL) < 0) {
1709 if (waitpid(tcp->pid, &status, 0) < 0) {
1716 if (wait4(tcp->pid, &status, __WCLONE,
1732 ptrace_restart(PTRACE_DETACH, tcp, sig);
1735 error = ptrace_restart(PTRACE_CONT, tcp,
1746 if (sig && kill(tcp->pid, sig) < 0)
1749 error = ptrace_restart(PTRACE_DETACH, tcp, sig);
1753 error |= resume_from_tcp (tcp);
1757 fprintf(stderr, "Process %u detached\n", tcp->pid);
1759 droptcb(tcp);
1788 struct tcb *tcp;
1791 tcp = tcbtab[i];
1792 if (!(tcp->flags & TCB_INUSE))
1796 "cleanup: looking at pid %u\n", tcp->pid);
1798 (!outfname || followfork < 2 || tcp_last == tcp)) {
1802 if (tcp->flags & TCB_ATTACHED)
1803 detach(tcp, 0);
1805 kill(tcp->pid, SIGCONT);
1806 kill(tcp->pid, SIGTERM);
1886 struct tcb *tcp = tcbtab[i];
1887 if (!(tcp->flags & TCB_INUSE))
1889 pollv[j].fd = tcp->pfd;
2034 struct tcb *tcp;
2045 tcp = pfd2tcb(pollv[last].fd);
2046 if (tcp && (tcp->flags & TCB_INSYSCALL))
2054 tcp = pfd2tcb(pollv[j].fd);
2055 if (!tcp) {
2059 droptcb(tcp);
2077 struct tcb *tcp;
2095 tcp = first_used_tcb();
2096 if (!tcp)
2098 pfd = tcp->pfd;
2115 tcp = in_syscall;
2117 pv.fd = tcp->pfd;
2149 if ((tcp = pfd2tcb(pfd)) == NULL) {
2159 ioctl_result = IOCTL_WSTOP (tcp);
2165 ioctl_result = IOCTL_STATUS (tcp);
2167 ioctl_result = IOCTL_WSTOP (tcp);
2195 droptcb(tcp);
2204 if ((tcp->flags & TCB_STARTUP) && (tcp->status.PR_WHY == PR_SYSEXIT)) {
2206 IOCTL (tcp->pfd, PIOCRUN, 0);
2212 tcp->flags &= ~TCB_STARTUP;
2215 outf = tcp->outf;
2216 curcol = tcp->curcol;
2224 if ((len = pread(tcp->pfd_status, buf, sizeof(buf) - 1, 0)) > 0) {
2232 stime.tv_sec = tcp->status.pr_stime.tv_sec;
2233 stime.tv_usec = tcp->status.pr_stime.tv_nsec/1000;
2235 tv_sub(&tcp->dtime, &stime, &tcp->stime);
2236 tcp->stime = stime;
2238 what = tcp->status.PR_WHAT;
2239 switch (tcp->status.PR_WHY) {
2242 if (tcp->status.PR_FLAGS & PR_ASLEEP) {
2243 tcp->status.PR_WHY = PR_SYSENTRY;
2244 if (trace_syscall(tcp) < 0) {
2253 in_syscall = tcp;
2256 if (trace_syscall(tcp) < 0) {
2264 printleader(tcp);
2269 if (tcp->status.PR_INFO.si_signo == what) {
2270 printleader(tcp);
2272 printsiginfo(&tcp->status.PR_INFO, 1);
2281 printleader(tcp);
2291 fprintf(stderr, "odd stop %d\n", tcp->status.PR_WHY);
2296 tcp->curcol = curcol;
2299 if (IOCTL (tcp->pfd, PIOCRUN, &arg) < 0)
2301 if (IOCTL (tcp->pfd, PIOCRUN, 0) < 0)
2321 handle_group_exit(struct tcb *tcp, int sig)
2327 if (tcp->flags & TCB_CLONE_THREAD)
2328 leader = tcp->parent;
2331 if (leader != NULL && leader != tcp
2333 && !(tcp->flags & TCB_STARTUP)
2337 tcp->pid, leader ? leader->pid : -1);
2341 resume_from_tcp(tcp);
2343 droptcb(tcp); /* Already died. */
2347 tcp->flags |= TCB_EXITING | TCB_GROUP_EXITING;
2348 if (tcp->flags & TCB_ATTACHED) {
2349 detach(tcp, sig);
2350 if (leader != NULL && leader != tcp)
2353 if (ptrace_restart(PTRACE_CONT, tcp, sig) < 0) {
2359 if (leader != tcp)
2360 droptcb(tcp);
2374 handle_ptrace_event(int status, struct tcb *tcp)
2381 if (do_ptrace(PTRACE_GETEVENTMSG, tcp, NULL, &childpid) < 0) {
2391 return handle_new_child(tcp, childpid, 0);
2403 struct tcb *tcp;
2473 if ((tcp = pid2tcb(pid)) == NULL) {
2485 tcp = alloctcb(pid);
2486 tcp->flags |= TCB_ATTACHED | TCB_SUSPENDED;
2504 outf = tcp->outf;
2505 curcol = tcp->curcol;
2508 tv_sub(&tcp->dtime, &ru.ru_stime, &tcp->stime);
2509 tcp->stime = ru.ru_stime;
2513 if (tcp->flags & TCB_SUSPENDED) {
2529 printleader(tcp);
2539 handle_group_exit(tcp, -1);
2541 droptcb(tcp);
2550 if ((tcp->flags & (TCB_ATTACHED|TCB_STARTUP)) == TCB_ATTACHED
2552 && !(tcp->parent && (tcp->parent->flags & TCB_GROUP_EXITING))
2553 && !(tcp->flags & TCB_GROUP_EXITING)
2560 if (tcp == tcp_last) {
2561 if ((tcp->flags & (TCB_INSYSCALL|TCB_REPRINT)) == TCB_INSYSCALL)
2567 handle_group_exit(tcp, -1);
2569 droptcb(tcp);
2575 droptcb(tcp);
2583 if (handle_ptrace_event(status, tcp) != 1)
2595 if ((tcp->flags & TCB_STARTUP) &&
2602 tcp->flags &= ~TCB_STARTUP;
2603 if (tcp->flags & TCB_BPTSET) {
2608 if (clearbpt(tcp) < 0) /* Pretty fatal */ {
2609 droptcb(tcp);
2615 if (followfork && (tcp->parent == NULL) && ptrace_setoptions)
2616 if (ptrace(PTRACE_SETOPTIONS, tcp->pid,
2626 (tcp->flags & TCB_SIGTRAPPED)) {
2631 tcp->flags &= ~(TCB_INSYSCALL | TCB_SIGTRAPPED);
2632 if (ptrace_restart(PTRACE_SYSCALL, tcp, 0) < 0) {
2645 upeek(tcp, PT_CR_IPSR, &psr);
2646 upeek(tcp, PT_CR_IIP, &pc);
2656 printleader(tcp);
2659 printsiginfo(&si, verbose(tcp));
2670 if (((tcp->flags & TCB_ATTACHED) ||
2671 tcp->nclone_threads > 0) &&
2672 !sigishandled(tcp, WSTOPSIG(status))) {
2674 handle_group_exit(tcp, WSTOPSIG(status));
2676 detach(tcp, WSTOPSIG(status));
2680 if (ptrace_restart(PTRACE_SYSCALL, tcp, WSTOPSIG(status)) < 0) {
2684 tcp->flags &= ~TCB_SUSPENDED;
2690 if (trace_syscall(tcp) < 0 && !tcp->ptrace_errno) {
2698 if (tcp->flags & TCB_ATTACHED) {
2707 detach(tcp, 0);
2710 tcp->pid, (char *) 1, SIGTERM);
2711 droptcb(tcp);
2715 if (tcp->flags & TCB_EXITING) {
2717 if (tcp->flags & TCB_GROUP_EXITING) {
2718 if (handle_group_exit(tcp, 0) < 0)
2723 if (tcp->flags & TCB_ATTACHED)
2724 detach(tcp, 0);
2725 else if (ptrace_restart(PTRACE_CONT, tcp, 0) < 0) {
2731 if (tcp->flags & TCB_SUSPENDED) {
2738 tcp->curcol = curcol;
2739 if (ptrace_restart(PTRACE_SYSCALL, tcp, 0) < 0) {
2771 printleader(tcp)
2772 struct tcb *tcp;
2782 } else if (!outfname || followfork < 2 || tcp_last == tcp) {
2789 tprintf("%-5d ", tcp->pid);
2791 tprintf("[pid %5u] ", tcp->pid);
2820 printcall(tcp);