[PATCH] D43048: [lldb-test/WIP] Allow a way to test autocompletion

Davide Italiano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 7 14:59:24 PST 2018


davide created this revision.
davide added reviewers: aprantl, vsk, friss, labath, zturner, jingham, jasonmolenda.

This is an experiment to improve out lldb testing capabilities and making them more similar to the one used in LLVM.

Example:

  davide at Davidinos-Mac-Pro ~/w/l/b/bin> ./lldb-test autocomplete "target cr"
  create
  davide at Davidinos-Mac-Pro ~/w/l/b/bin> ./lldb-test autocomplete "target "
  create
  delete
  list
  modules
  select
  stop-hook
  symbols
  variable

This allows the output to be FileCheck'ed, and has the advantage that it doesn't depend on python to be executed. It also removes a bunch of boilerplate the current autocompletion tests have.
Any feedback on this is appreciated, before I write the actual FileCheck tests.


https://reviews.llvm.org/D43048

Files:
  lldb/tools/lldb-test/lldb-test.cpp


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<std::string> Input(cl::Positional, cl::desc("input patterns"),
+                            cl::Required, cl::sub(AutoCompleteSubCommand));
+}
+
 namespace module {
 cl::opt<bool> SectionContents("contents",
                               cl::desc("Dump each section's contents"),
@@ -52,6 +59,22 @@
 
 static llvm::ManagedStatic<SystemLifetimeManager> 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43048.133318.patch
Type: text/x-patch
Size: 2484 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180207/6a01c95a/attachment-0001.bin>


More information about the llvm-commits mailing list