diff options
Diffstat (limited to 'source/Plugins/DynamicLoader')
20 files changed, 186 insertions, 170 deletions
diff --git a/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp index 8999000dff8c..3a80c68dd4d7 100644 --- a/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp +++ b/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp @@ -15,7 +15,6 @@ #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/Section.h" -#include "lldb/Core/State.h" #include "lldb/Core/StreamFile.h" #include "lldb/Host/Symbols.h" #include "lldb/Interpreter/OptionValueProperties.h" @@ -29,6 +28,7 @@ #include "lldb/Utility/DataBuffer.h" #include "lldb/Utility/DataBufferHeap.h" #include "lldb/Utility/Log.h" +#include "lldb/Utility/State.h" #include "DynamicLoaderDarwinKernel.h" @@ -58,7 +58,7 @@ enum KASLRScanType { // range looking for a kernel }; -OptionEnumValueElement g_kaslr_kernel_scan_enum_values[] = { +static constexpr OptionEnumValueElement g_kaslr_kernel_scan_enum_values[] = { {eKASLRScanNone, "none", "Do not read memory looking for a Darwin kernel when attaching."}, {eKASLRScanLowgloAddresses, "basic", "Check for the Darwin kernel's load " @@ -68,17 +68,15 @@ OptionEnumValueElement g_kaslr_kernel_scan_enum_values[] = { "the Darwin kernel's load address."}, {eKASLRScanExhaustiveScan, "exhaustive-scan", "Scan through the entire potential address range of Darwin kernel (only " - "on 32-bit targets)."}, - {0, NULL, NULL}}; + "on 32-bit targets)."}}; -static PropertyDefinition g_properties[] = { - {"load-kexts", OptionValue::eTypeBoolean, true, true, NULL, NULL, +static constexpr PropertyDefinition g_properties[] = { + {"load-kexts", OptionValue::eTypeBoolean, true, true, NULL, {}, "Automatically loads kext images when attaching to a kernel."}, {"scan-type", OptionValue::eTypeEnum, true, eKASLRScanNearPC, NULL, - g_kaslr_kernel_scan_enum_values, "Control how many reads lldb will make " - "while searching for a Darwin kernel on " - "attach."}, - {NULL, OptionValue::eTypeInvalid, false, 0, NULL, NULL, NULL}}; + OptionEnumValues(g_kaslr_kernel_scan_enum_values), + "Control how many reads lldb will make while searching for a Darwin " + "kernel on attach."}}; enum { ePropertyLoadKexts, ePropertyScanType }; @@ -149,6 +147,7 @@ DynamicLoader *DynamicLoaderDarwinKernel::CreateInstance(Process *process, case llvm::Triple::IOS: case llvm::Triple::TvOS: case llvm::Triple::WatchOS: + // NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS: if (triple_ref.getVendor() != llvm::Triple::Apple) { return NULL; } @@ -212,13 +211,13 @@ DynamicLoaderDarwinKernel::SearchForKernelAtSameLoadAddr(Process *process) { exe_objfile->GetStrata() != ObjectFile::eStrataKernel) return LLDB_INVALID_ADDRESS; - if (!exe_objfile->GetHeaderAddress().IsValid()) + if (!exe_objfile->GetBaseAddress().IsValid()) return LLDB_INVALID_ADDRESS; if (CheckForKernelImageAtAddress( - exe_objfile->GetHeaderAddress().GetFileAddress(), process) == + exe_objfile->GetBaseAddress().GetFileAddress(), process) == exe_module->GetUUID()) - return exe_objfile->GetHeaderAddress().GetFileAddress(); + return exe_objfile->GetBaseAddress().GetFileAddress(); return LLDB_INVALID_ADDRESS; } @@ -294,6 +293,18 @@ DynamicLoaderDarwinKernel::SearchForKernelNearPC(Process *process) { return LLDB_INVALID_ADDRESS; addr_t pc = thread->GetRegisterContext()->GetPC(LLDB_INVALID_ADDRESS); + // The kernel is always loaded in high memory, if the top bit is zero, + // this isn't a kernel. + if (process->GetTarget().GetArchitecture().GetAddressByteSize() == 8) { + if ((pc & (1ULL << 63)) == 0) { + return LLDB_INVALID_ADDRESS; + } + } else { + if ((pc & (1ULL << 31)) == 0) { + return LLDB_INVALID_ADDRESS; + } + } + if (pc == LLDB_INVALID_ADDRESS) return LLDB_INVALID_ADDRESS; @@ -308,12 +319,13 @@ DynamicLoaderDarwinKernel::SearchForKernelNearPC(Process *process) { // Search backwards 32 megabytes, looking for the start of the kernel at each // one-megabyte boundary. for (int i = 0; i < 32; i++, addr -= 0x100000) { + // x86_64 kernels are at offset 0 if (CheckForKernelImageAtAddress(addr, process).IsValid()) return addr; + // 32-bit arm kernels are at offset 0x1000 (one 4k page) if (CheckForKernelImageAtAddress(addr + 0x1000, process).IsValid()) return addr + 0x1000; - if (CheckForKernelImageAtAddress(addr + 0x2000, process).IsValid()) - return addr + 0x2000; + // 64-bit arm kernels are at offset 0x4000 (one 16k page) if (CheckForKernelImageAtAddress(addr + 0x4000, process).IsValid()) return addr + 0x4000; } @@ -352,12 +364,13 @@ lldb::addr_t DynamicLoaderDarwinKernel::SearchForKernelViaExhaustiveSearch( addr_t addr = kernel_range_low; while (addr >= kernel_range_low && addr < kernel_range_high) { + // x86_64 kernels are at offset 0 if (CheckForKernelImageAtAddress(addr, process).IsValid()) return addr; + // 32-bit arm kernels are at offset 0x1000 (one 4k page) if (CheckForKernelImageAtAddress(addr + 0x1000, process).IsValid()) return addr + 0x1000; - if (CheckForKernelImageAtAddress(addr + 0x2000, process).IsValid()) - return addr + 0x2000; + // 64-bit arm kernels are at offset 0x4000 (one 16k page) if (CheckForKernelImageAtAddress(addr + 0x4000, process).IsValid()) return addr + 0x4000; addr += 0x100000; @@ -388,8 +401,8 @@ DynamicLoaderDarwinKernel::ReadMachHeader(addr_t addr, Process *process, llvm::M if (::memcmp (&header.magic, &magicks[i], sizeof (uint32_t)) == 0) found_matching_pattern = true; - if (found_matching_pattern == false) - return false; + if (!found_matching_pattern) + return false; if (header.magic == llvm::MachO::MH_CIGAM || header.magic == llvm::MachO::MH_CIGAM_64) { @@ -425,7 +438,7 @@ DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress(lldb::addr_t addr, llvm::MachO::mach_header header; - if (ReadMachHeader (addr, process, header) == false) + if (!ReadMachHeader(addr, process, header)) return UUID(); // First try a quick test -- read the first 4 bytes and see if there is a @@ -436,8 +449,8 @@ DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress(lldb::addr_t addr, if (header.filetype == llvm::MachO::MH_EXECUTE && (header.flags & llvm::MachO::MH_DYLDLINK) == 0) { // Create a full module to get the UUID - ModuleSP memory_module_sp = process->ReadModuleFromMemory( - FileSpec("temp_mach_kernel", false), addr); + ModuleSP memory_module_sp = + process->ReadModuleFromMemory(FileSpec("temp_mach_kernel"), addr); if (!memory_module_sp.get()) return UUID(); @@ -605,16 +618,10 @@ void DynamicLoaderDarwinKernel::KextImageInfo::SetProcessStopId( bool DynamicLoaderDarwinKernel::KextImageInfo:: operator==(const KextImageInfo &rhs) { if (m_uuid.IsValid() || rhs.GetUUID().IsValid()) { - if (m_uuid == rhs.GetUUID()) { - return true; - } - return false; + return m_uuid == rhs.GetUUID(); } - if (m_name == rhs.GetName() && m_load_address == rhs.GetLoadAddress()) - return true; - - return false; + return m_name == rhs.GetName() && m_load_address == rhs.GetLoadAddress(); } void DynamicLoaderDarwinKernel::KextImageInfo::SetName(const char *name) { @@ -647,16 +654,16 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::ReadMemoryModule( if (m_load_address == LLDB_INVALID_ADDRESS) return false; - FileSpec file_spec; - file_spec.SetFile(m_name.c_str(), false, FileSpec::Style::native); + FileSpec file_spec(m_name.c_str()); llvm::MachO::mach_header mh; size_t size_to_read = 512; - if (ReadMachHeader (m_load_address, process, mh)) { - if (mh.magic == llvm::MachO::MH_CIGAM || llvm::MachO::MH_MAGIC) - size_to_read = sizeof (llvm::MachO::mach_header) + mh.sizeofcmds; - if (mh.magic == llvm::MachO::MH_CIGAM_64 || llvm::MachO::MH_MAGIC_64) - size_to_read = sizeof (llvm::MachO::mach_header_64) + mh.sizeofcmds; + if (ReadMachHeader(m_load_address, process, mh)) { + if (mh.magic == llvm::MachO::MH_CIGAM || mh.magic == llvm::MachO::MH_MAGIC) + size_to_read = sizeof(llvm::MachO::mach_header) + mh.sizeofcmds; + if (mh.magic == llvm::MachO::MH_CIGAM_64 || + mh.magic == llvm::MachO::MH_MAGIC_64) + size_to_read = sizeof(llvm::MachO::mach_header_64) + mh.sizeofcmds; } ModuleSP memory_module_sp = @@ -732,7 +739,7 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::ReadMemoryModule( } bool DynamicLoaderDarwinKernel::KextImageInfo::IsKernel() const { - return m_kernel_image == true; + return m_kernel_image; } void DynamicLoaderDarwinKernel::KextImageInfo::SetIsKernel(bool is_kernel) { @@ -784,7 +791,7 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule( // to do anything useful. This will force a clal to if (IsKernel()) { if (Symbols::DownloadObjectAndSymbolFile(module_spec, true)) { - if (module_spec.GetFileSpec().Exists()) { + if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) { m_module_sp.reset(new Module(module_spec.GetFileSpec(), target.GetArchitecture())); if (m_module_sp.get() && @@ -807,7 +814,7 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule( PlatformDarwinKernel::GetPluginNameStatic()); if (platform_name == g_platform_name) { ModuleSpec kext_bundle_module_spec(module_spec); - FileSpec kext_filespec(m_name.c_str(), false); + FileSpec kext_filespec(m_name.c_str()); kext_bundle_module_spec.GetFileSpec() = kext_filespec; platform_sp->GetSharedModule( kext_bundle_module_spec, process, m_module_sp, @@ -847,7 +854,7 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule( target.GetImages().AppendIfNeeded(m_module_sp); if (IsKernel() && target.GetExecutableModulePointer() != m_module_sp.get()) { - target.SetExecutableModule(m_module_sp, false); + target.SetExecutableModule(m_module_sp, eLoadDependentsNo); } } } @@ -932,7 +939,7 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule( ObjectFile *kernel_object_file = m_module_sp->GetObjectFile(); if (kernel_object_file) { addr_t file_address = - kernel_object_file->GetHeaderAddress().GetFileAddress(); + kernel_object_file->GetBaseAddress().GetFileAddress(); if (m_load_address != LLDB_INVALID_ADDRESS && file_address != LLDB_INVALID_ADDRESS) { s->Printf("Kernel slid 0x%" PRIx64 " in memory.\n", @@ -1006,10 +1013,10 @@ void DynamicLoaderDarwinKernel::LoadKernelModuleIfNeeded() { ObjectFile *kernel_object_file = m_kernel.GetModule()->GetObjectFile(); if (kernel_object_file) { addr_t load_address = - kernel_object_file->GetHeaderAddress().GetLoadAddress( + kernel_object_file->GetBaseAddress().GetLoadAddress( &m_process->GetTarget()); addr_t file_address = - kernel_object_file->GetHeaderAddress().GetFileAddress(); + kernel_object_file->GetBaseAddress().GetFileAddress(); if (load_address != LLDB_INVALID_ADDRESS && load_address != 0) { m_kernel.SetLoadAddress(load_address); if (load_address != file_address) { @@ -1281,7 +1288,7 @@ bool DynamicLoaderDarwinKernel::ParseKextSummaries( const uint32_t num_of_new_kexts = kext_summaries.size(); for (uint32_t new_kext = 0; new_kext < num_of_new_kexts; new_kext++) { - if (to_be_added[new_kext] == true) { + if (to_be_added[new_kext]) { KextImageInfo &image_info = kext_summaries[new_kext]; if (load_kexts) { if (!image_info.LoadImageUsingMemoryModule(m_process)) { diff --git a/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h b/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h index 75998f1cc3be..7aacebd9b50f 100644 --- a/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h +++ b/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h @@ -10,17 +10,13 @@ #ifndef liblldb_DynamicLoaderDarwinKernel_h_ #define liblldb_DynamicLoaderDarwinKernel_h_ -// C Includes -// C++ Includes #include <mutex> #include <string> #include <vector> -// Other libraries and framework includes -#include "lldb/Utility/SafeMachO.h" +#include "lldb/Host/SafeMachO.h" -// Project includes #include "lldb/Target/DynamicLoader.h" #include "lldb/Target/Process.h" #include "lldb/Utility/FileSpec.h" diff --git a/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp b/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp index 5ca20229d018..81eab8fdd970 100644 --- a/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp +++ b/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp @@ -7,9 +7,6 @@ // //===----------------------------------------------------------------------===// -// C Includes -// C++ Includes -// Other libraries and framework includes #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" @@ -179,7 +176,7 @@ ModuleSP DynamicLoaderHexagonDYLD::GetTargetExecutable() { return executable; // The target executable file does not exits - if (!executable->GetFileSpec().Exists()) + if (!FileSystem::Instance().Exists(executable->GetFileSpec())) return executable; // Prep module for loading @@ -205,8 +202,7 @@ ModuleSP DynamicLoaderHexagonDYLD::GetTargetExecutable() { if (executable.get() != target.GetExecutableModulePointer()) { // Don't load dependent images since we are in dyld where we will know and // find out about all images that are loaded - const bool get_dependent_images = false; - target.SetExecutableModule(executable, get_dependent_images); + target.SetExecutableModule(executable, eLoadDependentsNo); } return executable; @@ -368,7 +364,8 @@ void DynamicLoaderHexagonDYLD::RefreshModules() { E = m_rendezvous.loaded_end(); for (I = m_rendezvous.loaded_begin(); I != E; ++I) { - FileSpec file(I->path, true); + FileSpec file(I->path); + FileSystem::Instance().Resolve(file); ModuleSP module_sp = LoadModuleAtAddress(file, I->link_addr, I->base_addr, true); if (module_sp.get()) { @@ -392,7 +389,8 @@ void DynamicLoaderHexagonDYLD::RefreshModules() { E = m_rendezvous.unloaded_end(); for (I = m_rendezvous.unloaded_begin(); I != E; ++I) { - FileSpec file(I->path, true); + FileSpec file(I->path); + FileSystem::Instance().Resolve(file); ModuleSpec module_spec(file); ModuleSP module_sp = loaded_modules.FindFirstModule(module_spec); @@ -455,7 +453,7 @@ DynamicLoaderHexagonDYLD::GetStepThroughTrampolinePlan(Thread &thread, AddressVector::iterator start = addrs.begin(); AddressVector::iterator end = addrs.end(); - std::sort(start, end); + llvm::sort(start, end); addrs.erase(std::unique(start, end), end); thread_plan_sp.reset(new ThreadPlanRunToAddress(thread, addrs, stop)); } @@ -486,7 +484,7 @@ void DynamicLoaderHexagonDYLD::LoadAllCurrentModules() { for (I = m_rendezvous.begin(), E = m_rendezvous.end(); I != E; ++I) { const char *module_path = I->path.c_str(); - FileSpec file(module_path, false); + FileSpec file(module_path); ModuleSP module_sp = LoadModuleAtAddress(file, I->link_addr, I->base_addr, true); if (module_sp.get()) { diff --git a/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.h b/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.h index 200a4171bd1c..d39f14e8b3fb 100644 --- a/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.h +++ b/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.h @@ -10,10 +10,6 @@ #ifndef liblldb_DynamicLoaderHexagonDYLD_h_ #define liblldb_DynamicLoaderHexagonDYLD_h_ -// C Includes -// C++ Includes -// Other libraries and framework includes -// Project includes #include "lldb/Breakpoint/StoppointCallbackContext.h" #include "lldb/Target/DynamicLoader.h" diff --git a/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.h b/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.h index bdf6bae75197..758f358dc618 100644 --- a/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.h +++ b/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.h @@ -10,14 +10,11 @@ #ifndef liblldb_HexagonDYLDRendezvous_H_ #define liblldb_HexagonDYLDRendezvous_H_ -// C Includes -#include <limits.h> // for PATH_MAX -// C++ Includes +#include <limits.h> #include <list> #include <map> #include <string> -// Other libraries and framework includes #include "lldb/lldb-defines.h" #include "lldb/lldb-types.h" diff --git a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp index c6439a30c8a3..944be9633e00 100644 --- a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp +++ b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp @@ -15,7 +15,6 @@ #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/Section.h" -#include "lldb/Core/State.h" #include "lldb/Expression/DiagnosticManager.h" #include "lldb/Host/FileSystem.h" #include "lldb/Symbol/ClangASTContext.h" @@ -32,6 +31,7 @@ #include "lldb/Utility/DataBuffer.h" #include "lldb/Utility/DataBufferHeap.h" #include "lldb/Utility/Log.h" +#include "lldb/Utility/State.h" //#define ENABLE_DEBUG_PRINTF // COMMENT THIS LINE OUT PRIOR TO CHECKIN #ifdef ENABLE_DEBUG_PRINTF @@ -115,7 +115,7 @@ ModuleSP DynamicLoaderDarwin::FindTargetModuleForImageInfo( // No UUID, we must rely upon the cached module modification time and the // modification time of the file on disk if (module_sp->GetModificationTime() != - FileSystem::GetModificationTime(module_sp->GetFileSpec())) + FileSystem::Instance().GetModificationTime(module_sp->GetFileSpec())) module_sp.reset(); } @@ -359,22 +359,24 @@ bool DynamicLoaderDarwin::JSONImageInformationIntoImageInfo( if (image_sp.get() == nullptr || image_sp->GetAsDictionary() == nullptr) return false; StructuredData::Dictionary *image = image_sp->GetAsDictionary(); - if (image->HasKey("load_address") == false || - image->HasKey("pathname") == false || - image->HasKey("mod_date") == false || - image->HasKey("mach_header") == false || + // clang-format off + if (!image->HasKey("load_address") || + !image->HasKey("pathname") || + !image->HasKey("mod_date") || + !image->HasKey("mach_header") || image->GetValueForKey("mach_header")->GetAsDictionary() == nullptr || - image->HasKey("segments") == false || + !image->HasKey("segments") || image->GetValueForKey("segments")->GetAsArray() == nullptr || - image->HasKey("uuid") == false) { + !image->HasKey("uuid")) { return false; } + // clang-format on image_infos[i].address = image->GetValueForKey("load_address")->GetAsInteger()->GetValue(); image_infos[i].mod_date = image->GetValueForKey("mod_date")->GetAsInteger()->GetValue(); image_infos[i].file_spec.SetFile( - image->GetValueForKey("pathname")->GetAsString()->GetValue(), false, + image->GetValueForKey("pathname")->GetAsString()->GetValue(), FileSpec::Style::native); StructuredData::Dictionary *mh = @@ -400,6 +402,8 @@ bool DynamicLoaderDarwin::JSONImageInformationIntoImageInfo( image_infos[i].os_type = llvm::Triple::TvOS; else if (os_name == "watchos") image_infos[i].os_type = llvm::Triple::WatchOS; + // NEED_BRIDGEOS_TRIPLE else if (os_name == "bridgeos") + // NEED_BRIDGEOS_TRIPLE image_infos[i].os_type = llvm::Triple::BridgeOS; } if (image->HasKey("min_version_os_sdk")) { image_infos[i].min_version_os_sdk = @@ -513,11 +517,12 @@ void DynamicLoaderDarwin::UpdateSpecialBinariesFromNewImageInfos( const size_t image_infos_size = image_infos.size(); for (size_t i = 0; i < image_infos_size; i++) { if (image_infos[i].header.filetype == llvm::MachO::MH_DYLINKER) { - // In a "simulator" process (an x86 process that is ios/tvos/watchos) we - // will have two dyld modules -- a "dyld" that we want to keep track of, - // and a "dyld_sim" which we don't need to keep track of here. If the - // target is an x86 system and the OS of the dyld binary is - // ios/tvos/watchos, then we are looking at dyld_sym. + // In a "simulator" process (an x86 process that is + // ios/tvos/watchos/bridgeos) we will have two dyld modules -- + // a "dyld" that we want to keep track of, and a "dyld_sim" which + // we don't need to keep track of here. If the target is an x86 + // system and the OS of the dyld binary is ios/tvos/watchos/bridgeos, + // then we are looking at dyld_sym. // debugserver has only recently (late 2016) started sending up the os // type for each binary it sees -- so if we don't have an os type, use a @@ -531,6 +536,7 @@ void DynamicLoaderDarwin::UpdateSpecialBinariesFromNewImageInfos( if (image_infos[i].os_type != llvm::Triple::OSType::IOS && image_infos[i].os_type != llvm::Triple::TvOS && image_infos[i].os_type != llvm::Triple::WatchOS) { + // NEED_BRIDGEOS_TRIPLE image_infos[i].os_type != llvm::Triple::BridgeOS) { dyld_idx = i; } } @@ -555,8 +561,7 @@ void DynamicLoaderDarwin::UpdateSpecialBinariesFromNewImageInfos( target.GetImages().AppendIfNeeded(exe_module_sp); UpdateImageLoadAddress(exe_module_sp.get(), image_infos[exe_idx]); if (exe_module_sp.get() != target.GetExecutableModulePointer()) { - const bool get_dependent_images = false; - target.SetExecutableModule(exe_module_sp, get_dependent_images); + target.SetExecutableModule(exe_module_sp, eLoadDependentsNo); } } } @@ -709,11 +714,7 @@ bool DynamicLoaderDarwin::AlwaysRelyOnEHUnwindInfo(SymbolContext &sym_ctx) { return false; ObjCLanguageRuntime *objc_runtime = m_process->GetObjCLanguageRuntime(); - if (objc_runtime != NULL && objc_runtime->IsModuleObjCLibrary(module_sp)) { - return true; - } - - return false; + return objc_runtime != NULL && objc_runtime->IsModuleObjCLibrary(module_sp); } //---------------------------------------------------------------------- @@ -1124,6 +1125,10 @@ bool DynamicLoaderDarwin::UseDYLDSPI(Process *process) { // watchOS 3 and newer if (os_type == llvm::Triple::WatchOS && version >= llvm::VersionTuple(3)) use_new_spi_interface = true; + + // NEED_BRIDGEOS_TRIPLE // Any BridgeOS + // NEED_BRIDGEOS_TRIPLE if (os_type == llvm::Triple::BridgeOS) + // NEED_BRIDGEOS_TRIPLE use_new_spi_interface = true; } if (log) { diff --git a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h index a02d1ad9bee3..690253ba5ff2 100644 --- a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h +++ b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h @@ -10,18 +10,14 @@ #ifndef liblldb_DynamicLoaderDarwin_h_ #define liblldb_DynamicLoaderDarwin_h_ -// C Includes -// C++ Includes #include <map> #include <mutex> #include <vector> -// Other libraries and framework includes -// Project includes +#include "lldb/Host/SafeMachO.h" #include "lldb/Target/DynamicLoader.h" #include "lldb/Target/Process.h" #include "lldb/Utility/FileSpec.h" -#include "lldb/Utility/SafeMachO.h" #include "lldb/Utility/StructuredData.h" #include "lldb/Utility/UUID.h" diff --git a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp index 4a8ad38d1785..1ff0ec2c7937 100644 --- a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp +++ b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp @@ -12,7 +12,6 @@ #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/Section.h" -#include "lldb/Core/State.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/SymbolVendor.h" @@ -21,6 +20,7 @@ #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/Utility/Log.h" +#include "lldb/Utility/State.h" #include "DynamicLoaderDarwin.h" #include "DynamicLoaderMacOS.h" @@ -55,6 +55,7 @@ DynamicLoader *DynamicLoaderMacOS::CreateInstance(Process *process, case llvm::Triple::IOS: case llvm::Triple::TvOS: case llvm::Triple::WatchOS: + // NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS: create = triple_ref.getVendor() == llvm::Triple::Apple; break; default: @@ -64,7 +65,7 @@ DynamicLoader *DynamicLoaderMacOS::CreateInstance(Process *process, } } - if (UseDYLDSPI(process) == false) { + if (!UseDYLDSPI(process)) { create = false; } @@ -78,7 +79,8 @@ DynamicLoader *DynamicLoaderMacOS::CreateInstance(Process *process, //---------------------------------------------------------------------- DynamicLoaderMacOS::DynamicLoaderMacOS(Process *process) : DynamicLoaderDarwin(process), m_image_infos_stop_id(UINT32_MAX), - m_break_id(LLDB_INVALID_BREAK_ID), m_mutex() {} + m_break_id(LLDB_INVALID_BREAK_ID), m_mutex(), + m_maybe_image_infos_address(LLDB_INVALID_ADDRESS) {} //---------------------------------------------------------------------- // Destructor @@ -94,16 +96,31 @@ bool DynamicLoaderMacOS::ProcessDidExec() { if (m_process) { // If we are stopped after an exec, we will have only one thread... if (m_process->GetThreadList().GetSize() == 1) { - // See if we are stopped at '_dyld_start' - ThreadSP thread_sp(m_process->GetThreadList().GetThreadAtIndex(0)); - if (thread_sp) { - lldb::StackFrameSP frame_sp(thread_sp->GetStackFrameAtIndex(0)); - if (frame_sp) { - const Symbol *symbol = - frame_sp->GetSymbolContext(eSymbolContextSymbol).symbol; - if (symbol) { - if (symbol->GetName() == ConstString("_dyld_start")) - did_exec = true; + // Maybe we still have an image infos address around? If so see + // if that has changed, and if so we have exec'ed. + if (m_maybe_image_infos_address != LLDB_INVALID_ADDRESS) { + lldb::addr_t image_infos_address = m_process->GetImageInfoAddress(); + if (image_infos_address != m_maybe_image_infos_address) { + // We don't really have to reset this here, since we are going to + // call DoInitialImageFetch right away to handle the exec. But in + // case anybody looks at it in the meantime, it can't hurt. + m_maybe_image_infos_address = image_infos_address; + did_exec = true; + } + } + + if (!did_exec) { + // See if we are stopped at '_dyld_start' + ThreadSP thread_sp(m_process->GetThreadList().GetThreadAtIndex(0)); + if (thread_sp) { + lldb::StackFrameSP frame_sp(thread_sp->GetStackFrameAtIndex(0)); + if (frame_sp) { + const Symbol *symbol = + frame_sp->GetSymbolContext(eSymbolContextSymbol).symbol; + if (symbol) { + if (symbol->GetName() == ConstString("_dyld_start")) + did_exec = true; + } } } } @@ -179,6 +196,7 @@ void DynamicLoaderMacOS::DoInitialImageFetch() { } m_dyld_image_infos_stop_id = m_process->GetStopID(); + m_maybe_image_infos_address = m_process->GetImageInfoAddress(); } bool DynamicLoaderMacOS::NeedToDoInitialImageFetch() { return true; } @@ -485,8 +503,7 @@ bool DynamicLoaderMacOS::GetSharedCacheInformation( info_dict->GetValueForKey("shared_cache_uuid")->GetStringValue(); if (!uuid_str.empty()) uuid.SetFromStringRef(uuid_str); - if (info_dict->GetValueForKey("no_shared_cache")->GetBooleanValue() == - false) + if (!info_dict->GetValueForKey("no_shared_cache")->GetBooleanValue()) using_shared_cache = eLazyBoolYes; else using_shared_cache = eLazyBoolNo; diff --git a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h index db90966e5615..6303c066511c 100644 --- a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h +++ b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// // This is the DynamicLoader plugin for Darwin (macOS / iPhoneOS / tvOS / -// watchOS) +// watchOS / BridgeOS) // platforms late 2016 and newer, where lldb will call dyld SPI functions to get // information about shared libraries, information about the shared cache, and // the _dyld_debugger_notification function we put a breakpoint on give us an @@ -18,17 +18,12 @@ #ifndef liblldb_DynamicLoaderMacOS_h_ #define liblldb_DynamicLoaderMacOS_h_ -// C Includes -// C++ Includes #include <mutex> #include <vector> -// Other libraries and framework includes -// Project includes #include "lldb/Target/DynamicLoader.h" #include "lldb/Target/Process.h" #include "lldb/Utility/FileSpec.h" -#include "lldb/Utility/SafeMachO.h" #include "lldb/Utility/StructuredData.h" #include "lldb/Utility/UUID.h" @@ -109,6 +104,12 @@ protected: // loaded/unloaded images lldb::user_id_t m_break_id; mutable std::recursive_mutex m_mutex; + lldb::addr_t m_maybe_image_infos_address; // If dyld is still maintaining the + // all_image_infos address, store it + // here so we can use it to detect + // exec's when talking to + // debugservers that don't support + // the "reason:exec" annotation. private: DISALLOW_COPY_AND_ASSIGN(DynamicLoaderMacOS); diff --git a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp index 265f19d0ca06..ec459a783f94 100644 --- a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -13,7 +13,6 @@ #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/Section.h" -#include "lldb/Core/State.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/Function.h" #include "lldb/Symbol/ObjectFile.h" @@ -27,6 +26,7 @@ #include "lldb/Utility/DataBuffer.h" #include "lldb/Utility/DataBufferHeap.h" #include "lldb/Utility/Log.h" +#include "lldb/Utility/State.h" #include "DynamicLoaderDarwin.h" #include "DynamicLoaderMacOSXDYLD.h" @@ -75,6 +75,7 @@ DynamicLoader *DynamicLoaderMacOSXDYLD::CreateInstance(Process *process, case llvm::Triple::IOS: case llvm::Triple::TvOS: case llvm::Triple::WatchOS: + // NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS: create = triple_ref.getVendor() == llvm::Triple::Apple; break; default: @@ -84,7 +85,7 @@ DynamicLoader *DynamicLoaderMacOSXDYLD::CreateInstance(Process *process, } } - if (UseDYLDSPI(process) == true) { + if (UseDYLDSPI(process)) { create = false; } @@ -121,12 +122,12 @@ bool DynamicLoaderMacOSXDYLD::ProcessDidExec() { // value differs from the Process' image info address. When a process // execs itself it might cause a change if ASLR is enabled. const addr_t shlib_addr = m_process->GetImageInfoAddress(); - if (m_process_image_addr_is_all_images_infos == true && + if (m_process_image_addr_is_all_images_infos && shlib_addr != m_dyld_all_image_infos_addr) { // The image info address from the process is the // 'dyld_all_image_infos' address and it has changed. did_exec = true; - } else if (m_process_image_addr_is_all_images_infos == false && + } else if (!m_process_image_addr_is_all_images_infos && shlib_addr == m_dyld.address) { // The image info address from the process is the mach_header address // for dyld and it has changed. @@ -692,9 +693,7 @@ bool DynamicLoaderMacOSXDYLD::ReadImageInfos( error); // don't resolve the path if (error.Success()) { - const bool resolve_path = false; - image_infos[i].file_spec.SetFile(raw_path, resolve_path, - FileSpec::Style::native); + image_infos[i].file_spec.SetFile(raw_path, FileSpec::Style::native); } } return true; @@ -893,7 +892,8 @@ uint32_t DynamicLoaderMacOSXDYLD::ParseLoadCommands(const DataExtractor &data, const lldb::offset_t name_offset = load_cmd_offset + data.GetU32(&offset); const char *path = data.PeekCStr(name_offset); - lc_id_dylinker->SetFile(path, true, FileSpec::Style::native); + lc_id_dylinker->SetFile(path, FileSpec::Style::native); + FileSystem::Instance().Resolve(*lc_id_dylinker); } break; @@ -975,9 +975,8 @@ void DynamicLoaderMacOSXDYLD::UpdateImageInfosHeaderAndLoadCommands( // re-add it back to make sure it is always in the list. ModuleSP dyld_module_sp(GetDYLDModule()); - const bool get_dependent_images = false; m_process->GetTarget().SetExecutableModule(exe_module_sp, - get_dependent_images); + eLoadDependentsNo); if (dyld_module_sp) { if (target.GetImages().AppendIfNeeded(dyld_module_sp)) { diff --git a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h index 8b5052e4e230..3dc0f15bddf7 100644 --- a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h +++ b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// // This is the DynamicLoader plugin for Darwin (macOS / iPhoneOS / tvOS / -// watchOS) +// watchOS / BridgeOS) // platforms earlier than 2016, where lldb would read the "dyld_all_image_infos" // dyld internal structure to understand where things were loaded and the // solib loaded/unloaded notification function we put a breakpoint on gives us @@ -21,17 +21,13 @@ #ifndef liblldb_DynamicLoaderMacOSXDYLD_h_ #define liblldb_DynamicLoaderMacOSXDYLD_h_ -// C Includes -// C++ Includes #include <mutex> #include <vector> -// Other libraries and framework includes -// Project includes +#include "lldb/Host/SafeMachO.h" #include "lldb/Target/DynamicLoader.h" #include "lldb/Target/Process.h" #include "lldb/Utility/FileSpec.h" -#include "lldb/Utility/SafeMachO.h" #include "lldb/Utility/StructuredData.h" #include "lldb/Utility/UUID.h" diff --git a/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp b/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp index 7dd2b57da0cb..8068795df53a 100644 --- a/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp +++ b/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp @@ -100,7 +100,7 @@ const char *AuxVector::GetEntryName(EntryType type) { #define ENTRY_NAME(_type) \ _type: \ - name = #_type + 5 + name = &#_type[5] switch (type) { case ENTRY_NAME(AUXV_AT_NULL); break; case ENTRY_NAME(AUXV_AT_IGNORE); break; diff --git a/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.h b/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.h index 3b06fe18f0c6..25446e33afd4 100644 --- a/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.h +++ b/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.h @@ -10,11 +10,8 @@ #ifndef liblldb_AuxVector_H_ #define liblldb_AuxVector_H_ -// C Includes -// C++ Includes #include <vector> -// Other libraries and framework includes #include "lldb/lldb-forward.h" namespace lldb_private { diff --git a/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp b/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp index b1513b51a90a..b30a1ab2cf1f 100644 --- a/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp +++ b/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp @@ -243,7 +243,7 @@ bool DYLDRendezvous::FillSOEntryFromModuleInfo( entry.base_addr = base_addr; entry.dyn_addr = dyn_addr; - entry.file_spec.SetFile(name, false, FileSpec::Style::native); + entry.file_spec.SetFile(name, FileSpec::Style::native); UpdateBaseAddrIfNecessary(entry, name); @@ -455,14 +455,10 @@ static bool isLoadBiasIncorrect(Target &target, const std::string &file_path) { // On Android L (API 21, 22) the load address of the "/system/bin/linker" // isn't filled in correctly. unsigned os_major = target.GetPlatform()->GetOSVersion().getMajor(); - if (target.GetArchitecture().GetTriple().isAndroid() && - (os_major == 21 || os_major == 22) && - (file_path == "/system/bin/linker" || - file_path == "/system/bin/linker64")) { - return true; - } - - return false; + return target.GetArchitecture().GetTriple().isAndroid() && + (os_major == 21 || os_major == 22) && + (file_path == "/system/bin/linker" || + file_path == "/system/bin/linker64"); } void DYLDRendezvous::UpdateBaseAddrIfNecessary(SOEntry &entry, @@ -517,7 +513,7 @@ bool DYLDRendezvous::ReadSOEntryFromMemory(lldb::addr_t addr, SOEntry &entry) { return false; std::string file_path = ReadStringFromMemory(entry.path_addr); - entry.file_spec.SetFile(file_path, false, FileSpec::Style::native); + entry.file_spec.SetFile(file_path, FileSpec::Style::native); UpdateBaseAddrIfNecessary(entry, file_path); diff --git a/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h b/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h index a7071801f569..f1a62c3bf9d8 100644 --- a/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h +++ b/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h @@ -10,12 +10,9 @@ #ifndef liblldb_Rendezvous_H_ #define liblldb_Rendezvous_H_ -// C Includes -// C++ Includes #include <list> #include <string> -// Other libraries and framework includes #include "lldb/Utility/FileSpec.h" #include "lldb/lldb-defines.h" #include "lldb/lldb-types.h" diff --git a/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp b/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp index 26825d879f04..6774b4fd1291 100644 --- a/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp +++ b/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp @@ -10,10 +10,8 @@ // Main header include #include "DynamicLoaderPOSIXDYLD.h" -// Project includes #include "AuxVector.h" -// Other libraries and framework includes #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" @@ -29,8 +27,6 @@ #include "lldb/Target/ThreadPlanRunToAddress.h" #include "lldb/Utility/Log.h" -// C++ Includes -// C Includes using namespace lldb; using namespace lldb_private; @@ -121,7 +117,7 @@ void DynamicLoaderPOSIXDYLD::DidAttach() { EvalSpecialModulesStatus(); // if we dont have a load address we cant re-base - bool rebase_exec = (load_offset == LLDB_INVALID_ADDRESS) ? false : true; + bool rebase_exec = load_offset != LLDB_INVALID_ADDRESS; // if we have a valid executable if (executable_sp.get()) { @@ -500,7 +496,7 @@ DynamicLoaderPOSIXDYLD::GetStepThroughTrampolinePlan(Thread &thread, AddressVector::iterator start = addrs.begin(); AddressVector::iterator end = addrs.end(); - std::sort(start, end); + llvm::sort(start, end); addrs.erase(std::unique(start, end), end); thread_plan_sp.reset(new ThreadPlanRunToAddress(thread, addrs, stop)); } @@ -512,7 +508,7 @@ void DynamicLoaderPOSIXDYLD::LoadVDSO() { if (m_vdso_base == LLDB_INVALID_ADDRESS) return; - FileSpec file("[vdso]", false); + FileSpec file("[vdso]"); MemoryRegionInfo info; Status status = m_process->GetMemoryRegionInfo(m_vdso_base, info); @@ -543,7 +539,7 @@ ModuleSP DynamicLoaderPOSIXDYLD::LoadInterpreterModule() { return nullptr; } - FileSpec file(info.GetName().GetCString(), false); + FileSpec file(info.GetName().GetCString()); ModuleSpec module_spec(file, target.GetArchitecture()); if (ModuleSP module_sp = target.GetSharedModule(module_spec)) { @@ -756,7 +752,7 @@ void DynamicLoaderPOSIXDYLD::ResolveExecutableModule( return; } - target.SetExecutableModule(module_sp, false); + target.SetExecutableModule(module_sp, eLoadDependentsNo); } bool DynamicLoaderPOSIXDYLD::AlwaysRelyOnEHUnwindInfo( diff --git a/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h b/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h index 0456baf4a658..c5f2d3bcffbc 100644 --- a/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h +++ b/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h @@ -10,13 +10,9 @@ #ifndef liblldb_DynamicLoaderPOSIXDYLD_h_ #define liblldb_DynamicLoaderPOSIXDYLD_h_ -// C Includes -// C++ Includes #include <map> #include <memory> -// Other libraries and framework includes -// Project includes #include "DYLDRendezvous.h" #include "lldb/Breakpoint/StoppointCallbackContext.h" #include "lldb/Core/ModuleList.h" diff --git a/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.h b/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.h index 2d18ec86afd3..7f8f82c76f72 100644 --- a/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.h +++ b/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.h @@ -10,10 +10,6 @@ #ifndef liblldb_DynamicLoaderStatic_h_ #define liblldb_DynamicLoaderStatic_h_ -// C Includes -// C++ Includes -// Other libraries and framework includes -// Project includes #include "lldb/Target/DynamicLoader.h" #include "lldb/Target/Process.h" #include "lldb/Utility/FileSpec.h" diff --git a/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp b/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp index 6502d7a7a58c..9405b1a5cfdc 100644 --- a/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp +++ b/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp @@ -10,12 +10,14 @@ #include "DynamicLoaderWindowsDYLD.h" +#include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/Process.h" #include "lldb/Target/RegisterContext.h" #include "lldb/Target/Target.h" #include "lldb/Target/ThreadPlanStepInstruction.h" +#include "lldb/Utility/Log.h" #include "llvm/ADT/Triple.h" @@ -60,7 +62,39 @@ DynamicLoader *DynamicLoaderWindowsDYLD::CreateInstance(Process *process, return nullptr; } -void DynamicLoaderWindowsDYLD::DidAttach() {} +void DynamicLoaderWindowsDYLD::DidAttach() { + Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); + if (log) + log->Printf("DynamicLoaderWindowsDYLD::%s()", __FUNCTION__); + + ModuleSP executable = GetTargetExecutable(); + + if (!executable.get()) + return; + + // Try to fetch the load address of the file from the process, since there + // could be randomization of the load address. + + // It might happen that the remote has a different dir for the file, so we + // only send the basename of the executable in the query. I think this is safe + // because I doubt that two executables with the same basenames are loaded in + // memory... + FileSpec file_spec( + executable->GetPlatformFileSpec().GetFilename().GetCString()); + bool is_loaded; + addr_t base_addr = 0; + lldb::addr_t load_addr; + Status error = m_process->GetFileLoadAddress(file_spec, is_loaded, load_addr); + if (error.Success() && is_loaded) { + base_addr = load_addr; + UpdateLoadedSections(executable, LLDB_INVALID_ADDRESS, base_addr, false); + } + + ModuleList module_list; + module_list.Append(executable); + m_process->GetTarget().ModulesDidLoad(module_list); + m_process->LoadModules(); +} void DynamicLoaderWindowsDYLD::DidLaunch() {} diff --git a/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.h b/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.h index de6e295f7891..342b32b10927 100644 --- a/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.h +++ b/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.h @@ -10,10 +10,6 @@ #ifndef liblldb_Plugins_Process_Windows_DynamicLoaderWindowsDYLD_h_ #define liblldb_Plugins_Process_Windows_DynamicLoaderWindowsDYLD_h_ -// C Includes -// C++ Includes -// Other libraries and framework includes -// Project includes #include "lldb/Target/DynamicLoader.h" #include "lldb/lldb-forward.h" |
