Failed attempt w/ next app

This commit is contained in:
TuxSH 2019-06-14 01:32:50 +02:00
parent 84c5cf0661
commit d989c45c3d
9 changed files with 36 additions and 13 deletions

View File

@ -516,9 +516,9 @@ Result autolaunchSysmodules(void)
} }
// Custom // Custom
Result DebugNextApplicationByForce(void) Result DebugNextApplicationByForce(bool debug)
{ {
g_debugNextApplication = true; g_debugNextApplication = debug;
return 0; return 0;
} }

View File

@ -13,5 +13,5 @@ Result LaunchAppDebug(Handle *outDebug, const FS_ProgramInfo *programInfo, u32 l
Result autolaunchSysmodules(void); Result autolaunchSysmodules(void);
// Custom // Custom
Result DebugNextApplicationByForce(void); Result DebugNextApplicationByForce(bool debug);
Result LaunchTitleDebug(Handle *outDebug, const FS_ProgramInfo *programInfo, u32 launchFlags); Result LaunchTitleDebug(Handle *outDebug, const FS_ProgramInfo *programInfo, u32 launchFlags);

View File

@ -48,7 +48,7 @@ void pmDbgHandleCommands(void *ctx)
cmdbuf[4] = pid; cmdbuf[4] = pid;
break; break;
case 0x101: case 0x101:
cmdbuf[1] = DebugNextApplicationByForce(); cmdbuf[1] = DebugNextApplicationByForce(cmdbuf[1] != 0);
cmdbuf[0] = IPC_MakeHeader(0x101, 1, 0); cmdbuf[0] = IPC_MakeHeader(0x101, 1, 0);
break; break;
case 0x102: case 0x102:

View File

@ -7,5 +7,5 @@
#include <3ds/services/pmdbg.h> #include <3ds/services/pmdbg.h>
Result PMDBG_GetCurrentAppTitleIdAndPid(u64 *outTitleId, u32 *outPid); Result PMDBG_GetCurrentAppTitleIdAndPid(u64 *outTitleId, u32 *outPid);
Result PMDBG_DebugNextApplicationByForce(void); Result PMDBG_DebugNextApplicationByForce(bool debug);
Result PMDBG_LaunchTitleDebug(Handle *outDebug, const FS_ProgramInfo *programInfo, u32 launchFlags); Result PMDBG_LaunchTitleDebug(Handle *outDebug, const FS_ProgramInfo *programInfo, u32 launchFlags);

View File

@ -74,4 +74,5 @@ Result server_init(struct sock_server *serv);
void server_bind(struct sock_server *serv, u16 port); void server_bind(struct sock_server *serv, u16 port);
void server_run(struct sock_server *serv); void server_run(struct sock_server *serv);
void server_kill_connections(struct sock_server *serv); void server_kill_connections(struct sock_server *serv);
void server_set_should_close_all(struct sock_server *serv);
void server_finalize(struct sock_server *serv); void server_finalize(struct sock_server *serv);

View File

@ -332,7 +332,7 @@ void HBLDR_HandleCommands(void *ctx)
{ {
nextApplicationGdbCtx->debug = 0; nextApplicationGdbCtx->debug = 0;
nextApplicationGdbCtx->pid = 0xFFFFFFFF; nextApplicationGdbCtx->pid = 0xFFFFFFFF;
res = PMDBG_DebugNextApplicationByForce(); res = PMDBG_DebugNextApplicationByForce(true);
if (R_FAILED(res)) if (R_FAILED(res))
{ {
nextApplicationGdbCtx->flags = 0; nextApplicationGdbCtx->flags = 0;

View File

@ -147,11 +147,23 @@ void DebuggerMenu_DisableDebugger(void)
if(initialized) if(initialized)
{ {
GDB_LockAllContexts(&gdbServer);
svcSignalEvent(gdbServer.super.shall_terminate_event); svcSignalEvent(gdbServer.super.shall_terminate_event);
server_kill_connections(&gdbServer.super); //server_kill_connections(&gdbServer.super);
res = MyThread_Join(&debuggerDebugThread, 5 * 1000 * 1000 * 1000LL); server_set_should_close_all(&gdbServer.super);
GDB_UnlockAllContexts(&gdbServer);
res = MyThread_Join(&debuggerDebugThread, 2 * 1000 * 1000 * 1000LL);
if(res == 0) if(res == 0)
res = MyThread_Join(&debuggerSocketThread, 5 * 1000 * 1000 * 1000LL); res = MyThread_Join(&debuggerSocketThread, 2 * 1000 * 1000 * 1000LL);
Handle dummy = 0;
PMDBG_RunQueuedProcess(&dummy);
svcCloseHandle(dummy);
PMDBG_DebugNextApplicationByForce(false);
nextApplicationGdbCtx = NULL;
svcKernelSetState(0x10000, 2); svcKernelSetState(0x10000, 2);
} }
@ -188,7 +200,7 @@ void DebuggerMenu_DebugNextApplicationByForce(void)
{ {
nextApplicationGdbCtx->debug = 0; nextApplicationGdbCtx->debug = 0;
nextApplicationGdbCtx->pid = 0xFFFFFFFF; nextApplicationGdbCtx->pid = 0xFFFFFFFF;
res = PMDBG_DebugNextApplicationByForce(); res = PMDBG_DebugNextApplicationByForce(true);
if(R_SUCCEEDED(res)) if(R_SUCCEEDED(res))
sprintf(buf, "Operation succeeded.\nUse port %d to connect to the next launched\napplication.", nextApplicationGdbCtx->localPort); sprintf(buf, "Operation succeeded.\nUse port %d to connect to the next launched\napplication.", nextApplicationGdbCtx->localPort);
else else

View File

@ -22,11 +22,12 @@ Result PMDBG_GetCurrentAppTitleIdAndPid(u64 *outTitleId, u32 *outPid)
return cmdbuf[1]; return cmdbuf[1];
} }
Result PMDBG_DebugNextApplicationByForce(void) Result PMDBG_DebugNextApplicationByForce(bool debug)
{ {
Result ret = 0; Result ret = 0;
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x101, 0, 0); cmdbuf[0] = IPC_MakeHeader(0x101, 1, 0);
cmdbuf[1] = (u32)debug;
if(R_FAILED(ret = svcSendSyncRequest(*pmDbgGetSessionHandle()))) return ret; if(R_FAILED(ret = svcSendSyncRequest(*pmDbgGetSessionHandle()))) return ret;
return cmdbuf[1]; return cmdbuf[1];

View File

@ -152,7 +152,6 @@ void server_run(struct sock_server *serv)
serv->running = true; serv->running = true;
svcSignalEvent(serv->started_event); svcSignalEvent(serv->started_event);
while(serv->running && !terminationRequest) while(serv->running && !terminationRequest)
{ {
idx = -1; idx = -1;
@ -205,6 +204,7 @@ void server_run(struct sock_server *serv)
{ {
fds[serv->nfds].fd = client_sockfd; fds[serv->nfds].fd = client_sockfd;
fds[serv->nfds].events = POLLIN; fds[serv->nfds].events = POLLIN;
fds[serv->nfds].revents = 0;
int new_idx = serv->nfds; int new_idx = serv->nfds;
serv->nfds++; serv->nfds++;
@ -215,6 +215,7 @@ void server_run(struct sock_server *serv)
new_ctx->serv = curr_ctx; new_ctx->serv = curr_ctx;
new_ctx->i = new_idx; new_ctx->i = new_idx;
new_ctx->n = 0; new_ctx->n = 0;
new_ctx->should_close = false;
serv->ctx_ptrs[new_idx] = new_ctx; serv->ctx_ptrs[new_idx] = new_ctx;
@ -259,6 +260,14 @@ abort_connections:
svcClearEvent(serv->started_event); svcClearEvent(serv->started_event);
} }
void server_set_should_close_all(struct sock_server *serv)
{
nfds_t nfds = serv->nfds;
for(unsigned int i = 0; i < nfds; i++)
serv->ctx_ptrs[i]->should_close = true;
}
void server_kill_connections(struct sock_server *serv) void server_kill_connections(struct sock_server *serv)
{ {
struct pollfd *fds = serv->poll_fds; struct pollfd *fds = serv->poll_fds;