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