31llvm::Expected<std::shared_ptr<ScriptedThread>>
35 return llvm::createStringError(llvm::inconvertibleErrorCode(),
36 "Invalid scripted process.");
40 auto scripted_thread_interface =
42 if (!scripted_thread_interface)
43 return llvm::createStringError(
44 llvm::inconvertibleErrorCode(),
45 "Failed to create scripted thread interface.");
47 llvm::StringRef thread_class_name;
49 std::optional<std::string> class_name =
51 if (!class_name || class_name->empty())
52 return llvm::createStringError(
53 llvm::inconvertibleErrorCode(),
54 "Failed to get scripted thread class name.");
55 thread_class_name = *class_name;
59 auto obj_or_err = scripted_thread_interface->CreatePluginObject(
64 llvm::consumeError(obj_or_err.takeError());
65 return llvm::createStringError(llvm::inconvertibleErrorCode(),
66 "Failed to create script object.");
71 if (!owned_script_object_sp->IsValid())
72 return llvm::createStringError(llvm::inconvertibleErrorCode(),
73 "Created script object is invalid.");
75 lldb::tid_t tid = scripted_thread_interface->GetThreadID();
77 return std::make_shared<ScriptedThread>(process, scripted_thread_interface,
78 tid, owned_script_object_sp);
85 :
Thread(process, tid), m_scripted_process(process),
86 m_scripted_thread_interface_sp(interface_sp),
87 m_script_object_sp(script_object_sp) {}
93 std::optional<std::string> thread_name =
GetInterface()->GetName();
101 std::optional<std::string> queue_name =
GetInterface()->GetQueue();
119 const uint32_t concrete_frame_idx =
122 if (concrete_frame_idx)
128 std::optional<std::string> reg_data =
GetInterface()->GetRegisterContext();
130 return ScriptedInterface::ErrorWithMessage<lldb::RegisterContextSP>(
131 LLVM_PRETTY_FUNCTION,
"Failed to get scripted thread registers data.",
135 std::make_shared<DataBufferHeap>(reg_data->c_str(), reg_data->size()));
137 if (!data_sp->GetByteSize())
138 return ScriptedInterface::ErrorWithMessage<lldb::RegisterContextSP>(
139 LLVM_PRETTY_FUNCTION,
"Failed to copy raw registers data.",
error,
142 std::shared_ptr<RegisterContextMemory> reg_ctx_memory =
143 std::make_shared<RegisterContextMemory>(
146 return ScriptedInterface::ErrorWithMessage<lldb::RegisterContextSP>(
147 LLVM_PRETTY_FUNCTION,
"Failed to create a register context.",
error,
150 reg_ctx_memory->SetAllRegisterData(data_sp);
161 return ScriptedInterface::ErrorWithMessage<bool>(
162 LLVM_PRETTY_FUNCTION,
"Failed to get scripted thread stackframes.",
165 size_t arr_size = arr_sp->GetSize();
166 if (arr_size > std::numeric_limits<uint32_t>::max())
167 return ScriptedInterface::ErrorWithMessage<bool>(
168 LLVM_PRETTY_FUNCTION,
170 "StackFrame array size (" + llvm::Twine(arr_size) +
172 ") is greater than maximum authorized for a StackFrameList."))
178 for (
size_t idx = 0; idx < arr_size; idx++) {
179 std::optional<StructuredData::Dictionary *> maybe_dict =
180 arr_sp->GetItemAtIndexAsDictionary(idx);
182 return ScriptedInterface::ErrorWithMessage<bool>(
183 LLVM_PRETTY_FUNCTION,
185 "Couldn't get artificial stackframe dictionary at index (" +
186 llvm::Twine(idx) + llvm::Twine(
") from stackframe array."))
193 return ScriptedInterface::ErrorWithMessage<bool>(
194 LLVM_PRETTY_FUNCTION,
195 "Couldn't find value for key 'pc' in stackframe dictionary.",
error,
202 bool cfa_is_valid =
false;
203 const bool behaves_like_zeroth_frame =
false;
207 StackFrameSP synth_frame_sp = std::make_shared<StackFrame>(
208 this->shared_from_this(), idx, idx, cfa, cfa_is_valid,
pc,
211 if (!frames->SetFrameAtIndex(
static_cast<uint32_t
>(idx), synth_frame_sp))
212 return ScriptedInterface::ErrorWithMessage<bool>(
213 LLVM_PRETTY_FUNCTION,
214 llvm::Twine(
"Couldn't add frame (" + llvm::Twine(idx) +
215 llvm::Twine(
") to ScriptedThread StackFrameList."))
228 return ScriptedInterface::ErrorWithMessage<bool>(
229 LLVM_PRETTY_FUNCTION,
"Failed to get scripted thread stop info.",
error,
235 if (!dict_sp->GetValueForKeyAsInteger(
"type", stop_reason_type))
236 return ScriptedInterface::ErrorWithMessage<bool>(
237 LLVM_PRETTY_FUNCTION,
238 "Couldn't find value for key 'type' in stop reason dictionary.",
error,
242 if (!dict_sp->GetValueForKeyAsDictionary(
"data", data_dict))
243 return ScriptedInterface::ErrorWithMessage<bool>(
244 LLVM_PRETTY_FUNCTION,
245 "Couldn't find value for key 'data' in stop reason dictionary.",
error,
248 switch (stop_reason_type) {
260 llvm::StringRef description;
273#if defined(__APPLE__)
277 llvm::StringRef value;
280 StopInfoMachException::MachException::ExceptionCode(value.data());
285 uint32_t exc_data_size = 0;
286 llvm::SmallVector<uint64_t, 3> raw_codes;
294 raw_codes.push_back(obj->GetUnsignedIntegerValue());
298 exc_rawcodes->
ForEach(fetch_data);
299 exc_data_size = raw_codes.size();
303 *
this, *exc_type, exc_data_size,
304 exc_data_size >= 1 ? raw_codes[0] : 0,
305 exc_data_size >= 2 ? raw_codes[1] : 0,
306 exc_data_size >= 3 ? raw_codes[2] : 0);
315 return ScriptedInterface::ErrorWithMessage<bool>(
316 LLVM_PRETTY_FUNCTION,
317 llvm::Twine(
"Unsupported stop reason type (" +
318 llvm::Twine(stop_reason_type) + llvm::Twine(
")."))
348 std::shared_ptr<DynamicRegisterInfo>>(
349 LLVM_PRETTY_FUNCTION,
"Failed to get scripted thread registers info.",
365 if (!extended_info_sp || !extended_info_sp->GetSize())
366 return ScriptedInterface::ErrorWithMessage<StructuredData::ObjectSP>(
367 LLVM_PRETTY_FUNCTION,
"No extended information found",
error);
369 return extended_info_sp;
static llvm::raw_ostream & error(Stream &strm)
A section + offset based address class.
bool SetLoadAddress(lldb::addr_t load_addr, Target *target, bool allow_section_end=false)
Set the address to represent load_addr.
uint32_t CalculateSymbolContext(SymbolContext *sc, lldb::SymbolContextItem resolve_scope=lldb::eSymbolContextEverything) const
Reconstruct a symbol context from an address.
A uniqued constant string class.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
static std::unique_ptr< DynamicRegisterInfo > Create(const StructuredData::Dictionary &dict, const ArchSpec &arch)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
bool IsValid() const
Return whether this object is valid (i.e.
Target & GetTarget()
Get the target object pointer for this module.
static Ret ErrorWithMessage(llvm::StringRef caller_name, llvm::StringRef error_msg, Status &error, LLDBLog log_category=LLDBLog::Process)
virtual lldb::ScriptedThreadInterfaceSP CreateScriptedThreadInterface()
virtual std::optional< std::string > GetScriptedThreadPluginName()
const ScriptedMetadata m_scripted_metadata
void CheckScriptedInterface() const
ScriptedProcessInterface & GetInterface() const
void ClearStackFrames() override
void CheckInterpreterAndScriptObject() const
std::shared_ptr< DynamicRegisterInfo > GetDynamicRegisterInfo()
lldb_private::StructuredData::GenericSP m_script_object_sp
const char * GetQueueName() override
Retrieve the Queue name for the queue currently using this Thread.
lldb::RegisterContextSP CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override
std::shared_ptr< DynamicRegisterInfo > m_register_info_sp
lldb::ScriptedThreadInterfaceSP GetInterface() const
StructuredData::ObjectSP FetchThreadExtendedInfo() override
bool LoadArtificialStackFrames()
lldb::ScriptedThreadInterfaceSP m_scripted_thread_interface_sp
static llvm::Expected< std::shared_ptr< ScriptedThread > > Create(ScriptedProcess &process, StructuredData::Generic *script_object=nullptr)
void RefreshStateAfterStop() override
void WillResume(lldb::StateType resume_state) override
ScriptedThread(ScriptedProcess &process, lldb::ScriptedThreadInterfaceSP interface_sp, lldb::tid_t tid, StructuredData::GenericSP script_object_sp=nullptr)
const char * GetName() override
bool CalculateStopInfo() override
Ask the thread subclass to set its stop info.
const ScriptedProcess & m_scripted_process
~ScriptedThread() override
lldb::RegisterContextSP GetRegisterContext() override
This base class provides an interface to stack frames.
uint32_t GetConcreteFrameIndex() const
Query this frame to find what frame it is in this Thread's StackFrameList, not counting inlined frame...
@ Artificial
An artificial stack frame (e.g.
static lldb::StopInfoSP CreateStopReasonWithMachException(Thread &thread, uint32_t exc_type, uint32_t exc_data_count, uint64_t exc_code, uint64_t exc_sub_code, uint64_t exc_sub_sub_code, bool pc_already_adjusted=true, bool adjust_pc_if_needed=false)
static lldb::StopInfoSP CreateStopReasonToTrace(Thread &thread)
static lldb::StopInfoSP CreateStopReasonWithSignal(Thread &thread, int signo, const char *description=nullptr, std::optional< int > code=std::nullopt)
static lldb::StopInfoSP CreateStopReasonWithException(Thread &thread, const char *description)
static lldb::StopInfoSP CreateStopReasonWithBreakpointSiteID(Thread &thread, lldb::break_id_t break_id)
bool ForEach(std::function< bool(Object *object)> const &foreach_callback) const
bool GetValueForKeyAsInteger(llvm::StringRef key, IntType &result) const
bool GetValueForKeyAsString(llvm::StringRef key, llvm::StringRef &result) const
bool GetValueForKeyAsArray(llvm::StringRef key, Array *&result) const
bool GetValueForKeyAsDictionary(llvm::StringRef key, Dictionary *&result) const
std::shared_ptr< Generic > GenericSP
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
std::shared_ptr< Array > ArraySP
Defines a symbol context baton that can be handed other debug core functions.
const ArchSpec & GetArchitecture() const
void SetStopInfo(const lldb::StopInfoSP &stop_info_sp)
virtual void DestroyThread()
virtual void ClearStackFrames()
virtual Unwind & GetUnwinder()
lldb::ProcessSP GetProcess() const
lldb::StackFrameListSP GetStackFrameList()
lldb::RegisterContextSP m_reg_context_sp
The register context for this thread's current register state.
lldb::RegisterContextSP CreateRegisterContextForFrame(StackFrame *frame)
#define LLDB_INVALID_BREAK_ID
#define LLDB_INVALID_SIGNAL_NUMBER
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
StateType
Process and Thread States.
std::shared_ptr< lldb_private::ScriptedThreadInterface > ScriptedThreadInterfaceSP
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::StopInfo > StopInfoSP
StopReason
Thread stop reasons.
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
std::shared_ptr< lldb_private::StackFrameList > StackFrameListSP