pahole: Introduce --flat_array
CTF doesn't have support for multiple array dimensions, so it flattens the arrays. This caused a large number of false positives in ctfdwdiff, so introduce this conf_fprintf option, use it in pahole and ctfdwdiff. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
01c4fa3114
commit
57127d45fc
|
@ -6,8 +6,8 @@ ctf=/tmp/$obj.ctf.c
|
||||||
dwarf=/tmp/$obj.dwarf.c
|
dwarf=/tmp/$obj.dwarf.c
|
||||||
pahole -Z $obj
|
pahole -Z $obj
|
||||||
pahole -F ctf $obj > $ctf
|
pahole -F ctf $obj > $ctf
|
||||||
pahole -F dwarf $obj > $dwarf
|
pahole --flat_arrays -F dwarf $obj > $dwarf
|
||||||
diff -u $ctf $dwarf > $diff
|
diff -up $ctf $dwarf > $diff
|
||||||
if [ -s $diff ] ; then
|
if [ -s $diff ] ; then
|
||||||
# vim /tmp/$obj.diff
|
# vim /tmp/$obj.diff
|
||||||
exit 0
|
exit 0
|
||||||
|
|
14
dwarves.c
14
dwarves.c
|
@ -273,14 +273,26 @@ static size_t array_type__fprintf(const struct tag *tag_self,
|
||||||
struct array_type *self = tag__array_type(tag_self);
|
struct array_type *self = tag__array_type(tag_self);
|
||||||
struct tag *type = cu__type(cu, tag_self->type);
|
struct tag *type = cu__type(cu, tag_self->type);
|
||||||
size_t printed;
|
size_t printed;
|
||||||
|
unsigned long long flat_dimensions = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (type == NULL)
|
if (type == NULL)
|
||||||
return tag__id_not_found_fprintf(fp, tag_self->type);
|
return tag__id_not_found_fprintf(fp, tag_self->type);
|
||||||
|
|
||||||
printed = type__fprintf(type, cu, name, conf, fp);
|
printed = type__fprintf(type, cu, name, conf, fp);
|
||||||
for (i = 0; i < self->dimensions; ++i)
|
for (i = 0; i < self->dimensions; ++i) {
|
||||||
|
if (conf->flat_arrays) {
|
||||||
|
if (!flat_dimensions)
|
||||||
|
flat_dimensions = self->nr_entries[i];
|
||||||
|
else
|
||||||
|
flat_dimensions *= self->nr_entries[i];
|
||||||
|
} else
|
||||||
printed += fprintf(fp, "[%u]", self->nr_entries[i]);
|
printed += fprintf(fp, "[%u]", self->nr_entries[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conf->flat_arrays)
|
||||||
|
printed += fprintf(fp, "[%llu]", flat_dimensions);
|
||||||
|
|
||||||
return printed;
|
return printed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,10 @@ struct conf_load {
|
||||||
char *format_path;
|
char *format_path;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** struct conf_fprintf - hints to the __fprintf routines
|
||||||
|
*
|
||||||
|
* @flat_arrays - a->foo[10][2] becomes a->foo[20]
|
||||||
|
*/
|
||||||
struct conf_fprintf {
|
struct conf_fprintf {
|
||||||
const char *prefix;
|
const char *prefix;
|
||||||
const char *suffix;
|
const char *suffix;
|
||||||
|
@ -58,6 +62,7 @@ struct conf_fprintf {
|
||||||
uint8_t show_only_data_members:1;
|
uint8_t show_only_data_members:1;
|
||||||
uint8_t no_semicolon:1;
|
uint8_t no_semicolon:1;
|
||||||
uint8_t show_first_biggest_size_base_type_member:1;
|
uint8_t show_first_biggest_size_base_type_member:1;
|
||||||
|
uint8_t flat_arrays:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cus {
|
struct cus {
|
||||||
|
|
|
@ -159,6 +159,12 @@ Show how many times struct was defined.
|
||||||
.B \-u, \-\-defined_in
|
.B \-u, \-\-defined_in
|
||||||
Show CUs where CLASS_NAME (-C) is defined.
|
Show CUs where CLASS_NAME (-C) is defined.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.B \-\-flat_arrays
|
||||||
|
Flatten arrays, so that array[10][2] becomes array[20].
|
||||||
|
Useful when generating from both CTF and DWARF encodings
|
||||||
|
for the same binary for testing purposes.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-V, \-\-verbose
|
.B \-V, \-\-verbose
|
||||||
be verbose
|
be verbose
|
||||||
|
|
12
pahole.c
12
pahole.c
|
@ -703,6 +703,8 @@ 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
|
||||||
|
|
||||||
static const struct argp_option pahole__options[] = {
|
static const struct argp_option pahole__options[] = {
|
||||||
{
|
{
|
||||||
.name = "bit_holes",
|
.name = "bit_holes",
|
||||||
|
@ -900,6 +902,11 @@ static const struct argp_option pahole__options[] = {
|
||||||
.key = 'Z',
|
.key = 'Z',
|
||||||
.doc = "Encode as CTF",
|
.doc = "Encode as CTF",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.name = "flat_arrays",
|
||||||
|
.key = ARGP_flat_arrays,
|
||||||
|
.doc = "Flat arrays",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.name = NULL,
|
.name = NULL,
|
||||||
}
|
}
|
||||||
|
@ -968,9 +975,8 @@ static error_t pahole__options_parser(int key, char *arg,
|
||||||
if (!global_verbose)
|
if (!global_verbose)
|
||||||
formatter = class_name_formatter;
|
formatter = class_name_formatter;
|
||||||
break;
|
break;
|
||||||
case 'Z':
|
case 'Z': ctf_encode = 1; break;
|
||||||
ctf_encode = 1;
|
case ARGP_flat_arrays: conf.flat_arrays = 1; break;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return ARGP_ERR_UNKNOWN;
|
return ARGP_ERR_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue