Skip to content

Commit

Permalink
pahole: Add --lang_exclude to allow skipping compilation units writte…
Browse files Browse the repository at this point in the history
…n in some languages

For instance, to exclude rust compilation units when encoding BTF from
DWARF:

 $ pahole --btf_encode --lang_exclude rust

Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
acmel committed Apr 25, 2022
1 parent 8ee3637 commit 49358df
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 7 additions & 0 deletions man-pages/pahole.1
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,13 @@ Supported languages:

The linux kernel, for instance, is written in 'c89' circa 2022, use that in filters.

.B \-\-lang_exclude=languages
Don't process compilation units built from source code written in the specified languages.

To filter out compilation units written in Rust, for instance, use:

pahole -j --btf_encode --lang_exclude rust

.TP
.B \-y, \-\-prefix_filter=PREFIX
Include PREFIXed classes.
Expand Down
15 changes: 14 additions & 1 deletion pahole.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ static struct {
char *str;
int *entries;
int nr_entries;
bool exclude;
} languages;

static int lang_id_cmp(const void *pa, const void *pb)
Expand Down Expand Up @@ -683,7 +684,9 @@ static struct cu *cu__filter(struct cu *cu)
{
if (languages.nr_entries) {
bool in = languages__in(cu->language);
if (!in)

if ((!in && !languages.exclude) ||
(in && languages.exclude))
return NULL;
}

Expand Down Expand Up @@ -1216,6 +1219,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
#define ARGP_skip_encoding_btf_type_tag 333
#define ARGP_compile 334
#define ARGP_languages 335
#define ARGP_languages_exclude 336

static const struct argp_option pahole__options[] = {
{
Expand Down Expand Up @@ -1612,6 +1616,12 @@ static const struct argp_option pahole__options[] = {
.arg = "LANGUAGES",
.doc = "Only consider compilation units written in these languages"
},
{
.name = "lang_exclude",
.key = ARGP_languages_exclude,
.arg = "LANGUAGES",
.doc = "Don't consider compilation units written in these languages"
},
{
.name = NULL,
}
Expand Down Expand Up @@ -1772,6 +1782,9 @@ static error_t pahole__options_parser(int key, char *arg,
conf_load.skip_missing = true; break;
case ARGP_skip_encoding_btf_type_tag:
conf_load.skip_encoding_btf_type_tag = true; break;
case ARGP_languages_exclude:
languages.exclude = true;
/* fallthru */
case ARGP_languages:
languages.str = arg; break;
default:
Expand Down

0 comments on commit 49358df

Please sign in to comment.