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