Skip to content

Commit 73a0ddf

Browse files
committed
Treat anonymous struct that is nested in another one.
To determine whether an list of values is an array or an assortment of anonymous structs or unions, we have to look at the names of the members. But if the first member is itself anonymous, we have to inspect it recursively. So, do that.
1 parent e335e4a commit 73a0ddf

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

kdbg/gdbdriver.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,11 +1549,16 @@ static bool parseNested(const char*& s, ExprValue* variable)
15491549
* anonymous structs or unions. It is sufficient to check just two
15501550
* entries: if they have members with the same name, it is an array,
15511551
* because two anonymous structs or unions cannot have the same member names.
1552+
* Note that we must search for names recursively in the contained structs,
1553+
* because they can be anonymous as well.
15521554
* Also, if we find an empty struct, then this must be an array, because
15531555
* empty structs cannot be anonymous.
15541556
*/
15551557
auto firstName = [](ExprValue* var) {
1556-
return var->m_children.front()->m_name;
1558+
do {
1559+
var = var->m_children.front();
1560+
} while (var->m_nameKind == VarTree::NKanonymous);
1561+
return var->m_name;
15571562
};
15581563
ExprValue* a = variable->m_children.front();
15591564
ExprValue* b = variable->m_children.back();

kdbg/testprogs/anonstruct.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,15 @@ struct OnlyUnions {
4848
};
4949
};
5050
struct {
51+
// nested anonymous struct
5152
struct {
5253
int used;
5354
double avail;
5455
double* data;
55-
} member;
56+
};
57+
// need a named member, otherwise this struct
58+
// is mistakenly regarded as an array of length 1
59+
int member;
5660
};
5761
};
5862

0 commit comments

Comments
 (0)