py-auto-load.c 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* GDB routines for supporting auto-loaded scripts.
  2. Copyright (C) 2010-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include "defs.h"
  15. #include "top.h"
  16. #include "gdbcmd.h"
  17. #include "objfiles.h"
  18. #include "python.h"
  19. #include "auto-load.h"
  20. #include "python-internal.h"
  21. /* User-settable option to enable/disable auto-loading of Python scripts:
  22. set auto-load python-scripts on|off
  23. This is true if we should auto-load associated Python scripts when an
  24. objfile is opened, false otherwise. */
  25. static bool auto_load_python_scripts = true;
  26. /* "show" command for the auto_load_python_scripts configuration variable. */
  27. static void
  28. show_auto_load_python_scripts (struct ui_file *file, int from_tty,
  29. struct cmd_list_element *c, const char *value)
  30. {
  31. gdb_printf (file, _("Auto-loading of Python scripts is %s.\n"), value);
  32. }
  33. /* See python-internal.h. */
  34. bool
  35. gdbpy_auto_load_enabled (const struct extension_language_defn *extlang)
  36. {
  37. return auto_load_python_scripts;
  38. }
  39. /* Wrapper for "info auto-load python-scripts". */
  40. static void
  41. info_auto_load_python_scripts (const char *pattern, int from_tty)
  42. {
  43. auto_load_info_scripts (pattern, from_tty, &extension_language_python);
  44. }
  45. int
  46. gdbpy_initialize_auto_load (void)
  47. {
  48. add_setshow_boolean_cmd ("python-scripts", class_support,
  49. &auto_load_python_scripts, _("\
  50. Set the debugger's behaviour regarding auto-loaded Python scripts."), _("\
  51. Show the debugger's behaviour regarding auto-loaded Python scripts."), _("\
  52. If enabled, auto-loaded Python scripts are loaded when the debugger reads\n\
  53. an executable or shared library.\n\
  54. This options has security implications for untrusted inferiors."),
  55. NULL, show_auto_load_python_scripts,
  56. auto_load_set_cmdlist_get (),
  57. auto_load_show_cmdlist_get ());
  58. set_show_commands auto_load_scripts_cmds
  59. = add_setshow_boolean_cmd ("auto-load-scripts", class_support,
  60. &auto_load_python_scripts, _("\
  61. Set the debugger's behaviour regarding auto-loaded Python scripts, "
  62. "deprecated."),
  63. _("\
  64. Show the debugger's behaviour regarding auto-loaded Python scripts, "
  65. "deprecated."),
  66. NULL, NULL, show_auto_load_python_scripts,
  67. &setlist, &showlist);
  68. deprecate_cmd (auto_load_scripts_cmds.set, "set auto-load python-scripts");
  69. deprecate_cmd (auto_load_scripts_cmds.show, "show auto-load python-scripts");
  70. add_cmd ("python-scripts", class_info, info_auto_load_python_scripts,
  71. _("Print the list of automatically loaded Python scripts.\n\
  72. Usage: info auto-load python-scripts [REGEXP]"),
  73. auto_load_info_cmdlist_get ());
  74. cmd_list_element *info_auto_load_scripts_cmd
  75. = add_info ("auto-load-scripts", info_auto_load_python_scripts, _("\
  76. Print the list of automatically loaded Python scripts, deprecated."));
  77. deprecate_cmd (info_auto_load_scripts_cmd, "info auto-load python-scripts");
  78. return 0;
  79. }