[Lldb-commits] [lldb] r243619 - Fix bug in expression display when determining if a pointer should be treated as a string

Ilia K ki.stfu at gmail.com
Wed Jul 29 22:32:42 PDT 2015


Author: ki.stfu
Date: Thu Jul 30 00:32:41 2015
New Revision: 243619

URL: http://llvm.org/viewvc/llvm-project?rev=243619&view=rev
Log:
Fix bug in expression display when determining if a pointer should be treated as a string

Summary:
Currently if the "first child" of the pointer is a char type then the pointer is displayed as a string. This test succeeds incorrectly when the pointer is to a structured type with a char type as its first field. Fix this by switching the test to retrieve the pointee type and checking that it is a char type.


Reviewers: abidh, ChuckR, ki.stfu

Subscribers: greggm, lldb-commits

Differential Revision: http://reviews.llvm.org/D11488

Modified:
    lldb/trunk/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py
    lldb/trunk/test/tools/lldb-mi/variable/main.cpp
    lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp
    lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.h

Modified: lldb/trunk/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py?rev=243619&r1=243618&r2=243619&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py (original)
+++ lldb/trunk/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py Thu Jul 30 00:32:41 2015
@@ -132,6 +132,10 @@ class MiGdbSetShowTestCase(lldbmi_testca
         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\"")
 
+        # Test that a struct with a char first element is not formatted as a string
+        self.runCmd("-var-create - * &nstr")
+        self.expect("\^done,name=\"var\d+\",numchild=\"2\",value=\"0x[0-9a-f]+\",type=\"not_str \*\",thread-id=\"1\",has_more=\"0\"")
+
         # Test that -gdb-set can set print expand-aggregates flag
         self.runCmd("-gdb-set print expand-aggregates on")
         self.expect("\^done")

Modified: lldb/trunk/test/tools/lldb-mi/variable/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-mi/variable/main.cpp?rev=243619&r1=243618&r2=243619&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-mi/variable/main.cpp (original)
+++ lldb/trunk/test/tools/lldb-mi/variable/main.cpp Thu Jul 30 00:32:41 2015
@@ -67,11 +67,20 @@ gdb_set_show_print_char_array_as_string_
     // BP_gdb_set_show_print_char_array_as_string_test
 }
 
+struct not_str
+{
+    not_str(char _c, int _f)
+        : c(_c), f(_f) { }
+    char c;
+    int f;
+};
+
 void
 gdb_set_show_print_expand_aggregates(void)
 {
     complex_type complx = { 3, { 3L }, &complx };
     complex_type complx_array[2] = { { 4, { 4L }, &complx_array[1] }, { 5, { 5 }, &complx_array[0] } };
+    not_str nstr('a', 0), *pnstr = &nstr;
 
     // BP_gdb_set_show_print_expand_aggregates
 }

Modified: lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp?rev=243619&r1=243618&r2=243619&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp Thu Jul 30 00:32:41 2015
@@ -136,7 +136,7 @@ CMICmnLLDBUtilSBValue::GetSimpleValue(co
     }
     else if (IsPointerType())
     {
-        if (m_bHandleCharType && IsFirstChildCharType())
+        if (m_bHandleCharType && IsPointeeCharType())
         {
             vwrValue = GetSimpleValueCStringPointer();
             return MIstatus::success;
@@ -348,17 +348,15 @@ CMICmnLLDBUtilSBValue::GetCompositeValue
 }
 
 //++ ------------------------------------------------------------------------------------
-// Details: Retrieve the flag stating whether this value object is a char type or some
-//          other type. Char type can be signed or unsigned.
-// Type:    Method.
-// Args:    None.
+// Details: Check that basic type is a char type. Char type can be signed or unsigned.
+// Type:    Static.
+// Args:    eType   - type to check
 // Return:  bool    - True = Yes is a char type, false = some other type.
 // Throws:  None.
 //--
 bool
-CMICmnLLDBUtilSBValue::IsCharType(void) const
+CMICmnLLDBUtilSBValue::IsCharBasicType(lldb::BasicType eType)
 {
-    const lldb::BasicType eType = m_rValue.GetType().GetBasicType();
     switch (eType)
     {
         case lldb::eBasicTypeChar:
@@ -373,6 +371,21 @@ CMICmnLLDBUtilSBValue::IsCharType(void)
 }
 
 //++ ------------------------------------------------------------------------------------
+// Details: Retrieve the flag stating whether this value object is a char type or some
+//          other type. Char type can be signed or unsigned.
+// Type:    Method.
+// Args:    None.
+// Return:  bool    - True = Yes is a char type, false = some other type.
+// Throws:  None.
+//--
+bool
+CMICmnLLDBUtilSBValue::IsCharType(void) const
+{
+    const lldb::BasicType eType = m_rValue.GetType().GetBasicType();
+    return IsCharBasicType(eType);
+}
+
+//++ ------------------------------------------------------------------------------------
 // Details: Retrieve the flag stating whether first child value object of *this object is
 //          a char type or some other type. Returns false if there are not children. Char
 //          type can be signed or unsigned.
@@ -396,6 +409,28 @@ CMICmnLLDBUtilSBValue::IsFirstChildCharT
 }
 
 //++ ------------------------------------------------------------------------------------
+// Details: Retrieve the flag stating whether pointee object of *this object is
+//          a char type or some other type. Returns false if there are not children. Char
+//          type can be signed or unsigned.
+// Type:    Method.
+// Args:    None.
+// Return:  bool    - True = Yes is a char type, false = some other type.
+// Throws:  None.
+//--
+bool
+CMICmnLLDBUtilSBValue::IsPointeeCharType(void) const
+{
+    const MIuint nChildren = m_rValue.GetNumChildren();
+
+    // Is it a basic type
+    if (nChildren == 0)
+        return false;
+
+    const lldb::BasicType eType = m_rValue.GetType().GetPointeeType().GetBasicType();
+    return IsCharBasicType(eType);
+}
+
+//++ ------------------------------------------------------------------------------------
 // Details: Retrieve the flag stating whether this value object is a integer type or some
 //          other type. Char type can be signed or unsigned and short or long/very long.
 // Type:    Method.

Modified: lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.h?rev=243619&r1=243618&r2=243619&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.h (original)
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.h Thu Jul 30 00:32:41 2015
@@ -37,6 +37,7 @@ class CMICmnLLDBUtilSBValue
     CMIUtilString GetTypeNameDisplay(void) const;
     bool IsCharType(void) const;
     bool IsFirstChildCharType(void) const;
+    bool IsPointeeCharType(void) const;
     bool IsIntegerType(void) const;
     bool IsPointerType(void) const;
     bool IsArrayType(void) const;
@@ -55,6 +56,10 @@ class CMICmnLLDBUtilSBValue
     CMIUtilString GetSimpleValueCStringArray(void) const;
     bool GetCompositeValue(const bool vbPrintFieldNames, CMICmnMIValueTuple &vwrMiValueTuple, const MIuint vnDepth = 1) const;
 
+    // Statics:
+  private:
+    static bool IsCharBasicType(lldb::BasicType eType);
+
     // Attributes:
   private:
     lldb::SBValue &m_rValue;





More information about the lldb-commits mailing list