blob: db68034d78e9c760918f121a0774d1e452241d91 [file] [log] [blame]
Petr Machata94078ec2012-01-05 18:07:02 +01001/*
2 * This file is part of ltrace.
Petr Machata057caa52013-01-30 23:28:47 +01003 * Copyright (C) 2011,2012,2013 Petr Machata, Red Hat Inc.
Petr Machata94078ec2012-01-05 18:07:02 +01004 * 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 Cespedesd44c6b81998-09-25 14:48:42 +020026#include "config.h"
Juan Cespedesd44c6b81998-09-25 14:48:42 +020027
Petr Machata94078ec2012-01-05 18:07:02 +010028#define _GNU_SOURCE
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +020029#include <assert.h>
Petr Machata534e00f2011-09-27 17:58:38 +020030#include <errno.h>
Petr Machata3d0c91c2012-04-14 02:37:38 +020031#include <signal.h>
32#include <stdio.h>
33#include <stdlib.h>
34#include <string.h>
35#include <sys/time.h>
Juan Cespedes5e01f651998-03-08 22:31:44 +010036
Petr Machata64262602012-01-07 03:41:36 +010037#include "backend.h"
Petr Machata9294d822012-02-07 12:35:58 +010038#include "breakpoint.h"
Petr Machataba1664b2012-04-28 14:59:05 +020039#include "common.h"
40#include "fetch.h"
Petr Machata2b46cfc2012-02-18 11:17:29 +010041#include "library.h"
Petr Machata3d0c91c2012-04-14 02:37:38 +020042#include "proc.h"
Petr Machata64262602012-01-07 03:41:36 +010043#include "value_dict.h"
Petr Machatafed1e8d2012-02-07 02:06:29 +010044
Juan Cespedes03192f82009-07-03 10:16:22 +020045static void handle_signal(Event *event);
46static void handle_exit(Event *event);
47static void handle_exit_signal(Event *event);
48static void handle_syscall(Event *event);
49static void handle_arch_syscall(Event *event);
50static void handle_sysret(Event *event);
51static void handle_arch_sysret(Event *event);
52static void handle_clone(Event *event);
53static void handle_exec(Event *event);
54static void handle_breakpoint(Event *event);
55static void handle_new(Event *event);
Juan Cespedes5e01f651998-03-08 22:31:44 +010056
Petr Machata929bd572012-12-17 03:20:34 +010057static void callstack_push_syscall(struct process *proc, int sysnum);
58static void callstack_push_symfunc(struct process *proc,
Ian Wienand2d45b1a2006-02-20 22:48:07 +010059 struct library_symbol *sym);
Petr Machatae655ccf2012-10-26 22:21:59 +020060/* XXX Stack maintenance should be moved to a dedicated module, or to
61 * proc.c, and push/pop should be visible outside this module. For
62 * now, because we need this in proc.c, this is non-static. */
Petr Machata929bd572012-12-17 03:20:34 +010063void callstack_pop(struct process *proc);
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +020064
Petr Machata929bd572012-12-17 03:20:34 +010065static char *shortsignal(struct process *proc, int signum);
66static char *sysname(struct process *proc, int sysnum);
67static char *arch_sysname(struct process *proc, int sysnum);
Juan Cespedes61da3372009-07-03 11:55:44 +020068
Petr Machatacbe29c62011-09-27 02:27:58 +020069static Event *
Petr Machata929bd572012-12-17 03:20:34 +010070call_handler(struct process *proc, Event *event)
Petr Machatacbe29c62011-09-27 02:27:58 +020071{
72 assert(proc != NULL);
73
Petr Machata366c2f42012-02-09 19:34:36 +010074 struct event_handler *handler = proc->event_handler;
Petr Machatacbe29c62011-09-27 02:27:58 +020075 if (handler == NULL)
76 return event;
77
78 return (*handler->on_event) (handler, event);
79}
80
Juan Cespedes61da3372009-07-03 11:55:44 +020081void
Petr Machataffe4cd22012-04-11 18:01:44 +020082handle_event(Event *event)
83{
Petr Machata602330f2011-07-09 11:15:34 +020084 if (exiting == 1) {
Petr Machata602330f2011-07-09 11:15:34 +020085 debug(1, "ltrace about to exit");
Petr Machataffe4cd22012-04-11 18:01:44 +020086 os_ltrace_exiting();
87 exiting = 2;
Petr Machata602330f2011-07-09 11:15:34 +020088 }
Petr Machata26627682011-07-08 18:15:32 +020089 debug(DEBUG_FUNCTION, "handle_event(pid=%d, type=%d)",
90 event->proc ? event->proc->pid : -1, event->type);
Petr Machatacbe29c62011-09-27 02:27:58 +020091
92 /* If the thread group or an individual task define an
93 overriding event handler, give them a chance to kick in.
94 We will end up calling both handlers, if the first one
95 doesn't sink the event. */
96 if (event->proc != NULL) {
97 event = call_handler(event->proc, event);
98 if (event == NULL)
99 /* It was handled. */
100 return;
101
102 /* Note: the previous handler has a chance to alter
103 * the event. */
Petr Machata43d2fe52011-11-02 13:25:49 +0100104 if (event->proc != NULL
105 && event->proc->leader != NULL
106 && event->proc != event->proc->leader) {
Petr Machatacbe29c62011-09-27 02:27:58 +0200107 event = call_handler(event->proc->leader, event);
Petr Machata4007d742011-07-09 11:29:42 +0200108 if (event == NULL)
Petr Machata4007d742011-07-09 11:29:42 +0200109 return;
110 }
111 }
112
Juan Cespedes61da3372009-07-03 11:55:44 +0200113 switch (event->type) {
114 case EVENT_NONE:
115 debug(1, "event: none");
116 return;
Petr Machata9978de42013-01-08 23:46:22 +0100117
Juan Cespedes61da3372009-07-03 11:55:44 +0200118 case EVENT_SIGNAL:
Petr Machata9978de42013-01-08 23:46:22 +0100119 assert(event->proc != NULL);
Petr Machataebfe7d62012-04-13 21:34:49 +0200120 debug(1, "[%d] event: signal (%s [%d])",
121 event->proc->pid,
Juan Cespedes61da3372009-07-03 11:55:44 +0200122 shortsignal(event->proc, event->e_un.signum),
123 event->e_un.signum);
124 handle_signal(event);
125 return;
Petr Machata9978de42013-01-08 23:46:22 +0100126
Juan Cespedes61da3372009-07-03 11:55:44 +0200127 case EVENT_EXIT:
Petr Machata9978de42013-01-08 23:46:22 +0100128 assert(event->proc != NULL);
Petr Machataebfe7d62012-04-13 21:34:49 +0200129 debug(1, "[%d] event: exit (%d)",
130 event->proc->pid,
131 event->e_un.ret_val);
Juan Cespedes61da3372009-07-03 11:55:44 +0200132 handle_exit(event);
133 return;
Petr Machata9978de42013-01-08 23:46:22 +0100134
Juan Cespedes61da3372009-07-03 11:55:44 +0200135 case EVENT_EXIT_SIGNAL:
Petr Machata9978de42013-01-08 23:46:22 +0100136 assert(event->proc != NULL);
Petr Machataebfe7d62012-04-13 21:34:49 +0200137 debug(1, "[%d] event: exit signal (%s [%d])",
138 event->proc->pid,
Juan Cespedes61da3372009-07-03 11:55:44 +0200139 shortsignal(event->proc, event->e_un.signum),
140 event->e_un.signum);
141 handle_exit_signal(event);
142 return;
Petr Machata9978de42013-01-08 23:46:22 +0100143
Juan Cespedes61da3372009-07-03 11:55:44 +0200144 case EVENT_SYSCALL:
Petr Machata9978de42013-01-08 23:46:22 +0100145 assert(event->proc != NULL);
Petr Machataebfe7d62012-04-13 21:34:49 +0200146 debug(1, "[%d] event: syscall (%s [%d])",
147 event->proc->pid,
Juan Cespedes61da3372009-07-03 11:55:44 +0200148 sysname(event->proc, event->e_un.sysnum),
149 event->e_un.sysnum);
150 handle_syscall(event);
151 return;
Petr Machata9978de42013-01-08 23:46:22 +0100152
Juan Cespedes61da3372009-07-03 11:55:44 +0200153 case EVENT_SYSRET:
Petr Machata9978de42013-01-08 23:46:22 +0100154 assert(event->proc != NULL);
Petr Machataebfe7d62012-04-13 21:34:49 +0200155 debug(1, "[%d] event: sysret (%s [%d])",
156 event->proc->pid,
Juan Cespedes61da3372009-07-03 11:55:44 +0200157 sysname(event->proc, event->e_un.sysnum),
158 event->e_un.sysnum);
159 handle_sysret(event);
160 return;
Petr Machata9978de42013-01-08 23:46:22 +0100161
Juan Cespedes61da3372009-07-03 11:55:44 +0200162 case EVENT_ARCH_SYSCALL:
Petr Machata9978de42013-01-08 23:46:22 +0100163 assert(event->proc != NULL);
Petr Machataebfe7d62012-04-13 21:34:49 +0200164 debug(1, "[%d] event: arch_syscall (%s [%d])",
165 event->proc->pid,
166 arch_sysname(event->proc, event->e_un.sysnum),
167 event->e_un.sysnum);
Juan Cespedes61da3372009-07-03 11:55:44 +0200168 handle_arch_syscall(event);
169 return;
Petr Machata9978de42013-01-08 23:46:22 +0100170
Juan Cespedes61da3372009-07-03 11:55:44 +0200171 case EVENT_ARCH_SYSRET:
Petr Machata9978de42013-01-08 23:46:22 +0100172 assert(event->proc != NULL);
Petr Machataebfe7d62012-04-13 21:34:49 +0200173 debug(1, "[%d] event: arch_sysret (%s [%d])",
174 event->proc->pid,
175 arch_sysname(event->proc, event->e_un.sysnum),
176 event->e_un.sysnum);
Juan Cespedes61da3372009-07-03 11:55:44 +0200177 handle_arch_sysret(event);
178 return;
Petr Machata9978de42013-01-08 23:46:22 +0100179
Juan Cespedes61da3372009-07-03 11:55:44 +0200180 case EVENT_CLONE:
Petr Machatacbe29c62011-09-27 02:27:58 +0200181 case EVENT_VFORK:
Petr Machata9978de42013-01-08 23:46:22 +0100182 assert(event->proc != NULL);
Petr Machataebfe7d62012-04-13 21:34:49 +0200183 debug(1, "[%d] event: clone (%u)",
184 event->proc->pid, event->e_un.newpid);
Juan Cespedes61da3372009-07-03 11:55:44 +0200185 handle_clone(event);
186 return;
Petr Machata9978de42013-01-08 23:46:22 +0100187
Juan Cespedes61da3372009-07-03 11:55:44 +0200188 case EVENT_EXEC:
Petr Machata9978de42013-01-08 23:46:22 +0100189 assert(event->proc != NULL);
Petr Machataebfe7d62012-04-13 21:34:49 +0200190 debug(1, "[%d] event: exec()",
191 event->proc->pid);
Juan Cespedes61da3372009-07-03 11:55:44 +0200192 handle_exec(event);
193 return;
Petr Machata9978de42013-01-08 23:46:22 +0100194
Juan Cespedes61da3372009-07-03 11:55:44 +0200195 case EVENT_BREAKPOINT:
Petr Machata9978de42013-01-08 23:46:22 +0100196 assert(event->proc != NULL);
Petr Machataebfe7d62012-04-13 21:34:49 +0200197 debug(1, "[%d] event: breakpoint %p",
198 event->proc->pid, event->e_un.brk_addr);
Juan Cespedes61da3372009-07-03 11:55:44 +0200199 handle_breakpoint(event);
200 return;
Petr Machata9978de42013-01-08 23:46:22 +0100201
Juan Cespedes61da3372009-07-03 11:55:44 +0200202 case EVENT_NEW:
Petr Machataebfe7d62012-04-13 21:34:49 +0200203 debug(1, "[%d] event: new process",
204 event->e_un.newpid);
Juan Cespedes61da3372009-07-03 11:55:44 +0200205 handle_new(event);
206 return;
207 default:
208 fprintf(stderr, "Error! unknown event?\n");
209 exit(1);
210 }
211}
212
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200213typedef struct Pending_New Pending_New;
214struct Pending_New {
215 pid_t pid;
216 Pending_New * next;
217};
218static Pending_New * pending_news = NULL;
219
220static int
221pending_new(pid_t pid) {
Juan Cespedescd8976d2009-05-14 13:47:58 +0200222 Pending_New * p;
223
224 debug(DEBUG_FUNCTION, "pending_new(%d)", pid);
225
226 p = pending_news;
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200227 while (p) {
228 if (p->pid == pid) {
229 return 1;
230 }
231 p = p->next;
232 }
233 return 0;
234}
235
236static void
237pending_new_insert(pid_t pid) {
Juan Cespedescd8976d2009-05-14 13:47:58 +0200238 Pending_New * p;
239
240 debug(DEBUG_FUNCTION, "pending_new_insert(%d)", pid);
241
242 p = malloc(sizeof(Pending_New));
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200243 if (!p) {
244 perror("malloc()");
245 exit(1);
246 }
247 p->pid = pid;
248 p->next = pending_news;
249 pending_news = p;
250}
251
252static void
253pending_new_remove(pid_t pid) {
254 Pending_New *p, *pred;
255
Juan Cespedescd8976d2009-05-14 13:47:58 +0200256 debug(DEBUG_FUNCTION, "pending_new_remove(%d)", pid);
257
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200258 p = pending_news;
Sedat Dilek7d804e92012-09-01 02:30:52 +0200259 pred = NULL;
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200260 if (p->pid == pid) {
261 pending_news = p->next;
262 free(p);
263 } else {
264 while (p) {
265 if (p->pid == pid) {
266 pred->next = p->next;
267 free(p);
268 }
269 pred = p;
270 p = p->next;
271 }
272 }
273}
274
275static void
Petr Machata2b46cfc2012-02-18 11:17:29 +0100276handle_clone(Event *event)
277{
Juan Cespedes03192f82009-07-03 10:16:22 +0200278 debug(DEBUG_FUNCTION, "handle_clone(pid=%d)", event->proc->pid);
Juan Cespedescd8976d2009-05-14 13:47:58 +0200279
Petr Machata929bd572012-12-17 03:20:34 +0100280 struct process *proc = malloc(sizeof(*proc));
Petr Machata6095c132013-01-07 19:08:18 +0100281 pid_t newpid = event->e_un.newpid;
282 if (proc == NULL
283 || process_clone(proc, event->proc, newpid) < 0) {
Petr Machata2b46cfc2012-02-18 11:17:29 +0100284 free(proc);
Petr Machata6095c132013-01-07 19:08:18 +0100285 proc = NULL;
Petr Machata94078ec2012-01-05 18:07:02 +0100286 fprintf(stderr,
Petr Machata6095c132013-01-07 19:08:18 +0100287 "Couldn't initialize tracing of process %d.\n",
288 newpid);
289
290 } else {
291 proc->parent = event->proc;
292 /* We save register values to the arch pointer, and
293 * these need to be per-thread. XXX arch_ptr should
294 * be retired in favor of fetch interface anyway. */
295 proc->arch_ptr = NULL;
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200296 }
Petr Machata2b46cfc2012-02-18 11:17:29 +0100297
Petr Machata6095c132013-01-07 19:08:18 +0100298 if (pending_new(newpid)) {
299 pending_new_remove(newpid);
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200300
Petr Machata6095c132013-01-07 19:08:18 +0100301 if (proc != NULL) {
302 proc->event_handler = NULL;
303 if (event->proc->state == STATE_ATTACHED
304 && options.follow)
305 proc->state = STATE_ATTACHED;
306 else
307 proc->state = STATE_IGNORED;
308 }
Petr Machata75dcf7d2011-10-06 14:30:19 +0200309
Petr Machata6095c132013-01-07 19:08:18 +0100310 continue_process(newpid);
311
312 } else if (proc != NULL) {
Petr Machata2b46cfc2012-02-18 11:17:29 +0100313 proc->state = STATE_BEING_CREATED;
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200314 }
Petr Machata534e00f2011-09-27 17:58:38 +0200315
Petr Machata6095c132013-01-07 19:08:18 +0100316 if (event->type != EVENT_VFORK)
317 continue_process(event->proc->pid);
318 else if (proc != NULL)
Petr Machata2b46cfc2012-02-18 11:17:29 +0100319 continue_after_vfork(proc);
Petr Machatacbe29c62011-09-27 02:27:58 +0200320 else
Petr Machata6095c132013-01-07 19:08:18 +0100321 continue_process(newpid);
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200322}
323
324static void
Petr Machata929bd572012-12-17 03:20:34 +0100325handle_new(Event *event)
326{
Juan Cespedes03192f82009-07-03 10:16:22 +0200327 debug(DEBUG_FUNCTION, "handle_new(pid=%d)", event->e_un.newpid);
Juan Cespedescd8976d2009-05-14 13:47:58 +0200328
Petr Machata929bd572012-12-17 03:20:34 +0100329 struct process *proc = pid2proc(event->e_un.newpid);
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200330 if (!proc) {
331 pending_new_insert(event->e_un.newpid);
332 } else {
333 assert(proc->state == STATE_BEING_CREATED);
Juan Cespedes30439b42009-05-22 19:03:09 +0200334 if (options.follow) {
Juan Cespedes5c682042009-05-21 15:59:56 +0200335 proc->state = STATE_ATTACHED;
336 } else {
337 proc->state = STATE_IGNORED;
338 }
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200339 continue_process(proc->pid);
340 }
341}
342
Juan Cespedesf1350522008-12-16 18:19:58 +0100343static char *
Petr Machata929bd572012-12-17 03:20:34 +0100344shortsignal(struct process *proc, int signum)
345{
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100346 static char *signalent0[] = {
347#include "signalent.h"
Juan Cespedes5e01f651998-03-08 22:31:44 +0100348 };
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100349 static char *signalent1[] = {
350#include "signalent1.h"
Ian Wienand9a2ad352006-02-20 22:44:45 +0100351 };
352 static char **signalents[] = { signalent0, signalent1 };
353 int nsignals[] = { sizeof signalent0 / sizeof signalent0[0],
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100354 sizeof signalent1 / sizeof signalent1[0]
355 };
Juan Cespedes5e01f651998-03-08 22:31:44 +0100356
Juan Cespedescd8976d2009-05-14 13:47:58 +0200357 debug(DEBUG_FUNCTION, "shortsignal(pid=%d, signum=%d)", proc->pid, signum);
358
Ian Wienand9a2ad352006-02-20 22:44:45 +0100359 if (proc->personality > sizeof signalents / sizeof signalents[0])
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100360 abort();
Ian Wienand9a2ad352006-02-20 22:44:45 +0100361 if (signum < 0 || signum >= nsignals[proc->personality]) {
Juan Cespedes5e01f651998-03-08 22:31:44 +0100362 return "UNKNOWN_SIGNAL";
363 } else {
Ian Wienand9a2ad352006-02-20 22:44:45 +0100364 return signalents[proc->personality][signum];
Juan Cespedes5e01f651998-03-08 22:31:44 +0100365 }
366}
367
Juan Cespedesf1350522008-12-16 18:19:58 +0100368static char *
Petr Machata929bd572012-12-17 03:20:34 +0100369sysname(struct process *proc, int sysnum)
370{
Juan Cespedes5e01f651998-03-08 22:31:44 +0100371 static char result[128];
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100372 static char *syscalent0[] = {
373#include "syscallent.h"
Juan Cespedes5e01f651998-03-08 22:31:44 +0100374 };
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100375 static char *syscalent1[] = {
376#include "syscallent1.h"
Ian Wienand9a2ad352006-02-20 22:44:45 +0100377 };
378 static char **syscalents[] = { syscalent0, syscalent1 };
379 int nsyscals[] = { sizeof syscalent0 / sizeof syscalent0[0],
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100380 sizeof syscalent1 / sizeof syscalent1[0]
381 };
Juan Cespedes5e01f651998-03-08 22:31:44 +0100382
Juan Cespedescd8976d2009-05-14 13:47:58 +0200383 debug(DEBUG_FUNCTION, "sysname(pid=%d, sysnum=%d)", proc->pid, sysnum);
384
Ian Wienand9a2ad352006-02-20 22:44:45 +0100385 if (proc->personality > sizeof syscalents / sizeof syscalents[0])
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100386 abort();
Ian Wienand9a2ad352006-02-20 22:44:45 +0100387 if (sysnum < 0 || sysnum >= nsyscals[proc->personality]) {
Juan Cespedes5e01f651998-03-08 22:31:44 +0100388 sprintf(result, "SYS_%d", sysnum);
389 return result;
390 } else {
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100391 sprintf(result, "SYS_%s",
392 syscalents[proc->personality][sysnum]);
Juan Cespedes5e01f651998-03-08 22:31:44 +0100393 return result;
394 }
395}
396
Juan Cespedesf1350522008-12-16 18:19:58 +0100397static char *
Petr Machata929bd572012-12-17 03:20:34 +0100398arch_sysname(struct process *proc, int sysnum)
399{
Juan Cespedes63184be2008-12-10 13:30:12 +0100400 static char result[128];
401 static char *arch_syscalent[] = {
402#include "arch_syscallent.h"
403 };
404 int nsyscals = sizeof arch_syscalent / sizeof arch_syscalent[0];
405
Juan Cespedescd8976d2009-05-14 13:47:58 +0200406 debug(DEBUG_FUNCTION, "arch_sysname(pid=%d, sysnum=%d)", proc->pid, sysnum);
407
Juan Cespedes63184be2008-12-10 13:30:12 +0100408 if (sysnum < 0 || sysnum >= nsyscals) {
409 sprintf(result, "ARCH_%d", sysnum);
410 return result;
411 } else {
412 sprintf(result, "ARCH_%s",
413 arch_syscalent[sysnum]);
414 return result;
415 }
416}
417
Petr Machata7c4d3112012-12-09 11:55:03 +0100418#ifndef HAVE_STRSIGNAL
419# define strsignal(SIGNUM) "???"
420#endif
421
Juan Cespedesf1350522008-12-16 18:19:58 +0100422static void
Juan Cespedes03192f82009-07-03 10:16:22 +0200423handle_signal(Event *event) {
424 debug(DEBUG_FUNCTION, "handle_signal(pid=%d, signum=%d)", event->proc->pid, event->e_un.signum);
Joe Damato59e3fb12009-11-06 19:45:10 -0800425 if (event->proc->state != STATE_IGNORED && !options.no_signals) {
Juan Cespedes5c682042009-05-21 15:59:56 +0200426 output_line(event->proc, "--- %s (%s) ---",
427 shortsignal(event->proc, event->e_un.signum),
428 strsignal(event->e_un.signum));
429 }
Juan Cespedes5e01f651998-03-08 22:31:44 +0100430 continue_after_signal(event->proc->pid, event->e_un.signum);
431}
432
Juan Cespedesf1350522008-12-16 18:19:58 +0100433static void
Juan Cespedes03192f82009-07-03 10:16:22 +0200434handle_exit(Event *event) {
435 debug(DEBUG_FUNCTION, "handle_exit(pid=%d, status=%d)", event->proc->pid, event->e_un.ret_val);
Juan Cespedes5c682042009-05-21 15:59:56 +0200436 if (event->proc->state != STATE_IGNORED) {
437 output_line(event->proc, "+++ exited (status %d) +++",
438 event->e_un.ret_val);
439 }
Petr Machatacebb8842011-07-09 11:14:11 +0200440 remove_process(event->proc);
Juan Cespedes5e01f651998-03-08 22:31:44 +0100441}
442
Juan Cespedesf1350522008-12-16 18:19:58 +0100443static void
Juan Cespedes03192f82009-07-03 10:16:22 +0200444handle_exit_signal(Event *event) {
445 debug(DEBUG_FUNCTION, "handle_exit_signal(pid=%d, signum=%d)", event->proc->pid, event->e_un.signum);
Juan Cespedes5c682042009-05-21 15:59:56 +0200446 if (event->proc->state != STATE_IGNORED) {
447 output_line(event->proc, "+++ killed by %s +++",
448 shortsignal(event->proc, event->e_un.signum));
449 }
Petr Machatacebb8842011-07-09 11:14:11 +0200450 remove_process(event->proc);
Juan Cespedes5e01f651998-03-08 22:31:44 +0100451}
452
Petr Machataa32ef7c2012-04-23 18:05:24 +0200453static void
Petr Machata929bd572012-12-17 03:20:34 +0100454output_syscall(struct process *proc, const char *name, enum tof tof,
455 void (*output)(enum tof, struct process *,
Petr Machataa32ef7c2012-04-23 18:05:24 +0200456 struct library_symbol *))
Petr Machata29add4f2012-02-18 16:38:05 +0100457{
Petr Machataa32ef7c2012-04-23 18:05:24 +0200458 struct library_symbol syscall;
459 if (library_symbol_init(&syscall, 0, name, 0, LS_TOPLT_NONE) >= 0) {
Petr Machata1e0b9dc2012-04-28 15:58:43 +0200460 (*output)(tof, proc, &syscall);
Petr Machataa32ef7c2012-04-23 18:05:24 +0200461 library_symbol_destroy(&syscall);
Petr Machata29add4f2012-02-18 16:38:05 +0100462 }
Petr Machata29add4f2012-02-18 16:38:05 +0100463}
464
465static void
Petr Machata929bd572012-12-17 03:20:34 +0100466output_syscall_left(struct process *proc, const char *name)
Petr Machata29add4f2012-02-18 16:38:05 +0100467{
Petr Machata1e0b9dc2012-04-28 15:58:43 +0200468 output_syscall(proc, name, LT_TOF_SYSCALL, &output_left);
Petr Machata29add4f2012-02-18 16:38:05 +0100469}
470
471static void
Petr Machata929bd572012-12-17 03:20:34 +0100472output_syscall_right(struct process *proc, const char *name)
Petr Machata29add4f2012-02-18 16:38:05 +0100473{
Petr Machata1e0b9dc2012-04-28 15:58:43 +0200474 output_syscall(proc, name, LT_TOF_SYSCALLR, &output_right);
Petr Machata29add4f2012-02-18 16:38:05 +0100475}
476
Juan Cespedesf1350522008-12-16 18:19:58 +0100477static void
Juan Cespedes03192f82009-07-03 10:16:22 +0200478handle_syscall(Event *event) {
479 debug(DEBUG_FUNCTION, "handle_syscall(pid=%d, sysnum=%d)", event->proc->pid, event->e_un.sysnum);
Juan Cespedes5c682042009-05-21 15:59:56 +0200480 if (event->proc->state != STATE_IGNORED) {
Petr Machata211f0882010-11-03 18:42:18 +0100481 callstack_push_syscall(event->proc, event->e_un.sysnum);
Petr Machata29add4f2012-02-18 16:38:05 +0100482 if (options.syscalls)
483 output_syscall_left(event->proc,
484 sysname(event->proc,
485 event->e_un.sysnum));
Juan Cespedes5e01f651998-03-08 22:31:44 +0100486 }
Petr Machata43d2fe52011-11-02 13:25:49 +0100487 continue_after_syscall(event->proc, event->e_un.sysnum, 0);
Juan Cespedes5e01f651998-03-08 22:31:44 +0100488}
489
Juan Cespedesf1350522008-12-16 18:19:58 +0100490static void
Petr Machata929bd572012-12-17 03:20:34 +0100491handle_exec(Event *event)
492{
493 struct process *proc = event->proc;
Juan Cespedese0660df2009-05-21 18:14:39 +0200494
Petr Machata3d0c91c2012-04-14 02:37:38 +0200495 /* Save the PID so that we can use it after unsuccessful
496 * process_exec. */
497 pid_t pid = proc->pid;
498
Juan Cespedes03192f82009-07-03 10:16:22 +0200499 debug(DEBUG_FUNCTION, "handle_exec(pid=%d)", proc->pid);
Juan Cespedese0660df2009-05-21 18:14:39 +0200500 if (proc->state == STATE_IGNORED) {
Petr Machata3d0c91c2012-04-14 02:37:38 +0200501 untrace:
502 untrace_pid(pid);
Petr Machatacebb8842011-07-09 11:14:11 +0200503 remove_process(proc);
Juan Cespedese0660df2009-05-21 18:14:39 +0200504 return;
Juan Cespedes5c682042009-05-21 15:59:56 +0200505 }
Juan Cespedese0660df2009-05-21 18:14:39 +0200506 output_line(proc, "--- Called exec() ---");
Petr Machata3d0c91c2012-04-14 02:37:38 +0200507
508 if (process_exec(proc) < 0) {
Petr Machatacc0e1e42012-04-25 13:42:07 +0200509 fprintf(stderr,
510 "couldn't reinitialize process %d after exec\n", pid);
Petr Machata3d0c91c2012-04-14 02:37:38 +0200511 goto untrace;
512 }
513
Petr Machata057caa52013-01-30 23:28:47 +0100514 continue_after_exec(proc);
Juan Cespedes1e583132009-04-07 18:17:11 +0200515}
516
517static void
Juan Cespedes03192f82009-07-03 10:16:22 +0200518handle_arch_syscall(Event *event) {
519 debug(DEBUG_FUNCTION, "handle_arch_syscall(pid=%d, sysnum=%d)", event->proc->pid, event->e_un.sysnum);
Juan Cespedes5c682042009-05-21 15:59:56 +0200520 if (event->proc->state != STATE_IGNORED) {
Petr Machata211f0882010-11-03 18:42:18 +0100521 callstack_push_syscall(event->proc, 0xf0000 + event->e_un.sysnum);
Juan Cespedes5c682042009-05-21 15:59:56 +0200522 if (options.syscalls) {
Petr Machata29add4f2012-02-18 16:38:05 +0100523 output_syscall_left(event->proc,
524 arch_sysname(event->proc,
525 event->e_un.sysnum));
Juan Cespedes5c682042009-05-21 15:59:56 +0200526 }
Juan Cespedes63184be2008-12-10 13:30:12 +0100527 }
Juan Cespedes63184be2008-12-10 13:30:12 +0100528 continue_process(event->proc->pid);
529}
530
Juan Cespedesd65efa32003-02-03 00:22:30 +0100531struct timeval current_time_spent;
532
Juan Cespedesf1350522008-12-16 18:19:58 +0100533static void
Petr Machata929bd572012-12-17 03:20:34 +0100534calc_time_spent(struct process *proc)
535{
Juan Cespedesd65efa32003-02-03 00:22:30 +0100536 struct timeval tv;
537 struct timezone tz;
538 struct timeval diff;
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100539 struct callstack_element *elem;
Juan Cespedesd65efa32003-02-03 00:22:30 +0100540
Juan Cespedescd8976d2009-05-14 13:47:58 +0200541 debug(DEBUG_FUNCTION, "calc_time_spent(pid=%d)", proc->pid);
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100542 elem = &proc->callstack[proc->callstack_depth - 1];
Juan Cespedesd65efa32003-02-03 00:22:30 +0100543
544 gettimeofday(&tv, &tz);
545
546 diff.tv_sec = tv.tv_sec - elem->time_spent.tv_sec;
547 if (tv.tv_usec >= elem->time_spent.tv_usec) {
548 diff.tv_usec = tv.tv_usec - elem->time_spent.tv_usec;
549 } else {
Paul Buerger6aa01522012-09-12 10:58:52 -0400550 diff.tv_sec--;
Juan Cespedesd65efa32003-02-03 00:22:30 +0100551 diff.tv_usec = 1000000 + tv.tv_usec - elem->time_spent.tv_usec;
552 }
553 current_time_spent = diff;
554}
555
Juan Cespedesf1350522008-12-16 18:19:58 +0100556static void
Juan Cespedes03192f82009-07-03 10:16:22 +0200557handle_sysret(Event *event) {
558 debug(DEBUG_FUNCTION, "handle_sysret(pid=%d, sysnum=%d)", event->proc->pid, event->e_un.sysnum);
Juan Cespedes5c682042009-05-21 15:59:56 +0200559 if (event->proc->state != STATE_IGNORED) {
560 if (opt_T || options.summary) {
561 calc_time_spent(event->proc);
562 }
Petr Machata29add4f2012-02-18 16:38:05 +0100563 if (options.syscalls)
564 output_syscall_right(event->proc,
565 sysname(event->proc,
566 event->e_un.sysnum));
567
Petr Machata43d2fe52011-11-02 13:25:49 +0100568 assert(event->proc->callstack_depth > 0);
569 unsigned d = event->proc->callstack_depth - 1;
570 assert(event->proc->callstack[d].is_syscall);
Petr Machata211f0882010-11-03 18:42:18 +0100571 callstack_pop(event->proc);
Juan Cespedes21c63a12001-07-07 20:56:56 +0200572 }
Petr Machata43d2fe52011-11-02 13:25:49 +0100573 continue_after_syscall(event->proc, event->e_un.sysnum, 1);
Juan Cespedes5e01f651998-03-08 22:31:44 +0100574}
575
Juan Cespedesf1350522008-12-16 18:19:58 +0100576static void
Juan Cespedes03192f82009-07-03 10:16:22 +0200577handle_arch_sysret(Event *event) {
578 debug(DEBUG_FUNCTION, "handle_arch_sysret(pid=%d, sysnum=%d)", event->proc->pid, event->e_un.sysnum);
Juan Cespedes5c682042009-05-21 15:59:56 +0200579 if (event->proc->state != STATE_IGNORED) {
580 if (opt_T || options.summary) {
581 calc_time_spent(event->proc);
582 }
Petr Machata29add4f2012-02-18 16:38:05 +0100583 if (options.syscalls)
584 output_syscall_right(event->proc,
585 arch_sysname(event->proc,
586 event->e_un.sysnum));
Petr Machata211f0882010-11-03 18:42:18 +0100587 callstack_pop(event->proc);
Juan Cespedes63184be2008-12-10 13:30:12 +0100588 }
589 continue_process(event->proc->pid);
590}
591
Juan Cespedesf1350522008-12-16 18:19:58 +0100592static void
Petr Machata929bd572012-12-17 03:20:34 +0100593output_right_tos(struct process *proc)
Petr Machata14298742012-04-12 23:09:21 +0200594{
595 size_t d = proc->callstack_depth;
596 struct callstack_element *elem = &proc->callstack[d - 1];
597 if (proc->state != STATE_IGNORED)
Petr Machata9e1e9692012-04-19 02:29:38 +0200598 output_right(LT_TOF_FUNCTIONR, proc, elem->c_un.libfunc);
Petr Machata14298742012-04-12 23:09:21 +0200599}
600
Edgar E. Iglesias3a1806d2012-09-27 17:02:40 +0200601#ifndef ARCH_HAVE_SYMBOL_RET
Petr Machata929bd572012-12-17 03:20:34 +0100602void arch_symbol_ret(struct process *proc, struct library_symbol *libsym)
Edgar E. Iglesias3a1806d2012-09-27 17:02:40 +0200603{
604}
605#endif
606
Petr Machata14298742012-04-12 23:09:21 +0200607static void
Petr Machatafed1e8d2012-02-07 02:06:29 +0100608handle_breakpoint(Event *event)
609{
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100610 int i, j;
Petr Machatabc373262012-02-07 23:31:15 +0100611 struct breakpoint *sbp;
Petr Machata929bd572012-12-17 03:20:34 +0100612 struct process *leader = event->proc->leader;
Petr Machata31b2f9f2012-04-12 22:23:40 +0200613 void *brk_addr = event->e_un.brk_addr;
Petr Machata9a5420c2011-07-09 11:21:23 +0200614
615 /* The leader has terminated. */
616 if (leader == NULL) {
617 continue_process(event->proc->pid);
618 return;
619 }
Juan Cespedes5e01f651998-03-08 22:31:44 +0100620
Petr Machata31b2f9f2012-04-12 22:23:40 +0200621 debug(DEBUG_FUNCTION, "handle_breakpoint(pid=%d, addr=%p)",
622 event->proc->pid, brk_addr);
623 debug(2, "event: breakpoint (%p)", brk_addr);
Luis Machado55c5feb2008-03-12 15:56:01 +0100624
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100625 for (i = event->proc->callstack_depth - 1; i >= 0; i--) {
Petr Machata31b2f9f2012-04-12 22:23:40 +0200626 if (brk_addr == event->proc->callstack[i].return_addr) {
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100627 for (j = event->proc->callstack_depth - 1; j > i; j--) {
Juan Cespedes5916fda2002-02-25 00:19:21 +0100628 callstack_pop(event->proc);
629 }
Juan Cespedes5c682042009-05-21 15:59:56 +0200630 if (event->proc->state != STATE_IGNORED) {
631 if (opt_T || options.summary) {
632 calc_time_spent(event->proc);
633 }
Juan Cespedesd65efa32003-02-03 00:22:30 +0100634 }
Petr Machata31b2f9f2012-04-12 22:23:40 +0200635 event->proc->return_addr = brk_addr;
636
Petr Machata9e1e9692012-04-19 02:29:38 +0200637 struct library_symbol *libsym =
638 event->proc->callstack[i].c_un.libfunc;
639
Edgar E. Iglesias3a1806d2012-09-27 17:02:40 +0200640 arch_symbol_ret(event->proc, libsym);
Petr Machata14298742012-04-12 23:09:21 +0200641 output_right_tos(event->proc);
642 callstack_pop(event->proc);
643
Petr Machata31b2f9f2012-04-12 22:23:40 +0200644 /* Pop also any other entries that seem like
645 * they are linked to the current one: they
646 * have the same return address, but were made
647 * for different symbols. This should only
648 * happen for entry point tracing, i.e. for -x
Edgar E. Iglesias3a1806d2012-09-27 17:02:40 +0200649 * everywhere, or -x and -e on MIPS. */
Petr Machata31b2f9f2012-04-12 22:23:40 +0200650 while (event->proc->callstack_depth > 0) {
651 struct callstack_element *prev;
652 size_t d = event->proc->callstack_depth;
653 prev = &event->proc->callstack[d - 1];
654
Petr Machata14298742012-04-12 23:09:21 +0200655 if (prev->c_un.libfunc == libsym
656 || prev->return_addr != brk_addr)
Petr Machata31b2f9f2012-04-12 22:23:40 +0200657 break;
Petr Machata14298742012-04-12 23:09:21 +0200658
Edgar E. Iglesias3a1806d2012-09-27 17:02:40 +0200659 arch_symbol_ret(event->proc,
660 prev->c_un.libfunc);
Petr Machata14298742012-04-12 23:09:21 +0200661 output_right_tos(event->proc);
662 callstack_pop(event->proc);
Juan Cespedes5c682042009-05-21 15:59:56 +0200663 }
Petr Machata31b2f9f2012-04-12 22:23:40 +0200664
Petr Machata5ee36822012-04-19 17:01:51 +0200665 /* Maybe the previous callstack_pop's got rid
666 * of the breakpoint, but if we are in a
667 * recursive call, it's still enabled. In
668 * that case we need to skip it properly. */
Petr Machatac0649d82012-04-20 02:39:33 +0200669 if ((sbp = address2bpstruct(leader, brk_addr)) != NULL) {
Petr Machata5ee36822012-04-19 17:01:51 +0200670 continue_after_breakpoint(event->proc, sbp);
Petr Machatac0649d82012-04-20 02:39:33 +0200671 } else {
672 set_instruction_pointer(event->proc, brk_addr);
Petr Machata5ee36822012-04-19 17:01:51 +0200673 continue_process(event->proc->pid);
Petr Machatac0649d82012-04-20 02:39:33 +0200674 }
Juan Cespedes5916fda2002-02-25 00:19:21 +0100675 return;
676 }
Juan Cespedes5e01f651998-03-08 22:31:44 +0100677 }
678
Petr Machata5ee36822012-04-19 17:01:51 +0200679 if ((sbp = address2bpstruct(leader, brk_addr)) != NULL)
Petr Machataa9fd8f42012-02-07 13:25:56 +0100680 breakpoint_on_hit(sbp, event->proc);
Petr Machata5ee36822012-04-19 17:01:51 +0200681 else if (event->proc->state != STATE_IGNORED)
682 output_line(event->proc,
683 "unexpected breakpoint at %p", brk_addr);
Petr Machatabc373262012-02-07 23:31:15 +0100684
Petr Machata5ee36822012-04-19 17:01:51 +0200685 /* breakpoint_on_hit may delete its own breakpoint, so we have
686 * to look it up again. */
687 if ((sbp = address2bpstruct(leader, brk_addr)) != NULL) {
Petr Machata2b46cfc2012-02-18 11:17:29 +0100688 if (event->proc->state != STATE_IGNORED
689 && sbp->libsym != NULL) {
Juan Cespedes5c682042009-05-21 15:59:56 +0200690 event->proc->stack_pointer = get_stack_pointer(event->proc);
691 event->proc->return_addr =
692 get_return_addr(event->proc, event->proc->stack_pointer);
Juan Cespedes5c682042009-05-21 15:59:56 +0200693 callstack_push_symfunc(event->proc, sbp->libsym);
Petr Machata29add4f2012-02-18 16:38:05 +0100694 output_left(LT_TOF_FUNCTION, event->proc, sbp->libsym);
Juan Cespedes5c682042009-05-21 15:59:56 +0200695 }
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100696
Petr Machata56a9ea62012-03-27 03:09:29 +0200697 breakpoint_on_continue(sbp, event->proc);
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100698 return;
Petr Machatac0649d82012-04-20 02:39:33 +0200699 } else {
700 set_instruction_pointer(event->proc, brk_addr);
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100701 }
Ian Wienand9a2ad352006-02-20 22:44:45 +0100702
Juan Cespedes5e01f651998-03-08 22:31:44 +0100703 continue_process(event->proc->pid);
704}
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200705
Juan Cespedesf1350522008-12-16 18:19:58 +0100706static void
Petr Machata929bd572012-12-17 03:20:34 +0100707callstack_push_syscall(struct process *proc, int sysnum)
708{
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100709 struct callstack_element *elem;
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200710
Juan Cespedescd8976d2009-05-14 13:47:58 +0200711 debug(DEBUG_FUNCTION, "callstack_push_syscall(pid=%d, sysnum=%d)", proc->pid, sysnum);
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200712 /* FIXME: not good -- should use dynamic allocation. 19990703 mortene. */
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100713 if (proc->callstack_depth == MAX_CALLDEPTH - 1) {
Arnaud Patard91a1f322010-01-08 08:40:13 -0500714 fprintf(stderr, "%s: Error: call nesting too deep!\n", __func__);
715 abort();
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200716 return;
717 }
718
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100719 elem = &proc->callstack[proc->callstack_depth];
Petr Machata8ae36732012-04-30 01:19:09 +0200720 *elem = (struct callstack_element){};
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200721 elem->is_syscall = 1;
722 elem->c_un.syscall = sysnum;
723 elem->return_addr = NULL;
724
725 proc->callstack_depth++;
Juan Cespedesda9b9532009-04-07 15:33:50 +0200726 if (opt_T || options.summary) {
Juan Cespedesd65efa32003-02-03 00:22:30 +0100727 struct timezone tz;
728 gettimeofday(&elem->time_spent, &tz);
729 }
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200730}
731
Juan Cespedes21c63a12001-07-07 20:56:56 +0200732static void
Petr Machata929bd572012-12-17 03:20:34 +0100733callstack_push_symfunc(struct process *proc, struct library_symbol *sym)
734{
Petr Machata14298742012-04-12 23:09:21 +0200735 struct callstack_element *elem;
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200736
Juan Cespedescd8976d2009-05-14 13:47:58 +0200737 debug(DEBUG_FUNCTION, "callstack_push_symfunc(pid=%d, symbol=%s)", proc->pid, sym->name);
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200738 /* FIXME: not good -- should use dynamic allocation. 19990703 mortene. */
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100739 if (proc->callstack_depth == MAX_CALLDEPTH - 1) {
Arnaud Patard91a1f322010-01-08 08:40:13 -0500740 fprintf(stderr, "%s: Error: call nesting too deep!\n", __func__);
741 abort();
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200742 return;
743 }
744
Petr Machata14298742012-04-12 23:09:21 +0200745 elem = &proc->callstack[proc->callstack_depth++];
Petr Machata8ae36732012-04-30 01:19:09 +0200746 *elem = (struct callstack_element){};
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200747 elem->is_syscall = 0;
748 elem->c_un.libfunc = sym;
749
Juan Cespedes3f0b62e2001-07-09 01:02:52 +0200750 elem->return_addr = proc->return_addr;
Petr Machata9df15012012-02-20 12:49:46 +0100751 if (elem->return_addr)
752 insert_breakpoint(proc, elem->return_addr, NULL);
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200753
Juan Cespedesda9b9532009-04-07 15:33:50 +0200754 if (opt_T || options.summary) {
Juan Cespedesd65efa32003-02-03 00:22:30 +0100755 struct timezone tz;
756 gettimeofday(&elem->time_spent, &tz);
757 }
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200758}
759
Petr Machatae655ccf2012-10-26 22:21:59 +0200760void
Petr Machata929bd572012-12-17 03:20:34 +0100761callstack_pop(struct process *proc)
Petr Machatae655ccf2012-10-26 22:21:59 +0200762{
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100763 struct callstack_element *elem;
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200764 assert(proc->callstack_depth > 0);
765
Juan Cespedescd8976d2009-05-14 13:47:58 +0200766 debug(DEBUG_FUNCTION, "callstack_pop(pid=%d)", proc->pid);
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100767 elem = &proc->callstack[proc->callstack_depth - 1];
Petr Machatae655ccf2012-10-26 22:21:59 +0200768 if (!elem->is_syscall && elem->return_addr)
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200769 delete_breakpoint(proc, elem->return_addr);
Petr Machatae655ccf2012-10-26 22:21:59 +0200770
771 if (elem->fetch_context != NULL)
772 fetch_arg_done(elem->fetch_context);
773
774 if (elem->arguments != NULL) {
775 val_dict_destroy(elem->arguments);
776 free(elem->arguments);
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200777 }
Petr Machatae655ccf2012-10-26 22:21:59 +0200778
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200779 proc->callstack_depth--;
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200780}