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"
```

llvm-svn: 235805
This commit is contained in:
Ilia K 2015-04-25 20:10:02 +00:00
parent aa82b4af84
commit 81bd06d787
7 changed files with 78 additions and 2 deletions

View File

@ -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()

View File

@ -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
}

View File

@ -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;

View File

@ -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;

View File

@ -41,6 +41,7 @@ CMICmnLLDBDebugSessionInfo::CMICmnLLDBDebugSessionInfo(void)
, m_constStrSharedDataKeyWkDir("Working Directory")
, m_constStrSharedDataSolibPath("Solib Path")
, m_constStrPrintCharArrayAsString("Print CharArrayAsString")
, m_constStrPrintExpandAggregates("Print ExpandAggregates")
{
}

View File

@ -184,6 +184,7 @@ class CMICmnLLDBDebugSessionInfo : public CMICmnBase, public MI::ISingleton<CMIC
const CMIUtilString m_constStrSharedDataKeyWkDir;
const CMIUtilString m_constStrSharedDataSolibPath;
const CMIUtilString m_constStrPrintCharArrayAsString;
const CMIUtilString m_constStrPrintExpandAggregates;
// Typedefs:
private:

View File

@ -77,13 +77,18 @@ CMICmnLLDBUtilSBValue::GetValue(const bool vbExpandAggregates /* = false */) con
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;