Skip to content

Commit b0593e9

Browse files
committed
[DAP] Code stepping
1 parent 489a700 commit b0593e9

File tree

1 file changed

+88
-11
lines changed

1 file changed

+88
-11
lines changed

src/dap.cc

Lines changed: 88 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,15 @@ void dap_event_stopped(int stop_reason, uint32_t addr) {
294294
void dap_event_continued(void) {
295295
LOG_INFO(DAP_INFO, "dap_event_continued() called");
296296

297-
#if defined(__EMSCRIPTEN__)
298-
dap_js_event_continued();
299-
#endif
297+
if (state.session) {
298+
auto sess = static_cast<dap::Session*>(state.session);
299+
300+
// Notify UI about continued event
301+
dap::ContinuedEvent continuedEvent;
302+
continuedEvent.threadId = threadId;
303+
continuedEvent.allThreadsContinued = true;
304+
sess->send(continuedEvent);
305+
}
300306
}
301307

302308
void dap_event_reboot(void) {
@@ -319,6 +325,11 @@ void dap_event_reset(void) {
319325

320326
static bool do_dap_boot = false;
321327
static bool do_send_thread_info = false;
328+
static bool do_dap_reset = false;
329+
static bool do_dap_pause = false;
330+
static bool do_dap_run = false;
331+
static bool do_dap_stepForward = false;
332+
static bool do_dap_stepIn = false;
322333

323334
std::mutex dap_breakpoints_update_mutex;
324335
static std::map<dap::integer, std::vector<uint32_t>> dap_breakpoints = {};
@@ -551,11 +562,9 @@ void dap_register_session(dap::Session* session) {
551562
response.supportTerminateDebuggee = true;
552563
response.supportsRestartRequest = true;
553564
response.supportSuspendDebuggee = true;
554-
response.supportsValueFormattingOptions = true;
555565
response.supportsReadMemoryRequest = true;
556566
response.supportsWriteMemoryRequest = false;
557567
response.supportsDisassembleRequest = true;
558-
response.supportsStepInTargetsRequest = true;
559568
return response;
560569
});
561570

@@ -595,7 +604,7 @@ void dap_register_session(dap::Session* session) {
595604
const bool restart = request.restart.value(false);
596605
LOG_INFO(DAP_INFO, "%s request", restart ? "Restart" : "Terminate");
597606
if (restart) {
598-
dap_reset();
607+
do_dap_reset = true;
599608
}
600609
else {
601610
sapp_request_quit();
@@ -607,7 +616,7 @@ void dap_register_session(dap::Session* session) {
607616
// https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Restart
608617
session->registerHandler([&](const dap::RestartRequest&) {
609618
LOG_INFO(DAP_INFO, "Restart request");
610-
dap_reset();
619+
do_dap_reset = true;
611620
return dap::RestartResponse();
612621
});
613622

@@ -751,10 +760,6 @@ void dap_register_session(dap::Session* session) {
751760
// The Variables request reports all the variables for the given scope.
752761
// https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Variables
753762
session->registerHandler([&](const dap::VariablesRequest& request) -> dap::ResponseOrError<dap::VariablesResponse> {
754-
char buffer[20];
755-
webapi_cpu_state_t cpu_state = state.funcs.dbg_cpu_state();
756-
assert(cpu_state.items[WEBAPI_CPUSTATE_TYPE] == WEBAPI_CPUTYPE_65816);
757-
758763
dap::VariablesResponse response;
759764

760765
switch (request.variablesReference) {
@@ -776,6 +781,9 @@ void dap_register_session(dap::Session* session) {
776781
break;
777782
}
778783
case registerPVariablesReferenceId: {
784+
webapi_cpu_state_t cpu_state = state.funcs.dbg_cpu_state();
785+
assert(cpu_state.items[WEBAPI_CPUSTATE_TYPE] == WEBAPI_CPUTYPE_65816);
786+
779787
response.variables.push_back(evaluateVariable("flag.C"));
780788
response.variables.push_back(evaluateVariable("flag.Z"));
781789
response.variables.push_back(evaluateVariable("flag.I"));
@@ -816,6 +824,45 @@ void dap_register_session(dap::Session* session) {
816824

817825
return dap::Error("Unknown expression");
818826
});
827+
828+
// The Pause request instructs the debugger to pause execution of one or all
829+
// threads.
830+
// https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Pause
831+
session->registerHandler([&](const dap::PauseRequest&) {
832+
do_dap_pause = true;
833+
return dap::PauseResponse();
834+
});
835+
836+
// The Continue request instructs the debugger to resume execution of one or
837+
// all threads.
838+
// https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Continue
839+
session->registerHandler([&](const dap::ContinueRequest&) {
840+
do_dap_run = true;
841+
return dap::ContinueResponse();
842+
});
843+
844+
// The Next request instructs the debugger to single line step for a specific
845+
// thread.
846+
// https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Next
847+
session->registerHandler([&](const dap::NextRequest&) {
848+
do_dap_stepForward = true;
849+
return dap::NextResponse();
850+
});
851+
852+
// The StepIn request instructs the debugger to step-in for a specific thread.
853+
// https://microsoft.github.io/debug-adapter-protocol/specification#Requests_StepIn
854+
session->registerHandler([&](const dap::StepInRequest&) {
855+
do_dap_stepIn = true;
856+
return dap::StepInResponse();
857+
});
858+
859+
// The StepOut request instructs the debugger to step-out for a specific
860+
// thread.
861+
// https://microsoft.github.io/debug-adapter-protocol/specification#Requests_StepOut
862+
session->registerHandler([&](const dap::StepOutRequest&) {
863+
// Step-out is not supported.
864+
return dap::Error("Step-out is not supported");
865+
});
819866
}
820867

821868
void dap_init(const dap_desc_t* desc) {
@@ -964,6 +1011,36 @@ void dap_process() {
9641011
do_send_thread_info = true;
9651012
}
9661013

1014+
if (do_dap_reset) {
1015+
do_dap_reset = false;
1016+
1017+
dap_reset();
1018+
}
1019+
1020+
if (do_dap_pause) {
1021+
do_dap_pause = false;
1022+
1023+
dap_dbg_break();
1024+
}
1025+
1026+
if (do_dap_run) {
1027+
do_dap_run = false;
1028+
1029+
dap_dbg_continue();
1030+
}
1031+
1032+
if (do_dap_stepForward) {
1033+
do_dap_stepForward = false;
1034+
1035+
dap_dbg_step_next();
1036+
}
1037+
1038+
if (do_dap_stepIn) {
1039+
do_dap_stepIn = false;
1040+
1041+
dap_dbg_step_into();
1042+
}
1043+
9671044
while (!dap_breakpoints_update.empty()) {
9681045
dap::integer source;
9691046
std::vector<uint32_t> add_addresses;

0 commit comments

Comments
 (0)