blob: 224bfc454b4aa53d049e642dfc9feeadb1b37165 [file] [log] [blame]
Arnaldo Carvalho de Melo35563772017-01-05 15:33:32 -03001/*
2 * builtin-kallsyms.c
3 *
4 * Builtin command: Look for a symbol in the running kernel and its modules
5 *
6 * Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
7 *
8 * Released under the GPL v2. (and only v2, not any later version)
9 */
10#include "builtin.h"
11#include <linux/compiler.h>
12#include <subcmd/parse-options.h>
13#include "debug.h"
14#include "machine.h"
15#include "symbol.h"
16
17static int __cmd_kallsyms(int argc, const char **argv)
18{
19 int i;
20 struct machine *machine = machine__new_kallsyms();
21
22 if (machine == NULL) {
23 pr_err("Couldn't read /proc/kallsyms\n");
24 return -1;
25 }
26
27 for (i = 0; i < argc; ++i) {
28 struct map *map;
29 struct symbol *symbol = machine__find_kernel_function_by_name(machine, argv[i], &map);
30
31 if (symbol == NULL) {
32 printf("%s: not found\n", argv[i]);
33 continue;
34 }
35
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);
40 }
41
42 machine__delete(machine);
43 return 0;
44}
45
46int cmd_kallsyms(int argc, const char **argv, const char *prefix __maybe_unused)
47{
48 const struct option options[] = {
49 OPT_INCR('v', "verbose", &verbose, "be more verbose (show counter open errors, etc)"),
50 OPT_END()
51 };
52 const char * const kallsyms_usage[] = {
53 "perf kallsyms [<options>] symbol_name",
54 NULL
55 };
56
57 argc = parse_options(argc, argv, options, kallsyms_usage, 0);
58 if (argc < 1)
59 usage_with_options(kallsyms_usage, options);
60
61 symbol_conf.sort_by_name = true;
62 symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
63 if (symbol__init(NULL) < 0)
64 return -1;
65
66 return __cmd_kallsyms(argc, argv);
67}