| 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 | 393f1d0 | 2009-05-07 11:13:54 +0200 | [diff] [blame] | 23 | static void process_signal(Event *event); |
| 24 | static void process_exit(Event *event); |
| 25 | static void process_exit_signal(Event *event); |
| 26 | static void process_syscall(Event *event); |
| 27 | static void process_arch_syscall(Event *event); |
| 28 | static void process_sysret(Event *event); |
| 29 | static void process_arch_sysret(Event *event); |
| Juan Cespedes | 393f1d0 | 2009-05-07 11:13:54 +0200 | [diff] [blame] | 30 | static void process_clone(Event *event); |
| 31 | static void process_exec(Event *event); |
| 32 | static void process_breakpoint(Event *event); |
| Juan Cespedes | 8f6d1ec | 2009-05-07 17:50:34 +0200 | [diff] [blame] | 33 | static void process_new(Event *event); |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 34 | static void remove_proc(Process *proc); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 35 | |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 36 | static void callstack_push_syscall(Process *proc, int sysnum); |
| 37 | static void callstack_push_symfunc(Process *proc, |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 38 | struct library_symbol *sym); |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 39 | static void callstack_pop(Process *proc); |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 40 | |
| Juan Cespedes | bc8caf0 | 2009-05-07 19:38:38 +0200 | [diff] [blame^] | 41 | /* TODO */ |
| 42 | void * address_clone(void * addr) { |
| 43 | return addr; |
| 44 | } |
| 45 | |
| 46 | void * breakpoint_clone(void * bp) { |
| 47 | Breakpoint * b; |
| 48 | b = malloc(sizeof(Breakpoint)); |
| 49 | if (!b) { |
| 50 | perror("malloc()"); |
| 51 | exit(1); |
| 52 | } |
| 53 | memcpy(b, bp, sizeof(Breakpoint)); |
| 54 | return b; |
| 55 | } |
| 56 | |
| 57 | typedef struct Pending_New Pending_New; |
| 58 | struct Pending_New { |
| 59 | pid_t pid; |
| 60 | Pending_New * next; |
| 61 | }; |
| 62 | static Pending_New * pending_news = NULL; |
| 63 | |
| 64 | static int |
| 65 | pending_new(pid_t pid) { |
| 66 | Pending_New * p = pending_news; |
| 67 | while (p) { |
| 68 | if (p->pid == pid) { |
| 69 | return 1; |
| 70 | } |
| 71 | p = p->next; |
| 72 | } |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | static void |
| 77 | pending_new_insert(pid_t pid) { |
| 78 | Pending_New * p = malloc(sizeof(Pending_New)); |
| 79 | if (!p) { |
| 80 | perror("malloc()"); |
| 81 | exit(1); |
| 82 | } |
| 83 | p->pid = pid; |
| 84 | p->next = pending_news; |
| 85 | pending_news = p; |
| 86 | } |
| 87 | |
| 88 | static void |
| 89 | pending_new_remove(pid_t pid) { |
| 90 | Pending_New *p, *pred; |
| 91 | |
| 92 | p = pending_news; |
| 93 | if (p->pid == pid) { |
| 94 | pending_news = p->next; |
| 95 | free(p); |
| 96 | } else { |
| 97 | while (p) { |
| 98 | if (p->pid == pid) { |
| 99 | pred->next = p->next; |
| 100 | free(p); |
| 101 | } |
| 102 | pred = p; |
| 103 | p = p->next; |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | static void |
| 109 | process_clone(Event * event) { |
| 110 | Process *p; |
| 111 | |
| 112 | p = malloc(sizeof(Process)); |
| 113 | if (!p) { |
| 114 | perror("malloc()"); |
| 115 | exit(1); |
| 116 | } |
| 117 | memcpy(p, event->proc, sizeof(Process)); |
| 118 | p->breakpoints = dict_clone(event->proc->breakpoints, address_clone, breakpoint_clone); |
| 119 | p->pid = event->e_un.newpid; |
| 120 | |
| 121 | if (pending_new(p->pid)) { |
| 122 | pending_new_remove(p->pid); |
| 123 | if (p->breakpoint_being_enabled) { |
| 124 | enable_breakpoint(p->pid, p->breakpoint_being_enabled); |
| 125 | p->breakpoint_being_enabled = NULL; |
| 126 | } |
| 127 | p->state = STATE_ATTACHED; |
| 128 | continue_process(p->pid); |
| 129 | p->next = list_of_processes; |
| 130 | list_of_processes = p; |
| 131 | } else { |
| 132 | p->state = STATE_BEING_CREATED; |
| 133 | } |
| 134 | /* look for previous process_new() */ |
| 135 | } |
| 136 | |
| 137 | static void |
| 138 | process_new(Event * event) { |
| 139 | Process * proc = pid2proc(event->e_un.newpid); |
| 140 | if (!proc) { |
| 141 | pending_new_insert(event->e_un.newpid); |
| 142 | } else { |
| 143 | assert(proc->state == STATE_BEING_CREATED); |
| 144 | if (proc->breakpoint_being_enabled) { |
| 145 | enable_breakpoint(proc->pid, proc->breakpoint_being_enabled); |
| 146 | proc->breakpoint_being_enabled = NULL; |
| 147 | } |
| 148 | proc->state = STATE_ATTACHED; |
| 149 | continue_process(proc->pid); |
| 150 | } |
| 151 | } |
| 152 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 153 | static char * |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 154 | shortsignal(Process *proc, int signum) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 155 | static char *signalent0[] = { |
| 156 | #include "signalent.h" |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 157 | }; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 158 | static char *signalent1[] = { |
| 159 | #include "signalent1.h" |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 160 | }; |
| 161 | static char **signalents[] = { signalent0, signalent1 }; |
| 162 | int nsignals[] = { sizeof signalent0 / sizeof signalent0[0], |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 163 | sizeof signalent1 / sizeof signalent1[0] |
| 164 | }; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 165 | |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 166 | if (proc->personality > sizeof signalents / sizeof signalents[0]) |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 167 | abort(); |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 168 | if (signum < 0 || signum >= nsignals[proc->personality]) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 169 | return "UNKNOWN_SIGNAL"; |
| 170 | } else { |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 171 | return signalents[proc->personality][signum]; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 175 | static char * |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 176 | sysname(Process *proc, int sysnum) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 177 | static char result[128]; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 178 | static char *syscalent0[] = { |
| 179 | #include "syscallent.h" |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 180 | }; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 181 | static char *syscalent1[] = { |
| 182 | #include "syscallent1.h" |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 183 | }; |
| 184 | static char **syscalents[] = { syscalent0, syscalent1 }; |
| 185 | int nsyscals[] = { sizeof syscalent0 / sizeof syscalent0[0], |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 186 | sizeof syscalent1 / sizeof syscalent1[0] |
| 187 | }; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 188 | |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 189 | if (proc->personality > sizeof syscalents / sizeof syscalents[0]) |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 190 | abort(); |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 191 | if (sysnum < 0 || sysnum >= nsyscals[proc->personality]) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 192 | sprintf(result, "SYS_%d", sysnum); |
| 193 | return result; |
| 194 | } else { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 195 | sprintf(result, "SYS_%s", |
| 196 | syscalents[proc->personality][sysnum]); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 197 | return result; |
| 198 | } |
| 199 | } |
| 200 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 201 | static char * |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 202 | arch_sysname(Process *proc, int sysnum) { |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 203 | static char result[128]; |
| 204 | static char *arch_syscalent[] = { |
| 205 | #include "arch_syscallent.h" |
| 206 | }; |
| 207 | int nsyscals = sizeof arch_syscalent / sizeof arch_syscalent[0]; |
| 208 | |
| 209 | if (sysnum < 0 || sysnum >= nsyscals) { |
| 210 | sprintf(result, "ARCH_%d", sysnum); |
| 211 | return result; |
| 212 | } else { |
| 213 | sprintf(result, "ARCH_%s", |
| 214 | arch_syscalent[sysnum]); |
| 215 | return result; |
| 216 | } |
| 217 | } |
| 218 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 219 | void |
| Juan Cespedes | 393f1d0 | 2009-05-07 11:13:54 +0200 | [diff] [blame] | 220 | process_event(Event *event) { |
| Juan Cespedes | 8f6d1ec | 2009-05-07 17:50:34 +0200 | [diff] [blame] | 221 | switch (event->type) { |
| Juan Cespedes | 138d41c | 2009-04-07 00:49:12 +0200 | [diff] [blame] | 222 | case EVENT_NONE: |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 223 | debug(1, "event: none"); |
| 224 | return; |
| Juan Cespedes | 138d41c | 2009-04-07 00:49:12 +0200 | [diff] [blame] | 225 | case EVENT_SIGNAL: |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 226 | debug(1, "event: signal (%s [%d])", |
| 227 | shortsignal(event->proc, event->e_un.signum), |
| 228 | event->e_un.signum); |
| 229 | process_signal(event); |
| 230 | return; |
| Juan Cespedes | 138d41c | 2009-04-07 00:49:12 +0200 | [diff] [blame] | 231 | case EVENT_EXIT: |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 232 | debug(1, "event: exit (%d)", event->e_un.ret_val); |
| 233 | process_exit(event); |
| 234 | return; |
| Juan Cespedes | 138d41c | 2009-04-07 00:49:12 +0200 | [diff] [blame] | 235 | case EVENT_EXIT_SIGNAL: |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 236 | debug(1, "event: exit signal (%s [%d])", |
| 237 | shortsignal(event->proc, event->e_un.signum), |
| 238 | event->e_un.signum); |
| 239 | process_exit_signal(event); |
| 240 | return; |
| Juan Cespedes | 138d41c | 2009-04-07 00:49:12 +0200 | [diff] [blame] | 241 | case EVENT_SYSCALL: |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 242 | debug(1, "event: syscall (%s [%d])", |
| 243 | sysname(event->proc, event->e_un.sysnum), |
| 244 | event->e_un.sysnum); |
| 245 | process_syscall(event); |
| 246 | return; |
| Juan Cespedes | 138d41c | 2009-04-07 00:49:12 +0200 | [diff] [blame] | 247 | case EVENT_SYSRET: |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 248 | debug(1, "event: sysret (%s [%d])", |
| 249 | sysname(event->proc, event->e_un.sysnum), |
| 250 | event->e_un.sysnum); |
| 251 | process_sysret(event); |
| 252 | return; |
| Juan Cespedes | 138d41c | 2009-04-07 00:49:12 +0200 | [diff] [blame] | 253 | case EVENT_ARCH_SYSCALL: |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 254 | debug(1, "event: arch_syscall (%s [%d])", |
| 255 | arch_sysname(event->proc, event->e_un.sysnum), |
| 256 | event->e_un.sysnum); |
| 257 | process_arch_syscall(event); |
| 258 | return; |
| Juan Cespedes | 138d41c | 2009-04-07 00:49:12 +0200 | [diff] [blame] | 259 | case EVENT_ARCH_SYSRET: |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 260 | debug(1, "event: arch_sysret (%s [%d])", |
| 261 | arch_sysname(event->proc, event->e_un.sysnum), |
| 262 | event->e_un.sysnum); |
| 263 | process_arch_sysret(event); |
| 264 | return; |
| Juan Cespedes | 1e58313 | 2009-04-07 18:17:11 +0200 | [diff] [blame] | 265 | case EVENT_CLONE: |
| 266 | debug(1, "event: clone (%u)", event->e_un.newpid); |
| 267 | process_clone(event); |
| 268 | return; |
| 269 | case EVENT_EXEC: |
| 270 | debug(1, "event: exec()"); |
| 271 | process_exec(event); |
| 272 | return; |
| Juan Cespedes | 138d41c | 2009-04-07 00:49:12 +0200 | [diff] [blame] | 273 | case EVENT_BREAKPOINT: |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 274 | debug(1, "event: breakpoint"); |
| 275 | process_breakpoint(event); |
| 276 | return; |
| Juan Cespedes | 8f6d1ec | 2009-05-07 17:50:34 +0200 | [diff] [blame] | 277 | case EVENT_NEW: |
| 278 | debug(1, "event: new process"); |
| 279 | process_new(event); |
| 280 | return; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 281 | default: |
| 282 | fprintf(stderr, "Error! unknown event?\n"); |
| 283 | exit(1); |
| Juan Cespedes | efe85f0 | 2004-04-04 01:31:38 +0200 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 287 | static void |
| Juan Cespedes | 393f1d0 | 2009-05-07 11:13:54 +0200 | [diff] [blame] | 288 | process_signal(Event *event) { |
| Juan Cespedes | 28f6019 | 1998-04-12 00:04:39 +0200 | [diff] [blame] | 289 | if (exiting && event->e_un.signum == SIGSTOP) { |
| 290 | pid_t pid = event->proc->pid; |
| 291 | disable_all_breakpoints(event->proc); |
| 292 | untrace_pid(pid); |
| 293 | remove_proc(event->proc); |
| Juan Cespedes | 28f6019 | 1998-04-12 00:04:39 +0200 | [diff] [blame] | 294 | return; |
| 295 | } |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 296 | output_line(event->proc, "--- %s (%s) ---", |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 297 | shortsignal(event->proc, event->e_un.signum), |
| 298 | strsignal(event->e_un.signum)); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 299 | continue_after_signal(event->proc->pid, event->e_un.signum); |
| 300 | } |
| 301 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 302 | static void |
| Juan Cespedes | 393f1d0 | 2009-05-07 11:13:54 +0200 | [diff] [blame] | 303 | process_exit(Event *event) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 304 | output_line(event->proc, "+++ exited (status %d) +++", |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 305 | event->e_un.ret_val); |
| Juan Cespedes | 1fe93d5 | 1998-03-13 00:29:21 +0100 | [diff] [blame] | 306 | remove_proc(event->proc); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 307 | } |
| 308 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 309 | static void |
| Juan Cespedes | 393f1d0 | 2009-05-07 11:13:54 +0200 | [diff] [blame] | 310 | process_exit_signal(Event *event) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 311 | output_line(event->proc, "+++ killed by %s +++", |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 312 | shortsignal(event->proc, event->e_un.signum)); |
| Juan Cespedes | 1fe93d5 | 1998-03-13 00:29:21 +0100 | [diff] [blame] | 313 | remove_proc(event->proc); |
| 314 | } |
| 315 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 316 | static void |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 317 | remove_proc(Process *proc) { |
| 318 | Process *tmp, *tmp2; |
| Juan Cespedes | 1fe93d5 | 1998-03-13 00:29:21 +0100 | [diff] [blame] | 319 | |
| Juan Cespedes | cac15c3 | 2003-01-31 18:58:58 +0100 | [diff] [blame] | 320 | debug(1, "Removing pid %u\n", proc->pid); |
| Juan Cespedes | 28f6019 | 1998-04-12 00:04:39 +0200 | [diff] [blame] | 321 | |
| Juan Cespedes | 1fe93d5 | 1998-03-13 00:29:21 +0100 | [diff] [blame] | 322 | if (list_of_processes == proc) { |
| 323 | tmp = list_of_processes; |
| 324 | list_of_processes = list_of_processes->next; |
| 325 | free(tmp); |
| 326 | return; |
| 327 | } |
| 328 | tmp = list_of_processes; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 329 | while (tmp->next) { |
| 330 | if (tmp->next == proc) { |
| Juan Cespedes | 1fe93d5 | 1998-03-13 00:29:21 +0100 | [diff] [blame] | 331 | tmp2 = tmp->next; |
| 332 | tmp->next = tmp->next->next; |
| 333 | free(tmp2); |
| Juan Cespedes | 28f6019 | 1998-04-12 00:04:39 +0200 | [diff] [blame] | 334 | continue; |
| Juan Cespedes | 1fe93d5 | 1998-03-13 00:29:21 +0100 | [diff] [blame] | 335 | } |
| Juan Cespedes | 35d7063 | 1998-03-15 14:05:40 +0100 | [diff] [blame] | 336 | tmp = tmp->next; |
| Juan Cespedes | 1fe93d5 | 1998-03-13 00:29:21 +0100 | [diff] [blame] | 337 | } |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 338 | } |
| 339 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 340 | static void |
| Juan Cespedes | 393f1d0 | 2009-05-07 11:13:54 +0200 | [diff] [blame] | 341 | process_syscall(Event *event) { |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 342 | if (options.syscalls) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 343 | output_left(LT_TOF_SYSCALL, event->proc, |
| 344 | sysname(event->proc, event->e_un.sysnum)); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 345 | } |
| Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame] | 346 | if (fork_p(event->proc, event->e_un.sysnum)) { |
| 347 | disable_all_breakpoints(event->proc); |
| 348 | } else if (event->proc->breakpoints_enabled == 0) { |
| Juan Cespedes | 81690ef | 1998-03-13 19:31:29 +0100 | [diff] [blame] | 349 | enable_all_breakpoints(event->proc); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 350 | } |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 351 | callstack_push_syscall(event->proc, event->e_un.sysnum); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 352 | continue_process(event->proc->pid); |
| 353 | } |
| 354 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 355 | static void |
| Juan Cespedes | 393f1d0 | 2009-05-07 11:13:54 +0200 | [diff] [blame] | 356 | process_exec(Event * event) { |
| Juan Cespedes | 1e58313 | 2009-04-07 18:17:11 +0200 | [diff] [blame] | 357 | output_line(event->proc, "--- exec() ---"); |
| 358 | abort(); |
| 359 | } |
| 360 | |
| 361 | static void |
| Juan Cespedes | 393f1d0 | 2009-05-07 11:13:54 +0200 | [diff] [blame] | 362 | process_arch_syscall(Event *event) { |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 363 | if (options.syscalls) { |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 364 | output_left(LT_TOF_SYSCALL, event->proc, |
| 365 | arch_sysname(event->proc, event->e_un.sysnum)); |
| 366 | } |
| 367 | if (event->proc->breakpoints_enabled == 0) { |
| 368 | enable_all_breakpoints(event->proc); |
| 369 | } |
| 370 | callstack_push_syscall(event->proc, 0xf0000 + event->e_un.sysnum); |
| 371 | continue_process(event->proc->pid); |
| 372 | } |
| 373 | |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 374 | struct timeval current_time_spent; |
| 375 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 376 | static void |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 377 | calc_time_spent(Process *proc) { |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 378 | struct timeval tv; |
| 379 | struct timezone tz; |
| 380 | struct timeval diff; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 381 | struct callstack_element *elem; |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 382 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 383 | elem = &proc->callstack[proc->callstack_depth - 1]; |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 384 | |
| 385 | gettimeofday(&tv, &tz); |
| 386 | |
| 387 | diff.tv_sec = tv.tv_sec - elem->time_spent.tv_sec; |
| 388 | if (tv.tv_usec >= elem->time_spent.tv_usec) { |
| 389 | diff.tv_usec = tv.tv_usec - elem->time_spent.tv_usec; |
| 390 | } else { |
| 391 | diff.tv_sec++; |
| 392 | diff.tv_usec = 1000000 + tv.tv_usec - elem->time_spent.tv_usec; |
| 393 | } |
| 394 | current_time_spent = diff; |
| 395 | } |
| 396 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 397 | static void |
| Juan Cespedes | 393f1d0 | 2009-05-07 11:13:54 +0200 | [diff] [blame] | 398 | process_sysret(Event *event) { |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 399 | if (opt_T || options.summary) { |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 400 | calc_time_spent(event->proc); |
| 401 | } |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 402 | if (fork_p(event->proc, event->e_un.sysnum)) { |
| Juan Cespedes | cc813cd | 2009-04-07 15:45:53 +0200 | [diff] [blame] | 403 | if (options.follow) { |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 404 | arg_type_info info; |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 405 | info.type = ARGTYPE_LONG; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 406 | pid_t child = |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 407 | gimme_arg(LT_TOF_SYSCALLR, event->proc, -1, &info); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 408 | if (child > 0) { |
| Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 409 | open_pid(child, 0); |
| 410 | } |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 411 | } |
| Juan Cespedes | 35d7063 | 1998-03-15 14:05:40 +0100 | [diff] [blame] | 412 | enable_all_breakpoints(event->proc); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 413 | } |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 414 | callstack_pop(event->proc); |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 415 | if (options.syscalls) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 416 | output_right(LT_TOF_SYSCALLR, event->proc, |
| 417 | sysname(event->proc, event->e_un.sysnum)); |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 418 | } |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 419 | continue_process(event->proc->pid); |
| 420 | } |
| 421 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 422 | static void |
| Juan Cespedes | 393f1d0 | 2009-05-07 11:13:54 +0200 | [diff] [blame] | 423 | process_arch_sysret(Event *event) { |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 424 | if (opt_T || options.summary) { |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 425 | calc_time_spent(event->proc); |
| 426 | } |
| 427 | callstack_pop(event->proc); |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 428 | if (options.syscalls) { |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 429 | output_right(LT_TOF_SYSCALLR, event->proc, |
| 430 | arch_sysname(event->proc, event->e_un.sysnum)); |
| 431 | } |
| 432 | continue_process(event->proc->pid); |
| 433 | } |
| 434 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 435 | static void |
| Juan Cespedes | 393f1d0 | 2009-05-07 11:13:54 +0200 | [diff] [blame] | 436 | process_breakpoint(Event *event) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 437 | int i, j; |
| Juan Cespedes | 1dec217 | 2009-05-07 10:12:10 +0200 | [diff] [blame] | 438 | Breakpoint *sbp; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 439 | |
| Juan Cespedes | efe85f0 | 2004-04-04 01:31:38 +0200 | [diff] [blame] | 440 | debug(2, "event: breakpoint (%p)", event->e_un.brk_addr); |
| Luis Machado | 55c5feb | 2008-03-12 15:56:01 +0100 | [diff] [blame] | 441 | |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 442 | #ifdef __powerpc__ |
| Luis Machado | 55c5feb | 2008-03-12 15:56:01 +0100 | [diff] [blame] | 443 | /* Need to skip following NOP's to prevent a fake function from being stacked. */ |
| 444 | long stub_addr = (long) get_count_register(event->proc); |
| Juan Cespedes | 1dec217 | 2009-05-07 10:12:10 +0200 | [diff] [blame] | 445 | Breakpoint *stub_bp = NULL; |
| Luis Machado | 55c5feb | 2008-03-12 15:56:01 +0100 | [diff] [blame] | 446 | char nop_instruction[] = PPC_NOP; |
| 447 | |
| 448 | stub_bp = address2bpstruct (event->proc, event->e_un.brk_addr); |
| 449 | |
| 450 | if (stub_bp) { |
| 451 | unsigned char *bp_instruction = stub_bp->orig_value; |
| 452 | |
| 453 | if (memcmp(bp_instruction, nop_instruction, |
| 454 | PPC_NOP_LENGTH) == 0) { |
| 455 | if (stub_addr != (long) event->e_un.brk_addr) { |
| 456 | set_instruction_pointer (event->proc, event->e_un.brk_addr + 4); |
| 457 | continue_process(event->proc->pid); |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 458 | return; |
| 459 | } |
| 460 | } |
| Luis Machado | 55c5feb | 2008-03-12 15:56:01 +0100 | [diff] [blame] | 461 | } |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 462 | #endif |
| Luis Machado | 55c5feb | 2008-03-12 15:56:01 +0100 | [diff] [blame] | 463 | if ((sbp = event->proc->breakpoint_being_enabled) != 0) { |
| Juan Cespedes | b1dd77d | 2002-03-03 00:22:06 +0100 | [diff] [blame] | 464 | /* Reinsert breakpoint */ |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 465 | continue_enabling_breakpoint(event->proc->pid, |
| 466 | event->proc-> |
| 467 | breakpoint_being_enabled); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 468 | event->proc->breakpoint_being_enabled = NULL; |
| 469 | return; |
| 470 | } |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 471 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 472 | for (i = event->proc->callstack_depth - 1; i >= 0; i--) { |
| 473 | if (event->e_un.brk_addr == |
| 474 | event->proc->callstack[i].return_addr) { |
| Juan Cespedes | 5bfb061 | 2002-03-31 20:01:28 +0200 | [diff] [blame] | 475 | #ifdef __powerpc__ |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 476 | /* |
| 477 | * PPC HACK! (XXX FIXME TODO) |
| 478 | * The PLT gets modified during the first call, |
| 479 | * so be sure to re-enable the breakpoint. |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 480 | */ |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 481 | unsigned long a; |
| 482 | struct library_symbol *libsym = |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 483 | event->proc->callstack[i].c_un.libfunc; |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 484 | void *addr = sym2addr(event->proc, libsym); |
| Juan Cespedes | 5bfb061 | 2002-03-31 20:01:28 +0200 | [diff] [blame] | 485 | |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 486 | if (libsym->plt_type != LS_TOPLT_POINT) { |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 487 | unsigned char break_insn[] = BREAKPOINT_VALUE; |
| 488 | |
| 489 | sbp = address2bpstruct(event->proc, addr); |
| 490 | assert(sbp); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 491 | a = ptrace(PTRACE_PEEKTEXT, event->proc->pid, |
| 492 | addr); |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 493 | |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 494 | if (memcmp(&a, break_insn, BREAKPOINT_LENGTH)) { |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 495 | sbp->enabled--; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 496 | insert_breakpoint(event->proc, addr, |
| 497 | libsym); |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 498 | } |
| 499 | } else { |
| Juan Cespedes | bc8caf0 | 2009-05-07 19:38:38 +0200 | [diff] [blame^] | 500 | sbp = dict_find_entry(event->proc->breakpoints, sym2addr(event->proc, libsym)); |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 501 | assert(sbp); |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 502 | if (addr != sbp->addr) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 503 | insert_breakpoint(event->proc, addr, |
| 504 | libsym); |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 505 | } |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 506 | } |
| Eric Vaitl | 1228a91 | 2006-12-28 16:16:56 +0100 | [diff] [blame] | 507 | #elif defined(__mips__) |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 508 | void *addr; |
| 509 | void *old_addr; |
| 510 | struct library_symbol *sym= event->proc->callstack[i].c_un.libfunc; |
| Juan Cespedes | bc8caf0 | 2009-05-07 19:38:38 +0200 | [diff] [blame^] | 511 | assert(sym); |
| 512 | old_addr = dict_find_entry(event->proc->breakpoints, sym2addr(event->proc, sym))->addr; |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 513 | addr=sym2addr(event->proc,sym); |
| 514 | assert(old_addr !=0 && addr !=0); |
| 515 | if(addr != old_addr){ |
| 516 | struct library_symbol *new_sym; |
| 517 | new_sym=malloc(sizeof(*new_sym)); |
| 518 | memcpy(new_sym,sym,sizeof(*new_sym)); |
| 519 | new_sym->next=event->proc->list_of_symbols; |
| 520 | event->proc->list_of_symbols=new_sym; |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 521 | insert_breakpoint(event->proc, addr, new_sym); |
| 522 | } |
| Juan Cespedes | 5bfb061 | 2002-03-31 20:01:28 +0200 | [diff] [blame] | 523 | #endif |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 524 | for (j = event->proc->callstack_depth - 1; j > i; j--) { |
| Juan Cespedes | 5916fda | 2002-02-25 00:19:21 +0100 | [diff] [blame] | 525 | callstack_pop(event->proc); |
| 526 | } |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 527 | if (opt_T || options.summary) { |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 528 | calc_time_spent(event->proc); |
| 529 | } |
| 530 | callstack_pop(event->proc); |
| Juan Cespedes | 5916fda | 2002-02-25 00:19:21 +0100 | [diff] [blame] | 531 | event->proc->return_addr = event->e_un.brk_addr; |
| Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame] | 532 | output_right(LT_TOF_FUNCTIONR, event->proc, |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 533 | event->proc->callstack[i].c_un.libfunc-> |
| 534 | name); |
| Juan Cespedes | 5916fda | 2002-02-25 00:19:21 +0100 | [diff] [blame] | 535 | continue_after_breakpoint(event->proc, |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 536 | address2bpstruct(event->proc, |
| 537 | event->e_un. |
| 538 | brk_addr)); |
| Juan Cespedes | 5916fda | 2002-02-25 00:19:21 +0100 | [diff] [blame] | 539 | return; |
| 540 | } |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 541 | } |
| 542 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 543 | if ((sbp = address2bpstruct(event->proc, event->e_un.brk_addr))) { |
| 544 | event->proc->stack_pointer = get_stack_pointer(event->proc); |
| 545 | event->proc->return_addr = |
| 546 | get_return_addr(event->proc, event->proc->stack_pointer); |
| 547 | output_left(LT_TOF_FUNCTION, event->proc, sbp->libsym->name); |
| 548 | callstack_push_symfunc(event->proc, sbp->libsym); |
| Paul Gilliam | be32077 | 2006-04-24 22:06:23 +0200 | [diff] [blame] | 549 | #ifdef PLT_REINITALISATION_BP |
| 550 | if (event->proc->need_to_reinitialize_breakpoints |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 551 | && (strcmp(sbp->libsym->name, PLTs_initialized_by_here) == |
| 552 | 0)) |
| 553 | reinitialize_breakpoints(event->proc); |
| Paul Gilliam | be32077 | 2006-04-24 22:06:23 +0200 | [diff] [blame] | 554 | #endif |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 555 | |
| 556 | continue_after_breakpoint(event->proc, sbp); |
| 557 | return; |
| 558 | } |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 559 | |
| 560 | output_line(event->proc, "unexpected breakpoint at %p", |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 561 | (void *)event->e_un.brk_addr); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 562 | continue_process(event->proc->pid); |
| 563 | } |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 564 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 565 | static void |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 566 | callstack_push_syscall(Process *proc, int sysnum) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 567 | struct callstack_element *elem; |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 568 | |
| 569 | /* FIXME: not good -- should use dynamic allocation. 19990703 mortene. */ |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 570 | if (proc->callstack_depth == MAX_CALLDEPTH - 1) { |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 571 | fprintf(stderr, "Error: call nesting too deep!\n"); |
| 572 | return; |
| 573 | } |
| 574 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 575 | elem = &proc->callstack[proc->callstack_depth]; |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 576 | elem->is_syscall = 1; |
| 577 | elem->c_un.syscall = sysnum; |
| 578 | elem->return_addr = NULL; |
| 579 | |
| 580 | proc->callstack_depth++; |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 581 | if (opt_T || options.summary) { |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 582 | struct timezone tz; |
| 583 | gettimeofday(&elem->time_spent, &tz); |
| 584 | } |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 585 | } |
| 586 | |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 587 | static void |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 588 | callstack_push_symfunc(Process *proc, struct library_symbol *sym) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 589 | struct callstack_element *elem; |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 590 | |
| 591 | /* FIXME: not good -- should use dynamic allocation. 19990703 mortene. */ |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 592 | if (proc->callstack_depth == MAX_CALLDEPTH - 1) { |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 593 | fprintf(stderr, "Error: call nesting too deep!\n"); |
| 594 | return; |
| 595 | } |
| 596 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 597 | elem = &proc->callstack[proc->callstack_depth]; |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 598 | elem->is_syscall = 0; |
| 599 | elem->c_un.libfunc = sym; |
| 600 | |
| Juan Cespedes | 3f0b62e | 2001-07-09 01:02:52 +0200 | [diff] [blame] | 601 | elem->return_addr = proc->return_addr; |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 602 | if (elem->return_addr) { |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 603 | insert_breakpoint(proc, elem->return_addr, 0); |
| 604 | } |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 605 | |
| 606 | proc->callstack_depth++; |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 607 | if (opt_T || options.summary) { |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 608 | struct timezone tz; |
| 609 | gettimeofday(&elem->time_spent, &tz); |
| 610 | } |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 611 | } |
| 612 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 613 | static void |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 614 | callstack_pop(Process *proc) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 615 | struct callstack_element *elem; |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 616 | assert(proc->callstack_depth > 0); |
| 617 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 618 | elem = &proc->callstack[proc->callstack_depth - 1]; |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 619 | if (!elem->is_syscall && elem->return_addr) { |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 620 | delete_breakpoint(proc, elem->return_addr); |
| 621 | } |
| 622 | proc->callstack_depth--; |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 623 | } |