[Lldb-commits] [lldb] r369407 - Make the FindTypes(std::vector<CompilerContext>, ...) API testable in lldb-test

Adrian Prantl via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 20 09:44:25 PDT 2019


Author: adrian
Date: Tue Aug 20 09:44:25 2019
New Revision: 369407

URL: http://llvm.org/viewvc/llvm-project?rev=369407&view=rev
Log:
Make the FindTypes(std::vector<CompilerContext>, ...) API testable in lldb-test

This adds a -compiler-context=<...> option to lldb-test that trakes a
comma-separated string that is a list of kind/name pairs and
translates it into a std::vector<CompilerContext>, a CompilerContext
being a pair of context-kind and name.

Differential Revision: https://reviews.llvm.org/D66453

<rdar://problem/54471165>

Added:
    lldb/trunk/lit/SymbolFile/DWARF/compilercontext.ll
Modified:
    lldb/trunk/lit/SymbolFile/DWARF/lit.local.cfg
    lldb/trunk/tools/lldb-test/lldb-test.cpp

Added: lldb/trunk/lit/SymbolFile/DWARF/compilercontext.ll
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/DWARF/compilercontext.ll?rev=369407&view=auto
==============================================================================
--- lldb/trunk/lit/SymbolFile/DWARF/compilercontext.ll (added)
+++ lldb/trunk/lit/SymbolFile/DWARF/compilercontext.ll Tue Aug 20 09:44:25 2019
@@ -0,0 +1,35 @@
+; Test finding types by CompilerContext.
+; RUN: llc %s -filetype=obj -o %t.o
+; RUN: lldb-test symbols %t.o -find=type -compiler-context="Module:CModule,Module:SubModule,Structure:FromSubmodule" | FileCheck %s
+;
+;
+; CHECK: Found 1 types:
+; CHECK: struct FromSubmodule {
+; CHECK-NEXT:     unsigned int x;
+; CHECK-NEXT:     unsigned int y;
+; CHECK-NEXT:     unsigned int z;
+; CHECK-NEXT: }
+
+source_filename = "/t.c"
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.14.0"
+
+!llvm.dbg.cu = !{!2}
+!llvm.linker.options = !{}
+!llvm.module.flags = !{!18, !19}
+!llvm.ident = !{!22}
+
+; This simulates the debug info for a Clang module.
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, nameTableKind: GNU, retainedTypes: !{!11})
+!3 = !DIFile(filename: "t.c", directory: "/")
+!8 = !DIModule(scope: !9, name: "SubModule", includePath: "", isysroot: "/")
+!9 = !DIModule(scope: null, name: "CModule", includePath: "", isysroot: "/")
+!11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "FromSubmodule", scope: !8, file: !3, line: 1, size: 96, elements: !13)
+!13 = !{!14, !16, !17}
+!14 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !11, file: !3, line: 2, baseType: !15, size: 32)
+!15 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
+!16 = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: !11, file: !3, line: 2, baseType: !15, size: 32, offset: 32)
+!17 = !DIDerivedType(tag: DW_TAG_member, name: "z", scope: !11, file: !3, line: 2, baseType: !15, size: 32, offset: 64)
+!18 = !{i32 2, !"Dwarf Version", i32 4}
+!19 = !{i32 2, !"Debug Info Version", i32 3}
+!22 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project 056f1b5cc7c2133f0cb3e30e7f24808d321096d7)"}

Modified: lldb/trunk/lit/SymbolFile/DWARF/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/DWARF/lit.local.cfg?rev=369407&r1=369406&r2=369407&view=diff
==============================================================================
--- lldb/trunk/lit/SymbolFile/DWARF/lit.local.cfg (original)
+++ lldb/trunk/lit/SymbolFile/DWARF/lit.local.cfg Tue Aug 20 09:44:25 2019
@@ -1 +1 @@
-config.suffixes = ['.cpp', '.s', '.test']
+config.suffixes = ['.cpp', '.s', '.test', '.ll']

Modified: lldb/trunk/tools/lldb-test/lldb-test.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-test/lldb-test.cpp?rev=369407&r1=369406&r2=369407&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-test/lldb-test.cpp (original)
+++ lldb/trunk/tools/lldb-test/lldb-test.cpp Tue Aug 20 09:44:25 2019
@@ -139,6 +139,11 @@ static cl::opt<std::string>
             cl::desc("Restrict search to the context of the given variable."),
             cl::value_desc("variable"), cl::sub(SymbolsSubcommand));
 
+static cl::opt<std::string> CompilerContext(
+    "compiler-context",
+    cl::desc("Specify a compiler context as \"kind:name,...\"."),
+    cl::value_desc("context"), cl::sub(SymbolsSubcommand));
+
 static cl::list<FunctionNameType> FunctionNameFlags(
     "function-flags", cl::desc("Function search flags:"),
     cl::values(clEnumValN(eFunctionNameTypeAuto, "auto",
@@ -220,6 +225,44 @@ int evaluateMemoryMapCommands(Debugger &
 
 } // namespace opts
 
+std::vector<CompilerContext> parseCompilerContext() {
+  std::vector<CompilerContext> result;
+  if (opts::symbols::CompilerContext.empty())
+    return result;
+
+  StringRef str{opts::symbols::CompilerContext};
+  SmallVector<StringRef, 8> entries_str;
+  str.split(entries_str, ',', /*maxSplit*/-1, /*keepEmpty=*/false);
+  for (auto entry_str : entries_str) {
+    StringRef key, value;
+    std::tie(key, value) = entry_str.split(':');
+    auto kind =
+        StringSwitch<CompilerContextKind>(key)
+            .Case("TranslationUnit", CompilerContextKind::TranslationUnit)
+            .Case("Module", CompilerContextKind::Module)
+            .Case("Namespace", CompilerContextKind::Namespace)
+            .Case("Class", CompilerContextKind::Class)
+            .Case("Structure", CompilerContextKind::Structure)
+            .Case("Union", CompilerContextKind::Union)
+            .Case("Function", CompilerContextKind::Function)
+            .Case("Variable", CompilerContextKind::Variable)
+            .Case("Enumeration", CompilerContextKind::Enumeration)
+            .Case("Typedef", CompilerContextKind::Typedef)
+            .Default(CompilerContextKind::Invalid);
+    if (value.empty()) {
+      WithColor::error() << "compiler context entry has no \"name\"\n";
+      exit(1);
+    }
+    result.push_back({kind, ConstString{value}});
+  }
+  outs() << "Search context: {\n";
+  for (auto entry: result)
+    entry.Dump();
+  outs() << "}\n";
+
+  return result;
+}
+
 template <typename... Args>
 static Error make_string_error(const char *Format, Args &&... args) {
   return llvm::make_error<llvm::StringError>(
@@ -464,8 +507,11 @@ Error opts::symbols::findTypes(lldb_priv
 
   DenseSet<SymbolFile *> SearchedFiles;
   TypeMap Map;
-  Symfile.FindTypes(ConstString(Name), ContextPtr, true, UINT32_MAX,
-                   SearchedFiles, Map);
+  if (!Name.empty())
+    Symfile.FindTypes(ConstString(Name), ContextPtr, true, UINT32_MAX,
+                      SearchedFiles, Map);
+  else
+    Symfile.FindTypes(parseCompilerContext(), true, Map);
 
   outs() << formatv("Found {0} types:\n", Map.GetSize());
   StreamString Stream;
@@ -679,6 +725,9 @@ Expected<Error (*)(lldb_private::Module
     if (Regex || !File.empty() || Line != 0)
       return make_string_error("Cannot search for types using regular "
                                "expressions, file names or line numbers.");
+    if (!Name.empty() && !CompilerContext.empty())
+      return make_string_error("Name is ignored if compiler context present.");
+
     return findTypes;
 
   case FindType::Variable:




More information about the lldb-commits mailing list