Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 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" |
Johnny Chen | 4003f57 | 2011-09-10 00:48:33 +0000 | [diff] [blame] | 18 | #include "lldb/Utility/Utils.h" |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace lldb; |
| 21 | using namespace lldb_private; |
| 22 | |
| 23 | PlatformSP |
Greg Clayton | b1db658 | 2012-03-20 18:34:04 +0000 | [diff] [blame^] | 24 | OptionGroupPlatform::CreatePlatformWithOptions (CommandInterpreter &interpreter, const ArchSpec &arch, bool make_selected, Error& error) const |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 25 | { |
| 26 | PlatformSP platform_sp; |
Greg Clayton | b1db658 | 2012-03-20 18:34:04 +0000 | [diff] [blame^] | 27 | |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 28 | if (!m_platform_name.empty()) |
| 29 | { |
| 30 | platform_sp = Platform::Create (m_platform_name.c_str(), error); |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 31 | } |
Greg Clayton | b1db658 | 2012-03-20 18:34:04 +0000 | [diff] [blame^] | 32 | else if (arch.IsValid()) |
| 33 | { |
| 34 | platform_sp = Platform::Create (arch, error); |
| 35 | } |
| 36 | |
| 37 | if (platform_sp) |
| 38 | { |
| 39 | interpreter.GetDebugger().GetPlatformList().Append (platform_sp, make_selected); |
| 40 | if (m_os_version_major != UINT32_MAX) |
| 41 | { |
| 42 | platform_sp->SetOSVersion (m_os_version_major, |
| 43 | m_os_version_minor, |
| 44 | m_os_version_update); |
| 45 | } |
| 46 | |
| 47 | if (m_sdk_sysroot) |
| 48 | platform_sp->SetSDKRootDirectory (m_sdk_sysroot); |
| 49 | |
| 50 | if (m_sdk_build) |
| 51 | platform_sp->SetSDKBuild (m_sdk_build); |
| 52 | } |
| 53 | |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 54 | return platform_sp; |
| 55 | } |
| 56 | |
| 57 | void |
| 58 | OptionGroupPlatform::OptionParsingStarting (CommandInterpreter &interpreter) |
| 59 | { |
| 60 | m_platform_name.clear(); |
Greg Clayton | 604f0d3 | 2011-06-17 03:31:01 +0000 | [diff] [blame] | 61 | m_sdk_sysroot.Clear(); |
| 62 | m_sdk_build.Clear(); |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 63 | m_os_version_major = UINT32_MAX; |
| 64 | m_os_version_minor = UINT32_MAX; |
| 65 | m_os_version_update = UINT32_MAX; |
| 66 | } |
| 67 | |
| 68 | static OptionDefinition |
| 69 | g_option_table[] = |
| 70 | { |
Greg Clayton | 604f0d3 | 2011-06-17 03:31:01 +0000 | [diff] [blame] | 71 | { 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."}, |
| 72 | { LLDB_OPT_SET_ALL, false, "version" , 'v', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK version to use prior to connecting." }, |
| 73 | { LLDB_OPT_SET_ALL, false, "build" , 'b', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK build number." }, |
| 74 | { 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." } |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 77 | const OptionDefinition* |
| 78 | OptionGroupPlatform::GetDefinitions () |
| 79 | { |
| 80 | if (m_include_platform_option) |
| 81 | return g_option_table; |
| 82 | return g_option_table + 1; |
| 83 | } |
| 84 | |
| 85 | uint32_t |
| 86 | OptionGroupPlatform::GetNumDefinitions () |
| 87 | { |
| 88 | if (m_include_platform_option) |
Johnny Chen | 4003f57 | 2011-09-10 00:48:33 +0000 | [diff] [blame] | 89 | return arraysize(g_option_table); |
| 90 | return arraysize(g_option_table) - 1; |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | |
| 94 | Error |
| 95 | OptionGroupPlatform::SetOptionValue (CommandInterpreter &interpreter, |
| 96 | uint32_t option_idx, |
| 97 | const char *option_arg) |
| 98 | { |
| 99 | Error error; |
| 100 | if (!m_include_platform_option) |
Greg Clayton | e1f50b9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 101 | ++option_idx; |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 102 | |
| 103 | char short_option = (char) g_option_table[option_idx].short_option; |
| 104 | |
| 105 | switch (short_option) |
| 106 | { |
| 107 | case 'p': |
| 108 | m_platform_name.assign (option_arg); |
| 109 | break; |
| 110 | |
| 111 | case 'v': |
| 112 | if (Args::StringToVersion (option_arg, |
| 113 | m_os_version_major, |
| 114 | m_os_version_minor, |
| 115 | m_os_version_update) == option_arg) |
| 116 | error.SetErrorStringWithFormat ("invalid version string '%s'", option_arg); |
| 117 | break; |
| 118 | |
Greg Clayton | 604f0d3 | 2011-06-17 03:31:01 +0000 | [diff] [blame] | 119 | case 'b': |
| 120 | m_sdk_build.SetCString (option_arg); |
| 121 | break; |
| 122 | |
| 123 | case 's': |
| 124 | m_sdk_sysroot.SetCString (option_arg); |
| 125 | break; |
| 126 | |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 127 | default: |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 128 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 129 | break; |
| 130 | } |
| 131 | return error; |
| 132 | } |