debug: make xnu attach idempotent for di (#6295)
This commit is contained in:
parent
a99cc738c2
commit
056bb141a9
4 changed files with 34 additions and 29 deletions
|
|
@ -37,6 +37,7 @@ RZ_IPI bool rz_xnu_debug_init(RzDebug *dbg, void **user) {
|
|||
return false;
|
||||
}
|
||||
ctx->old_pid = -1;
|
||||
ctx->last_attached_pid = -1;
|
||||
*user = ctx;
|
||||
return true;
|
||||
}
|
||||
|
|
@ -152,6 +153,10 @@ int xnu_attach(RzDebug *dbg, int pid) {
|
|||
RzXnuDebug *ctx = dbg->plugin_data;
|
||||
|
||||
dbg->pid = pid;
|
||||
if (ctx->last_attached_pid == pid) {
|
||||
RZ_LOG_INFO("Already attached to pid %d, skipping attach\n", pid);
|
||||
return pid;
|
||||
}
|
||||
|
||||
ctx->cpu = xnu_get_cpu_type(pid);
|
||||
if (!ctx->cpu) {
|
||||
|
|
@ -180,6 +185,7 @@ int xnu_attach(RzDebug *dbg, int pid) {
|
|||
xnu_stop(dbg, pid);
|
||||
}
|
||||
|
||||
ctx->last_attached_pid = pid;
|
||||
return pid;
|
||||
}
|
||||
|
||||
|
|
@ -452,21 +458,6 @@ RzDebugInfo *xnu_info(RzDebug *dbg, const char *arg) {
|
|||
return rdi;
|
||||
}
|
||||
|
||||
/*
|
||||
static void xnu_free_threads_ports (RzDebugPid *p) {
|
||||
kern_return_t kr;
|
||||
if (!p) return;
|
||||
free (p->path);
|
||||
if (p->pid != old_pid) {
|
||||
kr = mach_port_deallocate (old_pid, p->pid);
|
||||
if (kr != KERN_SUCCESS) {
|
||||
eprintf ("error mach_port_deallocate in "
|
||||
"xnu_free_threads ports\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
RzList *xnu_thread_list(RzDebug *dbg, int pid, RzList *list) {
|
||||
rz_return_val_if_fail(dbg && dbg->plugin_data, NULL);
|
||||
RzXnuDebug *ctx = dbg->plugin_data;
|
||||
|
|
|
|||
|
|
@ -275,11 +275,18 @@ typedef struct _exception_info {
|
|||
mach_port_t exception_port;
|
||||
} xnu_exception_info;
|
||||
|
||||
/**
|
||||
* \brief XNU-specific debugger context.
|
||||
*
|
||||
* Holds XNU-specific state for a debug session and is used by the native XNU
|
||||
* debugger implementation to track the debuggee's info
|
||||
*/
|
||||
typedef struct rz_xnu_debug_t {
|
||||
cpu_type_t cpu; ///< CPU/Architecture of the debuggee, determined and set once after attach
|
||||
task_t task_dbg;
|
||||
int old_pid;
|
||||
xnu_exception_info ex;
|
||||
cpu_type_t cpu; ///< CPU/Architecture of the debuggee.
|
||||
task_t task_dbg; ///< Mach task port for the process with pid `old_pid`. Cache for `pid_to_task`.
|
||||
int old_pid; ///< Previously observed PID, related to `task_dbg`. Cache for `pid_to_task`.
|
||||
int last_attached_pid; ///< Last PID the plugin attached to.
|
||||
xnu_exception_info ex; ///< Exception handling state (ports, masks, flavors).
|
||||
} RzXnuDebug;
|
||||
|
||||
RZ_IPI bool rz_xnu_debug_init(RzDebug *dbg, void **user);
|
||||
|
|
|
|||
17
test/db/archos/darwin-x64/dbg_di
Normal file
17
test/db/archos/darwin-x64/dbg_di
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
NAME=dbg.di
|
||||
FILE=bins/mach0/hello-osx-x86_64
|
||||
ARGS=-d
|
||||
CMDS=<<EOF
|
||||
dcu main
|
||||
di~baddr
|
||||
ds
|
||||
di~baddr
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
baddr=0x100000000
|
||||
baddr=0x100000000
|
||||
EOF
|
||||
EXPECT_ERR=<<EOF
|
||||
hit breakpoint at: 0x100000f0c
|
||||
EOF
|
||||
RUN
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
NAME=dbg.di
|
||||
FILE=/bin/ls
|
||||
ARGS=-d
|
||||
BROKEN=1
|
||||
CMDS=di~baddr
|
||||
EXPECT=<<EOF
|
||||
baddr=0x100000000
|
||||
EOF
|
||||
RUN
|
||||
|
||||
Loading…
Reference in a new issue