2013-04-05 09:03:25 +08:00
//===-- PlatformDarwinKernel.cpp -----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
# include "PlatformDarwinKernel.h"
# if defined (__APPLE__) // This Plugin uses the Mac-specific source/Host/macosx/cfcpp utilities
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
# include "lldb/Breakpoint/BreakpointLocation.h"
# include "lldb/Core/ArchSpec.h"
# include "lldb/Core/Error.h"
2015-11-19 11:15:37 +08:00
# include "lldb/Core/Log.h"
2013-04-05 09:03:25 +08:00
# include "lldb/Core/Module.h"
# include "lldb/Core/ModuleList.h"
# include "lldb/Core/ModuleSpec.h"
# include "lldb/Core/PluginManager.h"
# include "lldb/Core/StreamString.h"
# include "lldb/Host/FileSpec.h"
# include "lldb/Host/Host.h"
2013-04-05 13:06:39 +08:00
# include "lldb/Interpreter/OptionValueFileSpecList.h"
# include "lldb/Interpreter/OptionValueProperties.h"
# include "lldb/Interpreter/Property.h"
2016-06-28 06:48:05 +08:00
# include "lldb/Symbol/ObjectFile.h"
2013-04-05 13:06:39 +08:00
# include "lldb/Target/Platform.h"
2013-04-05 09:03:25 +08:00
# include "lldb/Target/Process.h"
# include "lldb/Target/Target.h"
# include <CoreFoundation/CoreFoundation.h>
# include "Host/macosx/cfcpp/CFCBundle.h"
2013-05-14 05:52:06 +08:00
using namespace lldb ;
using namespace lldb_private ;
2013-04-05 09:03:25 +08:00
//------------------------------------------------------------------
// Static Variables
//------------------------------------------------------------------
static uint32_t g_initialize_count = 0 ;
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
void
PlatformDarwinKernel : : Initialize ( )
{
2015-02-13 02:18:27 +08:00
PlatformDarwin : : Initialize ( ) ;
2013-04-05 09:03:25 +08:00
if ( g_initialize_count + + = = 0 )
{
2013-05-11 05:47:16 +08:00
PluginManager : : RegisterPlugin ( PlatformDarwinKernel : : GetPluginNameStatic ( ) ,
2013-04-05 09:03:25 +08:00
PlatformDarwinKernel : : GetDescriptionStatic ( ) ,
2013-04-05 13:06:39 +08:00
PlatformDarwinKernel : : CreateInstance ,
PlatformDarwinKernel : : DebuggerInitialize ) ;
2013-04-05 09:03:25 +08:00
}
}
void
PlatformDarwinKernel : : Terminate ( )
{
if ( g_initialize_count > 0 )
{
if ( - - g_initialize_count = = 0 )
{
PluginManager : : UnregisterPlugin ( PlatformDarwinKernel : : CreateInstance ) ;
}
}
2015-02-13 02:18:27 +08:00
PlatformDarwin : : Terminate ( ) ;
2013-04-05 09:03:25 +08:00
}
2014-09-20 04:11:50 +08:00
PlatformSP
2013-04-05 09:03:25 +08:00
PlatformDarwinKernel : : CreateInstance ( bool force , const ArchSpec * arch )
{
2015-11-19 11:15:37 +08:00
Log * log ( GetLogIfAllCategoriesSet ( LIBLLDB_LOG_PLATFORM ) ) ;
if ( log )
{
const char * arch_name ;
if ( arch & & arch - > GetArchitectureName ( ) )
arch_name = arch - > GetArchitectureName ( ) ;
else
arch_name = " <null> " ;
const char * triple_cstr = arch ? arch - > GetTriple ( ) . getTriple ( ) . c_str ( ) : " <null> " ;
log - > Printf ( " PlatformDarwinKernel::%s(force=%s, arch={%s,%s}) " , __FUNCTION__ , force ? " true " : " false " , arch_name , triple_cstr ) ;
}
2013-04-05 09:03:25 +08:00
// This is a special plugin that we don't want to activate just based on an ArchSpec for normal
2015-07-03 02:48:40 +08:00
// userland debugging. It is only useful in kernel debug sessions and the DynamicLoaderDarwinPlugin
2013-04-05 09:03:25 +08:00
// (or a user doing 'platform select') will force the creation of this Platform plugin.
if ( force = = false )
2015-11-19 11:15:37 +08:00
{
if ( log )
log - > Printf ( " PlatformDarwinKernel::%s() aborting creation of platform because force == false " , __FUNCTION__ ) ;
2014-09-20 04:11:50 +08:00
return PlatformSP ( ) ;
2015-11-19 11:15:37 +08:00
}
2013-04-05 09:03:25 +08:00
bool create = force ;
LazyBool is_ios_debug_session = eLazyBoolCalculate ;
if ( create = = false & & arch & & arch - > IsValid ( ) )
{
const llvm : : Triple & triple = arch - > GetTriple ( ) ;
switch ( triple . getVendor ( ) )
{
case llvm : : Triple : : Apple :
create = true ;
break ;
// Only accept "unknown" for vendor if the host is Apple and
2014-06-27 10:42:12 +08:00
// it "unknown" wasn't specified (it was just returned because it
2013-04-05 09:03:25 +08:00
// was NOT specified)
case llvm : : Triple : : UnknownArch :
create = ! arch - > TripleVendorWasSpecified ( ) ;
break ;
default :
break ;
}
if ( create )
{
switch ( triple . getOS ( ) )
{
2015-11-06 07:03:44 +08:00
case llvm : : Triple : : Darwin :
2013-04-05 09:03:25 +08:00
case llvm : : Triple : : MacOSX :
2015-11-06 07:03:44 +08:00
case llvm : : Triple : : IOS :
case llvm : : Triple : : WatchOS :
case llvm : : Triple : : TvOS :
2013-04-05 09:03:25 +08:00
break ;
// Only accept "vendor" for vendor if the host is Apple and
2014-06-27 10:42:12 +08:00
// it "unknown" wasn't specified (it was just returned because it
2013-04-05 09:03:25 +08:00
// was NOT specified)
case llvm : : Triple : : UnknownOS :
create = ! arch - > TripleOSWasSpecified ( ) ;
break ;
default :
create = false ;
break ;
}
}
}
if ( arch & & arch - > IsValid ( ) )
{
switch ( arch - > GetMachine ( ) )
{
case llvm : : Triple : : x86 :
case llvm : : Triple : : x86_64 :
case llvm : : Triple : : ppc :
case llvm : : Triple : : ppc64 :
is_ios_debug_session = eLazyBoolNo ;
break ;
case llvm : : Triple : : arm :
2014-07-23 22:37:35 +08:00
case llvm : : Triple : : aarch64 :
2013-04-05 09:03:25 +08:00
case llvm : : Triple : : thumb :
is_ios_debug_session = eLazyBoolYes ;
break ;
default :
is_ios_debug_session = eLazyBoolCalculate ;
break ;
}
}
if ( create )
2015-11-19 11:15:37 +08:00
{
if ( log )
log - > Printf ( " PlatformDarwinKernel::%s() creating platform " , __FUNCTION__ ) ;
2014-09-20 04:11:50 +08:00
return PlatformSP ( new PlatformDarwinKernel ( is_ios_debug_session ) ) ;
2015-11-19 11:15:37 +08:00
}
if ( log )
log - > Printf ( " PlatformDarwinKernel::%s() aborting creation of platform " , __FUNCTION__ ) ;
2014-09-20 04:11:50 +08:00
return PlatformSP ( ) ;
2013-04-05 09:03:25 +08:00
}
2013-05-11 05:47:16 +08:00
lldb_private : : ConstString
2013-04-05 09:03:25 +08:00
PlatformDarwinKernel : : GetPluginNameStatic ( )
{
2013-05-11 05:47:16 +08:00
static ConstString g_name ( " darwin-kernel " ) ;
return g_name ;
2013-04-05 09:03:25 +08:00
}
const char *
PlatformDarwinKernel : : GetDescriptionStatic ( )
{
return " Darwin Kernel platform plug-in. " ;
}
2013-04-05 13:06:39 +08:00
//------------------------------------------------------------------
/// Code to handle the PlatformDarwinKernel settings
//------------------------------------------------------------------
static PropertyDefinition
g_properties [ ] =
{
2013-04-12 08:23:57 +08:00
{ " search-locally-for-kexts " , OptionValue : : eTypeBoolean , true , true , NULL , NULL , " Automatically search for kexts on the local system when doing kernel debugging. " } ,
2013-04-05 13:06:39 +08:00
{ " kext-directories " , OptionValue : : eTypeFileSpecList , false , 0 , NULL , NULL , " Directories/KDKs to search for kexts in when starting a kernel debug session. " } ,
{ NULL , OptionValue : : eTypeInvalid , false , 0 , NULL , NULL , NULL }
} ;
enum {
ePropertySearchForKexts = 0 ,
ePropertyKextDirectories
} ;
class PlatformDarwinKernelProperties : public Properties
{
public :
static ConstString &
GetSettingName ( )
{
static ConstString g_setting_name ( " darwin-kernel " ) ;
return g_setting_name ;
}
PlatformDarwinKernelProperties ( ) :
Properties ( )
{
m_collection_sp . reset ( new OptionValueProperties ( GetSettingName ( ) ) ) ;
m_collection_sp - > Initialize ( g_properties ) ;
}
virtual
~ PlatformDarwinKernelProperties ( )
{
}
bool
GetSearchForKexts ( ) const
{
const uint32_t idx = ePropertySearchForKexts ;
return m_collection_sp - > GetPropertyAtIndexAsBoolean ( NULL , idx , g_properties [ idx ] . default_uint_value ! = 0 ) ;
}
FileSpecList &
GetKextDirectories ( ) const
{
const uint32_t idx = ePropertyKextDirectories ;
OptionValueFileSpecList * option_value = m_collection_sp - > GetPropertyAtIndexAsOptionValueFileSpecList ( NULL , false , idx ) ;
assert ( option_value ) ;
return option_value - > GetCurrentValue ( ) ;
}
} ;
2013-04-19 06:45:39 +08:00
typedef std : : shared_ptr < PlatformDarwinKernelProperties > PlatformDarwinKernelPropertiesSP ;
2013-04-05 13:06:39 +08:00
static const PlatformDarwinKernelPropertiesSP &
GetGlobalProperties ( )
{
static PlatformDarwinKernelPropertiesSP g_settings_sp ;
if ( ! g_settings_sp )
g_settings_sp . reset ( new PlatformDarwinKernelProperties ( ) ) ;
return g_settings_sp ;
}
void
PlatformDarwinKernel : : DebuggerInitialize ( lldb_private : : Debugger & debugger )
{
if ( ! PluginManager : : GetSettingForPlatformPlugin ( debugger , PlatformDarwinKernelProperties : : GetSettingName ( ) ) )
{
const bool is_global_setting = true ;
PluginManager : : CreateSettingForPlatformPlugin ( debugger ,
GetGlobalProperties ( ) - > GetValueProperties ( ) ,
ConstString ( " Properties for the PlatformDarwinKernel plug-in. " ) ,
is_global_setting ) ;
}
}
2013-04-05 09:03:25 +08:00
//------------------------------------------------------------------
/// Default Constructor
//------------------------------------------------------------------
PlatformDarwinKernel : : PlatformDarwinKernel ( lldb_private : : LazyBool is_ios_debug_session ) :
PlatformDarwin ( false ) , // This is a remote platform
2016-07-29 14:24:03 +08:00
m_name_to_kext_path_map_with_dsyms ( ) ,
m_name_to_kext_path_map_without_dsyms ( ) ,
2015-01-29 14:20:05 +08:00
m_search_directories ( ) ,
2016-07-29 14:24:03 +08:00
m_kernel_binaries_with_dsyms ( ) ,
m_kernel_binaries_without_dsyms ( ) ,
2013-04-05 09:03:25 +08:00
m_ios_debug_session ( is_ios_debug_session )
{
2013-04-05 13:06:39 +08:00
if ( GetGlobalProperties ( ) - > GetSearchForKexts ( ) )
{
2015-01-29 14:20:05 +08:00
CollectKextAndKernelDirectories ( ) ;
IndexKextsInDirectories ( ) ;
IndexKernelsInDirectories ( ) ;
2013-04-05 13:06:39 +08:00
}
2013-04-05 09:03:25 +08:00
}
//------------------------------------------------------------------
/// Destructor.
///
/// The destructor is virtual since this class is designed to be
/// inherited from by the plug-in instance.
//------------------------------------------------------------------
PlatformDarwinKernel : : ~ PlatformDarwinKernel ( )
{
}
void
PlatformDarwinKernel : : GetStatus ( Stream & strm )
{
Platform : : GetStatus ( strm ) ;
strm . Printf ( " Debug session type: " ) ;
if ( m_ios_debug_session = = eLazyBoolYes )
strm . Printf ( " iOS kernel debugging \n " ) ;
else if ( m_ios_debug_session = = eLazyBoolNo )
2016-06-23 12:24:16 +08:00
strm . Printf ( " Mac OS X kernel debugging \n " ) ;
2013-04-05 09:03:25 +08:00
else
strm . Printf ( " unknown kernel debugging \n " ) ;
2015-01-29 14:20:05 +08:00
const uint32_t num_kext_dirs = m_search_directories . size ( ) ;
2013-04-06 06:40:42 +08:00
for ( uint32_t i = 0 ; i < num_kext_dirs ; + + i )
2013-04-05 09:03:25 +08:00
{
2015-01-29 14:20:05 +08:00
const FileSpec & kext_dir = m_search_directories [ i ] ;
2013-04-29 17:46:43 +08:00
strm . Printf ( " Kext directories: [%2u] \" %s \" \n " , i , kext_dir . GetPath ( ) . c_str ( ) ) ;
2013-04-05 09:03:25 +08:00
}
2016-07-29 14:24:03 +08:00
strm . Printf ( " Number of kexts with dSYMs indexed: %d \n " , ( int ) m_name_to_kext_path_map_with_dsyms . size ( ) ) ;
strm . Printf ( " Number of kexts without dSYMs indexed: %d \n " , ( int ) m_name_to_kext_path_map_without_dsyms . size ( ) ) ;
strm . Printf ( " Number of Kernel binaries with dSYMs indexed: %d \n " , ( int ) m_kernel_binaries_with_dsyms . size ( ) ) ;
strm . Printf ( " Number of Kernel binaries without dSYMs indexed: %d \n " , ( int ) m_kernel_binaries_without_dsyms . size ( ) ) ;
2013-04-05 09:03:25 +08:00
}
2015-01-29 14:20:05 +08:00
// Populate the m_search_directories vector with directories we should search
// for kernel & kext binaries.
2013-04-05 09:03:25 +08:00
void
2015-01-29 14:20:05 +08:00
PlatformDarwinKernel : : CollectKextAndKernelDirectories ( )
2013-04-05 09:03:25 +08:00
{
// Differentiate between "ios debug session" and "mac debug session" so we don't index
// kext bundles that won't be used in this debug session. If this is an ios kext debug
// session, looking in /System/Library/Extensions is a waste of stat()s, for example.
2015-01-29 14:20:05 +08:00
// Build up a list of all SDKs we'll be searching for directories of kexts/kernels
2013-04-05 09:03:25 +08:00
// e.g. /Applications/Xcode.app//Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.Internal.sdk
std : : vector < FileSpec > sdk_dirs ;
if ( m_ios_debug_session ! = eLazyBoolNo )
2015-11-06 07:03:44 +08:00
{
2013-04-05 09:03:25 +08:00
GetiOSSDKDirectoriesToSearch ( sdk_dirs ) ;
2015-11-06 07:03:44 +08:00
GetAppleTVOSSDKDirectoriesToSearch ( sdk_dirs ) ;
GetWatchOSSDKDirectoriesToSearch ( sdk_dirs ) ;
}
2013-04-05 09:03:25 +08:00
if ( m_ios_debug_session ! = eLazyBoolYes )
GetMacSDKDirectoriesToSearch ( sdk_dirs ) ;
GetGenericSDKDirectoriesToSearch ( sdk_dirs ) ;
2015-01-29 14:20:05 +08:00
// Build up a list of directories that hold may kext bundles & kernels
//
// e.g. given /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
// find
// /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.Internal.sdk/
// and
// /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.Internal.sdk/System/Library/Extensions
2013-04-05 09:03:25 +08:00
std : : vector < FileSpec > kext_dirs ;
SearchSDKsForKextDirectories ( sdk_dirs , kext_dirs ) ;
if ( m_ios_debug_session ! = eLazyBoolNo )
GetiOSDirectoriesToSearch ( kext_dirs ) ;
if ( m_ios_debug_session ! = eLazyBoolYes )
GetMacDirectoriesToSearch ( kext_dirs ) ;
GetGenericDirectoriesToSearch ( kext_dirs ) ;
2013-04-05 13:06:39 +08:00
GetUserSpecifiedDirectoriesToSearch ( kext_dirs ) ;
2015-01-29 14:20:05 +08:00
GetKernelDirectoriesToSearch ( kext_dirs ) ;
2013-04-05 09:03:25 +08:00
2015-01-29 14:20:05 +08:00
GetCurrentDirectoryToSearch ( kext_dirs ) ;
// We now have a complete list of directories that we will search for kext bundles
m_search_directories = kext_dirs ;
2013-04-05 09:03:25 +08:00
}
void
PlatformDarwinKernel : : GetiOSSDKDirectoriesToSearch ( std : : vector < lldb_private : : FileSpec > & directories )
{
// DeveloperDirectory is something like "/Applications/Xcode.app/Contents/Developer"
const char * developer_dir = GetDeveloperDirectory ( ) ;
if ( developer_dir = = NULL )
developer_dir = " /Applications/Xcode.app/Contents/Developer " ;
char pathbuf [ PATH_MAX ] ;
: : snprintf ( pathbuf , sizeof ( pathbuf ) , " %s/Platforms/iPhoneOS.platform/Developer/SDKs " , developer_dir ) ;
FileSpec ios_sdk ( pathbuf , true ) ;
2013-04-29 17:46:43 +08:00
if ( ios_sdk . Exists ( ) & & ios_sdk . IsDirectory ( ) )
2013-04-05 09:03:25 +08:00
{
directories . push_back ( ios_sdk ) ;
}
}
2015-11-06 07:03:44 +08:00
void
PlatformDarwinKernel : : GetAppleTVOSSDKDirectoriesToSearch ( std : : vector < lldb_private : : FileSpec > & directories )
{
// DeveloperDirectory is something like "/Applications/Xcode.app/Contents/Developer"
const char * developer_dir = GetDeveloperDirectory ( ) ;
if ( developer_dir = = NULL )
developer_dir = " /Applications/Xcode.app/Contents/Developer " ;
char pathbuf [ PATH_MAX ] ;
: : snprintf ( pathbuf , sizeof ( pathbuf ) , " %s/Platforms/AppleTVOS.platform/Developer/SDKs " , developer_dir ) ;
FileSpec ios_sdk ( pathbuf , true ) ;
if ( ios_sdk . Exists ( ) & & ios_sdk . IsDirectory ( ) )
{
directories . push_back ( ios_sdk ) ;
}
}
void
PlatformDarwinKernel : : GetWatchOSSDKDirectoriesToSearch ( std : : vector < lldb_private : : FileSpec > & directories )
{
// DeveloperDirectory is something like "/Applications/Xcode.app/Contents/Developer"
const char * developer_dir = GetDeveloperDirectory ( ) ;
if ( developer_dir = = NULL )
developer_dir = " /Applications/Xcode.app/Contents/Developer " ;
char pathbuf [ PATH_MAX ] ;
: : snprintf ( pathbuf , sizeof ( pathbuf ) , " %s/Platforms/watchOS.platform/Developer/SDKs " , developer_dir ) ;
FileSpec ios_sdk ( pathbuf , true ) ;
if ( ios_sdk . Exists ( ) & & ios_sdk . IsDirectory ( ) )
{
directories . push_back ( ios_sdk ) ;
}
else
{
: : snprintf ( pathbuf , sizeof ( pathbuf ) , " %s/Platforms/WatchOS.platform/Developer/SDKs " , developer_dir ) ;
FileSpec alt_watch_sdk ( pathbuf , true ) ;
if ( ios_sdk . Exists ( ) & & ios_sdk . IsDirectory ( ) )
{
directories . push_back ( ios_sdk ) ;
}
}
}
2013-04-05 09:03:25 +08:00
void
PlatformDarwinKernel : : GetMacSDKDirectoriesToSearch ( std : : vector < lldb_private : : FileSpec > & directories )
{
// DeveloperDirectory is something like "/Applications/Xcode.app/Contents/Developer"
const char * developer_dir = GetDeveloperDirectory ( ) ;
if ( developer_dir = = NULL )
developer_dir = " /Applications/Xcode.app/Contents/Developer " ;
char pathbuf [ PATH_MAX ] ;
: : snprintf ( pathbuf , sizeof ( pathbuf ) , " %s/Platforms/MacOSX.platform/Developer/SDKs " , developer_dir ) ;
FileSpec mac_sdk ( pathbuf , true ) ;
2013-04-29 17:46:43 +08:00
if ( mac_sdk . Exists ( ) & & mac_sdk . IsDirectory ( ) )
2013-04-05 09:03:25 +08:00
{
directories . push_back ( mac_sdk ) ;
}
}
void
PlatformDarwinKernel : : GetGenericSDKDirectoriesToSearch ( std : : vector < lldb_private : : FileSpec > & directories )
{
FileSpec generic_sdk ( " /AppleInternal/Developer/KDKs " , true ) ;
2013-04-29 17:46:43 +08:00
if ( generic_sdk . Exists ( ) & & generic_sdk . IsDirectory ( ) )
2013-04-05 09:03:25 +08:00
{
directories . push_back ( generic_sdk ) ;
}
2014-07-31 14:36:24 +08:00
// The KDKs distributed from Apple installed on external
// developer systems may be in directories like
// /Library/Developer/KDKs/KDK_10.10_14A298i.kdk
FileSpec installed_kdks ( " /Library/Developer/KDKs " , true ) ;
if ( installed_kdks . Exists ( ) & & installed_kdks . IsDirectory ( ) )
{
directories . push_back ( installed_kdks ) ;
}
2013-04-05 09:03:25 +08:00
}
void
PlatformDarwinKernel : : GetiOSDirectoriesToSearch ( std : : vector < lldb_private : : FileSpec > & directories )
{
}
void
PlatformDarwinKernel : : GetMacDirectoriesToSearch ( std : : vector < lldb_private : : FileSpec > & directories )
{
FileSpec sle ( " /System/Library/Extensions " , true ) ;
2013-04-29 17:46:43 +08:00
if ( sle . Exists ( ) & & sle . IsDirectory ( ) )
2013-04-05 09:03:25 +08:00
{
directories . push_back ( sle ) ;
}
2013-04-09 05:24:40 +08:00
2013-04-24 06:35:28 +08:00
FileSpec le ( " /Library/Extensions " , true ) ;
2013-04-29 17:46:43 +08:00
if ( le . Exists ( ) & & le . IsDirectory ( ) )
2013-04-24 06:35:28 +08:00
{
directories . push_back ( le ) ;
}
2013-04-09 05:24:40 +08:00
FileSpec kdk ( " /Volumes/KernelDebugKit " , true ) ;
2013-04-29 17:46:43 +08:00
if ( kdk . Exists ( ) & & kdk . IsDirectory ( ) )
2013-04-09 05:24:40 +08:00
{
directories . push_back ( kdk ) ;
}
2013-04-05 09:03:25 +08:00
}
void
PlatformDarwinKernel : : GetGenericDirectoriesToSearch ( std : : vector < lldb_private : : FileSpec > & directories )
{
// DeveloperDirectory is something like "/Applications/Xcode.app/Contents/Developer"
const char * developer_dir = GetDeveloperDirectory ( ) ;
if ( developer_dir = = NULL )
developer_dir = " /Applications/Xcode.app/Contents/Developer " ;
char pathbuf [ PATH_MAX ] ;
: : snprintf ( pathbuf , sizeof ( pathbuf ) , " %s/../Symbols " , developer_dir ) ;
FileSpec symbols_dir ( pathbuf , true ) ;
2013-04-29 17:46:43 +08:00
if ( symbols_dir . Exists ( ) & & symbols_dir . IsDirectory ( ) )
2013-04-05 09:03:25 +08:00
{
directories . push_back ( symbols_dir ) ;
}
}
2015-01-29 14:20:05 +08:00
void
PlatformDarwinKernel : : GetKernelDirectoriesToSearch ( std : : vector < lldb_private : : FileSpec > & directories )
{
FileSpec system_library_kernels ( " /System/Library/Kernels " , true ) ;
if ( system_library_kernels . Exists ( ) & & system_library_kernels . IsDirectory ( ) )
{
directories . push_back ( system_library_kernels ) ;
}
FileSpec slek ( " /System/Library/Extensions/KDK " , true ) ;
if ( slek . Exists ( ) & & slek . IsDirectory ( ) )
{
directories . push_back ( slek ) ;
}
}
void
PlatformDarwinKernel : : GetCurrentDirectoryToSearch ( std : : vector < lldb_private : : FileSpec > & directories )
{
directories . push_back ( FileSpec ( " . " , true ) ) ;
FileSpec sle_directory ( " System/Library/Extensions " , true ) ;
if ( sle_directory . Exists ( ) & & sle_directory . IsDirectory ( ) )
{
directories . push_back ( sle_directory ) ;
}
FileSpec le_directory ( " Library/Extensions " , true ) ;
if ( le_directory . Exists ( ) & & le_directory . IsDirectory ( ) )
{
directories . push_back ( le_directory ) ;
}
FileSpec slk_directory ( " System/Library/Kernels " , true ) ;
if ( slk_directory . Exists ( ) & & slk_directory . IsDirectory ( ) )
{
directories . push_back ( slk_directory ) ;
}
FileSpec slek ( " System/Library/Extensions/KDK " , true ) ;
if ( slek . Exists ( ) & & slek . IsDirectory ( ) )
{
directories . push_back ( slek ) ;
}
}
2013-04-05 13:06:39 +08:00
void
PlatformDarwinKernel : : GetUserSpecifiedDirectoriesToSearch ( std : : vector < lldb_private : : FileSpec > & directories )
{
FileSpecList user_dirs ( GetGlobalProperties ( ) - > GetKextDirectories ( ) ) ;
std : : vector < FileSpec > possible_sdk_dirs ;
const uint32_t user_dirs_count = user_dirs . GetSize ( ) ;
for ( uint32_t i = 0 ; i < user_dirs_count ; i + + )
{
2013-04-06 06:40:42 +08:00
FileSpec dir = user_dirs . GetFileSpecAtIndex ( i ) ;
dir . ResolvePath ( ) ;
2013-04-29 17:46:43 +08:00
if ( dir . Exists ( ) & & dir . IsDirectory ( ) )
2013-04-05 13:06:39 +08:00
{
directories . push_back ( dir ) ;
possible_sdk_dirs . push_back ( dir ) ; // does this directory have a *.sdk or *.kdk that we should look in?
2013-04-29 17:46:43 +08:00
// Is there a "System/Library/Extensions" subdir of this directory?
std : : string dir_sle_path = dir . GetPath ( ) ;
dir_sle_path . append ( " /System/Library/Extensions " ) ;
FileSpec dir_sle ( dir_sle_path . c_str ( ) , true ) ;
if ( dir_sle . Exists ( ) & & dir_sle . IsDirectory ( ) )
2013-04-05 13:06:39 +08:00
{
2013-04-29 17:46:43 +08:00
directories . push_back ( dir_sle ) ;
2013-04-05 13:06:39 +08:00
}
2015-01-29 14:20:05 +08:00
// Is there a "System/Library/Kernels" subdir of this directory?
std : : string dir_slk_path = dir . GetPath ( ) ;
dir_slk_path . append ( " /System/Library/Kernels " ) ;
FileSpec dir_slk ( dir_slk_path . c_str ( ) , true ) ;
if ( dir_slk . Exists ( ) & & dir_slk . IsDirectory ( ) )
{
directories . push_back ( dir_slk ) ;
}
// Is there a "System/Library/Extensions/KDK" subdir of this directory?
std : : string dir_slek_path = dir . GetPath ( ) ;
dir_slek_path . append ( " /System/Library/Kernels " ) ;
FileSpec dir_slek ( dir_slek_path . c_str ( ) , true ) ;
if ( dir_slek . Exists ( ) & & dir_slek . IsDirectory ( ) )
{
directories . push_back ( dir_slek ) ;
}
2013-04-05 13:06:39 +08:00
}
}
SearchSDKsForKextDirectories ( possible_sdk_dirs , directories ) ;
}
2013-04-05 09:03:25 +08:00
// Scan through the SDK directories, looking for directories where kexts are likely.
// Add those directories to kext_dirs.
void
PlatformDarwinKernel : : SearchSDKsForKextDirectories ( std : : vector < lldb_private : : FileSpec > sdk_dirs , std : : vector < lldb_private : : FileSpec > & kext_dirs )
{
const uint32_t num_sdks = sdk_dirs . size ( ) ;
for ( uint32_t i = 0 ; i < num_sdks ; i + + )
{
const FileSpec & sdk_dir = sdk_dirs [ i ] ;
2013-04-29 17:46:43 +08:00
std : : string sdk_dir_path = sdk_dir . GetPath ( ) ;
if ( ! sdk_dir_path . empty ( ) )
2013-04-05 09:03:25 +08:00
{
const bool find_directories = true ;
const bool find_files = false ;
const bool find_other = false ;
2013-04-29 17:46:43 +08:00
FileSpec : : EnumerateDirectory ( sdk_dir_path . c_str ( ) ,
2013-04-05 09:03:25 +08:00
find_directories ,
find_files ,
find_other ,
GetKextDirectoriesInSDK ,
& kext_dirs ) ;
}
}
}
// Callback for FileSpec::EnumerateDirectory().
// Step through the entries in a directory like
// /Applications/Xcode.app//Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
// looking for any subdirectories of the form MacOSX10.8.Internal.sdk/System/Library/Extensions
// Adds these to the vector of FileSpec's.
FileSpec : : EnumerateDirectoryResult
PlatformDarwinKernel : : GetKextDirectoriesInSDK ( void * baton ,
FileSpec : : FileType file_type ,
const FileSpec & file_spec )
{
if ( file_type = = FileSpec : : eFileTypeDirectory
& & ( file_spec . GetFileNameExtension ( ) = = ConstString ( " sdk " )
| | file_spec . GetFileNameExtension ( ) = = ConstString ( " kdk " ) ) )
{
2013-04-29 17:46:43 +08:00
std : : string kext_directory_path = file_spec . GetPath ( ) ;
2014-07-31 14:36:24 +08:00
// Append the raw directory path, e.g. /Library/Developer/KDKs/KDK_10.10_14A298i.kdk
// to the directory search list -- there may be kexts sitting directly
// in that directory instead of being in a System/Library/Extensions subdir.
( ( std : : vector < lldb_private : : FileSpec > * ) baton ) - > push_back ( file_spec ) ;
// Check to see if there is a System/Library/Extensions subdir & add it if it exists
std : : string sle_kext_directory_path ( kext_directory_path ) ;
sle_kext_directory_path . append ( " /System/Library/Extensions " ) ;
FileSpec sle_kext_directory ( sle_kext_directory_path . c_str ( ) , true ) ;
if ( sle_kext_directory . Exists ( ) & & sle_kext_directory . IsDirectory ( ) )
{
( ( std : : vector < lldb_private : : FileSpec > * ) baton ) - > push_back ( sle_kext_directory ) ;
}
// Check to see if there is a Library/Extensions subdir & add it if it exists
std : : string le_kext_directory_path ( kext_directory_path ) ;
le_kext_directory_path . append ( " /Library/Extensions " ) ;
FileSpec le_kext_directory ( le_kext_directory_path . c_str ( ) , true ) ;
if ( le_kext_directory . Exists ( ) & & le_kext_directory . IsDirectory ( ) )
2013-04-05 09:03:25 +08:00
{
2014-07-31 14:36:24 +08:00
( ( std : : vector < lldb_private : : FileSpec > * ) baton ) - > push_back ( le_kext_directory ) ;
2013-04-05 09:03:25 +08:00
}
2014-07-31 14:36:24 +08:00
2015-01-29 14:20:05 +08:00
// Check to see if there is a System/Library/Kernels subdir & add it if it exists
std : : string slk_kernel_path ( kext_directory_path ) ;
slk_kernel_path . append ( " /System/Library/Kernels " ) ;
FileSpec slk_kernel_directory ( slk_kernel_path . c_str ( ) , true ) ;
if ( slk_kernel_directory . Exists ( ) & & slk_kernel_directory . IsDirectory ( ) )
{
( ( std : : vector < lldb_private : : FileSpec > * ) baton ) - > push_back ( slk_kernel_directory ) ;
}
// Check to see if there is a System/Library/Extensions/KDK subdir & add it if it exists
std : : string slek_kernel_path ( kext_directory_path ) ;
slek_kernel_path . append ( " /System/Library/Extensions/KDK " ) ;
FileSpec slek_kernel_directory ( slek_kernel_path . c_str ( ) , true ) ;
if ( slek_kernel_directory . Exists ( ) & & slek_kernel_directory . IsDirectory ( ) )
{
( ( std : : vector < lldb_private : : FileSpec > * ) baton ) - > push_back ( slek_kernel_directory ) ;
}
2013-04-05 09:03:25 +08:00
}
return FileSpec : : eEnumerateDirectoryResultNext ;
}
2016-07-29 14:24:03 +08:00
// Given a FileSpec of /dir/dir/foo.kext
// Return true if any of these exist:
// /dir/dir/foo.kext.dSYM
// /dir/dir/foo.kext/Contents/MacOS/foo.dSYM
// /dir/dir/foo.kext/foo.dSYM
bool
PlatformDarwinKernel : : KextHasdSYMSibling ( const FileSpec & kext_bundle_filepath )
{
FileSpec dsym_fspec = kext_bundle_filepath ;
std : : string filename = dsym_fspec . GetFilename ( ) . AsCString ( ) ;
filename + = " .dSYM " ;
dsym_fspec . GetFilename ( ) = ConstString ( filename ) ;
if ( dsym_fspec . Exists ( ) & & dsym_fspec . IsDirectory ( ) )
{
return true ;
}
// Should probably get the CFBundleExecutable here or call CFBundleCopyExecutableURL
// Look for a deep bundle foramt
ConstString executable_name = kext_bundle_filepath . GetFileNameStrippingExtension ( ) ;
std : : string deep_bundle_str = kext_bundle_filepath . GetPath ( ) + " /Contents/MacOS/ " ;
deep_bundle_str + = executable_name . AsCString ( ) ;
deep_bundle_str + = " .dSYM " ;
dsym_fspec . SetFile ( deep_bundle_str , true ) ;
if ( dsym_fspec . Exists ( ) & & dsym_fspec . IsDirectory ( ) )
{
return true ;
}
// look for a shallow bundle format
//
std : : string shallow_bundle_str = kext_bundle_filepath . GetPath ( ) + " / " ;
shallow_bundle_str + = executable_name . AsCString ( ) ;
shallow_bundle_str + = " .dSYM " ;
dsym_fspec . SetFile ( shallow_bundle_str , true ) ;
if ( dsym_fspec . Exists ( ) & & dsym_fspec . IsDirectory ( ) )
{
return true ;
}
return false ;
}
// Given a FileSpec of /dir/dir/mach.development.t7004
// Return true if a dSYM exists next to it:
// /dir/dir/mach.development.t7004.dSYM
bool
PlatformDarwinKernel : : KernelHasdSYMSibling ( const FileSpec & kernel_binary )
{
FileSpec kernel_dsym = kernel_binary ;
std : : string filename = kernel_binary . GetFilename ( ) . AsCString ( ) ;
filename + = " .dSYM " ;
kernel_dsym . GetFilename ( ) = ConstString ( filename ) ;
if ( kernel_dsym . Exists ( ) & & kernel_dsym . IsDirectory ( ) )
{
return true ;
}
return false ;
}
2013-04-05 09:03:25 +08:00
void
2015-01-29 14:20:05 +08:00
PlatformDarwinKernel : : IndexKextsInDirectories ( )
2013-04-05 09:03:25 +08:00
{
std : : vector < FileSpec > kext_bundles ;
2013-04-05 13:06:39 +08:00
2015-01-29 14:20:05 +08:00
const uint32_t num_dirs = m_search_directories . size ( ) ;
2013-04-05 09:03:25 +08:00
for ( uint32_t i = 0 ; i < num_dirs ; i + + )
{
2015-01-29 14:20:05 +08:00
const FileSpec & dir = m_search_directories [ i ] ;
2013-04-29 17:46:43 +08:00
const bool find_directories = true ;
const bool find_files = false ;
const bool find_other = false ;
FileSpec : : EnumerateDirectory ( dir . GetPath ( ) . c_str ( ) ,
find_directories ,
find_files ,
find_other ,
GetKextsInDirectory ,
& kext_bundles ) ;
2013-04-05 09:03:25 +08:00
}
const uint32_t num_kexts = kext_bundles . size ( ) ;
for ( uint32_t i = 0 ; i < num_kexts ; i + + )
{
const FileSpec & kext = kext_bundles [ i ] ;
2013-04-29 17:46:43 +08:00
CFCBundle bundle ( kext . GetPath ( ) . c_str ( ) ) ;
CFStringRef bundle_id ( bundle . GetIdentifier ( ) ) ;
if ( bundle_id & & CFGetTypeID ( bundle_id ) = = CFStringGetTypeID ( ) )
2013-04-05 09:03:25 +08:00
{
2013-04-29 17:46:43 +08:00
char bundle_id_buf [ PATH_MAX ] ;
if ( CFStringGetCString ( bundle_id , bundle_id_buf , sizeof ( bundle_id_buf ) , kCFStringEncodingUTF8 ) )
2013-04-05 09:03:25 +08:00
{
2013-04-29 17:46:43 +08:00
ConstString bundle_conststr ( bundle_id_buf ) ;
2016-07-29 14:24:03 +08:00
if ( KextHasdSYMSibling ( kext ) )
m_name_to_kext_path_map_with_dsyms . insert ( std : : pair < ConstString , FileSpec > ( bundle_conststr , kext ) ) ;
else
m_name_to_kext_path_map_without_dsyms . insert ( std : : pair < ConstString , FileSpec > ( bundle_conststr , kext ) ) ;
2013-04-05 09:03:25 +08:00
}
}
}
}
// Callback for FileSpec::EnumerateDirectory().
// Step through the entries in a directory like /System/Library/Extensions, find .kext bundles, add them
// to the vector of FileSpecs.
// If a .kext bundle has a Contents/PlugIns or PlugIns subdir, search for kexts in there too.
FileSpec : : EnumerateDirectoryResult
PlatformDarwinKernel : : GetKextsInDirectory ( void * baton ,
FileSpec : : FileType file_type ,
const FileSpec & file_spec )
{
if ( file_type = = FileSpec : : eFileTypeDirectory & & file_spec . GetFileNameExtension ( ) = = ConstString ( " kext " ) )
{
( ( std : : vector < lldb_private : : FileSpec > * ) baton ) - > push_back ( file_spec ) ;
2013-04-29 17:46:43 +08:00
std : : string kext_bundle_path = file_spec . GetPath ( ) ;
std : : string search_here_too ;
std : : string contents_plugins_path = kext_bundle_path + " /Contents/PlugIns " ;
FileSpec contents_plugins ( contents_plugins_path . c_str ( ) , false ) ;
if ( contents_plugins . Exists ( ) & & contents_plugins . IsDirectory ( ) )
2013-04-05 09:03:25 +08:00
{
2013-04-29 17:46:43 +08:00
search_here_too = contents_plugins_path ;
2013-04-05 09:03:25 +08:00
}
else
{
2013-04-29 17:46:43 +08:00
std : : string plugins_path = kext_bundle_path + " /PlugIns " ;
FileSpec plugins ( plugins_path . c_str ( ) , false ) ;
if ( plugins . Exists ( ) & & plugins . IsDirectory ( ) )
2013-04-05 09:03:25 +08:00
{
2013-04-29 17:46:43 +08:00
search_here_too = plugins_path ;
2013-04-05 09:03:25 +08:00
}
}
2013-04-29 17:46:43 +08:00
if ( ! search_here_too . empty ( ) )
2013-04-05 09:03:25 +08:00
{
const bool find_directories = true ;
const bool find_files = false ;
const bool find_other = false ;
2013-04-29 17:46:43 +08:00
FileSpec : : EnumerateDirectory ( search_here_too . c_str ( ) ,
2013-04-05 09:03:25 +08:00
find_directories ,
find_files ,
find_other ,
GetKextsInDirectory ,
baton ) ;
}
}
return FileSpec : : eEnumerateDirectoryResultNext ;
}
2015-01-29 14:20:05 +08:00
void
PlatformDarwinKernel : : IndexKernelsInDirectories ( )
{
std : : vector < FileSpec > kernels ;
const uint32_t num_dirs = m_search_directories . size ( ) ;
for ( uint32_t i = 0 ; i < num_dirs ; i + + )
{
const FileSpec & dir = m_search_directories [ i ] ;
const bool find_directories = false ;
const bool find_files = true ;
const bool find_other = true ; // I think eFileTypeSymbolicLink are "other"s.
FileSpec : : EnumerateDirectory ( dir . GetPath ( ) . c_str ( ) ,
find_directories ,
find_files ,
find_other ,
GetKernelsInDirectory ,
2016-07-29 14:24:03 +08:00
& kernels ) ;
}
size_t kernels_size = kernels . size ( ) ;
for ( size_t i = 0 ; i < kernels_size ; i + + )
{
if ( KernelHasdSYMSibling ( kernels [ i ] ) )
m_kernel_binaries_with_dsyms . push_back ( kernels [ i ] ) ;
else
m_kernel_binaries_without_dsyms . push_back ( kernels [ i ] ) ;
2015-01-29 14:20:05 +08:00
}
}
// Callback for FileSpec::EnumerateDirectory().
// Step through the entries in a directory like /System/Library/Kernels/, find kernel binaries,
2016-07-29 14:24:03 +08:00
// add them to m_kernel_binaries_with_dsyms and m_kernel_binaries_without_dsyms.
2015-01-29 14:20:05 +08:00
// We're only doing a filename match here. We won't try opening the file to see if it's really
// a kernel or not until we need to find a kernel of a given UUID. There's no cheap way to find
// the UUID of a file (or if it's a Mach-O binary at all) without creating a whole Module for
// the file and throwing it away if it's not wanted.
FileSpec : : EnumerateDirectoryResult
PlatformDarwinKernel : : GetKernelsInDirectory ( void * baton ,
FileSpec : : FileType file_type ,
const FileSpec & file_spec )
{
if ( file_type = = FileSpec : : eFileTypeRegular | | file_type = = FileSpec : : eFileTypeSymbolicLink )
{
ConstString filename = file_spec . GetFilename ( ) ;
if ( strncmp ( filename . GetCString ( ) , " kernel " , 6 ) = = 0
2015-01-30 10:28:06 +08:00
| | strncmp ( filename . GetCString ( ) , " mach " , 4 ) = = 0 )
2015-01-29 14:20:05 +08:00
{
( ( std : : vector < lldb_private : : FileSpec > * ) baton ) - > push_back ( file_spec ) ;
}
}
return FileSpec : : eEnumerateDirectoryResultNext ;
}
2013-04-05 09:03:25 +08:00
Error
PlatformDarwinKernel : : GetSharedModule ( const ModuleSpec & module_spec ,
2015-03-24 22:30:28 +08:00
Process * process ,
2013-04-05 09:03:25 +08:00
ModuleSP & module_sp ,
const FileSpecList * module_search_paths_ptr ,
ModuleSP * old_module_sp_ptr ,
bool * did_create_ptr )
{
Error error ;
module_sp . reset ( ) ;
const FileSpec & platform_file = module_spec . GetFileSpec ( ) ;
2013-06-19 05:23:14 +08:00
// Treat the file's path as a kext bundle ID (e.g. "com.apple.driver.AppleIRController") and search our kext index.
2013-04-29 17:46:43 +08:00
std : : string kext_bundle_id = platform_file . GetPath ( ) ;
if ( ! kext_bundle_id . empty ( ) )
2013-04-05 09:03:25 +08:00
{
2013-04-29 17:46:43 +08:00
ConstString kext_bundle_cs ( kext_bundle_id . c_str ( ) ) ;
2016-07-29 14:24:03 +08:00
// First look through the kext bundles that had a dsym next to them
if ( m_name_to_kext_path_map_with_dsyms . count ( kext_bundle_cs ) > 0 )
{
for ( BundleIDToKextIterator it = m_name_to_kext_path_map_with_dsyms . begin ( ) ; it ! = m_name_to_kext_path_map_with_dsyms . end ( ) ; + + it )
{
if ( it - > first = = kext_bundle_cs )
{
error = ExamineKextForMatchingUUID ( it - > second , module_spec . GetUUID ( ) , module_spec . GetArchitecture ( ) , module_sp ) ;
if ( module_sp . get ( ) )
{
return error ;
}
}
}
}
// Second look through the kext binarys without dSYMs
if ( m_name_to_kext_path_map_without_dsyms . count ( kext_bundle_cs ) > 0 )
2013-04-05 09:03:25 +08:00
{
2016-07-29 14:24:03 +08:00
for ( BundleIDToKextIterator it = m_name_to_kext_path_map_without_dsyms . begin ( ) ; it ! = m_name_to_kext_path_map_without_dsyms . end ( ) ; + + it )
2013-04-05 09:03:25 +08:00
{
if ( it - > first = = kext_bundle_cs )
{
2013-05-03 09:31:44 +08:00
error = ExamineKextForMatchingUUID ( it - > second , module_spec . GetUUID ( ) , module_spec . GetArchitecture ( ) , module_sp ) ;
2013-04-05 09:03:25 +08:00
if ( module_sp . get ( ) )
{
return error ;
}
}
}
}
2016-07-29 14:24:03 +08:00
2013-04-05 09:03:25 +08:00
}
2015-01-29 14:20:05 +08:00
if ( kext_bundle_id . compare ( " mach_kernel " ) = = 0 & & module_spec . GetUUID ( ) . IsValid ( ) )
{
2016-07-29 14:24:03 +08:00
// First try all kernel binaries that have a dSYM next to them
for ( auto possible_kernel : m_kernel_binaries_with_dsyms )
{
if ( possible_kernel . Exists ( ) )
{
ModuleSpec kern_spec ( possible_kernel ) ;
kern_spec . GetUUID ( ) = module_spec . GetUUID ( ) ;
ModuleSP module_sp ( new Module ( kern_spec ) ) ;
if ( module_sp & & module_sp - > GetObjectFile ( ) & & module_sp - > MatchesModuleSpec ( kern_spec ) )
{
// module_sp is an actual kernel binary we want to add.
if ( process )
{
process - > GetTarget ( ) . GetImages ( ) . AppendIfNeeded ( module_sp ) ;
error . Clear ( ) ;
return error ;
}
else
{
error = ModuleList : : GetSharedModule ( kern_spec , module_sp , NULL , NULL , NULL ) ;
if ( module_sp
& & module_sp - > GetObjectFile ( )
& & module_sp - > GetObjectFile ( ) - > GetType ( ) ! = ObjectFile : : Type : : eTypeCoreFile )
{
return error ;
}
module_sp . reset ( ) ;
}
}
}
}
// Second try all kernel binaries that don't have a dSYM
for ( auto possible_kernel : m_kernel_binaries_without_dsyms )
2015-01-29 14:20:05 +08:00
{
if ( possible_kernel . Exists ( ) )
{
ModuleSpec kern_spec ( possible_kernel ) ;
kern_spec . GetUUID ( ) = module_spec . GetUUID ( ) ;
ModuleSP module_sp ( new Module ( kern_spec ) ) ;
if ( module_sp & & module_sp - > GetObjectFile ( ) & & module_sp - > MatchesModuleSpec ( kern_spec ) )
{
2016-06-28 06:48:05 +08:00
// module_sp is an actual kernel binary we want to add.
if ( process )
2015-01-29 14:20:05 +08:00
{
2016-06-28 06:48:05 +08:00
process - > GetTarget ( ) . GetImages ( ) . AppendIfNeeded ( module_sp ) ;
error . Clear ( ) ;
2015-01-29 14:20:05 +08:00
return error ;
}
2016-06-28 06:48:05 +08:00
else
{
error = ModuleList : : GetSharedModule ( kern_spec , module_sp , NULL , NULL , NULL ) ;
if ( module_sp
& & module_sp - > GetObjectFile ( )
& & module_sp - > GetObjectFile ( ) - > GetType ( ) ! = ObjectFile : : Type : : eTypeCoreFile )
{
return error ;
}
module_sp . reset ( ) ;
}
2015-01-29 14:20:05 +08:00
}
}
}
}
2013-06-19 05:23:14 +08:00
// Else fall back to treating the file's path as an actual file path - defer to PlatformDarwin's GetSharedModule.
2015-03-24 22:30:28 +08:00
return PlatformDarwin : : GetSharedModule ( module_spec , process , module_sp , module_search_paths_ptr , old_module_sp_ptr , did_create_ptr ) ;
2013-04-05 09:03:25 +08:00
}
Error
2013-05-03 09:31:44 +08:00
PlatformDarwinKernel : : ExamineKextForMatchingUUID ( const FileSpec & kext_bundle_path , const lldb_private : : UUID & uuid , const ArchSpec & arch , ModuleSP & exe_module_sp )
2013-04-05 09:03:25 +08:00
{
Error error ;
FileSpec exe_file = kext_bundle_path ;
Host : : ResolveExecutableInBundle ( exe_file ) ;
if ( exe_file . Exists ( ) )
{
ModuleSpec exe_spec ( exe_file ) ;
exe_spec . GetUUID ( ) = uuid ;
2014-10-15 05:47:45 +08:00
if ( ! uuid . IsValid ( ) )
{
exe_spec . GetArchitecture ( ) = arch ;
}
2013-05-04 06:28:10 +08:00
// First try to create a ModuleSP with the file / arch and see if the UUID matches.
// If that fails (this exec file doesn't have the correct uuid), don't call GetSharedModule
// (which may call in to the DebugSymbols framework and therefore can be slow.)
2014-10-15 05:47:45 +08:00
ModuleSP module_sp ( new Module ( exe_spec ) ) ;
2013-05-04 06:28:10 +08:00
if ( module_sp & & module_sp - > GetObjectFile ( ) & & module_sp - > MatchesModuleSpec ( exe_spec ) )
2013-04-05 09:03:25 +08:00
{
2013-05-04 06:28:10 +08:00
error = ModuleList : : GetSharedModule ( exe_spec , exe_module_sp , NULL , NULL , NULL ) ;
if ( exe_module_sp & & exe_module_sp - > GetObjectFile ( ) )
{
return error ;
}
2013-04-05 09:03:25 +08:00
}
exe_module_sp . reset ( ) ;
}
return error ;
}
bool
PlatformDarwinKernel : : GetSupportedArchitectureAtIndex ( uint32_t idx , ArchSpec & arch )
{
2014-07-09 09:29:05 +08:00
# if defined (__arm__) || defined (__arm64__) || defined (__aarch64__)
2013-04-05 09:03:25 +08:00
return ARMGetSupportedArchitectureAtIndex ( idx , arch ) ;
# else
return x86GetSupportedArchitectureAtIndex ( idx , arch ) ;
# endif
}
2014-02-14 07:11:45 +08:00
void
PlatformDarwinKernel : : CalculateTrapHandlerSymbolNames ( )
{
m_trap_handlers . push_back ( ConstString ( " trap_from_kernel " ) ) ;
2014-11-13 15:31:45 +08:00
m_trap_handlers . push_back ( ConstString ( " hndl_machine_check " ) ) ;
2014-02-14 07:11:45 +08:00
m_trap_handlers . push_back ( ConstString ( " hndl_double_fault " ) ) ;
2014-02-19 06:35:38 +08:00
m_trap_handlers . push_back ( ConstString ( " hndl_allintrs " ) ) ;
m_trap_handlers . push_back ( ConstString ( " hndl_alltraps " ) ) ;
2014-02-19 06:48:27 +08:00
m_trap_handlers . push_back ( ConstString ( " interrupt " ) ) ;
2014-11-13 15:31:45 +08:00
m_trap_handlers . push_back ( ConstString ( " fleh_prefabt " ) ) ;
m_trap_handlers . push_back ( ConstString ( " ExceptionVectorsBase " ) ) ;
m_trap_handlers . push_back ( ConstString ( " ExceptionVectorsTable " ) ) ;
m_trap_handlers . push_back ( ConstString ( " fleh_undef " ) ) ;
m_trap_handlers . push_back ( ConstString ( " fleh_dataabt " ) ) ;
m_trap_handlers . push_back ( ConstString ( " fleh_irq " ) ) ;
m_trap_handlers . push_back ( ConstString ( " fleh_decirq " ) ) ;
m_trap_handlers . push_back ( ConstString ( " fleh_fiq_generic " ) ) ;
m_trap_handlers . push_back ( ConstString ( " fleh_dec " ) ) ;
2014-02-19 06:35:38 +08:00
}
2014-02-14 07:11:45 +08:00
2013-05-14 02:22:55 +08:00
# else // __APPLE__
// Since DynamicLoaderDarwinKernel is compiled in for all systems, and relies on
// PlatformDarwinKernel for the plug-in name, we compile just the plug-in name in
// here to avoid issues. We are tracking an internal bug to resolve this issue by
// either not compiling in DynamicLoaderDarwinKernel for non-apple builds, or to make
// PlatformDarwinKernel build on all systems. PlatformDarwinKernel is currently not
// compiled on other platforms due to the use of the Mac-specific
// source/Host/macosx/cfcpp utilities.
lldb_private : : ConstString
PlatformDarwinKernel : : GetPluginNameStatic ( )
{
2013-05-14 05:52:06 +08:00
static lldb_private : : ConstString g_name ( " darwin-kernel " ) ;
2013-05-14 02:22:55 +08:00
return g_name ;
}
2013-04-05 09:03:25 +08:00
# endif // __APPLE__