linux/tools/perf/util/btf.c
Arnaldo Carvalho de Melo dcf900429d perf btf: Make the sigtrap test helper to find a member by name widely available
By introducing a tools/perf/util/btf.c to collect utilities not yet
available via libbpf, the first being a way to find a member by name
once we get the type_id for the struct.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-12-09 17:52:41 -03:00

27 lines
632 B
C

// SPDX-License-Identifier: GPL-2.0
/*
* Arnaldo Carvalho de Melo <acme@redhat.com>
*
* Copyright (C) 2024, Red Hat, Inc
*/
#include <bpf/btf.h>
#include <util/btf.h>
#include <string.h>
const struct btf_member *__btf_type__find_member_by_name(struct btf *btf,
int type_id, const char *member_name)
{
const struct btf_type *t = btf__type_by_id(btf, type_id);
const struct btf_member *m;
int i;
for (i = 0, m = btf_members(t); i < btf_vlen(t); i++, m++) {
const char *current_member_name = btf__name_by_offset(btf, m->name_off);
if (!strcmp(current_member_name, member_name))
return m;
}
return NULL;
}