40#include "clang/AST/Type.h"
57 m_objc_trampoline_handler_up(), m_Foundation_major() {
78 return llvm::createStringError(
"not a pointer type");
85 return llvm::createStringError(
"pointer value could not be resolved");
96 return llvm::createStringError(
"no process");
105 return llvm::createStringError(
"Objective-C runtime not loaded");
111 return llvm::createStringError(
"no process");
118 if (!function_address)
119 return llvm::createStringError(
"no print function");
125 return llvm::createStringError(
126 "Value doesn't point to an ObjC object.\n");
132 return llvm::createStringError(
"no scratch type system");
149 return llvm::createStringError(
"no scratch type system");
151 CompilerType return_compiler_type = scratch_ts_sp->GetCStringType(
true);
158 if (thread ==
nullptr) {
177 arg_value_list,
"objc-object-description",
error));
180 return llvm::createStringError(
182 "could not get function runner to call print for debugger "
190 exe_ctx, wrapper_struct_addr, arg_value_list, diagnostics);
202 exe_ctx, &wrapper_struct_addr, options, diagnostics, ret);
204 return llvm::createStringError(
205 "could not evaluate print object function: " +
toString(results));
211 size_t full_buffer_len =
sizeof(buf) - 1;
212 size_t curr_len = full_buffer_len;
213 while (curr_len == full_buffer_len) {
217 strm.
Write(buf, curr_len);
218 cstr_len += curr_len;
221 return llvm::Error::success();
222 return llvm::createStringError(
"empty object description");
233 for (uint32_t idx = 0; idx < modules.
GetSize(); idx++) {
290 if (type_and_or_name.
HasType()) {
297 if (static_type_flags.
AllSet(eTypeIsPointer))
304 if (static_type_flags.
AllSet(eTypeIsPointer))
305 corrected_name.append(
" *");
308 ret.
SetName(corrected_name.c_str());
315 const FileSpec &module_file_spec = module_sp->GetFileSpec();
318 if (module_file_spec) {
331 for (uint32_t idx = 0; idx < modules.
GetSize(); idx++) {
335 if (strcmp(module_sp->GetFileSpec().GetFilename().AsCString(
""),
336 "Foundation") == 0) {
360 m_process->shared_from_this(), module_sp);
373 thread, stop_others);
374 return thread_plan_sp;
385 llvm::Triple::VendorType::Apple)
396 module_sp->IsLoadedInTarget(&target)) {
397 objc_module_sp = module_sp;
398 ObjectFile *ofile = module_sp->GetObjectFile();
402 SectionList *sections = module_sp->GetSectionList();
407 if (v1_telltale_section_sp) {
418 const bool catch_bp =
false;
419 const bool throw_bp =
true;
420 const bool is_internal =
true;
453 uint64_t break_site_id = stop_reason->GetValue();
465 "-[NSDictionary objectForKeyedSubscript:]");
467 "__arclite_objectForKeyedSubscript");
493 auto cpp_exception = cpp_runtime->GetExceptionObjectForThread(thread_sp);
497 if (!descriptor || !descriptor->IsValid())
return ValueObjectSP();
500 ConstString class_name(descriptor->GetClassName());
501 if (class_name ==
"NSException")
502 return cpp_exception;
503 descriptor = descriptor->GetSuperclass();
516 LLDB_LOG(log,
"Failed getting backtrace from exception: {0}", msg);
523 exception_sp->GetChildMemberWithName(
"reserved");
527 reserved_dict = reserved_dict->GetSyntheticValue();
538 auto objc_object_from_address = [&exception_sp, &objc_id](uint64_t addr,
543 exception_sp->GetTargetSP().get(), value,
ConstString(name));
548 for (
size_t idx = 0; idx < reserved_dict->GetNumChildrenIgnoringErrors();
550 ValueObjectSP dict_entry = reserved_dict->GetChildAtIndex(idx);
555 dict_entry->GetData(data,
error);
559 auto dict_entry_key = data.
GetAddress(&data_offset);
560 auto dict_entry_value = data.
GetAddress(&data_offset);
562 auto key_nsstring = objc_object_from_address(dict_entry_key,
"key");
566 !key_summary.
Empty()) {
567 if (key_summary.
GetString() ==
"\"callStackReturnAddresses\"") {
568 return_addresses = objc_object_from_address(dict_entry_value,
569 "callStackReturnAddresses");
575 if (!return_addresses)
577 auto frames_value = return_addresses->GetChildMemberWithName(
"_frames");
580 addr_t frames_addr = frames_value->GetValueAsUnsigned(0);
581 auto count_value = return_addresses->GetChildMemberWithName(
"_cnt");
584 size_t count = count_value->GetValueAsUnsigned(0);
585 auto ignore_value = return_addresses->GetChildMemberWithName(
"_ignore");
588 size_t ignore = ignore_value->GetValueAsUnsigned(0);
591 std::vector<lldb::addr_t> pcs;
592 for (
size_t idx = 0; idx < count; idx++) {
595 frames_addr + (ignore + idx) * ptr_size,
error);
604 return new_thread_sp;
607std::tuple<FileSpec, ConstString>
609 return std::make_tuple(
615 std::lock_guard<std::recursive_mutex> guard(module_list.
GetMutex());
617 size_t num_modules = module_list.
GetSize();
618 for (
size_t i = 0; i < num_modules; i++) {
static ThreadSP FailExceptionParsing(llvm::StringRef msg)
Utility method for error handling in GetBacktraceThreadFromException.
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_PLUGIN_DEFINE(PluginName)
A section + offset based address class.
virtual void GetValuesForGlobalCFBooleans(lldb::addr_t &cf_true, lldb::addr_t &cf_false)
lldb::ThreadSP GetBacktraceThreadFromException(lldb::ValueObjectSP thread_sp) override
lldb::ModuleWP m_objc_module_wp
bool CalculateHasNewLiteralsAndIndexing() override
uint32_t GetFoundationVersion()
void SetExceptionBreakpoints() override
static bool AppleIsModuleObjCLibrary(const lldb::ModuleSP &module_sp)
bool ReadObjCLibrary(const lldb::ModuleSP &module_sp) override
bool ExceptionBreakpointsAreSet() override
bool ExceptionBreakpointsExplainStop(lldb::StopInfoSP stop_reason) override
bool GetDynamicTypeAndAddress(ValueObject &in_value, lldb::DynamicValueType use_dynamic, TypeAndOrName &class_type_or_name, Address &address, Value::ValueType &value_type) override
TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name, ValueObject &static_value) override
std::optional< uint32_t > m_Foundation_major
std::unique_ptr< Address > m_PrintForDebugger_addr
static std::tuple< FileSpec, ConstString > GetExceptionThrowLocation()
lldb::BreakpointSP m_objc_exception_bp_sp
void ReadObjCLibraryIfNeeded(const ModuleList &module_list)
lldb::SearchFilterSP CreateExceptionSearchFilter() override
AppleObjCRuntime(Process *process)
static ObjCRuntimeVersions GetObjCVersion(Process *process, lldb::ModuleSP &objc_module_sp)
llvm::Error GetObjectDescription(Stream &str, Value &value, ExecutionContextScope *exe_scope) override
Address * GetPrintForDebuggerAddr()
bool HasReadObjCLibrary() override
~AppleObjCRuntime() override
lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread, bool stop_others) override
void ClearExceptionBreakpoints() override
bool IsModuleObjCLibrary(const lldb::ModuleSP &module_sp) override
lldb::ValueObjectSP GetExceptionObjectForThread(lldb::ThreadSP thread_sp) override
std::unique_ptr< lldb_private::AppleObjCTrampolineHandler > m_objc_trampoline_handler_up
lldb::ModuleSP GetObjCModule()
void ModulesDidLoad(const ModuleList &module_list) override
Called when modules have been loaded in the process.
bool CouldHaveDynamicValue(ValueObject &in_value) override
std::unique_ptr< FunctionCaller > m_print_object_caller_up
llvm::Triple & GetTriple()
Architecture triple accessor.
Generic representation of a type in a programming language.
bool IsPossibleDynamicType(CompilerType *target_type, bool check_cplusplus, bool check_objc) const
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
bool IsIntegerType(bool &is_signed) const
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
bool IsPointerType(CompilerType *pointee_type=nullptr) const
A uniqued constant string class.
const char * GetCString() const
Get the string value as a C string.
void SetUnwindOnError(bool unwind=false)
void SetTryAllThreads(bool try_others=true)
void SetTimeout(const Timeout< std::micro > &timeout)
void SetStopOthers(bool stop_others=true)
void SetIsForUtilityExpr(bool b)
void SetIgnoreBreakpoints(bool ignore=false)
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
virtual void CalculateExecutionContext(ExecutionContext &exe_ctx)=0
Reconstruct the object's execution context into sc.
virtual lldb::TargetSP CalculateTarget()=0
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
void SetFrameSP(const lldb::StackFrameSP &frame_sp)
Set accessor to set only the frame shared pointer.
bool HasProcessScope() const
Returns true the ExecutionContext object contains a valid target and process.
ExecutionContextScope * GetBestExecutionContextScope() const
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
void SetContext(const lldb::TargetSP &target_sp, bool get_process)
Target * GetTargetPtr() const
Returns a pointer to the target object.
void SetThreadSP(const lldb::ThreadSP &thread_sp)
Set accessor to set only the thread shared pointer.
Process * GetProcessPtr() const
Returns a pointer to the process object.
Thread * GetThreadPtr() const
Returns a pointer to the thread object.
void Append(const FileSpec &file)
Append a FileSpec object to the list.
const ConstString & GetFilename() const
Filename string const get accessor.
bool AllSet(ValueType mask) const
Test if all bits in mask are 1 in the current flags.
A thread object representing a backtrace from a previous point in the process execution.
static lldb::BreakpointSP CreateExceptionBreakpoint(Target &target, lldb::LanguageType language, bool catch_bp, bool throw_bp, bool is_internal=false)
A collection class for Module objects.
std::recursive_mutex & GetMutex() const
void FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list) const
lldb::ModuleSP GetModuleAtIndex(size_t idx) const
Get the module shared pointer for the module at index idx.
ModuleIterable Modules() const
size_t GetSize() const
Gets the size of the module list.
virtual ClassDescriptorSP GetClassDescriptor(ValueObject &in_value)
lldb::LanguageType GetLanguageType() const override
A plug-in interface definition class for object file parsers.
std::chrono::seconds GetUtilityExpressionTimeout() const
A plug-in interface definition class for debugging a process.
StopPointSiteList< lldb_private::BreakpointSite > & GetBreakpointSiteList()
ThreadList & GetThreadList()
size_t ReadCStringFromMemory(lldb::addr_t vm_addr, char *cstr, size_t cstr_max_len, Status &error)
Read a NULL terminated C string from memory.
ThreadList & GetExtendedThreadList()
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
LanguageRuntime * GetLanguageRuntime(lldb::LanguageType language)
uint32_t GetAddressByteSize() const
Target & GetTarget()
Get the target object pointer for this module.
unsigned long long ULongLong(unsigned long long fail_value=0) const
static lldb::TypeSystemClangSP GetForTarget(Target &target, std::optional< IsolatedASTKind > ast_kind=DefaultAST, bool create_on_demand=true)
Returns the scratch TypeSystemClang for the given target.
lldb::SectionSP FindSectionByName(ConstString section_dstr) const
bool StopPointSiteContainsBreakpoint(typename StopPointSite::SiteID, lldb::break_id_t bp_id)
Returns whether the BreakpointSite site_id has a BreakpointLocation that is part of Breakpoint bp_id.
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
Defines a list of symbol context objects.
bool GetContextAtIndex(size_t idx, SymbolContext &sc) const
Get accessor for a symbol context at index idx.
Defines a symbol context baton that can be handed other debug core functions.
Symbol * symbol
The Symbol for a given query.
Address GetAddress() const
lldb::SearchFilterSP GetSearchFilterForModuleList(const FileSpecList *containingModuleList)
const ModuleList & GetImages() const
Get accessor for the images for this process.
const ArchSpec & GetArchitecture() const
void AddThread(const lldb::ThreadSP &thread_sp)
lldb::ThreadSP GetSelectedThread()
lldb::StackFrameSP GetSelectedFrame(SelectMostRelevant select_most_relevant)
Sometimes you can find the name of the type corresponding to an object, but we don't have debug infor...
void SetName(ConstString type_name)
CompilerType GetCompilerType() const
ConstString GetName() const
void SetCompilerType(CompilerType compiler_type)
static bool IsObjCObjectPointerType(const CompilerType &type, CompilerType *target_type=nullptr)
void PushValue(const Value &value)
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size, lldb::addr_t address=LLDB_INVALID_ADDRESS)
CompilerType GetCompilerType()
lldb::ProcessSP GetProcessSP() const
lldb::TargetSP GetTargetSP() const
virtual bool ResolveValue(Scalar &scalar)
const ExecutionContextRef & GetExecutionContextRef() const
const Scalar & GetScalar() const
ValueType
Type that describes Value::m_value.
void SetCompilerType(const CompilerType &compiler_type)
const CompilerType & GetCompilerType()
#define LLDB_INVALID_MODULE_VERSION
#define LLDB_INVALID_ADDRESS
@ DoNoSelectMostRelevantFrame
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
const char * toString(AppleArm64ExceptionClass EC)
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
std::shared_ptr< lldb_private::SearchFilter > SearchFilterSP
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
@ eLanguageTypeObjC
Objective-C.
@ eLanguageTypeC_plus_plus
ISO C++:1998.
ExpressionResults
The results of expression evaluation.
std::shared_ptr< lldb_private::TypeSystemClang > TypeSystemClangSP
std::shared_ptr< lldb_private::StopInfo > StopInfoSP
std::shared_ptr< lldb_private::Section > SectionSP
std::shared_ptr< lldb_private::Module > ModuleSP