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, bool make_selected, Error& error) const 25 { 26 PlatformSP platform_sp; 27 if (!m_platform_name.empty()) 28 { 29 platform_sp = Platform::Create (m_platform_name.c_str(), error); 30 31 if (platform_sp) 32 { 33 interpreter.GetDebugger().GetPlatformList().Append (platform_sp, make_selected); 34 if (m_os_version_major != UINT32_MAX) 35 { 36 platform_sp->SetOSVersion (m_os_version_major, 37 m_os_version_minor, 38 m_os_version_update); 39 } 40 41 if (m_sdk_sysroot) 42 platform_sp->SetSDKRootDirectory (m_sdk_sysroot); 43 44 if (m_sdk_build) 45 platform_sp->SetSDKBuild (m_sdk_build); 46 } 47 } 48 return platform_sp; 49 } 50 51 void 52 OptionGroupPlatform::OptionParsingStarting (CommandInterpreter &interpreter) 53 { 54 m_platform_name.clear(); 55 m_sdk_sysroot.Clear(); 56 m_sdk_build.Clear(); 57 m_os_version_major = UINT32_MAX; 58 m_os_version_minor = UINT32_MAX; 59 m_os_version_update = UINT32_MAX; 60 } 61 62 static OptionDefinition 63 g_option_table[] = 64 { 65 { 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."}, 66 { LLDB_OPT_SET_ALL, false, "version" , 'v', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK version to use prior to connecting." }, 67 { LLDB_OPT_SET_ALL, false, "build" , 'b', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK build number." }, 68 { 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." } 69 }; 70 71 const OptionDefinition* 72 OptionGroupPlatform::GetDefinitions () 73 { 74 if (m_include_platform_option) 75 return g_option_table; 76 return g_option_table + 1; 77 } 78 79 uint32_t 80 OptionGroupPlatform::GetNumDefinitions () 81 { 82 if (m_include_platform_option) 83 return arraysize(g_option_table); 84 return arraysize(g_option_table) - 1; 85 } 86 87 88 Error 89 OptionGroupPlatform::SetOptionValue (CommandInterpreter &interpreter, 90 uint32_t option_idx, 91 const char *option_arg) 92 { 93 Error error; 94 if (!m_include_platform_option) 95 ++option_idx; 96 97 char short_option = (char) g_option_table[option_idx].short_option; 98 99 switch (short_option) 100 { 101 case 'p': 102 m_platform_name.assign (option_arg); 103 break; 104 105 case 'v': 106 if (Args::StringToVersion (option_arg, 107 m_os_version_major, 108 m_os_version_minor, 109 m_os_version_update) == option_arg) 110 error.SetErrorStringWithFormat ("invalid version string '%s'", option_arg); 111 break; 112 113 case 'b': 114 m_sdk_build.SetCString (option_arg); 115 break; 116 117 case 's': 118 m_sdk_sysroot.SetCString (option_arg); 119 break; 120 121 default: 122 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); 123 break; 124 } 125 return error; 126 } 127