thermosphere: add more debugging strings

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

View file

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

View file

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

View file

@ -74,7 +74,15 @@ void dumpStackFrame(const ExceptionStackFrame *frame, bool sameEl)
if (frame == currentCoreCtx->guestFrame) {
DEBUG("cntp_ctl_el0\t%016llx\n", frame->cntp_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
(void)frame;
(void)sameEl;

View file

@ -43,7 +43,7 @@
#include "../watchpoints.h"
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{
char command;

View file

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