OptionGroupPlatform.cpp revision 314564
12116Sjkh//===-- OptionGroupPlatform.cpp ---------------------------------*- C++ -*-===// 22116Sjkh// 32116Sjkh// The LLVM Compiler Infrastructure 42116Sjkh// 52116Sjkh// This file is distributed under the University of Illinois Open Source 62116Sjkh// License. See LICENSE.TXT for details. 72116Sjkh// 88870Srgrimes//===----------------------------------------------------------------------===// 92116Sjkh 102116Sjkh#include "lldb/Interpreter/OptionGroupPlatform.h" 112116Sjkh 122116Sjkh// C Includes 13176451Sdas// C++ Includes 14176451Sdas// Other libraries and framework includes 152116Sjkh// Project includes 162116Sjkh#include "lldb/Interpreter/CommandInterpreter.h" 172116Sjkh#include "lldb/Target/Platform.h" 182116Sjkh#include "lldb/Utility/Utils.h" 192116Sjkh 202116Sjkhusing namespace lldb; 212116Sjkhusing namespace lldb_private; 222116Sjkh 23143216SdasPlatformSP OptionGroupPlatform::CreatePlatformWithOptions( 24143216Sdas CommandInterpreter &interpreter, const ArchSpec &arch, bool make_selected, 252116Sjkh Error &error, ArchSpec &platform_arch) const { 262116Sjkh PlatformSP platform_sp; 272116Sjkh 2897413Salfred if (!m_platform_name.empty()) { 2997413Salfred platform_sp = Platform::Create(ConstString(m_platform_name.c_str()), error); 302116Sjkh if (platform_sp) { 31143216Sdas if (platform_arch.IsValid() && 322116Sjkh !platform_sp->IsCompatibleArchitecture(arch, false, &platform_arch)) { 332116Sjkh error.SetErrorStringWithFormat("platform '%s' doesn't support '%s'", 342116Sjkh platform_sp->GetName().GetCString(), 352116Sjkh arch.GetTriple().getTriple().c_str()); 362116Sjkh platform_sp.reset(); 372116Sjkh return platform_sp; 382116Sjkh } 392116Sjkh } 408870Srgrimes } else if (arch.IsValid()) { 418870Srgrimes platform_sp = Platform::Create(arch, &platform_arch, error); 428870Srgrimes } 43140685Sdas 442116Sjkh if (platform_sp) { 452116Sjkh interpreter.GetDebugger().GetPlatformList().Append(platform_sp, 46143216Sdas make_selected); 47143216Sdas if (m_os_version_major != UINT32_MAX) { 488870Srgrimes platform_sp->SetOSVersion(m_os_version_major, m_os_version_minor, 492116Sjkh m_os_version_update); 502116Sjkh } 512116Sjkh 522116Sjkh if (m_sdk_sysroot) 532116Sjkh platform_sp->SetSDKRootDirectory(m_sdk_sysroot); 542116Sjkh 552116Sjkh if (m_sdk_build) 562116Sjkh platform_sp->SetSDKBuild(m_sdk_build); 572116Sjkh } 582116Sjkh 592116Sjkh return platform_sp; 602116Sjkh} 612116Sjkh 622116Sjkhvoid OptionGroupPlatform::OptionParsingStarting( 632116Sjkh ExecutionContext *execution_context) { 642116Sjkh m_platform_name.clear(); 652116Sjkh m_sdk_sysroot.Clear(); 662116Sjkh m_sdk_build.Clear(); 672116Sjkh m_os_version_major = UINT32_MAX; 682116Sjkh m_os_version_minor = UINT32_MAX; 69143216Sdas m_os_version_update = UINT32_MAX; 70143216Sdas} 712116Sjkh 722116Sjkhstatic OptionDefinition g_option_table[] = { 732116Sjkh {LLDB_OPT_SET_ALL, false, "platform", 'p', OptionParser::eRequiredArgument, 742116Sjkh nullptr, nullptr, 0, eArgTypePlatform, "Specify name of the platform to " 752116Sjkh "use for this target, creating the " 762116Sjkh "platform if necessary."}, 772116Sjkh {LLDB_OPT_SET_ALL, false, "version", 'v', OptionParser::eRequiredArgument, 78143216Sdas nullptr, nullptr, 0, eArgTypeNone, 79143216Sdas "Specify the initial SDK version to use prior to connecting."}, 80143264Sdas {LLDB_OPT_SET_ALL, false, "build", 'b', OptionParser::eRequiredArgument, 81143264Sdas nullptr, nullptr, 0, eArgTypeNone, 82143264Sdas "Specify the initial SDK build number."}, 83143216Sdas {LLDB_OPT_SET_ALL, false, "sysroot", 'S', OptionParser::eRequiredArgument, 84 nullptr, nullptr, 0, eArgTypeFilename, "Specify the SDK root directory " 85 "that contains a root of all " 86 "remote system files."}}; 87 88llvm::ArrayRef<OptionDefinition> OptionGroupPlatform::GetDefinitions() { 89 llvm::ArrayRef<OptionDefinition> result(g_option_table); 90 if (m_include_platform_option) 91 return result; 92 return result.drop_front(); 93} 94 95Error OptionGroupPlatform::SetOptionValue(uint32_t option_idx, 96 llvm::StringRef option_arg, 97 ExecutionContext *execution_context) { 98 Error error; 99 if (!m_include_platform_option) 100 ++option_idx; 101 102 const int short_option = g_option_table[option_idx].short_option; 103 104 switch (short_option) { 105 case 'p': 106 m_platform_name.assign(option_arg); 107 break; 108 109 case 'v': 110 if (!Args::StringToVersion(option_arg, m_os_version_major, 111 m_os_version_minor, m_os_version_update)) 112 error.SetErrorStringWithFormat("invalid version string '%s'", 113 option_arg.str().c_str()); 114 break; 115 116 case 'b': 117 m_sdk_build.SetString(option_arg); 118 break; 119 120 case 'S': 121 m_sdk_sysroot.SetString(option_arg); 122 break; 123 124 default: 125 error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); 126 break; 127 } 128 return error; 129} 130 131bool OptionGroupPlatform::PlatformMatches( 132 const lldb::PlatformSP &platform_sp) const { 133 if (platform_sp) { 134 if (!m_platform_name.empty()) { 135 if (platform_sp->GetName() != ConstString(m_platform_name.c_str())) 136 return false; 137 } 138 139 if (m_sdk_build && m_sdk_build != platform_sp->GetSDKBuild()) 140 return false; 141 142 if (m_sdk_sysroot && m_sdk_sysroot != platform_sp->GetSDKRootDirectory()) 143 return false; 144 145 if (m_os_version_major != UINT32_MAX) { 146 uint32_t major, minor, update; 147 if (platform_sp->GetOSVersion(major, minor, update)) { 148 if (m_os_version_major != major) 149 return false; 150 if (m_os_version_minor != minor) 151 return false; 152 if (m_os_version_update != update) 153 return false; 154 } 155 } 156 return true; 157 } 158 return false; 159} 160