perf symbols: Add kallsyms__get_symbol_start()

The kallsyms__get_symbol_start() to get any symbol address from
kallsyms.  The existing kallsyms__get_function_start() only allows text
symbols so create this to allow data symbols too.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230725001929.368041-1-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Namhyung Kim 2023-07-24 17:19:28 -07:00 committed by Arnaldo Carvalho de Melo
parent 4c11adff67
commit f9dd531c5b
2 changed files with 29 additions and 3 deletions

View File

@ -93,7 +93,7 @@ struct process_symbol_args {
u64 start;
};
static int find_symbol_cb(void *arg, const char *name, char type,
static int find_func_symbol_cb(void *arg, const char *name, char type,
u64 start)
{
struct process_symbol_args *args = arg;
@ -110,12 +110,36 @@ static int find_symbol_cb(void *arg, const char *name, char type,
return 1;
}
static int find_any_symbol_cb(void *arg, const char *name,
char type __maybe_unused, u64 start)
{
struct process_symbol_args *args = arg;
if (strcmp(name, args->name))
return 0;
args->start = start;
return 1;
}
int kallsyms__get_function_start(const char *kallsyms_filename,
const char *symbol_name, u64 *addr)
{
struct process_symbol_args args = { .name = symbol_name, };
if (kallsyms__parse(kallsyms_filename, &args, find_symbol_cb) <= 0)
if (kallsyms__parse(kallsyms_filename, &args, find_func_symbol_cb) <= 0)
return -1;
*addr = args.start;
return 0;
}
int kallsyms__get_symbol_start(const char *kallsyms_filename,
const char *symbol_name, u64 *addr)
{
struct process_symbol_args args = { .name = symbol_name, };
if (kallsyms__parse(kallsyms_filename, &args, find_any_symbol_cb) <= 0)
return -1;
*addr = args.start;

View File

@ -360,6 +360,8 @@ size_t perf_event__fprintf(union perf_event *event, struct machine *machine, FIL
int kallsyms__get_function_start(const char *kallsyms_filename,
const char *symbol_name, u64 *addr);
int kallsyms__get_symbol_start(const char *kallsyms_filename,
const char *symbol_name, u64 *addr);
void event_attr_init(struct perf_event_attr *attr);