1 //===-- ModuleDebugInfoPrinter.cpp - Prints module debug info metadata ----===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This pass decodes the debug info metadata in a module and prints in a
11 // (sufficiently-prepared-) human-readable form.
13 // For example, run this pass from opt along with the -analyze option, and
14 // it'll print to standard output.
16 //===----------------------------------------------------------------------===//
18 #include "llvm/Analysis/Passes.h"
19 #include "llvm/Analysis/DebugInfo.h"
20 #include "llvm/Assembly/Writer.h"
21 #include "llvm/Pass.h"
22 #include "llvm/Function.h"
23 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/raw_ostream.h"
25 #include "llvm/ADT/Statistic.h"
29 class ModuleDebugInfoPrinter : public ModulePass {
30 DebugInfoFinder Finder;
32 static char ID; // Pass identification, replacement for typeid
33 ModuleDebugInfoPrinter() : ModulePass(&ID) {}
35 virtual bool runOnModule(Module &M);
37 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
40 virtual void print(raw_ostream &O, const Module *M) const;
44 char ModuleDebugInfoPrinter::ID = 0;
45 static RegisterPass<ModuleDebugInfoPrinter>
47 "Decodes module-level debug info", false, true);
49 ModulePass *llvm::createModuleDebugInfoPrinterPass() {
50 return new ModuleDebugInfoPrinter();
53 bool ModuleDebugInfoPrinter::runOnModule(Module &M) {
54 Finder.processModule(M);
58 void ModuleDebugInfoPrinter::print(raw_ostream &O, const Module *M) const {
59 for (DebugInfoFinder::iterator I = Finder.compile_unit_begin(),
60 E = Finder.compile_unit_end(); I != E; ++I) {
61 O << "Compile Unit: ";
62 DICompileUnit(*I).print(O);
66 for (DebugInfoFinder::iterator I = Finder.subprogram_begin(),
67 E = Finder.subprogram_end(); I != E; ++I) {
69 DISubprogram(*I).print(O);
73 for (DebugInfoFinder::iterator I = Finder.global_variable_begin(),
74 E = Finder.global_variable_end(); I != E; ++I) {
75 O << "GlobalVariable: ";
76 DIGlobalVariable(*I).print(O);
80 for (DebugInfoFinder::iterator I = Finder.type_begin(),
81 E = Finder.type_end(); I != E; ++I) {