-
Notifications
You must be signed in to change notification settings - Fork 21
/
handle_event.c
719 lines (642 loc) · 18.6 KB
/
handle_event.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
#include "config.h"
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include <assert.h>
#include <sys/time.h>
#include "common.h"
#ifdef __powerpc__
#include <sys/ptrace.h>
#endif
static void handle_signal(Event *event);
static void handle_exit(Event *event);
static void handle_exit_signal(Event *event);
static void handle_syscall(Event *event);
static void handle_arch_syscall(Event *event);
static void handle_sysret(Event *event);
static void handle_arch_sysret(Event *event);
static void handle_clone(Event *event);
static void handle_exec(Event *event);
static void handle_breakpoint(Event *event);
static void handle_new(Event *event);
static void remove_proc(Process *proc);
static void callstack_push_syscall(Process *proc, int sysnum);
static void callstack_push_symfunc(Process *proc,
struct library_symbol *sym);
static void callstack_pop(Process *proc);
static char * shortsignal(Process *proc, int signum);
static char * sysname(Process *proc, int sysnum);
static char * arch_sysname(Process *proc, int sysnum);
void
handle_event(Event *event) {
debug(DEBUG_FUNCTION, "handle_event(pid=%d, type=%d)", event->proc ? event->proc->pid : -1, event->type);
switch (event->type) {
case EVENT_NONE:
debug(1, "event: none");
return;
case EVENT_SIGNAL:
debug(1, "event: signal (%s [%d])",
shortsignal(event->proc, event->e_un.signum),
event->e_un.signum);
handle_signal(event);
return;
case EVENT_EXIT:
debug(1, "event: exit (%d)", event->e_un.ret_val);
handle_exit(event);
return;
case EVENT_EXIT_SIGNAL:
debug(1, "event: exit signal (%s [%d])",
shortsignal(event->proc, event->e_un.signum),
event->e_un.signum);
handle_exit_signal(event);
return;
case EVENT_SYSCALL:
debug(1, "event: syscall (%s [%d])",
sysname(event->proc, event->e_un.sysnum),
event->e_un.sysnum);
handle_syscall(event);
return;
case EVENT_SYSRET:
debug(1, "event: sysret (%s [%d])",
sysname(event->proc, event->e_un.sysnum),
event->e_un.sysnum);
handle_sysret(event);
return;
case EVENT_ARCH_SYSCALL:
debug(1, "event: arch_syscall (%s [%d])",
arch_sysname(event->proc, event->e_un.sysnum),
event->e_un.sysnum);
handle_arch_syscall(event);
return;
case EVENT_ARCH_SYSRET:
debug(1, "event: arch_sysret (%s [%d])",
arch_sysname(event->proc, event->e_un.sysnum),
event->e_un.sysnum);
handle_arch_sysret(event);
return;
case EVENT_CLONE:
debug(1, "event: clone (%u)", event->e_un.newpid);
handle_clone(event);
return;
case EVENT_EXEC:
debug(1, "event: exec()");
handle_exec(event);
return;
case EVENT_BREAKPOINT:
debug(1, "event: breakpoint");
handle_breakpoint(event);
return;
case EVENT_NEW:
debug(1, "event: new process");
handle_new(event);
return;
default:
fprintf(stderr, "Error! unknown event?\n");
exit(1);
}
}
/* TODO */
static void *
address_clone(void * addr) {
debug(DEBUG_FUNCTION, "address_clone(%p)", addr);
return addr;
}
static void *
breakpoint_clone(void * bp) {
Breakpoint * b;
debug(DEBUG_FUNCTION, "breakpoint_clone(%p)", bp);
b = malloc(sizeof(Breakpoint));
if (!b) {
perror("malloc()");
exit(1);
}
memcpy(b, bp, sizeof(Breakpoint));
return b;
}
typedef struct Pending_New Pending_New;
struct Pending_New {
pid_t pid;
Pending_New * next;
};
static Pending_New * pending_news = NULL;
static int
pending_new(pid_t pid) {
Pending_New * p;
debug(DEBUG_FUNCTION, "pending_new(%d)", pid);
p = pending_news;
while (p) {
if (p->pid == pid) {
return 1;
}
p = p->next;
}
return 0;
}
static void
pending_new_insert(pid_t pid) {
Pending_New * p;
debug(DEBUG_FUNCTION, "pending_new_insert(%d)", pid);
p = malloc(sizeof(Pending_New));
if (!p) {
perror("malloc()");
exit(1);
}
p->pid = pid;
p->next = pending_news;
pending_news = p;
}
static void
pending_new_remove(pid_t pid) {
Pending_New *p, *pred;
debug(DEBUG_FUNCTION, "pending_new_remove(%d)", pid);
p = pending_news;
if (p->pid == pid) {
pending_news = p->next;
free(p);
} else {
while (p) {
if (p->pid == pid) {
pred->next = p->next;
free(p);
}
pred = p;
p = p->next;
}
}
}
static void
handle_clone(Event * event) {
Process *p;
debug(DEBUG_FUNCTION, "handle_clone(pid=%d)", event->proc->pid);
p = malloc(sizeof(Process));
if (!p) {
perror("malloc()");
exit(1);
}
memcpy(p, event->proc, sizeof(Process));
p->breakpoints = dict_clone(event->proc->breakpoints, address_clone, breakpoint_clone);
p->pid = event->e_un.newpid;
p->parent = event->proc;
if (pending_new(p->pid)) {
pending_new_remove(p->pid);
if (p->breakpoint_being_enabled) {
enable_breakpoint(p->pid, p->breakpoint_being_enabled);
p->breakpoint_being_enabled = NULL;
}
if (event->proc->state == STATE_ATTACHED && options.follow) {
p->state = STATE_ATTACHED;
} else {
p->state = STATE_IGNORED;
}
continue_process(p->pid);
p->next = list_of_processes;
list_of_processes = p;
} else {
p->state = STATE_BEING_CREATED;
p->next = list_of_processes;
list_of_processes = p;
}
continue_process(event->proc->pid);
}
static void
handle_new(Event * event) {
Process * proc;
debug(DEBUG_FUNCTION, "handle_new(pid=%d)", event->e_un.newpid);
proc = pid2proc(event->e_un.newpid);
if (!proc) {
pending_new_insert(event->e_un.newpid);
} else {
assert(proc->state == STATE_BEING_CREATED);
if (proc->breakpoint_being_enabled) {
enable_breakpoint(proc->pid, proc->breakpoint_being_enabled);
proc->breakpoint_being_enabled = NULL;
}
if (options.follow) {
proc->state = STATE_ATTACHED;
} else {
proc->state = STATE_IGNORED;
}
continue_process(proc->pid);
}
}
static char *
shortsignal(Process *proc, int signum) {
static char *signalent0[] = {
#include "signalent.h"
};
static char *signalent1[] = {
#include "signalent1.h"
};
static char **signalents[] = { signalent0, signalent1 };
int nsignals[] = { sizeof signalent0 / sizeof signalent0[0],
sizeof signalent1 / sizeof signalent1[0]
};
debug(DEBUG_FUNCTION, "shortsignal(pid=%d, signum=%d)", proc->pid, signum);
if (proc->personality > sizeof signalents / sizeof signalents[0])
abort();
if (signum < 0 || signum >= nsignals[proc->personality]) {
return "UNKNOWN_SIGNAL";
} else {
return signalents[proc->personality][signum];
}
}
static char *
sysname(Process *proc, int sysnum) {
static char result[128];
static char *syscalent0[] = {
#include "syscallent.h"
};
static char *syscalent1[] = {
#include "syscallent1.h"
};
static char **syscalents[] = { syscalent0, syscalent1 };
int nsyscals[] = { sizeof syscalent0 / sizeof syscalent0[0],
sizeof syscalent1 / sizeof syscalent1[0]
};
debug(DEBUG_FUNCTION, "sysname(pid=%d, sysnum=%d)", proc->pid, sysnum);
if (proc->personality > sizeof syscalents / sizeof syscalents[0])
abort();
if (sysnum < 0 || sysnum >= nsyscals[proc->personality]) {
sprintf(result, "SYS_%d", sysnum);
return result;
} else {
sprintf(result, "SYS_%s",
syscalents[proc->personality][sysnum]);
return result;
}
}
static char *
arch_sysname(Process *proc, int sysnum) {
static char result[128];
static char *arch_syscalent[] = {
#include "arch_syscallent.h"
};
int nsyscals = sizeof arch_syscalent / sizeof arch_syscalent[0];
debug(DEBUG_FUNCTION, "arch_sysname(pid=%d, sysnum=%d)", proc->pid, sysnum);
if (sysnum < 0 || sysnum >= nsyscals) {
sprintf(result, "ARCH_%d", sysnum);
return result;
} else {
sprintf(result, "ARCH_%s",
arch_syscalent[sysnum]);
return result;
}
}
static void
handle_signal(Event *event) {
debug(DEBUG_FUNCTION, "handle_signal(pid=%d, signum=%d)", event->proc->pid, event->e_un.signum);
if (exiting && event->e_un.signum == SIGSTOP) {
pid_t pid = event->proc->pid;
disable_all_breakpoints(event->proc);
untrace_pid(pid);
remove_proc(event->proc);
return;
}
if (event->proc->state != STATE_IGNORED && !options.no_signals) {
output_line(event->proc, "--- %s (%s) ---",
shortsignal(event->proc, event->e_un.signum),
strsignal(event->e_un.signum));
}
continue_after_signal(event->proc->pid, event->e_un.signum);
}
static void
handle_exit(Event *event) {
debug(DEBUG_FUNCTION, "handle_exit(pid=%d, status=%d)", event->proc->pid, event->e_un.ret_val);
if (event->proc->state != STATE_IGNORED) {
output_line(event->proc, "+++ exited (status %d) +++",
event->e_un.ret_val);
}
remove_proc(event->proc);
}
static void
handle_exit_signal(Event *event) {
debug(DEBUG_FUNCTION, "handle_exit_signal(pid=%d, signum=%d)", event->proc->pid, event->e_un.signum);
if (event->proc->state != STATE_IGNORED) {
output_line(event->proc, "+++ killed by %s +++",
shortsignal(event->proc, event->e_un.signum));
}
remove_proc(event->proc);
}
static void
remove_proc(Process *proc) {
Process *tmp, *tmp2;
debug(DEBUG_FUNCTION, "remove_proc(pid=%d)", proc->pid);
if (list_of_processes == proc) {
tmp = list_of_processes;
list_of_processes = list_of_processes->next;
free(tmp);
return;
}
tmp = list_of_processes;
while (tmp->next) {
if (tmp->next == proc) {
tmp2 = tmp->next;
tmp->next = tmp->next->next;
free(tmp2);
continue;
}
tmp = tmp->next;
}
}
static void
handle_syscall(Event *event) {
debug(DEBUG_FUNCTION, "handle_syscall(pid=%d, sysnum=%d)", event->proc->pid, event->e_un.sysnum);
if (event->proc->state != STATE_IGNORED) {
callstack_push_syscall(event->proc, event->e_un.sysnum);
if (options.syscalls) {
output_left(LT_TOF_SYSCALL, event->proc,
sysname(event->proc, event->e_un.sysnum));
}
if (event->proc->breakpoints_enabled == 0) {
enable_all_breakpoints(event->proc);
}
}
continue_process(event->proc->pid);
}
static void
handle_exec(Event * event) {
Process * proc = event->proc;
pid_t saved_pid;
debug(DEBUG_FUNCTION, "handle_exec(pid=%d)", proc->pid);
if (proc->state == STATE_IGNORED) {
untrace_pid(proc->pid);
remove_proc(proc);
return;
}
output_line(proc, "--- Called exec() ---");
proc->mask_32bit = 0;
proc->personality = 0;
proc->arch_ptr = NULL;
free(proc->filename);
proc->filename = pid2name(proc->pid);
saved_pid = proc->pid;
proc->pid = 0;
breakpoints_init(proc);
proc->pid = saved_pid;
proc->callstack_depth = 0;
continue_process(proc->pid);
}
static void
handle_arch_syscall(Event *event) {
debug(DEBUG_FUNCTION, "handle_arch_syscall(pid=%d, sysnum=%d)", event->proc->pid, event->e_un.sysnum);
if (event->proc->state != STATE_IGNORED) {
callstack_push_syscall(event->proc, 0xf0000 + event->e_un.sysnum);
if (options.syscalls) {
output_left(LT_TOF_SYSCALL, event->proc,
arch_sysname(event->proc, event->e_un.sysnum));
}
if (event->proc->breakpoints_enabled == 0) {
enable_all_breakpoints(event->proc);
}
}
continue_process(event->proc->pid);
}
struct timeval current_time_spent;
static void
calc_time_spent(Process *proc) {
struct timeval tv;
struct timezone tz;
struct timeval diff;
struct callstack_element *elem;
debug(DEBUG_FUNCTION, "calc_time_spent(pid=%d)", proc->pid);
elem = &proc->callstack[proc->callstack_depth - 1];
gettimeofday(&tv, &tz);
diff.tv_sec = tv.tv_sec - elem->time_spent.tv_sec;
if (tv.tv_usec >= elem->time_spent.tv_usec) {
diff.tv_usec = tv.tv_usec - elem->time_spent.tv_usec;
} else {
diff.tv_sec++;
diff.tv_usec = 1000000 + tv.tv_usec - elem->time_spent.tv_usec;
}
current_time_spent = diff;
}
static void
handle_sysret(Event *event) {
debug(DEBUG_FUNCTION, "handle_sysret(pid=%d, sysnum=%d)", event->proc->pid, event->e_un.sysnum);
if (event->proc->state != STATE_IGNORED) {
if (opt_T || options.summary) {
calc_time_spent(event->proc);
}
if (options.syscalls) {
output_right(LT_TOF_SYSCALLR, event->proc,
sysname(event->proc, event->e_un.sysnum));
}
callstack_pop(event->proc);
}
continue_process(event->proc->pid);
}
static void
handle_arch_sysret(Event *event) {
debug(DEBUG_FUNCTION, "handle_arch_sysret(pid=%d, sysnum=%d)", event->proc->pid, event->e_un.sysnum);
if (event->proc->state != STATE_IGNORED) {
if (opt_T || options.summary) {
calc_time_spent(event->proc);
}
if (options.syscalls) {
output_right(LT_TOF_SYSCALLR, event->proc,
arch_sysname(event->proc, event->e_un.sysnum));
}
callstack_pop(event->proc);
}
continue_process(event->proc->pid);
}
#ifdef __powerpc__
void *get_count_register (Process *proc);
#endif
static void
handle_breakpoint(Event *event) {
int i, j;
Breakpoint *sbp;
debug(DEBUG_FUNCTION, "handle_breakpoint(pid=%d, addr=%p)", event->proc->pid, event->e_un.brk_addr);
debug(2, "event: breakpoint (%p)", event->e_un.brk_addr);
#ifdef __powerpc__
/* Need to skip following NOP's to prevent a fake function from being stacked. */
long stub_addr = (long) get_count_register(event->proc);
Breakpoint *stub_bp = NULL;
char nop_instruction[] = PPC_NOP;
stub_bp = address2bpstruct (event->proc, event->e_un.brk_addr);
if (stub_bp) {
unsigned char *bp_instruction = stub_bp->orig_value;
if (memcmp(bp_instruction, nop_instruction,
PPC_NOP_LENGTH) == 0) {
if (stub_addr != (long) event->e_un.brk_addr) {
set_instruction_pointer (event->proc, event->e_un.brk_addr + 4);
continue_process(event->proc->pid);
return;
}
}
}
#endif
if ((sbp = event->proc->breakpoint_being_enabled) != 0) {
/* Reinsert breakpoint */
continue_enabling_breakpoint(event->proc->pid,
event->proc->
breakpoint_being_enabled);
event->proc->breakpoint_being_enabled = NULL;
return;
}
for (i = event->proc->callstack_depth - 1; i >= 0; i--) {
if (event->e_un.brk_addr ==
event->proc->callstack[i].return_addr) {
#ifdef __powerpc__
/*
* PPC HACK! (XXX FIXME TODO)
* The PLT gets modified during the first call,
* so be sure to re-enable the breakpoint.
*/
unsigned long a;
struct library_symbol *libsym =
event->proc->callstack[i].c_un.libfunc;
void *addr = sym2addr(event->proc, libsym);
if (libsym->plt_type != LS_TOPLT_POINT) {
unsigned char break_insn[] = BREAKPOINT_VALUE;
sbp = address2bpstruct(event->proc, addr);
assert(sbp);
a = ptrace(PTRACE_PEEKTEXT, event->proc->pid,
addr);
if (memcmp(&a, break_insn, BREAKPOINT_LENGTH)) {
sbp->enabled--;
insert_breakpoint(event->proc, addr,
libsym);
}
} else {
sbp = dict_find_entry(event->proc->breakpoints, addr);
/* On powerpc, the breakpoint address
may end up being actual entry point
of the library symbol, not the PLT
address we computed. In that case,
sbp is NULL. */
if (sbp == NULL || addr != sbp->addr) {
insert_breakpoint(event->proc, addr,
libsym);
}
}
#elif defined(__mips__)
void *addr = NULL;
struct library_symbol *sym= event->proc->callstack[i].c_un.libfunc;
struct library_symbol *new_sym;
assert(sym);
addr=sym2addr(event->proc,sym);
sbp = dict_find_entry(event->proc->breakpoints, addr);
if (sbp) {
if (addr != sbp->addr) {
insert_breakpoint(event->proc, addr, sym);
}
} else {
new_sym=malloc(sizeof(*new_sym) + strlen(sym->name) + 1);
memcpy(new_sym,sym,sizeof(*new_sym) + strlen(sym->name) + 1);
new_sym->next=event->proc->list_of_symbols;
event->proc->list_of_symbols=new_sym;
insert_breakpoint(event->proc, addr, new_sym);
}
#endif
for (j = event->proc->callstack_depth - 1; j > i; j--) {
callstack_pop(event->proc);
}
if (event->proc->state != STATE_IGNORED) {
if (opt_T || options.summary) {
calc_time_spent(event->proc);
}
}
event->proc->return_addr = event->e_un.brk_addr;
if (event->proc->state != STATE_IGNORED) {
output_right(LT_TOF_FUNCTIONR, event->proc,
event->proc->callstack[i].c_un.libfunc->name);
}
callstack_pop(event->proc);
continue_after_breakpoint(event->proc,
address2bpstruct(event->proc,
event->e_un.brk_addr));
return;
}
}
if ((sbp = address2bpstruct(event->proc, event->e_un.brk_addr))) {
if (strcmp(sbp->libsym->name, "") == 0) {
debug(2, "Hit _dl_debug_state breakpoint!\n");
arch_check_dbg(event->proc);
}
if (event->proc->state != STATE_IGNORED) {
event->proc->stack_pointer = get_stack_pointer(event->proc);
event->proc->return_addr =
get_return_addr(event->proc, event->proc->stack_pointer);
callstack_push_symfunc(event->proc, sbp->libsym);
output_left(LT_TOF_FUNCTION, event->proc, sbp->libsym->name);
}
#ifdef PLT_REINITALISATION_BP
if (event->proc->need_to_reinitialize_breakpoints
&& (strcmp(sbp->libsym->name, PLTs_initialized_by_here) ==
0))
reinitialize_breakpoints(event->proc);
#endif
continue_after_breakpoint(event->proc, sbp);
return;
}
if (event->proc->state != STATE_IGNORED && !options.no_plt) {
output_line(event->proc, "unexpected breakpoint at %p",
(void *)event->e_un.brk_addr);
}
continue_process(event->proc->pid);
}
static void
callstack_push_syscall(Process *proc, int sysnum) {
struct callstack_element *elem;
debug(DEBUG_FUNCTION, "callstack_push_syscall(pid=%d, sysnum=%d)", proc->pid, sysnum);
/* FIXME: not good -- should use dynamic allocation. 19990703 mortene. */
if (proc->callstack_depth == MAX_CALLDEPTH - 1) {
fprintf(stderr, "%s: Error: call nesting too deep!\n", __func__);
abort();
return;
}
elem = &proc->callstack[proc->callstack_depth];
elem->is_syscall = 1;
elem->c_un.syscall = sysnum;
elem->return_addr = NULL;
proc->callstack_depth++;
if (opt_T || options.summary) {
struct timezone tz;
gettimeofday(&elem->time_spent, &tz);
}
}
static void
callstack_push_symfunc(Process *proc, struct library_symbol *sym) {
struct callstack_element *elem, *prev;
debug(DEBUG_FUNCTION, "callstack_push_symfunc(pid=%d, symbol=%s)", proc->pid, sym->name);
/* FIXME: not good -- should use dynamic allocation. 19990703 mortene. */
if (proc->callstack_depth == MAX_CALLDEPTH - 1) {
fprintf(stderr, "%s: Error: call nesting too deep!\n", __func__);
abort();
return;
}
prev = &proc->callstack[proc->callstack_depth-1];
elem = &proc->callstack[proc->callstack_depth];
elem->is_syscall = 0;
elem->c_un.libfunc = sym;
elem->return_addr = proc->return_addr;
if (elem->return_addr) {
insert_breakpoint(proc, elem->return_addr, 0);
}
/* handle functions like atexit() on mips which have no return */
if (elem->return_addr != prev->return_addr)
proc->callstack_depth++;
if (opt_T || options.summary) {
struct timezone tz;
gettimeofday(&elem->time_spent, &tz);
}
}
static void
callstack_pop(Process *proc) {
struct callstack_element *elem;
assert(proc->callstack_depth > 0);
debug(DEBUG_FUNCTION, "callstack_pop(pid=%d)", proc->pid);
elem = &proc->callstack[proc->callstack_depth - 1];
if (!elem->is_syscall && elem->return_addr) {
delete_breakpoint(proc, elem->return_addr);
}
if (elem->arch_ptr != NULL) {
free(elem->arch_ptr);
elem->arch_ptr = NULL;
}
proc->callstack_depth--;
}