kdb.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Module kdb support
  4. *
  5. * Copyright (C) 2010 Jason Wessel
  6. */
  7. #include <linux/module.h>
  8. #include <linux/kdb.h>
  9. #include "internal.h"
  10. /*
  11. * kdb_lsmod - This function implements the 'lsmod' command. Lists
  12. * currently loaded kernel modules.
  13. * Mostly taken from userland lsmod.
  14. */
  15. int kdb_lsmod(int argc, const char **argv)
  16. {
  17. struct module *mod;
  18. if (argc != 0)
  19. return KDB_ARGCOUNT;
  20. kdb_printf("Module Size modstruct Used by\n");
  21. list_for_each_entry(mod, &modules, list) {
  22. if (mod->state == MODULE_STATE_UNFORMED)
  23. continue;
  24. kdb_printf("%-20s%8u", mod->name, mod->core_layout.size);
  25. #ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC
  26. kdb_printf("/%8u", mod->data_layout.size);
  27. #endif
  28. kdb_printf(" 0x%px ", (void *)mod);
  29. #ifdef CONFIG_MODULE_UNLOAD
  30. kdb_printf("%4d ", module_refcount(mod));
  31. #endif
  32. if (mod->state == MODULE_STATE_GOING)
  33. kdb_printf(" (Unloading)");
  34. else if (mod->state == MODULE_STATE_COMING)
  35. kdb_printf(" (Loading)");
  36. else
  37. kdb_printf(" (Live)");
  38. kdb_printf(" 0x%px", mod->core_layout.base);
  39. #ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC
  40. kdb_printf("/0x%px", mod->data_layout.base);
  41. #endif
  42. #ifdef CONFIG_MODULE_UNLOAD
  43. {
  44. struct module_use *use;
  45. kdb_printf(" [ ");
  46. list_for_each_entry(use, &mod->source_list,
  47. source_list)
  48. kdb_printf("%s ", use->target->name);
  49. kdb_printf("]\n");
  50. }
  51. #endif
  52. }
  53. return 0;
  54. }