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