diff --git a/arm9/source/main.c b/arm9/source/main.c index 00d4092..5221361 100644 --- a/arm9/source/main.c +++ b/arm9/source/main.c @@ -119,7 +119,6 @@ void main(int argc, char **argv, u32 magicWord) I2C_init(); if(isInvalidLoader) error("Launched using an unsupported loader."); - detectAndProcessExceptionDumps(); installArm9Handlers(); if(memcmp(launchedPath, u"sdmc", 8) == 0) @@ -157,6 +156,8 @@ void main(int argc, char **argv, u32 magicWord) error("Launched from an unsupported location: %s.", mountPoint); } + detectAndProcessExceptionDumps(); + //Attempt to read the configuration file needConfig = readConfig() ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION; diff --git a/sysmodules/loader/source/hbldr.c b/sysmodules/loader/source/hbldr.c index 6820507..db222c8 100644 --- a/sysmodules/loader/source/hbldr.c +++ b/sysmodules/loader/source/hbldr.c @@ -80,5 +80,18 @@ Result HBLDR_PatchExHeaderInfo(ExHeader_Info *exheaderInfo) Result rc = svcSendSyncRequest(hbldrHandle); if (R_SUCCEEDED(rc)) rc = cmdbuf[1]; + return rc; +} + +Result HBLDR_DebugNextApplicationByForce(bool dryRun) +{ + u32* cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = IPC_MakeHeader(5, 1, 0); // 0x50040 + cmdbuf[1] = dryRun ? 1 : 0; + + Result rc = svcSendSyncRequest(hbldrHandle); + if (R_SUCCEEDED(rc)) rc = cmdbuf[1]; + return rc; } \ No newline at end of file diff --git a/sysmodules/loader/source/hbldr.h b/sysmodules/loader/source/hbldr.h index cdec83a..34e22c4 100644 --- a/sysmodules/loader/source/hbldr.h +++ b/sysmodules/loader/source/hbldr.h @@ -11,3 +11,4 @@ Result HBLDR_LoadProcess(Handle *outCodeSet, u32 textAddr, u32 kernelFlags, u64 Result HBLDR_SetTarget(const char* path); Result HBLDR_SetArgv(const void* buffer, size_t size); Result HBLDR_PatchExHeaderInfo(ExHeader_Info *exheaderInfo); +Result HBLDR_DebugNextApplicationByForce(bool dryRun); diff --git a/sysmodules/rosalina/source/hbloader.c b/sysmodules/rosalina/source/hbloader.c index fbe6047..a043e67 100644 --- a/sysmodules/rosalina/source/hbloader.c +++ b/sysmodules/rosalina/source/hbloader.c @@ -318,30 +318,33 @@ void HBLDR_HandleCommands(void *ctx) case 5: // DebugNextApplicationByForce { res = 0; - GDB_LockAllContexts(&gdbServer); - if (nextApplicationGdbCtx != NULL) - res = MAKERESULT(RL_PERMANENT, RS_NOP, RM_LDR, RD_ALREADY_DONE); - else if (gdbServer.referenceCount == 0) + if (gdbServer.referenceCount == 0) res = MAKERESULT(RL_PERMANENT, RS_INVALIDSTATE, RM_LDR, RD_NOT_INITIALIZED); - else + else if (cmdbuf[1] == 0) { - nextApplicationGdbCtx = GDB_SelectAvailableContext(&gdbServer, GDB_PORT_BASE + 3, GDB_PORT_BASE + 4); + GDB_LockAllContexts(&gdbServer); if (nextApplicationGdbCtx != NULL) - { - nextApplicationGdbCtx->debug = 0; - nextApplicationGdbCtx->pid = 0xFFFFFFFF; - res = PMDBG_DebugNextApplicationByForce(); - if (R_FAILED(res)) - { - nextApplicationGdbCtx->flags = 0; - nextApplicationGdbCtx->localPort = 0; - nextApplicationGdbCtx = NULL; - } - } + res = MAKERESULT(RL_PERMANENT, RS_NOP, RM_LDR, RD_ALREADY_DONE); else - res = MAKERESULT(RL_PERMANENT, RS_OUTOFRESOURCE, RM_LDR, RD_OUT_OF_RANGE); + { + nextApplicationGdbCtx = GDB_SelectAvailableContext(&gdbServer, GDB_PORT_BASE + 3, GDB_PORT_BASE + 4); + if (nextApplicationGdbCtx != NULL) + { + nextApplicationGdbCtx->debug = 0; + nextApplicationGdbCtx->pid = 0xFFFFFFFF; + res = PMDBG_DebugNextApplicationByForce(); + if (R_FAILED(res)) + { + nextApplicationGdbCtx->flags = 0; + nextApplicationGdbCtx->localPort = 0; + nextApplicationGdbCtx = NULL; + } + } + else + res = MAKERESULT(RL_PERMANENT, RS_OUTOFRESOURCE, RM_LDR, RD_OUT_OF_RANGE); + } + GDB_UnlockAllContexts(&gdbServer); } - GDB_UnlockAllContexts(&gdbServer); cmdbuf[1] = res; cmdbuf[0] = IPC_MakeHeader(5, 1, 0); break; diff --git a/sysmodules/rosalina/source/menus/debugger.c b/sysmodules/rosalina/source/menus/debugger.c index fc0d078..1759b96 100644 --- a/sysmodules/rosalina/source/menus/debugger.c +++ b/sysmodules/rosalina/source/menus/debugger.c @@ -174,34 +174,37 @@ void DebuggerMenu_DebugNextApplicationByForce(void) Result res = 0; char buf[256]; - GDB_LockAllContexts(&gdbServer); - - if (nextApplicationGdbCtx != NULL) - strcpy(buf, "Operation already performed."); - else if(initialized) + if(initialized) { - nextApplicationGdbCtx = GDB_SelectAvailableContext(&gdbServer, GDB_PORT_BASE + 3, GDB_PORT_BASE + 4); + GDB_LockAllContexts(&gdbServer); + if (nextApplicationGdbCtx != NULL) - { - nextApplicationGdbCtx->debug = 0; - nextApplicationGdbCtx->pid = 0xFFFFFFFF; - res = PMDBG_DebugNextApplicationByForce(); - if(R_SUCCEEDED(res)) - sprintf(buf, "Operation succeeded.\nUse port %d to connect to the next launched\napplication.", nextApplicationGdbCtx->localPort); - else - { - nextApplicationGdbCtx->flags = 0; - nextApplicationGdbCtx->localPort = 0; - nextApplicationGdbCtx = NULL; - sprintf(buf, "Operation failed (0x%08lx).", (u32)res); - } - } + strcpy(buf, "Operation already performed."); else - strcpy(buf, "Failed to allocate a slot.\nPlease unselect a process in the process list first"); + { + nextApplicationGdbCtx = GDB_SelectAvailableContext(&gdbServer, GDB_PORT_BASE + 3, GDB_PORT_BASE + 4); + if (nextApplicationGdbCtx != NULL) + { + nextApplicationGdbCtx->debug = 0; + nextApplicationGdbCtx->pid = 0xFFFFFFFF; + res = PMDBG_DebugNextApplicationByForce(); + if(R_SUCCEEDED(res)) + sprintf(buf, "Operation succeeded.\nUse port %d to connect to the next launched\napplication.", nextApplicationGdbCtx->localPort); + else + { + nextApplicationGdbCtx->flags = 0; + nextApplicationGdbCtx->localPort = 0; + nextApplicationGdbCtx = NULL; + sprintf(buf, "Operation failed (0x%08lx).", (u32)res); + } + } + else + strcpy(buf, "Failed to allocate a slot.\nPlease unselect a process in the process list first"); + } + GDB_UnlockAllContexts(&gdbServer); } else strcpy(buf, "Debugger not enabled."); - GDB_UnlockAllContexts(&gdbServer); do {