builtin-kallsyms.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 <acme@redhat.com>
  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. const struct dso *dso;
  29. struct symbol *symbol = machine__find_kernel_symbol_by_name(machine, argv[i], &map);
  30. if (symbol == NULL) {
  31. printf("%s: not found\n", argv[i]);
  32. continue;
  33. }
  34. dso = map__dso(map);
  35. printf("%s: %s %s %#" PRIx64 "-%#" PRIx64 " (%#" PRIx64 "-%#" PRIx64")\n",
  36. symbol->name, dso__short_name(dso), dso__long_name(dso),
  37. map__unmap_ip(map, symbol->start), map__unmap_ip(map, symbol->end),
  38. symbol->start, symbol->end);
  39. }
  40. machine__delete(machine);
  41. return 0;
  42. }
  43. int cmd_kallsyms(int argc, const char **argv)
  44. {
  45. const struct option options[] = {
  46. OPT_INCR('v', "verbose", &verbose, "be more verbose (show counter open errors, etc)"),
  47. OPT_END()
  48. };
  49. const char * const kallsyms_usage[] = {
  50. "perf kallsyms [<options>] symbol_name",
  51. NULL
  52. };
  53. argc = parse_options(argc, argv, options, kallsyms_usage, 0);
  54. if (argc < 1)
  55. usage_with_options(kallsyms_usage, options);
  56. symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
  57. if (symbol__init(NULL) < 0)
  58. return -1;
  59. return __cmd_kallsyms(argc, argv);
  60. }