evgeny777 updated this revision to Diff 35618.
evgeny777 added a comment.

Revised, removed dependencies from http://reviews.llvm.org/D13094


http://reviews.llvm.org/D13058

Files:
  include/lldb/API/SBTypeSummary.h
  source/API/SBTypeSummary.cpp
  test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py
  test/tools/lldb-mi/variable/TestMiVar.py
  test/tools/lldb-mi/variable/main.cpp
  tools/lldb-mi/MICmnLLDBUtilSBValue.cpp
  tools/lldb-mi/MICmnLLDBUtilSBValue.h

Index: tools/lldb-mi/MICmnLLDBUtilSBValue.h
===================================================================
--- tools/lldb-mi/MICmnLLDBUtilSBValue.h
+++ tools/lldb-mi/MICmnLLDBUtilSBValue.h
@@ -55,7 +55,7 @@
     CMIUtilString GetSimpleValueCStringPointer() const;
     CMIUtilString GetSimpleValueCStringArray() const;
     bool GetCompositeValue(const bool vbPrintFieldNames, CMICmnMIValueTuple &vwrMiValueTuple, const MIuint vnDepth = 1) const;
-
+    bool TryGetValueSummary(CMIUtilString &vrValue) const;
     // Statics:
   private:
     static bool IsCharBasicType(lldb::BasicType eType);
Index: tools/lldb-mi/MICmnLLDBUtilSBValue.cpp
===================================================================
--- tools/lldb-mi/MICmnLLDBUtilSBValue.cpp
+++ tools/lldb-mi/MICmnLLDBUtilSBValue.cpp
@@ -17,6 +17,7 @@
 #include "MICmnMIValueTuple.h"
 #include "MIUtilString.h"
 
+#include "lldb/API/SBTypeSummary.h"
 //++ ------------------------------------------------------------------------------------
 // Details: CMICmnLLDBUtilSBValue constructor.
 // Type:    Method.
@@ -165,6 +166,13 @@
             return MIstatus::success;
         }
     }
+    else
+    {
+        // Treat composite value which has registered summary
+        // (for example with AddCXXSummary) as simple value
+        if (TryGetValueSummary(vwrValue))
+            return MIstatus::success;
+    }
 
     // Composite variable type i.e. struct
     return MIstatus::failure;
@@ -180,6 +188,10 @@
 CMIUtilString
 CMICmnLLDBUtilSBValue::GetSimpleValueChar() const
 {
+    CMIUtilString summary;
+    if (TryGetValueSummary(summary))
+        return summary;
+
     const uint64_t value = m_rValue.GetValueAsUnsigned();
     if (value == 0)
     {
@@ -227,6 +239,10 @@
     if (value == nullptr)
         return m_pUnkwn;
 
+    CMIUtilString summary;
+    if (TryGetValueSummary(summary))
+        return summary;
+
     lldb::SBValue child = m_rValue.GetChildAtIndex(0);
     const lldb::BasicType eType = child.GetType().GetBasicType();
     switch (eType)
@@ -266,6 +282,10 @@
 CMIUtilString
 CMICmnLLDBUtilSBValue::GetSimpleValueCStringArray() const
 {
+    CMIUtilString summary;
+    if (TryGetValueSummary(summary))
+        return summary;
+
     const MIuint nChildren = m_rValue.GetNumChildren();
     lldb::SBValue child = m_rValue.GetChildAtIndex(0);
     const lldb::BasicType eType = child.GetType().GetBasicType();
@@ -347,6 +367,30 @@
     return MIstatus::success;
 }
 
+bool
+CMICmnLLDBUtilSBValue::TryGetValueSummary(CMIUtilString &vrValue) const
+{
+    if (!m_rValue.IsValid())
+        return false;
+
+    const char* c_str = m_rValue.GetSummary();
+    if (c_str && c_str[0])
+    {
+        vrValue = c_str;
+        lldb::SBTypeSummary summary = m_rValue.GetTypeSummary();
+        if (summary.IsValid() && summary.DoesPrintValue(m_rValue))
+        {
+            c_str = m_rValue.GetValue();
+            if (c_str && c_str[0])
+            {
+                vrValue.insert(0, std::string(c_str) + " ");
+            }
+        }
+        return true;
+    }
+    return false;
+}
+
 //++ ------------------------------------------------------------------------------------
 // Details: Check that basic type is a char type. Char type can be signed or unsigned.
 // Type:    Static.
Index: test/tools/lldb-mi/variable/main.cpp
===================================================================
--- test/tools/lldb-mi/variable/main.cpp
+++ test/tools/lldb-mi/variable/main.cpp
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include <cstdint>
+#include <string>
 
 struct complex_type
 {
@@ -64,9 +65,21 @@
     const char32_t *u32p = U"\t\"hello\"\n";
     const char32_t u32a[] = U"\t\"hello\"\n";
 
+    const char16_t* u16p_rus = u"\\Аламо-сквер";
+    const char16_t  u16a_rus[] = u"\\Бейвью";
+    const char32_t* u32p_rus = U"\\Чайнатаун";
+    const char32_t  u32a_rus[] = U"\\Догпатч";
+
     // BP_gdb_set_show_print_char_array_as_string_test
 }
 
+void
+cpp_stl_types_test(void)
+{
+    std::string std_string = "hello";
+    // BP_cpp_stl_types_test
+}
+
 struct not_str
 {
     not_str(char _c, int _f)
@@ -105,6 +118,7 @@
     var_update_test();
     var_list_children_test();
     gdb_set_show_print_char_array_as_string_test();
+    cpp_stl_types_test();
     gdb_set_show_print_expand_aggregates();
     gdb_set_show_print_aggregate_field_names();
     return 0; // BP_return
Index: test/tools/lldb-mi/variable/TestMiVar.py
===================================================================
--- test/tools/lldb-mi/variable/TestMiVar.py
+++ test/tools/lldb-mi/variable/TestMiVar.py
@@ -329,5 +329,30 @@
         self.runCmd("-var-list-children 0 var_complx 0")
         self.expect("\^error,msg=\"Command 'var-list-children'. Variable children range invalid\"")
 
+    @lldbmi_test
+    @skipIfWindows #llvm.org/pr24452: Get lldb-mi working on Windows
+    @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
+    @skipIfLinux # llvm.org/pr22841: lldb-mi tests fail on all Linux buildbots
+    def test_lldbmi_var_create_for_stl_types(self):
+        """Test that 'lldb-mi --interpreter' print summary for STL types."""
+
+        self.spawnLldbMi(args = None)
+
+        # Load executable
+        self.runCmd("-file-exec-and-symbols %s" % self.myexe)
+        self.expect("\^done")
+
+        # Run to BP_gdb_set_show_print_char_array_as_string_test
+        line = line_number('main.cpp', '// BP_cpp_stl_types_test')
+        self.runCmd("-break-insert main.cpp:%d" % line)
+        self.expect("\^done,bkpt={number=\"1\"")
+        self.runCmd("-exec-run")
+        self.expect("\^running")
+        self.expect("\*stopped,reason=\"breakpoint-hit\"")
+
+        # Test for std::string
+        self.runCmd("-var-create - * std_string")
+        self.expect('\^done,name="var\d+",numchild="[0-9]+",value="\\\\"hello\\\\"",type="std::[\S]*string",thread-id="1",has_more="0"')
+
 if __name__ == '__main__':
     unittest2.main()
Index: test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py
===================================================================
--- test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py
+++ test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py
@@ -1,3 +1,4 @@
+#coding=utf8
 """
 Test lldb-mi -gdb-set and -gdb-show commands for 'print option-name'.
 """
@@ -10,6 +11,17 @@
 
     mydir = TestBase.compute_mydir(__file__)
 
+    # evaluates array when char-array-as-string is off
+    def eval_and_check_array(self, var, typ, length):
+        self.runCmd("-var-create - * %s" % var)
+        self.expect('\^done,name="var\d+",numchild="%d",value="\[%d\]",type="%s \[%d\]",thread-id="1",has_more="0"' % (length, length, typ, length))
+
+    # evaluates any type which can be represented as string of characters
+    def eval_and_match_string(self, var, value, typ):
+        value=value.replace("\\", "\\\\").replace("\"", "\\\"")
+        self.runCmd("-var-create - * " + var)
+        self.expect('\^done,name="var\d+",numchild="[0-9]+",value="%s",type="%s",thread-id="1",has_more="0"' % (value, typ))
+
     @lldbmi_test
     @skipIfWindows #llvm.org/pr24452: Get lldb-mi working on Windows
     @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@@ -36,28 +48,22 @@
         self.expect("\^done,value=\"off\"")
 
         # Test that an char* is expanded to string when print char-array-as-string is "off"
-        self.runCmd("-var-create - * cp")
-        self.expect("\^done,name=\"var\d+\",numchild=\"1\",value=\"0x[0-9a-f]+ \\\\\\\"\\\\\\\\t\\\\\\\\\\\\\"hello\\\\\\\\\\\\\"\\\\\\\\n\\\\\\\"\",type=\"const char \*\",thread-id=\"1\",has_more=\"0\"")
+        self.eval_and_match_string("cp", r'0x[0-9a-f]+ \"\\t\\\"hello\\\"\\n\"', r'const char \*')
 
         # Test that an char[] isn't expanded to string when print char-array-as-string is "off"
-        self.runCmd("-var-create - * ca")
-        self.expect("\^done,name=\"var\d+\",numchild=\"10\",value=\"\[10\]\",type=\"const char \[10\]\",thread-id=\"1\",has_more=\"0\"")
+        self.eval_and_check_array("ca", "const char", 10);
 
         # Test that an char16_t* is expanded to string when print char-array-as-string is "off"
-        self.runCmd("-var-create - * u16p")
-        self.expect("\^done,name=\"var\d+\",numchild=\"1\",value=\"0x[0-9a-f]+ u\\\\\\\"\\\\\\\\t\\\\\\\\\\\\\"hello\\\\\\\\\\\\\"\\\\\\\\n\\\\\\\"\",type=\"const char16_t \*\",thread-id=\"1\",has_more=\"0\"")
+        self.eval_and_match_string("u16p", r'0x[0-9a-f]+ u\"\\t\\\"hello\\\"\\n\"', r'const char16_t \*')
 
         # Test that an char16_t[] isn't expanded to string when print char-array-as-string is "off"
-        self.runCmd("-var-create - * u16a")
-        self.expect("\^done,name=\"var\d+\",numchild=\"10\",value=\"\[10\]\",type=\"const char16_t \[10\]\",thread-id=\"1\",has_more=\"0\"")
+        self.eval_and_check_array("u16a", "const char16_t", 10);
 
         # Test that an char32_t* is expanded to string when print char-array-as-string is "off"
-        self.runCmd("-var-create - * u32p")
-        self.expect("\^done,name=\"var\d+\",numchild=\"1\",value=\"0x[0-9a-f]+ U\\\\\\\"\\\\\\\\t\\\\\\\\\\\\\"hello\\\\\\\\\\\\\"\\\\\\\\n\\\\\\\"\",type=\"const char32_t \*\",thread-id=\"1\",has_more=\"0\"")
+        self.eval_and_match_string("u32p", r'0x[0-9a-f]+ U\"\\t\\\"hello\\\"\\n\"', r'const char32_t \*')
 
         # Test that an char32_t[] isn't expanded to string when print char-array-as-string is "off"
-        self.runCmd("-var-create - * u32a")
-        self.expect("\^done,name=\"var\d+\",numchild=\"10\",value=\"\[10\]\",type=\"const char32_t \[10\]\",thread-id=\"1\",has_more=\"0\"")
+        self.eval_and_check_array("u32a", "const char32_t", 10);
 
         # Test that -gdb-set can set print char-array-as-string flag
         self.runCmd("-gdb-set print char-array-as-string on")
@@ -68,28 +74,28 @@
         self.expect("\^done,value=\"on\"")
 
         # Test that an char* with escape chars is expanded to string when print char-array-as-string is "on"
-        self.runCmd("-var-create - * cp")
-        self.expect("\^done,name=\"var\d+\",numchild=\"1\",value=\"0x[0-9a-f]+ \\\\\\\"\\\\\\\\t\\\\\\\\\\\\\"hello\\\\\\\\\\\\\"\\\\\\\\n\\\\\\\"\",type=\"const char \*\",thread-id=\"1\",has_more=\"0\"")
+        self.eval_and_match_string("cp", r'0x[0-9a-f]+ \"\\t\\\"hello\\\"\\n\"', r'const char \*')
         
         # Test that an char[] with escape chars is expanded to string when print char-array-as-string is "on"
-        self.runCmd("-var-create - * ca")
-        self.expect("\^done,name=\"var\d+\",numchild=\"10\",value=\"\\\\\\\"\\\\\\\\t\\\\\\\\\\\\\"hello\\\\\\\\\\\\\"\\\\\\\\n\\\\\\\"\",type=\"const char \[10\]\",thread-id=\"1\",has_more=\"0\"")
+        self.eval_and_match_string("ca", r'\"\\t\\\"hello\\\"\\n\"', r'const char \[10\]')
         
         # Test that an char16_t* with esc1ape chars is expanded to string when print char-array-as-string is "on"
-        self.runCmd("-var-create - * u16p")
-        self.expect("\^done,name=\"var\d+\",numchild=\"1\",value=\"0x[0-9a-f]+ u\\\\\\\"\\\\\\\\t\\\\\\\\\\\\\"hello\\\\\\\\\\\\\"\\\\\\\\n\\\\\\\"\",type=\"const char16_t \*\",thread-id=\"1\",has_more=\"0\"")
+        self.eval_and_match_string("u16p", r'0x[0-9a-f]+ u\"\\t\\\"hello\\\"\\n\"', r'const char16_t \*')
         
         # Test that an char16_t[] with escape chars is expanded to string when print char-array-as-string is "on"
-        self.runCmd("-var-create - * u16a")
-        self.expect("\^done,name=\"var\d+\",numchild=\"10\",value=\"u\\\\\\\"\\\\\\\\t\\\\\\\\\\\\\"hello\\\\\\\\\\\\\"\\\\\\\\n\\\\\\\"\",type=\"const char16_t \[10\]\",thread-id=\"1\",has_more=\"0\"")
+        self.eval_and_match_string("u16a", r'u\"\\t\\\"hello\\\"\\n\"', r'const char16_t \[10\]')
         
         # Test that an char32_t* with escape chars is expanded to string when print char-array-as-string is "on"
-        self.runCmd("-var-create - * u32p")
-        self.expect("\^done,name=\"var\d+\",numchild=\"1\",value=\"0x[0-9a-f]+ U\\\\\\\"\\\\\\\\t\\\\\\\\\\\\\"hello\\\\\\\\\\\\\"\\\\\\\\n\\\\\\\"\",type=\"const char32_t \*\",thread-id=\"1\",has_more=\"0\"")
+        self.eval_and_match_string("u32p", r'0x[0-9a-f]+ U\"\\t\\\"hello\\\"\\n\"', r'const char32_t \*')
         
         # Test that an char32_t[] with escape chars is expanded to string when print char-array-as-string is "on"
-        self.runCmd("-var-create - * u32a")
-        self.expect("\^done,name=\"var\d+\",numchild=\"10\",value=\"U\\\\\\\"\\\\\\\\t\\\\\\\\\\\\\"hello\\\\\\\\\\\\\"\\\\\\\\n\\\\\\\"\",type=\"const char32_t \[10\]\",thread-id=\"1\",has_more=\"0\"")
+        self.eval_and_match_string("u32a", r'U\"\\t\\\"hello\\\"\\n\"', r'const char32_t \[10\]')
+
+        # Test russian unicode strings
+        self.eval_and_match_string("u16p_rus", r'0x[0-9a-f]+ u\"\\\\Аламо-сквер\"', r'const char16_t \*')
+        self.eval_and_match_string("u16a_rus", r'u\"\\\\Бейвью\"', r'const char16_t \[8\]')
+        self.eval_and_match_string("u32p_rus", r'0x[0-9a-f]+ U\"\\\\Чайнатаун\"', r'const char32_t \*')
+        self.eval_and_match_string("u32a_rus", r'U\"\\\\Догпатч\"', r'const char32_t \[9\]')
 
         # Test that -gdb-set print char-array-as-string fails if "on"/"off" isn't specified
         self.runCmd("-gdb-set print char-array-as-string")
@@ -129,8 +135,7 @@
         self.expect("\^done,name=\"var1\",numchild=\"3\",value=\"{\.\.\.}\",type=\"complex_type\",thread-id=\"1\",has_more=\"0\"")
 
         # Test that composite type[] isn't expanded when print expand-aggregates is "off"
-        self.runCmd("-var-create var2 * complx_array")
-        self.expect("\^done,name=\"var2\",numchild=\"2\",value=\"\[2\]\",type=\"complex_type \[2\]\",thread-id=\"1\",has_more=\"0\"")
+        self.eval_and_check_array("complx_array", "complex_type", 2)
 
         # Test that a struct with a char first element is not formatted as a string
         self.runCmd("-var-create - * &nstr")
Index: source/API/SBTypeSummary.cpp
===================================================================
--- source/API/SBTypeSummary.cpp
+++ source/API/SBTypeSummary.cpp
@@ -11,6 +11,8 @@
 
 #include "lldb/API/SBStream.h"
 
+#include "lldb/API/SBValue.h"
+
 #include "lldb/DataFormatters/DataVisualization.h"
 
 using namespace lldb;
@@ -284,6 +286,17 @@
     }
 }
 
+bool
+SBTypeSummary::DoesPrintValue(const SBValue& value)
+{
+    if (!IsValid())
+        return false;
+
+    lldb::ValueObjectSP value_sp = value.GetSP();
+    return m_opaque_sp->DoesPrintValue(value_sp.get());
+}
+
+
 lldb::SBTypeSummary &
 SBTypeSummary::operator = (const lldb::SBTypeSummary &rhs)
 {
Index: include/lldb/API/SBTypeSummary.h
===================================================================
--- include/lldb/API/SBTypeSummary.h
+++ include/lldb/API/SBTypeSummary.h
@@ -121,6 +121,9 @@
         bool
         GetDescription (lldb::SBStream &description, 
                         lldb::DescriptionLevel description_level);
+
+        bool
+        DoesPrintValue (const SBValue& value);
         
         lldb::SBTypeSummary &
         operator = (const lldb::SBTypeSummary &rhs);
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to