Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.h
39642 views
//===-- PdbUtil.h -----------------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBUTIL_H9#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBUTIL_H1011#include "lldb/Expression/DWARFExpression.h"12#include "lldb/Symbol/Variable.h"13#include "lldb/lldb-enumerations.h"1415#include "llvm/DebugInfo/CodeView/CodeView.h"16#include "llvm/DebugInfo/CodeView/SymbolRecord.h"17#include "llvm/DebugInfo/CodeView/TypeRecord.h"18#include "llvm/DebugInfo/PDB/PDBTypes.h"1920#include "PdbSymUid.h"2122#include <tuple>23#include <utility>2425namespace llvm {26namespace pdb {27class TpiStream;28}29} // namespace llvm3031namespace lldb_private {32namespace npdb {3334class PdbIndex;3536struct CVTagRecord {37enum Kind { Class, Struct, Union, Enum };3839static CVTagRecord create(llvm::codeview::CVType type);4041Kind kind() const { return m_kind; }4243const llvm::codeview::TagRecord &asTag() const {44if (m_kind == Struct || m_kind == Class)45return cvclass;46if (m_kind == Enum)47return cvenum;48return cvunion;49}5051const llvm::codeview::ClassRecord &asClass() const {52assert(m_kind == Struct || m_kind == Class);53return cvclass;54}5556const llvm::codeview::EnumRecord &asEnum() const {57assert(m_kind == Enum);58return cvenum;59}6061const llvm::codeview::UnionRecord &asUnion() const {62assert(m_kind == Union);63return cvunion;64}6566llvm::StringRef name() const {67if (m_kind == Struct || m_kind == Union)68return cvclass.Name;69if (m_kind == Enum)70return cvenum.Name;71return cvunion.Name;72}7374private:75CVTagRecord(llvm::codeview::ClassRecord &&c);76CVTagRecord(llvm::codeview::UnionRecord &&u);77CVTagRecord(llvm::codeview::EnumRecord &&e);78union {79llvm::codeview::ClassRecord cvclass;80llvm::codeview::EnumRecord cvenum;81llvm::codeview::UnionRecord cvunion;82};83Kind m_kind;84};8586struct SegmentOffset {87SegmentOffset() = default;88SegmentOffset(uint16_t s, uint32_t o) : segment(s), offset(o) {}89uint16_t segment = 0;90uint32_t offset = 0;91};9293struct SegmentOffsetLength {94SegmentOffsetLength() = default;95SegmentOffsetLength(uint16_t s, uint32_t o, uint32_t l)96: so(s, o), length(l) {}97SegmentOffset so;98uint32_t length = 0;99};100101struct VariableInfo {102llvm::StringRef name;103llvm::codeview::TypeIndex type;104DWARFExpressionList location;105bool is_param;106};107108llvm::pdb::PDB_SymType CVSymToPDBSym(llvm::codeview::SymbolKind kind);109llvm::pdb::PDB_SymType CVTypeToPDBType(llvm::codeview::TypeLeafKind kind);110111bool SymbolHasAddress(const llvm::codeview::CVSymbol &sym);112bool SymbolIsCode(const llvm::codeview::CVSymbol &sym);113114SegmentOffset GetSegmentAndOffset(const llvm::codeview::CVSymbol &sym);115SegmentOffsetLength116GetSegmentOffsetAndLength(const llvm::codeview::CVSymbol &sym);117118template <typename RecordT> bool IsValidRecord(const RecordT &sym) {119return true;120}121122inline bool IsValidRecord(const llvm::codeview::ProcRefSym &sym) {123// S_PROCREF symbols have 1-based module indices.124return sym.Module > 0;125}126127bool IsForwardRefUdt(llvm::codeview::CVType cvt);128bool IsTagRecord(llvm::codeview::CVType cvt);129bool IsClassStructUnion(llvm::codeview::CVType cvt);130131bool IsForwardRefUdt(const PdbTypeSymId &id, llvm::pdb::TpiStream &tpi);132bool IsTagRecord(const PdbTypeSymId &id, llvm::pdb::TpiStream &tpi);133134lldb::AccessType TranslateMemberAccess(llvm::codeview::MemberAccess access);135llvm::codeview::TypeIndex GetFieldListIndex(llvm::codeview::CVType cvt);136llvm::codeview::TypeIndex137LookThroughModifierRecord(llvm::codeview::CVType modifier);138139llvm::StringRef DropNameScope(llvm::StringRef name);140141VariableInfo GetVariableNameInfo(llvm::codeview::CVSymbol symbol);142VariableInfo GetVariableLocationInfo(PdbIndex &index, PdbCompilandSymId var_id,143Block &func_block, lldb::ModuleSP module);144145size_t GetTypeSizeForSimpleKind(llvm::codeview::SimpleTypeKind kind);146lldb::BasicType147GetCompilerTypeForSimpleKind(llvm::codeview::SimpleTypeKind kind);148149PdbTypeSymId GetBestPossibleDecl(PdbTypeSymId id, llvm::pdb::TpiStream &tpi);150151size_t GetSizeOfType(PdbTypeSymId id, llvm::pdb::TpiStream &tpi);152153} // namespace npdb154} // namespace lldb_private155156#endif157158159