1//===- NativeFunctionSymbol.cpp - info about function symbols----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/DebugInfo/PDB/Native/NativeFunctionSymbol.h"
10
11#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
12#include "llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h"
13#include "llvm/DebugInfo/PDB/Native/NativeTypeEnum.h"
14
15using namespace llvm;
16using namespace llvm::codeview;
17using namespace llvm::pdb;
18
19NativeFunctionSymbol::NativeFunctionSymbol(NativeSession &Session,
20                                           SymIndexId Id,
21                                           const codeview::ProcSym &Sym)
22    : NativeRawSymbol(Session, PDB_SymType::Data, Id), Sym(Sym) {}
23
24NativeFunctionSymbol::~NativeFunctionSymbol() {}
25
26void NativeFunctionSymbol::dump(raw_ostream &OS, int Indent,
27                                PdbSymbolIdField ShowIdFields,
28                                PdbSymbolIdField RecurseIdFields) const {
29  NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
30  dumpSymbolField(OS, "name", getName(), Indent);
31  dumpSymbolField(OS, "length", getLength(), Indent);
32  dumpSymbolField(OS, "offset", getAddressOffset(), Indent);
33  dumpSymbolField(OS, "section", getAddressSection(), Indent);
34}
35
36uint32_t NativeFunctionSymbol::getAddressOffset() const {
37  return Sym.CodeOffset;
38}
39
40uint32_t NativeFunctionSymbol::getAddressSection() const { return Sym.Segment; }
41std::string NativeFunctionSymbol::getName() const {
42  return std::string(Sym.Name);
43}
44
45PDB_SymType NativeFunctionSymbol::getSymTag() const {
46  return PDB_SymType::Function;
47}
48
49uint64_t NativeFunctionSymbol::getLength() const { return Sym.CodeSize; }
50
51uint32_t NativeFunctionSymbol::getRelativeVirtualAddress() const {
52  return Session.getRVAFromSectOffset(Sym.Segment, Sym.CodeOffset);
53}
54
55uint64_t NativeFunctionSymbol::getVirtualAddress() const {
56  return Session.getVAFromSectOffset(Sym.Segment, Sym.CodeOffset);
57}
58