32llvm::Expected<std::shared_ptr<ScriptedThread>>
36 return llvm::createStringError(llvm::inconvertibleErrorCode(),
37 "Invalid scripted process.");
41 auto scripted_thread_interface =
43 if (!scripted_thread_interface)
44 return llvm::createStringError(
45 llvm::inconvertibleErrorCode(),
46 "Failed to create scripted thread interface.");
48 llvm::StringRef thread_class_name;
50 std::optional<std::string> class_name =
52 if (!class_name || class_name->empty())
53 return llvm::createStringError(
54 llvm::inconvertibleErrorCode(),
55 "Failed to get scripted thread class name.");
56 thread_class_name = *class_name;
69 auto obj_or_err = scripted_thread_interface->CreatePluginObject(
70 thread_metadata, exe_ctx, script_object);
73 llvm::consumeError(obj_or_err.takeError());
74 return llvm::createStringError(llvm::inconvertibleErrorCode(),
75 "Failed to create script object.");
80 if (!owned_script_object_sp->IsValid())
81 return llvm::createStringError(llvm::inconvertibleErrorCode(),
82 "Created script object is invalid.");
84 lldb::tid_t tid = scripted_thread_interface->GetThreadID();
86 return std::make_shared<ScriptedThread>(process, scripted_thread_interface,
87 tid, owned_script_object_sp);
102 std::optional<std::string> thread_name =
GetInterface()->GetName();
110 std::optional<std::string> queue_name =
GetInterface()->GetQueue();
128 const uint32_t concrete_frame_idx =
131 if (concrete_frame_idx)
137 std::optional<std::string> reg_data =
GetInterface()->GetRegisterContext();
140 LLVM_PRETTY_FUNCTION,
"Failed to get scripted thread registers data.",
144 std::make_shared<DataBufferHeap>(reg_data->c_str(), reg_data->size()));
146 if (!data_sp->GetByteSize())
148 LLVM_PRETTY_FUNCTION,
"Failed to copy raw registers data.",
error,
151 std::shared_ptr<RegisterContextMemory> reg_ctx_memory =
152 std::make_shared<RegisterContextMemory>(
156 LLVM_PRETTY_FUNCTION,
"Failed to create a register context.",
error,
159 reg_ctx_memory->SetAllRegisterData(data_sp);
171 LLVM_PRETTY_FUNCTION,
"Failed to get scripted thread stackframes.",
174 size_t arr_size = arr_sp->GetSize();
177 LLVM_PRETTY_FUNCTION,
"StackFrame array is empty.",
error,
180 if (arr_size > std::numeric_limits<uint32_t>::max())
182 LLVM_PRETTY_FUNCTION,
184 "StackFrame array size (" + llvm::Twine(arr_size) +
185 ") is greater than maximum authorized for a StackFrameList.")
189 auto create_frame_from_dict =
190 [
this, arr_sp](
size_t idx,
191 uint32_t frame_list_idx) -> llvm::Expected<StackFrameSP> {
193 std::optional<StructuredData::Dictionary *> maybe_dict =
194 arr_sp->GetItemAtIndexAsDictionary(idx);
197 LLVM_PRETTY_FUNCTION,
199 "Couldn't get artificial stackframe dictionary at index (" +
200 llvm::Twine(idx) + llvm::Twine(
") from stackframe array."))
203 return error.ToError();
210 LLVM_PRETTY_FUNCTION,
211 "Couldn't find value for key 'pc' in stackframe dictionary.",
error,
213 return error.ToError();
220 bool cfa_is_valid =
false;
221 const bool artificial =
false;
222 const bool behaves_like_zeroth_frame = (frame_list_idx == 0);
226 return std::make_shared<StackFrame>(shared_from_this(), frame_list_idx, idx,
227 cfa, cfa_is_valid,
pc,
229 behaves_like_zeroth_frame, &sc);
232 auto create_frame_from_script_object =
233 [
this, arr_sp](
size_t idx) -> llvm::Expected<StackFrameSP> {
236 if (!object_sp || !object_sp->GetAsGeneric()) {
238 LLVM_PRETTY_FUNCTION,
239 llvm::Twine(
"Couldn't get artificial stackframe object at index (" +
241 llvm::Twine(
") from stackframe array."))
244 return error.ToError();
248 shared_from_this(),
GetInterface(),
nullptr, object_sp->GetAsGeneric());
250 if (!frame_or_error) {
252 LLVM_PRETTY_FUNCTION,
toString(frame_or_error.takeError()),
error);
253 return error.ToError();
257 lldbassert(frame_sp &&
"Couldn't initialize scripted frame.");
263 uint32_t frame_list_idx = 0;
265 for (
size_t idx = 0; idx < arr_size; idx++) {
268 auto frame_from_dict_or_err = create_frame_from_dict(idx, frame_list_idx);
269 if (!frame_from_dict_or_err) {
270 auto frame_from_script_obj_or_err = create_frame_from_script_object(idx);
272 if (!frame_from_script_obj_or_err) {
274 LLVM_PRETTY_FUNCTION,
276 "Couldn't add artificial frame (" + llvm::Twine(idx) +
277 llvm::Twine(
") to ScriptedThread StackFrameList: ") +
278 llvm::toString(frame_from_script_obj_or_err.takeError()))
282 llvm::consumeError(frame_from_dict_or_err.takeError());
283 synth_frame_sp = *frame_from_script_obj_or_err;
286 synth_frame_sp = *frame_from_dict_or_err;
289 if (!frames->SetFrameAtIndex(frame_list_idx, synth_frame_sp))
291 LLVM_PRETTY_FUNCTION,
292 llvm::Twine(
"Couldn't add frame (" + llvm::Twine(idx) +
293 llvm::Twine(
") to ScriptedThread StackFrameList."))
299 frame_list_idx += frames->SynthesizeInlineFrames(
306 frames->SetAllFramesFetched();
317 LLVM_PRETTY_FUNCTION,
"Failed to get scripted thread stop info.",
error,
327 proc->GetBreakpointSiteList().FindByAddress(
pc))
328 if (proc->IsBreakpointSitePhysicallyEnabled(*bp_site_sp))
335 if (!dict_sp->GetValueForKeyAsInteger(
"type", stop_reason_type))
337 LLVM_PRETTY_FUNCTION,
338 "Couldn't find value for key 'type' in stop reason dictionary.",
error,
342 if (!dict_sp->GetValueForKeyAsDictionary(
"data", data_dict))
344 LLVM_PRETTY_FUNCTION,
345 "Couldn't find value for key 'data' in stop reason dictionary.",
error,
348 switch (stop_reason_type) {
360 llvm::StringRef description;
373#if defined(__APPLE__)
377 llvm::StringRef value;
380 StopInfoMachException::MachException::ExceptionCode(value.data());
385 uint32_t exc_data_size = 0;
386 llvm::SmallVector<uint64_t, 3> raw_codes;
394 raw_codes.push_back(obj->GetUnsignedIntegerValue());
398 exc_rawcodes->
ForEach(fetch_data);
399 exc_data_size = raw_codes.size();
403 *
this, *exc_type, exc_data_size,
404 exc_data_size >= 1 ? raw_codes[0] : 0,
405 exc_data_size >= 2 ? raw_codes[1] : 0,
406 exc_data_size >= 3 ? raw_codes[2] : 0);
416 LLVM_PRETTY_FUNCTION,
417 llvm::Twine(
"Unsupported stop reason type (" +
418 llvm::Twine(stop_reason_type) + llvm::Twine(
")."))
448 std::shared_ptr<DynamicRegisterInfo>>(
449 LLVM_PRETTY_FUNCTION,
"Failed to get scripted thread registers info.",
465 if (!extended_info_sp || !extended_info_sp->GetSize())
467 LLVM_PRETTY_FUNCTION,
"No extended information found",
error);
469 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) 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.
static llvm::Expected< std::shared_ptr< ScriptedFrame > > Create(lldb::ThreadSP thread_sp, lldb::ScriptedThreadInterfaceSP scripted_thread_interface_sp, StructuredData::DictionarySP args_sp, StructuredData::Generic *script_object=nullptr)
Create a ScriptedFrame from a object instanciated in the script interpreter.
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
virtual uint32_t GetConcreteFrameIndex()
Query this frame to find what frame it is in this Thread's StackFrameList, not counting inlined frame...
@ Synthetic
An synthetic 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.
void SetStopInfo(const lldb::StopInfoSP &stop_info_sp)
virtual void DestroyThread()
virtual void ClearStackFrames()
virtual Unwind & GetUnwinder()
Thread(Process &process, lldb::tid_t tid, bool use_invalid_index_id=false)
Constructor.
void SetThreadStoppedAtUnexecutedBP(lldb::addr_t pc)
When a thread stops at an enabled BreakpointSite that has not executed, the Process plugin should cal...
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::string toString(FormatterBytecode::OpCodes op)
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::BreakpointSite > BreakpointSiteSP
StateType
Process and Thread States.
std::shared_ptr< lldb_private::Process > ProcessSP
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