pahole: Introduce --fixup_silly_bitfields

$ pahole -C acpi_device_perf_flags ac.o
struct acpi_device_perf_flags {
	u8          reserved:8;           /*     0: 0  1 */

	/* size: 1, cachelines: 1, members: 1 */
	/* last cacheline: 1 bytes */
};
$ pahole --fixup_silly_bitfields -C acpi_device_perf_flags ac.o
struct acpi_device_perf_flags {
	u8          reserved;             /*     0     1 */

	/* size: 1, cachelines: 1, members: 1 */
	/* last cacheline: 1 bytes */
};
$

Used in ctfdwdiff as in CTF land we can't express such sillyness.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2009-03-20 13:54:04 -03:00
parent aff24d3517
commit ac7778099a
5 changed files with 32 additions and 8 deletions

View File

@ -8,10 +8,12 @@ ctf=$dir/$obj.ctf.c
dwarf=$dir/$obj.dwarf.c dwarf=$dir/$obj.dwarf.c
pahole -Z $obj pahole -Z $obj
pahole -F ctf $obj > $ctf pahole -F ctf $obj > $ctf
pahole --flat_arrays --show_private_classes -F dwarf $obj > $dwarf pahole --flat_arrays \
--show_private_classes \
--fixup_silly_bitfields -F dwarf $obj > $dwarf
diff -up $ctf $dwarf > $diff diff -up $ctf $dwarf > $diff
if [ -s $diff ] ; then if [ -s $diff ] ; then
# vim $dir/$obj.diff [ $# -gt 1 ] && vim $dir/$obj.diff
exit 0 exit 0
else else
rm -f $diff $ctf $dwarf rm -f $diff $ctf $dwarf

View File

@ -1715,9 +1715,10 @@ static void die__process(Dwarf_Die *die, struct cu *cu)
} }
static int class_member__cache_byte_size(struct tag *self, struct cu *cu, static int class_member__cache_byte_size(struct tag *self, struct cu *cu,
void *cookie __unused) void *cookie)
{ {
if (self->tag == DW_TAG_member || self->tag == DW_TAG_inheritance) { if (self->tag == DW_TAG_member || self->tag == DW_TAG_inheritance) {
struct conf_load *conf_load = cookie;
struct class_member *member; struct class_member *member;
if (member->bitfield_size != 0) { if (member->bitfield_size != 0) {
@ -1742,8 +1743,15 @@ static int class_member__cache_byte_size(struct tag *self, struct cu *cu,
*/ */
member->byte_size = integral_bit_size / 8; member->byte_size = integral_bit_size / 8;
if (integral_bit_size == 0 || type_bit_size == integral_bit_size) { if (integral_bit_size == 0)
return 0;
if (type_bit_size == integral_bit_size) {
member->bit_size = integral_bit_size; member->bit_size = integral_bit_size;
if (conf_load && conf_load->fixup_silly_bitfields) {
member->bitfield_size = 0;
member->bitfield_offset = 0;
}
return 0; return 0;
} }
@ -1785,7 +1793,7 @@ static int cus__load_module(struct cus *self, struct conf_load *conf,
cu->extra_dbg_info = conf ? conf->extra_dbg_info : 0; cu->extra_dbg_info = conf ? conf->extra_dbg_info : 0;
die__process(cu_die, cu); die__process(cu_die, cu);
base_type_name_to_size_table__init(); base_type_name_to_size_table__init();
cu__for_all_tags(cu, class_member__cache_byte_size, NULL); cu__for_all_tags(cu, class_member__cache_byte_size, conf);
off = noff; off = noff;
if (conf && conf->steal) { if (conf && conf->steal) {
switch (conf->steal(cu, conf)) { switch (conf->steal(cu, conf)) {

View File

@ -32,13 +32,15 @@ enum load_steal_kind {
/** struct conf_load - load configuration /** struct conf_load - load configuration
* @extra_dbg_info - keep original debugging format extra info * @extra_dbg_info - keep original debugging format extra info
* (e.g. DWARF's decl_{line,file}, id, etc) * (e.g. DWARF's decl_{line,file}, id, etc)
* @fixup_silly_bitfields - Fixup silly things such as "int foo:32;"
*/ */
struct conf_load { struct conf_load {
bool extra_dbg_info;
enum load_steal_kind (*steal)(struct cu *self, enum load_steal_kind (*steal)(struct cu *self,
struct conf_load *conf); struct conf_load *conf);
void *cookie; void *cookie;
char *format_path; char *format_path;
bool extra_dbg_info;
bool fixup_silly_bitfields;
}; };
/** struct conf_fprintf - hints to the __fprintf routines /** struct conf_fprintf - hints to the __fprintf routines

View File

@ -165,6 +165,10 @@ Flatten arrays, so that array[10][2] becomes array[20].
Useful when generating from both CTF and DWARF encodings Useful when generating from both CTF and DWARF encodings
for the same binary for testing purposes. for the same binary for testing purposes.
.TP
.B \-\-fixup_silly_bitfields
Converts silly bitfields such as "int foo:32" to plain "int foo".
.TP .TP
.B \-V, \-\-verbose .B \-V, \-\-verbose
be verbose be verbose

View File

@ -704,8 +704,9 @@ static void print_containers(const struct cu *cu, uint16_t type, int ident)
/* Name and version of program. */ /* Name and version of program. */
ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version; ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
#define ARGP_flat_arrays 300 #define ARGP_flat_arrays 300
#define ARGP_show_private_classes 301 #define ARGP_show_private_classes 301
#define ARGP_fixup_silly_bitfields 302
static const struct argp_option pahole__options[] = { static const struct argp_option pahole__options[] = {
{ {
@ -914,6 +915,11 @@ static const struct argp_option pahole__options[] = {
.key = ARGP_show_private_classes, .key = ARGP_show_private_classes,
.doc = "Show classes that are defined inside other classes or in functions", .doc = "Show classes that are defined inside other classes or in functions",
}, },
{
.name = "fixup_silly_bitfields",
.key = ARGP_fixup_silly_bitfields,
.doc = "Fix silly bitfields such as int foo:32",
},
{ {
.name = NULL, .name = NULL,
} }
@ -986,6 +992,8 @@ static error_t pahole__options_parser(int key, char *arg,
case ARGP_flat_arrays: conf.flat_arrays = 1; break; case ARGP_flat_arrays: conf.flat_arrays = 1; break;
case ARGP_show_private_classes: case ARGP_show_private_classes:
show_private_classes = true; break; show_private_classes = true; break;
case ARGP_fixup_silly_bitfields:
conf_load.fixup_silly_bitfields = 1; break;
default: default:
return ARGP_ERR_UNKNOWN; return ARGP_ERR_UNKNOWN;
} }