blob: b64847b14dd104fa257b94472de7c73af5177efc [file] [log] [blame]
Dan Gohmanfb64b5d2010-05-07 16:22:32 +00001//===-- 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"
Chandler Carruthed0881b2012-12-03 16:50:05 +000019#include "llvm/ADT/Statistic.h"
Bill Wendlinge38859d2012-06-28 00:05:13 +000020#include "llvm/DebugInfo.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000021#include "llvm/IR/Function.h"
Bill Wendlinge38859d2012-06-28 00:05:13 +000022#include "llvm/Pass.h"
Dan Gohmanfb64b5d2010-05-07 16:22:32 +000023#include "llvm/Support/ErrorHandling.h"
24#include "llvm/Support/raw_ostream.h"
Dan Gohmanfb64b5d2010-05-07 16:22:32 +000025using namespace llvm;
26
27namespace {
28 class ModuleDebugInfoPrinter : public ModulePass {
29 DebugInfoFinder Finder;
30 public:
31 static char ID; // Pass identification, replacement for typeid
Owen Anderson6c18d1a2010-10-19 17:21:58 +000032 ModuleDebugInfoPrinter() : ModulePass(ID) {
33 initializeModuleDebugInfoPrinterPass(*PassRegistry::getPassRegistry());
34 }
Dan Gohmanfb64b5d2010-05-07 16:22:32 +000035
Craig Toppere9ba7592014-03-05 07:30:04 +000036 bool runOnModule(Module &M) override;
Dan Gohmanfb64b5d2010-05-07 16:22:32 +000037
Craig Toppere9ba7592014-03-05 07:30:04 +000038 void getAnalysisUsage(AnalysisUsage &AU) const override {
Dan Gohmanfb64b5d2010-05-07 16:22:32 +000039 AU.setPreservesAll();
40 }
Craig Toppere9ba7592014-03-05 07:30:04 +000041 void print(raw_ostream &O, const Module *M) const override;
Dan Gohmanfb64b5d2010-05-07 16:22:32 +000042 };
43}
44
45char ModuleDebugInfoPrinter::ID = 0;
Owen Andersona57b97e2010-07-21 22:09:45 +000046INITIALIZE_PASS(ModuleDebugInfoPrinter, "module-debuginfo",
Owen Andersondf7a4f22010-10-07 22:25:06 +000047 "Decodes module-level debug info", false, true)
Dan Gohmanfb64b5d2010-05-07 16:22:32 +000048
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 (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);
63 O << '\n';
64 }
65
66 for (DebugInfoFinder::iterator I = Finder.subprogram_begin(),
67 E = Finder.subprogram_end(); I != E; ++I) {
68 O << "Subprogram: ";
69 DISubprogram(*I).print(O);
70 O << '\n';
71 }
72
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);
77 O << '\n';
78 }
79
80 for (DebugInfoFinder::iterator I = Finder.type_begin(),
81 E = Finder.type_end(); I != E; ++I) {
82 O << "Type: ";
83 DIType(*I).print(O);
84 O << '\n';
85 }
86}