blob: 4e54c39c24f4db916149ebc2350a32985fab4b62 [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 Clayton3e8c25f2011-09-24 00:52:29 +000024OptionGroupPlatform::CreatePlatformWithOptions (CommandInterpreter &interpreter, bool make_selected, Error& error) const
Greg Claytonabe0fed2011-04-18 08:33:37 +000025{
26 PlatformSP platform_sp;
27 if (!m_platform_name.empty())
28 {
29 platform_sp = Platform::Create (m_platform_name.c_str(), error);
30
31 if (platform_sp)
32 {
33 interpreter.GetDebugger().GetPlatformList().Append (platform_sp, make_selected);
34 if (m_os_version_major != UINT32_MAX)
35 {
36 platform_sp->SetOSVersion (m_os_version_major,
37 m_os_version_minor,
38 m_os_version_update);
39 }
Greg Clayton604f0d32011-06-17 03:31:01 +000040
41 if (m_sdk_sysroot)
42 platform_sp->SetSDKRootDirectory (m_sdk_sysroot);
43
44 if (m_sdk_build)
45 platform_sp->SetSDKBuild (m_sdk_build);
Greg Claytonabe0fed2011-04-18 08:33:37 +000046 }
47 }
48 return platform_sp;
49}
50
51void
52OptionGroupPlatform::OptionParsingStarting (CommandInterpreter &interpreter)
53{
54 m_platform_name.clear();
Greg Clayton604f0d32011-06-17 03:31:01 +000055 m_sdk_sysroot.Clear();
56 m_sdk_build.Clear();
Greg Claytonabe0fed2011-04-18 08:33:37 +000057 m_os_version_major = UINT32_MAX;
58 m_os_version_minor = UINT32_MAX;
59 m_os_version_update = UINT32_MAX;
60}
61
62static OptionDefinition
63g_option_table[] =
64{
Greg Clayton604f0d32011-06-17 03:31:01 +000065 { 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."},
66 { LLDB_OPT_SET_ALL, false, "version" , 'v', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK version to use prior to connecting." },
67 { LLDB_OPT_SET_ALL, false, "build" , 'b', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK build number." },
68 { 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 +000069};
70
Greg Claytonabe0fed2011-04-18 08:33:37 +000071const OptionDefinition*
72OptionGroupPlatform::GetDefinitions ()
73{
74 if (m_include_platform_option)
75 return g_option_table;
76 return g_option_table + 1;
77}
78
79uint32_t
80OptionGroupPlatform::GetNumDefinitions ()
81{
82 if (m_include_platform_option)
Johnny Chen4003f572011-09-10 00:48:33 +000083 return arraysize(g_option_table);
84 return arraysize(g_option_table) - 1;
Greg Claytonabe0fed2011-04-18 08:33:37 +000085}
86
87
88Error
89OptionGroupPlatform::SetOptionValue (CommandInterpreter &interpreter,
90 uint32_t option_idx,
91 const char *option_arg)
92{
93 Error error;
94 if (!m_include_platform_option)
Greg Claytone1f50b92011-05-03 22:09:39 +000095 ++option_idx;
Greg Claytonabe0fed2011-04-18 08:33:37 +000096
97 char short_option = (char) g_option_table[option_idx].short_option;
98
99 switch (short_option)
100 {
101 case 'p':
102 m_platform_name.assign (option_arg);
103 break;
104
105 case 'v':
106 if (Args::StringToVersion (option_arg,
107 m_os_version_major,
108 m_os_version_minor,
109 m_os_version_update) == option_arg)
110 error.SetErrorStringWithFormat ("invalid version string '%s'", option_arg);
111 break;
112
Greg Clayton604f0d32011-06-17 03:31:01 +0000113 case 'b':
114 m_sdk_build.SetCString (option_arg);
115 break;
116
117 case 's':
118 m_sdk_sysroot.SetCString (option_arg);
119 break;
120
Greg Claytonabe0fed2011-04-18 08:33:37 +0000121 default:
Greg Clayton9c236732011-10-26 00:56:27 +0000122 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000123 break;
124 }
125 return error;
126}