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:
59 create = triple_ref.getVendor() == llvm::Triple::Apple;
83 m_libsystem_fully_initalized(false) {}
94 std::lock_guard<std::recursive_mutex> baseclass_guard(
GetMutex());
95 bool did_exec =
false;
119 frame_sp->GetSymbolContext(eSymbolContextSymbol).symbol;
121 if (symbol->
GetName() ==
"_dyld_start")
140 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
158 if (!process_state_sp)
160 if (process_state_sp->GetAsDictionary()->HasKey(
"error"))
162 if (!process_state_sp->GetAsDictionary()->HasKey(
"process_state string"))
164 std::string proc_state = process_state_sp->GetAsDictionary()
165 ->GetValueForKey(
"process_state string")
169 if (proc_state ==
"dyld_process_state_not_started" ||
170 proc_state ==
"dyld_process_state_dyld_initialized" ||
171 proc_state ==
"dyld_process_state_terminated_before_inits") {
195 Log *log =
GetLog(LLDBLog::DynamicLoader);
205 ImageInfo::collection image_infos;
206 if (all_image_info_json_sp.get() &&
207 all_image_info_json_sp->GetAsDictionary() &&
208 all_image_info_json_sp->GetAsDictionary()->HasKey(
"images") &&
209 all_image_info_json_sp->GetAsDictionary()
210 ->GetValueForKey(
"images")
214 LLDB_LOGF(log,
"Initial module fetch: Adding %" PRId64
" modules.\n",
215 (uint64_t)image_infos.size());
297 argument_values.
PushValue(headers_value);
299 if (abi->GetArgumentValues(exe_ctx.
GetThreadRef(), argument_values)) {
302 if (dyld_mode !=
static_cast<uint32_t
>(-1)) {
305 uint32_t image_infos_count =
307 if (image_infos_count !=
static_cast<uint32_t
>(-1)) {
310 if (header_array !=
static_cast<uint64_t
>(-1)) {
311 std::vector<addr_t> image_load_addresses;
324 for (uint64_t i = 0; i < image_infos_count; i++) {
326 addr_t dyld_image_info = header_array + (addrsize * 3 * i);
329 if (
error.Success()) {
330 image_load_addresses.push_back(addr);
333 "DynamicLoaderMacOS::NotifyBreakpointHit unable "
334 "to read binary mach-o load address at 0x%" PRIx64,
338 if (dyld_mode == 0) {
356 }
else if (dyld_mode == 1) {
359 }
else if (dyld_mode == 2) {
362 }
else if (dyld_mode == 3 && image_infos_count == 1) {
374 addr_t notification_location = all_image_infos + 4 +
378 addr_t notification_addr =
380 if (!
error.Success()) {
382 "DynamicLoaderMacOS::NotifyBreakpointHit unable "
383 "to read address of dyld-handover notification function at "
385 notification_location);
398 "no ABI plugin located for triple " +
400 ": shared libraries will not be registered",
409 const std::vector<lldb::addr_t> &load_addresses) {
410 Log *log =
GetLog(LLDBLog::DynamicLoader);
411 ImageInfo::collection image_infos;
413 LLDB_LOGF(log,
"Adding %" PRId64
" modules.",
414 (uint64_t)load_addresses.size());
417 if (binaries_info_sp.get() && binaries_info_sp->GetAsDictionary() &&
418 binaries_info_sp->GetAsDictionary()->HasKey(
"images") &&
419 binaries_info_sp->GetAsDictionary()
420 ->GetValueForKey(
"images")
422 binaries_info_sp->GetAsDictionary()
423 ->GetValueForKey(
"images")
425 ->GetSize() == load_addresses.size()) {
456 return notification_addr;
460 return notification_addr;
462 const uint32_t addr_size =
464 offset_t registered_infos_addr_offset =
488 all_image_infos_addr + registered_infos_addr_offset,
error);
489 if (!
error.Success())
490 return notification_addr;
491 if (registered_infos_addr != all_image_infos_addr)
492 return notification_addr;
494 offset_t notification_fptr_offset =
sizeof(uint32_t) +
499 all_image_infos_addr + notification_fptr_offset,
error);
502 return notification_addr;
518 bool internal =
true;
519 bool hardware =
false;
523 dyld_filelist.
Append(dyld_sp->GetFileSpec());
528 "lldb_image_notifier", eFunctionNameTypeFull,
544 "gdb_image_notifier", eFunctionNameTypeFull,
584 addr_t notification_address) {
587 notification_address,
true,
false);
590 dyld_handover_bp->SetOneShot(
true);
608 std::vector<uint32_t> match_indexes;
609 ConstString g_symbol_name(
"_dyld_global_lock_held");
610 uint32_t num_matches = 0;
612 symtab->AppendSymbolIndexesWithName(g_symbol_name, match_indexes);
613 if (num_matches == 1) {
614 Symbol *symbol = symtab->SymbolAtIndex(match_indexes[0]);
636 std::lock_guard<std::recursive_mutex> guard(target_modules.
GetMutex());
641 if (module_sp->GetFileSpec().GetFilename() == g_libdyld_name) {
669 if (lock_held != 0) {
670 error.SetErrorString(
"dyld lock held - unsafe to load images.");
680 error.SetErrorString(
"could not find the dyld library or "
681 "the dyld lock symbol");
697 if (info.get() && info->GetAsDictionary()) {
705 if (info_dict && info_dict->
HasKey(
"shared_cache_uuid") &&
706 info_dict->
HasKey(
"no_shared_cache") &&
707 info_dict->
HasKey(
"shared_cache_base_address")) {
708 base_address = info_dict->
GetValueForKey(
"shared_cache_base_address")
710 std::string uuid_str = std::string(
711 info_dict->
GetValueForKey(
"shared_cache_uuid")->GetStringValue());
712 if (!uuid_str.empty())
714 if (!info_dict->
GetValueForKey(
"no_shared_cache")->GetBooleanValue())
740 return "Dynamic loader plug-in that watches for shared library loads/unloads "
741 "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()
void UpdateSpecialBinariesFromNewImageInfos(ImageInfo::collection &image_infos)
uint32_t m_dyld_image_infos_stop_id
std::recursive_mutex & GetMutex() const
bool AddModulesUsingImageInfos(ImageInfo::collection &image_infos)
lldb::ModuleWP m_libpthread_module_wp
bool JSONImageInformationIntoImageInfo(lldb_private::StructuredData::ObjectSP image_details, ImageInfo::collection &image_infos)
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.
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.