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 <acme@redhat.com>
diff --git a/man-pages/pahole.1 b/man-pages/pahole.1
index 6a7aee3..eefa437 100644
--- a/man-pages/pahole.1
+++ b/man-pages/pahole.1
@@ -381,6 +381,13 @@
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 d8269c7..78caa08 100644
--- a/pahole.c
+++ b/pahole.c
@@ -133,6 +133,7 @@
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 @@
{
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 @@
#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[] = {
{
@@ -1613,6 +1617,12 @@
.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 @@
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: