1 //===-- OptionGroupPlatform.cpp ---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Interpreter/OptionGroupPlatform.h"
12 #include "lldb/Host/OptionParser.h"
13 #include "lldb/Interpreter/CommandInterpreter.h"
14 #include "lldb/Target/Platform.h"
17 using namespace lldb_private;
19 PlatformSP OptionGroupPlatform::CreatePlatformWithOptions(
20 CommandInterpreter &interpreter, const ArchSpec &arch, bool make_selected,
21 Status &error, ArchSpec &platform_arch) const {
22 PlatformSP platform_sp;
24 if (!m_platform_name.empty()) {
25 platform_sp = Platform::Create(ConstString(m_platform_name.c_str()), error);
27 if (platform_arch.IsValid() &&
28 !platform_sp->IsCompatibleArchitecture(arch, false, &platform_arch)) {
29 error.SetErrorStringWithFormat("platform '%s' doesn't support '%s'",
30 platform_sp->GetName().GetCString(),
31 arch.GetTriple().getTriple().c_str());
36 } else if (arch.IsValid()) {
37 platform_sp = Platform::Create(arch, &platform_arch, error);
41 interpreter.GetDebugger().GetPlatformList().Append(platform_sp,
43 if (!m_os_version.empty())
44 platform_sp->SetOSVersion(m_os_version);
47 platform_sp->SetSDKRootDirectory(m_sdk_sysroot);
50 platform_sp->SetSDKBuild(m_sdk_build);
56 void OptionGroupPlatform::OptionParsingStarting(
57 ExecutionContext *execution_context) {
58 m_platform_name.clear();
59 m_sdk_sysroot.Clear();
61 m_os_version = llvm::VersionTuple();
64 static constexpr OptionDefinition g_option_table[] = {
65 {LLDB_OPT_SET_ALL, false, "platform", 'p', OptionParser::eRequiredArgument,
66 nullptr, {}, 0, eArgTypePlatform, "Specify name of the platform to "
67 "use for this target, creating the "
68 "platform if necessary."},
69 {LLDB_OPT_SET_ALL, false, "version", 'v', OptionParser::eRequiredArgument,
70 nullptr, {}, 0, eArgTypeNone,
71 "Specify the initial SDK version to use prior to connecting."},
72 {LLDB_OPT_SET_ALL, false, "build", 'b', OptionParser::eRequiredArgument,
73 nullptr, {}, 0, eArgTypeNone,
74 "Specify the initial SDK build number."},
75 {LLDB_OPT_SET_ALL, false, "sysroot", 'S', OptionParser::eRequiredArgument,
76 nullptr, {}, 0, eArgTypeFilename, "Specify the SDK root directory "
77 "that contains a root of all "
78 "remote system files."}};
80 llvm::ArrayRef<OptionDefinition> OptionGroupPlatform::GetDefinitions() {
81 llvm::ArrayRef<OptionDefinition> result(g_option_table);
82 if (m_include_platform_option)
84 return result.drop_front();
88 OptionGroupPlatform::SetOptionValue(uint32_t option_idx,
89 llvm::StringRef option_arg,
90 ExecutionContext *execution_context) {
92 if (!m_include_platform_option)
95 const int short_option = g_option_table[option_idx].short_option;
97 switch (short_option) {
99 m_platform_name.assign(option_arg);
103 if (m_os_version.tryParse(option_arg))
104 error.SetErrorStringWithFormatv("invalid version string '{0}'",
109 m_sdk_build.SetString(option_arg);
113 m_sdk_sysroot.SetString(option_arg);
117 error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
123 bool OptionGroupPlatform::PlatformMatches(
124 const lldb::PlatformSP &platform_sp) const {
126 if (!m_platform_name.empty()) {
127 if (platform_sp->GetName() != ConstString(m_platform_name.c_str()))
131 if (m_sdk_build && m_sdk_build != platform_sp->GetSDKBuild())
134 if (m_sdk_sysroot && m_sdk_sysroot != platform_sp->GetSDKRootDirectory())
137 if (!m_os_version.empty() && m_os_version != platform_sp->GetOSVersion())