[llvm-commits] [dragonegg] r94901 - in /dragonegg/trunk: llvm-debug.cpp llvm-debug.h

Duncan Sands baldrick at free.fr
Sat Jan 30 09:19:03 PST 2010


Author: baldrick
Date: Sat Jan 30 11:19:03 2010
New Revision: 94901

URL: http://llvm.org/viewvc/llvm-project?rev=94901&view=rev
Log:
Port commit 93972 (dpatel) from llvm-gcc:
Use lang_hooks.dwarf_name() to create human readable symbol names for C++ destructors, operators etc..
Keep a copy of this names because dwarf_name() uses a temp. storage.

Modified:
    dragonegg/trunk/llvm-debug.cpp
    dragonegg/trunk/llvm-debug.h

Modified: dragonegg/trunk/llvm-debug.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-debug.cpp?rev=94901&r1=94900&r2=94901&view=diff

==============================================================================
--- dragonegg/trunk/llvm-debug.cpp (original)
+++ dragonegg/trunk/llvm-debug.cpp Sat Jan 30 11:19:03 2010
@@ -30,6 +30,7 @@
 #include "llvm/Intrinsics.h"
 #include "llvm/Module.h"
 #include "llvm/Analysis/DebugInfo.h"
+#include "llvm/Support/Allocator.h"
 #include "llvm/Support/Dwarf.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/ADT/StringExtras.h"
@@ -225,6 +226,25 @@
 , RegionStack()
 {}
 
+/// getFunctionName - Get function name for the given FnDecl. If the
+/// name is constructred on demand (e.g. C++ destructor) then the name
+/// is stored on the side.
+StringRef DebugInfo::getFunctionName(tree FnDecl) {
+  StringRef FnNodeName = GetNodeName(FnDecl);
+  // Use dwarf_name to construct function names. In C++ this is used to
+  // create human readable destructor names.
+  StringRef FnName = lang_hooks.dwarf_name(FnDecl, 0);
+  if (FnNodeName.equals(FnName))
+    return FnNodeName;
+
+  // Use name returned by dwarf_name. It is in a temp. storage so make a 
+  // copy first.
+  char *StrPtr = FunctionNames.Allocate<char>(FnName.size() + 1);
+  strncpy(StrPtr, FnName.data(), FnName.size());
+  StrPtr[FnName.size()] = NULL;
+  return StringRef(StrPtr);
+}
+
 /// EmitFunctionStart - Constructs the debug code for entering a function -
 /// "llvm.dbg.func.start."
 void DebugInfo::EmitFunctionStart(tree FnDecl, Function *Fn,
@@ -267,7 +287,8 @@
       && DECL_ABSTRACT_ORIGIN (FnDecl) != FnDecl)
     ArtificialFnWithAbstractOrigin = true;
 
-  StringRef FnName = GetNodeName(FnDecl);
+  StringRef FnName = getFunctionName(FnDecl);
+
   DISubprogram SP = 
     DebugFactory.CreateSubprogram(ArtificialFnWithAbstractOrigin ?
                                   getOrCreateCompileUnit(main_input_filename) :
@@ -833,7 +854,7 @@
     else {
       // Get the location of the member.
       expanded_location MemLoc = GetNodeLocation(Member, false);
-      StringRef MemberName = GetNodeName(Member);        
+      StringRef MemberName = getFunctionName(Member);
       StringRef LinkageName = getLinkageName(Member);
       DIType SPTy = getOrCreateType(TREE_TYPE(Member));
       unsigned Virtuality = 0;

Modified: dragonegg/trunk/llvm-debug.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-debug.h?rev=94901&r1=94900&r2=94901&view=diff

==============================================================================
--- dragonegg/trunk/llvm-debug.h (original)
+++ dragonegg/trunk/llvm-debug.h Sat Jan 30 11:19:03 2010
@@ -67,10 +67,16 @@
   std::map<tree_node *, WeakVH> NameSpaceCache;
                                         // Cache of previously constructed name 
                                         // spaces.
+
   SmallVector<WeakVH, 4> RegionStack;
                                         // Stack to track declarative scopes.
   
   std::map<tree_node *, WeakVH> RegionMap;
+
+  /// FunctionNames - This is a storage for function names that are
+  /// constructed on demand. For example, C++ destructors, C++ operators etc..
+  llvm::BumpPtrAllocator FunctionNames;
+
 public:
   DebugInfo(Module *m);
 
@@ -138,6 +144,11 @@
   
   /// getOrCreateNameSpace - Get name space descriptor for the tree node.
   DINameSpace getOrCreateNameSpace(tree_node *Node, DIDescriptor Context);
+
+  /// getFunctionName - Get function name for the given FnDecl. If the
+  /// name is constructred on demand (e.g. C++ destructor) then the name
+  /// is stored on the side.
+  StringRef getFunctionName(tree_node *FnDecl);
 };
 
 } // end namespace llvm





More information about the llvm-commits mailing list