Add mi/ and testsuite/gdb.mi/ subdirectories.
[external/binutils.git] / gdb / mi / mi-cmds.c
1 /* MI Command Set.
2    Copyright (C) 2000, Free Software Foundation, Inc.
3    Contributed by Cygnus Solutions.
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place - Suite 330,
20    Boston, MA 02111-1307, USA.  */
21
22 #include "defs.h"
23 #include "top.h"
24 #include "mi-cmds.h"
25 #include <string.h>
26
27 extern void _initialize_mi_cmds (void);
28 struct mi_cmd;
29 static struct mi_cmd **lookup_table (const char *command);
30 static void build_table (struct mi_cmd *commands);
31
32
33 struct mi_cmd mi_cmds[] =
34 {
35   {"break-after", "ignore %s", 0},
36   {"break-catch", 0, 0},
37   {"break-commands", 0, 0},
38   {"break-condition", "cond %s", 0},
39   {"break-delete", "delete breakpoint %s", 0},
40   {"break-disable", "disable breakpoint %s", 0},
41   {"break-enable", "enable breakpoint %s", 0},
42   {"break-info", "info break %s", 0},
43   {"break-insert", 0, 0, mi_cmd_break_insert},
44   {"break-list", "info break", 0},
45   {"break-watch", 0, 0, mi_cmd_break_watch},
46   {"data-disassemble", 0, 0, mi_cmd_disassemble},
47   {"data-evaluate-expression", 0, 0, mi_cmd_data_evaluate_expression},
48   {"data-list-changed-registers", 0, 0, mi_cmd_data_list_changed_registers},
49   {"data-list-register-names", 0, 0, mi_cmd_data_list_register_names},
50   {"data-list-register-values", 0, 0, mi_cmd_data_list_register_values},
51   {"data-read-memory", 0, 0, mi_cmd_data_read_memory},
52   {"data-write-memory", 0, 0, mi_cmd_data_write_memory},
53   {"display-delete", 0, 0},
54   {"display-disable", 0, 0},
55   {"display-enable", 0, 0},
56   {"display-insert", 0, 0},
57   {"display-list", 0, 0},
58   {"environment-cd", "cd %s", 0},
59   {"environment-directory", "dir %s", 0},
60   {"environment-path", "path %s", 0},
61   {"environment-pwd", "pwd", 0},
62   {"exec-abort", 0, 0},
63   {"exec-arguments", "set args %s", 0},
64   {"exec-continue", 0, mi_cmd_exec_continue},
65   {"exec-finish", 0, mi_cmd_exec_finish},
66   {"exec-interrupt", 0, mi_cmd_exec_interrupt},
67   {"exec-next", 0, mi_cmd_exec_next},
68   {"exec-next-instruction", 0, mi_cmd_exec_next_instruction},
69   {"exec-return", 0, mi_cmd_exec_return},
70   {"exec-run", 0, mi_cmd_exec_run},
71   {"exec-show-arguments", 0, 0},
72   {"exec-signal", 0, 0},
73   {"exec-step", 0, mi_cmd_exec_step},
74   {"exec-step-instruction", 0, mi_cmd_exec_step_instruction},
75   {"exec-until", 0, mi_cmd_exec_until},
76   {"file-clear", 0, 0},
77   {"file-exec-and-symbols", "file %s", 0},
78   {"file-exec-file", "exec-file %s", 0},
79   {"file-list-exec-sections", 0, 0},
80   {"file-list-exec-source-files", 0, 0},
81   {"file-list-shared-libraries", 0, 0},
82   {"file-list-symbol-files", 0, 0},
83   {"file-symbol-file", "symbol-file %s", 0},
84   {"gdb-complete", 0, 0},
85   {"gdb-exit", 0, 0, mi_cmd_gdb_exit},
86   {"gdb-set", "set %s", 0},
87   {"gdb-show", "show %s", 0},
88   {"gdb-source", 0, 0},
89   {"gdb-version", "show version", 0},
90   {"kod-info", 0, 0},
91   {"kod-list", 0, 0},
92   {"kod-list-object-types", 0, 0},
93   {"kod-show", 0, 0},
94   {"overlay-auto", 0, 0},
95   {"overlay-list-mapping-state", 0, 0},
96   {"overlay-list-overlays", 0, 0},
97   {"overlay-map", 0, 0},
98   {"overlay-off", 0, 0},
99   {"overlay-on", 0, 0},
100   {"overlay-unmap", 0, 0},
101   {"signal-handle", 0, 0},
102   {"signal-list-handle-actions", 0, 0},
103   {"signal-list-signal-types", 0, 0},
104   {"stack-info-depth", 0, 0, mi_cmd_stack_info_depth},
105   {"stack-info-frame", 0, 0},
106   {"stack-list-arguments", 0, 0, mi_cmd_stack_list_args},
107   {"stack-list-exception-handlers", 0, 0},
108   {"stack-list-frames", 0, 0, mi_cmd_stack_list_frames},
109   {"stack-list-locals", 0, 0, mi_cmd_stack_list_locals},
110   {"stack-select-frame", 0, 0, mi_cmd_stack_select_frame},
111   {"symbol-info-address", 0, 0},
112   {"symbol-info-file", 0, 0},
113   {"symbol-info-function", 0, 0},
114   {"symbol-info-line", 0, 0},
115   {"symbol-info-symbol", 0, 0},
116   {"symbol-list-functions", 0, 0},
117   {"symbol-list-types", 0, 0},
118   {"symbol-list-variables", 0, 0},
119   {"symbol-locate", 0, 0},
120   {"symbol-type", 0, 0},
121   {"target-attach", 0, 0},
122   {"target-compare-sections", 0, 0},
123   {"target-detach", "detach", 0},
124   {"target-download", 0, mi_cmd_target_download},
125   {"target-exec-status", 0, 0},
126   {"target-list-available-targets", 0, 0},
127   {"target-list-current-targets", 0, 0},
128   {"target-list-parameters", 0, 0},
129   {"target-select", 0, mi_cmd_target_select},
130   {"thread-info", 0, 0},
131   {"thread-list-all-threads", 0, 0},
132   {"thread-list-ids", 0, 0, mi_cmd_thread_list_ids},
133   {"thread-select", 0, 0, mi_cmd_thread_select},
134   {"trace-actions", 0, 0},
135   {"trace-delete", 0, 0},
136   {"trace-disable", 0, 0},
137   {"trace-dump", 0, 0},
138   {"trace-enable", 0, 0},
139   {"trace-exists", 0, 0},
140   {"trace-find", 0, 0},
141   {"trace-frame-number", 0, 0},
142   {"trace-info", 0, 0},
143   {"trace-insert", 0, 0},
144   {"trace-list", 0, 0},
145   {"trace-pass-count", 0, 0},
146   {"trace-save", 0, 0},
147   {"trace-start", 0, 0},
148   {"trace-stop", 0, 0},
149   {"var-assign", 0, 0, mi_cmd_var_assign},
150   {"var-create", 0, 0, mi_cmd_var_create},
151   {"var-delete", 0, 0, mi_cmd_var_delete},
152   {"var-evaluate-expression", 0, 0, mi_cmd_var_evaluate_expression},
153   {"var-info-expression", 0, 0, mi_cmd_var_info_expression},
154   {"var-info-num-children", 0, 0, mi_cmd_var_info_num_children},
155   {"var-info-type", 0, 0, mi_cmd_var_info_type},
156   {"var-list-children", 0, 0, mi_cmd_var_list_children},
157   {"var-set-format", 0, 0, mi_cmd_var_set_format},
158   {"var-show-attributes", 0, 0, mi_cmd_var_show_attributes},
159   {"var-show-format", 0, 0, mi_cmd_var_show_format},
160   {"var-update", 0, 0, mi_cmd_var_update},
161   {0,}
162 };
163
164 /* Pointer to the mi command table (built at run time) */
165
166 static struct mi_cmd **mi_table;
167
168 /* A prime large enough to accomodate the entire command table */
169 enum
170   {
171     MI_TABLE_SIZE = 227
172   };
173
174 /* Exported function used to obtain info from the table */
175 struct mi_cmd *
176 mi_lookup (const char *command)
177 {
178   return *lookup_table (command);
179 }
180
181 /* stat collecting */
182 struct mi_cmd_stats
183 {
184   int hit;
185   int miss;
186   int rehash;
187 };
188 struct mi_cmd_stats stats;
189
190 /* our lookup function */
191 static struct mi_cmd **
192 lookup_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
222 static void
223 build_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)
236         internal_error ("command `%s' appears to be duplicated",
237                         command->name);
238       *entry = command;
239       if (0)
240         {
241           fprintf_unfiltered (gdb_stdlog, "%-30s %2d\n",
242                               command->name, stats.rehash - nr_rehash);
243         }
244       nr_entries++;
245       nr_rehash = stats.rehash;
246     }
247   if (0)
248     {
249       fprintf_filtered (gdb_stdlog, "Average %3.1f\n",
250                         (double) nr_rehash / (double) nr_entries);
251     }
252 }
253
254 void
255 _initialize_mi_cmds ()
256 {
257   build_table (mi_cmds);
258   memset (&stats, 0, sizeof (stats));
259 }
260
261 /* Local variables: */
262 /* change-log-default-name: "ChangeLog-mi" */
263 /* End: */