Skip to content

Commit 5628fcf

Browse files
authored
QSaveRegisterState and QRestoreRegisterState packets may not include thread suffix (#149)
## Purpose Fix the implementation of `QSaveRegisterState` and `QRestoreRegisterState` to work even with no thread identifier, per the [lldb packet documentation](https://lldb.llvm.org/resources/lldbgdbremote.html#qrestoreregisterstate-save-id-qrestoreregisterstate-save-id-thread-xxxx). ## Overview * Fix handling of `QSaveRegisterState` to use the current thread if none was specified in the packet arguments. * Fix handling of `QSRestoreRegisterState` to use the current thread if none was specified in the packet arguments. ## Validation With PR #143 applied, the `TestGdbRemoteRegisterState.test_grp_register_save_restore_works_no_suffix_llgs` passes locally running against DS2 on Linux x86_64.
1 parent 21ba9e3 commit 5628fcf

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Sources/GDBRemote/DebugSessionImpl.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,12 @@ ErrorCode DebugSessionImplBase::onSaveRegisters(Session &session,
672672
uint64_t &id) {
673673
static uint64_t counter = 1;
674674

675-
Thread *thread = findThread(ptid);
675+
Thread *thread = nullptr;
676+
if (ptid.valid())
677+
thread = findThread(ptid);
678+
else if (_process != nullptr)
679+
thread = _process->currentThread();
680+
676681
if (thread == nullptr)
677682
return kErrorProcessNotFound;
678683

@@ -687,7 +692,12 @@ ErrorCode DebugSessionImplBase::onSaveRegisters(Session &session,
687692
ErrorCode DebugSessionImplBase::onRestoreRegisters(Session &session,
688693
ProcessThreadId const &ptid,
689694
uint64_t id) {
690-
Thread *thread = findThread(ptid);
695+
Thread *thread = nullptr;
696+
if (ptid.valid())
697+
thread = findThread(ptid);
698+
else if (_process != nullptr)
699+
thread = _process->currentThread();
700+
691701
if (thread == nullptr)
692702
return kErrorProcessNotFound;
693703

0 commit comments

Comments
 (0)