summaryrefslogtreecommitdiff
path: root/tools/opt
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2010-12-07 00:33:43 +0000
committerDevang Patel <dpatel@apple.com>2010-12-07 00:33:43 +0000
commitf5f2300d2489ba1110b919abd18714ad707ec9a8 (patch)
tree42138a87559af8f2152663973f25f7d78226c3b8 /tools/opt
parent85f2ecc697a8ca6c8cf08093054cbbb9d2060ccf (diff)
downloadllvm-f5f2300d2489ba1110b919abd18714ad707ec9a8.tar.gz
llvm-f5f2300d2489ba1110b919abd18714ad707ec9a8.tar.bz2
llvm-f5f2300d2489ba1110b919abd18714ad707ec9a8.tar.xz
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
Diffstat (limited to 'tools/opt')
-rw-r--r--tools/opt/opt.cpp60
1 files changed, 59 insertions, 1 deletions
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index 2b6109f2bc..c1e0ad128b 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -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;