blob: 97eb0a4e5fcf25fd17bdcf1bb208f7a65266314a [file] [log] [blame]
Greg Claytonb1888f22011-03-19 01:12:21 +00001//===-- CommandObjectPlatform.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 "CommandObjectPlatform.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Core/DataExtractor.h"
17#include "lldb/Core/Debugger.h"
18#include "lldb/Core/PluginManager.h"
19#include "lldb/Interpreter/Args.h"
20#include "lldb/Interpreter/CommandInterpreter.h"
21#include "lldb/Interpreter/CommandReturnObject.h"
22#include "lldb/Target/ExecutionContext.h"
23#include "lldb/Target/Platform.h"
24
25using namespace lldb;
26using namespace lldb_private;
27
28//----------------------------------------------------------------------
29// "platform create <platform-name>"
30//----------------------------------------------------------------------
31class CommandObjectPlatformCreate : public CommandObject
32{
33public:
34 CommandObjectPlatformCreate (CommandInterpreter &interpreter) :
35 CommandObject (interpreter,
36 "platform create",
37 "Create a platform instance by name and select it as the current platform.",
38 "platform create <platform-name>",
39 0)
40 {
41 }
42
43 virtual
44 ~CommandObjectPlatformCreate ()
45 {
46 }
47
48 virtual bool
49 Execute (Args& args, CommandReturnObject &result)
50 {
51 Error error;
52 if (args.GetArgumentCount() == 1)
53 {
54 PlatformSP platform_sp (Platform::Create (args.GetArgumentAtIndex (0), error));
55
56 if (platform_sp)
57 {
58 m_interpreter.GetDebugger().GetPlatformList().Append (platform_sp, true);
59 if (m_options.os_version_major != UINT32_MAX)
60 {
61 platform_sp->SetOSVersion (m_options.os_version_major,
62 m_options.os_version_minor,
63 m_options.os_version_update);
64 }
65
66 platform_sp->GetStatus (result.GetOutputStream());
67 }
68 }
69 else
70 {
71 result.AppendError ("command not implemented");
72 result.SetStatus (eReturnStatusFailed);
73 }
74 return result.Succeeded();
75 }
76
77 virtual Options *
78 GetOptions ()
79 {
80 return &m_options;
81 }
82
83protected:
84
85 class CommandOptions : public Options
86 {
87 public:
88
89 CommandOptions () :
90 os_version_major (UINT32_MAX),
91 os_version_minor (UINT32_MAX),
92 os_version_update (UINT32_MAX)
93 {
94 }
95
96 virtual
97 ~CommandOptions ()
98 {
99 }
100
101 virtual Error
102 SetOptionValue (int option_idx, const char *option_arg)
103 {
104 Error error;
105 char short_option = (char) m_getopt_table[option_idx].val;
106
107 switch (short_option)
108 {
109 case 'v':
110 if (Args::StringToVersion (option_arg,
111 os_version_major,
112 os_version_minor,
113 os_version_update) == option_arg)
114 {
115 error.SetErrorStringWithFormat ("invalid version string '%s'", option_arg);
116 }
117 break;
118
119 default:
120 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
121 break;
122 }
123
124 return error;
125 }
126
127 void
128 ResetOptionValues ()
129 {
130 os_version_major = UINT32_MAX;
131 os_version_minor = UINT32_MAX;
132 os_version_update = UINT32_MAX;
133 }
134
135 const lldb::OptionDefinition*
136 GetDefinitions ()
137 {
138 return g_option_table;
139 }
140
141 // Options table: Required for subclasses of Options.
142
143 static lldb::OptionDefinition g_option_table[];
144
145 // Instance variables to hold the values for command options.
146
147 uint32_t os_version_major;
148 uint32_t os_version_minor;
149 uint32_t os_version_update;
150 };
151 CommandOptions m_options;
152};
153
154lldb::OptionDefinition
155CommandObjectPlatformCreate::CommandOptions::g_option_table[] =
156{
157 { LLDB_OPT_SET_ALL, false, "sdk-version", 'v', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK version to use prior to connecting." },
158 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
159};
160
161//----------------------------------------------------------------------
162// "platform list"
163//----------------------------------------------------------------------
164class CommandObjectPlatformList : public CommandObject
165{
166public:
167 CommandObjectPlatformList (CommandInterpreter &interpreter) :
168 CommandObject (interpreter,
169 "platform list",
170 "List all platforms that are available.",
171 NULL,
172 0)
173 {
174 }
175
176 virtual
177 ~CommandObjectPlatformList ()
178 {
179 }
180
181 virtual bool
182 Execute (Args& args, CommandReturnObject &result)
183 {
184 Stream &ostrm = result.GetOutputStream();
185 ostrm.Printf("Available platforms:\n");
186
187 PlatformSP host_platform_sp (Platform::GetDefaultPlatform());
188 ostrm.Printf ("%s: %s\n",
189 host_platform_sp->GetShortPluginName(),
190 host_platform_sp->GetDescription());
191
192 uint32_t idx;
193 for (idx = 0; 1; ++idx)
194 {
195 const char *plugin_name = PluginManager::GetPlatformPluginNameAtIndex (idx);
196 if (plugin_name == NULL)
197 break;
198 const char *plugin_desc = PluginManager::GetPlatformPluginDescriptionAtIndex (idx);
199 if (plugin_desc == NULL)
200 break;
201 ostrm.Printf("%s: %s\n", plugin_name, plugin_desc);
202 }
203
204 if (idx == 0)
205 {
206 result.AppendError ("no platforms are available");
207 result.SetStatus (eReturnStatusFailed);
208 }
209 return result.Succeeded();
210 }
211};
212
213//----------------------------------------------------------------------
214// "platform status"
215//----------------------------------------------------------------------
216class CommandObjectPlatformStatus : public CommandObject
217{
218public:
219 CommandObjectPlatformStatus (CommandInterpreter &interpreter) :
220 CommandObject (interpreter,
221 "platform status",
222 "Display status for the currently selected platform.",
223 NULL,
224 0)
225 {
226 }
227
228 virtual
229 ~CommandObjectPlatformStatus ()
230 {
231 }
232
233 virtual bool
234 Execute (Args& args, CommandReturnObject &result)
235 {
236 Stream &ostrm = result.GetOutputStream();
237
238 PlatformSP selected_platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
239 if (selected_platform_sp)
240 {
241 selected_platform_sp->GetStatus (ostrm);
242 result.SetStatus (eReturnStatusSuccessFinishResult);
243 }
244 else
245 {
246 result.AppendError ("no platform us currently selected");
247 result.SetStatus (eReturnStatusFailed);
248 }
249 return result.Succeeded();
250 }
251};
252
253
254//----------------------------------------------------------------------
255// "platform select <platform-name>"
256//----------------------------------------------------------------------
257class CommandObjectPlatformSelect : public CommandObject
258{
259public:
260 CommandObjectPlatformSelect (CommandInterpreter &interpreter) :
261 CommandObject (interpreter,
262 "platform select",
263 "Select a platform by name to be the currently selected platform.",
264 "platform select <platform-name>",
265 0)
266 {
267 }
268
269 virtual
270 ~CommandObjectPlatformSelect ()
271 {
272 }
273
274 virtual bool
275 Execute (Args& args, CommandReturnObject &result)
276 {
277 result.AppendError ("command not implemented");
278 result.SetStatus (eReturnStatusFailed);
279 return result.Succeeded();
280 }
281};
282
283
284
285//----------------------------------------------------------------------
286// CommandObjectPlatform constructor
287//----------------------------------------------------------------------
288CommandObjectPlatform::CommandObjectPlatform(CommandInterpreter &interpreter) :
289 CommandObjectMultiword (interpreter,
290 "platform",
291 "A set of commands to manage and create platforms.",
292 "platform [create|list|status|select] ...")
293{
294 LoadSubCommand ("create", CommandObjectSP (new CommandObjectPlatformCreate (interpreter)));
295 LoadSubCommand ("list" , CommandObjectSP (new CommandObjectPlatformList (interpreter)));
296 LoadSubCommand ("select", CommandObjectSP (new CommandObjectPlatformSelect (interpreter)));
297 LoadSubCommand ("status", CommandObjectSP (new CommandObjectPlatformStatus (interpreter)));
298}
299
300
301//----------------------------------------------------------------------
302// Destructor
303//----------------------------------------------------------------------
304CommandObjectPlatform::~CommandObjectPlatform()
305{
306}