Add a simple breakpoint location printer. This will be used by upcoming "debug info in optimized code" quality test harness to set breakpoints at "interesting" locations.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121078 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel 2010-12-07 00:33:43 +00:00
parent 85f2ecc697
commit f5f2300d24

View File

@ -18,6 +18,7 @@
#include "llvm/CallGraphSCCPass.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Assembly/PrintModulePass.h"
#include "llvm/Analysis/DebugInfo.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/RegionPass.h"
@ -128,6 +129,10 @@ QuietA("quiet", cl::desc("Alias for -q"), cl::aliasopt(Quiet));
static cl::opt<bool>
AnalyzeOnly("analyze", cl::desc("Only perform analysis, no optimization"));
static cl::opt<bool>
PrintBreakpoints("print-breakpoints-for-testing",
cl::desc("Print select breakpoints location for testing"));
static cl::opt<std::string>
DefaultDataLayout("default-data-layout",
cl::desc("data layout string to use if not specified by module"),
@ -334,6 +339,41 @@ struct BasicBlockPassPrinter : public BasicBlockPass {
};
char BasicBlockPassPrinter::ID = 0;
struct BreakpointPrinter : public FunctionPass {
raw_ostream &Out;
static char ID;
BreakpointPrinter(raw_ostream &out)
: FunctionPass(ID), Out(out) {
}
virtual bool runOnFunction(Function &F) {
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
BasicBlock::const_iterator BI = I->end();
--BI;
do {
const Instruction *In = BI;
const DebugLoc DL = In->getDebugLoc();
if (!DL.isUnknown()) {
DIScope S(DL.getScope(getGlobalContext()));
Out << S.getFilename() << " " << DL.getLine() << "\n";
break;
}
--BI;
} while (BI != I->begin());
break;
}
return false;
}
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
}
};
char BreakpointPrinter::ID = 0;
inline void addPass(PassManagerBase &PM, Pass *P) {
// Add the pass to the pass manager...
PM.add(P);
@ -509,6 +549,24 @@ int main(int argc, char **argv) {
FPasses->add(new TargetData(*TD));
}
if (PrintBreakpoints) {
// Default to standard output.
if (!Out) {
if (OutputFilename.empty())
OutputFilename = "-";
std::string ErrorInfo;
Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
raw_fd_ostream::F_Binary));
if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n';
return 1;
}
}
Passes.add(new BreakpointPrinter(Out->os()));
NoOutput = true;
}
// If the -strip-debug command line option was specified, add it. If
// -std-compile-opts was also specified, it will handle StripDebug.
if (StripDebug && !StandardCompileOpts)
@ -623,7 +681,7 @@ int main(int argc, char **argv) {
Passes.run(*M.get());
// Declare success.
if (!NoOutput)
if (!NoOutput || PrintBreakpoints)
Out->keep();
return 0;