[Lldb-commits] [lldb] [lldb] Remove SymbolFilePDB and make the native one the default (PR #113647)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Oct 24 20:52:20 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Jonas Devlieghere (JDevlieghere)
<details>
<summary>Changes</summary>
Remove `SymbolFilePDB` in favor of always using `SymbolFileNativePDB`. This effectively makes `LLDB_USE_NATIVE_PDB_READER` the default. The non-native (DIA based) PDB symbol file implementation was unmaintained and known to have issues.
---
Patch is 212.52 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/113647.diff
66 Files Affected:
- (modified) lldb/source/Plugins/SymbolFile/CMakeLists.txt (-1)
- (removed) lldb/source/Plugins/SymbolFile/PDB/CMakeLists.txt (-18)
- (removed) lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp (-1455)
- (removed) lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.h (-116)
- (removed) lldb/source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp (-182)
- (removed) lldb/source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.h (-47)
- (removed) lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp (-2053)
- (removed) lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h (-252)
- (modified) lldb/source/Plugins/TypeSystem/Clang/CMakeLists.txt (+1-1)
- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (-9)
- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h (-3)
- (modified) lldb/test/Shell/Minidump/Windows/Sigsegv/sigsegv.test (+1-1)
- (modified) lldb/test/Shell/Process/Windows/exception_access_violation.cpp (+2-2)
- (modified) lldb/test/Shell/Process/Windows/process_load.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/ast-functions-msvc.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/ast-functions.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/ast-methods.cpp (+2-2)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/ast-types.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/bitfields.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/blocks.s (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/break-by-function.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/break-by-line.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/class_layout.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/disassembly.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/function-types-builtins.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/function-types-calling-conv.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/function-types-classes.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/global-classes.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/global-ctor-dtor.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/globals-bss.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/globals-fundamental.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/icf.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/incomplete-tag-type.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/inline_sites.test (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/inline_sites_live.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/load-pdb.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/local-variables-registers.s (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/local-variables.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/locate-pdb.cpp (+2-2)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/lookup-by-address.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/lookup-by-types.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/nested-blocks-same-address.s (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/nested-types.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/s_constant.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/source-list.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/stack_unwinding01.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/tag-types.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/NativePDB/typedefs.cpp (+1-1)
- (modified) lldb/test/Shell/SymbolFile/PDB/ast-restore.test (+2-4)
- (modified) lldb/test/Shell/SymbolFile/PDB/compilands.test (+1-2)
- (modified) lldb/test/Shell/SymbolFile/PDB/function-level-linking.test (+1-2)
- (modified) lldb/test/Shell/SymbolFile/PDB/variables-locations.test (+1-2)
- (modified) lldb/unittests/SymbolFile/CMakeLists.txt (-3)
- (modified) lldb/unittests/SymbolFile/DWARF/CMakeLists.txt (-1)
- (modified) lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp (+1-4)
- (removed) lldb/unittests/SymbolFile/PDB/CMakeLists.txt (-25)
- (removed) lldb/unittests/SymbolFile/PDB/Inputs/test-pdb-alt.cpp (-7)
- (removed) lldb/unittests/SymbolFile/PDB/Inputs/test-pdb-nested.h (-6)
- (removed) lldb/unittests/SymbolFile/PDB/Inputs/test-pdb-types.cpp (-77)
- (removed) lldb/unittests/SymbolFile/PDB/Inputs/test-pdb-types.exe ()
- (removed) lldb/unittests/SymbolFile/PDB/Inputs/test-pdb-types.pdb ()
- (removed) lldb/unittests/SymbolFile/PDB/Inputs/test-pdb.cpp (-9)
- (removed) lldb/unittests/SymbolFile/PDB/Inputs/test-pdb.exe ()
- (removed) lldb/unittests/SymbolFile/PDB/Inputs/test-pdb.h (-10)
- (removed) lldb/unittests/SymbolFile/PDB/Inputs/test-pdb.pdb ()
- (removed) lldb/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp (-628)
``````````diff
diff --git a/lldb/source/Plugins/SymbolFile/CMakeLists.txt b/lldb/source/Plugins/SymbolFile/CMakeLists.txt
index 106387b45ec1a9..6b0a3901cc4b9e 100644
--- a/lldb/source/Plugins/SymbolFile/CMakeLists.txt
+++ b/lldb/source/Plugins/SymbolFile/CMakeLists.txt
@@ -3,5 +3,4 @@ add_subdirectory(CTF)
add_subdirectory(DWARF)
add_subdirectory(JSON)
add_subdirectory(NativePDB)
-add_subdirectory(PDB)
add_subdirectory(Symtab)
diff --git a/lldb/source/Plugins/SymbolFile/PDB/CMakeLists.txt b/lldb/source/Plugins/SymbolFile/PDB/CMakeLists.txt
deleted file mode 100644
index ceeb173a99e1d6..00000000000000
--- a/lldb/source/Plugins/SymbolFile/PDB/CMakeLists.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-add_lldb_library(lldbPluginSymbolFilePDB PLUGIN
- PDBASTParser.cpp
- PDBLocationToDWARFExpression.cpp
- SymbolFilePDB.cpp
-
- LINK_LIBS
- lldbCore
- lldbPluginSymbolFileNativePDB
- lldbSymbol
- lldbUtility
- lldbPluginTypeSystemClang
- CLANG_LIBS
- clangAST
- clangLex
- LINK_COMPONENTS
- DebugInfoPDB
- Support
- )
diff --git a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp b/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
deleted file mode 100644
index fa3530a0c22ff3..00000000000000
--- a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
+++ /dev/null
@@ -1,1455 +0,0 @@
-//===-- PDBASTParser.cpp --------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "PDBASTParser.h"
-
-#include "SymbolFilePDB.h"
-
-#include "clang/AST/CharUnits.h"
-#include "clang/AST/Decl.h"
-#include "clang/AST/DeclCXX.h"
-
-#include "Plugins/ExpressionParser/Clang/ClangASTMetadata.h"
-#include "Plugins/ExpressionParser/Clang/ClangUtil.h"
-#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
-#include "lldb/Core/Declaration.h"
-#include "lldb/Core/Module.h"
-#include "lldb/Symbol/SymbolFile.h"
-#include "lldb/Symbol/TypeMap.h"
-#include "lldb/Symbol/TypeSystem.h"
-#include "lldb/Utility/LLDBLog.h"
-#include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
-#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
-#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
-#include "llvm/DebugInfo/PDB/PDBSymbol.h"
-#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
-#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
-#include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h"
-#include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"
-#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
-#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"
-
-#include "Plugins/Language/CPlusPlus/MSVCUndecoratedNameParser.h"
-#include <optional>
-
-using namespace lldb;
-using namespace lldb_private;
-using namespace llvm::pdb;
-
-static int TranslateUdtKind(PDB_UdtType pdb_kind) {
- switch (pdb_kind) {
- case PDB_UdtType::Class:
- return llvm::to_underlying(clang::TagTypeKind::Class);
- case PDB_UdtType::Struct:
- return llvm::to_underlying(clang::TagTypeKind::Struct);
- case PDB_UdtType::Union:
- return llvm::to_underlying(clang::TagTypeKind::Union);
- case PDB_UdtType::Interface:
- return llvm::to_underlying(clang::TagTypeKind::Interface);
- }
- llvm_unreachable("unsuported PDB UDT type");
-}
-
-static lldb::Encoding TranslateBuiltinEncoding(PDB_BuiltinType type) {
- switch (type) {
- case PDB_BuiltinType::Float:
- return lldb::eEncodingIEEE754;
- case PDB_BuiltinType::Int:
- case PDB_BuiltinType::Long:
- case PDB_BuiltinType::Char:
- return lldb::eEncodingSint;
- case PDB_BuiltinType::Bool:
- case PDB_BuiltinType::Char16:
- case PDB_BuiltinType::Char32:
- case PDB_BuiltinType::UInt:
- case PDB_BuiltinType::ULong:
- case PDB_BuiltinType::HResult:
- case PDB_BuiltinType::WCharT:
- return lldb::eEncodingUint;
- default:
- return lldb::eEncodingInvalid;
- }
-}
-
-static lldb::Encoding TranslateEnumEncoding(PDB_VariantType type) {
- switch (type) {
- case PDB_VariantType::Int8:
- case PDB_VariantType::Int16:
- case PDB_VariantType::Int32:
- case PDB_VariantType::Int64:
- return lldb::eEncodingSint;
-
- case PDB_VariantType::UInt8:
- case PDB_VariantType::UInt16:
- case PDB_VariantType::UInt32:
- case PDB_VariantType::UInt64:
- return lldb::eEncodingUint;
-
- default:
- break;
- }
-
- return lldb::eEncodingSint;
-}
-
-static CompilerType
-GetBuiltinTypeForPDBEncodingAndBitSize(TypeSystemClang &clang_ast,
- const PDBSymbolTypeBuiltin &pdb_type,
- Encoding encoding, uint32_t width) {
- clang::ASTContext &ast = clang_ast.getASTContext();
-
- switch (pdb_type.getBuiltinType()) {
- default:
- break;
- case PDB_BuiltinType::None:
- return CompilerType();
- case PDB_BuiltinType::Void:
- return clang_ast.GetBasicType(eBasicTypeVoid);
- case PDB_BuiltinType::Char:
- return clang_ast.GetBasicType(eBasicTypeChar);
- case PDB_BuiltinType::Bool:
- return clang_ast.GetBasicType(eBasicTypeBool);
- case PDB_BuiltinType::Long:
- if (width == ast.getTypeSize(ast.LongTy))
- return CompilerType(clang_ast.weak_from_this(),
- ast.LongTy.getAsOpaquePtr());
- if (width == ast.getTypeSize(ast.LongLongTy))
- return CompilerType(clang_ast.weak_from_this(),
- ast.LongLongTy.getAsOpaquePtr());
- break;
- case PDB_BuiltinType::ULong:
- if (width == ast.getTypeSize(ast.UnsignedLongTy))
- return CompilerType(clang_ast.weak_from_this(),
- ast.UnsignedLongTy.getAsOpaquePtr());
- if (width == ast.getTypeSize(ast.UnsignedLongLongTy))
- return CompilerType(clang_ast.weak_from_this(),
- ast.UnsignedLongLongTy.getAsOpaquePtr());
- break;
- case PDB_BuiltinType::WCharT:
- if (width == ast.getTypeSize(ast.WCharTy))
- return CompilerType(clang_ast.weak_from_this(),
- ast.WCharTy.getAsOpaquePtr());
- break;
- case PDB_BuiltinType::Char16:
- return CompilerType(clang_ast.weak_from_this(),
- ast.Char16Ty.getAsOpaquePtr());
- case PDB_BuiltinType::Char32:
- return CompilerType(clang_ast.weak_from_this(),
- ast.Char32Ty.getAsOpaquePtr());
- case PDB_BuiltinType::Float:
- // Note: types `long double` and `double` have same bit size in MSVC and
- // there is no information in the PDB to distinguish them. So when falling
- // back to default search, the compiler type of `long double` will be
- // represented by the one generated for `double`.
- break;
- }
- // If there is no match on PDB_BuiltinType, fall back to default search by
- // encoding and width only
- return clang_ast.GetBuiltinTypeForEncodingAndBitSize(encoding, width);
-}
-
-static ConstString GetPDBBuiltinTypeName(const PDBSymbolTypeBuiltin &pdb_type,
- CompilerType &compiler_type) {
- PDB_BuiltinType kind = pdb_type.getBuiltinType();
- switch (kind) {
- default:
- break;
- case PDB_BuiltinType::Currency:
- return ConstString("CURRENCY");
- case PDB_BuiltinType::Date:
- return ConstString("DATE");
- case PDB_BuiltinType::Variant:
- return ConstString("VARIANT");
- case PDB_BuiltinType::Complex:
- return ConstString("complex");
- case PDB_BuiltinType::Bitfield:
- return ConstString("bitfield");
- case PDB_BuiltinType::BSTR:
- return ConstString("BSTR");
- case PDB_BuiltinType::HResult:
- return ConstString("HRESULT");
- case PDB_BuiltinType::BCD:
- return ConstString("BCD");
- case PDB_BuiltinType::Char16:
- return ConstString("char16_t");
- case PDB_BuiltinType::Char32:
- return ConstString("char32_t");
- case PDB_BuiltinType::None:
- return ConstString("...");
- }
- return compiler_type.GetTypeName();
-}
-
-static bool AddSourceInfoToDecl(const PDBSymbol &symbol, Declaration &decl) {
- auto &raw_sym = symbol.getRawSymbol();
- auto first_line_up = raw_sym.getSrcLineOnTypeDefn();
-
- if (!first_line_up) {
- auto lines_up = symbol.getSession().findLineNumbersByAddress(
- raw_sym.getVirtualAddress(), raw_sym.getLength());
- if (!lines_up)
- return false;
- first_line_up = lines_up->getNext();
- if (!first_line_up)
- return false;
- }
- uint32_t src_file_id = first_line_up->getSourceFileId();
- auto src_file_up = symbol.getSession().getSourceFileById(src_file_id);
- if (!src_file_up)
- return false;
-
- FileSpec spec(src_file_up->getFileName());
- decl.SetFile(spec);
- decl.SetColumn(first_line_up->getColumnNumber());
- decl.SetLine(first_line_up->getLineNumber());
- return true;
-}
-
-static AccessType TranslateMemberAccess(PDB_MemberAccess access) {
- switch (access) {
- case PDB_MemberAccess::Private:
- return eAccessPrivate;
- case PDB_MemberAccess::Protected:
- return eAccessProtected;
- case PDB_MemberAccess::Public:
- return eAccessPublic;
- }
- return eAccessNone;
-}
-
-static AccessType GetDefaultAccessibilityForUdtKind(PDB_UdtType udt_kind) {
- switch (udt_kind) {
- case PDB_UdtType::Struct:
- case PDB_UdtType::Union:
- return eAccessPublic;
- case PDB_UdtType::Class:
- case PDB_UdtType::Interface:
- return eAccessPrivate;
- }
- llvm_unreachable("unsupported PDB UDT type");
-}
-
-static AccessType GetAccessibilityForUdt(const PDBSymbolTypeUDT &udt) {
- AccessType access = TranslateMemberAccess(udt.getAccess());
- if (access != lldb::eAccessNone || !udt.isNested())
- return access;
-
- auto parent = udt.getClassParent();
- if (!parent)
- return lldb::eAccessNone;
-
- auto parent_udt = llvm::dyn_cast<PDBSymbolTypeUDT>(parent.get());
- if (!parent_udt)
- return lldb::eAccessNone;
-
- return GetDefaultAccessibilityForUdtKind(parent_udt->getUdtKind());
-}
-
-static clang::MSInheritanceAttr::Spelling
-GetMSInheritance(const PDBSymbolTypeUDT &udt) {
- int base_count = 0;
- bool has_virtual = false;
-
- auto bases_enum = udt.findAllChildren<PDBSymbolTypeBaseClass>();
- if (bases_enum) {
- while (auto base = bases_enum->getNext()) {
- base_count++;
- has_virtual |= base->isVirtualBaseClass();
- }
- }
-
- if (has_virtual)
- return clang::MSInheritanceAttr::Keyword_virtual_inheritance;
- if (base_count > 1)
- return clang::MSInheritanceAttr::Keyword_multiple_inheritance;
- return clang::MSInheritanceAttr::Keyword_single_inheritance;
-}
-
-static std::unique_ptr<llvm::pdb::PDBSymbol>
-GetClassOrFunctionParent(const llvm::pdb::PDBSymbol &symbol) {
- const IPDBSession &session = symbol.getSession();
- const IPDBRawSymbol &raw = symbol.getRawSymbol();
- auto tag = symbol.getSymTag();
-
- // For items that are nested inside of a class, return the class that it is
- // nested inside of.
- // Note that only certain items can be nested inside of classes.
- switch (tag) {
- case PDB_SymType::Function:
- case PDB_SymType::Data:
- case PDB_SymType::UDT:
- case PDB_SymType::Enum:
- case PDB_SymType::FunctionSig:
- case PDB_SymType::Typedef:
- case PDB_SymType::BaseClass:
- case PDB_SymType::VTable: {
- auto class_parent_id = raw.getClassParentId();
- if (auto class_parent = session.getSymbolById(class_parent_id))
- return class_parent;
- break;
- }
- default:
- break;
- }
-
- // Otherwise, if it is nested inside of a function, return the function.
- // Note that only certain items can be nested inside of functions.
- switch (tag) {
- case PDB_SymType::Block:
- case PDB_SymType::Data: {
- auto lexical_parent_id = raw.getLexicalParentId();
- auto lexical_parent = session.getSymbolById(lexical_parent_id);
- if (!lexical_parent)
- return nullptr;
-
- auto lexical_parent_tag = lexical_parent->getSymTag();
- if (lexical_parent_tag == PDB_SymType::Function)
- return lexical_parent;
- if (lexical_parent_tag == PDB_SymType::Exe)
- return nullptr;
-
- return GetClassOrFunctionParent(*lexical_parent);
- }
- default:
- return nullptr;
- }
-}
-
-static clang::NamedDecl *
-GetDeclFromContextByName(const clang::ASTContext &ast,
- const clang::DeclContext &decl_context,
- llvm::StringRef name) {
- clang::IdentifierInfo &ident = ast.Idents.get(name);
- clang::DeclarationName decl_name = ast.DeclarationNames.getIdentifier(&ident);
- clang::DeclContext::lookup_result result = decl_context.lookup(decl_name);
- if (result.empty())
- return nullptr;
-
- return *result.begin();
-}
-
-static bool IsAnonymousNamespaceName(llvm::StringRef 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::TypeSystemClang &ast) : m_ast(ast) {}
-
-PDBASTParser::~PDBASTParser() = default;
-
-// DebugInfoASTParser interface
-
-lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
- Declaration decl;
- switch (type.getSymTag()) {
- case PDB_SymType::BaseClass: {
- auto symbol_file = m_ast.GetSymbolFile();
- if (!symbol_file)
- return nullptr;
-
- auto ty = symbol_file->ResolveTypeUID(type.getRawSymbol().getTypeId());
- return ty ? ty->shared_from_this() : nullptr;
- } break;
- case PDB_SymType::UDT: {
- auto udt = llvm::dyn_cast<PDBSymbolTypeUDT>(&type);
- assert(udt);
-
- // Note that, unnamed UDT being typedef-ed is generated as a UDT symbol
- // other than a Typedef symbol in PDB. For example,
- // typedef union { short Row; short Col; } Union;
- // is generated as a named UDT in PDB:
- // union Union { short Row; short Col; }
- // Such symbols will be handled here.
-
- // Some UDT with trival ctor has zero length. Just ignore.
- if (udt->getLength() == 0)
- return nullptr;
-
- // Ignore unnamed-tag UDTs.
- std::string name =
- std::string(MSVCUndecoratedNameParser::DropScope(udt->getName()));
- if (name.empty())
- return nullptr;
-
- auto decl_context = GetDeclContextContainingSymbol(type);
-
- // Check if such an UDT already exists in the current context.
- // This may occur with const or volatile types. There are separate type
- // symbols in PDB for types with const or volatile modifiers, but we need
- // to create only one declaration for them all.
- Type::ResolveState type_resolve_state;
- CompilerType clang_type =
- m_ast.GetTypeForIdentifier<clang::CXXRecordDecl>(name, decl_context);
- if (!clang_type.IsValid()) {
- auto access = GetAccessibilityForUdt(*udt);
-
- auto tag_type_kind = TranslateUdtKind(udt->getUdtKind());
-
- ClangASTMetadata metadata;
- metadata.SetUserID(type.getSymIndexId());
- metadata.SetIsDynamicCXXType(false);
-
- clang_type = m_ast.CreateRecordType(
- decl_context, OptionalClangModuleID(), access, name, tag_type_kind,
- lldb::eLanguageTypeC_plus_plus, metadata);
- assert(clang_type.IsValid());
-
- auto record_decl =
- m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType());
- assert(record_decl);
- m_uid_to_decl[type.getSymIndexId()] = record_decl;
-
- auto inheritance_attr = clang::MSInheritanceAttr::CreateImplicit(
- m_ast.getASTContext(), GetMSInheritance(*udt));
- record_decl->addAttr(inheritance_attr);
-
- TypeSystemClang::StartTagDeclarationDefinition(clang_type);
-
- auto children = udt->findAllChildren();
- if (!children || children->getChildCount() == 0) {
- // PDB does not have symbol of forwarder. We assume we get an udt w/o
- // any fields. Just complete it at this point.
- TypeSystemClang::CompleteTagDeclarationDefinition(clang_type);
-
- TypeSystemClang::SetHasExternalStorage(clang_type.GetOpaqueQualType(),
- false);
-
- type_resolve_state = Type::ResolveState::Full;
- } else {
- // Add the type to the forward declarations. It will help us to avoid
- // an endless recursion in CompleteTypeFromUdt function.
- m_forward_decl_to_uid[record_decl] = type.getSymIndexId();
-
- TypeSystemClang::SetHasExternalStorage(clang_type.GetOpaqueQualType(),
- true);
-
- type_resolve_state = Type::ResolveState::Forward;
- }
- } else
- type_resolve_state = Type::ResolveState::Forward;
-
- if (udt->isConstType())
- clang_type = clang_type.AddConstModifier();
-
- if (udt->isVolatileType())
- clang_type = clang_type.AddVolatileModifier();
-
- AddSourceInfoToDecl(type, decl);
- return m_ast.GetSymbolFile()->MakeType(
- type.getSymIndexId(), ConstString(name), udt->getLength(), nullptr,
- LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, clang_type,
- type_resolve_state);
- } break;
- case PDB_SymType::Enum: {
- auto enum_type = llvm::dyn_cast<PDBSymbolTypeEnum>(&type);
- assert(enum_type);
-
- std::string name =
- std::string(MSVCUndecoratedNameParser::DropScope(enum_type->getName()));
- auto decl_context = GetDeclContextContainingSymbol(type);
- uint64_t bytes = enum_type->getLength();
-
- // Check if such an enum already exists in the current context
- CompilerType ast_enum =
- m_ast.GetTypeForIdentifier<clang::EnumDecl>(name, decl_context);
- if (!ast_enum.IsValid()) {
- auto underlying_type_up = enum_type->getUnderlyingType();
- if (!underlying_type_up)
- return nullptr;
-
- lldb::Encoding encoding =
- TranslateBuiltinEncoding(underlying_type_up->getBuiltinType());
- // FIXME: Type of underlying builtin is always `Int`. We correct it with
- // the very first enumerator's encoding if any.
- auto first_child = enum_type->findOneChild<PDBSymbolData>();
- if (first_child)
- encoding = TranslateEnumEncoding(first_child->getValue().Type);
-
- CompilerType builtin_type;
- if (bytes > 0)
- builtin_type = GetBuiltinTypeForPDBEncodingAndBitSize(
- m_ast, *underlying_type_up, encoding, bytes * 8);
- else
- builtin_type = m_ast.GetBasicType(eBasicTypeInt);
-
- // FIXME: PDB does not have information about scoped enumeration (Enum
- // Class). Set it false for now.
- bool isScoped = false;
-
- ast_enum = m_ast.CreateEnumerationType(name, decl_context,
- OptionalClangModuleID(), decl,
- builtin_type, isScoped);
-
- auto enum_decl = TypeSystemClang::GetAsEnumDecl(ast_enum);
- assert(enum_decl);
- m_uid_to_decl[type.getSymIndexId()] = enum_decl;
-
- auto enum_values = enum_type->findAllChildren<PDBSymbolData>();
- if (enum_values) {
- while (auto enum_value = enum_values->getNext()) {
- if (enum_value->getDataKind() != PDB_DataKind::Constant)
- continue;
- AddEnumValue(ast_enum, *enum_value);
- }
- }
-
- if (TypeSystemClang::StartTagDeclarationDefinition(ast_enum))
- TypeSystemClang::CompleteTagDeclarationDefinition(ast_enum);
- }
-
- if (enum_type->isConstType())
- ast_enum = ast_enum.AddConstModifier();
-
- if (enum_type->isVolatileType())
- ast_enum = ast_enum.AddVolatileModifie...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/113647
More information about the lldb-commits
mailing list