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