1 //===-- OptionGroupPlatform.cpp ---------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Interpreter/OptionGroupPlatform.h" 11 12 // C Includes 13 // C++ Includes 14 // Other libraries and framework includes 15 // Project includes 16 #include "lldb/Interpreter/CommandInterpreter.h" 17 #include "lldb/Target/Platform.h" 18 #include "lldb/Utility/Utils.h" 19 20 using namespace lldb; 21 using namespace lldb_private; 22 23 PlatformSP 24 OptionGroupPlatform::CreatePlatformWithOptions (CommandInterpreter &interpreter, 25 const ArchSpec &arch, 26 bool make_selected, 27 Error& error, 28 ArchSpec &platform_arch) const 29 { 30 PlatformSP platform_sp; 31 32 if (!m_platform_name.empty()) 33 { 34 platform_sp = Platform::Create (m_platform_name.c_str(), error); 35 if (platform_sp) 36 { 37 if (platform_arch.IsValid() && !platform_sp->IsCompatibleArchitecture(arch, &platform_arch)) 38 { 39 error.SetErrorStringWithFormat("platform '%s' doesn't support '%s'", platform_sp->GetName(), arch.GetTriple().getTriple().c_str()); 40 platform_sp.reset(); 41 return platform_sp; 42 } 43 } 44 } 45 else if (arch.IsValid()) 46 { 47 platform_sp = Platform::Create (arch, &platform_arch, error); 48 } 49 50 if (platform_sp) 51 { 52 interpreter.GetDebugger().GetPlatformList().Append (platform_sp, make_selected); 53 if (m_os_version_major != UINT32_MAX) 54 { 55 platform_sp->SetOSVersion (m_os_version_major, 56 m_os_version_minor, 57 m_os_version_update); 58 } 59 60 if (m_sdk_sysroot) 61 platform_sp->SetSDKRootDirectory (m_sdk_sysroot); 62 63 if (m_sdk_build) 64 platform_sp->SetSDKBuild (m_sdk_build); 65 } 66 67 return platform_sp; 68 } 69 70 void 71 OptionGroupPlatform::OptionParsingStarting (CommandInterpreter &interpreter) 72 { 73 m_platform_name.clear(); 74 m_sdk_sysroot.Clear(); 75 m_sdk_build.Clear(); 76 m_os_version_major = UINT32_MAX; 77 m_os_version_minor = UINT32_MAX; 78 m_os_version_update = UINT32_MAX; 79 } 80 81 static OptionDefinition 82 g_option_table[] = 83 { 84 { LLDB_OPT_SET_ALL, false, "platform", 'p', required_argument, NULL, 0, eArgTypePlatform, "Specify name of the platform to use for this target, creating the platform if necessary."}, 85 { LLDB_OPT_SET_ALL, false, "version" , 'v', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK version to use prior to connecting." }, 86 { LLDB_OPT_SET_ALL, false, "build" , 'b', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK build number." }, 87 { LLDB_OPT_SET_ALL, false, "sysroot" , 's', required_argument, NULL, 0, eArgTypeFilename, "Specify the SDK root directory that contains a root of all remote system files." } 88 }; 89 90 const OptionDefinition* 91 OptionGroupPlatform::GetDefinitions () 92 { 93 if (m_include_platform_option) 94 return g_option_table; 95 return g_option_table + 1; 96 } 97 98 uint32_t 99 OptionGroupPlatform::GetNumDefinitions () 100 { 101 if (m_include_platform_option) 102 return llvm::array_lengthof(g_option_table); 103 return llvm::array_lengthof(g_option_table) - 1; 104 } 105 106 107 Error 108 OptionGroupPlatform::SetOptionValue (CommandInterpreter &interpreter, 109 uint32_t option_idx, 110 const char *option_arg) 111 { 112 Error error; 113 if (!m_include_platform_option) 114 ++option_idx; 115 116 char short_option = (char) g_option_table[option_idx].short_option; 117 118 switch (short_option) 119 { 120 case 'p': 121 m_platform_name.assign (option_arg); 122 break; 123 124 case 'v': 125 if (Args::StringToVersion (option_arg, 126 m_os_version_major, 127 m_os_version_minor, 128 m_os_version_update) == option_arg) 129 error.SetErrorStringWithFormat ("invalid version string '%s'", option_arg); 130 break; 131 132 case 'b': 133 m_sdk_build.SetCString (option_arg); 134 break; 135 136 case 's': 137 m_sdk_sysroot.SetCString (option_arg); 138 break; 139 140 default: 141 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 142 break; 143 } 144 return error; 145 } 146