4 * Builtin command: Look for a symbol in the running kernel and its modules
6 * Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
8 * Released under the GPL v2. (and only v2, not any later version)
11 #include <linux/compiler.h>
12 #include <subcmd/parse-options.h>
17 static int __cmd_kallsyms(int argc, const char **argv)
20 struct machine *machine = machine__new_kallsyms();
22 if (machine == NULL) {
23 pr_err("Couldn't read /proc/kallsyms\n");
27 for (i = 0; i < argc; ++i) {
29 struct symbol *symbol = machine__find_kernel_function_by_name(machine, argv[i], &map);
32 printf("%s: not found\n", argv[i]);
36 printf("%s: %s %s %#" PRIx64 "-%#" PRIx64 " (%#" PRIx64 "-%#" PRIx64")\n",
37 symbol->name, map->dso->short_name, map->dso->long_name,
38 map->unmap_ip(map, symbol->start), map->unmap_ip(map, symbol->end),
39 symbol->start, symbol->end);
42 machine__delete(machine);
46 int cmd_kallsyms(int argc, const char **argv, const char *prefix __maybe_unused)
48 const struct option options[] = {
49 OPT_INCR('v', "verbose", &verbose, "be more verbose (show counter open errors, etc)"),
52 const char * const kallsyms_usage[] = {
53 "perf kallsyms [<options>] symbol_name",
57 argc = parse_options(argc, argv, options, kallsyms_usage, 0);
59 usage_with_options(kallsyms_usage, options);
61 symbol_conf.sort_by_name = true;
62 symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
63 if (symbol__init(NULL) < 0)
66 return __cmd_kallsyms(argc, argv);