| Petr Machata | 94078ec | 2012-01-05 18:07:02 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of ltrace. |
| Petr Machata | 057caa5 | 2013-01-30 23:28:47 +0100 | [diff] [blame] | 3 | * Copyright (C) 2011,2012,2013 Petr Machata, Red Hat Inc. |
| Petr Machata | 94078ec | 2012-01-05 18:07:02 +0100 | [diff] [blame] | 4 | * Copyright (C) 2010 Arnaud Patard, Mandriva SA |
| 5 | * Copyright (C) 1998,2001,2002,2003,2004,2007,2008,2009 Juan Cespedes |
| 6 | * Copyright (C) 2008 Luis Machado, IBM Corporation |
| 7 | * Copyright (C) 2006 Ian Wienand |
| 8 | * Copyright (C) 2006 Paul Gilliam, IBM Corporation |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of the |
| 13 | * License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 23 | * 02110-1301 USA |
| 24 | */ |
| 25 | |
| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 26 | #include "config.h" |
| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 27 | |
| Petr Machata | 94078ec | 2012-01-05 18:07:02 +0100 | [diff] [blame] | 28 | #define _GNU_SOURCE |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 29 | #include <assert.h> |
| Petr Machata | 534e00f | 2011-09-27 17:58:38 +0200 | [diff] [blame] | 30 | #include <errno.h> |
| Petr Machata | 3d0c91c | 2012-04-14 02:37:38 +0200 | [diff] [blame] | 31 | #include <signal.h> |
| 32 | #include <stdio.h> |
| 33 | #include <stdlib.h> |
| 34 | #include <string.h> |
| 35 | #include <sys/time.h> |
| Petr Machata | 82f748d | 2013-10-23 00:39:23 +0200 | [diff] [blame^] | 36 | #include <stdbool.h> |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 37 | |
| Petr Machata | 6426260 | 2012-01-07 03:41:36 +0100 | [diff] [blame] | 38 | #include "backend.h" |
| Petr Machata | 9294d82 | 2012-02-07 12:35:58 +0100 | [diff] [blame] | 39 | #include "breakpoint.h" |
| Petr Machata | ba1664b | 2012-04-28 14:59:05 +0200 | [diff] [blame] | 40 | #include "common.h" |
| 41 | #include "fetch.h" |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 42 | #include "library.h" |
| Petr Machata | 3d0c91c | 2012-04-14 02:37:38 +0200 | [diff] [blame] | 43 | #include "proc.h" |
| Petr Machata | 6426260 | 2012-01-07 03:41:36 +0100 | [diff] [blame] | 44 | #include "value_dict.h" |
| Petr Machata | 82f748d | 2013-10-23 00:39:23 +0200 | [diff] [blame^] | 45 | #include "prototype.h" |
| Petr Machata | fed1e8d | 2012-02-07 02:06:29 +0100 | [diff] [blame] | 46 | |
| Juan Cespedes | 03192f8 | 2009-07-03 10:16:22 +0200 | [diff] [blame] | 47 | static void handle_signal(Event *event); |
| 48 | static void handle_exit(Event *event); |
| 49 | static void handle_exit_signal(Event *event); |
| 50 | static void handle_syscall(Event *event); |
| 51 | static void handle_arch_syscall(Event *event); |
| 52 | static void handle_sysret(Event *event); |
| 53 | static void handle_arch_sysret(Event *event); |
| 54 | static void handle_clone(Event *event); |
| 55 | static void handle_exec(Event *event); |
| 56 | static void handle_breakpoint(Event *event); |
| 57 | static void handle_new(Event *event); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 58 | |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 59 | static void callstack_push_syscall(struct process *proc, int sysnum); |
| 60 | static void callstack_push_symfunc(struct process *proc, |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 61 | struct library_symbol *sym); |
| Petr Machata | e655ccf | 2012-10-26 22:21:59 +0200 | [diff] [blame] | 62 | /* XXX Stack maintenance should be moved to a dedicated module, or to |
| 63 | * proc.c, and push/pop should be visible outside this module. For |
| 64 | * now, because we need this in proc.c, this is non-static. */ |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 65 | void callstack_pop(struct process *proc); |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 66 | |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 67 | static char *shortsignal(struct process *proc, int signum); |
| 68 | static char *sysname(struct process *proc, int sysnum); |
| 69 | static char *arch_sysname(struct process *proc, int sysnum); |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 70 | |
| Petr Machata | cbe29c6 | 2011-09-27 02:27:58 +0200 | [diff] [blame] | 71 | static Event * |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 72 | call_handler(struct process *proc, Event *event) |
| Petr Machata | cbe29c6 | 2011-09-27 02:27:58 +0200 | [diff] [blame] | 73 | { |
| 74 | assert(proc != NULL); |
| 75 | |
| Petr Machata | 366c2f4 | 2012-02-09 19:34:36 +0100 | [diff] [blame] | 76 | struct event_handler *handler = proc->event_handler; |
| Petr Machata | cbe29c6 | 2011-09-27 02:27:58 +0200 | [diff] [blame] | 77 | if (handler == NULL) |
| 78 | return event; |
| 79 | |
| 80 | return (*handler->on_event) (handler, event); |
| 81 | } |
| 82 | |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 83 | void |
| Petr Machata | ffe4cd2 | 2012-04-11 18:01:44 +0200 | [diff] [blame] | 84 | handle_event(Event *event) |
| 85 | { |
| Petr Machata | 602330f | 2011-07-09 11:15:34 +0200 | [diff] [blame] | 86 | if (exiting == 1) { |
| Petr Machata | 602330f | 2011-07-09 11:15:34 +0200 | [diff] [blame] | 87 | debug(1, "ltrace about to exit"); |
| Petr Machata | ffe4cd2 | 2012-04-11 18:01:44 +0200 | [diff] [blame] | 88 | os_ltrace_exiting(); |
| 89 | exiting = 2; |
| Petr Machata | 602330f | 2011-07-09 11:15:34 +0200 | [diff] [blame] | 90 | } |
| Petr Machata | 2662768 | 2011-07-08 18:15:32 +0200 | [diff] [blame] | 91 | debug(DEBUG_FUNCTION, "handle_event(pid=%d, type=%d)", |
| 92 | event->proc ? event->proc->pid : -1, event->type); |
| Petr Machata | cbe29c6 | 2011-09-27 02:27:58 +0200 | [diff] [blame] | 93 | |
| 94 | /* If the thread group or an individual task define an |
| 95 | overriding event handler, give them a chance to kick in. |
| 96 | We will end up calling both handlers, if the first one |
| 97 | doesn't sink the event. */ |
| 98 | if (event->proc != NULL) { |
| 99 | event = call_handler(event->proc, event); |
| 100 | if (event == NULL) |
| 101 | /* It was handled. */ |
| 102 | return; |
| 103 | |
| 104 | /* Note: the previous handler has a chance to alter |
| 105 | * the event. */ |
| Petr Machata | 43d2fe5 | 2011-11-02 13:25:49 +0100 | [diff] [blame] | 106 | if (event->proc != NULL |
| 107 | && event->proc->leader != NULL |
| 108 | && event->proc != event->proc->leader) { |
| Petr Machata | cbe29c6 | 2011-09-27 02:27:58 +0200 | [diff] [blame] | 109 | event = call_handler(event->proc->leader, event); |
| Petr Machata | 4007d74 | 2011-07-09 11:29:42 +0200 | [diff] [blame] | 110 | if (event == NULL) |
| Petr Machata | 4007d74 | 2011-07-09 11:29:42 +0200 | [diff] [blame] | 111 | return; |
| 112 | } |
| 113 | } |
| 114 | |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 115 | switch (event->type) { |
| 116 | case EVENT_NONE: |
| 117 | debug(1, "event: none"); |
| 118 | return; |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 119 | |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 120 | case EVENT_SIGNAL: |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 121 | assert(event->proc != NULL); |
| Petr Machata | ebfe7d6 | 2012-04-13 21:34:49 +0200 | [diff] [blame] | 122 | debug(1, "[%d] event: signal (%s [%d])", |
| 123 | event->proc->pid, |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 124 | shortsignal(event->proc, event->e_un.signum), |
| 125 | event->e_un.signum); |
| 126 | handle_signal(event); |
| 127 | return; |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 128 | |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 129 | case EVENT_EXIT: |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 130 | assert(event->proc != NULL); |
| Petr Machata | ebfe7d6 | 2012-04-13 21:34:49 +0200 | [diff] [blame] | 131 | debug(1, "[%d] event: exit (%d)", |
| 132 | event->proc->pid, |
| 133 | event->e_un.ret_val); |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 134 | handle_exit(event); |
| 135 | return; |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 136 | |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 137 | case EVENT_EXIT_SIGNAL: |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 138 | assert(event->proc != NULL); |
| Petr Machata | ebfe7d6 | 2012-04-13 21:34:49 +0200 | [diff] [blame] | 139 | debug(1, "[%d] event: exit signal (%s [%d])", |
| 140 | event->proc->pid, |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 141 | shortsignal(event->proc, event->e_un.signum), |
| 142 | event->e_un.signum); |
| 143 | handle_exit_signal(event); |
| 144 | return; |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 145 | |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 146 | case EVENT_SYSCALL: |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 147 | assert(event->proc != NULL); |
| Petr Machata | ebfe7d6 | 2012-04-13 21:34:49 +0200 | [diff] [blame] | 148 | debug(1, "[%d] event: syscall (%s [%d])", |
| 149 | event->proc->pid, |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 150 | sysname(event->proc, event->e_un.sysnum), |
| 151 | event->e_un.sysnum); |
| 152 | handle_syscall(event); |
| 153 | return; |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 154 | |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 155 | case EVENT_SYSRET: |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 156 | assert(event->proc != NULL); |
| Petr Machata | ebfe7d6 | 2012-04-13 21:34:49 +0200 | [diff] [blame] | 157 | debug(1, "[%d] event: sysret (%s [%d])", |
| 158 | event->proc->pid, |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 159 | sysname(event->proc, event->e_un.sysnum), |
| 160 | event->e_un.sysnum); |
| 161 | handle_sysret(event); |
| 162 | return; |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 163 | |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 164 | case EVENT_ARCH_SYSCALL: |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 165 | assert(event->proc != NULL); |
| Petr Machata | ebfe7d6 | 2012-04-13 21:34:49 +0200 | [diff] [blame] | 166 | debug(1, "[%d] event: arch_syscall (%s [%d])", |
| 167 | event->proc->pid, |
| 168 | arch_sysname(event->proc, event->e_un.sysnum), |
| 169 | event->e_un.sysnum); |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 170 | handle_arch_syscall(event); |
| 171 | return; |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 172 | |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 173 | case EVENT_ARCH_SYSRET: |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 174 | assert(event->proc != NULL); |
| Petr Machata | ebfe7d6 | 2012-04-13 21:34:49 +0200 | [diff] [blame] | 175 | debug(1, "[%d] event: arch_sysret (%s [%d])", |
| 176 | event->proc->pid, |
| 177 | arch_sysname(event->proc, event->e_un.sysnum), |
| 178 | event->e_un.sysnum); |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 179 | handle_arch_sysret(event); |
| 180 | return; |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 181 | |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 182 | case EVENT_CLONE: |
| Petr Machata | cbe29c6 | 2011-09-27 02:27:58 +0200 | [diff] [blame] | 183 | case EVENT_VFORK: |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 184 | assert(event->proc != NULL); |
| Petr Machata | ebfe7d6 | 2012-04-13 21:34:49 +0200 | [diff] [blame] | 185 | debug(1, "[%d] event: clone (%u)", |
| 186 | event->proc->pid, event->e_un.newpid); |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 187 | handle_clone(event); |
| 188 | return; |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 189 | |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 190 | case EVENT_EXEC: |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 191 | assert(event->proc != NULL); |
| Petr Machata | ebfe7d6 | 2012-04-13 21:34:49 +0200 | [diff] [blame] | 192 | debug(1, "[%d] event: exec()", |
| 193 | event->proc->pid); |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 194 | handle_exec(event); |
| 195 | return; |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 196 | |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 197 | case EVENT_BREAKPOINT: |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 198 | assert(event->proc != NULL); |
| Petr Machata | ebfe7d6 | 2012-04-13 21:34:49 +0200 | [diff] [blame] | 199 | debug(1, "[%d] event: breakpoint %p", |
| 200 | event->proc->pid, event->e_un.brk_addr); |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 201 | handle_breakpoint(event); |
| 202 | return; |
| Petr Machata | 9978de4 | 2013-01-08 23:46:22 +0100 | [diff] [blame] | 203 | |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 204 | case EVENT_NEW: |
| Petr Machata | ebfe7d6 | 2012-04-13 21:34:49 +0200 | [diff] [blame] | 205 | debug(1, "[%d] event: new process", |
| 206 | event->e_un.newpid); |
| Juan Cespedes | 61da337 | 2009-07-03 11:55:44 +0200 | [diff] [blame] | 207 | handle_new(event); |
| 208 | return; |
| 209 | default: |
| 210 | fprintf(stderr, "Error! unknown event?\n"); |
| 211 | exit(1); |
| 212 | } |
| 213 | } |
| 214 | |
| Juan Cespedes | bc8caf0 | 2009-05-07 19:38:38 +0200 | [diff] [blame] | 215 | typedef struct Pending_New Pending_New; |
| 216 | struct Pending_New { |
| 217 | pid_t pid; |
| 218 | Pending_New * next; |
| 219 | }; |
| 220 | static Pending_New * pending_news = NULL; |
| 221 | |
| 222 | static int |
| 223 | pending_new(pid_t pid) { |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 224 | Pending_New * p; |
| 225 | |
| 226 | debug(DEBUG_FUNCTION, "pending_new(%d)", pid); |
| 227 | |
| 228 | p = pending_news; |
| Juan Cespedes | bc8caf0 | 2009-05-07 19:38:38 +0200 | [diff] [blame] | 229 | while (p) { |
| 230 | if (p->pid == pid) { |
| 231 | return 1; |
| 232 | } |
| 233 | p = p->next; |
| 234 | } |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | static void |
| 239 | pending_new_insert(pid_t pid) { |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 240 | Pending_New * p; |
| 241 | |
| 242 | debug(DEBUG_FUNCTION, "pending_new_insert(%d)", pid); |
| 243 | |
| 244 | p = malloc(sizeof(Pending_New)); |
| Juan Cespedes | bc8caf0 | 2009-05-07 19:38:38 +0200 | [diff] [blame] | 245 | if (!p) { |
| 246 | perror("malloc()"); |
| 247 | exit(1); |
| 248 | } |
| 249 | p->pid = pid; |
| 250 | p->next = pending_news; |
| 251 | pending_news = p; |
| 252 | } |
| 253 | |
| 254 | static void |
| Petr Machata | c1f1bf4 | 2013-01-09 22:39:41 +0100 | [diff] [blame] | 255 | pending_new_remove(pid_t pid) |
| 256 | { |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 257 | debug(DEBUG_FUNCTION, "pending_new_remove(%d)", pid); |
| 258 | |
| Petr Machata | c1f1bf4 | 2013-01-09 22:39:41 +0100 | [diff] [blame] | 259 | Pending_New **pp; |
| 260 | for (pp = &pending_news; *pp != NULL; pp = &(*pp)->next) |
| 261 | if ((*pp)->pid == pid) { |
| 262 | Pending_New *p = *pp; |
| 263 | *pp = p->next; |
| 264 | free(p); |
| 265 | return; |
| Juan Cespedes | bc8caf0 | 2009-05-07 19:38:38 +0200 | [diff] [blame] | 266 | } |
| Juan Cespedes | bc8caf0 | 2009-05-07 19:38:38 +0200 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | static void |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 270 | handle_clone(Event *event) |
| 271 | { |
| Juan Cespedes | 03192f8 | 2009-07-03 10:16:22 +0200 | [diff] [blame] | 272 | debug(DEBUG_FUNCTION, "handle_clone(pid=%d)", event->proc->pid); |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 273 | |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 274 | struct process *proc = malloc(sizeof(*proc)); |
| Petr Machata | 6095c13 | 2013-01-07 19:08:18 +0100 | [diff] [blame] | 275 | pid_t newpid = event->e_un.newpid; |
| 276 | if (proc == NULL |
| 277 | || process_clone(proc, event->proc, newpid) < 0) { |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 278 | free(proc); |
| Petr Machata | 6095c13 | 2013-01-07 19:08:18 +0100 | [diff] [blame] | 279 | proc = NULL; |
| Petr Machata | 94078ec | 2012-01-05 18:07:02 +0100 | [diff] [blame] | 280 | fprintf(stderr, |
| Petr Machata | 6095c13 | 2013-01-07 19:08:18 +0100 | [diff] [blame] | 281 | "Couldn't initialize tracing of process %d.\n", |
| 282 | newpid); |
| 283 | |
| 284 | } else { |
| 285 | proc->parent = event->proc; |
| 286 | /* We save register values to the arch pointer, and |
| 287 | * these need to be per-thread. XXX arch_ptr should |
| 288 | * be retired in favor of fetch interface anyway. */ |
| 289 | proc->arch_ptr = NULL; |
| Juan Cespedes | bc8caf0 | 2009-05-07 19:38:38 +0200 | [diff] [blame] | 290 | } |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 291 | |
| Petr Machata | 6095c13 | 2013-01-07 19:08:18 +0100 | [diff] [blame] | 292 | if (pending_new(newpid)) { |
| 293 | pending_new_remove(newpid); |
| Juan Cespedes | bc8caf0 | 2009-05-07 19:38:38 +0200 | [diff] [blame] | 294 | |
| Petr Machata | 6095c13 | 2013-01-07 19:08:18 +0100 | [diff] [blame] | 295 | if (proc != NULL) { |
| 296 | proc->event_handler = NULL; |
| 297 | if (event->proc->state == STATE_ATTACHED |
| 298 | && options.follow) |
| 299 | proc->state = STATE_ATTACHED; |
| 300 | else |
| 301 | proc->state = STATE_IGNORED; |
| 302 | } |
| Petr Machata | 75dcf7d | 2011-10-06 14:30:19 +0200 | [diff] [blame] | 303 | |
| Petr Machata | 6095c13 | 2013-01-07 19:08:18 +0100 | [diff] [blame] | 304 | continue_process(newpid); |
| 305 | |
| 306 | } else if (proc != NULL) { |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 307 | proc->state = STATE_BEING_CREATED; |
| Juan Cespedes | bc8caf0 | 2009-05-07 19:38:38 +0200 | [diff] [blame] | 308 | } |
| Petr Machata | 534e00f | 2011-09-27 17:58:38 +0200 | [diff] [blame] | 309 | |
| Petr Machata | 6095c13 | 2013-01-07 19:08:18 +0100 | [diff] [blame] | 310 | if (event->type != EVENT_VFORK) |
| 311 | continue_process(event->proc->pid); |
| 312 | else if (proc != NULL) |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 313 | continue_after_vfork(proc); |
| Petr Machata | cbe29c6 | 2011-09-27 02:27:58 +0200 | [diff] [blame] | 314 | else |
| Petr Machata | 6095c13 | 2013-01-07 19:08:18 +0100 | [diff] [blame] | 315 | continue_process(newpid); |
| Juan Cespedes | bc8caf0 | 2009-05-07 19:38:38 +0200 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | static void |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 319 | handle_new(Event *event) |
| 320 | { |
| Juan Cespedes | 03192f8 | 2009-07-03 10:16:22 +0200 | [diff] [blame] | 321 | debug(DEBUG_FUNCTION, "handle_new(pid=%d)", event->e_un.newpid); |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 322 | |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 323 | struct process *proc = pid2proc(event->e_un.newpid); |
| Juan Cespedes | bc8caf0 | 2009-05-07 19:38:38 +0200 | [diff] [blame] | 324 | if (!proc) { |
| 325 | pending_new_insert(event->e_un.newpid); |
| 326 | } else { |
| 327 | assert(proc->state == STATE_BEING_CREATED); |
| Juan Cespedes | 30439b4 | 2009-05-22 19:03:09 +0200 | [diff] [blame] | 328 | if (options.follow) { |
| Juan Cespedes | 5c68204 | 2009-05-21 15:59:56 +0200 | [diff] [blame] | 329 | proc->state = STATE_ATTACHED; |
| 330 | } else { |
| 331 | proc->state = STATE_IGNORED; |
| 332 | } |
| Juan Cespedes | bc8caf0 | 2009-05-07 19:38:38 +0200 | [diff] [blame] | 333 | continue_process(proc->pid); |
| 334 | } |
| 335 | } |
| 336 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 337 | static char * |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 338 | shortsignal(struct process *proc, int signum) |
| 339 | { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 340 | static char *signalent0[] = { |
| 341 | #include "signalent.h" |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 342 | }; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 343 | static char *signalent1[] = { |
| 344 | #include "signalent1.h" |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 345 | }; |
| 346 | static char **signalents[] = { signalent0, signalent1 }; |
| 347 | int nsignals[] = { sizeof signalent0 / sizeof signalent0[0], |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 348 | sizeof signalent1 / sizeof signalent1[0] |
| 349 | }; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 350 | |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 351 | debug(DEBUG_FUNCTION, "shortsignal(pid=%d, signum=%d)", proc->pid, signum); |
| 352 | |
| Petr Machata | 8e682c2 | 2013-01-09 16:20:20 +0100 | [diff] [blame] | 353 | assert(proc->personality < sizeof signalents / sizeof signalents[0]); |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 354 | if (signum < 0 || signum >= nsignals[proc->personality]) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 355 | return "UNKNOWN_SIGNAL"; |
| 356 | } else { |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 357 | return signalents[proc->personality][signum]; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 361 | static char * |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 362 | sysname(struct process *proc, int sysnum) |
| 363 | { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 364 | static char result[128]; |
| Petr Machata | 8e682c2 | 2013-01-09 16:20:20 +0100 | [diff] [blame] | 365 | static char *syscallent0[] = { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 366 | #include "syscallent.h" |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 367 | }; |
| Petr Machata | 8e682c2 | 2013-01-09 16:20:20 +0100 | [diff] [blame] | 368 | static char *syscallent1[] = { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 369 | #include "syscallent1.h" |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 370 | }; |
| Petr Machata | 8e682c2 | 2013-01-09 16:20:20 +0100 | [diff] [blame] | 371 | static char **syscallents[] = { syscallent0, syscallent1 }; |
| 372 | int nsyscalls[] = { |
| 373 | sizeof syscallent0 / sizeof syscallent0[0], |
| 374 | sizeof syscallent1 / sizeof syscallent1[0], |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 375 | }; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 376 | |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 377 | debug(DEBUG_FUNCTION, "sysname(pid=%d, sysnum=%d)", proc->pid, sysnum); |
| 378 | |
| Petr Machata | 8e682c2 | 2013-01-09 16:20:20 +0100 | [diff] [blame] | 379 | assert(proc->personality < sizeof syscallents / sizeof syscallents[0]); |
| 380 | if (sysnum < 0 || sysnum >= nsyscalls[proc->personality]) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 381 | sprintf(result, "SYS_%d", sysnum); |
| 382 | return result; |
| 383 | } else { |
| Petr Machata | 82f748d | 2013-10-23 00:39:23 +0200 | [diff] [blame^] | 384 | return syscallents[proc->personality][sysnum]; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 388 | static char * |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 389 | arch_sysname(struct process *proc, int sysnum) |
| 390 | { |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 391 | static char result[128]; |
| Petr Machata | 8e682c2 | 2013-01-09 16:20:20 +0100 | [diff] [blame] | 392 | static char *arch_syscallent[] = { |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 393 | #include "arch_syscallent.h" |
| 394 | }; |
| Petr Machata | 8e682c2 | 2013-01-09 16:20:20 +0100 | [diff] [blame] | 395 | int nsyscalls = sizeof arch_syscallent / sizeof arch_syscallent[0]; |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 396 | |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 397 | debug(DEBUG_FUNCTION, "arch_sysname(pid=%d, sysnum=%d)", proc->pid, sysnum); |
| 398 | |
| Petr Machata | 8e682c2 | 2013-01-09 16:20:20 +0100 | [diff] [blame] | 399 | if (sysnum < 0 || sysnum >= nsyscalls) { |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 400 | sprintf(result, "ARCH_%d", sysnum); |
| 401 | return result; |
| 402 | } else { |
| Petr Machata | 8e682c2 | 2013-01-09 16:20:20 +0100 | [diff] [blame] | 403 | sprintf(result, "ARCH_%s", arch_syscallent[sysnum]); |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 404 | return result; |
| 405 | } |
| 406 | } |
| 407 | |
| Petr Machata | 7c4d311 | 2012-12-09 11:55:03 +0100 | [diff] [blame] | 408 | #ifndef HAVE_STRSIGNAL |
| 409 | # define strsignal(SIGNUM) "???" |
| 410 | #endif |
| 411 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 412 | static void |
| Juan Cespedes | 03192f8 | 2009-07-03 10:16:22 +0200 | [diff] [blame] | 413 | handle_signal(Event *event) { |
| 414 | debug(DEBUG_FUNCTION, "handle_signal(pid=%d, signum=%d)", event->proc->pid, event->e_un.signum); |
| Joe Damato | 59e3fb1 | 2009-11-06 19:45:10 -0800 | [diff] [blame] | 415 | if (event->proc->state != STATE_IGNORED && !options.no_signals) { |
| Juan Cespedes | 5c68204 | 2009-05-21 15:59:56 +0200 | [diff] [blame] | 416 | output_line(event->proc, "--- %s (%s) ---", |
| 417 | shortsignal(event->proc, event->e_un.signum), |
| 418 | strsignal(event->e_un.signum)); |
| 419 | } |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 420 | continue_after_signal(event->proc->pid, event->e_un.signum); |
| 421 | } |
| 422 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 423 | static void |
| Juan Cespedes | 03192f8 | 2009-07-03 10:16:22 +0200 | [diff] [blame] | 424 | handle_exit(Event *event) { |
| 425 | debug(DEBUG_FUNCTION, "handle_exit(pid=%d, status=%d)", event->proc->pid, event->e_un.ret_val); |
| Juan Cespedes | 5c68204 | 2009-05-21 15:59:56 +0200 | [diff] [blame] | 426 | if (event->proc->state != STATE_IGNORED) { |
| 427 | output_line(event->proc, "+++ exited (status %d) +++", |
| 428 | event->e_un.ret_val); |
| 429 | } |
| Petr Machata | cebb884 | 2011-07-09 11:14:11 +0200 | [diff] [blame] | 430 | remove_process(event->proc); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 431 | } |
| 432 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 433 | static void |
| Juan Cespedes | 03192f8 | 2009-07-03 10:16:22 +0200 | [diff] [blame] | 434 | handle_exit_signal(Event *event) { |
| 435 | debug(DEBUG_FUNCTION, "handle_exit_signal(pid=%d, signum=%d)", event->proc->pid, event->e_un.signum); |
| Juan Cespedes | 5c68204 | 2009-05-21 15:59:56 +0200 | [diff] [blame] | 436 | if (event->proc->state != STATE_IGNORED) { |
| 437 | output_line(event->proc, "+++ killed by %s +++", |
| 438 | shortsignal(event->proc, event->e_un.signum)); |
| 439 | } |
| Petr Machata | cebb884 | 2011-07-09 11:14:11 +0200 | [diff] [blame] | 440 | remove_process(event->proc); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 441 | } |
| 442 | |
| Petr Machata | a32ef7c | 2012-04-23 18:05:24 +0200 | [diff] [blame] | 443 | static void |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 444 | output_syscall(struct process *proc, const char *name, enum tof tof, |
| 445 | void (*output)(enum tof, struct process *, |
| Petr Machata | a32ef7c | 2012-04-23 18:05:24 +0200 | [diff] [blame] | 446 | struct library_symbol *)) |
| Petr Machata | 29add4f | 2012-02-18 16:38:05 +0100 | [diff] [blame] | 447 | { |
| Petr Machata | 82f748d | 2013-10-23 00:39:23 +0200 | [diff] [blame^] | 448 | static struct library syscall_lib; |
| 449 | if (syscall_lib.protolib == NULL) { |
| 450 | struct protolib *protolib |
| 451 | = protolib_cache_search(&g_protocache, "syscalls", 0, 1); |
| 452 | if (protolib == NULL) { |
| 453 | fprintf(stderr, "Couldn't load system call prototypes:" |
| 454 | " %s.\n", strerror(errno)); |
| 455 | |
| 456 | /* Instead, get a fake one just so we can |
| 457 | * carry on, limping. */ |
| 458 | protolib = malloc(sizeof *protolib); |
| 459 | if (protolib == NULL) { |
| 460 | fprintf(stderr, "Couldn't even allocate a fake " |
| 461 | "prototype library: %s.\n", |
| 462 | strerror(errno)); |
| 463 | abort(); |
| 464 | } |
| 465 | protolib_init(protolib); |
| 466 | } |
| 467 | |
| 468 | assert(protolib != NULL); |
| 469 | if (library_init(&syscall_lib, LT_LIBTYPE_SYSCALL) < 0) { |
| 470 | fprintf(stderr, "Couldn't initialize system call " |
| 471 | "library: %s.\n", strerror(errno)); |
| 472 | abort(); |
| 473 | } |
| 474 | |
| 475 | library_set_soname(&syscall_lib, "SYS", 0); |
| 476 | syscall_lib.protolib = protolib; |
| 477 | } |
| 478 | |
| Petr Machata | a32ef7c | 2012-04-23 18:05:24 +0200 | [diff] [blame] | 479 | struct library_symbol syscall; |
| 480 | if (library_symbol_init(&syscall, 0, name, 0, LS_TOPLT_NONE) >= 0) { |
| Petr Machata | 82f748d | 2013-10-23 00:39:23 +0200 | [diff] [blame^] | 481 | syscall.lib = &syscall_lib; |
| Petr Machata | 1e0b9dc | 2012-04-28 15:58:43 +0200 | [diff] [blame] | 482 | (*output)(tof, proc, &syscall); |
| Petr Machata | a32ef7c | 2012-04-23 18:05:24 +0200 | [diff] [blame] | 483 | library_symbol_destroy(&syscall); |
| Petr Machata | 29add4f | 2012-02-18 16:38:05 +0100 | [diff] [blame] | 484 | } |
| Petr Machata | 29add4f | 2012-02-18 16:38:05 +0100 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | static void |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 488 | output_syscall_left(struct process *proc, const char *name) |
| Petr Machata | 29add4f | 2012-02-18 16:38:05 +0100 | [diff] [blame] | 489 | { |
| Petr Machata | 1e0b9dc | 2012-04-28 15:58:43 +0200 | [diff] [blame] | 490 | output_syscall(proc, name, LT_TOF_SYSCALL, &output_left); |
| Petr Machata | 29add4f | 2012-02-18 16:38:05 +0100 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | static void |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 494 | output_syscall_right(struct process *proc, const char *name) |
| Petr Machata | 29add4f | 2012-02-18 16:38:05 +0100 | [diff] [blame] | 495 | { |
| Petr Machata | 1e0b9dc | 2012-04-28 15:58:43 +0200 | [diff] [blame] | 496 | output_syscall(proc, name, LT_TOF_SYSCALLR, &output_right); |
| Petr Machata | 29add4f | 2012-02-18 16:38:05 +0100 | [diff] [blame] | 497 | } |
| 498 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 499 | static void |
| Juan Cespedes | 03192f8 | 2009-07-03 10:16:22 +0200 | [diff] [blame] | 500 | handle_syscall(Event *event) { |
| 501 | debug(DEBUG_FUNCTION, "handle_syscall(pid=%d, sysnum=%d)", event->proc->pid, event->e_un.sysnum); |
| Juan Cespedes | 5c68204 | 2009-05-21 15:59:56 +0200 | [diff] [blame] | 502 | if (event->proc->state != STATE_IGNORED) { |
| Petr Machata | 211f088 | 2010-11-03 18:42:18 +0100 | [diff] [blame] | 503 | callstack_push_syscall(event->proc, event->e_un.sysnum); |
| Petr Machata | 29add4f | 2012-02-18 16:38:05 +0100 | [diff] [blame] | 504 | if (options.syscalls) |
| 505 | output_syscall_left(event->proc, |
| 506 | sysname(event->proc, |
| 507 | event->e_un.sysnum)); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 508 | } |
| Petr Machata | 43d2fe5 | 2011-11-02 13:25:49 +0100 | [diff] [blame] | 509 | continue_after_syscall(event->proc, event->e_un.sysnum, 0); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 510 | } |
| 511 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 512 | static void |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 513 | handle_exec(Event *event) |
| 514 | { |
| 515 | struct process *proc = event->proc; |
| Juan Cespedes | e0660df | 2009-05-21 18:14:39 +0200 | [diff] [blame] | 516 | |
| Petr Machata | 3d0c91c | 2012-04-14 02:37:38 +0200 | [diff] [blame] | 517 | /* Save the PID so that we can use it after unsuccessful |
| 518 | * process_exec. */ |
| 519 | pid_t pid = proc->pid; |
| 520 | |
| Juan Cespedes | 03192f8 | 2009-07-03 10:16:22 +0200 | [diff] [blame] | 521 | debug(DEBUG_FUNCTION, "handle_exec(pid=%d)", proc->pid); |
| Juan Cespedes | e0660df | 2009-05-21 18:14:39 +0200 | [diff] [blame] | 522 | if (proc->state == STATE_IGNORED) { |
| Petr Machata | 3d0c91c | 2012-04-14 02:37:38 +0200 | [diff] [blame] | 523 | untrace: |
| 524 | untrace_pid(pid); |
| Petr Machata | cebb884 | 2011-07-09 11:14:11 +0200 | [diff] [blame] | 525 | remove_process(proc); |
| Juan Cespedes | e0660df | 2009-05-21 18:14:39 +0200 | [diff] [blame] | 526 | return; |
| Juan Cespedes | 5c68204 | 2009-05-21 15:59:56 +0200 | [diff] [blame] | 527 | } |
| Juan Cespedes | e0660df | 2009-05-21 18:14:39 +0200 | [diff] [blame] | 528 | output_line(proc, "--- Called exec() ---"); |
| Petr Machata | 3d0c91c | 2012-04-14 02:37:38 +0200 | [diff] [blame] | 529 | |
| 530 | if (process_exec(proc) < 0) { |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 531 | fprintf(stderr, |
| 532 | "couldn't reinitialize process %d after exec\n", pid); |
| Petr Machata | 3d0c91c | 2012-04-14 02:37:38 +0200 | [diff] [blame] | 533 | goto untrace; |
| 534 | } |
| 535 | |
| Petr Machata | 057caa5 | 2013-01-30 23:28:47 +0100 | [diff] [blame] | 536 | continue_after_exec(proc); |
| Juan Cespedes | 1e58313 | 2009-04-07 18:17:11 +0200 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | static void |
| Juan Cespedes | 03192f8 | 2009-07-03 10:16:22 +0200 | [diff] [blame] | 540 | handle_arch_syscall(Event *event) { |
| 541 | debug(DEBUG_FUNCTION, "handle_arch_syscall(pid=%d, sysnum=%d)", event->proc->pid, event->e_un.sysnum); |
| Juan Cespedes | 5c68204 | 2009-05-21 15:59:56 +0200 | [diff] [blame] | 542 | if (event->proc->state != STATE_IGNORED) { |
| Petr Machata | 211f088 | 2010-11-03 18:42:18 +0100 | [diff] [blame] | 543 | callstack_push_syscall(event->proc, 0xf0000 + event->e_un.sysnum); |
| Juan Cespedes | 5c68204 | 2009-05-21 15:59:56 +0200 | [diff] [blame] | 544 | if (options.syscalls) { |
| Petr Machata | 29add4f | 2012-02-18 16:38:05 +0100 | [diff] [blame] | 545 | output_syscall_left(event->proc, |
| 546 | arch_sysname(event->proc, |
| 547 | event->e_un.sysnum)); |
| Juan Cespedes | 5c68204 | 2009-05-21 15:59:56 +0200 | [diff] [blame] | 548 | } |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 549 | } |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 550 | continue_process(event->proc->pid); |
| 551 | } |
| 552 | |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 553 | struct timeval current_time_spent; |
| 554 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 555 | static void |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 556 | calc_time_spent(struct process *proc) |
| 557 | { |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 558 | struct timeval tv; |
| 559 | struct timezone tz; |
| 560 | struct timeval diff; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 561 | struct callstack_element *elem; |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 562 | |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 563 | debug(DEBUG_FUNCTION, "calc_time_spent(pid=%d)", proc->pid); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 564 | elem = &proc->callstack[proc->callstack_depth - 1]; |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 565 | |
| 566 | gettimeofday(&tv, &tz); |
| 567 | |
| 568 | diff.tv_sec = tv.tv_sec - elem->time_spent.tv_sec; |
| 569 | if (tv.tv_usec >= elem->time_spent.tv_usec) { |
| 570 | diff.tv_usec = tv.tv_usec - elem->time_spent.tv_usec; |
| 571 | } else { |
| Paul Buerger | 6aa0152 | 2012-09-12 10:58:52 -0400 | [diff] [blame] | 572 | diff.tv_sec--; |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 573 | diff.tv_usec = 1000000 + tv.tv_usec - elem->time_spent.tv_usec; |
| 574 | } |
| 575 | current_time_spent = diff; |
| 576 | } |
| 577 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 578 | static void |
| Juan Cespedes | 03192f8 | 2009-07-03 10:16:22 +0200 | [diff] [blame] | 579 | handle_sysret(Event *event) { |
| 580 | debug(DEBUG_FUNCTION, "handle_sysret(pid=%d, sysnum=%d)", event->proc->pid, event->e_un.sysnum); |
| Juan Cespedes | 5c68204 | 2009-05-21 15:59:56 +0200 | [diff] [blame] | 581 | if (event->proc->state != STATE_IGNORED) { |
| 582 | if (opt_T || options.summary) { |
| 583 | calc_time_spent(event->proc); |
| 584 | } |
| Petr Machata | 29add4f | 2012-02-18 16:38:05 +0100 | [diff] [blame] | 585 | if (options.syscalls) |
| 586 | output_syscall_right(event->proc, |
| 587 | sysname(event->proc, |
| 588 | event->e_un.sysnum)); |
| 589 | |
| Petr Machata | 43d2fe5 | 2011-11-02 13:25:49 +0100 | [diff] [blame] | 590 | assert(event->proc->callstack_depth > 0); |
| 591 | unsigned d = event->proc->callstack_depth - 1; |
| 592 | assert(event->proc->callstack[d].is_syscall); |
| Petr Machata | 211f088 | 2010-11-03 18:42:18 +0100 | [diff] [blame] | 593 | callstack_pop(event->proc); |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 594 | } |
| Petr Machata | 43d2fe5 | 2011-11-02 13:25:49 +0100 | [diff] [blame] | 595 | continue_after_syscall(event->proc, event->e_un.sysnum, 1); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 596 | } |
| 597 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 598 | static void |
| Juan Cespedes | 03192f8 | 2009-07-03 10:16:22 +0200 | [diff] [blame] | 599 | handle_arch_sysret(Event *event) { |
| 600 | debug(DEBUG_FUNCTION, "handle_arch_sysret(pid=%d, sysnum=%d)", event->proc->pid, event->e_un.sysnum); |
| Juan Cespedes | 5c68204 | 2009-05-21 15:59:56 +0200 | [diff] [blame] | 601 | if (event->proc->state != STATE_IGNORED) { |
| 602 | if (opt_T || options.summary) { |
| 603 | calc_time_spent(event->proc); |
| 604 | } |
| Petr Machata | 29add4f | 2012-02-18 16:38:05 +0100 | [diff] [blame] | 605 | if (options.syscalls) |
| 606 | output_syscall_right(event->proc, |
| 607 | arch_sysname(event->proc, |
| 608 | event->e_un.sysnum)); |
| Petr Machata | 211f088 | 2010-11-03 18:42:18 +0100 | [diff] [blame] | 609 | callstack_pop(event->proc); |
| Juan Cespedes | 63184be | 2008-12-10 13:30:12 +0100 | [diff] [blame] | 610 | } |
| 611 | continue_process(event->proc->pid); |
| 612 | } |
| 613 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 614 | static void |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 615 | output_right_tos(struct process *proc) |
| Petr Machata | 1429874 | 2012-04-12 23:09:21 +0200 | [diff] [blame] | 616 | { |
| 617 | size_t d = proc->callstack_depth; |
| 618 | struct callstack_element *elem = &proc->callstack[d - 1]; |
| 619 | if (proc->state != STATE_IGNORED) |
| Petr Machata | 9e1e969 | 2012-04-19 02:29:38 +0200 | [diff] [blame] | 620 | output_right(LT_TOF_FUNCTIONR, proc, elem->c_un.libfunc); |
| Petr Machata | 1429874 | 2012-04-12 23:09:21 +0200 | [diff] [blame] | 621 | } |
| 622 | |
| Edgar E. Iglesias | 3a1806d | 2012-09-27 17:02:40 +0200 | [diff] [blame] | 623 | #ifndef ARCH_HAVE_SYMBOL_RET |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 624 | void arch_symbol_ret(struct process *proc, struct library_symbol *libsym) |
| Edgar E. Iglesias | 3a1806d | 2012-09-27 17:02:40 +0200 | [diff] [blame] | 625 | { |
| 626 | } |
| 627 | #endif |
| 628 | |
| Petr Machata | 1429874 | 2012-04-12 23:09:21 +0200 | [diff] [blame] | 629 | static void |
| Petr Machata | fed1e8d | 2012-02-07 02:06:29 +0100 | [diff] [blame] | 630 | handle_breakpoint(Event *event) |
| 631 | { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 632 | int i, j; |
| Petr Machata | bc37326 | 2012-02-07 23:31:15 +0100 | [diff] [blame] | 633 | struct breakpoint *sbp; |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 634 | struct process *leader = event->proc->leader; |
| Petr Machata | 31b2f9f | 2012-04-12 22:23:40 +0200 | [diff] [blame] | 635 | void *brk_addr = event->e_un.brk_addr; |
| Petr Machata | 9a5420c | 2011-07-09 11:21:23 +0200 | [diff] [blame] | 636 | |
| 637 | /* The leader has terminated. */ |
| 638 | if (leader == NULL) { |
| 639 | continue_process(event->proc->pid); |
| 640 | return; |
| 641 | } |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 642 | |
| Petr Machata | 31b2f9f | 2012-04-12 22:23:40 +0200 | [diff] [blame] | 643 | debug(DEBUG_FUNCTION, "handle_breakpoint(pid=%d, addr=%p)", |
| 644 | event->proc->pid, brk_addr); |
| 645 | debug(2, "event: breakpoint (%p)", brk_addr); |
| Luis Machado | 55c5feb | 2008-03-12 15:56:01 +0100 | [diff] [blame] | 646 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 647 | for (i = event->proc->callstack_depth - 1; i >= 0; i--) { |
| Petr Machata | 31b2f9f | 2012-04-12 22:23:40 +0200 | [diff] [blame] | 648 | if (brk_addr == event->proc->callstack[i].return_addr) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 649 | for (j = event->proc->callstack_depth - 1; j > i; j--) { |
| Juan Cespedes | 5916fda | 2002-02-25 00:19:21 +0100 | [diff] [blame] | 650 | callstack_pop(event->proc); |
| 651 | } |
| Juan Cespedes | 5c68204 | 2009-05-21 15:59:56 +0200 | [diff] [blame] | 652 | if (event->proc->state != STATE_IGNORED) { |
| 653 | if (opt_T || options.summary) { |
| 654 | calc_time_spent(event->proc); |
| 655 | } |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 656 | } |
| Petr Machata | 31b2f9f | 2012-04-12 22:23:40 +0200 | [diff] [blame] | 657 | |
| Petr Machata | 9e1e969 | 2012-04-19 02:29:38 +0200 | [diff] [blame] | 658 | struct library_symbol *libsym = |
| 659 | event->proc->callstack[i].c_un.libfunc; |
| 660 | |
| Edgar E. Iglesias | 3a1806d | 2012-09-27 17:02:40 +0200 | [diff] [blame] | 661 | arch_symbol_ret(event->proc, libsym); |
| Petr Machata | 1429874 | 2012-04-12 23:09:21 +0200 | [diff] [blame] | 662 | output_right_tos(event->proc); |
| 663 | callstack_pop(event->proc); |
| 664 | |
| Petr Machata | 31b2f9f | 2012-04-12 22:23:40 +0200 | [diff] [blame] | 665 | /* Pop also any other entries that seem like |
| 666 | * they are linked to the current one: they |
| 667 | * have the same return address, but were made |
| 668 | * for different symbols. This should only |
| 669 | * happen for entry point tracing, i.e. for -x |
| Edgar E. Iglesias | 3a1806d | 2012-09-27 17:02:40 +0200 | [diff] [blame] | 670 | * everywhere, or -x and -e on MIPS. */ |
| Petr Machata | 31b2f9f | 2012-04-12 22:23:40 +0200 | [diff] [blame] | 671 | while (event->proc->callstack_depth > 0) { |
| 672 | struct callstack_element *prev; |
| 673 | size_t d = event->proc->callstack_depth; |
| 674 | prev = &event->proc->callstack[d - 1]; |
| 675 | |
| Petr Machata | 1429874 | 2012-04-12 23:09:21 +0200 | [diff] [blame] | 676 | if (prev->c_un.libfunc == libsym |
| 677 | || prev->return_addr != brk_addr) |
| Petr Machata | 31b2f9f | 2012-04-12 22:23:40 +0200 | [diff] [blame] | 678 | break; |
| Petr Machata | 1429874 | 2012-04-12 23:09:21 +0200 | [diff] [blame] | 679 | |
| Edgar E. Iglesias | 3a1806d | 2012-09-27 17:02:40 +0200 | [diff] [blame] | 680 | arch_symbol_ret(event->proc, |
| 681 | prev->c_un.libfunc); |
| Petr Machata | 1429874 | 2012-04-12 23:09:21 +0200 | [diff] [blame] | 682 | output_right_tos(event->proc); |
| 683 | callstack_pop(event->proc); |
| Juan Cespedes | 5c68204 | 2009-05-21 15:59:56 +0200 | [diff] [blame] | 684 | } |
| Petr Machata | 31b2f9f | 2012-04-12 22:23:40 +0200 | [diff] [blame] | 685 | |
| Petr Machata | 5ee3682 | 2012-04-19 17:01:51 +0200 | [diff] [blame] | 686 | /* Maybe the previous callstack_pop's got rid |
| 687 | * of the breakpoint, but if we are in a |
| 688 | * recursive call, it's still enabled. In |
| 689 | * that case we need to skip it properly. */ |
| Petr Machata | c0649d8 | 2012-04-20 02:39:33 +0200 | [diff] [blame] | 690 | if ((sbp = address2bpstruct(leader, brk_addr)) != NULL) { |
| Petr Machata | 5ee3682 | 2012-04-19 17:01:51 +0200 | [diff] [blame] | 691 | continue_after_breakpoint(event->proc, sbp); |
| Petr Machata | c0649d8 | 2012-04-20 02:39:33 +0200 | [diff] [blame] | 692 | } else { |
| 693 | set_instruction_pointer(event->proc, brk_addr); |
| Petr Machata | 5ee3682 | 2012-04-19 17:01:51 +0200 | [diff] [blame] | 694 | continue_process(event->proc->pid); |
| Petr Machata | c0649d8 | 2012-04-20 02:39:33 +0200 | [diff] [blame] | 695 | } |
| Juan Cespedes | 5916fda | 2002-02-25 00:19:21 +0100 | [diff] [blame] | 696 | return; |
| 697 | } |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 698 | } |
| 699 | |
| Petr Machata | 5ee3682 | 2012-04-19 17:01:51 +0200 | [diff] [blame] | 700 | if ((sbp = address2bpstruct(leader, brk_addr)) != NULL) |
| Petr Machata | a9fd8f4 | 2012-02-07 13:25:56 +0100 | [diff] [blame] | 701 | breakpoint_on_hit(sbp, event->proc); |
| Petr Machata | 5ee3682 | 2012-04-19 17:01:51 +0200 | [diff] [blame] | 702 | else if (event->proc->state != STATE_IGNORED) |
| 703 | output_line(event->proc, |
| 704 | "unexpected breakpoint at %p", brk_addr); |
| Petr Machata | bc37326 | 2012-02-07 23:31:15 +0100 | [diff] [blame] | 705 | |
| Petr Machata | 5ee3682 | 2012-04-19 17:01:51 +0200 | [diff] [blame] | 706 | /* breakpoint_on_hit may delete its own breakpoint, so we have |
| 707 | * to look it up again. */ |
| 708 | if ((sbp = address2bpstruct(leader, brk_addr)) != NULL) { |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 709 | if (event->proc->state != STATE_IGNORED |
| 710 | && sbp->libsym != NULL) { |
| Juan Cespedes | 5c68204 | 2009-05-21 15:59:56 +0200 | [diff] [blame] | 711 | event->proc->stack_pointer = get_stack_pointer(event->proc); |
| Juan Cespedes | 5c68204 | 2009-05-21 15:59:56 +0200 | [diff] [blame] | 712 | callstack_push_symfunc(event->proc, sbp->libsym); |
| Petr Machata | 29add4f | 2012-02-18 16:38:05 +0100 | [diff] [blame] | 713 | output_left(LT_TOF_FUNCTION, event->proc, sbp->libsym); |
| Juan Cespedes | 5c68204 | 2009-05-21 15:59:56 +0200 | [diff] [blame] | 714 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 715 | |
| Petr Machata | 56a9ea6 | 2012-03-27 03:09:29 +0200 | [diff] [blame] | 716 | breakpoint_on_continue(sbp, event->proc); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 717 | return; |
| Petr Machata | c0649d8 | 2012-04-20 02:39:33 +0200 | [diff] [blame] | 718 | } else { |
| 719 | set_instruction_pointer(event->proc, brk_addr); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 720 | } |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 721 | |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 722 | continue_process(event->proc->pid); |
| 723 | } |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 724 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 725 | static void |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 726 | callstack_push_syscall(struct process *proc, int sysnum) |
| 727 | { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 728 | struct callstack_element *elem; |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 729 | |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 730 | debug(DEBUG_FUNCTION, "callstack_push_syscall(pid=%d, sysnum=%d)", proc->pid, sysnum); |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 731 | /* FIXME: not good -- should use dynamic allocation. 19990703 mortene. */ |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 732 | if (proc->callstack_depth == MAX_CALLDEPTH - 1) { |
| Arnaud Patard | 91a1f32 | 2010-01-08 08:40:13 -0500 | [diff] [blame] | 733 | fprintf(stderr, "%s: Error: call nesting too deep!\n", __func__); |
| 734 | abort(); |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 735 | return; |
| 736 | } |
| 737 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 738 | elem = &proc->callstack[proc->callstack_depth]; |
| Petr Machata | 8ae3673 | 2012-04-30 01:19:09 +0200 | [diff] [blame] | 739 | *elem = (struct callstack_element){}; |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 740 | elem->is_syscall = 1; |
| 741 | elem->c_un.syscall = sysnum; |
| 742 | elem->return_addr = NULL; |
| 743 | |
| 744 | proc->callstack_depth++; |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 745 | if (opt_T || options.summary) { |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 746 | struct timezone tz; |
| 747 | gettimeofday(&elem->time_spent, &tz); |
| 748 | } |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 749 | } |
| 750 | |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 751 | static void |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 752 | callstack_push_symfunc(struct process *proc, struct library_symbol *sym) |
| 753 | { |
| Petr Machata | 1429874 | 2012-04-12 23:09:21 +0200 | [diff] [blame] | 754 | struct callstack_element *elem; |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 755 | |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 756 | debug(DEBUG_FUNCTION, "callstack_push_symfunc(pid=%d, symbol=%s)", proc->pid, sym->name); |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 757 | /* FIXME: not good -- should use dynamic allocation. 19990703 mortene. */ |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 758 | if (proc->callstack_depth == MAX_CALLDEPTH - 1) { |
| Arnaud Patard | 91a1f32 | 2010-01-08 08:40:13 -0500 | [diff] [blame] | 759 | fprintf(stderr, "%s: Error: call nesting too deep!\n", __func__); |
| 760 | abort(); |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 761 | return; |
| 762 | } |
| 763 | |
| Petr Machata | 1429874 | 2012-04-12 23:09:21 +0200 | [diff] [blame] | 764 | elem = &proc->callstack[proc->callstack_depth++]; |
| Petr Machata | 8ae3673 | 2012-04-30 01:19:09 +0200 | [diff] [blame] | 765 | *elem = (struct callstack_element){}; |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 766 | elem->is_syscall = 0; |
| 767 | elem->c_un.libfunc = sym; |
| 768 | |
| Petr Machata | f9d93c5 | 2013-01-30 23:09:02 +0100 | [diff] [blame] | 769 | arch_addr_t return_addr = get_return_addr(proc, proc->stack_pointer); |
| 770 | struct breakpoint *rbp = NULL; |
| 771 | if (return_addr != 0) |
| Petr Machata | 02a796e | 2013-10-11 17:24:30 +0200 | [diff] [blame] | 772 | rbp = insert_breakpoint_at(proc, return_addr, NULL); |
| Petr Machata | f9d93c5 | 2013-01-30 23:09:02 +0100 | [diff] [blame] | 773 | elem->return_addr = rbp != NULL ? rbp->addr : 0; |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 774 | |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 775 | if (opt_T || options.summary) { |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 776 | struct timezone tz; |
| 777 | gettimeofday(&elem->time_spent, &tz); |
| 778 | } |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 779 | } |
| 780 | |
| Petr Machata | e655ccf | 2012-10-26 22:21:59 +0200 | [diff] [blame] | 781 | void |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 782 | callstack_pop(struct process *proc) |
| Petr Machata | e655ccf | 2012-10-26 22:21:59 +0200 | [diff] [blame] | 783 | { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 784 | struct callstack_element *elem; |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 785 | assert(proc->callstack_depth > 0); |
| 786 | |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 787 | debug(DEBUG_FUNCTION, "callstack_pop(pid=%d)", proc->pid); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 788 | elem = &proc->callstack[proc->callstack_depth - 1]; |
| Petr Machata | e655ccf | 2012-10-26 22:21:59 +0200 | [diff] [blame] | 789 | if (!elem->is_syscall && elem->return_addr) |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 790 | delete_breakpoint(proc, elem->return_addr); |
| Petr Machata | e655ccf | 2012-10-26 22:21:59 +0200 | [diff] [blame] | 791 | |
| 792 | if (elem->fetch_context != NULL) |
| 793 | fetch_arg_done(elem->fetch_context); |
| 794 | |
| 795 | if (elem->arguments != NULL) { |
| 796 | val_dict_destroy(elem->arguments); |
| 797 | free(elem->arguments); |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 798 | } |
| Petr Machata | e655ccf | 2012-10-26 22:21:59 +0200 | [diff] [blame] | 799 | |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 800 | proc->callstack_depth--; |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 801 | } |