blob: 1734a792d608ebf4b339f76046cb6ab00031a444 [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"
18
19using namespace lldb;
20using namespace lldb_private;
21
22PlatformSP
23OptionGroupPlatform::CreatePlatformWithOptions (CommandInterpreter &interpreter, bool make_selected, Error& error)
24{
25 PlatformSP platform_sp;
26 if (!m_platform_name.empty())
27 {
28 platform_sp = Platform::Create (m_platform_name.c_str(), error);
29
30 if (platform_sp)
31 {
32 interpreter.GetDebugger().GetPlatformList().Append (platform_sp, make_selected);
33 if (m_os_version_major != UINT32_MAX)
34 {
35 platform_sp->SetOSVersion (m_os_version_major,
36 m_os_version_minor,
37 m_os_version_update);
38 }
Greg Clayton604f0d32011-06-17 03:31:01 +000039
40 if (m_sdk_sysroot)
41 platform_sp->SetSDKRootDirectory (m_sdk_sysroot);
42
43 if (m_sdk_build)
44 platform_sp->SetSDKBuild (m_sdk_build);
Greg Claytonabe0fed2011-04-18 08:33:37 +000045 }
46 }
47 return platform_sp;
48}
49
50void
51OptionGroupPlatform::OptionParsingStarting (CommandInterpreter &interpreter)
52{
53 m_platform_name.clear();
Greg Clayton604f0d32011-06-17 03:31:01 +000054 m_sdk_sysroot.Clear();
55 m_sdk_build.Clear();
Greg Claytonabe0fed2011-04-18 08:33:37 +000056 m_os_version_major = UINT32_MAX;
57 m_os_version_minor = UINT32_MAX;
58 m_os_version_update = UINT32_MAX;
59}
60
61static OptionDefinition
62g_option_table[] =
63{
Greg Clayton604f0d32011-06-17 03:31:01 +000064 { 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."},
65 { LLDB_OPT_SET_ALL, false, "version" , 'v', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK version to use prior to connecting." },
66 { LLDB_OPT_SET_ALL, false, "build" , 'b', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK build number." },
67 { 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 +000068};
69
70static const uint32_t k_option_table_size = sizeof(g_option_table)/sizeof (OptionDefinition);
71
72const OptionDefinition*
73OptionGroupPlatform::GetDefinitions ()
74{
75 if (m_include_platform_option)
76 return g_option_table;
77 return g_option_table + 1;
78}
79
80uint32_t
81OptionGroupPlatform::GetNumDefinitions ()
82{
83 if (m_include_platform_option)
84 return k_option_table_size;
85 return k_option_table_size - 1;
86}
87
88
89Error
90OptionGroupPlatform::SetOptionValue (CommandInterpreter &interpreter,
91 uint32_t option_idx,
92 const char *option_arg)
93{
94 Error error;
95 if (!m_include_platform_option)
Greg Claytone1f50b92011-05-03 22:09:39 +000096 ++option_idx;
Greg Claytonabe0fed2011-04-18 08:33:37 +000097
98 char short_option = (char) g_option_table[option_idx].short_option;
99
100 switch (short_option)
101 {
102 case 'p':
103 m_platform_name.assign (option_arg);
104 break;
105
106 case 'v':
107 if (Args::StringToVersion (option_arg,
108 m_os_version_major,
109 m_os_version_minor,
110 m_os_version_update) == option_arg)
111 error.SetErrorStringWithFormat ("invalid version string '%s'", option_arg);
112 break;
113
Greg Clayton604f0d32011-06-17 03:31:01 +0000114 case 'b':
115 m_sdk_build.SetCString (option_arg);
116 break;
117
118 case 's':
119 m_sdk_sysroot.SetCString (option_arg);
120 break;
121
Greg Claytonabe0fed2011-04-18 08:33:37 +0000122 default:
123 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
124 break;
125 }
126 return error;
127}