Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- Symbols.cpp ---------------------------------------------*- C++ -*-===// |
| 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 | |
| 10 | #include "lldb/Host/Symbols.h" |
| 11 | |
| 12 | // C Includes |
| 13 | #include <dirent.h> |
Jason Molenda | f256975 | 2012-10-30 21:26:30 +0000 | [diff] [blame] | 14 | #include <pwd.h> |
Greg Clayton | 1674b12 | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 15 | #include "llvm/Support/MachO.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | |
| 17 | // C++ Includes |
| 18 | // Other libraries and framework includes |
| 19 | #include <CoreFoundation/CoreFoundation.h> |
| 20 | |
| 21 | // Project includes |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Core/ArchSpec.h" |
| 23 | #include "lldb/Core/DataBuffer.h" |
| 24 | #include "lldb/Core/DataExtractor.h" |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 25 | #include "lldb/Core/Module.h" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 26 | #include "lldb/Core/ModuleSpec.h" |
Johnny Chen | 9262cd5 | 2012-08-22 00:18:43 +0000 | [diff] [blame] | 27 | #include "lldb/Core/StreamString.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | #include "lldb/Core/Timer.h" |
| 29 | #include "lldb/Core/UUID.h" |
Greg Clayton | cd54803 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 30 | #include "lldb/Host/Endian.h" |
Johnny Chen | cbf1591 | 2012-02-01 01:49:50 +0000 | [diff] [blame] | 31 | #include "lldb/Host/Host.h" |
Greg Clayton | ad40027 | 2011-02-01 05:15:02 +0000 | [diff] [blame] | 32 | #include "lldb/Utility/CleanUp.h" |
Daniel Dunbar | a1ebbd2 | 2011-10-31 22:50:53 +0000 | [diff] [blame] | 33 | #include "Host/macosx/cfcpp/CFCBundle.h" |
Greg Clayton | b924eb6 | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 34 | #include "Host/macosx/cfcpp/CFCData.h" |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 35 | #include "Host/macosx/cfcpp/CFCReleaser.h" |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 36 | #include "Host/macosx/cfcpp/CFCString.h" |
Chris Lattner | 5bc7b67 | 2010-09-08 23:01:14 +0000 | [diff] [blame] | 37 | #include "mach/machine.h" |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 38 | |
Greg Clayton | 0fa5124 | 2011-07-19 03:57:15 +0000 | [diff] [blame] | 39 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 40 | using namespace lldb; |
| 41 | using namespace lldb_private; |
Greg Clayton | 1674b12 | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 42 | using namespace llvm::MachO; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 44 | #if !defined (__arm__) // No DebugSymbols on the iOS devices |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | extern "C" { |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 46 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 47 | CFURLRef DBGCopyFullDSYMURLForUUID (CFUUIDRef uuid, CFURLRef exec_url); |
| 48 | CFDictionaryRef DBGCopyDSYMPropertyLists (CFURLRef dsym_url); |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 49 | |
| 50 | } |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 51 | #endif |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | |
| 53 | static bool |
| 54 | SkinnyMachOFileContainsArchAndUUID |
| 55 | ( |
| 56 | const FileSpec &file_spec, |
| 57 | const ArchSpec *arch, |
Greg Clayton | 0467c78 | 2011-02-04 18:53:10 +0000 | [diff] [blame] | 58 | const lldb_private::UUID *uuid, // the UUID we are looking for |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 59 | off_t file_offset, |
| 60 | DataExtractor& data, |
| 61 | uint32_t data_offset, |
| 62 | const uint32_t magic |
| 63 | ) |
| 64 | { |
Greg Clayton | 1674b12 | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 65 | assert(magic == HeaderMagic32 || magic == HeaderMagic32Swapped || magic == HeaderMagic64 || magic == HeaderMagic64Swapped); |
| 66 | if (magic == HeaderMagic32 || magic == HeaderMagic64) |
Greg Clayton | cd54803 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 67 | data.SetByteOrder (lldb::endian::InlHostByteOrder()); |
| 68 | else if (lldb::endian::InlHostByteOrder() == eByteOrderBig) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 69 | data.SetByteOrder (eByteOrderLittle); |
| 70 | else |
| 71 | data.SetByteOrder (eByteOrderBig); |
| 72 | |
| 73 | uint32_t i; |
| 74 | const uint32_t cputype = data.GetU32(&data_offset); // cpu specifier |
| 75 | const uint32_t cpusubtype = data.GetU32(&data_offset); // machine specifier |
| 76 | data_offset+=4; // Skip mach file type |
| 77 | const uint32_t ncmds = data.GetU32(&data_offset); // number of load commands |
| 78 | const uint32_t sizeofcmds = data.GetU32(&data_offset); // the size of all the load commands |
| 79 | data_offset+=4; // Skip flags |
| 80 | |
| 81 | // Check the architecture if we have a valid arch pointer |
| 82 | if (arch) |
| 83 | { |
Greg Clayton | cf01505 | 2010-06-11 03:25:34 +0000 | [diff] [blame] | 84 | ArchSpec file_arch(eArchTypeMachO, cputype, cpusubtype); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 85 | |
Sean Callanan | 878f13c | 2012-12-14 23:43:03 +0000 | [diff] [blame^] | 86 | if (!file_arch.IsCompatibleMatch(*arch)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 87 | return false; |
| 88 | } |
| 89 | |
| 90 | // The file exists, and if a valid arch pointer was passed in we know |
| 91 | // if already matches, so we can return if we aren't looking for a specific |
| 92 | // UUID |
| 93 | if (uuid == NULL) |
| 94 | return true; |
| 95 | |
Greg Clayton | 1674b12 | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 96 | if (magic == HeaderMagic64Swapped || magic == HeaderMagic64) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 97 | data_offset += 4; // Skip reserved field for in mach_header_64 |
| 98 | |
| 99 | // Make sure we have enough data for all the load commands |
Greg Clayton | 1674b12 | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 100 | if (magic == HeaderMagic64Swapped || magic == HeaderMagic64) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 101 | { |
| 102 | if (data.GetByteSize() < sizeof(struct mach_header_64) + sizeofcmds) |
| 103 | { |
| 104 | DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset, sizeof(struct mach_header_64) + sizeofcmds)); |
| 105 | data.SetData (data_buffer_sp); |
| 106 | } |
| 107 | } |
| 108 | else |
| 109 | { |
| 110 | if (data.GetByteSize() < sizeof(struct mach_header) + sizeofcmds) |
| 111 | { |
| 112 | DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset, sizeof(struct mach_header) + sizeofcmds)); |
| 113 | data.SetData (data_buffer_sp); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | for (i=0; i<ncmds; i++) |
| 118 | { |
| 119 | const uint32_t cmd_offset = data_offset; // Save this data_offset in case parsing of the segment goes awry! |
| 120 | uint32_t cmd = data.GetU32(&data_offset); |
| 121 | uint32_t cmd_size = data.GetU32(&data_offset); |
Greg Clayton | 1674b12 | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 122 | if (cmd == LoadCommandUUID) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 123 | { |
Greg Clayton | 0467c78 | 2011-02-04 18:53:10 +0000 | [diff] [blame] | 124 | lldb_private::UUID file_uuid (data.GetData(&data_offset, 16), 16); |
Johnny Chen | cbf1591 | 2012-02-01 01:49:50 +0000 | [diff] [blame] | 125 | if (file_uuid == *uuid) |
| 126 | return true; |
| 127 | |
| 128 | // Emit some warning messages since the UUIDs do not match! |
| 129 | char path_buf[PATH_MAX]; |
| 130 | path_buf[0] = '\0'; |
| 131 | const char *path = file_spec.GetPath(path_buf, PATH_MAX) ? path_buf |
| 132 | : file_spec.GetFilename().AsCString(); |
Johnny Chen | 9262cd5 | 2012-08-22 00:18:43 +0000 | [diff] [blame] | 133 | StreamString ss_m_uuid, ss_o_uuid; |
| 134 | uuid->Dump(&ss_m_uuid); |
| 135 | file_uuid.Dump(&ss_o_uuid); |
Johnny Chen | cbf1591 | 2012-02-01 01:49:50 +0000 | [diff] [blame] | 136 | Host::SystemLog (Host::eSystemLogWarning, |
Johnny Chen | 9262cd5 | 2012-08-22 00:18:43 +0000 | [diff] [blame] | 137 | "warning: UUID mismatch detected between binary (%s) and:\n\t'%s' (%s)\n", |
| 138 | ss_m_uuid.GetData(), path, ss_o_uuid.GetData()); |
Johnny Chen | cbf1591 | 2012-02-01 01:49:50 +0000 | [diff] [blame] | 139 | return false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 140 | } |
| 141 | data_offset = cmd_offset + cmd_size; |
| 142 | } |
| 143 | return false; |
| 144 | } |
| 145 | |
| 146 | bool |
| 147 | UniversalMachOFileContainsArchAndUUID |
| 148 | ( |
| 149 | const FileSpec &file_spec, |
| 150 | const ArchSpec *arch, |
Greg Clayton | 0467c78 | 2011-02-04 18:53:10 +0000 | [diff] [blame] | 151 | const lldb_private::UUID *uuid, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 152 | off_t file_offset, |
| 153 | DataExtractor& data, |
| 154 | uint32_t data_offset, |
| 155 | const uint32_t magic |
| 156 | ) |
| 157 | { |
Greg Clayton | 1674b12 | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 158 | assert(magic == UniversalMagic || magic == UniversalMagicSwapped); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 159 | |
| 160 | // Universal mach-o files always have their headers encoded as BIG endian |
| 161 | data.SetByteOrder(eByteOrderBig); |
| 162 | |
| 163 | uint32_t i; |
| 164 | const uint32_t nfat_arch = data.GetU32(&data_offset); // number of structs that follow |
| 165 | const uint32_t fat_header_and_arch_size = sizeof(struct fat_header) + nfat_arch * sizeof(struct fat_arch); |
| 166 | if (data.GetByteSize() < fat_header_and_arch_size) |
| 167 | { |
| 168 | DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset, fat_header_and_arch_size)); |
| 169 | data.SetData (data_buffer_sp); |
| 170 | } |
| 171 | |
| 172 | for (i=0; i<nfat_arch; i++) |
| 173 | { |
| 174 | cpu_type_t arch_cputype = data.GetU32(&data_offset); // cpu specifier (int) |
| 175 | cpu_subtype_t arch_cpusubtype = data.GetU32(&data_offset); // machine specifier (int) |
| 176 | uint32_t arch_offset = data.GetU32(&data_offset); // file offset to this object file |
| 177 | // uint32_t arch_size = data.GetU32(&data_offset); // size of this object file |
| 178 | // uint32_t arch_align = data.GetU32(&data_offset); // alignment as a power of 2 |
| 179 | data_offset += 8; // Skip size and align as we don't need those |
| 180 | // Only process this slice if the cpu type/subtype matches |
| 181 | if (arch) |
| 182 | { |
Greg Clayton | cf01505 | 2010-06-11 03:25:34 +0000 | [diff] [blame] | 183 | ArchSpec fat_arch(eArchTypeMachO, arch_cputype, arch_cpusubtype); |
Sean Callanan | 878f13c | 2012-12-14 23:43:03 +0000 | [diff] [blame^] | 184 | if (!fat_arch.IsCompatibleMatch(*arch)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 185 | continue; |
| 186 | } |
| 187 | |
| 188 | // Create a buffer with only the arch slice date in it |
| 189 | DataExtractor arch_data; |
| 190 | DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset + arch_offset, 0x1000)); |
| 191 | arch_data.SetData(data_buffer_sp); |
| 192 | uint32_t arch_data_offset = 0; |
| 193 | uint32_t arch_magic = arch_data.GetU32(&arch_data_offset); |
| 194 | |
| 195 | switch (arch_magic) |
| 196 | { |
Greg Clayton | 1674b12 | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 197 | case HeaderMagic32: |
| 198 | case HeaderMagic32Swapped: |
| 199 | case HeaderMagic64: |
| 200 | case HeaderMagic64Swapped: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 201 | if (SkinnyMachOFileContainsArchAndUUID (file_spec, arch, uuid, file_offset + arch_offset, arch_data, arch_data_offset, arch_magic)) |
| 202 | return true; |
| 203 | break; |
| 204 | } |
| 205 | } |
| 206 | return false; |
| 207 | } |
| 208 | |
| 209 | static bool |
| 210 | FileAtPathContainsArchAndUUID |
| 211 | ( |
| 212 | const FileSpec &file_spec, |
| 213 | const ArchSpec *arch, |
Greg Clayton | 0467c78 | 2011-02-04 18:53:10 +0000 | [diff] [blame] | 214 | const lldb_private::UUID *uuid |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 215 | ) |
| 216 | { |
| 217 | DataExtractor data; |
| 218 | off_t file_offset = 0; |
| 219 | DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset, 0x1000)); |
| 220 | |
| 221 | if (data_buffer_sp && data_buffer_sp->GetByteSize() > 0) |
| 222 | { |
| 223 | data.SetData(data_buffer_sp); |
| 224 | |
| 225 | uint32_t data_offset = 0; |
| 226 | uint32_t magic = data.GetU32(&data_offset); |
| 227 | |
| 228 | switch (magic) |
| 229 | { |
| 230 | // 32 bit mach-o file |
Greg Clayton | 1674b12 | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 231 | case HeaderMagic32: |
| 232 | case HeaderMagic32Swapped: |
| 233 | case HeaderMagic64: |
| 234 | case HeaderMagic64Swapped: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 235 | return SkinnyMachOFileContainsArchAndUUID (file_spec, arch, uuid, file_offset, data, data_offset, magic); |
| 236 | |
| 237 | // fat mach-o file |
Greg Clayton | 1674b12 | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 238 | case UniversalMagic: |
| 239 | case UniversalMagicSwapped: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 240 | return UniversalMachOFileContainsArchAndUUID (file_spec, arch, uuid, file_offset, data, data_offset, magic); |
| 241 | |
| 242 | default: |
| 243 | break; |
| 244 | } |
| 245 | } |
| 246 | return false; |
| 247 | } |
| 248 | |
Greg Clayton | 95b765e | 2012-09-12 02:03:59 +0000 | [diff] [blame] | 249 | FileSpec |
| 250 | Symbols::FindSymbolFileInBundle (const FileSpec& dsym_bundle_fspec, |
| 251 | const lldb_private::UUID *uuid, |
| 252 | const ArchSpec *arch) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 253 | { |
| 254 | char path[PATH_MAX]; |
| 255 | |
| 256 | FileSpec dsym_fspec; |
| 257 | |
| 258 | if (dsym_bundle_fspec.GetPath(path, sizeof(path))) |
| 259 | { |
| 260 | ::strncat (path, "/Contents/Resources/DWARF", sizeof(path) - strlen(path) - 1); |
| 261 | |
Greg Clayton | 52fd984 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 262 | lldb_utility::CleanUp <DIR *, int> dirp (opendir(path), NULL, closedir); |
Greg Clayton | ad40027 | 2011-02-01 05:15:02 +0000 | [diff] [blame] | 263 | if (dirp.is_valid()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 264 | { |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 265 | dsym_fspec.GetDirectory().SetCString(path); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 266 | struct dirent* dp; |
Greg Clayton | ad40027 | 2011-02-01 05:15:02 +0000 | [diff] [blame] | 267 | while ((dp = readdir(dirp.get())) != NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 268 | { |
| 269 | // Only search directories |
| 270 | if (dp->d_type == DT_DIR || dp->d_type == DT_UNKNOWN) |
| 271 | { |
| 272 | if (dp->d_namlen == 1 && dp->d_name[0] == '.') |
| 273 | continue; |
| 274 | |
| 275 | if (dp->d_namlen == 2 && dp->d_name[0] == '.' && dp->d_name[1] == '.') |
| 276 | continue; |
| 277 | } |
| 278 | |
| 279 | if (dp->d_type == DT_REG || dp->d_type == DT_UNKNOWN) |
| 280 | { |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 281 | dsym_fspec.GetFilename().SetCString(dp->d_name); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 282 | if (FileAtPathContainsArchAndUUID (dsym_fspec, arch, uuid)) |
| 283 | return dsym_fspec; |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | dsym_fspec.Clear(); |
| 289 | return dsym_fspec; |
| 290 | } |
| 291 | |
| 292 | static int |
| 293 | LocateMacOSXFilesUsingDebugSymbols |
| 294 | ( |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 295 | const ModuleSpec &module_spec, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 296 | FileSpec *out_exec_fspec, // If non-NULL, try and find the executable |
| 297 | FileSpec *out_dsym_fspec // If non-NULL try and find the debug symbol file |
| 298 | ) |
| 299 | { |
| 300 | int items_found = 0; |
| 301 | |
| 302 | if (out_exec_fspec) |
| 303 | out_exec_fspec->Clear(); |
| 304 | |
| 305 | if (out_dsym_fspec) |
| 306 | out_dsym_fspec->Clear(); |
| 307 | |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 308 | #if !defined (__arm__) // No DebugSymbols on the iOS devices |
| 309 | |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 310 | const UUID *uuid = module_spec.GetUUIDPtr(); |
| 311 | const ArchSpec *arch = module_spec.GetArchitecturePtr(); |
| 312 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 313 | if (uuid && uuid->IsValid()) |
| 314 | { |
| 315 | // Try and locate the dSYM file using DebugSymbols first |
| 316 | const UInt8 *module_uuid = (const UInt8 *)uuid->GetBytes(); |
| 317 | if (module_uuid != NULL) |
| 318 | { |
Greg Clayton | 0fa5124 | 2011-07-19 03:57:15 +0000 | [diff] [blame] | 319 | CFCReleaser<CFUUIDRef> module_uuid_ref(::CFUUIDCreateWithBytes (NULL, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 320 | module_uuid[0], |
| 321 | module_uuid[1], |
| 322 | module_uuid[2], |
| 323 | module_uuid[3], |
| 324 | module_uuid[4], |
| 325 | module_uuid[5], |
| 326 | module_uuid[6], |
| 327 | module_uuid[7], |
| 328 | module_uuid[8], |
| 329 | module_uuid[9], |
| 330 | module_uuid[10], |
| 331 | module_uuid[11], |
| 332 | module_uuid[12], |
| 333 | module_uuid[13], |
| 334 | module_uuid[14], |
| 335 | module_uuid[15])); |
| 336 | |
| 337 | if (module_uuid_ref.get()) |
| 338 | { |
| 339 | CFCReleaser<CFURLRef> exec_url; |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 340 | const FileSpec *exec_fspec = module_spec.GetFileSpecPtr(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 341 | if (exec_fspec) |
| 342 | { |
| 343 | char exec_cf_path[PATH_MAX]; |
| 344 | if (exec_fspec->GetPath(exec_cf_path, sizeof(exec_cf_path))) |
| 345 | exec_url.reset(::CFURLCreateFromFileSystemRepresentation (NULL, |
| 346 | (const UInt8 *)exec_cf_path, |
| 347 | strlen(exec_cf_path), |
| 348 | FALSE)); |
| 349 | } |
| 350 | |
| 351 | CFCReleaser<CFURLRef> dsym_url (::DBGCopyFullDSYMURLForUUID(module_uuid_ref.get(), exec_url.get())); |
| 352 | char path[PATH_MAX]; |
| 353 | |
| 354 | if (dsym_url.get()) |
| 355 | { |
| 356 | if (out_dsym_fspec) |
| 357 | { |
| 358 | if (::CFURLGetFileSystemRepresentation (dsym_url.get(), true, (UInt8*)path, sizeof(path)-1)) |
| 359 | { |
Jason Molenda | 1b09dfe | 2012-10-05 04:57:34 +0000 | [diff] [blame] | 360 | out_dsym_fspec->SetFile(path, path[0] == '~'); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 361 | |
| 362 | if (out_dsym_fspec->GetFileType () == FileSpec::eFileTypeDirectory) |
| 363 | { |
Greg Clayton | 95b765e | 2012-09-12 02:03:59 +0000 | [diff] [blame] | 364 | *out_dsym_fspec = Symbols::FindSymbolFileInBundle (*out_dsym_fspec, uuid, arch); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 365 | if (*out_dsym_fspec) |
| 366 | ++items_found; |
| 367 | } |
| 368 | else |
| 369 | { |
| 370 | ++items_found; |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | |
Greg Clayton | 964deba | 2012-03-15 21:01:31 +0000 | [diff] [blame] | 375 | CFCReleaser<CFDictionaryRef> dict(::DBGCopyDSYMPropertyLists (dsym_url.get())); |
| 376 | CFDictionaryRef uuid_dict = NULL; |
| 377 | if (dict.get()) |
| 378 | { |
| 379 | char uuid_cstr_buf[64]; |
| 380 | const char *uuid_cstr = uuid->GetAsCString (uuid_cstr_buf, sizeof(uuid_cstr_buf)); |
| 381 | CFCString uuid_cfstr (uuid_cstr); |
Jason Molenda | 63e5cf6 | 2012-10-02 22:23:42 +0000 | [diff] [blame] | 382 | uuid_dict = static_cast<CFDictionaryRef>(::CFDictionaryGetValue (dict.get(), uuid_cfstr.get())); |
Greg Clayton | 964deba | 2012-03-15 21:01:31 +0000 | [diff] [blame] | 383 | if (uuid_dict) |
| 384 | { |
| 385 | |
| 386 | CFStringRef actual_src_cfpath = static_cast<CFStringRef>(::CFDictionaryGetValue (uuid_dict, CFSTR("DBGSourcePath"))); |
| 387 | if (actual_src_cfpath) |
| 388 | { |
| 389 | CFStringRef build_src_cfpath = static_cast<CFStringRef>(::CFDictionaryGetValue (uuid_dict, CFSTR("DBGBuildSourcePath"))); |
| 390 | if (build_src_cfpath) |
| 391 | { |
| 392 | char actual_src_path[PATH_MAX]; |
| 393 | char build_src_path[PATH_MAX]; |
| 394 | ::CFStringGetFileSystemRepresentation (actual_src_cfpath, actual_src_path, sizeof(actual_src_path)); |
| 395 | ::CFStringGetFileSystemRepresentation (build_src_cfpath, build_src_path, sizeof(build_src_path)); |
Greg Clayton | 4d8c543 | 2012-07-13 01:20:25 +0000 | [diff] [blame] | 396 | if (actual_src_path[0] == '~') |
| 397 | { |
| 398 | FileSpec resolved_source_path(actual_src_path, true); |
| 399 | resolved_source_path.GetPath(actual_src_path, sizeof(actual_src_path)); |
| 400 | } |
Greg Clayton | 964deba | 2012-03-15 21:01:31 +0000 | [diff] [blame] | 401 | module_spec.GetSourceMappingList().Append (ConstString(build_src_path), ConstString(actual_src_path), true); |
| 402 | } |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 407 | if (out_exec_fspec) |
| 408 | { |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 409 | bool success = false; |
Greg Clayton | 964deba | 2012-03-15 21:01:31 +0000 | [diff] [blame] | 410 | if (uuid_dict) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 411 | { |
Greg Clayton | 964deba | 2012-03-15 21:01:31 +0000 | [diff] [blame] | 412 | CFStringRef exec_cf_path = static_cast<CFStringRef>(::CFDictionaryGetValue (uuid_dict, CFSTR("DBGSymbolRichExecutable"))); |
| 413 | if (exec_cf_path && ::CFStringGetFileSystemRepresentation (exec_cf_path, path, sizeof(path))) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 414 | { |
Greg Clayton | 964deba | 2012-03-15 21:01:31 +0000 | [diff] [blame] | 415 | ++items_found; |
| 416 | out_exec_fspec->SetFile(path, path[0] == '~'); |
| 417 | if (out_exec_fspec->Exists()) |
| 418 | success = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 419 | } |
| 420 | } |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 421 | |
| 422 | if (!success) |
Greg Clayton | 0fa5124 | 2011-07-19 03:57:15 +0000 | [diff] [blame] | 423 | { |
| 424 | // No dictionary, check near the dSYM bundle for an executable that matches... |
| 425 | if (::CFURLGetFileSystemRepresentation (dsym_url.get(), true, (UInt8*)path, sizeof(path)-1)) |
| 426 | { |
| 427 | char *dsym_extension_pos = ::strstr (path, ".dSYM"); |
| 428 | if (dsym_extension_pos) |
| 429 | { |
| 430 | *dsym_extension_pos = '\0'; |
| 431 | FileSpec file_spec (path, true); |
| 432 | switch (file_spec.GetFileType()) |
| 433 | { |
| 434 | case FileSpec::eFileTypeDirectory: // Bundle directory? |
| 435 | { |
| 436 | CFCBundle bundle (path); |
| 437 | CFCReleaser<CFURLRef> bundle_exe_url (bundle.CopyExecutableURL ()); |
| 438 | if (bundle_exe_url.get()) |
| 439 | { |
| 440 | if (::CFURLGetFileSystemRepresentation (bundle_exe_url.get(), true, (UInt8*)path, sizeof(path)-1)) |
| 441 | { |
| 442 | FileSpec bundle_exe_file_spec (path, true); |
| 443 | |
| 444 | if (FileAtPathContainsArchAndUUID (bundle_exe_file_spec, arch, uuid)) |
| 445 | { |
| 446 | ++items_found; |
| 447 | *out_exec_fspec = bundle_exe_file_spec; |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | break; |
| 453 | |
| 454 | case FileSpec::eFileTypePipe: // Forget pipes |
| 455 | case FileSpec::eFileTypeSocket: // We can't process socket files |
| 456 | case FileSpec::eFileTypeInvalid: // File doesn't exist... |
| 457 | break; |
| 458 | |
| 459 | case FileSpec::eFileTypeUnknown: |
| 460 | case FileSpec::eFileTypeRegular: |
| 461 | case FileSpec::eFileTypeSymbolicLink: |
| 462 | case FileSpec::eFileTypeOther: |
| 463 | if (FileAtPathContainsArchAndUUID (file_spec, arch, uuid)) |
| 464 | { |
| 465 | ++items_found; |
| 466 | *out_exec_fspec = file_spec; |
| 467 | } |
| 468 | break; |
| 469 | } |
| 470 | } |
| 471 | } |
| 472 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | } |
| 476 | } |
| 477 | } |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 478 | #endif // #if !defined (__arm__) |
| 479 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 480 | return items_found; |
| 481 | } |
| 482 | |
| 483 | static bool |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 484 | LocateDSYMInVincinityOfExecutable (const ModuleSpec &module_spec, FileSpec &dsym_fspec) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 485 | { |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 486 | const FileSpec *exec_fspec = module_spec.GetFileSpecPtr(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 487 | if (exec_fspec) |
| 488 | { |
| 489 | char path[PATH_MAX]; |
| 490 | if (exec_fspec->GetPath(path, sizeof(path))) |
| 491 | { |
| 492 | // Make sure the module isn't already just a dSYM file... |
| 493 | if (strcasestr(path, ".dSYM/Contents/Resources/DWARF") == NULL) |
| 494 | { |
| 495 | size_t obj_file_path_length = strlen(path); |
Filipe Cabecinhas | 78c180a | 2012-05-06 17:56:42 +0000 | [diff] [blame] | 496 | strlcat(path, ".dSYM/Contents/Resources/DWARF/", sizeof(path)); |
| 497 | strlcat(path, exec_fspec->GetFilename().AsCString(), sizeof(path)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 498 | |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 499 | dsym_fspec.SetFile(path, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 500 | |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 501 | if (dsym_fspec.Exists() && FileAtPathContainsArchAndUUID (dsym_fspec, module_spec.GetArchitecturePtr(), module_spec.GetUUIDPtr())) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 502 | { |
| 503 | return true; |
| 504 | } |
| 505 | else |
| 506 | { |
| 507 | path[obj_file_path_length] = '\0'; |
| 508 | |
| 509 | char *last_dot = strrchr(path, '.'); |
| 510 | while (last_dot != NULL && last_dot[0]) |
| 511 | { |
| 512 | char *next_slash = strchr(last_dot, '/'); |
| 513 | if (next_slash != NULL) |
| 514 | { |
| 515 | *next_slash = '\0'; |
Filipe Cabecinhas | 78c180a | 2012-05-06 17:56:42 +0000 | [diff] [blame] | 516 | strlcat(path, ".dSYM/Contents/Resources/DWARF/", sizeof(path)); |
| 517 | strlcat(path, exec_fspec->GetFilename().AsCString(), sizeof(path)); |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 518 | dsym_fspec.SetFile(path, false); |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 519 | if (dsym_fspec.Exists() && FileAtPathContainsArchAndUUID (dsym_fspec, module_spec.GetArchitecturePtr(), module_spec.GetUUIDPtr())) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 520 | return true; |
| 521 | else |
| 522 | { |
| 523 | *last_dot = '\0'; |
| 524 | char *prev_slash = strrchr(path, '/'); |
| 525 | if (prev_slash != NULL) |
| 526 | *prev_slash = '\0'; |
| 527 | else |
| 528 | break; |
| 529 | } |
| 530 | } |
| 531 | else |
| 532 | { |
| 533 | break; |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | } |
| 540 | dsym_fspec.Clear(); |
| 541 | return false; |
| 542 | } |
| 543 | |
| 544 | FileSpec |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 545 | Symbols::LocateExecutableObjectFile (const ModuleSpec &module_spec) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 546 | { |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 547 | const FileSpec *exec_fspec = module_spec.GetFileSpecPtr(); |
| 548 | const ArchSpec *arch = module_spec.GetArchitecturePtr(); |
| 549 | const UUID *uuid = module_spec.GetUUIDPtr(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 550 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 551 | "LocateExecutableObjectFile (file = %s, arch = %s, uuid = %p)", |
| 552 | exec_fspec ? exec_fspec->GetFilename().AsCString ("<NULL>") : "<NULL>", |
Greg Clayton | 940b103 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 553 | arch ? arch->GetArchitectureName() : "<NULL>", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 554 | uuid); |
| 555 | |
| 556 | FileSpec objfile_fspec; |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 557 | if (exec_fspec && FileAtPathContainsArchAndUUID (exec_fspec, arch, uuid)) |
| 558 | objfile_fspec = exec_fspec; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 559 | else |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 560 | LocateMacOSXFilesUsingDebugSymbols (module_spec, &objfile_fspec, NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 561 | return objfile_fspec; |
| 562 | } |
| 563 | |
| 564 | FileSpec |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 565 | Symbols::LocateExecutableSymbolFile (const ModuleSpec &module_spec) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 566 | { |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 567 | const FileSpec *exec_fspec = module_spec.GetFileSpecPtr(); |
| 568 | const ArchSpec *arch = module_spec.GetArchitecturePtr(); |
| 569 | const UUID *uuid = module_spec.GetUUIDPtr(); |
| 570 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 571 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 572 | "LocateExecutableSymbolFile (file = %s, arch = %s, uuid = %p)", |
| 573 | exec_fspec ? exec_fspec->GetFilename().AsCString ("<NULL>") : "<NULL>", |
Greg Clayton | 940b103 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 574 | arch ? arch->GetArchitectureName() : "<NULL>", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 575 | uuid); |
| 576 | |
| 577 | FileSpec symbol_fspec; |
| 578 | // First try and find the dSYM in the same directory as the executable or in |
| 579 | // an appropriate parent directory |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 580 | if (LocateDSYMInVincinityOfExecutable (module_spec, symbol_fspec) == false) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 581 | { |
| 582 | // We failed to easily find the dSYM above, so use DebugSymbols |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 583 | LocateMacOSXFilesUsingDebugSymbols (module_spec, NULL, &symbol_fspec); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 584 | } |
| 585 | return symbol_fspec; |
| 586 | } |
Greg Clayton | b924eb6 | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 587 | |
| 588 | |
Greg Clayton | 437b5bc | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 589 | static bool |
| 590 | GetModuleSpecInfoFromUUIDDictionary (CFDictionaryRef uuid_dict, ModuleSpec &module_spec) |
| 591 | { |
| 592 | bool success = false; |
| 593 | if (uuid_dict != NULL && CFGetTypeID (uuid_dict) == CFDictionaryGetTypeID ()) |
| 594 | { |
| 595 | std::string str; |
| 596 | CFStringRef cf_str; |
| 597 | |
| 598 | cf_str = (CFStringRef)CFDictionaryGetValue ((CFDictionaryRef) uuid_dict, CFSTR("DBGSymbolRichExecutable")); |
| 599 | if (cf_str && CFGetTypeID (cf_str) == CFStringGetTypeID ()) |
| 600 | { |
| 601 | if (CFCString::FileSystemRepresentation(cf_str, str)) |
| 602 | module_spec.GetFileSpec().SetFile (str.c_str(), true); |
| 603 | } |
| 604 | |
| 605 | cf_str = (CFStringRef)CFDictionaryGetValue ((CFDictionaryRef) uuid_dict, CFSTR("DBGDSYMPath")); |
| 606 | if (cf_str && CFGetTypeID (cf_str) == CFStringGetTypeID ()) |
| 607 | { |
| 608 | if (CFCString::FileSystemRepresentation(cf_str, str)) |
| 609 | { |
| 610 | module_spec.GetSymbolFileSpec().SetFile (str.c_str(), true); |
| 611 | success = true; |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | cf_str = (CFStringRef)CFDictionaryGetValue ((CFDictionaryRef) uuid_dict, CFSTR("DBGArchitecture")); |
| 616 | if (cf_str && CFGetTypeID (cf_str) == CFStringGetTypeID ()) |
| 617 | { |
| 618 | if (CFCString::FileSystemRepresentation(cf_str, str)) |
| 619 | module_spec.GetArchitecture().SetTriple(str.c_str()); |
| 620 | } |
| 621 | |
| 622 | std::string DBGBuildSourcePath; |
| 623 | std::string DBGSourcePath; |
| 624 | |
| 625 | cf_str = (CFStringRef)CFDictionaryGetValue ((CFDictionaryRef) uuid_dict, CFSTR("DBGBuildSourcePath")); |
| 626 | if (cf_str && CFGetTypeID (cf_str) == CFStringGetTypeID ()) |
| 627 | { |
| 628 | CFCString::FileSystemRepresentation(cf_str, DBGBuildSourcePath); |
| 629 | } |
| 630 | |
| 631 | cf_str = (CFStringRef)CFDictionaryGetValue ((CFDictionaryRef) uuid_dict, CFSTR("DBGSourcePath")); |
| 632 | if (cf_str && CFGetTypeID (cf_str) == CFStringGetTypeID ()) |
| 633 | { |
| 634 | CFCString::FileSystemRepresentation(cf_str, DBGSourcePath); |
| 635 | } |
| 636 | |
| 637 | if (!DBGBuildSourcePath.empty() && !DBGSourcePath.empty()) |
| 638 | { |
| 639 | module_spec.GetSourceMappingList().Append (ConstString(DBGBuildSourcePath.c_str()), ConstString(DBGSourcePath.c_str()), true); |
| 640 | } |
| 641 | } |
| 642 | return success; |
| 643 | } |
Greg Clayton | b924eb6 | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 644 | |
| 645 | |
| 646 | bool |
Jason Molenda | d6d45ce | 2012-10-09 01:17:11 +0000 | [diff] [blame] | 647 | Symbols::DownloadObjectAndSymbolFile (ModuleSpec &module_spec, bool force_lookup) |
Greg Clayton | b924eb6 | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 648 | { |
| 649 | bool success = false; |
| 650 | const UUID *uuid_ptr = module_spec.GetUUIDPtr(); |
Greg Clayton | 437b5bc | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 651 | const FileSpec *file_spec_ptr = module_spec.GetFileSpecPtr(); |
Jason Molenda | d6d45ce | 2012-10-09 01:17:11 +0000 | [diff] [blame] | 652 | |
| 653 | // It's expensive to check for the DBGShellCommands defaults setting, only do it once per |
| 654 | // lldb run and cache the result. |
| 655 | static bool g_have_checked_for_dbgshell_command = false; |
| 656 | static const char *g_dbgshell_command = NULL; |
| 657 | if (g_have_checked_for_dbgshell_command == false) |
| 658 | { |
| 659 | g_have_checked_for_dbgshell_command = true; |
| 660 | CFTypeRef defaults_setting = CFPreferencesCopyAppValue (CFSTR ("DBGShellCommands"), CFSTR ("com.apple.DebugSymbols")); |
| 661 | if (defaults_setting && CFGetTypeID (defaults_setting) == CFStringGetTypeID()) |
| 662 | { |
| 663 | char cstr_buf[PATH_MAX]; |
| 664 | if (CFStringGetCString ((CFStringRef) defaults_setting, cstr_buf, sizeof (cstr_buf), kCFStringEncodingUTF8)) |
| 665 | { |
| 666 | g_dbgshell_command = strdup (cstr_buf); // this malloc'ed memory will never be freed |
| 667 | } |
| 668 | } |
| 669 | if (defaults_setting) |
| 670 | { |
| 671 | CFRelease (defaults_setting); |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | // When g_dbgshell_command is NULL, the user has not enabled the use of an external program |
| 676 | // to find the symbols, don't run it for them. |
| 677 | if (force_lookup == false && g_dbgshell_command == NULL) |
| 678 | { |
| 679 | return false; |
| 680 | } |
| 681 | |
Greg Clayton | 437b5bc | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 682 | if (uuid_ptr || (file_spec_ptr && file_spec_ptr->Exists())) |
Greg Clayton | b924eb6 | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 683 | { |
| 684 | static bool g_located_dsym_for_uuid_exe = false; |
| 685 | static bool g_dsym_for_uuid_exe_exists = false; |
| 686 | static char g_dsym_for_uuid_exe_path[PATH_MAX]; |
| 687 | if (!g_located_dsym_for_uuid_exe) |
| 688 | { |
| 689 | g_located_dsym_for_uuid_exe = true; |
| 690 | const char *dsym_for_uuid_exe_path_cstr = getenv("LLDB_APPLE_DSYMFORUUID_EXECUTABLE"); |
| 691 | FileSpec dsym_for_uuid_exe_spec; |
| 692 | if (dsym_for_uuid_exe_path_cstr) |
| 693 | { |
| 694 | dsym_for_uuid_exe_spec.SetFile(dsym_for_uuid_exe_path_cstr, true); |
| 695 | g_dsym_for_uuid_exe_exists = dsym_for_uuid_exe_spec.Exists(); |
| 696 | } |
| 697 | |
| 698 | if (!g_dsym_for_uuid_exe_exists) |
| 699 | { |
Jason Molenda | f256975 | 2012-10-30 21:26:30 +0000 | [diff] [blame] | 700 | dsym_for_uuid_exe_spec.SetFile("/usr/local/bin/dsymForUUID", false); |
Greg Clayton | b924eb6 | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 701 | g_dsym_for_uuid_exe_exists = dsym_for_uuid_exe_spec.Exists(); |
| 702 | if (!g_dsym_for_uuid_exe_exists) |
| 703 | { |
Jason Molenda | f256975 | 2012-10-30 21:26:30 +0000 | [diff] [blame] | 704 | int bufsize; |
| 705 | if ((bufsize = sysconf(_SC_GETPW_R_SIZE_MAX)) != -1) |
| 706 | { |
| 707 | char buffer[bufsize]; |
| 708 | struct passwd pwd; |
| 709 | struct passwd *tilde_rc = NULL; |
| 710 | // we are a library so we need to use the reentrant version of getpwnam() |
| 711 | if (getpwnam_r ("rc", &pwd, buffer, bufsize, &tilde_rc) == 0 |
| 712 | && tilde_rc |
| 713 | && tilde_rc->pw_dir) |
| 714 | { |
| 715 | std::string dsymforuuid_path(tilde_rc->pw_dir); |
| 716 | dsymforuuid_path += "/bin/dsymForUUID"; |
| 717 | dsym_for_uuid_exe_spec.SetFile(dsymforuuid_path.c_str(), false); |
| 718 | g_dsym_for_uuid_exe_exists = dsym_for_uuid_exe_spec.Exists(); |
| 719 | } |
| 720 | } |
Greg Clayton | b924eb6 | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 721 | } |
| 722 | } |
Jason Molenda | d6d45ce | 2012-10-09 01:17:11 +0000 | [diff] [blame] | 723 | if (!g_dsym_for_uuid_exe_exists && g_dbgshell_command != NULL) |
| 724 | { |
| 725 | dsym_for_uuid_exe_spec.SetFile(g_dbgshell_command, true); |
| 726 | g_dsym_for_uuid_exe_exists = dsym_for_uuid_exe_spec.Exists(); |
| 727 | } |
| 728 | |
Greg Clayton | b924eb6 | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 729 | if (g_dsym_for_uuid_exe_exists) |
| 730 | dsym_for_uuid_exe_spec.GetPath (g_dsym_for_uuid_exe_path, sizeof(g_dsym_for_uuid_exe_path)); |
| 731 | } |
| 732 | if (g_dsym_for_uuid_exe_exists) |
| 733 | { |
Greg Clayton | b924eb6 | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 734 | char uuid_cstr_buffer[64]; |
Greg Clayton | 437b5bc | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 735 | char file_path[PATH_MAX]; |
| 736 | uuid_cstr_buffer[0] = '\0'; |
| 737 | file_path[0] = '\0'; |
| 738 | const char *uuid_cstr = NULL; |
| 739 | |
| 740 | if (uuid_ptr) |
| 741 | uuid_cstr = uuid_ptr->GetAsCString(uuid_cstr_buffer, sizeof(uuid_cstr_buffer)); |
| 742 | |
| 743 | if (file_spec_ptr) |
| 744 | file_spec_ptr->GetPath(file_path, sizeof(file_path)); |
| 745 | |
| 746 | StreamString command; |
| 747 | if (uuid_cstr) |
Jason Molenda | 63e5cf6 | 2012-10-02 22:23:42 +0000 | [diff] [blame] | 748 | command.Printf("%s --ignoreNegativeCache --copyExecutable %s", g_dsym_for_uuid_exe_path, uuid_cstr); |
Greg Clayton | 437b5bc | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 749 | else if (file_path && file_path[0]) |
Jason Molenda | 63e5cf6 | 2012-10-02 22:23:42 +0000 | [diff] [blame] | 750 | command.Printf("%s --ignoreNegativeCache --copyExecutable %s", g_dsym_for_uuid_exe_path, file_path); |
Greg Clayton | 437b5bc | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 751 | |
| 752 | if (!command.GetString().empty()) |
Greg Clayton | b924eb6 | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 753 | { |
Greg Clayton | 437b5bc | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 754 | int exit_status = -1; |
| 755 | int signo = -1; |
| 756 | std::string command_output; |
| 757 | Error error = Host::RunShellCommand (command.GetData(), |
| 758 | NULL, // current working directory |
| 759 | &exit_status, // Exit status |
| 760 | &signo, // Signal int * |
| 761 | &command_output, // Command output |
| 762 | 30, // Large timeout to allow for long dsym download times |
| 763 | NULL); // Don't run in a shell (we don't need shell expansion) |
| 764 | if (error.Success() && exit_status == 0 && !command_output.empty()) |
Greg Clayton | b924eb6 | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 765 | { |
Greg Clayton | 437b5bc | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 766 | CFCData data (CFDataCreateWithBytesNoCopy (NULL, |
| 767 | (const UInt8 *)command_output.data(), |
| 768 | command_output.size(), |
| 769 | kCFAllocatorNull)); |
| 770 | |
| 771 | CFCReleaser<CFDictionaryRef> plist((CFDictionaryRef)::CFPropertyListCreateFromXMLData (NULL, data.get(), kCFPropertyListImmutable, NULL)); |
| 772 | |
| 773 | if (CFGetTypeID (plist.get()) == CFDictionaryGetTypeID ()) |
Greg Clayton | b924eb6 | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 774 | { |
Greg Clayton | 437b5bc | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 775 | if (uuid_cstr) |
Greg Clayton | b924eb6 | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 776 | { |
Greg Clayton | 437b5bc | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 777 | CFCString uuid_cfstr(uuid_cstr); |
| 778 | CFDictionaryRef uuid_dict = (CFDictionaryRef)CFDictionaryGetValue (plist.get(), uuid_cfstr.get()); |
| 779 | success = GetModuleSpecInfoFromUUIDDictionary (uuid_dict, module_spec); |
Greg Clayton | b924eb6 | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 780 | } |
Greg Clayton | 437b5bc | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 781 | else |
Greg Clayton | b924eb6 | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 782 | { |
Greg Clayton | 437b5bc | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 783 | const CFIndex num_values = ::CFDictionaryGetCount(plist.get()); |
| 784 | if (num_values > 0) |
Greg Clayton | b924eb6 | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 785 | { |
Greg Clayton | 437b5bc | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 786 | std::vector<CFStringRef> keys (num_values, NULL); |
| 787 | std::vector<CFDictionaryRef> values (num_values, NULL); |
| 788 | ::CFDictionaryGetKeysAndValues(plist.get(), NULL, (const void **)&values[0]); |
| 789 | if (num_values == 1) |
| 790 | { |
| 791 | return GetModuleSpecInfoFromUUIDDictionary (values[0], module_spec); |
| 792 | } |
| 793 | else |
| 794 | { |
| 795 | for (CFIndex i=0; i<num_values; ++i) |
| 796 | { |
| 797 | ModuleSpec curr_module_spec; |
| 798 | if (GetModuleSpecInfoFromUUIDDictionary (values[i], curr_module_spec)) |
| 799 | { |
Sean Callanan | 40e278c | 2012-12-13 22:07:14 +0000 | [diff] [blame] | 800 | if (module_spec.GetArchitecture().IsCompatibleMatch(curr_module_spec.GetArchitecture())) |
Greg Clayton | 437b5bc | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 801 | { |
| 802 | module_spec = curr_module_spec; |
| 803 | return true; |
| 804 | } |
| 805 | } |
| 806 | } |
| 807 | } |
Greg Clayton | b924eb6 | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 808 | } |
| 809 | } |
| 810 | } |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | } |
| 815 | return success; |
| 816 | } |
| 817 | |