Added auto completion for architecture names and for platforms.
Modified the OptionGroupOptions to be able to specify only some of the options
that should be appended by using the usage_mask in the group defintions and
also provided a way to remap them to a new usage mask after the copy. This
allows options to be re-used and also targetted for specific option groups.
Modfied the CommandArgumentType to have a new eArgTypePlatform enumeration.
Taught the option parser to be able to automatically use the appropriate
auto completion for a given options if nothing is explicitly specified
in the option definition. So you don't have to specify it in the option
definition tables.
Renamed the default host platform name to "host", and the default platform
hostname to be "localhost".
Modified the "file" and "platform select" commands to make sure all options
and args are good prior to creating a new platform. Also defer the computation
of the architecture in the file command until all options are parsed and the
platform has either not been specified or reset to a new value to avoid
computing the arch more than once.
Switch the PluginManager code over to using llvm::StringRef for string
comparisons and got rid of all the AccessorXXX functions in lieu of the newer
mutex + collection singleton accessors.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@129483 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Commands/CommandCompletions.cpp b/source/Commands/CommandCompletions.cpp
index fcfc29b..e57a8b4 100644
--- a/source/Commands/CommandCompletions.cpp
+++ b/source/Commands/CommandCompletions.cpp
@@ -20,6 +20,7 @@
// Project includes
#include "lldb/Host/FileSpec.h"
#include "lldb/Core/FileSpecList.h"
+#include "lldb/Core/PluginManager.h"
#include "lldb/Interpreter/Args.h"
#include "lldb/Interpreter/CommandCompletions.h"
#include "lldb/Interpreter/CommandInterpreter.h"
@@ -38,6 +39,8 @@
{eSymbolCompletion, CommandCompletions::Symbols},
{eModuleCompletion, CommandCompletions::Modules},
{eSettingsNameCompletion, CommandCompletions::SettingsNames},
+ {ePlatformPluginCompletion, CommandCompletions::PlatformPluginNames},
+ {eArchitectureCompletion, CommandCompletions::ArchitectureNames},
{eNoCompletion, NULL} // This one has to be last in the list.
};
@@ -413,6 +416,36 @@
//return matches.GetSize();
}
+
+int
+CommandCompletions::PlatformPluginNames (CommandInterpreter &interpreter,
+ const char *partial_name,
+ int match_start_point,
+ int max_return_elements,
+ SearchFilter *searcher,
+ bool &word_complete,
+ lldb_private::StringList &matches)
+{
+ const uint32_t num_matches = PluginManager::AutoCompletePlatformName(partial_name, matches);
+ word_complete = num_matches == 1;
+ return num_matches;
+}
+
+int
+CommandCompletions::ArchitectureNames (CommandInterpreter &interpreter,
+ const char *partial_name,
+ int match_start_point,
+ int max_return_elements,
+ SearchFilter *searcher,
+ bool &word_complete,
+ lldb_private::StringList &matches)
+{
+ const uint32_t num_matches = ArchSpec::AutoComplete (partial_name, matches);
+ word_complete = num_matches == 1;
+ return num_matches;
+}
+
+
CommandCompletions::Completer::Completer
(
CommandInterpreter &interpreter,
diff --git a/source/Commands/CommandObjectFile.cpp b/source/Commands/CommandObjectFile.cpp
index 372baf9..563cbe2 100644
--- a/source/Commands/CommandObjectFile.cpp
+++ b/source/Commands/CommandObjectFile.cpp
@@ -26,7 +26,6 @@
using namespace lldb_private;
FileOptionGroup::FileOptionGroup() :
- m_arch (),
m_arch_str ()
{
}
@@ -53,6 +52,17 @@
return g_file_option_table;
}
+bool
+FileOptionGroup::GetArchitecture (Platform *platform, ArchSpec &arch)
+{
+ if (m_arch_str.empty())
+ arch.Clear();
+ else
+ arch.SetTriple(m_arch_str.c_str(), platform);
+ return arch.IsValid();
+}
+
+
Error
FileOptionGroup::SetOptionValue (CommandInterpreter &interpreter,
uint32_t option_idx,
@@ -64,17 +74,7 @@
switch (short_option)
{
case 'a':
- {
- // 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
- error.SetErrorStringWithFormat ("Invalid arch string '%s'.\n", option_arg);
- }
+ m_arch_str.assign (option_arg);
break;
default:
@@ -88,26 +88,7 @@
void
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;
+ m_arch_str.clear();
}
//-------------------------------------------------------------------------
@@ -136,8 +117,8 @@
// 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.Append (&m_file_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+ m_option_group.Append (&m_platform_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
m_option_group.Finalize();
}
@@ -164,18 +145,46 @@
if (argc == 1)
{
FileSpec file_spec (file_path, true);
+
+ bool select = true;
+ PlatformSP platform_sp;
+
+ Error error;
+
+ if (!m_platform_options.platform_name.empty())
+ {
+ platform_sp = m_platform_options.CreatePlatformWithOptions(m_interpreter, select, error);
+ if (!platform_sp)
+ {
+ result.AppendError(error.AsCString());
+ result.SetStatus (eReturnStatusFailed);
+ return false;
+ }
+ }
+ ArchSpec file_arch;
+
+ if (!m_file_options.m_arch_str.empty())
+ {
+ if (!platform_sp)
+ platform_sp = m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform();
+ if (!m_file_options.GetArchitecture(platform_sp.get(), file_arch))
+ {
+ result.AppendErrorWithFormat("invalid architecture '%s'", m_file_options.m_arch_str.c_str());
+ result.SetStatus (eReturnStatusFailed);
+ return false;
+ }
+ }
if (! file_spec.Exists() && !file_spec.ResolveExecutableLocation())
{
result.AppendErrorWithFormat ("File '%s' does not exist.\n", file_path);
result.SetStatus (eReturnStatusFailed);
- return result.Succeeded();
+ return false;
}
TargetSP target_sp;
-
Debugger &debugger = m_interpreter.GetDebugger();
- Error error = debugger.GetTargetList().CreateTarget (debugger, file_spec, m_file_options.m_arch, true, target_sp);
+ error = debugger.GetTargetList().CreateTarget (debugger, file_spec, file_arch, true, target_sp);
if (target_sp)
{
diff --git a/source/Commands/CommandObjectFile.h b/source/Commands/CommandObjectFile.h
index 1af8896..f3ef2d9 100644
--- a/source/Commands/CommandObjectFile.h
+++ b/source/Commands/CommandObjectFile.h
@@ -26,37 +26,35 @@
// CommandObjectFile
//-------------------------------------------------------------------------
- class FileOptionGroup : public OptionGroup
- {
- public:
-
- FileOptionGroup ();
-
- virtual
- ~FileOptionGroup ();
+class FileOptionGroup : public OptionGroup
+{
+public:
+
+ FileOptionGroup ();
+
+ virtual
+ ~FileOptionGroup ();
-
- virtual uint32_t
- GetNumDefinitions ();
-
- virtual const OptionDefinition*
- GetDefinitions ();
-
- virtual Error
- SetOptionValue (CommandInterpreter &interpreter,
- uint32_t option_idx,
- const char *option_value);
-
- virtual void
- OptionParsingStarting (CommandInterpreter &interpreter);
-
- virtual Error
- OptionParsingFinished (CommandInterpreter &interpreter);
-
- ArchSpec m_arch;
- lldb::PlatformSP m_arch_platform_sp; // The platform that was used to resolve m_arch
- std::string m_arch_str; // Save the arch triple in case a platform is specified after the architecture
- };
+
+ virtual uint32_t
+ GetNumDefinitions ();
+
+ virtual const OptionDefinition*
+ GetDefinitions ();
+
+ virtual Error
+ SetOptionValue (CommandInterpreter &interpreter,
+ uint32_t option_idx,
+ const char *option_value);
+
+ virtual void
+ OptionParsingStarting (CommandInterpreter &interpreter);
+
+ bool
+ GetArchitecture (Platform *platform, ArchSpec &arch);
+
+ std::string m_arch_str; // Save the arch triple in case a platform is specified after the architecture
+};
class CommandObjectFile : public CommandObject
{
diff --git a/source/Commands/CommandObjectLog.cpp b/source/Commands/CommandObjectLog.cpp
index e38b618..7dcfabc 100644
--- a/source/Commands/CommandObjectLog.cpp
+++ b/source/Commands/CommandObjectLog.cpp
@@ -42,16 +42,6 @@
using namespace lldb_private;
-static LogChannelSP
-GetLogChannelPluginForChannel (const char *channel)
-{
- std::string log_channel_plugin_name(channel);
- log_channel_plugin_name += LogChannel::GetPluginSuffix();
- LogChannelSP log_channel_sp (LogChannel::FindPlugin (log_channel_plugin_name.c_str()));
- return log_channel_sp;
-}
-
-
class CommandObjectLogEnable : public CommandObject
{
public:
@@ -99,6 +89,27 @@
return &m_options;
}
+// int
+// HandleArgumentCompletion (Args &input,
+// int &cursor_index,
+// int &cursor_char_position,
+// OptionElementVector &opt_element_vector,
+// int match_start_point,
+// int max_return_elements,
+// bool &word_complete,
+// StringList &matches)
+// {
+// std::string completion_str (input.GetArgumentAtIndex(cursor_index));
+// completion_str.erase (cursor_char_position);
+//
+// if (cursor_index == 1)
+// {
+// //
+// Log::AutoCompleteChannelName (completion_str.c_str(), matches);
+// }
+// return matches.GetSize();
+// }
+//
virtual bool
Execute (Args& args,
CommandReturnObject &result)
@@ -141,7 +152,7 @@
}
else
{
- LogChannelSP log_channel_sp (GetLogChannelPluginForChannel(channel.c_str()));
+ LogChannelSP log_channel_sp (LogChannel::FindPlugin (channel.c_str()));
if (log_channel_sp)
{
if (log_channel_sp->Enable (log_stream_sp, log_options, &result.GetErrorStream(), args))
@@ -314,7 +325,7 @@
}
else
{
- LogChannelSP log_channel_sp (GetLogChannelPluginForChannel(channel.c_str()));
+ LogChannelSP log_channel_sp (LogChannel::FindPlugin(channel.c_str()));
if (log_channel_sp)
{
log_channel_sp->Disable(args, &result.GetErrorStream());
@@ -388,7 +399,7 @@
}
else
{
- LogChannelSP log_channel_sp (GetLogChannelPluginForChannel(channel.c_str()));
+ LogChannelSP log_channel_sp (LogChannel::FindPlugin(channel.c_str()));
if (log_channel_sp)
{
log_channel_sp->ListCategories(&result.GetOutputStream());
diff --git a/source/Commands/CommandObjectPlatform.cpp b/source/Commands/CommandObjectPlatform.cpp
index 46a53c7..2528651 100644
--- a/source/Commands/CommandObjectPlatform.cpp
+++ b/source/Commands/CommandObjectPlatform.cpp
@@ -29,44 +29,31 @@
PlatformSP
-PlatformOptionGroup::CreatePlatformWithOptions (CommandInterpreter &interpreter,
- const char *platform_name,
- bool select,
- Error& error)
+PlatformOptionGroup::CreatePlatformWithOptions (CommandInterpreter &interpreter, bool select, Error& error)
{
- if (platform_name && platform_name[0])
+ PlatformSP platform_sp;
+ if (!platform_name.empty())
{
- if (platform_sp)
- {
- error.SetErrorString ("platform can't be set more than once in a command");
- return PlatformSP();
- }
-
- platform_sp = Platform::Create (platform_name, error);
+ platform_sp = Platform::Create (platform_name.c_str(), error);
if (platform_sp)
{
- interpreter.GetDebugger().GetPlatformList().Append (platform_sp, select);
- if (os_version_major != UINT32_MAX)
- {
- platform_sp->SetOSVersion (os_version_major,
- os_version_minor,
- os_version_update);
- }
+ interpreter.GetDebugger().GetPlatformList().Append (platform_sp, select);
+ if (os_version_major != UINT32_MAX)
+ {
+ platform_sp->SetOSVersion (os_version_major,
+ os_version_minor,
+ os_version_update);
+ }
}
}
- else
- {
- error.SetErrorString ("invalid platform name");
- platform_sp.reset();
- }
return platform_sp;
}
void
PlatformOptionGroup::OptionParsingStarting (CommandInterpreter &interpreter)
{
- platform_sp.reset();
+ platform_name.clear();
os_version_major = UINT32_MAX;
os_version_minor = UINT32_MAX;
os_version_update = UINT32_MAX;
@@ -75,7 +62,7 @@
static OptionDefinition
g_option_table[] =
{
- { LLDB_OPT_SET_ALL, false, "platform" , 'p', required_argument, NULL, 0, eArgTypeNone, "Specify name of the platform to use for this target, creating the platform if necessary."},
+ { 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."},
{ LLDB_OPT_SET_ALL, false, "sdk-version", 'v', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK version to use prior to connecting." }
};
@@ -112,19 +99,12 @@
switch (short_option)
{
case 'p':
- CreatePlatformWithOptions (interpreter, option_arg, true, error);
+ platform_name.assign (option_arg);
break;
case 'v':
if (Args::StringToVersion (option_arg, os_version_major, os_version_minor, os_version_update) == option_arg)
- {
error.SetErrorStringWithFormat ("invalid version string '%s'", option_arg);
- }
- else
- {
- if (platform_sp)
- platform_sp->SetOSVersion (os_version_major, os_version_minor, os_version_update);
- }
break;
default:
@@ -149,7 +129,7 @@
m_option_group (interpreter),
m_platform_options (false) // Don't include the "--platform" option by passing false
{
- m_option_group.Append (&m_platform_options);
+ m_option_group.Append (&m_platform_options, LLDB_OPT_SET_ALL, 1);
m_option_group.Finalize();
}
@@ -161,16 +141,31 @@
virtual bool
Execute (Args& args, CommandReturnObject &result)
{
- Error error;
if (args.GetArgumentCount() == 1)
{
- const bool select = true;
- PlatformSP platform_sp (m_platform_options.CreatePlatformWithOptions (m_interpreter,
- args.GetArgumentAtIndex (0),
- select,
- error));
- if (platform_sp)
- platform_sp->GetStatus (result.GetOutputStream());
+ const char *platform_name = args.GetArgumentAtIndex (0);
+ if (platform_name && platform_name[0])
+ {
+ const bool select = true;
+ m_platform_options.platform_name.assign (platform_name);
+ Error error;
+ PlatformSP platform_sp (m_platform_options.CreatePlatformWithOptions (m_interpreter, select, error));
+ if (platform_sp)
+ {
+ platform_sp->GetStatus (result.GetOutputStream());
+ result.SetStatus (eReturnStatusSuccessFinishResult);
+ }
+ else
+ {
+ result.AppendError(error.AsCString());
+ result.SetStatus (eReturnStatusFailed);
+ }
+ }
+ else
+ {
+ result.AppendError ("invalid platform name");
+ result.SetStatus (eReturnStatusFailed);
+ }
}
else
{
diff --git a/source/Commands/CommandObjectPlatform.h b/source/Commands/CommandObjectPlatform.h
index 255fc3b..0019915 100644
--- a/source/Commands/CommandObjectPlatform.h
+++ b/source/Commands/CommandObjectPlatform.h
@@ -49,11 +49,11 @@
public:
PlatformOptionGroup (bool include_platform_option) :
- m_include_platform_option (include_platform_option),
- platform_sp (),
+ platform_name (),
os_version_major (UINT32_MAX),
os_version_minor (UINT32_MAX),
- os_version_update (UINT32_MAX)
+ os_version_update (UINT32_MAX),
+ m_include_platform_option (include_platform_option)
{
}
@@ -74,17 +74,16 @@
const char *option_value);
lldb::PlatformSP
- CreatePlatformWithOptions (CommandInterpreter &interpreter,
- const char *platform_name,
- bool select,
- Error& error);
+ CreatePlatformWithOptions (CommandInterpreter &interpreter,
+ bool select,
+ Error &error);
virtual void
OptionParsingStarting (CommandInterpreter &interpreter);
// Instance variables to hold the values for command options.
- lldb::PlatformSP platform_sp;
+ std::string platform_name;
uint32_t os_version_major;
uint32_t os_version_minor;
uint32_t os_version_update;