* target.c (maybe_kill_then_attach)
[deliverable/binutils-gdb.git] / gdb / mi / mi-cmds.c
CommitLineData
4389a95a
AC
1/* MI Command Set for GDB, the GNU debugger.
2
9b254dd1 3 Copyright (C) 2000, 2001, 2003, 2007, 2008 Free Software Foundation, Inc.
4389a95a 4
ab91fdd5 5 Contributed by Cygnus Solutions (a Red Hat company).
fb40c209
AC
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
fb40c209
AC
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
fb40c209
AC
21
22#include "defs.h"
23#include "top.h"
24#include "mi-cmds.h"
27b82ed2 25#include "gdb_string.h"
fb40c209
AC
26
27extern void _initialize_mi_cmds (void);
28struct mi_cmd;
29static struct mi_cmd **lookup_table (const char *command);
30static void build_table (struct mi_cmd *commands);
31
32
33struct mi_cmd mi_cmds[] =
34{
9e22b03a
VP
35 { "break-after", { "ignore", 1 }, NULL },
36 { "break-catch", { NULL, 0 }, NULL },
37 { "break-commands", { NULL, 0 }, NULL },
38 { "break-condition", { "cond", 1 }, NULL },
39 { "break-delete", { "delete breakpoint", 1 }, NULL },
40 { "break-disable", { "disable breakpoint", 1 }, NULL },
41 { "break-enable", { "enable breakpoint", 1 }, NULL },
42 { "break-info", { "info break", 1 }, NULL },
43 { "break-insert", { NULL, 0 }, mi_cmd_break_insert},
44 { "break-list", { "info break", }, NULL },
45 { "break-watch", { NULL, 0 }, mi_cmd_break_watch},
46 { "data-disassemble", { NULL, 0 }, mi_cmd_disassemble},
47 { "data-evaluate-expression", { NULL, 0 }, mi_cmd_data_evaluate_expression},
48 { "data-list-changed-registers", { NULL, 0 }, mi_cmd_data_list_changed_registers},
49 { "data-list-register-names", { NULL, 0 }, mi_cmd_data_list_register_names},
50 { "data-list-register-values", { NULL, 0 }, mi_cmd_data_list_register_values},
51 { "data-read-memory", { NULL, 0 }, mi_cmd_data_read_memory},
52 { "data-write-memory", { NULL, 0 }, mi_cmd_data_write_memory},
53 { "data-write-register-values", { NULL, 0 }, mi_cmd_data_write_register_values},
54 { "enable-timings", { NULL, 0 }, mi_cmd_enable_timings},
55 { "environment-cd", { NULL, 0 }, mi_cmd_env_cd},
56 { "environment-directory", { NULL, 0 }, mi_cmd_env_dir},
57 { "environment-path", { NULL, 0 }, mi_cmd_env_path},
58 { "environment-pwd", { NULL, 0 }, mi_cmd_env_pwd},
59 { "exec-abort", { NULL, 0 }, NULL },
60 { "exec-arguments", { "set args", 1 }, NULL },
b2af646b
AC
61 { "exec-continue", { NULL, 0 }, mi_cmd_exec_continue},
62 { "exec-finish", { NULL, 0 }, mi_cmd_exec_finish},
63 { "exec-interrupt", { NULL, 0 }, mi_cmd_exec_interrupt},
64 { "exec-next", { NULL, 0 }, mi_cmd_exec_next},
65 { "exec-next-instruction", { NULL, 0 }, mi_cmd_exec_next_instruction},
66 { "exec-return", { NULL, 0 }, mi_cmd_exec_return},
1b98914a 67 { "exec-run", { "run", 1 }, NULL},
9e22b03a
VP
68 { "exec-show-arguments", { NULL, 0 }, NULL },
69 { "exec-signal", { NULL, 0 }, NULL },
b2af646b
AC
70 { "exec-step", { NULL, 0 }, mi_cmd_exec_step},
71 { "exec-step-instruction", { NULL, 0 }, mi_cmd_exec_step_instruction},
1b98914a 72 { "exec-until", { "until", 1 }, NULL},
9e22b03a
VP
73 { "file-clear", { NULL, 0 }, NULL },
74 { "file-exec-and-symbols", { "file", 1 }, NULL },
75 { "file-exec-file", { "exec-file", 1 }, NULL },
76 { "file-list-exec-sections", { NULL, 0 }, NULL },
77 { "file-list-exec-source-file", { NULL, 0 }, mi_cmd_file_list_exec_source_file},
78 { "file-list-exec-source-files", { NULL, 0 }, mi_cmd_file_list_exec_source_files },
79 { "file-list-shared-libraries", { NULL, 0 }, NULL },
80 { "file-list-symbol-files", { NULL, 0 }, NULL },
81 { "file-symbol-file", { "symbol-file", 1 }, NULL },
82 { "gdb-complete", { NULL, 0 }, NULL },
83 { "gdb-exit", { NULL, 0 }, mi_cmd_gdb_exit},
84 { "gdb-set", { "set", 1 }, NULL },
85 { "gdb-show", { "show", 1 }, NULL },
86 { "gdb-source", { NULL, 0 }, NULL },
b2af646b 87 { "gdb-version", { "show version", 0 }, 0 },
9e22b03a
VP
88 { "inferior-tty-set", { NULL, 0 }, mi_cmd_inferior_tty_set},
89 { "inferior-tty-show", { NULL, 0 }, mi_cmd_inferior_tty_show},
90 { "interpreter-exec", { NULL, 0 }, mi_cmd_interpreter_exec},
91 { "list-features", { NULL, 0 }, mi_cmd_list_features},
92 { "overlay-auto", { NULL, 0 }, NULL },
93 { "overlay-list-mapping-state", { NULL, 0 }, NULL },
94 { "overlay-list-overlays", { NULL, 0 }, NULL },
95 { "overlay-map", { NULL, 0 }, NULL },
96 { "overlay-off", { NULL, 0 }, NULL },
97 { "overlay-on", { NULL, 0 }, NULL },
98 { "overlay-unmap", { NULL, 0 }, NULL },
99 { "signal-handle", { NULL, 0 }, NULL },
100 { "signal-list-handle-actions", { NULL, 0 }, NULL },
101 { "signal-list-signal-types", { NULL, 0 }, NULL },
102 { "stack-info-depth", { NULL, 0 }, mi_cmd_stack_info_depth},
103 { "stack-info-frame", { NULL, 0 }, mi_cmd_stack_info_frame},
104 { "stack-list-arguments", { NULL, 0 }, mi_cmd_stack_list_args},
105 { "stack-list-exception-handlers", { NULL, 0 }, NULL },
106 { "stack-list-frames", { NULL, 0 }, mi_cmd_stack_list_frames},
107 { "stack-list-locals", { NULL, 0 }, mi_cmd_stack_list_locals},
108 { "stack-select-frame", { NULL, 0 }, mi_cmd_stack_select_frame},
109 { "symbol-info-address", { NULL, 0 }, NULL },
110 { "symbol-info-file", { NULL, 0 }, NULL },
111 { "symbol-info-function", { NULL, 0 }, NULL },
112 { "symbol-info-line", { NULL, 0 }, NULL },
113 { "symbol-info-symbol", { NULL, 0 }, NULL },
114 { "symbol-list-functions", { NULL, 0 }, NULL },
115 { "symbol-list-lines", { NULL, 0 }, mi_cmd_symbol_list_lines},
116 { "symbol-list-types", { NULL, 0 }, NULL },
117 { "symbol-list-variables", { NULL, 0 }, NULL },
118 { "symbol-locate", { NULL, 0 }, NULL },
119 { "symbol-type", { NULL, 0 }, NULL },
711eabed 120 { "target-attach", { "attach", 1 }, NULL },
9e22b03a 121 { "target-compare-sections", { NULL, 0 }, NULL },
b2af646b
AC
122 { "target-detach", { "detach", 0 }, 0 },
123 { "target-disconnect", { "disconnect", 0 }, 0 },
1b98914a 124 { "target-download", { "load", 1 }, NULL},
9e22b03a
VP
125 { "target-exec-status", { NULL, 0 }, NULL },
126 { "target-file-delete", { NULL, 0 }, mi_cmd_target_file_delete },
127 { "target-file-get", { NULL, 0 }, mi_cmd_target_file_get },
128 { "target-file-put", { NULL, 0 }, mi_cmd_target_file_put },
129 { "target-list-available-targets", { NULL, 0 }, NULL },
130 { "target-list-current-targets", { NULL, 0 }, NULL },
131 { "target-list-parameters", { NULL, 0 }, NULL },
1b98914a 132 { "target-select", { "target", 1 }, NULL},
9e22b03a
VP
133 { "thread-info", { NULL, 0 }, mi_cmd_thread_info },
134 { "thread-list-ids", { NULL, 0 }, mi_cmd_thread_list_ids},
135 { "thread-select", { NULL, 0 }, mi_cmd_thread_select},
136 { "trace-actions", { NULL, 0 }, NULL },
137 { "trace-delete", { NULL, 0 }, NULL },
138 { "trace-disable", { NULL, 0 }, NULL },
139 { "trace-dump", { NULL, 0 }, NULL },
140 { "trace-enable", { NULL, 0 }, NULL },
141 { "trace-exists", { NULL, 0 }, NULL },
142 { "trace-find", { NULL, 0 }, NULL },
143 { "trace-frame-number", { NULL, 0 }, NULL },
144 { "trace-info", { NULL, 0 }, NULL },
145 { "trace-insert", { NULL, 0 }, NULL },
146 { "trace-list", { NULL, 0 }, NULL },
147 { "trace-pass-count", { NULL, 0 }, NULL },
148 { "trace-save", { NULL, 0 }, NULL },
149 { "trace-start", { NULL, 0 }, NULL },
150 { "trace-stop", { NULL, 0 }, NULL },
151 { "var-assign", { NULL, 0 }, mi_cmd_var_assign},
152 { "var-create", { NULL, 0 }, mi_cmd_var_create},
153 { "var-delete", { NULL, 0 }, mi_cmd_var_delete},
154 { "var-evaluate-expression", { NULL, 0 }, mi_cmd_var_evaluate_expression},
155 { "var-info-path-expression", { NULL, 0 }, mi_cmd_var_info_path_expression},
156 { "var-info-expression", { NULL, 0 }, mi_cmd_var_info_expression},
157 { "var-info-num-children", { NULL, 0 }, mi_cmd_var_info_num_children},
158 { "var-info-type", { NULL, 0 }, mi_cmd_var_info_type},
159 { "var-list-children", { NULL, 0 }, mi_cmd_var_list_children},
160 { "var-set-format", { NULL, 0 }, mi_cmd_var_set_format},
161 { "var-set-frozen", { NULL, 0 }, mi_cmd_var_set_frozen},
162 { "var-show-attributes", { NULL, 0 }, mi_cmd_var_show_attributes},
163 { "var-show-format", { NULL, 0 }, mi_cmd_var_show_format},
164 { "var-update", { NULL, 0 }, mi_cmd_var_update},
b2af646b 165 { NULL, }
fb40c209
AC
166};
167
168/* Pointer to the mi command table (built at run time) */
169
170static struct mi_cmd **mi_table;
171
172/* A prime large enough to accomodate the entire command table */
173enum
174 {
175 MI_TABLE_SIZE = 227
176 };
177
178/* Exported function used to obtain info from the table */
179struct mi_cmd *
180mi_lookup (const char *command)
181{
182 return *lookup_table (command);
183}
184
185/* stat collecting */
186struct mi_cmd_stats
187{
188 int hit;
189 int miss;
190 int rehash;
191};
192struct mi_cmd_stats stats;
193
194/* our lookup function */
195static struct mi_cmd **
196lookup_table (const char *command)
197{
198 const char *chp;
199 unsigned int index = 0;
200 /* compute our hash */
201 for (chp = command; *chp; chp++)
202 {
203 /* some what arbitrary */
204 index = ((index << 6) + (unsigned int) *chp) % MI_TABLE_SIZE;
205 }
206 /* look it up */
207 while (1)
208 {
209 struct mi_cmd **entry = &mi_table[index];
210 if ((*entry) == 0)
211 {
212 /* not found, return pointer to next free. */
213 stats.miss++;
214 return entry;
215 }
216 if (strcmp (command, (*entry)->name) == 0)
217 {
218 stats.hit++;
219 return entry; /* found */
220 }
221 index = (index + 1) % MI_TABLE_SIZE;
222 stats.rehash++;
223 }
224}
225
226static void
227build_table (struct mi_cmd *commands)
228{
229 int nr_rehash = 0;
230 int nr_entries = 0;
231 struct mi_cmd *command;
232 int sizeof_table = sizeof (struct mi_cmd **) * MI_TABLE_SIZE;
233
234 mi_table = xmalloc (sizeof_table);
235 memset (mi_table, 0, sizeof_table);
236 for (command = commands; command->name != 0; command++)
237 {
238 struct mi_cmd **entry = lookup_table (command->name);
239 if (*entry)
8e65ff28 240 internal_error (__FILE__, __LINE__,
e2e0b3e5 241 _("command `%s' appears to be duplicated"),
fb40c209
AC
242 command->name);
243 *entry = command;
244 if (0)
245 {
246 fprintf_unfiltered (gdb_stdlog, "%-30s %2d\n",
247 command->name, stats.rehash - nr_rehash);
248 }
249 nr_entries++;
250 nr_rehash = stats.rehash;
251 }
252 if (0)
253 {
254 fprintf_filtered (gdb_stdlog, "Average %3.1f\n",
255 (double) nr_rehash / (double) nr_entries);
256 }
257}
258
259void
fba45db2 260_initialize_mi_cmds (void)
fb40c209
AC
261{
262 build_table (mi_cmds);
263 memset (&stats, 0, sizeof (stats));
264}
This page took 0.637943 seconds and 4 git commands to generate.