blob: ca2f3ffc937b23d67187169383d6c4999834829c [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 Claytonb1db6582012-03-20 18:34:04 +000024OptionGroupPlatform::CreatePlatformWithOptions (CommandInterpreter &interpreter, const ArchSpec &arch, bool make_selected, Error& error) const
Greg Claytonabe0fed2011-04-18 08:33:37 +000025{
26 PlatformSP platform_sp;
Greg Claytonb1db6582012-03-20 18:34:04 +000027
Greg Claytonabe0fed2011-04-18 08:33:37 +000028 if (!m_platform_name.empty())
29 {
30 platform_sp = Platform::Create (m_platform_name.c_str(), error);
Greg Claytonabe0fed2011-04-18 08:33:37 +000031 }
Greg Claytonb1db6582012-03-20 18:34:04 +000032 else if (arch.IsValid())
33 {
34 platform_sp = Platform::Create (arch, error);
35 }
36
37 if (platform_sp)
38 {
39 interpreter.GetDebugger().GetPlatformList().Append (platform_sp, make_selected);
40 if (m_os_version_major != UINT32_MAX)
41 {
42 platform_sp->SetOSVersion (m_os_version_major,
43 m_os_version_minor,
44 m_os_version_update);
45 }
46
47 if (m_sdk_sysroot)
48 platform_sp->SetSDKRootDirectory (m_sdk_sysroot);
49
50 if (m_sdk_build)
51 platform_sp->SetSDKBuild (m_sdk_build);
52 }
53
Greg Claytonabe0fed2011-04-18 08:33:37 +000054 return platform_sp;
55}
56
57void
58OptionGroupPlatform::OptionParsingStarting (CommandInterpreter &interpreter)
59{
60 m_platform_name.clear();
Greg Clayton604f0d32011-06-17 03:31:01 +000061 m_sdk_sysroot.Clear();
62 m_sdk_build.Clear();
Greg Claytonabe0fed2011-04-18 08:33:37 +000063 m_os_version_major = UINT32_MAX;
64 m_os_version_minor = UINT32_MAX;
65 m_os_version_update = UINT32_MAX;
66}
67
68static OptionDefinition
69g_option_table[] =
70{
Greg Clayton604f0d32011-06-17 03:31:01 +000071 { 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."},
72 { LLDB_OPT_SET_ALL, false, "version" , 'v', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK version to use prior to connecting." },
73 { LLDB_OPT_SET_ALL, false, "build" , 'b', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK build number." },
74 { 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 +000075};
76
Greg Claytonabe0fed2011-04-18 08:33:37 +000077const OptionDefinition*
78OptionGroupPlatform::GetDefinitions ()
79{
80 if (m_include_platform_option)
81 return g_option_table;
82 return g_option_table + 1;
83}
84
85uint32_t
86OptionGroupPlatform::GetNumDefinitions ()
87{
88 if (m_include_platform_option)
Johnny Chen4003f572011-09-10 00:48:33 +000089 return arraysize(g_option_table);
90 return arraysize(g_option_table) - 1;
Greg Claytonabe0fed2011-04-18 08:33:37 +000091}
92
93
94Error
95OptionGroupPlatform::SetOptionValue (CommandInterpreter &interpreter,
96 uint32_t option_idx,
97 const char *option_arg)
98{
99 Error error;
100 if (!m_include_platform_option)
Greg Claytone1f50b92011-05-03 22:09:39 +0000101 ++option_idx;
Greg Claytonabe0fed2011-04-18 08:33:37 +0000102
103 char short_option = (char) g_option_table[option_idx].short_option;
104
105 switch (short_option)
106 {
107 case 'p':
108 m_platform_name.assign (option_arg);
109 break;
110
111 case 'v':
112 if (Args::StringToVersion (option_arg,
113 m_os_version_major,
114 m_os_version_minor,
115 m_os_version_update) == option_arg)
116 error.SetErrorStringWithFormat ("invalid version string '%s'", option_arg);
117 break;
118
Greg Clayton604f0d32011-06-17 03:31:01 +0000119 case 'b':
120 m_sdk_build.SetCString (option_arg);
121 break;
122
123 case 's':
124 m_sdk_sysroot.SetCString (option_arg);
125 break;
126
Greg Claytonabe0fed2011-04-18 08:33:37 +0000127 default:
Greg Clayton9c236732011-10-26 00:56:27 +0000128 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000129 break;
130 }
131 return error;
132}