blob: 63ed536b04058a670af035a9f41208f8485dbe23 [file] [log] [blame]
Petr Machatafed1e8d2012-02-07 02:06:29 +01001#define _GNU_SOURCE
Juan Cespedesd44c6b81998-09-25 14:48:42 +02002#include "config.h"
Juan Cespedesd44c6b81998-09-25 14:48:42 +02003
Juan Cespedes5e01f651998-03-08 22:31:44 +01004#include <stdio.h>
5#include <string.h>
Juan Cespedes1fe93d51998-03-13 00:29:21 +01006#include <stdlib.h>
Juan Cespedes28f60191998-04-12 00:04:39 +02007#include <signal.h>
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +02008#include <assert.h>
Juan Cespedesd65efa32003-02-03 00:22:30 +01009#include <sys/time.h>
Petr Machata534e00f2011-09-27 17:58:38 +020010#include <errno.h>
Juan Cespedes5e01f651998-03-08 22:31:44 +010011
Juan Cespedesf1bfe202002-03-27 00:22:23 +010012#ifdef __powerpc__
13#include <sys/ptrace.h>
14#endif
15
Petr Machatafed1e8d2012-02-07 02:06:29 +010016#include "common.h"
Petr Machata9294d822012-02-07 12:35:58 +010017#include "breakpoint.h"
Petr Machatafed1e8d2012-02-07 02:06:29 +010018
Juan Cespedes03192f82009-07-03 10:16:22 +020019static void handle_signal(Event *event);
20static void handle_exit(Event *event);
21static void handle_exit_signal(Event *event);
22static void handle_syscall(Event *event);
23static void handle_arch_syscall(Event *event);
24static void handle_sysret(Event *event);
25static void handle_arch_sysret(Event *event);
26static void handle_clone(Event *event);
27static void handle_exec(Event *event);
28static void handle_breakpoint(Event *event);
29static void handle_new(Event *event);
Juan Cespedes5e01f651998-03-08 22:31:44 +010030
Juan Cespedesa8909f72009-04-28 20:02:41 +020031static void callstack_push_syscall(Process *proc, int sysnum);
32static void callstack_push_symfunc(Process *proc,
Ian Wienand2d45b1a2006-02-20 22:48:07 +010033 struct library_symbol *sym);
Juan Cespedesa8909f72009-04-28 20:02:41 +020034static void callstack_pop(Process *proc);
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +020035
Juan Cespedes61da3372009-07-03 11:55:44 +020036static char * shortsignal(Process *proc, int signum);
37static char * sysname(Process *proc, int sysnum);
38static char * arch_sysname(Process *proc, int sysnum);
39
Petr Machatacbe29c62011-09-27 02:27:58 +020040static Event *
41call_handler(Process * proc, Event * event)
42{
43 assert(proc != NULL);
44
45 Event_Handler * handler = proc->event_handler;
46 if (handler == NULL)
47 return event;
48
49 return (*handler->on_event) (handler, event);
50}
51
Juan Cespedes61da3372009-07-03 11:55:44 +020052void
Petr Machataffe4cd22012-04-11 18:01:44 +020053handle_event(Event *event)
54{
Petr Machata602330f2011-07-09 11:15:34 +020055 if (exiting == 1) {
Petr Machata602330f2011-07-09 11:15:34 +020056 debug(1, "ltrace about to exit");
Petr Machataffe4cd22012-04-11 18:01:44 +020057 os_ltrace_exiting();
58 exiting = 2;
Petr Machata602330f2011-07-09 11:15:34 +020059 }
Petr Machata26627682011-07-08 18:15:32 +020060 debug(DEBUG_FUNCTION, "handle_event(pid=%d, type=%d)",
61 event->proc ? event->proc->pid : -1, event->type);
Petr Machatacbe29c62011-09-27 02:27:58 +020062
63 /* If the thread group or an individual task define an
64 overriding event handler, give them a chance to kick in.
65 We will end up calling both handlers, if the first one
66 doesn't sink the event. */
67 if (event->proc != NULL) {
68 event = call_handler(event->proc, event);
69 if (event == NULL)
70 /* It was handled. */
71 return;
72
73 /* Note: the previous handler has a chance to alter
74 * the event. */
Petr Machata43d2fe52011-11-02 13:25:49 +010075 if (event->proc != NULL
76 && event->proc->leader != NULL
77 && event->proc != event->proc->leader) {
Petr Machatacbe29c62011-09-27 02:27:58 +020078 event = call_handler(event->proc->leader, event);
Petr Machata4007d742011-07-09 11:29:42 +020079 if (event == NULL)
Petr Machata4007d742011-07-09 11:29:42 +020080 return;
81 }
82 }
83
Juan Cespedes61da3372009-07-03 11:55:44 +020084 switch (event->type) {
85 case EVENT_NONE:
86 debug(1, "event: none");
87 return;
88 case EVENT_SIGNAL:
89 debug(1, "event: signal (%s [%d])",
90 shortsignal(event->proc, event->e_un.signum),
91 event->e_un.signum);
92 handle_signal(event);
93 return;
94 case EVENT_EXIT:
95 debug(1, "event: exit (%d)", event->e_un.ret_val);
96 handle_exit(event);
97 return;
98 case EVENT_EXIT_SIGNAL:
99 debug(1, "event: exit signal (%s [%d])",
100 shortsignal(event->proc, event->e_un.signum),
101 event->e_un.signum);
102 handle_exit_signal(event);
103 return;
104 case EVENT_SYSCALL:
105 debug(1, "event: syscall (%s [%d])",
106 sysname(event->proc, event->e_un.sysnum),
107 event->e_un.sysnum);
108 handle_syscall(event);
109 return;
110 case EVENT_SYSRET:
111 debug(1, "event: sysret (%s [%d])",
112 sysname(event->proc, event->e_un.sysnum),
113 event->e_un.sysnum);
114 handle_sysret(event);
115 return;
116 case EVENT_ARCH_SYSCALL:
117 debug(1, "event: arch_syscall (%s [%d])",
118 arch_sysname(event->proc, event->e_un.sysnum),
119 event->e_un.sysnum);
120 handle_arch_syscall(event);
121 return;
122 case EVENT_ARCH_SYSRET:
123 debug(1, "event: arch_sysret (%s [%d])",
124 arch_sysname(event->proc, event->e_un.sysnum),
125 event->e_un.sysnum);
126 handle_arch_sysret(event);
127 return;
128 case EVENT_CLONE:
Petr Machatacbe29c62011-09-27 02:27:58 +0200129 case EVENT_VFORK:
Juan Cespedes61da3372009-07-03 11:55:44 +0200130 debug(1, "event: clone (%u)", event->e_un.newpid);
131 handle_clone(event);
132 return;
133 case EVENT_EXEC:
134 debug(1, "event: exec()");
135 handle_exec(event);
136 return;
137 case EVENT_BREAKPOINT:
138 debug(1, "event: breakpoint");
139 handle_breakpoint(event);
140 return;
141 case EVENT_NEW:
142 debug(1, "event: new process");
143 handle_new(event);
144 return;
145 default:
146 fprintf(stderr, "Error! unknown event?\n");
147 exit(1);
148 }
149}
150
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200151/* TODO */
Juan Cespedes61da3372009-07-03 11:55:44 +0200152static void *
Petr Machata534e00f2011-09-27 17:58:38 +0200153address_clone(void * addr, void * data)
154{
Juan Cespedescd8976d2009-05-14 13:47:58 +0200155 debug(DEBUG_FUNCTION, "address_clone(%p)", addr);
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200156 return addr;
157}
158
Juan Cespedes61da3372009-07-03 11:55:44 +0200159static void *
Petr Machatafed1e8d2012-02-07 02:06:29 +0100160breakpoint_clone(void *bp, void *data)
Petr Machata534e00f2011-09-27 17:58:38 +0200161{
Petr Machatafed1e8d2012-02-07 02:06:29 +0100162 Dict *map = data;
Juan Cespedescd8976d2009-05-14 13:47:58 +0200163 debug(DEBUG_FUNCTION, "breakpoint_clone(%p)", bp);
Petr Machata9294d822012-02-07 12:35:58 +0100164 struct breakpoint *b = malloc(sizeof(*b));
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200165 if (!b) {
166 perror("malloc()");
167 exit(1);
168 }
Petr Machatafed1e8d2012-02-07 02:06:29 +0100169 memcpy(b, bp, sizeof(*b));
Petr Machata534e00f2011-09-27 17:58:38 +0200170 if (b->libsym != NULL) {
Petr Machatafed1e8d2012-02-07 02:06:29 +0100171 struct library_symbol *sym = dict_find_entry(map, b->libsym);
Petr Machata534e00f2011-09-27 17:58:38 +0200172 if (b->libsym == NULL) {
173 fprintf(stderr, "Can't find cloned symbol %s.\n",
174 b->libsym->name);
175 return NULL;
176 }
177 b->libsym = sym;
178 }
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200179 return b;
180}
181
182typedef struct Pending_New Pending_New;
183struct Pending_New {
184 pid_t pid;
185 Pending_New * next;
186};
187static Pending_New * pending_news = NULL;
188
189static int
190pending_new(pid_t pid) {
Juan Cespedescd8976d2009-05-14 13:47:58 +0200191 Pending_New * p;
192
193 debug(DEBUG_FUNCTION, "pending_new(%d)", pid);
194
195 p = pending_news;
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200196 while (p) {
197 if (p->pid == pid) {
198 return 1;
199 }
200 p = p->next;
201 }
202 return 0;
203}
204
205static void
206pending_new_insert(pid_t pid) {
Juan Cespedescd8976d2009-05-14 13:47:58 +0200207 Pending_New * p;
208
209 debug(DEBUG_FUNCTION, "pending_new_insert(%d)", pid);
210
211 p = malloc(sizeof(Pending_New));
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200212 if (!p) {
213 perror("malloc()");
214 exit(1);
215 }
216 p->pid = pid;
217 p->next = pending_news;
218 pending_news = p;
219}
220
221static void
222pending_new_remove(pid_t pid) {
223 Pending_New *p, *pred;
224
Juan Cespedescd8976d2009-05-14 13:47:58 +0200225 debug(DEBUG_FUNCTION, "pending_new_remove(%d)", pid);
226
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200227 p = pending_news;
228 if (p->pid == pid) {
229 pending_news = p->next;
230 free(p);
231 } else {
232 while (p) {
233 if (p->pid == pid) {
234 pred->next = p->next;
235 free(p);
236 }
237 pred = p;
238 p = p->next;
239 }
240 }
241}
242
Petr Machata534e00f2011-09-27 17:58:38 +0200243static int
244clone_breakpoints(Process * proc, Process * orig_proc)
245{
246 /* When copying breakpoints, we also have to copy the
247 * referenced symbols, and link them properly. */
248 Dict * map = dict_init(&dict_key2hash_int, &dict_key_cmp_int);
249 struct library_symbol * it = proc->list_of_symbols;
250 proc->list_of_symbols = NULL;
251 for (; it != NULL; it = it->next) {
252 struct library_symbol * libsym = clone_library_symbol(it);
253 if (libsym == NULL) {
254 int save_errno;
255 err:
256 save_errno = errno;
257 destroy_library_symbol_chain(proc->list_of_symbols);
258 dict_clear(map);
259 errno = save_errno;
260 return -1;
261 }
262 libsym->next = proc->list_of_symbols;
263 proc->list_of_symbols = libsym;
264 if (dict_enter(map, it, libsym) != 0)
265 goto err;
266 }
267
268 proc->breakpoints = dict_clone2(orig_proc->breakpoints,
269 address_clone, breakpoint_clone, map);
270 if (proc->breakpoints == NULL)
271 goto err;
272
273 dict_clear(map);
274 return 0;
275}
276
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200277static void
Juan Cespedes03192f82009-07-03 10:16:22 +0200278handle_clone(Event * event) {
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200279 Process *p;
280
Juan Cespedes03192f82009-07-03 10:16:22 +0200281 debug(DEBUG_FUNCTION, "handle_clone(pid=%d)", event->proc->pid);
Juan Cespedescd8976d2009-05-14 13:47:58 +0200282
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200283 p = malloc(sizeof(Process));
284 if (!p) {
285 perror("malloc()");
286 exit(1);
287 }
288 memcpy(p, event->proc, sizeof(Process));
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200289 p->pid = event->e_un.newpid;
Juan Cespedes2721e6a2009-05-21 15:15:40 +0200290 p->parent = event->proc;
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200291
Petr Machata75dcf7d2011-10-06 14:30:19 +0200292 /* We save register values to the arch pointer, and these need
293 to be per-thread. */
294 p->arch_ptr = NULL;
295
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200296 if (pending_new(p->pid)) {
297 pending_new_remove(p->pid);
Petr Machata4007d742011-07-09 11:29:42 +0200298 if (p->event_handler != NULL)
299 destroy_event_handler(p);
Juan Cespedes5c682042009-05-21 15:59:56 +0200300 if (event->proc->state == STATE_ATTACHED && options.follow) {
301 p->state = STATE_ATTACHED;
302 } else {
303 p->state = STATE_IGNORED;
304 }
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200305 continue_process(p->pid);
Petr Machatacebb8842011-07-09 11:14:11 +0200306 add_process(p);
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200307 } else {
308 p->state = STATE_BEING_CREATED;
Petr Machatacebb8842011-07-09 11:14:11 +0200309 add_process(p);
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200310 }
Petr Machatacbe29c62011-09-27 02:27:58 +0200311
Petr Machata534e00f2011-09-27 17:58:38 +0200312 if (p->leader == p)
Petr Machataba9911f2011-09-27 21:09:47 +0200313 clone_breakpoints(p, event->proc->leader);
Petr Machata534e00f2011-09-27 17:58:38 +0200314 else
315 /* Thread groups share breakpoints. */
316 p->breakpoints = NULL;
317
Petr Machatacbe29c62011-09-27 02:27:58 +0200318 if (event->type == EVENT_VFORK)
319 continue_after_vfork(p);
320 else
321 continue_process(event->proc->pid);
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200322}
323
324static void
Juan Cespedes03192f82009-07-03 10:16:22 +0200325handle_new(Event * event) {
Juan Cespedescd8976d2009-05-14 13:47:58 +0200326 Process * proc;
327
Juan Cespedes03192f82009-07-03 10:16:22 +0200328 debug(DEBUG_FUNCTION, "handle_new(pid=%d)", event->e_un.newpid);
Juan Cespedescd8976d2009-05-14 13:47:58 +0200329
330 proc = pid2proc(event->e_un.newpid);
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200331 if (!proc) {
332 pending_new_insert(event->e_un.newpid);
333 } else {
334 assert(proc->state == STATE_BEING_CREATED);
Juan Cespedes30439b42009-05-22 19:03:09 +0200335 if (options.follow) {
Juan Cespedes5c682042009-05-21 15:59:56 +0200336 proc->state = STATE_ATTACHED;
337 } else {
338 proc->state = STATE_IGNORED;
339 }
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200340 continue_process(proc->pid);
341 }
342}
343
Juan Cespedesf1350522008-12-16 18:19:58 +0100344static char *
Juan Cespedesa8909f72009-04-28 20:02:41 +0200345shortsignal(Process *proc, int signum) {
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 *
Juan Cespedesa8909f72009-04-28 20:02:41 +0200369sysname(Process *proc, int sysnum) {
Juan Cespedes5e01f651998-03-08 22:31:44 +0100370 static char result[128];
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100371 static char *syscalent0[] = {
372#include "syscallent.h"
Juan Cespedes5e01f651998-03-08 22:31:44 +0100373 };
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100374 static char *syscalent1[] = {
375#include "syscallent1.h"
Ian Wienand9a2ad352006-02-20 22:44:45 +0100376 };
377 static char **syscalents[] = { syscalent0, syscalent1 };
378 int nsyscals[] = { sizeof syscalent0 / sizeof syscalent0[0],
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100379 sizeof syscalent1 / sizeof syscalent1[0]
380 };
Juan Cespedes5e01f651998-03-08 22:31:44 +0100381
Juan Cespedescd8976d2009-05-14 13:47:58 +0200382 debug(DEBUG_FUNCTION, "sysname(pid=%d, sysnum=%d)", proc->pid, sysnum);
383
Ian Wienand9a2ad352006-02-20 22:44:45 +0100384 if (proc->personality > sizeof syscalents / sizeof syscalents[0])
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100385 abort();
Ian Wienand9a2ad352006-02-20 22:44:45 +0100386 if (sysnum < 0 || sysnum >= nsyscals[proc->personality]) {
Juan Cespedes5e01f651998-03-08 22:31:44 +0100387 sprintf(result, "SYS_%d", sysnum);
388 return result;
389 } else {
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100390 sprintf(result, "SYS_%s",
391 syscalents[proc->personality][sysnum]);
Juan Cespedes5e01f651998-03-08 22:31:44 +0100392 return result;
393 }
394}
395
Juan Cespedesf1350522008-12-16 18:19:58 +0100396static char *
Juan Cespedesa8909f72009-04-28 20:02:41 +0200397arch_sysname(Process *proc, int sysnum) {
Juan Cespedes63184be2008-12-10 13:30:12 +0100398 static char result[128];
399 static char *arch_syscalent[] = {
400#include "arch_syscallent.h"
401 };
402 int nsyscals = sizeof arch_syscalent / sizeof arch_syscalent[0];
403
Juan Cespedescd8976d2009-05-14 13:47:58 +0200404 debug(DEBUG_FUNCTION, "arch_sysname(pid=%d, sysnum=%d)", proc->pid, sysnum);
405
Juan Cespedes63184be2008-12-10 13:30:12 +0100406 if (sysnum < 0 || sysnum >= nsyscals) {
407 sprintf(result, "ARCH_%d", sysnum);
408 return result;
409 } else {
410 sprintf(result, "ARCH_%s",
411 arch_syscalent[sysnum]);
412 return result;
413 }
414}
415
Juan Cespedesf1350522008-12-16 18:19:58 +0100416static void
Juan Cespedes03192f82009-07-03 10:16:22 +0200417handle_signal(Event *event) {
418 debug(DEBUG_FUNCTION, "handle_signal(pid=%d, signum=%d)", event->proc->pid, event->e_un.signum);
Joe Damato59e3fb12009-11-06 19:45:10 -0800419 if (event->proc->state != STATE_IGNORED && !options.no_signals) {
Juan Cespedes5c682042009-05-21 15:59:56 +0200420 output_line(event->proc, "--- %s (%s) ---",
421 shortsignal(event->proc, event->e_un.signum),
422 strsignal(event->e_un.signum));
423 }
Juan Cespedes5e01f651998-03-08 22:31:44 +0100424 continue_after_signal(event->proc->pid, event->e_un.signum);
425}
426
Juan Cespedesf1350522008-12-16 18:19:58 +0100427static void
Juan Cespedes03192f82009-07-03 10:16:22 +0200428handle_exit(Event *event) {
429 debug(DEBUG_FUNCTION, "handle_exit(pid=%d, status=%d)", event->proc->pid, event->e_un.ret_val);
Juan Cespedes5c682042009-05-21 15:59:56 +0200430 if (event->proc->state != STATE_IGNORED) {
431 output_line(event->proc, "+++ exited (status %d) +++",
432 event->e_un.ret_val);
433 }
Petr Machatacebb8842011-07-09 11:14:11 +0200434 remove_process(event->proc);
Juan Cespedes5e01f651998-03-08 22:31:44 +0100435}
436
Juan Cespedesf1350522008-12-16 18:19:58 +0100437static void
Juan Cespedes03192f82009-07-03 10:16:22 +0200438handle_exit_signal(Event *event) {
439 debug(DEBUG_FUNCTION, "handle_exit_signal(pid=%d, signum=%d)", event->proc->pid, event->e_un.signum);
Juan Cespedes5c682042009-05-21 15:59:56 +0200440 if (event->proc->state != STATE_IGNORED) {
441 output_line(event->proc, "+++ killed by %s +++",
442 shortsignal(event->proc, event->e_un.signum));
443 }
Petr Machatacebb8842011-07-09 11:14:11 +0200444 remove_process(event->proc);
Juan Cespedes5e01f651998-03-08 22:31:44 +0100445}
446
Juan Cespedesf1350522008-12-16 18:19:58 +0100447static void
Juan Cespedes03192f82009-07-03 10:16:22 +0200448handle_syscall(Event *event) {
449 debug(DEBUG_FUNCTION, "handle_syscall(pid=%d, sysnum=%d)", event->proc->pid, event->e_un.sysnum);
Juan Cespedes5c682042009-05-21 15:59:56 +0200450 if (event->proc->state != STATE_IGNORED) {
Petr Machata211f0882010-11-03 18:42:18 +0100451 callstack_push_syscall(event->proc, event->e_un.sysnum);
Juan Cespedes5c682042009-05-21 15:59:56 +0200452 if (options.syscalls) {
453 output_left(LT_TOF_SYSCALL, event->proc,
Petr Machata26627682011-07-08 18:15:32 +0200454 sysname(event->proc, event->e_un.sysnum));
Juan Cespedes5c682042009-05-21 15:59:56 +0200455 }
456 if (event->proc->breakpoints_enabled == 0) {
457 enable_all_breakpoints(event->proc);
458 }
Juan Cespedes5e01f651998-03-08 22:31:44 +0100459 }
Petr Machata43d2fe52011-11-02 13:25:49 +0100460 continue_after_syscall(event->proc, event->e_un.sysnum, 0);
Juan Cespedes5e01f651998-03-08 22:31:44 +0100461}
462
Juan Cespedesf1350522008-12-16 18:19:58 +0100463static void
Juan Cespedes03192f82009-07-03 10:16:22 +0200464handle_exec(Event * event) {
Juan Cespedese0660df2009-05-21 18:14:39 +0200465 Process * proc = event->proc;
466 pid_t saved_pid;
467
Juan Cespedes03192f82009-07-03 10:16:22 +0200468 debug(DEBUG_FUNCTION, "handle_exec(pid=%d)", proc->pid);
Juan Cespedese0660df2009-05-21 18:14:39 +0200469 if (proc->state == STATE_IGNORED) {
470 untrace_pid(proc->pid);
Petr Machatacebb8842011-07-09 11:14:11 +0200471 remove_process(proc);
Juan Cespedese0660df2009-05-21 18:14:39 +0200472 return;
Juan Cespedes5c682042009-05-21 15:59:56 +0200473 }
Juan Cespedese0660df2009-05-21 18:14:39 +0200474 output_line(proc, "--- Called exec() ---");
475 proc->mask_32bit = 0;
476 proc->personality = 0;
477 proc->arch_ptr = NULL;
478 free(proc->filename);
479 proc->filename = pid2name(proc->pid);
480 saved_pid = proc->pid;
481 proc->pid = 0;
Petr Machatac7585b62011-07-08 22:58:12 +0200482 breakpoints_init(proc, 0);
Juan Cespedese0660df2009-05-21 18:14:39 +0200483 proc->pid = saved_pid;
484 proc->callstack_depth = 0;
485 continue_process(proc->pid);
Juan Cespedes1e583132009-04-07 18:17:11 +0200486}
487
488static void
Juan Cespedes03192f82009-07-03 10:16:22 +0200489handle_arch_syscall(Event *event) {
490 debug(DEBUG_FUNCTION, "handle_arch_syscall(pid=%d, sysnum=%d)", event->proc->pid, event->e_un.sysnum);
Juan Cespedes5c682042009-05-21 15:59:56 +0200491 if (event->proc->state != STATE_IGNORED) {
Petr Machata211f0882010-11-03 18:42:18 +0100492 callstack_push_syscall(event->proc, 0xf0000 + event->e_un.sysnum);
Juan Cespedes5c682042009-05-21 15:59:56 +0200493 if (options.syscalls) {
494 output_left(LT_TOF_SYSCALL, event->proc,
495 arch_sysname(event->proc, event->e_un.sysnum));
496 }
497 if (event->proc->breakpoints_enabled == 0) {
498 enable_all_breakpoints(event->proc);
499 }
Juan Cespedes63184be2008-12-10 13:30:12 +0100500 }
Juan Cespedes63184be2008-12-10 13:30:12 +0100501 continue_process(event->proc->pid);
502}
503
Juan Cespedesd65efa32003-02-03 00:22:30 +0100504struct timeval current_time_spent;
505
Juan Cespedesf1350522008-12-16 18:19:58 +0100506static void
Juan Cespedesa8909f72009-04-28 20:02:41 +0200507calc_time_spent(Process *proc) {
Juan Cespedesd65efa32003-02-03 00:22:30 +0100508 struct timeval tv;
509 struct timezone tz;
510 struct timeval diff;
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100511 struct callstack_element *elem;
Juan Cespedesd65efa32003-02-03 00:22:30 +0100512
Juan Cespedescd8976d2009-05-14 13:47:58 +0200513 debug(DEBUG_FUNCTION, "calc_time_spent(pid=%d)", proc->pid);
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100514 elem = &proc->callstack[proc->callstack_depth - 1];
Juan Cespedesd65efa32003-02-03 00:22:30 +0100515
516 gettimeofday(&tv, &tz);
517
518 diff.tv_sec = tv.tv_sec - elem->time_spent.tv_sec;
519 if (tv.tv_usec >= elem->time_spent.tv_usec) {
520 diff.tv_usec = tv.tv_usec - elem->time_spent.tv_usec;
521 } else {
522 diff.tv_sec++;
523 diff.tv_usec = 1000000 + tv.tv_usec - elem->time_spent.tv_usec;
524 }
525 current_time_spent = diff;
526}
527
Juan Cespedesf1350522008-12-16 18:19:58 +0100528static void
Juan Cespedes03192f82009-07-03 10:16:22 +0200529handle_sysret(Event *event) {
530 debug(DEBUG_FUNCTION, "handle_sysret(pid=%d, sysnum=%d)", event->proc->pid, event->e_un.sysnum);
Juan Cespedes5c682042009-05-21 15:59:56 +0200531 if (event->proc->state != STATE_IGNORED) {
532 if (opt_T || options.summary) {
533 calc_time_spent(event->proc);
534 }
Juan Cespedes5c682042009-05-21 15:59:56 +0200535 if (options.syscalls) {
536 output_right(LT_TOF_SYSCALLR, event->proc,
537 sysname(event->proc, event->e_un.sysnum));
538 }
Petr Machata43d2fe52011-11-02 13:25:49 +0100539 assert(event->proc->callstack_depth > 0);
540 unsigned d = event->proc->callstack_depth - 1;
541 assert(event->proc->callstack[d].is_syscall);
Petr Machata211f0882010-11-03 18:42:18 +0100542 callstack_pop(event->proc);
Juan Cespedes21c63a12001-07-07 20:56:56 +0200543 }
Petr Machata43d2fe52011-11-02 13:25:49 +0100544 continue_after_syscall(event->proc, event->e_un.sysnum, 1);
Juan Cespedes5e01f651998-03-08 22:31:44 +0100545}
546
Juan Cespedesf1350522008-12-16 18:19:58 +0100547static void
Juan Cespedes03192f82009-07-03 10:16:22 +0200548handle_arch_sysret(Event *event) {
549 debug(DEBUG_FUNCTION, "handle_arch_sysret(pid=%d, sysnum=%d)", event->proc->pid, event->e_un.sysnum);
Juan Cespedes5c682042009-05-21 15:59:56 +0200550 if (event->proc->state != STATE_IGNORED) {
551 if (opt_T || options.summary) {
552 calc_time_spent(event->proc);
553 }
Juan Cespedes5c682042009-05-21 15:59:56 +0200554 if (options.syscalls) {
555 output_right(LT_TOF_SYSCALLR, event->proc,
556 arch_sysname(event->proc, event->e_un.sysnum));
557 }
Petr Machata211f0882010-11-03 18:42:18 +0100558 callstack_pop(event->proc);
Juan Cespedes63184be2008-12-10 13:30:12 +0100559 }
560 continue_process(event->proc->pid);
561}
562
Petr Machata067322d2010-10-25 14:47:55 +0200563#ifdef __powerpc__
564void *get_count_register (Process *proc);
565#endif
566
Juan Cespedesf1350522008-12-16 18:19:58 +0100567static void
Petr Machata14298742012-04-12 23:09:21 +0200568output_right_tos(struct Process *proc)
569{
570 size_t d = proc->callstack_depth;
571 struct callstack_element *elem = &proc->callstack[d - 1];
572 if (proc->state != STATE_IGNORED)
573 output_right(LT_TOF_FUNCTIONR, proc, elem->c_un.libfunc->name);
574}
575
576static void
Petr Machatafed1e8d2012-02-07 02:06:29 +0100577handle_breakpoint(Event *event)
578{
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100579 int i, j;
Juan Cespedes1dec2172009-05-07 10:12:10 +0200580 Breakpoint *sbp;
Petr Machata9a5420c2011-07-09 11:21:23 +0200581 Process *leader = event->proc->leader;
Petr Machata31b2f9f2012-04-12 22:23:40 +0200582 void *brk_addr = event->e_un.brk_addr;
Petr Machata9a5420c2011-07-09 11:21:23 +0200583
584 /* The leader has terminated. */
585 if (leader == NULL) {
586 continue_process(event->proc->pid);
587 return;
588 }
Juan Cespedes5e01f651998-03-08 22:31:44 +0100589
Petr Machata31b2f9f2012-04-12 22:23:40 +0200590 debug(DEBUG_FUNCTION, "handle_breakpoint(pid=%d, addr=%p)",
591 event->proc->pid, brk_addr);
592 debug(2, "event: breakpoint (%p)", brk_addr);
Luis Machado55c5feb2008-03-12 15:56:01 +0100593
Paul Gilliam76c61f12006-06-14 06:55:21 +0200594#ifdef __powerpc__
Luis Machado55c5feb2008-03-12 15:56:01 +0100595 /* Need to skip following NOP's to prevent a fake function from being stacked. */
596 long stub_addr = (long) get_count_register(event->proc);
Juan Cespedes1dec2172009-05-07 10:12:10 +0200597 Breakpoint *stub_bp = NULL;
Luis Machado55c5feb2008-03-12 15:56:01 +0100598 char nop_instruction[] = PPC_NOP;
599
Petr Machata31b2f9f2012-04-12 22:23:40 +0200600 stub_bp = address2bpstruct(leader, brk_addr);
Luis Machado55c5feb2008-03-12 15:56:01 +0100601
602 if (stub_bp) {
603 unsigned char *bp_instruction = stub_bp->orig_value;
604
605 if (memcmp(bp_instruction, nop_instruction,
606 PPC_NOP_LENGTH) == 0) {
Petr Machata31b2f9f2012-04-12 22:23:40 +0200607 if (stub_addr != (long) brk_addr) {
608 set_instruction_pointer(event->proc,
609 brk_addr + 4);
Luis Machado55c5feb2008-03-12 15:56:01 +0100610 continue_process(event->proc->pid);
Paul Gilliam76c61f12006-06-14 06:55:21 +0200611 return;
612 }
613 }
Luis Machado55c5feb2008-03-12 15:56:01 +0100614 }
Paul Gilliam76c61f12006-06-14 06:55:21 +0200615#endif
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200616
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100617 for (i = event->proc->callstack_depth - 1; i >= 0; i--) {
Petr Machata31b2f9f2012-04-12 22:23:40 +0200618 if (brk_addr == event->proc->callstack[i].return_addr) {
Juan Cespedes5bfb0612002-03-31 20:01:28 +0200619#ifdef __powerpc__
Ian Wienand3219f322006-02-16 06:00:00 +0100620 /*
621 * PPC HACK! (XXX FIXME TODO)
622 * The PLT gets modified during the first call,
623 * so be sure to re-enable the breakpoint.
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100624 */
Ian Wienand9a2ad352006-02-20 22:44:45 +0100625 unsigned long a;
626 struct library_symbol *libsym =
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100627 event->proc->callstack[i].c_un.libfunc;
Paul Gilliam76c61f12006-06-14 06:55:21 +0200628 void *addr = sym2addr(event->proc, libsym);
Juan Cespedes5bfb0612002-03-31 20:01:28 +0200629
Paul Gilliam76c61f12006-06-14 06:55:21 +0200630 if (libsym->plt_type != LS_TOPLT_POINT) {
Ian Wienand9a2ad352006-02-20 22:44:45 +0100631 unsigned char break_insn[] = BREAKPOINT_VALUE;
632
Petr Machata9a5420c2011-07-09 11:21:23 +0200633 sbp = address2bpstruct(leader, addr);
Ian Wienand9a2ad352006-02-20 22:44:45 +0100634 assert(sbp);
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100635 a = ptrace(PTRACE_PEEKTEXT, event->proc->pid,
636 addr);
Ian Wienand9a2ad352006-02-20 22:44:45 +0100637
Paul Gilliam76c61f12006-06-14 06:55:21 +0200638 if (memcmp(&a, break_insn, BREAKPOINT_LENGTH)) {
Ian Wienand9a2ad352006-02-20 22:44:45 +0100639 sbp->enabled--;
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100640 insert_breakpoint(event->proc, addr,
Petr Machata46d66ab2011-08-20 05:29:25 +0200641 libsym, 1);
Ian Wienand9a2ad352006-02-20 22:44:45 +0100642 }
643 } else {
Petr Machata9a5420c2011-07-09 11:21:23 +0200644 sbp = dict_find_entry(leader->breakpoints, addr);
Petr Machata067322d2010-10-25 14:47:55 +0200645 /* On powerpc, the breakpoint address
646 may end up being actual entry point
647 of the library symbol, not the PLT
648 address we computed. In that case,
649 sbp is NULL. */
650 if (sbp == NULL || addr != sbp->addr) {
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100651 insert_breakpoint(event->proc, addr,
Petr Machata46d66ab2011-08-20 05:29:25 +0200652 libsym, 1);
Paul Gilliam76c61f12006-06-14 06:55:21 +0200653 }
Ian Wienand3219f322006-02-16 06:00:00 +0100654 }
Eric Vaitl1228a912006-12-28 16:16:56 +0100655#elif defined(__mips__)
Arnaud Patard161193f2010-01-08 08:40:14 -0500656 void *addr = NULL;
Juan Cespedesa413e5b2007-09-04 17:34:53 +0200657 struct library_symbol *sym= event->proc->callstack[i].c_un.libfunc;
Arnaud Patard161193f2010-01-08 08:40:14 -0500658 struct library_symbol *new_sym;
Juan Cespedesbc8caf02009-05-07 19:38:38 +0200659 assert(sym);
Petr Machatac185aff2011-11-09 16:18:06 +0100660 addr = sym2addr(event->proc, sym);
Petr Machata9a5420c2011-07-09 11:21:23 +0200661 sbp = dict_find_entry(leader->breakpoints, addr);
Arnaud Patard161193f2010-01-08 08:40:14 -0500662 if (sbp) {
663 if (addr != sbp->addr) {
Petr Machata46d66ab2011-08-20 05:29:25 +0200664 insert_breakpoint(event->proc, addr, sym, 1);
Arnaud Patard161193f2010-01-08 08:40:14 -0500665 }
666 } else {
667 new_sym=malloc(sizeof(*new_sym) + strlen(sym->name) + 1);
668 memcpy(new_sym,sym,sizeof(*new_sym) + strlen(sym->name) + 1);
Petr Machata26627682011-07-08 18:15:32 +0200669 new_sym->next = leader->list_of_symbols;
Petr Machata9a5420c2011-07-09 11:21:23 +0200670 leader->list_of_symbols = new_sym;
Petr Machata46d66ab2011-08-20 05:29:25 +0200671 insert_breakpoint(event->proc, addr, new_sym, 1);
Juan Cespedesa413e5b2007-09-04 17:34:53 +0200672 }
Juan Cespedes5bfb0612002-03-31 20:01:28 +0200673#endif
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100674 for (j = event->proc->callstack_depth - 1; j > i; j--) {
Juan Cespedes5916fda2002-02-25 00:19:21 +0100675 callstack_pop(event->proc);
676 }
Juan Cespedes5c682042009-05-21 15:59:56 +0200677 if (event->proc->state != STATE_IGNORED) {
678 if (opt_T || options.summary) {
679 calc_time_spent(event->proc);
680 }
Juan Cespedesd65efa32003-02-03 00:22:30 +0100681 }
Petr Machata31b2f9f2012-04-12 22:23:40 +0200682 event->proc->return_addr = brk_addr;
683
Petr Machata14298742012-04-12 23:09:21 +0200684 output_right_tos(event->proc);
685 callstack_pop(event->proc);
686
Petr Machata31b2f9f2012-04-12 22:23:40 +0200687 /* Pop also any other entries that seem like
688 * they are linked to the current one: they
689 * have the same return address, but were made
690 * for different symbols. This should only
691 * happen for entry point tracing, i.e. for -x
692 * everywhere, or -x and -e on PPC64. */
Petr Machata31b2f9f2012-04-12 22:23:40 +0200693 while (event->proc->callstack_depth > 0) {
694 struct callstack_element *prev;
695 size_t d = event->proc->callstack_depth;
696 prev = &event->proc->callstack[d - 1];
697
Petr Machata14298742012-04-12 23:09:21 +0200698 if (prev->c_un.libfunc == libsym
699 || prev->return_addr != brk_addr)
Petr Machata31b2f9f2012-04-12 22:23:40 +0200700 break;
Petr Machata14298742012-04-12 23:09:21 +0200701
702 output_right_tos(event->proc);
703 callstack_pop(event->proc);
Juan Cespedes5c682042009-05-21 15:59:56 +0200704 }
Petr Machata31b2f9f2012-04-12 22:23:40 +0200705
706 sbp = address2bpstruct(leader, brk_addr);
Petr Machata9a5420c2011-07-09 11:21:23 +0200707 continue_after_breakpoint(event->proc, sbp);
Juan Cespedes5916fda2002-02-25 00:19:21 +0100708 return;
709 }
Juan Cespedes5e01f651998-03-08 22:31:44 +0100710 }
711
Petr Machata31b2f9f2012-04-12 22:23:40 +0200712 if ((sbp = address2bpstruct(leader, brk_addr))) {
Petr Machata9a5420c2011-07-09 11:21:23 +0200713 if (sbp->libsym == NULL) {
714 continue_after_breakpoint(event->proc, sbp);
715 return;
716 }
717
Joe Damatof0bd98b2010-11-08 15:47:42 -0800718 if (strcmp(sbp->libsym->name, "") == 0) {
Petr Machata26627682011-07-08 18:15:32 +0200719 debug(DEBUG_PROCESS, "Hit _dl_debug_state breakpoint!\n");
Petr Machata9a5420c2011-07-09 11:21:23 +0200720 arch_check_dbg(leader);
Zachary T Welch97baa652010-12-08 13:34:03 -0800721 }
Petr Machata9a5420c2011-07-09 11:21:23 +0200722
Zachary T Welch97baa652010-12-08 13:34:03 -0800723 if (event->proc->state != STATE_IGNORED) {
Juan Cespedes5c682042009-05-21 15:59:56 +0200724 event->proc->stack_pointer = get_stack_pointer(event->proc);
725 event->proc->return_addr =
726 get_return_addr(event->proc, event->proc->stack_pointer);
Juan Cespedes5c682042009-05-21 15:59:56 +0200727 callstack_push_symfunc(event->proc, sbp->libsym);
Petr Machata211f0882010-11-03 18:42:18 +0100728 output_left(LT_TOF_FUNCTION, event->proc, sbp->libsym->name);
Juan Cespedes5c682042009-05-21 15:59:56 +0200729 }
Paul Gilliambe320772006-04-24 22:06:23 +0200730#ifdef PLT_REINITALISATION_BP
731 if (event->proc->need_to_reinitialize_breakpoints
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100732 && (strcmp(sbp->libsym->name, PLTs_initialized_by_here) ==
733 0))
Petr Machata9a5420c2011-07-09 11:21:23 +0200734 reinitialize_breakpoints(leader);
Paul Gilliambe320772006-04-24 22:06:23 +0200735#endif
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100736
737 continue_after_breakpoint(event->proc, sbp);
738 return;
739 }
Ian Wienand9a2ad352006-02-20 22:44:45 +0100740
Joe Damatofa2aefc2010-10-30 19:56:50 -0700741 if (event->proc->state != STATE_IGNORED && !options.no_plt) {
Juan Cespedes5c682042009-05-21 15:59:56 +0200742 output_line(event->proc, "unexpected breakpoint at %p",
Petr Machata31b2f9f2012-04-12 22:23:40 +0200743 brk_addr);
Juan Cespedes5c682042009-05-21 15:59:56 +0200744 }
Juan Cespedes5e01f651998-03-08 22:31:44 +0100745 continue_process(event->proc->pid);
746}
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200747
Juan Cespedesf1350522008-12-16 18:19:58 +0100748static void
Juan Cespedesa8909f72009-04-28 20:02:41 +0200749callstack_push_syscall(Process *proc, int sysnum) {
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100750 struct callstack_element *elem;
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200751
Juan Cespedescd8976d2009-05-14 13:47:58 +0200752 debug(DEBUG_FUNCTION, "callstack_push_syscall(pid=%d, sysnum=%d)", proc->pid, sysnum);
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200753 /* FIXME: not good -- should use dynamic allocation. 19990703 mortene. */
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100754 if (proc->callstack_depth == MAX_CALLDEPTH - 1) {
Arnaud Patard91a1f322010-01-08 08:40:13 -0500755 fprintf(stderr, "%s: Error: call nesting too deep!\n", __func__);
756 abort();
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200757 return;
758 }
759
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100760 elem = &proc->callstack[proc->callstack_depth];
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200761 elem->is_syscall = 1;
762 elem->c_un.syscall = sysnum;
763 elem->return_addr = NULL;
764
765 proc->callstack_depth++;
Juan Cespedesda9b9532009-04-07 15:33:50 +0200766 if (opt_T || options.summary) {
Juan Cespedesd65efa32003-02-03 00:22:30 +0100767 struct timezone tz;
768 gettimeofday(&elem->time_spent, &tz);
769 }
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200770}
771
Juan Cespedes21c63a12001-07-07 20:56:56 +0200772static void
Juan Cespedesa8909f72009-04-28 20:02:41 +0200773callstack_push_symfunc(Process *proc, struct library_symbol *sym) {
Petr Machata14298742012-04-12 23:09:21 +0200774 struct callstack_element *elem;
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200775
Juan Cespedescd8976d2009-05-14 13:47:58 +0200776 debug(DEBUG_FUNCTION, "callstack_push_symfunc(pid=%d, symbol=%s)", proc->pid, sym->name);
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200777 /* FIXME: not good -- should use dynamic allocation. 19990703 mortene. */
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100778 if (proc->callstack_depth == MAX_CALLDEPTH - 1) {
Arnaud Patard91a1f322010-01-08 08:40:13 -0500779 fprintf(stderr, "%s: Error: call nesting too deep!\n", __func__);
780 abort();
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200781 return;
782 }
783
Petr Machata14298742012-04-12 23:09:21 +0200784 elem = &proc->callstack[proc->callstack_depth++];
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200785 elem->is_syscall = 0;
786 elem->c_un.libfunc = sym;
787
Juan Cespedes3f0b62e2001-07-09 01:02:52 +0200788 elem->return_addr = proc->return_addr;
Juan Cespedesa413e5b2007-09-04 17:34:53 +0200789 if (elem->return_addr) {
Petr Machatac7585b62011-07-08 22:58:12 +0200790 insert_breakpoint(proc, elem->return_addr, NULL, 1);
Paul Gilliam76c61f12006-06-14 06:55:21 +0200791 }
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200792
Arnaud Patard26570082010-01-08 08:40:12 -0500793 /* handle functions like atexit() on mips which have no return */
Juan Cespedesda9b9532009-04-07 15:33:50 +0200794 if (opt_T || options.summary) {
Juan Cespedesd65efa32003-02-03 00:22:30 +0100795 struct timezone tz;
796 gettimeofday(&elem->time_spent, &tz);
797 }
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200798}
799
Juan Cespedesf1350522008-12-16 18:19:58 +0100800static void
Juan Cespedesa8909f72009-04-28 20:02:41 +0200801callstack_pop(Process *proc) {
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100802 struct callstack_element *elem;
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200803 assert(proc->callstack_depth > 0);
804
Juan Cespedescd8976d2009-05-14 13:47:58 +0200805 debug(DEBUG_FUNCTION, "callstack_pop(pid=%d)", proc->pid);
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100806 elem = &proc->callstack[proc->callstack_depth - 1];
Paul Gilliam76c61f12006-06-14 06:55:21 +0200807 if (!elem->is_syscall && elem->return_addr) {
Petr Machata9a5420c2011-07-09 11:21:23 +0200808 assert(proc->leader != NULL);
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200809 delete_breakpoint(proc, elem->return_addr);
810 }
Petr Machata211f0882010-11-03 18:42:18 +0100811 if (elem->arch_ptr != NULL) {
812 free(elem->arch_ptr);
813 elem->arch_ptr = NULL;
814 }
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200815 proc->callstack_depth--;
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200816}