diff --git a/lldb/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py b/lldb/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py index 19284468137a..938e2425560b 100644 --- a/lldb/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py +++ b/lldb/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py @@ -65,5 +65,60 @@ class MiGdbSetShowTestCase(lldbmi_testcase.MiTestCaseBase): 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() diff --git a/lldb/test/tools/lldb-mi/variable/main.cpp b/lldb/test/tools/lldb-mi/variable/main.cpp index a61baa56103a..294f54542d79 100644 --- a/lldb/test/tools/lldb-mi/variable/main.cpp +++ b/lldb/test/tools/lldb-mi/variable/main.cpp @@ -43,6 +43,15 @@ gdb_set_show_print_char_array_as_string_test(void) // 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 } diff --git a/lldb/tools/lldb-mi/MICmdCmdGdbSet.cpp b/lldb/tools/lldb-mi/MICmdCmdGdbSet.cpp index b5202cf77891..dde01fb40375 100644 --- a/lldb/tools/lldb-mi/MICmdCmdGdbSet.cpp +++ b/lldb/tools/lldb-mi/MICmdCmdGdbSet.cpp @@ -282,6 +282,8 @@ CMICmdCmdGdbSet::OptionFnPrint(const CMIUtilString::VecString_t &vrWords) 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; diff --git a/lldb/tools/lldb-mi/MICmdCmdGdbShow.cpp b/lldb/tools/lldb-mi/MICmdCmdGdbShow.cpp index 41661c23e4a4..df2bfcff67db 100644 --- a/lldb/tools/lldb-mi/MICmdCmdGdbShow.cpp +++ b/lldb/tools/lldb-mi/MICmdCmdGdbShow.cpp @@ -264,6 +264,8 @@ CMICmdCmdGdbShow::OptionFnPrint(const CMIUtilString::VecString_t &vrWords) 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; diff --git a/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp b/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp index 63c9a183c04d..f65fbe2b00a5 100644 --- a/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp +++ b/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp @@ -41,6 +41,7 @@ CMICmnLLDBDebugSessionInfo::CMICmnLLDBDebugSessionInfo(void) , m_constStrSharedDataKeyWkDir("Working Directory") , m_constStrSharedDataSolibPath("Solib Path") , m_constStrPrintCharArrayAsString("Print CharArrayAsString") + , m_constStrPrintExpandAggregates("Print ExpandAggregates") { } diff --git a/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h b/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h index 03ebc39aea39..2f9ae0c9b04d 100644 --- a/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h +++ b/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h @@ -184,6 +184,7 @@ class CMICmnLLDBDebugSessionInfo : public CMICmnBase, public MI::ISingleton(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;