[PATCH v2 09/19] gendwarfksyms: Expand array_type
From: Sami Tolvanen
Date: Thu Aug 15 2024 - 13:41:40 EST
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@xxxxxxxxxx>
---
scripts/gendwarfksyms/dwarf.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/scripts/gendwarfksyms/dwarf.c b/scripts/gendwarfksyms/dwarf.c
index c81652426be8..4ec69fce95f3 100644
--- a/scripts/gendwarfksyms/dwarf.c
+++ b/scripts/gendwarfksyms/dwarf.c
@@ -218,6 +218,7 @@ DEFINE_PROCESS_UDATA_ATTRIBUTE(encoding)
}
DEFINE_MATCH(formal_parameter)
+DEFINE_MATCH(subrange)
bool match_all(Dwarf_Die *die)
{
@@ -309,6 +310,34 @@ DEFINE_PROCESS_TYPE(shared)
DEFINE_PROCESS_TYPE(volatile)
DEFINE_PROCESS_TYPE(typedef)
+static int process_subrange_type(struct state *state, struct die *cache,
+ Dwarf_Die *die)
+{
+ Dwarf_Word count = 0;
+
+ if (get_udata_attr(die, DW_AT_count, &count))
+ return check(process_fmt(state, cache, "[%" PRIu64 "]", count));
+ if (get_udata_attr(die, DW_AT_upper_bound, &count))
+ return check(
+ process_fmt(state, cache, "[%" PRIu64 "]", count + 1));
+
+ return check(process(state, cache, "[]"));
+}
+
+static int process_array_type(struct state *state, struct die *cache,
+ Dwarf_Die *die)
+{
+ check(process(state, cache, "array_type "));
+ /* Array size */
+ check(process_die_container(state, cache, die, process_type,
+ match_subrange_type));
+ check(process(state, cache, " {"));
+ check(process_linebreak(cache, 1));
+ check(process_type_attr(state, cache, die));
+ check(process_linebreak(cache, -1));
+ return check(process(state, cache, "}"));
+}
+
static int __process_subroutine_type(struct state *state, struct die *cache,
Dwarf_Die *die, const char *type)
{
@@ -411,7 +440,9 @@ static int process_type(struct state *state, struct die *parent, Dwarf_Die *die)
PROCESS_TYPE(volatile)
/* Subtypes */
PROCESS_TYPE(formal_parameter)
+ PROCESS_TYPE(subrange)
/* Other types */
+ PROCESS_TYPE(array)
PROCESS_TYPE(base)
PROCESS_TYPE(subroutine)
PROCESS_TYPE(typedef)
--
2.46.0.184.g6999bdac58-goog