Lines Matching +full:cs +full:- +full:out
1 /*-
2 * SPDX-License-Identifier: BSD-4-Clause
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * Various setup functions for truss. Not the cleanest-written code,
128 { "FreeBSD a.out", &freebsd32 },
131 { "FreeBSD a.out", &freebsd },
153 if (pid == -1)
180 } while (ret && retry-- > 0);
191 * Restore a process back to it's pre-truss state.
193 * applies if truss was told to monitor an already-existing
209 * Stop the child so that we can detach. Filter out possible
270 LIST_FOREACH(nt, &p->threadlist, entries) {
271 if (nt->tid == lwpid)
278 nt->proc = p;
279 nt->tid = lwpid;
280 LIST_INSERT_HEAD(&p->threadlist, nt, entries);
300 nlwps = ptrace(PT_GETNUMLWPS, p->pid, NULL, 0);
301 if (nlwps == -1)
305 nlwps = ptrace(PT_GETLWPLIST, p->pid, (caddr_t)lwps, nlwps);
306 if (nlwps == -1)
310 if (ptrace(PT_LWPINFO, lwps[i], (caddr_t)&pl, sizeof(pl)) == -1)
313 info->curthread = t;
329 LIST_FOREACH(np, &info->proclist, entries) {
330 if (np->pid == pid)
334 if (info->flags & FOLLOWFORKS)
335 if (ptrace(PT_FOLLOW_FORK, pid, NULL, 1) == -1)
337 if (ptrace(PT_LWP_EVENTS, pid, NULL, 1) == -1)
340 np->pid = pid;
341 np->abi = find_abi(pid);
342 LIST_INIT(&np->threadlist);
343 LIST_INSERT_HEAD(&info->proclist, np, entries);
356 LIST_FOREACH_SAFE(t, &p->threadlist, entries, t2) {
368 LIST_FOREACH_SAFE(p, &info->proclist, entries, p2) {
369 detach_proc(p->pid);
379 LIST_FOREACH(np, &info->proclist, entries) {
380 if (np->pid == pid)
399 LIST_FOREACH(nt, &np->threadlist, entries) {
400 if (nt->tid == lwpid) {
401 info->curthread = nt;
420 info->curthread = LIST_FIRST(&p->threadlist);
421 assert(info->curthread != NULL);
422 assert(LIST_NEXT(info->curthread, entries) == NULL);
430 assert(t->in_syscall == 0);
431 assert(t->cs.number == 0);
432 assert(t->cs.sc == NULL);
433 assert(t->cs.nargs == 0);
434 for (i = 0; i < nitems(t->cs.s_args); i++)
435 assert(t->cs.s_args[i] == NULL);
436 memset(t->cs.args, 0, sizeof(t->cs.args));
437 t->cs.number = pl->pl_syscall_code;
438 t->in_syscall = 1;
446 for (i = 0; i < t->cs.nargs; i++)
447 free(t->cs.s_args[i]);
448 memset(&t->cs, 0, sizeof(t->cs));
449 t->in_syscall = 0;
460 narg = MIN(pl->pl_syscall_narg, nitems(t->cs.args));
461 if (narg != 0 && ptrace(PT_GET_SC_ARGS, t->tid, (caddr_t)t->cs.args,
462 sizeof(t->cs.args)) != 0) {
467 sc = get_syscall(t, t->cs.number, narg);
468 if (sc->unknown)
469 fprintf(info->outfile, "-- UNKNOWN %s SYSCALL %d --\n",
470 t->proc->abi->type, t->cs.number);
472 t->cs.nargs = sc->decode.nargs;
473 assert(sc->decode.nargs <= nitems(t->cs.s_args));
475 t->cs.sc = sc;
479 * We ignore any OUT ones, however -- those are arguments that
482 * passed in *and* out, however.
485 fprintf(stderr, "syscall %s(", sc->name);
487 for (i = 0; i < t->cs.nargs; i++) {
490 t->cs.args[sc->decode.args[i].offset],
491 i < (t->cs.nargs - 1) ? "," : "");
493 if (!(sc->decode.args[i].type & OUT)) {
494 t->cs.s_args[i] = print_arg(&sc->decode.args[i],
495 t->cs.args, NULL, info);
502 clock_gettime(CLOCK_REALTIME, &t->before);
517 t = info->curthread;
518 if (!t->in_syscall)
521 clock_gettime(CLOCK_REALTIME, &t->after);
536 t = info->curthread;
537 if (!t->in_syscall)
540 clock_gettime(CLOCK_REALTIME, &t->after);
541 p = t->proc;
542 if (ptrace(PT_GET_SC_RET, t->tid, (caddr_t)&psr, sizeof(psr)) != 0) {
547 sc = t->cs.sc;
549 * Here, we only look for arguments that have OUT masked in --
552 for (i = 0; i < sc->decode.nargs; i++) {
555 if (sc->decode.args[i].type & OUT) {
562 (long)t->cs.args[sc->decode.args[i].offset]);
564 temp = print_arg(&sc->decode.args[i],
565 t->cs.args, psr.sr_retval, info);
567 t->cs.s_args[i] = temp;
578 if (pl->pl_flags & PL_FLAG_EXEC) {
579 assert(LIST_NEXT(LIST_FIRST(&p->threadlist), entries) == NULL);
580 p->abi = find_abi(p->pid);
581 if (p->abi == NULL) {
582 if (ptrace(PT_DETACH, p->pid, (caddr_t)1, 0) < 0)
597 t = info->curthread;
598 if (info->flags & (FOLLOWFORKS | DISPLAYTIDS)) {
599 if (info->flags & FOLLOWFORKS)
600 len += fprintf(info->outfile, "%5d", t->proc->pid);
601 if ((info->flags & (FOLLOWFORKS | DISPLAYTIDS)) ==
603 len += fprintf(info->outfile, " ");
604 if (info->flags & DISPLAYTIDS)
605 len += fprintf(info->outfile, "%6d", t->tid);
606 len += fprintf(info->outfile, ": ");
608 if (info->flags & ABSOLUTETIMESTAMPS) {
609 timespecsub(&t->after, &info->start_time, &timediff);
610 len += fprintf(info->outfile, "%jd.%09ld ",
613 if (info->flags & RELATIVETIMESTAMPS) {
614 timespecsub(&t->after, &t->before, &timediff);
615 len += fprintf(info->outfile, "%jd.%09ld ",
626 t = info->curthread;
627 clock_gettime(CLOCK_REALTIME, &t->after);
629 fprintf(info->outfile, "<thread %ld exited>\n", (long)t->tid);
637 t = info->curthread;
638 clock_gettime(CLOCK_REALTIME, &t->after);
639 t->before = t->after;
641 fprintf(info->outfile, "<new thread %ld>\n", (long)t->tid);
649 t = info->curthread;
650 clock_gettime(CLOCK_REALTIME, &t->after);
652 if (si->si_code == CLD_EXITED)
653 fprintf(info->outfile, "process exit, rval = %u\n",
654 si->si_status);
656 fprintf(info->outfile, "process killed, signal = %u%s\n",
657 si->si_status, si->si_code == CLD_DUMPED ?
666 t = info->curthread;
667 clock_gettime(CLOCK_REALTIME, &t->after);
668 t->before = t->after;
670 fprintf(info->outfile, "<new process>\n");
679 str = sysdecode_sigcode(si->si_signo, si->si_code);
681 fprintf(fp, "%d", si->si_code);
684 switch (si->si_code) {
688 fprintf(fp, " value=%p", si->si_value.sival_ptr);
692 fprintf(fp, " pid=%jd uid=%jd", (intmax_t)si->si_pid,
693 (intmax_t)si->si_uid);
696 fprintf(fp, " value=%p", si->si_value.sival_ptr);
697 fprintf(fp, " timerid=%d", si->si_timerid);
698 fprintf(fp, " overrun=%d", si->si_overrun);
699 if (si->si_errno != 0)
700 fprintf(fp, " errno=%d", si->si_errno);
703 fprintf(fp, " value=%p", si->si_value.sival_ptr);
706 fprintf(fp, " value=%p", si->si_value.sival_ptr);
707 fprintf(fp, " mqd=%d", si->si_mqd);
710 switch (si->si_signo) {
715 fprintf(fp, " trapno=%d", si->si_trapno);
716 fprintf(fp, " addr=%p", si->si_addr);
719 fprintf(fp, " pid=%jd uid=%jd", (intmax_t)si->si_pid,
720 (intmax_t)si->si_uid);
721 fprintf(fp, " status=%d", si->si_status);
733 t = info->curthread;
734 clock_gettime(CLOCK_REALTIME, &t->after);
736 signame = sysdecode_signal(si->si_status);
739 fprintf(info->outfile, "SIGNAL %u (%s)", si->si_status, signame);
740 if (pl->pl_event == PL_EVENT_SIGNAL && pl->pl_flags & PL_FLAG_SI)
741 decode_siginfo(info->outfile, &pl->pl_siginfo);
742 fprintf(info->outfile, "\n");
757 while (!LIST_EMPTY(&info->proclist)) {
763 if (waitid(P_ALL, 0, &si, WTRAPPED | WEXITED) == -1) {
776 if ((info->flags & COUNTONLY) == 0) {
781 free_proc(info->curthread->proc);
782 info->curthread = NULL;
786 sizeof(pl)) == -1)
791 assert(LIST_FIRST(&info->proclist)->abi !=
802 if ((info->flags & COUNTONLY) == 0)
805 if ((info->flags & COUNTONLY) == 0)
807 free_thread(info->curthread);
808 info->curthread = NULL;
810 enter_syscall(info, info->curthread, &pl);
815 if ((info->flags & COUNTONLY) == 0)
819 if ((info->flags & NOSIGS) == 0)