]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Interpreter/OptionGroupPlatform.cpp
Merge ^/head r338988 through r339014.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Interpreter / OptionGroupPlatform.cpp
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/Host/OptionParser.h"
17 #include "lldb/Interpreter/CommandInterpreter.h"
18 #include "lldb/Target/Platform.h"
19
20 using namespace lldb;
21 using namespace lldb_private;
22
23 PlatformSP OptionGroupPlatform::CreatePlatformWithOptions(
24     CommandInterpreter &interpreter, const ArchSpec &arch, bool make_selected,
25     Status &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       }
39     }
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.empty())
48       platform_sp->SetOSVersion(m_os_version);
49
50     if (m_sdk_sysroot)
51       platform_sp->SetSDKRootDirectory(m_sdk_sysroot);
52
53     if (m_sdk_build)
54       platform_sp->SetSDKBuild(m_sdk_build);
55   }
56
57   return platform_sp;
58 }
59
60 void OptionGroupPlatform::OptionParsingStarting(
61     ExecutionContext *execution_context) {
62   m_platform_name.clear();
63   m_sdk_sysroot.Clear();
64   m_sdk_build.Clear();
65   m_os_version = llvm::VersionTuple();
66 }
67
68 static OptionDefinition g_option_table[] = {
69     {LLDB_OPT_SET_ALL, false, "platform", 'p', OptionParser::eRequiredArgument,
70      nullptr, nullptr, 0, eArgTypePlatform, "Specify name of the platform to "
71                                             "use for this target, creating the "
72                                             "platform if necessary."},
73     {LLDB_OPT_SET_ALL, false, "version", 'v', OptionParser::eRequiredArgument,
74      nullptr, nullptr, 0, eArgTypeNone,
75      "Specify the initial SDK version to use prior to connecting."},
76     {LLDB_OPT_SET_ALL, false, "build", 'b', OptionParser::eRequiredArgument,
77      nullptr, nullptr, 0, eArgTypeNone,
78      "Specify the initial SDK build number."},
79     {LLDB_OPT_SET_ALL, false, "sysroot", 'S', OptionParser::eRequiredArgument,
80      nullptr, nullptr, 0, eArgTypeFilename, "Specify the SDK root directory "
81                                             "that contains a root of all "
82                                             "remote system files."}};
83
84 llvm::ArrayRef<OptionDefinition> OptionGroupPlatform::GetDefinitions() {
85   llvm::ArrayRef<OptionDefinition> result(g_option_table);
86   if (m_include_platform_option)
87     return result;
88   return result.drop_front();
89 }
90
91 Status
92 OptionGroupPlatform::SetOptionValue(uint32_t option_idx,
93                                     llvm::StringRef option_arg,
94                                     ExecutionContext *execution_context) {
95   Status error;
96   if (!m_include_platform_option)
97     ++option_idx;
98
99   const int short_option = g_option_table[option_idx].short_option;
100
101   switch (short_option) {
102   case 'p':
103     m_platform_name.assign(option_arg);
104     break;
105
106   case 'v':
107     if (m_os_version.tryParse(option_arg))
108       error.SetErrorStringWithFormatv("invalid version string '{0}'",
109                                       option_arg);
110     break;
111
112   case 'b':
113     m_sdk_build.SetString(option_arg);
114     break;
115
116   case 'S':
117     m_sdk_sysroot.SetString(option_arg);
118     break;
119
120   default:
121     error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
122     break;
123   }
124   return error;
125 }
126
127 bool OptionGroupPlatform::PlatformMatches(
128     const lldb::PlatformSP &platform_sp) const {
129   if (platform_sp) {
130     if (!m_platform_name.empty()) {
131       if (platform_sp->GetName() != ConstString(m_platform_name.c_str()))
132         return false;
133     }
134
135     if (m_sdk_build && m_sdk_build != platform_sp->GetSDKBuild())
136       return false;
137
138     if (m_sdk_sysroot && m_sdk_sysroot != platform_sp->GetSDKRootDirectory())
139       return false;
140
141     if (!m_os_version.empty() && m_os_version != platform_sp->GetOSVersion())
142       return false;
143     return true;
144   }
145   return false;
146 }