Skip to content

Commit 886d8cc

Browse files
authored
[lldb][debugserver] Save and restore the SVE/SME register state (llvm#134184) (#10418)
debugserver isn't saving and restoring the SVE/SME register state around inferior function calls. Making arbitrary function calls while in Streaming SVE mode is generally a poor idea because a NEON instruction can be hit and crash the expression execution, which is how I missed this, but they should be handled correctly if the user knows it is safe to do. Re-landing this change after fixing an incorrect behavior on systems without SME support. rdar://146886210 (cherry picked from commit f1c6612)
1 parent bddce88 commit 886d8cc

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -2952,8 +2952,15 @@ kern_return_t DNBArchMachARM64::SetRegisterState(int set) {
29522952
return err;
29532953

29542954
switch (set) {
2955-
case e_regSetALL:
2956-
return SetGPRState() | SetVFPState() | SetEXCState() | SetDBGState(false);
2955+
case e_regSetALL: {
2956+
kern_return_t ret =
2957+
SetGPRState() | SetVFPState() | SetEXCState() | SetDBGState(false);
2958+
if (CPUHasSME()) {
2959+
SetSVEState();
2960+
SetSMEState();
2961+
}
2962+
return ret;
2963+
}
29572964
case e_regSetGPR:
29582965
return SetGPRState();
29592966
case e_regSetVFP:
@@ -3123,6 +3130,12 @@ uint32_t DNBArchMachARM64::SaveRegisterState() {
31233130
"error: %s regs failed to read: %u",
31243131
"VFP", kret);
31253132
} else {
3133+
if (CPUHasSME()) {
3134+
// These can fail when processor is not in streaming SVE mode,
3135+
// and that failure should be ignored.
3136+
GetSVEState(force);
3137+
GetSMEState(force);
3138+
}
31263139
const uint32_t save_id = GetNextRegisterStateSaveID();
31273140
m_saved_register_states[save_id] = m_state.context;
31283141
return save_id;
@@ -3150,6 +3163,12 @@ bool DNBArchMachARM64::RestoreRegisterState(uint32_t save_id) {
31503163
save_id, "VFP", kret);
31513164
success = false;
31523165
}
3166+
if (CPUHasSME()) {
3167+
// These can fail when processor is not in streaming SVE mode,
3168+
// and that failure should be ignored.
3169+
SetSVEState();
3170+
SetSMEState();
3171+
}
31533172
m_saved_register_states.erase(pos);
31543173
return success;
31553174
}

0 commit comments

Comments
 (0)