1 |
330 |
jeremybenn |
/* MI Command Set for GDB, the GNU debugger.
|
2 |
|
|
|
3 |
|
|
Copyright (C) 2000, 2001, 2003, 2007, 2008, 2009, 2010
|
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 |
|
|
{ "add-inferior", { NULL, 0 }, mi_cmd_add_inferior },
|
37 |
|
|
{ "break-after", { "ignore", 1 }, NULL },
|
38 |
|
|
{ "break-condition", { "cond", 1 }, NULL },
|
39 |
|
|
{ "break-commands", { NULL, 0 }, mi_cmd_break_commands },
|
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-passcount", { NULL, 0 }, mi_cmd_break_passcount},
|
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},
|
54 |
|
|
{ "data-write-memory", { NULL, 0 }, mi_cmd_data_write_memory},
|
55 |
|
|
{ "data-write-register-values", { NULL, 0 }, mi_cmd_data_write_register_values},
|
56 |
|
|
{ "enable-timings", { NULL, 0 }, mi_cmd_enable_timings},
|
57 |
|
|
{ "enable-pretty-printing", { NULL, 0 }, mi_cmd_enable_pretty_printing},
|
58 |
|
|
{ "environment-cd", { NULL, 0 }, mi_cmd_env_cd},
|
59 |
|
|
{ "environment-directory", { NULL, 0 }, mi_cmd_env_dir},
|
60 |
|
|
{ "environment-path", { NULL, 0 }, mi_cmd_env_path},
|
61 |
|
|
{ "environment-pwd", { NULL, 0 }, mi_cmd_env_pwd},
|
62 |
|
|
{ "exec-arguments", { "set args", 1 }, NULL },
|
63 |
|
|
{ "exec-continue", { NULL, 0 }, mi_cmd_exec_continue},
|
64 |
|
|
{ "exec-finish", { NULL, 0 }, mi_cmd_exec_finish},
|
65 |
|
|
{ "exec-jump", { NULL, 0 }, mi_cmd_exec_jump},
|
66 |
|
|
{ "exec-interrupt", { NULL, 0 }, mi_cmd_exec_interrupt},
|
67 |
|
|
{ "exec-next", { NULL, 0 }, mi_cmd_exec_next},
|
68 |
|
|
{ "exec-next-instruction", { NULL, 0 }, mi_cmd_exec_next_instruction},
|
69 |
|
|
{ "exec-return", { NULL, 0 }, mi_cmd_exec_return},
|
70 |
|
|
{ "exec-run", { NULL, 0}, mi_cmd_exec_run},
|
71 |
|
|
{ "exec-step", { NULL, 0 }, mi_cmd_exec_step},
|
72 |
|
|
{ "exec-step-instruction", { NULL, 0 }, mi_cmd_exec_step_instruction},
|
73 |
|
|
{ "exec-until", { "until", 1 }, NULL},
|
74 |
|
|
{ "file-exec-and-symbols", { "file", 1 }, NULL },
|
75 |
|
|
{ "file-exec-file", { "exec-file", 1 }, NULL },
|
76 |
|
|
{ "file-list-exec-source-file", { NULL, 0 }, mi_cmd_file_list_exec_source_file},
|
77 |
|
|
{ "file-list-exec-source-files", { NULL, 0 }, mi_cmd_file_list_exec_source_files },
|
78 |
|
|
{ "file-symbol-file", { "symbol-file", 1 }, NULL },
|
79 |
|
|
{ "gdb-exit", { NULL, 0 }, mi_cmd_gdb_exit},
|
80 |
|
|
{ "gdb-set", { "set", 1 }, NULL },
|
81 |
|
|
{ "gdb-show", { "show", 1 }, NULL },
|
82 |
|
|
{ "gdb-version", { "show version", 0 }, 0 },
|
83 |
|
|
{ "inferior-tty-set", { NULL, 0 }, mi_cmd_inferior_tty_set},
|
84 |
|
|
{ "inferior-tty-show", { NULL, 0 }, mi_cmd_inferior_tty_show},
|
85 |
|
|
{ "interpreter-exec", { NULL, 0 }, mi_cmd_interpreter_exec},
|
86 |
|
|
{ "list-features", { NULL, 0 }, mi_cmd_list_features},
|
87 |
|
|
{ "list-target-features", { NULL, 0 }, mi_cmd_list_target_features},
|
88 |
|
|
{ "list-thread-groups", { NULL, 0 }, mi_cmd_list_thread_groups },
|
89 |
|
|
{ "remove-inferior", { NULL, 0 }, mi_cmd_remove_inferior },
|
90 |
|
|
{ "stack-info-depth", { NULL, 0 }, mi_cmd_stack_info_depth},
|
91 |
|
|
{ "stack-info-frame", { NULL, 0 }, mi_cmd_stack_info_frame},
|
92 |
|
|
{ "stack-list-arguments", { NULL, 0 }, mi_cmd_stack_list_args},
|
93 |
|
|
{ "stack-list-frames", { NULL, 0 }, mi_cmd_stack_list_frames},
|
94 |
|
|
{ "stack-list-locals", { NULL, 0 }, mi_cmd_stack_list_locals},
|
95 |
|
|
{ "stack-list-variables", { NULL, 0 }, mi_cmd_stack_list_variables},
|
96 |
|
|
{ "stack-select-frame", { NULL, 0 }, mi_cmd_stack_select_frame},
|
97 |
|
|
{ "symbol-list-lines", { NULL, 0 }, mi_cmd_symbol_list_lines},
|
98 |
|
|
{ "target-attach", { "attach", 1 }, NULL },
|
99 |
|
|
{ "target-detach", { NULL, 0 }, mi_cmd_target_detach },
|
100 |
|
|
{ "target-disconnect", { "disconnect", 0 }, 0 },
|
101 |
|
|
{ "target-download", { "load", 1 }, NULL},
|
102 |
|
|
{ "target-file-delete", { NULL, 0 }, mi_cmd_target_file_delete },
|
103 |
|
|
{ "target-file-get", { NULL, 0 }, mi_cmd_target_file_get },
|
104 |
|
|
{ "target-file-put", { NULL, 0 }, mi_cmd_target_file_put },
|
105 |
|
|
{ "target-select", { "target", 1 }, NULL},
|
106 |
|
|
{ "thread-info", { NULL, 0 }, mi_cmd_thread_info },
|
107 |
|
|
{ "thread-list-ids", { NULL, 0 }, mi_cmd_thread_list_ids},
|
108 |
|
|
{ "thread-select", { NULL, 0 }, mi_cmd_thread_select},
|
109 |
|
|
{ "trace-define-variable", { NULL, 0 }, mi_cmd_trace_define_variable },
|
110 |
|
|
{ "trace-find", { NULL, 0 }, mi_cmd_trace_find },
|
111 |
|
|
{ "trace-list-variables", { NULL, 0 }, mi_cmd_trace_list_variables },
|
112 |
|
|
{ "trace-save", { NULL, 0 }, mi_cmd_trace_save },
|
113 |
|
|
{ "trace-start", { NULL, 0 }, mi_cmd_trace_start },
|
114 |
|
|
{ "trace-status", { NULL, 0 }, mi_cmd_trace_status },
|
115 |
|
|
{ "trace-stop", { NULL, 0 }, mi_cmd_trace_stop },
|
116 |
|
|
{ "var-assign", { NULL, 0 }, mi_cmd_var_assign},
|
117 |
|
|
{ "var-create", { NULL, 0 }, mi_cmd_var_create},
|
118 |
|
|
{ "var-delete", { NULL, 0 }, mi_cmd_var_delete},
|
119 |
|
|
{ "var-evaluate-expression", { NULL, 0 }, mi_cmd_var_evaluate_expression},
|
120 |
|
|
{ "var-info-path-expression", { NULL, 0 }, mi_cmd_var_info_path_expression},
|
121 |
|
|
{ "var-info-expression", { NULL, 0 }, mi_cmd_var_info_expression},
|
122 |
|
|
{ "var-info-num-children", { NULL, 0 }, mi_cmd_var_info_num_children},
|
123 |
|
|
{ "var-info-type", { NULL, 0 }, mi_cmd_var_info_type},
|
124 |
|
|
{ "var-list-children", { NULL, 0 }, mi_cmd_var_list_children},
|
125 |
|
|
{ "var-set-format", { NULL, 0 }, mi_cmd_var_set_format},
|
126 |
|
|
{ "var-set-frozen", { NULL, 0 }, mi_cmd_var_set_frozen},
|
127 |
|
|
{ "var-set-update-range", { NULL, 0 }, mi_cmd_var_set_update_range },
|
128 |
|
|
{ "var-set-visualizer", { NULL, 0 }, mi_cmd_var_set_visualizer},
|
129 |
|
|
{ "var-show-attributes", { NULL, 0 }, mi_cmd_var_show_attributes},
|
130 |
|
|
{ "var-show-format", { NULL, 0 }, mi_cmd_var_show_format},
|
131 |
|
|
{ "var-update", { NULL, 0 }, mi_cmd_var_update},
|
132 |
|
|
{ NULL, }
|
133 |
|
|
};
|
134 |
|
|
|
135 |
|
|
/* Pointer to the mi command table (built at run time) */
|
136 |
|
|
|
137 |
|
|
static struct mi_cmd **mi_table;
|
138 |
|
|
|
139 |
|
|
/* A prime large enough to accomodate the entire command table */
|
140 |
|
|
enum
|
141 |
|
|
{
|
142 |
|
|
MI_TABLE_SIZE = 227
|
143 |
|
|
};
|
144 |
|
|
|
145 |
|
|
/* Exported function used to obtain info from the table */
|
146 |
|
|
struct mi_cmd *
|
147 |
|
|
mi_lookup (const char *command)
|
148 |
|
|
{
|
149 |
|
|
return *lookup_table (command);
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
/* stat collecting */
|
153 |
|
|
struct mi_cmd_stats
|
154 |
|
|
{
|
155 |
|
|
int hit;
|
156 |
|
|
int miss;
|
157 |
|
|
int rehash;
|
158 |
|
|
};
|
159 |
|
|
struct mi_cmd_stats stats;
|
160 |
|
|
|
161 |
|
|
/* our lookup function */
|
162 |
|
|
static struct mi_cmd **
|
163 |
|
|
lookup_table (const char *command)
|
164 |
|
|
{
|
165 |
|
|
const char *chp;
|
166 |
|
|
unsigned int index = 0;
|
167 |
|
|
|
168 |
|
|
/* compute our hash */
|
169 |
|
|
for (chp = command; *chp; chp++)
|
170 |
|
|
{
|
171 |
|
|
/* some what arbitrary */
|
172 |
|
|
index = ((index << 6) + (unsigned int) *chp) % MI_TABLE_SIZE;
|
173 |
|
|
}
|
174 |
|
|
/* look it up */
|
175 |
|
|
while (1)
|
176 |
|
|
{
|
177 |
|
|
struct mi_cmd **entry = &mi_table[index];
|
178 |
|
|
if ((*entry) == 0)
|
179 |
|
|
{
|
180 |
|
|
/* not found, return pointer to next free. */
|
181 |
|
|
stats.miss++;
|
182 |
|
|
return entry;
|
183 |
|
|
}
|
184 |
|
|
if (strcmp (command, (*entry)->name) == 0)
|
185 |
|
|
{
|
186 |
|
|
stats.hit++;
|
187 |
|
|
return entry; /* found */
|
188 |
|
|
}
|
189 |
|
|
index = (index + 1) % MI_TABLE_SIZE;
|
190 |
|
|
stats.rehash++;
|
191 |
|
|
}
|
192 |
|
|
}
|
193 |
|
|
|
194 |
|
|
static void
|
195 |
|
|
build_table (struct mi_cmd *commands)
|
196 |
|
|
{
|
197 |
|
|
int nr_rehash = 0;
|
198 |
|
|
int nr_entries = 0;
|
199 |
|
|
struct mi_cmd *command;
|
200 |
|
|
int sizeof_table = sizeof (struct mi_cmd **) * MI_TABLE_SIZE;
|
201 |
|
|
|
202 |
|
|
mi_table = xmalloc (sizeof_table);
|
203 |
|
|
memset (mi_table, 0, sizeof_table);
|
204 |
|
|
for (command = commands; command->name != 0; command++)
|
205 |
|
|
{
|
206 |
|
|
struct mi_cmd **entry = lookup_table (command->name);
|
207 |
|
|
|
208 |
|
|
if (*entry)
|
209 |
|
|
internal_error (__FILE__, __LINE__,
|
210 |
|
|
_("command `%s' appears to be duplicated"),
|
211 |
|
|
command->name);
|
212 |
|
|
*entry = command;
|
213 |
|
|
if (0)
|
214 |
|
|
{
|
215 |
|
|
fprintf_unfiltered (gdb_stdlog, "%-30s %2d\n",
|
216 |
|
|
command->name, stats.rehash - nr_rehash);
|
217 |
|
|
}
|
218 |
|
|
nr_entries++;
|
219 |
|
|
nr_rehash = stats.rehash;
|
220 |
|
|
}
|
221 |
|
|
if (0)
|
222 |
|
|
{
|
223 |
|
|
fprintf_filtered (gdb_stdlog, "Average %3.1f\n",
|
224 |
|
|
(double) nr_rehash / (double) nr_entries);
|
225 |
|
|
}
|
226 |
|
|
}
|
227 |
|
|
|
228 |
|
|
void
|
229 |
|
|
_initialize_mi_cmds (void)
|
230 |
|
|
{
|
231 |
|
|
build_table (mi_cmds);
|
232 |
|
|
memset (&stats, 0, sizeof (stats));
|
233 |
|
|
}
|