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