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