diff options
| author | Greg Clayton <gclayton@apple.com> | 2012-10-13 02:07:45 +0000 |
|---|---|---|
| committer | Greg Clayton <gclayton@apple.com> | 2012-10-13 02:07:45 +0000 |
| commit | 998255bfe841a4191d458a56aae0267f673b1a72 (patch) | |
| tree | ada5b24a203f1a24e041f9cce2188283d037de98 /lldb/source/Commands | |
| parent | 88db3171dd5dcc54e3890b6f823c60831fc520a5 (diff) | |
| download | bcm5719-llvm-998255bfe841a4191d458a56aae0267f673b1a72.tar.gz bcm5719-llvm-998255bfe841a4191d458a56aae0267f673b1a72.zip | |
<rdar://problem/12491387>
I added the ability for a process plug-in to implement custom commands. All the lldb_private::Process plug-in has to do is override:
virtual CommandObject *
GetPluginCommandObject();
This object returned should be a multi-word command that vends LLDB commands. There is a sample implementation in ProcessGDBRemote that is hollowed out. It is intended to be used for sending a custom packet, though the body of the command execute function has yet to be implemented!
llvm-svn: 165861
Diffstat (limited to 'lldb/source/Commands')
| -rw-r--r-- | lldb/source/Commands/CommandObjectCommands.cpp | 3 | ||||
| -rw-r--r-- | lldb/source/Commands/CommandObjectHelp.cpp | 5 | ||||
| -rw-r--r-- | lldb/source/Commands/CommandObjectMultiword.cpp | 229 | ||||
| -rw-r--r-- | lldb/source/Commands/CommandObjectProcess.cpp | 35 | ||||
| -rw-r--r-- | lldb/source/Commands/CommandObjectSyntax.cpp | 8 |
5 files changed, 269 insertions, 11 deletions
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp index 364c6f52c23..4c41d313c4f 100644 --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -599,8 +599,7 @@ protected: { const std::string sub_command = args.GetArgumentAtIndex(0); assert (sub_command.length() != 0); - subcommand_obj_sp = - (((CommandObjectMultiword *) cmd_obj)->GetSubcommandSP (sub_command.c_str())); + subcommand_obj_sp = cmd_obj->GetSubcommandSP (sub_command.c_str()); if (subcommand_obj_sp.get()) { sub_cmd_obj = subcommand_obj_sp.get(); diff --git a/lldb/source/Commands/CommandObjectHelp.cpp b/lldb/source/Commands/CommandObjectHelp.cpp index 5dfb105b841..3879005af3e 100644 --- a/lldb/source/Commands/CommandObjectHelp.cpp +++ b/lldb/source/Commands/CommandObjectHelp.cpp @@ -103,8 +103,7 @@ CommandObjectHelp::DoExecute (Args& command, CommandReturnObject &result) else { CommandObject *found_cmd; - found_cmd = ((CommandObjectMultiword *) sub_cmd_obj)->GetSubcommandObject(sub_command.c_str(), - &matches); + found_cmd = sub_cmd_obj->GetSubcommandObject(sub_command.c_str(), &matches); if (found_cmd == NULL) all_okay = false; else if (matches.GetSize() > 1) @@ -189,7 +188,7 @@ CommandObjectHelp::DoExecute (Args& command, CommandReturnObject &result) } else m_interpreter.OutputFormattedHelpText (output_strm, "", "", sub_cmd_obj->GetHelp(), 1); - ((CommandObjectMultiword *) sub_cmd_obj)->GenerateHelpText (result); + sub_cmd_obj->GenerateHelpText (result); } else { diff --git a/lldb/source/Commands/CommandObjectMultiword.cpp b/lldb/source/Commands/CommandObjectMultiword.cpp index e11d37bb77d..9fcd40fe6af 100644 --- a/lldb/source/Commands/CommandObjectMultiword.cpp +++ b/lldb/source/Commands/CommandObjectMultiword.cpp @@ -307,3 +307,232 @@ CommandObjectMultiword::GetRepeatCommand (Args ¤t_command_args, uint32_t i return sub_command_object->GetRepeatCommand(current_command_args, index); } + +void +CommandObjectMultiword::AproposAllSubCommands (const char *prefix, + const char *search_word, + StringList &commands_found, + StringList &commands_help) +{ + CommandObject::CommandMap::const_iterator pos; + + for (pos = m_subcommand_dict.begin(); pos != m_subcommand_dict.end(); ++pos) + { + const char * command_name = pos->first.c_str(); + CommandObject *sub_cmd_obj = pos->second.get(); + StreamString complete_command_name; + + complete_command_name.Printf ("%s %s", prefix, command_name); + + if (sub_cmd_obj->HelpTextContainsWord (search_word)) + { + commands_found.AppendString (complete_command_name.GetData()); + commands_help.AppendString (sub_cmd_obj->GetHelp()); + } + + if (sub_cmd_obj->IsMultiwordObject()) + sub_cmd_obj->AproposAllSubCommands (complete_command_name.GetData(), + search_word, + commands_found, + commands_help); + } +} + + + +CommandObjectProxy::CommandObjectProxy (CommandInterpreter &interpreter, + const char *name, + const char *help, + const char *syntax, + uint32_t flags) : + CommandObject (interpreter, name, help, syntax, flags) +{ +} + +CommandObjectProxy::~CommandObjectProxy () +{ +} + +const char * +CommandObjectProxy::GetHelpLong () +{ + CommandObject *proxy_command = GetProxyCommandObject(); + if (proxy_command) + return proxy_command->GetHelpLong(); + return NULL; +} + +void +CommandObjectProxy::AddObject (const char *obj_name) +{ + CommandObject *proxy_command = GetProxyCommandObject(); + if (proxy_command) + return proxy_command->AddObject (obj_name); +} + +bool +CommandObjectProxy::IsCrossRefObject () +{ + CommandObject *proxy_command = GetProxyCommandObject(); + if (proxy_command) + return proxy_command->IsCrossRefObject(); + return false; +} + +bool +CommandObjectProxy::IsRemovable() const +{ + const CommandObject *proxy_command = const_cast<CommandObjectProxy *>(this)->GetProxyCommandObject(); + if (proxy_command) + return proxy_command->IsRemovable(); + return false; +} + +bool +CommandObjectProxy::IsMultiwordObject () +{ + CommandObject *proxy_command = GetProxyCommandObject(); + if (proxy_command) + return proxy_command->IsMultiwordObject(); + return false; +} + +lldb::CommandObjectSP +CommandObjectProxy::GetSubcommandSP (const char *sub_cmd, StringList *matches) +{ + CommandObject *proxy_command = GetProxyCommandObject(); + if (proxy_command) + return proxy_command->GetSubcommandSP(sub_cmd, matches); + return lldb::CommandObjectSP(); +} + +CommandObject * +CommandObjectProxy::GetSubcommandObject (const char *sub_cmd, StringList *matches) +{ + CommandObject *proxy_command = GetProxyCommandObject(); + if (proxy_command) + return proxy_command->GetSubcommandObject(sub_cmd, matches); + return NULL; +} + +void +CommandObjectProxy::AproposAllSubCommands (const char *prefix, + const char *search_word, + StringList &commands_found, + StringList &commands_help) +{ + CommandObject *proxy_command = GetProxyCommandObject(); + if (proxy_command) + return proxy_command->AproposAllSubCommands (prefix, + search_word, + commands_found, + commands_help); +} + +bool +CommandObjectProxy::LoadSubCommand (const char *cmd_name, + const lldb::CommandObjectSP& command_sp) +{ + CommandObject *proxy_command = GetProxyCommandObject(); + if (proxy_command) + return proxy_command->LoadSubCommand (cmd_name, command_sp); + return false; +} + +bool +CommandObjectProxy::WantsRawCommandString() +{ + CommandObject *proxy_command = GetProxyCommandObject(); + if (proxy_command) + return proxy_command->WantsRawCommandString(); + return false; +} + +bool +CommandObjectProxy::WantsCompletion() +{ + CommandObject *proxy_command = GetProxyCommandObject(); + if (proxy_command) + return proxy_command->WantsCompletion(); + return false; +} + + +Options * +CommandObjectProxy::GetOptions () +{ + CommandObject *proxy_command = GetProxyCommandObject(); + if (proxy_command) + return proxy_command->GetOptions (); + return NULL; +} + + +int +CommandObjectProxy::HandleCompletion (Args &input, + int &cursor_index, + int &cursor_char_position, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches) +{ + CommandObject *proxy_command = GetProxyCommandObject(); + if (proxy_command) + return proxy_command->HandleCompletion (input, + cursor_index, + cursor_char_position, + match_start_point, + max_return_elements, + word_complete, + matches); + matches.Clear(); + return 0; +} +int +CommandObjectProxy::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) +{ + CommandObject *proxy_command = GetProxyCommandObject(); + if (proxy_command) + return proxy_command->HandleArgumentCompletion (input, + cursor_index, + cursor_char_position, + opt_element_vector, + match_start_point, + max_return_elements, + word_complete, + matches); + matches.Clear(); + return 0; +} + +const char * +CommandObjectProxy::GetRepeatCommand (Args ¤t_command_args, + uint32_t index) +{ + CommandObject *proxy_command = GetProxyCommandObject(); + if (proxy_command) + return proxy_command->GetRepeatCommand (current_command_args, index); + return NULL; +} + +bool +CommandObjectProxy::Execute (const char *args_string, + CommandReturnObject &result) +{ + CommandObject *proxy_command = GetProxyCommandObject(); + if (proxy_command) + return proxy_command->Execute (args_string, result); + result.AppendError ("command is not implemented"); + result.SetStatus (eReturnStatusFailed); + return false; +} + + diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index 5653e7a724e..41e216ec6cb 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -1071,7 +1071,6 @@ protected: CommandOptions m_options; }; - OptionDefinition CommandObjectProcessConnect::CommandOptions::g_option_table[] = { @@ -1080,6 +1079,39 @@ CommandObjectProcessConnect::CommandOptions::g_option_table[] = }; //------------------------------------------------------------------------- +// CommandObjectProcessPlugin +//------------------------------------------------------------------------- +#pragma mark CommandObjectProcessPlugin + +class CommandObjectProcessPlugin : public CommandObjectProxy +{ +public: + + CommandObjectProcessPlugin (CommandInterpreter &interpreter) : + CommandObjectProxy (interpreter, + "process plugin", + "Send a custom command to the current process plug-in.", + "process plugin <args>", + 0) + { + } + + ~CommandObjectProcessPlugin () + { + } + + virtual CommandObject * + GetProxyCommandObject() + { + Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); + if (process) + return process->GetPluginCommandObject(); + return NULL; + } +}; + + +//------------------------------------------------------------------------- // CommandObjectProcessLoad //------------------------------------------------------------------------- #pragma mark CommandObjectProcessLoad @@ -1794,6 +1826,7 @@ CommandObjectMultiwordProcess::CommandObjectMultiwordProcess (CommandInterpreter LoadSubCommand ("status", CommandObjectSP (new CommandObjectProcessStatus (interpreter))); LoadSubCommand ("interrupt", CommandObjectSP (new CommandObjectProcessInterrupt (interpreter))); LoadSubCommand ("kill", CommandObjectSP (new CommandObjectProcessKill (interpreter))); + LoadSubCommand ("plugin", CommandObjectSP (new CommandObjectProcessPlugin (interpreter))); } CommandObjectMultiwordProcess::~CommandObjectMultiwordProcess () diff --git a/lldb/source/Commands/CommandObjectSyntax.cpp b/lldb/source/Commands/CommandObjectSyntax.cpp index d96542ee9cd..64308aac5e5 100644 --- a/lldb/source/Commands/CommandObjectSyntax.cpp +++ b/lldb/source/Commands/CommandObjectSyntax.cpp @@ -66,14 +66,12 @@ CommandObjectSyntax::DoExecute (Args& command, CommandReturnObject &result) for (int i = 1; i < argc; ++i) { std::string sub_command = command.GetArgumentAtIndex (i); - if (! cmd_obj->IsMultiwordObject()) + if (!cmd_obj->IsMultiwordObject()) all_okay = false; else { - pos = ((CommandObjectMultiword *) cmd_obj)->m_subcommand_dict.find (sub_command); - if (pos != ((CommandObjectMultiword *) cmd_obj)->m_subcommand_dict.end()) - cmd_obj = pos->second.get(); - else + cmd_obj = cmd_obj->GetSubcommandObject(sub_command.c_str()); + if (!cmd_obj) all_okay = false; } } |

