Path: blob/main/contrib/llvm-project/lldb/source/Interpreter/OptionGroupPlatform.cpp
39587 views
//===-- OptionGroupPlatform.cpp -------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Interpreter/OptionGroupPlatform.h"910#include "lldb/Host/OptionParser.h"11#include "lldb/Interpreter/CommandInterpreter.h"12#include "lldb/Target/Platform.h"1314using namespace lldb;15using namespace lldb_private;1617PlatformSP OptionGroupPlatform::CreatePlatformWithOptions(18CommandInterpreter &interpreter, const ArchSpec &arch, bool make_selected,19Status &error, ArchSpec &platform_arch) const {20PlatformList &platforms = interpreter.GetDebugger().GetPlatformList();2122PlatformSP platform_sp;2324if (!m_platform_name.empty()) {25platform_sp = platforms.Create(m_platform_name);26if (!platform_sp) {27error.SetErrorStringWithFormatv(28"unable to find a plug-in for the platform named \"{0}\"",29m_platform_name);30}31if (platform_sp) {32if (platform_arch.IsValid() &&33!platform_sp->IsCompatibleArchitecture(34arch, {}, ArchSpec::CompatibleMatch, &platform_arch)) {35error.SetErrorStringWithFormatv("platform '{0}' doesn't support '{1}'",36platform_sp->GetPluginName(),37arch.GetTriple().getTriple());38platform_sp.reset();39return platform_sp;40}41}42} else if (arch.IsValid()) {43platform_sp = platforms.GetOrCreate(arch, {}, &platform_arch, error);44}4546if (platform_sp) {47if (make_selected)48platforms.SetSelectedPlatform(platform_sp);49if (!m_os_version.empty())50platform_sp->SetOSVersion(m_os_version);5152if (!m_sdk_sysroot.empty())53platform_sp->SetSDKRootDirectory(m_sdk_sysroot);5455if (!m_sdk_build.empty())56platform_sp->SetSDKBuild(m_sdk_build);57}5859return platform_sp;60}6162void OptionGroupPlatform::OptionParsingStarting(63ExecutionContext *execution_context) {64m_platform_name.clear();65m_sdk_sysroot.clear();66m_sdk_build.clear();67m_os_version = llvm::VersionTuple();68}6970static constexpr OptionDefinition g_option_table[] = {71{LLDB_OPT_SET_ALL, false, "platform", 'p', OptionParser::eRequiredArgument,72nullptr, {}, 0, eArgTypePlatform, "Specify name of the platform to "73"use for this target, creating the "74"platform if necessary."},75{LLDB_OPT_SET_ALL, false, "version", 'v', OptionParser::eRequiredArgument,76nullptr, {}, 0, eArgTypeNone,77"Specify the initial SDK version to use prior to connecting."},78{LLDB_OPT_SET_ALL, false, "build", 'b', OptionParser::eRequiredArgument,79nullptr, {}, 0, eArgTypeNone,80"Specify the initial SDK build number."},81{LLDB_OPT_SET_ALL, false, "sysroot", 'S', OptionParser::eRequiredArgument,82nullptr, {}, 0, eArgTypeFilename, "Specify the SDK root directory "83"that contains a root of all "84"remote system files."}};8586llvm::ArrayRef<OptionDefinition> OptionGroupPlatform::GetDefinitions() {87llvm::ArrayRef<OptionDefinition> result(g_option_table);88if (m_include_platform_option)89return result;90return result.drop_front();91}9293Status94OptionGroupPlatform::SetOptionValue(uint32_t option_idx,95llvm::StringRef option_arg,96ExecutionContext *execution_context) {97Status error;98if (!m_include_platform_option)99++option_idx;100101const int short_option = g_option_table[option_idx].short_option;102103switch (short_option) {104case 'p':105m_platform_name.assign(option_arg.str());106break;107108case 'v':109if (m_os_version.tryParse(option_arg))110error.SetErrorStringWithFormatv("invalid version string '{0}'",111option_arg);112break;113114case 'b':115m_sdk_build.assign(option_arg.str());116break;117118case 'S':119m_sdk_sysroot.assign(option_arg.str());120break;121122default:123llvm_unreachable("Unimplemented option");124}125return error;126}127128bool OptionGroupPlatform::PlatformMatches(129const lldb::PlatformSP &platform_sp) const {130if (!platform_sp)131return false;132133if (!m_platform_name.empty() && platform_sp->GetName() != m_platform_name)134return false;135136if (!m_sdk_build.empty() && platform_sp->GetSDKBuild() != m_sdk_build)137return false;138139if (!m_sdk_sysroot.empty() &&140platform_sp->GetSDKRootDirectory() != m_sdk_sysroot)141return false;142143if (!m_os_version.empty() && platform_sp->GetOSVersion() != m_os_version)144return false;145146return true;147}148149150