diff options
| author | Devang Patel <dpatel@apple.com> | 2011-08-09 01:03:14 +0000 | 
|---|---|---|
| committer | Devang Patel <dpatel@apple.com> | 2011-08-09 01:03:14 +0000 | 
| commit | 3d6e38942d8ef62b6e6e945d3ae4d2f63c1357ff (patch) | |
| tree | ed6b182c611adb11df6a28e5e0683455f4e3de0f /llvm | |
| parent | e7dddfd7f678cb2c93566aac8b6f7ebc32c5d9a0 (diff) | |
| download | bcm5719-llvm-3d6e38942d8ef62b6e6e945d3ae4d2f63c1357ff.tar.gz bcm5719-llvm-3d6e38942d8ef62b6e6e945d3ae4d2f63c1357ff.zip  | |
Provide method to print variable's extended name which includes inline location.
llvm-svn: 137095
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/Analysis/DebugInfo.h | 4 | ||||
| -rw-r--r-- | llvm/lib/Analysis/DebugInfo.cpp | 38 | 
2 files changed, 40 insertions, 2 deletions
diff --git a/llvm/include/llvm/Analysis/DebugInfo.h b/llvm/include/llvm/Analysis/DebugInfo.h index 88372b27999..2699580ad53 100644 --- a/llvm/include/llvm/Analysis/DebugInfo.h +++ b/llvm/include/llvm/Analysis/DebugInfo.h @@ -615,7 +615,7 @@ namespace llvm {      }      /// getInlinedAt - If this variable is inlined then return inline location. -    MDNode *getInlinedAt(); +    MDNode *getInlinedAt() const;      /// Verify - Verify that a variable descriptor is well formed.      bool Verify() const; @@ -648,6 +648,8 @@ namespace llvm {      /// print - print variable.      void print(raw_ostream &OS) const; +    void printExtendedName(raw_ostream &OS) const; +      /// dump - print variable to dbgs() with a newline.      void dump() const;    }; diff --git a/llvm/lib/Analysis/DebugInfo.cpp b/llvm/lib/Analysis/DebugInfo.cpp index 43408eea698..b243772a016 100644 --- a/llvm/lib/Analysis/DebugInfo.cpp +++ b/llvm/lib/Analysis/DebugInfo.cpp @@ -117,7 +117,7 @@ unsigned DIVariable::getNumAddrElements() const {  }  /// getInlinedAt - If this variable is inlined then return inline location. -MDNode *DIVariable::getInlinedAt() { +MDNode *DIVariable::getInlinedAt() const {    if (getVersion() <= llvm::LLVMDebugVersion9)      return NULL;    return dyn_cast_or_null<MDNode>(DbgNode->getOperand(7)); @@ -674,6 +674,42 @@ void DIGlobalVariable::print(raw_ostream &OS) const {    OS << "]\n";  } +static void printDebugLoc(DebugLoc DL, raw_ostream &CommentOS, +                          const LLVMContext &Ctx) { +  if (!DL.isUnknown()) {          // Print source line info. +    DIScope Scope(DL.getScope(Ctx)); +    // Omit the directory, because it's likely to be long and uninteresting. +    if (Scope.Verify()) +      CommentOS << Scope.getFilename(); +    else +      CommentOS << "<unknown>"; +    CommentOS << ':' << DL.getLine(); +    if (DL.getCol() != 0) +      CommentOS << ':' << DL.getCol(); +    DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(DL.getInlinedAt(Ctx)); +    if (!InlinedAtDL.isUnknown()) { +      CommentOS << " @[ "; +      printDebugLoc(InlinedAtDL, CommentOS, Ctx); +      CommentOS << " ]"; +    } +  } +} + +void DIVariable::printExtendedName(raw_ostream &OS) const { +  const LLVMContext &Ctx = DbgNode->getContext(); +  StringRef Res = getName(); +  if (!Res.empty()) +    OS << Res << "," << getLineNumber(); +  if (MDNode *InlinedAt = getInlinedAt()) { +    DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(InlinedAt); +    if (!InlinedAtDL.isUnknown()) { +      OS << " @["; +      printDebugLoc(InlinedAtDL, OS, Ctx); +      OS << "]"; +    } +  } +} +  /// print - Print variable.  void DIVariable::print(raw_ostream &OS) const {    StringRef Res = getName();  | 

