aboutsummaryrefslogtreecommitdiffstats
path: root/tools/llvm-dis
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2011-03-11 18:07:33 +0000
committerDevang Patel <dpatel@apple.com>2011-03-11 18:07:33 +0000
commit027f0995d4f2a73836fe3225514c507f5c63deae (patch)
treebfc85bdd7c8f0d79b56b6c46fe7532b864055b30 /tools/llvm-dis
parenteb582d7ba202e06ea339def0b610bc31565250da (diff)
downloadexternal_llvm-027f0995d4f2a73836fe3225514c507f5c63deae.zip
external_llvm-027f0995d4f2a73836fe3225514c507f5c63deae.tar.gz
external_llvm-027f0995d4f2a73836fe3225514c507f5c63deae.tar.bz2
While printing annotations, print line number and variable name if debug info is present.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127470 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-dis')
-rw-r--r--tools/llvm-dis/Makefile2
-rw-r--r--tools/llvm-dis/llvm-dis.cpp53
2 files changed, 50 insertions, 5 deletions
diff --git a/tools/llvm-dis/Makefile b/tools/llvm-dis/Makefile
index 22c9ecc..be71100 100644
--- a/tools/llvm-dis/Makefile
+++ b/tools/llvm-dis/Makefile
@@ -9,7 +9,7 @@
LEVEL = ../..
TOOLNAME = llvm-dis
-LINK_COMPONENTS := bitreader
+LINK_COMPONENTS := bitreader analysis
# This tool has no plugins, optimize startup time.
TOOL_NO_EXPORTS = 1
diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp
index b4977ce..d1ac9de 100644
--- a/tools/llvm-dis/llvm-dis.cpp
+++ b/tools/llvm-dis/llvm-dis.cpp
@@ -19,7 +19,9 @@
#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Type.h"
+#include "llvm/IntrinsicInst.h"
#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/Analysis/DebugInfo.h"
#include "llvm/Assembly/AssemblyAnnotationWriter.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FormattedStream.h"
@@ -50,6 +52,16 @@ ShowAnnotations("show-annotations",
namespace {
+static void printDebugLoc(const DebugLoc &DL, formatted_raw_ostream &OS) {
+ OS << DL.getLine() << ":" << DL.getCol();
+ if (MDNode *N = DL.getInlinedAt(getGlobalContext())) {
+ DebugLoc IDL = DebugLoc::getFromDILocation(N);
+ if (!IDL.isUnknown()) {
+ OS << "@";
+ printDebugLoc(IDL,OS);
+ }
+ }
+}
class CommentWriter : public AssemblyAnnotationWriter {
public:
void emitFunctionAnnot(const Function *F,
@@ -58,10 +70,43 @@ public:
OS << '\n';
}
void printInfoComment(const Value &V, formatted_raw_ostream &OS) {
- if (V.getType()->isVoidTy()) return;
-
- OS.PadToColumn(50);
- OS << "; [#uses=" << V.getNumUses() << ']'; // Output # uses
+ bool Padded = false;
+ if (!V.getType()->isVoidTy()) {
+ OS.PadToColumn(50);
+ Padded = true;
+ OS << "; [#uses=" << V.getNumUses() << ']'; // Output # uses
+ }
+ if (const Instruction *I = dyn_cast<Instruction>(&V)) {
+ const DebugLoc &DL = I->getDebugLoc();
+ if (!DL.isUnknown()) {
+ if (!Padded) {
+ OS.PadToColumn(50);
+ Padded = true;
+ OS << ";";
+ }
+ OS << " [debug line = ";
+ printDebugLoc(DL,OS);
+ OS << "]";
+ }
+ if (const DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(I)) {
+ DIVariable Var(DDI->getVariable());
+ if (!Padded) {
+ OS.PadToColumn(50);
+ Padded = true;
+ OS << ";";
+ }
+ OS << " [debug variable = " << Var.getName() << "]";
+ }
+ else if (const DbgValueInst *DVI = dyn_cast<DbgValueInst>(I)) {
+ DIVariable Var(DVI->getVariable());
+ if (!Padded) {
+ OS.PadToColumn(50);
+ Padded = true;
+ OS << ";";
+ }
+ OS << " [debug variable = " << Var.getName() << "]";
+ }
+ }
}
};