2012-05-23 Stan Shebs <stan@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / mi / mi-cmds.c
CommitLineData
4389a95a 1/* MI Command Set for GDB, the GNU debugger.
0b302171
JB
2 Copyright (C) 2000-2001, 2003, 2007-2012 Free Software Foundation,
3 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);
2b03b41d 28
fb40c209
AC
29struct mi_cmd;
30static struct mi_cmd **lookup_table (const char *command);
31static void build_table (struct mi_cmd *commands);
32
fb40c209
AC
33struct mi_cmd mi_cmds[] =
34{
75082e8c 35 { "ada-task-info", { NULL, 0 }, mi_cmd_ada_task_info },
a79b8f6e 36 { "add-inferior", { NULL, 0 }, mi_cmd_add_inferior },
9e22b03a 37 { "break-after", { "ignore", 1 }, NULL },
9e22b03a 38 { "break-condition", { "cond", 1 }, NULL },
48cb2d85 39 { "break-commands", { NULL, 0 }, mi_cmd_break_commands },
9e22b03a
VP
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 },
9b4c786c 46 { "break-passcount", { NULL, 0 }, mi_cmd_break_passcount},
9e22b03a
VP
47 { "break-watch", { NULL, 0 }, mi_cmd_break_watch},
48 { "data-disassemble", { NULL, 0 }, mi_cmd_disassemble},
49 { "data-evaluate-expression", { NULL, 0 }, mi_cmd_data_evaluate_expression},
9a2b4c1b
MS
50 { "data-list-changed-registers", { NULL, 0 },
51 mi_cmd_data_list_changed_registers},
9e22b03a 52 { "data-list-register-names", { NULL, 0 }, mi_cmd_data_list_register_names},
9a2b4c1b
MS
53 { "data-list-register-values", { NULL, 0 },
54 mi_cmd_data_list_register_values},
9e22b03a 55 { "data-read-memory", { NULL, 0 }, mi_cmd_data_read_memory},
8dedea02 56 { "data-read-memory-bytes", { NULL, 0 }, mi_cmd_data_read_memory_bytes},
9e22b03a 57 { "data-write-memory", { NULL, 0 }, mi_cmd_data_write_memory},
8dedea02 58 { "data-write-memory-bytes", {NULL, 0}, mi_cmd_data_write_memory_bytes},
9a2b4c1b
MS
59 { "data-write-register-values", { NULL, 0 },
60 mi_cmd_data_write_register_values},
9e22b03a 61 { "enable-timings", { NULL, 0 }, mi_cmd_enable_timings},
0cc7d26f 62 { "enable-pretty-printing", { NULL, 0 }, mi_cmd_enable_pretty_printing},
9e22b03a
VP
63 { "environment-cd", { NULL, 0 }, mi_cmd_env_cd},
64 { "environment-directory", { NULL, 0 }, mi_cmd_env_dir},
65 { "environment-path", { NULL, 0 }, mi_cmd_env_path},
66 { "environment-pwd", { NULL, 0 }, mi_cmd_env_pwd},
9e22b03a 67 { "exec-arguments", { "set args", 1 }, NULL },
b2af646b
AC
68 { "exec-continue", { NULL, 0 }, mi_cmd_exec_continue},
69 { "exec-finish", { NULL, 0 }, mi_cmd_exec_finish},
143260c9 70 { "exec-jump", { NULL, 0 }, mi_cmd_exec_jump},
b2af646b
AC
71 { "exec-interrupt", { NULL, 0 }, mi_cmd_exec_interrupt},
72 { "exec-next", { NULL, 0 }, mi_cmd_exec_next},
73 { "exec-next-instruction", { NULL, 0 }, mi_cmd_exec_next_instruction},
74 { "exec-return", { NULL, 0 }, mi_cmd_exec_return},
115d30f9 75 { "exec-run", { NULL, 0}, mi_cmd_exec_run},
b2af646b
AC
76 { "exec-step", { NULL, 0 }, mi_cmd_exec_step},
77 { "exec-step-instruction", { NULL, 0 }, mi_cmd_exec_step_instruction},
1b98914a 78 { "exec-until", { "until", 1 }, NULL},
9e22b03a
VP
79 { "file-exec-and-symbols", { "file", 1 }, NULL },
80 { "file-exec-file", { "exec-file", 1 }, NULL },
9a2b4c1b
MS
81 { "file-list-exec-source-file", { NULL, 0 },
82 mi_cmd_file_list_exec_source_file},
83 { "file-list-exec-source-files", { NULL, 0 },
84 mi_cmd_file_list_exec_source_files },
9e22b03a 85 { "file-symbol-file", { "symbol-file", 1 }, NULL },
9e22b03a
VP
86 { "gdb-exit", { NULL, 0 }, mi_cmd_gdb_exit},
87 { "gdb-set", { "set", 1 }, NULL },
88 { "gdb-show", { "show", 1 }, NULL },
b2af646b 89 { "gdb-version", { "show version", 0 }, 0 },
9e22b03a
VP
90 { "inferior-tty-set", { NULL, 0 }, mi_cmd_inferior_tty_set},
91 { "inferior-tty-show", { NULL, 0 }, mi_cmd_inferior_tty_show},
f3e0e960 92 { "info-os", { NULL, 0 }, mi_cmd_info_os},
9e22b03a
VP
93 { "interpreter-exec", { NULL, 0 }, mi_cmd_interpreter_exec},
94 { "list-features", { NULL, 0 }, mi_cmd_list_features},
c6ebd6cf 95 { "list-target-features", { NULL, 0 }, mi_cmd_list_target_features},
3ee1c036 96 { "list-thread-groups", { NULL, 0 }, mi_cmd_list_thread_groups },
a79b8f6e 97 { "remove-inferior", { NULL, 0 }, mi_cmd_remove_inferior },
9e22b03a
VP
98 { "stack-info-depth", { NULL, 0 }, mi_cmd_stack_info_depth},
99 { "stack-info-frame", { NULL, 0 }, mi_cmd_stack_info_frame},
100 { "stack-list-arguments", { NULL, 0 }, mi_cmd_stack_list_args},
9e22b03a
VP
101 { "stack-list-frames", { NULL, 0 }, mi_cmd_stack_list_frames},
102 { "stack-list-locals", { NULL, 0 }, mi_cmd_stack_list_locals},
daf3c977 103 { "stack-list-variables", { NULL, 0 }, mi_cmd_stack_list_variables},
9e22b03a 104 { "stack-select-frame", { NULL, 0 }, mi_cmd_stack_select_frame},
9e22b03a 105 { "symbol-list-lines", { NULL, 0 }, mi_cmd_symbol_list_lines},
711eabed 106 { "target-attach", { "attach", 1 }, NULL },
6418d433 107 { "target-detach", { NULL, 0 }, mi_cmd_target_detach },
b2af646b 108 { "target-disconnect", { "disconnect", 0 }, 0 },
1b98914a 109 { "target-download", { "load", 1 }, NULL},
9e22b03a
VP
110 { "target-file-delete", { NULL, 0 }, mi_cmd_target_file_delete },
111 { "target-file-get", { NULL, 0 }, mi_cmd_target_file_get },
112 { "target-file-put", { NULL, 0 }, mi_cmd_target_file_put },
1b98914a 113 { "target-select", { "target", 1 }, NULL},
9e22b03a
VP
114 { "thread-info", { NULL, 0 }, mi_cmd_thread_info },
115 { "thread-list-ids", { NULL, 0 }, mi_cmd_thread_list_ids},
116 { "thread-select", { NULL, 0 }, mi_cmd_thread_select},
40e1c229 117 { "trace-define-variable", { NULL, 0 }, mi_cmd_trace_define_variable },
f197e0f1 118 { "trace-find", { NULL, 0 }, mi_cmd_trace_find },
40e1c229 119 { "trace-list-variables", { NULL, 0 }, mi_cmd_trace_list_variables },
011aacb0 120 { "trace-save", { NULL, 0 }, mi_cmd_trace_save },
f224b49d
VP
121 { "trace-start", { NULL, 0 }, mi_cmd_trace_start },
122 { "trace-status", { NULL, 0 }, mi_cmd_trace_status },
123 { "trace-stop", { NULL, 0 }, mi_cmd_trace_stop },
9e22b03a
VP
124 { "var-assign", { NULL, 0 }, mi_cmd_var_assign},
125 { "var-create", { NULL, 0 }, mi_cmd_var_create},
126 { "var-delete", { NULL, 0 }, mi_cmd_var_delete},
127 { "var-evaluate-expression", { NULL, 0 }, mi_cmd_var_evaluate_expression},
128 { "var-info-path-expression", { NULL, 0 }, mi_cmd_var_info_path_expression},
129 { "var-info-expression", { NULL, 0 }, mi_cmd_var_info_expression},
130 { "var-info-num-children", { NULL, 0 }, mi_cmd_var_info_num_children},
131 { "var-info-type", { NULL, 0 }, mi_cmd_var_info_type},
132 { "var-list-children", { NULL, 0 }, mi_cmd_var_list_children},
133 { "var-set-format", { NULL, 0 }, mi_cmd_var_set_format},
134 { "var-set-frozen", { NULL, 0 }, mi_cmd_var_set_frozen},
0cc7d26f 135 { "var-set-update-range", { NULL, 0 }, mi_cmd_var_set_update_range },
b6313243 136 { "var-set-visualizer", { NULL, 0 }, mi_cmd_var_set_visualizer},
9e22b03a
VP
137 { "var-show-attributes", { NULL, 0 }, mi_cmd_var_show_attributes},
138 { "var-show-format", { NULL, 0 }, mi_cmd_var_show_format},
139 { "var-update", { NULL, 0 }, mi_cmd_var_update},
b2af646b 140 { NULL, }
fb40c209
AC
141};
142
2b03b41d 143/* Pointer to the mi command table (built at run time). */
fb40c209
AC
144
145static struct mi_cmd **mi_table;
146
2b03b41d 147/* A prime large enough to accomodate the entire command table. */
fb40c209
AC
148enum
149 {
150 MI_TABLE_SIZE = 227
151 };
152
2b03b41d 153/* Exported function used to obtain info from the table. */
fb40c209
AC
154struct mi_cmd *
155mi_lookup (const char *command)
156{
157 return *lookup_table (command);
158}
159
2b03b41d
SS
160/* Used for collecting hash hit/miss statistics. */
161
fb40c209
AC
162struct mi_cmd_stats
163{
164 int hit;
165 int miss;
166 int rehash;
167};
168struct mi_cmd_stats stats;
169
2b03b41d
SS
170/* Look up a command. */
171
fb40c209
AC
172static struct mi_cmd **
173lookup_table (const char *command)
174{
175 const char *chp;
176 unsigned int index = 0;
102040f0 177
2b03b41d 178 /* Compute our hash. */
fb40c209
AC
179 for (chp = command; *chp; chp++)
180 {
2b03b41d 181 /* We use a somewhat arbitrary formula. */
fb40c209
AC
182 index = ((index << 6) + (unsigned int) *chp) % MI_TABLE_SIZE;
183 }
2b03b41d 184
fb40c209
AC
185 while (1)
186 {
187 struct mi_cmd **entry = &mi_table[index];
188 if ((*entry) == 0)
189 {
190 /* not found, return pointer to next free. */
191 stats.miss++;
192 return entry;
193 }
194 if (strcmp (command, (*entry)->name) == 0)
195 {
196 stats.hit++;
197 return entry; /* found */
198 }
199 index = (index + 1) % MI_TABLE_SIZE;
200 stats.rehash++;
201 }
202}
203
204static void
205build_table (struct mi_cmd *commands)
206{
207 int nr_rehash = 0;
208 int nr_entries = 0;
209 struct mi_cmd *command;
210 int sizeof_table = sizeof (struct mi_cmd **) * MI_TABLE_SIZE;
211
212 mi_table = xmalloc (sizeof_table);
213 memset (mi_table, 0, sizeof_table);
214 for (command = commands; command->name != 0; command++)
215 {
216 struct mi_cmd **entry = lookup_table (command->name);
102040f0 217
fb40c209 218 if (*entry)
8e65ff28 219 internal_error (__FILE__, __LINE__,
e2e0b3e5 220 _("command `%s' appears to be duplicated"),
fb40c209
AC
221 command->name);
222 *entry = command;
2b03b41d 223 /* FIXME lose these prints */
fb40c209
AC
224 if (0)
225 {
226 fprintf_unfiltered (gdb_stdlog, "%-30s %2d\n",
227 command->name, stats.rehash - nr_rehash);
228 }
229 nr_entries++;
230 nr_rehash = stats.rehash;
231 }
232 if (0)
233 {
234 fprintf_filtered (gdb_stdlog, "Average %3.1f\n",
235 (double) nr_rehash / (double) nr_entries);
236 }
237}
238
239void
fba45db2 240_initialize_mi_cmds (void)
fb40c209
AC
241{
242 build_table (mi_cmds);
243 memset (&stats, 0, sizeof (stats));
244}
This page took 1.400692 seconds and 4 git commands to generate.