History

gendwarfksyms: Expand array_type

Add support for expanding DW_TAG_array_type, and the subrange type indicating array size. Example source code: const char *s[34]; Output with --dump-dies: variable array_type[34] { pointer_type { const_type { base_type char byte_size(1) encoding(6) } } byte_size(8) }

Sami Tolvanen committed 1 year ago

Commit c772f1d1 parent 220a0851 file · +30 −0Browse files

Unified · Split

scripts/gendwarfksyms/dwarf.c+30−0
@@ -220,6 +220,7 @@ DEFINE_PROCESS_UDATA_ATTRIBUTE(encoding) · 219 unmodified lines
220220 }
221221
222222 DEFINE_MATCH(formal_parameter)
223+DEFINE_MATCH(subrange)
223224
224225 bool match_all(Dwarf_Die *die)
225226 {
@@ -342,6 +343,33 @@ DEFINE_PROCESS_TYPE(shared) · 116 unmodified lines
342343 DEFINE_PROCESS_TYPE(volatile)
343344 DEFINE_PROCESS_TYPE(typedef)
344345
346+static void process_subrange_type(struct state *state, struct die *cache,
347+ Dwarf_Die *die)
348+{
349+ Dwarf_Word count = 0;
350+
351+ if (get_udata_attr(die, DW_AT_count, &count))
352+ process_fmt(cache, "[%" PRIu64 "]", count);
353+ else if (get_udata_attr(die, DW_AT_upper_bound, &count))
354+ process_fmt(cache, "[%" PRIu64 "]", count + 1);
355+ else
356+ process(cache, "[]");
357+}
358+
359+static void process_array_type(struct state *state, struct die *cache,
360+ Dwarf_Die *die)
361+{
362+ process(cache, "array_type");
363+ /* Array size */
364+ check(process_die_container(state, cache, die, process_type,
365+ match_subrange_type));
366+ process(cache, " {");
367+ process_linebreak(cache, 1);
368+ process_type_attr(state, cache, die);
369+ process_linebreak(cache, -1);
370+ process(cache, "}");
371+}
372+
345373 static void __process_subroutine_type(struct state *state, struct die *cache,
346374 Dwarf_Die *die, const char *type)
347375 {
@@ -437,7 +465,9 @@ static int process_type(struct state *state, struct die *parent, Dwarf_Die *die) · 89 unmodified lines
437465 PROCESS_TYPE(volatile)
438466 /* Subtypes */
439467 PROCESS_TYPE(formal_parameter)
468+ PROCESS_TYPE(subrange)
440469 /* Other types */
470+ PROCESS_TYPE(array)
441471 PROCESS_TYPE(base)
442472 PROCESS_TYPE(subroutine)
443473 PROCESS_TYPE(typedef)