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