CompilandDumper.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //===- CompilandDumper.cpp - llvm-pdbdump compiland symbol dumper *- C++ *-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #include "CompilandDumper.h"
  10. #include "LinePrinter.h"
  11. #include "llvm-pdbdump.h"
  12. #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
  13. #include "llvm/DebugInfo/PDB/IPDBSession.h"
  14. #include "llvm/DebugInfo/PDB/PDBExtras.h"
  15. #include "llvm/DebugInfo/PDB/PDBSymbol.h"
  16. #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
  17. #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
  18. #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
  19. #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
  20. #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
  21. #include "llvm/DebugInfo/PDB/PDBSymbolLabel.h"
  22. #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
  23. #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
  24. #include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h"
  25. #include "llvm/Support/Format.h"
  26. #include "llvm/Support/Path.h"
  27. #include "llvm/Support/raw_ostream.h"
  28. #include "FunctionDumper.h"
  29. #include <utility>
  30. #include <vector>
  31. using namespace llvm;
  32. CompilandDumper::CompilandDumper(LinePrinter &P)
  33. : PDBSymDumper(true), Printer(P) {}
  34. void CompilandDumper::dump(const PDBSymbolCompilandDetails &Symbol) {}
  35. void CompilandDumper::dump(const PDBSymbolCompilandEnv &Symbol) {}
  36. void CompilandDumper::start(const PDBSymbolCompiland &Symbol, bool Children) {
  37. std::string FullName = Symbol.getName();
  38. if (Printer.IsCompilandExcluded(FullName))
  39. return;
  40. Printer.NewLine();
  41. WithColor(Printer, PDB_ColorItem::Path).get() << FullName;
  42. if (!Children)
  43. return;
  44. auto ChildrenEnum = Symbol.findAllChildren();
  45. Printer.Indent();
  46. while (auto Child = ChildrenEnum->getNext())
  47. Child->dump(*this);
  48. Printer.Unindent();
  49. }
  50. void CompilandDumper::dump(const PDBSymbolData &Symbol) {
  51. if (Printer.IsSymbolExcluded(Symbol.getName()))
  52. return;
  53. Printer.NewLine();
  54. switch (auto LocType = Symbol.getLocationType()) {
  55. case PDB_LocType::Static:
  56. Printer << "data: ";
  57. WithColor(Printer, PDB_ColorItem::Address).get()
  58. << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "]";
  59. break;
  60. case PDB_LocType::Constant:
  61. Printer << "constant: ";
  62. WithColor(Printer, PDB_ColorItem::LiteralValue).get()
  63. << "[" << Symbol.getValue() << "]";
  64. break;
  65. default:
  66. Printer << "data(unexpected type=" << LocType << ")";
  67. }
  68. Printer << " ";
  69. WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
  70. }
  71. void CompilandDumper::dump(const PDBSymbolFunc &Symbol) {
  72. if (Symbol.getLength() == 0)
  73. return;
  74. if (Printer.IsSymbolExcluded(Symbol.getName()))
  75. return;
  76. Printer.NewLine();
  77. FunctionDumper Dumper(Printer);
  78. Dumper.start(Symbol, FunctionDumper::PointerType::None);
  79. }
  80. void CompilandDumper::dump(const PDBSymbolLabel &Symbol) {
  81. if (Printer.IsSymbolExcluded(Symbol.getName()))
  82. return;
  83. Printer.NewLine();
  84. Printer << "label ";
  85. WithColor(Printer, PDB_ColorItem::Address).get()
  86. << "[" << format_hex(Symbol.getVirtualAddress(), 10) << "] ";
  87. WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
  88. }
  89. void CompilandDumper::dump(const PDBSymbolThunk &Symbol) {
  90. if (Printer.IsSymbolExcluded(Symbol.getName()))
  91. return;
  92. Printer.NewLine();
  93. Printer << "thunk ";
  94. PDB_ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
  95. uint64_t VA = Symbol.getVirtualAddress();
  96. if (Ordinal == PDB_ThunkOrdinal::TrampIncremental) {
  97. uint64_t Target = Symbol.getTargetVirtualAddress();
  98. WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(VA, 10);
  99. Printer << " -> ";
  100. WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10);
  101. } else {
  102. WithColor(Printer, PDB_ColorItem::Address).get()
  103. << "[" << format_hex(VA, 10) << " - "
  104. << format_hex(VA + Symbol.getLength(), 10) << "]";
  105. }
  106. Printer << " (";
  107. WithColor(Printer, PDB_ColorItem::Register).get() << Ordinal;
  108. Printer << ") ";
  109. std::string Name = Symbol.getName();
  110. if (!Name.empty())
  111. WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
  112. }
  113. void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol) {}
  114. void CompilandDumper::dump(const PDBSymbolUnknown &Symbol) {
  115. Printer.NewLine();
  116. Printer << "unknown (" << Symbol.getSymTag() << ")";
  117. }