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