2010-06-09 00:52:24 +08:00
|
|
|
//===-- Symbols.cpp ---------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Host/Symbols.h"
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
#include <dirent.h>
|
2010-07-22 06:12:05 +08:00
|
|
|
#include "llvm/Support/MachO.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
|
|
|
|
|
|
|
// Project includes
|
|
|
|
#include "lldb/Core/ArchSpec.h"
|
|
|
|
#include "lldb/Core/DataBuffer.h"
|
|
|
|
#include "lldb/Core/DataExtractor.h"
|
2012-02-26 13:51:37 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-30 05:13:06 +08:00
|
|
|
#include "lldb/Core/ModuleSpec.h"
|
2012-08-22 08:18:43 +08:00
|
|
|
#include "lldb/Core/StreamString.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Timer.h"
|
|
|
|
#include "lldb/Core/UUID.h"
|
2011-02-01 09:31:41 +08:00
|
|
|
#include "lldb/Host/Endian.h"
|
2012-02-01 09:49:50 +08:00
|
|
|
#include "lldb/Host/Host.h"
|
2011-02-01 13:15:02 +08:00
|
|
|
#include "lldb/Utility/CleanUp.h"
|
2011-11-01 06:50:53 +08:00
|
|
|
#include "Host/macosx/cfcpp/CFCBundle.h"
|
2012-09-27 11:13:55 +08:00
|
|
|
#include "Host/macosx/cfcpp/CFCData.h"
|
2010-07-10 04:39:50 +08:00
|
|
|
#include "Host/macosx/cfcpp/CFCReleaser.h"
|
2011-04-12 13:54:46 +08:00
|
|
|
#include "Host/macosx/cfcpp/CFCString.h"
|
2010-09-09 07:01:14 +08:00
|
|
|
#include "mach/machine.h"
|
2010-07-10 04:39:50 +08:00
|
|
|
|
2011-07-19 11:57:15 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
2010-07-22 06:12:05 +08:00
|
|
|
using namespace llvm::MachO;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-11-04 11:34:56 +08:00
|
|
|
#if !defined (__arm__) // No DebugSymbols on the iOS devices
|
2010-06-09 00:52:24 +08:00
|
|
|
extern "C" {
|
2010-07-10 04:39:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
CFURLRef DBGCopyFullDSYMURLForUUID (CFUUIDRef uuid, CFURLRef exec_url);
|
|
|
|
CFDictionaryRef DBGCopyDSYMPropertyLists (CFURLRef dsym_url);
|
2010-07-10 04:39:50 +08:00
|
|
|
|
|
|
|
}
|
2011-11-04 11:34:56 +08:00
|
|
|
#endif
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
static bool
|
|
|
|
SkinnyMachOFileContainsArchAndUUID
|
|
|
|
(
|
|
|
|
const FileSpec &file_spec,
|
|
|
|
const ArchSpec *arch,
|
2011-02-05 02:53:10 +08:00
|
|
|
const lldb_private::UUID *uuid, // the UUID we are looking for
|
2010-06-09 00:52:24 +08:00
|
|
|
off_t file_offset,
|
|
|
|
DataExtractor& data,
|
|
|
|
uint32_t data_offset,
|
|
|
|
const uint32_t magic
|
|
|
|
)
|
|
|
|
{
|
2010-07-22 06:12:05 +08:00
|
|
|
assert(magic == HeaderMagic32 || magic == HeaderMagic32Swapped || magic == HeaderMagic64 || magic == HeaderMagic64Swapped);
|
|
|
|
if (magic == HeaderMagic32 || magic == HeaderMagic64)
|
2011-02-01 09:31:41 +08:00
|
|
|
data.SetByteOrder (lldb::endian::InlHostByteOrder());
|
|
|
|
else if (lldb::endian::InlHostByteOrder() == eByteOrderBig)
|
2010-06-09 00:52:24 +08:00
|
|
|
data.SetByteOrder (eByteOrderLittle);
|
|
|
|
else
|
|
|
|
data.SetByteOrder (eByteOrderBig);
|
|
|
|
|
|
|
|
uint32_t i;
|
|
|
|
const uint32_t cputype = data.GetU32(&data_offset); // cpu specifier
|
|
|
|
const uint32_t cpusubtype = data.GetU32(&data_offset); // machine specifier
|
|
|
|
data_offset+=4; // Skip mach file type
|
|
|
|
const uint32_t ncmds = data.GetU32(&data_offset); // number of load commands
|
|
|
|
const uint32_t sizeofcmds = data.GetU32(&data_offset); // the size of all the load commands
|
|
|
|
data_offset+=4; // Skip flags
|
|
|
|
|
|
|
|
// Check the architecture if we have a valid arch pointer
|
|
|
|
if (arch)
|
|
|
|
{
|
2010-06-11 11:25:34 +08:00
|
|
|
ArchSpec file_arch(eArchTypeMachO, cputype, cpusubtype);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (file_arch != *arch)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The file exists, and if a valid arch pointer was passed in we know
|
|
|
|
// if already matches, so we can return if we aren't looking for a specific
|
|
|
|
// UUID
|
|
|
|
if (uuid == NULL)
|
|
|
|
return true;
|
|
|
|
|
2010-07-22 06:12:05 +08:00
|
|
|
if (magic == HeaderMagic64Swapped || magic == HeaderMagic64)
|
2010-06-09 00:52:24 +08:00
|
|
|
data_offset += 4; // Skip reserved field for in mach_header_64
|
|
|
|
|
|
|
|
// Make sure we have enough data for all the load commands
|
2010-07-22 06:12:05 +08:00
|
|
|
if (magic == HeaderMagic64Swapped || magic == HeaderMagic64)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (data.GetByteSize() < sizeof(struct mach_header_64) + sizeofcmds)
|
|
|
|
{
|
|
|
|
DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset, sizeof(struct mach_header_64) + sizeofcmds));
|
|
|
|
data.SetData (data_buffer_sp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (data.GetByteSize() < sizeof(struct mach_header) + sizeofcmds)
|
|
|
|
{
|
|
|
|
DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset, sizeof(struct mach_header) + sizeofcmds));
|
|
|
|
data.SetData (data_buffer_sp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<ncmds; i++)
|
|
|
|
{
|
|
|
|
const uint32_t cmd_offset = data_offset; // Save this data_offset in case parsing of the segment goes awry!
|
|
|
|
uint32_t cmd = data.GetU32(&data_offset);
|
|
|
|
uint32_t cmd_size = data.GetU32(&data_offset);
|
2010-07-22 06:12:05 +08:00
|
|
|
if (cmd == LoadCommandUUID)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-02-05 02:53:10 +08:00
|
|
|
lldb_private::UUID file_uuid (data.GetData(&data_offset, 16), 16);
|
2012-02-01 09:49:50 +08:00
|
|
|
if (file_uuid == *uuid)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Emit some warning messages since the UUIDs do not match!
|
|
|
|
char path_buf[PATH_MAX];
|
|
|
|
path_buf[0] = '\0';
|
|
|
|
const char *path = file_spec.GetPath(path_buf, PATH_MAX) ? path_buf
|
|
|
|
: file_spec.GetFilename().AsCString();
|
2012-08-22 08:18:43 +08:00
|
|
|
StreamString ss_m_uuid, ss_o_uuid;
|
|
|
|
uuid->Dump(&ss_m_uuid);
|
|
|
|
file_uuid.Dump(&ss_o_uuid);
|
2012-02-01 09:49:50 +08:00
|
|
|
Host::SystemLog (Host::eSystemLogWarning,
|
2012-08-22 08:18:43 +08:00
|
|
|
"warning: UUID mismatch detected between binary (%s) and:\n\t'%s' (%s)\n",
|
|
|
|
ss_m_uuid.GetData(), path, ss_o_uuid.GetData());
|
2012-02-01 09:49:50 +08:00
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
data_offset = cmd_offset + cmd_size;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
UniversalMachOFileContainsArchAndUUID
|
|
|
|
(
|
|
|
|
const FileSpec &file_spec,
|
|
|
|
const ArchSpec *arch,
|
2011-02-05 02:53:10 +08:00
|
|
|
const lldb_private::UUID *uuid,
|
2010-06-09 00:52:24 +08:00
|
|
|
off_t file_offset,
|
|
|
|
DataExtractor& data,
|
|
|
|
uint32_t data_offset,
|
|
|
|
const uint32_t magic
|
|
|
|
)
|
|
|
|
{
|
2010-07-22 06:12:05 +08:00
|
|
|
assert(magic == UniversalMagic || magic == UniversalMagicSwapped);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// Universal mach-o files always have their headers encoded as BIG endian
|
|
|
|
data.SetByteOrder(eByteOrderBig);
|
|
|
|
|
|
|
|
uint32_t i;
|
|
|
|
const uint32_t nfat_arch = data.GetU32(&data_offset); // number of structs that follow
|
|
|
|
const uint32_t fat_header_and_arch_size = sizeof(struct fat_header) + nfat_arch * sizeof(struct fat_arch);
|
|
|
|
if (data.GetByteSize() < fat_header_and_arch_size)
|
|
|
|
{
|
|
|
|
DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset, fat_header_and_arch_size));
|
|
|
|
data.SetData (data_buffer_sp);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<nfat_arch; i++)
|
|
|
|
{
|
|
|
|
cpu_type_t arch_cputype = data.GetU32(&data_offset); // cpu specifier (int)
|
|
|
|
cpu_subtype_t arch_cpusubtype = data.GetU32(&data_offset); // machine specifier (int)
|
|
|
|
uint32_t arch_offset = data.GetU32(&data_offset); // file offset to this object file
|
|
|
|
// uint32_t arch_size = data.GetU32(&data_offset); // size of this object file
|
|
|
|
// uint32_t arch_align = data.GetU32(&data_offset); // alignment as a power of 2
|
|
|
|
data_offset += 8; // Skip size and align as we don't need those
|
|
|
|
// Only process this slice if the cpu type/subtype matches
|
|
|
|
if (arch)
|
|
|
|
{
|
2010-06-11 11:25:34 +08:00
|
|
|
ArchSpec fat_arch(eArchTypeMachO, arch_cputype, arch_cpusubtype);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (fat_arch != *arch)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a buffer with only the arch slice date in it
|
|
|
|
DataExtractor arch_data;
|
|
|
|
DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset + arch_offset, 0x1000));
|
|
|
|
arch_data.SetData(data_buffer_sp);
|
|
|
|
uint32_t arch_data_offset = 0;
|
|
|
|
uint32_t arch_magic = arch_data.GetU32(&arch_data_offset);
|
|
|
|
|
|
|
|
switch (arch_magic)
|
|
|
|
{
|
2010-07-22 06:12:05 +08:00
|
|
|
case HeaderMagic32:
|
|
|
|
case HeaderMagic32Swapped:
|
|
|
|
case HeaderMagic64:
|
|
|
|
case HeaderMagic64Swapped:
|
2010-06-09 00:52:24 +08:00
|
|
|
if (SkinnyMachOFileContainsArchAndUUID (file_spec, arch, uuid, file_offset + arch_offset, arch_data, arch_data_offset, arch_magic))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
FileAtPathContainsArchAndUUID
|
|
|
|
(
|
|
|
|
const FileSpec &file_spec,
|
|
|
|
const ArchSpec *arch,
|
2011-02-05 02:53:10 +08:00
|
|
|
const lldb_private::UUID *uuid
|
2010-06-09 00:52:24 +08:00
|
|
|
)
|
|
|
|
{
|
|
|
|
DataExtractor data;
|
|
|
|
off_t file_offset = 0;
|
|
|
|
DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset, 0x1000));
|
|
|
|
|
|
|
|
if (data_buffer_sp && data_buffer_sp->GetByteSize() > 0)
|
|
|
|
{
|
|
|
|
data.SetData(data_buffer_sp);
|
|
|
|
|
|
|
|
uint32_t data_offset = 0;
|
|
|
|
uint32_t magic = data.GetU32(&data_offset);
|
|
|
|
|
|
|
|
switch (magic)
|
|
|
|
{
|
|
|
|
// 32 bit mach-o file
|
2010-07-22 06:12:05 +08:00
|
|
|
case HeaderMagic32:
|
|
|
|
case HeaderMagic32Swapped:
|
|
|
|
case HeaderMagic64:
|
|
|
|
case HeaderMagic64Swapped:
|
2010-06-09 00:52:24 +08:00
|
|
|
return SkinnyMachOFileContainsArchAndUUID (file_spec, arch, uuid, file_offset, data, data_offset, magic);
|
|
|
|
|
|
|
|
// fat mach-o file
|
2010-07-22 06:12:05 +08:00
|
|
|
case UniversalMagic:
|
|
|
|
case UniversalMagicSwapped:
|
2010-06-09 00:52:24 +08:00
|
|
|
return UniversalMachOFileContainsArchAndUUID (file_spec, arch, uuid, file_offset, data, data_offset, magic);
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-12 10:03:59 +08:00
|
|
|
FileSpec
|
|
|
|
Symbols::FindSymbolFileInBundle (const FileSpec& dsym_bundle_fspec,
|
|
|
|
const lldb_private::UUID *uuid,
|
|
|
|
const ArchSpec *arch)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
char path[PATH_MAX];
|
|
|
|
|
|
|
|
FileSpec dsym_fspec;
|
|
|
|
|
|
|
|
if (dsym_bundle_fspec.GetPath(path, sizeof(path)))
|
|
|
|
{
|
|
|
|
::strncat (path, "/Contents/Resources/DWARF", sizeof(path) - strlen(path) - 1);
|
|
|
|
|
Modified the PluginManager to be ready for loading plug-ins from a system
LLDB plugin directory and a user LLDB plugin directory. We currently still
need to work out at what layer the plug-ins will be, but at least we are
prepared for plug-ins. Plug-ins will attempt to be loaded from the
"/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Plugins"
folder, and from the "~/Library/Application Support/LLDB/Plugins" folder on
MacOSX. Each plugin will be scanned for:
extern "C" bool LLDBPluginInitialize(void);
extern "C" void LLDBPluginTerminate(void);
If at least LLDBPluginInitialize is found, the plug-in will be loaded. The
LLDBPluginInitialize function returns a bool that indicates if the plug-in
should stay loaded or not (plug-ins might check the current OS, current
hardware, or anything else and determine they don't want to run on the current
host). The plug-in is uniqued by path and added to a static loaded plug-in
map. The plug-in scanning happens during "lldb_private::Initialize()" which
calls to the PluginManager::Initialize() function. Likewise with termination
lldb_private::Terminate() calls PluginManager::Terminate(). The paths for the
plug-in directories is fetched through new Host calls:
bool Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec);
bool Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec);
This way linux and other systems can define their own appropriate locations
for plug-ins to be loaded.
To allow dynamic shared library loading, the Host layer has also been modified
to include shared library open, close and get symbol:
static void *
Host::DynamicLibraryOpen (const FileSpec &file_spec,
Error &error);
static Error
Host::DynamicLibraryClose (void *dynamic_library_handle);
static void *
Host::DynamicLibraryGetSymbol (void *dynamic_library_handle,
const char *symbol_name,
Error &error);
lldb_private::FileSpec also has been modified to support directory enumeration
in an attempt to abstract the directory enumeration into one spot in the code.
The directory enumertion function is static and takes a callback:
typedef enum EnumerateDirectoryResult
{
eEnumerateDirectoryResultNext, // Enumerate next entry in the current directory
eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a directory or symlink, or next if not
eEnumerateDirectoryResultExit, // Exit from the current directory at the current level.
eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
};
typedef FileSpec::EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton,
FileSpec::FileType file_type,
const FileSpec &spec);
static FileSpec::EnumerateDirectoryResult
FileSpec::EnumerateDirectory (const char *dir_path,
bool find_directories,
bool find_files,
bool find_other,
EnumerateDirectoryCallbackType callback,
void *callback_baton);
This allow clients to specify the directory to search, and specifies if only
files, directories or other (pipe, symlink, fifo, etc) files will cause the
callback to be called. The callback also gets to return with the action that
should be performed after this directory entry. eEnumerateDirectoryResultNext
specifies to continue enumerating through a directory with the next entry.
eEnumerateDirectoryResultEnter specifies to recurse down into a directory
entry, or if the file is not a directory or symlink/alias to a directory, then
just iterate to the next entry. eEnumerateDirectoryResultExit specifies to
exit the current directory and skip any entries that might be remaining, yet
continue enumerating to the next entry in the parent directory. And finally
eEnumerateDirectoryResultQuit means to abort all directory enumerations at
all levels.
Modified the Declaration class to not include column information currently
since we don't have any compilers that currently support column based
declaration information. Columns support can be re-enabled with the
additions of a #define.
Added the ability to find an EmulateInstruction plug-in given a target triple
and optional plug-in name in the plug-in manager.
Fixed a few cases where opendir/readdir was being used, but yet not closedir
was being used. Soon these will be deprecated in favor of the new directory
enumeration call that was added to the FileSpec class.
llvm-svn: 124716
2011-02-02 10:24:04 +08:00
|
|
|
lldb_utility::CleanUp <DIR *, int> dirp (opendir(path), NULL, closedir);
|
2011-02-01 13:15:02 +08:00
|
|
|
if (dirp.is_valid())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-21 04:54:39 +08:00
|
|
|
dsym_fspec.GetDirectory().SetCString(path);
|
2010-06-09 00:52:24 +08:00
|
|
|
struct dirent* dp;
|
2011-02-01 13:15:02 +08:00
|
|
|
while ((dp = readdir(dirp.get())) != NULL)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
// Only search directories
|
|
|
|
if (dp->d_type == DT_DIR || dp->d_type == DT_UNKNOWN)
|
|
|
|
{
|
|
|
|
if (dp->d_namlen == 1 && dp->d_name[0] == '.')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (dp->d_namlen == 2 && dp->d_name[0] == '.' && dp->d_name[1] == '.')
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dp->d_type == DT_REG || dp->d_type == DT_UNKNOWN)
|
|
|
|
{
|
2010-10-21 04:54:39 +08:00
|
|
|
dsym_fspec.GetFilename().SetCString(dp->d_name);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (FileAtPathContainsArchAndUUID (dsym_fspec, arch, uuid))
|
|
|
|
return dsym_fspec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dsym_fspec.Clear();
|
|
|
|
return dsym_fspec;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
LocateMacOSXFilesUsingDebugSymbols
|
|
|
|
(
|
2012-02-26 13:51:37 +08:00
|
|
|
const ModuleSpec &module_spec,
|
2010-06-09 00:52:24 +08:00
|
|
|
FileSpec *out_exec_fspec, // If non-NULL, try and find the executable
|
|
|
|
FileSpec *out_dsym_fspec // If non-NULL try and find the debug symbol file
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int items_found = 0;
|
|
|
|
|
|
|
|
if (out_exec_fspec)
|
|
|
|
out_exec_fspec->Clear();
|
|
|
|
|
|
|
|
if (out_dsym_fspec)
|
|
|
|
out_dsym_fspec->Clear();
|
|
|
|
|
2011-11-04 11:34:56 +08:00
|
|
|
#if !defined (__arm__) // No DebugSymbols on the iOS devices
|
|
|
|
|
2012-02-26 13:51:37 +08:00
|
|
|
const UUID *uuid = module_spec.GetUUIDPtr();
|
|
|
|
const ArchSpec *arch = module_spec.GetArchitecturePtr();
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (uuid && uuid->IsValid())
|
|
|
|
{
|
|
|
|
// Try and locate the dSYM file using DebugSymbols first
|
|
|
|
const UInt8 *module_uuid = (const UInt8 *)uuid->GetBytes();
|
|
|
|
if (module_uuid != NULL)
|
|
|
|
{
|
2011-07-19 11:57:15 +08:00
|
|
|
CFCReleaser<CFUUIDRef> module_uuid_ref(::CFUUIDCreateWithBytes (NULL,
|
2010-06-09 00:52:24 +08:00
|
|
|
module_uuid[0],
|
|
|
|
module_uuid[1],
|
|
|
|
module_uuid[2],
|
|
|
|
module_uuid[3],
|
|
|
|
module_uuid[4],
|
|
|
|
module_uuid[5],
|
|
|
|
module_uuid[6],
|
|
|
|
module_uuid[7],
|
|
|
|
module_uuid[8],
|
|
|
|
module_uuid[9],
|
|
|
|
module_uuid[10],
|
|
|
|
module_uuid[11],
|
|
|
|
module_uuid[12],
|
|
|
|
module_uuid[13],
|
|
|
|
module_uuid[14],
|
|
|
|
module_uuid[15]));
|
|
|
|
|
|
|
|
if (module_uuid_ref.get())
|
|
|
|
{
|
|
|
|
CFCReleaser<CFURLRef> exec_url;
|
2012-02-26 13:51:37 +08:00
|
|
|
const FileSpec *exec_fspec = module_spec.GetFileSpecPtr();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (exec_fspec)
|
|
|
|
{
|
|
|
|
char exec_cf_path[PATH_MAX];
|
|
|
|
if (exec_fspec->GetPath(exec_cf_path, sizeof(exec_cf_path)))
|
|
|
|
exec_url.reset(::CFURLCreateFromFileSystemRepresentation (NULL,
|
|
|
|
(const UInt8 *)exec_cf_path,
|
|
|
|
strlen(exec_cf_path),
|
|
|
|
FALSE));
|
|
|
|
}
|
|
|
|
|
|
|
|
CFCReleaser<CFURLRef> dsym_url (::DBGCopyFullDSYMURLForUUID(module_uuid_ref.get(), exec_url.get()));
|
|
|
|
char path[PATH_MAX];
|
|
|
|
|
|
|
|
if (dsym_url.get())
|
|
|
|
{
|
|
|
|
if (out_dsym_fspec)
|
|
|
|
{
|
|
|
|
if (::CFURLGetFileSystemRepresentation (dsym_url.get(), true, (UInt8*)path, sizeof(path)-1))
|
|
|
|
{
|
2010-10-21 04:54:39 +08:00
|
|
|
out_dsym_fspec->SetFile(path, false);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (out_dsym_fspec->GetFileType () == FileSpec::eFileTypeDirectory)
|
|
|
|
{
|
2012-09-12 10:03:59 +08:00
|
|
|
*out_dsym_fspec = Symbols::FindSymbolFileInBundle (*out_dsym_fspec, uuid, arch);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (*out_dsym_fspec)
|
|
|
|
++items_found;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++items_found;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-16 05:01:31 +08:00
|
|
|
CFCReleaser<CFDictionaryRef> dict(::DBGCopyDSYMPropertyLists (dsym_url.get()));
|
|
|
|
CFDictionaryRef uuid_dict = NULL;
|
|
|
|
if (dict.get())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-03-16 05:01:31 +08:00
|
|
|
char uuid_cstr_buf[64];
|
|
|
|
const char *uuid_cstr = uuid->GetAsCString (uuid_cstr_buf, sizeof(uuid_cstr_buf));
|
|
|
|
CFCString uuid_cfstr (uuid_cstr);
|
|
|
|
CFDictionaryRef uuid_dict = static_cast<CFDictionaryRef>(::CFDictionaryGetValue (dict.get(), uuid_cfstr.get()));
|
|
|
|
if (uuid_dict)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-03-16 05:01:31 +08:00
|
|
|
|
|
|
|
CFStringRef actual_src_cfpath = static_cast<CFStringRef>(::CFDictionaryGetValue (uuid_dict, CFSTR("DBGSourcePath")));
|
|
|
|
if (actual_src_cfpath)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-03-16 05:01:31 +08:00
|
|
|
CFStringRef build_src_cfpath = static_cast<CFStringRef>(::CFDictionaryGetValue (uuid_dict, CFSTR("DBGBuildSourcePath")));
|
|
|
|
if (build_src_cfpath)
|
2011-04-12 13:54:46 +08:00
|
|
|
{
|
2012-03-16 05:01:31 +08:00
|
|
|
char actual_src_path[PATH_MAX];
|
|
|
|
char build_src_path[PATH_MAX];
|
|
|
|
::CFStringGetFileSystemRepresentation (actual_src_cfpath, actual_src_path, sizeof(actual_src_path));
|
|
|
|
::CFStringGetFileSystemRepresentation (build_src_cfpath, build_src_path, sizeof(build_src_path));
|
2012-07-13 09:20:25 +08:00
|
|
|
if (actual_src_path[0] == '~')
|
|
|
|
{
|
|
|
|
FileSpec resolved_source_path(actual_src_path, true);
|
|
|
|
resolved_source_path.GetPath(actual_src_path, sizeof(actual_src_path));
|
|
|
|
}
|
2012-03-16 05:01:31 +08:00
|
|
|
module_spec.GetSourceMappingList().Append (ConstString(build_src_path), ConstString(actual_src_path), true);
|
2011-04-12 13:54:46 +08:00
|
|
|
}
|
2011-07-19 11:57:15 +08:00
|
|
|
}
|
|
|
|
}
|
2012-03-16 05:01:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (out_exec_fspec)
|
|
|
|
{
|
|
|
|
bool success = false;
|
|
|
|
if (uuid_dict)
|
|
|
|
{
|
|
|
|
CFStringRef exec_cf_path = static_cast<CFStringRef>(::CFDictionaryGetValue (uuid_dict, CFSTR("DBGSymbolRichExecutable")));
|
|
|
|
if (exec_cf_path && ::CFStringGetFileSystemRepresentation (exec_cf_path, path, sizeof(path)))
|
|
|
|
{
|
|
|
|
++items_found;
|
|
|
|
out_exec_fspec->SetFile(path, path[0] == '~');
|
|
|
|
if (out_exec_fspec->Exists())
|
|
|
|
success = true;
|
|
|
|
}
|
|
|
|
}
|
2012-02-14 07:10:39 +08:00
|
|
|
|
|
|
|
if (!success)
|
2011-07-19 11:57:15 +08:00
|
|
|
{
|
|
|
|
// No dictionary, check near the dSYM bundle for an executable that matches...
|
|
|
|
if (::CFURLGetFileSystemRepresentation (dsym_url.get(), true, (UInt8*)path, sizeof(path)-1))
|
|
|
|
{
|
|
|
|
char *dsym_extension_pos = ::strstr (path, ".dSYM");
|
|
|
|
if (dsym_extension_pos)
|
|
|
|
{
|
|
|
|
*dsym_extension_pos = '\0';
|
|
|
|
FileSpec file_spec (path, true);
|
|
|
|
switch (file_spec.GetFileType())
|
|
|
|
{
|
|
|
|
case FileSpec::eFileTypeDirectory: // Bundle directory?
|
|
|
|
{
|
|
|
|
CFCBundle bundle (path);
|
|
|
|
CFCReleaser<CFURLRef> bundle_exe_url (bundle.CopyExecutableURL ());
|
|
|
|
if (bundle_exe_url.get())
|
|
|
|
{
|
|
|
|
if (::CFURLGetFileSystemRepresentation (bundle_exe_url.get(), true, (UInt8*)path, sizeof(path)-1))
|
|
|
|
{
|
|
|
|
FileSpec bundle_exe_file_spec (path, true);
|
|
|
|
|
|
|
|
if (FileAtPathContainsArchAndUUID (bundle_exe_file_spec, arch, uuid))
|
|
|
|
{
|
|
|
|
++items_found;
|
|
|
|
*out_exec_fspec = bundle_exe_file_spec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileSpec::eFileTypePipe: // Forget pipes
|
|
|
|
case FileSpec::eFileTypeSocket: // We can't process socket files
|
|
|
|
case FileSpec::eFileTypeInvalid: // File doesn't exist...
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileSpec::eFileTypeUnknown:
|
|
|
|
case FileSpec::eFileTypeRegular:
|
|
|
|
case FileSpec::eFileTypeSymbolicLink:
|
|
|
|
case FileSpec::eFileTypeOther:
|
|
|
|
if (FileAtPathContainsArchAndUUID (file_spec, arch, uuid))
|
|
|
|
{
|
|
|
|
++items_found;
|
|
|
|
*out_exec_fspec = file_spec;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-04 11:34:56 +08:00
|
|
|
#endif // #if !defined (__arm__)
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return items_found;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2012-02-26 13:51:37 +08:00
|
|
|
LocateDSYMInVincinityOfExecutable (const ModuleSpec &module_spec, FileSpec &dsym_fspec)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-02-26 13:51:37 +08:00
|
|
|
const FileSpec *exec_fspec = module_spec.GetFileSpecPtr();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (exec_fspec)
|
|
|
|
{
|
|
|
|
char path[PATH_MAX];
|
|
|
|
if (exec_fspec->GetPath(path, sizeof(path)))
|
|
|
|
{
|
|
|
|
// Make sure the module isn't already just a dSYM file...
|
|
|
|
if (strcasestr(path, ".dSYM/Contents/Resources/DWARF") == NULL)
|
|
|
|
{
|
|
|
|
size_t obj_file_path_length = strlen(path);
|
2012-05-07 01:56:42 +08:00
|
|
|
strlcat(path, ".dSYM/Contents/Resources/DWARF/", sizeof(path));
|
|
|
|
strlcat(path, exec_fspec->GetFilename().AsCString(), sizeof(path));
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-10-21 04:54:39 +08:00
|
|
|
dsym_fspec.SetFile(path, false);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-02-26 13:51:37 +08:00
|
|
|
if (dsym_fspec.Exists() && FileAtPathContainsArchAndUUID (dsym_fspec, module_spec.GetArchitecturePtr(), module_spec.GetUUIDPtr()))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path[obj_file_path_length] = '\0';
|
|
|
|
|
|
|
|
char *last_dot = strrchr(path, '.');
|
|
|
|
while (last_dot != NULL && last_dot[0])
|
|
|
|
{
|
|
|
|
char *next_slash = strchr(last_dot, '/');
|
|
|
|
if (next_slash != NULL)
|
|
|
|
{
|
|
|
|
*next_slash = '\0';
|
2012-05-07 01:56:42 +08:00
|
|
|
strlcat(path, ".dSYM/Contents/Resources/DWARF/", sizeof(path));
|
|
|
|
strlcat(path, exec_fspec->GetFilename().AsCString(), sizeof(path));
|
2010-10-21 04:54:39 +08:00
|
|
|
dsym_fspec.SetFile(path, false);
|
2012-02-26 13:51:37 +08:00
|
|
|
if (dsym_fspec.Exists() && FileAtPathContainsArchAndUUID (dsym_fspec, module_spec.GetArchitecturePtr(), module_spec.GetUUIDPtr()))
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*last_dot = '\0';
|
|
|
|
char *prev_slash = strrchr(path, '/');
|
|
|
|
if (prev_slash != NULL)
|
|
|
|
*prev_slash = '\0';
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dsym_fspec.Clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSpec
|
2012-02-26 13:51:37 +08:00
|
|
|
Symbols::LocateExecutableObjectFile (const ModuleSpec &module_spec)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-02-26 13:51:37 +08:00
|
|
|
const FileSpec *exec_fspec = module_spec.GetFileSpecPtr();
|
|
|
|
const ArchSpec *arch = module_spec.GetArchitecturePtr();
|
|
|
|
const UUID *uuid = module_spec.GetUUIDPtr();
|
2010-06-09 00:52:24 +08:00
|
|
|
Timer scoped_timer (__PRETTY_FUNCTION__,
|
|
|
|
"LocateExecutableObjectFile (file = %s, arch = %s, uuid = %p)",
|
|
|
|
exec_fspec ? exec_fspec->GetFilename().AsCString ("<NULL>") : "<NULL>",
|
2011-02-23 08:35:02 +08:00
|
|
|
arch ? arch->GetArchitectureName() : "<NULL>",
|
2010-06-09 00:52:24 +08:00
|
|
|
uuid);
|
|
|
|
|
|
|
|
FileSpec objfile_fspec;
|
2012-02-26 13:51:37 +08:00
|
|
|
if (exec_fspec && FileAtPathContainsArchAndUUID (exec_fspec, arch, uuid))
|
|
|
|
objfile_fspec = exec_fspec;
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
2012-02-26 13:51:37 +08:00
|
|
|
LocateMacOSXFilesUsingDebugSymbols (module_spec, &objfile_fspec, NULL);
|
2010-06-09 00:52:24 +08:00
|
|
|
return objfile_fspec;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSpec
|
2012-02-26 13:51:37 +08:00
|
|
|
Symbols::LocateExecutableSymbolFile (const ModuleSpec &module_spec)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-02-26 13:51:37 +08:00
|
|
|
const FileSpec *exec_fspec = module_spec.GetFileSpecPtr();
|
|
|
|
const ArchSpec *arch = module_spec.GetArchitecturePtr();
|
|
|
|
const UUID *uuid = module_spec.GetUUIDPtr();
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
Timer scoped_timer (__PRETTY_FUNCTION__,
|
|
|
|
"LocateExecutableSymbolFile (file = %s, arch = %s, uuid = %p)",
|
|
|
|
exec_fspec ? exec_fspec->GetFilename().AsCString ("<NULL>") : "<NULL>",
|
2011-02-23 08:35:02 +08:00
|
|
|
arch ? arch->GetArchitectureName() : "<NULL>",
|
2010-06-09 00:52:24 +08:00
|
|
|
uuid);
|
|
|
|
|
|
|
|
FileSpec symbol_fspec;
|
|
|
|
// First try and find the dSYM in the same directory as the executable or in
|
|
|
|
// an appropriate parent directory
|
2012-02-26 13:51:37 +08:00
|
|
|
if (LocateDSYMInVincinityOfExecutable (module_spec, symbol_fspec) == false)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
// We failed to easily find the dSYM above, so use DebugSymbols
|
2012-02-26 13:51:37 +08:00
|
|
|
LocateMacOSXFilesUsingDebugSymbols (module_spec, NULL, &symbol_fspec);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return symbol_fspec;
|
|
|
|
}
|
2012-09-27 11:13:55 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
Symbols::DownloadObjectAndSymbolFile (ModuleSpec &module_spec)
|
|
|
|
{
|
|
|
|
bool success = false;
|
|
|
|
const UUID *uuid_ptr = module_spec.GetUUIDPtr();
|
|
|
|
if (uuid_ptr)
|
|
|
|
{
|
|
|
|
static bool g_located_dsym_for_uuid_exe = false;
|
|
|
|
static bool g_dsym_for_uuid_exe_exists = false;
|
|
|
|
static char g_dsym_for_uuid_exe_path[PATH_MAX];
|
|
|
|
if (!g_located_dsym_for_uuid_exe)
|
|
|
|
{
|
|
|
|
g_located_dsym_for_uuid_exe = true;
|
|
|
|
const char *dsym_for_uuid_exe_path_cstr = getenv("LLDB_APPLE_DSYMFORUUID_EXECUTABLE");
|
|
|
|
FileSpec dsym_for_uuid_exe_spec;
|
|
|
|
if (dsym_for_uuid_exe_path_cstr)
|
|
|
|
{
|
|
|
|
dsym_for_uuid_exe_spec.SetFile(dsym_for_uuid_exe_path_cstr, true);
|
|
|
|
g_dsym_for_uuid_exe_exists = dsym_for_uuid_exe_spec.Exists();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_dsym_for_uuid_exe_exists)
|
|
|
|
{
|
|
|
|
dsym_for_uuid_exe_spec.SetFile("~rc/bin/dsymForUUID", true);
|
|
|
|
g_dsym_for_uuid_exe_exists = dsym_for_uuid_exe_spec.Exists();
|
|
|
|
if (!g_dsym_for_uuid_exe_exists)
|
|
|
|
{
|
|
|
|
dsym_for_uuid_exe_spec.SetFile("/usr/local/bin/dsymForUUID", false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_dsym_for_uuid_exe_exists)
|
|
|
|
dsym_for_uuid_exe_spec.GetPath (g_dsym_for_uuid_exe_path, sizeof(g_dsym_for_uuid_exe_path));
|
|
|
|
}
|
|
|
|
if (g_dsym_for_uuid_exe_exists)
|
|
|
|
{
|
|
|
|
StreamString command;
|
|
|
|
char uuid_cstr_buffer[64];
|
|
|
|
const char *uuid_cstr = uuid_ptr->GetAsCString(uuid_cstr_buffer, sizeof(uuid_cstr_buffer));
|
|
|
|
command.Printf("%s --copyExecutable %s", g_dsym_for_uuid_exe_path, uuid_cstr);
|
|
|
|
int exit_status = -1;
|
|
|
|
int signo = -1;
|
|
|
|
std::string command_output;
|
|
|
|
Error error = Host::RunShellCommand (command.GetData(),
|
|
|
|
NULL, // current working directory
|
|
|
|
&exit_status, // Exit status
|
|
|
|
&signo, // Signal int *
|
|
|
|
&command_output, // Command output
|
|
|
|
30, // Large timeout to allow for long dsym download times
|
|
|
|
NULL); // Don't run in a shell (we don't need shell expansion)
|
|
|
|
if (error.Success() && exit_status == 0 && !command_output.empty())
|
|
|
|
{
|
|
|
|
CFCData data (CFDataCreateWithBytesNoCopy (NULL,
|
|
|
|
(const UInt8 *)command_output.data(),
|
|
|
|
command_output.size(),
|
|
|
|
kCFAllocatorNull));
|
|
|
|
|
|
|
|
CFCReleaser<CFPropertyListRef> plist(::CFPropertyListCreateFromXMLData (NULL, data.get(), kCFPropertyListImmutable, NULL));
|
|
|
|
|
|
|
|
if (CFGetTypeID (plist.get()) == CFDictionaryGetTypeID ())
|
|
|
|
{
|
|
|
|
std::string str;
|
|
|
|
CFCString uuid_cfstr(uuid_cstr);
|
|
|
|
CFTypeRef uuid_dict = CFDictionaryGetValue ((CFDictionaryRef) plist.get(), uuid_cfstr.get());
|
|
|
|
if (uuid_dict != NULL && CFGetTypeID (uuid_dict) == CFDictionaryGetTypeID ())
|
|
|
|
{
|
|
|
|
CFStringRef cf_str;
|
|
|
|
|
|
|
|
cf_str = (CFStringRef)CFDictionaryGetValue ((CFDictionaryRef) uuid_dict, CFSTR("DBGSymbolRichExecutable"));
|
|
|
|
if (cf_str && CFGetTypeID (cf_str) == CFStringGetTypeID ())
|
|
|
|
{
|
|
|
|
if (CFCString::FileSystemRepresentation(cf_str, str))
|
|
|
|
{
|
|
|
|
success = true;
|
|
|
|
module_spec.GetFileSpec().SetFile (str.c_str(), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cf_str = (CFStringRef)CFDictionaryGetValue ((CFDictionaryRef) uuid_dict, CFSTR("DBGDSYMPath"));
|
|
|
|
if (cf_str && CFGetTypeID (cf_str) == CFStringGetTypeID ())
|
|
|
|
{
|
|
|
|
if (CFCString::FileSystemRepresentation(cf_str, str))
|
|
|
|
{
|
|
|
|
success = true;
|
|
|
|
module_spec.GetSymbolFileSpec().SetFile (str.c_str(), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|