2020-01-24 08:23:27 +01:00
|
|
|
//===-- OptionGroupPlatform.cpp -------------------------------------------===//
|
2011-04-18 08:33:37 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-04-18 08:33:37 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "lldb/Interpreter/OptionGroupPlatform.h"
|
|
|
|
|
|
2017-03-22 23:33:16 +00:00
|
|
|
#include "lldb/Host/OptionParser.h"
|
2011-04-18 08:33:37 +00:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
|
|
|
#include "lldb/Target/Platform.h"
|
|
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
2012-05-08 01:45:38 +00:00
|
|
|
PlatformSP OptionGroupPlatform::CreatePlatformWithOptions(
|
|
|
|
|
CommandInterpreter &interpreter, const ArchSpec &arch, bool make_selected,
|
2017-05-12 04:51:55 +00:00
|
|
|
Status &error, ArchSpec &platform_arch) const {
|
2011-04-18 08:33:37 +00:00
|
|
|
PlatformSP platform_sp;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-04-18 08:33:37 +00:00
|
|
|
if (!m_platform_name.empty()) {
|
2014-09-19 20:11:50 +00:00
|
|
|
platform_sp = Platform::Create(ConstString(m_platform_name.c_str()), error);
|
2012-05-08 01:45:38 +00:00
|
|
|
if (platform_sp) {
|
2013-01-11 20:49:54 +00:00
|
|
|
if (platform_arch.IsValid() &&
|
|
|
|
|
!platform_sp->IsCompatibleArchitecture(arch, false, &platform_arch)) {
|
2013-05-10 21:47:16 +00:00
|
|
|
error.SetErrorStringWithFormat("platform '%s' doesn't support '%s'",
|
|
|
|
|
platform_sp->GetName().GetCString(),
|
|
|
|
|
arch.GetTriple().getTriple().c_str());
|
2012-05-08 01:45:38 +00:00
|
|
|
platform_sp.reset();
|
|
|
|
|
return platform_sp;
|
|
|
|
|
}
|
2011-04-18 08:33:37 +00:00
|
|
|
}
|
2012-03-20 18:34:04 +00:00
|
|
|
} else if (arch.IsValid()) {
|
2012-05-08 01:45:38 +00:00
|
|
|
platform_sp = Platform::Create(arch, &platform_arch, error);
|
2012-03-20 18:34:04 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-03-20 18:34:04 +00:00
|
|
|
if (platform_sp) {
|
|
|
|
|
interpreter.GetDebugger().GetPlatformList().Append(platform_sp,
|
|
|
|
|
make_selected);
|
2018-06-18 15:02:23 +00:00
|
|
|
if (!m_os_version.empty())
|
|
|
|
|
platform_sp->SetOSVersion(m_os_version);
|
2012-03-20 18:34:04 +00:00
|
|
|
|
|
|
|
|
if (m_sdk_sysroot)
|
|
|
|
|
platform_sp->SetSDKRootDirectory(m_sdk_sysroot);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-03-20 18:34:04 +00:00
|
|
|
if (m_sdk_build)
|
|
|
|
|
platform_sp->SetSDKBuild(m_sdk_build);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2011-04-18 08:33:37 +00:00
|
|
|
return platform_sp;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-11 23:51:28 +00:00
|
|
|
void OptionGroupPlatform::OptionParsingStarting(
|
|
|
|
|
ExecutionContext *execution_context) {
|
2011-04-18 08:33:37 +00:00
|
|
|
m_platform_name.clear();
|
2011-06-17 03:31:01 +00:00
|
|
|
m_sdk_sysroot.Clear();
|
|
|
|
|
m_sdk_build.Clear();
|
2018-06-18 15:02:23 +00:00
|
|
|
m_os_version = llvm::VersionTuple();
|
2011-04-18 08:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
2018-09-26 18:50:19 +00:00
|
|
|
static constexpr OptionDefinition g_option_table[] = {
|
2014-07-09 16:31:49 +00:00
|
|
|
{LLDB_OPT_SET_ALL, false, "platform", 'p', OptionParser::eRequiredArgument,
|
2018-09-26 18:50:19 +00:00
|
|
|
nullptr, {}, 0, eArgTypePlatform, "Specify name of the platform to "
|
|
|
|
|
"use for this target, creating the "
|
|
|
|
|
"platform if necessary."},
|
2014-07-09 16:31:49 +00:00
|
|
|
{LLDB_OPT_SET_ALL, false, "version", 'v', OptionParser::eRequiredArgument,
|
2018-09-26 18:50:19 +00:00
|
|
|
nullptr, {}, 0, eArgTypeNone,
|
2014-07-09 16:31:49 +00:00
|
|
|
"Specify the initial SDK version to use prior to connecting."},
|
|
|
|
|
{LLDB_OPT_SET_ALL, false, "build", 'b', OptionParser::eRequiredArgument,
|
2018-09-26 18:50:19 +00:00
|
|
|
nullptr, {}, 0, eArgTypeNone,
|
2014-07-09 16:31:49 +00:00
|
|
|
"Specify the initial SDK build number."},
|
|
|
|
|
{LLDB_OPT_SET_ALL, false, "sysroot", 'S', OptionParser::eRequiredArgument,
|
2018-09-26 18:50:19 +00:00
|
|
|
nullptr, {}, 0, eArgTypeFilename, "Specify the SDK root directory "
|
|
|
|
|
"that contains a root of all "
|
|
|
|
|
"remote system files."}};
|
2011-04-18 08:33:37 +00:00
|
|
|
|
2016-09-22 20:22:55 +00:00
|
|
|
llvm::ArrayRef<OptionDefinition> OptionGroupPlatform::GetDefinitions() {
|
|
|
|
|
llvm::ArrayRef<OptionDefinition> result(g_option_table);
|
2011-04-18 08:33:37 +00:00
|
|
|
if (m_include_platform_option)
|
2016-09-22 20:22:55 +00:00
|
|
|
return result;
|
|
|
|
|
return result.drop_front();
|
2011-04-18 08:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status
|
|
|
|
|
OptionGroupPlatform::SetOptionValue(uint32_t option_idx,
|
|
|
|
|
llvm::StringRef option_arg,
|
|
|
|
|
ExecutionContext *execution_context) {
|
|
|
|
|
Status error;
|
2011-04-18 08:33:37 +00:00
|
|
|
if (!m_include_platform_option)
|
2011-05-03 22:09:39 +00:00
|
|
|
++option_idx;
|
2011-04-18 08:33:37 +00:00
|
|
|
|
2012-12-04 00:32:51 +00:00
|
|
|
const int short_option = g_option_table[option_idx].short_option;
|
2011-06-17 03:31:01 +00:00
|
|
|
|
2011-04-18 08:33:37 +00:00
|
|
|
switch (short_option) {
|
|
|
|
|
case 'p':
|
2020-01-28 20:23:46 +01:00
|
|
|
m_platform_name.assign(std::string(option_arg));
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
|
2011-04-18 08:33:37 +00:00
|
|
|
case 'v':
|
2018-06-18 15:02:23 +00:00
|
|
|
if (m_os_version.tryParse(option_arg))
|
|
|
|
|
error.SetErrorStringWithFormatv("invalid version string '{0}'",
|
|
|
|
|
option_arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
|
2011-06-17 03:31:01 +00:00
|
|
|
case 'b':
|
2016-09-23 17:48:13 +00:00
|
|
|
m_sdk_build.SetString(option_arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
|
2013-03-29 23:18:38 +00:00
|
|
|
case 'S':
|
2016-09-23 17:48:13 +00:00
|
|
|
m_sdk_sysroot.SetString(option_arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
|
2011-04-18 08:33:37 +00:00
|
|
|
default:
|
2019-08-22 08:08:05 +00:00
|
|
|
llvm_unreachable("Unimplemented option");
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2011-04-18 08:33:37 +00:00
|
|
|
return error;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-28 01:33:37 +00:00
|
|
|
bool OptionGroupPlatform::PlatformMatches(
|
|
|
|
|
const lldb::PlatformSP &platform_sp) const {
|
|
|
|
|
if (platform_sp) {
|
|
|
|
|
if (!m_platform_name.empty()) {
|
|
|
|
|
if (platform_sp->GetName() != ConstString(m_platform_name.c_str()))
|
|
|
|
|
return false;
|
2011-04-18 08:33:37 +00:00
|
|
|
}
|
2015-01-28 01:33:37 +00:00
|
|
|
|
|
|
|
|
if (m_sdk_build && m_sdk_build != platform_sp->GetSDKBuild())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (m_sdk_sysroot && m_sdk_sysroot != platform_sp->GetSDKRootDirectory())
|
|
|
|
|
return false;
|
|
|
|
|
|
2018-06-18 15:02:23 +00:00
|
|
|
if (!m_os_version.empty() && m_os_version != platform_sp->GetOSVersion())
|
|
|
|
|
return false;
|
2015-01-28 01:33:37 +00:00
|
|
|
return true;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2015-01-28 01:33:37 +00:00
|
|
|
return false;
|
|
|
|
|
}
|