asmith updated this revision to Diff 128069.
asmith retitled this revision from "[lldb] Fix crash when parsing the type of a
function without any arguments" to "Fix crash when parsing the type of a
function without any arguments".
asmith edited the summary of this revision.
Repository:
rL LLVM
https://reviews.llvm.org/D41427
Files:
source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
unittests/SymbolFile/PDB/Inputs/test-pdb-types.cpp
unittests/SymbolFile/PDB/Inputs/test-pdb-types.exe
unittests/SymbolFile/PDB/Inputs/test-pdb-types.pdb
unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp
Index: unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp
===================================================================
--- unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp
+++ unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp
@@ -484,7 +484,10 @@
llvm::DenseSet<SymbolFile *> searched_files;
TypeMap results;
- const char *TypedefsToCheck[] = {"ClassTypedef", "NSClassTypedef"};
+ const char *TypedefsToCheck[] = {
+ "ClassTypedef", "NSClassTypedef",
+ "FuncPointerTypedef", "VariadicFuncPointerTypedef"
+ };
for (auto Typedef : TypedefsToCheck) {
TypeMap results;
EXPECT_EQ(1u, symfile->FindTypes(sc, ConstString(Typedef), nullptr, false,
Index: unittests/SymbolFile/PDB/Inputs/test-pdb-types.cpp
===================================================================
--- unittests/SymbolFile/PDB/Inputs/test-pdb-types.cpp
+++ unittests/SymbolFile/PDB/Inputs/test-pdb-types.cpp
@@ -48,6 +48,10 @@
typedef Class ClassTypedef;
typedef NS::NSClass NSClassTypedef;
+typedef int(*FuncPointerTypedef)();
+typedef int(*VariadicFuncPointerTypedef)(char,...);
+FuncPointerTypedef GlobalFunc;
+VariadicFuncPointerTypedef GlobalVariadicFunc;
int GlobalArray[10];
static const int sizeof_NSClass = sizeof(NS::NSClass);
@@ -57,6 +61,8 @@
static const int sizeof_ShortEnum = sizeof(ShortEnum);
static const int sizeof_ClassTypedef = sizeof(ClassTypedef);
static const int sizeof_NSClassTypedef = sizeof(NSClassTypedef);
+static const int sizeof_FuncPointerTypedef = sizeof(FuncPointerTypedef);
+static const int sizeof_VariadicFuncPointerTypedef = sizeof(VariadicFuncPointerTypedef);
static const int sizeof_GlobalArray = sizeof(GlobalArray);
int main(int argc, char **argv) {
Index: source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
===================================================================
--- source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
+++ source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
@@ -26,12 +26,12 @@
#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
+#include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
using namespace lldb;
using namespace lldb_private;
-using namespace llvm;
using namespace llvm::pdb;
namespace {
@@ -141,8 +141,14 @@
} else if (auto func_sig = llvm::dyn_cast<PDBSymbolTypeFunctionSig>(&type)) {
auto arg_enum = func_sig->getArguments();
uint32_t num_args = arg_enum->getChildCount();
+ bool is_variadic = false;
std::vector<CompilerType> arg_list;
while (auto arg = arg_enum->getNext()) {
+ if (arg->getSymTag() == PDB_SymType::BuiltinType &&
+ arg->getRawSymbol().getLength() == 0) {
+ is_variadic = true;
+ continue;
+ }
lldb_private::Type *arg_type =
m_ast.GetSymbolFile()->ResolveTypeUID(arg->getSymIndexId());
// If there's some error looking up one of the dependent types of this
@@ -168,7 +174,8 @@
if (func_sig->isVolatileType())
type_quals |= clang::Qualifiers::Volatile;
CompilerType func_sig_ast_type = m_ast.CreateFunctionType(
- return_ast_type, arg_list.data(), arg_list.size(), false, type_quals);
+ return_ast_type, arg_list.data(), arg_list.size(), is_variadic,
+ type_quals);
return std::make_shared<lldb_private::Type>(
func_sig->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(), 0,
@@ -188,6 +195,35 @@
array_type->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(),
bytes, nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID,
decl, array_ast_type, lldb_private::Type::eResolveStateFull);
+ } else if (auto *builtin_type = llvm::dyn_cast<PDBSymbolTypeBuiltin>(&type)) {
+ uint64_t bytes = builtin_type->getLength();
+ PDB_BuiltinType pdb_builtin = builtin_type->getBuiltinType();
+ Encoding encoding = TranslateBuiltinEncoding(pdb_builtin);
+
+ // A 'void' builtin type has zero byte and invalid encoding type.
+ if (bytes || encoding != eEncodingInvalid ||
+ pdb_builtin == PDB_BuiltinType::Void) {
+ CompilerType builtin_ast_type =
+ m_ast.GetBuiltinTypeForEncodingAndBitSize(encoding, bytes * 8);
+
+ return std::make_shared<lldb_private::Type>(
+ builtin_type->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(),
+ bytes, nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID,
+ decl, builtin_ast_type, lldb_private::Type::eResolveStateFull);
+ }
+ } else if (auto *pointer_type = llvm::dyn_cast<PDBSymbolTypePointer>(&type)) {
+ Type *pointee_type = m_ast.GetSymbolFile()->ResolveTypeUID(
+ pointer_type->getPointeeType()->getSymIndexId());
+ if (!pointee_type)
+ return nullptr;
+
+ CompilerType pointer_ast_type =
+ pointee_type->GetFullCompilerType().GetPointerType();
+ return std::make_shared<lldb_private::Type>(
+ pointer_type->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(),
+ pointer_type->getLength(), nullptr, LLDB_INVALID_UID,
+ lldb_private::Type::eEncodingIsPointerUID, decl, pointer_ast_type,
+ lldb_private::Type::eResolveStateFull);
}
return nullptr;
}
_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits