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