50 const llvm::Triple &triple_ref =
52 switch (triple_ref.getOS()) {
53 case llvm::Triple::Darwin:
54 case llvm::Triple::MacOSX:
55 case llvm::Triple::IOS:
56 case llvm::Triple::TvOS:
57 case llvm::Triple::WatchOS:
58 case llvm::Triple::XROS:
59 case llvm::Triple::BridgeOS:
60 create = triple_ref.getVendor() == llvm::Triple::Apple;
84 m_libsystem_fully_initalized(false) {}
95 std::lock_guard<std::recursive_mutex> baseclass_guard(
GetMutex());
96 bool did_exec =
false;
120 frame_sp->GetSymbolContext(eSymbolContextSymbol).symbol;
122 if (symbol->
GetName() ==
"_dyld_start")
141 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
159 if (!process_state_sp)
161 if (process_state_sp->GetAsDictionary()->HasKey(
"error"))
163 if (!process_state_sp->GetAsDictionary()->HasKey(
"process_state string"))
165 std::string proc_state = process_state_sp->GetAsDictionary()
166 ->GetValueForKey(
"process_state string")
170 if (proc_state ==
"dyld_process_state_not_started" ||
171 proc_state ==
"dyld_process_state_dyld_initialized" ||
172 proc_state ==
"dyld_process_state_terminated_before_inits") {
196 Log *log =
GetLog(LLDBLog::DynamicLoader);
206 ImageInfo::collection image_infos;
207 if (all_image_info_json_sp.get() &&
208 all_image_info_json_sp->GetAsDictionary() &&
209 all_image_info_json_sp->GetAsDictionary()->HasKey(
"images") &&
210 all_image_info_json_sp->GetAsDictionary()
211 ->GetValueForKey(
"images")
215 LLDB_LOGF(log,
"Initial module fetch: Adding %" PRId64
" modules.\n",
216 (uint64_t)image_infos.size());
299 argument_values.
PushValue(headers_value);
301 if (abi->GetArgumentValues(exe_ctx.
GetThreadRef(), argument_values)) {
304 if (dyld_mode !=
static_cast<uint32_t
>(-1)) {
307 uint32_t image_infos_count =
309 if (image_infos_count !=
static_cast<uint32_t
>(-1)) {
312 if (header_array !=
static_cast<uint64_t
>(-1)) {
313 std::vector<addr_t> image_load_addresses;
326 for (uint64_t i = 0; i < image_infos_count; i++) {
328 addr_t dyld_image_info = header_array + (addrsize * 3 * i);
331 if (
error.Success()) {
332 image_load_addresses.push_back(addr);
335 "DynamicLoaderMacOS::NotifyBreakpointHit unable "
336 "to read binary mach-o load address at 0x%" PRIx64,
340 if (dyld_mode == 0) {
358 }
else if (dyld_mode == 1) {
361 }
else if (dyld_mode == 2) {
364 }
else if (dyld_mode == 3 && image_infos_count == 1) {
376 addr_t notification_location = all_image_infos + 4 +
380 addr_t notification_addr =
382 if (!
error.Success()) {
384 "DynamicLoaderMacOS::NotifyBreakpointHit unable "
385 "to read address of dyld-handover notification function at "
387 notification_location);
400 "no ABI plugin located for triple " +
402 ": shared libraries will not be registered",
411 const std::vector<lldb::addr_t> &load_addresses) {
412 Log *log =
GetLog(LLDBLog::DynamicLoader);
413 ImageInfo::collection image_infos;
415 LLDB_LOGF(log,
"Adding %" PRId64
" modules.",
416 (uint64_t)load_addresses.size());
419 if (binaries_info_sp.get() && binaries_info_sp->GetAsDictionary() &&
420 binaries_info_sp->GetAsDictionary()->HasKey(
"images") &&
421 binaries_info_sp->GetAsDictionary()
422 ->GetValueForKey(
"images")
424 binaries_info_sp->GetAsDictionary()
425 ->GetValueForKey(
"images")
427 ->GetSize() == load_addresses.size()) {
459 return notification_addr;
463 return notification_addr;
465 const uint32_t addr_size =
467 offset_t registered_infos_addr_offset =
491 all_image_infos_addr + registered_infos_addr_offset,
error);
492 if (!
error.Success())
493 return notification_addr;
494 if (registered_infos_addr != all_image_infos_addr)
495 return notification_addr;
497 offset_t notification_fptr_offset =
sizeof(uint32_t) +
502 all_image_infos_addr + notification_fptr_offset,
error);
505 return notification_addr;
521 bool internal =
true;
522 bool hardware =
false;
526 dyld_filelist.
Append(dyld_sp->GetFileSpec());
531 "lldb_image_notifier", eFunctionNameTypeFull,
547 "gdb_image_notifier", eFunctionNameTypeFull,
587 addr_t notification_address) {
590 notification_address,
true,
false);
593 dyld_handover_bp->SetOneShot(
true);
611 std::vector<uint32_t> match_indexes;
612 ConstString g_symbol_name(
"_dyld_global_lock_held");
613 uint32_t num_matches = 0;
615 symtab->AppendSymbolIndexesWithName(g_symbol_name, match_indexes);
616 if (num_matches == 1) {
617 Symbol *symbol = symtab->SymbolAtIndex(match_indexes[0]);
639 std::lock_guard<std::recursive_mutex> guard(target_modules.
GetMutex());
644 if (module_sp->GetFileSpec().GetFilename() == g_libdyld_name) {
672 if (lock_held != 0) {
685 "the dyld lock symbol");
701 if (info.get() && info->GetAsDictionary()) {
709 if (info_dict && info_dict->
HasKey(
"shared_cache_uuid") &&
710 info_dict->
HasKey(
"no_shared_cache") &&
711 info_dict->
HasKey(
"shared_cache_base_address")) {
712 base_address = info_dict->
GetValueForKey(
"shared_cache_base_address")
714 std::string uuid_str = std::string(
715 info_dict->
GetValueForKey(
"shared_cache_uuid")->GetStringValue());
716 if (!uuid_str.empty())
718 if (!info_dict->
GetValueForKey(
"no_shared_cache")->GetBooleanValue())
744 return "Dynamic loader plug-in that watches for shared library loads/unloads "
745 "in MacOSX user processes.";
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
bool SetNotificationBreakpoint() override
bool GetSharedCacheInformation(lldb::addr_t &base_address, lldb_private::UUID &uuid, lldb_private::LazyBool &using_shared_cache, lldb_private::LazyBool &private_shared_cache) override
Get information about the shared cache for a process, if possible.
static lldb_private::DynamicLoader * CreateInstance(lldb_private::Process *process, bool force)
uint32_t m_image_infos_stop_id
lldb_private::Status CanLoadImage() override
Ask if it is ok to try and load or unload an shared library (image).
void PutToLog(lldb_private::Log *log) const
bool IsFullyInitialized() override
Return whether the dynamic loader is fully initialized and it's safe to call its APIs.
lldb::addr_t GetDyldLockVariableAddressFromModule(lldb_private::Module *module)
bool m_libsystem_fully_initalized
bool NeedToDoInitialImageFetch() override
std::recursive_mutex m_mutex
void DoInitialImageFetch() override
static llvm::StringRef GetPluginNameStatic()
static llvm::StringRef GetPluginDescriptionStatic()
lldb::user_id_t m_break_id
lldb::addr_t GetNotificationFuncAddrFromImageInfos()
bool SetDYLDHandoverBreakpoint(lldb::addr_t notification_address)
void AddBinaries(const std::vector< lldb::addr_t > &load_addresses)
void ClearNotificationBreakpoint() override
void ClearDYLDHandoverBreakpoint()
static bool NotifyBreakpointHit(void *baton, lldb_private::StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
lldb::addr_t m_maybe_image_infos_address
bool ProcessDidExec() override
Called after attaching a process.
~DynamicLoaderMacOS() override
lldb::user_id_t m_dyld_handover_break_id
DynamicLoaderMacOS(lldb_private::Process *process)
bool DidSetNotificationBreakpoint() override
A section + offset based address class.
void Clear()
Clear the object's state.
lldb::addr_t GetOpcodeLoadAddress(Target *target, AddressClass addr_class=AddressClass::eInvalid) const
Get the load address as an opcode load address.
void SetRawAddress(lldb::addr_t addr)
bool IsValid() const
Check if the object state is valid.
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
llvm::Triple & GetTriple()
Architecture triple accessor.
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
void SetBreakpointKind(const char *kind)
Set the "kind" description for a breakpoint.
bool HasResolvedLocations() const
Return whether this breakpoint has any resolved locations.
void SetCallback(BreakpointHitCallback callback, void *baton, bool is_synchronous=false)
Set the callback action invoked when the breakpoint is hit.
Generic representation of a type in a programming language.
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
A uniqued constant string class.
static void ReportWarning(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report warning events.
lldb::ModuleSP GetDYLDModule()
uint32_t m_dyld_image_infos_stop_id
std::recursive_mutex & GetMutex() const
std::vector< std::pair< ImageInfo, lldb::ModuleSP > > PreloadModulesFromImageInfos(const ImageInfo::collection &image_infos)
lldb::ModuleWP m_libpthread_module_wp
bool JSONImageInformationIntoImageInfo(lldb_private::StructuredData::ObjectSP image_details, ImageInfo::collection &image_infos)
void UpdateSpecialBinariesFromPreloadedModules(std::vector< std::pair< ImageInfo, lldb::ModuleSP > > &images)
bool AddModulesUsingPreloadedModules(std::vector< std::pair< ImageInfo, lldb::ModuleSP > > &images)
static bool UseDYLDSPI(lldb_private::Process *process)
lldb_private::Address m_pthread_getspecific_addr
void UnloadImages(const std::vector< lldb::addr_t > &solib_addresses)
A plug-in interface definition class for dynamic loaders.
Process * m_process
The process that this dynamic loader plug-in is tracking.
bool GetStopWhenImagesChange() const
Get whether the process should stop when images change.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
Process * GetProcessPtr() const
Returns a pointer to the process object.
Thread & GetThreadRef() const
Returns a reference to the thread object.
void Append(const FileSpec &file)
Append a FileSpec object to the list.
A collection class for Module objects.
ModuleIterableNoLocking ModulesNoLocking() const
std::recursive_mutex & GetMutex() const
void Clear()
Clear the object's state.
ModuleIterable Modules() const
size_t GetSize() const
Gets the size of the module list.
A class that describes an executable image and its associated object and symbol files.
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
A plug-in interface definition class for object file parsers.
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
A plug-in interface definition class for debugging a process.
ThreadList & GetThreadList()
virtual lldb_private::StructuredData::ObjectSP GetSharedCacheInfo()
virtual lldb_private::StructuredData::ObjectSP GetLoadedDynamicLibrariesInfos(lldb::addr_t image_list_address, lldb::addr_t image_count)
Retrieve the list of shared libraries that are loaded for this process This method is used on pre-mac...
uint64_t ReadUnsignedIntegerFromMemory(lldb::addr_t load_addr, size_t byte_size, uint64_t fail_value, Status &error)
Reads an unsigned integer of the specified byte size from process memory.
virtual lldb::addr_t GetImageInfoAddress()
Get the image information address for the current process.
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
virtual lldb_private::StructuredData::ObjectSP GetDynamicLoaderProcessState()
lldb::addr_t FixCodeAddress(lldb::addr_t pc)
Some targets might use bits in a code address to indicate a mode switch, ARM uses bit zero to signify...
uint32_t GetStopID() const
const lldb::ABISP & GetABI()
Target & GetTarget()
Get the target object pointer for this module.
unsigned int UInt(unsigned int fail_value=0) const
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.
static Status FromErrorString(const char *str)
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
ExecutionContextRef exe_ctx_ref
lldb::break_id_t GetID() const
ObjectSP GetValueForKey(llvm::StringRef key) const
bool HasKey(llvm::StringRef key) const
Dictionary * GetAsDictionary()
std::shared_ptr< Object > ObjectSP
Defines a symbol context baton that can be handed other debug core functions.
bool ValueIsAddress() const
Address & GetAddressRef()
ConstString GetName() const
Module * GetExecutableModulePointer()
SectionLoadList & GetSectionLoadList()
bool RemoveBreakpointByID(lldb::break_id_t break_id)
lldb::BreakpointSP CreateBreakpoint(const FileSpecList *containingModules, const FileSpec &file, uint32_t line_no, uint32_t column, lldb::addr_t offset, LazyBool check_inlines, LazyBool skip_prologue, bool internal, bool request_hardware, LazyBool move_to_nearest_code)
const ModuleList & GetImages() const
Get accessor for the images for this process.
const ArchSpec & GetArchitecture() const
uint32_t GetSize(bool can_update=true)
lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update=true)
bool SetFromStringRef(llvm::StringRef str)
void PushValue(const Value &value)
Value * GetValueAtIndex(size_t idx)
const Scalar & GetScalar() const
void SetCompilerType(const CompilerType &compiler_type)
void SetValueType(ValueType value_type)
#define LLDB_INVALID_BREAK_ID
#define LLDB_BREAK_ID_IS_VALID(bid)
#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.
std::shared_ptr< lldb_private::ABI > ABISP
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::Thread > ThreadSP
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
@ eEncodingUint
unsigned integer
std::shared_ptr< lldb_private::TypeSystemClang > TypeSystemClangSP
std::shared_ptr< lldb_private::Module > ModuleSP
lldb::user_id_t GetID() const
Get accessor for the user ID.