Index: llvm/include/llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h =================================================================== --- /dev/null +++ llvm/include/llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h @@ -0,0 +1,36 @@ +//===- NativeCompilandSymbol.h - Native impl of PDBSymbolCompiland - 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_NATIVECOMPILANDSYMBOL_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVECOMPILANDSYMBOL_H + +#include "llvm/DebugInfo/PDB/Native/ModInfo.h" +#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" + +namespace llvm { +namespace pdb { + +class NativeCompilandSymbol : public NativeRawSymbol { +public: + NativeCompilandSymbol(NativeSession &Session, const ModuleInfoEx &MI); + PDB_SymType getSymTag() const override; + bool isEditAndContinueEnabled() const override; + uint32_t getLexicalParentId() const override; + std::string getLibraryName() const override; + std::string getName() const override; + +private: + ModuleInfoEx Module; +}; + +} // namespace pdb +} // namespace llvm + +#endif Index: llvm/include/llvm/DebugInfo/PDB/Native/NativeEnumModules.h =================================================================== --- /dev/null +++ llvm/include/llvm/DebugInfo/PDB/Native/NativeEnumModules.h @@ -0,0 +1,41 @@ +//==- NativeEnumModules.h - Native Module Enumerator impl --------*- 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_NATIVEENUMMODULES_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVEENUMMODULES_H + +#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" +#include "llvm/DebugInfo/PDB/Native/ModInfo.h" +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +namespace llvm { +namespace pdb { + +class NativeSession; + +class NativeEnumModules : public IPDBEnumChildren { +public: + explicit NativeEnumModules(NativeSession &Session, + ArrayRef Modules, + uint32_t Index = 0); + + uint32_t getChildCount() const override; + std::unique_ptr getChildAtIndex(uint32_t Index) const override; + std::unique_ptr getNext() override; + void reset() override; + NativeEnumModules *clone() const override; + +private: + NativeSession &Session; + ArrayRef Modules; + uint32_t Index; +}; +} +} + +#endif Index: llvm/lib/DebugInfo/PDB/CMakeLists.txt =================================================================== --- llvm/lib/DebugInfo/PDB/CMakeLists.txt +++ llvm/lib/DebugInfo/PDB/CMakeLists.txt @@ -39,6 +39,8 @@ Native/InfoStreamBuilder.cpp Native/ModInfo.cpp Native/ModStream.cpp + Native/NativeCompilandSymbol.cpp + Native/NativeEnumModules.cpp Native/NativeRawSymbol.cpp Native/NamedStreamMap.cpp Native/NativeSession.cpp Index: llvm/lib/DebugInfo/PDB/Native/NativeCompilandSymbol.cpp =================================================================== --- /dev/null +++ llvm/lib/DebugInfo/PDB/Native/NativeCompilandSymbol.cpp @@ -0,0 +1,40 @@ +//===- NativeCompilandSymbol.h - Native impl of PDBCompilandSymbol -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/NativeCompilandSymbol.h" + +namespace llvm { +namespace pdb { + +NativeCompilandSymbol::NativeCompilandSymbol(NativeSession &Session, + const ModuleInfoEx &MI) + : NativeRawSymbol(Session), Module(MI) {} + +PDB_SymType NativeCompilandSymbol::getSymTag() const { + return PDB_SymType::Compiland; +} + +bool NativeCompilandSymbol::isEditAndContinueEnabled() const { return false; } + +uint32_t NativeCompilandSymbol::getLexicalParentId() const { return 0; } + +// DIA, which this API was modeled after, uses counter-intuitive meanings for +// IDiaSymbol::get_name and IDiaSymbol::get_libraryName, which is why these +// methods may appear to be cross-mapped. + +std::string NativeCompilandSymbol::getLibraryName() const { + return Module.Info.getObjFileName(); +} + +std::string NativeCompilandSymbol::getName() const { + return Module.Info.getModuleName(); +} + +} // namespace pdb +} // namespace llvm Index: llvm/lib/DebugInfo/PDB/Native/NativeEnumModules.cpp =================================================================== --- /dev/null +++ llvm/lib/DebugInfo/PDB/Native/NativeEnumModules.cpp @@ -0,0 +1,52 @@ +//==- NativeEnumModules.cpp - Native Symbol Enumerator impl ------*- 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/NativeEnumModules.h" + +#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" +#include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h" +#include "llvm/DebugInfo/PDB/Native/NativeSession.h" +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" + +namespace llvm { +namespace pdb { + +NativeEnumModules::NativeEnumModules(NativeSession &PDBSession, + ArrayRef Modules, + uint32_t Index) + : Session(PDBSession), Modules(Modules), Index(Index) {} + +uint32_t NativeEnumModules::getChildCount() const { + return static_cast(Modules.size()); +} + +std::unique_ptr +NativeEnumModules::getChildAtIndex(uint32_t Index) const { + if (Index >= Modules.size()) + return nullptr; + return std::unique_ptr(new PDBSymbolCompiland(Session, + std::unique_ptr( + new NativeCompilandSymbol(Session, Modules[Index])))); +} + +std::unique_ptr NativeEnumModules::getNext() { + if (Index >= Modules.size()) + return nullptr; + return getChildAtIndex(Index++); +} + +void NativeEnumModules::reset() { Index = 0; } + +NativeEnumModules *NativeEnumModules::clone() const { + return new NativeEnumModules(Session, Modules, Index); +} + +} +} Index: llvm/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp =================================================================== --- llvm/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp +++ llvm/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp @@ -10,11 +10,13 @@ #include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/DebugInfo/PDB/Native/InfoStream.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/DebugInfo/PDB/Native/NativeSession.h" #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/raw_ostream.h" @@ -28,6 +30,21 @@ 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; }