Clean up this file fixing 80-column violations, bad formatting, etc. No functionality change.

llvm-svn: 71781
This commit is contained in:
Bill Wendling 2009-05-14 18:16:46 +00:00
parent 4d226cf45f
commit 3fe4cf745b
1 changed files with 69 additions and 60 deletions

View File

@ -1,4 +1,4 @@
//===- DbgInfoPrinter.cpp - Print debug info in a human readable form -----==// //===- DbgInfoPrinter.cpp - Print debug info in a human readable form ------==//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@ -9,150 +9,159 @@
// //
// This file implements a pass that prints instructions, and associated debug // This file implements a pass that prints instructions, and associated debug
// info: // info:
//
// - source/line/col information // - source/line/col information
// - original variable name // - original variable name
// - original type name // - original type name
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "llvm/Function.h" #include "llvm/Function.h"
#include "llvm/Module.h"
#include "llvm/Value.h"
#include "llvm/IntrinsicInst.h" #include "llvm/IntrinsicInst.h"
#include "llvm/Assembly/Writer.h" #include "llvm/Assembly/Writer.h"
#include "llvm/Analysis/DebugInfo.h" #include "llvm/Analysis/DebugInfo.h"
#include "llvm/Analysis/Passes.h" #include "llvm/Analysis/Passes.h"
#include "llvm/Analysis/ValueTracking.h" #include "llvm/Analysis/ValueTracking.h"
#include "llvm/Support/CFG.h" #include "llvm/Support/CFG.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
using namespace llvm; using namespace llvm;
static cl::opt<bool> static cl::opt<bool>
PrintDirectory("print-fullpath", cl::desc("Print fullpath when printing debug info"), cl::Hidden); PrintDirectory("print-fullpath",
cl::desc("Print fullpath when printing debug info"),
cl::Hidden);
namespace { namespace {
struct VISIBILITY_HIDDEN PrintDbgInfo : public FunctionPass { class VISIBILITY_HIDDEN PrintDbgInfo : public FunctionPass {
private: raw_ostream &Out;
raw_ostream &Out; void printStopPoint(const DbgStopPointInst *DSI);
void printStopPoint(const DbgStopPointInst *DSI); void printFuncStart(const DbgFuncStartInst *FS);
void printFuncStart(const DbgFuncStartInst *FS); void printVariableDeclaration(const Value *V);
void printVariableDeclaration(const Value *V); public:
public: static char ID; // Pass identification
static char ID; // Pass identification PrintDbgInfo() : FunctionPass(&ID), Out(outs()) {}
PrintDbgInfo() : FunctionPass(&ID), Out(outs()) {}
virtual bool runOnFunction(Function &F); virtual bool runOnFunction(Function &F);
virtual void getAnalysisUsage(AnalysisUsage &AU) const { virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll(); AU.setPreservesAll();
} }
};
}; char PrintDbgInfo::ID = 0;
char PrintDbgInfo::ID = 0; static RegisterPass<PrintDbgInfo> X("print-dbginfo",
static RegisterPass<PrintDbgInfo> X("print-dbginfo", "Print debug info in human readable form");
"Print debug info in human readable form");
} }
FunctionPass *llvm::createDbgInfoPrinterPass() { return new PrintDbgInfo(); } FunctionPass *llvm::createDbgInfoPrinterPass() { return new PrintDbgInfo(); }
void PrintDbgInfo::printVariableDeclaration(const Value *V) void PrintDbgInfo::printVariableDeclaration(const Value *V) {
{
std::string DisplayName, File, Directory, Type; std::string DisplayName, File, Directory, Type;
unsigned LineNo; unsigned LineNo;
if (getLocationInfo(V, DisplayName, Type, LineNo, File, Directory)) {
Out << "; "; if (!getLocationInfo(V, DisplayName, Type, LineNo, File, Directory))
WriteAsOperand(Out, V, false, 0); return;
Out << " is variable " << DisplayName
Out << "; ";
WriteAsOperand(Out, V, false, 0);
Out << " is variable " << DisplayName
<< " of type " << Type << " declared at "; << " of type " << Type << " declared at ";
if (PrintDirectory) {
Out << Directory << "/"; if (PrintDirectory)
} Out << Directory << "/";
Out << File << ":" << LineNo << "\n";
} Out << File << ":" << LineNo << "\n";
} }
void PrintDbgInfo::printStopPoint(const DbgStopPointInst *DSI) void PrintDbgInfo::printStopPoint(const DbgStopPointInst *DSI) {
{
if (PrintDirectory) { if (PrintDirectory) {
std::string dir; std::string dir;
GetConstantStringInfo(DSI->getDirectory(), dir); GetConstantStringInfo(DSI->getDirectory(), dir);
Out << dir << "/"; Out << dir << "/";
} }
std::string file; std::string file;
GetConstantStringInfo(DSI->getFileName(), file); GetConstantStringInfo(DSI->getFileName(), file);
Out << file << ":" << DSI->getLine(); Out << file << ":" << DSI->getLine();
if (unsigned Col = DSI->getColumn()) {
if (unsigned Col = DSI->getColumn())
Out << ":" << Col; Out << ":" << Col;
}
} }
void PrintDbgInfo::printFuncStart(const DbgFuncStartInst *FS) void PrintDbgInfo::printFuncStart(const DbgFuncStartInst *FS) {
{
DISubprogram Subprogram(cast<GlobalVariable>(FS->getSubprogram())); DISubprogram Subprogram(cast<GlobalVariable>(FS->getSubprogram()));
std::string Res1, Res2; std::string Res1, Res2;
Out << ";fully qualified function name: " << Subprogram.getDisplayName(Res1) Out << "; fully qualified function name: " << Subprogram.getDisplayName(Res1)
<< " return type: " << Subprogram.getType().getName(Res2) << " return type: " << Subprogram.getType().getName(Res2)
<< " at line " << Subprogram.getLineNumber() << " at line " << Subprogram.getLineNumber()
<< "\n\n"; << "\n\n";
} }
bool PrintDbgInfo::runOnFunction(Function &F) bool PrintDbgInfo::runOnFunction(Function &F) {
{
if (F.isDeclaration()) if (F.isDeclaration())
return false; return false;
Out << "function " << F.getName() << "\n\n"; Out << "function " << F.getName() << "\n\n";
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) { for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
BasicBlock *BB = I; BasicBlock *BB = I;
if (I != F.begin() && (pred_begin(BB) == pred_end(BB))) if (I != F.begin() && (pred_begin(BB) == pred_end(BB)))
// Skip dead blocks. // Skip dead blocks.
continue; continue;
const DbgStopPointInst *DSI = findBBStopPoint(BB); const DbgStopPointInst *DSI = findBBStopPoint(BB);
Out << BB->getName(); Out << BB->getName();
Out << ":"; Out << ":";
if (DSI) { if (DSI) {
Out << "; ("; Out << "; (";
printStopPoint(DSI); printStopPoint(DSI);
Out << ")"; Out << ")";
} }
Out << "\n"; Out << "\n";
// A dbgstoppoint's information is valid until we encounter a new one. // A dbgstoppoint's information is valid until we encounter a new one.
const DbgStopPointInst *LastDSP = DSI; const DbgStopPointInst *LastDSP = DSI;
bool printed = DSI != 0; bool Printed = DSI != 0;
for (BasicBlock::const_iterator i = BB->begin(), e = BB->end(); i != e; ++i) { for (BasicBlock::const_iterator i = BB->begin(), e = BB->end();
i != e; ++i) {
if (isa<DbgInfoIntrinsic>(i)) { if (isa<DbgInfoIntrinsic>(i)) {
if ((DSI = dyn_cast<DbgStopPointInst>(i))) { if ((DSI = dyn_cast<DbgStopPointInst>(i))) {
if (DSI->getContext() == LastDSP->getContext() && if (DSI->getContext() == LastDSP->getContext() &&
DSI->getLineValue() == LastDSP->getLineValue() && DSI->getLineValue() == LastDSP->getLineValue() &&
DSI->getColumnValue() == LastDSP->getColumnValue()) { DSI->getColumnValue() == LastDSP->getColumnValue())
// Don't print same location twice. // Don't print same location twice.
continue; continue;
}
LastDSP = cast<DbgStopPointInst>(i);
// Don't print consecutive stoppoints, use a flag
// to know which one we printed.
printed = false;
LastDSP = cast<DbgStopPointInst>(i);
// Don't print consecutive stoppoints, use a flag to know which one we
// printed.
Printed = false;
} else if (const DbgFuncStartInst *FS = dyn_cast<DbgFuncStartInst>(i)) { } else if (const DbgFuncStartInst *FS = dyn_cast<DbgFuncStartInst>(i)) {
printFuncStart(FS); printFuncStart(FS);
} }
} else { } else {
if (!printed && LastDSP) { if (!Printed && LastDSP) {
Out << "; "; Out << "; ";
printStopPoint(LastDSP); printStopPoint(LastDSP);
Out << "\n"; Out << "\n";
printed = true; Printed = true;
} }
Out << *i; Out << *i;
printVariableDeclaration(i); printVariableDeclaration(i);
if (const User *U = dyn_cast<User>(i)) { if (const User *U = dyn_cast<User>(i)) {
for(unsigned i=0;i<U->getNumOperands();i++) { for(unsigned i=0;i<U->getNumOperands();i++)
printVariableDeclaration(U->getOperand(i)); printVariableDeclaration(U->getOperand(i));
}
} }
} }
} }
} }
return false; return false;
} }