Continuing with remedybg integration
This commit is contained in:
@@ -2099,15 +2099,15 @@ void DebugEventsSample(char* server_name)
|
||||
|
||||
uint8_t command_buf[COMMAND_BUF_SIZE];
|
||||
uint8_t reply_buf[REPLY_BUF_SIZE];
|
||||
ClientContext RDB_Ctx;
|
||||
ClientContext RDBG_Ctx;
|
||||
|
||||
|
||||
bool RDB_InitConnection() {
|
||||
bool RDBG_InitConnection() {
|
||||
enum rdbg_CommandResult res;
|
||||
if (RDB_Ctx.command_pipe_handle != NULL) {
|
||||
if (RDBG_Ctx.command_pipe_handle != NULL) {
|
||||
enum rdbg_TargetState state;
|
||||
GetTargetState(&RDB_Ctx, &res, &state);
|
||||
if (!ContextHadError(&RDB_Ctx)) {
|
||||
GetTargetState(&RDBG_Ctx, &res, &state);
|
||||
if (!ContextHadError(&RDBG_Ctx)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -2115,134 +2115,149 @@ bool RDB_InitConnection() {
|
||||
String session_name = Format(scratch, "te%llu", GetTimeNanos());
|
||||
String remedy_string = Format(scratch, "%S --servername %S", RemedyBGPath, session_name);
|
||||
Exec(NullViewID, true, remedy_string, GetMainDir());
|
||||
MemoryZero(&RDB_Ctx, sizeof(RDB_Ctx));
|
||||
RDB_Ctx.cmd.data = command_buf;
|
||||
RDB_Ctx.cmd.capacity = sizeof(command_buf);
|
||||
RDB_Ctx.reply.data = reply_buf;
|
||||
RDB_Ctx.reply.capacity = sizeof(reply_buf);
|
||||
RDB_Ctx.dbg_target_behavior = RDBG_IF_DEBUGGING_TARGET_STOP_DEBUGGING;
|
||||
RDB_Ctx.mod_session_behavior = RDBG_IF_SESSION_IS_MODIFIED_CONTINUE_WITHOUT_SAVING;
|
||||
RDB_Ctx.last_error[0] = 0;
|
||||
MemoryZero(&RDBG_Ctx, sizeof(RDBG_Ctx));
|
||||
RDBG_Ctx.cmd.data = command_buf;
|
||||
RDBG_Ctx.cmd.capacity = sizeof(command_buf);
|
||||
RDBG_Ctx.reply.data = reply_buf;
|
||||
RDBG_Ctx.reply.capacity = sizeof(reply_buf);
|
||||
RDBG_Ctx.dbg_target_behavior = RDBG_IF_DEBUGGING_TARGET_STOP_DEBUGGING;
|
||||
RDBG_Ctx.mod_session_behavior = RDBG_IF_SESSION_IS_MODIFIED_CONTINUE_WITHOUT_SAVING;
|
||||
RDBG_Ctx.last_error[0] = 0;
|
||||
|
||||
bool result = false;
|
||||
for (int i = 0; i < 64; i += 1) {
|
||||
Sleep(10);
|
||||
result = InitConnection(session_name.data, DebugControlPipe, sizeof(RDB_Ctx.last_error), RDB_Ctx.last_error, &RDB_Ctx.command_pipe_handle);
|
||||
result = InitConnection(session_name.data, DebugControlPipe, sizeof(RDBG_Ctx.last_error), RDBG_Ctx.last_error, &RDBG_Ctx.command_pipe_handle);
|
||||
if (result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (result == false) {
|
||||
ReportErrorf("Remedy error: %s", RDB_Ctx.last_error);
|
||||
RDB_Ctx = {};
|
||||
ReportErrorf("Remedy error: %s", RDBG_Ctx.last_error);
|
||||
RDBG_Ctx = {};
|
||||
return false;
|
||||
}
|
||||
MemoryZero(RDB_Ctx.last_error, sizeof(RDB_Ctx.last_error));
|
||||
MemoryZero(RDBG_Ctx.last_error, sizeof(RDBG_Ctx.last_error));
|
||||
|
||||
rdbg_Id cfg_id;
|
||||
char *exe = BinaryUnderDebug.data;
|
||||
char *exe = Format(scratch, "%S/%S", WorkDir, BinaryUnderDebug).data;
|
||||
char *args = NULL;
|
||||
char *work_dir = WorkDir.data;
|
||||
char *env = NULL;
|
||||
AddSessionConfig(&RDB_Ctx, exe, args, work_dir, env, true, true, &res, &cfg_id);
|
||||
if (ContextHadError(&RDB_Ctx)) {
|
||||
ReportErrorf("Remedy error: %s", RDB_Ctx.last_error);
|
||||
MemoryZero(RDB_Ctx.last_error, sizeof(RDB_Ctx.last_error));
|
||||
AddSessionConfig(&RDBG_Ctx, exe, args, work_dir, env, true, true, &res, &cfg_id);
|
||||
if (ContextHadError(&RDBG_Ctx)) {
|
||||
ReportErrorf("Remedy error: %s", RDBG_Ctx.last_error);
|
||||
MemoryZero(RDBG_Ctx.last_error, sizeof(RDBG_Ctx.last_error));
|
||||
return true;
|
||||
}
|
||||
|
||||
SetActiveSessionConfig(&RDB_Ctx, cfg_id, &res);
|
||||
if (ContextHadError(&RDB_Ctx)) {
|
||||
ReportErrorf("Remedy error: %s", RDB_Ctx.last_error);
|
||||
MemoryZero(RDB_Ctx.last_error, sizeof(RDB_Ctx.last_error));
|
||||
SetActiveSessionConfig(&RDBG_Ctx, cfg_id, &res);
|
||||
if (ContextHadError(&RDBG_Ctx)) {
|
||||
ReportErrorf("Remedy error: %s", RDBG_Ctx.last_error);
|
||||
MemoryZero(RDBG_Ctx.last_error, sizeof(RDBG_Ctx.last_error));
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This should continue execution if stopped @todo:
|
||||
void CMD_StartDebugging(HookParam param) {
|
||||
bool conn = RDB_InitConnection();
|
||||
bool conn = RDBG_InitConnection();
|
||||
if (!conn) {
|
||||
return;
|
||||
}
|
||||
|
||||
enum rdbg_CommandResult res;
|
||||
enum rdbg_TargetState state;
|
||||
GetTargetState(&RDB_Ctx, &res, &state);
|
||||
if (ContextHadError(&RDB_Ctx)) {
|
||||
ReportErrorf("Remedy error: %s", RDB_Ctx.last_error);
|
||||
MemoryZero(RDB_Ctx.last_error, sizeof(RDB_Ctx.last_error));
|
||||
GetTargetState(&RDBG_Ctx, &res, &state);
|
||||
if (ContextHadError(&RDBG_Ctx)) {
|
||||
ReportErrorf("Remedy error: %s", RDBG_Ctx.last_error);
|
||||
MemoryZero(RDBG_Ctx.last_error, sizeof(RDBG_Ctx.last_error));
|
||||
return;
|
||||
}
|
||||
|
||||
if (state == RDBG_TARGET_STATE_NONE) {
|
||||
StartDebugging(&RDB_Ctx, false, &res);
|
||||
if (ContextHadError(&RDB_Ctx)) {
|
||||
ReportErrorf("Remedy error: %s", RDB_Ctx.last_error);
|
||||
MemoryZero(RDB_Ctx.last_error, sizeof(RDB_Ctx.last_error));
|
||||
StartDebugging(&RDBG_Ctx, false, &res);
|
||||
if (ContextHadError(&RDBG_Ctx)) {
|
||||
ReportErrorf("Remedy error: %s", RDBG_Ctx.last_error);
|
||||
MemoryZero(RDBG_Ctx.last_error, sizeof(RDBG_Ctx.last_error));
|
||||
return;
|
||||
}
|
||||
} else if (state == RDBG_TARGET_STATE_SUSPENDED) {
|
||||
ContinueExecution(&RDB_Ctx, &res);
|
||||
if (ContextHadError(&RDB_Ctx)) {
|
||||
ReportErrorf("Remedy error: %s", RDB_Ctx.last_error);
|
||||
MemoryZero(RDB_Ctx.last_error, sizeof(RDB_Ctx.last_error));
|
||||
ContinueExecution(&RDBG_Ctx, &res);
|
||||
if (ContextHadError(&RDBG_Ctx)) {
|
||||
ReportErrorf("Remedy error: %s", RDBG_Ctx.last_error);
|
||||
MemoryZero(RDBG_Ctx.last_error, sizeof(RDBG_Ctx.last_error));
|
||||
return;
|
||||
}
|
||||
}
|
||||
BringDebuggerToForeground(&RDB_Ctx, &res);
|
||||
if (ContextHadError(&RDB_Ctx)) {
|
||||
ReportErrorf("Remedy error: %s", RDB_Ctx.last_error);
|
||||
MemoryZero(RDB_Ctx.last_error, sizeof(RDB_Ctx.last_error));
|
||||
BringDebuggerToForeground(&RDBG_Ctx, &res);
|
||||
if (ContextHadError(&RDBG_Ctx)) {
|
||||
ReportErrorf("Remedy error: %s", RDBG_Ctx.last_error);
|
||||
MemoryZero(RDBG_Ctx.last_error, sizeof(RDBG_Ctx.last_error));
|
||||
return;
|
||||
}
|
||||
} RegisterCommand(CMD_StartDebugging, "f5", "Start debugging, if debugger not active it starts it, uses BinaryUnderDebug");
|
||||
|
||||
void CMD_RunToLineInDebugger(HookParam param) {
|
||||
bool conn = RDB_InitConnection();
|
||||
bool conn = RDBG_InitConnection();
|
||||
if (!conn) {
|
||||
return;
|
||||
}
|
||||
|
||||
BSet prim = GetBSet(PrimaryWindowID);
|
||||
|
||||
enum rdbg_CommandResult res;
|
||||
Int line = PosToLine(prim.buffer, GetFront(prim.view->carets[0]));
|
||||
RunToFileAtLine(&RDB_Ctx, prim.buffer->name.data, (uint32_t)line + 1, &res);
|
||||
RunToFileAtLine(&RDBG_Ctx, prim.buffer->name.data, (uint32_t)line + 1, &res);
|
||||
if (res != RDBG_COMMAND_RESULT_OK) {
|
||||
ReportErrorf("Remedy error: %s", RDB_Ctx.last_error);
|
||||
MemoryZero(RDB_Ctx.last_error, sizeof(RDB_Ctx.last_error));
|
||||
ReportErrorf("Remedy error: %s", RDBG_Ctx.last_error);
|
||||
MemoryZero(RDBG_Ctx.last_error, sizeof(RDBG_Ctx.last_error));
|
||||
return;
|
||||
}
|
||||
} RegisterCommand(CMD_RunToLineInDebugger, "ctrl-f10", "Instruct debugger to execute until line and column under caret");
|
||||
|
||||
void CMD_StopDebugging(HookParam param) {
|
||||
bool conn = RDB_InitConnection();
|
||||
bool conn = RDBG_InitConnection();
|
||||
if (!conn) {
|
||||
return;
|
||||
}
|
||||
|
||||
enum rdbg_CommandResult res;
|
||||
StopDebugging(&RDB_Ctx, &res);
|
||||
StopDebugging(&RDBG_Ctx, &res);
|
||||
if (res != RDBG_COMMAND_RESULT_OK) {
|
||||
ReportErrorf("Remedy error: %s", RDB_Ctx.last_error);
|
||||
MemoryZero(RDB_Ctx.last_error, sizeof(RDB_Ctx.last_error));
|
||||
ReportErrorf("Remedy error: %s", RDBG_Ctx.last_error);
|
||||
MemoryZero(RDBG_Ctx.last_error, sizeof(RDBG_Ctx.last_error));
|
||||
return;
|
||||
}
|
||||
} RegisterCommand(CMD_StopDebugging, "shift-f5", "Stop debugging");
|
||||
|
||||
void CMD_AddBreakpoint(HookParam param) {
|
||||
if (!RDBG_InitConnection()) {
|
||||
return;
|
||||
}
|
||||
|
||||
BSet prim = GetBSet(PrimaryWindowID);
|
||||
Int line = PosToLine(prim.buffer, GetFront(prim.view->carets[0]));
|
||||
enum rdbg_CommandResult res;
|
||||
rdbg_Id bp_id;
|
||||
AddBreakpointAtFilenameLine(&RDBG_Ctx, prim.buffer->name.data, (uint32_t)line + 1, "", &res, &bp_id);
|
||||
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;
|
||||
}
|
||||
} RegisterCommand(CMD_AddBreakpoint, "f9", "Add a breakpoint at filename + line");
|
||||
|
||||
void HOOK_QuitDebugger(HookParam param) {
|
||||
bool conn = RDB_InitConnection();
|
||||
bool conn = RDBG_InitConnection();
|
||||
if (!conn) {
|
||||
return;
|
||||
}
|
||||
|
||||
enum rdbg_CommandResult res;
|
||||
ExitDebugger(&RDB_Ctx, &res);
|
||||
CloseConnection(&RDB_Ctx);
|
||||
ExitDebugger(&RDBG_Ctx, &res);
|
||||
CloseConnection(&RDBG_Ctx);
|
||||
} RegisterHook(HOOK_QuitDebugger, HookKind_AppQuit, "", "exit the connected debugger");
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user