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 | b170aee | 2012-05-08 01:45:38 +0000 | [diff] [blame^] | 24 | OptionGroupPlatform::CreatePlatformWithOptions (CommandInterpreter &interpreter, |
| 25 | const ArchSpec &arch, |
| 26 | bool make_selected, |
| 27 | Error& error, |
| 28 | ArchSpec &platform_arch) const |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 29 | { |
| 30 | PlatformSP platform_sp; |
Greg Clayton | b1db658 | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 31 | |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 32 | if (!m_platform_name.empty()) |
| 33 | { |
| 34 | platform_sp = Platform::Create (m_platform_name.c_str(), error); |
Greg Clayton | b170aee | 2012-05-08 01:45:38 +0000 | [diff] [blame^] | 35 | if (platform_sp) |
| 36 | { |
| 37 | if (!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 | } |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 44 | } |
Greg Clayton | b1db658 | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 45 | else if (arch.IsValid()) |
| 46 | { |
Greg Clayton | b170aee | 2012-05-08 01:45:38 +0000 | [diff] [blame^] | 47 | platform_sp = Platform::Create (arch, &platform_arch, error); |
Greg Clayton | b1db658 | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 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 | |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 67 | return platform_sp; |
| 68 | } |
| 69 | |
| 70 | void |
| 71 | OptionGroupPlatform::OptionParsingStarting (CommandInterpreter &interpreter) |
| 72 | { |
| 73 | m_platform_name.clear(); |
Greg Clayton | 604f0d3 | 2011-06-17 03:31:01 +0000 | [diff] [blame] | 74 | m_sdk_sysroot.Clear(); |
| 75 | m_sdk_build.Clear(); |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 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 | { |
Greg Clayton | 604f0d3 | 2011-06-17 03:31:01 +0000 | [diff] [blame] | 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." } |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 88 | }; |
| 89 | |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 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) |
Johnny Chen | 4003f57 | 2011-09-10 00:48:33 +0000 | [diff] [blame] | 102 | return arraysize(g_option_table); |
| 103 | return arraysize(g_option_table) - 1; |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 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) |
Greg Clayton | e1f50b9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 114 | ++option_idx; |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 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 | |
Greg Clayton | 604f0d3 | 2011-06-17 03:31:01 +0000 | [diff] [blame] | 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 | |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 140 | default: |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 141 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 142 | break; |
| 143 | } |
| 144 | return error; |
| 145 | } |