[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 <eteo@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
This commit is contained in:
Eugene Teo 2007-05-02 16:14:20 -03:00 committed by Arnaldo Carvalho de Melo
parent 224ba634ee
commit 93183ec9ee
3 changed files with 18 additions and 4 deletions

View File

@ -1240,9 +1240,13 @@ static size_t struct_member__fprintf(struct class_member *self,
int spacing; int spacing;
const int size = tag__size(type, cu); const int size = tag__size(type, cu);
struct conf_fprintf sconf = *conf; struct conf_fprintf sconf = *conf;
uint32_t offset = self->offset;
size_t printed; 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); 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 */", return printed + fprintf(fp, "%*s/* %5u %5u */",
(sconf.type_spacing + (sconf.type_spacing +
sconf.name_spacing - slen - 3), sconf.name_spacing - slen - 3),
" ", sconf.base_offset, size); " ", offset, size);
} }
spacing = sconf.type_spacing + sconf.name_spacing - printed; spacing = sconf.type_spacing + sconf.name_spacing - printed;
return printed + fprintf(fp, "%*s/* %5u %5u */", return printed + fprintf(fp, "%*s/* %5u %5u */",
spacing > 0 ? spacing : 0, " ", spacing > 0 ? spacing : 0, " ",
sconf.base_offset, size); offset, size);
} }
static size_t union_member__fprintf(struct class_member *self, static size_t union_member__fprintf(struct class_member *self,

View File

@ -263,6 +263,7 @@ struct conf_fprintf {
const char *suffix; const char *suffix;
uint32_t base_offset; uint32_t base_offset;
uint8_t expand_types; uint8_t expand_types;
uint8_t rel_offset;
uint8_t emit_stats; uint8_t emit_stats;
uint8_t indent; uint8_t indent;
int32_t type_spacing; int32_t type_spacing;

View File

@ -34,6 +34,7 @@ static uint16_t nr_bit_holes;
static uint8_t show_packable; static uint8_t show_packable;
static uint8_t global_verbose; static uint8_t global_verbose;
static uint8_t expand_types; static uint8_t expand_types;
static uint8_t rel_offset;
static size_t cacheline_size; static size_t cacheline_size;
static int reorganize; static int reorganize;
static int show_reorg_steps; static int show_reorg_steps;
@ -140,6 +141,7 @@ static void class_formatter(const struct structure *self)
const char *name = class__name(self->class); const char *name = class__name(self->class);
struct conf_fprintf conf = { struct conf_fprintf conf = {
.expand_types = expand_types, .expand_types = expand_types,
.rel_offset = rel_offset,
.emit_stats = 1, .emit_stats = 1,
}; };
@ -450,6 +452,11 @@ static const struct argp_option pahole__options[] = {
.key = 'n', .key = 'n',
.doc = "show number of members", .doc = "show number of members",
}, },
{
.name = "rel_offset",
.key = 'r',
.doc = "show relative offsets of members in inner structs"
},
{ {
.name = "reorganize", .name = "reorganize",
.key = 'R', .key = 'R',
@ -530,6 +537,7 @@ static error_t pahole__options_parser(int key, char *arg,
case 'H': nr_holes = atoi(arg); break; case 'H': nr_holes = atoi(arg); break;
case 'B': nr_bit_holes = atoi(arg); break; case 'B': nr_bit_holes = atoi(arg); break;
case 'E': expand_types = 1; break; case 'E': expand_types = 1; break;
case 'r': rel_offset = 1; break;
case 'R': reorganize = 1; break; case 'R': reorganize = 1; break;
case 'S': show_reorg_steps = 1; break; case 'S': show_reorg_steps = 1; break;
case 's': formatter = size_formatter; 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 structure *s = structures__find(class_name);
struct conf_fprintf conf = { struct conf_fprintf conf = {
.expand_types = expand_types, .expand_types = expand_types,
.rel_offset = rel_offset,
.emit_stats = 1, .emit_stats = 1,
}; };