Skip to content
This repository was archived by the owner on Apr 2, 2020. It is now read-only.

Commit c1ab123

Browse files
committed
Merge remote-tracking branch 'llvm/master' into upstream-with-swift
2 parents 64c0406 + e8307fb commit c1ab123

File tree

3 files changed

+87
-3
lines changed

3 files changed

+87
-3
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; Test finding types by CompilerContext.
2+
; RUN: llc %s -filetype=obj -o %t.o
3+
; RUN: lldb-test symbols %t.o -find=type -compiler-context="Module:CModule,Module:SubModule,Structure:FromSubmodule" | FileCheck %s
4+
;
5+
;
6+
; CHECK: Found 1 types:
7+
; CHECK: struct FromSubmodule {
8+
; CHECK-NEXT: unsigned int x;
9+
; CHECK-NEXT: unsigned int y;
10+
; CHECK-NEXT: unsigned int z;
11+
; CHECK-NEXT: }
12+
13+
source_filename = "/t.c"
14+
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
15+
target triple = "x86_64-apple-macosx10.14.0"
16+
17+
!llvm.dbg.cu = !{!2}
18+
!llvm.linker.options = !{}
19+
!llvm.module.flags = !{!18, !19}
20+
!llvm.ident = !{!22}
21+
22+
; This simulates the debug info for a Clang module.
23+
!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, nameTableKind: GNU, retainedTypes: !{!11})
24+
!3 = !DIFile(filename: "t.c", directory: "/")
25+
!8 = !DIModule(scope: !9, name: "SubModule", includePath: "", isysroot: "/")
26+
!9 = !DIModule(scope: null, name: "CModule", includePath: "", isysroot: "/")
27+
!11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "FromSubmodule", scope: !8, file: !3, line: 1, size: 96, elements: !13)
28+
!13 = !{!14, !16, !17}
29+
!14 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !11, file: !3, line: 2, baseType: !15, size: 32)
30+
!15 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
31+
!16 = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: !11, file: !3, line: 2, baseType: !15, size: 32, offset: 32)
32+
!17 = !DIDerivedType(tag: DW_TAG_member, name: "z", scope: !11, file: !3, line: 2, baseType: !15, size: 32, offset: 64)
33+
!18 = !{i32 2, !"Dwarf Version", i32 4}
34+
!19 = !{i32 2, !"Debug Info Version", i32 3}
35+
!22 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project 056f1b5cc7c2133f0cb3e30e7f24808d321096d7)"}

lit/SymbolFile/DWARF/lit.local.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
config.suffixes = ['.cpp', '.s', '.test']
1+
config.suffixes = ['.cpp', '.s', '.test', '.ll']

tools/lldb-test/lldb-test.cpp

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ static cl::opt<std::string>
139139
cl::desc("Restrict search to the context of the given variable."),
140140
cl::value_desc("variable"), cl::sub(SymbolsSubcommand));
141141

142+
static cl::opt<std::string> CompilerContext(
143+
"compiler-context",
144+
cl::desc("Specify a compiler context as \"kind:name,...\"."),
145+
cl::value_desc("context"), cl::sub(SymbolsSubcommand));
146+
142147
static cl::list<FunctionNameType> FunctionNameFlags(
143148
"function-flags", cl::desc("Function search flags:"),
144149
cl::values(clEnumValN(eFunctionNameTypeAuto, "auto",
@@ -220,6 +225,44 @@ int evaluateMemoryMapCommands(Debugger &Dbg);
220225

221226
} // namespace opts
222227

228+
std::vector<CompilerContext> parseCompilerContext() {
229+
std::vector<CompilerContext> result;
230+
if (opts::symbols::CompilerContext.empty())
231+
return result;
232+
233+
StringRef str{opts::symbols::CompilerContext};
234+
SmallVector<StringRef, 8> entries_str;
235+
str.split(entries_str, ',', /*maxSplit*/-1, /*keepEmpty=*/false);
236+
for (auto entry_str : entries_str) {
237+
StringRef key, value;
238+
std::tie(key, value) = entry_str.split(':');
239+
auto kind =
240+
StringSwitch<CompilerContextKind>(key)
241+
.Case("TranslationUnit", CompilerContextKind::TranslationUnit)
242+
.Case("Module", CompilerContextKind::Module)
243+
.Case("Namespace", CompilerContextKind::Namespace)
244+
.Case("Class", CompilerContextKind::Class)
245+
.Case("Structure", CompilerContextKind::Structure)
246+
.Case("Union", CompilerContextKind::Union)
247+
.Case("Function", CompilerContextKind::Function)
248+
.Case("Variable", CompilerContextKind::Variable)
249+
.Case("Enumeration", CompilerContextKind::Enumeration)
250+
.Case("Typedef", CompilerContextKind::Typedef)
251+
.Default(CompilerContextKind::Invalid);
252+
if (value.empty()) {
253+
WithColor::error() << "compiler context entry has no \"name\"\n";
254+
exit(1);
255+
}
256+
result.push_back({kind, ConstString{value}});
257+
}
258+
outs() << "Search context: {\n";
259+
for (auto entry: result)
260+
entry.Dump();
261+
outs() << "}\n";
262+
263+
return result;
264+
}
265+
223266
template <typename... Args>
224267
static Error make_string_error(const char *Format, Args &&... args) {
225268
return llvm::make_error<llvm::StringError>(
@@ -464,8 +507,11 @@ Error opts::symbols::findTypes(lldb_private::Module &Module) {
464507

465508
DenseSet<SymbolFile *> SearchedFiles;
466509
TypeMap Map;
467-
Symfile.FindTypes(ConstString(Name), ContextPtr, true, UINT32_MAX,
468-
SearchedFiles, Map);
510+
if (!Name.empty())
511+
Symfile.FindTypes(ConstString(Name), ContextPtr, true, UINT32_MAX,
512+
SearchedFiles, Map);
513+
else
514+
Symfile.FindTypes(parseCompilerContext(), true, Map);
469515

470516
outs() << formatv("Found {0} types:\n", Map.GetSize());
471517
StreamString Stream;
@@ -679,6 +725,9 @@ Expected<Error (*)(lldb_private::Module &)> opts::symbols::getAction() {
679725
if (Regex || !File.empty() || Line != 0)
680726
return make_string_error("Cannot search for types using regular "
681727
"expressions, file names or line numbers.");
728+
if (!Name.empty() && !CompilerContext.empty())
729+
return make_string_error("Name is ignored if compiler context present.");
730+
682731
return findTypes;
683732

684733
case FindType::Variable:

0 commit comments

Comments
 (0)