Skip to content

Commit 21ba9e3

Browse files
authored
add support for the vRun GDB packet
## Purpose Add support for GDB's `vRun` packet to ds2 debug sessions. Fixes issue #150. ## Overview * Override `SessionDelegate::onRunAttach` in `DebugSession`. Use existing `spawnProcess` method to actually launch the process. * Preserve environment variables set on `_spawner` by previous calls to `onSetEnvironmentVariable`. * Preserve previous executable and arguments set on `_spawner` from previous calls to `onRunAttach`. * Update `spawnProcess` to use memoized executable, arguments, and environment when new ones are not provided. * Fix missing `index++` in `Session::Handle_vRun. ## Problem Details The following test cases rely on the `vRun` packet to work properly in the debug session: ``` GdbRemoteLaunchTestCase.test_QEnvironmentHexEncoded_llgs GdbRemoteLaunchTestCase.test_QEnvironment_llgs GdbRemoteLaunchTestCase.test_launch_via_vRun_llgs GdbRemoteLaunchTestCase.test_launch_via_vRun_no_args_llgs ``` ## Validation Combined with PR #143, this change gets all of the `GdbRemoteLaunchTestCase` test cases passing against ds2 running on Linux x86_64.
1 parent 443bb5d commit 21ba9e3

File tree

5 files changed

+44
-17
lines changed

5 files changed

+44
-17
lines changed

Headers/DebugServer2/GDBRemote/DebugSessionImpl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ class DebugSessionImplBase : public DummySessionDelegateImpl {
145145
protected:
146146
ErrorCode onAttach(Session &session, ProcessId pid, AttachMode mode,
147147
StopInfo &stop) override;
148+
ErrorCode onRunAttach(Session &session, std::string const &filename,
149+
StringCollection const &arguments,
150+
StopInfo &stop) override;
148151

149152
protected:
150153
ErrorCode onResume(Session &session,

Headers/DebugServer2/Host/POSIX/ProcessSpawner.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ class ProcessSpawner {
112112
inline ProcessId pid() const { return _pid; }
113113
inline int exitStatus() const { return _exitStatus; }
114114
inline int signalCode() const { return _signalCode; }
115+
inline std::string const &executable() const { return _executablePath; }
116+
inline StringCollection const &arguments() const { return _arguments; }
117+
inline EnvironmentBlock const &environment() const { return _environment; }
115118

116119
public:
117120
ErrorCode input(ByteVector const &buf);

Headers/DebugServer2/Host/Windows/ProcessSpawner.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ class ProcessSpawner {
9191
inline HANDLE threadHandle() const { return _threadHandle; }
9292
inline int exitStatus() const { return 0; }
9393
inline int signalCode() const { return 0; }
94+
inline std::string const &executable() const { return _executablePath; }
95+
inline StringCollection const &arguments() const { return _arguments; }
96+
inline EnvironmentBlock const &environment() const { return _environment; }
9497

9598
public:
9699
ErrorCode input(ByteVector const &buf) { return kErrorUnsupported; }

Sources/GDBRemote/DebugSessionImpl.cpp

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,23 @@ ErrorCode DebugSessionImplBase::onAttach(Session &session, ProcessId pid,
845845
return queryStopInfo(session, pid, stop);
846846
}
847847

848+
ErrorCode DebugSessionImplBase::onRunAttach(Session &session,
849+
std::string const &filename,
850+
StringCollection const &arguments,
851+
StopInfo &stop) {
852+
if (_process != nullptr)
853+
return kErrorAlreadyExist;
854+
855+
if (!filename.empty())
856+
_spawner.setExecutable(filename);
857+
858+
if (!arguments.empty())
859+
_spawner.setArguments(arguments);
860+
861+
CHK(spawnProcess({}, {}));
862+
return queryStopInfo(session, _spawner.pid(), stop);
863+
}
864+
848865
ErrorCode
849866
DebugSessionImplBase::onResume(Session &session,
850867
ThreadResumeAction::Collection const &actions,
@@ -1134,25 +1151,14 @@ ErrorCode DebugSessionImplBase::onRemoveBreakpoint(Session &session,
11341151

11351152
ErrorCode DebugSessionImplBase::spawnProcess(StringCollection const &args,
11361153
EnvironmentBlock const &env) {
1137-
bool displayArgs = args.size() > 1;
1138-
auto it = args.begin();
1139-
DS2LOG(Debug, "spawning process '%s'%s", (it++)->c_str(),
1140-
displayArgs ? " with args:" : "");
1141-
while (it != args.end()) {
1142-
DS2LOG(Debug, " %s", (it++)->c_str());
1143-
}
1154+
if (!args.empty())
1155+
_spawner.setExecutable(args[0]);
11441156

1145-
_spawner.setExecutable(args[0]);
1146-
_spawner.setArguments(StringCollection(args.begin() + 1, args.end()));
1147-
1148-
if (!env.empty()) {
1149-
DS2LOG(Debug, "%swith environment:", displayArgs ? "and " : "");
1150-
for (auto const &val : env) {
1151-
DS2LOG(Debug, " %s=%s", val.first.c_str(), val.second.c_str());
1152-
}
1157+
if (args.size() > 1)
1158+
_spawner.setArguments(StringCollection(args.begin() + 1, args.end()));
11531159

1160+
if (!env.empty())
11541161
_spawner.setEnvironment(env);
1155-
}
11561162

11571163
auto outputDelegate = [this](void *buf, size_t size) {
11581164
appendOutput(static_cast<char *>(buf), size);
@@ -1162,6 +1168,18 @@ ErrorCode DebugSessionImplBase::spawnProcess(StringCollection const &args,
11621168
_spawner.redirectOutputToDelegate(outputDelegate);
11631169
_spawner.redirectErrorToDelegate(outputDelegate);
11641170

1171+
const bool displayArgs = !_spawner.arguments().empty();
1172+
DS2LOG(Debug, "spawning process '%s'%s", _spawner.executable().c_str(),
1173+
displayArgs ? " with args:" : "");
1174+
for (auto const &val : _spawner.arguments())
1175+
DS2LOG(Debug, " %s", val.c_str());
1176+
1177+
if (!_spawner.environment().empty()) {
1178+
DS2LOG(Debug, "%swith environment:", displayArgs ? "and " : "");
1179+
for (auto const &val : _spawner.environment())
1180+
DS2LOG(Debug, " %s=%s", val.first.c_str(), val.second.c_str());
1181+
}
1182+
11651183
_process = ds2::Target::Process::Create(_spawner);
11661184
if (_process == nullptr) {
11671185
DS2LOG(Error, "cannot execute '%s'", args[0].c_str());

Sources/GDBRemote/Session.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3233,7 +3233,7 @@ void Session::Handle_vRun(ProtocolInterpreter::Handler const &,
32333233
size_t index = 0;
32343234

32353235
ParseList(args, ';', [&](std::string const &arg) {
3236-
if (index == 0) {
3236+
if (index++ == 0) {
32373237
filename = HexToString(arg);
32383238
} else {
32393239
arguments.push_back(HexToString(arg));

0 commit comments

Comments
 (0)