Zachary Turner c68925aba3 Change lldb-test to use ParseAllDebugSymbols.
ParseDeclsForContext was originally created to serve the very specific
case where the context is a function block. It was never intended to be
used for arbitrary DeclContexts, however due to the generic name, the
DWARF and PDB plugins implemented it in this way "just in case". Then,
lldb-test came along and decided to use it in that way.

Related to this, there are a set of functions in the SymbolFile class
interface whose requirements and expectations are not documented. For
example, if you call ParseCompileUnitFunctions, there's an inherent
requirement that you create entries in the underlying clang AST for
these functions as well as their signature types, because in order to
create an lldb_private::Function object, you have to pass it a
CompilerType for the parameter representing the signature.

On the other hand, there is no similar requirement (either inherent or
documented) if one were to call ParseDeclsForContext. Specifically, if
one calls ParseDeclsForContext, and some variable declarations, types,
and other things are added to the clang AST, is it necessary to create
lldb::Variable, lldb::Type, etc objects representing them? Nobody knows.
There is, however, an accidental requirement, because since all of the
plugins implemented this just in case, lldb-test came along and used
ParsedDeclsForContext, and then wrote check lines that depended on this.

When I went to try and implemented the NativePDB reader, I did not
adhere to this (in fact, from a layering perspective I went out of my
way to avoid it), and as a result the existing DIA PDB tests don't work
when the native PDB reader is enabled, because they expect that calling
ParseDeclsForContext will modify the *module's* view of symbols, and not
just the internal AST.

All of this confusion, however, can be avoided if we simply stick to
using ParseDeclsForContext for its original intended use case (blocks),
and use a different function (ParseAllDebugSymbols) for its intended use
case which is, unsuprisingly, to parse all the debug symbols (which is
all lldb-test really wanted to do anyway).

In the future, I would like to change ParseDeclsForContext to
ParseDeclsForFunctionBlock, then delete all of the dead code inside that
handles other types of DeclContexts (and probably even assert if the
DeclContext is anything other than a block).

A few PDB tests needed to be fixed up as a result of this, and this also
exposed a couple of bugs in the DIA PDB reader (doesn't matter much
since it should be going away soon, but worth mentioning) where the
appropriate AST entries weren't being created always.

Differential Revision: https://reviews.llvm.org/D56418

llvm-svn: 350764
2019-01-09 21:20:44 +00:00

270 lines
9.8 KiB
C++

//===-- SymbolFilePDB.h -------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_
#define lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_
#include "lldb/Core/UniqueCStringMap.h"
#include "lldb/Symbol/SymbolFile.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Utility/UserID.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/DebugInfo/PDB/IPDBSession.h"
#include "llvm/DebugInfo/PDB/PDB.h"
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
class PDBASTParser;
class SymbolFilePDB : public lldb_private::SymbolFile {
public:
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
static void Initialize();
static void Terminate();
static void DebuggerInitialize(lldb_private::Debugger &debugger);
static lldb_private::ConstString GetPluginNameStatic();
static const char *GetPluginDescriptionStatic();
static lldb_private::SymbolFile *
CreateInstance(lldb_private::ObjectFile *obj_file);
//------------------------------------------------------------------
// Constructors and Destructors
//------------------------------------------------------------------
SymbolFilePDB(lldb_private::ObjectFile *ofile);
~SymbolFilePDB() override;
uint32_t CalculateAbilities() override;
void InitializeObject() override;
//------------------------------------------------------------------
// Compile Unit function calls
//------------------------------------------------------------------
uint32_t GetNumCompileUnits() override;
lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
lldb::LanguageType
ParseCompileUnitLanguage(const lldb_private::SymbolContext &sc) override;
size_t
ParseCompileUnitFunctions(const lldb_private::SymbolContext &sc) override;
bool
ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc) override;
bool
ParseCompileUnitDebugMacros(const lldb_private::SymbolContext &sc) override;
bool ParseCompileUnitSupportFiles(
const lldb_private::SymbolContext &sc,
lldb_private::FileSpecList &support_files) override;
bool ParseImportedModules(
const lldb_private::SymbolContext &sc,
std::vector<lldb_private::ConstString> &imported_modules) override;
size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc) override;
size_t ParseTypes(const lldb_private::SymbolContext &sc) override;
size_t
ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
llvm::Optional<ArrayInfo> GetDynamicArrayInfoForUID(
lldb::user_id_t type_uid,
const lldb_private::ExecutionContext *exe_ctx) override;
bool CompleteType(lldb_private::CompilerType &compiler_type) override;
lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override;
lldb_private::CompilerDeclContext
GetDeclContextForUID(lldb::user_id_t uid) override;
lldb_private::CompilerDeclContext
GetDeclContextContainingUID(lldb::user_id_t uid) override;
void
ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
lldb::SymbolContextItem resolve_scope,
lldb_private::SymbolContext &sc) override;
uint32_t
ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line,
bool check_inlines,
lldb::SymbolContextItem resolve_scope,
lldb_private::SymbolContextList &sc_list) override;
uint32_t
FindGlobalVariables(const lldb_private::ConstString &name,
const lldb_private::CompilerDeclContext *parent_decl_ctx,
uint32_t max_matches,
lldb_private::VariableList &variables) override;
uint32_t FindGlobalVariables(const lldb_private::RegularExpression &regex,
uint32_t max_matches,
lldb_private::VariableList &variables) override;
uint32_t
FindFunctions(const lldb_private::ConstString &name,
const lldb_private::CompilerDeclContext *parent_decl_ctx,
lldb::FunctionNameType name_type_mask, bool include_inlines,
bool append, lldb_private::SymbolContextList &sc_list) override;
uint32_t FindFunctions(const lldb_private::RegularExpression &regex,
bool include_inlines, bool append,
lldb_private::SymbolContextList &sc_list) override;
void GetMangledNamesForFunction(
const std::string &scope_qualified_name,
std::vector<lldb_private::ConstString> &mangled_names) override;
void AddSymbols(lldb_private::Symtab &symtab) override;
uint32_t
FindTypes(const lldb_private::SymbolContext &sc,
const lldb_private::ConstString &name,
const lldb_private::CompilerDeclContext *parent_decl_ctx,
bool append, uint32_t max_matches,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
lldb_private::TypeMap &types) override;
size_t FindTypes(const std::vector<lldb_private::CompilerContext> &context,
bool append, lldb_private::TypeMap &types) override;
void FindTypesByRegex(const lldb_private::RegularExpression &regex,
uint32_t max_matches, lldb_private::TypeMap &types);
lldb_private::TypeList *GetTypeList() override;
size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
lldb::TypeClass type_mask,
lldb_private::TypeList &type_list) override;
lldb_private::TypeSystem *
GetTypeSystemForLanguage(lldb::LanguageType language) override;
lldb_private::CompilerDeclContext FindNamespace(
const lldb_private::SymbolContext &sc,
const lldb_private::ConstString &name,
const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
lldb_private::ConstString GetPluginName() override;
uint32_t GetPluginVersion() override;
llvm::pdb::IPDBSession &GetPDBSession();
const llvm::pdb::IPDBSession &GetPDBSession() const;
void DumpClangAST(lldb_private::Stream &s) override;
private:
struct SecContribInfo {
uint32_t Offset;
uint32_t Size;
uint32_t CompilandId;
};
using SecContribsMap = std::map<uint32_t, std::vector<SecContribInfo>>;
lldb::CompUnitSP ParseCompileUnitForUID(uint32_t id,
uint32_t index = UINT32_MAX);
bool ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc,
uint32_t match_line);
void BuildSupportFileIdToSupportFileIndexMap(
const llvm::pdb::PDBSymbolCompiland &pdb_compiland,
llvm::DenseMap<uint32_t, uint32_t> &index_map) const;
void FindTypesByName(llvm::StringRef name,
const lldb_private::CompilerDeclContext *parent_decl_ctx,
uint32_t max_matches, lldb_private::TypeMap &types);
std::string GetMangledForPDBData(const llvm::pdb::PDBSymbolData &pdb_data);
lldb::VariableSP
ParseVariableForPDBData(const lldb_private::SymbolContext &sc,
const llvm::pdb::PDBSymbolData &pdb_data);
size_t ParseVariables(const lldb_private::SymbolContext &sc,
const llvm::pdb::PDBSymbol &pdb_data,
lldb_private::VariableList *variable_list = nullptr);
lldb::CompUnitSP
GetCompileUnitContainsAddress(const lldb_private::Address &so_addr);
typedef std::vector<lldb_private::Type *> TypeCollection;
void GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol &pdb_symbol,
uint32_t type_mask,
TypeCollection &type_collection);
lldb_private::Function *
ParseCompileUnitFunctionForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func,
const lldb_private::SymbolContext &sc);
void GetCompileUnitIndex(const llvm::pdb::PDBSymbolCompiland &pdb_compiland,
uint32_t &index);
PDBASTParser *GetPDBAstParser();
std::unique_ptr<llvm::pdb::PDBSymbolCompiland>
GetPDBCompilandByUID(uint32_t uid);
lldb_private::Mangled
GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func);
bool ResolveFunction(const llvm::pdb::PDBSymbolFunc &pdb_func,
bool include_inlines,
lldb_private::SymbolContextList &sc_list);
bool ResolveFunction(uint32_t uid, bool include_inlines,
lldb_private::SymbolContextList &sc_list);
void CacheFunctionNames();
bool DeclContextMatchesThisSymbolFile(
const lldb_private::CompilerDeclContext *decl_ctx);
uint32_t GetCompilandId(const llvm::pdb::PDBSymbolData &data);
llvm::DenseMap<uint32_t, lldb::CompUnitSP> m_comp_units;
llvm::DenseMap<uint32_t, lldb::TypeSP> m_types;
llvm::DenseMap<uint32_t, lldb::VariableSP> m_variables;
llvm::DenseMap<uint64_t, std::string> m_public_names;
SecContribsMap m_sec_contribs;
std::vector<lldb::TypeSP> m_builtin_types;
std::unique_ptr<llvm::pdb::IPDBSession> m_session_up;
std::unique_ptr<llvm::pdb::PDBSymbolExe> m_global_scope_up;
uint32_t m_cached_compile_unit_count;
std::unique_ptr<lldb_private::CompilerDeclContext> m_tu_decl_ctx_up;
lldb_private::UniqueCStringMap<uint32_t> m_func_full_names;
lldb_private::UniqueCStringMap<uint32_t> m_func_base_names;
lldb_private::UniqueCStringMap<uint32_t> m_func_method_names;
};
#endif // lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_