xref: /freebsd/contrib/llvm-project/llvm/tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp (revision cfd6422a5217410fbd66f7a7a8a64d9d85e61229)
1 //===- PrettyExternalSymbolDumper.cpp -------------------------- *- 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 "PrettyExternalSymbolDumper.h"
10 #include "LinePrinter.h"
11 
12 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
13 #include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
14 #include "llvm/Support/Format.h"
15 
16 using namespace llvm;
17 using namespace llvm::pdb;
18 
19 ExternalSymbolDumper::ExternalSymbolDumper(LinePrinter &P)
20     : PDBSymDumper(true), Printer(P) {}
21 
22 void ExternalSymbolDumper::start(const PDBSymbolExe &Symbol) {
23   if (auto Vars = Symbol.findAllChildren<PDBSymbolPublicSymbol>()) {
24     while (auto Var = Vars->getNext())
25       Var->dump(*this);
26   }
27 }
28 
29 void ExternalSymbolDumper::dump(const PDBSymbolPublicSymbol &Symbol) {
30   std::string LinkageName = Symbol.getName();
31   if (Printer.IsSymbolExcluded(LinkageName))
32     return;
33 
34   Printer.NewLine();
35   uint64_t Addr = Symbol.getVirtualAddress();
36 
37   Printer << "public [";
38   WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Addr, 10);
39   Printer << "] ";
40   WithColor(Printer, PDB_ColorItem::Identifier).get() << LinkageName;
41 }
42