blob: e6d4e7f5ad5f878ce5f48b790fa060ce2b66e005 [file] [log] [blame]
Greg Claytonabe0fed2011-04-18 08:33:37 +00001//===-- 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 Chen4003f572011-09-10 00:48:33 +000018#include "lldb/Utility/Utils.h"
Greg Claytonabe0fed2011-04-18 08:33:37 +000019
20using namespace lldb;
21using namespace lldb_private;
22
23PlatformSP
Greg Claytonb170aee2012-05-08 01:45:38 +000024OptionGroupPlatform::CreatePlatformWithOptions (CommandInterpreter &interpreter,
25 const ArchSpec &arch,
26 bool make_selected,
27 Error& error,
28 ArchSpec &platform_arch) const
Greg Claytonabe0fed2011-04-18 08:33:37 +000029{
30 PlatformSP platform_sp;
Greg Claytonb1db6582012-03-20 18:34:04 +000031
Greg Claytonabe0fed2011-04-18 08:33:37 +000032 if (!m_platform_name.empty())
33 {
34 platform_sp = Platform::Create (m_platform_name.c_str(), error);
Greg Claytonb170aee2012-05-08 01:45:38 +000035 if (platform_sp)
36 {
Greg Clayton1a7f6302012-05-11 18:37:58 +000037 if (platform_arch.IsValid() && !platform_sp->IsCompatibleArchitecture(arch, &platform_arch))
Greg Claytonb170aee2012-05-08 01:45:38 +000038 {
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 Claytonabe0fed2011-04-18 08:33:37 +000044 }
Greg Claytonb1db6582012-03-20 18:34:04 +000045 else if (arch.IsValid())
46 {
Greg Claytonb170aee2012-05-08 01:45:38 +000047 platform_sp = Platform::Create (arch, &platform_arch, error);
Greg Claytonb1db6582012-03-20 18:34:04 +000048 }
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 Claytonabe0fed2011-04-18 08:33:37 +000067 return platform_sp;
68}
69
70void
71OptionGroupPlatform::OptionParsingStarting (CommandInterpreter &interpreter)
72{
73 m_platform_name.clear();
Greg Clayton604f0d32011-06-17 03:31:01 +000074 m_sdk_sysroot.Clear();
75 m_sdk_build.Clear();
Greg Claytonabe0fed2011-04-18 08:33:37 +000076 m_os_version_major = UINT32_MAX;
77 m_os_version_minor = UINT32_MAX;
78 m_os_version_update = UINT32_MAX;
79}
80
81static OptionDefinition
82g_option_table[] =
83{
Greg Clayton604f0d32011-06-17 03:31:01 +000084 { 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 Claytonabe0fed2011-04-18 08:33:37 +000088};
89
Greg Claytonabe0fed2011-04-18 08:33:37 +000090const OptionDefinition*
91OptionGroupPlatform::GetDefinitions ()
92{
93 if (m_include_platform_option)
94 return g_option_table;
95 return g_option_table + 1;
96}
97
98uint32_t
99OptionGroupPlatform::GetNumDefinitions ()
100{
101 if (m_include_platform_option)
Johnny Chen4003f572011-09-10 00:48:33 +0000102 return arraysize(g_option_table);
103 return arraysize(g_option_table) - 1;
Greg Claytonabe0fed2011-04-18 08:33:37 +0000104}
105
106
107Error
108OptionGroupPlatform::SetOptionValue (CommandInterpreter &interpreter,
109 uint32_t option_idx,
110 const char *option_arg)
111{
112 Error error;
113 if (!m_include_platform_option)
Greg Claytone1f50b92011-05-03 22:09:39 +0000114 ++option_idx;
Greg Claytonabe0fed2011-04-18 08:33:37 +0000115
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 Clayton604f0d32011-06-17 03:31:01 +0000132 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 Claytonabe0fed2011-04-18 08:33:37 +0000140 default:
Greg Clayton9c236732011-10-26 00:56:27 +0000141 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000142 break;
143 }
144 return error;
145}