Greg Clayton | 7260f62 | 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 | 7c575b3 | 2011-09-10 00:48:33 +0000 | [diff] [blame] | 18 | #include "lldb/Utility/Utils.h" |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace lldb; |
| 21 | using namespace lldb_private; |
| 22 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 23 | PlatformSP OptionGroupPlatform::CreatePlatformWithOptions( |
| 24 | CommandInterpreter &interpreter, const ArchSpec &arch, bool make_selected, |
| 25 | Error &error, ArchSpec &platform_arch) const { |
| 26 | PlatformSP platform_sp; |
| 27 | |
| 28 | if (!m_platform_name.empty()) { |
| 29 | platform_sp = Platform::Create(ConstString(m_platform_name.c_str()), error); |
| 30 | if (platform_sp) { |
| 31 | if (platform_arch.IsValid() && |
| 32 | !platform_sp->IsCompatibleArchitecture(arch, false, &platform_arch)) { |
| 33 | error.SetErrorStringWithFormat("platform '%s' doesn't support '%s'", |
| 34 | platform_sp->GetName().GetCString(), |
| 35 | arch.GetTriple().getTriple().c_str()); |
| 36 | platform_sp.reset(); |
| 37 | return platform_sp; |
| 38 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 39 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 40 | } else if (arch.IsValid()) { |
| 41 | platform_sp = Platform::Create(arch, &platform_arch, error); |
| 42 | } |
| 43 | |
| 44 | if (platform_sp) { |
| 45 | interpreter.GetDebugger().GetPlatformList().Append(platform_sp, |
| 46 | make_selected); |
| 47 | if (m_os_version_major != UINT32_MAX) { |
| 48 | platform_sp->SetOSVersion(m_os_version_major, m_os_version_minor, |
| 49 | m_os_version_update); |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 52 | if (m_sdk_sysroot) |
| 53 | platform_sp->SetSDKRootDirectory(m_sdk_sysroot); |
| 54 | |
| 55 | if (m_sdk_build) |
| 56 | platform_sp->SetSDKBuild(m_sdk_build); |
| 57 | } |
| 58 | |
| 59 | return platform_sp; |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 62 | void OptionGroupPlatform::OptionParsingStarting( |
| 63 | ExecutionContext *execution_context) { |
| 64 | m_platform_name.clear(); |
| 65 | m_sdk_sysroot.Clear(); |
| 66 | m_sdk_build.Clear(); |
| 67 | m_os_version_major = UINT32_MAX; |
| 68 | m_os_version_minor = UINT32_MAX; |
| 69 | m_os_version_update = UINT32_MAX; |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 72 | static OptionDefinition g_option_table[] = { |
| 73 | {LLDB_OPT_SET_ALL, false, "platform", 'p', OptionParser::eRequiredArgument, |
| 74 | nullptr, nullptr, 0, eArgTypePlatform, "Specify name of the platform to " |
| 75 | "use for this target, creating the " |
| 76 | "platform if necessary."}, |
| 77 | {LLDB_OPT_SET_ALL, false, "version", 'v', OptionParser::eRequiredArgument, |
| 78 | nullptr, nullptr, 0, eArgTypeNone, |
| 79 | "Specify the initial SDK version to use prior to connecting."}, |
| 80 | {LLDB_OPT_SET_ALL, false, "build", 'b', OptionParser::eRequiredArgument, |
| 81 | nullptr, nullptr, 0, eArgTypeNone, |
| 82 | "Specify the initial SDK build number."}, |
| 83 | {LLDB_OPT_SET_ALL, false, "sysroot", 'S', OptionParser::eRequiredArgument, |
| 84 | nullptr, nullptr, 0, eArgTypeFilename, "Specify the SDK root directory " |
| 85 | "that contains a root of all " |
| 86 | "remote system files."}}; |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 87 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 88 | llvm::ArrayRef<OptionDefinition> OptionGroupPlatform::GetDefinitions() { |
| 89 | llvm::ArrayRef<OptionDefinition> result(g_option_table); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 90 | if (m_include_platform_option) |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 91 | return result; |
| 92 | return result.drop_front(); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 95 | Error OptionGroupPlatform::SetOptionValue(uint32_t option_idx, |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 96 | llvm::StringRef option_arg, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 97 | ExecutionContext *execution_context) { |
| 98 | Error error; |
| 99 | if (!m_include_platform_option) |
| 100 | ++option_idx; |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 101 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 102 | const int short_option = g_option_table[option_idx].short_option; |
Greg Clayton | f3dd93c | 2011-06-17 03:31:01 +0000 | [diff] [blame] | 103 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 104 | switch (short_option) { |
| 105 | case 'p': |
| 106 | m_platform_name.assign(option_arg); |
| 107 | break; |
| 108 | |
| 109 | case 'v': |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 110 | if (!Args::StringToVersion(option_arg, m_os_version_major, |
Zachary Turner | 6fa7681b | 2016-09-17 02:00:02 +0000 | [diff] [blame] | 111 | m_os_version_minor, m_os_version_update)) |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 112 | error.SetErrorStringWithFormat("invalid version string '%s'", |
| 113 | option_arg.str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 114 | break; |
| 115 | |
| 116 | case 'b': |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 117 | m_sdk_build.SetString(option_arg); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 118 | break; |
| 119 | |
| 120 | case 'S': |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 121 | m_sdk_sysroot.SetString(option_arg); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 122 | break; |
| 123 | |
| 124 | default: |
| 125 | error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); |
| 126 | break; |
| 127 | } |
| 128 | return error; |
| 129 | } |
| 130 | |
| 131 | bool OptionGroupPlatform::PlatformMatches( |
| 132 | const lldb::PlatformSP &platform_sp) const { |
| 133 | if (platform_sp) { |
| 134 | if (!m_platform_name.empty()) { |
| 135 | if (platform_sp->GetName() != ConstString(m_platform_name.c_str())) |
| 136 | return false; |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 137 | } |
Greg Clayton | ccd2a6d | 2015-01-28 01:33:37 +0000 | [diff] [blame] | 138 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 139 | if (m_sdk_build && m_sdk_build != platform_sp->GetSDKBuild()) |
| 140 | return false; |
Greg Clayton | ccd2a6d | 2015-01-28 01:33:37 +0000 | [diff] [blame] | 141 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 142 | if (m_sdk_sysroot && m_sdk_sysroot != platform_sp->GetSDKRootDirectory()) |
| 143 | return false; |
Greg Clayton | ccd2a6d | 2015-01-28 01:33:37 +0000 | [diff] [blame] | 144 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 145 | if (m_os_version_major != UINT32_MAX) { |
| 146 | uint32_t major, minor, update; |
| 147 | if (platform_sp->GetOSVersion(major, minor, update)) { |
| 148 | if (m_os_version_major != major) |
| 149 | return false; |
| 150 | if (m_os_version_minor != minor) |
| 151 | return false; |
| 152 | if (m_os_version_update != update) |
| 153 | return false; |
| 154 | } |
Greg Clayton | ccd2a6d | 2015-01-28 01:33:37 +0000 | [diff] [blame] | 155 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 156 | return true; |
| 157 | } |
| 158 | return false; |
Greg Clayton | ccd2a6d | 2015-01-28 01:33:37 +0000 | [diff] [blame] | 159 | } |