gdb: add GDB_FindAllocatedContextByPid
This commit is contained in:
parent
1e0996c395
commit
bd670cf87c
@ -52,6 +52,7 @@ void GDB_LockAllContexts(GDBServer *server);
|
|||||||
void GDB_UnlockAllContexts(GDBServer *server);
|
void GDB_UnlockAllContexts(GDBServer *server);
|
||||||
|
|
||||||
GDBContext *GDB_SelectAvailableContext(GDBServer *server, u16 minPort, u16 maxPort);
|
GDBContext *GDB_SelectAvailableContext(GDBServer *server, u16 minPort, u16 maxPort);
|
||||||
|
GDBContext *GDB_FindAllocatedContextByPid(GDBServer *server, u32 pid);
|
||||||
|
|
||||||
int GDB_AcceptClient(GDBContext *ctx);
|
int GDB_AcceptClient(GDBContext *ctx);
|
||||||
int GDB_CloseClient(GDBContext *ctx);
|
int GDB_CloseClient(GDBContext *ctx);
|
||||||
|
@ -152,6 +152,19 @@ GDBContext *GDB_SelectAvailableContext(GDBServer *server, u16 minPort, u16 maxPo
|
|||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GDBContext *GDB_FindAllocatedContextByPid(GDBServer *server, u32 pid)
|
||||||
|
{
|
||||||
|
GDB_LockAllContexts(server);
|
||||||
|
GDBContext *ctx = NULL;
|
||||||
|
for(u32 i = 0; i < MAX_DEBUG; i++)
|
||||||
|
{
|
||||||
|
if((server->ctxs[i].flags & GDB_FLAG_SELECTED) && server->ctxs[i].pid == pid)
|
||||||
|
ctx = &server->ctxs[i];
|
||||||
|
}
|
||||||
|
GDB_UnlockAllContexts(server);
|
||||||
|
return ctx;
|
||||||
|
}
|
||||||
|
|
||||||
int GDB_AcceptClient(GDBContext *ctx)
|
int GDB_AcceptClient(GDBContext *ctx)
|
||||||
{
|
{
|
||||||
Result r;
|
Result r;
|
||||||
|
@ -52,13 +52,13 @@ extern GDBServer gdbServer;
|
|||||||
static inline int ProcessListMenu_FormatInfoLine(char *out, const ProcessInfo *info)
|
static inline int ProcessListMenu_FormatInfoLine(char *out, const ProcessInfo *info)
|
||||||
{
|
{
|
||||||
const char *checkbox;
|
const char *checkbox;
|
||||||
u32 id = 0;
|
GDBContext *ctx = NULL;
|
||||||
|
|
||||||
if(gdbServer.super.running)
|
if(gdbServer.super.running)
|
||||||
{
|
{
|
||||||
GDB_LockAllContexts(&gdbServer);
|
GDB_LockAllContexts(&gdbServer);
|
||||||
for(id = 0; id < MAX_DEBUG && (!(gdbServer.ctxs[id].flags & GDB_FLAG_SELECTED) || gdbServer.ctxs[id].pid != info->pid); id++);
|
ctx = GDB_FindAllocatedContextByPid(&gdbServer, info->pid);
|
||||||
checkbox = id < MAX_DEBUG ? "(x) " : "( ) ";
|
checkbox = ctx != NULL ? "(x) " : "( ) ";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
checkbox = "";
|
checkbox = "";
|
||||||
@ -69,18 +69,18 @@ static inline int ProcessListMenu_FormatInfoLine(char *out, const ProcessInfo *i
|
|||||||
if(info->isZombie)
|
if(info->isZombie)
|
||||||
memcpy(commentBuf, "Zombie", 7);
|
memcpy(commentBuf, "Zombie", 7);
|
||||||
|
|
||||||
else if(gdbServer.super.running && id < MAX_DEBUG)
|
else if(gdbServer.super.running && ctx != NULL)
|
||||||
{
|
{
|
||||||
if(gdbServer.ctxs[id].state >= GDB_STATE_CONNECTED && gdbServer.ctxs[id].state < GDB_STATE_DETACHING)
|
if(ctx->state >= GDB_STATE_CONNECTED && ctx->state < GDB_STATE_DETACHING)
|
||||||
{
|
{
|
||||||
u8 *addr = (u8 *)&gdbServer.ctxs[id].super.addr_in.sin_addr;
|
u8 *addr = (u8 *)&ctx->super.addr_in.sin_addr;
|
||||||
checkbox = "(A) ";
|
checkbox = "(A) ";
|
||||||
sprintf(commentBuf, "Remote: %hhu.%hhu.%hhu.%hhu", addr[0], addr[1], addr[2], addr[3]);
|
sprintf(commentBuf, "Remote: %hhu.%hhu.%hhu.%hhu", addr[0], addr[1], addr[2], addr[3]);
|
||||||
}
|
}
|
||||||
else if (gdbServer.ctxs[id].localPort >= GDB_PORT_BASE && gdbServer.ctxs[id].localPort < GDB_PORT_BASE + MAX_DEBUG)
|
else if (ctx->localPort >= GDB_PORT_BASE && ctx->localPort < GDB_PORT_BASE + MAX_DEBUG)
|
||||||
{
|
{
|
||||||
checkbox = "(W) ";
|
checkbox = "(W) ";
|
||||||
sprintf(commentBuf, "Port: %hu", gdbServer.ctxs[id].localPort);
|
sprintf(commentBuf, "Port: %hu", ctx->localPort);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -591,12 +591,11 @@ static inline void ProcessListMenu_HandleSelected(const ProcessInfo *info)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GDB_LockAllContexts(&gdbServer);
|
GDB_LockAllContexts(&gdbServer);
|
||||||
u32 id;
|
GDBContext *ctx = NULL;
|
||||||
for(id = 0; id < MAX_DEBUG && (!(gdbServer.ctxs[id].flags & GDB_FLAG_SELECTED) || gdbServer.ctxs[id].pid != info->pid); id++);
|
ctx = GDB_FindAllocatedContextByPid(&gdbServer, info->pid);
|
||||||
|
|
||||||
if(id < MAX_DEBUG)
|
if(ctx != NULL)
|
||||||
{
|
{
|
||||||
GDBContext *ctx = &gdbServer.ctxs[id];
|
|
||||||
if(ctx->flags & GDB_FLAG_USED)
|
if(ctx->flags & GDB_FLAG_USED)
|
||||||
{
|
{
|
||||||
RecursiveLock_Lock(&ctx->lock);
|
RecursiveLock_Lock(&ctx->lock);
|
||||||
@ -606,7 +605,7 @@ static inline void ProcessListMenu_HandleSelected(const ProcessInfo *info)
|
|||||||
while(ctx->super.should_close)
|
while(ctx->super.should_close)
|
||||||
svcSleepThread(12 * 1000 * 1000LL);
|
svcSleepThread(12 * 1000 * 1000LL);
|
||||||
}
|
}
|
||||||
else if (gdbServer.ctxs[id].localPort >= GDB_PORT_BASE && gdbServer.ctxs[id].localPort < GDB_PORT_BASE + MAX_DEBUG)
|
else if (ctx->localPort >= GDB_PORT_BASE && ctx->localPort < GDB_PORT_BASE + MAX_DEBUG)
|
||||||
{
|
{
|
||||||
RecursiveLock_Lock(&ctx->lock);
|
RecursiveLock_Lock(&ctx->lock);
|
||||||
ctx->flags &= ~GDB_FLAG_SELECTED;
|
ctx->flags &= ~GDB_FLAG_SELECTED;
|
||||||
|
Reference in New Issue
Block a user