23#include "llvm/ADT/DenseMap.h"
24#include "llvm/ADT/ScopeExit.h"
25#include "llvm/ADT/SmallString.h"
26#include "llvm/ADT/StringMap.h"
27#include "llvm/Support/FileSystem.h"
28#include "llvm/Support/Path.h"
29#include "llvm/Support/RWMutex.h"
30#include "llvm/Support/raw_ostream.h"
39#include <sys/sysctl.h>
40#include <sys/syslimits.h>
45#include <AvailabilityMacros.h>
46#include <CoreFoundation/CoreFoundation.h>
47#include <Foundation/Foundation.h>
48#include <Security/Security.h>
49#include <mach-o/dyld.h>
50#if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \
51 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_12_0
52#if __has_include(<mach-o/dyld_introspection.h>)
53#include <mach-o/dyld_introspection.h>
54#define SDK_HAS_NEW_DYLD_INTROSPECTION_SPIS
57#include <objc/objc-auto.h>
61#ifndef CPU_SUBTYPE_X86_64_H
62#define CPU_SUBTYPE_X86_64_H ((cpu_subtype_t)8)
65#define CPU_TYPE_ARM64 (CPU_TYPE_ARM | CPU_ARCH_ABI64)
68#ifndef CPU_TYPE_ARM64_32
69#define CPU_ARCH_ABI64_32 0x02000000
70#define CPU_TYPE_ARM64_32 (CPU_TYPE_ARM | CPU_ARCH_ABI64_32)
73#include <TargetConditionals.h>
79 int mib[2] = {CTL_KERN, KERN_OSVERSION};
81 size_t cstr_len =
sizeof(cstr);
82 if (::sysctl(mib, 2, cstr, &cstr_len, NULL, 0) == 0)
83 return std::string(cstr, cstr_len - 1);
90 NSDictionary *version_info =
91 [NSDictionary dictionaryWithContentsOfFile:
92 @"/System/Library/CoreServices/SystemVersion.plist"];
93 NSString *version_value = [version_info objectForKey: Key];
94 const char *version_str = [version_value UTF8String];
95 version.tryParse(version_str);
100 static llvm::VersionTuple g_version;
101 if (g_version.empty())
107 static llvm::VersionTuple g_version;
108 if (g_version.empty())
116 if (!g_program_filespec) {
119 uint32_t len =
sizeof(program_fullpath);
120 int err = _NSGetExecutablePath(program_fullpath, &len);
122 g_program_filespec.
SetFile(program_fullpath, FileSpec::Style::native);
123 else if (err == -1) {
124 char *large_program_fullpath = (
char *)::malloc(len + 1);
126 err = _NSGetExecutablePath(large_program_fullpath, &len);
128 g_program_filespec.
SetFile(large_program_fullpath,
129 FileSpec::Style::native);
131 ::free(large_program_fullpath);
134 return g_program_filespec;
148 std::string raw_path = lldb_file_spec.
GetPath();
150 size_t framework_pos = raw_path.find(
"LLDB.framework");
151 if (framework_pos != std::string::npos) {
152 framework_pos += strlen(
"LLDB.framework");
155 raw_path.resize(framework_pos);
158 raw_path.resize(framework_pos);
159 raw_path.append(
"/Resources");
171 FileSpec support_dir_spec_lib(raw_path);
177 support_dir_spec = support_dir_spec_bin;
179 support_dir_spec = support_dir_spec_lib;
182 LLDB_LOG(log,
"failed to find support directory");
188 char *
const dir_realpath =
189 realpath(support_dir_spec.
GetPath().c_str(), NULL);
191 raw_path = dir_realpath;
194 raw_path = support_dir_spec.
GetPath();
207 std::string raw_path = lldb_file_spec.
GetPath();
209 size_t framework_pos = raw_path.find(
"LLDB.framework");
210 if (framework_pos != std::string::npos) {
211 framework_pos += strlen(
"LLDB.framework");
212 raw_path.resize(framework_pos);
213 raw_path.append(
"/Headers");
224 std::string raw_path = lldb_file_spec.
GetPath();
226 size_t framework_pos = raw_path.find(
"LLDB.framework");
227 if (framework_pos == std::string::npos)
230 framework_pos += strlen(
"LLDB.framework");
231 raw_path.resize(framework_pos);
232 raw_path.append(
"/Resources/PlugIns");
247 uint32_t cputype, cpusubtype;
248 uint32_t is_64_bit_capable =
false;
249 size_t len =
sizeof(cputype);
253 if (::sysctlbyname(
"hw.cputype", &cputype, &len, NULL, 0) == 0) {
254 len =
sizeof(cpusubtype);
255 if (::sysctlbyname(
"hw.cpusubtype", &cpusubtype, &len, NULL, 0) != 0)
256 cpusubtype = CPU_TYPE_ANY;
258 len =
sizeof(is_64_bit_capable);
259 ::sysctlbyname(
"hw.cpu64bit_capable", &is_64_bit_capable, &len, NULL, 0);
261 if (cputype ==
CPU_TYPE_ARM64 && cpusubtype == CPU_SUBTYPE_ARM64E) {
264 cpusubtype = CPU_SUBTYPE_ARM64_ALL;
267 if (is_64_bit_capable) {
268 if (cputype & CPU_ARCH_ABI64) {
279 uint32_t cpusubtype32 = cpusubtype;
280#if defined(__i386__) || defined(__x86_64__)
282 cpusubtype32 = CPU_SUBTYPE_I386_ALL;
283#elif defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
285 cpusubtype32 = CPU_SUBTYPE_ARM_V7S;
290 if (cputype == CPU_TYPE_ARM ||
294#if defined(TARGET_OS_TV) && TARGET_OS_TV == 1
295 arch_32.
GetTriple().setOS(llvm::Triple::TvOS);
296 arch_64.
GetTriple().setOS(llvm::Triple::TvOS);
297#elif defined(TARGET_OS_BRIDGE) && TARGET_OS_BRIDGE == 1
298 arch_32.
GetTriple().setOS(llvm::Triple::BridgeOS);
299 arch_64.
GetTriple().setOS(llvm::Triple::BridgeOS);
300#elif defined(TARGET_OS_WATCHOS) && TARGET_OS_WATCHOS == 1
301 arch_32.
GetTriple().setOS(llvm::Triple::WatchOS);
302 arch_64.
GetTriple().setOS(llvm::Triple::WatchOS);
303#elif defined(TARGET_OS_XR) && TARGET_OS_XR == 1
304 arch_32.
GetTriple().setOS(llvm::Triple::XROS);
305 arch_64.
GetTriple().setOS(llvm::Triple::XROS);
306#elif defined(TARGET_OS_OSX) && TARGET_OS_OSX == 1
307 arch_32.
GetTriple().setOS(llvm::Triple::MacOSX);
308 arch_64.
GetTriple().setOS(llvm::Triple::MacOSX);
310 arch_32.
GetTriple().setOS(llvm::Triple::IOS);
311 arch_64.
GetTriple().setOS(llvm::Triple::IOS);
314 arch_32.
GetTriple().setOS(llvm::Triple::MacOSX);
315 arch_64.
GetTriple().setOS(llvm::Triple::MacOSX);
320#if defined(TARGET_OS_WATCH) && TARGET_OS_WATCH == 1
321 arch_32.
GetTriple().setOS(llvm::Triple::WatchOS);
323 arch_32.
GetTriple().setOS(llvm::Triple::IOS);
332 static std::string g_env_developer_dir;
333 static std::once_flag g_once_flag;
334 std::call_once(g_once_flag, [&]() {
335 if (
const char *developer_dir_env_var = getenv(
"DEVELOPER_DIR")) {
336 FileSpec fspec(developer_dir_env_var);
338 g_env_developer_dir = fspec.
GetPath();
340 return g_env_developer_dir;
344 static FileSpec g_xcode_contents_path;
345 static std::once_flag g_once_flag;
346 std::call_once(g_once_flag, [&]() {
348 if (
FileSpec fspec = HostInfo::GetShlibDir()) {
350 std::string xcode_contents_dir =
352 if (!xcode_contents_dir.empty()) {
353 g_xcode_contents_path =
FileSpec(xcode_contents_dir);
360 if (!env_developer_dir.empty()) {
361 llvm::sys::path::append(env_developer_dir,
"Contents");
362 std::string xcode_contents_dir =
364 if (!xcode_contents_dir.empty()) {
365 g_xcode_contents_path =
FileSpec(xcode_contents_dir);
370 auto sdk_path_or_err =
372 if (!sdk_path_or_err) {
375 "Error while searching for Xcode SDK: {0}");
381 std::string xcode_contents_dir =
383 if (!xcode_contents_dir.empty()) {
384 g_xcode_contents_path =
FileSpec(xcode_contents_dir);
390 return g_xcode_contents_path;
395 static llvm::once_flag g_once_flag;
396 llvm::call_once(g_once_flag, []() {
398 fspec.AppendPathComponent(
"Developer");
400 g_developer_directory = fspec;
403 return g_developer_directory;
407 llvm::StringRef component) {
408 auto begin = llvm::sys::path::begin(path);
409 auto end = llvm::sys::path::end(path);
410 for (
auto it = begin; it != end; ++it) {
411 if (it->contains(component)) {
412 llvm::SmallString<128> buffer;
413 llvm::sys::path::append(buffer, begin, ++it,
414 llvm::sys::path::Style::posix);
415 return buffer.str().str();
422 if (
FileSpec fspec = HostInfo::GetShlibDir())
428 if (
FileSpec fspec = HostInfo::GetShlibDir())
433static llvm::Expected<std::string>
434xcrun(
const std::string &sdk, llvm::ArrayRef<llvm::StringRef> arguments,
435 llvm::StringRef developer_dir =
"") {
437 if (!developer_dir.empty()) {
444 for (
auto arg: arguments)
451 LLDB_LOG(log,
"GetXcodeSDK() running shell cmd '{0}'", cmdstr);
456 std::string output_str;
459 auto timeout = std::chrono::seconds(60);
460 bool run_in_shell =
false;
463 nullptr, timeout, run_in_shell);
469 return error.ToError();
474 LLDB_LOG(log,
"xcrun returned exit code {0}", status);
475 if (!output_str.empty())
476 LLDB_LOG(log,
"xcrun output was:\n{0}", output_str);
479 if (output_str.empty()) {
480 LLDB_LOG(log,
"xcrun returned no results");
486 llvm::StringRef output(output_str);
489 output = output.rtrim();
492 const size_t last_newline = output.rfind(
'\n');
493 if (last_newline != llvm::StringRef::npos)
494 output = output.substr(last_newline + 1);
502 if (sdk_name.empty())
503 return llvm::createStringError(llvm::inconvertibleErrorCode(),
504 "Unrecognized SDK type: " + sdk.
GetString());
509 [](
const std::string &sdk_name) -> llvm::Expected<std::string> {
510 llvm::SmallVector<llvm::StringRef, 1> show_sdk_path = {
"--show-sdk-path"};
513 if (!developer_dir.empty()) {
515 return xcrun(sdk_name, show_sdk_path, developer_dir);
519 if (
FileSpec fspec = HostInfo::GetShlibDir()) {
521 llvm::SmallString<0> shlib_developer_dir(
523 llvm::sys::path::append(shlib_developer_dir,
"Developer");
525 auto sdk =
xcrun(sdk_name, show_sdk_path, shlib_developer_dir);
527 return sdk.takeError();
535 return xcrun(sdk_name, show_sdk_path);
538 auto path_or_err = find_sdk(sdk_name);
540 return path_or_err.takeError();
541 std::string path = *path_or_err;
542 while (path.empty()) {
546 llvm::StringRef fixed(sdk_name);
547 if (fixed.consume_back(
".internal"))
548 sdk_name = fixed.str() +
"internal";
549 path_or_err = find_sdk(sdk_name);
551 return path_or_err.takeError();
556 LLDB_LOG(log,
"Couldn't find SDK {0} on host", sdk_name);
562 path_or_err = find_sdk(sdk_name);
564 return path_or_err.takeError();
570 LLDB_LOG(log,
"Couldn't find any matching SDK on host");
576 LLDB_LOG(log,
"SDK returned by xcrun doesn't exist");
577 return llvm::createStringError(llvm::inconvertibleErrorCode(),
578 "SDK returned by xcrun doesn't exist");
590static llvm::Expected<llvm::StringRef>
593 std::function<llvm::Expected<std::string>(
void)> compute) {
594 std::lock_guard<std::mutex> guard(mutex);
597 auto it = cache.find(key);
598 if (it != cache.end()) {
599 if (it->second.is_error)
600 return llvm::createStringError(llvm::inconvertibleErrorCode(),
602 return it->second.str;
604 auto path_or_err = compute();
607 cache.insert({key, {
error,
true}});
608 return llvm::createStringError(llvm::inconvertibleErrorCode(),
error);
610 auto it_new = cache.insert({key, {*path_or_err,
false}});
611 return it_new.first->second.str;
615 static llvm::StringMap<ErrorOrPath> g_sdk_path;
616 static std::mutex g_sdk_path_mutex;
618 return llvm::createStringError(llvm::inconvertibleErrorCode(),
619 "XcodeSDK not specified");
627llvm::Expected<llvm::StringRef>
629 static llvm::StringMap<ErrorOrPath> g_tool_path;
630 static std::mutex g_tool_path_mutex;
632 llvm::raw_string_ostream(key) << sdk.
GetString() <<
":" << tool;
634 g_tool_path, g_tool_path_mutex, key,
635 [&]() -> llvm::Expected<std::string> {
637 if (sdk_name.empty())
638 return llvm::createStringError(llvm::inconvertibleErrorCode(),
639 "Unrecognized SDK type: " +
641 llvm::SmallVector<llvm::StringRef, 2> find = {
"-find", tool};
642 return xcrun(sdk_name, find);
647struct dyld_shared_cache_dylib_text_info {
650 uint64_t loadAddressUnslid;
651 uint64_t textSegmentSize;
655 uint64_t textSegmentOffset;
657typedef struct dyld_shared_cache_dylib_text_info
658 dyld_shared_cache_dylib_text_info;
670 void (^callback)(
const dyld_shared_cache_dylib_text_info *info));
674 void (^)(
const char *segmentName,
675 uint64_t vmAddr, uint64_t vmSize,
690class SharedCacheInfo {
692 SharedCacheImageInfo GetByFilename(UUID sc_uuid, ConstString filename) {
693 llvm::sys::ScopedReader guard(m_mutex);
695 sc_uuid = m_host_uuid;
696 if (!m_filename_map.contains(sc_uuid))
698 if (!m_filename_map[sc_uuid].contains(filename))
700 size_t idx = m_filename_map[sc_uuid][filename];
701 return m_file_infos[sc_uuid][idx];
704 SharedCacheImageInfo GetByUUID(UUID sc_uuid, UUID file_uuid) {
705 llvm::sys::ScopedReader guard(m_mutex);
707 sc_uuid = m_host_uuid;
708 if (!m_uuid_map.contains(sc_uuid))
710 if (!m_uuid_map[sc_uuid].contains(file_uuid))
712 size_t idx = m_uuid_map[sc_uuid][file_uuid];
713 return m_file_infos[sc_uuid][idx];
718 bool CreateSharedCacheImageList(UUID uuid, std::string filepath);
723 bool CreateSharedCacheInfoWithInstrospectionSPIs();
724 void CreateSharedCacheInfoLLDBsVirtualMemory();
725 bool CreateHostSharedCacheImageList();
730 llvm::SmallDenseMap<UUID, std::vector<SharedCacheImageInfo>> m_file_infos;
731 llvm::SmallDenseMap<UUID, llvm::DenseMap<ConstString, size_t>> m_filename_map;
732 llvm::SmallDenseMap<UUID, llvm::DenseMap<UUID, size_t>> m_uuid_map;
736 llvm::sys::RWMutex m_mutex;
739 void (*m_dyld_image_retain_4HWTrace)(
void *image);
740 void (*m_dyld_image_release_4HWTrace)(
void *image);
741 dispatch_data_t (*m_dyld_image_segment_data_4HWTrace)(
742 void *image,
const char *segmentName);
749 m_dyld_image_retain_4HWTrace =
750 (void (*)(
void *))dlsym(RTLD_DEFAULT,
"dyld_image_retain_4HWTrace");
751 m_dyld_image_release_4HWTrace =
752 (void (*)(
void *))dlsym(RTLD_DEFAULT,
"dyld_image_release_4HWTrace");
753 m_dyld_image_segment_data_4HWTrace =
754 (dispatch_data_t(*)(
void *image,
const char *segmentName))dlsym(
755 RTLD_DEFAULT,
"dyld_image_segment_data_4HWTrace");
759 m_host_uuid =
UUID(dsc_uuid);
767 bool use_libdyld_spi =
770 if (use_libdyld_spi && CreateHostSharedCacheImageList())
775 if (CreateSharedCacheInfoWithInstrospectionSPIs())
780 CreateSharedCacheInfoLLDBsVirtualMemory();
796 static std::mutex g_mutex;
797 std::lock_guard<std::mutex> guard(g_mutex);
799 static dispatch_data_t (*g_dyld_image_segment_data_4HWTrace)(
800 void *image,
const char *segmentName);
801 static std::once_flag g_once_flag;
802 std::call_once(g_once_flag, [&]() {
803 g_dyld_image_segment_data_4HWTrace =
804 (dispatch_data_t(*)(
void *,
const char *))dlsym(
805 RTLD_DEFAULT,
"dyld_image_segment_data_4HWTrace");
807 if (!g_dyld_image_segment_data_4HWTrace)
810 __block std::vector<segment> segments;
814 ^(
const char *segmentName, uint64_t vmAddr, uint64_t vmSize,
int perm) {
816 seg.
name = segmentName;
820 dispatch_data_t data_from_libdyld =
821 g_dyld_image_segment_data_4HWTrace(image_copy, segmentName);
822 (void)dispatch_data_create_map(data_from_libdyld, &seg.
data, &seg.
size);
825 segments.push_back(seg);
828 if (!segments.size())
833 "map_shared_cache_binary_segments() mapping segments of "
834 "dyld_image_t %p into lldb address space",
836 for (
const segment &seg : segments) {
838 log,
"image %p %s vmaddr 0x%llx vmsize 0x%zx mapped to lldb vm addr %p",
839 image, seg.name.c_str(), seg.vmaddr, seg.vmsize, seg.data);
846 uint64_t max_lldb_vm_addr = 0;
852 for (
const segment &seg : segments) {
853 min_lldb_vm_addr = std::min(min_lldb_vm_addr, (uint64_t)seg.data);
855 std::max(max_lldb_vm_addr, (uint64_t)seg.data + seg.vmsize);
856 min_file_vm_addr = std::min(min_file_vm_addr, (uint64_t)seg.vmaddr);
858 DataBufferSP data_sp = std::make_shared<DataBufferUnowned>(
859 (uint8_t *)min_lldb_vm_addr, max_lldb_vm_addr - min_lldb_vm_addr);
861 for (
const segment &seg : segments)
863 (uint64_t)seg.vmaddr - min_file_vm_addr, (uint64_t)seg.vmsize,
864 (uint64_t)seg.data - (uint64_t)min_lldb_vm_addr));
866 return std::make_shared<VirtualDataExtractor>(data_sp, remap_table);
872bool SharedCacheInfo::CreateSharedCacheImageList(
UUID sc_uuid,
873 std::string filepath) {
874 llvm::sys::ScopedWriter guard(m_mutex);
875 if (!m_dyld_image_retain_4HWTrace || !m_dyld_image_release_4HWTrace ||
876 !m_dyld_image_segment_data_4HWTrace)
879 if (filepath.empty())
885 if (m_file_infos.contains(sc_uuid)) {
886 LLDB_LOGF(log,
"Have already indexed shared cache UUID %s",
891 LLDB_LOGF(log,
"Opening shared cache at %s to check for matching UUID %s",
894 __block
bool return_failed =
false;
897 dyld_shared_cache_copy_uuid(cache, &uuid);
898 UUID this_cache(uuid, sizeof(uuid_t));
899 if (this_cache != sc_uuid) {
900 return_failed = true;
905 m_file_infos[sc_uuid].reserve(4000);
920 m_dyld_image_retain_4HWTrace(image);
930 size_t file_info_size = m_file_infos[sc_uuid].size();
931 for (
size_t i = 0; i < file_info_size; i++) {
934 m_uuid_map[sc_uuid][entry->
GetUUID()] = i;
942bool SharedCacheInfo::CreateHostSharedCacheImageList() {
944 __block
UUID host_sc_uuid;
948 dyld_shared_cache_copy_uuid(cache, &sc_uuid);
949 host_sc_uuid = UUID(sc_uuid, sizeof(uuid_t));
952 if (host_sc_uuid.IsValid())
953 return CreateSharedCacheImageList(host_sc_uuid, host_shared_cache_file);
961bool SharedCacheInfo::CreateSharedCacheInfoWithInstrospectionSPIs() {
962 llvm::sys::ScopedWriter guard(m_mutex);
963#if defined(SDK_HAS_NEW_DYLD_INTROSPECTION_SPIS)
964 dyld_process_t dyld_process = dyld_process_create_for_current_task();
968 llvm::scope_exit cleanup_process_on_exit(
969 [&]() { dyld_process_dispose(dyld_process); });
972 dyld_process_snapshot_create_for_process(dyld_process,
nullptr);
976 llvm::scope_exit cleanup_snapshot_on_exit(
977 [&]() { dyld_process_snapshot_dispose(snapshot); });
980 dyld_process_snapshot_get_shared_cache(snapshot);
985 m_file_infos[m_host_uuid].reserve(4000);
989 __block uint64_t maxVmAddr = 0;
991 __block
uuid_t *uuid = &uuidStore;
995 ^(
const char *segmentName, uint64_t vmAddr, uint64_t vmSize,
int perm) {
996 minVmAddr = std::min(minVmAddr, vmAddr);
997 maxVmAddr = std::max(maxVmAddr, vmAddr + vmSize);
1000 assert(minVmAddr != UINT_MAX);
1001 assert(maxVmAddr != 0);
1003 (uint8_t *)minVmAddr, maxVmAddr - minVmAddr);
1008 m_file_infos[m_host_uuid].push_back(
1014 size_t file_info_size = m_file_infos[m_host_uuid].size();
1015 for (
size_t i = 0; i < file_info_size; i++) {
1017 m_filename_map[m_host_uuid][entry->
GetFilename()] = i;
1018 m_uuid_map[m_host_uuid][entry->
GetUUID()] = i;
1028void SharedCacheInfo::CreateSharedCacheInfoLLDBsVirtualMemory() {
1029 llvm::sys::ScopedWriter guard(m_mutex);
1030 size_t shared_cache_size;
1031 uint8_t *shared_cache_start =
1035 m_file_infos[m_host_uuid].reserve(4000);
1038 m_host_uuid.GetBytes().data(),
1039 ^(
const dyld_shared_cache_dylib_text_info *info) {
1040 lldb::DataBufferSP buffer_sp = std::make_shared<DataBufferUnowned>(
1041 shared_cache_start + info->textSegmentOffset,
1042 shared_cache_size - info->textSegmentOffset);
1043 lldb::DataExtractorSP extractor_sp =
1044 std::make_shared<DataExtractor>(buffer_sp);
1045 ConstString filepath(info->path);
1046 m_file_infos[m_host_uuid].push_back(SharedCacheImageInfo(
1047 filepath, UUID(info->dylibUuid, 16), extractor_sp));
1052 size_t file_info_size = m_file_infos[m_host_uuid].size();
1053 for (
size_t i = 0; i < file_info_size; i++) {
1055 m_filename_map[m_host_uuid][entry->
GetFilename()] = i;
1056 m_uuid_map[m_host_uuid][entry->
GetUUID()] = i;
1061 static SharedCacheInfo g_shared_cache_info(sc_mode);
1062 return g_shared_cache_info;
1103 std::string path = bundle_path.
GetPath();
1104 CFURLRef url = CFURLCreateFromFileSystemRepresentation(
1105 kCFAllocatorDefault,
reinterpret_cast<const UInt8 *
>(path.data()),
1109 auto url_cleanup = llvm::make_scope_exit([&]() { CFRelease(url); });
1111 SecStaticCodeRef static_code =
nullptr;
1112 if (SecStaticCodeCreateWithPath(url, kSecCSDefaultFlags, &static_code) !=
1115 auto code_cleanup = llvm::make_scope_exit([&]() { CFRelease(static_code); });
1118 SecRequirementRef requirement =
nullptr;
1119 if (SecRequirementCreateWithString(CFSTR(
"anchor trusted"),
1121 &requirement) != errSecSuccess)
1123 auto req_cleanup = llvm::make_scope_exit([&]() { CFRelease(requirement); });
1125 return SecStaticCodeCheckValidity(static_code, kSecCSDefaultFlags,
1126 requirement) == errSecSuccess;
static llvm::raw_ostream & error(Stream &strm)
void dyld_shared_cache_copy_uuid(dyld_shared_cache_t cache, uuid_t *uuid)
struct dyld_process_s * dyld_process_t
struct dyld_image_s * dyld_image_t
bool dyld_image_for_each_segment_info(dyld_image_t image, void(^)(const char *segmentName, uint64_t vmAddr, uint64_t vmSize, int perm))
struct dyld_shared_cache_s * dyld_shared_cache_t
#define CPU_SUBTYPE_X86_64_H
static llvm::Expected< std::string > GetXcodeSDK(XcodeSDK sdk)
const char * dyld_image_get_file_path(dyld_image_t image)
struct dyld_process_snapshot_s * dyld_process_snapshot_t
static llvm::Expected< std::string > xcrun(const std::string &sdk, llvm::ArrayRef< llvm::StringRef > arguments, llvm::StringRef developer_dir="")
uint64_t dyld_shared_cache_get_base_address(dyld_shared_cache_t cache)
static DataExtractorSP map_shared_cache_binary_segments(void *image)
uint8_t * _dyld_get_shared_cache_range(size_t *length)
bool dyld_image_copy_uuid(dyld_image_t cache, uuid_t *uuid)
const char * dyld_image_get_installname(dyld_image_t image)
static std::string GetEnvDeveloperDir()
Return and cache $DEVELOPER_DIR if it is set and exists.
const char * dyld_shared_cache_file_path(void)
void dyld_shared_cache_for_each_image(dyld_shared_cache_t cache, void(^block)(dyld_image_t image))
static llvm::Expected< llvm::StringRef > find_cached_path(llvm::StringMap< ErrorOrPath > &cache, std::mutex &mutex, llvm::StringRef key, std::function< llvm::Expected< std::string >(void)> compute)
static bool ResolveAndVerifyCandidateSupportDir(FileSpec &path)
Resolve the given candidate support dir and return true if it's valid.
bool dyld_shared_cache_for_file(const char *filePath, void(^block)(dyld_shared_cache_t cache))
int dyld_shared_cache_iterate_text(const uuid_t cacheUuid, void(^callback)(const dyld_shared_cache_dylib_text_info *info))
SharedCacheInfo & GetSharedCacheSingleton(SymbolSharedCacheUse sc_mode)
#define CPU_TYPE_ARM64_32
bool _dyld_get_shared_cache_uuid(uuid_t uuid)
static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGF_VERBOSE(log,...)
#define LLDB_LOGF(log,...)
#define LLDB_LOG_ERROR(log, error,...)
#define LLDB_SCOPED_TIMER()
An architecture specification class.
void Clear()
Clears the object state.
llvm::Triple & GetTriple()
Architecture triple accessor.
bool SetArchitecture(ArchitectureType arch_type, uint32_t cpu, uint32_t sub, uint32_t os=0)
Change the architecture object type, CPU type and OS type.
A command line argument class.
void AppendArgument(llvm::StringRef arg_str, char quote_char='\0')
Appends a new argument to the end of the list argument list.
bool GetCommandString(std::string &command) const
A uniqued constant string class.
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
FileSpec CopyByAppendingPathComponent(llvm::StringRef component) const
void AppendPathComponent(llvm::StringRef component)
void SetDirectory(ConstString directory)
Directory string set accessor.
const ConstString & GetDirectory() const
Directory string const get accessor.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
ConstString GetPathAsConstString(bool denormalize=true) const
Get the full path as a ConstString.
bool IsDirectory(const FileSpec &file_spec) const
Returns whether the given path is a directory.
static FileSystem & Instance()
void Resolve(llvm::SmallVectorImpl< char > &path, bool force_make_absolute=false)
Resolve path to make it canonical.
static FileSpec GetShlibDir()
Returns the directory containing the lldb shared library.
static FileSpec GetUserHomeDir()
Returns the directory containing the users home (e.g.
static llvm::Expected< llvm::StringRef > GetSDKRoot(SDKOptions options)
Query xcrun to find an Xcode SDK directory.
static bool IsBundleCodeSignTrusted(const FileSpec &bundle_path)
Check whether a bundle at the given path has a valid code signature that chains to a trusted anchor i...
static bool SharedCacheIndexFiles(FileSpec &filepath, UUID &uuid, lldb::SymbolSharedCacheUse sc_mode)
static FileSpec GetProgramFileSpec()
static std::optional< std::string > GetOSBuildString()
static FileSpec GetCurrentXcodeToolchainDirectory()
static SharedCacheImageInfo GetSharedCacheImageInfo(ConstString filepath, lldb::SymbolSharedCacheUse sc_mode)
Shared cache utilities.
static FileSpec GetXcodeContentsDirectory()
static bool ComputeSupportExeDirectory(FileSpec &file_spec)
static std::string FindComponentInPath(llvm::StringRef path, llvm::StringRef component)
static void ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64)
static bool ComputeUserPluginsDirectory(FileSpec &file_spec)
static FileSpec GetCurrentCommandLineToolsDirectory()
static llvm::VersionTuple GetMacCatalystVersion()
static bool ComputeSystemPluginsDirectory(FileSpec &file_spec)
static bool ComputeHeaderDirectory(FileSpec &file_spec)
static FileSpec GetXcodeDeveloperDirectory()
static llvm::VersionTuple GetOSVersion()
static llvm::Expected< llvm::StringRef > FindSDKTool(XcodeSDK sdk, llvm::StringRef tool)
static Status RunShellCommand(llvm::StringRef command, const FileSpec &working_dir, int *status_ptr, int *signo_ptr, std::string *command_output, std::string *error_output, const Timeout< std::micro > &timeout, bool run_in_shell=true)
Run a shell command.
RangeData< lldb::offset_t, lldb::offset_t, lldb::offset_t > Entry
void Append(const Entry &entry)
Represents UUID's of various sizes.
std::string GetAsString(llvm::StringRef separator="-") const
An abstraction for Xcode-style SDKs that works like ArchSpec.
static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path)
static XcodeSDK GetAnyMacOS()
llvm::StringRef GetString() const
static std::string GetCanonicalName(Info info)
Return the canonical SDK name, such as "macosx" for the macOS SDK.
Info Parse() const
Return parsed SDK type and version number.
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
std::string toString(FormatterBytecode::OpCodes op)
@ eSymbolSharedCacheUseHostSharedCache
@ eSymbolSharedCacheUseInferiorSharedCacheOnly
@ eSymbolSharedCacheUseHostLLDBMemory
@ eSymbolSharedCacheUseHostAndInferiorSharedCache
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::optional< XcodeSDK > XcodeSDKSelection
ConstString GetFilename() const
const UUID & GetUUID() const
A parsed SDK directory name.
llvm::VersionTuple version