[Lldb-commits] [lldb] r136945 - in /lldb/trunk: include/lldb/Core/FormatManager.h include/lldb/lldb-enumerations.h source/Core/ValueObject.cpp

Enrico Granata granata.enrico at gmail.com
Thu Aug 4 16:37:19 PDT 2011


Author: enrico
Date: Thu Aug  4 18:37:18 2011
New Revision: 136945

URL: http://llvm.org/viewvc/llvm-project?rev=136945&view=rev
Log:
fixed a potential memory leak ; small improvement in the formatters lookup algorithm

Modified:
    lldb/trunk/include/lldb/Core/FormatManager.h
    lldb/trunk/include/lldb/lldb-enumerations.h
    lldb/trunk/source/Core/ValueObject.cpp

Modified: lldb/trunk/include/lldb/Core/FormatManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FormatManager.h?rev=136945&r1=136944&r2=136945&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/FormatManager.h (original)
+++ lldb/trunk/include/lldb/Core/FormatManager.h Thu Aug  4 18:37:18 2011
@@ -351,16 +351,28 @@
             return false;
         }
         ConstString name(ClangASTType::GetTypeNameForQualType(type).c_str());
+        const char* typeName = name.GetCString();
         if (vobj.GetBitfieldBitSize() > 0)
         {
             // for bitfields, append size to the typename so one can custom format them
             StreamString sstring;
-            sstring.Printf("%s:%d",name.AsCString(),vobj.GetBitfieldBitSize());
-            name = ConstString(sstring.GetData());
+            sstring.Printf("%s:%d",typeName,vobj.GetBitfieldBitSize());
+            ConstString bitfieldname = ConstString(sstring.GetData());
             if (log)
-                log->Printf("appended bitfield info, final result is %s", name.GetCString());
+                log->Printf("appended bitfield info, final result is %s", bitfieldname.GetCString());
+            if (Get(bitfieldname.AsCString(), entry))
+            {
+                if (log)
+                    log->Printf("bitfield direct match found, returning");
+                return true;
+            }
+            else
+            {
+                reason |= lldb::eFormatterChoiceCriterionStrippedBitField;
+                if (log)
+                    log->Printf("no bitfield direct match");
+            }
         }
-        const char* typeName = name.GetCString();
         if (log)
             log->Printf("trying to get %s for VO name %s of type %s",
                         m_name.c_str(),

Modified: lldb/trunk/include/lldb/lldb-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=136945&r1=136944&r2=136945&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-enumerations.h Thu Aug  4 18:37:18 2011
@@ -507,7 +507,8 @@
         eFormatterChoiceCriterionNavigatedBaseClasses =          0x00000004,
         eFormatterChoiceCriterionRegularExpressionSummary =      0x00000008,
         eFormatterChoiceCriterionRegularExpressionFilter =       0x00000008,
-        eFormatterChoiceCriterionDynamicObjCHierarchy =          0x00000010
+        eFormatterChoiceCriterionDynamicObjCHierarchy =          0x00000010,
+        eFormatterChoiceCriterionStrippedBitField =              0x00000020
     } FormatterChoiceCriterion;
     
     //----------------------------------------------------------------------

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=136945&r1=136944&r2=136945&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Thu Aug  4 18:37:18 2011
@@ -953,7 +953,7 @@
         SetFormat(custom_format);
     
     const char * return_value;
-    std::auto_ptr<char> alloc_mem;
+    std::string alloc_mem;
     
     switch(val_obj_display)
     {
@@ -970,12 +970,11 @@
             return_value = GetLocationAsCString();
             break;
         case eDisplayChildrenCount:
-            // keep this out of the local scope so it will only get deleted when
-            // we exit the function (..and we have a copy of the data into the Stream)
-            alloc_mem = std::auto_ptr<char>((char*)(return_value = new char[512]));
         {
+            alloc_mem.resize(512);
+            return_value = &alloc_mem[0];
             int count = GetNumChildren();
-            snprintf(alloc_mem.get(), 512, "%d", count);
+            snprintf((char*)return_value, 512, "%d", count);
             break;
         }
         default:





More information about the lldb-commits mailing list