thermosphere: add more debugging strings

This commit is contained in:
TuxSH 2020-02-01 15:11:59 +00:00
parent e1a8bdd495
commit 8f25d4f77f
5 changed files with 37 additions and 10 deletions

View file

@ -15,6 +15,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include "debug_log.h" #include "debug_log.h"
#include "platform/uart.h" #include "platform/uart.h"
#include "semihosting.h" #include "semihosting.h"
@ -35,6 +36,16 @@ void debugLogInit(void)
} }
} }
void debugLogRaw(const char *str)
{
// Use semihosting if available (we assume qemu was launched with -semihosting), otherwise UART
if (DLOG_USE_SEMIHOSTING_WRITE0 && semihosting_connection_supported()) {
semihosting_write_string(str);
} else {
transportInterfaceWriteData(g_debugLogTransportInterface, str, strlen(str));
}
}
// NOTE: UNSAFE! // NOTE: UNSAFE!
int debugLog(const char *fmt, ...) int debugLog(const char *fmt, ...)
{ {
@ -44,12 +55,7 @@ int debugLog(const char *fmt, ...)
int res = vsprintf(buf, fmt, args); int res = vsprintf(buf, fmt, args);
va_end(args); va_end(args);
// Use semihosting if available (we assume qemu was launched with -semihosting), otherwise UART debugLogRaw(buf);
if (DLOG_USE_SEMIHOSTING_WRITE0 && semihosting_connection_supported()) {
semihosting_write_string(buf);
} else {
transportInterfaceWriteData(g_debugLogTransportInterface, buf, res);
}
return res; return res;
} }

View file

@ -18,10 +18,13 @@
#include <stdarg.h> #include <stdarg.h>
#ifndef NDEBUG #ifndef NDEBUG
#define DEBUG(...) debugLog(__VA_ARGS__) #define DEBUG(...) debugLog(__VA_ARGS__)
#define DEBUGRAW(str) debugLogRaw(str)
#else #else
#define DEBUG(...) #define DEBUG(...)
#define DEBUGRAW(str)
#endif #endif
void debugLogInit(void); void debugLogInit(void);
void debugLogRaw(const char *str);
int debugLog(const char *fmt, ...); int debugLog(const char *fmt, ...);

View file

@ -74,7 +74,15 @@ void dumpStackFrame(const ExceptionStackFrame *frame, bool sameEl)
if (frame == currentCoreCtx->guestFrame) { if (frame == currentCoreCtx->guestFrame) {
DEBUG("cntp_ctl_el0\t%016llx\n", frame->cntp_ctl_el0); DEBUG("cntp_ctl_el0\t%016llx\n", frame->cntp_ctl_el0);
DEBUG("cntv_ctl_el0\t%016llx\n", frame->cntv_ctl_el0); DEBUG("cntv_ctl_el0\t%016llx\n", frame->cntv_ctl_el0);
} }/* else {
// Try to dump the stack (comment if this crashes)
u64 *sp = (u64 *)(frame->sp_el2 - 8);
u64 *spEnd = (u64 *)((frame->sp_el2 & ~0xFFF) + 0x1000);
DEBUG("Stack trace:\n");
while (sp < spEnd) {
DEBUG("\t%016lx\n", *--sp);
}
}*/
#else #else
(void)frame; (void)frame;
(void)sameEl; (void)sameEl;

View file

@ -43,7 +43,7 @@
#include "../watchpoints.h" #include "../watchpoints.h"
static TEMPORARY char g_gdbWorkBuffer[GDB_WORK_BUF_LEN]; static TEMPORARY char g_gdbWorkBuffer[GDB_WORK_BUF_LEN];
static TEMPORARY char g_gdbBuffer[GDB_BUF_LEN + 4]; static TEMPORARY char g_gdbBuffer[GDB_BUF_LEN + 4 + 1];
static const struct{ static const struct{
char command; char command;

View file

@ -236,11 +236,14 @@ int GDB_ReceivePacket(GDBContext *ctx)
ctx->state = GDB_STATE_ATTACHED; ctx->state = GDB_STATE_ATTACHED;
} }
DEBUGRAW("->");
DEBUGRAW(ctx->buffer);
DEBUGRAW("\n");
// Set helper attributes, change '#' to NUL // Set helper attributes, change '#' to NUL
ctx->commandData = ctx->buffer + 2; ctx->commandData = ctx->buffer + 2;
ctx->commandEnd = ctx->buffer + delimPos; ctx->commandEnd = ctx->buffer + delimPos;
ctx->buffer[delimPos] = '\0'; ctx->buffer[delimPos] = '\0';
DEBUG("Packet: %s\n", ctx->buffer + 1);
return (int)(delimPos + 2); return (int)(delimPos + 2);
} }
@ -249,6 +252,13 @@ static int GDB_DoSendPacket(GDBContext *ctx, size_t len)
{ {
transportInterfaceWriteData(ctx->transportInterface, ctx->buffer, len); transportInterfaceWriteData(ctx->transportInterface, ctx->buffer, len);
ctx->lastSentPacketSize = len; ctx->lastSentPacketSize = len;
// Debugging:
ctx->buffer[len] = 0;
DEBUGRAW("<-");
DEBUGRAW(ctx->buffer);
DEBUGRAW("\n");
return (int)len; return (int)len;
} }