Skip to content

Commit e18ef2f

Browse files
committed
pahole: Implement --contains_enumerator=ENUMERATOR_NAME
To find the enum where some enumerator is defined: E.g. $ pahole --contains_enumerator S_VERSION enum file_time_flags { S_ATIME = 1, S_MTIME = 2, S_CTIME = 4, S_VERSION = 8, } $ Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 7146ad0 commit e18ef2f

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

man-pages/pahole.1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,21 @@ Show the struct layout at each reorganization step.
180180
.B \-i, \-\-contains=CLASS_NAME
181181
Show classes that contains CLASS_NAME.
182182

183+
.TP
184+
.B \-\-contains_enumerator=ENUMERATOR_NAME
185+
Show enumeration that contains ENUMERATOR_NAME.
186+
.PP
187+
.nf
188+
$ pahole --contains_enumerator S_VERSION
189+
enum file_time_flags {
190+
S_ATIME = 1,
191+
S_MTIME = 2,
192+
S_CTIME = 4,
193+
S_VERSION = 8,
194+
}
195+
$
196+
.fi
197+
183198
.TP
184199
.B \-a, \-\-anon_include
185200
Include anonymous classes.

pahole.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static uint8_t global_verbose;
6666
static uint8_t recursive;
6767
static size_t cacheline_size;
6868
static uint8_t find_containers;
69+
static bool find_enumeration_with_enumerator;
6970
static uint8_t find_pointers_in_structs;
7071
static int reorganize;
7172
static bool show_private_classes;
@@ -75,6 +76,7 @@ static bool just_structs;
7576
static bool just_packed_structs;
7677
static int show_reorg_steps;
7778
static const char *class_name;
79+
static const char *enumerator_name;
7880
static LIST_HEAD(class_names);
7981
static char separator = '\t';
8082

@@ -1232,6 +1234,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
12321234
#define ARGP_btf_features 341
12331235
#define ARGP_supported_btf_features 342
12341236
#define ARGP_btf_features_strict 343
1237+
#define ARGP_contains_enumerator 344
12351238

12361239
/* --btf_features=feature1[,feature2,..] allows us to specify
12371240
* a list of requested BTF features or "all" to enable all features.
@@ -1445,6 +1448,12 @@ static const struct argp_option pahole__options[] = {
14451448
.arg = "CLASS_NAME",
14461449
.doc = "Show classes that contains CLASS_NAME"
14471450
},
1451+
{
1452+
.name = "contains_enumerator",
1453+
.key = ARGP_contains_enumerator,
1454+
.arg = "ENUMERATOR",
1455+
.doc = "Show enumerations that contains ENUMERATOR"
1456+
},
14481457
{
14491458
.name = "show_decl_info",
14501459
.key = 'I',
@@ -1841,6 +1850,9 @@ static error_t pahole__options_parser(int key, char *arg,
18411850
conf_load.extra_dbg_info = 1; break;
18421851
case 'i': find_containers = 1;
18431852
class_name = arg; break;
1853+
case ARGP_contains_enumerator:
1854+
find_enumeration_with_enumerator = true;
1855+
enumerator_name = arg; break;
18441856
case 'j':
18451857
#if _ELFUTILS_PREREQ(0, 178)
18461858
conf_load.nr_jobs = arg ? atoi(arg) :
@@ -3124,6 +3136,22 @@ static int type__find_type_enum(struct type *type, struct cu *cu, const char *ty
31243136

31253137
static struct type_instance *header;
31263138

3139+
static bool print_enumeration_with_enumerator(struct cu *cu, const char *name)
3140+
{
3141+
struct type *enumeration;
3142+
uint32_t id;
3143+
3144+
cu__for_each_enumeration(cu, id, enumeration) {
3145+
if (enumeration__find_enumerator(enumeration, name) != NULL) {
3146+
enumeration__fprintf(type__tag(enumeration), &conf, stdout);
3147+
fputc('\n', stdout);
3148+
return true;
3149+
}
3150+
}
3151+
3152+
return false;
3153+
}
3154+
31273155
struct thread_data {
31283156
struct btf *btf;
31293157
struct btf_encoder *encoder;
@@ -3209,6 +3237,10 @@ static enum load_steal_kind pahole_stealer(struct cu *cu,
32093237
cu__fprintf_ptr_table_stats_csv(cu, stderr);
32103238
}
32113239

3240+
if (find_enumeration_with_enumerator &&
3241+
print_enumeration_with_enumerator(cu, enumerator_name))
3242+
return LSK__DELETE; // Maybe we can find this in several CUs, so don't stop it
3243+
32123244
if (btf_encode) {
32133245
static pthread_mutex_t btf_lock = PTHREAD_MUTEX_INITIALIZER;
32143246
struct btf_encoder *encoder;

0 commit comments

Comments
 (0)