-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtrace.c
110 lines (89 loc) · 2.46 KB
/
trace.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
/*
* This file is part of mtrace-ng.
* Copyright (C) 2018 Stefani Seibold <[email protected]>
*
* This work was sponsored by Rohde & Schwarz GmbH & Co. KG, Munich/Germany.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include "config.h"
#include <asm/unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "backend.h"
#include "breakpoint.h"
#include "debug.h"
#include "event.h"
#include "options.h"
#include "report.h"
#include "task.h"
#include "library.h"
#include "main.h"
int skip_breakpoint(struct task *task, struct breakpoint *bp)
{
debug(DEBUG_PROCESS, "pid=%d, addr=%#lx", task->pid, bp->addr);
assert(task->event.type == EVENT_BREAKPOINT);
assert(task->stopped);
assert(task->skip_bp == NULL);
if (bp->sw && bp->enabled) {
int ret = 0;
struct timespec start;
if (task->skip_bp) {
task->event.type = EVENT_NONE;
return 1;
}
if (unlikely(options.verbose > 1))
start_time(&start);
breakpoint_disable(task, bp);
ret = do_singlestep(task, bp);
breakpoint_enable(task, bp);
if (unlikely(options.verbose > 1))
set_timer(&start, &skip_bp_time);
if (unlikely(ret)) {
task->skip_bp = breakpoint_get(bp);
assert(task->skip_bp);
return ret;
}
}
continue_task(task, 0);
return 0;
}
void fix_about_exit(struct task *task)
{
if (task->about_exit) {
task->about_exit = 0;
continue_task(task, 0);
}
}
static void detach_cb(struct task *task, void *data)
{
(void)data;
remove_task(task);
}
void detach_proc(struct task *leader)
{
assert(leader->leader == leader);
breakpoint_disable_all(leader);
if (unlikely(options.verbose > 1))
fprintf(stderr, "+++ process detach pid=%d\n", leader->pid);
each_task(leader, &detach_cb, NULL);
}