Skip to content

Commit 226d748

Browse files
committed
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 --debug: variable array_type [34] { pointer_type <unnamed> { const_type <unnamed> { base_type char byte_size(1) encoding(6) } } byte_size(8) }; Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
1 parent cb94504 commit 226d748

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

scripts/gendwarfksyms/dwarf.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ DEFINE_PROCESS_UDATA_ATTRIBUTE(encoding)
218218
}
219219

220220
DEFINE_MATCH(formal_parameter)
221+
DEFINE_MATCH(subrange)
221222

222223
bool match_all(Dwarf_Die *die)
223224
{
@@ -309,6 +310,34 @@ DEFINE_PROCESS_TYPE(shared)
309310
DEFINE_PROCESS_TYPE(volatile)
310311
DEFINE_PROCESS_TYPE(typedef)
311312

313+
static int process_subrange_type(struct state *state, struct die *cache,
314+
Dwarf_Die *die)
315+
{
316+
Dwarf_Word count = 0;
317+
318+
if (get_udata_attr(die, DW_AT_count, &count))
319+
return check(process_fmt(state, cache, "[%" PRIu64 "]", count));
320+
if (get_udata_attr(die, DW_AT_upper_bound, &count))
321+
return check(
322+
process_fmt(state, cache, "[%" PRIu64 "]", count + 1));
323+
324+
return check(process(state, cache, "[]"));
325+
}
326+
327+
static int process_array_type(struct state *state, struct die *cache,
328+
Dwarf_Die *die)
329+
{
330+
check(process(state, cache, "array_type "));
331+
/* Array size */
332+
check(process_die_container(state, cache, die, process_type,
333+
match_subrange_type));
334+
check(process(state, cache, " {"));
335+
check(process_linebreak(cache, 1));
336+
check(process_type_attr(state, cache, die));
337+
check(process_linebreak(cache, -1));
338+
return check(process(state, cache, "}"));
339+
}
340+
312341
static int __process_subroutine_type(struct state *state, struct die *cache,
313342
Dwarf_Die *die, const char *type)
314343
{
@@ -411,7 +440,9 @@ static int process_type(struct state *state, struct die *parent, Dwarf_Die *die)
411440
PROCESS_TYPE(volatile)
412441
/* Subtypes */
413442
PROCESS_TYPE(formal_parameter)
443+
PROCESS_TYPE(subrange)
414444
/* Other types */
445+
PROCESS_TYPE(array)
415446
PROCESS_TYPE(base)
416447
PROCESS_TYPE(subroutine)
417448
PROCESS_TYPE(typedef)

0 commit comments

Comments
 (0)