[LIB]: Use a base_offset when printing inner structs
That way we can have the offsets from the top level struct. If the user wants to focus some inner struct, just call the tool again specifying the inner struct name. Perhaps this is not so clear, shoot me, erm, no, an example should help. Look at the member offsets (first column in the comment after each member), before and after: before: acme@filo pahole]$ pahole -C tcp_sock --expand_types examples/net /* <12a> examples/expand.c:18 */ struct tcp_sock { struct inet_sock { struct sock { int protocol; /* 0 4 */ struct spinlock { int magic; /* 0 4 */ int counter; /* 4 4 */ } sklock; /* 4 8 */ int b; /* 12 4 */ int c; /* 16 4 */ } sk; /* 0 20 */ long int daddr; /* 20 4 */ } inet; /* 0 24 */ long int cwnd; /* 24 4 */ struct spinlock { int magic; /* 0 4 */ int counter; /* 4 4 */ } lock; /* 28 8 */ }; /* size: 36, cachelines: 1 */ /* last cacheline: 36 bytes */ After: acme@filo pahole]$ pahole -C tcp_sock --expand_types examples/net /* <12a> examples/expand.c:18 */ struct tcp_sock { struct inet_sock { struct sock { int protocol; /* 0 4 */ struct spinlock { int magic; /* 4 4 */ int counter; /* 8 4 */ } sklock; /* 4 8 */ int b; /* 12 4 */ int c; /* 16 4 */ } sk; /* 0 20 */ long int daddr; /* 20 4 */ } inet; /* 0 24 */ long int cwnd; /* 24 4 */ struct spinlock { int magic; /* 28 4 */ int counter; /* 32 4 */ } lock; /* 28 8 */ }; /* size: 36, cachelines: 1 */ /* last cacheline: 36 bytes */ Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
This commit is contained in:
parent
55dd0a7efa
commit
711d96943a
|
@ -281,7 +281,7 @@ static int class__emit_ostra_converter(const struct tag *tag_self,
|
|||
fputs("#include <stdio.h>\n"
|
||||
"#include <string.h>\n"
|
||||
"#include \"ctracer_relay.h\"\n\n", fp_converter);
|
||||
class__fprintf(mini_class, cu, NULL, NULL, 0, 0, 26, 23, 1,
|
||||
class__fprintf(mini_class, cu, NULL, NULL, 0, 0, 0, 26, 23, 1,
|
||||
fp_converter);
|
||||
emit_struct_member_table_entry(fp_fields, field++, "action", 0,
|
||||
"entry,exit");
|
||||
|
@ -354,7 +354,7 @@ static int class__emit_subset(const struct tag *tag_self, const struct cu *cu)
|
|||
if (mini_class == NULL)
|
||||
goto out;
|
||||
|
||||
class__fprintf(mini_class, cu, NULL, NULL, 0, 0, 26, 23, 1,
|
||||
class__fprintf(mini_class, cu, NULL, NULL, 0, 0, 0, 26, 23, 1,
|
||||
fp_methods);
|
||||
fputc('\n', fp_methods);
|
||||
class__emit_class_state_collector(self, mini_class);
|
||||
|
@ -539,7 +539,7 @@ static void emit_function_defs(const char *fn)
|
|||
cus__emit_ftype_definitions(kprobes_cus, cu,
|
||||
&tag__function(f)->proto,
|
||||
fp_methods);
|
||||
tag__fprintf(f, cu, NULL, NULL, 0, fp_methods);
|
||||
tag__fprintf(f, cu, NULL, NULL, 0, 0, fp_methods);
|
||||
fputs(";\n", fp_methods);
|
||||
}
|
||||
}
|
||||
|
|
78
dwarves.c
78
dwarves.c
|
@ -1133,14 +1133,14 @@ static struct label *label__new(Dwarf_Die *die)
|
|||
|
||||
static size_t union__fprintf(const struct type *self, const struct cu *cu,
|
||||
const char *prefix, const char *suffix,
|
||||
uint8_t expand_types, uint8_t indent,
|
||||
size_t type_spacing, size_t name_spacing,
|
||||
FILE *fp);
|
||||
uint32_t base_offset, uint8_t expand_types,
|
||||
uint8_t indent, size_t type_spacing,
|
||||
size_t name_spacing, FILE *fp);
|
||||
|
||||
static size_t type__fprintf(struct tag *type, const char *name,
|
||||
const struct cu *cu, uint8_t expand_types,
|
||||
int indent, int type_spacing,
|
||||
int name_spacing, FILE *fp)
|
||||
const struct cu *cu, uint32_t base_offset,
|
||||
uint8_t expand_types, int indent,
|
||||
int type_spacing, int name_spacing, FILE *fp)
|
||||
{
|
||||
char tbf[128];
|
||||
struct type *ctype;
|
||||
|
@ -1195,7 +1195,7 @@ static size_t type__fprintf(struct tag *type, const char *name,
|
|||
type_spacing - 7, ctype->name, name);
|
||||
return (printed +
|
||||
class__fprintf(tag__class(type), cu, NULL, name,
|
||||
expand_types, indent,
|
||||
base_offset, expand_types, indent,
|
||||
type_spacing - 8, name_spacing, 0, fp));
|
||||
case DW_TAG_union_type:
|
||||
ctype = tag__type(type);
|
||||
|
@ -1204,8 +1204,8 @@ static size_t type__fprintf(struct tag *type, const char *name,
|
|||
return fprintf(fp, "union %-*s %s", type_spacing - 6,
|
||||
ctype->name, name);
|
||||
return printed + union__fprintf(ctype, cu, NULL, name,
|
||||
expand_types, indent,
|
||||
type_spacing - 8,
|
||||
base_offset, expand_types,
|
||||
indent, type_spacing - 8,
|
||||
name_spacing, fp);
|
||||
case DW_TAG_enumeration_type:
|
||||
ctype = tag__type(type);
|
||||
|
@ -1225,13 +1225,15 @@ out_type_not_found:
|
|||
|
||||
static size_t struct_member__fprintf(struct class_member *self,
|
||||
struct tag *type, const struct cu *cu,
|
||||
uint32_t base_offset,
|
||||
uint8_t expand_types, int indent,
|
||||
int type_spacing, int name_spacing,
|
||||
FILE *fp)
|
||||
{
|
||||
int spacing;
|
||||
const int size = tag__size(type, cu);
|
||||
size_t printed = type__fprintf(type, self->name, cu, expand_types,
|
||||
size_t printed = type__fprintf(type, self->name, cu, base_offset + self->offset,
|
||||
expand_types,
|
||||
indent, type_spacing, name_spacing, fp);
|
||||
|
||||
if (self->bit_size != 0)
|
||||
|
@ -1251,24 +1253,26 @@ static size_t struct_member__fprintf(struct class_member *self,
|
|||
(int)strlen(self->name) : -1;
|
||||
return printed + fprintf(fp, "%*s/* %5u %5u */",
|
||||
type_spacing + name_spacing - slen - 3,
|
||||
" ", self->offset, size);
|
||||
" ", base_offset + self->offset,
|
||||
size);
|
||||
}
|
||||
spacing = type_spacing + name_spacing - printed;
|
||||
return printed + fprintf(fp, "%*s/* %5u %5u */",
|
||||
spacing > 0 ? spacing : 0, " ",
|
||||
self->offset, size);
|
||||
base_offset + self->offset, size);
|
||||
}
|
||||
|
||||
static size_t union_member__fprintf(struct class_member *self,
|
||||
struct tag *type, const struct cu *cu,
|
||||
uint8_t expand_types, int indent,
|
||||
int type_spacing, int name_spacing,
|
||||
FILE *fp)
|
||||
uint32_t base_offset, uint8_t expand_types,
|
||||
int indent, int type_spacing,
|
||||
int name_spacing, FILE *fp)
|
||||
{
|
||||
int spacing;
|
||||
const size_t size = tag__size(type, cu);
|
||||
size_t printed = type__fprintf(type, self->name, cu, expand_types,
|
||||
indent, type_spacing, name_spacing, fp);
|
||||
size_t printed = type__fprintf(type, self->name, cu, base_offset,
|
||||
expand_types, indent, type_spacing,
|
||||
name_spacing, fp);
|
||||
|
||||
if ((type->tag == DW_TAG_union_type ||
|
||||
type->tag == DW_TAG_enumeration_type ||
|
||||
|
@ -1293,9 +1297,9 @@ static size_t union_member__fprintf(struct class_member *self,
|
|||
|
||||
static size_t union__fprintf(const struct type *self, const struct cu *cu,
|
||||
const char *prefix, const char *suffix,
|
||||
uint8_t expand_types, uint8_t indent,
|
||||
size_t type_spacing, size_t name_spacing,
|
||||
FILE *fp)
|
||||
uint32_t base_offset, uint8_t expand_types,
|
||||
uint8_t indent, size_t type_spacing,
|
||||
size_t name_spacing, FILE *fp)
|
||||
{
|
||||
struct class_member *pos;
|
||||
size_t printed = 0;
|
||||
|
@ -1311,8 +1315,9 @@ static size_t union__fprintf(const struct type *self, const struct cu *cu,
|
|||
struct tag *type = cu__find_tag_by_id(cu, pos->tag.type);
|
||||
|
||||
printed += fprintf(fp, "%.*s", indent + 1, tabs);
|
||||
printed += union_member__fprintf(pos, type, cu, expand_types,
|
||||
indent + 1, type_spacing,
|
||||
printed += union_member__fprintf(pos, type, cu, base_offset,
|
||||
expand_types, indent + 1,
|
||||
type_spacing,
|
||||
name_spacing, fp);
|
||||
fputc('\n', fp);
|
||||
++printed;
|
||||
|
@ -2095,7 +2100,7 @@ static void class__move_member(struct class *class, struct class_member *dest,
|
|||
|
||||
if (verbose > 1) {
|
||||
class__find_holes(class, cu);
|
||||
class__fprintf(class, cu, NULL, NULL, 0, 0, 26, 23, 1, fp);
|
||||
class__fprintf(class, cu, NULL, NULL, 0, 0, 0, 26, 23, 1, fp);
|
||||
fputc('\n', fp);
|
||||
}
|
||||
}
|
||||
|
@ -2171,7 +2176,7 @@ static void class__move_bit_member(struct class *class, const struct cu *cu,
|
|||
dest->hole = 0;
|
||||
if (verbose > 1) {
|
||||
class__find_holes(class, cu);
|
||||
class__fprintf(class, cu, NULL, NULL, 0, 0, 26, 23, 1, fp);
|
||||
class__fprintf(class, cu, NULL, NULL, 0, 0, 0, 26, 23, 1, fp);
|
||||
fputc('\n', fp);
|
||||
}
|
||||
}
|
||||
|
@ -2295,7 +2300,7 @@ static int class__demote_bitfields(struct class *class, const struct cu *cu,
|
|||
--class->nr_bit_holes;
|
||||
if (verbose > 1) {
|
||||
class__find_holes(class, cu);
|
||||
class__fprintf(class, cu, NULL, NULL, 0, 0,
|
||||
class__fprintf(class, cu, NULL, NULL, 0, 0, 0,
|
||||
26, 23, 1, fp);
|
||||
fputc('\n', fp);
|
||||
}
|
||||
|
@ -2347,7 +2352,7 @@ static int class__demote_bitfields(struct class *class, const struct cu *cu,
|
|||
some_was_demoted = 1;
|
||||
if (verbose > 1) {
|
||||
class__find_holes(class, cu);
|
||||
class__fprintf(class, cu, NULL, NULL, 0, 0,
|
||||
class__fprintf(class, cu, NULL, NULL, 0, 0, 0,
|
||||
26, 23, 1, fp);
|
||||
fputc('\n', fp);
|
||||
}
|
||||
|
@ -2471,7 +2476,7 @@ static void class__fixup_member_types(struct class *self, const struct cu *cu,
|
|||
fprintf(fp, "/* bitfield types were fixed */\n");
|
||||
if (verbose > 1) {
|
||||
class__find_holes(self, cu);
|
||||
class__fprintf(self, cu, NULL, NULL, 0, 0,
|
||||
class__fprintf(self, cu, NULL, NULL, 0, 0, 0,
|
||||
26, 23, 1, fp);
|
||||
fputc('\n', fp);
|
||||
}
|
||||
|
@ -2614,8 +2619,8 @@ static size_t class__fprintf_cacheline_boundary(uint32_t last_cacheline,
|
|||
|
||||
size_t class__fprintf(const struct class *self, const struct cu *cu,
|
||||
const char *prefix, const char *suffix,
|
||||
uint8_t expand_types, uint8_t indent,
|
||||
int type_spacing, int name_spacing,
|
||||
uint32_t base_offset, uint8_t expand_types,
|
||||
uint8_t indent, int type_spacing, int name_spacing,
|
||||
int emit_stats, FILE *fp)
|
||||
{
|
||||
const struct type *tself = &self->type;
|
||||
|
@ -2713,8 +2718,9 @@ size_t class__fprintf(const struct class *self, const struct cu *cu,
|
|||
|
||||
size = tag__size(type, cu);
|
||||
printed += fprintf(fp, "%.*s", indent + 1, tabs);
|
||||
printed += struct_member__fprintf(pos, type, cu, expand_types,
|
||||
indent + 1, type_spacing,
|
||||
printed += struct_member__fprintf(pos, type, cu, base_offset,
|
||||
expand_types, indent + 1,
|
||||
type_spacing,
|
||||
name_spacing, fp);
|
||||
|
||||
if (type->tag == DW_TAG_structure_type) {
|
||||
|
@ -2836,7 +2842,7 @@ static size_t variable__fprintf(const struct tag *tag, const struct cu *cu,
|
|||
|
||||
if (varprefix != NULL)
|
||||
printed += fprintf(fp, "%s", varprefix);
|
||||
printed += type__fprintf(type, name, cu, expand_types,
|
||||
printed += type__fprintf(type, name, cu, 0, expand_types,
|
||||
0, 0, 0, fp);
|
||||
}
|
||||
}
|
||||
|
@ -2845,7 +2851,7 @@ static size_t variable__fprintf(const struct tag *tag, const struct cu *cu,
|
|||
|
||||
size_t tag__fprintf(const struct tag *self, const struct cu *cu,
|
||||
const char *prefix, const char *suffix,
|
||||
uint8_t expand_types, FILE *fp)
|
||||
uint32_t base_offset, uint8_t expand_types, FILE *fp)
|
||||
{
|
||||
size_t printed = tag__fprintf_decl_info(self, fp);
|
||||
|
||||
|
@ -2858,7 +2864,7 @@ size_t tag__fprintf(const struct tag *self, const struct cu *cu,
|
|||
break;
|
||||
case DW_TAG_structure_type:
|
||||
printed += class__fprintf(tag__class(self), cu, prefix, suffix,
|
||||
expand_types, 0, 26,
|
||||
base_offset, expand_types, 0, 26,
|
||||
expand_types ? 55 : 23, 1, fp);
|
||||
break;
|
||||
case DW_TAG_subprogram:
|
||||
|
@ -2866,7 +2872,7 @@ size_t tag__fprintf(const struct tag *self, const struct cu *cu,
|
|||
break;
|
||||
case DW_TAG_union_type:
|
||||
printed += union__fprintf(tag__type(self), cu, prefix, suffix,
|
||||
expand_types, 0, 26,
|
||||
base_offset, expand_types, 0, 26,
|
||||
expand_types ? 55 : 21, fp);
|
||||
break;
|
||||
case DW_TAG_variable:
|
||||
|
@ -3782,7 +3788,7 @@ void type__emit(struct tag *tag_self, struct cu *cu,
|
|||
class__find_holes(tag__class(tag_self), cu);
|
||||
|
||||
if (ctype->name != NULL || suffix != NULL || prefix != NULL) {
|
||||
tag__fprintf(tag_self, cu, prefix, suffix, 0, fp);
|
||||
tag__fprintf(tag_self, cu, prefix, suffix, 0, 0, fp);
|
||||
|
||||
if (tag_self->tag != DW_TAG_structure_type)
|
||||
fputc(';', fp);
|
||||
|
|
|
@ -270,12 +270,13 @@ extern struct class *class__reorganize(struct class *self,
|
|||
const int verbose, FILE *fp);
|
||||
extern size_t class__fprintf(const struct class *self, const struct cu *cu,
|
||||
const char *prefix, const char *suffix,
|
||||
uint8_t expand_types, uint8_t indent,
|
||||
int type_spacing, int name_spacing,
|
||||
int emit_stats, FILE *fp);
|
||||
uint32_t base_offset, uint8_t expand_types,
|
||||
uint8_t indent, int type_spacing,
|
||||
int name_spacing, int emit_stats, FILE *fp);
|
||||
extern size_t tag__fprintf(const struct tag *self, const struct cu *cu,
|
||||
const char *prefix, const char *suffix,
|
||||
uint8_t expand_types, FILE *fp);
|
||||
uint32_t base_offset, uint8_t expand_types,
|
||||
FILE *fp);
|
||||
|
||||
extern const char *function__name(struct function *self, const struct cu *cu);
|
||||
extern size_t function__fprintf_stats(const struct tag *tag_self,
|
||||
|
|
9
pahole.c
9
pahole.c
|
@ -160,10 +160,11 @@ static void class_formatter(const struct structure *self)
|
|||
|
||||
if (typedef_alias != NULL) {
|
||||
const struct type *tdef = tag__type(typedef_alias);
|
||||
tag__fprintf(tag, self->cu, "typedef", tdef->name,
|
||||
tag__fprintf(tag, self->cu, "typedef", tdef->name, 0,
|
||||
expand_types, stdout);
|
||||
} else
|
||||
tag__fprintf(tag, self->cu, NULL, NULL, expand_types, stdout);
|
||||
tag__fprintf(tag, self->cu, NULL, NULL, 0,
|
||||
expand_types, stdout);
|
||||
|
||||
printf(" /* definitions: %u */\n", self->nr_files);
|
||||
putchar('\n');
|
||||
|
@ -603,7 +604,7 @@ int main(int argc, char *argv[])
|
|||
puts("/* Final reorganized struct: */");
|
||||
}
|
||||
tag__fprintf(class__tag(clone), s->cu, NULL, NULL, 0,
|
||||
stdout);
|
||||
0, stdout);
|
||||
if (savings != 0) {
|
||||
const size_t cacheline_savings =
|
||||
(tag__nr_cachelines(class__tag(s->class),
|
||||
|
@ -622,7 +623,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
} else
|
||||
tag__fprintf(class__tag(s->class), s->cu, NULL, NULL,
|
||||
expand_types, stdout);
|
||||
0, expand_types, stdout);
|
||||
} else
|
||||
print_classes(formatter);
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ static int emit_tag(struct tag *self, struct cu *cu, void *cookie __unused)
|
|||
if (self->tag == DW_TAG_structure_type)
|
||||
class__find_holes(tag__class(self), cu);
|
||||
|
||||
tag__fprintf(self, cu, NULL, NULL, 0, stdout);
|
||||
tag__fprintf(self, cu, NULL, NULL, 0, 0, stdout);
|
||||
|
||||
if (self->tag == DW_TAG_subprogram) {
|
||||
const struct function *fn = tag__function(self);
|
||||
|
|
6
pfunct.c
6
pfunct.c
|
@ -120,7 +120,7 @@ static void fn_stats_size_fmtr(const struct fn_stats *self)
|
|||
static void fn_stats_fmtr(const struct fn_stats *self)
|
||||
{
|
||||
if (verbose) {
|
||||
tag__fprintf(self->tag, self->cu, NULL, NULL, 0, stdout);
|
||||
tag__fprintf(self->tag, self->cu, NULL, NULL, 0, 0, stdout);
|
||||
putchar('\n');
|
||||
if (show_variables || show_inline_expansions)
|
||||
function__fprintf_stats(self->tag, self->cu, stdout);
|
||||
|
@ -276,7 +276,7 @@ static int class_iterator(struct tag *tag, struct cu *cu, void *cookie)
|
|||
|
||||
if (ftype__has_parm_of_type(&function->proto, cookie, cu)) {
|
||||
if (verbose)
|
||||
tag__fprintf(tag, cu, NULL, NULL, 0, stdout);
|
||||
tag__fprintf(tag, cu, NULL, NULL, 0, 0, stdout);
|
||||
else
|
||||
fputs(function__name(function, cu), stdout);
|
||||
putchar('\n');
|
||||
|
@ -303,7 +303,7 @@ static int function_iterator(struct tag *tag, struct cu *cu, void *cookie)
|
|||
|
||||
function = tag__function(tag);
|
||||
if (strcmp(function__name(function, cu), cookie) == 0) {
|
||||
tag__fprintf(tag, cu, NULL, NULL, 0, stdout);
|
||||
tag__fprintf(tag, cu, NULL, NULL, 0, 0, stdout);
|
||||
putchar('\n');
|
||||
if (show_variables || show_inline_expansions)
|
||||
function__fprintf_stats(tag, cu, stdout);
|
||||
|
|
|
@ -220,7 +220,7 @@ static void declaration_action__walk(const void *nodep, const VISIT which,
|
|||
|
||||
tag = extvar__tag(gvar);
|
||||
|
||||
tag__fprintf(tag, gvar->cu, NULL, NULL, 0, stdout);
|
||||
tag__fprintf(tag, gvar->cu, NULL, NULL, 0, 0, stdout);
|
||||
|
||||
for (pos = gvar->next; pos; pos = pos->next)
|
||||
count++;
|
||||
|
@ -252,7 +252,7 @@ static void function_action__walk(const void *nodep, const VISIT which,
|
|||
|
||||
tag = extfun__tag(gfun);
|
||||
|
||||
tag__fprintf(tag, gfun->cu, NULL, NULL, 0, stdout);
|
||||
tag__fprintf(tag, gfun->cu, NULL, NULL, 0, 0, stdout);
|
||||
|
||||
fputs("\n\n", stdout);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue