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