TypeGraph: Fix multi dimensional arrays

Multi dimensional arrays are not flattened into 1-D arrays when using
TypeGraph. Update TreeBuilder to account for this.

By not flattening arrays, we are able to produce more descriptive
results.

The disadvantage is that we must now recurse inside arrays
containing only primitives. A better solution to requiring flattening
would be the planned work to not recurse into any static types (not just
primitives). This would also apply to multi-dimensional arrays of
primtivies.
This commit is contained in:
Alastair Robertson 2023-05-31 08:40:21 -07:00 committed by Alastair Robertson
parent 784b900218
commit 2d28b20d46
3 changed files with 22 additions and 3 deletions

View File

@ -81,6 +81,9 @@ struct OIArray {
} }
void addIncludes(const TypeGraph& typeGraph, std::string& code) { void addIncludes(const TypeGraph& typeGraph, std::string& code) {
// Required for the offsetof() macro
code += "#include <cstddef>\n";
// TODO deduplicate containers // TODO deduplicate containers
for (const Type& t : typeGraph.finalTypes) { for (const Type& t : typeGraph.finalTypes) {
if (const auto* c = dynamic_cast<const Container*>(&t)) { if (const auto* c = dynamic_cast<const Container*>(&t)) {

View File

@ -571,8 +571,13 @@ void TreeBuilder::processContainer(const Variable& variable, Node& node) {
kind = ARRAY_TYPE; kind = ARRAY_TYPE;
struct drgn_type* arrayElementType = nullptr; struct drgn_type* arrayElementType = nullptr;
size_t numElems = 0; size_t numElems = 0;
drgn_utils::getDrgnArrayElementType(variable.type, &arrayElementType, if (config.features[Feature::TypeGraph]) {
numElems); arrayElementType = drgn_type_type(variable.type).type;
numElems = drgn_type_length(variable.type);
} else {
drgn_utils::getDrgnArrayElementType(variable.type, &arrayElementType,
numElems);
}
assert(numElems > 0); assert(numElems > 0);
elementTypes.push_back( elementTypes.push_back(
drgn_qualified_type{arrayElementType, (enum drgn_qualifiers)(0)}); drgn_qualified_type{arrayElementType, (enum drgn_qualifiers)(0)});

View File

@ -43,7 +43,8 @@ definitions = '''
"staticSize":0, "staticSize":0,
"dynamicSize":0 "dynamicSize":0
}]}]''' }]}]'''
[cases.multidim] [cases.multidim_legacy] # Test for legacy behaviour. Remove with OICodeGen
cli_options = ["-Ftype-graph"]
param_types = ["const MultiDim&"] param_types = ["const MultiDim&"]
setup = "return {};" setup = "return {};"
expect_json = '''[{ expect_json = '''[{
@ -56,6 +57,16 @@ definitions = '''
"capacity":6, "capacity":6,
"elementStaticSize":4 "elementStaticSize":4
}]}]''' }]}]'''
[cases.multidim]
cli_options = ["-ftype-graph"]
param_types = ["const MultiDim&"]
setup = "return {};"
expect_json = '''[
{"staticSize":24, "dynamicSize":0, "exclusiveSize":0, "members":[
{"staticSize":24, "dynamicSize":0, "exclusiveSize":0, "length":2, "capacity":2, "elementStaticSize":12, "members":[
{"staticSize":12, "dynamicSize":0, "exclusiveSize":12, "length":3, "capacity":3, "elementStaticSize":4},
{"staticSize":12, "dynamicSize":0, "exclusiveSize":12, "length":3, "capacity":3, "elementStaticSize":4}]
}]}]'''
[cases.direct_int10] [cases.direct_int10]
skip = "Direct array arguments don't work" skip = "Direct array arguments don't work"
param_types = ["int[10]"] param_types = ["int[10]"]