LLDB mainline
HostInfoMacOSX.mm
Go to the documentation of this file.
1//===-- HostInfoMacOSX.mm ---------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
11#include "lldb/Host/Host.h"
12#include "lldb/Host/HostInfo.h"
13#include "lldb/Utility/Args.h"
18#include "lldb/Utility/Log.h"
19#include "lldb/Utility/Timer.h"
21
22#include "llvm/ADT/DenseMap.h"
23#include "llvm/ADT/ScopeExit.h"
24#include "llvm/ADT/SmallString.h"
25#include "llvm/ADT/StringMap.h"
26#include "llvm/Support/FileSystem.h"
27#include "llvm/Support/Path.h"
28#include "llvm/Support/RWMutex.h"
29#include "llvm/Support/raw_ostream.h"
30
31// C++ Includes
32#include <optional>
33#include <string>
34
35// C inclues
36#include <cstdlib>
37#include <dlfcn.h>
38#include <sys/sysctl.h>
39#include <sys/syslimits.h>
40#include <sys/types.h>
41#include <uuid/uuid.h>
42
43// Objective-C/C++ includes
44#include <AvailabilityMacros.h>
45#include <CoreFoundation/CoreFoundation.h>
46#include <Foundation/Foundation.h>
47#include <Security/Security.h>
48#include <mach-o/dyld.h>
49#if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \
50 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_12_0
51#if __has_include(<mach-o/dyld_introspection.h>)
52#include <mach-o/dyld_introspection.h>
53#define SDK_HAS_NEW_DYLD_INTROSPECTION_SPIS
54#endif
55#endif
56#include <objc/objc-auto.h>
57
58// These are needed when compiling on systems
59// that do not yet have these definitions
60#ifndef CPU_SUBTYPE_X86_64_H
61#define CPU_SUBTYPE_X86_64_H ((cpu_subtype_t)8)
62#endif
63#ifndef CPU_TYPE_ARM64
64#define CPU_TYPE_ARM64 (CPU_TYPE_ARM | CPU_ARCH_ABI64)
65#endif
66
67#ifndef CPU_TYPE_ARM64_32
68#define CPU_ARCH_ABI64_32 0x02000000
69#define CPU_TYPE_ARM64_32 (CPU_TYPE_ARM | CPU_ARCH_ABI64_32)
70#endif
71
72#include <TargetConditionals.h> // for TARGET_OS_TV, TARGET_OS_WATCH
73
74using namespace lldb;
75using namespace lldb_private;
76
77std::optional<std::string> HostInfoMacOSX::GetOSBuildString() {
78 int mib[2] = {CTL_KERN, KERN_OSVERSION};
79 char cstr[PATH_MAX];
80 size_t cstr_len = sizeof(cstr);
81 if (::sysctl(mib, 2, cstr, &cstr_len, NULL, 0) == 0)
82 return std::string(cstr, cstr_len - 1);
83
84 return std::nullopt;
85}
86
87static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
88 @autoreleasepool {
89 NSDictionary *version_info =
90 [NSDictionary dictionaryWithContentsOfFile:
91 @"/System/Library/CoreServices/SystemVersion.plist"];
92 NSString *version_value = [version_info objectForKey: Key];
93 const char *version_str = [version_value UTF8String];
94 version.tryParse(version_str);
95 }
96}
97
98llvm::VersionTuple HostInfoMacOSX::GetOSVersion() {
99 static llvm::VersionTuple g_version;
100 if (g_version.empty())
101 ParseOSVersion(g_version, @"ProductVersion");
102 return g_version;
103}
104
106 static llvm::VersionTuple g_version;
107 if (g_version.empty())
108 ParseOSVersion(g_version, @"iOSSupportVersion");
109 return g_version;
110}
111
112
114 static FileSpec g_program_filespec;
115 if (!g_program_filespec) {
116 char program_fullpath[PATH_MAX];
117 // If DST is NULL, then return the number of bytes needed.
118 uint32_t len = sizeof(program_fullpath);
119 int err = _NSGetExecutablePath(program_fullpath, &len);
120 if (err == 0)
121 g_program_filespec.SetFile(program_fullpath, FileSpec::Style::native);
122 else if (err == -1) {
123 char *large_program_fullpath = (char *)::malloc(len + 1);
124
125 err = _NSGetExecutablePath(large_program_fullpath, &len);
126 if (err == 0)
127 g_program_filespec.SetFile(large_program_fullpath,
128 FileSpec::Style::native);
129
130 ::free(large_program_fullpath);
131 }
132 }
133 return g_program_filespec;
134}
135
136/// Resolve the given candidate support dir and return true if it's valid.
141
143 FileSpec lldb_file_spec = GetShlibDir();
144 if (!lldb_file_spec)
145 return false;
146
147 std::string raw_path = lldb_file_spec.GetPath();
148
149 size_t framework_pos = raw_path.find("LLDB.framework");
150 if (framework_pos != std::string::npos) {
151 framework_pos += strlen("LLDB.framework");
152#if TARGET_OS_IPHONE
153 // Shallow bundle
154 raw_path.resize(framework_pos);
155#else
156 // Normal bundle
157 raw_path.resize(framework_pos);
158 raw_path.append("/Resources");
159#endif
160 } else {
161 // Find the bin path relative to the lib path where the cmake-based
162 // OS X .dylib lives. We try looking first at a possible sibling `bin`
163 // directory, and then at the `lib` directory itself. This last case is
164 // useful for supporting build systems like Bazel which in many cases prefer
165 // to place support binaries right next to dylibs.
166 //
167 // It is not going to work to do it by the executable path,
168 // as in the case of a python script, the executable is python, not
169 // the lldb driver.
170 FileSpec support_dir_spec_lib(raw_path);
171 FileSpec support_dir_spec_bin =
172 support_dir_spec_lib.CopyByAppendingPathComponent("/../bin");
173 FileSpec support_dir_spec;
174
175 if (ResolveAndVerifyCandidateSupportDir(support_dir_spec_bin)) {
176 support_dir_spec = support_dir_spec_bin;
177 } else if (ResolveAndVerifyCandidateSupportDir(support_dir_spec_lib)) {
178 support_dir_spec = support_dir_spec_lib;
179 } else {
180 Log *log = GetLog(LLDBLog::Host);
181 LLDB_LOG(log, "failed to find support directory");
182 return false;
183 }
184
185 // Get normalization from support_dir_spec. Note the FileSpec resolve
186 // does not remove '..' in the path.
187 char *const dir_realpath =
188 realpath(support_dir_spec.GetPath().c_str(), NULL);
189 if (dir_realpath) {
190 raw_path = dir_realpath;
191 free(dir_realpath);
192 } else {
193 raw_path = support_dir_spec.GetPath();
194 }
195 }
196
197 file_spec.SetDirectory(raw_path);
198 return (bool)file_spec.GetDirectory();
199}
200
202 FileSpec lldb_file_spec = GetShlibDir();
203 if (!lldb_file_spec)
204 return false;
205
206 std::string raw_path = lldb_file_spec.GetPath();
207
208 size_t framework_pos = raw_path.find("LLDB.framework");
209 if (framework_pos != std::string::npos) {
210 framework_pos += strlen("LLDB.framework");
211 raw_path.resize(framework_pos);
212 raw_path.append("/Headers");
213 }
214 file_spec.SetDirectory(raw_path);
215 return true;
216}
217
219 FileSpec lldb_file_spec = GetShlibDir();
220 if (!lldb_file_spec)
221 return false;
222
223 std::string raw_path = lldb_file_spec.GetPath();
224
225 size_t framework_pos = raw_path.find("LLDB.framework");
226 if (framework_pos == std::string::npos)
227 return false;
228
229 framework_pos += strlen("LLDB.framework");
230 raw_path.resize(framework_pos);
231 raw_path.append("/Resources/PlugIns");
232 file_spec.SetDirectory(raw_path);
233 return true;
234}
235
237 FileSpec home_dir_spec = GetUserHomeDir();
238 home_dir_spec.AppendPathComponent("Library/Application Support/LLDB/PlugIns");
239 file_spec.SetDirectory(home_dir_spec.GetPathAsConstString());
240 return true;
241}
242
244 ArchSpec &arch_64) {
245 // All apple systems support 32 bit execution.
246 uint32_t cputype, cpusubtype;
247 uint32_t is_64_bit_capable = false;
248 size_t len = sizeof(cputype);
249 ArchSpec host_arch;
250 // These will tell us about the kernel architecture, which even on a 64
251 // bit machine can be 32 bit...
252 if (::sysctlbyname("hw.cputype", &cputype, &len, NULL, 0) == 0) {
253 len = sizeof(cpusubtype);
254 if (::sysctlbyname("hw.cpusubtype", &cpusubtype, &len, NULL, 0) != 0)
255 cpusubtype = CPU_TYPE_ANY;
256
257 len = sizeof(is_64_bit_capable);
258 ::sysctlbyname("hw.cpu64bit_capable", &is_64_bit_capable, &len, NULL, 0);
259
260 if (cputype == CPU_TYPE_ARM64 && cpusubtype == CPU_SUBTYPE_ARM64E) {
261 // The arm64e architecture is a preview. Pretend the host architecture
262 // is arm64.
263 cpusubtype = CPU_SUBTYPE_ARM64_ALL;
264 }
265
266 if (is_64_bit_capable) {
267 if (cputype & CPU_ARCH_ABI64) {
268 // We have a 64 bit kernel on a 64 bit system
269 arch_64.SetArchitecture(eArchTypeMachO, cputype, cpusubtype);
270 } else {
271 // We have a 64 bit kernel that is returning a 32 bit cputype, the
272 // cpusubtype will be correct as if it were for a 64 bit architecture
273 arch_64.SetArchitecture(eArchTypeMachO, cputype | CPU_ARCH_ABI64,
274 cpusubtype);
275 }
276
277 // Now we need modify the cpusubtype for the 32 bit slices.
278 uint32_t cpusubtype32 = cpusubtype;
279#if defined(__i386__) || defined(__x86_64__)
280 if (cpusubtype == CPU_SUBTYPE_486 || cpusubtype == CPU_SUBTYPE_X86_64_H)
281 cpusubtype32 = CPU_SUBTYPE_I386_ALL;
282#elif defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
283 if (cputype == CPU_TYPE_ARM || cputype == CPU_TYPE_ARM64)
284 cpusubtype32 = CPU_SUBTYPE_ARM_V7S;
285#endif
286 arch_32.SetArchitecture(eArchTypeMachO, cputype & ~(CPU_ARCH_MASK),
287 cpusubtype32);
288
289 if (cputype == CPU_TYPE_ARM ||
290 cputype == CPU_TYPE_ARM64 ||
291 cputype == CPU_TYPE_ARM64_32) {
292// When running on a watch or tv, report the host os correctly
293#if defined(TARGET_OS_TV) && TARGET_OS_TV == 1
294 arch_32.GetTriple().setOS(llvm::Triple::TvOS);
295 arch_64.GetTriple().setOS(llvm::Triple::TvOS);
296#elif defined(TARGET_OS_BRIDGE) && TARGET_OS_BRIDGE == 1
297 arch_32.GetTriple().setOS(llvm::Triple::BridgeOS);
298 arch_64.GetTriple().setOS(llvm::Triple::BridgeOS);
299#elif defined(TARGET_OS_WATCHOS) && TARGET_OS_WATCHOS == 1
300 arch_32.GetTriple().setOS(llvm::Triple::WatchOS);
301 arch_64.GetTriple().setOS(llvm::Triple::WatchOS);
302#elif defined(TARGET_OS_XR) && TARGET_OS_XR == 1
303 arch_32.GetTriple().setOS(llvm::Triple::XROS);
304 arch_64.GetTriple().setOS(llvm::Triple::XROS);
305#elif defined(TARGET_OS_OSX) && TARGET_OS_OSX == 1
306 arch_32.GetTriple().setOS(llvm::Triple::MacOSX);
307 arch_64.GetTriple().setOS(llvm::Triple::MacOSX);
308#else
309 arch_32.GetTriple().setOS(llvm::Triple::IOS);
310 arch_64.GetTriple().setOS(llvm::Triple::IOS);
311#endif
312 } else {
313 arch_32.GetTriple().setOS(llvm::Triple::MacOSX);
314 arch_64.GetTriple().setOS(llvm::Triple::MacOSX);
315 }
316 } else {
317 // We have a 32 bit kernel on a 32 bit system
318 arch_32.SetArchitecture(eArchTypeMachO, cputype, cpusubtype);
319#if defined(TARGET_OS_WATCH) && TARGET_OS_WATCH == 1
320 arch_32.GetTriple().setOS(llvm::Triple::WatchOS);
321#else
322 arch_32.GetTriple().setOS(llvm::Triple::IOS);
323#endif
324 arch_64.Clear();
325 }
326 }
327}
328
329/// Return and cache $DEVELOPER_DIR if it is set and exists.
330static std::string GetEnvDeveloperDir() {
331 static std::string g_env_developer_dir;
332 static std::once_flag g_once_flag;
333 std::call_once(g_once_flag, [&]() {
334 if (const char *developer_dir_env_var = getenv("DEVELOPER_DIR")) {
335 FileSpec fspec(developer_dir_env_var);
336 if (FileSystem::Instance().Exists(fspec))
337 g_env_developer_dir = fspec.GetPath();
338 }});
339 return g_env_developer_dir;
340}
341
343 static FileSpec g_xcode_contents_path;
344 static std::once_flag g_once_flag;
345 std::call_once(g_once_flag, [&]() {
346 // Try the shlib dir first.
347 if (FileSpec fspec = HostInfo::GetShlibDir()) {
348 if (FileSystem::Instance().Exists(fspec)) {
349 std::string xcode_contents_dir =
351 if (!xcode_contents_dir.empty()) {
352 g_xcode_contents_path = FileSpec(xcode_contents_dir);
353 return;
354 }
355 }
356 }
357
358 llvm::SmallString<128> env_developer_dir(GetEnvDeveloperDir());
359 if (!env_developer_dir.empty()) {
360 llvm::sys::path::append(env_developer_dir, "Contents");
361 std::string xcode_contents_dir =
363 if (!xcode_contents_dir.empty()) {
364 g_xcode_contents_path = FileSpec(xcode_contents_dir);
365 return;
366 }
367 }
368
369 auto sdk_path_or_err =
370 HostInfo::GetSDKRoot(SDKOptions{XcodeSDK::GetAnyMacOS()});
371 if (!sdk_path_or_err) {
372 Log *log = GetLog(LLDBLog::Host);
373 LLDB_LOG_ERROR(log, sdk_path_or_err.takeError(),
374 "Error while searching for Xcode SDK: {0}");
375 return;
376 }
377 FileSpec fspec(*sdk_path_or_err);
378 if (fspec) {
379 if (FileSystem::Instance().Exists(fspec)) {
380 std::string xcode_contents_dir =
382 if (!xcode_contents_dir.empty()) {
383 g_xcode_contents_path = FileSpec(xcode_contents_dir);
384 return;
385 }
386 }
387 }
388 });
389 return g_xcode_contents_path;
390}
391
393 static lldb_private::FileSpec g_developer_directory;
394 static llvm::once_flag g_once_flag;
395 llvm::call_once(g_once_flag, []() {
396 if (FileSpec fspec = GetXcodeContentsDirectory()) {
397 fspec.AppendPathComponent("Developer");
398 if (FileSystem::Instance().Exists(fspec))
399 g_developer_directory = fspec;
400 }
401 });
402 return g_developer_directory;
403}
404
405std::string HostInfoMacOSX::FindComponentInPath(llvm::StringRef path,
406 llvm::StringRef component) {
407 auto begin = llvm::sys::path::begin(path);
408 auto end = llvm::sys::path::end(path);
409 for (auto it = begin; it != end; ++it) {
410 if (it->contains(component)) {
411 llvm::SmallString<128> buffer;
412 llvm::sys::path::append(buffer, begin, ++it,
413 llvm::sys::path::Style::posix);
414 return buffer.str().str();
415 }
416 }
417 return {};
418}
419
421 if (FileSpec fspec = HostInfo::GetShlibDir())
422 return FileSpec(FindComponentInPath(fspec.GetPath(), ".xctoolchain"));
423 return {};
424}
425
427 if (FileSpec fspec = HostInfo::GetShlibDir())
428 return FileSpec(FindComponentInPath(fspec.GetPath(), "CommandLineTools"));
429 return {};
430}
431
432static llvm::Expected<std::string>
433xcrun(const std::string &sdk, llvm::ArrayRef<llvm::StringRef> arguments,
434 llvm::StringRef developer_dir = "") {
435 Args args;
436 if (!developer_dir.empty()) {
437 args.AppendArgument("/usr/bin/env");
438 args.AppendArgument("DEVELOPER_DIR=" + developer_dir.str());
439 }
440 args.AppendArgument("/usr/bin/xcrun");
441 args.AppendArgument("--sdk");
442 args.AppendArgument(sdk);
443 for (auto arg: arguments)
444 args.AppendArgument(arg);
445
446 Log *log = GetLog(LLDBLog::Host);
447 if (log) {
448 std::string cmdstr;
449 args.GetCommandString(cmdstr);
450 LLDB_LOG(log, "GetXcodeSDK() running shell cmd '{0}'", cmdstr);
451 }
452
453 int status = 0;
454 int signo = 0;
455 std::string output_str;
456 // The first time after Xcode was updated or freshly installed,
457 // xcrun can take surprisingly long to build up its database.
458 auto timeout = std::chrono::seconds(60);
459 bool run_in_shell = false;
461 Host::RunShellCommand(args, FileSpec(), &status, &signo, &output_str,
462 nullptr, timeout, run_in_shell);
463
464 // Check that xcrun returned something useful.
465 if (error.Fail()) {
466 // Catastrophic error.
467 LLDB_LOG(log, "xcrun failed to execute: {0}", error);
468 return error.ToError();
469 }
470 if (status != 0) {
471 // xcrun didn't find a matching SDK. Not an error, we'll try
472 // different spellings.
473 LLDB_LOG(log, "xcrun returned exit code {0}", status);
474 if (!output_str.empty())
475 LLDB_LOG(log, "xcrun output was:\n{0}", output_str);
476 return "";
477 }
478 if (output_str.empty()) {
479 LLDB_LOG(log, "xcrun returned no results");
480 return "";
481 }
482
483 // Convert to a StringRef so we can manipulate the string without modifying
484 // the underlying data.
485 llvm::StringRef output(output_str);
486
487 // Remove any trailing newline characters.
488 output = output.rtrim();
489
490 // Strip any leading newline characters and everything before them.
491 const size_t last_newline = output.rfind('\n');
492 if (last_newline != llvm::StringRef::npos)
493 output = output.substr(last_newline + 1);
494
495 return output.str();
496}
497
498static llvm::Expected<std::string> GetXcodeSDK(XcodeSDK sdk) {
499 XcodeSDK::Info info = sdk.Parse();
500 std::string sdk_name = XcodeSDK::GetCanonicalName(info);
501 if (sdk_name.empty())
502 return llvm::createStringError(llvm::inconvertibleErrorCode(),
503 "Unrecognized SDK type: " + sdk.GetString());
504
505 Log *log = GetLog(LLDBLog::Host);
506
507 auto find_sdk =
508 [](const std::string &sdk_name) -> llvm::Expected<std::string> {
509 llvm::SmallVector<llvm::StringRef, 1> show_sdk_path = {"--show-sdk-path"};
510 // Invoke xcrun with the developer dir specified in the environment.
511 std::string developer_dir = GetEnvDeveloperDir();
512 if (!developer_dir.empty()) {
513 // Don't fallback if DEVELOPER_DIR was set.
514 return xcrun(sdk_name, show_sdk_path, developer_dir);
515 }
516
517 // Invoke xcrun with the shlib dir.
518 if (FileSpec fspec = HostInfo::GetShlibDir()) {
519 if (FileSystem::Instance().Exists(fspec)) {
520 llvm::SmallString<0> shlib_developer_dir(
522 llvm::sys::path::append(shlib_developer_dir, "Developer");
523 if (FileSystem::Instance().Exists(shlib_developer_dir)) {
524 auto sdk = xcrun(sdk_name, show_sdk_path, shlib_developer_dir);
525 if (!sdk)
526 return sdk.takeError();
527 if (!sdk->empty())
528 return sdk;
529 }
530 }
531 }
532
533 // Invoke xcrun without a developer dir as a last resort.
534 return xcrun(sdk_name, show_sdk_path);
535 };
536
537 auto path_or_err = find_sdk(sdk_name);
538 if (!path_or_err)
539 return path_or_err.takeError();
540 std::string path = *path_or_err;
541 while (path.empty()) {
542 // Try an alternate spelling of the name ("macosx10.9internal").
543 if (info.type == XcodeSDK::Type::MacOSX && !info.version.empty() &&
544 info.internal) {
545 llvm::StringRef fixed(sdk_name);
546 if (fixed.consume_back(".internal"))
547 sdk_name = fixed.str() + "internal";
548 path_or_err = find_sdk(sdk_name);
549 if (!path_or_err)
550 return path_or_err.takeError();
551 path = *path_or_err;
552 if (!path.empty())
553 break;
554 }
555 LLDB_LOG(log, "Couldn't find SDK {0} on host", sdk_name);
556
557 // Try without the version.
558 if (!info.version.empty()) {
559 info.version = {};
560 sdk_name = XcodeSDK::GetCanonicalName(info);
561 path_or_err = find_sdk(sdk_name);
562 if (!path_or_err)
563 return path_or_err.takeError();
564 path = *path_or_err;
565 if (!path.empty())
566 break;
567 }
568
569 LLDB_LOG(log, "Couldn't find any matching SDK on host");
570 return "";
571 }
572
573 // Whatever is left in output should be a valid path.
574 if (!FileSystem::Instance().Exists(path)) {
575 LLDB_LOG(log, "SDK returned by xcrun doesn't exist");
576 return llvm::createStringError(llvm::inconvertibleErrorCode(),
577 "SDK returned by xcrun doesn't exist");
578 }
579 return path;
580}
581
582namespace {
583struct ErrorOrPath {
584 std::string str;
585 bool is_error;
586};
587} // namespace
588
589static llvm::Expected<llvm::StringRef>
590find_cached_path(llvm::StringMap<ErrorOrPath> &cache, std::mutex &mutex,
591 llvm::StringRef key,
592 std::function<llvm::Expected<std::string>(void)> compute) {
593 std::lock_guard<std::mutex> guard(mutex);
595
596 auto it = cache.find(key);
597 if (it != cache.end()) {
598 if (it->second.is_error)
599 return llvm::createStringError(llvm::inconvertibleErrorCode(),
600 it->second.str);
601 return it->second.str;
602 }
603 auto path_or_err = compute();
604 if (!path_or_err) {
605 std::string error = toString(path_or_err.takeError());
606 cache.insert({key, {error, true}});
607 return llvm::createStringError(llvm::inconvertibleErrorCode(), error);
608 }
609 auto it_new = cache.insert({key, {*path_or_err, false}});
610 return it_new.first->second.str;
611}
612
613llvm::Expected<llvm::StringRef> HostInfoMacOSX::GetSDKRoot(SDKOptions options) {
614 static llvm::StringMap<ErrorOrPath> g_sdk_path;
615 static std::mutex g_sdk_path_mutex;
616 if (!options.XcodeSDKSelection)
617 return llvm::createStringError(llvm::inconvertibleErrorCode(),
618 "XcodeSDK not specified");
619 XcodeSDK sdk = *options.XcodeSDKSelection;
620 auto key = sdk.GetString();
621 return find_cached_path(g_sdk_path, g_sdk_path_mutex, key, [&](){
622 return GetXcodeSDK(sdk);
623 });
624}
625
626llvm::Expected<llvm::StringRef>
627HostInfoMacOSX::FindSDKTool(XcodeSDK sdk, llvm::StringRef tool) {
628 static llvm::StringMap<ErrorOrPath> g_tool_path;
629 static std::mutex g_tool_path_mutex;
630 std::string key;
631 llvm::raw_string_ostream(key) << sdk.GetString() << ":" << tool;
632 return find_cached_path(
633 g_tool_path, g_tool_path_mutex, key,
634 [&]() -> llvm::Expected<std::string> {
635 std::string sdk_name = XcodeSDK::GetCanonicalName(sdk.Parse());
636 if (sdk_name.empty())
637 return llvm::createStringError(llvm::inconvertibleErrorCode(),
638 "Unrecognized SDK type: " +
639 sdk.GetString());
640 llvm::SmallVector<llvm::StringRef, 2> find = {"-find", tool};
641 return xcrun(sdk_name, find);
642 });
643}
644
645namespace {
646struct dyld_shared_cache_dylib_text_info {
647 uint64_t version; // current version 1
648 // following fields all exist in version 1
649 uint64_t loadAddressUnslid;
650 uint64_t textSegmentSize;
651 uuid_t dylibUuid;
652 const char *path; // pointer invalid at end of iterations
653 // following fields all exist in version 2
654 uint64_t textSegmentOffset; // offset from start of cache
655};
656typedef struct dyld_shared_cache_dylib_text_info
657 dyld_shared_cache_dylib_text_info;
658}
659
660// All available on at least macOS 12
661extern "C" {
662typedef struct dyld_process_s *dyld_process_t;
663typedef struct dyld_process_snapshot_s *dyld_process_snapshot_t;
664typedef struct dyld_shared_cache_s *dyld_shared_cache_t;
665typedef struct dyld_image_s *dyld_image_t;
666
668 const uuid_t cacheUuid,
669 void (^callback)(const dyld_shared_cache_dylib_text_info *info));
670uint8_t *_dyld_get_shared_cache_range(size_t *length);
673 void (^)(const char *segmentName,
674 uint64_t vmAddr, uint64_t vmSize,
675 int perm));
677bool dyld_shared_cache_for_file(const char *filePath,
678 void (^block)(dyld_shared_cache_t cache));
682 void (^block)(dyld_image_t image));
686}
687
688namespace {
689class SharedCacheInfo {
690public:
691 SharedCacheImageInfo GetByFilename(UUID sc_uuid, ConstString filename) {
692 llvm::sys::ScopedReader guard(m_mutex);
693 if (!sc_uuid)
694 sc_uuid = m_host_uuid;
695 if (!m_filename_map.contains(sc_uuid))
696 return {};
697 if (!m_filename_map[sc_uuid].contains(filename))
698 return {};
699 size_t idx = m_filename_map[sc_uuid][filename];
700 return m_file_infos[sc_uuid][idx];
701 }
702
703 SharedCacheImageInfo GetByUUID(UUID sc_uuid, UUID file_uuid) {
704 llvm::sys::ScopedReader guard(m_mutex);
705 if (!sc_uuid)
706 sc_uuid = m_host_uuid;
707 if (!m_uuid_map.contains(sc_uuid))
708 return {};
709 if (!m_uuid_map[sc_uuid].contains(file_uuid))
710 return {};
711 size_t idx = m_uuid_map[sc_uuid][file_uuid];
712 return m_file_infos[sc_uuid][idx];
713 }
714
715 /// Given the UUID and filepath to a shared cache on the local debug host
716 /// system, open it and add all of the binary images to m_caches.
717 bool CreateSharedCacheImageList(UUID uuid, std::string filepath);
718
719 SharedCacheInfo(SymbolSharedCacheUse sc_mode);
720
721private:
722 bool CreateSharedCacheInfoWithInstrospectionSPIs();
723 void CreateSharedCacheInfoLLDBsVirtualMemory();
724 bool CreateHostSharedCacheImageList();
725
726 // These three ivars have an initial key of a shared cache UUID.
727 // All of the entries for a given shared cache are in m_file_infos.
728 // m_filename_map and m_uuid_map have pointers into those entries.
729 llvm::SmallDenseMap<UUID, std::vector<SharedCacheImageInfo>> m_file_infos;
730 llvm::SmallDenseMap<UUID, llvm::DenseMap<ConstString, size_t>> m_filename_map;
731 llvm::SmallDenseMap<UUID, llvm::DenseMap<UUID, size_t>> m_uuid_map;
732
733 UUID m_host_uuid;
734
735 llvm::sys::RWMutex m_mutex;
736
737 // macOS 26.4 and newer
738 void (*m_dyld_image_retain_4HWTrace)(void *image);
739 void (*m_dyld_image_release_4HWTrace)(void *image);
740 dispatch_data_t (*m_dyld_image_segment_data_4HWTrace)(
741 void *image, const char *segmentName);
742};
743
744} // namespace
745
746SharedCacheInfo::SharedCacheInfo(SymbolSharedCacheUse sc_mode) {
747 // macOS 26.4 and newer
748 m_dyld_image_retain_4HWTrace =
749 (void (*)(void *))dlsym(RTLD_DEFAULT, "dyld_image_retain_4HWTrace");
750 m_dyld_image_release_4HWTrace =
751 (void (*)(void *))dlsym(RTLD_DEFAULT, "dyld_image_release_4HWTrace");
752 m_dyld_image_segment_data_4HWTrace =
753 (dispatch_data_t(*)(void *image, const char *segmentName))dlsym(
754 RTLD_DEFAULT, "dyld_image_segment_data_4HWTrace");
755
756 uuid_t dsc_uuid;
758 m_host_uuid = UUID(dsc_uuid);
759
760 // Don't scan/index lldb's own shared cache at all, in-memory or
761 // via libdyld SPI.
763 return;
764
765 // Check if the settings allow the use of the libdyld SPI.
766 bool use_libdyld_spi =
769 if (use_libdyld_spi && CreateHostSharedCacheImageList())
770 return;
771
772 // Scan lldb's shared cache memory if we're built against the
773 // internal SDK and have those headers.
774 if (CreateSharedCacheInfoWithInstrospectionSPIs())
775 return;
776
777 // Scan lldb's shared cache memory if we're built against the public
778 // SDK.
779 CreateSharedCacheInfoLLDBsVirtualMemory();
780}
781
782struct segment {
783 std::string name;
784 uint64_t vmaddr;
785 size_t vmsize;
786
787 // Mapped into lldb's own address space via libdispatch:
788 const void *data;
789 size_t size;
790};
791
793 // dyld_image_segment_data_4HWTrace can't be called on
794 // multiple threads simultaneously.
795 static std::mutex g_mutex;
796 std::lock_guard<std::mutex> guard(g_mutex);
797
798 static dispatch_data_t (*g_dyld_image_segment_data_4HWTrace)(
799 void *image, const char *segmentName);
800 static std::once_flag g_once_flag;
801 std::call_once(g_once_flag, [&]() {
802 g_dyld_image_segment_data_4HWTrace =
803 (dispatch_data_t(*)(void *, const char *))dlsym(
804 RTLD_DEFAULT, "dyld_image_segment_data_4HWTrace");
805 });
806 if (!g_dyld_image_segment_data_4HWTrace)
807 return {};
808
809 __block std::vector<segment> segments;
810 __block dyld_image_t image_copy = (dyld_image_t)image;
812 (dyld_image_t)image,
813 ^(const char *segmentName, uint64_t vmAddr, uint64_t vmSize, int perm) {
814 segment seg;
815 seg.name = segmentName;
816 seg.vmaddr = vmAddr;
817 seg.vmsize = vmSize;
818
819 dispatch_data_t data_from_libdyld =
820 g_dyld_image_segment_data_4HWTrace(image_copy, segmentName);
821 (void)dispatch_data_create_map(data_from_libdyld, &seg.data, &seg.size);
822
823 if (seg.size > 0 && seg.data != 0)
824 segments.push_back(seg);
825 });
826
827 if (!segments.size())
828 return {};
829
831 LLDB_LOGF(log,
832 "map_shared_cache_binary_segments() mapping segments of "
833 "dyld_image_t %p into lldb address space",
834 image);
835 for (const segment &seg : segments) {
837 log, "image %p %s vmaddr 0x%llx vmsize 0x%zx mapped to lldb vm addr %p",
838 image, seg.name.c_str(), seg.vmaddr, seg.vmsize, seg.data);
839 }
840
841 // Calculate the virtual address range in lldb's
842 // address space (lowest memory address to highest) so
843 // we can contain the entire range in an unowned data buffer.
844 uint64_t min_lldb_vm_addr = UINT64_MAX;
845 uint64_t max_lldb_vm_addr = 0;
846 // Calculate the minimum shared cache address seen; we want the first
847 // segment, __TEXT, at "vm offset" 0 in our DataExtractor.
848 // A __DATA segment which is at the __TEXT vm addr + 0x1000 needs to be
849 // listed as offset 0x1000.
850 uint64_t min_file_vm_addr = UINT64_MAX;
851 for (const segment &seg : segments) {
852 min_lldb_vm_addr = std::min(min_lldb_vm_addr, (uint64_t)seg.data);
853 max_lldb_vm_addr =
854 std::max(max_lldb_vm_addr, (uint64_t)seg.data + seg.vmsize);
855 min_file_vm_addr = std::min(min_file_vm_addr, (uint64_t)seg.vmaddr);
856 }
857 DataBufferSP data_sp = std::make_shared<DataBufferUnowned>(
858 (uint8_t *)min_lldb_vm_addr, max_lldb_vm_addr - min_lldb_vm_addr);
860 for (const segment &seg : segments)
862 (uint64_t)seg.vmaddr - min_file_vm_addr, (uint64_t)seg.vmsize,
863 (uint64_t)seg.data - (uint64_t)min_lldb_vm_addr));
864
865 return std::make_shared<VirtualDataExtractor>(data_sp, remap_table);
866}
867
868// Scan the binaries in the specified shared cache filepath
869// if the UUID matches, using the macOS 26.4 libdyld SPI,
870// create a new entry in m_caches.
871bool SharedCacheInfo::CreateSharedCacheImageList(UUID sc_uuid,
872 std::string filepath) {
873 llvm::sys::ScopedWriter guard(m_mutex);
874 if (!m_dyld_image_retain_4HWTrace || !m_dyld_image_release_4HWTrace ||
875 !m_dyld_image_segment_data_4HWTrace)
876 return false;
877
878 if (filepath.empty())
879 return false;
880
882
883 // Have we already indexed this shared cache.
884 if (m_file_infos.contains(sc_uuid)) {
885 LLDB_LOGF(log, "Have already indexed shared cache UUID %s",
886 sc_uuid.GetAsString().c_str());
887 return true;
888 }
889
890 LLDB_LOGF(log, "Opening shared cache at %s to check for matching UUID %s",
891 filepath.c_str(), sc_uuid.GetAsString().c_str());
892
893 __block bool return_failed = false;
894 dyld_shared_cache_for_file(filepath.c_str(), ^(dyld_shared_cache_t cache) {
895 uuid_t uuid;
896 dyld_shared_cache_copy_uuid(cache, &uuid);
897 UUID this_cache(uuid, sizeof(uuid_t));
898 if (this_cache != sc_uuid) {
899 return_failed = true;
900 return;
901 }
902
903 // In macOS 26, a shared cache has around 3500 files.
904 m_file_infos[sc_uuid].reserve(4000);
905
907 uuid_t uuid_tmp;
908 if (!dyld_image_copy_uuid(image, &uuid_tmp))
909 return;
910 UUID image_uuid(uuid_tmp, sizeof(uuid_t));
911
912 // Copy the filename into the const string pool to
913 // ensure lifetime.
914 ConstString installname(dyld_image_get_installname(image));
916 LLDB_LOGF_VERBOSE(log, "sc file %s image %p", installname.GetCString(),
917 (void *)image);
918
919 m_dyld_image_retain_4HWTrace(image);
920 m_file_infos[sc_uuid].push_back(SharedCacheImageInfo(
921 installname, image_uuid, map_shared_cache_binary_segments, image));
922 });
923 });
924 if (return_failed)
925 return false;
926
927 // Vector of SharedCacheImageInfos has been fully populated, we can
928 // take pointers to the objects now.
929 size_t file_info_size = m_file_infos[sc_uuid].size();
930 for (size_t i = 0; i < file_info_size; i++) {
931 SharedCacheImageInfo *entry = &m_file_infos[sc_uuid][i];
932 m_filename_map[sc_uuid][entry->GetFilename()] = i;
933 m_uuid_map[sc_uuid][entry->GetUUID()] = i;
934 }
935
936 return true;
937}
938
939// Get the filename and uuid of lldb's own shared cache, scan
940// the files in it using the macOS 26.4 and newer libdyld SPI.
941bool SharedCacheInfo::CreateHostSharedCacheImageList() {
942 std::string host_shared_cache_file = dyld_shared_cache_file_path();
943 __block UUID host_sc_uuid;
944 dyld_shared_cache_for_file(host_shared_cache_file.c_str(),
945 ^(dyld_shared_cache_t cache) {
946 uuid_t sc_uuid;
947 dyld_shared_cache_copy_uuid(cache, &sc_uuid);
948 host_sc_uuid = UUID(sc_uuid, sizeof(uuid_t));
949 });
950
951 if (host_sc_uuid.IsValid())
952 return CreateSharedCacheImageList(host_sc_uuid, host_shared_cache_file);
953
954 return false;
955}
956
957// Index the binaries in lldb's own shared cache memory, using
958// libdyld SPI present on macOS 12 and newer, when building against
959// the internal SDK, and add an entry to the m_caches map.
960bool SharedCacheInfo::CreateSharedCacheInfoWithInstrospectionSPIs() {
961 llvm::sys::ScopedWriter guard(m_mutex);
962#if defined(SDK_HAS_NEW_DYLD_INTROSPECTION_SPIS)
963 dyld_process_t dyld_process = dyld_process_create_for_current_task();
964 if (!dyld_process)
965 return false;
966
967 llvm::scope_exit cleanup_process_on_exit(
968 [&]() { dyld_process_dispose(dyld_process); });
969
970 dyld_process_snapshot_t snapshot =
971 dyld_process_snapshot_create_for_process(dyld_process, nullptr);
972 if (!snapshot)
973 return false;
974
975 llvm::scope_exit cleanup_snapshot_on_exit(
976 [&]() { dyld_process_snapshot_dispose(snapshot); });
977
978 dyld_shared_cache_t shared_cache =
979 dyld_process_snapshot_get_shared_cache(snapshot);
980 if (!shared_cache)
981 return false;
982
983 // In macOS 26, a shared cache has around 3500 files.
984 m_file_infos[m_host_uuid].reserve(4000);
985
986 dyld_shared_cache_for_each_image(shared_cache, ^(dyld_image_t image) {
987 __block uint64_t minVmAddr = UINT64_MAX;
988 __block uint64_t maxVmAddr = 0;
989 uuid_t uuidStore;
990 __block uuid_t *uuid = &uuidStore;
991
993 image,
994 ^(const char *segmentName, uint64_t vmAddr, uint64_t vmSize, int perm) {
995 minVmAddr = std::min(minVmAddr, vmAddr);
996 maxVmAddr = std::max(maxVmAddr, vmAddr + vmSize);
997 dyld_image_copy_uuid(image, uuid);
998 });
999 assert(minVmAddr != UINT_MAX);
1000 assert(maxVmAddr != 0);
1001 lldb::DataBufferSP data_sp = std::make_shared<DataBufferUnowned>(
1002 (uint8_t *)minVmAddr, maxVmAddr - minVmAddr);
1003 lldb::DataExtractorSP extractor_sp = std::make_shared<DataExtractor>(data_sp);
1004 // Copy the filename into the const string pool to
1005 // ensure lifetime.
1006 ConstString installname(dyld_image_get_installname(image));
1007 m_file_infos[m_host_uuid].push_back(
1008 SharedCacheImageInfo(installname, UUID(uuid, 16), extractor_sp));
1009 });
1010
1011 // std::vector of SharedCacheImageInfos has been fully populated, we can
1012 // take pointers to the objects now.
1013 size_t file_info_size = m_file_infos[m_host_uuid].size();
1014 for (size_t i = 0; i < file_info_size; i++) {
1015 SharedCacheImageInfo *entry = &m_file_infos[m_host_uuid][i];
1016 m_filename_map[m_host_uuid][entry->GetFilename()] = i;
1017 m_uuid_map[m_host_uuid][entry->GetUUID()] = i;
1018 }
1019 return true;
1020#endif
1021 return false;
1022}
1023
1024// Index the binaries in lldb's own shared cache memory using
1025// libdyld SPI available on macOS 10.13 or newer, add an entry to
1026// m_caches.
1027void SharedCacheInfo::CreateSharedCacheInfoLLDBsVirtualMemory() {
1028 llvm::sys::ScopedWriter guard(m_mutex);
1029 size_t shared_cache_size;
1030 uint8_t *shared_cache_start =
1031 _dyld_get_shared_cache_range(&shared_cache_size);
1032
1033 // In macOS 26, a shared cache has around 3500 files.
1034 m_file_infos[m_host_uuid].reserve(4000);
1035
1037 m_host_uuid.GetBytes().data(),
1038 ^(const dyld_shared_cache_dylib_text_info *info) {
1039 lldb::DataBufferSP buffer_sp = std::make_shared<DataBufferUnowned>(
1040 shared_cache_start + info->textSegmentOffset,
1041 shared_cache_size - info->textSegmentOffset);
1042 lldb::DataExtractorSP extractor_sp =
1043 std::make_shared<DataExtractor>(buffer_sp);
1044 ConstString filepath(info->path);
1045 m_file_infos[m_host_uuid].push_back(SharedCacheImageInfo(
1046 filepath, UUID(info->dylibUuid, 16), extractor_sp));
1047 });
1048
1049 // std::vector of SharedCacheImageInfos has been fully populated, we can
1050 // take pointers to the objects now.
1051 size_t file_info_size = m_file_infos[m_host_uuid].size();
1052 for (size_t i = 0; i < file_info_size; i++) {
1053 SharedCacheImageInfo *entry = &m_file_infos[m_host_uuid][i];
1054 m_filename_map[m_host_uuid][entry->GetFilename()] = i;
1055 m_uuid_map[m_host_uuid][entry->GetUUID()] = i;
1056 }
1057}
1058
1060 static SharedCacheInfo g_shared_cache_info(sc_mode);
1061 return g_shared_cache_info;
1062}
1063
1066 SymbolSharedCacheUse sc_mode) {
1067 return GetSharedCacheSingleton(sc_mode).GetByFilename(UUID(), filepath);
1068}
1069
1072 SymbolSharedCacheUse sc_mode) {
1073 return GetSharedCacheSingleton(sc_mode).GetByUUID(UUID(), file_uuid);
1074}
1075
1077 ConstString filepath, const UUID &sc_uuid, SymbolSharedCacheUse sc_mode) {
1078 return GetSharedCacheSingleton(sc_mode).GetByFilename(sc_uuid, filepath);
1079}
1080
1082 const UUID &file_uuid, const UUID &sc_uuid, SymbolSharedCacheUse sc_mode) {
1083 return GetSharedCacheSingleton(sc_mode).GetByUUID(sc_uuid, file_uuid);
1084}
1085
1087 SymbolSharedCacheUse sc_mode) {
1089 return false;
1090
1091 // There is a libdyld SPI to iterate over all installed shared caches,
1092 // but it can have performance problems if an older Simulator SDK shared
1093 // cache is installed. So require that we are given a filepath of
1094 // the shared cache.
1095 if (FileSystem::Instance().Exists(filepath))
1096 return GetSharedCacheSingleton(sc_mode).CreateSharedCacheImageList(
1097 uuid, filepath.GetPath());
1098 return false;
1099}
1100
1102 std::string path = bundle_path.GetPath();
1103 CFURLRef url = CFURLCreateFromFileSystemRepresentation(
1104 kCFAllocatorDefault, reinterpret_cast<const UInt8 *>(path.data()),
1105 path.size(), /*isDirectory=*/true);
1106 if (!url)
1107 return false;
1108 auto url_cleanup = llvm::make_scope_exit([&]() { CFRelease(url); });
1109
1110 SecStaticCodeRef static_code = nullptr;
1111 if (SecStaticCodeCreateWithPath(url, kSecCSDefaultFlags, &static_code) !=
1112 errSecSuccess)
1113 return false;
1114 auto code_cleanup = llvm::make_scope_exit([&]() { CFRelease(static_code); });
1115
1116 // Check that the signature chains to a trusted root CA.
1117 SecRequirementRef requirement = nullptr;
1118 if (SecRequirementCreateWithString(CFSTR("anchor trusted"),
1119 kSecCSDefaultFlags,
1120 &requirement) != errSecSuccess)
1121 return false;
1122 auto req_cleanup = llvm::make_scope_exit([&]() { CFRelease(requirement); });
1123
1124 return SecStaticCodeCheckValidity(static_code, kSecCSDefaultFlags,
1125 requirement) == errSecSuccess;
1126}
unsigned char uuid_t[16]
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))
#define CPU_TYPE_ARM64
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.
Definition Log.h:369
#define LLDB_LOGF_VERBOSE(log,...)
Definition Log.h:390
#define LLDB_LOGF(log,...)
Definition Log.h:383
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:399
#define LLDB_SCOPED_TIMER()
Definition Timer.h:83
An architecture specification class.
Definition ArchSpec.h:32
void Clear()
Clears the object state.
Definition ArchSpec.cpp:538
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition ArchSpec.h:457
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.
Definition ArchSpec.cpp:843
A command line argument class.
Definition Args.h:33
void AppendArgument(llvm::StringRef arg_str, char quote_char='\0')
Appends a new argument to the end of the list argument list.
Definition Args.cpp:332
bool GetCommandString(std::string &command) const
Definition Args.cpp:215
A uniqued constant string class.
Definition ConstString.h:40
A file utility class.
Definition FileSpec.h:57
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition FileSpec.cpp:174
FileSpec CopyByAppendingPathComponent(llvm::StringRef component) const
Definition FileSpec.cpp:425
void AppendPathComponent(llvm::StringRef component)
Definition FileSpec.cpp:454
void SetDirectory(ConstString directory)
Directory string set accessor.
Definition FileSpec.cpp:342
const ConstString & GetDirectory() const
Directory string const get accessor.
Definition FileSpec.h:234
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition FileSpec.cpp:374
ConstString GetPathAsConstString(bool denormalize=true) const
Get the full path as a ConstString.
Definition FileSpec.cpp:390
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
Definition RangeMap.h:462
void Append(const Entry &entry)
Definition RangeMap.h:474
An error handling class.
Definition Status.h:118
Represents UUID's of various sizes.
Definition UUID.h:27
std::string GetAsString(llvm::StringRef separator="-") const
Definition UUID.cpp:54
RangeDataVector< lldb::offset_t, lldb::offset_t, lldb::offset_t > LookupTable
Type alias for the range map used internally.
An abstraction for Xcode-style SDKs that works like ArchSpec.
Definition XcodeSDK.h:25
static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path)
Definition XcodeSDK.cpp:293
static XcodeSDK GetAnyMacOS()
Definition XcodeSDK.h:71
llvm::StringRef GetString() const
Definition XcodeSDK.cpp:143
static std::string GetCanonicalName(Info info)
Return the canonical SDK name, such as "macosx" for the macOS SDK.
Definition XcodeSDK.cpp:177
Info Parse() const
Return parsed SDK type and version number.
Definition XcodeSDK.cpp:116
#define UINT64_MAX
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.
Definition Log.h:332
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
A parsed SDK directory name.
Definition XcodeSDK.h:48
llvm::VersionTuple version
Definition XcodeSDK.h:50
size_t vmsize
const void * data
std::string name
uint64_t vmaddr
#define PATH_MAX