Commit e3e6797f authored by hjk's avatar hjk

debugger: fix display and editing of nested anonymous structures

parent c6e88eec
......@@ -178,6 +178,17 @@ def listOfBreakpoints(d):
bp = Breakpoint()
# Creates a list of field names of an anon union or struct
def listOfFields(type):
fields = []
for field in type.fields():
if len(field.name) > 0:
fields += field.name
else:
fields += listOfFields(field.type)
return fields
def listOfLocals(varList):
try:
frame = gdb.selected_frame()
......@@ -1148,22 +1159,36 @@ class Dumper:
self.putField("iname", child.iname)
self.safePutItemHelper(child)
self.endHash()
elif field.name == "":
elif len(field.name) == 0:
# Anonymous union. We need a dummy name to distinguish
# multiple anonymous unions in the struct.
iname = "%s.#%d" % (item.iname, anonNumber)
anonNumber += 1
iname = "%s.#%d" % (item.iname, anonNumber)
#innerType = item.value.type.target()
#self.putType(innerType)
#self.childTypes.append(
# stripClassTag(str(innerType)))
#self.putItemHelper(
# Item(item.value.dereference(), item.iname, None, None))
#self.childTypes.pop()
#isHandled = True
self.beginHash()
self.putField("iname", iname)
self.putField("name", "<n/a>")
self.putField("name", "#%d" % anonNumber)
self.putField("value", " ")
self.putField("type", "<anonymous union>")
if self.isExpandedIName(iname):
self.beginChildren()
for f in field.type.fields():
child = Item(item.value[f.name],
item.iname, f.name, f.name)
self.safePutItem(child)
fields = listOfFields(field.type)
for field in fields:
value = item.value[field]
child = Item(value, item.iname, field, field)
self.beginHash()
self.put('addr="%s",' % cleanAddress(value.address))
self.safePutItemHelper(child)
self.endHash();
self.endChildren()
self.endHash()
else:
......
......@@ -212,6 +212,25 @@ void testArray()
}
}
struct TestAnonymous
{
union {
struct { int i; int b; };
struct { float f; };
double d;
};
};
// union { struct { int a; }; struct { int b; }; };
void testAnonymous()
{
TestAnonymous a;
a.i = 1;
a.i = 2;
a.i = 3;
}
void testQByteArray()
{
QByteArray ba = "Hello";
......@@ -1415,6 +1434,7 @@ int testReference()
int main(int argc, char *argv[])
{
testAnonymous();
testReference();
//testEndlessRecursion();
testQStack();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment