From 5fa4774559d7d68deaf9234d424db9efa11322f0 Mon Sep 17 00:00:00 2001 From: Adrian McCarthy Date: Thu, 16 Mar 2017 22:28:39 +0000 Subject: [PATCH] Make NativeExeSymbol a concrete subclass of NativeRawSymbol [PDB] This moves exe symbol-specific method implementations out of NativeRawSymbol into a concrete subclass. Also adds implementations for hasCTypes and hasPrivateSymbols and a simple test to ensure the native reader can access the summary information for the executable from the PDB. Differential Revision: https://reviews.llvm.org/D31059 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298005 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../llvm/DebugInfo/PDB/Native/NativeExeSymbol.h | 39 +++++++++++ .../llvm/DebugInfo/PDB/Native/NativeRawSymbol.h | 2 +- lib/DebugInfo/PDB/CMakeLists.txt | 1 + lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp | 79 ++++++++++++++++++++++ lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp | 33 +-------- lib/DebugInfo/PDB/Native/NativeSession.cpp | 4 +- test/DebugInfo/PDB/Native/pdb-native-summary.test | 11 +++ 7 files changed, 134 insertions(+), 35 deletions(-) create mode 100644 include/llvm/DebugInfo/PDB/Native/NativeExeSymbol.h create mode 100644 lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp create mode 100644 test/DebugInfo/PDB/Native/pdb-native-summary.test diff --git a/include/llvm/DebugInfo/PDB/Native/NativeExeSymbol.h b/include/llvm/DebugInfo/PDB/Native/NativeExeSymbol.h new file mode 100644 index 00000000000..9516810539b --- /dev/null +++ b/include/llvm/DebugInfo/PDB/Native/NativeExeSymbol.h @@ -0,0 +1,39 @@ +//===- NativeExeSymbol.h - native impl for PDBSymbolExe ---------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVEEXESYMBOL_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVEEXESYMBOL_H + +#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" +#include "llvm/DebugInfo/PDB/Native/NativeSession.h" + +namespace llvm { +namespace pdb { + +class NativeExeSymbol : public NativeRawSymbol { +public: + NativeExeSymbol(NativeSession &Session); + + std::unique_ptr + findChildren(PDB_SymType Type) const override; + + uint32_t getAge() const override; + std::string getSymbolsFileName() const override; + PDB_UniqueId getGuid() const override; + bool hasCTypes() const override; + bool hasPrivateSymbols() const override; + +private: + PDBFile &File; +}; + +} // namespace pdb +} // namespace llvm + +#endif diff --git a/include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h b/include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h index e6582068848..655bed9ac17 100644 --- a/include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h +++ b/include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h @@ -197,7 +197,7 @@ public: bool wasInlined() const override; std::string getUnused() const override; -private: +protected: NativeSession &Session; }; diff --git a/lib/DebugInfo/PDB/CMakeLists.txt b/lib/DebugInfo/PDB/CMakeLists.txt index 448b6a369b0..1295d2a19ce 100644 --- a/lib/DebugInfo/PDB/CMakeLists.txt +++ b/lib/DebugInfo/PDB/CMakeLists.txt @@ -42,6 +42,7 @@ add_pdb_impl_folder(Native Native/ModStream.cpp Native/NativeCompilandSymbol.cpp Native/NativeEnumModules.cpp + Native/NativeExeSymbol.cpp Native/NativeRawSymbol.cpp Native/NamedStreamMap.cpp Native/NativeSession.cpp diff --git a/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp b/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp new file mode 100644 index 00000000000..ec2a4b87457 --- /dev/null +++ b/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp @@ -0,0 +1,79 @@ +//===- NativeExeSymbol.cpp - native impl for PDBSymbolExe -------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h" + +#include "llvm/DebugInfo/PDB/Native/DbiStream.h" +#include "llvm/DebugInfo/PDB/Native/InfoStream.h" +#include "llvm/DebugInfo/PDB/Native/NativeEnumModules.h" +#include "llvm/DebugInfo/PDB/Native/PDBFile.h" + +namespace llvm { +namespace pdb { + +NativeExeSymbol::NativeExeSymbol(NativeSession &Session) + : NativeRawSymbol(Session), File(Session.getPDBFile()) {} + +std::unique_ptr +NativeExeSymbol::findChildren(PDB_SymType Type) const { + switch (Type) { + case PDB_SymType::Compiland: { + auto Dbi = File.getPDBDbiStream(); + if (Dbi) { + const auto Modules = Dbi->modules(); + return std::unique_ptr( + new NativeEnumModules(Session, Modules)); + } + consumeError(Dbi.takeError()); + break; + } + default: + break; + } + return nullptr; +} + +uint32_t NativeExeSymbol::getAge() const { + auto IS = File.getPDBInfoStream(); + if (IS) + return IS->getAge(); + consumeError(IS.takeError()); + return 0; +} + +std::string NativeExeSymbol::getSymbolsFileName() const { + return File.getFilePath(); +} + +PDB_UniqueId NativeExeSymbol::getGuid() const { + auto IS = File.getPDBInfoStream(); + if (IS) + return IS->getGuid(); + consumeError(IS.takeError()); + return PDB_UniqueId{{0}}; +} + +bool NativeExeSymbol::hasCTypes() const { + auto Dbi = File.getPDBDbiStream(); + if (Dbi) + return Dbi->hasCTypes(); + consumeError(Dbi.takeError()); + return false; +} + +bool NativeExeSymbol::hasPrivateSymbols() const { + auto Dbi = File.getPDBDbiStream(); + if (Dbi) + return !Dbi->isStripped(); + consumeError(Dbi.takeError()); + return false; +} + +} // namespace pdb +} // namespace llvm diff --git a/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp b/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp index 3974ddc08a4..4841ded7410 100644 --- a/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp +++ b/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp @@ -11,11 +11,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" -#include "llvm/DebugInfo/PDB/Native/DbiStream.h" -#include "llvm/DebugInfo/PDB/Native/InfoStream.h" -#include "llvm/DebugInfo/PDB/Native/NativeEnumModules.h" #include "llvm/DebugInfo/PDB/Native/NativeSession.h" -#include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/PDBExtras.h" #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/raw_ostream.h" @@ -30,21 +26,6 @@ void NativeRawSymbol::dump(raw_ostream &OS, int Indent) const {} std::unique_ptr NativeRawSymbol::findChildren(PDB_SymType Type) const { - switch (Type) { - case PDB_SymType::Compiland: { - auto &File = Session.getPDBFile(); - auto Dbi = File.getPDBDbiStream(); - if (Dbi) { - const auto Modules = Dbi->modules(); - return std::unique_ptr( - new NativeEnumModules(Session, Modules)); - } - consumeError(Dbi.takeError()); - break; - } - default: - break; - } return nullptr; } @@ -82,11 +63,6 @@ uint32_t NativeRawSymbol::getAddressSection() const { } uint32_t NativeRawSymbol::getAge() const { - auto &File = Session.getPDBFile(); - auto IS = File.getPDBInfoStream(); - if (IS) - return IS->getAge(); - consumeError(IS.takeError()); return 0; } @@ -272,9 +248,7 @@ uint32_t NativeRawSymbol::getSubTypeId() const { return 0; } -std::string NativeRawSymbol::getSymbolsFileName() const { - return Session.getPDBFile().getFilePath(); -} +std::string NativeRawSymbol::getSymbolsFileName() const { return ""; } uint32_t NativeRawSymbol::getSymIndexId() const { return 0; @@ -353,11 +327,6 @@ PDB_SymType NativeRawSymbol::getSymTag() const { } PDB_UniqueId NativeRawSymbol::getGuid() const { - auto &File = Session.getPDBFile(); - auto IS = File.getPDBInfoStream(); - if (IS) - return IS->getGuid(); - consumeError(IS.takeError()); return PDB_UniqueId{{0}}; } diff --git a/lib/DebugInfo/PDB/Native/NativeSession.cpp b/lib/DebugInfo/PDB/Native/NativeSession.cpp index d49e61f6c21..3a83a326cfe 100644 --- a/lib/DebugInfo/PDB/Native/NativeSession.cpp +++ b/lib/DebugInfo/PDB/Native/NativeSession.cpp @@ -13,7 +13,7 @@ #include "llvm/DebugInfo/PDB/GenericError.h" #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" #include "llvm/DebugInfo/PDB/IPDBSourceFile.h" -#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" +#include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/RawError.h" #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" @@ -71,7 +71,7 @@ uint64_t NativeSession::getLoadAddress() const { return 0; } void NativeSession::setLoadAddress(uint64_t Address) {} std::unique_ptr NativeSession::getGlobalScope() { - auto RawSymbol = llvm::make_unique(*this); + auto RawSymbol = llvm::make_unique(*this); auto PdbSymbol(PDBSymbol::create(*this, std::move(RawSymbol))); std::unique_ptr ExeSymbol( static_cast(PdbSymbol.release())); diff --git a/test/DebugInfo/PDB/Native/pdb-native-summary.test b/test/DebugInfo/PDB/Native/pdb-native-summary.test new file mode 100644 index 00000000000..f86a9c81a08 --- /dev/null +++ b/test/DebugInfo/PDB/Native/pdb-native-summary.test @@ -0,0 +1,11 @@ +; Test that the native PDB reader gets the PDB summary correct. +; RUN: llvm-pdbdump pretty -native %p/../Inputs/empty.pdb \ +; RUN: | FileCheck -check-prefix=EMPTY %s + +; Reference output was generated with the DIA reader to ensure that the +; `-native` option produces identical output. + +EMPTY: Size: 102400 bytes +EMPTY: Guid: {0B355641-86A0-A249-896F-9988FAE52FF0} +EMPTY: Age: 1 +EMPTY: Attributes: HasPrivateSymbols -- 2.11.0