mirror of
https://github.com/LumaTeam/Luma3DS.git
synced 2026-02-22 01:44:38 +00:00
rosalina: Add debug flag to dump gdb communications
This commit is contained in:
parent
902f306ab3
commit
e0e86c46a7
@ -16,6 +16,9 @@
|
||||
#include "memory.h"
|
||||
#include "ifile.h"
|
||||
|
||||
// Uncomment the line below to dump GDB communications to a file
|
||||
//#define DEBUG_GDB_COMMUNICATIONS
|
||||
|
||||
#define MAX_DEBUG 3
|
||||
#define MAX_DEBUG_THREAD 127
|
||||
#define MAX_BREAKPOINT 64
|
||||
@ -154,6 +157,10 @@ typedef struct GDBContext
|
||||
|
||||
char memoryOsInfoXmlData[0x800];
|
||||
char processesOsInfoXmlData[0x1800];
|
||||
|
||||
#ifdef DEBUG_GDB_COMMUNICATIONS
|
||||
IFile debugFile;
|
||||
#endif
|
||||
} GDBContext;
|
||||
|
||||
typedef int (*GDBCommandHandler)(GDBContext *ctx);
|
||||
|
||||
@ -44,3 +44,4 @@ Result IFile_GetSize(IFile *file, u64 *size);
|
||||
Result IFile_SetSize(IFile *file, u64 size);
|
||||
Result IFile_Read(IFile *file, u64 *total, void *buffer, u32 len);
|
||||
Result IFile_Write(IFile *file, u64 *total, const void *buffer, u32 len, u32 flags);
|
||||
Result IFile_Flush(IFile *file);
|
||||
|
||||
@ -28,6 +28,10 @@ void GDB_InitializeContext(GDBContext *ctx)
|
||||
ctx->eventToWaitFor = ctx->processAttachedEvent;
|
||||
ctx->continueFlags = (DebugFlags)(DBG_SIGNAL_FAULT_EXCEPTION_EVENTS | DBG_INHIBIT_USER_CPU_EXCEPTION_HANDLERS);
|
||||
|
||||
#ifdef DEBUG_GDB_COMMUNICATIONS
|
||||
IFile_Open(&ctx->debugFile, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, "/luma/gdb_debug.txt"), FS_OPEN_READ | FS_OPEN_WRITE | FS_OPEN_CREATE);
|
||||
#endif
|
||||
|
||||
RecursiveLock_Unlock(&ctx->lock);
|
||||
}
|
||||
|
||||
@ -40,6 +44,10 @@ void GDB_FinalizeContext(GDBContext *ctx)
|
||||
svcCloseHandle(ctx->processAttachedEvent);
|
||||
svcCloseHandle(ctx->continuedEvent);
|
||||
|
||||
#ifdef DEBUG_GDB_COMMUNICATIONS
|
||||
IFile_Close(&ctx->debugFile);
|
||||
#endif
|
||||
|
||||
RecursiveLock_Unlock(&ctx->lock);
|
||||
}
|
||||
|
||||
|
||||
@ -171,6 +171,17 @@ const char *GDB_ParseHexIntegerList64(u64 *dst, const char *src, u32 nb, char la
|
||||
return GDB_ParseIntegerList64(dst, src, nb, ',', lastSep, 16, false);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_GDB_COMMUNICATIONS
|
||||
void GDB_LogPacket(GDBContext *ctx, void* buffer, u32 pLen, bool incoming)
|
||||
{
|
||||
u64 written;
|
||||
IFile_Write(&ctx->debugFile, &written, incoming ? "<-\t" : "->\t", 3, 0);
|
||||
IFile_Write(&ctx->debugFile, &written, buffer, pLen, 0);
|
||||
IFile_Write(&ctx->debugFile, &written, "\n", 1, 0);
|
||||
IFile_Flush(&ctx->debugFile);
|
||||
}
|
||||
#endif
|
||||
|
||||
int GDB_ReceivePacket(GDBContext *ctx)
|
||||
{
|
||||
char backupbuf[GDB_BUF_LEN + 4];
|
||||
@ -189,6 +200,9 @@ int GDB_ReceivePacket(GDBContext *ctx)
|
||||
r = socRecv(ctx->super.sockfd, ctx->buffer, 1, 0);
|
||||
if(r != 1)
|
||||
return -1;
|
||||
#ifdef DEBUG_GDB_COMMUNICATIONS
|
||||
GDB_LogPacket(ctx, ctx->buffer, r, true);
|
||||
#endif
|
||||
|
||||
ctx->buffer[0] = 0;
|
||||
|
||||
@ -197,9 +211,19 @@ int GDB_ReceivePacket(GDBContext *ctx)
|
||||
if(r == -1)
|
||||
goto packet_error;
|
||||
}
|
||||
else if(ctx->buffer[0] == '-')
|
||||
|
||||
#ifdef DEBUG_GDB_COMMUNICATIONS
|
||||
GDB_LogPacket(ctx, ctx->buffer, r, true);
|
||||
#endif
|
||||
|
||||
if(ctx->buffer[0] == '-')
|
||||
{
|
||||
socSend(ctx->super.sockfd, backupbuf, ctx->latestSentPacketSize, 0);
|
||||
|
||||
#ifdef DEBUG_GDB_COMMUNICATIONS
|
||||
GDB_LogPacket(ctx, backupbuf, ctx->latestSentPacketSize, false);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
int maxlen = r > (int)sizeof(ctx->buffer) ? (int)sizeof(ctx->buffer) : r;
|
||||
@ -239,6 +263,9 @@ int GDB_ReceivePacket(GDBContext *ctx)
|
||||
int r2 = socSend(ctx->super.sockfd, "+", 1, 0);
|
||||
if(r2 != 1)
|
||||
return -1;
|
||||
#ifdef DEBUG_GDB_COMMUNICATIONS
|
||||
GDB_LogPacket(ctx, "+", 1, false);
|
||||
#endif
|
||||
}
|
||||
|
||||
if(ctx->noAckSent)
|
||||
@ -255,9 +282,13 @@ packet_error:
|
||||
r = socSend(ctx->super.sockfd, "-", 1, 0);
|
||||
if(r != 1)
|
||||
return -1;
|
||||
else
|
||||
else {
|
||||
#ifdef DEBUG_GDB_COMMUNICATIONS
|
||||
GDB_LogPacket(ctx, "-", 1, false);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
@ -265,6 +296,9 @@ packet_error:
|
||||
static int GDB_DoSendPacket(GDBContext *ctx, u32 len)
|
||||
{
|
||||
int r = socSend(ctx->super.sockfd, ctx->buffer, len, 0);
|
||||
#ifdef DEBUG_GDB_COMMUNICATIONS
|
||||
GDB_LogPacket(ctx, ctx->buffer, len, false);
|
||||
#endif
|
||||
|
||||
if(r > 0)
|
||||
ctx->latestSentPacketSize = r;
|
||||
|
||||
@ -149,3 +149,8 @@ Result IFile_Write(IFile *file, u64 *total, const void *buffer, u32 len, u32 fla
|
||||
*total = cur;
|
||||
return res;
|
||||
}
|
||||
|
||||
Result IFile_Flush(IFile *file)
|
||||
{
|
||||
return FSFILE_Flush(file->handle);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user