From 91ff9fceb916324358130cdba39a9513258ea15b Mon Sep 17 00:00:00 2001 From: Thierry Treyer Date: Wed, 10 Jan 2024 08:14:30 -0800 Subject: [PATCH] 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. --- oi/TreeBuilder.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/oi/TreeBuilder.cpp b/oi/TreeBuilder.cpp index 954b293..2ff1102 100644 --- a/oi/TreeBuilder.cpp +++ b/oi/TreeBuilder.cpp @@ -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) {