ModuleDebugInfoPrinter.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //===-- ModuleDebugInfoPrinter.cpp - Prints module debug info metadata ----===//
  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. //
  10. // This pass decodes the debug info metadata in a module and prints in a
  11. // (sufficiently-prepared-) human-readable form.
  12. //
  13. // For example, run this pass from opt along with the -analyze option, and
  14. // it'll print to standard output.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #include "llvm/Analysis/Passes.h"
  18. #include "llvm/ADT/Statistic.h"
  19. #include "llvm/Assembly/Writer.h"
  20. #include "llvm/DebugInfo.h"
  21. #include "llvm/Function.h"
  22. #include "llvm/Pass.h"
  23. #include "llvm/Support/ErrorHandling.h"
  24. #include "llvm/Support/raw_ostream.h"
  25. using namespace llvm;
  26. namespace {
  27. class ModuleDebugInfoPrinter : public ModulePass {
  28. DebugInfoFinder Finder;
  29. public:
  30. static char ID; // Pass identification, replacement for typeid
  31. ModuleDebugInfoPrinter() : ModulePass(ID) {
  32. initializeModuleDebugInfoPrinterPass(*PassRegistry::getPassRegistry());
  33. }
  34. virtual bool runOnModule(Module &M);
  35. virtual void getAnalysisUsage(AnalysisUsage &AU) const {
  36. AU.setPreservesAll();
  37. }
  38. virtual void print(raw_ostream &O, const Module *M) const;
  39. };
  40. }
  41. char ModuleDebugInfoPrinter::ID = 0;
  42. INITIALIZE_PASS(ModuleDebugInfoPrinter, "module-debuginfo",
  43. "Decodes module-level debug info", false, true)
  44. ModulePass *llvm::createModuleDebugInfoPrinterPass() {
  45. return new ModuleDebugInfoPrinter();
  46. }
  47. bool ModuleDebugInfoPrinter::runOnModule(Module &M) {
  48. Finder.processModule(M);
  49. return false;
  50. }
  51. void ModuleDebugInfoPrinter::print(raw_ostream &O, const Module *M) const {
  52. for (DebugInfoFinder::iterator I = Finder.compile_unit_begin(),
  53. E = Finder.compile_unit_end(); I != E; ++I) {
  54. O << "Compile Unit: ";
  55. DICompileUnit(*I).print(O);
  56. O << '\n';
  57. }
  58. for (DebugInfoFinder::iterator I = Finder.subprogram_begin(),
  59. E = Finder.subprogram_end(); I != E; ++I) {
  60. O << "Subprogram: ";
  61. DISubprogram(*I).print(O);
  62. O << '\n';
  63. }
  64. for (DebugInfoFinder::iterator I = Finder.global_variable_begin(),
  65. E = Finder.global_variable_end(); I != E; ++I) {
  66. O << "GlobalVariable: ";
  67. DIGlobalVariable(*I).print(O);
  68. O << '\n';
  69. }
  70. for (DebugInfoFinder::iterator I = Finder.type_begin(),
  71. E = Finder.type_end(); I != E; ++I) {
  72. O << "Type: ";
  73. DIType(*I).print(O);
  74. O << '\n';
  75. }
  76. }