diff --git a/src/DebugServer/Gdb/AvrGdb/AvrGdbRsp.cpp b/src/DebugServer/Gdb/AvrGdb/AvrGdbRsp.cpp index 64df2aee..840bccea 100644 --- a/src/DebugServer/Gdb/AvrGdb/AvrGdbRsp.cpp +++ b/src/DebugServer/Gdb/AvrGdb/AvrGdbRsp.cpp @@ -176,7 +176,8 @@ namespace DebugServer::Gdb::AvrGdb * The target stopped due to an intercepting breakpoint, but we're still within the stepping range, * which can only mean that we weren't sure where this instruction would lead to. * - * We must perform a single step and see what happens. + * We must perform a single step and see what happens. If the instruction takes us out of the stepping + * range, we'll end the session and report back to GDB. */ Logger::debug("Reached intercepting breakpoint within stepping range"); Logger::debug("Attempting single step from 0x" + StringService::toHex(programAddress)); @@ -191,7 +192,7 @@ namespace DebugServer::Gdb::AvrGdb * We performed a single step once and we're still within the stepping range, so we're good to * continue the range stepping session. */ - Logger::debug("Completed single step from an intercepted address - PC still within stepping range"); + Logger::debug("Completed single step - PC still within stepping range"); Logger::debug("Continuing range stepping"); activeRangeSteppingSession->singleStepping = false; diff --git a/src/DebugServer/Gdb/AvrGdb/CommandPackets/VContRangeStep.cpp b/src/DebugServer/Gdb/AvrGdb/CommandPackets/VContRangeStep.cpp index b1ab4f72..4b6e80ae 100644 --- a/src/DebugServer/Gdb/AvrGdb/CommandPackets/VContRangeStep.cpp +++ b/src/DebugServer/Gdb/AvrGdb/CommandPackets/VContRangeStep.cpp @@ -205,7 +205,16 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets } debugSession.startRangeSteppingSession(std::move(rangeSteppingSession), targetControllerService); - targetControllerService.continueTargetExecution(std::nullopt, std::nullopt); + + /* + * GDB expects us to start the range stepping session with a single step, and then only continue if the + * single step didn't immediately take us out of the stepping range. + * + * So we kick off a single step here, then let AvrGdbRsp::handleTargetStoppedGdbResponse() determine if + * we should continue. See that member function for more. + */ + debugSession.activeRangeSteppingSession->singleStepping = true; + targetControllerService.stepTargetExecution(std::nullopt); debugSession.waitingForBreak = true; } catch (const Exception& exception) { diff --git a/src/DebugServer/Gdb/RangeSteppingSession.hpp b/src/DebugServer/Gdb/RangeSteppingSession.hpp index ffbb2aa9..fdb136df 100644 --- a/src/DebugServer/Gdb/RangeSteppingSession.hpp +++ b/src/DebugServer/Gdb/RangeSteppingSession.hpp @@ -28,8 +28,8 @@ namespace DebugServer::Gdb std::set interceptedAddresses; /** - * Whether we're currently performing a single step, in this session, to observe the behaviour of a particular - * instruction. + * Whether we're currently performing a single step, in this session, to start the session or observe the + * behaviour of a particular instruction. * * See AvrGdbRsp::handleTargetStoppedGdbResponse() for more. */