[Lldb-commits] [PATCH] D13657: [lldb] char summary provider

Eugene Leviant via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 12 08:40:01 PDT 2015


evgeny777 created this revision.
evgeny777 added a reviewer: granata.enrico.
evgeny777 added subscribers: lldb-commits, KLapshin.

This patch enables type summary for 'char' type. Let's suppose we have:

**char c = 'h'; **

Current revision evaluates c as:

**(char) $0 = 'h'**

After this patch (104 is the ASCII code of 'h'):

**(char) $0 = 104 'h'**

This change primary objective is to conform MI evaluation of character type, so that MI formatting
can be eliminated and entirely replaced with one of lldb. Also this can be useful when evaluating non-printable 
characters

http://reviews.llvm.org/D13657

Files:
  source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
  source/Plugins/Language/CPlusPlus/CxxStringTypes.h
  test/lang/cpp/wchar_t/TestCxxWCharT.py
  test/lang/cpp/wchar_t/main.cpp

Index: test/lang/cpp/wchar_t/main.cpp
===================================================================
--- test/lang/cpp/wchar_t/main.cpp
+++ test/lang/cpp/wchar_t/main.cpp
@@ -26,6 +26,7 @@
     Foo<int> foo_x('a');
     Foo<wchar_t> foo_y(L'a');
     const wchar_t *mazeltov = L"מזל טוב";
+    char c8 = 'h';
     wchar_t *ws_NULL = nullptr;
     wchar_t *ws_empty = L"";
   	wchar_t array[200], * array_source = L"Hey, I'm a super wchar_t string, éõñž";
Index: test/lang/cpp/wchar_t/TestCxxWCharT.py
===================================================================
--- test/lang/cpp/wchar_t/TestCxxWCharT.py
+++ test/lang/cpp/wchar_t/TestCxxWCharT.py
@@ -37,6 +37,10 @@
 
         if not process:
             self.fail("SBTarget.Launch() failed")
+        
+        # Check that summary for char type works
+        self.expect("frame variable c8",
+            substrs = ["(char) c8 = 104 'h'"])
 
         # Check that we correctly report templates on wchar_t
         self.expect("frame variable foo_y",
Index: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===================================================================
--- source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -656,7 +656,9 @@
     .SetDontShowChildren(true)
     .SetHideItemNames(true)
     .SetShowMembersOneLiner(false);
-    
+    const TypeSummaryImpl::Flags char_flags = widechar_flags;
+
+    AddCXXSummary(cpp_category_sp, lldb_private::formatters::CharSummaryProvider, "char summary provider", ConstString("char"), char_flags);
     AddCXXSummary(cpp_category_sp, lldb_private::formatters::Char16SummaryProvider, "char16_t summary provider", ConstString("char16_t"), widechar_flags);
     AddCXXSummary(cpp_category_sp, lldb_private::formatters::Char32SummaryProvider, "char32_t summary provider", ConstString("char32_t"), widechar_flags);
     AddCXXSummary(cpp_category_sp, lldb_private::formatters::WCharSummaryProvider, "wchar_t summary provider", ConstString("wchar_t"), widechar_flags);
Index: source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
===================================================================
--- source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
+++ source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
@@ -131,6 +131,18 @@
 }
 
 bool
+lldb_private::formatters::CharSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions&)
+{
+    bool success;    
+    int64_t code = valobj.GetValueAsSigned(0, &success);
+    if (!success)
+        return false;
+        
+    stream.Printf("%d %s", (int)code, valobj.GetValueAsCString());
+    return true;
+}
+
+bool
 lldb_private::formatters::Char16SummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions&)
 {
     DataExtractor data;
Index: source/Plugins/Language/CPlusPlus/CxxStringTypes.h
===================================================================
--- source/Plugins/Language/CPlusPlus/CxxStringTypes.h
+++ source/Plugins/Language/CPlusPlus/CxxStringTypes.h
@@ -18,6 +18,9 @@
     namespace formatters
     {
         bool
+        CharSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions&);
+
+        bool
         Char16StringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); // char16_t* and unichar*
         
         bool


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13657.37119.patch
Type: text/x-patch
Size: 3411 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20151012/46c541cd/attachment.bin>


More information about the lldb-commits mailing list