[LIB]: Emit typedefs of typedef arrays
Such as this one, when using ctracer to trace struct task_struct methods: --- ctracer_methods.c.before 2007-01-24 09:20:30.000000000 -0200 +++ ctracer_methods.c 2007-01-24 09:38:35.000000000 -0200 @@ -759,7 +759,8 @@ .entry = (kprobe_opcode_t *)jprobe_entry__release_thread, }; -typedef elf_greg_t elf_gregset_t; +typedef long unsigned int elf_greg_t; +typedef elf_greg_t elf_gregset_t[17]; static int jprobe_entry__dump_task_regs(struct task_struct * tsk, elf_gregset_t * regs) { Code impact: [acme@filo pahole]$ codiff build/libdwarves.so.before build/libdwarves.so /home/acme/git/pahole/dwarves.c: typedef__print | +154 cus__emit_typedef_definitions | +27 2 functions changed, 181 bytes added [acme@filo pahole]$ Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
68d64b2930
commit
a4856181a7
79
dwarves.c
79
dwarves.c
|
@ -304,6 +304,40 @@ static struct base_type *base_type__new(Dwarf_Die *die)
|
|||
return self;
|
||||
}
|
||||
|
||||
static struct array_type *array_type__new(Dwarf_Die *die)
|
||||
{
|
||||
struct array_type *self = zalloc(sizeof(*self));
|
||||
|
||||
if (self != NULL)
|
||||
tag__init(&self->tag, die);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
static size_t array_type__snprintf(const struct tag *tag_self,
|
||||
const struct cu *cu,
|
||||
char *bf, const size_t len,
|
||||
const char *name,
|
||||
size_t type_spacing)
|
||||
{
|
||||
struct array_type *self = tag__array_type(tag_self);
|
||||
char tbf[128];
|
||||
size_t l = len;
|
||||
size_t n = snprintf(bf, l, "%-*s %s", type_spacing,
|
||||
tag__name(tag_self, cu, tbf, sizeof(tbf)),
|
||||
name);
|
||||
int i;
|
||||
|
||||
bf += n; l -= n;
|
||||
|
||||
for (i = 0; i < self->dimensions; ++i) {
|
||||
n = snprintf(bf, l, "[%u]", self->nr_entries[i]);
|
||||
bf += n; l -= n;
|
||||
}
|
||||
|
||||
return len - l;
|
||||
}
|
||||
|
||||
static void type__init(struct type *self, Dwarf_Die *die)
|
||||
{
|
||||
tag__init(&self->tag, die);
|
||||
|
@ -341,6 +375,11 @@ static void typedef__print(const struct tag *tag_self, const struct cu *cu)
|
|||
}
|
||||
|
||||
switch (type->tag) {
|
||||
case DW_TAG_array_type:
|
||||
array_type__snprintf(type, cu, bf, sizeof(bf), self->name, 0);
|
||||
fputs("typedef ", stdout);
|
||||
fputs(bf, stdout);
|
||||
return;
|
||||
case DW_TAG_pointer_type:
|
||||
if (type->type == 0) /* void pointer */
|
||||
break;
|
||||
|
@ -1019,40 +1058,6 @@ static struct label *label__new(Dwarf_Die *die)
|
|||
return self;
|
||||
}
|
||||
|
||||
static struct array_type *array_type__new(Dwarf_Die *die)
|
||||
{
|
||||
struct array_type *self = zalloc(sizeof(*self));
|
||||
|
||||
if (self != NULL)
|
||||
tag__init(&self->tag, die);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
static size_t array_type__snprintf(const struct tag *tag_self,
|
||||
const struct cu *cu,
|
||||
char *bf, const size_t len,
|
||||
const char *name,
|
||||
size_t type_spacing)
|
||||
{
|
||||
struct array_type *self = tag__array_type(tag_self);
|
||||
char tbf[128];
|
||||
size_t l = len;
|
||||
size_t n = snprintf(bf, l, "%-*s %s", type_spacing,
|
||||
tag__name(tag_self, cu, tbf, sizeof(tbf)),
|
||||
name);
|
||||
int i;
|
||||
|
||||
bf += n; l -= n;
|
||||
|
||||
for (i = 0; i < self->dimensions; ++i) {
|
||||
n = snprintf(bf, l, "[%u]", self->nr_entries[i]);
|
||||
bf += n; l -= n;
|
||||
}
|
||||
|
||||
return len - l;
|
||||
}
|
||||
|
||||
static size_t union__snprintf(const struct type *self, const struct cu *cu,
|
||||
char *bf, size_t len, const char *prefix,
|
||||
const char *suffix, uint8_t indent,
|
||||
|
@ -2596,6 +2601,9 @@ static int cus__emit_enumeration_definitions(struct cus *self, struct tag *tag,
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int cus__emit_tag_definitions(struct cus *self, struct cu *cu,
|
||||
struct tag *tag);
|
||||
|
||||
static int cus__emit_typedef_definitions(struct cus *self, struct cu *cu,
|
||||
struct tag *tdef)
|
||||
{
|
||||
|
@ -2620,6 +2628,9 @@ static int cus__emit_typedef_definitions(struct cus *self, struct cu *cu,
|
|||
type = cu__find_tag_by_id(cu, tdef->type);
|
||||
|
||||
switch (type->tag) {
|
||||
case DW_TAG_array_type:
|
||||
cus__emit_tag_definitions(self, cu, type);
|
||||
break;
|
||||
case DW_TAG_typedef:
|
||||
cus__emit_typedef_definitions(self, cu, type);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue