gdb: simply gdbstate

This commit is contained in:
TuxSH 2019-04-09 23:59:05 +02:00
parent 5f295c4227
commit 1e0996c395
4 changed files with 11 additions and 9 deletions

View File

@ -61,9 +61,10 @@ typedef enum GDBFlags
{ {
GDB_FLAG_SELECTED = 1, GDB_FLAG_SELECTED = 1,
GDB_FLAG_USED = 2, GDB_FLAG_USED = 2,
GDB_FLAG_PROCESS_CONTINUING = 4, GDB_FLAG_NOACK = 4,
GDB_FLAG_TERMINATE_PROCESS = 8, GDB_FLAG_PROCESS_CONTINUING = 8,
GDB_FLAG_ATTACHED_AT_START = 16, GDB_FLAG_TERMINATE_PROCESS = 16,
GDB_FLAG_ATTACHED_AT_START = 32,
} GDBFlags; } GDBFlags;
typedef enum GDBState typedef enum GDBState
@ -71,7 +72,6 @@ typedef enum GDBState
GDB_STATE_DISCONNECTED, GDB_STATE_DISCONNECTED,
GDB_STATE_CONNECTED, GDB_STATE_CONNECTED,
GDB_STATE_NOACK_SENT, GDB_STATE_NOACK_SENT,
GDB_STATE_NOACK,
GDB_STATE_DETACHING GDB_STATE_DETACHING
} GDBState; } GDBState;

View File

@ -178,7 +178,6 @@ void GDB_DetachFromProcess(GDBContext *ctx)
ctx->nbThreads = 0; ctx->nbThreads = 0;
ctx->totalNbCreatedThreads = 0; ctx->totalNbCreatedThreads = 0;
memset(ctx->threadInfos, 0, sizeof(ctx->threadInfos)); memset(ctx->threadInfos, 0, sizeof(ctx->threadInfos));
ctx->catchThreadEvents = false;
} }
GDB_DECLARE_HANDLER(Unsupported) GDB_DECLARE_HANDLER(Unsupported)

View File

@ -141,7 +141,7 @@ int GDB_ReceivePacket(GDBContext *ctx)
return -1; return -1;
if(ctx->buffer[0] == '+') // GDB sometimes acknowleges TCP acknowledgment packets (yes...). IDA does it properly if(ctx->buffer[0] == '+') // GDB sometimes acknowleges TCP acknowledgment packets (yes...). IDA does it properly
{ {
if(ctx->state == GDB_STATE_NOACK) if(ctx->flags & GDB_FLAG_NOACK)
return -1; return -1;
// Consume it // Consume it
@ -193,7 +193,7 @@ int GDB_ReceivePacket(GDBContext *ctx)
ctx->commandEnd = ctx->buffer; ctx->commandEnd = ctx->buffer;
} }
if(ctx->state >= GDB_STATE_CONNECTED && ctx->state < GDB_STATE_NOACK) if(!(ctx->flags & GDB_FLAG_NOACK))
{ {
int r2 = soc_send(ctx->super.sockfd, "+", 1, 0); int r2 = soc_send(ctx->super.sockfd, "+", 1, 0);
if(r2 != 1) if(r2 != 1)
@ -201,12 +201,12 @@ int GDB_ReceivePacket(GDBContext *ctx)
} }
if(ctx->state == GDB_STATE_NOACK_SENT) if(ctx->state == GDB_STATE_NOACK_SENT)
ctx->state = GDB_STATE_NOACK; ctx->flags |= GDB_FLAG_NOACK;
return r; return r;
packet_error: packet_error:
if(ctx->state >= GDB_STATE_CONNECTED && ctx->state < GDB_STATE_NOACK) if(!(ctx->flags & GDB_FLAG_NOACK))
{ {
r = soc_send(ctx->super.sockfd, "-", 1, 0); r = soc_send(ctx->super.sockfd, "-", 1, 0);
if(r != 1) if(r != 1)

View File

@ -205,6 +205,9 @@ void GDB_ReleaseClient(GDBServer *server, GDBContext *ctx)
ctx->enableExternalMemoryAccess = false; ctx->enableExternalMemoryAccess = false;
ctx->flags = (GDBFlags)0; ctx->flags = (GDBFlags)0;
ctx->state = GDB_STATE_DISCONNECTED; ctx->state = GDB_STATE_DISCONNECTED;
ctx->catchThreadEvents = false;
RecursiveLock_Unlock(&ctx->lock); RecursiveLock_Unlock(&ctx->lock);
} }