LLDB mainline
PlatformDarwin.cpp
Go to the documentation of this file.
1//===-- PlatformDarwin.cpp ------------------------------------------------===//
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
9#include "PlatformDarwin.h"
10
11#include <cstring>
12
13#include <algorithm>
14#include <memory>
15#include <mutex>
16#include <optional>
17
20#include "lldb/Core/Debugger.h"
21#include "lldb/Core/Module.h"
24#include "lldb/Core/Progress.h"
25#include "lldb/Core/Section.h"
26#include "lldb/Host/Host.h"
27#include "lldb/Host/HostInfo.h"
28#include "lldb/Host/XML.h"
39#include "lldb/Target/Process.h"
40#include "lldb/Target/Target.h"
42#include "lldb/Utility/Log.h"
44#include "lldb/Utility/Status.h"
45#include "lldb/Utility/Timer.h"
46#include "llvm/ADT/STLExtras.h"
47#include "llvm/ADT/StringTable.h"
48#include "llvm/Support/Error.h"
49#include "llvm/Support/FileSystem.h"
50#include "llvm/Support/Threading.h"
51#include "llvm/Support/VersionTuple.h"
52
53#if defined(__APPLE__)
55#include <TargetConditionals.h>
56#endif
57
58using namespace lldb;
59using namespace lldb_private;
60
61#define OPTTABLE_STR_TABLE_CODE
62#include "clang/Options/Options.inc"
63#undef OPTTABLE_STR_TABLE_CODE
64
65static Status ExceptionMaskValidator(const char *string, void *unused) {
67 llvm::StringRef str_ref(string);
68 llvm::SmallVector<llvm::StringRef> candidates;
69 str_ref.split(candidates, '|');
70 for (auto candidate : candidates) {
71 if (!(candidate == "EXC_BAD_ACCESS"
72 || candidate == "EXC_BAD_INSTRUCTION"
73 || candidate == "EXC_ARITHMETIC"
74 || candidate == "EXC_RESOURCE"
75 || candidate == "EXC_GUARD"
76 || candidate == "EXC_SYSCALL")) {
77 error = Status::FromErrorStringWithFormat("invalid exception type: '%s'",
78 candidate.str().c_str());
79 return error;
80 }
81 }
82 return {};
83}
84
85/// Destructor.
86///
87/// The destructor is virtual since this class is designed to be
88/// inherited from by the plug-in instance.
90
91// Static Variables
92static uint32_t g_initialize_count = 0;
93
102
110
112 return "Darwin platform plug-in.";
113}
114
116 // We only create subclasses of the PlatformDarwin plugin.
117 return PlatformSP();
118}
119
120#define LLDB_PROPERTIES_platformdarwin
121#include "PlatformMacOSXProperties.inc"
122
123#define LLDB_PROPERTIES_platformdarwin
124enum {
125#include "PlatformMacOSXPropertiesEnum.inc"
126};
127
129public:
130 static llvm::StringRef GetSettingName() {
131 static constexpr llvm::StringLiteral g_setting_name("darwin");
132 return g_setting_name;
133 }
134
136 m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName());
137 m_collection_sp->Initialize(g_platformdarwin_properties_def);
138 }
139
140 ~PlatformDarwinProperties() override = default;
141
142 const char *GetIgnoredExceptions() const {
143 const uint32_t idx = ePropertyIgnoredExceptions;
144 const OptionValueString *option_value =
145 m_collection_sp->GetPropertyAtIndexAsOptionValueString(idx);
146 assert(option_value);
147 return option_value->GetCurrentValue();
148 }
149
151 const uint32_t idx = ePropertyIgnoredExceptions;
152 OptionValueString *option_value =
153 m_collection_sp->GetPropertyAtIndexAsOptionValueString(idx);
154 assert(option_value);
155 return option_value;
156 }
157};
158
160 static PlatformDarwinProperties g_settings;
161 return g_settings;
162}
163
165 lldb_private::Debugger &debugger) {
168 const bool is_global_setting = false;
170 debugger, GetGlobalProperties().GetValueProperties(),
171 "Properties for the Darwin platform plug-in.", is_global_setting);
172 OptionValueString *value = GetGlobalProperties().GetIgnoredExceptionValue();
174 }
175}
176
177Args
179 std::string ignored_exceptions
180 = GetGlobalProperties().GetIgnoredExceptions();
181 if (ignored_exceptions.empty())
182 return {};
183 Args ret_args;
184 std::string packet = "QSetIgnoredExceptions:";
185 packet.append(ignored_exceptions);
186 ret_args.AppendArgument(packet);
187 return ret_args;
188}
189
192 const lldb_private::FileSpec &destination, uint32_t uid,
193 uint32_t gid) {
194 // Unconditionally unlink the destination. If it is an executable,
195 // simply opening it and truncating its contents would invalidate
196 // its cached code signature.
197 Unlink(destination);
198 return PlatformPOSIX::PutFile(source, destination, uid, gid);
199}
200
201llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile>
203 Stream &feedback_stream, FileSpec module_spec, const Target &target,
204 const FileSpec &symfile_spec) {
205
206 assert(target.GetDebugger().GetScriptInterpreter() &&
207 "Trying to locate scripting resources but no ScriptInterpreter is "
208 "available.");
209
210 llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile> file_specs;
211 const FileSpec original_module_spec = module_spec;
212 while (module_spec.GetFilename()) {
214 target.GetDebugger()
217 module_spec.GetFilename().GetStringRef());
218
219 StreamString path_string;
220 StreamString original_path_string;
221 // for OSX we are going to be in
222 // .dSYM/Contents/Resources/DWARF/<basename> let us go to
223 // .dSYM/Contents/Resources/Python/<basename>.py and see if the
224 // file exists
225 path_string.Format("{0}/../Python/{1}.py",
226 symfile_spec.GetDirectory().GetStringRef(),
227 sanitized_name.GetSanitizedName());
228 original_path_string.Format("{0}/../Python/{1}.py",
229 symfile_spec.GetDirectory().GetStringRef(),
230 sanitized_name.GetOriginalName());
231
232 FileSpec script_fspec(path_string.GetString());
233 FileSystem::Instance().Resolve(script_fspec);
234 FileSpec orig_script_fspec(original_path_string.GetString());
235 FileSystem::Instance().Resolve(orig_script_fspec);
236
237 WarnIfInvalidUnsanitizedScriptExists(feedback_stream, sanitized_name,
238 orig_script_fspec, script_fspec);
239
240 if (FileSystem::Instance().Exists(script_fspec)) {
241 LoadScriptFromSymFile load_style =
242 Platform::GetScriptLoadStyleForModule(original_module_spec, target);
243 file_specs.try_emplace(std::move(script_fspec), load_style);
244 break;
245 }
246
247 // If we didn't find the python file, then keep stripping the
248 // extensions and try again
249 ConstString filename_no_extension(
250 module_spec.GetFileNameStrippingExtension());
251 if (module_spec.GetFilename() == filename_no_extension)
252 break;
253
254 module_spec.SetFilename(filename_no_extension);
255 }
256
257 return file_specs;
258}
259
260llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile>
262 Target *target, Module &module, Stream &feedback_stream) {
263 llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile> empty;
264 if (!target)
265 return empty;
266
267 // For now only Python scripts supported for auto-loading.
269 return empty;
270
271 // NB some extensions might be meaningful and should not be stripped -
272 // "this.binary.file"
273 // should not lose ".file" but GetFileNameStrippingExtension() will do
274 // precisely that. Ideally, we should have a per-platform list of
275 // extensions (".exe", ".app", ".dSYM", ".framework") which should be
276 // stripped while leaving "this.binary.file" as-is.
277
278 const FileSpec &module_spec = module.GetFileSpec();
279
280 if (!module_spec)
281 return empty;
282
283 SymbolFile *symfile = module.GetSymbolFile();
284 if (!symfile)
285 return empty;
286
287 ObjectFile *objfile = symfile->GetObjectFile();
288 if (!objfile)
289 return empty;
290
291 const FileSpec &symfile_spec = objfile->GetFileSpec();
292 if (symfile_spec &&
293 llvm::StringRef(symfile_spec.GetPath())
294 .contains_insensitive(".dSYM/Contents/Resources/DWARF") &&
295 FileSystem::Instance().Exists(symfile_spec))
297 feedback_stream, module_spec, *target, symfile_spec);
298
299 return empty;
300}
301
303#if defined(__APPLE__)
304 SymbolFile *symfile = module.GetSymbolFile();
305 if (!symfile)
306 return false;
307
308 ObjectFile *objfile = symfile->GetObjectFile();
309 if (!objfile)
310 return false;
311
312 std::string symfile_path = objfile->GetFileSpec().GetPath();
313 llvm::StringRef path_ref(symfile_path);
314
315 // Find the .dSYM bundle root from the symfile path, which is typically
316 // .dSYM/Contents/Resources/DWARF/<name>.
317 auto pos = path_ref.find(".dSYM/");
318 if (pos == llvm::StringRef::npos)
319 return false;
320
321 FileSpec bundle_spec(path_ref.substr(0, pos + 5));
322
325 "dSYM bundle '{0}' has valid trusted code signature",
326 bundle_spec.GetPath());
327 return true;
328 }
329
330 return false;
331#else
332 return false;
333#endif
334}
335
337 const ModuleSpec &sym_spec,
338 FileSpec &sym_file) {
339 sym_file = sym_spec.GetSymbolFileSpec();
340 if (FileSystem::Instance().IsDirectory(sym_file)) {
342 sym_file, sym_spec.GetUUIDPtr(), sym_spec.GetArchitecturePtr());
343 }
344 return {};
345}
346
348 const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp,
349 llvm::SmallVectorImpl<ModuleSP> *old_modules, bool *did_create_ptr) {
351 module_sp.reset();
352
353 if (IsRemote()) {
354 // If we have a remote platform always, let it try and locate the shared
355 // module first.
357 error = m_remote_platform_sp->GetSharedModule(
358 module_spec, process, module_sp, old_modules, did_create_ptr);
359 }
360 }
361
362 if (!module_sp) {
363 // Fall back to the local platform and find the file locally
364 error = Platform::GetSharedModule(module_spec, process, module_sp,
365 old_modules, did_create_ptr);
366
367 const FileSpec &platform_file = module_spec.GetFileSpec();
368 // Get module search paths from the target if available.
369 TargetSP target_sp = module_spec.GetTargetSP();
370 FileSpecList module_search_paths;
371 if (target_sp)
372 module_search_paths = target_sp->GetExecutableSearchPaths();
373 if (!module_sp && !module_search_paths.IsEmpty() && platform_file) {
374 // We can try to pull off part of the file path up to the bundle
375 // directory level and try any module search paths...
376 FileSpec bundle_directory;
377 if (Host::GetBundleDirectory(platform_file, bundle_directory)) {
378 if (platform_file == bundle_directory) {
379 ModuleSpec new_module_spec(module_spec);
380 new_module_spec.GetFileSpec() = bundle_directory;
381 if (Host::ResolveExecutableInBundle(new_module_spec.GetFileSpec())) {
382 Status new_error(Platform::GetSharedModule(new_module_spec, process,
383 module_sp, old_modules,
384 did_create_ptr));
385
386 if (module_sp)
387 return new_error;
388 }
389 } else {
390 char platform_path[PATH_MAX];
391 char bundle_dir[PATH_MAX];
392 platform_file.GetPath(platform_path, sizeof(platform_path));
393 const size_t bundle_directory_len =
394 bundle_directory.GetPath(bundle_dir, sizeof(bundle_dir));
395 char new_path[PATH_MAX];
396 size_t num_module_search_paths = module_search_paths.GetSize();
397 for (size_t i = 0; i < num_module_search_paths; ++i) {
398 const size_t search_path_len =
399 module_search_paths.GetFileSpecAtIndex(i).GetPath(
400 new_path, sizeof(new_path));
401 if (search_path_len < sizeof(new_path)) {
402 snprintf(new_path + search_path_len,
403 sizeof(new_path) - search_path_len, "/%s",
404 platform_path + bundle_directory_len);
405 FileSpec new_file_spec(new_path);
406 if (FileSystem::Instance().Exists(new_file_spec)) {
407 ModuleSpec new_module_spec(module_spec);
408 new_module_spec.GetFileSpec() = new_file_spec;
410 new_module_spec, process, module_sp, old_modules,
411 did_create_ptr));
412
413 if (module_sp) {
414 module_sp->SetPlatformFileSpec(new_file_spec);
415 return new_error;
416 }
417 }
418 }
419 }
420 }
421 }
422 }
423 }
424 if (module_sp)
425 module_sp->SetPlatformFileSpec(module_spec.GetFileSpec());
426 return error;
427}
429 const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp,
430 llvm::SmallVectorImpl<ModuleSP> *old_modules, bool *did_create_ptr) {
431 Status err;
432
433 SymbolSharedCacheUse sc_mode =
435 SharedCacheImageInfo image_info;
436 if (process && process->GetDynamicLoader()) {
437 addr_t sc_base_addr;
438 UUID sc_uuid;
439 LazyBool using_sc, private_sc;
440 FileSpec sc_path;
441 std::optional<uint64_t> size;
443 sc_base_addr, sc_uuid, using_sc, private_sc, sc_path, size)) {
444 if (module_spec.GetUUID())
445 image_info = HostInfo::GetSharedCacheImageInfo(module_spec.GetUUID(),
446 sc_uuid, sc_mode);
447 else
448 image_info = HostInfo::GetSharedCacheImageInfo(
449 module_spec.GetFileSpec().GetPathAsConstString(), sc_uuid, sc_mode);
450 }
451 }
452 // Fall back to looking for the file in lldb's own shared cache.
453 if (!image_info.GetUUID())
454 image_info = HostInfo::GetSharedCacheImageInfo(
455 module_spec.GetFileSpec().GetPathAsConstString(), sc_mode);
456
457 // If we found it and it has the correct UUID, let's proceed with
458 // creating a module from the memory contents.
459 if (image_info.GetUUID() && (!module_spec.GetUUID() ||
460 module_spec.GetUUID() == image_info.GetUUID())) {
461 ModuleSpec shared_cache_spec(module_spec.GetFileSpec(),
462 image_info.GetUUID(),
463 image_info.GetExtractor());
464 err = ModuleList::GetSharedModule(shared_cache_spec, module_sp, old_modules,
465 did_create_ptr);
466 if (module_sp) {
468 LLDB_LOGF(log, "module %s was found in a shared cache",
469 module_spec.GetFileSpec().GetPath().c_str());
470 }
471 }
472 return err;
473}
474
475size_t
477 BreakpointSite *bp_site) {
478 const uint8_t *trap_opcode = nullptr;
479 uint32_t trap_opcode_size = 0;
480 bool bp_is_thumb = false;
481
482 llvm::Triple::ArchType machine = target.GetArchitecture().GetMachine();
483 switch (machine) {
484 case llvm::Triple::aarch64_32:
485 case llvm::Triple::aarch64: {
486 // 'brk #0' or 0xd4200000 in BE byte order
487 static const uint8_t g_arm64_breakpoint_opcode[] = {0x00, 0x00, 0x20, 0xD4};
488 trap_opcode = g_arm64_breakpoint_opcode;
489 trap_opcode_size = sizeof(g_arm64_breakpoint_opcode);
490 } break;
491
492 case llvm::Triple::thumb:
493 bp_is_thumb = true;
494 [[fallthrough]];
495 case llvm::Triple::arm: {
496 static const uint8_t g_arm_breakpoint_opcode[] = {0xFE, 0xDE, 0xFF, 0xE7};
497 static const uint8_t g_thumb_breakpooint_opcode[] = {0xFE, 0xDE};
498
499 // Auto detect arm/thumb if it wasn't explicitly specified
500 if (!bp_is_thumb) {
502 if (bp_loc_sp)
503 bp_is_thumb = bp_loc_sp->GetAddress().GetAddressClass() ==
505 }
506 if (bp_is_thumb) {
507 trap_opcode = g_thumb_breakpooint_opcode;
508 trap_opcode_size = sizeof(g_thumb_breakpooint_opcode);
509 break;
510 }
511 trap_opcode = g_arm_breakpoint_opcode;
512 trap_opcode_size = sizeof(g_arm_breakpoint_opcode);
513 } break;
514
515 case llvm::Triple::ppc:
516 case llvm::Triple::ppc64: {
517 static const uint8_t g_ppc_breakpoint_opcode[] = {0x7F, 0xC0, 0x00, 0x08};
518 trap_opcode = g_ppc_breakpoint_opcode;
519 trap_opcode_size = sizeof(g_ppc_breakpoint_opcode);
520 } break;
521
522 default:
523 return Platform::GetSoftwareBreakpointTrapOpcode(target, bp_site);
524 }
525
526 if (trap_opcode && trap_opcode_size) {
527 if (bp_site->SetTrapOpcode(trap_opcode, trap_opcode_size))
528 return trap_opcode_size;
529 }
530 return 0;
531}
532
534 lldb_private::Target &target, const lldb::ModuleSP &module_sp) {
535 if (!module_sp)
536 return false;
537
538 ObjectFile *obj_file = module_sp->GetObjectFile();
539 if (!obj_file)
540 return false;
541
542 ObjectFile::Type obj_type = obj_file->GetType();
543 return obj_type == ObjectFile::eTypeDynamicLinker;
544}
545
547 std::vector<ArchSpec> &archs) {
548 ArchSpec host_arch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
549 archs.push_back(host_arch);
550
551 if (host_arch.GetCore() == ArchSpec::eCore_x86_64_x86_64h) {
552 archs.push_back(ArchSpec("x86_64-apple-macosx"));
553 archs.push_back(HostInfo::GetArchitecture(HostInfo::eArchKind32));
554 } else {
555 ArchSpec host_arch64 = HostInfo::GetArchitecture(HostInfo::eArchKind64);
556 if (host_arch.IsExactMatch(host_arch64))
557 archs.push_back(HostInfo::GetArchitecture(HostInfo::eArchKind32));
558 }
559}
560
561static llvm::ArrayRef<const char *> GetCompatibleArchs(ArchSpec::Core core) {
562 switch (core) {
563 default:
564 [[fallthrough]];
566 static const char *g_arm64e_compatible_archs[] = {
567 "arm64e", "arm64", "armv7", "armv7f", "armv7k", "armv7s",
568 "armv7m", "armv7em", "armv6m", "armv6", "armv5", "armv4",
569 "arm", "thumbv7", "thumbv7f", "thumbv7k", "thumbv7s", "thumbv7m",
570 "thumbv7em", "thumbv6m", "thumbv6", "thumbv5", "thumbv4t", "thumb",
571 };
572 return {g_arm64e_compatible_archs};
573 }
575 static const char *g_arm64_compatible_archs[] = {
576 "arm64", "armv7", "armv7f", "armv7k", "armv7s", "armv7m",
577 "armv7em", "armv6m", "armv6", "armv5", "armv4", "arm",
578 "thumbv7", "thumbv7f", "thumbv7k", "thumbv7s", "thumbv7m", "thumbv7em",
579 "thumbv6m", "thumbv6", "thumbv5", "thumbv4t", "thumb",
580 };
581 return {g_arm64_compatible_archs};
582 }
584 static const char *g_armv7_compatible_archs[] = {
585 "armv7", "armv6m", "armv6", "armv5", "armv4", "arm",
586 "thumbv7", "thumbv6m", "thumbv6", "thumbv5", "thumbv4t", "thumb",
587 };
588 return {g_armv7_compatible_archs};
589 }
591 static const char *g_armv7f_compatible_archs[] = {
592 "armv7f", "armv7", "armv6m", "armv6", "armv5",
593 "armv4", "arm", "thumbv7f", "thumbv7", "thumbv6m",
594 "thumbv6", "thumbv5", "thumbv4t", "thumb",
595 };
596 return {g_armv7f_compatible_archs};
597 }
599 static const char *g_armv7k_compatible_archs[] = {
600 "armv7k", "armv7", "armv6m", "armv6", "armv5",
601 "armv4", "arm", "thumbv7k", "thumbv7", "thumbv6m",
602 "thumbv6", "thumbv5", "thumbv4t", "thumb",
603 };
604 return {g_armv7k_compatible_archs};
605 }
607 static const char *g_armv7s_compatible_archs[] = {
608 "armv7s", "armv7", "armv6m", "armv6", "armv5",
609 "armv4", "arm", "thumbv7s", "thumbv7", "thumbv6m",
610 "thumbv6", "thumbv5", "thumbv4t", "thumb",
611 };
612 return {g_armv7s_compatible_archs};
613 }
615 static const char *g_armv7m_compatible_archs[] = {
616 "armv7m", "armv7", "armv6m", "armv6", "armv5",
617 "armv4", "arm", "thumbv7m", "thumbv7", "thumbv6m",
618 "thumbv6", "thumbv5", "thumbv4t", "thumb",
619 };
620 return {g_armv7m_compatible_archs};
621 }
623 static const char *g_armv7em_compatible_archs[] = {
624 "armv7em", "armv7", "armv6m", "armv6", "armv5",
625 "armv4", "arm", "thumbv7em", "thumbv7", "thumbv6m",
626 "thumbv6", "thumbv5", "thumbv4t", "thumb",
627 };
628 return {g_armv7em_compatible_archs};
629 }
631 static const char *g_armv6m_compatible_archs[] = {
632 "armv6m", "armv6", "armv5", "armv4", "arm",
633 "thumbv6m", "thumbv6", "thumbv5", "thumbv4t", "thumb",
634 };
635 return {g_armv6m_compatible_archs};
636 }
638 static const char *g_armv6_compatible_archs[] = {
639 "armv6", "armv5", "armv4", "arm",
640 "thumbv6", "thumbv5", "thumbv4t", "thumb",
641 };
642 return {g_armv6_compatible_archs};
643 }
645 static const char *g_armv5_compatible_archs[] = {
646 "armv5", "armv4", "arm", "thumbv5", "thumbv4t", "thumb",
647 };
648 return {g_armv5_compatible_archs};
649 }
651 static const char *g_armv4_compatible_archs[] = {
652 "armv4",
653 "arm",
654 "thumbv4t",
655 "thumb",
656 };
657 return {g_armv4_compatible_archs};
658 }
659 }
660 return {};
661}
662
663/// The architecture selection rules for arm processors These cpu subtypes have
664/// distinct names (e.g. armv7f) but armv7 binaries run fine on an armv7f
665/// processor.
667 std::vector<ArchSpec> &archs, std::optional<llvm::Triple::OSType> os) {
668 const ArchSpec system_arch = GetSystemArchitecture();
669 const ArchSpec::Core system_core = system_arch.GetCore();
670 for (const char *arch : GetCompatibleArchs(system_core)) {
671 llvm::Triple triple;
672 triple.setArchName(arch);
673 triple.setVendor(llvm::Triple::VendorType::Apple);
674 if (os)
675 triple.setOS(*os);
676 archs.push_back(ArchSpec(triple));
677 }
678}
679
681 static FileSpec g_xcode_select_filespec;
682
683 if (!g_xcode_select_filespec) {
684 FileSpec xcode_select_cmd("/usr/bin/xcode-select");
685 if (FileSystem::Instance().Exists(xcode_select_cmd)) {
686 int exit_status = -1;
687 int signo = -1;
688 std::string command_output;
689 Status status =
690 Host::RunShellCommand("/usr/bin/xcode-select --print-path",
691 FileSpec(), // current working directory
692 &exit_status, &signo, &command_output, nullptr,
693 std::chrono::seconds(2), // short timeout
694 false); // don't run in a shell
695 if (status.Success() && exit_status == 0 && !command_output.empty()) {
696 size_t first_non_newline = command_output.find_last_not_of("\r\n");
697 if (first_non_newline != std::string::npos) {
698 command_output.erase(first_non_newline + 1);
699 }
700 g_xcode_select_filespec = FileSpec(command_output);
701 }
702 }
703 }
704
705 return g_xcode_select_filespec;
706}
707
709 BreakpointSP bp_sp;
710 static const char *g_bp_names[] = {
711 "start_wqthread", "_pthread_wqthread", "_pthread_start",
712 };
713
714 static const char *g_bp_modules[] = {"libsystem_c.dylib", "libSystem.B.dylib",
715 "libsystem_pthread.dylib"};
716
717 FileSpecList bp_modules;
718 for (size_t i = 0; i < std::size(g_bp_modules); i++) {
719 const char *bp_module = g_bp_modules[i];
720 bp_modules.EmplaceBack(bp_module);
721 }
722
723 bool internal = true;
724 bool hardware = false;
725 LazyBool skip_prologue = eLazyBoolNo;
726 bp_sp = target.CreateBreakpoint(&bp_modules, nullptr, g_bp_names,
727 std::size(g_bp_names), eFunctionNameTypeFull,
728 eLanguageTypeUnknown, 0, skip_prologue,
729 internal, hardware);
730 bp_sp->SetBreakpointKind("thread-creation");
731
732 return bp_sp;
733}
734
735uint32_t
737 const FileSpec &shell = launch_info.GetShell();
738 if (!shell)
739 return 1;
740
741 std::string shell_string = shell.GetPath();
742 const char *shell_name = strrchr(shell_string.c_str(), '/');
743 if (shell_name == nullptr)
744 shell_name = shell_string.c_str();
745 else
746 shell_name++;
747
748 if (strcmp(shell_name, "sh") == 0) {
749 // /bin/sh re-exec's itself as /bin/bash requiring another resume. But it
750 // only does this if the COMMAND_MODE environment variable is set to
751 // "legacy".
752 if (launch_info.GetEnvironment().lookup("COMMAND_MODE") == "legacy")
753 return 2;
754 return 1;
755 } else if (strcmp(shell_name, "csh") == 0 ||
756 strcmp(shell_name, "tcsh") == 0 ||
757 strcmp(shell_name, "zsh") == 0) {
758 // csh and tcsh always seem to re-exec themselves.
759 return 2;
760 } else
761 return 1;
762}
763
765 Debugger &debugger, Target &target,
766 Status &error) {
767 ProcessSP process_sp;
768
769 if (IsHost()) {
770 // We are going to hand this process off to debugserver which will be in
771 // charge of setting the exit status. However, we still need to reap it
772 // from lldb. So, make sure we use a exit callback which does not set exit
773 // status.
774 launch_info.SetMonitorProcessCallback(
776 process_sp = Platform::DebugProcess(launch_info, debugger, target, error);
777 } else {
779 process_sp = m_remote_platform_sp->DebugProcess(launch_info, debugger,
780 target, error);
781 else
782 error =
783 Status::FromErrorString("the platform is not currently connected");
784 }
785 return process_sp;
786}
787
791
793 static FileSpec g_command_line_tools_filespec;
794
795 if (!g_command_line_tools_filespec) {
796 FileSpec command_line_tools_path(GetXcodeSelectPath());
797 command_line_tools_path.AppendPathComponent("Library");
798 if (FileSystem::Instance().Exists(command_line_tools_path)) {
799 g_command_line_tools_filespec = command_line_tools_path;
800 }
801 }
802
803 return g_command_line_tools_filespec;
804}
805
807 void *baton, llvm::sys::fs::file_type file_type, llvm::StringRef path) {
808 SDKEnumeratorInfo *enumerator_info = static_cast<SDKEnumeratorInfo *>(baton);
809
810 FileSpec spec(path);
811 if (XcodeSDK::SDKSupportsModules(enumerator_info->sdk_type, spec)) {
812 enumerator_info->found_path = spec;
814 }
815
817}
818
820 const FileSpec &sdks_spec) {
821 // Look inside Xcode for the required installed iOS SDK version
822
823 if (!FileSystem::Instance().IsDirectory(sdks_spec)) {
824 return FileSpec();
825 }
826
827 const bool find_directories = true;
828 const bool find_files = false;
829 const bool find_other = true; // include symlinks
830
831 SDKEnumeratorInfo enumerator_info;
832
833 enumerator_info.sdk_type = sdk_type;
834
836 sdks_spec.GetPath(), find_directories, find_files, find_other,
837 DirectoryEnumerator, &enumerator_info);
838
839 if (FileSystem::Instance().IsDirectory(enumerator_info.found_path))
840 return enumerator_info.found_path;
841 else
842 return FileSpec();
843}
844
846 FileSpec sdks_spec = HostInfo::GetXcodeContentsDirectory();
847 sdks_spec.AppendPathComponent("Developer");
848 sdks_spec.AppendPathComponent("Platforms");
849
850 switch (sdk_type) {
852 sdks_spec.AppendPathComponent("MacOSX.platform");
853 break;
855 sdks_spec.AppendPathComponent("iPhoneSimulator.platform");
856 break;
858 sdks_spec.AppendPathComponent("iPhoneOS.platform");
859 break;
861 sdks_spec.AppendPathComponent("WatchSimulator.platform");
862 break;
864 sdks_spec.AppendPathComponent("AppleTVSimulator.platform");
865 break;
867 sdks_spec.AppendPathComponent("XRSimulator.platform");
868 break;
869 default:
870 llvm_unreachable("unsupported sdk");
871 }
872
873 sdks_spec.AppendPathComponent("Developer");
874 sdks_spec.AppendPathComponent("SDKs");
875
876 if (sdk_type == XcodeSDK::Type::MacOSX) {
877 llvm::VersionTuple version = HostInfo::GetOSVersion();
878
879 if (!version.empty()) {
881 // If the Xcode SDKs are not available then try to use the
882 // Command Line Tools one which is only for MacOSX.
883 if (!FileSystem::Instance().Exists(sdks_spec)) {
884 sdks_spec = GetCommandLineToolsLibraryPath();
885 sdks_spec.AppendPathComponent("SDKs");
886 }
887
888 // We slightly prefer the exact SDK for this machine. See if it is
889 // there.
890
891 FileSpec native_sdk_spec = sdks_spec;
892 StreamString native_sdk_name;
893 native_sdk_name.Printf("MacOSX%u.%u.sdk", version.getMajor(),
894 version.getMinor().value_or(0));
895 native_sdk_spec.AppendPathComponent(native_sdk_name.GetString());
896
897 if (FileSystem::Instance().Exists(native_sdk_spec)) {
898 return native_sdk_spec;
899 }
900 }
901 }
902 }
903
904 return FindSDKInXcodeForModules(sdk_type, sdks_spec);
905}
906
907// Discovering the correct version and build can help us
908// identify the most likely SDK directory when looking for
909// files.
910//
911// The directory name can be one of many formats, such as
912// 10.0 (21R329) universal
913// 17.0 (23A200) arm64e
914// 17.0 (20A352)
915// Watch4,2 10.0 (21R329)
916std::tuple<llvm::VersionTuple, llvm::StringRef>
918 llvm::StringRef build;
919 llvm::VersionTuple version;
920
921 llvm::SmallVector<llvm::StringRef> parts;
922 dir.split(parts, ' ');
923 for (llvm::StringRef part : parts) {
924 // Look for an OS version number, eg "17.0"
925 if (isdigit(part[0]))
926 version.tryParse(part);
927 // Look for a build number, eg "(20A352)"
928 if (part.consume_front("(")) {
929 size_t pos = part.find(')');
930 build = part.slice(0, pos);
931 }
932 }
933
934 return std::make_tuple(version, build);
935}
936
937llvm::Expected<StructuredData::DictionarySP>
939 static constexpr llvm::StringLiteral crash_info_key("Crash-Info Annotations");
940 static constexpr llvm::StringLiteral asi_info_key(
941 "Application Specific Information");
942
943 // We cache the information we find in the process extended info dict:
944 StructuredData::DictionarySP process_dict_sp =
945 process.GetExtendedCrashInfoDict();
946 StructuredData::Array *annotations = nullptr;
947 StructuredData::ArraySP new_annotations_sp;
948 if (!process_dict_sp->GetValueForKeyAsArray(crash_info_key, annotations)) {
949 new_annotations_sp = ExtractCrashInfoAnnotations(process);
950 if (new_annotations_sp && new_annotations_sp->GetSize()) {
951 process_dict_sp->AddItem(crash_info_key, new_annotations_sp);
952 annotations = new_annotations_sp.get();
953 }
954 }
955
956 StructuredData::Dictionary *app_specific_info;
957 StructuredData::DictionarySP new_app_specific_info_sp;
958 if (!process_dict_sp->GetValueForKeyAsDictionary(asi_info_key,
959 app_specific_info)) {
960 new_app_specific_info_sp = ExtractAppSpecificInfo(process);
961 if (new_app_specific_info_sp && new_app_specific_info_sp->GetSize()) {
962 process_dict_sp->AddItem(asi_info_key, new_app_specific_info_sp);
963 app_specific_info = new_app_specific_info_sp.get();
964 }
965 }
966
967 // Now get anything else that was in the process info dict, and add it to the
968 // return here:
969 return process_dict_sp->GetSize() ? process_dict_sp : nullptr;
970}
971
975
976 ConstString section_name("__crash_info");
977 Target &target = process.GetTarget();
978 StructuredData::ArraySP array_sp = std::make_shared<StructuredData::Array>();
979
980 for (ModuleSP module : target.GetImages().Modules()) {
981 SectionList *sections = module->GetSectionList();
982
983 std::string module_name = module->GetSpecificationDescription();
984
985 // The DYDL module is skipped since it's always loaded when running the
986 // binary.
987 if (module_name == "/usr/lib/dyld")
988 continue;
989
990 if (!sections) {
991 LLDB_LOG(log, "Module {0} doesn't have any section!", module_name);
992 continue;
993 }
994
995 SectionSP crash_info = sections->FindSectionByName(section_name);
996 if (!crash_info) {
997 LLDB_LOG(log, "Module {0} doesn't have section {1}!", module_name,
998 section_name);
999 continue;
1000 }
1001
1002 addr_t load_addr = crash_info->GetLoadBaseAddress(&target);
1003
1004 if (load_addr == LLDB_INVALID_ADDRESS) {
1005 LLDB_LOG(log, "Module {0} has an invalid '{1}' section load address: {2}",
1006 module_name, section_name, load_addr);
1007 continue;
1008 }
1009
1010 Status error;
1011 CrashInfoAnnotations annotations;
1012 size_t expected_size = sizeof(CrashInfoAnnotations);
1013 size_t bytes_read = process.ReadMemoryFromInferior(load_addr, &annotations,
1014 expected_size, error);
1015
1016 if (expected_size != bytes_read || error.Fail()) {
1017 LLDB_LOG(log, "Failed to read {0} section from memory in module {1}: {2}",
1018 section_name, module_name, error);
1019 continue;
1020 }
1021
1022 // initial support added for version 5
1023 if (annotations.version < 5) {
1024 LLDB_LOG(log,
1025 "Annotation version lower than 5 unsupported! Module {0} has "
1026 "version {1} instead.",
1027 module_name, annotations.version);
1028 continue;
1029 }
1030
1031 if (!annotations.message) {
1032 LLDB_LOG(log, "No message available for module {0}.", module_name);
1033 continue;
1034 }
1035
1036 std::string message;
1037 bytes_read =
1038 process.ReadCStringFromMemory(annotations.message, message, error);
1039
1040 if (message.empty() || bytes_read != message.size() || error.Fail()) {
1041 LLDB_LOG(log, "Failed to read the message from memory in module {0}: {1}",
1042 module_name, error);
1043 continue;
1044 }
1045
1046 // Remove trailing newline from message
1047 if (message.back() == '\n')
1048 message.pop_back();
1049
1050 if (!annotations.message2)
1051 LLDB_LOG(log, "No message2 available for module {0}.", module_name);
1052
1053 std::string message2;
1054 bytes_read =
1055 process.ReadCStringFromMemory(annotations.message2, message2, error);
1056
1057 if (!message2.empty() && bytes_read == message2.size() && error.Success())
1058 if (message2.back() == '\n')
1059 message2.pop_back();
1060
1062 std::make_shared<StructuredData::Dictionary>();
1063
1064 entry_sp->AddStringItem("image", module->GetFileSpec().GetPath(false));
1065 entry_sp->AddStringItem("uuid", module->GetUUID().GetAsString());
1066 entry_sp->AddStringItem("message", message);
1067 entry_sp->AddStringItem("message2", message2);
1068 entry_sp->AddIntegerItem("abort-cause", annotations.abort_cause);
1069
1070 array_sp->AddItem(entry_sp);
1071 }
1072
1073 return array_sp;
1074}
1075
1078 StructuredData::DictionarySP metadata_sp = process.GetMetadata();
1079
1080 if (!metadata_sp || !metadata_sp->GetSize() || !metadata_sp->HasKey("asi"))
1081 return {};
1082
1084 if (!metadata_sp->GetValueForKeyAsDictionary("asi", asi))
1085 return {};
1086
1088 std::make_shared<StructuredData::Dictionary>();
1089
1090 auto flatten_asi_dict = [&dict_sp](llvm::StringRef key,
1091 StructuredData::Object *val) -> bool {
1092 if (!val)
1093 return false;
1094
1095 StructuredData::Array *arr = val->GetAsArray();
1096 if (!arr || !arr->GetSize())
1097 return false;
1098
1099 dict_sp->AddItem(key, arr->GetItemAtIndex(0));
1100 return true;
1101 };
1102
1103 asi->ForEach(flatten_asi_dict);
1104
1105 return dict_sp;
1106}
1107
1108static llvm::Expected<lldb_private::FileSpec>
1110
1111 ModuleSP exe_module_sp = target->GetExecutableModule();
1112 if (!exe_module_sp)
1113 return llvm::createStringError("could not get module from target");
1114
1115 SymbolFile *sym_file = exe_module_sp->GetSymbolFile();
1116 if (!sym_file)
1117 return llvm::createStringError("could not get symbol file from executable");
1118
1119 if (sym_file->GetNumCompileUnits() == 0)
1120 return llvm::createStringError(
1121 "could not resolve SDK for target: executable's symbol file has no "
1122 "compile units");
1123
1124 XcodeSDK merged_sdk;
1125 for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i)
1126 if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i))
1127 merged_sdk.Merge(sym_file->ParseXcodeSDK(*cu_sp));
1128
1129 // TODO: The result of this loop is almost equivalent to deriving the SDK
1130 // from the target triple, which would be a lot cheaper.
1131 return PlatformDarwin::ResolveXcodeSDK(std::move(merged_sdk));
1132}
1133
1135 Target *target, std::vector<std::string> &options, XcodeSDK::Type sdk_type) {
1136 const std::vector<std::string> apple_arguments = {
1137 "-x", "objective-c++", "-fobjc-arc",
1138 "-fblocks", "-D_ISO646_H", "-D__ISO646_H",
1139 "-fgnuc-version=4.2.1"};
1140
1141 options.insert(options.end(), apple_arguments.begin(), apple_arguments.end());
1142
1143 StreamString minimum_version_option;
1144 bool use_current_os_version = false;
1145 // If the SDK type is for the host OS, use its version number.
1146 auto get_host_os = []() { return HostInfo::GetTargetTriple().getOS(); };
1147 switch (sdk_type) {
1149 use_current_os_version = get_host_os() == llvm::Triple::MacOSX;
1150 break;
1152 use_current_os_version = get_host_os() == llvm::Triple::IOS;
1153 break;
1155 use_current_os_version = get_host_os() == llvm::Triple::TvOS;
1156 break;
1158 use_current_os_version = get_host_os() == llvm::Triple::WatchOS;
1159 break;
1161 use_current_os_version = get_host_os() == llvm::Triple::XROS;
1162 break;
1163 default:
1164 break;
1165 }
1166
1167 llvm::VersionTuple version;
1168 if (use_current_os_version)
1169 version = GetOSVersion();
1170 else if (target) {
1171 // Our OS doesn't match our executable so we need to get the min OS version
1172 // from the object file
1173 ModuleSP exe_module_sp = target->GetExecutableModule();
1174 if (exe_module_sp) {
1175 ObjectFile *object_file = exe_module_sp->GetObjectFile();
1176 if (object_file)
1177 version = object_file->GetMinimumOSVersion();
1178 }
1179 }
1180 // Only add the version-min options if we got a version from somewhere.
1181 // clang has no version-min clang flag for XROS.
1182 if (!version.empty() && sdk_type != XcodeSDK::Type::Linux &&
1183 sdk_type != XcodeSDK::Type::XROS) {
1184#define OPTION(PREFIX_OFFSET, NAME_OFFSET, VAR, ...) \
1185 llvm::StringRef opt_##VAR = OptionStrTable[NAME_OFFSET]; \
1186 (void)opt_##VAR;
1187#include "clang/Options/Options.inc"
1188#undef OPTION
1189 minimum_version_option << '-';
1190 switch (sdk_type) {
1192 minimum_version_option << opt_mmacos_version_min_EQ;
1193 break;
1195 minimum_version_option << opt_mios_simulator_version_min_EQ;
1196 break;
1198 minimum_version_option << opt_mios_version_min_EQ;
1199 break;
1201 minimum_version_option << opt_mtvos_simulator_version_min_EQ;
1202 break;
1204 minimum_version_option << opt_mtvos_version_min_EQ;
1205 break;
1207 minimum_version_option << opt_mwatchos_simulator_version_min_EQ;
1208 break;
1210 minimum_version_option << opt_mwatchos_version_min_EQ;
1211 break;
1214 // FIXME: Pass the right argument once it exists.
1218 if (Log *log = GetLog(LLDBLog::Host)) {
1219 XcodeSDK::Info info;
1220 info.type = sdk_type;
1221 LLDB_LOGF(log, "Clang modules on %s are not supported",
1222 XcodeSDK::GetCanonicalName(info).c_str());
1223 }
1224 return;
1225 }
1226 minimum_version_option << version.getAsString();
1227 options.emplace_back(std::string(minimum_version_option.GetString()));
1228 }
1229
1230 FileSpec sysroot_spec;
1231
1232 if (target) {
1233 auto sysroot_spec_or_err = ::ResolveSDKPathFromDebugInfo(target);
1234 if (!sysroot_spec_or_err) {
1236 sysroot_spec_or_err.takeError(),
1237 "Failed to resolve sysroot: {0}");
1238 } else {
1239 sysroot_spec = *sysroot_spec_or_err;
1240 }
1241 }
1242
1243 if (!FileSystem::Instance().IsDirectory(sysroot_spec.GetPath())) {
1244 std::lock_guard<std::mutex> guard(m_mutex);
1245 sysroot_spec = GetSDKDirectoryForModules(sdk_type);
1246 }
1247
1248 if (FileSystem::Instance().IsDirectory(sysroot_spec.GetPath())) {
1249 options.push_back("-isysroot");
1250 options.push_back(sysroot_spec.GetPath());
1251 }
1252}
1253
1255 if (basename.IsEmpty())
1256 return basename;
1257
1258 StreamString stream;
1259 stream.Printf("lib%s.dylib", basename.GetCString());
1260 return ConstString(stream.GetString());
1261}
1262
1263llvm::VersionTuple PlatformDarwin::GetOSVersion(Process *process) {
1264 if (process && GetPluginName().contains("-simulator")) {
1266 if (Host::GetProcessInfo(process->GetID(), proc_info)) {
1267 const Environment &env = proc_info.GetEnvironment();
1268
1269 llvm::VersionTuple result;
1270 if (!result.tryParse(env.lookup("SIMULATOR_RUNTIME_VERSION")))
1271 return result;
1272
1273 std::string dyld_root_path = env.lookup("DYLD_ROOT_PATH");
1274 if (!dyld_root_path.empty()) {
1275 dyld_root_path += "/System/Library/CoreServices/SystemVersion.plist";
1276 ApplePropertyList system_version_plist(dyld_root_path.c_str());
1277 std::string product_version;
1278 if (system_version_plist.GetValueAsString("ProductVersion",
1279 product_version)) {
1280 if (!result.tryParse(product_version))
1281 return result;
1282 }
1283 }
1284 }
1285 // For simulator platforms, do NOT call back through
1286 // Platform::GetOSVersion() as it might call Process::GetHostOSVersion()
1287 // which we don't want as it will be incorrect
1288 return llvm::VersionTuple();
1289 }
1290
1291 return Platform::GetOSVersion(process);
1292}
1293
1295 // A collection of SBFileSpec whose SBFileSpec.m_directory members are filled
1296 // in with any executable directories that should be searched.
1297 static std::vector<FileSpec> g_executable_dirs;
1298
1299 // Find the global list of directories that we will search for executables
1300 // once so we don't keep doing the work over and over.
1301 static llvm::once_flag g_once_flag;
1302 llvm::call_once(g_once_flag, []() {
1303
1304 // When locating executables, trust the DEVELOPER_DIR first if it is set
1305 FileSpec xcode_contents_dir = HostInfo::GetXcodeContentsDirectory();
1306 if (xcode_contents_dir) {
1307 FileSpec xcode_lldb_resources = xcode_contents_dir;
1308 xcode_lldb_resources.AppendPathComponent("SharedFrameworks");
1309 xcode_lldb_resources.AppendPathComponent("LLDB.framework");
1310 xcode_lldb_resources.AppendPathComponent("Resources");
1311 if (FileSystem::Instance().Exists(xcode_lldb_resources)) {
1312 FileSpec dir;
1313 dir.SetDirectory(xcode_lldb_resources.GetPathAsConstString());
1314 g_executable_dirs.push_back(dir);
1315 }
1316 }
1317 // Xcode might not be installed so we also check for the Command Line Tools.
1318 FileSpec command_line_tools_dir = GetCommandLineToolsLibraryPath();
1319 if (command_line_tools_dir) {
1320 FileSpec cmd_line_lldb_resources = command_line_tools_dir;
1321 cmd_line_lldb_resources.AppendPathComponent("PrivateFrameworks");
1322 cmd_line_lldb_resources.AppendPathComponent("LLDB.framework");
1323 cmd_line_lldb_resources.AppendPathComponent("Resources");
1324 if (FileSystem::Instance().Exists(cmd_line_lldb_resources)) {
1325 FileSpec dir;
1326 dir.SetDirectory(cmd_line_lldb_resources.GetPathAsConstString());
1327 g_executable_dirs.push_back(dir);
1328 }
1329 }
1330 });
1331
1332 // Now search the global list of executable directories for the executable we
1333 // are looking for
1334 for (const auto &executable_dir : g_executable_dirs) {
1335 FileSpec executable_file;
1336 executable_file.SetDirectory(executable_dir.GetDirectory());
1337 executable_file.SetFilename(basename);
1338 if (FileSystem::Instance().Exists(executable_file))
1339 return executable_file;
1340 }
1341
1342 return FileSpec();
1343}
1344
1347 // Starting in Fall 2016 OSes, NSLog messages only get mirrored to stderr if
1348 // the OS_ACTIVITY_DT_MODE environment variable is set. (It doesn't require
1349 // any specific value; rather, it just needs to exist). We will set it here
1350 // as long as the IDE_DISABLED_OS_ACTIVITY_DT_MODE flag is not set. Xcode
1351 // makes use of IDE_DISABLED_OS_ACTIVITY_DT_MODE to tell
1352 // LLDB *not* to muck with the OS_ACTIVITY_DT_MODE flag when they
1353 // specifically want it unset.
1354 const char *disable_env_var = "IDE_DISABLED_OS_ACTIVITY_DT_MODE";
1355 auto &env_vars = launch_info.GetEnvironment();
1356 if (!env_vars.count(disable_env_var)) {
1357 // We want to make sure that OS_ACTIVITY_DT_MODE is set so that we get
1358 // os_log and NSLog messages mirrored to the target process stderr.
1359 env_vars.try_emplace("OS_ACTIVITY_DT_MODE", "enable");
1360 }
1361
1362 // Let our parent class do the real launching.
1363 return PlatformPOSIX::LaunchProcess(launch_info);
1364}
1365
1367 const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp,
1368 llvm::SmallVectorImpl<ModuleSP> *old_modules, bool *did_create_ptr) {
1369 const FileSpec &platform_file = module_spec.GetFileSpec();
1370 TargetSP target_sp = module_spec.GetTargetSP();
1371 FileSpecList module_search_paths;
1372 if (target_sp)
1373 module_search_paths = target_sp->GetExecutableSearchPaths();
1374 // See if the file is present in any of the module_search_paths
1375 // directories.
1376 if (!module_sp && !module_search_paths.IsEmpty() && platform_file) {
1377 // create a vector of all the file / directory names in platform_file e.g.
1378 // this might be
1379 // /System/Library/PrivateFrameworks/UIFoundation.framework/UIFoundation
1380 //
1381 // We'll need to look in the module_search_paths_ptr directories for both
1382 // "UIFoundation" and "UIFoundation.framework" -- most likely the latter
1383 // will be the one we find there.
1384
1385 std::vector<llvm::StringRef> path_parts = platform_file.GetComponents();
1386 // We want the components in reverse order.
1387 std::reverse(path_parts.begin(), path_parts.end());
1388 const size_t path_parts_size = path_parts.size();
1389
1390 size_t num_module_search_paths = module_search_paths.GetSize();
1391 for (size_t i = 0; i < num_module_search_paths; ++i) {
1392 Log *log_verbose = GetLog(LLDBLog::Host);
1393 LLDB_LOGF(
1394 log_verbose,
1395 "PlatformRemoteDarwinDevice::GetSharedModule searching for binary in "
1396 "search-path %s",
1397 module_search_paths.GetFileSpecAtIndex(i).GetPath().c_str());
1398 // Create a new FileSpec with this module_search_paths_ptr plus just the
1399 // filename ("UIFoundation"), then the parent dir plus filename
1400 // ("UIFoundation.framework/UIFoundation") etc - up to four names (to
1401 // handle "Foo.framework/Contents/MacOS/Foo")
1402
1403 for (size_t j = 0; j < 4 && j < path_parts_size - 1; ++j) {
1404 FileSpec path_to_try(module_search_paths.GetFileSpecAtIndex(i));
1405
1406 // Add the components backwards. For
1407 // .../PrivateFrameworks/UIFoundation.framework/UIFoundation path_parts
1408 // is
1409 // [0] UIFoundation
1410 // [1] UIFoundation.framework
1411 // [2] PrivateFrameworks
1412 //
1413 // and if 'j' is 2, we want to append path_parts[1] and then
1414 // path_parts[0], aka 'UIFoundation.framework/UIFoundation', to the
1415 // module_search_paths_ptr path.
1416
1417 for (int k = j; k >= 0; --k) {
1418 path_to_try.AppendPathComponent(path_parts[k]);
1419 }
1420
1421 if (FileSystem::Instance().Exists(path_to_try)) {
1422 ModuleSpec new_module_spec(module_spec);
1423 new_module_spec.GetFileSpec() = path_to_try;
1424 Status new_error(Platform::GetSharedModule(new_module_spec, process,
1425 module_sp, old_modules,
1426 did_create_ptr));
1427
1428 if (module_sp) {
1429 module_sp->SetPlatformFileSpec(path_to_try);
1430 return new_error;
1431 }
1432 }
1433 }
1434 }
1435 }
1436 return Status();
1437}
1438
1439llvm::Triple::OSType PlatformDarwin::GetHostOSType() {
1440#if !defined(__APPLE__)
1441 return llvm::Triple::MacOSX;
1442#else
1443#if TARGET_OS_OSX
1444 return llvm::Triple::MacOSX;
1445#elif TARGET_OS_IOS
1446 return llvm::Triple::IOS;
1447#elif TARGET_OS_WATCH
1448 return llvm::Triple::WatchOS;
1449#elif TARGET_OS_TV
1450 return llvm::Triple::TvOS;
1451#elif TARGET_OS_BRIDGE
1452 return llvm::Triple::BridgeOS;
1453#elif TARGET_OS_XR
1454 return llvm::Triple::XROS;
1455#else
1456#error "LLDB being compiled for an unrecognized Darwin OS"
1457#endif
1458#endif // __APPLE__
1459}
1460
1461llvm::Expected<std::pair<XcodeSDK, bool>>
1463 SymbolFile *sym_file = module.GetSymbolFile();
1464 if (!sym_file)
1465 return llvm::createStringError(
1466 llvm::inconvertibleErrorCode(),
1467 llvm::formatv("No symbol file available for module '{0}'",
1468 module.GetFileSpec().GetFilename().AsCString("")));
1469
1470 if (sym_file->GetNumCompileUnits() == 0)
1471 return llvm::createStringError(
1472 llvm::formatv("Could not resolve SDK for module '{0}'. Symbol file has "
1473 "no compile units.",
1474 module.GetFileSpec()));
1475
1476 bool found_public_sdk = false;
1477 bool found_internal_sdk = false;
1478 XcodeSDK merged_sdk;
1479 for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) {
1480 if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) {
1481 auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp);
1482 bool is_internal_sdk = cu_sdk.IsAppleInternalSDK();
1483 found_public_sdk |= !is_internal_sdk;
1484 found_internal_sdk |= is_internal_sdk;
1485
1486 merged_sdk.Merge(cu_sdk);
1487 }
1488 }
1489
1490 const bool found_mismatch = found_internal_sdk && found_public_sdk;
1491
1492 return std::pair{std::move(merged_sdk), found_mismatch};
1493}
1494
1495llvm::Expected<FileSpec> PlatformDarwin::ResolveXcodeSDK(XcodeSDK sdk) {
1496 if (FileSpec sysroot = sdk.GetSysroot();
1497 FileSystem::Instance().Exists(sysroot))
1498 return sysroot;
1499
1500 Progress progress("Looking for Xcode SDK", sdk.GetString().str());
1501 auto path_or_err = HostInfo::GetSDKRoot(HostInfo::SDKOptions{sdk});
1502 if (!path_or_err)
1503 return llvm::joinErrors(llvm::createStringError(llvm::formatv(
1504 "could not find SDK '{0}'", sdk.GetString())),
1505 path_or_err.takeError());
1506 return FileSpec(*path_or_err);
1507}
1508
1509llvm::Expected<std::string>
1511 auto sdk_or_err = GetSDKPathFromDebugInfo(module);
1512 if (!sdk_or_err)
1513 return llvm::joinErrors(
1514 llvm::createStringError("could not parse SDK path from debug-info"),
1515 sdk_or_err.takeError());
1516
1517 auto path_or_err = ResolveXcodeSDK(std::move(sdk_or_err->first));
1518 if (!path_or_err)
1519 return path_or_err.takeError();
1520 return path_or_err->GetPath();
1521}
1522
1523llvm::Expected<XcodeSDK>
1525 ModuleSP module_sp = unit.CalculateSymbolContextModule();
1526 if (!module_sp)
1527 return llvm::createStringError("compile unit has no module");
1528 SymbolFile *sym_file = module_sp->GetSymbolFile();
1529 if (!sym_file)
1530 return llvm::createStringError(
1531 llvm::formatv("No symbol file available for module '{0}'",
1532 module_sp->GetFileSpec().GetFilename()));
1533
1534 return sym_file->ParseXcodeSDK(unit);
1535}
1536
1537llvm::Expected<std::string>
1539 auto sdk_or_err = GetSDKPathFromDebugInfo(unit);
1540 if (!sdk_or_err)
1541 return llvm::joinErrors(
1542 llvm::createStringError("could not parse SDK path from debug-info"),
1543 sdk_or_err.takeError());
1544
1545 auto path_or_err = ResolveXcodeSDK(std::move(*sdk_or_err));
1546 if (!path_or_err)
1547 return path_or_err.takeError();
1548 return path_or_err->GetPath();
1549}
1550
1551llvm::Expected<FileSpecList>
1554
1555 XcodeSDK::Type sdk_type =
1557 XcodeSDK::Info info;
1558 info.type = sdk_type;
1559 XcodeSDK sdk(info);
1560
1561 auto sdk_root_or_err = ResolveXcodeSDK(sdk);
1562 if (!sdk_root_or_err) {
1563 LLDB_LOG_ERROR(log, sdk_root_or_err.takeError(),
1564 "Failed to resolve SDK root for triple '{1}': {0}",
1565 target.GetArchitecture().GetTriple().str());
1566
1567 // Fall back to any macOS SDK.
1568 sdk = XcodeSDK::GetAnyMacOS();
1569 LLDB_LOG(log, "Falling back to SDK '{0}'", sdk.GetString());
1570 sdk_root_or_err = ResolveXcodeSDK(sdk);
1571 }
1572
1573 if (!sdk_root_or_err)
1574 return sdk_root_or_err.takeError();
1575
1576 // $SDKROOT/usr/share/lldb is an auto-loadable path.
1577 llvm::SmallString<256> resolved(sdk_root_or_err->GetPath());
1578 llvm::sys::path::append(resolved, "usr", "share", "lldb");
1579
1580 FileSpecList fspecs;
1581 fspecs.Append(FileSpec(resolved));
1582
1583 return fspecs;
1584}
static llvm::raw_ostream & error(Stream &strm)
static DynamicLoaderDarwinKernelProperties & GetGlobalProperties()
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:364
#define LLDB_LOGF(log,...)
Definition Log.h:378
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:394
static uint32_t g_initialize_count
static llvm::Expected< lldb_private::FileSpec > ResolveSDKPathFromDebugInfo(lldb_private::Target *target)
static Status ExceptionMaskValidator(const char *string, void *unused)
static llvm::ArrayRef< const char * > GetCompatibleArchs(ArchSpec::Core core)
static FileSpec GetXcodeSelectPath()
static FileSpec GetCommandLineToolsLibraryPath()
static llvm::StringRef GetSettingName()
OptionValueString * GetIgnoredExceptionValue()
const char * GetIgnoredExceptions() const
~PlatformDarwinProperties() override=default
lldb_private::Status PutFile(const lldb_private::FileSpec &source, const lldb_private::FileSpec &destination, uint32_t uid=UINT32_MAX, uint32_t gid=UINT32_MAX) override
bool GetValueAsString(const char *key, std::string &value) const
Definition XML.cpp:404
An architecture specification class.
Definition ArchSpec.h:32
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition ArchSpec.h:460
bool IsExactMatch(const ArchSpec &rhs) const
Shorthand for IsMatch(rhs, ExactMatch).
Definition ArchSpec.h:507
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition ArchSpec.cpp:682
Core GetCore() const
Definition ArchSpec.h:451
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
Class that manages the actual breakpoint that will be inserted into the running program.
bool SetTrapOpcode(const uint8_t *trap_opcode, uint32_t trap_opcode_size)
Sets the trap opcode.
lldb::BreakpointLocationSP GetConstituentAtIndex(size_t idx)
This method returns the breakpoint location at index index located at this breakpoint site.
A class that describes a compilation unit.
Definition CompileUnit.h:43
lldb::ModuleSP CalculateSymbolContextModule() override
A uniqued constant string class.
Definition ConstString.h:40
bool IsEmpty() const
Test for empty string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
const char * GetCString() const
Get the string value as a C string.
const char * AsCString(const char *value_if_empty) const
Get the string value as a C string.
A class to manage flag bits.
Definition Debugger.h:100
lldb::ScriptLanguage GetScriptLanguage() const
Definition Debugger.cpp:437
ScriptInterpreter * GetScriptInterpreter(bool can_create=true, std::optional< lldb::ScriptLanguage > language={})
virtual bool GetSharedCacheInformation(lldb::addr_t &base_address, UUID &uuid, LazyBool &using_shared_cache, LazyBool &private_shared_cache, lldb_private::FileSpec &shared_cache_path, std::optional< uint64_t > &size)
Get information about the shared cache for a process, if possible.
A file collection class.
const FileSpec & GetFileSpecAtIndex(size_t idx) const
Get file at index.
void EmplaceBack(Args &&...args)
Inserts a new FileSpec into the FileSpecList constructed in-place with the given arguments.
void Append(const FileSpec &file)
Append a FileSpec object to the list.
size_t GetSize() const
Get the number of files in the file list.
A file utility class.
Definition FileSpec.h:57
void AppendPathComponent(llvm::StringRef component)
Definition FileSpec.cpp:454
void SetDirectory(ConstString directory)
Directory string set accessor.
Definition FileSpec.cpp:342
const ConstString & GetFilename() const
Filename string const get accessor.
Definition FileSpec.h:250
std::vector< llvm::StringRef > GetComponents() const
Gets the components of the FileSpec's path.
Definition FileSpec.cpp:475
const ConstString & GetDirectory() const
Directory string const get accessor.
Definition FileSpec.h:234
ConstString GetFileNameStrippingExtension() const
Return the filename without the extension part.
Definition FileSpec.cpp:414
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
void SetFilename(ConstString filename)
Filename string set accessor.
Definition FileSpec.cpp:352
void EnumerateDirectory(llvm::Twine path, bool find_directories, bool find_files, bool find_other, EnumerateDirectoryCallbackType callback, void *callback_baton)
@ eEnumerateDirectoryResultNext
Enumerate next entry in the current directory.
Definition FileSystem.h:182
static FileSystem & Instance()
void Resolve(llvm::SmallVectorImpl< char > &path, bool force_make_absolute=false)
Resolve path to make it canonical.
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 ResolveExecutableInBundle(FileSpec &file)
When executable files may live within a directory, where the directory represents an executable bundl...
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.
static bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info)
Definition aix/Host.cpp:211
static bool GetBundleDirectory(const FileSpec &file, FileSpec &bundle_directory)
If you have an executable that is in a bundle and want to get back to the bundle directory from the p...
lldb::SymbolSharedCacheUse GetSharedCacheBinaryLoading() const
static Status GetSharedModule(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr, bool invoke_locate_callback=true)
static ModuleListProperties & GetGlobalModuleListProperties()
ModuleIterable Modules() const
Definition ModuleList.h:570
FileSpec & GetFileSpec()
Definition ModuleSpec.h:57
FileSpec & GetSymbolFileSpec()
Definition ModuleSpec.h:81
ArchSpec * GetArchitecturePtr()
Definition ModuleSpec.h:85
lldb::TargetSP GetTargetSP() const
Definition ModuleSpec.h:133
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:91
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition Module.h:447
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
@ eTypeDynamicLinker
The platform's dynamic linker executable.
Definition ObjectFile.h:59
virtual llvm::VersionTuple GetMinimumOSVersion()
Get the minimum OS version this object file can run on.
Definition ObjectFile.h:616
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
Definition ObjectFile.h:280
void SetValidator(ValidatorCallback validator, void *baton=nullptr)
const char * GetCurrentValue() const
StructuredData::ArraySP ExtractCrashInfoAnnotations(Process &process)
Extract the __crash_info annotations from each of the target's modules.
bool IsSymbolFileTrusted(Module &module) override
Returns true if the module's symbol file (e.g.
llvm::Expected< StructuredData::DictionarySP > FetchExtendedCrashInformation(Process &process) override
Gather all of crash informations into a structured data dictionary.
~PlatformDarwin() override
Destructor.
static FileSpec GetSDKDirectoryForModules(XcodeSDK::Type sdk_type)
Status GetModuleFromSharedCaches(const ModuleSpec &module_spec, Process *process, lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr)
Status ResolveSymbolFile(Target &target, const ModuleSpec &sym_spec, FileSpec &sym_file) override
Find a symbol file given a symbol file module specification.
void CalculateTrapHandlerSymbolNames() override
Ask the Platform subclass to fill in the list of trap handler names.
static std::tuple< llvm::VersionTuple, llvm::StringRef > ParseVersionBuildDir(llvm::StringRef str)
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch)
llvm::VersionTuple GetOSVersion(Process *process=nullptr) override
Get the OS version from a connected platform.
Status GetSharedModule(const ModuleSpec &module_spec, Process *process, lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr) override
static FileSystem::EnumerateDirectoryResult DirectoryEnumerator(void *baton, llvm::sys::fs::file_type file_type, llvm::StringRef path)
static FileSpec FindSDKInXcodeForModules(XcodeSDK::Type sdk_type, const FileSpec &sdks_spec)
ConstString GetFullNameForDylib(ConstString basename) override
static void DebuggerInitialize(lldb_private::Debugger &debugger)
static llvm::StringRef GetPluginNameStatic()
static llvm::Triple::OSType GetHostOSType()
StructuredData::DictionarySP ExtractAppSpecificInfo(Process &process)
Extract the Application Specific Information messages from a crash report.
lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, Target &target, Status &error) override
Subclasses do not need to implement this function as it uses the Platform::LaunchProcess() followed b...
lldb::BreakpointSP SetThreadCreationBreakpoint(Target &target) override
static llvm::StringRef GetDescriptionStatic()
Status FindBundleBinaryInExecSearchPaths(const ModuleSpec &module_spec, Process *process, lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr)
Status LaunchProcess(ProcessLaunchInfo &launch_info) override
Launch a new process on a platform, not necessarily for debugging, it could be just for running the p...
uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) override
llvm::Expected< std::string > ResolveSDKPathFromDebugInfo(Module &module) override
Returns the full path of the most appropriate SDK for the specified 'module'.
size_t GetSoftwareBreakpointTrapOpcode(Target &target, BreakpointSite *bp_site) override
void AddClangModuleCompilationOptionsForSDKType(Target *target, std::vector< std::string > &options, XcodeSDK::Type sdk_type)
Args GetExtraStartupCommands() override
Status PutFile(const FileSpec &source, const FileSpec &destination, uint32_t uid=UINT32_MAX, uint32_t gid=UINT32_MAX) override
static llvm::SmallDenseMap< FileSpec, LoadScriptFromSymFile > LocateExecutableScriptingResourcesFromDSYM(Stream &feedback_stream, FileSpec module_spec, const Target &target, const FileSpec &symfile_spec)
Helper function for LocateExecutableScriptingResources which gathers FileSpecs for executable scripts...
FileSpec LocateExecutable(const char *basename) override
Find a support executable that may not live within in the standard locations related to LLDB.
void x86GetSupportedArchitectures(std::vector< ArchSpec > &archs)
llvm::Expected< std::pair< XcodeSDK, bool > > GetSDKPathFromDebugInfo(Module &module) override
Search each CU associated with the specified 'module' for the SDK paths the CUs were compiled against...
llvm::SmallDenseMap< FileSpec, LoadScriptFromSymFile > LocateExecutableScriptingResourcesForPlatform(Target *target, Module &module_spec, Stream &feedback_stream) override
Locate the platform-specific scripting resource given a module specification.
llvm::Expected< FileSpecList > GetSafeAutoLoadPaths(const Target &target) const override
Returns a FileSpecList of safe paths to auto-load scripting resources from for a particular platform.
bool ModuleIsExcludedForUnconstrainedSearches(Target &target, const lldb::ModuleSP &module_sp) override
static llvm::Expected< FileSpec > ResolveXcodeSDK(XcodeSDK sdk)
Resolve an XcodeSDK to an on-disk path under a Progress event.
void ARMGetSupportedArchitectures(std::vector< ArchSpec > &archs, std::optional< llvm::Triple::OSType > os={})
The architecture selection rules for arm processors These cpu subtypes have distinct names (e....
std::vector< ConstString > m_trap_handlers
Definition Platform.h:1091
virtual size_t GetSoftwareBreakpointTrapOpcode(Target &target, BreakpointSite *bp_site)
virtual lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, Target &target, Status &error)
Subclasses do not need to implement this function as it uses the Platform::LaunchProcess() followed b...
virtual Status GetSharedModule(const ModuleSpec &module_spec, Process *process, lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr)
Definition Platform.cpp:259
const ArchSpec & GetSystemArchitecture()
Definition Platform.cpp:907
static void WarnIfInvalidUnsanitizedScriptExists(Stream &os, const ScriptInterpreter::SanitizedScriptingModuleName &sanitized_name, const FileSpec &original_fspec, const FileSpec &fspec)
If we did some replacements of reserved characters, and a file with the untampered name exists,...
virtual llvm::VersionTuple GetOSVersion(Process *process=nullptr)
Get the OS version from a connected platform.
Definition Platform.cpp:391
virtual Status LaunchProcess(ProcessLaunchInfo &launch_info)
Launch a new process on a platform, not necessarily for debugging, it could be just for running the p...
bool IsRemote() const
Definition Platform.h:561
bool IsHost() const
Definition Platform.h:557
static LoadScriptFromSymFile GetScriptLoadStyleForModule(const FileSpec &module_fspec, const Target &target)
Returns the LoadScriptFromSymFile of scripting resource associated with the specified module FileSpec...
Definition Platform.cpp:166
virtual llvm::StringRef GetPluginName()=0
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static lldb::OptionValuePropertiesSP GetSettingForPlatformPlugin(Debugger &debugger, llvm::StringRef setting_name)
static bool CreateSettingForPlatformPlugin(Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, llvm::StringRef description, bool is_global_property)
static bool UnregisterPlugin(ABICreateInstance create_callback)
static FileSpec FindSymbolFileInBundle(const FileSpec &dsym_bundle_fspec, const UUID *uuid, const ArchSpec *arch)
Environment & GetEnvironment()
Definition ProcessInfo.h:88
const FileSpec & GetShell() const
static void NoOpMonitorCallback(lldb::pid_t pid, int signal, int status)
A Monitor callback which does not take any action on process events.
void SetMonitorProcessCallback(Host::MonitorChildProcessCallback callback)
A plug-in interface definition class for debugging a process.
Definition Process.h:357
lldb::pid_t GetID() const
Returns the pid of the process or LLDB_INVALID_PROCESS_ID if there is no known pid.
Definition Process.h:540
size_t ReadMemoryFromInferior(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
Definition Process.cpp:2371
virtual StructuredData::DictionarySP GetMetadata()
Fetch process defined metadata.
Definition Process.h:2779
size_t ReadCStringFromMemory(lldb::addr_t vm_addr, char *cstr, size_t cstr_max_len, Status &error)
Read a NULL terminated C string from memory.
Definition Process.cpp:2325
StructuredData::DictionarySP GetExtendedCrashInfoDict()
Fetch extended crash information held by the process.
Definition Process.h:2784
virtual DynamicLoader * GetDynamicLoader()
Get the dynamic loader plug-in for this process.
Definition Process.cpp:3090
Target & GetTarget()
Get the target object pointer for this module.
Definition Process.h:1255
A Progress indicator helper class.
Definition Progress.h:60
lldb::OptionValuePropertiesSP m_collection_sp
Status Unlink(const FileSpec &file_spec) override
Holds an lldb_private::Module name and a "sanitized" version of it for the purposes of loading a scri...
virtual SanitizedScriptingModuleName GetSanitizedScriptingModuleName(llvm::StringRef name)
lldb::SectionSP FindSectionByName(ConstString section_dstr) const
Definition Section.cpp:556
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
bool Success() const
Test for success condition.
Definition Status.cpp:303
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
Definition Stream.h:28
void Format(const char *format, Args &&... args)
Forwards the arguments to llvm::formatv and writes to the stream.
Definition Stream.h:370
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
ObjectSP GetItemAtIndex(size_t idx) const
void ForEach(std::function< bool(llvm::StringRef key, Object *object)> const &callback) const
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Array > ArraySP
Provides public interface for all SymbolFiles.
Definition SymbolFile.h:51
virtual XcodeSDK ParseXcodeSDK(CompileUnit &comp_unit)
Return the Xcode SDK comp_unit was compiled against.
Definition SymbolFile.h:152
virtual uint32_t GetNumCompileUnits()=0
virtual lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx)=0
virtual ObjectFile * GetObjectFile()=0
Debugger & GetDebugger() const
Definition Target.h:1324
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
Definition Target.cpp:1593
lldb::BreakpointSP CreateBreakpoint(const FileSpecList *containingModules, const FileSpec &file, uint32_t line_no, uint32_t column, lldb::addr_t offset, LazyBool check_inlines, LazyBool skip_prologue, bool internal, bool request_hardware, LazyBool move_to_nearest_code)
Definition Target.cpp:504
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition Target.h:1241
const ArchSpec & GetArchitecture() const
Definition Target.h:1283
Represents UUID's of various sizes.
Definition UUID.h:27
An abstraction for Xcode-style SDKs that works like ArchSpec.
Definition XcodeSDK.h:25
Type
Different types of Xcode SDKs.
Definition XcodeSDK.h:31
const FileSpec & GetSysroot() const
Definition XcodeSDK.cpp:145
void Merge(const XcodeSDK &other)
The merge function follows a strict order to maintain monotonicity:
Definition XcodeSDK.cpp:157
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
static XcodeSDK::Type GetSDKTypeForTriple(const llvm::Triple &triple)
Return the best-matching SDK type for a specific triple.
Definition XcodeSDK.cpp:259
bool IsAppleInternalSDK() const
Definition XcodeSDK.cpp:125
static bool SDKSupportsModules(Type type, llvm::VersionTuple version)
Whether LLDB feels confident importing Clang modules from this SDK.
Definition XcodeSDK.cpp:223
#define LLDB_INVALID_ADDRESS
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
LoadScriptFromSymFile
Definition Target.h:59
@ eScriptLanguagePython
std::shared_ptr< lldb_private::BreakpointLocation > BreakpointLocationSP
std::shared_ptr< lldb_private::Platform > PlatformSP
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Section > SectionSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP
lldb::DataExtractorSP GetExtractor()
A parsed SDK directory name.
Definition XcodeSDK.h:48
#define PATH_MAX