From 49358dfe2aaae4e90b072332c3e324019826783f Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Mon, 25 Apr 2022 14:49:36 -0300 Subject: [PATCH] pahole: Add --lang_exclude to allow skipping compilation units written 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 --- man-pages/pahole.1 | 7 +++++++ pahole.c | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/man-pages/pahole.1 b/man-pages/pahole.1 index 6a7aee3c..eefa4376 100644 --- a/man-pages/pahole.1 +++ b/man-pages/pahole.1 @@ -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. diff --git a/pahole.c b/pahole.c index d8269c70..78caa080 100644 --- a/pahole.c +++ b/pahole.c @@ -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) @@ -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; } @@ -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[] = { { @@ -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, } @@ -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: