pahole: Add --format_path/-F to specify a list of formats to try

For a file with just DWARF info:

$ pahole -F ctf build/pahole
$

But if we ask that it also try dwarf:

$ pahole -F ctf,dwarf build/pahole | head -2
struct _IO_FILE {
	int          _flags;    /*     0     4 */
$

Useful when testing the new CTF support in these tools, as we'll be able to,
from the DWARF info in objects, generate the CTF equivalent and add to the same
object, then run pahole -A -F ctf, pahole -A -F dwarf and compare the outputs.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2009-03-19 12:19:37 -03:00
parent feab8aa5e3
commit 45255ec6b6
4 changed files with 39 additions and 8 deletions

View File

@ -2670,19 +2670,37 @@ static debugging_format_loader_t debugging_formats__loader(const char *name)
int cus__load(struct cus *self, struct conf_load *conf, char *filename)
{
int i = 0;
int i = 0, err = 0;
debugging_format_loader_t loader;
if (conf && conf->format_path != NULL) {
while (conf->format_path[i] != NULL) {
loader = debugging_formats__loader(conf->format_path[i]);
char *fpath = strdup(conf->format_path);
if (fpath == NULL)
return -ENOMEM;
char *fp = fpath;
while (1) {
char *sep = strchr(fp, ',');
if (sep != NULL)
*sep = '\0';
err = -ENOTSUP;
loader = debugging_formats__loader(fp);
if (loader == NULL)
return -ENOTSUP;
break;
err = 0;
if (loader(self, conf, filename) == 0)
return 0;
++i;
break;
err = -EINVAL;
if (sep == NULL)
break;
fp = sep + 1;
}
return -EINVAL;
free(fpath);
return err;
}
while (debugging_formats__table[i].name != NULL) {

View File

@ -38,7 +38,7 @@ struct conf_load {
enum load_steal_kind (*steal)(struct cu *self,
struct conf_load *conf);
void *cookie;
char **format_path;
char *format_path;
};
struct conf_fprintf {

View File

@ -49,6 +49,12 @@ Set cacheline size to SIZE bytes.
Expand class members. Useful to find in what member of inner structs where an
offset from the beginning of a struct is.
.TP
.B \-F, \-\-format_path
Allows specifying a list of debugging formats to try, in order. Right now this
includes "ctf" and "dwarf". The default format path used is equivalent to
"-F dwarf,ctf".
.TP
.B \-r, \-\-rel_offset
Show relative offsets of members in inner structs.

View File

@ -728,6 +728,12 @@ static const struct argp_option pahole__options[] = {
.arg = "CLASS_NAME",
.doc = "Find pointers to CLASS_NAME"
},
{
.name = "format_path",
.key = 'F',
.arg = "FORMAT_LIST",
.doc = "List of debugging formats to try"
},
{
.name = "contains",
.key = 'i',
@ -919,6 +925,7 @@ static error_t pahole__options_parser(int key, char *arg,
case 'E': conf.expand_types = 1; break;
case 'f': find_pointers_in_structs = 1;
class_name = arg; break;
case 'F': conf_load.format_path = arg; break;
case 'H': nr_holes = atoi(arg); break;
case 'I': conf.show_decl_info = 1;
conf_load.extra_dbg_info = 1; break;