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