summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksandr Urakov <aleksandr.urakov@jetbrains.com>2019-01-29 09:32:23 +0000
committerAleksandr Urakov <aleksandr.urakov@jetbrains.com>2019-01-29 09:32:23 +0000
commitee7c61f10eb68b72405c7783945395f89d20d8e5 (patch)
treea76f82ef2383bcd3fd8a57c0ce3877a861c1ca84
parent015f97db8b34d48af22ac7f7f49df2a2635f677e (diff)
downloadbcm5719-llvm-ee7c61f10eb68b72405c7783945395f89d20d8e5.tar.gz
bcm5719-llvm-ee7c61f10eb68b72405c7783945395f89d20d8e5.zip
[NativePDB] Add basic support of methods recostruction in AST
Summary: This patch adds the basic support of methods reconstruction by native PDB plugin. It contains only most obvious changes (it processes LF_ONEMETHOD and LF_METHOD records), some things still remain unsolved: - mangled names retrieving; - support of template methods. Reviewers: zturner, labath, lemo, stella.stamenova Reviewed by: zturner Differential Revision: https://reviews.llvm.org/D56126 llvm-svn: 352464
-rw-r--r--lldb/lit/SymbolFile/NativePDB/Inputs/ast-methods.lldbinit5
-rw-r--r--lldb/lit/SymbolFile/NativePDB/ast-methods.cpp36
-rw-r--r--lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp20
-rw-r--r--lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h3
-rw-r--r--lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp32
-rw-r--r--lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.h4
6 files changed, 93 insertions, 7 deletions
diff --git a/lldb/lit/SymbolFile/NativePDB/Inputs/ast-methods.lldbinit b/lldb/lit/SymbolFile/NativePDB/Inputs/ast-methods.lldbinit
new file mode 100644
index 00000000000..6d593589c4a
--- /dev/null
+++ b/lldb/lit/SymbolFile/NativePDB/Inputs/ast-methods.lldbinit
@@ -0,0 +1,5 @@
+target variable s
+
+target modules dump ast
+
+quit
diff --git a/lldb/lit/SymbolFile/NativePDB/ast-methods.cpp b/lldb/lit/SymbolFile/NativePDB/ast-methods.cpp
new file mode 100644
index 00000000000..6006c722cfb
--- /dev/null
+++ b/lldb/lit/SymbolFile/NativePDB/ast-methods.cpp
@@ -0,0 +1,36 @@
+// clang-format off
+// REQUIRES: lld
+
+// RUN: %build --compiler=clang-cl --nodefaultlib -o %t.exe -- %s
+// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \
+// RUN: %p/Inputs/ast-methods.lldbinit 2>&1 | FileCheck %s
+
+struct Struct {
+ void simple_method() {}
+
+ virtual void virtual_method() {}
+
+ static void static_method() {}
+
+ int overloaded_method() {}
+ int overloaded_method(char c) {}
+ int overloaded_method(char c, int i, ...) {}
+};
+
+Struct s;
+
+int main(int argc, char **argv) {
+ return 0;
+}
+
+// CHECK: TranslationUnitDecl
+// CHECK: |-CXXRecordDecl {{.*}} struct Struct definition
+// CHECK: | |-CXXMethodDecl {{.*}} simple_method 'void (){{.*}}'
+// CHECK: | |-CXXMethodDecl {{.*}} virtual_method 'void (){{.*}}' virtual
+// CHECK: | |-CXXMethodDecl {{.*}} static_method 'void ()' static
+// CHECK: | |-CXXMethodDecl {{.*}} overloaded_method 'int (){{.*}}'
+// CHECK: | |-CXXMethodDecl {{.*}} overloaded_method 'int (char){{.*}}'
+// CHECK: | | `-ParmVarDecl {{.*}} 'char'
+// CHECK: | `-CXXMethodDecl {{.*}} overloaded_method 'int (char, int, ...)'
+// CHECK: | |-ParmVarDecl {{.*}} 'char'
+// CHECK: | `-ParmVarDecl {{.*}} 'int'
diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
index 8917fd09238..6e5640c1ea0 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
@@ -933,7 +933,14 @@ clang::QualType PdbAstBuilder::CreateType(PdbTypeSymId type) {
if (cvt.kind() == LF_PROCEDURE) {
ProcedureRecord pr;
llvm::cantFail(TypeDeserializer::deserializeAs<ProcedureRecord>(cvt, pr));
- return CreateProcedureType(pr);
+ return CreateFunctionType(pr.ArgumentList, pr.ReturnType, pr.CallConv);
+ }
+
+ if (cvt.kind() == LF_MFUNCTION) {
+ MemberFunctionRecord mfr;
+ llvm::cantFail(
+ TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, mfr));
+ return CreateFunctionType(mfr.ArgumentList, mfr.ReturnType, mfr.CallConv);
}
return {};
@@ -1117,10 +1124,11 @@ clang::QualType PdbAstBuilder::CreateArrayType(const ArrayRecord &ar) {
return clang::QualType::getFromOpaquePtr(array_ct.GetOpaqueQualType());
}
-clang::QualType
-PdbAstBuilder::CreateProcedureType(const ProcedureRecord &proc) {
+clang::QualType PdbAstBuilder::CreateFunctionType(
+ TypeIndex args_type_idx, TypeIndex return_type_idx,
+ llvm::codeview::CallingConvention calling_convention) {
TpiStream &stream = m_index.tpi();
- CVType args_cvt = stream.getType(proc.ArgumentList);
+ CVType args_cvt = stream.getType(args_type_idx);
ArgListRecord args;
llvm::cantFail(
TypeDeserializer::deserializeAs<ArgListRecord>(args_cvt, args));
@@ -1138,10 +1146,10 @@ PdbAstBuilder::CreateProcedureType(const ProcedureRecord &proc) {
arg_types.push_back(ToCompilerType(arg_type));
}
- clang::QualType return_type = GetOrCreateType(proc.ReturnType);
+ clang::QualType return_type = GetOrCreateType(return_type_idx);
llvm::Optional<clang::CallingConv> cc =
- TranslateCallingConvention(proc.CallConv);
+ TranslateCallingConvention(calling_convention);
if (!cc)
return {};
diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h
index e3bcc9ae826..761d11bf273 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h
@@ -102,7 +102,8 @@ private:
clang::QualType CreateEnumType(PdbTypeSymId id,
const llvm::codeview::EnumRecord &record);
clang::QualType
- CreateProcedureType(const llvm::codeview::ProcedureRecord &proc);
+ CreateFunctionType(TypeIndex args_type_idx, TypeIndex return_type_idx,
+ llvm::codeview::CallingConvention calling_convention);
clang::QualType CreateType(PdbTypeSymId type);
void CreateFunctionParameters(PdbCompilandSymId func_id,
diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
index 239dfbee625..37be3bc9cdf 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
@@ -65,6 +65,22 @@ clang::QualType UdtRecordCompleter::AddBaseClassForTypeIndex(
return qt;
}
+void UdtRecordCompleter::AddMethod(llvm::StringRef name, TypeIndex type_idx,
+ MemberAccess access, MethodOptions options,
+ MemberAttributes attrs) {
+ clang::QualType method_qt =
+ m_ast_builder.GetOrCreateType(PdbTypeSymId(type_idx));
+ m_ast_builder.CompleteType(method_qt);
+
+ lldb::AccessType access_type = TranslateMemberAccess(access);
+ bool is_artificial = (options & MethodOptions::CompilerGenerated) ==
+ MethodOptions::CompilerGenerated;
+ m_ast_builder.clang().AddMethodToCXXRecordType(
+ m_derived_ct.GetOpaqueQualType(), name.data(), nullptr,
+ m_ast_builder.ToCompilerType(method_qt), access_type, attrs.isVirtual(),
+ attrs.isStatic(), false, false, false, is_artificial);
+}
+
Error UdtRecordCompleter::visitKnownMember(CVMemberRecord &cvr,
BaseClassRecord &base) {
clang::QualType base_qt =
@@ -158,11 +174,27 @@ Error UdtRecordCompleter::visitKnownMember(CVMemberRecord &cvr,
Error UdtRecordCompleter::visitKnownMember(CVMemberRecord &cvr,
OneMethodRecord &one_method) {
+ AddMethod(one_method.Name, one_method.Type, one_method.getAccess(),
+ one_method.getOptions(), one_method.Attrs);
+
return Error::success();
}
Error UdtRecordCompleter::visitKnownMember(CVMemberRecord &cvr,
OverloadedMethodRecord &overloaded) {
+ TypeIndex method_list_idx = overloaded.MethodList;
+
+ CVType method_list_type = m_tpi.getType(method_list_idx);
+ assert(method_list_type.Type == LF_METHODLIST);
+
+ MethodOverloadListRecord method_list;
+ llvm::cantFail(TypeDeserializer::deserializeAs<MethodOverloadListRecord>(
+ method_list_type, method_list));
+
+ for (const OneMethodRecord &method : method_list.Methods)
+ AddMethod(overloaded.Name, method.Type, method.getAccess(),
+ method.getOptions(), method.Attrs);
+
return Error::success();
}
diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.h b/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.h
index 934b218aca6..43015f9e25b 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.h
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.h
@@ -66,6 +66,10 @@ public:
private:
clang::QualType AddBaseClassForTypeIndex(llvm::codeview::TypeIndex ti,
llvm::codeview::MemberAccess access);
+ void AddMethod(llvm::StringRef name, llvm::codeview::TypeIndex type_idx,
+ llvm::codeview::MemberAccess access,
+ llvm::codeview::MethodOptions options,
+ llvm::codeview::MemberAttributes attrs);
};
} // namespace npdb
OpenPOWER on IntegriCloud