[Lldb-commits] [lldb] r235807 - Add -gdb-set/-gdb-show aggregate-field-names option (MI)

Ilia K ki.stfu at gmail.com
Sat Apr 25 13:33:03 PDT 2015


Author: ki.stfu
Date: Sat Apr 25 15:33:02 2015
New Revision: 235807

URL: http://llvm.org/viewvc/llvm-project?rev=235807&view=rev
Log:
Add -gdb-set/-gdb-show aggregate-field-names option (MI)

Use this option to print/skip field names (default is on):
```
-var-create var1 * complx
^done,name="var1",numchild="3",value="{i = 3, inner = {l = 3}, complex_ptr = 0x[0-9a-f]+}",type="complex_type",thread-id="1",has_more="0"
-var-create var2 * complx_array
^done,name="var2",numchild="2",value="{[0] = {i = 4, inner = {l = 4}, complex_ptr = 0x[0-9a-f]+}, [1] = {i = 5, inner = {l = 5}, complex_ptr = 0x[0-9a-f]+}}",type="complex_type [2]",thread-id="1",has_more="0"
-gdb-set print aggregate-field-names off
^done
-var-create var3 * complx
^done,name="var3",numchild="3",value="{3,{3},0x[0-9a-f]+}",type="complex_type",thread-id="1",has_more="0"
-var-create var4 * complx_array
^done,name="var4",numchild="2",value="{{4,{4},0x[0-9a-f]+},{5,{5},0x[0-9a-f]+}}",type="complex_type [2]",thread-id="1",has_more="0"
```


Modified:
    lldb/trunk/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py
    lldb/trunk/test/tools/lldb-mi/variable/main.cpp
    lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.cpp
    lldb/trunk/tools/lldb-mi/MICmdCmdGdbShow.cpp
    lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp
    lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h
    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=235807&r1=235806&r2=235807&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py (original)
+++ lldb/trunk/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py Sat Apr 25 15:33:02 2015
@@ -120,5 +120,64 @@ class MiGdbSetShowTestCase(lldbmi_testca
         self.runCmd("-gdb-set print expand-aggregates unknown")
         self.expect("\^error,msg=\"The request ''print' expects option-name and \"on\" or \"off\"' failed.\"")
 
+    @lldbmi_test
+    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
+    def test_lldbmi_gdb_set_show_print_aggregate_field_names(self):
+        """Test that 'lldb-mi --interpreter' can expand aggregates everywhere."""
+
+        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_aggregate_field_names
+        line = line_number('main.cpp', '// BP_gdb_set_show_print_aggregate_field_names')
+        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 that default print aggregatep-field-names value is "on"
+        self.runCmd("-gdb-show print aggregate-field-names")
+        self.expect("\^done,value=\"on\"")
+
+        # Set print expand-aggregates flag to "on"
+        self.runCmd("-gdb-set print expand-aggregates on")
+        self.expect("\^done")
+
+        # Test that composite type is expanded with field name when print aggregate-field-names is "on"
+        self.runCmd("-var-create var1 * complx")
+        self.expect("\^done,name=\"var1\",numchild=\"3\",value=\"{i = 3, inner = {l = 3}, complex_ptr = 0x[0-9a-f]+}\",type=\"complex_type\",thread-id=\"1\",has_more=\"0\"")
+
+        # Test that composite type[] is expanded with field name when print aggregate-field-names is "on"
+        self.runCmd("-var-create var2 * complx_array")
+        self.expect("\^done,name=\"var2\",numchild=\"2\",value=\"{\[0\] = {i = 4, inner = {l = 4}, complex_ptr = 0x[0-9a-f]+}, \[1\] = {i = 5, inner = {l = 5}, complex_ptr = 0x[0-9a-f]+}}\",type=\"complex_type \[2\]\",thread-id=\"1\",has_more=\"0\"")
+
+        # Test that -gdb-set can set print aggregate-field-names flag
+        self.runCmd("-gdb-set print aggregate-field-names off")
+        self.expect("\^done")
+        self.runCmd("-gdb-set print aggregate-field-names 0")
+        self.expect("\^done")
+        self.runCmd("-gdb-show print aggregate-field-names")
+        self.expect("\^done,value=\"off\"")
+
+        # Test that composite type is expanded without field name when print aggregate-field-names is "off"
+        self.runCmd("-var-create var3 * complx")
+        self.expect("\^done,name=\"var3\",numchild=\"3\",value=\"{3,\{3\},0x[0-9a-f]+}\",type=\"complex_type\",thread-id=\"1\",has_more=\"0\"")
+
+        # Test that composite type[] is expanded without field name when print aggregate-field-names is "off"
+        self.runCmd("-var-create var4 * complx_array")
+        self.expect("\^done,name=\"var4\",numchild=\"2\",value=\"{{4,\{4\},0x[0-9a-f]+},{5,\{5\},0x[0-9a-f]+}}\",type=\"complex_type \[2\]\",thread-id=\"1\",has_more=\"0\"")
+
+        # Test that -gdb-set print aggregate-field-names fails if "on"/"off" isn't specified
+        self.runCmd("-gdb-set print aggregate-field-names")
+        self.expect("\^error,msg=\"The request ''print' expects option-name and \"on\" or \"off\"' failed.\"")
+
+        # Test that -gdb-set print aggregate-field-names fails when option is unknown
+        self.runCmd("-gdb-set print aggregate-field-names unknown")
+        self.expect("\^error,msg=\"The request ''print' expects option-name and \"on\" or \"off\"' failed.\"")
+
 if __name__ == '__main__':
     unittest2.main()

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=235807&r1=235806&r2=235807&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-mi/variable/main.cpp (original)
+++ lldb/trunk/test/tools/lldb-mi/variable/main.cpp Sat Apr 25 15:33:02 2015
@@ -52,6 +52,15 @@ gdb_set_show_print_expand_aggregates(voi
     // BP_gdb_set_show_print_expand_aggregates
 }
 
+void
+gdb_set_show_print_aggregate_field_names(void)
+{
+    complex_type complx = { 3, { 3L }, &complx };
+    complex_type complx_array[2] = { { 4, { 4L }, &complx_array[1] }, { 5, { 5 }, &complx_array[0] } };
+
+    // BP_gdb_set_show_print_aggregate_field_names
+}
+
 int g_MyVar = 3;
 static int s_MyVar = 4;
 
@@ -63,5 +72,6 @@ main(int argc, char const *argv[])
     var_update_test();
     gdb_set_show_print_char_array_as_string_test();
     gdb_set_show_print_expand_aggregates();
+    gdb_set_show_print_aggregate_field_names();
     return 0; // BP_return
 }

Modified: lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.cpp?rev=235807&r1=235806&r2=235807&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.cpp Sat Apr 25 15:33:02 2015
@@ -284,6 +284,8 @@ CMICmdCmdGdbSet::OptionFnPrint(const CMI
         strOptionKey = m_rLLDBDebugSessionInfo.m_constStrPrintCharArrayAsString;
     else if (CMIUtilString::Compare(strOption, "expand-aggregates"))
         strOptionKey = m_rLLDBDebugSessionInfo.m_constStrPrintExpandAggregates;
+    else if (CMIUtilString::Compare(strOption, "aggregate-field-names"))
+        strOptionKey = m_rLLDBDebugSessionInfo.m_constStrPrintAggregateFieldNames;
     else
     {
         m_bGbbOptionFnHasError = true;

Modified: lldb/trunk/tools/lldb-mi/MICmdCmdGdbShow.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCmdGdbShow.cpp?rev=235807&r1=235806&r2=235807&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdCmdGdbShow.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdCmdGdbShow.cpp Sat Apr 25 15:33:02 2015
@@ -266,6 +266,11 @@ CMICmdCmdGdbShow::OptionFnPrint(const CM
         strOptionKey = m_rLLDBDebugSessionInfo.m_constStrPrintCharArrayAsString;
     else if (CMIUtilString::Compare(strOption, "expand-aggregates"))
         strOptionKey = m_rLLDBDebugSessionInfo.m_constStrPrintExpandAggregates;
+    else if (CMIUtilString::Compare(strOption, "aggregate-field-names"))
+    {
+        strOptionKey = m_rLLDBDebugSessionInfo.m_constStrPrintAggregateFieldNames;
+        bOptionValueDefault = true;
+    }
     else
     {
         m_bGbbOptionFnHasError = true;

Modified: lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp?rev=235807&r1=235806&r2=235807&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp Sat Apr 25 15:33:02 2015
@@ -42,6 +42,7 @@ CMICmnLLDBDebugSessionInfo::CMICmnLLDBDe
     , m_constStrSharedDataSolibPath("Solib Path")
     , m_constStrPrintCharArrayAsString("Print CharArrayAsString")
     , m_constStrPrintExpandAggregates("Print ExpandAggregates")
+    , m_constStrPrintAggregateFieldNames("Print AggregateFieldNames")
 {
 }
 

Modified: lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h?rev=235807&r1=235806&r2=235807&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h (original)
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h Sat Apr 25 15:33:02 2015
@@ -185,6 +185,7 @@ class CMICmnLLDBDebugSessionInfo : publi
     const CMIUtilString m_constStrSharedDataSolibPath;
     const CMIUtilString m_constStrPrintCharArrayAsString;
     const CMIUtilString m_constStrPrintExpandAggregates;
+    const CMIUtilString m_constStrPrintAggregateFieldNames;
 
     // Typedefs:
   private:

Modified: lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp?rev=235807&r1=235806&r2=235807&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp Sat Apr 25 15:33:02 2015
@@ -91,8 +91,12 @@ CMICmnLLDBUtilSBValue::GetValue(const bo
     if (!vbExpandAggregates && !bPrintExpandAggregates)
         return m_pComposite;
 
+    bool bPrintAggregateFieldNames = false;
+    bPrintAggregateFieldNames = !rSessionInfo.SharedDataRetrieve<bool>(rSessionInfo.m_constStrPrintAggregateFieldNames,
+                                                                       bPrintAggregateFieldNames) || bPrintAggregateFieldNames;
+
     CMICmnMIValueTuple miValueTuple;
-    const bool bOk = GetCompositeValue(miValueTuple);
+    const bool bOk = GetCompositeValue(bPrintAggregateFieldNames, miValueTuple);
     if (!bOk)
         return m_pUnkwn;
 
@@ -175,7 +179,7 @@ CMICmnLLDBUtilSBValue::GetSimpleValue(co
 }
 
 bool
-CMICmnLLDBUtilSBValue::GetCompositeValue(CMICmnMIValueTuple &vwrMiValueTuple,
+CMICmnLLDBUtilSBValue::GetCompositeValue(const bool vbPrintFieldNames, CMICmnMIValueTuple &vwrMiValueTuple,
                                          const MIuint vnDepth /* = 1 */) const
 {
     const MIuint nMaxDepth = 10;
@@ -195,7 +199,7 @@ CMICmnLLDBUtilSBValue::GetCompositeValue
         {
             // Need to get value from composite type
             CMICmnMIValueTuple miValueTuple;
-            const bool bOk = utilMember.GetCompositeValue(miValueTuple, vnDepth + 1);
+            const bool bOk = utilMember.GetCompositeValue(vbPrintFieldNames, miValueTuple, vnDepth + 1);
             if (!bOk)
                 // Can't obtain composite type
                 value = m_pUnkwn;
@@ -210,11 +214,21 @@ CMICmnLLDBUtilSBValue::GetCompositeValue
         }
         const bool bNoQuotes = true;
         const CMICmnMIValueConst miValueConst(value, bNoQuotes);
-        const bool bUseSpacing = true;
-        const CMICmnMIValueResult miValueResult(utilMember.GetName(), miValueConst, bUseSpacing);
-        const bool bOk = vwrMiValueTuple.Add(miValueResult, bUseSpacing);
-        if (!bOk)
-            return MIstatus::failure;
+        if (vbPrintFieldNames)
+        {
+            const bool bUseSpacing = true;
+            const CMICmnMIValueResult miValueResult(utilMember.GetName(), miValueConst, bUseSpacing);
+            const bool bOk = vwrMiValueTuple.Add(miValueResult, bUseSpacing);
+            if (!bOk)
+                return MIstatus::failure;
+        }
+        else
+        {
+            const bool bUseSpacing = false;
+            const bool bOk = vwrMiValueTuple.Add(miValueConst, bUseSpacing);
+            if (!bOk)
+                return MIstatus::failure;
+        }
     }
 
     return MIstatus::success;

Modified: lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.h?rev=235807&r1=235806&r2=235807&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.h (original)
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.h Sat Apr 25 15:33:02 2015
@@ -55,7 +55,7 @@ class CMICmnLLDBUtilSBValue
   private:
     CMIUtilString ReadCStringFromHostMemory(const lldb::SBValue &vrValueObj) const;
     bool GetSimpleValue(const bool vbHandleArrayType, CMIUtilString &vrValue) const;
-    bool GetCompositeValue(CMICmnMIValueTuple &vwrMiValueTuple, const MIuint vnDepth = 1) const;
+    bool GetCompositeValue(const bool vbPrintFieldNames, CMICmnMIValueTuple &vwrMiValueTuple, const MIuint vnDepth = 1) const;
 
     // Attributes:
   private:





More information about the lldb-commits mailing list