[Lldb-commits] [lldb] r235805 - Add -gdb-set/-gdb-show expand-aggregates option (MI)

Ilia K ki.stfu at gmail.com
Sat Apr 25 13:10:02 PDT 2015


Author: ki.stfu
Date: Sat Apr 25 15:10:02 2015
New Revision: 235805

URL: http://llvm.org/viewvc/llvm-project?rev=235805&view=rev
Log:
Add -gdb-set/-gdb-show expand-aggregates option (MI)

Use this option to expand complex types always:
```
-var-create var1 * complx
^done,name="var1",numchild="3",value="{...}",type="complex_type",thread-id="1",has_more="0"
-var-create var2 * complx_array
^done,name="var2",numchild="2",value="[2]",type="complex_type [2]",thread-id="1",has_more="0"
-gdb-set print expand-aggregates on
^done
-var-create var3 * complx
^done,name="var3",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 var4 * complx_array
^done,name="var4",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"
```


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

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=235805&r1=235804&r2=235805&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:10:02 2015
@@ -65,5 +65,60 @@ class MiGdbSetShowTestCase(lldbmi_testca
         self.runCmd("-gdb-set print char-array-as-string 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_expand_aggregates(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_expand_aggregates
+        line = line_number('main.cpp', '// BP_gdb_set_show_print_expand_aggregates')
+        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 expand-aggregates value is "off"
+        self.runCmd("-gdb-show print expand-aggregates")
+        self.expect("\^done,value=\"off\"")
+
+        # Test that composite type isn't expanded when print expand-aggregates is "off"
+        self.runCmd("-var-create var1 * complx")
+        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\"")
+
+        # Test that -gdb-set can set print expand-aggregates flag
+        self.runCmd("-gdb-set print expand-aggregates on")
+        self.expect("\^done")
+        self.runCmd("-gdb-set print expand-aggregates 1")
+        self.expect("\^done")
+        self.runCmd("-gdb-show print expand-aggregates")
+        self.expect("\^done,value=\"on\"")
+
+        # Test that composite type is expanded when print expand-aggregates is "on"
+        self.runCmd("-var-create var3 * complx")
+        self.expect("\^done,name=\"var3\",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 when print expand-aggregates is "on"
+        self.runCmd("-var-create var4 * complx_array")
+        self.expect("\^done,name=\"var4\",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 print expand-aggregates fails if "on"/"off" isn't specified
+        self.runCmd("-gdb-set print expand-aggregates")
+        self.expect("\^error,msg=\"The request ''print' expects option-name and \"on\" or \"off\"' failed.\"")
+
+        # Test that -gdb-set print expand-aggregates fails when option is unknown
+        self.runCmd("-gdb-set print expand-aggregates 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=235805&r1=235804&r2=235805&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:10:02 2015
@@ -43,6 +43,15 @@ gdb_set_show_print_char_array_as_string_
     // BP_gdb_set_show_print_char_array_as_string_test
 }
 
+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] } };
+
+    // BP_gdb_set_show_print_expand_aggregates
+}
+
 int g_MyVar = 3;
 static int s_MyVar = 4;
 
@@ -53,5 +62,6 @@ main(int argc, char const *argv[])
     s_MyVar = a + b;
     var_update_test();
     gdb_set_show_print_char_array_as_string_test();
+    gdb_set_show_print_expand_aggregates();
     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=235805&r1=235804&r2=235805&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.cpp Sat Apr 25 15:10:02 2015
@@ -282,6 +282,8 @@ CMICmdCmdGdbSet::OptionFnPrint(const CMI
     CMIUtilString strOptionKey;
     if (CMIUtilString::Compare(strOption, "char-array-as-string"))
         strOptionKey = m_rLLDBDebugSessionInfo.m_constStrPrintCharArrayAsString;
+    else if (CMIUtilString::Compare(strOption, "expand-aggregates"))
+        strOptionKey = m_rLLDBDebugSessionInfo.m_constStrPrintExpandAggregates;
     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=235805&r1=235804&r2=235805&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdCmdGdbShow.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdCmdGdbShow.cpp Sat Apr 25 15:10:02 2015
@@ -264,6 +264,8 @@ CMICmdCmdGdbShow::OptionFnPrint(const CM
     bool bOptionValueDefault = false;
     if (CMIUtilString::Compare(strOption, "char-array-as-string"))
         strOptionKey = m_rLLDBDebugSessionInfo.m_constStrPrintCharArrayAsString;
+    else if (CMIUtilString::Compare(strOption, "expand-aggregates"))
+        strOptionKey = m_rLLDBDebugSessionInfo.m_constStrPrintExpandAggregates;
     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=235805&r1=235804&r2=235805&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp Sat Apr 25 15:10:02 2015
@@ -41,6 +41,7 @@ CMICmnLLDBDebugSessionInfo::CMICmnLLDBDe
     , m_constStrSharedDataKeyWkDir("Working Directory")
     , m_constStrSharedDataSolibPath("Solib Path")
     , m_constStrPrintCharArrayAsString("Print CharArrayAsString")
+    , m_constStrPrintExpandAggregates("Print ExpandAggregates")
 {
 }
 

Modified: lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h?rev=235805&r1=235804&r2=235805&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h (original)
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h Sat Apr 25 15:10:02 2015
@@ -184,6 +184,7 @@ class CMICmnLLDBDebugSessionInfo : publi
     const CMIUtilString m_constStrSharedDataKeyWkDir;
     const CMIUtilString m_constStrSharedDataSolibPath;
     const CMIUtilString m_constStrPrintCharArrayAsString;
+    const CMIUtilString m_constStrPrintExpandAggregates;
 
     // 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=235805&r1=235804&r2=235805&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp Sat Apr 25 15:10:02 2015
@@ -77,13 +77,18 @@ CMICmnLLDBUtilSBValue::GetValue(const bo
     if (!m_bValidSBValue)
         return m_pUnkwn;
 
-    const bool bHandleArrayTypeAsSimple = m_bHandleArrayType && !vbExpandAggregates;
+    CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
+    bool bPrintExpandAggregates = false;
+    bPrintExpandAggregates = rSessionInfo.SharedDataRetrieve<bool>(rSessionInfo.m_constStrPrintExpandAggregates,
+                                                                   bPrintExpandAggregates) && bPrintExpandAggregates;
+
+    const bool bHandleArrayTypeAsSimple = m_bHandleArrayType && !vbExpandAggregates && !bPrintExpandAggregates;
     CMIUtilString value;
     const bool bIsSimpleValue = GetSimpleValue(bHandleArrayTypeAsSimple, value);
     if (bIsSimpleValue)
         return value;
 
-    if (!vbExpandAggregates)
+    if (!vbExpandAggregates && !bPrintExpandAggregates)
         return m_pComposite;
 
     CMICmnMIValueTuple miValueTuple;





More information about the lldb-commits mailing list