gdb: refactor port/ctx alloc

This commit is contained in:
TuxSH
2019-03-31 00:24:45 +01:00
parent 22ec031495
commit cd18b85632
5 changed files with 70 additions and 18 deletions

View File

@@ -73,7 +73,7 @@ static inline int ProcessListMenu_FormatInfoLine(char *out, const ProcessInfo *i
else
{
checkbox = "(W) ";
sprintf(commentBuf, "Port: %ld", GDB_PORT_BASE + id);
sprintf(commentBuf, "Port: %hu", gdbServer.ctxs[id].localPort);
}
}
@@ -584,10 +584,9 @@ static inline void ProcessListMenu_HandleSelected(const ProcessInfo *info)
u32 id;
for(id = 0; id < MAX_DEBUG && (!(gdbServer.ctxs[id].flags & GDB_FLAG_SELECTED) || gdbServer.ctxs[id].pid != info->pid); id++);
GDBContext *ctx = &gdbServer.ctxs[id];
if(id < MAX_DEBUG)
{
GDBContext *ctx = &gdbServer.ctxs[id];
if(ctx->flags & GDB_FLAG_USED)
{
RecursiveLock_Lock(&ctx->lock);
@@ -601,20 +600,15 @@ static inline void ProcessListMenu_HandleSelected(const ProcessInfo *info)
{
RecursiveLock_Lock(&ctx->lock);
ctx->flags &= ~GDB_FLAG_SELECTED;
ctx->localPort = 0;
RecursiveLock_Unlock(&ctx->lock);
}
}
else
{
for(id = 0; id < MAX_DEBUG && gdbServer.ctxs[id].flags & GDB_FLAG_SELECTED; id++);
if(id < MAX_DEBUG)
{
ctx = &gdbServer.ctxs[id];
RecursiveLock_Lock(&ctx->lock);
GDBContext *ctx = GDB_SelectAvailableContext(&gdbServer, GDB_PORT_BASE, GDB_PORT_BASE + MAX_DEBUG);
if (ctx != NULL)
ctx->pid = info->pid;
ctx->flags |= GDB_FLAG_SELECTED;
RecursiveLock_Unlock(&ctx->lock);
}
}
}