pfunct: Introduce --no_parm_names

Because CTF doesn't encodes the names of the parameters and I want to
test the upcoming CTF function section code in ctftwdiff.

$ pfunct -V pahole > /tmp/before
$ pfunct --no_parm_names -V pahole > /tmp/after
$ diff -u /tmp/before /tmp/after | tail -3
-struct structure * structure__new(strings_t name);
+struct structure * structure__new(strings_t);
 /* definitions: 1 */
$

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2009-03-30 21:47:59 -03:00
parent 31fd625644
commit 2d8700009b
4 changed files with 53 additions and 29 deletions

View File

@ -475,7 +475,7 @@ size_t typedef__fprintf(const struct tag *tag_self, const struct cu *cu,
return printed + ftype__fprintf(tag__ftype(type), cu,
type__name(self),
0, is_pointer, 0,
fp);
pconf, fp);
case DW_TAG_class_type:
case DW_TAG_structure_type: {
struct type *ctype = tag__type(type);
@ -1108,8 +1108,10 @@ const char *tag__name(const struct tag *self, const struct cu *cu,
break;
case DW_TAG_subroutine_type: {
FILE *bfp = fmemopen(bf, len, "w");
if (bfp != NULL) {
ftype__fprintf(tag__ftype(self), cu, NULL, 0, 0, 0, bfp);
ftype__fprintf(tag__ftype(self), cu, NULL, 0, 0, 0,
&conf_fprintf__defaults, bfp);
fclose(bfp);
} else
snprintf(bf, len, "<ERROR(%s): fmemopen failed!>",
@ -1257,7 +1259,7 @@ static size_t type__fprintf(struct tag *type, const struct cu *cu,
printed += ftype__fprintf(tag__ftype(ptype),
cu, name, 0, 1,
conf->type_spacing,
fp);
conf, fp);
break;
}
}
@ -1268,7 +1270,7 @@ static size_t type__fprintf(struct tag *type, const struct cu *cu,
break;
case DW_TAG_subroutine_type:
printed += ftype__fprintf(tag__ftype(type), cu, name, 0, 0,
conf->type_spacing, fp);
conf->type_spacing, conf, fp);
break;
case DW_TAG_array_type:
printed += array_type__fprintf(type, cu, name, conf, fp);
@ -1583,7 +1585,8 @@ const char *function__prototype(const struct function *self,
FILE *bfp = fmemopen(bf, len, "w");
if (bfp != NULL) {
ftype__fprintf(&self->proto, cu, NULL, 0, 0, 0, bfp);
ftype__fprintf(&self->proto, cu, NULL, 0, 0, 0,
&conf_fprintf__defaults, bfp);
fclose(bfp);
} else
snprintf(bf, len, "<ERROR(%s): fmemopen failed!>", __func__);
@ -1864,7 +1867,7 @@ void cu__account_inline_expansions(struct cu *self)
static size_t ftype__fprintf_parms(const struct ftype *self,
const struct cu *cu, int indent,
FILE *fp)
const struct conf_fprintf *conf, FILE *fp)
{
struct parameter *pos;
int first_parm = 1;
@ -1882,7 +1885,7 @@ static size_t ftype__fprintf_parms(const struct ftype *self,
indent, tabs);
} else
first_parm = 0;
name = parameter__name(pos);
name = conf->no_parm_names ? NULL : parameter__name(pos);
type = cu__type(cu, pos->tag.type);
if (type == NULL) {
snprintf(sbf, sizeof(sbf),
@ -1902,13 +1905,13 @@ static size_t ftype__fprintf_parms(const struct ftype *self,
printed +=
ftype__fprintf(tag__ftype(ptype),
cu, name, 0, 1, 0,
fp);
conf, fp);
continue;
}
}
} else if (type->tag == DW_TAG_subroutine_type) {
printed += ftype__fprintf(tag__ftype(type), cu, name,
0, 0, 0, fp);
0, 0, 0, conf, fp);
continue;
}
stype = tag__name(type, cu, sbf, sizeof(sbf));
@ -1928,8 +1931,8 @@ print_it:
}
static size_t function__tag_fprintf(const struct tag *tag, const struct cu *cu,
struct function *function,
uint16_t indent, FILE *fp)
struct function *function, uint16_t indent,
const struct conf_fprintf *conf, FILE *fp)
{
char bf[512];
size_t printed = 0, n;
@ -1959,7 +1962,7 @@ static size_t function__tag_fprintf(const struct tag *tag, const struct cu *cu,
namelen = strlen(name);
n += ftype__fprintf_parms(&alias->proto, cu,
indent + (namelen + 7) / 8,
fp);
conf, fp);
n += fprintf(fp, "; /* size=%zd, low_pc=%#llx */",
exp->size, (unsigned long long)exp->low_pc);
#if 0
@ -1989,7 +1992,8 @@ static size_t function__tag_fprintf(const struct tag *tag, const struct cu *cu,
}
break;
case DW_TAG_lexical_block:
printed = lexblock__fprintf(vtag, cu, function, indent, fp);
printed = lexblock__fprintf(vtag, cu, function, indent,
conf, fp);
fputc('\n', fp);
return printed + 1;
default:
@ -2005,7 +2009,8 @@ static size_t function__tag_fprintf(const struct tag *tag, const struct cu *cu,
}
size_t lexblock__fprintf(const struct lexblock *self, const struct cu *cu,
struct function *function, uint16_t indent, FILE *fp)
struct function *function, uint16_t indent,
const struct conf_fprintf *conf, FILE *fp)
{
struct tag *pos;
size_t printed;
@ -2026,7 +2031,8 @@ size_t lexblock__fprintf(const struct lexblock *self, const struct cu *cu,
}
printed += fprintf(fp, "\n");
list_for_each_entry(pos, &self->tags, node)
printed += function__tag_fprintf(pos, cu, function, indent + 1, fp);
printed += function__tag_fprintf(pos, cu, function, indent + 1,
conf, fp);
printed += fprintf(fp, "%.*s}", indent, tabs);
if (function->lexblock.low_pc != self->low_pc)
@ -2037,7 +2043,8 @@ size_t lexblock__fprintf(const struct lexblock *self, const struct cu *cu,
size_t ftype__fprintf(const struct ftype *self, const struct cu *cu,
const char *name, const int inlined,
const int is_pointer, int type_spacing, FILE *fp)
const int is_pointer, int type_spacing,
const struct conf_fprintf *conf, FILE *fp)
{
struct tag *type = cu__type(cu, self->tag.type);
char sbf[128];
@ -2051,11 +2058,13 @@ size_t ftype__fprintf(const struct ftype *self, const struct cu *cu,
self->tag.tag == DW_TAG_subroutine_type ?
")" : "");
return printed + ftype__fprintf_parms(self, cu, 0, fp);
return printed + ftype__fprintf_parms(self, cu, 0, conf, fp);
}
static size_t function__fprintf(const struct tag *tag_self,
const struct cu *cu, FILE *fp)
const struct cu *cu,
const struct conf_fprintf *conf,
FILE *fp)
{
struct function *self = tag__function(tag_self);
size_t printed = 0;
@ -2065,7 +2074,8 @@ static size_t function__fprintf(const struct tag *tag_self,
printed += fprintf(fp, "virtual ");
printed += ftype__fprintf(&self->proto, cu, function__name(self, cu),
function__declared_inline(self), 0, 0, fp);
function__declared_inline(self), 0, 0,
conf, fp);
if (self->virtuality == DW_VIRTUALITY_pure_virtual)
printed += fprintf(fp, " = 0");
@ -2074,10 +2084,12 @@ static size_t function__fprintf(const struct tag *tag_self,
}
size_t function__fprintf_stats(const struct tag *tag_self,
const struct cu *cu, FILE *fp)
const struct cu *cu,
const struct conf_fprintf *conf,
FILE *fp)
{
struct function *self = tag__function(tag_self);
size_t printed = lexblock__fprintf(&self->lexblock, cu, self, 0, fp);
size_t printed = lexblock__fprintf(&self->lexblock, cu, self, 0, conf, fp);
printed += fprintf(fp, "/* size: %d", function__size(self));
if (self->lexblock.nr_variables > 0)
@ -2581,7 +2593,7 @@ size_t tag__fprintf(struct tag *self, const struct cu *cu,
printed += namespace__fprintf(self, cu, pconf, fp);
break;
case DW_TAG_subprogram:
printed += function__fprintf(self, cu, fp);
printed += function__fprintf(self, cu, pconf, fp);
break;
case DW_TAG_union_type:
printed += union__fprintf(tag__type(self), cu, pconf, fp);

View File

@ -65,6 +65,7 @@ struct conf_fprintf {
uint8_t no_semicolon:1;
uint8_t show_first_biggest_size_base_type_member:1;
uint8_t flat_arrays:1;
uint8_t no_parm_names:1;
};
struct cus {
@ -485,7 +486,8 @@ void lexblock__add_lexblock(struct lexblock *self, struct lexblock *child);
void lexblock__add_tag(struct lexblock *self, struct tag *tag);
void lexblock__add_variable(struct lexblock *self, struct variable *var);
size_t lexblock__fprintf(const struct lexblock *self, const struct cu *cu,
struct function *function, uint16_t indent, FILE *fp);
struct function *function, uint16_t indent,
const struct conf_fprintf *conf, FILE *fp);
struct parameter {
struct tag tag;
@ -539,7 +541,8 @@ void ftype__delete(struct ftype *self);
void ftype__add_parameter(struct ftype *self, struct parameter *parm);
size_t ftype__fprintf(const struct ftype *self, const struct cu *cu,
const char *name, const int inlined,
const int is_pointer, const int type_spacing, FILE *fp);
const int is_pointer, const int type_spacing,
const struct conf_fprintf *conf, FILE *fp);
int ftype__has_parm_of_type(const struct ftype *self, const uint16_t target,
const struct cu *cu);
@ -590,7 +593,9 @@ static __pure inline int tag__is_function(const struct tag *self)
const char *function__name(struct function *self, const struct cu *cu);
size_t function__fprintf_stats(const struct tag *tag_self,
const struct cu *cu, FILE *fp);
const struct cu *cu,
const struct conf_fprintf *conf,
FILE *fp);
const char *function__prototype(const struct function *self,
const struct cu *cu, char *bf, size_t len);

View File

@ -39,7 +39,7 @@ static void emit_tag(struct tag *self, uint32_t tag_id, struct cu *cu)
if (tag__is_function(self)) {
struct function *fn = tag__function(self);
putchar('\n');
lexblock__fprintf(&fn->lexblock, cu, fn, 0, stdout);
lexblock__fprintf(&fn->lexblock, cu, fn, 0, &conf, stdout);
}
printf(" size: %zd\n\n", tag__size(self, cu));
}

View File

@ -152,7 +152,7 @@ static void fn_stats_fmtr(const struct fn_stats *self)
tag__fprintf(self->tag, self->cu, &conf, stdout);
putchar('\n');
if (show_variables || show_inline_expansions)
function__fprintf_stats(self->tag, self->cu, stdout);
function__fprintf_stats(self->tag, self->cu, &conf, stdout);
printf("/* definitions: %u */\n", self->nr_files);
putchar('\n');
} else {
@ -368,7 +368,7 @@ static int function_iterator(struct tag *tag, struct cu *cu, void *cookie)
tag__fprintf(tag, cu, &conf, stdout);
putchar('\n');
if (show_variables || show_inline_expansions)
function__fprintf_stats(tag, cu, stdout);
function__fprintf_stats(tag, cu, &conf, stdout);
return 1;
}
return 0;
@ -463,7 +463,8 @@ int elf_symtabs__show(char *filenames[])
/* Name and version of program. */
ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
#define ARGP_symtab 300
#define ARGP_symtab 300
#define ARGP_no_parm_names 301
static const struct argp_option pfunct__options[] = {
{
@ -566,6 +567,11 @@ static const struct argp_option pfunct__options[] = {
.flags = OPTION_ARG_OPTIONAL,
.doc = "show symbol table NAME (Default .symtab)",
},
{
.name = "no_parm_names",
.key = ARGP_no_parm_names,
.doc = "Don't show parameter names",
},
{
.name = NULL,
}
@ -607,6 +613,7 @@ static error_t pfunct__options_parser(int key, char *arg,
case 'V': verbose = 1;
conf_load.extra_dbg_info = 1; break;
case ARGP_symtab: symtab_name = arg ?: ".symtab"; break;
case ARGP_no_parm_names: conf.no_parm_names = 1; break;
default: return ARGP_ERR_UNKNOWN;
}