blob: 59dbceb76269254798d08b6016785fc440034b6c [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 }
39 }
40 }
41 return platform_sp;
42}
43
44void
45OptionGroupPlatform::OptionParsingStarting (CommandInterpreter &interpreter)
46{
47 m_platform_name.clear();
48 m_os_version_major = UINT32_MAX;
49 m_os_version_minor = UINT32_MAX;
50 m_os_version_update = UINT32_MAX;
51}
52
53static OptionDefinition
54g_option_table[] =
55{
56 { 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."},
57 { LLDB_OPT_SET_ALL, false, "sdk-version", 'v', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK version to use prior to connecting." }
58};
59
60static const uint32_t k_option_table_size = sizeof(g_option_table)/sizeof (OptionDefinition);
61
62const OptionDefinition*
63OptionGroupPlatform::GetDefinitions ()
64{
65 if (m_include_platform_option)
66 return g_option_table;
67 return g_option_table + 1;
68}
69
70uint32_t
71OptionGroupPlatform::GetNumDefinitions ()
72{
73 if (m_include_platform_option)
74 return k_option_table_size;
75 return k_option_table_size - 1;
76}
77
78
79Error
80OptionGroupPlatform::SetOptionValue (CommandInterpreter &interpreter,
81 uint32_t option_idx,
82 const char *option_arg)
83{
84 Error error;
85 if (!m_include_platform_option)
86 --option_idx;
87
88 char short_option = (char) g_option_table[option_idx].short_option;
89
90 switch (short_option)
91 {
92 case 'p':
93 m_platform_name.assign (option_arg);
94 break;
95
96 case 'v':
97 if (Args::StringToVersion (option_arg,
98 m_os_version_major,
99 m_os_version_minor,
100 m_os_version_update) == option_arg)
101 error.SetErrorStringWithFormat ("invalid version string '%s'", option_arg);
102 break;
103
104 default:
105 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
106 break;
107 }
108 return error;
109}