39#include "clang/AST/Type.h"
56 m_objc_trampoline_handler_up(), m_Foundation_major() {
114 if (!function_address)
121 strm.
Printf(
"Value doesn't point to an ObjC object.\n");
126 TypeSystemClangSP scratch_ts_sp =
142 TypeSystemClangSP scratch_ts_sp =
147 CompilerType return_compiler_type = scratch_ts_sp->GetCStringType(
true);
154 if (thread ==
nullptr) {
173 arg_value_list,
"objc-object-description",
error));
176 strm.
Printf(
"Could not get function runner to call print for debugger "
185 exe_ctx, wrapper_struct_addr, arg_value_list, diagnostics);
197 exe_ctx, &wrapper_struct_addr, options, diagnostics, ret);
199 strm.
Printf(
"Error evaluating Print Object function: %d.\n", results);
207 size_t full_buffer_len =
sizeof(buf) - 1;
208 size_t curr_len = full_buffer_len;
209 while (curr_len == full_buffer_len) {
213 strm.
Write(buf, curr_len);
214 cstr_len += curr_len;
284 if (type_and_or_name.
HasType()) {
291 if (static_type_flags.
AllSet(eTypeIsPointer))
298 if (static_type_flags.
AllSet(eTypeIsPointer))
299 corrected_name.append(
" *");
302 ret.
SetName(corrected_name.c_str());
309 const FileSpec &module_file_spec = module_sp->GetFileSpec();
312 if (module_file_spec) {
329 if (strcmp(module_sp->GetFileSpec().GetFilename().AsCString(
""),
330 "Foundation") == 0) {
354 m_process->shared_from_this(), module_sp);
364 ThreadPlanSP thread_plan_sp;
367 thread, stop_others);
368 return thread_plan_sp;
379 llvm::Triple::VendorType::Apple)
390 module_sp->IsLoadedInTarget(&target)) {
391 objc_module_sp = module_sp;
392 ObjectFile *ofile = module_sp->GetObjectFile();
396 SectionList *sections = module_sp->GetSectionList();
399 SectionSP v1_telltale_section_sp =
401 if (v1_telltale_section_sp) {
412 const bool catch_bp =
false;
413 const bool throw_bp =
true;
414 const bool is_internal =
true;
440 lldb::StopInfoSP stop_reason) {
447 uint64_t break_site_id = stop_reason->GetValue();
459 "-[NSDictionary objectForKeyedSubscript:]");
461 "__arclite_objectForKeyedSubscript");
476 FileSpecList filter_modules;
484 ThreadSP thread_sp) {
486 if (!cpp_runtime)
return ValueObjectSP();
487 auto cpp_exception = cpp_runtime->GetExceptionObjectForThread(thread_sp);
488 if (!cpp_exception)
return ValueObjectSP();
491 if (!descriptor || !descriptor->IsValid())
return ValueObjectSP();
494 ConstString class_name(descriptor->GetClassName());
495 if (class_name ==
"NSException")
496 return cpp_exception;
497 descriptor = descriptor->GetSuperclass();
500 return ValueObjectSP();
510 LLDB_LOG(log,
"Failed getting backtrace from exception: {0}", msg);
515 lldb::ValueObjectSP exception_sp) {
516 ValueObjectSP reserved_dict =
517 exception_sp->GetChildMemberWithName(
ConstString(
"reserved"),
true);
521 reserved_dict = reserved_dict->GetSyntheticValue();
525 TypeSystemClangSP scratch_ts_sp =
530 ValueObjectSP return_addresses;
532 auto objc_object_from_address = [&exception_sp, &objc_id](uint64_t addr,
537 exception_sp->GetTargetSP().get(), value,
ConstString(name));
542 for (
size_t idx = 0; idx < reserved_dict->GetNumChildren(); idx++) {
543 ValueObjectSP dict_entry = reserved_dict->GetChildAtIndex(idx,
true);
548 dict_entry->GetData(data,
error);
549 if (
error.Fail())
return ThreadSP();
552 auto dict_entry_key = data.
GetAddress(&data_offset);
553 auto dict_entry_value = data.
GetAddress(&data_offset);
555 auto key_nsstring = objc_object_from_address(dict_entry_key,
"key");
559 !key_summary.
Empty()) {
560 if (key_summary.
GetString() ==
"\"callStackReturnAddresses\"") {
561 return_addresses = objc_object_from_address(dict_entry_value,
562 "callStackReturnAddresses");
568 if (!return_addresses)
571 return_addresses->GetChildMemberWithName(
ConstString(
"_frames"),
true);
574 addr_t frames_addr = frames_value->GetValueAsUnsigned(0);
576 return_addresses->GetChildMemberWithName(
ConstString(
"_cnt"),
true);
579 size_t count = count_value->GetValueAsUnsigned(0);
581 return_addresses->GetChildMemberWithName(
ConstString(
"_ignore"),
true);
584 size_t ignore = ignore_value->GetValueAsUnsigned(0);
587 std::vector<lldb::addr_t> pcs;
588 for (
size_t idx = 0; idx < count; idx++) {
591 frames_addr + (ignore + idx) * ptr_size,
error);
600 return new_thread_sp;
603std::tuple<FileSpec, ConstString>
605 return std::make_tuple(
611 std::lock_guard<std::recursive_mutex> guard(module_list.
GetMutex());
613 size_t num_modules = module_list.
GetSize();
614 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
bool GetObjectDescription(Stream &str, Value &value, ExecutionContextScope *exe_scope) 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)
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.
bool BreakpointSiteContainsBreakpoint(lldb::break_id_t bp_site_id, lldb::break_id_t bp_id)
Returns whether the breakpoint site bp_site_id has bp_id.
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.
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.
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
BreakpointSiteList & GetBreakpointSiteList()
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
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.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output 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()
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
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.
@ eLanguageTypeObjC
Objective-C.
@ eLanguageTypeC_plus_plus
ISO C++:1998.
ExpressionResults
The results of expression evaluation.