From 98df4b62c410b0bafb3e3ce20627140e5b84e78c Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 4 Oct 2017 11:46:27 +0900 Subject: deal with arbitrary number of pointers --- dwarf-extract-struct.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/dwarf-extract-struct.c b/dwarf-extract-struct.c index dfd373b..57e7bbd 100644 --- a/dwarf-extract-struct.c +++ b/dwarf-extract-struct.c @@ -430,6 +430,7 @@ static void print_field(Dwarf_Debug dbg, Dwarf_Die die, const char *field_name, int offset = 0; char type_buf[1024]; char array_buf[128] = ""; + char pointer_buf[128] = ""; int rc; rc = dwarf_get_offset(dbg, die, &offset, &err); @@ -482,24 +483,26 @@ static void print_field(Dwarf_Debug dbg, Dwarf_Die die, const char *field_name, exit(7); } - if (type_tag == DW_TAG_pointer_type) { + while (type_tag == DW_TAG_pointer_type) { + pointer_buf[pointer++] = '*'; + rc = deref_type(dbg, type_die, &next, &type_tag, &err); /* No entry here means void* */ - if (rc != DW_DLV_NO_ENTRY) { - if (rc != DW_DLV_OK) { - fprintf(stderr, - "Could not deref type for %s: %s\n", - field_name, dwarf_errmsg(err)); - exit(7); - } + if (rc == DW_DLV_NO_ENTRY) + break; - dwarf_dealloc(dbg, type_die, DW_DLA_DIE); - type_die = next; + if (rc != DW_DLV_OK) { + fprintf(stderr, + "Could not deref type for %s: %s\n", + field_name, dwarf_errmsg(err)); + exit(7); } - pointer++; + dwarf_dealloc(dbg, type_die, DW_DLA_DIE); + type_die = next; } + if (type_tag == DW_TAG_array_type) { int next_offset, size; @@ -592,13 +595,13 @@ static void print_field(Dwarf_Debug dbg, Dwarf_Die die, const char *field_name, if (type_tag == DW_TAG_structure_type) { snprintf(type_buf, 1024, "struct %s %s", - type_name, pointer ? "*" : ""); + type_name, pointer_buf); } else if (type_tag == DW_TAG_base_type || type_tag == DW_TAG_typedef) { snprintf(type_buf, 1024, "%s %s", type_name, - pointer ? "*" : ""); + pointer_buf); } else if (type_tag == DW_TAG_pointer_type) { - snprintf(type_buf, 1024, "void *"); + snprintf(type_buf, 1024, "void %s", pointer_buf); } else { const char *tag_name; -- cgit v1.2.1-2-g3f67