Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * builtin-kallsyms.c
0004  *
0005  * Builtin command: Look for a symbol in the running kernel and its modules
0006  *
0007  * Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
0008  */
0009 #include <inttypes.h>
0010 #include "builtin.h"
0011 #include <linux/compiler.h>
0012 #include <subcmd/parse-options.h>
0013 #include "debug.h"
0014 #include "dso.h"
0015 #include "machine.h"
0016 #include "map.h"
0017 #include "symbol.h"
0018 
0019 static int __cmd_kallsyms(int argc, const char **argv)
0020 {
0021     int i;
0022     struct machine *machine = machine__new_kallsyms();
0023 
0024     if (machine == NULL) {
0025         pr_err("Couldn't read /proc/kallsyms\n");
0026         return -1;
0027     }
0028 
0029     for (i = 0; i < argc; ++i) {
0030         struct map *map;
0031         struct symbol *symbol = machine__find_kernel_symbol_by_name(machine, argv[i], &map);
0032 
0033         if (symbol == NULL) {
0034             printf("%s: not found\n", argv[i]);
0035             continue;
0036         }
0037 
0038         printf("%s: %s %s %#" PRIx64 "-%#" PRIx64 " (%#" PRIx64 "-%#" PRIx64")\n",
0039             symbol->name, map->dso->short_name, map->dso->long_name,
0040             map->unmap_ip(map, symbol->start), map->unmap_ip(map, symbol->end),
0041             symbol->start, symbol->end);
0042     }
0043 
0044     machine__delete(machine);
0045     return 0;
0046 }
0047 
0048 int cmd_kallsyms(int argc, const char **argv)
0049 {
0050     const struct option options[] = {
0051     OPT_INCR('v', "verbose", &verbose, "be more verbose (show counter open errors, etc)"),
0052     OPT_END()
0053     };
0054     const char * const kallsyms_usage[] = {
0055         "perf kallsyms [<options>] symbol_name",
0056         NULL
0057     };
0058 
0059     argc = parse_options(argc, argv, options, kallsyms_usage, 0);
0060     if (argc < 1)
0061         usage_with_options(kallsyms_usage, options);
0062 
0063     symbol_conf.sort_by_name = true;
0064     symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
0065     if (symbol__init(NULL) < 0)
0066         return -1;
0067 
0068     return __cmd_kallsyms(argc, argv);
0069 }