[llvm-commits] [llvm-gcc-4.2] r93972 - in /llvm-gcc-4.2/trunk/gcc: llvm-debug.cpp llvm-debug.h

Devang Patel dpatel at apple.com
Tue Jan 19 19:07:54 PST 2010


Author: dpatel
Date: Tue Jan 19 21:07:53 2010
New Revision: 93972

URL: http://llvm.org/viewvc/llvm-project?rev=93972&view=rev
Log:
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:
    llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp
    llvm-gcc-4.2/trunk/gcc/llvm-debug.h

Modified: llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp?rev=93972&r1=93971&r2=93972&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp Tue Jan 19 21:07:53 2010
@@ -228,6 +228,25 @@
     return false;
 }
 
+/// 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);
+}
+
 // Starting at the 'desired' BLOCK, recursively walk back to the
 // 'grand' context, and return pushing regions to make 'desired' the
 // current context.  'desired' should be a GCC lexical BLOCK, and
@@ -313,7 +332,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) :
@@ -921,7 +941,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: llvm-gcc-4.2/trunk/gcc/llvm-debug.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-debug.h?rev=93972&r1=93971&r2=93972&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-debug.h (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-debug.h Tue Jan 19 21:07:53 2010
@@ -32,6 +32,7 @@
 #include "llvm/Analysis/DebugInfo.h"
 #include "llvm/Support/Dwarf.h"
 #include "llvm/Support/ValueHandle.h"
+#include "llvm/Support/Allocator.h"
 
 extern "C" {
 #include "llvm.h"
@@ -72,6 +73,7 @@
   std::map<tree_node *, WeakVH> NameSpaceCache;
                                         // Cache of previously constructed name 
                                         // spaces.
+
   SmallVector<WeakVH, 4> RegionStack;
                                         // Stack to track declarative scopes.
   
@@ -84,7 +86,11 @@
   // be an ancestor of 'desired'.
   void push_regions(tree_node *desired, tree_node *grand);
 
-public:
+  /// 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);
 
   /// Initialize - Initialize debug info by creating compile unit for
@@ -159,6 +165,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