| Raphael Isemann | 8081428 | 2020-01-24 08:23:27 +0100 | [diff] [blame] | 1 | //===-- DynamicLoaderDarwin.cpp -------------------------------------------===// |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 2 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| Pavel Labath | 1408bf7 | 2016-11-01 16:11:14 +0000 | [diff] [blame] | 9 | #include "DynamicLoaderDarwin.h" |
| 10 | |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 11 | #include "lldb/Breakpoint/StoppointCallbackContext.h" |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Debugger.h" |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Module.h" |
| 14 | #include "lldb/Core/ModuleSpec.h" |
| 15 | #include "lldb/Core/PluginManager.h" |
| 16 | #include "lldb/Core/Section.h" |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 17 | #include "lldb/Expression/DiagnosticManager.h" |
| Pavel Labath | 1408bf7 | 2016-11-01 16:11:14 +0000 | [diff] [blame] | 18 | #include "lldb/Host/FileSystem.h" |
| Raphael Isemann | 6e3b0cc | 2020-01-23 10:04:13 +0100 | [diff] [blame] | 19 | #include "lldb/Symbol/TypeSystemClang.h" |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 20 | #include "lldb/Symbol/Function.h" |
| 21 | #include "lldb/Symbol/ObjectFile.h" |
| 22 | #include "lldb/Target/ABI.h" |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 23 | #include "lldb/Target/RegisterContext.h" |
| 24 | #include "lldb/Target/StackFrame.h" |
| 25 | #include "lldb/Target/Target.h" |
| 26 | #include "lldb/Target/Thread.h" |
| 27 | #include "lldb/Target/ThreadPlanCallFunction.h" |
| 28 | #include "lldb/Target/ThreadPlanRunToAddress.h" |
| Zachary Turner | 666cc0b | 2017-03-04 01:30:05 +0000 | [diff] [blame] | 29 | #include "lldb/Utility/DataBuffer.h" |
| 30 | #include "lldb/Utility/DataBufferHeap.h" |
| Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 31 | #include "lldb/Utility/Log.h" |
| Pavel Labath | d821c99 | 2018-08-07 11:07:21 +0000 | [diff] [blame] | 32 | #include "lldb/Utility/State.h" |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 33 | |
| Alex Langford | b5701710 | 2019-07-15 22:56:12 +0000 | [diff] [blame] | 34 | #include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h" |
| 35 | |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 36 | //#define ENABLE_DEBUG_PRINTF // COMMENT THIS LINE OUT PRIOR TO CHECKIN |
| 37 | #ifdef ENABLE_DEBUG_PRINTF |
| 38 | #include <stdio.h> |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 39 | #define DEBUG_PRINTF(fmt, ...) printf(fmt, ##__VA_ARGS__) |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 40 | #else |
| 41 | #define DEBUG_PRINTF(fmt, ...) |
| 42 | #endif |
| 43 | |
| 44 | #ifndef __APPLE__ |
| 45 | #include "Utility/UuidCompatibility.h" |
| 46 | #else |
| 47 | #include <uuid/uuid.h> |
| 48 | #endif |
| 49 | |
| Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 50 | #include <memory> |
| 51 | |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 52 | using namespace lldb; |
| 53 | using namespace lldb_private; |
| 54 | |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 55 | // Constructor |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | DynamicLoaderDarwin::DynamicLoaderDarwin(Process *process) |
| 57 | : DynamicLoader(process), m_dyld_module_wp(), m_libpthread_module_wp(), |
| 58 | m_pthread_getspecific_addr(), m_tid_to_tls_map(), m_dyld_image_infos(), |
| 59 | m_dyld_image_infos_stop_id(UINT32_MAX), m_dyld(), m_mutex() {} |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 60 | |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 61 | // Destructor |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 62 | DynamicLoaderDarwin::~DynamicLoaderDarwin() {} |
| 63 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | /// Called after attaching a process. |
| 65 | /// |
| 66 | /// Allow DynamicLoader plug-ins to execute some code after |
| 67 | /// attaching to a process. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 68 | void DynamicLoaderDarwin::DidAttach() { |
| 69 | PrivateInitialize(m_process); |
| 70 | DoInitialImageFetch(); |
| 71 | SetNotificationBreakpoint(); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 74 | /// Called after attaching a process. |
| 75 | /// |
| 76 | /// Allow DynamicLoader plug-ins to execute some code after |
| 77 | /// attaching to a process. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 78 | void DynamicLoaderDarwin::DidLaunch() { |
| 79 | PrivateInitialize(m_process); |
| 80 | DoInitialImageFetch(); |
| 81 | SetNotificationBreakpoint(); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 84 | // Clear out the state of this class. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 85 | void DynamicLoaderDarwin::Clear(bool clear_process) { |
| 86 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 87 | if (clear_process) |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 88 | m_process = nullptr; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 89 | m_dyld_image_infos.clear(); |
| 90 | m_dyld_image_infos_stop_id = UINT32_MAX; |
| 91 | m_dyld.Clear(false); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 94 | ModuleSP DynamicLoaderDarwin::FindTargetModuleForImageInfo( |
| 95 | ImageInfo &image_info, bool can_create, bool *did_create_ptr) { |
| 96 | if (did_create_ptr) |
| 97 | *did_create_ptr = false; |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 98 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 99 | Target &target = m_process->GetTarget(); |
| 100 | const ModuleList &target_images = target.GetImages(); |
| 101 | ModuleSpec module_spec(image_info.file_spec); |
| 102 | module_spec.GetUUID() = image_info.uuid; |
| Adrian Prantl | 2461061 | 2019-09-04 17:23:15 +0000 | [diff] [blame] | 103 | |
| 104 | // macCatalyst support: Request matching os/environment. |
| 105 | { |
| 106 | auto &target_triple = target.GetArchitecture().GetTriple(); |
| 107 | if (target_triple.getOS() == llvm::Triple::IOS && |
| 108 | target_triple.getEnvironment() == llvm::Triple::MacABI) { |
| 109 | // Request the macCatalyst variant of frameworks that have both |
| 110 | // a PLATFORM_MACOS and a PLATFORM_MACCATALYST load command. |
| 111 | module_spec.GetArchitecture() = ArchSpec(target_triple); |
| 112 | } |
| 113 | } |
| 114 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 115 | ModuleSP module_sp(target_images.FindFirstModule(module_spec)); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 116 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 117 | if (module_sp && !module_spec.GetUUID().IsValid() && |
| 118 | !module_sp->GetUUID().IsValid()) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 119 | // No UUID, we must rely upon the cached module modification time and the |
| 120 | // modification time of the file on disk |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 121 | if (module_sp->GetModificationTime() != |
| Jonas Devlieghere | 4637696 | 2018-10-31 21:49:27 +0000 | [diff] [blame] | 122 | FileSystem::Instance().GetModificationTime(module_sp->GetFileSpec())) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 123 | module_sp.reset(); |
| 124 | } |
| 125 | |
| 126 | if (!module_sp) { |
| 127 | if (can_create) { |
| Jason Molenda | 1724a17 | 2019-04-08 23:03:02 +0000 | [diff] [blame] | 128 | // We'll call Target::ModulesDidLoad after all the modules have been |
| 129 | // added to the target, don't let it be called for every one. |
| 130 | module_sp = target.GetOrCreateModule(module_spec, false /* notify */); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 131 | if (!module_sp || module_sp->GetObjectFile() == nullptr) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 132 | module_sp = m_process->ReadModuleFromMemory(image_info.file_spec, |
| 133 | image_info.address); |
| 134 | |
| 135 | if (did_create_ptr) |
| 136 | *did_create_ptr = (bool)module_sp; |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 137 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 138 | } |
| 139 | return module_sp; |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 142 | void DynamicLoaderDarwin::UnloadImages( |
| 143 | const std::vector<lldb::addr_t> &solib_addresses) { |
| 144 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 145 | if (m_process->GetStopID() == m_dyld_image_infos_stop_id) |
| 146 | return; |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 147 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 148 | Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); |
| 149 | Target &target = m_process->GetTarget(); |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 150 | LLDB_LOGF(log, "Removing %" PRId64 " modules.", |
| 151 | (uint64_t)solib_addresses.size()); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 152 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 153 | ModuleList unloaded_module_list; |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 154 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 155 | for (addr_t solib_addr : solib_addresses) { |
| 156 | Address header; |
| 157 | if (header.SetLoadAddress(solib_addr, &target)) { |
| 158 | if (header.GetOffset() == 0) { |
| 159 | ModuleSP module_to_remove(header.GetModule()); |
| 160 | if (module_to_remove.get()) { |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 161 | LLDB_LOGF(log, "Removing module at address 0x%" PRIx64, solib_addr); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 162 | // remove the sections from the Target |
| 163 | UnloadSections(module_to_remove); |
| 164 | // add this to the list of modules to remove |
| 165 | unloaded_module_list.AppendIfNeeded(module_to_remove); |
| 166 | // remove the entry from the m_dyld_image_infos |
| 167 | ImageInfo::collection::iterator pos, end = m_dyld_image_infos.end(); |
| 168 | for (pos = m_dyld_image_infos.begin(); pos != end; pos++) { |
| 169 | if (solib_addr == (*pos).address) { |
| 170 | m_dyld_image_infos.erase(pos); |
| 171 | break; |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 172 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 173 | } |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 174 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 175 | } |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 176 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 177 | } |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 178 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 179 | if (unloaded_module_list.GetSize() > 0) { |
| 180 | if (log) { |
| 181 | log->PutCString("Unloaded:"); |
| 182 | unloaded_module_list.LogUUIDAndPaths( |
| 183 | log, "DynamicLoaderDarwin::UnloadModules"); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 184 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 185 | m_process->GetTarget().GetImages().Remove(unloaded_module_list); |
| 186 | m_dyld_image_infos_stop_id = m_process->GetStopID(); |
| 187 | } |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 190 | void DynamicLoaderDarwin::UnloadAllImages() { |
| 191 | Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); |
| 192 | ModuleList unloaded_modules_list; |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 193 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 194 | Target &target = m_process->GetTarget(); |
| 195 | const ModuleList &target_modules = target.GetImages(); |
| 196 | std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex()); |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 197 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 198 | size_t num_modules = target_modules.GetSize(); |
| 199 | ModuleSP dyld_sp(GetDYLDModule()); |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 200 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 201 | for (size_t i = 0; i < num_modules; i++) { |
| 202 | ModuleSP module_sp = target_modules.GetModuleAtIndexUnlocked(i); |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 203 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 204 | // Don't remove dyld - else we'll lose our breakpoint notifying us about |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 205 | // libraries being re-loaded... |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 206 | if (module_sp.get() != nullptr && module_sp.get() != dyld_sp.get()) { |
| 207 | UnloadSections(module_sp); |
| 208 | unloaded_modules_list.Append(module_sp); |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 209 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 210 | } |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 211 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 212 | if (unloaded_modules_list.GetSize() != 0) { |
| 213 | if (log) { |
| 214 | log->PutCString("Unloaded:"); |
| 215 | unloaded_modules_list.LogUUIDAndPaths( |
| 216 | log, "DynamicLoaderDarwin::UnloadAllImages"); |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 217 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 218 | target.GetImages().Remove(unloaded_modules_list); |
| 219 | m_dyld_image_infos.clear(); |
| 220 | m_dyld_image_infos_stop_id = m_process->GetStopID(); |
| 221 | } |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 224 | // Update the load addresses for all segments in MODULE using the updated INFO |
| 225 | // that is passed in. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 226 | bool DynamicLoaderDarwin::UpdateImageLoadAddress(Module *module, |
| 227 | ImageInfo &info) { |
| 228 | bool changed = false; |
| 229 | if (module) { |
| 230 | ObjectFile *image_object_file = module->GetObjectFile(); |
| 231 | if (image_object_file) { |
| 232 | SectionList *section_list = image_object_file->GetSectionList(); |
| 233 | if (section_list) { |
| 234 | std::vector<uint32_t> inaccessible_segment_indexes; |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 235 | // We now know the slide amount, so go through all sections and update |
| 236 | // the load addresses with the correct values. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 237 | const size_t num_segments = info.segments.size(); |
| 238 | for (size_t i = 0; i < num_segments; ++i) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 239 | // Only load a segment if it has protections. Things like __PAGEZERO |
| 240 | // don't have any protections, and they shouldn't be slid |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 241 | SectionSP section_sp( |
| 242 | section_list->FindSectionByName(info.segments[i].name)); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 243 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 244 | if (info.segments[i].maxprot == 0) { |
| 245 | inaccessible_segment_indexes.push_back(i); |
| 246 | } else { |
| 247 | const addr_t new_section_load_addr = |
| 248 | info.segments[i].vmaddr + info.slide; |
| 249 | static ConstString g_section_name_LINKEDIT("__LINKEDIT"); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 250 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 251 | if (section_sp) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 252 | // __LINKEDIT sections from files in the shared cache can overlap |
| 253 | // so check to see what the segment name is and pass "false" so |
| 254 | // we don't warn of overlapping "Section" objects, and "true" for |
| 255 | // all other sections. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 256 | const bool warn_multiple = |
| 257 | section_sp->GetName() != g_section_name_LINKEDIT; |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 258 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 259 | changed = m_process->GetTarget().SetSectionLoadAddress( |
| 260 | section_sp, new_section_load_addr, warn_multiple); |
| Jason Molenda | 9073eb4 | 2019-01-25 03:01:48 +0000 | [diff] [blame] | 261 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 262 | } |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 263 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 264 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 265 | // If the loaded the file (it changed) and we have segments that are |
| 266 | // not readable or writeable, add them to the invalid memory region |
| 267 | // cache for the process. This will typically only be the __PAGEZERO |
| 268 | // segment in the main executable. We might be able to apply this more |
| 269 | // generally to more sections that have no protections in the future, |
| 270 | // but for now we are going to just do __PAGEZERO. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 271 | if (changed && !inaccessible_segment_indexes.empty()) { |
| 272 | for (uint32_t i = 0; i < inaccessible_segment_indexes.size(); ++i) { |
| 273 | const uint32_t seg_idx = inaccessible_segment_indexes[i]; |
| 274 | SectionSP section_sp( |
| 275 | section_list->FindSectionByName(info.segments[seg_idx].name)); |
| 276 | |
| 277 | if (section_sp) { |
| 278 | static ConstString g_pagezero_section_name("__PAGEZERO"); |
| 279 | if (g_pagezero_section_name == section_sp->GetName()) { |
| 280 | // __PAGEZERO never slides... |
| 281 | const lldb::addr_t vmaddr = info.segments[seg_idx].vmaddr; |
| 282 | const lldb::addr_t vmsize = info.segments[seg_idx].vmsize; |
| 283 | Process::LoadRange pagezero_range(vmaddr, vmsize); |
| 284 | m_process->AddInvalidMemoryRegion(pagezero_range); |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | } |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 290 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 291 | } |
| 292 | // We might have an in memory image that was loaded as soon as it was created |
| 293 | if (info.load_stop_id == m_process->GetStopID()) |
| 294 | changed = true; |
| 295 | else if (changed) { |
| 296 | // Update the stop ID when this library was updated |
| 297 | info.load_stop_id = m_process->GetStopID(); |
| 298 | } |
| 299 | return changed; |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 302 | // Unload the segments in MODULE using the INFO that is passed in. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 303 | bool DynamicLoaderDarwin::UnloadModuleSections(Module *module, |
| 304 | ImageInfo &info) { |
| 305 | bool changed = false; |
| 306 | if (module) { |
| 307 | ObjectFile *image_object_file = module->GetObjectFile(); |
| 308 | if (image_object_file) { |
| 309 | SectionList *section_list = image_object_file->GetSectionList(); |
| 310 | if (section_list) { |
| 311 | const size_t num_segments = info.segments.size(); |
| 312 | for (size_t i = 0; i < num_segments; ++i) { |
| 313 | SectionSP section_sp( |
| 314 | section_list->FindSectionByName(info.segments[i].name)); |
| 315 | if (section_sp) { |
| 316 | const addr_t old_section_load_addr = |
| 317 | info.segments[i].vmaddr + info.slide; |
| 318 | if (m_process->GetTarget().SetSectionUnloaded( |
| 319 | section_sp, old_section_load_addr)) |
| 320 | changed = true; |
| 321 | } else { |
| 322 | Host::SystemLog(Host::eSystemLogWarning, |
| 323 | "warning: unable to find and unload segment named " |
| 324 | "'%s' in '%s' in macosx dynamic loader plug-in.\n", |
| 325 | info.segments[i].name.AsCString("<invalid>"), |
| 326 | image_object_file->GetFileSpec().GetPath().c_str()); |
| 327 | } |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 328 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 329 | } |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 330 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 331 | } |
| 332 | return changed; |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 333 | } |
| 334 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 335 | // Given a JSON dictionary (from debugserver, most likely) of binary images |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 336 | // loaded in the inferior process, add the images to the ImageInfo collection. |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 337 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 338 | bool DynamicLoaderDarwin::JSONImageInformationIntoImageInfo( |
| 339 | StructuredData::ObjectSP image_details, |
| 340 | ImageInfo::collection &image_infos) { |
| 341 | StructuredData::ObjectSP images_sp = |
| 342 | image_details->GetAsDictionary()->GetValueForKey("images"); |
| 343 | if (images_sp.get() == nullptr) |
| 344 | return false; |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 345 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 346 | image_infos.resize(images_sp->GetAsArray()->GetSize()); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 347 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 348 | for (size_t i = 0; i < image_infos.size(); i++) { |
| 349 | StructuredData::ObjectSP image_sp = |
| 350 | images_sp->GetAsArray()->GetItemAtIndex(i); |
| 351 | if (image_sp.get() == nullptr || image_sp->GetAsDictionary() == nullptr) |
| 352 | return false; |
| 353 | StructuredData::Dictionary *image = image_sp->GetAsDictionary(); |
| Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 354 | // clang-format off |
| 355 | if (!image->HasKey("load_address") || |
| 356 | !image->HasKey("pathname") || |
| 357 | !image->HasKey("mod_date") || |
| 358 | !image->HasKey("mach_header") || |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 359 | image->GetValueForKey("mach_header")->GetAsDictionary() == nullptr || |
| Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 360 | !image->HasKey("segments") || |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 361 | image->GetValueForKey("segments")->GetAsArray() == nullptr || |
| Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 362 | !image->HasKey("uuid")) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 363 | return false; |
| 364 | } |
| Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 365 | // clang-format on |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 366 | image_infos[i].address = |
| 367 | image->GetValueForKey("load_address")->GetAsInteger()->GetValue(); |
| 368 | image_infos[i].mod_date = |
| 369 | image->GetValueForKey("mod_date")->GetAsInteger()->GetValue(); |
| 370 | image_infos[i].file_spec.SetFile( |
| Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 371 | image->GetValueForKey("pathname")->GetAsString()->GetValue(), |
| Jonas Devlieghere | 937348c | 2018-06-13 22:08:14 +0000 | [diff] [blame] | 372 | FileSpec::Style::native); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 373 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 374 | StructuredData::Dictionary *mh = |
| 375 | image->GetValueForKey("mach_header")->GetAsDictionary(); |
| 376 | image_infos[i].header.magic = |
| 377 | mh->GetValueForKey("magic")->GetAsInteger()->GetValue(); |
| 378 | image_infos[i].header.cputype = |
| 379 | mh->GetValueForKey("cputype")->GetAsInteger()->GetValue(); |
| 380 | image_infos[i].header.cpusubtype = |
| 381 | mh->GetValueForKey("cpusubtype")->GetAsInteger()->GetValue(); |
| 382 | image_infos[i].header.filetype = |
| 383 | mh->GetValueForKey("filetype")->GetAsInteger()->GetValue(); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 384 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 385 | if (image->HasKey("min_version_os_name")) { |
| Benjamin Kramer | adcd026 | 2020-01-28 20:23:46 +0100 | [diff] [blame^] | 386 | std::string os_name = |
| 387 | std::string(image->GetValueForKey("min_version_os_name") |
| 388 | ->GetAsString() |
| 389 | ->GetValue()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 390 | if (os_name == "macosx") |
| 391 | image_infos[i].os_type = llvm::Triple::MacOSX; |
| 392 | else if (os_name == "ios" || os_name == "iphoneos") |
| 393 | image_infos[i].os_type = llvm::Triple::IOS; |
| 394 | else if (os_name == "tvos") |
| 395 | image_infos[i].os_type = llvm::Triple::TvOS; |
| 396 | else if (os_name == "watchos") |
| 397 | image_infos[i].os_type = llvm::Triple::WatchOS; |
| Jason Molenda | 32762fd | 2018-10-11 00:28:35 +0000 | [diff] [blame] | 398 | // NEED_BRIDGEOS_TRIPLE else if (os_name == "bridgeos") |
| 399 | // NEED_BRIDGEOS_TRIPLE image_infos[i].os_type = llvm::Triple::BridgeOS; |
| Adrian Prantl | 2461061 | 2019-09-04 17:23:15 +0000 | [diff] [blame] | 400 | else if (os_name == "maccatalyst") { |
| 401 | image_infos[i].os_type = llvm::Triple::IOS; |
| 402 | image_infos[i].os_env = llvm::Triple::MacABI; |
| 403 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 404 | } |
| 405 | if (image->HasKey("min_version_os_sdk")) { |
| 406 | image_infos[i].min_version_os_sdk = |
| Benjamin Kramer | adcd026 | 2020-01-28 20:23:46 +0100 | [diff] [blame^] | 407 | std::string(image->GetValueForKey("min_version_os_sdk") |
| 408 | ->GetAsString() |
| 409 | ->GetValue()); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 410 | } |
| 411 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 412 | // Fields that aren't used by DynamicLoaderDarwin so debugserver doesn't |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 413 | // currently send them in the reply. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 414 | |
| 415 | if (mh->HasKey("flags")) |
| 416 | image_infos[i].header.flags = |
| 417 | mh->GetValueForKey("flags")->GetAsInteger()->GetValue(); |
| 418 | else |
| 419 | image_infos[i].header.flags = 0; |
| 420 | |
| 421 | if (mh->HasKey("ncmds")) |
| 422 | image_infos[i].header.ncmds = |
| 423 | mh->GetValueForKey("ncmds")->GetAsInteger()->GetValue(); |
| 424 | else |
| 425 | image_infos[i].header.ncmds = 0; |
| 426 | |
| 427 | if (mh->HasKey("sizeofcmds")) |
| 428 | image_infos[i].header.sizeofcmds = |
| 429 | mh->GetValueForKey("sizeofcmds")->GetAsInteger()->GetValue(); |
| 430 | else |
| 431 | image_infos[i].header.sizeofcmds = 0; |
| 432 | |
| 433 | StructuredData::Array *segments = |
| 434 | image->GetValueForKey("segments")->GetAsArray(); |
| 435 | uint32_t segcount = segments->GetSize(); |
| 436 | for (size_t j = 0; j < segcount; j++) { |
| 437 | Segment segment; |
| 438 | StructuredData::Dictionary *seg = |
| 439 | segments->GetItemAtIndex(j)->GetAsDictionary(); |
| Zachary Turner | 2833321 | 2017-05-12 05:49:54 +0000 | [diff] [blame] | 440 | segment.name = |
| 441 | ConstString(seg->GetValueForKey("name")->GetAsString()->GetValue()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 442 | segment.vmaddr = |
| 443 | seg->GetValueForKey("vmaddr")->GetAsInteger()->GetValue(); |
| 444 | segment.vmsize = |
| 445 | seg->GetValueForKey("vmsize")->GetAsInteger()->GetValue(); |
| 446 | segment.fileoff = |
| 447 | seg->GetValueForKey("fileoff")->GetAsInteger()->GetValue(); |
| 448 | segment.filesize = |
| 449 | seg->GetValueForKey("filesize")->GetAsInteger()->GetValue(); |
| 450 | segment.maxprot = |
| 451 | seg->GetValueForKey("maxprot")->GetAsInteger()->GetValue(); |
| 452 | |
| 453 | // Fields that aren't used by DynamicLoaderDarwin so debugserver doesn't |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 454 | // currently send them in the reply. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 455 | |
| 456 | if (seg->HasKey("initprot")) |
| 457 | segment.initprot = |
| 458 | seg->GetValueForKey("initprot")->GetAsInteger()->GetValue(); |
| 459 | else |
| 460 | segment.initprot = 0; |
| 461 | |
| 462 | if (seg->HasKey("flags")) |
| 463 | segment.flags = |
| 464 | seg->GetValueForKey("flags")->GetAsInteger()->GetValue(); |
| 465 | else |
| 466 | segment.flags = 0; |
| 467 | |
| 468 | if (seg->HasKey("nsects")) |
| 469 | segment.nsects = |
| 470 | seg->GetValueForKey("nsects")->GetAsInteger()->GetValue(); |
| 471 | else |
| 472 | segment.nsects = 0; |
| 473 | |
| 474 | image_infos[i].segments.push_back(segment); |
| 475 | } |
| 476 | |
| Jim Ingham | f3ecbfc | 2019-01-24 22:43:44 +0000 | [diff] [blame] | 477 | image_infos[i].uuid.SetFromOptionalStringRef( |
| Zachary Turner | 2833321 | 2017-05-12 05:49:54 +0000 | [diff] [blame] | 478 | image->GetValueForKey("uuid")->GetAsString()->GetValue()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 479 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 480 | // All sections listed in the dyld image info structure will all either be |
| 481 | // fixed up already, or they will all be off by a single slide amount that |
| 482 | // is determined by finding the first segment that is at file offset zero |
| 483 | // which also has bytes (a file size that is greater than zero) in the |
| 484 | // object file. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 485 | |
| 486 | // Determine the slide amount (if any) |
| 487 | const size_t num_sections = image_infos[i].segments.size(); |
| 488 | for (size_t k = 0; k < num_sections; ++k) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 489 | // Iterate through the object file sections to find the first section |
| 490 | // that starts of file offset zero and that has bytes in the file... |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 491 | if ((image_infos[i].segments[k].fileoff == 0 && |
| 492 | image_infos[i].segments[k].filesize > 0) || |
| Raphael Isemann | 05cfdb0 | 2019-04-26 07:21:36 +0000 | [diff] [blame] | 493 | (image_infos[i].segments[k].name == "__TEXT")) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 494 | image_infos[i].slide = |
| 495 | image_infos[i].address - image_infos[i].segments[k].vmaddr; |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 496 | // We have found the slide amount, so we can exit this for loop. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 497 | break; |
| 498 | } |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | return true; |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 503 | } |
| 504 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 505 | void DynamicLoaderDarwin::UpdateSpecialBinariesFromNewImageInfos( |
| 506 | ImageInfo::collection &image_infos) { |
| 507 | uint32_t exe_idx = UINT32_MAX; |
| 508 | uint32_t dyld_idx = UINT32_MAX; |
| 509 | Target &target = m_process->GetTarget(); |
| 510 | Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); |
| 511 | ConstString g_dyld_sim_filename("dyld_sim"); |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 512 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 513 | ArchSpec target_arch = target.GetArchitecture(); |
| 514 | const size_t image_infos_size = image_infos.size(); |
| 515 | for (size_t i = 0; i < image_infos_size; i++) { |
| 516 | if (image_infos[i].header.filetype == llvm::MachO::MH_DYLINKER) { |
| Jason Molenda | 32762fd | 2018-10-11 00:28:35 +0000 | [diff] [blame] | 517 | // In a "simulator" process (an x86 process that is |
| 518 | // ios/tvos/watchos/bridgeos) we will have two dyld modules -- |
| 519 | // a "dyld" that we want to keep track of, and a "dyld_sim" which |
| 520 | // we don't need to keep track of here. If the target is an x86 |
| 521 | // system and the OS of the dyld binary is ios/tvos/watchos/bridgeos, |
| 522 | // then we are looking at dyld_sym. |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 523 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 524 | // debugserver has only recently (late 2016) started sending up the os |
| 525 | // type for each binary it sees -- so if we don't have an os type, use a |
| 526 | // filename check as our next best guess. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 527 | if (image_infos[i].os_type == llvm::Triple::OSType::UnknownOS) { |
| 528 | if (image_infos[i].file_spec.GetFilename() != g_dyld_sim_filename) { |
| 529 | dyld_idx = i; |
| 530 | } |
| 531 | } else if (target_arch.GetTriple().getArch() == llvm::Triple::x86 || |
| 532 | target_arch.GetTriple().getArch() == llvm::Triple::x86_64) { |
| 533 | if (image_infos[i].os_type != llvm::Triple::OSType::IOS && |
| 534 | image_infos[i].os_type != llvm::Triple::TvOS && |
| 535 | image_infos[i].os_type != llvm::Triple::WatchOS) { |
| Jason Molenda | 32762fd | 2018-10-11 00:28:35 +0000 | [diff] [blame] | 536 | // NEED_BRIDGEOS_TRIPLE image_infos[i].os_type != llvm::Triple::BridgeOS) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 537 | dyld_idx = i; |
| 538 | } |
| 539 | } |
| Jason Molenda | 777fcec | 2017-01-21 01:17:36 +0000 | [diff] [blame] | 540 | else { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 541 | // catch-all for any other environment -- trust that dyld is actually |
| 542 | // dyld |
| Jason Molenda | 777fcec | 2017-01-21 01:17:36 +0000 | [diff] [blame] | 543 | dyld_idx = i; |
| 544 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 545 | } else if (image_infos[i].header.filetype == llvm::MachO::MH_EXECUTE) { |
| 546 | exe_idx = i; |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | if (exe_idx != UINT32_MAX) { |
| 551 | const bool can_create = true; |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 552 | ModuleSP exe_module_sp(FindTargetModuleForImageInfo(image_infos[exe_idx], |
| 553 | can_create, nullptr)); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 554 | if (exe_module_sp) { |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 555 | LLDB_LOGF(log, "Found executable module: %s", |
| 556 | exe_module_sp->GetFileSpec().GetPath().c_str()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 557 | target.GetImages().AppendIfNeeded(exe_module_sp); |
| 558 | UpdateImageLoadAddress(exe_module_sp.get(), image_infos[exe_idx]); |
| 559 | if (exe_module_sp.get() != target.GetExecutableModulePointer()) { |
| Jonas Devlieghere | f9a07e9 | 2018-09-20 09:09:05 +0000 | [diff] [blame] | 560 | target.SetExecutableModule(exe_module_sp, eLoadDependentsNo); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | if (dyld_idx != UINT32_MAX) { |
| 566 | const bool can_create = true; |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 567 | ModuleSP dyld_sp = FindTargetModuleForImageInfo(image_infos[dyld_idx], |
| 568 | can_create, nullptr); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 569 | if (dyld_sp.get()) { |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 570 | LLDB_LOGF(log, "Found dyld module: %s", |
| 571 | dyld_sp->GetFileSpec().GetPath().c_str()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 572 | target.GetImages().AppendIfNeeded(dyld_sp); |
| 573 | UpdateImageLoadAddress(dyld_sp.get(), image_infos[dyld_idx]); |
| 574 | SetDYLDModule(dyld_sp); |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | void DynamicLoaderDarwin::UpdateDYLDImageInfoFromNewImageInfo( |
| 580 | ImageInfo &image_info) { |
| 581 | if (image_info.header.filetype == llvm::MachO::MH_DYLINKER) { |
| 582 | const bool can_create = true; |
| 583 | ModuleSP dyld_sp = |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 584 | FindTargetModuleForImageInfo(image_info, can_create, nullptr); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 585 | if (dyld_sp.get()) { |
| 586 | Target &target = m_process->GetTarget(); |
| 587 | target.GetImages().AppendIfNeeded(dyld_sp); |
| 588 | UpdateImageLoadAddress(dyld_sp.get(), image_info); |
| 589 | SetDYLDModule(dyld_sp); |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | void DynamicLoaderDarwin::SetDYLDModule(lldb::ModuleSP &dyld_module_sp) { |
| 595 | m_dyld_module_wp = dyld_module_sp; |
| 596 | } |
| 597 | |
| 598 | ModuleSP DynamicLoaderDarwin::GetDYLDModule() { |
| 599 | ModuleSP dyld_sp(m_dyld_module_wp.lock()); |
| 600 | return dyld_sp; |
| 601 | } |
| 602 | |
| 603 | bool DynamicLoaderDarwin::AddModulesUsingImageInfos( |
| 604 | ImageInfo::collection &image_infos) { |
| 605 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 606 | // Now add these images to the main list. |
| 607 | ModuleList loaded_module_list; |
| 608 | Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); |
| 609 | Target &target = m_process->GetTarget(); |
| 610 | ModuleList &target_images = target.GetImages(); |
| 611 | |
| 612 | for (uint32_t idx = 0; idx < image_infos.size(); ++idx) { |
| 613 | if (log) { |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 614 | LLDB_LOGF(log, "Adding new image at address=0x%16.16" PRIx64 ".", |
| 615 | image_infos[idx].address); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 616 | image_infos[idx].PutToLog(log); |
| 617 | } |
| 618 | |
| 619 | m_dyld_image_infos.push_back(image_infos[idx]); |
| 620 | |
| 621 | ModuleSP image_module_sp( |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 622 | FindTargetModuleForImageInfo(image_infos[idx], true, nullptr)); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 623 | |
| 624 | if (image_module_sp) { |
| 625 | ObjectFile *objfile = image_module_sp->GetObjectFile(); |
| 626 | if (objfile) { |
| 627 | SectionList *sections = objfile->GetSectionList(); |
| 628 | if (sections) { |
| 629 | ConstString commpage_dbstr("__commpage"); |
| 630 | Section *commpage_section = |
| 631 | sections->FindSectionByName(commpage_dbstr).get(); |
| 632 | if (commpage_section) { |
| 633 | ModuleSpec module_spec(objfile->GetFileSpec(), |
| 634 | image_infos[idx].GetArchitecture()); |
| 635 | module_spec.GetObjectName() = commpage_dbstr; |
| 636 | ModuleSP commpage_image_module_sp( |
| 637 | target_images.FindFirstModule(module_spec)); |
| 638 | if (!commpage_image_module_sp) { |
| 639 | module_spec.SetObjectOffset(objfile->GetFileOffset() + |
| 640 | commpage_section->GetFileOffset()); |
| 641 | module_spec.SetObjectSize(objfile->GetByteSize()); |
| Jason Molenda | 1724a17 | 2019-04-08 23:03:02 +0000 | [diff] [blame] | 642 | commpage_image_module_sp = target.GetOrCreateModule(module_spec, |
| 643 | true /* notify */); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 644 | if (!commpage_image_module_sp || |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 645 | commpage_image_module_sp->GetObjectFile() == nullptr) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 646 | commpage_image_module_sp = m_process->ReadModuleFromMemory( |
| 647 | image_infos[idx].file_spec, image_infos[idx].address); |
| 648 | // Always load a memory image right away in the target in case |
| 649 | // we end up trying to read the symbol table from memory... The |
| 650 | // __LINKEDIT will need to be mapped so we can figure out where |
| 651 | // the symbol table bits are... |
| 652 | bool changed = false; |
| 653 | UpdateImageLoadAddress(commpage_image_module_sp.get(), |
| 654 | image_infos[idx]); |
| 655 | target.GetImages().Append(commpage_image_module_sp); |
| 656 | if (changed) { |
| 657 | image_infos[idx].load_stop_id = m_process->GetStopID(); |
| 658 | loaded_module_list.AppendIfNeeded(commpage_image_module_sp); |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 659 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 660 | } |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 661 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 662 | } |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 663 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 664 | } |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 665 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 666 | // UpdateImageLoadAddress will return true if any segments change load |
| 667 | // address. We need to check this so we don't mention that all loaded |
| 668 | // shared libraries are newly loaded each time we hit out dyld breakpoint |
| 669 | // since dyld will list all shared libraries each time. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 670 | if (UpdateImageLoadAddress(image_module_sp.get(), image_infos[idx])) { |
| 671 | target_images.AppendIfNeeded(image_module_sp); |
| 672 | loaded_module_list.AppendIfNeeded(image_module_sp); |
| 673 | } |
| Adrian Prantl | 2461061 | 2019-09-04 17:23:15 +0000 | [diff] [blame] | 674 | |
| 675 | // macCataylst support: |
| 676 | // Update the module's platform with the DYLD info. |
| 677 | ArchSpec dyld_spec = image_infos[idx].GetArchitecture(); |
| 678 | if (dyld_spec.GetTriple().getOS() == llvm::Triple::IOS && |
| 679 | dyld_spec.GetTriple().getEnvironment() == llvm::Triple::MacABI) { |
| 680 | image_module_sp->MergeArchitecture(dyld_spec); |
| 681 | const auto &target_triple = target.GetArchitecture().GetTriple(); |
| 682 | // If dyld reports the process as being loaded as MACCATALYST, |
| 683 | // force-update the target's architecture to MACCATALYST. |
| 684 | if (!(target_triple.getOS() == llvm::Triple::IOS && |
| 685 | target_triple.getEnvironment() == llvm::Triple::MacABI)) |
| 686 | target.SetArchitecture(dyld_spec); |
| 687 | } |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 688 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 689 | } |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 690 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 691 | if (loaded_module_list.GetSize() > 0) { |
| 692 | if (log) |
| 693 | loaded_module_list.LogUUIDAndPaths(log, |
| 694 | "DynamicLoaderDarwin::ModulesDidLoad"); |
| 695 | m_process->GetTarget().ModulesDidLoad(loaded_module_list); |
| 696 | } |
| 697 | return true; |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 700 | // On Mac OS X libobjc (the Objective-C runtime) has several critical dispatch |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 701 | // functions written in hand-written assembly, and also have hand-written |
| 702 | // unwind information in the eh_frame section. Normally we prefer analyzing |
| 703 | // the assembly instructions of a currently executing frame to unwind from that |
| 704 | // frame -- but on hand-written functions this profiling can fail. We should |
| 705 | // use the eh_frame instructions for these functions all the time. |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 706 | // |
| 707 | // As an aside, it would be better if the eh_frame entries had a flag (or were |
| 708 | // extensible so they could have an Apple-specific flag) which indicates that |
| 709 | // the instructions are asynchronous -- accurate at every instruction, instead |
| 710 | // of our normal default assumption that they are not. |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 711 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 712 | bool DynamicLoaderDarwin::AlwaysRelyOnEHUnwindInfo(SymbolContext &sym_ctx) { |
| 713 | ModuleSP module_sp; |
| 714 | if (sym_ctx.symbol) { |
| 715 | module_sp = sym_ctx.symbol->GetAddressRef().GetModule(); |
| 716 | } |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 717 | if (module_sp.get() == nullptr && sym_ctx.function) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 718 | module_sp = |
| 719 | sym_ctx.function->GetAddressRange().GetBaseAddress().GetModule(); |
| 720 | } |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 721 | if (module_sp.get() == nullptr) |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 722 | return false; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 723 | |
| Alex Langford | e823bbe | 2019-06-10 20:53:23 +0000 | [diff] [blame] | 724 | ObjCLanguageRuntime *objc_runtime = ObjCLanguageRuntime::Get(*m_process); |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 725 | return objc_runtime != nullptr && |
| 726 | objc_runtime->IsModuleObjCLibrary(module_sp); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 729 | // Dump a Segment to the file handle provided. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 730 | void DynamicLoaderDarwin::Segment::PutToLog(Log *log, |
| 731 | lldb::addr_t slide) const { |
| 732 | if (log) { |
| 733 | if (slide == 0) |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 734 | LLDB_LOGF(log, "\t\t%16s [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")", |
| 735 | name.AsCString(""), vmaddr + slide, vmaddr + slide + vmsize); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 736 | else |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 737 | LLDB_LOGF(log, |
| 738 | "\t\t%16s [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 |
| 739 | ") slide = 0x%" PRIx64, |
| 740 | name.AsCString(""), vmaddr + slide, vmaddr + slide + vmsize, |
| 741 | slide); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 742 | } |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 743 | } |
| 744 | |
| Adrian Prantl | 2461061 | 2019-09-04 17:23:15 +0000 | [diff] [blame] | 745 | lldb_private::ArchSpec DynamicLoaderDarwin::ImageInfo::GetArchitecture() const { |
| 746 | // Update the module's platform with the DYLD info. |
| 747 | lldb_private::ArchSpec arch_spec(lldb_private::eArchTypeMachO, header.cputype, |
| 748 | header.cpusubtype); |
| 749 | if (os_type == llvm::Triple::IOS && os_env == llvm::Triple::MacABI) { |
| 750 | llvm::Triple triple(llvm::Twine("x86_64-apple-ios") + min_version_os_sdk + |
| 751 | "-macabi"); |
| 752 | ArchSpec maccatalyst_spec(triple); |
| 753 | if (arch_spec.IsCompatibleMatch(maccatalyst_spec)) |
| 754 | arch_spec.MergeFrom(maccatalyst_spec); |
| 755 | } |
| 756 | return arch_spec; |
| 757 | } |
| 758 | |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 759 | const DynamicLoaderDarwin::Segment * |
| Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 760 | DynamicLoaderDarwin::ImageInfo::FindSegment(ConstString name) const { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 761 | const size_t num_segments = segments.size(); |
| 762 | for (size_t i = 0; i < num_segments; ++i) { |
| 763 | if (segments[i].name == name) |
| 764 | return &segments[i]; |
| 765 | } |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 766 | return nullptr; |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 767 | } |
| 768 | |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 769 | // Dump an image info structure to the file handle provided. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 770 | void DynamicLoaderDarwin::ImageInfo::PutToLog(Log *log) const { |
| Pavel Labath | fbb1428 | 2018-06-20 20:13:04 +0000 | [diff] [blame] | 771 | if (!log) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 772 | return; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 773 | if (address == LLDB_INVALID_ADDRESS) { |
| Pavel Labath | fbb1428 | 2018-06-20 20:13:04 +0000 | [diff] [blame] | 774 | LLDB_LOG(log, "modtime={0:x+8} uuid={1} path='{2}' (UNLOADED)", mod_date, |
| 775 | uuid.GetAsString(), file_spec.GetPath()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 776 | } else { |
| Pavel Labath | fbb1428 | 2018-06-20 20:13:04 +0000 | [diff] [blame] | 777 | LLDB_LOG(log, "address={0:x+16} modtime={1:x+8} uuid={2} path='{3}'", |
| 778 | address, mod_date, uuid.GetAsString(), file_spec.GetPath()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 779 | for (uint32_t i = 0; i < segments.size(); ++i) |
| 780 | segments[i].PutToLog(log, slide); |
| 781 | } |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 782 | } |
| 783 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 784 | void DynamicLoaderDarwin::PrivateInitialize(Process *process) { |
| 785 | DEBUG_PRINTF("DynamicLoaderDarwin::%s() process state = %s\n", __FUNCTION__, |
| 786 | StateAsCString(m_process->GetState())); |
| 787 | Clear(true); |
| 788 | m_process = process; |
| 789 | m_process->GetTarget().ClearAllLoadedSections(); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 790 | } |
| 791 | |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 792 | // Member function that gets called when the process state changes. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 793 | void DynamicLoaderDarwin::PrivateProcessStateChanged(Process *process, |
| 794 | StateType state) { |
| 795 | DEBUG_PRINTF("DynamicLoaderDarwin::%s(%s)\n", __FUNCTION__, |
| 796 | StateAsCString(state)); |
| 797 | switch (state) { |
| 798 | case eStateConnected: |
| 799 | case eStateAttaching: |
| 800 | case eStateLaunching: |
| 801 | case eStateInvalid: |
| 802 | case eStateUnloaded: |
| 803 | case eStateExited: |
| 804 | case eStateDetached: |
| 805 | Clear(false); |
| 806 | break; |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 807 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 808 | case eStateStopped: |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 809 | // Keep trying find dyld and set our notification breakpoint each time we |
| 810 | // stop until we succeed |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 811 | if (!DidSetNotificationBreakpoint() && m_process->IsAlive()) { |
| 812 | if (NeedToDoInitialImageFetch()) |
| 813 | DoInitialImageFetch(); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 814 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 815 | SetNotificationBreakpoint(); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 816 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 817 | break; |
| 818 | |
| 819 | case eStateRunning: |
| 820 | case eStateStepping: |
| 821 | case eStateCrashed: |
| 822 | case eStateSuspended: |
| 823 | break; |
| 824 | } |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | ThreadPlanSP |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 828 | DynamicLoaderDarwin::GetStepThroughTrampolinePlan(Thread &thread, |
| 829 | bool stop_others) { |
| 830 | ThreadPlanSP thread_plan_sp; |
| 831 | StackFrame *current_frame = thread.GetStackFrameAtIndex(0).get(); |
| 832 | const SymbolContext ¤t_context = |
| 833 | current_frame->GetSymbolContext(eSymbolContextSymbol); |
| 834 | Symbol *current_symbol = current_context.symbol; |
| 835 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); |
| 836 | TargetSP target_sp(thread.CalculateTarget()); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 837 | |
| Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 838 | if (current_symbol != nullptr) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 839 | std::vector<Address> addresses; |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 840 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 841 | if (current_symbol->IsTrampoline()) { |
| Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 842 | ConstString trampoline_name = current_symbol->GetMangled().GetName( |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 843 | current_symbol->GetLanguage(), Mangled::ePreferMangled); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 844 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 845 | if (trampoline_name) { |
| 846 | const ModuleList &images = target_sp->GetImages(); |
| 847 | |
| 848 | SymbolContextList code_symbols; |
| 849 | images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeCode, |
| 850 | code_symbols); |
| 851 | size_t num_code_symbols = code_symbols.GetSize(); |
| 852 | |
| 853 | if (num_code_symbols > 0) { |
| 854 | for (uint32_t i = 0; i < num_code_symbols; i++) { |
| 855 | SymbolContext context; |
| 856 | AddressRange addr_range; |
| 857 | if (code_symbols.GetContextAtIndex(i, context)) { |
| 858 | context.GetAddressRange(eSymbolContextEverything, 0, false, |
| 859 | addr_range); |
| 860 | addresses.push_back(addr_range.GetBaseAddress()); |
| 861 | if (log) { |
| 862 | addr_t load_addr = |
| 863 | addr_range.GetBaseAddress().GetLoadAddress(target_sp.get()); |
| 864 | |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 865 | LLDB_LOGF(log, |
| 866 | "Found a trampoline target symbol at 0x%" PRIx64 ".", |
| 867 | load_addr); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 868 | } |
| 869 | } |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | SymbolContextList reexported_symbols; |
| 874 | images.FindSymbolsWithNameAndType( |
| 875 | trampoline_name, eSymbolTypeReExported, reexported_symbols); |
| 876 | size_t num_reexported_symbols = reexported_symbols.GetSize(); |
| 877 | if (num_reexported_symbols > 0) { |
| 878 | for (uint32_t i = 0; i < num_reexported_symbols; i++) { |
| 879 | SymbolContext context; |
| 880 | if (reexported_symbols.GetContextAtIndex(i, context)) { |
| 881 | if (context.symbol) { |
| 882 | Symbol *actual_symbol = |
| 883 | context.symbol->ResolveReExportedSymbol(*target_sp.get()); |
| 884 | if (actual_symbol) { |
| 885 | const Address actual_symbol_addr = |
| 886 | actual_symbol->GetAddress(); |
| 887 | if (actual_symbol_addr.IsValid()) { |
| 888 | addresses.push_back(actual_symbol_addr); |
| 889 | if (log) { |
| 890 | lldb::addr_t load_addr = |
| 891 | actual_symbol_addr.GetLoadAddress(target_sp.get()); |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 892 | LLDB_LOGF( |
| 893 | log, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 894 | "Found a re-exported symbol: %s at 0x%" PRIx64 ".", |
| 895 | actual_symbol->GetName().GetCString(), load_addr); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 896 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 897 | } |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 898 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 899 | } |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 900 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 901 | } |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 902 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 903 | |
| 904 | SymbolContextList indirect_symbols; |
| 905 | images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeResolver, |
| 906 | indirect_symbols); |
| 907 | size_t num_indirect_symbols = indirect_symbols.GetSize(); |
| 908 | if (num_indirect_symbols > 0) { |
| 909 | for (uint32_t i = 0; i < num_indirect_symbols; i++) { |
| 910 | SymbolContext context; |
| 911 | AddressRange addr_range; |
| 912 | if (indirect_symbols.GetContextAtIndex(i, context)) { |
| 913 | context.GetAddressRange(eSymbolContextEverything, 0, false, |
| 914 | addr_range); |
| 915 | addresses.push_back(addr_range.GetBaseAddress()); |
| 916 | if (log) { |
| 917 | addr_t load_addr = |
| 918 | addr_range.GetBaseAddress().GetLoadAddress(target_sp.get()); |
| 919 | |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 920 | LLDB_LOGF(log, |
| 921 | "Found an indirect target symbol at 0x%" PRIx64 ".", |
| 922 | load_addr); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 923 | } |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 924 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 925 | } |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 926 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 927 | } |
| 928 | } else if (current_symbol->GetType() == eSymbolTypeReExported) { |
| 929 | // I am not sure we could ever end up stopped AT a re-exported symbol. |
| 930 | // But just in case: |
| 931 | |
| 932 | const Symbol *actual_symbol = |
| 933 | current_symbol->ResolveReExportedSymbol(*(target_sp.get())); |
| 934 | if (actual_symbol) { |
| 935 | Address target_addr(actual_symbol->GetAddress()); |
| 936 | if (target_addr.IsValid()) { |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 937 | LLDB_LOGF( |
| 938 | log, |
| 939 | "Found a re-exported symbol: %s pointing to: %s at 0x%" PRIx64 |
| 940 | ".", |
| 941 | current_symbol->GetName().GetCString(), |
| 942 | actual_symbol->GetName().GetCString(), |
| 943 | target_addr.GetLoadAddress(target_sp.get())); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 944 | addresses.push_back(target_addr.GetLoadAddress(target_sp.get())); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 945 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 946 | } |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 947 | } |
| 948 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 949 | if (addresses.size() > 0) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 950 | // First check whether any of the addresses point to Indirect symbols, |
| 951 | // and if they do, resolve them: |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 952 | std::vector<lldb::addr_t> load_addrs; |
| 953 | for (Address address : addresses) { |
| 954 | Symbol *symbol = address.CalculateSymbolContextSymbol(); |
| 955 | if (symbol && symbol->IsIndirect()) { |
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 956 | Status error; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 957 | Address symbol_address = symbol->GetAddress(); |
| 958 | addr_t resolved_addr = thread.GetProcess()->ResolveIndirectFunction( |
| 959 | &symbol_address, error); |
| 960 | if (error.Success()) { |
| 961 | load_addrs.push_back(resolved_addr); |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 962 | LLDB_LOGF(log, |
| 963 | "ResolveIndirectFunction found resolved target for " |
| 964 | "%s at 0x%" PRIx64 ".", |
| 965 | symbol->GetName().GetCString(), resolved_addr); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 966 | } |
| 967 | } else { |
| 968 | load_addrs.push_back(address.GetLoadAddress(target_sp.get())); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 969 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 970 | } |
| Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 971 | thread_plan_sp = std::make_shared<ThreadPlanRunToAddress>( |
| 972 | thread, load_addrs, stop_others); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 973 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 974 | } else { |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 975 | LLDB_LOGF(log, "Could not find symbol for step through."); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | return thread_plan_sp; |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 979 | } |
| 980 | |
| Adrian Prantl | 1ad655e | 2019-10-17 19:56:40 +0000 | [diff] [blame] | 981 | void DynamicLoaderDarwin::FindEquivalentSymbols( |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 982 | lldb_private::Symbol *original_symbol, lldb_private::ModuleList &images, |
| 983 | lldb_private::SymbolContextList &equivalent_symbols) { |
| Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 984 | ConstString trampoline_name = original_symbol->GetMangled().GetName( |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 985 | original_symbol->GetLanguage(), Mangled::ePreferMangled); |
| 986 | if (!trampoline_name) |
| Adrian Prantl | 1ad655e | 2019-10-17 19:56:40 +0000 | [diff] [blame] | 987 | return; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 988 | |
| 989 | static const char *resolver_name_regex = "(_gc|_non_gc|\\$[A-Za-z0-9\\$]+)$"; |
| 990 | std::string equivalent_regex_buf("^"); |
| 991 | equivalent_regex_buf.append(trampoline_name.GetCString()); |
| 992 | equivalent_regex_buf.append(resolver_name_regex); |
| 993 | |
| Zachary Turner | 95eae42 | 2016-09-21 16:01:28 +0000 | [diff] [blame] | 994 | RegularExpression equivalent_name_regex(equivalent_regex_buf); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 995 | images.FindSymbolsMatchingRegExAndType(equivalent_name_regex, eSymbolTypeCode, |
| Adrian Prantl | 1ad655e | 2019-10-17 19:56:40 +0000 | [diff] [blame] | 996 | equivalent_symbols); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 997 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | lldb::ModuleSP DynamicLoaderDarwin::GetPThreadLibraryModule() { |
| 1001 | ModuleSP module_sp = m_libpthread_module_wp.lock(); |
| 1002 | if (!module_sp) { |
| 1003 | SymbolContextList sc_list; |
| 1004 | ModuleSpec module_spec; |
| 1005 | module_spec.GetFileSpec().GetFilename().SetCString( |
| 1006 | "libsystem_pthread.dylib"); |
| 1007 | ModuleList module_list; |
| Adrian Prantl | 1ad655e | 2019-10-17 19:56:40 +0000 | [diff] [blame] | 1008 | m_process->GetTarget().GetImages().FindModules(module_spec, module_list); |
| 1009 | if (!module_list.IsEmpty()) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1010 | if (module_list.GetSize() == 1) { |
| 1011 | module_sp = module_list.GetModuleAtIndex(0); |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 1012 | if (module_sp) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1013 | m_libpthread_module_wp = module_sp; |
| 1014 | } |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 1015 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1016 | } |
| 1017 | return module_sp; |
| 1018 | } |
| 1019 | |
| 1020 | Address DynamicLoaderDarwin::GetPthreadSetSpecificAddress() { |
| 1021 | if (!m_pthread_getspecific_addr.IsValid()) { |
| 1022 | ModuleSP module_sp = GetPThreadLibraryModule(); |
| 1023 | if (module_sp) { |
| 1024 | lldb_private::SymbolContextList sc_list; |
| 1025 | module_sp->FindSymbolsWithNameAndType(ConstString("pthread_getspecific"), |
| 1026 | eSymbolTypeCode, sc_list); |
| 1027 | SymbolContext sc; |
| 1028 | if (sc_list.GetContextAtIndex(0, sc)) { |
| 1029 | if (sc.symbol) |
| 1030 | m_pthread_getspecific_addr = sc.symbol->GetAddress(); |
| 1031 | } |
| 1032 | } |
| 1033 | } |
| 1034 | return m_pthread_getspecific_addr; |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | lldb::addr_t |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1038 | DynamicLoaderDarwin::GetThreadLocalData(const lldb::ModuleSP module_sp, |
| 1039 | const lldb::ThreadSP thread_sp, |
| 1040 | lldb::addr_t tls_file_addr) { |
| 1041 | if (!thread_sp || !module_sp) |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 1042 | return LLDB_INVALID_ADDRESS; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1043 | |
| 1044 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 1045 | |
| 1046 | const uint32_t addr_size = m_process->GetAddressByteSize(); |
| 1047 | uint8_t buf[sizeof(lldb::addr_t) * 3]; |
| 1048 | |
| 1049 | lldb_private::Address tls_addr; |
| 1050 | if (module_sp->ResolveFileAddress(tls_file_addr, tls_addr)) { |
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1051 | Status error; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1052 | const size_t tsl_data_size = addr_size * 3; |
| 1053 | Target &target = m_process->GetTarget(); |
| 1054 | if (target.ReadMemory(tls_addr, false, buf, tsl_data_size, error) == |
| 1055 | tsl_data_size) { |
| 1056 | const ByteOrder byte_order = m_process->GetByteOrder(); |
| 1057 | DataExtractor data(buf, sizeof(buf), byte_order, addr_size); |
| 1058 | lldb::offset_t offset = addr_size; // Skip the first pointer |
| 1059 | const lldb::addr_t pthread_key = data.GetAddress(&offset); |
| 1060 | const lldb::addr_t tls_offset = data.GetAddress(&offset); |
| 1061 | if (pthread_key != 0) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1062 | // First check to see if we have already figured out the location of |
| 1063 | // TLS data for the pthread_key on a specific thread yet. If we have we |
| 1064 | // can re-use it since its location will not change unless the process |
| 1065 | // execs. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1066 | const tid_t tid = thread_sp->GetID(); |
| 1067 | auto tid_pos = m_tid_to_tls_map.find(tid); |
| 1068 | if (tid_pos != m_tid_to_tls_map.end()) { |
| 1069 | auto tls_pos = tid_pos->second.find(pthread_key); |
| 1070 | if (tls_pos != tid_pos->second.end()) { |
| 1071 | return tls_pos->second + tls_offset; |
| 1072 | } |
| 1073 | } |
| 1074 | StackFrameSP frame_sp = thread_sp->GetStackFrameAtIndex(0); |
| 1075 | if (frame_sp) { |
| Raphael Isemann | 6e3b0cc | 2020-01-23 10:04:13 +0100 | [diff] [blame] | 1076 | TypeSystemClang *clang_ast_context = |
| 1077 | TypeSystemClang::GetScratch(target); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1078 | |
| 1079 | if (!clang_ast_context) |
| 1080 | return LLDB_INVALID_ADDRESS; |
| 1081 | |
| 1082 | CompilerType clang_void_ptr_type = |
| 1083 | clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); |
| 1084 | Address pthread_getspecific_addr = GetPthreadSetSpecificAddress(); |
| 1085 | if (pthread_getspecific_addr.IsValid()) { |
| 1086 | EvaluateExpressionOptions options; |
| 1087 | |
| 1088 | lldb::ThreadPlanSP thread_plan_sp(new ThreadPlanCallFunction( |
| 1089 | *thread_sp, pthread_getspecific_addr, clang_void_ptr_type, |
| 1090 | llvm::ArrayRef<lldb::addr_t>(pthread_key), options)); |
| 1091 | |
| 1092 | DiagnosticManager execution_errors; |
| 1093 | ExecutionContext exe_ctx(thread_sp); |
| 1094 | lldb::ExpressionResults results = m_process->RunThreadPlan( |
| 1095 | exe_ctx, thread_plan_sp, options, execution_errors); |
| 1096 | |
| 1097 | if (results == lldb::eExpressionCompleted) { |
| 1098 | lldb::ValueObjectSP result_valobj_sp = |
| 1099 | thread_plan_sp->GetReturnValueObject(); |
| 1100 | if (result_valobj_sp) { |
| 1101 | const lldb::addr_t pthread_key_data = |
| 1102 | result_valobj_sp->GetValueAsUnsigned(0); |
| 1103 | if (pthread_key_data) { |
| 1104 | m_tid_to_tls_map[tid].insert( |
| 1105 | std::make_pair(pthread_key, pthread_key_data)); |
| 1106 | return pthread_key_data + tls_offset; |
| 1107 | } |
| 1108 | } |
| 1109 | } |
| 1110 | } |
| 1111 | } |
| 1112 | } |
| 1113 | } |
| 1114 | } |
| 1115 | return LLDB_INVALID_ADDRESS; |
| Jason Molenda | 5fe4d14 | 2016-07-17 21:27:32 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1118 | bool DynamicLoaderDarwin::UseDYLDSPI(Process *process) { |
| 1119 | Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1120 | bool use_new_spi_interface = false; |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 1121 | |
| Pavel Labath | 2272c48 | 2018-06-18 15:02:23 +0000 | [diff] [blame] | 1122 | llvm::VersionTuple version = process->GetHostOSVersion(); |
| 1123 | if (!version.empty()) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1124 | const llvm::Triple::OSType os_type = |
| 1125 | process->GetTarget().GetArchitecture().GetTriple().getOS(); |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 1126 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1127 | // macOS 10.12 and newer |
| 1128 | if (os_type == llvm::Triple::MacOSX && |
| Pavel Labath | 2272c48 | 2018-06-18 15:02:23 +0000 | [diff] [blame] | 1129 | version >= llvm::VersionTuple(10, 12)) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1130 | use_new_spi_interface = true; |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 1131 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1132 | // iOS 10 and newer |
| Pavel Labath | 2272c48 | 2018-06-18 15:02:23 +0000 | [diff] [blame] | 1133 | if (os_type == llvm::Triple::IOS && version >= llvm::VersionTuple(10)) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1134 | use_new_spi_interface = true; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1135 | |
| 1136 | // tvOS 10 and newer |
| Pavel Labath | 2272c48 | 2018-06-18 15:02:23 +0000 | [diff] [blame] | 1137 | if (os_type == llvm::Triple::TvOS && version >= llvm::VersionTuple(10)) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1138 | use_new_spi_interface = true; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1139 | |
| 1140 | // watchOS 3 and newer |
| Pavel Labath | 2272c48 | 2018-06-18 15:02:23 +0000 | [diff] [blame] | 1141 | if (os_type == llvm::Triple::WatchOS && version >= llvm::VersionTuple(3)) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1142 | use_new_spi_interface = true; |
| Jason Molenda | 32762fd | 2018-10-11 00:28:35 +0000 | [diff] [blame] | 1143 | |
| 1144 | // NEED_BRIDGEOS_TRIPLE // Any BridgeOS |
| 1145 | // NEED_BRIDGEOS_TRIPLE if (os_type == llvm::Triple::BridgeOS) |
| 1146 | // NEED_BRIDGEOS_TRIPLE use_new_spi_interface = true; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1149 | if (log) { |
| 1150 | if (use_new_spi_interface) |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1151 | LLDB_LOGF( |
| 1152 | log, "DynamicLoaderDarwin::UseDYLDSPI: Use new DynamicLoader plugin"); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1153 | else |
| Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1154 | LLDB_LOGF( |
| 1155 | log, "DynamicLoaderDarwin::UseDYLDSPI: Use old DynamicLoader plugin"); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1156 | } |
| 1157 | return use_new_spi_interface; |
| Jason Molenda | 9ab5dc2 | 2016-07-21 08:30:55 +0000 | [diff] [blame] | 1158 | } |