From 93183ec9ee4ee8468df2190f4cf64468242f41cf Mon Sep 17 00:00:00 2001 From: Eugene Teo Date: Wed, 2 May 2007 16:14:20 -0300 Subject: [PATCH] [PAHOLE]: Added an option -r to use rel_offset when printing inner structs By default, pahole will display the offsets of the inner struct members from the top level struct. If the user wants to focus on some inner structs, just call the tool with the -r option to use relative offset instead of the base offset. Signed-off-by: Eugene Teo Signed-off-by: Arnaldo Carvalho de Melo --- dwarves.c | 12 ++++++++---- dwarves.h | 1 + pahole.c | 9 +++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/dwarves.c b/dwarves.c index 130049a..8ffc3a2 100644 --- a/dwarves.c +++ b/dwarves.c @@ -1240,9 +1240,13 @@ static size_t struct_member__fprintf(struct class_member *self, int spacing; const int size = tag__size(type, cu); struct conf_fprintf sconf = *conf; + uint32_t offset = self->offset; size_t printed; - - sconf.base_offset += self->offset; + + if (!sconf.rel_offset) { + sconf.base_offset += self->offset; + offset = sconf.base_offset; + } printed = type__fprintf(type, cu, self->name, &sconf, fp); @@ -1264,12 +1268,12 @@ static size_t struct_member__fprintf(struct class_member *self, return printed + fprintf(fp, "%*s/* %5u %5u */", (sconf.type_spacing + sconf.name_spacing - slen - 3), - " ", sconf.base_offset, size); + " ", offset, size); } spacing = sconf.type_spacing + sconf.name_spacing - printed; return printed + fprintf(fp, "%*s/* %5u %5u */", spacing > 0 ? spacing : 0, " ", - sconf.base_offset, size); + offset, size); } static size_t union_member__fprintf(struct class_member *self, diff --git a/dwarves.h b/dwarves.h index b9f3b6a..8f4d67b 100644 --- a/dwarves.h +++ b/dwarves.h @@ -263,6 +263,7 @@ struct conf_fprintf { const char *suffix; uint32_t base_offset; uint8_t expand_types; + uint8_t rel_offset; uint8_t emit_stats; uint8_t indent; int32_t type_spacing; diff --git a/pahole.c b/pahole.c index 441d703..40fcf68 100644 --- a/pahole.c +++ b/pahole.c @@ -34,6 +34,7 @@ static uint16_t nr_bit_holes; static uint8_t show_packable; static uint8_t global_verbose; static uint8_t expand_types; +static uint8_t rel_offset; static size_t cacheline_size; static int reorganize; static int show_reorg_steps; @@ -140,6 +141,7 @@ static void class_formatter(const struct structure *self) const char *name = class__name(self->class); struct conf_fprintf conf = { .expand_types = expand_types, + .rel_offset = rel_offset, .emit_stats = 1, }; @@ -450,6 +452,11 @@ static const struct argp_option pahole__options[] = { .key = 'n', .doc = "show number of members", }, + { + .name = "rel_offset", + .key = 'r', + .doc = "show relative offsets of members in inner structs" + }, { .name = "reorganize", .key = 'R', @@ -530,6 +537,7 @@ static error_t pahole__options_parser(int key, char *arg, case 'H': nr_holes = atoi(arg); break; case 'B': nr_bit_holes = atoi(arg); break; case 'E': expand_types = 1; break; + case 'r': rel_offset = 1; break; case 'R': reorganize = 1; break; case 'S': show_reorg_steps = 1; break; case 's': formatter = size_formatter; break; @@ -589,6 +597,7 @@ int main(int argc, char *argv[]) struct structure *s = structures__find(class_name); struct conf_fprintf conf = { .expand_types = expand_types, + .rel_offset = rel_offset, .emit_stats = 1, };