aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectFile.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2011-04-13 00:18:08 +0000
committerGreg Clayton <gclayton@apple.com>2011-04-13 00:18:08 +0000
commitf6b8b581846b3d7a0853d89f54b4ac9f94ff5a0e (patch)
tree81a565ca1841c10e1ce58a447724ea9eaf154400 /lldb/source/Commands/CommandObjectFile.cpp
parentdc8355e81a94f5d5e09390f5d98860eedb212121 (diff)
downloadllvm-f6b8b581846b3d7a0853d89f54b4ac9f94ff5a0e.zip
llvm-f6b8b581846b3d7a0853d89f54b4ac9f94ff5a0e.tar.gz
llvm-f6b8b581846b3d7a0853d89f54b4ac9f94ff5a0e.tar.bz2
Added two new classes for command options:
lldb_private::OptionGroup lldb_private::OptionGroupOptions OptionGroup lets you define a class that encapsulates settings that you want to reuse in multiple commands. It contains only the option definitions and the ability to set the option values, but it doesn't directly interface with the lldb_private::Options class that is the front end to all of the CommandObject option parsing. For that the OptionGroupOptions class can be used. It aggregates one or more OptionGroup objects and directs the option setting to the appropriate OptionGroup class. For an example of this, take a look at the CommandObjectFile and how it uses its "m_option_group" object shown below to be able to set values in both the FileOptionGroup and PlatformOptionGroup classes. The members used in CommandObjectFile are: OptionGroupOptions m_option_group; FileOptionGroup m_file_options; PlatformOptionGroup m_platform_options; Then in the constructor for CommandObjectFile you can combine the option settings. The code below shows a simplified version of the constructor: CommandObjectFile::CommandObjectFile(CommandInterpreter &interpreter) : CommandObject (...), m_option_group (interpreter), m_file_options (), m_platform_options(true) { m_option_group.Append (&m_file_options); m_option_group.Append (&m_platform_options); m_option_group.Finalize(); } We append the m_file_options and then the m_platform_options and then tell the option group the finalize the results. This allows the m_option_group to become the organizer of our prefs and after option parsing we end up with valid preference settings in both the m_file_options and m_platform_options objects. This also allows any other commands to use the FileOptionGroup and PlatformOptionGroup classes to implement options for their commands. Renamed: virtual void Options::ResetOptionValues(); to: virtual void Options::OptionParsingStarting(); And implemented a new callback named: virtual Error Options::OptionParsingFinished(); This allows Options subclasses to verify that the options all go together after all of the options have been specified and gives the chance for the command object to return an error. It also gives a chance to take all of the option values and produce or initialize objects after all options have completed parsing. Modfied: virtual Error SetOptionValue (int option_idx, const char *option_arg) = 0; to be: virtual Error SetOptionValue (uint32_t option_idx, const char *option_arg) = 0; (option_idx is now unsigned). llvm-svn: 129415
Diffstat (limited to 'lldb/source/Commands/CommandObjectFile.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectFile.cpp71
1 files changed, 53 insertions, 18 deletions
diff --git a/lldb/source/Commands/CommandObjectFile.cpp b/lldb/source/Commands/CommandObjectFile.cpp
index 1177f5a..372baf9 100644
--- a/lldb/source/Commands/CommandObjectFile.cpp
+++ b/lldb/source/Commands/CommandObjectFile.cpp
@@ -25,41 +25,51 @@
using namespace lldb;
using namespace lldb_private;
-CommandObjectFile::CommandOptions::CommandOptions(CommandInterpreter &interpreter) :
- Options (interpreter),
- m_arch () // Breakpoint info defaults to brief descriptions
+FileOptionGroup::FileOptionGroup() :
+ m_arch (),
+ m_arch_str ()
{
}
-CommandObjectFile::CommandOptions::~CommandOptions ()
+FileOptionGroup::~FileOptionGroup ()
{
}
-OptionDefinition
-CommandObjectFile::CommandOptions::g_option_table[] =
+OptionDefinition g_file_option_table[] =
{
- { LLDB_OPT_SET_1, false, "arch", 'a', required_argument, NULL, 0, eArgTypeArchitecture, "Specify the architecture to be used when the process is launched."},
- { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
+ { LLDB_OPT_SET_1 , false, "arch" , 'a', required_argument, NULL, 0, eArgTypeArchitecture , "Specify the architecture for the target."},
};
+const uint32_t k_num_file_options = sizeof(g_file_option_table)/sizeof(OptionDefinition);
+
+uint32_t
+FileOptionGroup::GetNumDefinitions ()
+{
+ return k_num_file_options;
+}
const OptionDefinition *
-CommandObjectFile::CommandOptions::GetDefinitions ()
+FileOptionGroup::GetDefinitions ()
{
- return g_option_table;
+ return g_file_option_table;
}
Error
-CommandObjectFile::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
+FileOptionGroup::SetOptionValue (CommandInterpreter &interpreter,
+ uint32_t option_idx,
+ const char *option_arg)
{
Error error;
- char short_option = (char) m_getopt_table[option_idx].val;
+ char short_option = (char) g_file_option_table[option_idx].short_option;
switch (short_option)
{
case 'a':
{
- PlatformSP platform_sp (m_interpreter.GetPlatform (false));
- ArchSpec option_arch (option_arg, platform_sp.get());
+ // Save the arch value in case we specify a platform after specifying the arch
+ m_arch_str.assign (option_arg);
+ // Check to see if we already have a platform?
+ m_arch_platform_sp = interpreter.GetPlatform (false);
+ ArchSpec option_arch (option_arg, m_arch_platform_sp.get());
if (option_arch.IsValid())
m_arch = option_arch;
else
@@ -76,11 +86,30 @@ CommandObjectFile::CommandOptions::SetOptionValue (int option_idx, const char *o
}
void
-CommandObjectFile::CommandOptions::ResetOptionValues ()
+FileOptionGroup::OptionParsingStarting (CommandInterpreter &interpreter)
{
m_arch.Clear();
}
+Error
+FileOptionGroup::OptionParsingFinished (CommandInterpreter &interpreter)
+{
+ Error error;
+ if (m_arch.IsValid())
+ {
+ PlatformSP curr_platform_sp (interpreter.GetPlatform (false));
+ if (curr_platform_sp.get() != m_arch_platform_sp.get())
+ {
+ ArchSpec option_arch (m_arch_str.c_str(), curr_platform_sp.get());
+ if (option_arch.IsValid())
+ m_arch = option_arch;
+ else
+ error.SetErrorStringWithFormat ("invalid arch '%s' for platform '%s'", m_arch_str.c_str(), curr_platform_sp->GetName());
+ }
+ }
+ return error;
+}
+
//-------------------------------------------------------------------------
// CommandObjectFile
//-------------------------------------------------------------------------
@@ -90,7 +119,9 @@ CommandObjectFile::CommandObjectFile(CommandInterpreter &interpreter) :
"file",
"Set the file to be used as the main executable by the debugger.",
NULL),
- m_options (interpreter)
+ m_option_group (interpreter),
+ m_file_options (),
+ m_platform_options(true) // Do include the "--platform" option in the platform settings by passing true
{
CommandArgumentEntry arg;
CommandArgumentData file_arg;
@@ -104,6 +135,10 @@ CommandObjectFile::CommandObjectFile(CommandInterpreter &interpreter) :
// Push the data for the first argument into the m_arguments vector.
m_arguments.push_back (arg);
+
+ m_option_group.Append (&m_file_options);
+ m_option_group.Append (&m_platform_options);
+ m_option_group.Finalize();
}
CommandObjectFile::~CommandObjectFile ()
@@ -113,7 +148,7 @@ CommandObjectFile::~CommandObjectFile ()
Options *
CommandObjectFile::GetOptions ()
{
- return &m_options;
+ return &m_option_group;
}
bool
@@ -140,7 +175,7 @@ CommandObjectFile::Execute
TargetSP target_sp;
Debugger &debugger = m_interpreter.GetDebugger();
- Error error = debugger.GetTargetList().CreateTarget (debugger, file_spec, m_options.m_arch, true, target_sp);
+ Error error = debugger.GetTargetList().CreateTarget (debugger, file_spec, m_file_options.m_arch, true, target_sp);
if (target_sp)
{