LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ModuleDebugInfoPrinter.cpp
Go to the documentation of this file.
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 
18 #include "llvm/Analysis/Passes.h"
19 #include "llvm/ADT/Statistic.h"
20 #include "llvm/Assembly/Writer.h"
21 #include "llvm/DebugInfo.h"
22 #include "llvm/IR/Function.h"
23 #include "llvm/Pass.h"
26 using namespace llvm;
27 
28 namespace {
29  class ModuleDebugInfoPrinter : public ModulePass {
30  DebugInfoFinder Finder;
31  public:
32  static char ID; // Pass identification, replacement for typeid
33  ModuleDebugInfoPrinter() : ModulePass(ID) {
35  }
36 
37  virtual bool runOnModule(Module &M);
38 
39  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
40  AU.setPreservesAll();
41  }
42  virtual void print(raw_ostream &O, const Module *M) const;
43  };
44 }
45 
47 INITIALIZE_PASS(ModuleDebugInfoPrinter, "module-debuginfo",
48  "Decodes module-level debug info", false, true)
49 
51  return new ModuleDebugInfoPrinter();
52 }
53 
54 bool ModuleDebugInfoPrinter::runOnModule(Module &M) {
55  Finder.processModule(M);
56  return false;
57 }
58 
59 void ModuleDebugInfoPrinter::print(raw_ostream &O, const Module *M) const {
60  for (DebugInfoFinder::iterator I = Finder.compile_unit_begin(),
61  E = Finder.compile_unit_end(); I != E; ++I) {
62  O << "Compile Unit: ";
63  DICompileUnit(*I).print(O);
64  O << '\n';
65  }
66 
67  for (DebugInfoFinder::iterator I = Finder.subprogram_begin(),
68  E = Finder.subprogram_end(); I != E; ++I) {
69  O << "Subprogram: ";
70  DISubprogram(*I).print(O);
71  O << '\n';
72  }
73 
74  for (DebugInfoFinder::iterator I = Finder.global_variable_begin(),
75  E = Finder.global_variable_end(); I != E; ++I) {
76  O << "GlobalVariable: ";
77  DIGlobalVariable(*I).print(O);
78  O << '\n';
79  }
80 
81  for (DebugInfoFinder::iterator I = Finder.type_begin(),
82  E = Finder.type_end(); I != E; ++I) {
83  O << "Type: ";
84  DIType(*I).print(O);
85  O << '\n';
86  }
87 }
static PassRegistry * getPassRegistry()
The main container class for the LLVM Intermediate Representation.
Definition: Module.h:112
INITIALIZE_PASS(ModuleDebugInfoPrinter,"module-debuginfo","Decodes module-level debug info", false, true) ModulePass *llvm
ID
LLVM Calling Convention Representation.
Definition: CallingConv.h:26
DISubprogram - This is a wrapper for a subprogram (e.g. a function).
Definition: DebugInfo.h:429
void initializeModuleDebugInfoPrinterPass(PassRegistry &)
DIGlobalVariable - This is a wrapper for a global variable.
Definition: DebugInfo.h:572
ModulePass * createModuleDebugInfoPrinterPass()
void print(raw_ostream &OS) const
print - print descriptor.
Definition: DebugInfo.cpp:1201
#define I(x, y, z)
Definition: MD5.cpp:54
void print(raw_ostream &O, AssemblyAnnotationWriter *AAW=0) const
Definition: AsmWriter.cpp:2162
DICompileUnit - A wrapper for a compile unit.
Definition: DebugInfo.h:402