Index: lldb/tools/lldb-test/lldb-test.cpp =================================================================== --- lldb/tools/lldb-test/lldb-test.cpp +++ lldb/tools/lldb-test/lldb-test.cpp @@ -15,6 +15,7 @@ #include "lldb/Core/Module.h" #include "lldb/Core/Section.h" #include "lldb/Initialization/SystemLifetimeManager.h" +#include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/ClangASTImporter.h" #include "lldb/Utility/DataExtractor.h" @@ -32,10 +33,16 @@ using namespace llvm; namespace opts { +cl::SubCommand AutoCompleteSubCommand("autocomplete", "Test LLDB autocomplete"); cl::SubCommand ModuleSubcommand("module-sections", "Display LLDB Module Information"); cl::SubCommand SymbolsSubcommand("symbols", "Dump symbols for an object file"); +namespace autocomplete { +cl::list Input(cl::Positional, cl::desc("input patterns"), + cl::Required, cl::sub(AutoCompleteSubCommand)); +} + namespace module { cl::opt SectionContents("contents", cl::desc("Dump each section's contents"), @@ -52,6 +59,22 @@ static llvm::ManagedStatic DebuggerLifetime; +static void autocompleteCommand(Debugger &Dbg) { + assert(opts::autocomplete::Input.length() == 1 && "Incorret number of args"); + std::string InputStr = opts::autocomplete::Input[0]; + lldb_private::StringList Results; + CommandInterpreter &CI = Dbg.GetCommandInterpreter(); + unsigned Matches = CI.HandleCompletion( + InputStr.c_str(), InputStr.c_str() + InputStr.size(), + InputStr.c_str() + InputStr.size(), 0 /* match_start_point */, + -1 /* max_return_elements */, Results); + for (unsigned I = 1; I <= Matches; ++I) { + const char *Match = Results.GetStringAtIndex(I); + llvm::outs() << Match << "\n"; + llvm::outs().flush(); + } +} + static void dumpSymbols(Debugger &Dbg) { for (const auto &File : opts::symbols::InputFilenames) { ModuleSpec Spec{FileSpec(File, false)}; @@ -116,10 +139,13 @@ auto Dbg = lldb_private::Debugger::CreateInstance(); - if (opts::ModuleSubcommand) + if (opts::AutoCompleteSubCommand) { + autocompleteCommand(*Dbg); + } else if (opts::ModuleSubcommand) { dumpModules(*Dbg); - else if (opts::SymbolsSubcommand) + } else if (opts::SymbolsSubcommand) { dumpSymbols(*Dbg); + } DebuggerLifetime->Terminate(); return 0;