ModuleDebugInfoPrinter.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/DebugInfo.h"
  20. #include "llvm/IR/Function.h"
  21. #include "llvm/Pass.h"
  22. #include "llvm/Support/ErrorHandling.h"
  23. #include "llvm/Support/raw_ostream.h"
  24. using namespace llvm;
  25. namespace {
  26. class ModuleDebugInfoPrinter : public ModulePass {
  27. DebugInfoFinder Finder;
  28. public:
  29. static char ID; // Pass identification, replacement for typeid
  30. ModuleDebugInfoPrinter() : ModulePass(ID) {
  31. initializeModuleDebugInfoPrinterPass(*PassRegistry::getPassRegistry());
  32. }
  33. virtual bool runOnModule(Module &M);
  34. virtual void getAnalysisUsage(AnalysisUsage &AU) const {
  35. AU.setPreservesAll();
  36. }
  37. virtual void print(raw_ostream &O, const Module *M) const;
  38. };
  39. }
  40. char ModuleDebugInfoPrinter::ID = 0;
  41. INITIALIZE_PASS(ModuleDebugInfoPrinter, "module-debuginfo",
  42. "Decodes module-level debug info", false, true)
  43. ModulePass *llvm::createModuleDebugInfoPrinterPass() {
  44. return new ModuleDebugInfoPrinter();
  45. }
  46. bool ModuleDebugInfoPrinter::runOnModule(Module &M) {
  47. Finder.processModule(M);
  48. return false;
  49. }
  50. void ModuleDebugInfoPrinter::print(raw_ostream &O, const Module *M) const {
  51. for (DebugInfoFinder::iterator I = Finder.compile_unit_begin(),
  52. E = Finder.compile_unit_end(); I != E; ++I) {
  53. O << "Compile Unit: ";
  54. DICompileUnit(*I).print(O);
  55. O << '\n';
  56. }
  57. for (DebugInfoFinder::iterator I = Finder.subprogram_begin(),
  58. E = Finder.subprogram_end(); I != E; ++I) {
  59. O << "Subprogram: ";
  60. DISubprogram(*I).print(O);
  61. O << '\n';
  62. }
  63. for (DebugInfoFinder::iterator I = Finder.global_variable_begin(),
  64. E = Finder.global_variable_end(); I != E; ++I) {
  65. O << "GlobalVariable: ";
  66. DIGlobalVariable(*I).print(O);
  67. O << '\n';
  68. }
  69. for (DebugInfoFinder::iterator I = Finder.type_begin(),
  70. E = Finder.type_end(); I != E; ++I) {
  71. O << "Type: ";
  72. DIType(*I).print(O);
  73. O << '\n';
  74. }
  75. }