[Lldb-commits] [lldb] r172165 - in /lldb/trunk: source/Core/CXXFormatterFunctions.cpp source/Core/FormatManager.cpp test/lang/cpp/wchar_t/TestCxxWCharT.py test/lang/cpp/wchar_t/main.cpp

Enrico Granata egranata at apple.com
Thu Jan 10 18:44:00 PST 2013


Author: enrico
Date: Thu Jan 10 20:44:00 2013
New Revision: 172165

URL: http://llvm.org/viewvc/llvm-project?rev=172165&view=rev
Log:
<rdar://problem/11383764>

Making a data formatter for wchar_t *


Modified:
    lldb/trunk/source/Core/CXXFormatterFunctions.cpp
    lldb/trunk/source/Core/FormatManager.cpp
    lldb/trunk/test/lang/cpp/wchar_t/TestCxxWCharT.py
    lldb/trunk/test/lang/cpp/wchar_t/main.cpp

Modified: lldb/trunk/source/Core/CXXFormatterFunctions.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/CXXFormatterFunctions.cpp?rev=172165&r1=172164&r2=172165&view=diff
==============================================================================
--- lldb/trunk/source/Core/CXXFormatterFunctions.cpp (original)
+++ lldb/trunk/source/Core/CXXFormatterFunctions.cpp Thu Jan 10 20:44:00 2013
@@ -163,6 +163,10 @@
 
     Error error;
     lldb::DataBufferSP buffer_sp(new DataBufferHeap(bufferSPSize,0));
+    
+    if (!buffer_sp->GetBytes())
+        return false;
+    
     size_t data_read = process_sp->ReadMemoryFromInferior(location, (char*)buffer_sp->GetBytes(), bufferSPSize, error);
     if (error.Fail())
     {
@@ -194,12 +198,18 @@
         *data_ptr = 0;
         data_ptr = (SourceDataType*)buffer_sp->GetBytes();
         
-        lldb::DataBufferSP utf8_data_buffer_sp(new DataBufferHeap(bufferSPSize,0));
-        UTF8* utf8_data_ptr = (UTF8*)utf8_data_buffer_sp->GetBytes();
-        UTF8* utf8_data_end_ptr = utf8_data_ptr + bufferSPSize;
-        
+        lldb::DataBufferSP utf8_data_buffer_sp;
+        UTF8* utf8_data_ptr = nullptr;
+        UTF8* utf8_data_end_ptr = nullptr;
+
         if (ConvertFunction)
+        {
+            utf8_data_buffer_sp.reset(new DataBufferHeap(bufferSPSize,0));
+            utf8_data_ptr = (UTF8*)utf8_data_buffer_sp->GetBytes();
+            utf8_data_end_ptr = utf8_data_ptr + bufferSPSize;
             ConvertFunction ( (const SourceDataType**)&data_ptr, data_end_ptr, &utf8_data_ptr, utf8_data_end_ptr, lenientConversion );
+            utf8_data_ptr = (UTF8*)utf8_data_buffer_sp->GetBytes(); // needed because the ConvertFunction will change the value of the data_ptr
+        }
         else
         {
             // just copy the pointers - the cast is necessary to make the compiler happy
@@ -208,7 +218,6 @@
             utf8_data_end_ptr = (UTF8*)data_end_ptr;
         }
         
-        utf8_data_ptr = (UTF8*)utf8_data_buffer_sp->GetBytes();
         for (;utf8_data_ptr != utf8_data_end_ptr; utf8_data_ptr++)
         {
             if (!*utf8_data_ptr)
@@ -277,7 +286,50 @@
 bool
 lldb_private::formatters::WCharStringSummaryProvider (ValueObject& valobj, Stream& stream)
 {
-    return false;
+    ProcessSP process_sp = valobj.GetProcessSP();
+    if (!process_sp)
+        return false;
+
+    lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
+
+    if (!valobj_addr)
+        return false;
+
+    clang::ASTContext* ast = valobj.GetClangAST();
+
+    if (!ast)
+        return false;
+
+    uint32_t wchar_size = ClangASTType::GetClangTypeBitWidth(ast, ClangASTType::GetBasicType(ast, lldb::eBasicTypeWChar).GetOpaqueQualType());
+
+    switch (wchar_size)
+    {
+        case 8:
+            // utf 8
+            return ReadUTFBufferAndDumpToStream<UTF8, nullptr>(valobj_addr,
+                                                               process_sp,
+                                                               stream,
+                                                               false, // no @ sign for C++
+                                                               true); // but use quotes
+        case 16:
+            // utf 16
+            return ReadUTFBufferAndDumpToStream<UTF16, ConvertUTF16toUTF8>(valobj_addr,
+                                                                           process_sp,
+                                                                           stream,
+                                                                           false, // no @ sign for C++
+                                                                           true); // but use quotes
+        case 32:
+            // utf 32
+            return ReadUTFBufferAndDumpToStream<UTF32, ConvertUTF32toUTF8>(valobj_addr,
+                                                                           process_sp,
+                                                                           stream,
+                                                                           false, // no @ sign for C++
+                                                                           true); // but use quotes
+        default:
+            stream.Printf("size for wchar_t is not valid");
+            return true;
+    }
+    return true;
 }
 
 template<bool name_entries>
@@ -337,7 +389,7 @@
             return false;
         if (is_64bit)
             value &= ~0x0f1f000000000000UL;
-            }
+    }
     else
     {
         if (!ExtractValueFromObjCExpression(valobj, "int", "count", value))

Modified: lldb/trunk/source/Core/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FormatManager.cpp?rev=172165&r1=172164&r2=172165&view=diff
==============================================================================
--- lldb/trunk/source/Core/FormatManager.cpp (original)
+++ lldb/trunk/source/Core/FormatManager.cpp Thu Jan 10 20:44:00 2013
@@ -943,6 +943,9 @@
     
     AddCXXSummary(sys_category_sp, lldb_private::formatters::Char32StringSummaryProvider, "char32_t * summary provider", ConstString("char32_t *"), string_flags);
     AddCXXSummary(sys_category_sp, lldb_private::formatters::Char32StringSummaryProvider, "char32_t * summary provider", ConstString("const char32_t *"), string_flags);
+    
+    AddCXXSummary(sys_category_sp, lldb_private::formatters::WCharStringSummaryProvider, "wchar_t * summary provider", ConstString("wchar_t *"), string_flags);
+    AddCXXSummary(sys_category_sp, lldb_private::formatters::WCharStringSummaryProvider, "wchar_t * summary provider", ConstString("const wchar_t *"), string_flags);
 }
 
 void

Modified: lldb/trunk/test/lang/cpp/wchar_t/TestCxxWCharT.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/wchar_t/TestCxxWCharT.py?rev=172165&r1=172164&r2=172165&view=diff
==============================================================================
--- lldb/trunk/test/lang/cpp/wchar_t/TestCxxWCharT.py (original)
+++ lldb/trunk/test/lang/cpp/wchar_t/TestCxxWCharT.py Thu Jan 10 20:44:00 2013
@@ -1,3 +1,4 @@
+#coding=utf8
 """
 Test that C++ supports wchar_t correctly.
 """
@@ -68,6 +69,10 @@
         # Check that we can run expressions that return wchar_t
         self.expect("expression L'a'",substrs = ['(wchar_t) $'])
 
+        # Mazel Tov if this works!
+        self.expect("frame variable mazeltov",
+            substrs = ['(const wchar_t *) mazeltov = ','מזל טוב'])
+
 
 if __name__ == '__main__':
     import atexit

Modified: lldb/trunk/test/lang/cpp/wchar_t/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/wchar_t/main.cpp?rev=172165&r1=172164&r2=172165&view=diff
==============================================================================
--- lldb/trunk/test/lang/cpp/wchar_t/main.cpp (original)
+++ lldb/trunk/test/lang/cpp/wchar_t/main.cpp Thu Jan 10 20:44:00 2013
@@ -23,5 +23,6 @@
 {
     Foo<int> foo_x('a');
     Foo<wchar_t> foo_y(L'a');
+    const wchar_t *mazeltov = L"מזל טוב";
     return 0; // Set break point at this line.
 }





More information about the lldb-commits mailing list