SelfAttachDebugger command
This commit is contained in:
@@ -2097,7 +2097,8 @@ uint8_t command_buf[COMMAND_BUF_SIZE];
|
||||
uint8_t reply_buf[REPLY_BUF_SIZE];
|
||||
ClientContext RDBG_Ctx;
|
||||
|
||||
bool RDBG_InitConnection(mco_coro *co) {
|
||||
bool RDBG_InitConnection(mco_coro *co, bool create_session = true) {
|
||||
ReportConsolef("Remedybg: InitConnection");
|
||||
enum rdbg_CommandResult res;
|
||||
if (RDBG_Ctx.command_pipe_handle != NULL) {
|
||||
enum rdbg_TargetState state;
|
||||
@@ -2107,30 +2108,9 @@ bool RDBG_InitConnection(mco_coro *co) {
|
||||
}
|
||||
}
|
||||
|
||||
String file = "";
|
||||
if (BinaryUnderDebug.len) {
|
||||
Window *window = GetWindow(PrimaryWindowID);
|
||||
ResolvedOpen res = ResolveOpen(CoCurr->arena, window, BinaryUnderDebug, ResolveOpenMeta_DontError | ResolveOpenMeta_DontExec);
|
||||
if (res.kind == OpenKind_Goto) {
|
||||
file = Intern(&GlobalInternTable, res.path);
|
||||
}
|
||||
}
|
||||
|
||||
if (file.len == 0) {
|
||||
Scratch scratch;
|
||||
for (FileIter it = IterateFiles(scratch, ProjectDirectory); IsValid(it); Advance(&it)) {
|
||||
if (EndsWith(it.filename, ".rdbg")) {
|
||||
file = Intern(&GlobalInternTable, it.absolute_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (file.len == 0) {
|
||||
file = QueryUserFile(co);
|
||||
}
|
||||
|
||||
String session_name = Format(CoCurr->arena, "te%llu", GetTimeNanos());
|
||||
String remedy_string = Format(CoCurr->arena, "%S --servername %S", RemedyBGPath, session_name);
|
||||
ReportConsolef("Remedybg: %S", remedy_string);
|
||||
Exec(LogViewID, true, remedy_string, GetPrimaryDirectory());
|
||||
MemoryZero(&RDBG_Ctx, sizeof(RDBG_Ctx));
|
||||
RDBG_Ctx.cmd.data = command_buf;
|
||||
@@ -2157,9 +2137,37 @@ bool RDBG_InitConnection(mco_coro *co) {
|
||||
}
|
||||
MemoryZero(RDBG_Ctx.last_error, sizeof(RDBG_Ctx.last_error));
|
||||
|
||||
if (create_session == false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String file = "";
|
||||
if (BinaryUnderDebug.len) {
|
||||
Window *window = GetWindow(PrimaryWindowID);
|
||||
ResolvedOpen res = ResolveOpen(CoCurr->arena, window, BinaryUnderDebug, ResolveOpenMeta_DontError | ResolveOpenMeta_DontExec);
|
||||
if (res.kind == OpenKind_Goto) {
|
||||
file = Intern(&GlobalInternTable, res.path);
|
||||
}
|
||||
}
|
||||
|
||||
if (file.len == 0) {
|
||||
Scratch scratch;
|
||||
for (FileIter it = IterateFiles(scratch, ProjectDirectory); IsValid(it); Advance(&it)) {
|
||||
if (EndsWith(it.filename, ".rdbg")) {
|
||||
file = Intern(&GlobalInternTable, it.absolute_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (file.len == 0) {
|
||||
file = QueryUserFile(co);
|
||||
}
|
||||
|
||||
if (EndsWith(file, ".rdbg")) {
|
||||
ReportConsolef("Remedybg: OpenSession %S", file);
|
||||
OpenSession(&RDBG_Ctx, file.data, &res);
|
||||
} else {
|
||||
ReportConsolef("Remedybg: CreateSession %S", file);
|
||||
rdbg_Id cfg_id;
|
||||
char *exe = file.data;
|
||||
char *args = NULL;
|
||||
@@ -2179,7 +2187,6 @@ bool RDBG_InitConnection(mco_coro *co) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2270,6 +2277,20 @@ void CO_AddBreakpoint(mco_coro *co) {
|
||||
}
|
||||
} RegisterCoroutineCommand(CO_AddBreakpoint, "f9", "Add a breakpoint at filename + line");
|
||||
|
||||
void CO_SelfAttachDebugger(mco_coro *co) {
|
||||
bool conn = RDBG_InitConnection(co, false);
|
||||
if (!conn) {
|
||||
return;
|
||||
}
|
||||
enum rdbg_CommandResult res;
|
||||
AttachToProcessById(&RDBG_Ctx, GetCurrentProcessId(), true, &res);
|
||||
if (res != RDBG_COMMAND_RESULT_OK) {
|
||||
ReportErrorf("Remedy error: %s", RDBG_Ctx.last_error);
|
||||
MemoryZero(RDBG_Ctx.last_error, sizeof(RDBG_Ctx.last_error));
|
||||
return;
|
||||
}
|
||||
} RegisterCoroutineCommand(CO_SelfAttachDebugger, "f9", "Spawn and self attach the debugger to the text editor");
|
||||
|
||||
void QuitDebugger() {
|
||||
if (RDBG_Ctx.command_pipe_handle == NULL) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user