1 //===-- OptionGroupPlatform.cpp -------------------------------------------===//
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 PlatformList
&platforms
= interpreter
.GetDebugger().GetPlatformList();
23 PlatformSP platform_sp
;
25 if (!m_platform_name
.empty()) {
26 platform_sp
= platforms
.Create(m_platform_name
);
28 error
= Status::FromErrorStringWithFormatv(
29 "unable to find a plug-in for the platform named \"{0}\"",
33 if (platform_arch
.IsValid() &&
34 !platform_sp
->IsCompatibleArchitecture(
35 arch
, {}, ArchSpec::CompatibleMatch
, &platform_arch
)) {
36 error
= Status::FromErrorStringWithFormatv(
37 "platform '{0}' doesn't support '{1}'",
38 platform_sp
->GetPluginName(), arch
.GetTriple().getTriple());
43 } else if (arch
.IsValid()) {
44 platform_sp
= platforms
.GetOrCreate(arch
, {}, &platform_arch
, error
);
49 platforms
.SetSelectedPlatform(platform_sp
);
50 if (!m_os_version
.empty())
51 platform_sp
->SetOSVersion(m_os_version
);
53 if (!m_sdk_sysroot
.empty())
54 platform_sp
->SetSDKRootDirectory(m_sdk_sysroot
);
56 if (!m_sdk_build
.empty())
57 platform_sp
->SetSDKBuild(m_sdk_build
);
63 void OptionGroupPlatform::OptionParsingStarting(
64 ExecutionContext
*execution_context
) {
65 m_platform_name
.clear();
66 m_sdk_sysroot
.clear();
68 m_os_version
= llvm::VersionTuple();
71 static constexpr OptionDefinition g_option_table
[] = {
72 {LLDB_OPT_SET_ALL
, false, "platform", 'p', OptionParser::eRequiredArgument
,
73 nullptr, {}, 0, eArgTypePlatform
, "Specify name of the platform to "
74 "use for this target, creating the "
75 "platform if necessary."},
76 {LLDB_OPT_SET_ALL
, false, "version", 'v', OptionParser::eRequiredArgument
,
77 nullptr, {}, 0, eArgTypeNone
,
78 "Specify the initial SDK version to use prior to connecting."},
79 {LLDB_OPT_SET_ALL
, false, "build", 'b', OptionParser::eRequiredArgument
,
80 nullptr, {}, 0, eArgTypeNone
,
81 "Specify the initial SDK build number."},
82 {LLDB_OPT_SET_ALL
, false, "sysroot", 'S', OptionParser::eRequiredArgument
,
83 nullptr, {}, 0, eArgTypeFilename
, "Specify the SDK root directory "
84 "that contains a root of all "
85 "remote system files."}};
87 llvm::ArrayRef
<OptionDefinition
> OptionGroupPlatform::GetDefinitions() {
88 llvm::ArrayRef
<OptionDefinition
> result(g_option_table
);
89 if (m_include_platform_option
)
91 return result
.drop_front();
95 OptionGroupPlatform::SetOptionValue(uint32_t option_idx
,
96 llvm::StringRef option_arg
,
97 ExecutionContext
*execution_context
) {
99 if (!m_include_platform_option
)
102 const int short_option
= g_option_table
[option_idx
].short_option
;
104 switch (short_option
) {
106 m_platform_name
.assign(option_arg
.str());
110 if (m_os_version
.tryParse(option_arg
))
111 error
= Status::FromErrorStringWithFormatv("invalid version string '{0}'",
116 m_sdk_build
.assign(option_arg
.str());
120 m_sdk_sysroot
.assign(option_arg
.str());
124 llvm_unreachable("Unimplemented option");
129 bool OptionGroupPlatform::PlatformMatches(
130 const lldb::PlatformSP
&platform_sp
) const {
134 if (!m_platform_name
.empty() && platform_sp
->GetName() != m_platform_name
)
137 if (!m_sdk_build
.empty() && platform_sp
->GetSDKBuild() != m_sdk_build
)
140 if (!m_sdk_sysroot
.empty() &&
141 platform_sp
->GetSDKRootDirectory() != m_sdk_sysroot
)
144 if (!m_os_version
.empty() && platform_sp
->GetOSVersion() != m_os_version
)