ModuleDebugInfoPrinter.cpp revision 36b56886974eae4f9c5ebc96befd3e7bfe5de338
16e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)//===-- ModuleDebugInfoPrinter.cpp - Prints module debug info metadata ----===//
26e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)//
36e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)//                     The LLVM Compiler Infrastructure
46e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)//
56e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// This file is distributed under the University of Illinois Open Source
66e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// License. See LICENSE.TXT for details.
76e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)//
86e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)//===----------------------------------------------------------------------===//
96e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)//
106e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// This pass decodes the debug info metadata in a module and prints in a
116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// (sufficiently-prepared-) human-readable form.
126e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)//
136e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// For example, run this pass from opt along with the -analyze option, and
146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// it'll print to standard output.
156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)//
166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)//===----------------------------------------------------------------------===//
176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
186e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "llvm/Analysis/Passes.h"
196e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "llvm/ADT/Statistic.h"
206e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "llvm/IR/DebugInfo.h"
216e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "llvm/IR/Function.h"
226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "llvm/Pass.h"
23#include "llvm/Support/ErrorHandling.h"
24#include "llvm/Support/raw_ostream.h"
25using namespace llvm;
26
27namespace {
28  class ModuleDebugInfoPrinter : public ModulePass {
29    DebugInfoFinder Finder;
30  public:
31    static char ID; // Pass identification, replacement for typeid
32    ModuleDebugInfoPrinter() : ModulePass(ID) {
33      initializeModuleDebugInfoPrinterPass(*PassRegistry::getPassRegistry());
34    }
35
36    bool runOnModule(Module &M) override;
37
38    void getAnalysisUsage(AnalysisUsage &AU) const override {
39      AU.setPreservesAll();
40    }
41    void print(raw_ostream &O, const Module *M) const override;
42  };
43}
44
45char ModuleDebugInfoPrinter::ID = 0;
46INITIALIZE_PASS(ModuleDebugInfoPrinter, "module-debuginfo",
47                "Decodes module-level debug info", false, true)
48
49ModulePass *llvm::createModuleDebugInfoPrinterPass() {
50  return new ModuleDebugInfoPrinter();
51}
52
53bool ModuleDebugInfoPrinter::runOnModule(Module &M) {
54  Finder.processModule(M);
55  return false;
56}
57
58void ModuleDebugInfoPrinter::print(raw_ostream &O, const Module *M) const {
59  for (DICompileUnit CU : Finder.compile_units()) {
60    O << "Compile Unit: ";
61    CU.print(O);
62    O << '\n';
63  }
64
65  for (DISubprogram S : Finder.subprograms()) {
66    O << "Subprogram: ";
67    S.print(O);
68    O << '\n';
69  }
70
71  for (DIGlobalVariable GV : Finder.global_variables()) {
72    O << "GlobalVariable: ";
73    GV.print(O);
74    O << '\n';
75  }
76
77  for (DIType T : Finder.types()) {
78    O << "Type: ";
79    T.print(O);
80    O << '\n';
81  }
82}
83