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