builtin-kallsyms.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * builtin-kallsyms.c
  4. *
  5. * Builtin command: Look for a symbol in the running kernel and its modules
  6. *
  7. * Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <[email protected]>
  8. */
  9. #include <inttypes.h>
  10. #include "builtin.h"
  11. #include <linux/compiler.h>
  12. #include <subcmd/parse-options.h>
  13. #include "debug.h"
  14. #include "dso.h"
  15. #include "machine.h"
  16. #include "map.h"
  17. #include "symbol.h"
  18. static int __cmd_kallsyms(int argc, const char **argv)
  19. {
  20. int i;
  21. struct machine *machine = machine__new_kallsyms();
  22. if (machine == NULL) {
  23. pr_err("Couldn't read /proc/kallsyms\n");
  24. return -1;
  25. }
  26. for (i = 0; i < argc; ++i) {
  27. struct map *map;
  28. struct symbol *symbol = machine__find_kernel_symbol_by_name(machine, argv[i], &map);
  29. if (symbol == NULL) {
  30. printf("%s: not found\n", argv[i]);
  31. continue;
  32. }
  33. printf("%s: %s %s %#" PRIx64 "-%#" PRIx64 " (%#" PRIx64 "-%#" PRIx64")\n",
  34. symbol->name, map->dso->short_name, map->dso->long_name,
  35. map->unmap_ip(map, symbol->start), map->unmap_ip(map, symbol->end),
  36. symbol->start, symbol->end);
  37. }
  38. machine__delete(machine);
  39. return 0;
  40. }
  41. int cmd_kallsyms(int argc, const char **argv)
  42. {
  43. const struct option options[] = {
  44. OPT_INCR('v', "verbose", &verbose, "be more verbose (show counter open errors, etc)"),
  45. OPT_END()
  46. };
  47. const char * const kallsyms_usage[] = {
  48. "perf kallsyms [<options>] symbol_name",
  49. NULL
  50. };
  51. argc = parse_options(argc, argv, options, kallsyms_usage, 0);
  52. if (argc < 1)
  53. usage_with_options(kallsyms_usage, options);
  54. symbol_conf.sort_by_name = true;
  55. symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
  56. if (symbol__init(NULL) < 0)
  57. return -1;
  58. return __cmd_kallsyms(argc, argv);
  59. }