Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1 | //===-- DynamicLoaderDarwinKernel.cpp -----------------------------*- C++ -*-===// |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Daniel Malea | d891f9b | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 12 | #include "lldb/Breakpoint/StoppointCallbackContext.h" |
| 13 | #include "lldb/Core/DataBuffer.h" |
| 14 | #include "lldb/Core/DataBufferHeap.h" |
Greg Clayton | 234981a | 2011-07-20 03:41:06 +0000 | [diff] [blame] | 15 | #include "lldb/Core/Debugger.h" |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Log.h" |
| 17 | #include "lldb/Core/Module.h" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 18 | #include "lldb/Core/ModuleSpec.h" |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 19 | #include "lldb/Core/PluginManager.h" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Section.h" |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 21 | #include "lldb/Core/State.h" |
Jason Molenda | 4952db8 | 2012-10-02 03:49:41 +0000 | [diff] [blame] | 22 | #include "lldb/Host/Symbols.h" |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 23 | #include "lldb/Symbol/ObjectFile.h" |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 24 | #include "lldb/Target/RegisterContext.h" |
Jason Molenda | 4952db8 | 2012-10-02 03:49:41 +0000 | [diff] [blame] | 25 | #include "lldb/Target/StackFrame.h" |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 26 | #include "lldb/Target/Target.h" |
| 27 | #include "lldb/Target/Thread.h" |
| 28 | #include "lldb/Target/ThreadPlanRunToAddress.h" |
Jason Molenda | 4952db8 | 2012-10-02 03:49:41 +0000 | [diff] [blame] | 29 | |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 30 | |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 31 | #include "DynamicLoaderDarwinKernel.h" |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 32 | |
| 33 | //#define ENABLE_DEBUG_PRINTF // COMMENT THIS LINE OUT PRIOR TO CHECKIN |
| 34 | #ifdef ENABLE_DEBUG_PRINTF |
| 35 | #include <stdio.h> |
| 36 | #define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__) |
| 37 | #else |
| 38 | #define DEBUG_PRINTF(fmt, ...) |
| 39 | #endif |
| 40 | |
| 41 | using namespace lldb; |
| 42 | using namespace lldb_private; |
| 43 | |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 44 | // Progressively greater amounts of scanning we will allow |
| 45 | // For some targets very early in startup, we can't do any random reads of memory or we can crash the device |
| 46 | // so a setting is needed that can completely disable the KASLR scans. |
| 47 | |
| 48 | enum KASLRScanType |
| 49 | { |
| 50 | eKASLRScanNone = 0, // No reading into the inferior at all |
| 51 | eKASLRScanLowgloAddresses, // Check one word of memory for a possible kernel addr, then see if a kernel is there |
Jason Molenda | 94c0f4c | 2013-01-30 04:48:16 +0000 | [diff] [blame] | 52 | eKASLRScanNearPC, // Scan backwards from the current $pc looking for kernel; checking at 96 locations total |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 53 | eKASLRScanExhaustiveScan // Scan through the entire possible kernel address range looking for a kernel |
| 54 | }; |
| 55 | |
| 56 | OptionEnumValueElement |
| 57 | g_kaslr_kernel_scan_enum_values[] = |
| 58 | { |
| 59 | { eKASLRScanNone, "none", "Do not read memory looking for a Darwin kernel when attaching." }, |
| 60 | { eKASLRScanLowgloAddresses, "basic", "Check for the Darwin kernel's load addr in the lowglo page (boot-args=debug) only." }, |
| 61 | { eKASLRScanNearPC, "fast-scan", "Scan near the pc value on attach to find the Darwin kernel's load address."}, |
| 62 | { eKASLRScanExhaustiveScan, "exhaustive-scan", "Scan through the entire potential address range of Darwin kernel (only on 32-bit targets)."}, |
| 63 | { 0, NULL, NULL } |
| 64 | }; |
| 65 | |
Greg Clayton | 87e9d32 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 66 | static PropertyDefinition |
| 67 | g_properties[] = |
| 68 | { |
Greg Clayton | 2f27af8 | 2012-10-19 20:53:18 +0000 | [diff] [blame] | 69 | { "load-kexts" , OptionValue::eTypeBoolean, true, true, NULL, NULL, "Automatically loads kext images when attaching to a kernel." }, |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 70 | { "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." }, |
Greg Clayton | 2f27af8 | 2012-10-19 20:53:18 +0000 | [diff] [blame] | 71 | { NULL , OptionValue::eTypeInvalid, false, 0 , NULL, NULL, NULL } |
Greg Clayton | 87e9d32 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | enum { |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 75 | ePropertyLoadKexts, |
| 76 | ePropertyScanType |
Greg Clayton | 87e9d32 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | class DynamicLoaderDarwinKernelProperties : public Properties |
| 80 | { |
| 81 | public: |
| 82 | |
| 83 | static ConstString & |
| 84 | GetSettingName () |
| 85 | { |
Greg Clayton | 2acbc2a | 2012-10-19 18:14:47 +0000 | [diff] [blame] | 86 | static ConstString g_setting_name("darwin-kernel"); |
Greg Clayton | 87e9d32 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 87 | return g_setting_name; |
| 88 | } |
| 89 | |
| 90 | DynamicLoaderDarwinKernelProperties() : |
| 91 | Properties () |
| 92 | { |
| 93 | m_collection_sp.reset (new OptionValueProperties(GetSettingName())); |
| 94 | m_collection_sp->Initialize(g_properties); |
| 95 | } |
| 96 | |
| 97 | virtual |
| 98 | ~DynamicLoaderDarwinKernelProperties() |
| 99 | { |
| 100 | } |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 101 | |
Greg Clayton | 87e9d32 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 102 | bool |
Greg Clayton | 2f27af8 | 2012-10-19 20:53:18 +0000 | [diff] [blame] | 103 | GetLoadKexts() const |
Greg Clayton | 87e9d32 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 104 | { |
Greg Clayton | 2f27af8 | 2012-10-19 20:53:18 +0000 | [diff] [blame] | 105 | const uint32_t idx = ePropertyLoadKexts; |
Greg Clayton | 87e9d32 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 106 | return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); |
| 107 | } |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 108 | |
| 109 | KASLRScanType |
| 110 | GetScanType() const |
| 111 | { |
| 112 | const uint32_t idx = ePropertyScanType; |
Jason Molenda | 94c0f4c | 2013-01-30 04:48:16 +0000 | [diff] [blame] | 113 | return (KASLRScanType) m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value); |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | |
Greg Clayton | 87e9d32 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 117 | }; |
| 118 | |
Greg Clayton | 102b2c2 | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 119 | typedef std::shared_ptr<DynamicLoaderDarwinKernelProperties> DynamicLoaderDarwinKernelPropertiesSP; |
Greg Clayton | 87e9d32 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 120 | |
| 121 | static const DynamicLoaderDarwinKernelPropertiesSP & |
| 122 | GetGlobalProperties() |
| 123 | { |
| 124 | static DynamicLoaderDarwinKernelPropertiesSP g_settings_sp; |
| 125 | if (!g_settings_sp) |
| 126 | g_settings_sp.reset (new DynamicLoaderDarwinKernelProperties ()); |
| 127 | return g_settings_sp; |
| 128 | } |
| 129 | |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 130 | //---------------------------------------------------------------------- |
| 131 | // Create an instance of this class. This function is filled into |
| 132 | // the plugin info class that gets handed out by the plugin factory and |
| 133 | // allows the lldb to instantiate an instance of this class. |
| 134 | //---------------------------------------------------------------------- |
| 135 | DynamicLoader * |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 136 | DynamicLoaderDarwinKernel::CreateInstance (Process* process, bool force) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 137 | { |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 138 | if (!force) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 139 | { |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 140 | // If the user provided an executable binary and it is not a kernel, |
| 141 | // this plugin should not create an instance. |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 142 | Module* exe_module = process->GetTarget().GetExecutableModulePointer(); |
Greg Clayton | 40f7917 | 2011-07-08 04:11:42 +0000 | [diff] [blame] | 143 | if (exe_module) |
| 144 | { |
| 145 | ObjectFile *object_file = exe_module->GetObjectFile(); |
| 146 | if (object_file) |
| 147 | { |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 148 | if (object_file->GetStrata() != ObjectFile::eStrataKernel) |
| 149 | { |
| 150 | return NULL; |
| 151 | } |
Greg Clayton | 40f7917 | 2011-07-08 04:11:42 +0000 | [diff] [blame] | 152 | } |
| 153 | } |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 154 | |
| 155 | // If the target's architecture does not look like an Apple environment, |
| 156 | // this plugin should not create an instance. |
| 157 | const llvm::Triple &triple_ref = process->GetTarget().GetArchitecture().GetTriple(); |
| 158 | switch (triple_ref.getOS()) |
Greg Clayton | 40f7917 | 2011-07-08 04:11:42 +0000 | [diff] [blame] | 159 | { |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 160 | case llvm::Triple::Darwin: |
| 161 | case llvm::Triple::MacOSX: |
| 162 | case llvm::Triple::IOS: |
| 163 | if (triple_ref.getVendor() != llvm::Triple::Apple) |
| 164 | { |
| 165 | return NULL; |
| 166 | } |
| 167 | break; |
| 168 | // If we have triple like armv7-unknown-unknown, we should try looking for a Darwin kernel. |
| 169 | case llvm::Triple::UnknownOS: |
| 170 | break; |
| 171 | default: |
| 172 | return NULL; |
| 173 | break; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | // At this point if there is an ExecutableModule, it is a kernel and the Target is some variant of an Apple system. |
| 178 | // If the Process hasn't provided the kernel load address, we need to look around in memory to find it. |
| 179 | |
Jason Molenda | cd0dd8f | 2013-03-02 07:19:32 +0000 | [diff] [blame] | 180 | addr_t kernel_load_address = SearchForDarwinKernel (process); |
| 181 | if (kernel_load_address != LLDB_INVALID_ADDRESS) |
| 182 | { |
| 183 | process->SetCanJIT(false); |
| 184 | return new DynamicLoaderDarwinKernel (process, kernel_load_address); |
| 185 | } |
| 186 | return NULL; |
| 187 | } |
| 188 | |
| 189 | lldb::addr_t |
| 190 | DynamicLoaderDarwinKernel::SearchForDarwinKernel (Process *process) |
| 191 | { |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 192 | addr_t kernel_load_address = process->GetImageInfoAddress(); |
| 193 | if (kernel_load_address == LLDB_INVALID_ADDRESS) |
| 194 | { |
| 195 | kernel_load_address = SearchForKernelAtSameLoadAddr (process); |
| 196 | if (kernel_load_address == LLDB_INVALID_ADDRESS) |
| 197 | { |
| 198 | kernel_load_address = SearchForKernelWithDebugHints (process); |
| 199 | if (kernel_load_address == LLDB_INVALID_ADDRESS) |
Greg Clayton | b170aee | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 200 | { |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 201 | kernel_load_address = SearchForKernelNearPC (process); |
| 202 | if (kernel_load_address == LLDB_INVALID_ADDRESS) |
| 203 | { |
| 204 | kernel_load_address = SearchForKernelViaExhaustiveSearch (process); |
| 205 | } |
Greg Clayton | b170aee | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 206 | } |
Greg Clayton | 40f7917 | 2011-07-08 04:11:42 +0000 | [diff] [blame] | 207 | } |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 208 | } |
Jason Molenda | cd0dd8f | 2013-03-02 07:19:32 +0000 | [diff] [blame] | 209 | return kernel_load_address; |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | //---------------------------------------------------------------------- |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 213 | // Check if the kernel binary is loaded in memory without a slide. |
| 214 | // First verify that the ExecutableModule is a kernel before we proceed. |
| 215 | // Returns the address of the kernel if one was found, else LLDB_INVALID_ADDRESS. |
| 216 | //---------------------------------------------------------------------- |
| 217 | lldb::addr_t |
| 218 | DynamicLoaderDarwinKernel::SearchForKernelAtSameLoadAddr (Process *process) |
| 219 | { |
| 220 | Module *exe_module = process->GetTarget().GetExecutableModulePointer(); |
| 221 | if (exe_module == NULL) |
| 222 | return LLDB_INVALID_ADDRESS; |
| 223 | |
| 224 | ObjectFile *exe_objfile = exe_module->GetObjectFile(); |
| 225 | if (exe_objfile == NULL) |
| 226 | return LLDB_INVALID_ADDRESS; |
| 227 | |
| 228 | if (exe_objfile->GetType() != ObjectFile::eTypeExecutable || exe_objfile->GetStrata() != ObjectFile::eStrataKernel) |
| 229 | return LLDB_INVALID_ADDRESS; |
| 230 | |
| 231 | if (!exe_objfile->GetHeaderAddress().IsValid()) |
| 232 | return LLDB_INVALID_ADDRESS; |
| 233 | |
| 234 | if (CheckForKernelImageAtAddress (exe_objfile->GetHeaderAddress().GetFileAddress(), process) == exe_module->GetUUID()) |
| 235 | return exe_objfile->GetHeaderAddress().GetFileAddress(); |
| 236 | |
| 237 | return LLDB_INVALID_ADDRESS; |
| 238 | } |
| 239 | |
| 240 | //---------------------------------------------------------------------- |
| 241 | // If the debug flag is included in the boot-args nvram setting, the kernel's load address |
| 242 | // will be noted in the lowglo page at a fixed address |
| 243 | // Returns the address of the kernel if one was found, else LLDB_INVALID_ADDRESS. |
| 244 | //---------------------------------------------------------------------- |
| 245 | lldb::addr_t |
| 246 | DynamicLoaderDarwinKernel::SearchForKernelWithDebugHints (Process *process) |
| 247 | { |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 248 | if (GetGlobalProperties()->GetScanType() == eKASLRScanNone) |
| 249 | return LLDB_INVALID_ADDRESS; |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 250 | |
| 251 | Error read_err; |
| 252 | addr_t addr = LLDB_INVALID_ADDRESS; |
| 253 | if (process->GetTarget().GetArchitecture().GetAddressByteSize() == 8) |
| 254 | { |
| 255 | addr = process->ReadUnsignedIntegerFromMemory (0xffffff8000002010ULL, 8, LLDB_INVALID_ADDRESS, read_err); |
| 256 | } |
| 257 | else |
| 258 | { |
| 259 | addr = process->ReadUnsignedIntegerFromMemory (0xffff0110, 4, LLDB_INVALID_ADDRESS, read_err); |
| 260 | } |
| 261 | |
| 262 | if (addr == 0) |
| 263 | addr = LLDB_INVALID_ADDRESS; |
| 264 | |
| 265 | if (addr != LLDB_INVALID_ADDRESS) |
| 266 | { |
| 267 | if (CheckForKernelImageAtAddress (addr, process).IsValid()) |
| 268 | return addr; |
| 269 | } |
| 270 | |
| 271 | return LLDB_INVALID_ADDRESS; |
| 272 | } |
| 273 | |
| 274 | //---------------------------------------------------------------------- |
| 275 | // If the kernel is currently executing when lldb attaches, and we don't have |
| 276 | // a better way of finding the kernel's load address, try searching backwards |
| 277 | // from the current pc value looking for the kernel's Mach header in memory. |
| 278 | // Returns the address of the kernel if one was found, else LLDB_INVALID_ADDRESS. |
| 279 | //---------------------------------------------------------------------- |
| 280 | lldb::addr_t |
| 281 | DynamicLoaderDarwinKernel::SearchForKernelNearPC (Process *process) |
| 282 | { |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 283 | if (GetGlobalProperties()->GetScanType() == eKASLRScanNone |
| 284 | || GetGlobalProperties()->GetScanType() == eKASLRScanLowgloAddresses) |
| 285 | { |
| 286 | return LLDB_INVALID_ADDRESS; |
| 287 | } |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 288 | |
| 289 | ThreadSP thread = process->GetThreadList().GetSelectedThread (); |
| 290 | if (thread.get() == NULL) |
| 291 | return LLDB_INVALID_ADDRESS; |
| 292 | addr_t pc = thread->GetRegisterContext ()->GetPC(LLDB_INVALID_ADDRESS); |
| 293 | |
| 294 | if (pc == LLDB_INVALID_ADDRESS) |
| 295 | return LLDB_INVALID_ADDRESS; |
| 296 | |
Jason Molenda | 1377cdc | 2013-04-19 00:50:28 +0000 | [diff] [blame] | 297 | addr_t kernel_range_low; |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 298 | if (process->GetTarget().GetArchitecture().GetAddressByteSize() == 8) |
| 299 | { |
| 300 | kernel_range_low = 1ULL << 63; |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 301 | } |
| 302 | else |
| 303 | { |
| 304 | kernel_range_low = 1ULL << 31; |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | // Outside the normal kernel address range, this is probably userland code running right now |
| 308 | if (pc < kernel_range_low) |
Jason Molenda | 1377cdc | 2013-04-19 00:50:28 +0000 | [diff] [blame] | 309 | return LLDB_INVALID_ADDRESS; |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 310 | |
| 311 | // The kernel will load at at one megabyte boundary (0x100000), or at that boundary plus |
| 312 | // an offset of one page (0x1000) or two, depending on the device. |
| 313 | |
| 314 | // Round the current pc down to the nearest one megabyte boundary - the place where we will start searching. |
| 315 | addr_t addr = pc & ~0xfffff; |
| 316 | |
| 317 | int i = 0; |
| 318 | while (i < 32 && pc >= kernel_range_low) |
| 319 | { |
| 320 | if (CheckForKernelImageAtAddress (addr, process).IsValid()) |
| 321 | return addr; |
| 322 | if (CheckForKernelImageAtAddress (addr + 0x1000, process).IsValid()) |
| 323 | return addr + 0x1000; |
| 324 | if (CheckForKernelImageAtAddress (addr + 0x2000, process).IsValid()) |
| 325 | return addr + 0x2000; |
| 326 | i++; |
| 327 | addr -= 0x100000; |
| 328 | } |
| 329 | |
| 330 | return LLDB_INVALID_ADDRESS; |
| 331 | } |
| 332 | |
| 333 | //---------------------------------------------------------------------- |
| 334 | // Scan through the valid address range for a kernel binary. |
| 335 | // This is uselessly slow in 64-bit environments so we don't even try it. |
| 336 | // This scan is not enabled by default even for 32-bit targets. |
| 337 | // Returns the address of the kernel if one was found, else LLDB_INVALID_ADDRESS. |
| 338 | //---------------------------------------------------------------------- |
| 339 | lldb::addr_t |
| 340 | DynamicLoaderDarwinKernel::SearchForKernelViaExhaustiveSearch (Process *process) |
| 341 | { |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 342 | if (GetGlobalProperties()->GetScanType() != eKASLRScanExhaustiveScan) |
| 343 | { |
| 344 | return LLDB_INVALID_ADDRESS; |
| 345 | } |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 346 | |
| 347 | addr_t kernel_range_low, kernel_range_high; |
| 348 | if (process->GetTarget().GetArchitecture().GetAddressByteSize() == 8) |
| 349 | { |
| 350 | kernel_range_low = 1ULL << 63; |
| 351 | kernel_range_high = UINT64_MAX; |
| 352 | } |
| 353 | else |
| 354 | { |
| 355 | kernel_range_low = 1ULL << 31; |
| 356 | kernel_range_high = UINT32_MAX; |
| 357 | } |
| 358 | |
| 359 | // Stepping through memory at one-megabyte resolution looking for a kernel |
| 360 | // rarely works (fast enough) with a 64-bit address space -- for now, let's |
| 361 | // not even bother. We may be attaching to something which *isn't* a kernel |
| 362 | // and we don't want to spin for minutes on-end looking for a kernel. |
| 363 | if (process->GetTarget().GetArchitecture().GetAddressByteSize() == 8) |
| 364 | return LLDB_INVALID_ADDRESS; |
| 365 | |
| 366 | addr_t addr = kernel_range_low; |
| 367 | |
| 368 | while (addr >= kernel_range_low && addr < kernel_range_high) |
| 369 | { |
| 370 | if (CheckForKernelImageAtAddress (addr, process).IsValid()) |
| 371 | return addr; |
| 372 | if (CheckForKernelImageAtAddress (addr + 0x1000, process).IsValid()) |
| 373 | return addr + 0x1000; |
| 374 | if (CheckForKernelImageAtAddress (addr + 0x2000, process).IsValid()) |
| 375 | return addr + 0x2000; |
| 376 | addr += 0x100000; |
| 377 | } |
| 378 | return LLDB_INVALID_ADDRESS; |
| 379 | } |
| 380 | |
| 381 | //---------------------------------------------------------------------- |
| 382 | // Given an address in memory, look to see if there is a kernel image at that |
| 383 | // address. |
| 384 | // Returns a UUID; if a kernel was not found at that address, UUID.IsValid() will be false. |
| 385 | //---------------------------------------------------------------------- |
| 386 | lldb_private::UUID |
| 387 | DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress (lldb::addr_t addr, Process *process) |
| 388 | { |
| 389 | if (addr == LLDB_INVALID_ADDRESS) |
| 390 | return UUID(); |
| 391 | |
| 392 | // First try a quick test -- read the first 4 bytes and see if there is a valid Mach-O magic field there |
| 393 | // (the first field of the mach_header/mach_header_64 struct). |
| 394 | |
| 395 | Error read_error; |
| 396 | uint64_t result = process->ReadUnsignedIntegerFromMemory (addr, 4, LLDB_INVALID_ADDRESS, read_error); |
| 397 | if (result != llvm::MachO::HeaderMagic64 |
| 398 | && result != llvm::MachO::HeaderMagic32 |
| 399 | && result != llvm::MachO::HeaderMagic32Swapped |
| 400 | && result != llvm::MachO::HeaderMagic64Swapped) |
| 401 | { |
| 402 | return UUID(); |
| 403 | } |
| 404 | |
| 405 | // Read the mach header and see whether it looks like a kernel |
| 406 | llvm::MachO::mach_header header; |
| 407 | if (process->DoReadMemory (addr, &header, sizeof(header), read_error) != sizeof(header)) |
| 408 | return UUID(); |
| 409 | |
| 410 | if (header.magic == llvm::MachO::HeaderMagic32Swapped || |
| 411 | header.magic == llvm::MachO::HeaderMagic64Swapped) |
| 412 | { |
| 413 | header.magic = llvm::ByteSwap_32(header.magic); |
| 414 | header.cputype = llvm::ByteSwap_32(header.cputype); |
| 415 | header.cpusubtype = llvm::ByteSwap_32(header.cpusubtype); |
| 416 | header.filetype = llvm::ByteSwap_32(header.filetype); |
| 417 | header.ncmds = llvm::ByteSwap_32(header.ncmds); |
| 418 | header.sizeofcmds = llvm::ByteSwap_32(header.sizeofcmds); |
| 419 | header.flags = llvm::ByteSwap_32(header.flags); |
| 420 | } |
| 421 | |
| 422 | // A kernel is an executable which does not have the dynamic link object flag set. |
| 423 | if (header.filetype == llvm::MachO::HeaderFileTypeExecutable |
| 424 | && (header.flags & llvm::MachO::HeaderFlagBitIsDynamicLinkObject) == 0) |
| 425 | { |
| 426 | // Create a full module to get the UUID |
Greg Clayton | 2ddb2b8 | 2013-02-01 21:38:35 +0000 | [diff] [blame] | 427 | ModuleSP memory_module_sp = process->ReadModuleFromMemory (FileSpec ("temp_mach_kernel", false), addr); |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 428 | if (!memory_module_sp.get()) |
| 429 | return UUID(); |
| 430 | |
| 431 | ObjectFile *exe_objfile = memory_module_sp->GetObjectFile(); |
| 432 | if (exe_objfile == NULL) |
| 433 | return UUID(); |
| 434 | |
| 435 | if (exe_objfile->GetType() == ObjectFile::eTypeExecutable && exe_objfile->GetStrata() == ObjectFile::eStrataKernel) |
| 436 | { |
| 437 | return memory_module_sp->GetUUID(); |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | return UUID(); |
| 442 | } |
| 443 | |
| 444 | //---------------------------------------------------------------------- |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 445 | // Constructor |
| 446 | //---------------------------------------------------------------------- |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 447 | DynamicLoaderDarwinKernel::DynamicLoaderDarwinKernel (Process* process, lldb::addr_t kernel_addr) : |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 448 | DynamicLoader(process), |
Jason Molenda | 9338dd5 | 2013-01-30 04:39:32 +0000 | [diff] [blame] | 449 | m_kernel_load_address (kernel_addr), |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 450 | m_kernel(), |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 451 | m_kext_summary_header_ptr_addr (), |
Greg Clayton | 8c547d4 | 2011-07-08 03:21:57 +0000 | [diff] [blame] | 452 | m_kext_summary_header_addr (), |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 453 | m_kext_summary_header (), |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 454 | m_known_kexts (), |
Daniel Dunbar | 97c8957 | 2011-10-31 22:50:49 +0000 | [diff] [blame] | 455 | m_mutex(Mutex::eMutexTypeRecursive), |
| 456 | m_break_id (LLDB_INVALID_BREAK_ID) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 457 | { |
Jason Molenda | e369aed | 2013-04-05 01:03:25 +0000 | [diff] [blame] | 458 | PlatformSP platform_sp(Platform::FindPlugin (process, "darwin-kernel")); |
| 459 | // Only select the darwin-kernel Platform if we've been asked to load kexts. |
| 460 | // It can take some time to scan over all of the kext info.plists and that |
| 461 | // shouldn't be done if kext loading is explicitly disabled. |
| 462 | if (platform_sp.get() && GetGlobalProperties()->GetLoadKexts()) |
| 463 | { |
| 464 | process->GetTarget().SetPlatform (platform_sp); |
Jason Molenda | e369aed | 2013-04-05 01:03:25 +0000 | [diff] [blame] | 465 | } |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | //---------------------------------------------------------------------- |
| 469 | // Destructor |
| 470 | //---------------------------------------------------------------------- |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 471 | DynamicLoaderDarwinKernel::~DynamicLoaderDarwinKernel() |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 472 | { |
| 473 | Clear(true); |
| 474 | } |
| 475 | |
Greg Clayton | 645faca | 2011-07-09 17:15:55 +0000 | [diff] [blame] | 476 | void |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 477 | DynamicLoaderDarwinKernel::UpdateIfNeeded() |
Greg Clayton | 645faca | 2011-07-09 17:15:55 +0000 | [diff] [blame] | 478 | { |
| 479 | LoadKernelModuleIfNeeded(); |
| 480 | SetNotificationBreakpointIfNeeded (); |
| 481 | } |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 482 | //------------------------------------------------------------------ |
| 483 | /// Called after attaching a process. |
| 484 | /// |
| 485 | /// Allow DynamicLoader plug-ins to execute some code after |
| 486 | /// attaching to a process. |
| 487 | //------------------------------------------------------------------ |
| 488 | void |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 489 | DynamicLoaderDarwinKernel::DidAttach () |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 490 | { |
| 491 | PrivateInitialize(m_process); |
Greg Clayton | 645faca | 2011-07-09 17:15:55 +0000 | [diff] [blame] | 492 | UpdateIfNeeded(); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | //------------------------------------------------------------------ |
| 496 | /// Called after attaching a process. |
| 497 | /// |
| 498 | /// Allow DynamicLoader plug-ins to execute some code after |
| 499 | /// attaching to a process. |
| 500 | //------------------------------------------------------------------ |
| 501 | void |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 502 | DynamicLoaderDarwinKernel::DidLaunch () |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 503 | { |
| 504 | PrivateInitialize(m_process); |
Greg Clayton | 645faca | 2011-07-09 17:15:55 +0000 | [diff] [blame] | 505 | UpdateIfNeeded(); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | |
| 509 | //---------------------------------------------------------------------- |
| 510 | // Clear out the state of this class. |
| 511 | //---------------------------------------------------------------------- |
| 512 | void |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 513 | DynamicLoaderDarwinKernel::Clear (bool clear_process) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 514 | { |
| 515 | Mutex::Locker locker(m_mutex); |
| 516 | |
| 517 | if (m_process->IsAlive() && LLDB_BREAK_ID_IS_VALID(m_break_id)) |
| 518 | m_process->ClearBreakpointSiteByID(m_break_id); |
| 519 | |
| 520 | if (clear_process) |
| 521 | m_process = NULL; |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 522 | m_kernel.Clear(); |
| 523 | m_known_kexts.clear(); |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 524 | m_kext_summary_header_ptr_addr.Clear(); |
Greg Clayton | 8c547d4 | 2011-07-08 03:21:57 +0000 | [diff] [blame] | 525 | m_kext_summary_header_addr.Clear(); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 526 | m_break_id = LLDB_INVALID_BREAK_ID; |
| 527 | } |
| 528 | |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 529 | |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 530 | bool |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 531 | DynamicLoaderDarwinKernel::KextImageInfo::LoadImageAtFileAddress (Process *process) |
Greg Clayton | aa20630 | 2012-03-21 04:25:00 +0000 | [diff] [blame] | 532 | { |
| 533 | if (IsLoaded()) |
| 534 | return true; |
| 535 | |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 536 | if (m_module_sp) |
Greg Clayton | aa20630 | 2012-03-21 04:25:00 +0000 | [diff] [blame] | 537 | { |
| 538 | bool changed = false; |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 539 | if (m_module_sp->SetLoadAddress (process->GetTarget(), 0, changed)) |
| 540 | m_load_process_stop_id = process->GetStopID(); |
Greg Clayton | aa20630 | 2012-03-21 04:25:00 +0000 | [diff] [blame] | 541 | } |
| 542 | return false; |
| 543 | } |
| 544 | |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 545 | void |
| 546 | DynamicLoaderDarwinKernel::KextImageInfo::SetModule (ModuleSP module_sp) |
| 547 | { |
| 548 | m_module_sp = module_sp; |
| 549 | if (module_sp.get() && module_sp->GetObjectFile()) |
| 550 | { |
| 551 | if (module_sp->GetObjectFile()->GetType() == ObjectFile::eTypeExecutable |
| 552 | && module_sp->GetObjectFile()->GetStrata() == ObjectFile::eStrataKernel) |
| 553 | { |
| 554 | m_kernel_image = true; |
| 555 | } |
| 556 | else |
| 557 | { |
| 558 | m_kernel_image = false; |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | ModuleSP |
| 564 | DynamicLoaderDarwinKernel::KextImageInfo::GetModule () |
| 565 | { |
| 566 | return m_module_sp; |
| 567 | } |
| 568 | |
| 569 | void |
| 570 | DynamicLoaderDarwinKernel::KextImageInfo::SetLoadAddress (addr_t load_addr) |
| 571 | { |
| 572 | m_load_address = load_addr; |
| 573 | } |
| 574 | |
| 575 | addr_t |
| 576 | DynamicLoaderDarwinKernel::KextImageInfo::GetLoadAddress () const |
| 577 | { |
| 578 | return m_load_address; |
| 579 | } |
| 580 | |
| 581 | uint64_t |
| 582 | DynamicLoaderDarwinKernel::KextImageInfo::GetSize () const |
| 583 | { |
| 584 | return m_size; |
| 585 | } |
| 586 | |
| 587 | void |
| 588 | DynamicLoaderDarwinKernel::KextImageInfo::SetSize (uint64_t size) |
| 589 | { |
| 590 | m_size = size; |
| 591 | } |
| 592 | |
| 593 | uint32_t |
| 594 | DynamicLoaderDarwinKernel::KextImageInfo::GetProcessStopId () const |
| 595 | { |
| 596 | return m_load_process_stop_id; |
| 597 | } |
| 598 | |
| 599 | void |
| 600 | DynamicLoaderDarwinKernel::KextImageInfo::SetProcessStopId (uint32_t stop_id) |
| 601 | { |
| 602 | m_load_process_stop_id = stop_id; |
| 603 | } |
| 604 | |
Greg Clayton | aa20630 | 2012-03-21 04:25:00 +0000 | [diff] [blame] | 605 | bool |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 606 | DynamicLoaderDarwinKernel::KextImageInfo::operator== (const KextImageInfo &rhs) |
| 607 | { |
| 608 | if (m_uuid.IsValid() || rhs.GetUUID().IsValid()) |
| 609 | { |
| 610 | if (m_uuid == rhs.GetUUID()) |
| 611 | { |
| 612 | return true; |
| 613 | } |
| 614 | return false; |
| 615 | } |
| 616 | |
| 617 | if (m_name == rhs.GetName() && m_load_address == rhs.GetLoadAddress()) |
| 618 | return true; |
| 619 | |
| 620 | return false; |
| 621 | } |
| 622 | |
| 623 | void |
| 624 | DynamicLoaderDarwinKernel::KextImageInfo::SetName (const char *name) |
| 625 | { |
| 626 | m_name = name; |
| 627 | } |
| 628 | |
| 629 | std::string |
| 630 | DynamicLoaderDarwinKernel::KextImageInfo::GetName () const |
| 631 | { |
| 632 | return m_name; |
| 633 | } |
| 634 | |
| 635 | void |
| 636 | DynamicLoaderDarwinKernel::KextImageInfo::SetUUID (const UUID &uuid) |
| 637 | { |
| 638 | m_uuid = uuid; |
| 639 | } |
| 640 | |
| 641 | UUID |
| 642 | DynamicLoaderDarwinKernel::KextImageInfo::GetUUID () const |
| 643 | { |
| 644 | return m_uuid; |
| 645 | } |
| 646 | |
| 647 | // Given the m_load_address from the kext summaries, and a UUID, try to create an in-memory |
| 648 | // Module at that address. Require that the MemoryModule have a matching UUID and detect |
| 649 | // if this MemoryModule is a kernel or a kext. |
| 650 | // |
| 651 | // Returns true if m_memory_module_sp is now set to a valid Module. |
| 652 | |
| 653 | bool |
| 654 | DynamicLoaderDarwinKernel::KextImageInfo::ReadMemoryModule (Process *process) |
| 655 | { |
| 656 | if (m_memory_module_sp.get() != NULL) |
| 657 | return true; |
| 658 | if (m_load_address == LLDB_INVALID_ADDRESS) |
| 659 | return false; |
| 660 | |
| 661 | FileSpec file_spec; |
| 662 | file_spec.SetFile (m_name.c_str(), false); |
| 663 | |
| 664 | ModuleSP memory_module_sp = process->ReadModuleFromMemory (file_spec, m_load_address); |
| 665 | |
| 666 | if (memory_module_sp.get() == NULL) |
| 667 | return false; |
| 668 | |
| 669 | bool is_kernel = false; |
| 670 | if (memory_module_sp->GetObjectFile()) |
| 671 | { |
| 672 | if (memory_module_sp->GetObjectFile()->GetType() == ObjectFile::eTypeExecutable |
| 673 | && memory_module_sp->GetObjectFile()->GetStrata() == ObjectFile::eStrataKernel) |
| 674 | { |
| 675 | is_kernel = true; |
| 676 | } |
| 677 | else if (memory_module_sp->GetObjectFile()->GetType() == ObjectFile::eTypeSharedLibrary) |
| 678 | { |
| 679 | is_kernel = false; |
| 680 | } |
| 681 | } |
| 682 | |
Jason Molenda | 6699c6e | 2013-02-27 03:07:49 +0000 | [diff] [blame] | 683 | // If this is a kext, and the kernel specified what UUID we should find at this |
| 684 | // load address, require that the memory module have a matching UUID or something |
| 685 | // has gone wrong and we should discard it. |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 686 | if (m_uuid.IsValid()) |
| 687 | { |
| 688 | if (m_uuid != memory_module_sp->GetUUID()) |
| 689 | { |
| 690 | return false; |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | // If the in-memory Module has a UUID, let's use that. |
| 695 | if (!m_uuid.IsValid() && memory_module_sp->GetUUID().IsValid()) |
| 696 | { |
| 697 | m_uuid = memory_module_sp->GetUUID(); |
| 698 | } |
| 699 | |
| 700 | m_memory_module_sp = memory_module_sp; |
| 701 | m_kernel_image = is_kernel; |
| 702 | if (is_kernel) |
| 703 | { |
Jason Molenda | 6699c6e | 2013-02-27 03:07:49 +0000 | [diff] [blame] | 704 | if (memory_module_sp->GetArchitecture().IsValid()) |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 705 | { |
| 706 | process->GetTarget().SetArchitecture(memory_module_sp->GetArchitecture()); |
| 707 | } |
Jason Molenda | 6699c6e | 2013-02-27 03:07:49 +0000 | [diff] [blame] | 708 | if (m_uuid.IsValid()) |
| 709 | { |
| 710 | Module* exe_module = process->GetTarget().GetExecutableModulePointer(); |
| 711 | if (exe_module && exe_module->GetUUID().IsValid()) |
| 712 | { |
| 713 | if (m_uuid != exe_module->GetUUID()) |
| 714 | { |
| 715 | Stream *s = &process->GetTarget().GetDebugger().GetOutputStream(); |
| 716 | if (s) |
| 717 | { |
| 718 | char memory_module_uuidbuf[64]; |
| 719 | char exe_module_uuidbuf[64]; |
| 720 | s->Printf ("warning: Host-side kernel file has Mach-O UUID of %s but remote kernel has a UUID of %s -- a mismatched kernel file will result in a poor debugger experience.\n", |
| 721 | exe_module->GetUUID().GetAsCString(exe_module_uuidbuf, sizeof (exe_module_uuidbuf)), |
| 722 | m_uuid.GetAsCString(memory_module_uuidbuf, sizeof (memory_module_uuidbuf))); |
| 723 | s->Flush (); |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | } |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | return true; |
| 731 | } |
| 732 | |
| 733 | bool |
| 734 | DynamicLoaderDarwinKernel::KextImageInfo::IsKernel () const |
| 735 | { |
| 736 | return m_kernel_image == true; |
| 737 | } |
| 738 | |
| 739 | void |
| 740 | DynamicLoaderDarwinKernel::KextImageInfo::SetIsKernel (bool is_kernel) |
| 741 | { |
| 742 | m_kernel_image = is_kernel; |
| 743 | } |
| 744 | |
| 745 | bool |
| 746 | DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule (Process *process) |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 747 | { |
| 748 | if (IsLoaded()) |
| 749 | return true; |
| 750 | |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 751 | |
| 752 | Target &target = process->GetTarget(); |
Jason Molenda | 127291c | 2012-10-19 03:40:45 +0000 | [diff] [blame] | 753 | |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 754 | // If we don't have / can't create a memory module for this kext, don't try to load it - we won't |
| 755 | // have the correct segment load addresses. |
| 756 | if (!ReadMemoryModule (process)) |
Jason Molenda | 127291c | 2012-10-19 03:40:45 +0000 | [diff] [blame] | 757 | { |
| 758 | return false; |
| 759 | } |
| 760 | |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 761 | bool uuid_is_valid = m_uuid.IsValid(); |
| 762 | |
Jason Molenda | 0d31111 | 2013-02-19 06:11:13 +0000 | [diff] [blame] | 763 | if (IsKernel() && uuid_is_valid && m_memory_module_sp.get()) |
| 764 | { |
| 765 | Stream *s = &target.GetDebugger().GetOutputStream(); |
| 766 | if (s) |
| 767 | { |
| 768 | char uuidbuf[64]; |
| 769 | s->Printf ("Kernel UUID: %s\n", m_memory_module_sp->GetUUID().GetAsCString(uuidbuf, sizeof (uuidbuf))); |
| 770 | s->Printf ("Load Address: 0x%" PRIx64 "\n", m_load_address); |
| 771 | } |
| 772 | } |
| 773 | |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 774 | if (!m_module_sp) |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 775 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 776 | // See if the kext has already been loaded into the target, probably by the user doing target modules add. |
| 777 | const ModuleList &target_images = target.GetImages(); |
| 778 | m_module_sp = target_images.FindModule(m_uuid); |
| 779 | |
| 780 | // Search for the kext on the local filesystem via the UUID |
| 781 | if (!m_module_sp && uuid_is_valid) |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 782 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 783 | ModuleSpec module_spec; |
| 784 | module_spec.GetUUID() = m_uuid; |
| 785 | module_spec.GetArchitecture() = target.GetArchitecture(); |
Jason Molenda | d6b8122 | 2012-10-06 02:02:26 +0000 | [diff] [blame] | 786 | |
Jason Molenda | 2c529b1 | 2013-02-19 07:16:22 +0000 | [diff] [blame] | 787 | // For the kernel, we really do need an on-disk file copy of the binary to do anything useful. |
| 788 | // This will force a clal to |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 789 | if (IsKernel()) |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 790 | { |
Jason Molenda | 2c529b1 | 2013-02-19 07:16:22 +0000 | [diff] [blame] | 791 | if (Symbols::DownloadObjectAndSymbolFile (module_spec, true)) |
Jason Molenda | d6d45ce | 2012-10-09 01:17:11 +0000 | [diff] [blame] | 792 | { |
Jason Molenda | 2c529b1 | 2013-02-19 07:16:22 +0000 | [diff] [blame] | 793 | if (module_spec.GetFileSpec().Exists()) |
Jason Molenda | d6d45ce | 2012-10-09 01:17:11 +0000 | [diff] [blame] | 794 | { |
Jason Molenda | 2c529b1 | 2013-02-19 07:16:22 +0000 | [diff] [blame] | 795 | m_module_sp.reset(new Module (module_spec.GetFileSpec(), target.GetArchitecture())); |
| 796 | if (m_module_sp.get() && m_module_sp->MatchesModuleSpec (module_spec)) |
| 797 | { |
| 798 | ModuleList loaded_module_list; |
| 799 | loaded_module_list.Append (m_module_sp); |
| 800 | target.ModulesDidLoad (loaded_module_list); |
| 801 | } |
Jason Molenda | d6d45ce | 2012-10-09 01:17:11 +0000 | [diff] [blame] | 802 | } |
| 803 | } |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 804 | } |
Jason Molenda | 2c529b1 | 2013-02-19 07:16:22 +0000 | [diff] [blame] | 805 | |
Jason Molenda | e369aed | 2013-04-05 01:03:25 +0000 | [diff] [blame] | 806 | // If the current platform is PlatformDarwinKernel, create a ModuleSpec with the filename set |
| 807 | // to be the bundle ID for this kext, e.g. "com.apple.filesystems.msdosfs", and ask the platform |
| 808 | // to find it. |
| 809 | PlatformSP platform_sp (target.GetPlatform()); |
| 810 | if (platform_sp) |
| 811 | { |
| 812 | const char *pname = platform_sp->GetShortPluginName(); |
| 813 | if (pname && strcmp (pname, "darwin-kernel") == 0) |
| 814 | { |
| 815 | ModuleSpec kext_bundle_module_spec(module_spec); |
| 816 | FileSpec kext_filespec(m_name.c_str(), false); |
| 817 | kext_bundle_module_spec.GetFileSpec() = kext_filespec; |
| 818 | platform_sp->GetSharedModule (kext_bundle_module_spec, m_module_sp, &target.GetExecutableSearchPaths(), NULL, NULL); |
| 819 | } |
| 820 | } |
| 821 | |
Jason Molenda | 2c529b1 | 2013-02-19 07:16:22 +0000 | [diff] [blame] | 822 | // Ask the Target to find this file on the local system, if possible. |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 823 | // This will search in the list of currently-loaded files, look in the |
| 824 | // standard search paths on the system, and on a Mac it will try calling |
| 825 | // the DebugSymbols framework with the UUID to find the binary via its |
| 826 | // search methods. |
| 827 | if (!m_module_sp) |
| 828 | { |
| 829 | m_module_sp = target.GetSharedModule (module_spec); |
| 830 | } |
Jason Molenda | 0d31111 | 2013-02-19 06:11:13 +0000 | [diff] [blame] | 831 | |
Jason Molenda | 2c529b1 | 2013-02-19 07:16:22 +0000 | [diff] [blame] | 832 | if (IsKernel() && !m_module_sp) |
Jason Molenda | 0d31111 | 2013-02-19 06:11:13 +0000 | [diff] [blame] | 833 | { |
| 834 | Stream *s = &target.GetDebugger().GetOutputStream(); |
| 835 | if (s) |
| 836 | { |
Jason Molenda | fcd9bf1 | 2013-02-19 06:39:56 +0000 | [diff] [blame] | 837 | s->Printf ("WARNING: Unable to locate kernel binary on this system.\n"); |
Jason Molenda | 0d31111 | 2013-02-19 06:11:13 +0000 | [diff] [blame] | 838 | } |
| 839 | } |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 840 | } |
Jason Molenda | 5fdfc6d | 2012-12-01 06:13:29 +0000 | [diff] [blame] | 841 | |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 842 | // If we managed to find a module, append it to the target's list of images. |
| 843 | // If we also have a memory module, require that they have matching UUIDs |
| 844 | if (m_module_sp) |
| 845 | { |
| 846 | bool uuid_match_ok = true; |
| 847 | if (m_memory_module_sp) |
| 848 | { |
| 849 | if (m_module_sp->GetUUID() != m_memory_module_sp->GetUUID()) |
Jason Molenda | 5fdfc6d | 2012-12-01 06:13:29 +0000 | [diff] [blame] | 850 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 851 | uuid_match_ok = false; |
| 852 | } |
| 853 | } |
| 854 | if (uuid_match_ok) |
| 855 | { |
Jason Molenda | d79d625 | 2013-02-19 07:41:13 +0000 | [diff] [blame] | 856 | target.GetImages().AppendIfNeeded(m_module_sp); |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 857 | if (IsKernel() && target.GetExecutableModulePointer() != m_module_sp.get()) |
| 858 | { |
| 859 | target.SetExecutableModule (m_module_sp, false); |
Jason Molenda | 5fdfc6d | 2012-12-01 06:13:29 +0000 | [diff] [blame] | 860 | } |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 861 | } |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 862 | } |
| 863 | } |
| 864 | |
Jason Molenda | fcd9bf1 | 2013-02-19 06:39:56 +0000 | [diff] [blame] | 865 | if (!m_module_sp && !IsKernel() && m_uuid.IsValid() && !m_name.empty()) |
| 866 | { |
| 867 | Stream *s = &target.GetDebugger().GetOutputStream(); |
| 868 | if (s) |
| 869 | { |
| 870 | char uuidbuf[64]; |
| 871 | s->Printf ("warning: Can't find binary/dSYM for %s (%s)\n", |
| 872 | m_name.c_str(), m_uuid.GetAsCString(uuidbuf, sizeof (uuidbuf))); |
| 873 | } |
| 874 | } |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 875 | |
Greg Clayton | a4d860f | 2012-12-11 01:20:51 +0000 | [diff] [blame] | 876 | static ConstString g_section_name_LINKEDIT ("__LINKEDIT"); |
| 877 | |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 878 | if (m_memory_module_sp && m_module_sp) |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 879 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 880 | if (m_module_sp->GetUUID() == m_memory_module_sp->GetUUID()) |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 881 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 882 | ObjectFile *ondisk_object_file = m_module_sp->GetObjectFile(); |
| 883 | ObjectFile *memory_object_file = m_memory_module_sp->GetObjectFile(); |
Greg Clayton | a4d860f | 2012-12-11 01:20:51 +0000 | [diff] [blame] | 884 | |
Jason Molenda | d6d45ce | 2012-10-09 01:17:11 +0000 | [diff] [blame] | 885 | if (memory_object_file && ondisk_object_file) |
| 886 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 887 | // The memory_module for kexts may have an invalid __LINKEDIT seg; skip it. |
| 888 | const bool ignore_linkedit = !IsKernel (); |
Greg Clayton | a4d860f | 2012-12-11 01:20:51 +0000 | [diff] [blame] | 889 | |
Jason Molenda | d6d45ce | 2012-10-09 01:17:11 +0000 | [diff] [blame] | 890 | SectionList *ondisk_section_list = ondisk_object_file->GetSectionList (); |
| 891 | SectionList *memory_section_list = memory_object_file->GetSectionList (); |
| 892 | if (memory_section_list && ondisk_section_list) |
| 893 | { |
| 894 | const uint32_t num_ondisk_sections = ondisk_section_list->GetSize(); |
| 895 | // There may be CTF sections in the memory image so we can't |
| 896 | // always just compare the number of sections (which are actually |
| 897 | // segments in mach-o parlance) |
| 898 | uint32_t sect_idx = 0; |
| 899 | |
| 900 | // Use the memory_module's addresses for each section to set the |
| 901 | // file module's load address as appropriate. We don't want to use |
| 902 | // a single slide value for the entire kext - different segments may |
| 903 | // be slid different amounts by the kext loader. |
| 904 | |
| 905 | uint32_t num_sections_loaded = 0; |
| 906 | for (sect_idx=0; sect_idx<num_ondisk_sections; ++sect_idx) |
| 907 | { |
| 908 | SectionSP ondisk_section_sp(ondisk_section_list->GetSectionAtIndex(sect_idx)); |
| 909 | if (ondisk_section_sp) |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 910 | { |
Greg Clayton | a4d860f | 2012-12-11 01:20:51 +0000 | [diff] [blame] | 911 | // Don't ever load __LINKEDIT as it may or may not be actually |
| 912 | // mapped into memory and there is no current way to tell. |
| 913 | // I filed rdar://problem/12851706 to track being able to tell |
| 914 | // if the __LINKEDIT is actually mapped, but until then, we need |
| 915 | // to not load the __LINKEDIT |
| 916 | if (ignore_linkedit && ondisk_section_sp->GetName() == g_section_name_LINKEDIT) |
| 917 | continue; |
| 918 | |
Jason Molenda | d6d45ce | 2012-10-09 01:17:11 +0000 | [diff] [blame] | 919 | const Section *memory_section = memory_section_list->FindSectionByName(ondisk_section_sp->GetName()).get(); |
| 920 | if (memory_section) |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 921 | { |
Jason Molenda | d6d45ce | 2012-10-09 01:17:11 +0000 | [diff] [blame] | 922 | target.GetSectionLoadList().SetSectionLoadAddress (ondisk_section_sp, memory_section->GetFileAddress()); |
| 923 | ++num_sections_loaded; |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 924 | } |
| 925 | } |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 926 | } |
Jason Molenda | d6d45ce | 2012-10-09 01:17:11 +0000 | [diff] [blame] | 927 | if (num_sections_loaded > 0) |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 928 | m_load_process_stop_id = process->GetStopID(); |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 929 | else |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 930 | m_module_sp.reset(); // No sections were loaded |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 931 | } |
| 932 | else |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 933 | m_module_sp.reset(); // One or both section lists |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 934 | } |
| 935 | else |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 936 | m_module_sp.reset(); // One or both object files missing |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 937 | } |
Jason Molenda | d6d45ce | 2012-10-09 01:17:11 +0000 | [diff] [blame] | 938 | else |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 939 | m_module_sp.reset(); // UUID mismatch |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 940 | } |
Jason Molenda | d6d45ce | 2012-10-09 01:17:11 +0000 | [diff] [blame] | 941 | |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 942 | bool is_loaded = IsLoaded(); |
| 943 | |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 944 | if (is_loaded && m_module_sp && IsKernel()) |
Jason Molenda | 4952db8 | 2012-10-02 03:49:41 +0000 | [diff] [blame] | 945 | { |
| 946 | Stream *s = &target.GetDebugger().GetOutputStream(); |
| 947 | if (s) |
| 948 | { |
Jason Molenda | 88f7e75 | 2013-03-01 00:06:37 +0000 | [diff] [blame] | 949 | ObjectFile *kernel_object_file = m_module_sp->GetObjectFile(); |
| 950 | if (kernel_object_file) |
| 951 | { |
| 952 | addr_t file_address = kernel_object_file->GetHeaderAddress().GetFileAddress(); |
| 953 | if (m_load_address != LLDB_INVALID_ADDRESS && file_address != LLDB_INVALID_ADDRESS) |
| 954 | { |
Matt Kopec | e5bc8c1 | 2013-03-12 17:45:38 +0000 | [diff] [blame] | 955 | s->Printf ("Kernel slid 0x%" PRIx64 " in memory.\n", m_load_address - file_address); |
Jason Molenda | 88f7e75 | 2013-03-01 00:06:37 +0000 | [diff] [blame] | 956 | } |
| 957 | } |
Jason Molenda | 63e5cf6 | 2012-10-02 22:23:42 +0000 | [diff] [blame] | 958 | { |
Greg Clayton | 97a19b2 | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 959 | s->Printf ("Loaded kernel file %s\n", |
| 960 | m_module_sp->GetFileSpec().GetPath().c_str()); |
Jason Molenda | 63e5cf6 | 2012-10-02 22:23:42 +0000 | [diff] [blame] | 961 | } |
Jason Molenda | 4952db8 | 2012-10-02 03:49:41 +0000 | [diff] [blame] | 962 | s->Flush (); |
| 963 | } |
| 964 | } |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 965 | return is_loaded; |
| 966 | } |
| 967 | |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 968 | uint32_t |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 969 | DynamicLoaderDarwinKernel::KextImageInfo::GetAddressByteSize () |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 970 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 971 | if (m_memory_module_sp) |
| 972 | return m_memory_module_sp->GetArchitecture().GetAddressByteSize(); |
| 973 | if (m_module_sp) |
| 974 | return m_module_sp->GetArchitecture().GetAddressByteSize(); |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 975 | return 0; |
| 976 | } |
| 977 | |
| 978 | lldb::ByteOrder |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 979 | DynamicLoaderDarwinKernel::KextImageInfo::GetByteOrder() |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 980 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 981 | if (m_memory_module_sp) |
| 982 | return m_memory_module_sp->GetArchitecture().GetByteOrder(); |
| 983 | if (m_module_sp) |
| 984 | return m_module_sp->GetArchitecture().GetByteOrder(); |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 985 | return lldb::endian::InlHostByteOrder(); |
| 986 | } |
| 987 | |
| 988 | lldb_private::ArchSpec |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 989 | DynamicLoaderDarwinKernel::KextImageInfo::GetArchitecture () const |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 990 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 991 | if (m_memory_module_sp) |
| 992 | return m_memory_module_sp->GetArchitecture(); |
| 993 | if (m_module_sp) |
| 994 | return m_module_sp->GetArchitecture(); |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 995 | return lldb_private::ArchSpec (); |
| 996 | } |
| 997 | |
| 998 | |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 999 | //---------------------------------------------------------------------- |
| 1000 | // Load the kernel module and initialize the "m_kernel" member. Return |
| 1001 | // true _only_ if the kernel is loaded the first time through (subsequent |
| 1002 | // calls to this function should return false after the kernel has been |
| 1003 | // already loaded). |
| 1004 | //---------------------------------------------------------------------- |
Greg Clayton | 645faca | 2011-07-09 17:15:55 +0000 | [diff] [blame] | 1005 | void |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1006 | DynamicLoaderDarwinKernel::LoadKernelModuleIfNeeded() |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1007 | { |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1008 | if (!m_kext_summary_header_ptr_addr.IsValid()) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1009 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1010 | m_kernel.Clear(); |
| 1011 | m_kernel.SetModule (m_process->GetTarget().GetExecutableModule()); |
| 1012 | m_kernel.SetIsKernel(true); |
Jason Molenda | fac2e62 | 2012-09-29 04:02:01 +0000 | [diff] [blame] | 1013 | |
| 1014 | ConstString kernel_name("mach_kernel"); |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1015 | if (m_kernel.GetModule().get() |
| 1016 | && m_kernel.GetModule()->GetObjectFile() |
| 1017 | && !m_kernel.GetModule()->GetObjectFile()->GetFileSpec().GetFilename().IsEmpty()) |
Jason Molenda | fac2e62 | 2012-09-29 04:02:01 +0000 | [diff] [blame] | 1018 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1019 | kernel_name = m_kernel.GetModule()->GetObjectFile()->GetFileSpec().GetFilename(); |
Jason Molenda | fac2e62 | 2012-09-29 04:02:01 +0000 | [diff] [blame] | 1020 | } |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1021 | m_kernel.SetName (kernel_name.AsCString()); |
Jason Molenda | fac2e62 | 2012-09-29 04:02:01 +0000 | [diff] [blame] | 1022 | |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1023 | if (m_kernel.GetLoadAddress() == LLDB_INVALID_ADDRESS) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1024 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1025 | m_kernel.SetLoadAddress(m_kernel_load_address); |
| 1026 | if (m_kernel.GetLoadAddress() == LLDB_INVALID_ADDRESS && m_kernel.GetModule()) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1027 | { |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 1028 | // We didn't get a hint from the process, so we will |
| 1029 | // try the kernel at the address that it exists at in |
| 1030 | // the file if we have one |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1031 | ObjectFile *kernel_object_file = m_kernel.GetModule()->GetObjectFile(); |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 1032 | if (kernel_object_file) |
Jason Molenda | fac2e62 | 2012-09-29 04:02:01 +0000 | [diff] [blame] | 1033 | { |
| 1034 | addr_t load_address = kernel_object_file->GetHeaderAddress().GetLoadAddress(&m_process->GetTarget()); |
| 1035 | addr_t file_address = kernel_object_file->GetHeaderAddress().GetFileAddress(); |
| 1036 | if (load_address != LLDB_INVALID_ADDRESS && load_address != 0) |
| 1037 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1038 | m_kernel.SetLoadAddress (load_address); |
Jason Molenda | fac2e62 | 2012-09-29 04:02:01 +0000 | [diff] [blame] | 1039 | if (load_address != file_address) |
| 1040 | { |
| 1041 | // Don't accidentally relocate the kernel to the File address -- |
| 1042 | // the Load address has already been set to its actual in-memory address. |
| 1043 | // Mark it as IsLoaded. |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1044 | m_kernel.SetProcessStopId (m_process->GetStopID()); |
Jason Molenda | fac2e62 | 2012-09-29 04:02:01 +0000 | [diff] [blame] | 1045 | } |
| 1046 | } |
| 1047 | else |
| 1048 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1049 | m_kernel.SetLoadAddress(file_address); |
Jason Molenda | fac2e62 | 2012-09-29 04:02:01 +0000 | [diff] [blame] | 1050 | } |
| 1051 | } |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1052 | } |
| 1053 | } |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 1054 | |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1055 | if (m_kernel.GetLoadAddress() != LLDB_INVALID_ADDRESS) |
Greg Clayton | aa20630 | 2012-03-21 04:25:00 +0000 | [diff] [blame] | 1056 | { |
| 1057 | if (!m_kernel.LoadImageUsingMemoryModule (m_process)) |
| 1058 | { |
| 1059 | m_kernel.LoadImageAtFileAddress (m_process); |
| 1060 | } |
| 1061 | } |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1062 | |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1063 | if (m_kernel.IsLoaded() && m_kernel.GetModule()) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1064 | { |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 1065 | static ConstString kext_summary_symbol ("gLoadedKextSummaries"); |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1066 | const Symbol *symbol = m_kernel.GetModule()->FindFirstSymbolWithNameAndType (kext_summary_symbol, eSymbolTypeData); |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 1067 | if (symbol) |
| 1068 | { |
Greg Clayton | 0c31d3d | 2012-03-07 21:03:09 +0000 | [diff] [blame] | 1069 | m_kext_summary_header_ptr_addr = symbol->GetAddress(); |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 1070 | // Update all image infos |
| 1071 | ReadAllKextSummaries (); |
| 1072 | } |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1073 | } |
| 1074 | else |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1075 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1076 | m_kernel.Clear(); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1077 | } |
| 1078 | } |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1081 | //---------------------------------------------------------------------- |
| 1082 | // Static callback function that gets called when our DYLD notification |
| 1083 | // breakpoint gets hit. We update all of our image infos and then |
| 1084 | // let our super class DynamicLoader class decide if we should stop |
| 1085 | // or not (based on global preference). |
| 1086 | //---------------------------------------------------------------------- |
| 1087 | bool |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1088 | DynamicLoaderDarwinKernel::BreakpointHitCallback (void *baton, |
Greg Clayton | 645faca | 2011-07-09 17:15:55 +0000 | [diff] [blame] | 1089 | StoppointCallbackContext *context, |
| 1090 | user_id_t break_id, |
| 1091 | user_id_t break_loc_id) |
Greg Clayton | 8c547d4 | 2011-07-08 03:21:57 +0000 | [diff] [blame] | 1092 | { |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1093 | return static_cast<DynamicLoaderDarwinKernel*>(baton)->BreakpointHit (context, break_id, break_loc_id); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | bool |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1097 | DynamicLoaderDarwinKernel::BreakpointHit (StoppointCallbackContext *context, |
Greg Clayton | 645faca | 2011-07-09 17:15:55 +0000 | [diff] [blame] | 1098 | user_id_t break_id, |
| 1099 | user_id_t break_loc_id) |
| 1100 | { |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1101 | Log *log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER)); |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1102 | if (log) |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1103 | log->Printf ("DynamicLoaderDarwinKernel::BreakpointHit (...)\n"); |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1104 | |
Greg Clayton | 645faca | 2011-07-09 17:15:55 +0000 | [diff] [blame] | 1105 | ReadAllKextSummaries (); |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1106 | |
| 1107 | if (log) |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1108 | PutToLog(log); |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1109 | |
Greg Clayton | 645faca | 2011-07-09 17:15:55 +0000 | [diff] [blame] | 1110 | return GetStopWhenImagesChange(); |
| 1111 | } |
| 1112 | |
| 1113 | |
| 1114 | bool |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1115 | DynamicLoaderDarwinKernel::ReadKextSummaryHeader () |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1116 | { |
| 1117 | Mutex::Locker locker(m_mutex); |
| 1118 | |
| 1119 | // the all image infos is already valid for this process stop ID |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1120 | |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1121 | if (m_kext_summary_header_ptr_addr.IsValid()) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1122 | { |
| 1123 | const uint32_t addr_size = m_kernel.GetAddressByteSize (); |
| 1124 | const ByteOrder byte_order = m_kernel.GetByteOrder(); |
| 1125 | Error error; |
| 1126 | // Read enough bytes for a "OSKextLoadedKextSummaryHeader" structure |
| 1127 | // which is currenty 4 uint32_t and a pointer. |
| 1128 | uint8_t buf[24]; |
| 1129 | DataExtractor data (buf, sizeof(buf), byte_order, addr_size); |
| 1130 | const size_t count = 4 * sizeof(uint32_t) + addr_size; |
Greg Clayton | 8c547d4 | 2011-07-08 03:21:57 +0000 | [diff] [blame] | 1131 | const bool prefer_file_cache = false; |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1132 | if (m_process->GetTarget().ReadPointerFromMemory (m_kext_summary_header_ptr_addr, |
| 1133 | prefer_file_cache, |
| 1134 | error, |
| 1135 | m_kext_summary_header_addr)) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1136 | { |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1137 | // We got a valid address for our kext summary header and make sure it isn't NULL |
| 1138 | if (m_kext_summary_header_addr.IsValid() && |
| 1139 | m_kext_summary_header_addr.GetFileAddress() != 0) |
| 1140 | { |
| 1141 | const size_t bytes_read = m_process->GetTarget().ReadMemory (m_kext_summary_header_addr, prefer_file_cache, buf, count, error); |
| 1142 | if (bytes_read == count) |
| 1143 | { |
Greg Clayton | 36da2aa | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1144 | lldb::offset_t offset = 0; |
Greg Clayton | 0fa5124 | 2011-07-19 03:57:15 +0000 | [diff] [blame] | 1145 | m_kext_summary_header.version = data.GetU32(&offset); |
| 1146 | if (m_kext_summary_header.version >= 2) |
| 1147 | { |
| 1148 | m_kext_summary_header.entry_size = data.GetU32(&offset); |
| 1149 | } |
| 1150 | else |
| 1151 | { |
| 1152 | // Versions less than 2 didn't have an entry size, it was hard coded |
| 1153 | m_kext_summary_header.entry_size = KERNEL_MODULE_ENTRY_SIZE_VERSION_1; |
| 1154 | } |
| 1155 | m_kext_summary_header.entry_count = data.GetU32(&offset); |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1156 | return true; |
| 1157 | } |
| 1158 | } |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1159 | } |
| 1160 | } |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1161 | m_kext_summary_header_addr.Clear(); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1162 | return false; |
| 1163 | } |
| 1164 | |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1165 | // We've either (a) just attached to a new kernel, or (b) the kexts-changed breakpoint was hit |
| 1166 | // and we need to figure out what kexts have been added or removed. |
| 1167 | // Read the kext summaries from the inferior kernel memory, compare them against the |
| 1168 | // m_known_kexts vector and update the m_known_kexts vector as needed to keep in sync with the |
| 1169 | // inferior. |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1170 | |
| 1171 | bool |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1172 | DynamicLoaderDarwinKernel::ParseKextSummaries (const Address &kext_summary_addr, uint32_t count) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1173 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1174 | KextImageInfo::collection kext_summaries; |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1175 | Log *log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER)); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1176 | if (log) |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1177 | log->Printf ("Kexts-changed breakpoint hit, there are %d kexts currently.\n", count); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1178 | |
| 1179 | Mutex::Locker locker(m_mutex); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1180 | |
| 1181 | if (!ReadKextSummaries (kext_summary_addr, count, kext_summaries)) |
| 1182 | return false; |
| 1183 | |
Jason Molenda | 7cb80c9 | 2013-02-26 00:26:47 +0000 | [diff] [blame] | 1184 | // read the plugin.dynamic-loader.darwin-kernel.load-kexts setting -- if the user requested no |
| 1185 | // kext loading, don't print any messages about kexts & don't try to read them. |
| 1186 | const bool load_kexts = GetGlobalProperties()->GetLoadKexts(); |
| 1187 | |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1188 | // By default, all kexts we've loaded in the past are marked as "remove" and all of the kexts |
| 1189 | // we just found out about from ReadKextSummaries are marked as "add". |
| 1190 | std::vector<bool> to_be_removed(m_known_kexts.size(), true); |
| 1191 | std::vector<bool> to_be_added(count, true); |
| 1192 | |
| 1193 | int number_of_new_kexts_being_added = 0; |
| 1194 | int number_of_old_kexts_being_removed = m_known_kexts.size(); |
| 1195 | |
| 1196 | const uint32_t new_kexts_size = kext_summaries.size(); |
| 1197 | const uint32_t old_kexts_size = m_known_kexts.size(); |
| 1198 | |
| 1199 | // The m_known_kexts vector may have entries that have been Cleared, |
| 1200 | // or are a kernel. |
| 1201 | for (uint32_t old_kext = 0; old_kext < old_kexts_size; old_kext++) |
| 1202 | { |
| 1203 | bool ignore = false; |
| 1204 | KextImageInfo &image_info = m_known_kexts[old_kext]; |
| 1205 | if (image_info.IsKernel()) |
| 1206 | { |
| 1207 | ignore = true; |
| 1208 | } |
| 1209 | else if (image_info.GetLoadAddress() == LLDB_INVALID_ADDRESS && !image_info.GetModule()) |
| 1210 | { |
| 1211 | ignore = true; |
| 1212 | } |
| 1213 | |
| 1214 | if (ignore) |
| 1215 | { |
| 1216 | number_of_old_kexts_being_removed--; |
| 1217 | to_be_removed[old_kext] = false; |
| 1218 | } |
| 1219 | } |
| 1220 | |
| 1221 | // Scan over the list of kexts we just read from the kernel, note those that |
| 1222 | // need to be added and those already loaded. |
| 1223 | for (uint32_t new_kext = 0; new_kext < new_kexts_size; new_kext++) |
| 1224 | { |
| 1225 | bool add_this_one = true; |
| 1226 | for (uint32_t old_kext = 0; old_kext < old_kexts_size; old_kext++) |
| 1227 | { |
| 1228 | if (m_known_kexts[old_kext] == kext_summaries[new_kext]) |
| 1229 | { |
| 1230 | // We already have this kext, don't re-load it. |
| 1231 | to_be_added[new_kext] = false; |
| 1232 | // This kext is still present, do not remove it. |
| 1233 | to_be_removed[old_kext] = false; |
| 1234 | |
| 1235 | number_of_old_kexts_being_removed--; |
| 1236 | add_this_one = false; |
| 1237 | break; |
| 1238 | } |
| 1239 | } |
| 1240 | if (add_this_one) |
| 1241 | { |
| 1242 | number_of_new_kexts_being_added++; |
| 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | if (number_of_new_kexts_being_added == 0 && number_of_old_kexts_being_removed == 0) |
| 1247 | return true; |
| 1248 | |
Greg Clayton | 234981a | 2011-07-20 03:41:06 +0000 | [diff] [blame] | 1249 | Stream *s = &m_process->GetTarget().GetDebugger().GetOutputStream(); |
Jason Molenda | 7cb80c9 | 2013-02-26 00:26:47 +0000 | [diff] [blame] | 1250 | if (s && load_kexts) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1251 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1252 | if (number_of_new_kexts_being_added > 0 && number_of_old_kexts_being_removed > 0) |
| 1253 | { |
| 1254 | s->Printf ("Loading %d kext modules and unloading %d kext modules ", number_of_new_kexts_being_added, number_of_old_kexts_being_removed); |
| 1255 | } |
| 1256 | else if (number_of_new_kexts_being_added > 0) |
| 1257 | { |
| 1258 | s->Printf ("Loading %d kext modules ", number_of_new_kexts_being_added); |
| 1259 | } |
| 1260 | else if (number_of_old_kexts_being_removed > 0) |
| 1261 | { |
| 1262 | s->Printf ("Unloading %d kext modules ", number_of_old_kexts_being_removed); |
| 1263 | } |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1264 | } |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1265 | |
| 1266 | if (log) |
Jason Molenda | 7cb80c9 | 2013-02-26 00:26:47 +0000 | [diff] [blame] | 1267 | { |
| 1268 | if (load_kexts) |
| 1269 | { |
| 1270 | log->Printf ("DynamicLoaderDarwinKernel::ParseKextSummaries: %d kexts added, %d kexts removed", number_of_new_kexts_being_added, number_of_old_kexts_being_removed); |
| 1271 | } |
| 1272 | else |
| 1273 | { |
| 1274 | log->Printf ("DynamicLoaderDarwinKernel::ParseKextSummaries kext loading is disabled, else would have %d kexts added, %d kexts removed", number_of_new_kexts_being_added, number_of_old_kexts_being_removed); |
| 1275 | } |
| 1276 | } |
| 1277 | |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1278 | |
| 1279 | if (number_of_new_kexts_being_added > 0) |
| 1280 | { |
| 1281 | ModuleList loaded_module_list; |
| 1282 | |
| 1283 | const uint32_t num_of_new_kexts = kext_summaries.size(); |
| 1284 | for (uint32_t new_kext = 0; new_kext < num_of_new_kexts; new_kext++) |
| 1285 | { |
| 1286 | if (to_be_added[new_kext] == true) |
| 1287 | { |
| 1288 | KextImageInfo &image_info = kext_summaries[new_kext]; |
Jason Molenda | 7cb80c9 | 2013-02-26 00:26:47 +0000 | [diff] [blame] | 1289 | if (load_kexts) |
| 1290 | { |
| 1291 | if (!image_info.LoadImageUsingMemoryModule (m_process)) |
| 1292 | { |
| 1293 | image_info.LoadImageAtFileAddress (m_process); |
| 1294 | } |
| 1295 | } |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1296 | |
| 1297 | m_known_kexts.push_back(image_info); |
| 1298 | |
| 1299 | if (image_info.GetModule() && m_process->GetStopID() == image_info.GetProcessStopId()) |
| 1300 | loaded_module_list.AppendIfNeeded (image_info.GetModule()); |
| 1301 | |
Jason Molenda | 7cb80c9 | 2013-02-26 00:26:47 +0000 | [diff] [blame] | 1302 | if (s && load_kexts) |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1303 | s->Printf ("."); |
| 1304 | |
| 1305 | if (log) |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1306 | kext_summaries[new_kext].PutToLog (log); |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1307 | } |
| 1308 | } |
| 1309 | m_process->GetTarget().ModulesDidLoad (loaded_module_list); |
| 1310 | } |
| 1311 | |
| 1312 | if (number_of_old_kexts_being_removed > 0) |
| 1313 | { |
| 1314 | ModuleList loaded_module_list; |
| 1315 | const uint32_t num_of_old_kexts = m_known_kexts.size(); |
| 1316 | for (uint32_t old_kext = 0; old_kext < num_of_old_kexts; old_kext++) |
| 1317 | { |
| 1318 | ModuleList unloaded_module_list; |
| 1319 | if (to_be_removed[old_kext]) |
| 1320 | { |
| 1321 | KextImageInfo &image_info = m_known_kexts[old_kext]; |
| 1322 | // You can't unload the kernel. |
| 1323 | if (!image_info.IsKernel()) |
| 1324 | { |
| 1325 | if (image_info.GetModule()) |
| 1326 | { |
| 1327 | unloaded_module_list.AppendIfNeeded (image_info.GetModule()); |
| 1328 | } |
| 1329 | if (s) |
| 1330 | s->Printf ("."); |
| 1331 | image_info.Clear(); |
| 1332 | // should pull it out of the KextImageInfos vector but that would mutate the list and invalidate |
| 1333 | // the to_be_removed bool vector; leaving it in place once Cleared() is relatively harmless. |
| 1334 | } |
| 1335 | } |
| 1336 | m_process->GetTarget().ModulesDidUnload (unloaded_module_list); |
| 1337 | } |
| 1338 | } |
| 1339 | |
Jason Molenda | 7cb80c9 | 2013-02-26 00:26:47 +0000 | [diff] [blame] | 1340 | if (s && load_kexts) |
Jason Molenda | 4952db8 | 2012-10-02 03:49:41 +0000 | [diff] [blame] | 1341 | { |
| 1342 | s->Printf (" done.\n"); |
| 1343 | s->Flush (); |
| 1344 | } |
| 1345 | |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1346 | return true; |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1349 | uint32_t |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1350 | DynamicLoaderDarwinKernel::ReadKextSummaries (const Address &kext_summary_addr, |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1351 | uint32_t image_infos_count, |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1352 | KextImageInfo::collection &image_infos) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1353 | { |
| 1354 | const ByteOrder endian = m_kernel.GetByteOrder(); |
| 1355 | const uint32_t addr_size = m_kernel.GetAddressByteSize(); |
| 1356 | |
| 1357 | image_infos.resize(image_infos_count); |
| 1358 | const size_t count = image_infos.size() * m_kext_summary_header.entry_size; |
| 1359 | DataBufferHeap data(count, 0); |
| 1360 | Error error; |
Greg Clayton | 7b13922 | 2011-07-21 01:12:01 +0000 | [diff] [blame] | 1361 | |
Greg Clayton | 8c547d4 | 2011-07-08 03:21:57 +0000 | [diff] [blame] | 1362 | const bool prefer_file_cache = false; |
| 1363 | const size_t bytes_read = m_process->GetTarget().ReadMemory (kext_summary_addr, |
| 1364 | prefer_file_cache, |
| 1365 | data.GetBytes(), |
| 1366 | data.GetByteSize(), |
| 1367 | error); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1368 | if (bytes_read == count) |
| 1369 | { |
Greg Clayton | 0fa5124 | 2011-07-19 03:57:15 +0000 | [diff] [blame] | 1370 | |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1371 | DataExtractor extractor (data.GetBytes(), data.GetByteSize(), endian, addr_size); |
| 1372 | uint32_t i=0; |
Greg Clayton | 0fa5124 | 2011-07-19 03:57:15 +0000 | [diff] [blame] | 1373 | for (uint32_t kext_summary_offset = 0; |
| 1374 | i < image_infos.size() && extractor.ValidOffsetForDataOfSize(kext_summary_offset, m_kext_summary_header.entry_size); |
| 1375 | ++i, kext_summary_offset += m_kext_summary_header.entry_size) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1376 | { |
Greg Clayton | 36da2aa | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1377 | lldb::offset_t offset = kext_summary_offset; |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1378 | const void *name_data = extractor.GetData(&offset, KERNEL_MODULE_MAX_NAME); |
| 1379 | if (name_data == NULL) |
| 1380 | break; |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1381 | image_infos[i].SetName ((const char *) name_data); |
| 1382 | UUID uuid (extractor.GetData (&offset, 16), 16); |
| 1383 | image_infos[i].SetUUID (uuid); |
| 1384 | image_infos[i].SetLoadAddress (extractor.GetU64(&offset)); |
| 1385 | image_infos[i].SetSize (extractor.GetU64(&offset)); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1386 | } |
| 1387 | if (i < image_infos.size()) |
| 1388 | image_infos.resize(i); |
| 1389 | } |
| 1390 | else |
| 1391 | { |
| 1392 | image_infos.clear(); |
| 1393 | } |
| 1394 | return image_infos.size(); |
| 1395 | } |
| 1396 | |
| 1397 | bool |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1398 | DynamicLoaderDarwinKernel::ReadAllKextSummaries () |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1399 | { |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1400 | Mutex::Locker locker(m_mutex); |
Greg Clayton | 645faca | 2011-07-09 17:15:55 +0000 | [diff] [blame] | 1401 | |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1402 | if (ReadKextSummaryHeader ()) |
| 1403 | { |
Greg Clayton | 645faca | 2011-07-09 17:15:55 +0000 | [diff] [blame] | 1404 | if (m_kext_summary_header.entry_count > 0 && m_kext_summary_header_addr.IsValid()) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1405 | { |
Greg Clayton | 8c547d4 | 2011-07-08 03:21:57 +0000 | [diff] [blame] | 1406 | Address summary_addr (m_kext_summary_header_addr); |
Greg Clayton | 0fa5124 | 2011-07-19 03:57:15 +0000 | [diff] [blame] | 1407 | summary_addr.Slide(m_kext_summary_header.GetSize()); |
Greg Clayton | 8c547d4 | 2011-07-08 03:21:57 +0000 | [diff] [blame] | 1408 | if (!ParseKextSummaries (summary_addr, m_kext_summary_header.entry_count)) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1409 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1410 | m_known_kexts.clear(); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1411 | } |
| 1412 | return true; |
| 1413 | } |
| 1414 | } |
| 1415 | return false; |
| 1416 | } |
| 1417 | |
| 1418 | //---------------------------------------------------------------------- |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1419 | // Dump an image info structure to the file handle provided. |
| 1420 | //---------------------------------------------------------------------- |
| 1421 | void |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1422 | DynamicLoaderDarwinKernel::KextImageInfo::PutToLog (Log *log) const |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1423 | { |
| 1424 | if (log == NULL) |
| 1425 | return; |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1426 | const uint8_t *u = (uint8_t *) m_uuid.GetBytes(); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1427 | |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1428 | if (m_load_address == LLDB_INVALID_ADDRESS) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1429 | { |
| 1430 | if (u) |
| 1431 | { |
Greg Clayton | 0fa5124 | 2011-07-19 03:57:15 +0000 | [diff] [blame] | 1432 | log->Printf("\tuuid=%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X name=\"%s\" (UNLOADED)", |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1433 | u[ 0], u[ 1], u[ 2], u[ 3], |
| 1434 | u[ 4], u[ 5], u[ 6], u[ 7], |
| 1435 | u[ 8], u[ 9], u[10], u[11], |
| 1436 | u[12], u[13], u[14], u[15], |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1437 | m_name.c_str()); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1438 | } |
| 1439 | else |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1440 | log->Printf("\tname=\"%s\" (UNLOADED)", m_name.c_str()); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1441 | } |
| 1442 | else |
| 1443 | { |
| 1444 | if (u) |
| 1445 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1446 | log->Printf("\taddr=0x%16.16" PRIx64 " size=0x%16.16" PRIx64 " uuid=%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X name=\"%s\"", |
| 1447 | m_load_address, m_size, |
Greg Clayton | 0fa5124 | 2011-07-19 03:57:15 +0000 | [diff] [blame] | 1448 | u[ 0], u[ 1], u[ 2], u[ 3], u[ 4], u[ 5], u[ 6], u[ 7], |
| 1449 | u[ 8], u[ 9], u[10], u[11], u[12], u[13], u[14], u[15], |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1450 | m_name.c_str()); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1451 | } |
| 1452 | else |
| 1453 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1454 | log->Printf("\t[0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ") name=\"%s\"", |
| 1455 | m_load_address, m_load_address+m_size, m_name.c_str()); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1456 | } |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | //---------------------------------------------------------------------- |
| 1461 | // Dump the _dyld_all_image_infos members and all current image infos |
| 1462 | // that we have parsed to the file handle provided. |
| 1463 | //---------------------------------------------------------------------- |
| 1464 | void |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1465 | DynamicLoaderDarwinKernel::PutToLog(Log *log) const |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1466 | { |
| 1467 | if (log == NULL) |
| 1468 | return; |
| 1469 | |
| 1470 | Mutex::Locker locker(m_mutex); |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1471 | log->Printf("gLoadedKextSummaries = 0x%16.16" PRIx64 " { version=%u, entry_size=%u, entry_count=%u }", |
Greg Clayton | 8c547d4 | 2011-07-08 03:21:57 +0000 | [diff] [blame] | 1472 | m_kext_summary_header_addr.GetFileAddress(), |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1473 | m_kext_summary_header.version, |
| 1474 | m_kext_summary_header.entry_size, |
Greg Clayton | 0fa5124 | 2011-07-19 03:57:15 +0000 | [diff] [blame] | 1475 | m_kext_summary_header.entry_count); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1476 | |
| 1477 | size_t i; |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1478 | const size_t count = m_known_kexts.size(); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1479 | if (count > 0) |
| 1480 | { |
| 1481 | log->PutCString("Loaded:"); |
| 1482 | for (i = 0; i<count; i++) |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1483 | m_known_kexts[i].PutToLog(log); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1484 | } |
| 1485 | } |
| 1486 | |
| 1487 | void |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1488 | DynamicLoaderDarwinKernel::PrivateInitialize(Process *process) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1489 | { |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1490 | DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s() process state = %s\n", __FUNCTION__, StateAsCString(m_process->GetState())); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1491 | Clear(true); |
| 1492 | m_process = process; |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1493 | } |
| 1494 | |
Greg Clayton | 645faca | 2011-07-09 17:15:55 +0000 | [diff] [blame] | 1495 | void |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1496 | DynamicLoaderDarwinKernel::SetNotificationBreakpointIfNeeded () |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1497 | { |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1498 | if (m_break_id == LLDB_INVALID_BREAK_ID && m_kernel.GetModule()) |
Greg Clayton | 645faca | 2011-07-09 17:15:55 +0000 | [diff] [blame] | 1499 | { |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1500 | DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s() process state = %s\n", __FUNCTION__, StateAsCString(m_process->GetState())); |
Greg Clayton | 645faca | 2011-07-09 17:15:55 +0000 | [diff] [blame] | 1501 | |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1502 | |
Jim Ingham | 2cf5ccb | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1503 | const bool internal_bp = true; |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 1504 | const LazyBool skip_prologue = eLazyBoolNo; |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1505 | FileSpecList module_spec_list; |
Jason Molenda | 32a4528 | 2013-02-19 05:42:46 +0000 | [diff] [blame] | 1506 | module_spec_list.Append (m_kernel.GetModule()->GetFileSpec()); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1507 | Breakpoint *bp = m_process->GetTarget().CreateBreakpoint (&module_spec_list, |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1508 | NULL, |
Greg Clayton | 645faca | 2011-07-09 17:15:55 +0000 | [diff] [blame] | 1509 | "OSKextLoadedKextSummariesUpdated", |
| 1510 | eFunctionNameTypeFull, |
Jim Ingham | 2cf5ccb | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1511 | skip_prologue, |
| 1512 | internal_bp).get(); |
Greg Clayton | 645faca | 2011-07-09 17:15:55 +0000 | [diff] [blame] | 1513 | |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1514 | bp->SetCallback (DynamicLoaderDarwinKernel::BreakpointHitCallback, this, true); |
Greg Clayton | 645faca | 2011-07-09 17:15:55 +0000 | [diff] [blame] | 1515 | m_break_id = bp->GetID(); |
| 1516 | } |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | //---------------------------------------------------------------------- |
| 1520 | // Member function that gets called when the process state changes. |
| 1521 | //---------------------------------------------------------------------- |
| 1522 | void |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1523 | DynamicLoaderDarwinKernel::PrivateProcessStateChanged (Process *process, StateType state) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1524 | { |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1525 | DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s(%s)\n", __FUNCTION__, StateAsCString(state)); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1526 | switch (state) |
| 1527 | { |
| 1528 | case eStateConnected: |
| 1529 | case eStateAttaching: |
| 1530 | case eStateLaunching: |
| 1531 | case eStateInvalid: |
| 1532 | case eStateUnloaded: |
| 1533 | case eStateExited: |
| 1534 | case eStateDetached: |
| 1535 | Clear(false); |
| 1536 | break; |
| 1537 | |
| 1538 | case eStateStopped: |
Greg Clayton | 645faca | 2011-07-09 17:15:55 +0000 | [diff] [blame] | 1539 | UpdateIfNeeded(); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1540 | break; |
| 1541 | |
| 1542 | case eStateRunning: |
| 1543 | case eStateStepping: |
| 1544 | case eStateCrashed: |
| 1545 | case eStateSuspended: |
| 1546 | break; |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1547 | } |
| 1548 | } |
| 1549 | |
| 1550 | ThreadPlanSP |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1551 | DynamicLoaderDarwinKernel::GetStepThroughTrampolinePlan (Thread &thread, bool stop_others) |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1552 | { |
| 1553 | ThreadPlanSP thread_plan_sp; |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1554 | Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Greg Clayton | 645faca | 2011-07-09 17:15:55 +0000 | [diff] [blame] | 1555 | if (log) |
| 1556 | log->Printf ("Could not find symbol for step through."); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1557 | return thread_plan_sp; |
| 1558 | } |
| 1559 | |
| 1560 | Error |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1561 | DynamicLoaderDarwinKernel::CanLoadImage () |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1562 | { |
| 1563 | Error error; |
| 1564 | error.SetErrorString("always unsafe to load or unload shared libraries in the darwin kernel"); |
| 1565 | return error; |
| 1566 | } |
| 1567 | |
| 1568 | void |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1569 | DynamicLoaderDarwinKernel::Initialize() |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1570 | { |
| 1571 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 1572 | GetPluginDescriptionStatic(), |
Greg Clayton | 87e9d32 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 1573 | CreateInstance, |
| 1574 | DebuggerInitialize); |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | void |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1578 | DynamicLoaderDarwinKernel::Terminate() |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1579 | { |
| 1580 | PluginManager::UnregisterPlugin (CreateInstance); |
| 1581 | } |
| 1582 | |
Greg Clayton | 87e9d32 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 1583 | void |
| 1584 | DynamicLoaderDarwinKernel::DebuggerInitialize (lldb_private::Debugger &debugger) |
| 1585 | { |
| 1586 | if (!PluginManager::GetSettingForDynamicLoaderPlugin (debugger, DynamicLoaderDarwinKernelProperties::GetSettingName())) |
| 1587 | { |
| 1588 | const bool is_global_setting = true; |
| 1589 | PluginManager::CreateSettingForDynamicLoaderPlugin (debugger, |
| 1590 | GetGlobalProperties()->GetValueProperties(), |
| 1591 | ConstString ("Properties for the DynamicLoaderDarwinKernel plug-in."), |
| 1592 | is_global_setting); |
| 1593 | } |
| 1594 | } |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1595 | |
| 1596 | const char * |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1597 | DynamicLoaderDarwinKernel::GetPluginNameStatic() |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1598 | { |
Greg Clayton | 2acbc2a | 2012-10-19 18:14:47 +0000 | [diff] [blame] | 1599 | return "dynamic-loader.darwin-kernel"; |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | const char * |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1603 | DynamicLoaderDarwinKernel::GetPluginDescriptionStatic() |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1604 | { |
| 1605 | return "Dynamic loader plug-in that watches for shared library loads/unloads in the MacOSX kernel."; |
| 1606 | } |
| 1607 | |
| 1608 | |
| 1609 | //------------------------------------------------------------------ |
| 1610 | // PluginInterface protocol |
| 1611 | //------------------------------------------------------------------ |
| 1612 | const char * |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1613 | DynamicLoaderDarwinKernel::GetPluginName() |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1614 | { |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1615 | return "DynamicLoaderDarwinKernel"; |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | const char * |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1619 | DynamicLoaderDarwinKernel::GetShortPluginName() |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1620 | { |
| 1621 | return GetPluginNameStatic(); |
| 1622 | } |
| 1623 | |
| 1624 | uint32_t |
Greg Clayton | 17f3d05 | 2011-08-22 22:30:57 +0000 | [diff] [blame] | 1625 | DynamicLoaderDarwinKernel::GetPluginVersion() |
Greg Clayton | bbea133 | 2011-07-08 00:48:09 +0000 | [diff] [blame] | 1626 | { |
| 1627 | return 1; |
| 1628 | } |
| 1629 | |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1630 | lldb::ByteOrder |
| 1631 | DynamicLoaderDarwinKernel::GetByteOrderFromMagic (uint32_t magic) |
| 1632 | { |
| 1633 | switch (magic) |
| 1634 | { |
| 1635 | case llvm::MachO::HeaderMagic32: |
| 1636 | case llvm::MachO::HeaderMagic64: |
| 1637 | return lldb::endian::InlHostByteOrder(); |
| 1638 | |
| 1639 | case llvm::MachO::HeaderMagic32Swapped: |
| 1640 | case llvm::MachO::HeaderMagic64Swapped: |
| 1641 | if (lldb::endian::InlHostByteOrder() == lldb::eByteOrderBig) |
| 1642 | return lldb::eByteOrderLittle; |
| 1643 | else |
| 1644 | return lldb::eByteOrderBig; |
| 1645 | |
| 1646 | default: |
| 1647 | break; |
| 1648 | } |
| 1649 | return lldb::eByteOrderInvalid; |
| 1650 | } |
| 1651 | |