forked from OSchip/llvm-project
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" ``` llvm-svn: 235807
This commit is contained in:
parent
3c613d608d
commit
94b8ebcacf
|
@ -120,5 +120,64 @@ class MiGdbSetShowTestCase(lldbmi_testcase.MiTestCaseBase):
|
|||
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()
|
||||
|
|
|
@ -52,6 +52,15 @@ gdb_set_show_print_expand_aggregates(void)
|
|||
// 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
|
||||
}
|
||||
|
|
|
@ -284,6 +284,8 @@ CMICmdCmdGdbSet::OptionFnPrint(const CMIUtilString::VecString_t &vrWords)
|
|||
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;
|
||||
|
|
|
@ -266,6 +266,11 @@ CMICmdCmdGdbShow::OptionFnPrint(const CMIUtilString::VecString_t &vrWords)
|
|||
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;
|
||||
|
|
|
@ -42,6 +42,7 @@ CMICmnLLDBDebugSessionInfo::CMICmnLLDBDebugSessionInfo(void)
|
|||
, m_constStrSharedDataSolibPath("Solib Path")
|
||||
, m_constStrPrintCharArrayAsString("Print CharArrayAsString")
|
||||
, m_constStrPrintExpandAggregates("Print ExpandAggregates")
|
||||
, m_constStrPrintAggregateFieldNames("Print AggregateFieldNames")
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -185,6 +185,7 @@ class CMICmnLLDBDebugSessionInfo : public CMICmnBase, public MI::ISingleton<CMIC
|
|||
const CMIUtilString m_constStrSharedDataSolibPath;
|
||||
const CMIUtilString m_constStrPrintCharArrayAsString;
|
||||
const CMIUtilString m_constStrPrintExpandAggregates;
|
||||
const CMIUtilString m_constStrPrintAggregateFieldNames;
|
||||
|
||||
// Typedefs:
|
||||
private:
|
||||
|
|
|
@ -91,8 +91,12 @@ CMICmnLLDBUtilSBValue::GetValue(const bool vbExpandAggregates /* = false */) con
|
|||
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(const bool vbHandleArrayType, CMIUtilStrin
|
|||
}
|
||||
|
||||
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(CMICmnMIValueTuple &vwrMiValueTuple,
|
|||
{
|
||||
// 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(CMICmnMIValueTuple &vwrMiValueTuple,
|
|||
}
|
||||
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;
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue