agent.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* Copyright (C) 2012-2022 Free Software Foundation, Inc.
  2. This file is part of GDB.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #include "defs.h"
  14. #include "command.h"
  15. #include "gdbcmd.h"
  16. #include "target.h"
  17. #include "gdbsupport/agent.h"
  18. #include "observable.h"
  19. #include "objfiles.h"
  20. /* Enum strings for "set|show agent". */
  21. static const char can_use_agent_on[] = "on";
  22. static const char can_use_agent_off[] = "off";
  23. static const char * const can_use_agent_enum[] =
  24. {
  25. can_use_agent_on,
  26. can_use_agent_off,
  27. NULL,
  28. };
  29. static const char *can_use_agent = can_use_agent_off;
  30. static void
  31. show_can_use_agent (struct ui_file *file, int from_tty,
  32. struct cmd_list_element *c, const char *value)
  33. {
  34. gdb_printf (file,
  35. _("Debugger's willingness to use agent in inferior "
  36. "as a helper is %s.\n"), value);
  37. }
  38. static void
  39. set_can_use_agent (const char *args, int from_tty, struct cmd_list_element *c)
  40. {
  41. bool can_use = (can_use_agent == can_use_agent_on);
  42. if (can_use && !agent_loaded_p ())
  43. {
  44. /* Since the setting was off, we may not have observed the objfiles and
  45. therefore not looked up the required symbols. Do so now. */
  46. for (objfile *objfile : current_program_space->objfiles ())
  47. if (agent_look_up_symbols (objfile) == 0)
  48. break;
  49. }
  50. if (target_use_agent (can_use) == 0)
  51. /* Something wrong during setting, set flag to default value. */
  52. can_use_agent = can_use_agent_off;
  53. }
  54. static void
  55. agent_new_objfile (struct objfile *objfile)
  56. {
  57. if (objfile == NULL || agent_loaded_p ())
  58. return;
  59. if (can_use_agent == can_use_agent_off)
  60. return;
  61. agent_look_up_symbols (objfile);
  62. }
  63. void _initialize_agent ();
  64. void
  65. _initialize_agent ()
  66. {
  67. gdb::observers::new_objfile.attach (agent_new_objfile,
  68. "agent");
  69. add_setshow_enum_cmd ("agent", class_run,
  70. can_use_agent_enum,
  71. &can_use_agent, _("\
  72. Set debugger's willingness to use agent as a helper."), _("\
  73. Show debugger's willingness to use agent as a helper."), _("\
  74. If on, GDB will delegate some of the debugging operations to the\n\
  75. agent, if the target supports it. This will speed up those\n\
  76. operations that are supported by the agent.\n\
  77. If off, GDB will not use agent, even if such is supported by the\n\
  78. target."),
  79. set_can_use_agent,
  80. show_can_use_agent,
  81. &setlist, &showlist);
  82. }