| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 1 | #if HAVE_CONFIG_H |
| 2 | #include "config.h" |
| 3 | #endif |
| 4 | |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 5 | #define _GNU_SOURCE |
| 6 | #include <stdio.h> |
| 7 | #include <string.h> |
| Juan Cespedes | 1fe93d5 | 1998-03-13 00:29:21 +0100 | [diff] [blame] | 8 | #include <stdlib.h> |
| Juan Cespedes | 28f6019 | 1998-04-12 00:04:39 +0200 | [diff] [blame] | 9 | #include <signal.h> |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 10 | #include <assert.h> |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 11 | #include <sys/time.h> |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 12 | |
| 13 | #include "ltrace.h" |
| 14 | #include "output.h" |
| 15 | #include "options.h" |
| Juan Cespedes | 81690ef | 1998-03-13 19:31:29 +0100 | [diff] [blame] | 16 | #include "elf.h" |
| Juan Cespedes | cac15c3 | 2003-01-31 18:58:58 +0100 | [diff] [blame] | 17 | #include "debug.h" |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 18 | |
| Juan Cespedes | f1bfe20 | 2002-03-27 00:22:23 +0100 | [diff] [blame] | 19 | #ifdef __powerpc__ |
| 20 | #include <sys/ptrace.h> |
| 21 | #endif |
| 22 | |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 23 | static void process_signal(struct event * event); |
| 24 | static void process_exit(struct event * event); |
| 25 | static void process_exit_signal(struct event * event); |
| 26 | static void process_syscall(struct event * event); |
| 27 | static void process_sysret(struct event * event); |
| 28 | static void process_breakpoint(struct event * event); |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 29 | static void remove_proc(struct process * proc); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 30 | |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 31 | static void callstack_push_syscall(struct process * proc, int sysnum); |
| 32 | static void callstack_push_symfunc(struct process * proc, struct library_symbol * sym); |
| 33 | static void callstack_pop(struct process * proc); |
| 34 | |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 35 | static char * |
| 36 | shortsignal(int signum) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 37 | static char * signalent0[] = { |
| 38 | #include "signalent.h" |
| 39 | }; |
| 40 | int nsignals0 = sizeof signalent0 / sizeof signalent0[0]; |
| 41 | |
| Juan Cespedes | 504a385 | 2003-02-04 23:24:38 +0100 | [diff] [blame] | 42 | if (signum < 0 || signum >= nsignals0) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 43 | return "UNKNOWN_SIGNAL"; |
| 44 | } else { |
| 45 | return signalent0[signum]; |
| 46 | } |
| 47 | } |
| 48 | |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 49 | static char * |
| 50 | sysname(int sysnum) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 51 | static char result[128]; |
| 52 | static char * syscalent0[] = { |
| 53 | #include "syscallent.h" |
| 54 | }; |
| 55 | int nsyscals0 = sizeof syscalent0 / sizeof syscalent0[0]; |
| 56 | |
| Juan Cespedes | 504a385 | 2003-02-04 23:24:38 +0100 | [diff] [blame] | 57 | if (sysnum < 0 || sysnum >= nsyscals0) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 58 | sprintf(result, "SYS_%d", sysnum); |
| 59 | return result; |
| 60 | } else { |
| 61 | sprintf(result, "SYS_%s", syscalent0[sysnum]); |
| 62 | return result; |
| 63 | } |
| 64 | } |
| 65 | |
| Juan Cespedes | efe85f0 | 2004-04-04 01:31:38 +0200 | [diff] [blame^] | 66 | void |
| 67 | process_event(struct event * event) { |
| 68 | switch (event->thing) { |
| 69 | case LT_EV_NONE: |
| 70 | debug(1, "event: none"); |
| 71 | return; |
| 72 | case LT_EV_SIGNAL: |
| 73 | debug(1, "event: signal (%s [%d])", shortsignal(event->e_un.signum), event->e_un.signum); |
| 74 | process_signal(event); |
| 75 | return; |
| 76 | case LT_EV_EXIT: |
| 77 | debug(1, "event: exit (%d)", event->e_un.ret_val); |
| 78 | process_exit(event); |
| 79 | return; |
| 80 | case LT_EV_EXIT_SIGNAL: |
| 81 | debug(1, "event: exit signal (%s [%d])", shortsignal(event->e_un.signum), event->e_un.signum); |
| 82 | process_exit_signal(event); |
| 83 | return; |
| 84 | case LT_EV_SYSCALL: |
| 85 | debug(1, "event: syscall (%s [%d])", sysname (event->e_un.sysnum), event->e_un.sysnum); |
| 86 | process_syscall(event); |
| 87 | return; |
| 88 | case LT_EV_SYSRET: |
| 89 | debug(1, "event: sysret (%s [%d])", sysname (event->e_un.sysnum), event->e_un.sysnum); |
| 90 | process_sysret(event); |
| 91 | return; |
| 92 | case LT_EV_BREAKPOINT: |
| 93 | debug(1, "event: breakpoint"); |
| 94 | process_breakpoint(event); |
| 95 | return; |
| 96 | default: |
| 97 | fprintf(stderr, "Error! unknown event?\n"); |
| 98 | exit(1); |
| 99 | } |
| 100 | } |
| 101 | |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 102 | static void |
| 103 | process_signal(struct event * event) { |
| Juan Cespedes | 28f6019 | 1998-04-12 00:04:39 +0200 | [diff] [blame] | 104 | if (exiting && event->e_un.signum == SIGSTOP) { |
| 105 | pid_t pid = event->proc->pid; |
| 106 | disable_all_breakpoints(event->proc); |
| 107 | untrace_pid(pid); |
| 108 | remove_proc(event->proc); |
| 109 | continue_after_signal(pid, event->e_un.signum); |
| 110 | return; |
| 111 | } |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 112 | output_line(event->proc, "--- %s (%s) ---", |
| 113 | shortsignal(event->e_un.signum), strsignal(event->e_un.signum)); |
| 114 | continue_after_signal(event->proc->pid, event->e_un.signum); |
| 115 | } |
| 116 | |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 117 | static void |
| 118 | process_exit(struct event * event) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 119 | output_line(event->proc, "+++ exited (status %d) +++", |
| 120 | event->e_un.ret_val); |
| Juan Cespedes | 1fe93d5 | 1998-03-13 00:29:21 +0100 | [diff] [blame] | 121 | remove_proc(event->proc); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 122 | } |
| 123 | |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 124 | static void |
| 125 | process_exit_signal(struct event * event) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 126 | output_line(event->proc, "+++ killed by %s +++", |
| 127 | shortsignal(event->e_un.signum)); |
| Juan Cespedes | 1fe93d5 | 1998-03-13 00:29:21 +0100 | [diff] [blame] | 128 | remove_proc(event->proc); |
| 129 | } |
| 130 | |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 131 | static void |
| 132 | remove_proc(struct process * proc) { |
| Juan Cespedes | 1fe93d5 | 1998-03-13 00:29:21 +0100 | [diff] [blame] | 133 | struct process *tmp, *tmp2; |
| 134 | |
| Juan Cespedes | cac15c3 | 2003-01-31 18:58:58 +0100 | [diff] [blame] | 135 | debug(1, "Removing pid %u\n", proc->pid); |
| Juan Cespedes | 28f6019 | 1998-04-12 00:04:39 +0200 | [diff] [blame] | 136 | |
| Juan Cespedes | 1fe93d5 | 1998-03-13 00:29:21 +0100 | [diff] [blame] | 137 | if (list_of_processes == proc) { |
| 138 | tmp = list_of_processes; |
| 139 | list_of_processes = list_of_processes->next; |
| 140 | free(tmp); |
| 141 | return; |
| 142 | } |
| 143 | tmp = list_of_processes; |
| 144 | while(tmp->next) { |
| 145 | if (tmp->next==proc) { |
| 146 | tmp2 = tmp->next; |
| 147 | tmp->next = tmp->next->next; |
| 148 | free(tmp2); |
| Juan Cespedes | 28f6019 | 1998-04-12 00:04:39 +0200 | [diff] [blame] | 149 | continue; |
| Juan Cespedes | 1fe93d5 | 1998-03-13 00:29:21 +0100 | [diff] [blame] | 150 | } |
| Juan Cespedes | 35d7063 | 1998-03-15 14:05:40 +0100 | [diff] [blame] | 151 | tmp = tmp->next; |
| Juan Cespedes | 1fe93d5 | 1998-03-13 00:29:21 +0100 | [diff] [blame] | 152 | } |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 153 | } |
| 154 | |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 155 | static void |
| 156 | process_syscall(struct event * event) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 157 | if (opt_S) { |
| 158 | output_left(LT_TOF_SYSCALL, event->proc, sysname(event->e_un.sysnum)); |
| 159 | } |
| Juan Cespedes | 7186e2a | 2003-01-31 19:56:34 +0100 | [diff] [blame] | 160 | if (fork_p(event->e_un.sysnum)) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 161 | disable_all_breakpoints(event->proc); |
| Juan Cespedes | 81690ef | 1998-03-13 19:31:29 +0100 | [diff] [blame] | 162 | } else if (!event->proc->breakpoints_enabled) { |
| 163 | enable_all_breakpoints(event->proc); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 164 | } |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 165 | callstack_push_syscall(event->proc, event->e_un.sysnum); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 166 | continue_process(event->proc->pid); |
| 167 | } |
| 168 | |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 169 | struct timeval current_time_spent; |
| 170 | |
| 171 | static void |
| 172 | calc_time_spent(struct process * proc) { |
| 173 | struct timeval tv; |
| 174 | struct timezone tz; |
| 175 | struct timeval diff; |
| 176 | struct callstack_element * elem; |
| 177 | |
| 178 | elem = & proc->callstack[proc->callstack_depth-1]; |
| 179 | |
| 180 | gettimeofday(&tv, &tz); |
| 181 | |
| 182 | diff.tv_sec = tv.tv_sec - elem->time_spent.tv_sec; |
| 183 | if (tv.tv_usec >= elem->time_spent.tv_usec) { |
| 184 | diff.tv_usec = tv.tv_usec - elem->time_spent.tv_usec; |
| 185 | } else { |
| 186 | diff.tv_sec++; |
| 187 | diff.tv_usec = 1000000 + tv.tv_usec - elem->time_spent.tv_usec; |
| 188 | } |
| 189 | current_time_spent = diff; |
| 190 | } |
| 191 | |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 192 | static void |
| 193 | process_sysret(struct event * event) { |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 194 | if (opt_T || opt_c) { |
| 195 | calc_time_spent(event->proc); |
| 196 | } |
| Juan Cespedes | 81690ef | 1998-03-13 19:31:29 +0100 | [diff] [blame] | 197 | if (fork_p(event->e_un.sysnum)) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 198 | if (opt_f) { |
| Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 199 | pid_t child = gimme_arg(LT_TOF_SYSCALL,event->proc,-1); |
| 200 | if (child>0) { |
| 201 | open_pid(child, 0); |
| 202 | } |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 203 | } |
| Juan Cespedes | 35d7063 | 1998-03-15 14:05:40 +0100 | [diff] [blame] | 204 | enable_all_breakpoints(event->proc); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 205 | } |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 206 | callstack_pop(event->proc); |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 207 | if (opt_S) { |
| 208 | output_right(LT_TOF_SYSCALL, event->proc, sysname(event->e_un.sysnum)); |
| 209 | } |
| Juan Cespedes | 7186e2a | 2003-01-31 19:56:34 +0100 | [diff] [blame] | 210 | if (exec_p(event->e_un.sysnum)) { |
| 211 | if (gimme_arg(LT_TOF_SYSCALL,event->proc,-1)==0) { |
| 212 | event->proc->filename = pid2name(event->proc->pid); |
| 213 | breakpoints_init(event->proc); |
| 214 | } |
| 215 | } |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 216 | continue_process(event->proc->pid); |
| 217 | } |
| 218 | |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 219 | static void |
| 220 | process_breakpoint(struct event * event) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 221 | struct library_symbol * tmp; |
| Juan Cespedes | 5916fda | 2002-02-25 00:19:21 +0100 | [diff] [blame] | 222 | int i,j; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 223 | |
| Juan Cespedes | efe85f0 | 2004-04-04 01:31:38 +0200 | [diff] [blame^] | 224 | debug(2, "event: breakpoint (%p)", event->e_un.brk_addr); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 225 | if (event->proc->breakpoint_being_enabled) { |
| Juan Cespedes | b1dd77d | 2002-03-03 00:22:06 +0100 | [diff] [blame] | 226 | /* Reinsert breakpoint */ |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 227 | continue_enabling_breakpoint(event->proc->pid, event->proc->breakpoint_being_enabled); |
| 228 | event->proc->breakpoint_being_enabled = NULL; |
| 229 | return; |
| 230 | } |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 231 | |
| Juan Cespedes | 5916fda | 2002-02-25 00:19:21 +0100 | [diff] [blame] | 232 | for(i=event->proc->callstack_depth-1; i>=0; i--) { |
| 233 | if (event->e_un.brk_addr == event->proc->callstack[i].return_addr) { |
| Juan Cespedes | 5bfb061 | 2002-03-31 20:01:28 +0200 | [diff] [blame] | 234 | #ifdef __powerpc__ |
| 235 | unsigned long a; |
| 236 | unsigned long addr = event->proc->callstack[i].c_un.libfunc->enter_addr; |
| Juan Cespedes | cac15c3 | 2003-01-31 18:58:58 +0100 | [diff] [blame] | 237 | struct breakpoint *sbp = address2bpstruct(event->proc, addr); |
| Juan Cespedes | 5bfb061 | 2002-03-31 20:01:28 +0200 | [diff] [blame] | 238 | unsigned char break_insn[] = BREAKPOINT_VALUE; |
| 239 | |
| 240 | /* |
| 241 | * PPC HACK! (XXX FIXME TODO) |
| 242 | * The PLT gets modified during the first call, |
| 243 | * so be sure to re-enable the breakpoint. |
| 244 | */ |
| 245 | a = ptrace(PTRACE_PEEKTEXT, event->proc->pid, addr); |
| 246 | |
| 247 | if (memcmp(&a, break_insn, 4)) { |
| 248 | sbp->enabled--; |
| 249 | insert_breakpoint(event->proc, addr); |
| 250 | } |
| 251 | #endif |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 252 | for(j=event->proc->callstack_depth-1; j>i; j--) { |
| Juan Cespedes | 5916fda | 2002-02-25 00:19:21 +0100 | [diff] [blame] | 253 | callstack_pop(event->proc); |
| 254 | } |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 255 | if (opt_T || opt_c) { |
| 256 | calc_time_spent(event->proc); |
| 257 | } |
| 258 | callstack_pop(event->proc); |
| Juan Cespedes | 5916fda | 2002-02-25 00:19:21 +0100 | [diff] [blame] | 259 | event->proc->return_addr = event->e_un.brk_addr; |
| 260 | output_right(LT_TOF_FUNCTION, event->proc, |
| 261 | event->proc->callstack[i].c_un.libfunc->name); |
| 262 | continue_after_breakpoint(event->proc, |
| 263 | address2bpstruct(event->proc, event->e_un.brk_addr)); |
| 264 | return; |
| 265 | } |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | tmp = event->proc->list_of_symbols; |
| 269 | while(tmp) { |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 270 | if (event->e_un.brk_addr == tmp->enter_addr) { |
| Juan Cespedes | 3f0b62e | 2001-07-09 01:02:52 +0200 | [diff] [blame] | 271 | event->proc->stack_pointer = get_stack_pointer(event->proc->pid); |
| 272 | event->proc->return_addr = get_return_addr(event->proc->pid, event->proc->stack_pointer); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 273 | output_left(LT_TOF_FUNCTION, event->proc, tmp->name); |
| Juan Cespedes | 3f0b62e | 2001-07-09 01:02:52 +0200 | [diff] [blame] | 274 | callstack_push_symfunc(event->proc, tmp); |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 275 | continue_after_breakpoint(event->proc, address2bpstruct(event->proc, tmp->enter_addr)); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 276 | return; |
| 277 | } |
| 278 | tmp = tmp->next; |
| 279 | } |
| Juan Cespedes | efe85f0 | 2004-04-04 01:31:38 +0200 | [diff] [blame^] | 280 | output_line(event->proc, "breakpointed at %p (?)", |
| 281 | (void *)event->e_un.brk_addr); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 282 | continue_process(event->proc->pid); |
| 283 | } |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 284 | |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 285 | static void |
| 286 | callstack_push_syscall(struct process * proc, int sysnum) { |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 287 | struct callstack_element * elem; |
| 288 | |
| 289 | /* FIXME: not good -- should use dynamic allocation. 19990703 mortene. */ |
| 290 | if (proc->callstack_depth == MAX_CALLDEPTH-1) { |
| 291 | fprintf(stderr, "Error: call nesting too deep!\n"); |
| 292 | return; |
| 293 | } |
| 294 | |
| 295 | elem = & proc->callstack[proc->callstack_depth]; |
| 296 | elem->is_syscall = 1; |
| 297 | elem->c_un.syscall = sysnum; |
| 298 | elem->return_addr = NULL; |
| 299 | |
| 300 | proc->callstack_depth++; |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 301 | if (opt_T || opt_c) { |
| 302 | struct timezone tz; |
| 303 | gettimeofday(&elem->time_spent, &tz); |
| 304 | } |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 305 | } |
| 306 | |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 307 | static void |
| 308 | callstack_push_symfunc(struct process * proc, struct library_symbol * sym) { |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 309 | struct callstack_element * elem; |
| 310 | |
| 311 | /* FIXME: not good -- should use dynamic allocation. 19990703 mortene. */ |
| 312 | if (proc->callstack_depth == MAX_CALLDEPTH-1) { |
| 313 | fprintf(stderr, "Error: call nesting too deep!\n"); |
| 314 | return; |
| 315 | } |
| 316 | |
| 317 | elem = & proc->callstack[proc->callstack_depth]; |
| 318 | elem->is_syscall = 0; |
| 319 | elem->c_un.libfunc = sym; |
| 320 | |
| Juan Cespedes | 3f0b62e | 2001-07-09 01:02:52 +0200 | [diff] [blame] | 321 | elem->return_addr = proc->return_addr; |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 322 | insert_breakpoint(proc, elem->return_addr); |
| 323 | |
| 324 | proc->callstack_depth++; |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 325 | if (opt_T || opt_c) { |
| 326 | struct timezone tz; |
| 327 | gettimeofday(&elem->time_spent, &tz); |
| 328 | } |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 329 | } |
| 330 | |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 331 | static void |
| 332 | callstack_pop(struct process * proc) { |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 333 | struct callstack_element * elem; |
| 334 | assert(proc->callstack_depth > 0); |
| 335 | |
| 336 | elem = & proc->callstack[proc->callstack_depth-1]; |
| 337 | if (!elem->is_syscall) { |
| 338 | delete_breakpoint(proc, elem->return_addr); |
| 339 | } |
| 340 | proc->callstack_depth--; |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 341 | } |