@@ -64,32 +64,6 @@ ScriptedThread::ScriptedThread(ScriptedProcess &process, Status &error)
64
64
m_script_object_sp = object_sp;
65
65
66
66
SetID (scripted_thread_interface->GetThreadID ());
67
-
68
- llvm::Optional<std::string> reg_data =
69
- scripted_thread_interface->GetRegisterContext ();
70
- if (!reg_data) {
71
- error.SetErrorString (" Failed to get scripted thread registers data." );
72
- return ;
73
- }
74
-
75
- DataBufferSP data_sp (
76
- std::make_shared<DataBufferHeap>(reg_data->c_str (), reg_data->size ()));
77
-
78
- if (!data_sp->GetByteSize ()) {
79
- error.SetErrorString (" Failed to copy raw registers data." );
80
- return ;
81
- }
82
-
83
- std::shared_ptr<RegisterContextMemory> reg_ctx_memory =
84
- std::make_shared<RegisterContextMemory>(
85
- *this , 0 , *GetDynamicRegisterInfo (), LLDB_INVALID_ADDRESS);
86
- if (!reg_ctx_memory) {
87
- error.SetErrorString (" Failed to create a register context." );
88
- return ;
89
- }
90
-
91
- reg_ctx_memory->SetAllRegisterData (data_sp);
92
- m_reg_context_sp = reg_ctx_memory;
93
67
}
94
68
95
69
ScriptedThread::~ScriptedThread () { DestroyThread (); }
@@ -115,21 +89,48 @@ void ScriptedThread::WillResume(StateType resume_state) {}
115
89
void ScriptedThread::ClearStackFrames () { Thread::ClearStackFrames (); }
116
90
117
91
RegisterContextSP ScriptedThread::GetRegisterContext () {
118
- if (!m_reg_context_sp) {
119
- m_reg_context_sp = std::make_shared<RegisterContextThreadMemory>(
120
- *this , LLDB_INVALID_ADDRESS);
121
- GetInterface ()->GetRegisterContext ();
122
- }
92
+ if (!m_reg_context_sp)
93
+ m_reg_context_sp = CreateRegisterContextForFrame (nullptr );
123
94
return m_reg_context_sp;
124
95
}
125
96
126
97
RegisterContextSP
127
98
ScriptedThread::CreateRegisterContextForFrame (StackFrame *frame) {
128
- uint32_t concrete_frame_idx = frame ? frame->GetConcreteFrameIndex () : 0 ;
99
+ const uint32_t concrete_frame_idx =
100
+ frame ? frame->GetConcreteFrameIndex () : 0 ;
101
+
102
+ if (concrete_frame_idx)
103
+ return GetUnwinder ().CreateRegisterContextForFrame (frame);
104
+
105
+ lldb::RegisterContextSP reg_ctx_sp;
106
+ Status error;
107
+
108
+ llvm::Optional<std::string> reg_data = GetInterface ()->GetRegisterContext ();
109
+ if (!reg_data)
110
+ return GetInterface ()->ErrorWithMessage <lldb::RegisterContextSP>(
111
+ LLVM_PRETTY_FUNCTION, " Failed to get scripted thread registers data." ,
112
+ error, LIBLLDB_LOG_THREAD);
113
+
114
+ DataBufferSP data_sp (
115
+ std::make_shared<DataBufferHeap>(reg_data->c_str (), reg_data->size ()));
116
+
117
+ if (!data_sp->GetByteSize ())
118
+ return GetInterface ()->ErrorWithMessage <lldb::RegisterContextSP>(
119
+ LLVM_PRETTY_FUNCTION, " Failed to copy raw registers data." , error,
120
+ LIBLLDB_LOG_THREAD);
129
121
130
- if (concrete_frame_idx == 0 )
131
- return GetRegisterContext ();
132
- return GetUnwinder ().CreateRegisterContextForFrame (frame);
122
+ std::shared_ptr<RegisterContextMemory> reg_ctx_memory =
123
+ std::make_shared<RegisterContextMemory>(
124
+ *this , 0 , *GetDynamicRegisterInfo (), LLDB_INVALID_ADDRESS);
125
+ if (!reg_ctx_memory)
126
+ return GetInterface ()->ErrorWithMessage <lldb::RegisterContextSP>(
127
+ LLVM_PRETTY_FUNCTION, " Failed to create a register context." , error,
128
+ LIBLLDB_LOG_THREAD);
129
+
130
+ reg_ctx_memory->SetAllRegisterData (data_sp);
131
+ m_reg_context_sp = reg_ctx_memory;
132
+
133
+ return m_reg_context_sp;
133
134
}
134
135
135
136
bool ScriptedThread::CalculateStopInfo () {
@@ -142,13 +143,15 @@ bool ScriptedThread::CalculateStopInfo() {
142
143
if (!dict_sp->GetValueForKeyAsInteger (" type" , stop_reason_type))
143
144
return GetInterface ()->ErrorWithMessage <bool >(
144
145
LLVM_PRETTY_FUNCTION,
145
- " Couldn't find value for key 'type' in stop reason dictionary." , error);
146
+ " Couldn't find value for key 'type' in stop reason dictionary." , error,
147
+ LIBLLDB_LOG_THREAD);
146
148
147
149
StructuredData::Dictionary *data_dict;
148
150
if (!dict_sp->GetValueForKeyAsDictionary (" data" , data_dict))
149
151
return GetInterface ()->ErrorWithMessage <bool >(
150
152
LLVM_PRETTY_FUNCTION,
151
- " Couldn't find value for key 'type' in stop reason dictionary." , error);
153
+ " Couldn't find value for key 'type' in stop reason dictionary." , error,
154
+ LIBLLDB_LOG_THREAD);
152
155
153
156
switch (stop_reason_type) {
154
157
case lldb::eStopReasonNone:
@@ -175,17 +178,15 @@ bool ScriptedThread::CalculateStopInfo() {
175
178
llvm::Twine (" Unsupported stop reason type (" +
176
179
llvm::Twine (stop_reason_type) + llvm::Twine (" )." ))
177
180
.str (),
178
- error);
181
+ error, LIBLLDB_LOG_THREAD );
179
182
}
180
183
181
184
SetStopInfo (stop_info_sp);
182
185
return true ;
183
186
}
184
187
185
188
void ScriptedThread::RefreshStateAfterStop () {
186
- // TODO: Implement
187
- if (m_reg_context_sp)
188
- m_reg_context_sp->InvalidateAllRegisters ();
189
+ GetRegisterContext ()->InvalidateIfNeeded (/* force=*/ false );
189
190
}
190
191
191
192
lldb::ScriptedThreadInterfaceSP ScriptedThread::GetInterface () const {
0 commit comments