Lines Matching refs:proc
42 #include "proc.h"
59 static void callstack_push_syscall(struct process *proc, int sysnum);
60 static void callstack_push_symfunc(struct process *proc, struct breakpoint *bp);
62 * proc.c, and push/pop should be visible outside this module. For
63 * now, because we need this in proc.c, this is non-static. */
64 void callstack_pop(struct process *proc);
66 static char *shortsignal(struct process *proc, int signum);
67 static char *sysname(struct process *proc, int sysnum);
68 static char *arch_sysname(struct process *proc, int sysnum);
71 call_handler(struct process *proc, Event *event)
73 assert(proc != NULL);
75 struct event_handler *handler = proc->event_handler;
91 event->proc ? event->proc->pid : -1, event->type);
97 if (event->proc != NULL) {
98 event = call_handler(event->proc, event);
105 if (event->proc != NULL
106 && event->proc->leader != NULL
107 && event->proc != event->proc->leader) {
108 event = call_handler(event->proc->leader, event);
120 assert(event->proc != NULL);
122 event->proc->pid,
123 shortsignal(event->proc, event->e_un.signum),
129 assert(event->proc != NULL);
131 event->proc->pid,
137 assert(event->proc != NULL);
139 event->proc->pid,
140 shortsignal(event->proc, event->e_un.signum),
146 assert(event->proc != NULL);
148 event->proc->pid,
149 sysname(event->proc, event->e_un.sysnum),
155 assert(event->proc != NULL);
157 event->proc->pid,
158 sysname(event->proc, event->e_un.sysnum),
164 assert(event->proc != NULL);
166 event->proc->pid,
167 arch_sysname(event->proc, event->e_un.sysnum),
173 assert(event->proc != NULL);
175 event->proc->pid,
176 arch_sysname(event->proc, event->e_un.sysnum),
183 assert(event->proc != NULL);
185 event->proc->pid, event->e_un.newpid);
190 assert(event->proc != NULL);
192 event->proc->pid);
197 assert(event->proc != NULL);
199 event->proc->pid, event->e_un.brk_addr);
271 debug(DEBUG_FUNCTION, "handle_clone(pid=%d)", event->proc->pid);
273 struct process *proc = malloc(sizeof(*proc));
275 if (proc == NULL
276 || process_clone(proc, event->proc, newpid) < 0) {
277 free(proc);
278 proc = NULL;
284 proc->parent = event->proc;
288 proc->arch_ptr = NULL;
294 if (proc != NULL) {
295 proc->event_handler = NULL;
296 if (event->proc->state == STATE_ATTACHED
298 proc->state = STATE_ATTACHED;
300 proc->state = STATE_IGNORED;
305 } else if (proc != NULL) {
306 proc->state = STATE_BEING_CREATED;
310 continue_process(event->proc->pid);
311 else if (proc != NULL)
312 continue_after_vfork(proc);
322 struct process *proc = pid2proc(event->e_un.newpid);
323 if (!proc) {
326 assert(proc->state == STATE_BEING_CREATED);
328 proc->state = STATE_ATTACHED;
330 proc->state = STATE_IGNORED;
332 continue_process(proc->pid);
337 shortsignal(struct process *proc, int signum)
350 debug(DEBUG_FUNCTION, "shortsignal(pid=%d, signum=%d)", proc->pid, signum);
352 assert(proc->personality < sizeof signalents / sizeof signalents[0]);
353 if (signum < 0 || signum >= nsignals[proc->personality]) {
356 return signalents[proc->personality][signum];
361 sysname(struct process *proc, int sysnum)
376 debug(DEBUG_FUNCTION, "sysname(pid=%d, sysnum=%d)", proc->pid, sysnum);
378 assert(proc->personality < sizeof syscallents / sizeof syscallents[0]);
379 if (sysnum < 0 || sysnum >= nsyscalls[proc->personality]) {
383 return syscallents[proc->personality][sysnum];
388 arch_sysname(struct process *proc, int sysnum)
396 debug(DEBUG_FUNCTION, "arch_sysname(pid=%d, sysnum=%d)", proc->pid, sysnum);
413 debug(DEBUG_FUNCTION, "handle_signal(pid=%d, signum=%d)", event->proc->pid, event->e_un.signum);
414 if (event->proc->state != STATE_IGNORED && !options.no_signals) {
415 output_line(event->proc, "--- %s (%s) ---",
416 shortsignal(event->proc, event->e_un.signum),
419 continue_after_signal(event->proc->pid, event->e_un.signum);
466 account_current_callstack(struct process *proc)
471 struct timedelta spent[proc->callstack_depth];
474 for (i = 0; i < proc->callstack_depth; ++i) {
475 struct callstack_element *elem = &proc->callstack[i];
479 for (i = 0; i < proc->callstack_depth; ++i) {
480 struct callstack_element *elem = &proc->callstack[i];
483 const char *name = sysname(proc, elem->c_un.syscall);
502 debug(DEBUG_FUNCTION, "handle_exit(pid=%d, status=%d)", event->proc->pid, event->e_un.ret_val);
503 if (event->proc->state != STATE_IGNORED) {
504 output_line(event->proc, "+++ exited (status %d) +++",
508 account_current_callstack(event->proc);
509 remove_process(event->proc);
514 debug(DEBUG_FUNCTION, "handle_exit_signal(pid=%d, signum=%d)", event->proc->pid, event->e_un.signum);
515 if (event->proc->state != STATE_IGNORED) {
516 output_line(event->proc, "+++ killed by %s +++",
517 shortsignal(event->proc, event->e_un.signum));
520 account_current_callstack(event->proc);
521 remove_process(event->proc);
525 output_syscall(struct process *proc, const char *name, enum tof tof,
535 output_left(tof, proc, &syscall);
539 output_right(tof, proc, &syscall, spent);
547 output_syscall_left(struct process *proc, const char *name)
549 output_syscall(proc, name, LT_TOF_SYSCALL, true, NULL);
553 output_syscall_right(struct process *proc, const char *name,
556 output_syscall(proc, name, LT_TOF_SYSCALLR, false, spent);
562 debug(DEBUG_FUNCTION, "handle_syscall(pid=%d, sysnum=%d)", event->proc->pid, event->e_un.sysnum);
563 if (event->proc->state != STATE_IGNORED) {
564 callstack_push_syscall(event->proc, event->e_un.sysnum);
566 output_syscall_left(event->proc,
567 sysname(event->proc,
570 continue_after_syscall(event->proc, event->e_un.sysnum, 0);
576 struct process *proc = event->proc;
580 pid_t pid = proc->pid;
582 debug(DEBUG_FUNCTION, "handle_exec(pid=%d)", proc->pid);
583 if (proc->state == STATE_IGNORED) {
586 remove_process(proc);
589 output_line(proc, "--- Called exec() ---");
591 account_current_callstack(proc);
593 if (process_exec(proc) < 0) {
599 continue_after_exec(proc);
604 debug(DEBUG_FUNCTION, "handle_arch_syscall(pid=%d, sysnum=%d)", event->proc->pid, event->e_un.sysnum);
605 if (event->proc->state != STATE_IGNORED) {
606 callstack_push_syscall(event->proc, 0xf0000 + event->e_un.sysnum);
608 output_syscall_left(event->proc,
609 arch_sysname(event->proc,
613 continue_process(event->proc->pid);
620 event->proc->pid, event->e_un.sysnum);
622 unsigned d = event->proc->callstack_depth;
624 struct callstack_element *elem = &event->proc->callstack[d - 1];
627 if (event->proc->state != STATE_IGNORED) {
630 output_syscall_right(event->proc,
631 name_cb(event->proc,
635 callstack_pop(event->proc);
637 continue_after_syscall(event->proc, event->e_un.sysnum, 1);
653 output_right_tos(struct process *proc)
655 size_t d = proc->callstack_depth;
657 struct callstack_element *elem = &proc->callstack[d - 1];
660 if (proc->state != STATE_IGNORED) {
665 output_right(LT_TOF_FUNCTIONR, proc, elem->c_un.libfunc,
671 void arch_symbol_ret(struct process *proc, struct library_symbol *libsym)
681 struct process *leader = event->proc->leader;
686 continue_process(event->proc->pid);
691 event->proc->pid, brk_addr);
694 for (i = event->proc->callstack_depth - 1; i >= 0; i--) {
695 if (brk_addr == event->proc->callstack[i].return_addr) {
696 for (j = event->proc->callstack_depth - 1; j > i; j--)
697 callstack_pop(event->proc);
700 event->proc->callstack[i].c_un.libfunc;
702 arch_symbol_ret(event->proc, libsym);
703 output_right_tos(event->proc);
704 callstack_pop(event->proc);
712 while (event->proc->callstack_depth > 0) {
714 size_t d = event->proc->callstack_depth;
715 prev = &event->proc->callstack[d - 1];
721 arch_symbol_ret(event->proc,
723 output_right_tos(event->proc);
724 callstack_pop(event->proc);
732 continue_after_breakpoint(event->proc, sbp);
734 set_instruction_pointer(event->proc, brk_addr);
735 continue_process(event->proc->pid);
742 breakpoint_on_hit(sbp, event->proc);
743 else if (event->proc->state != STATE_IGNORED)
744 output_line(event->proc,
751 if (event->proc->state != STATE_IGNORED
753 event->proc->stack_pointer = get_stack_pointer(event->proc);
754 callstack_push_symfunc(event->proc, sbp);
756 output_left(LT_TOF_FUNCTION, event->proc,
760 breakpoint_on_continue(sbp, event->proc);
763 set_instruction_pointer(event->proc, brk_addr);
766 continue_process(event->proc->pid);
770 callstack_push_syscall(struct process *proc, int sysnum)
774 debug(DEBUG_FUNCTION, "callstack_push_syscall(pid=%d, sysnum=%d)", proc->pid, sysnum);
776 if (proc->callstack_depth == MAX_CALLDEPTH - 1) {
782 elem = &proc->callstack[proc->callstack_depth];
788 proc->callstack_depth++;
796 callstack_push_symfunc(struct process *proc, struct breakpoint *bp)
801 proc->pid, bp->libsym->name);
803 if (proc->callstack_depth == MAX_CALLDEPTH - 1) {
809 elem = &proc->callstack[proc->callstack_depth++];
815 if (breakpoint_get_return_bp(&rbp, bp, proc) == 0
817 struct breakpoint *ext_rbp = insert_breakpoint(proc, rbp);
834 callstack_pop(struct process *proc)
837 assert(proc->callstack_depth > 0);
839 debug(DEBUG_FUNCTION, "callstack_pop(pid=%d)", proc->pid);
840 elem = &proc->callstack[proc->callstack_depth - 1];
843 = address2bpstruct(proc->leader, elem->return_addr);
845 breakpoint_on_hit(bp, proc);
846 delete_breakpoint(proc, bp);
858 proc->callstack_depth--;