blob: 50161def0dbf04e2e85b6e6ee24e9051ee17350f [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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>
Greg Clayton1674b122010-07-21 22:12:05 +000014#include "llvm/Support/MachO.h"
Chris Lattner24943d22010-06-08 16:52:24 +000015
16// C++ Includes
17// Other libraries and framework includes
18#include <CoreFoundation/CoreFoundation.h>
19
20// Project includes
Chris Lattner24943d22010-06-08 16:52:24 +000021#include "lldb/Core/ArchSpec.h"
22#include "lldb/Core/DataBuffer.h"
23#include "lldb/Core/DataExtractor.h"
24#include "lldb/Core/Timer.h"
25#include "lldb/Core/UUID.h"
Greg Claytoncd548032011-02-01 01:31:41 +000026#include "lldb/Host/Endian.h"
Johnny Chencbf15912012-02-01 01:49:50 +000027#include "lldb/Host/Host.h"
Greg Claytonad400272011-02-01 05:15:02 +000028#include "lldb/Utility/CleanUp.h"
Daniel Dunbara1ebbd22011-10-31 22:50:53 +000029#include "Host/macosx/cfcpp/CFCBundle.h"
Greg Clayton54e7afa2010-07-09 20:39:50 +000030#include "Host/macosx/cfcpp/CFCReleaser.h"
Greg Claytonb72d0f02011-04-12 05:54:46 +000031#include "Host/macosx/cfcpp/CFCString.h"
Chris Lattner5bc7b672010-09-08 23:01:14 +000032#include "mach/machine.h"
Greg Clayton54e7afa2010-07-09 20:39:50 +000033
Greg Clayton0fa51242011-07-19 03:57:15 +000034
Chris Lattner24943d22010-06-08 16:52:24 +000035using namespace lldb;
36using namespace lldb_private;
Greg Clayton1674b122010-07-21 22:12:05 +000037using namespace llvm::MachO;
Chris Lattner24943d22010-06-08 16:52:24 +000038
Greg Clayton3e4238d2011-11-04 03:34:56 +000039#if !defined (__arm__) // No DebugSymbols on the iOS devices
Chris Lattner24943d22010-06-08 16:52:24 +000040extern "C" {
Greg Clayton54e7afa2010-07-09 20:39:50 +000041
Chris Lattner24943d22010-06-08 16:52:24 +000042CFURLRef DBGCopyFullDSYMURLForUUID (CFUUIDRef uuid, CFURLRef exec_url);
43CFDictionaryRef DBGCopyDSYMPropertyLists (CFURLRef dsym_url);
Greg Clayton54e7afa2010-07-09 20:39:50 +000044
45}
Greg Clayton3e4238d2011-11-04 03:34:56 +000046#endif
Chris Lattner24943d22010-06-08 16:52:24 +000047
48static bool
49SkinnyMachOFileContainsArchAndUUID
50(
51 const FileSpec &file_spec,
52 const ArchSpec *arch,
Greg Clayton0467c782011-02-04 18:53:10 +000053 const lldb_private::UUID *uuid, // the UUID we are looking for
Chris Lattner24943d22010-06-08 16:52:24 +000054 off_t file_offset,
55 DataExtractor& data,
56 uint32_t data_offset,
57 const uint32_t magic
58)
59{
Greg Clayton1674b122010-07-21 22:12:05 +000060 assert(magic == HeaderMagic32 || magic == HeaderMagic32Swapped || magic == HeaderMagic64 || magic == HeaderMagic64Swapped);
61 if (magic == HeaderMagic32 || magic == HeaderMagic64)
Greg Claytoncd548032011-02-01 01:31:41 +000062 data.SetByteOrder (lldb::endian::InlHostByteOrder());
63 else if (lldb::endian::InlHostByteOrder() == eByteOrderBig)
Chris Lattner24943d22010-06-08 16:52:24 +000064 data.SetByteOrder (eByteOrderLittle);
65 else
66 data.SetByteOrder (eByteOrderBig);
67
68 uint32_t i;
69 const uint32_t cputype = data.GetU32(&data_offset); // cpu specifier
70 const uint32_t cpusubtype = data.GetU32(&data_offset); // machine specifier
71 data_offset+=4; // Skip mach file type
72 const uint32_t ncmds = data.GetU32(&data_offset); // number of load commands
73 const uint32_t sizeofcmds = data.GetU32(&data_offset); // the size of all the load commands
74 data_offset+=4; // Skip flags
75
76 // Check the architecture if we have a valid arch pointer
77 if (arch)
78 {
Greg Claytoncf015052010-06-11 03:25:34 +000079 ArchSpec file_arch(eArchTypeMachO, cputype, cpusubtype);
Chris Lattner24943d22010-06-08 16:52:24 +000080
81 if (file_arch != *arch)
82 return false;
83 }
84
85 // The file exists, and if a valid arch pointer was passed in we know
86 // if already matches, so we can return if we aren't looking for a specific
87 // UUID
88 if (uuid == NULL)
89 return true;
90
Greg Clayton1674b122010-07-21 22:12:05 +000091 if (magic == HeaderMagic64Swapped || magic == HeaderMagic64)
Chris Lattner24943d22010-06-08 16:52:24 +000092 data_offset += 4; // Skip reserved field for in mach_header_64
93
94 // Make sure we have enough data for all the load commands
Greg Clayton1674b122010-07-21 22:12:05 +000095 if (magic == HeaderMagic64Swapped || magic == HeaderMagic64)
Chris Lattner24943d22010-06-08 16:52:24 +000096 {
97 if (data.GetByteSize() < sizeof(struct mach_header_64) + sizeofcmds)
98 {
99 DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset, sizeof(struct mach_header_64) + sizeofcmds));
100 data.SetData (data_buffer_sp);
101 }
102 }
103 else
104 {
105 if (data.GetByteSize() < sizeof(struct mach_header) + sizeofcmds)
106 {
107 DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset, sizeof(struct mach_header) + sizeofcmds));
108 data.SetData (data_buffer_sp);
109 }
110 }
111
112 for (i=0; i<ncmds; i++)
113 {
114 const uint32_t cmd_offset = data_offset; // Save this data_offset in case parsing of the segment goes awry!
115 uint32_t cmd = data.GetU32(&data_offset);
116 uint32_t cmd_size = data.GetU32(&data_offset);
Greg Clayton1674b122010-07-21 22:12:05 +0000117 if (cmd == LoadCommandUUID)
Chris Lattner24943d22010-06-08 16:52:24 +0000118 {
Greg Clayton0467c782011-02-04 18:53:10 +0000119 lldb_private::UUID file_uuid (data.GetData(&data_offset, 16), 16);
Johnny Chencbf15912012-02-01 01:49:50 +0000120 if (file_uuid == *uuid)
121 return true;
122
123 // Emit some warning messages since the UUIDs do not match!
124 char path_buf[PATH_MAX];
125 path_buf[0] = '\0';
126 const char *path = file_spec.GetPath(path_buf, PATH_MAX) ? path_buf
127 : file_spec.GetFilename().AsCString();
128 Host::SystemLog (Host::eSystemLogWarning,
129 "warning: UUID mismatch detected between binary and:\n\t'%s'\n",
130 path);
131 return false;
Chris Lattner24943d22010-06-08 16:52:24 +0000132 }
133 data_offset = cmd_offset + cmd_size;
134 }
135 return false;
136}
137
138bool
139UniversalMachOFileContainsArchAndUUID
140(
141 const FileSpec &file_spec,
142 const ArchSpec *arch,
Greg Clayton0467c782011-02-04 18:53:10 +0000143 const lldb_private::UUID *uuid,
Chris Lattner24943d22010-06-08 16:52:24 +0000144 off_t file_offset,
145 DataExtractor& data,
146 uint32_t data_offset,
147 const uint32_t magic
148)
149{
Greg Clayton1674b122010-07-21 22:12:05 +0000150 assert(magic == UniversalMagic || magic == UniversalMagicSwapped);
Chris Lattner24943d22010-06-08 16:52:24 +0000151
152 // Universal mach-o files always have their headers encoded as BIG endian
153 data.SetByteOrder(eByteOrderBig);
154
155 uint32_t i;
156 const uint32_t nfat_arch = data.GetU32(&data_offset); // number of structs that follow
157 const uint32_t fat_header_and_arch_size = sizeof(struct fat_header) + nfat_arch * sizeof(struct fat_arch);
158 if (data.GetByteSize() < fat_header_and_arch_size)
159 {
160 DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset, fat_header_and_arch_size));
161 data.SetData (data_buffer_sp);
162 }
163
164 for (i=0; i<nfat_arch; i++)
165 {
166 cpu_type_t arch_cputype = data.GetU32(&data_offset); // cpu specifier (int)
167 cpu_subtype_t arch_cpusubtype = data.GetU32(&data_offset); // machine specifier (int)
168 uint32_t arch_offset = data.GetU32(&data_offset); // file offset to this object file
169 // uint32_t arch_size = data.GetU32(&data_offset); // size of this object file
170 // uint32_t arch_align = data.GetU32(&data_offset); // alignment as a power of 2
171 data_offset += 8; // Skip size and align as we don't need those
172 // Only process this slice if the cpu type/subtype matches
173 if (arch)
174 {
Greg Claytoncf015052010-06-11 03:25:34 +0000175 ArchSpec fat_arch(eArchTypeMachO, arch_cputype, arch_cpusubtype);
Chris Lattner24943d22010-06-08 16:52:24 +0000176 if (fat_arch != *arch)
177 continue;
178 }
179
180 // Create a buffer with only the arch slice date in it
181 DataExtractor arch_data;
182 DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset + arch_offset, 0x1000));
183 arch_data.SetData(data_buffer_sp);
184 uint32_t arch_data_offset = 0;
185 uint32_t arch_magic = arch_data.GetU32(&arch_data_offset);
186
187 switch (arch_magic)
188 {
Greg Clayton1674b122010-07-21 22:12:05 +0000189 case HeaderMagic32:
190 case HeaderMagic32Swapped:
191 case HeaderMagic64:
192 case HeaderMagic64Swapped:
Chris Lattner24943d22010-06-08 16:52:24 +0000193 if (SkinnyMachOFileContainsArchAndUUID (file_spec, arch, uuid, file_offset + arch_offset, arch_data, arch_data_offset, arch_magic))
194 return true;
195 break;
196 }
197 }
198 return false;
199}
200
201static bool
202FileAtPathContainsArchAndUUID
203(
204 const FileSpec &file_spec,
205 const ArchSpec *arch,
Greg Clayton0467c782011-02-04 18:53:10 +0000206 const lldb_private::UUID *uuid
Chris Lattner24943d22010-06-08 16:52:24 +0000207)
208{
209 DataExtractor data;
210 off_t file_offset = 0;
211 DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset, 0x1000));
212
213 if (data_buffer_sp && data_buffer_sp->GetByteSize() > 0)
214 {
215 data.SetData(data_buffer_sp);
216
217 uint32_t data_offset = 0;
218 uint32_t magic = data.GetU32(&data_offset);
219
220 switch (magic)
221 {
222 // 32 bit mach-o file
Greg Clayton1674b122010-07-21 22:12:05 +0000223 case HeaderMagic32:
224 case HeaderMagic32Swapped:
225 case HeaderMagic64:
226 case HeaderMagic64Swapped:
Chris Lattner24943d22010-06-08 16:52:24 +0000227 return SkinnyMachOFileContainsArchAndUUID (file_spec, arch, uuid, file_offset, data, data_offset, magic);
228
229 // fat mach-o file
Greg Clayton1674b122010-07-21 22:12:05 +0000230 case UniversalMagic:
231 case UniversalMagicSwapped:
Chris Lattner24943d22010-06-08 16:52:24 +0000232 return UniversalMachOFileContainsArchAndUUID (file_spec, arch, uuid, file_offset, data, data_offset, magic);
233
234 default:
235 break;
236 }
237 }
238 return false;
239}
240
241static FileSpec
242LocateDSYMMachFileInDSYMBundle
243(
244 const FileSpec& dsym_bundle_fspec,
Greg Clayton0467c782011-02-04 18:53:10 +0000245 const lldb_private::UUID *uuid,
Chris Lattner24943d22010-06-08 16:52:24 +0000246 const ArchSpec *arch)
247{
248 char path[PATH_MAX];
249
250 FileSpec dsym_fspec;
251
252 if (dsym_bundle_fspec.GetPath(path, sizeof(path)))
253 {
254 ::strncat (path, "/Contents/Resources/DWARF", sizeof(path) - strlen(path) - 1);
255
Greg Clayton52fd9842011-02-02 02:24:04 +0000256 lldb_utility::CleanUp <DIR *, int> dirp (opendir(path), NULL, closedir);
Greg Claytonad400272011-02-01 05:15:02 +0000257 if (dirp.is_valid())
Chris Lattner24943d22010-06-08 16:52:24 +0000258 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000259 dsym_fspec.GetDirectory().SetCString(path);
Chris Lattner24943d22010-06-08 16:52:24 +0000260 struct dirent* dp;
Greg Claytonad400272011-02-01 05:15:02 +0000261 while ((dp = readdir(dirp.get())) != NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000262 {
263 // Only search directories
264 if (dp->d_type == DT_DIR || dp->d_type == DT_UNKNOWN)
265 {
266 if (dp->d_namlen == 1 && dp->d_name[0] == '.')
267 continue;
268
269 if (dp->d_namlen == 2 && dp->d_name[0] == '.' && dp->d_name[1] == '.')
270 continue;
271 }
272
273 if (dp->d_type == DT_REG || dp->d_type == DT_UNKNOWN)
274 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000275 dsym_fspec.GetFilename().SetCString(dp->d_name);
Chris Lattner24943d22010-06-08 16:52:24 +0000276 if (FileAtPathContainsArchAndUUID (dsym_fspec, arch, uuid))
277 return dsym_fspec;
278 }
279 }
280 }
281 }
282 dsym_fspec.Clear();
283 return dsym_fspec;
284}
285
286static int
287LocateMacOSXFilesUsingDebugSymbols
288(
289 const FileSpec *exec_fspec, // An executable path that may or may not be correct if UUID is specified
290 const ArchSpec* arch, // Limit the search to files with this architecture if non-NULL
Greg Clayton0467c782011-02-04 18:53:10 +0000291 const lldb_private::UUID *uuid, // Match the UUID value if non-NULL,
Chris Lattner24943d22010-06-08 16:52:24 +0000292 FileSpec *out_exec_fspec, // If non-NULL, try and find the executable
293 FileSpec *out_dsym_fspec // If non-NULL try and find the debug symbol file
294)
295{
296 int items_found = 0;
297
298 if (out_exec_fspec)
299 out_exec_fspec->Clear();
300
301 if (out_dsym_fspec)
302 out_dsym_fspec->Clear();
303
Greg Clayton3e4238d2011-11-04 03:34:56 +0000304#if !defined (__arm__) // No DebugSymbols on the iOS devices
305
Chris Lattner24943d22010-06-08 16:52:24 +0000306 if (uuid && uuid->IsValid())
307 {
308 // Try and locate the dSYM file using DebugSymbols first
309 const UInt8 *module_uuid = (const UInt8 *)uuid->GetBytes();
310 if (module_uuid != NULL)
311 {
Greg Clayton0fa51242011-07-19 03:57:15 +0000312 CFCReleaser<CFUUIDRef> module_uuid_ref(::CFUUIDCreateWithBytes (NULL,
Chris Lattner24943d22010-06-08 16:52:24 +0000313 module_uuid[0],
314 module_uuid[1],
315 module_uuid[2],
316 module_uuid[3],
317 module_uuid[4],
318 module_uuid[5],
319 module_uuid[6],
320 module_uuid[7],
321 module_uuid[8],
322 module_uuid[9],
323 module_uuid[10],
324 module_uuid[11],
325 module_uuid[12],
326 module_uuid[13],
327 module_uuid[14],
328 module_uuid[15]));
329
330 if (module_uuid_ref.get())
331 {
332 CFCReleaser<CFURLRef> exec_url;
333
334 if (exec_fspec)
335 {
336 char exec_cf_path[PATH_MAX];
337 if (exec_fspec->GetPath(exec_cf_path, sizeof(exec_cf_path)))
338 exec_url.reset(::CFURLCreateFromFileSystemRepresentation (NULL,
339 (const UInt8 *)exec_cf_path,
340 strlen(exec_cf_path),
341 FALSE));
342 }
343
344 CFCReleaser<CFURLRef> dsym_url (::DBGCopyFullDSYMURLForUUID(module_uuid_ref.get(), exec_url.get()));
345 char path[PATH_MAX];
346
347 if (dsym_url.get())
348 {
349 if (out_dsym_fspec)
350 {
351 if (::CFURLGetFileSystemRepresentation (dsym_url.get(), true, (UInt8*)path, sizeof(path)-1))
352 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000353 out_dsym_fspec->SetFile(path, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000354
355 if (out_dsym_fspec->GetFileType () == FileSpec::eFileTypeDirectory)
356 {
357 *out_dsym_fspec = LocateDSYMMachFileInDSYMBundle (*out_dsym_fspec, uuid, arch);
358 if (*out_dsym_fspec)
359 ++items_found;
360 }
361 else
362 {
363 ++items_found;
364 }
365 }
366 }
367
368 if (out_exec_fspec)
369 {
Greg Clayton9ce95382012-02-13 23:10:39 +0000370 CFCReleaser<CFDictionaryRef> dict(::DBGCopyDSYMPropertyLists (dsym_url.get()));
371 bool success = false;
Chris Lattner24943d22010-06-08 16:52:24 +0000372 if (dict.get())
373 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000374 char uuid_cstr_buf[64];
375 const char *uuid_cstr = uuid->GetAsCString (uuid_cstr_buf, sizeof(uuid_cstr_buf));
376 CFCString uuid_cfstr (uuid_cstr);
377 CFDictionaryRef uuid_dict = static_cast<CFDictionaryRef>(::CFDictionaryGetValue (dict.get(), uuid_cfstr.get()));
378 if (uuid_dict)
Chris Lattner24943d22010-06-08 16:52:24 +0000379 {
Greg Claytonb72d0f02011-04-12 05:54:46 +0000380 CFStringRef exec_cf_path = static_cast<CFStringRef>(::CFDictionaryGetValue (uuid_dict, CFSTR("DBGSymbolRichExecutable")));
381 if (exec_cf_path && ::CFStringGetFileSystemRepresentation (exec_cf_path, path, sizeof(path)))
382 {
383 ++items_found;
384 out_exec_fspec->SetFile(path, path[0] == '~');
Greg Clayton9ce95382012-02-13 23:10:39 +0000385 if (out_exec_fspec->Exists())
386 success = true;
Greg Claytonb72d0f02011-04-12 05:54:46 +0000387 }
Chris Lattner24943d22010-06-08 16:52:24 +0000388 }
389 }
Greg Clayton9ce95382012-02-13 23:10:39 +0000390
391 if (!success)
Greg Clayton0fa51242011-07-19 03:57:15 +0000392 {
393 // No dictionary, check near the dSYM bundle for an executable that matches...
394 if (::CFURLGetFileSystemRepresentation (dsym_url.get(), true, (UInt8*)path, sizeof(path)-1))
395 {
396 char *dsym_extension_pos = ::strstr (path, ".dSYM");
397 if (dsym_extension_pos)
398 {
399 *dsym_extension_pos = '\0';
400 FileSpec file_spec (path, true);
401 switch (file_spec.GetFileType())
402 {
403 case FileSpec::eFileTypeDirectory: // Bundle directory?
404 {
405 CFCBundle bundle (path);
406 CFCReleaser<CFURLRef> bundle_exe_url (bundle.CopyExecutableURL ());
407 if (bundle_exe_url.get())
408 {
409 if (::CFURLGetFileSystemRepresentation (bundle_exe_url.get(), true, (UInt8*)path, sizeof(path)-1))
410 {
411 FileSpec bundle_exe_file_spec (path, true);
412
413 if (FileAtPathContainsArchAndUUID (bundle_exe_file_spec, arch, uuid))
414 {
415 ++items_found;
416 *out_exec_fspec = bundle_exe_file_spec;
417 }
418 }
419 }
420 }
421 break;
422
423 case FileSpec::eFileTypePipe: // Forget pipes
424 case FileSpec::eFileTypeSocket: // We can't process socket files
425 case FileSpec::eFileTypeInvalid: // File doesn't exist...
426 break;
427
428 case FileSpec::eFileTypeUnknown:
429 case FileSpec::eFileTypeRegular:
430 case FileSpec::eFileTypeSymbolicLink:
431 case FileSpec::eFileTypeOther:
432 if (FileAtPathContainsArchAndUUID (file_spec, arch, uuid))
433 {
434 ++items_found;
435 *out_exec_fspec = file_spec;
436 }
437 break;
438 }
439 }
440 }
441 }
Chris Lattner24943d22010-06-08 16:52:24 +0000442 }
443 }
444 }
445 }
446 }
Greg Clayton3e4238d2011-11-04 03:34:56 +0000447#endif // #if !defined (__arm__)
448
Chris Lattner24943d22010-06-08 16:52:24 +0000449 return items_found;
450}
451
452static bool
Greg Clayton0467c782011-02-04 18:53:10 +0000453LocateDSYMInVincinityOfExecutable (const FileSpec *exec_fspec, const ArchSpec* arch, const lldb_private::UUID *uuid, FileSpec &dsym_fspec)
Chris Lattner24943d22010-06-08 16:52:24 +0000454{
455 if (exec_fspec)
456 {
457 char path[PATH_MAX];
458 if (exec_fspec->GetPath(path, sizeof(path)))
459 {
460 // Make sure the module isn't already just a dSYM file...
461 if (strcasestr(path, ".dSYM/Contents/Resources/DWARF") == NULL)
462 {
463 size_t obj_file_path_length = strlen(path);
464 strncat(path, ".dSYM/Contents/Resources/DWARF/", sizeof(path));
465 strncat(path, exec_fspec->GetFilename().AsCString(), sizeof(path));
466
Greg Clayton537a7a82010-10-20 20:54:39 +0000467 dsym_fspec.SetFile(path, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000468
Greg Claytondb2dc2b2012-01-12 05:25:17 +0000469 if (dsym_fspec.Exists() && FileAtPathContainsArchAndUUID (dsym_fspec, arch, uuid))
Chris Lattner24943d22010-06-08 16:52:24 +0000470 {
471 return true;
472 }
473 else
474 {
475 path[obj_file_path_length] = '\0';
476
477 char *last_dot = strrchr(path, '.');
478 while (last_dot != NULL && last_dot[0])
479 {
480 char *next_slash = strchr(last_dot, '/');
481 if (next_slash != NULL)
482 {
483 *next_slash = '\0';
484 strncat(path, ".dSYM/Contents/Resources/DWARF/", sizeof(path));
485 strncat(path, exec_fspec->GetFilename().AsCString(), sizeof(path));
Greg Clayton537a7a82010-10-20 20:54:39 +0000486 dsym_fspec.SetFile(path, false);
Greg Claytondb2dc2b2012-01-12 05:25:17 +0000487 if (dsym_fspec.Exists() && FileAtPathContainsArchAndUUID (dsym_fspec, arch, uuid))
Chris Lattner24943d22010-06-08 16:52:24 +0000488 return true;
489 else
490 {
491 *last_dot = '\0';
492 char *prev_slash = strrchr(path, '/');
493 if (prev_slash != NULL)
494 *prev_slash = '\0';
495 else
496 break;
497 }
498 }
499 else
500 {
501 break;
502 }
503 }
504 }
505 }
506 }
507 }
508 dsym_fspec.Clear();
509 return false;
510}
511
512FileSpec
Greg Clayton0467c782011-02-04 18:53:10 +0000513Symbols::LocateExecutableObjectFile (const FileSpec *exec_fspec, const ArchSpec* arch, const lldb_private::UUID *uuid)
Chris Lattner24943d22010-06-08 16:52:24 +0000514{
515 Timer scoped_timer (__PRETTY_FUNCTION__,
516 "LocateExecutableObjectFile (file = %s, arch = %s, uuid = %p)",
517 exec_fspec ? exec_fspec->GetFilename().AsCString ("<NULL>") : "<NULL>",
Greg Clayton940b1032011-02-23 00:35:02 +0000518 arch ? arch->GetArchitectureName() : "<NULL>",
Chris Lattner24943d22010-06-08 16:52:24 +0000519 uuid);
520
521 FileSpec objfile_fspec;
522 if (exec_fspec && FileAtPathContainsArchAndUUID (*exec_fspec, arch, uuid))
523 objfile_fspec = *exec_fspec;
524 else
525 LocateMacOSXFilesUsingDebugSymbols (exec_fspec, arch, uuid, &objfile_fspec, NULL);
526 return objfile_fspec;
527}
528
529FileSpec
Greg Clayton0467c782011-02-04 18:53:10 +0000530Symbols::LocateExecutableSymbolFile (const FileSpec *exec_fspec, const ArchSpec* arch, const lldb_private::UUID *uuid)
Chris Lattner24943d22010-06-08 16:52:24 +0000531{
532 Timer scoped_timer (__PRETTY_FUNCTION__,
533 "LocateExecutableSymbolFile (file = %s, arch = %s, uuid = %p)",
534 exec_fspec ? exec_fspec->GetFilename().AsCString ("<NULL>") : "<NULL>",
Greg Clayton940b1032011-02-23 00:35:02 +0000535 arch ? arch->GetArchitectureName() : "<NULL>",
Chris Lattner24943d22010-06-08 16:52:24 +0000536 uuid);
537
538 FileSpec symbol_fspec;
539 // First try and find the dSYM in the same directory as the executable or in
540 // an appropriate parent directory
541 if (LocateDSYMInVincinityOfExecutable (exec_fspec, arch, uuid, symbol_fspec) == false)
542 {
543 // We failed to easily find the dSYM above, so use DebugSymbols
544 LocateMacOSXFilesUsingDebugSymbols (exec_fspec, arch, uuid, NULL, &symbol_fspec);
545 }
546 return symbol_fspec;
547}