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());
298 argument_values.
PushValue(headers_value);
300 if (abi->GetArgumentValues(exe_ctx.
GetThreadRef(), argument_values)) {
303 if (dyld_mode !=
static_cast<uint32_t
>(-1)) {
306 uint32_t image_infos_count =
308 if (image_infos_count !=
static_cast<uint32_t
>(-1)) {
311 if (header_array !=
static_cast<uint64_t
>(-1)) {
312 std::vector<addr_t> image_load_addresses;
325 for (uint64_t i = 0; i < image_infos_count; i++) {
327 addr_t dyld_image_info = header_array + (addrsize * 3 * i);
330 if (
error.Success()) {
331 image_load_addresses.push_back(addr);
334 "DynamicLoaderMacOS::NotifyBreakpointHit unable "
335 "to read binary mach-o load address at 0x%" PRIx64,
339 if (dyld_mode == 0) {
357 }
else if (dyld_mode == 1) {
360 }
else if (dyld_mode == 2) {
363 }
else if (dyld_mode == 3 && image_infos_count == 1) {
375 addr_t notification_location = all_image_infos + 4 +
379 addr_t notification_addr =
381 if (!
error.Success()) {
383 "DynamicLoaderMacOS::NotifyBreakpointHit unable "
384 "to read address of dyld-handover notification function at "
386 notification_location);
399 "no ABI plugin located for triple " +
401 ": shared libraries will not be registered",
410 const std::vector<lldb::addr_t> &load_addresses) {
411 Log *log =
GetLog(LLDBLog::DynamicLoader);
412 ImageInfo::collection image_infos;
414 LLDB_LOGF(log,
"Adding %" PRId64
" modules.",
415 (uint64_t)load_addresses.size());
418 if (binaries_info_sp.get() && binaries_info_sp->GetAsDictionary() &&
419 binaries_info_sp->GetAsDictionary()->HasKey(
"images") &&
420 binaries_info_sp->GetAsDictionary()
421 ->GetValueForKey(
"images")
423 binaries_info_sp->GetAsDictionary()
424 ->GetValueForKey(
"images")
426 ->GetSize() == load_addresses.size()) {
457 return notification_addr;
461 return notification_addr;
463 const uint32_t addr_size =
465 offset_t registered_infos_addr_offset =
489 all_image_infos_addr + registered_infos_addr_offset,
error);
490 if (!
error.Success())
491 return notification_addr;
492 if (registered_infos_addr != all_image_infos_addr)
493 return notification_addr;
495 offset_t notification_fptr_offset =
sizeof(uint32_t) +
500 all_image_infos_addr + notification_fptr_offset,
error);
503 return notification_addr;
519 bool internal =
true;
520 bool hardware =
false;
524 dyld_filelist.
Append(dyld_sp->GetFileSpec());
529 "lldb_image_notifier", eFunctionNameTypeFull,
545 "gdb_image_notifier", eFunctionNameTypeFull,
585 addr_t notification_address) {
588 notification_address,
true,
false);
591 dyld_handover_bp->SetOneShot(
true);
609 std::vector<uint32_t> match_indexes;
610 ConstString g_symbol_name(
"_dyld_global_lock_held");
611 uint32_t num_matches = 0;
613 symtab->AppendSymbolIndexesWithName(g_symbol_name, match_indexes);
614 if (num_matches == 1) {
615 Symbol *symbol = symtab->SymbolAtIndex(match_indexes[0]);
637 std::lock_guard<std::recursive_mutex> guard(target_modules.
GetMutex());
642 if (module_sp->GetFileSpec().GetFilename() == g_libdyld_name) {
670 if (lock_held != 0) {
671 error.SetErrorString(
"dyld lock held - unsafe to load images.");
681 error.SetErrorString(
"could not find the dyld library or "
682 "the dyld lock symbol");
698 if (info.get() && info->GetAsDictionary()) {
706 if (info_dict && info_dict->
HasKey(
"shared_cache_uuid") &&
707 info_dict->
HasKey(
"no_shared_cache") &&
708 info_dict->
HasKey(
"shared_cache_base_address")) {
709 base_address = info_dict->
GetValueForKey(
"shared_cache_base_address")
711 std::string uuid_str = std::string(
712 info_dict->
GetValueForKey(
"shared_cache_uuid")->GetStringValue());
713 if (!uuid_str.empty())
715 if (!info_dict->
GetValueForKey(
"no_shared_cache")->GetBooleanValue())
741 return "Dynamic loader plug-in that watches for shared library loads/unloads "
742 "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.