24 void ScriptedThread::CheckInterpreterAndScriptObject()
const {
25 lldbassert(m_script_object_sp &&
"Invalid Script Object.");
26 lldbassert(GetInterface() &&
"Invalid Scripted Thread Interface.");
29 llvm::Expected<std::shared_ptr<ScriptedThread>>
33 return llvm::createStringError(llvm::inconvertibleErrorCode(),
34 "Invalid scripted process.");
38 auto scripted_thread_interface =
40 if (!scripted_thread_interface)
41 return llvm::createStringError(
42 llvm::inconvertibleErrorCode(),
43 "Failed to create scripted thread interface.");
45 llvm::StringRef thread_class_name;
47 llvm::Optional<std::string> class_name =
49 if (!class_name || class_name->empty())
50 return llvm::createStringError(
51 llvm::inconvertibleErrorCode(),
52 "Failed to get scripted thread class name.");
53 thread_class_name = *class_name;
58 scripted_thread_interface->CreatePluginObject(
59 thread_class_name, exe_ctx,
62 if (!owned_script_object_sp)
63 return llvm::createStringError(llvm::inconvertibleErrorCode(),
64 "Failed to create script object.");
65 if (!owned_script_object_sp->IsValid())
66 return llvm::createStringError(llvm::inconvertibleErrorCode(),
67 "Created script object is invalid.");
69 lldb::tid_t tid = scripted_thread_interface->GetThreadID();
71 return std::make_shared<ScriptedThread>(process, scripted_thread_interface,
72 tid, owned_script_object_sp);
76 ScriptedThreadInterfaceSP interface_sp,
79 :
Thread(process, tid), m_scripted_process(process),
80 m_scripted_thread_interface_sp(interface_sp),
81 m_script_object_sp(script_object_sp) {}
87 llvm::Optional<std::string> thread_name =
GetInterface()->GetName();
95 llvm::Optional<std::string> queue_name =
GetInterface()->GetQueue();
116 if (concrete_frame_idx)
119 lldb::RegisterContextSP reg_ctx_sp;
122 llvm::Optional<std::string> reg_data =
GetInterface()->GetRegisterContext();
124 return ScriptedInterface::ErrorWithMessage<lldb::RegisterContextSP>(
125 LLVM_PRETTY_FUNCTION,
"Failed to get scripted thread registers data.",
128 DataBufferSP data_sp(
129 std::make_shared<DataBufferHeap>(reg_data->c_str(), reg_data->size()));
131 if (!data_sp->GetByteSize())
132 return ScriptedInterface::ErrorWithMessage<lldb::RegisterContextSP>(
133 LLVM_PRETTY_FUNCTION,
"Failed to copy raw registers data.",
error,
136 std::shared_ptr<RegisterContextMemory> reg_ctx_memory =
137 std::make_shared<RegisterContextMemory>(
140 return ScriptedInterface::ErrorWithMessage<lldb::RegisterContextSP>(
141 LLVM_PRETTY_FUNCTION,
"Failed to create a register context.",
error,
144 reg_ctx_memory->SetAllRegisterData(data_sp);
155 return ScriptedInterface::ErrorWithMessage<bool>(
156 LLVM_PRETTY_FUNCTION,
"Failed to get scripted thread stackframes.",
159 size_t arr_size = arr_sp->GetSize();
160 if (arr_size > std::numeric_limits<uint32_t>::max())
161 return ScriptedInterface::ErrorWithMessage<bool>(
162 LLVM_PRETTY_FUNCTION,
164 "StackFrame array size (" + llvm::Twine(arr_size) +
166 ") is greater than maximum autorized for a StackFrameList."))
172 for (
size_t idx = 0; idx < arr_size; idx++) {
176 if (!arr_sp->GetItemAtIndexAsDictionary(idx, dict) || !dict)
177 return ScriptedInterface::ErrorWithMessage<bool>(
178 LLVM_PRETTY_FUNCTION,
180 "Couldn't get artificial stackframe dictionary at index (" +
181 llvm::Twine(idx) + llvm::Twine(
") from stackframe array."))
187 return ScriptedInterface::ErrorWithMessage<bool>(
188 LLVM_PRETTY_FUNCTION,
189 "Couldn't find value for key 'pc' in stackframe dictionary.",
error,
196 bool cfa_is_valid =
false;
197 const bool behaves_like_zeroth_frame =
false;
201 StackFrameSP synth_frame_sp = std::make_shared<StackFrame>(
202 this->shared_from_this(), idx, idx, cfa, cfa_is_valid,
pc,
205 if (!frames->SetFrameAtIndex(
static_cast<uint32_t>(idx), synth_frame_sp))
206 return ScriptedInterface::ErrorWithMessage<bool>(
207 LLVM_PRETTY_FUNCTION,
208 llvm::Twine(
"Couldn't add frame (" + llvm::Twine(idx) +
209 llvm::Twine(
") to ScriptedThread StackFrameList."))
222 return ScriptedInterface::ErrorWithMessage<bool>(
223 LLVM_PRETTY_FUNCTION,
"Failed to get scripted thread stop info.",
error,
226 lldb::StopInfoSP stop_info_sp;
229 if (!dict_sp->GetValueForKeyAsInteger(
"type", stop_reason_type))
230 return ScriptedInterface::ErrorWithMessage<bool>(
231 LLVM_PRETTY_FUNCTION,
232 "Couldn't find value for key 'type' in stop reason dictionary.",
error,
236 if (!dict_sp->GetValueForKeyAsDictionary(
"data", data_dict))
237 return ScriptedInterface::ErrorWithMessage<bool>(
238 LLVM_PRETTY_FUNCTION,
239 "Couldn't find value for key 'data' in stop reason dictionary.",
error,
242 switch (stop_reason_type) {
254 llvm::StringRef description;
262 llvm::StringRef description;
269 return ScriptedInterface::ErrorWithMessage<bool>(
270 LLVM_PRETTY_FUNCTION,
271 llvm::Twine(
"Unsupported stop reason type (" +
272 llvm::Twine(stop_reason_type) + llvm::Twine(
")."))
302 ->ErrorWithMessage<std::shared_ptr<DynamicRegisterInfo>>(
303 LLVM_PRETTY_FUNCTION,
304 "Failed to get scripted thread registers info.",
error,