@@ -169,21 +169,49 @@ static lldb::Format GetItemFormatForFormat(lldb::Format format,
169
169
}
170
170
}
171
171
172
- static size_t CalculateNumChildren (
173
- CompilerType container_type, CompilerType element_type,
174
- lldb_private::ExecutionContextScope *exe_scope =
175
- nullptr // does not matter here because all we trade in are basic types
176
- ) {
177
- std::optional<uint64_t > container_size =
178
- container_type.GetByteSize (exe_scope);
179
- std::optional<uint64_t > element_size = element_type.GetByteSize (exe_scope);
180
-
181
- if (container_size && element_size && *element_size) {
182
- if (*container_size % *element_size)
183
- return 0 ;
184
- return *container_size / *element_size;
185
- }
186
- return 0 ;
172
+ // / Calculates the number of elements stored in a container (with
173
+ // / element type 'container_elem_type') as if it had elements of type
174
+ // / 'element_type'.
175
+ // /
176
+ // / For example, a container of type
177
+ // / `uint8_t __attribute__((vector_size(16)))` has 16 elements.
178
+ // / But calling `CalculateNumChildren` with an 'element_type'
179
+ // / of `float` (4-bytes) will return `4` because we are interpreting
180
+ // / the byte-array as a `float32[]`.
181
+ // /
182
+ // / \param[in] container_elem_type The type of the elements stored
183
+ // / in the container we are calculating the children of.
184
+ // /
185
+ // / \param[in] num_elements Number of 'container_elem_type's our
186
+ // / container stores.
187
+ // /
188
+ // / \param[in] element_type The type of elements we interpret
189
+ // / container_type to contain for the purposes of calculating
190
+ // / the number of children.
191
+ // /
192
+ // / \returns The number of elements stored in a container of
193
+ // / type 'element_type'. Returns a std::nullopt if the
194
+ // / size of the container is not a multiple of 'element_type'
195
+ // / or if an error occurs.
196
+ static std::optional<size_t >
197
+ CalculateNumChildren (CompilerType container_elem_type, uint64_t num_elements,
198
+ CompilerType element_type) {
199
+ std::optional<uint64_t > container_elem_size =
200
+ container_elem_type.GetByteSize (/* exe_scope */ nullptr );
201
+ if (!container_elem_size)
202
+ return {};
203
+
204
+ auto container_size = *container_elem_size * num_elements;
205
+
206
+ std::optional<uint64_t > element_size =
207
+ element_type.GetByteSize (/* exe_scope */ nullptr );
208
+ if (!element_size || !*element_size)
209
+ return {};
210
+
211
+ if (container_size % *element_size)
212
+ return {};
213
+
214
+ return container_size / *element_size;
187
215
}
188
216
189
217
namespace lldb_private {
@@ -221,11 +249,14 @@ class VectorTypeSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
221
249
m_parent_format = m_backend.GetFormat ();
222
250
CompilerType parent_type (m_backend.GetCompilerType ());
223
251
CompilerType element_type;
224
- parent_type.IsVectorType (&element_type);
252
+ uint64_t num_elements;
253
+ parent_type.IsVectorType (&element_type, &num_elements);
225
254
m_child_type = ::GetCompilerTypeForFormat (
226
255
m_parent_format, element_type,
227
256
parent_type.GetTypeSystem ().GetSharedPointer ());
228
- m_num_children = ::CalculateNumChildren (parent_type, m_child_type);
257
+ m_num_children =
258
+ ::CalculateNumChildren (element_type, num_elements, m_child_type)
259
+ .value_or(0 );
229
260
m_item_format = GetItemFormatForFormat (m_parent_format, m_child_type);
230
261
return false ;
231
262
}
0 commit comments