diff options
author | Aleksandr Urakov <aleksandr.urakov@jetbrains.com> | 2018-09-26 09:03:34 +0000 |
---|---|---|
committer | Aleksandr Urakov <aleksandr.urakov@jetbrains.com> | 2018-09-26 09:03:34 +0000 |
commit | 5a2575abd5a0156faeae20646802b411b7ce3096 (patch) | |
tree | 3c0c3df25db6ca4ef7f66a0c8a7b2716fb13fb54 /lldb | |
parent | f4d4cf1709c3761ce8619155d3ec293bcea7c5dd (diff) |
[PDB] Restore the calling convention from PDB
Summary:
This patch implements restoring of the calling convention from PDB.
It is necessary for expressions evaluation, if we want to call a function
of the debuggee process with a calling convention other than ccall.
Reviewers: clayborg, zturner, labath, asmith
Reviewed By: clayborg
Subscribers: teemperor, lldb-commits, stella.stamenova
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D52501
Diffstat (limited to 'lldb')
-rw-r--r-- | lldb/include/lldb/Symbol/ClangASTContext.h | 21 | ||||
-rw-r--r-- | lldb/lit/SymbolFile/PDB/Inputs/CallingConventionsTest.cpp | 20 | ||||
-rw-r--r-- | lldb/lit/SymbolFile/PDB/calling-conventions.test | 11 | ||||
-rw-r--r-- | lldb/lit/SymbolFile/PDB/pointers.test | 2 | ||||
-rw-r--r-- | lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp | 23 | ||||
-rw-r--r-- | lldb/source/Symbol/ClangASTContext.cpp | 4 |
6 files changed, 77 insertions, 4 deletions
diff --git a/lldb/include/lldb/Symbol/ClangASTContext.h b/lldb/include/lldb/Symbol/ClangASTContext.h index abb64689286..1e13ba93f85 100644 --- a/lldb/include/lldb/Symbol/ClangASTContext.h +++ b/lldb/include/lldb/Symbol/ClangASTContext.h @@ -377,7 +377,17 @@ public: const CompilerType &result_type, const CompilerType *args, unsigned num_args, bool is_variadic, - unsigned type_quals); + unsigned type_quals, + clang::CallingConv cc); + + static CompilerType CreateFunctionType(clang::ASTContext *ast, + const CompilerType &result_type, + const CompilerType *args, + unsigned num_args, bool is_variadic, + unsigned type_quals) { + return ClangASTContext::CreateFunctionType( + ast, result_type, args, num_args, is_variadic, type_quals, clang::CC_C); + } CompilerType CreateFunctionType(const CompilerType &result_type, const CompilerType *args, unsigned num_args, @@ -386,6 +396,15 @@ public: getASTContext(), result_type, args, num_args, is_variadic, type_quals); } + CompilerType CreateFunctionType(const CompilerType &result_type, + const CompilerType *args, unsigned num_args, + bool is_variadic, unsigned type_quals, + clang::CallingConv cc) { + return ClangASTContext::CreateFunctionType(getASTContext(), result_type, + args, num_args, is_variadic, + type_quals, cc); + } + clang::ParmVarDecl *CreateParameterDeclaration(const char *name, const CompilerType ¶m_type, int storage); diff --git a/lldb/lit/SymbolFile/PDB/Inputs/CallingConventionsTest.cpp b/lldb/lit/SymbolFile/PDB/Inputs/CallingConventionsTest.cpp new file mode 100644 index 00000000000..60854c04c60 --- /dev/null +++ b/lldb/lit/SymbolFile/PDB/Inputs/CallingConventionsTest.cpp @@ -0,0 +1,20 @@ +int FuncCCall() { return 0; } +auto FuncCCallPtr = &FuncCCall; + +int __stdcall FuncStdCall() { return 0; } +auto FuncStdCallPtr = &FuncStdCall; + +int __fastcall FuncFastCall() { return 0; } +auto FuncFastCallPtr = &FuncFastCall; + +int __vectorcall FuncVectorCall() { return 0; } +auto FuncVectorCallPtr = &FuncVectorCall; + +struct S { + int FuncThisCall() { return 0; } +}; +auto FuncThisCallPtr = &S::FuncThisCall; + +int main() { + return 0; +} diff --git a/lldb/lit/SymbolFile/PDB/calling-conventions.test b/lldb/lit/SymbolFile/PDB/calling-conventions.test new file mode 100644 index 00000000000..cc1474945e1 --- /dev/null +++ b/lldb/lit/SymbolFile/PDB/calling-conventions.test @@ -0,0 +1,11 @@ +REQUIRES: windows, lld +RUN: clang-cl -m32 /Zi /GS- /c %S/Inputs/CallingConventionsTest.cpp /o %t.obj +RUN: lld-link /debug:full /nodefaultlib /entry:main %t.obj /out:%t.exe +RUN: lldb-test symbols -dump-ast %t.exe | FileCheck %s + +CHECK: Module: {{.*}} +CHECK-DAG: int (*FuncCCallPtr)(); +CHECK-DAG: int (*FuncStdCallPtr)() __attribute__((stdcall)); +CHECK-DAG: int (*FuncFastCallPtr)() __attribute__((fastcall)); +CHECK-DAG: int (*FuncVectorCallPtr)() __attribute__((vectorcall)); +CHECK-DAG: int (S::*FuncThisCallPtr)() __attribute__((thiscall)); diff --git a/lldb/lit/SymbolFile/PDB/pointers.test b/lldb/lit/SymbolFile/PDB/pointers.test index 3924989ab58..03e31c4ff3c 100644 --- a/lldb/lit/SymbolFile/PDB/pointers.test +++ b/lldb/lit/SymbolFile/PDB/pointers.test @@ -28,7 +28,7 @@ MAIN-SAME: (int *), scope = local MAIN: Variable{{.*}}, name = "p_member_field" MAIN-SAME: (int ST::*), scope = local MAIN: Variable{{.*}}, name = "p_member_method" -MAIN-SAME: (int (ST::*)(int)), scope = local +MAIN-SAME: (int (ST::*)(int) __attribute__((thiscall))), scope = local F: Function{[[FID2:.*]]}, demangled = {{.*}}f(int) F-NEXT: Block{[[FID2]]} diff --git a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp b/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp index a4c4459bf56..50076307001 100644 --- a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp +++ b/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp @@ -331,6 +331,26 @@ static bool IsAnonymousNamespaceName(const std::string &name) { return name == "`anonymous namespace'" || name == "`anonymous-namespace'"; } +static clang::CallingConv TranslateCallingConvention(PDB_CallingConv pdb_cc) { + switch (pdb_cc) { + case llvm::codeview::CallingConvention::NearC: + return clang::CC_C; + case llvm::codeview::CallingConvention::NearStdCall: + return clang::CC_X86StdCall; + case llvm::codeview::CallingConvention::NearFast: + return clang::CC_X86FastCall; + case llvm::codeview::CallingConvention::ThisCall: + return clang::CC_X86ThisCall; + case llvm::codeview::CallingConvention::NearVector: + return clang::CC_X86VectorCall; + case llvm::codeview::CallingConvention::NearPascal: + return clang::CC_X86Pascal; + default: + assert(false && "Unknown calling convention"); + return clang::CC_C; + } +} + PDBASTParser::PDBASTParser(lldb_private::ClangASTContext &ast) : m_ast(ast) {} PDBASTParser::~PDBASTParser() {} @@ -603,9 +623,10 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) { type_quals |= clang::Qualifiers::Const; if (func_sig->isVolatileType()) type_quals |= clang::Qualifiers::Volatile; + auto cc = TranslateCallingConvention(func_sig->getCallingConvention()); CompilerType func_sig_ast_type = m_ast.CreateFunctionType(return_ast_type, arg_list.data(), - arg_list.size(), is_variadic, type_quals); + arg_list.size(), is_variadic, type_quals, cc); GetDeclarationForSymbol(type, decl); return std::make_shared<lldb_private::Type>( diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp index 23e94884e37..fe47f29f18b 100644 --- a/lldb/source/Symbol/ClangASTContext.cpp +++ b/lldb/source/Symbol/ClangASTContext.cpp @@ -2058,7 +2058,8 @@ FunctionDecl *ClangASTContext::CreateFunctionDeclaration( CompilerType ClangASTContext::CreateFunctionType( ASTContext *ast, const CompilerType &result_type, const CompilerType *args, - unsigned num_args, bool is_variadic, unsigned type_quals) { + unsigned num_args, bool is_variadic, unsigned type_quals, + clang::CallingConv cc) { if (ast == nullptr) return CompilerType(); // invalid AST @@ -2086,6 +2087,7 @@ CompilerType ClangASTContext::CreateFunctionType( // TODO: Detect calling convention in DWARF? FunctionProtoType::ExtProtoInfo proto_info; + proto_info.ExtInfo = cc; proto_info.Variadic = is_variadic; proto_info.ExceptionSpec = EST_None; proto_info.TypeQuals = type_quals; |