1 //===-- OptionGroupPlatform.cpp ---------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Interpreter/OptionGroupPlatform.h"
11 #include "lldb/Host/OptionParser.h"
12 #include "lldb/Interpreter/CommandInterpreter.h"
13 #include "lldb/Target/Platform.h"
16 using namespace lldb_private;
18 PlatformSP OptionGroupPlatform::CreatePlatformWithOptions(
19 CommandInterpreter &interpreter, const ArchSpec &arch, bool make_selected,
20 Status &error, ArchSpec &platform_arch) const {
21 PlatformSP platform_sp;
23 if (!m_platform_name.empty()) {
24 platform_sp = Platform::Create(ConstString(m_platform_name.c_str()), error);
26 if (platform_arch.IsValid() &&
27 !platform_sp->IsCompatibleArchitecture(arch, false, &platform_arch)) {
28 error.SetErrorStringWithFormat("platform '%s' doesn't support '%s'",
29 platform_sp->GetName().GetCString(),
30 arch.GetTriple().getTriple().c_str());
35 } else if (arch.IsValid()) {
36 platform_sp = Platform::Create(arch, &platform_arch, error);
40 interpreter.GetDebugger().GetPlatformList().Append(platform_sp,
42 if (!m_os_version.empty())
43 platform_sp->SetOSVersion(m_os_version);
46 platform_sp->SetSDKRootDirectory(m_sdk_sysroot);
49 platform_sp->SetSDKBuild(m_sdk_build);
55 void OptionGroupPlatform::OptionParsingStarting(
56 ExecutionContext *execution_context) {
57 m_platform_name.clear();
58 m_sdk_sysroot.Clear();
60 m_os_version = llvm::VersionTuple();
63 static constexpr OptionDefinition g_option_table[] = {
64 {LLDB_OPT_SET_ALL, false, "platform", 'p', OptionParser::eRequiredArgument,
65 nullptr, {}, 0, eArgTypePlatform, "Specify name of the platform to "
66 "use for this target, creating the "
67 "platform if necessary."},
68 {LLDB_OPT_SET_ALL, false, "version", 'v', OptionParser::eRequiredArgument,
69 nullptr, {}, 0, eArgTypeNone,
70 "Specify the initial SDK version to use prior to connecting."},
71 {LLDB_OPT_SET_ALL, false, "build", 'b', OptionParser::eRequiredArgument,
72 nullptr, {}, 0, eArgTypeNone,
73 "Specify the initial SDK build number."},
74 {LLDB_OPT_SET_ALL, false, "sysroot", 'S', OptionParser::eRequiredArgument,
75 nullptr, {}, 0, eArgTypeFilename, "Specify the SDK root directory "
76 "that contains a root of all "
77 "remote system files."}};
79 llvm::ArrayRef<OptionDefinition> OptionGroupPlatform::GetDefinitions() {
80 llvm::ArrayRef<OptionDefinition> result(g_option_table);
81 if (m_include_platform_option)
83 return result.drop_front();
87 OptionGroupPlatform::SetOptionValue(uint32_t option_idx,
88 llvm::StringRef option_arg,
89 ExecutionContext *execution_context) {
91 if (!m_include_platform_option)
94 const int short_option = g_option_table[option_idx].short_option;
96 switch (short_option) {
98 m_platform_name.assign(option_arg);
102 if (m_os_version.tryParse(option_arg))
103 error.SetErrorStringWithFormatv("invalid version string '{0}'",
108 m_sdk_build.SetString(option_arg);
112 m_sdk_sysroot.SetString(option_arg);
116 llvm_unreachable("Unimplemented option");
121 bool OptionGroupPlatform::PlatformMatches(
122 const lldb::PlatformSP &platform_sp) const {
124 if (!m_platform_name.empty()) {
125 if (platform_sp->GetName() != ConstString(m_platform_name.c_str()))
129 if (m_sdk_build && m_sdk_build != platform_sp->GetSDKBuild())
132 if (m_sdk_sysroot && m_sdk_sysroot != platform_sp->GetSDKRootDirectory())
135 if (!m_os_version.empty() && m_os_version != platform_sp->GetOSVersion())