Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | /* Copyright (C) 2012-2020 Free Software Foundation, Inc. |
d1feda86 YQ |
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 "defs.h" | |
19 | #include "command.h" | |
20 | #include "gdbcmd.h" | |
21 | #include "target.h" | |
268a13a5 | 22 | #include "gdbsupport/agent.h" |
8d6efaa2 CB |
23 | #include "observable.h" |
24 | #include "objfiles.h" | |
d1feda86 YQ |
25 | |
26 | /* Enum strings for "set|show agent". */ | |
27 | ||
28 | static const char can_use_agent_on[] = "on"; | |
29 | static const char can_use_agent_off[] = "off"; | |
30 | static const char *can_use_agent_enum[] = | |
31 | { | |
32 | can_use_agent_on, | |
33 | can_use_agent_off, | |
34 | NULL, | |
35 | }; | |
36 | ||
37 | static const char *can_use_agent = can_use_agent_off; | |
38 | ||
39 | static void | |
40 | show_can_use_agent (struct ui_file *file, int from_tty, | |
41 | struct cmd_list_element *c, const char *value) | |
42 | { | |
43 | fprintf_filtered (file, | |
44 | _("Debugger's willingness to use agent in inferior " | |
45 | "as a helper is %s.\n"), value); | |
46 | } | |
47 | ||
48 | static void | |
eb4c3f4a | 49 | set_can_use_agent (const char *args, int from_tty, struct cmd_list_element *c) |
d1feda86 | 50 | { |
8d6efaa2 CB |
51 | bool can_use = (can_use_agent == can_use_agent_on); |
52 | if (can_use && !agent_loaded_p ()) | |
53 | { | |
54 | /* Since the setting was off, we may not have observed the objfiles and | |
55 | therefore not looked up the required symbols. Do so now. */ | |
56 | for (objfile *objfile : current_program_space->objfiles ()) | |
57 | if (agent_look_up_symbols (objfile) == 0) | |
58 | break; | |
59 | } | |
60 | if (target_use_agent (can_use) == 0) | |
d1feda86 YQ |
61 | /* Something wrong during setting, set flag to default value. */ |
62 | can_use_agent = can_use_agent_off; | |
63 | } | |
64 | ||
5808517f YQ |
65 | static void |
66 | agent_new_objfile (struct objfile *objfile) | |
67 | { | |
68 | if (objfile == NULL || agent_loaded_p ()) | |
69 | return; | |
70 | ||
8d6efaa2 CB |
71 | if (can_use_agent == can_use_agent_off) |
72 | return; | |
73 | ||
5808517f YQ |
74 | agent_look_up_symbols (objfile); |
75 | } | |
76 | ||
d1feda86 YQ |
77 | void |
78 | _initialize_agent (void) | |
79 | { | |
76727919 | 80 | gdb::observers::new_objfile.attach (agent_new_objfile); |
5808517f | 81 | |
d1feda86 YQ |
82 | add_setshow_enum_cmd ("agent", class_run, |
83 | can_use_agent_enum, | |
84 | &can_use_agent, _("\ | |
85 | Set debugger's willingness to use agent as a helper."), _("\ | |
86 | Show debugger's willingness to use agent as a helper."), _("\ | |
87 | If on, GDB will delegate some of the debugging operations to the\n\ | |
88 | agent, if the target supports it. This will speed up those\n\ | |
89 | operations that are supported by the agent.\n\ | |
90 | If off, GDB will not use agent, even if such is supported by the\n\ | |
91 | target."), | |
92 | set_can_use_agent, | |
93 | show_can_use_agent, | |
94 | &setlist, &showlist); | |
95 | } |