]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Interpreter/OptionGroupPlatform.cpp
Upgrade Unbound to 1.7.3. More to follow.
[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_major != UINT32_MAX) {
48       platform_sp->SetOSVersion(m_os_version_major, m_os_version_minor,
49                                 m_os_version_update);
50     }
51
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;
60 }
61
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;
70 }
71
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."}};
87
88 llvm::ArrayRef<OptionDefinition> OptionGroupPlatform::GetDefinitions() {
89   llvm::ArrayRef<OptionDefinition> result(g_option_table);
90   if (m_include_platform_option)
91     return result;
92   return result.drop_front();
93 }
94
95 Status
96 OptionGroupPlatform::SetOptionValue(uint32_t option_idx,
97                                     llvm::StringRef option_arg,
98                                     ExecutionContext *execution_context) {
99   Status error;
100   if (!m_include_platform_option)
101     ++option_idx;
102
103   const int short_option = g_option_table[option_idx].short_option;
104
105   switch (short_option) {
106   case 'p':
107     m_platform_name.assign(option_arg);
108     break;
109
110   case 'v':
111     if (!Args::StringToVersion(option_arg, m_os_version_major,
112                                m_os_version_minor, m_os_version_update))
113       error.SetErrorStringWithFormat("invalid version string '%s'",
114                                      option_arg.str().c_str());
115     break;
116
117   case 'b':
118     m_sdk_build.SetString(option_arg);
119     break;
120
121   case 'S':
122     m_sdk_sysroot.SetString(option_arg);
123     break;
124
125   default:
126     error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
127     break;
128   }
129   return error;
130 }
131
132 bool OptionGroupPlatform::PlatformMatches(
133     const lldb::PlatformSP &platform_sp) const {
134   if (platform_sp) {
135     if (!m_platform_name.empty()) {
136       if (platform_sp->GetName() != ConstString(m_platform_name.c_str()))
137         return false;
138     }
139
140     if (m_sdk_build && m_sdk_build != platform_sp->GetSDKBuild())
141       return false;
142
143     if (m_sdk_sysroot && m_sdk_sysroot != platform_sp->GetSDKRootDirectory())
144       return false;
145
146     if (m_os_version_major != UINT32_MAX) {
147       uint32_t major, minor, update;
148       if (platform_sp->GetOSVersion(major, minor, update)) {
149         if (m_os_version_major != major)
150           return false;
151         if (m_os_version_minor != minor)
152           return false;
153         if (m_os_version_update != update)
154           return false;
155       }
156     }
157     return true;
158   }
159   return false;
160 }