xref: /freebsd/contrib/llvm-project/llvm/lib/DebugInfo/PDB/Native/NativeFunctionSymbol.cpp (revision cfd6422a5217410fbd66f7a7a8a64d9d85e61229)
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 
15 using namespace llvm;
16 using namespace llvm::codeview;
17 using namespace llvm::pdb;
18 
19 NativeFunctionSymbol::NativeFunctionSymbol(NativeSession &Session,
20                                            SymIndexId Id,
21                                            const codeview::ProcSym &Sym)
22     : NativeRawSymbol(Session, PDB_SymType::Data, Id), Sym(Sym) {}
23 
24 NativeFunctionSymbol::~NativeFunctionSymbol() {}
25 
26 void 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 
36 uint32_t NativeFunctionSymbol::getAddressOffset() const {
37   return Sym.CodeOffset;
38 }
39 
40 uint32_t NativeFunctionSymbol::getAddressSection() const { return Sym.Segment; }
41 std::string NativeFunctionSymbol::getName() const {
42   return std::string(Sym.Name);
43 }
44 
45 PDB_SymType NativeFunctionSymbol::getSymTag() const {
46   return PDB_SymType::Function;
47 }
48 
49 uint64_t NativeFunctionSymbol::getLength() const { return Sym.CodeSize; }
50 
51 uint32_t NativeFunctionSymbol::getRelativeVirtualAddress() const {
52   return Session.getRVAFromSectOffset(Sym.Segment, Sym.CodeOffset);
53 }
54 
55 uint64_t NativeFunctionSymbol::getVirtualAddress() const {
56   return Session.getVAFromSectOffset(Sym.Segment, Sym.CodeOffset);
57 }
58