LLVM API Documentation

ModuleDebugInfoPrinter.cpp
Go to the documentation of this file.
00001 //===-- ModuleDebugInfoPrinter.cpp - Prints module debug info metadata ----===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This pass decodes the debug info metadata in a module and prints in a
00011 // (sufficiently-prepared-) human-readable form.
00012 //
00013 // For example, run this pass from opt along with the -analyze option, and
00014 // it'll print to standard output.
00015 //
00016 //===----------------------------------------------------------------------===//
00017 
00018 #include "llvm/Analysis/Passes.h"
00019 #include "llvm/ADT/Statistic.h"
00020 #include "llvm/IR/DebugInfo.h"
00021 #include "llvm/IR/Function.h"
00022 #include "llvm/Pass.h"
00023 #include "llvm/Support/ErrorHandling.h"
00024 #include "llvm/Support/raw_ostream.h"
00025 using namespace llvm;
00026 
00027 namespace {
00028   class ModuleDebugInfoPrinter : public ModulePass {
00029     DebugInfoFinder Finder;
00030   public:
00031     static char ID; // Pass identification, replacement for typeid
00032     ModuleDebugInfoPrinter() : ModulePass(ID) {
00033       initializeModuleDebugInfoPrinterPass(*PassRegistry::getPassRegistry());
00034     }
00035 
00036     bool runOnModule(Module &M) override;
00037 
00038     void getAnalysisUsage(AnalysisUsage &AU) const override {
00039       AU.setPreservesAll();
00040     }
00041     void print(raw_ostream &O, const Module *M) const override;
00042   };
00043 }
00044 
00045 char ModuleDebugInfoPrinter::ID = 0;
00046 INITIALIZE_PASS(ModuleDebugInfoPrinter, "module-debuginfo",
00047                 "Decodes module-level debug info", false, true)
00048 
00049 ModulePass *llvm::createModuleDebugInfoPrinterPass() {
00050   return new ModuleDebugInfoPrinter();
00051 }
00052 
00053 bool ModuleDebugInfoPrinter::runOnModule(Module &M) {
00054   Finder.processModule(M);
00055   return false;
00056 }
00057 
00058 void ModuleDebugInfoPrinter::print(raw_ostream &O, const Module *M) const {
00059   for (DICompileUnit CU : Finder.compile_units()) {
00060     O << "Compile Unit: ";
00061     CU.print(O);
00062     O << '\n';
00063   }
00064 
00065   for (DISubprogram S : Finder.subprograms()) {
00066     O << "Subprogram: ";
00067     S.print(O);
00068     O << '\n';
00069   }
00070 
00071   for (DIGlobalVariable GV : Finder.global_variables()) {
00072     O << "GlobalVariable: ";
00073     GV.print(O);
00074     O << '\n';
00075   }
00076 
00077   for (DIType T : Finder.types()) {
00078     O << "Type: ";
00079     T.print(O);
00080     O << '\n';
00081   }
00082 }