Fix TreeBuilder processing of zero-length array

TreeBuilder did not consider a zero-length array like a container and
never read the array's sizeof stored in the data buffer, leading to a
mismatch between bytes written vs read out of the buffer.

Now, `TreeBuilder::isContainer` does consider zero-length array like
a container and properly consume all the object sizes in the buffer.
This commit is contained in:
Thierry Treyer 2024-01-10 08:14:30 -08:00 committed by Thierry Treyer
parent fba0d527fd
commit 91ff9fceb9

View File

@ -378,9 +378,20 @@ uint64_t TreeBuilder::next() {
}
bool TreeBuilder::isContainer(const Variable& variable) {
return th->containerTypeMap.contains(variable.type) ||
(drgn_type_kind(variable.type) == DRGN_TYPE_ARRAY &&
drgn_type_length(variable.type) > 0);
if (th->containerTypeMap.contains(variable.type)) {
return true;
}
if (drgn_type_kind(variable.type) == DRGN_TYPE_ARRAY) {
/* CodeGen v1 does not consider zero-length array as containers,
* but CodeGen v2 does. This discrepancy is handled here.
* TODO: Cleanup this workaround once CodeGen v1 is gone. See #453
*/
return config.features[Feature::TypeGraph] ||
drgn_type_length(variable.type) > 0;
}
return false;
}
bool TreeBuilder::isPrimitive(struct drgn_type* type) {