mirror of
https://github.com/sstefani/mtrace.git
synced 2026-02-08 02:36:41 +08:00
fix process attach
first attach all threads of a process and than set the breakpoints.
This commit is contained in:
parent
0259e186ab
commit
fc303d05be
35
task.c
35
task.c
@ -131,7 +131,6 @@ static int leader_setup(struct task *leader)
|
|||||||
return backtrace_init(leader);
|
return backtrace_init(leader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int task_init(struct task *task, int attached)
|
static int task_init(struct task *task, int attached)
|
||||||
{
|
{
|
||||||
pid_t tgid;
|
pid_t tgid;
|
||||||
@ -400,9 +399,10 @@ static void show_attached(struct task *task, void *data)
|
|||||||
fprintf(options.output, "+++ process pid=%d attached (%s) +++\n", task->pid, library_execname(task->leader));
|
fprintf(options.output, "+++ process pid=%d attached (%s) +++\n", task->pid, library_execname(task->leader));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void open_pid(pid_t pid)
|
void open_pid(pid_t pid)
|
||||||
{
|
{
|
||||||
struct task *task;
|
struct task *leader;
|
||||||
|
|
||||||
debug(DEBUG_PROCESS, "pid=%d", pid);
|
debug(DEBUG_PROCESS, "pid=%d", pid);
|
||||||
|
|
||||||
@ -412,11 +412,8 @@ void open_pid(pid_t pid)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* First, see if we can attach the requested PID itself. */
|
/* First, see if we can attach the requested PID itself. */
|
||||||
task = open_one_pid(pid);
|
leader = open_one_pid(pid);
|
||||||
if (!task)
|
if (!leader)
|
||||||
goto fail2;
|
|
||||||
|
|
||||||
if (leader_setup(task) < 0)
|
|
||||||
goto fail2;
|
goto fail2;
|
||||||
|
|
||||||
/* Now attach to all tasks that belong to that PID. There's a
|
/* Now attach to all tasks that belong to that PID. There's a
|
||||||
@ -437,18 +434,20 @@ void open_pid(pid_t pid)
|
|||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (process_tasks(pid, &tasks, &ntasks) < 0) {
|
if (process_tasks(pid, &tasks, &ntasks) < 0) {
|
||||||
fprintf(stderr, "Cannot obtain tasks of pid %u: %s\n", pid, strerror(errno));
|
fprintf(stderr, "Cannot obtain tasks of pid %d: %s\n", pid, strerror(errno));
|
||||||
goto fail1;
|
goto fail1;
|
||||||
}
|
}
|
||||||
|
|
||||||
have_all = 1;
|
have_all = 1;
|
||||||
for (i = 0; i < ntasks; ++i) {
|
for (i = 0; i < ntasks; ++i) {
|
||||||
if (!pid2task(tasks[i])) {
|
if (!pid2task(tasks[i])) {
|
||||||
struct task *child = open_one_pid(tasks[i]);
|
struct task *task = open_one_pid(tasks[i]);
|
||||||
|
|
||||||
if (child) {
|
if (task) {
|
||||||
if (task_clone(child->leader, child) < 0)
|
if (backtrace_init(task) < 0) {
|
||||||
goto fail2;
|
fprintf(stderr, "Cannot init backtrace for pid %d: %s\n", pid, strerror(errno));
|
||||||
|
goto fail1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
have_all = 0;
|
have_all = 0;
|
||||||
@ -462,14 +461,18 @@ void open_pid(pid_t pid)
|
|||||||
old_ntasks = ntasks;
|
old_ntasks = ntasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (leader_setup(leader) < 0)
|
||||||
|
goto fail1;
|
||||||
|
|
||||||
if (options.verbose)
|
if (options.verbose)
|
||||||
each_task(task, &show_attached, NULL);
|
each_task(leader, &show_attached, NULL);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
fail2:
|
fail2:
|
||||||
fprintf(stderr, "Cannot attach to pid %u: %s\n", pid, strerror(errno));
|
fprintf(stderr, "Cannot attach to pid %d: %s\n", pid, strerror(errno));
|
||||||
fail1:
|
fail1:
|
||||||
if (task)
|
if (leader)
|
||||||
remove_proc(task);
|
remove_proc(leader);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct task *get_first_process(void)
|
struct task *get_first_process(void)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user