-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcmddb.c
322 lines (308 loc) · 7.38 KB
/
cmddb.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/* MSPDebug - debugging tool for MSP430 MCUs
* Copyright (C) 2009, 2010 Daniel Beer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <string.h>
#include "cmddb.h"
#include "util.h"
#include "devcmd.h"
#include "gdb.h"
#include "rtools.h"
#include "sym.h"
#include "stdcmd.h"
#include "simio.h"
#include "aliasdb.h"
const struct cmddb_record commands[] = {
{
.name = "help",
.func = cmd_help,
.help =
"help [command]\n"
" Without arguments, displays a list of commands. With a command\n"
" name as an argument, displays help for that command.\n"
},
{
.name = "opt",
.func = cmd_opt,
.help =
"opt [name] [value]\n"
" Query or set option variables. With no arguments, displays all\n"
" available options.\n"
},
{
.name = "read",
.func = cmd_read,
.help =
"read <filename>\n"
" Read commands from a file and evaluate them.\n"
},
{
.name = "setbreak",
.func = cmd_setbreak,
.help =
"setbreak <addr> [index]\n"
" Set a breakpoint. If no index is specified, the first available\n"
" slot will be used.\n"
},
{
.name = "delbreak",
.func = cmd_delbreak,
.help =
"delbreak [index]\n"
" Delete a breakpoint. If no index is specified, then all active\n"
" breakpoints are cleared.\n"
},
{
.name = "break",
.func = cmd_break,
.help =
"break\n"
" List active breakpoints.\n"
},
{
.name = "regs",
.func = cmd_regs,
.help =
"regs\n"
" Read and display the current register contents.\n"
},
{
.name = "prog",
.func = cmd_prog,
.help =
"prog <filename>\n"
" Erase the device and flash the data contained in a binary file.\n"
" This command also loads symbols from the file, if available.\n"
},
{
.name = "load",
.func = cmd_load,
.help =
"load <filename>\n"
" Flash the data contained in a binary file. Does not load symbols\n"
" or erase the device.\n"
},
{
.name = "md",
.func = cmd_md,
.help =
"md <address> [length]\n"
" Read the specified number of bytes from memory at the given\n"
" address, and display a hexdump.\n"
},
{
.name = "mw",
.func = cmd_mw,
.help =
"mw <address> bytes ...\n"
" Write a sequence of bytes to a memory address. Byte values are\n"
" two-digit hexadecimal numbers.\n"
},
{
.name = "reset",
.func = cmd_reset,
.help =
"reset\n"
" Reset (and halt) the CPU.\n"
},
{
.name = "erase",
.func = cmd_erase,
.help =
"erase [all|segment] [address]\n"
" Erase the device under test. With no arguments, erases all of main\n"
" memory. Specify arguments to perform a mass erase, or to erase\n"
" individual segments.\n"
},
{
.name = "step",
.func = cmd_step,
.help =
"step [count]\n"
" Single-step the CPU, and display the register state.\n"
},
{
.name = "run",
.func = cmd_run,
.help =
"run\n"
" Run the CPU to until a breakpoint is reached or the command is\n"
" interrupted.\n"
},
{
.name = "set",
.func = cmd_set,
.help =
"set <register> <value>\n"
" Change the value of a CPU register.\n"
},
{
.name = "dis",
.func = cmd_dis,
.help =
"dis <address> [length]\n"
" Disassemble a section of memory.\n"
},
{
.name = "hexout",
.func = cmd_hexout,
.help =
"hexout <address> <length> <filename.hex>\n"
" Save a region of memory into a HEX file.\n"
},
{
.name = "gdb",
.func = cmd_gdb,
.help =
"gdb [port]\n"
" Run a GDB remote stub on the given TCP/IP port.\n"
},
{
.name = "=",
.func = cmd_eval,
.help =
"= <expression>\n"
" Evaluate an expression using the symbol table.\n"
},
{
.name = "sym",
.func = cmd_sym,
.help =
"sym clear\n"
" Clear the symbol table.\n"
"sym set <name> <value>\n"
" Set or overwrite the value of a symbol.\n"
"sym del <name>\n"
" Delete a symbol from the symbol table.\n"
"sym import <filename>\n"
" Load symbols from the given file.\n"
"sym import+ <filename>\n"
" Load additional symbols from the given file.\n"
"sym export <filename>\n"
" Save the current symbols to a BSD-style symbol file.\n"
"sym find <regex>\n"
" Search for symbols by regular expression.\n"
"sym rename <regex> <string>\n"
" Replace every occurance of a pattern in symbol names.\n"
},
{
.name = "isearch",
.func = cmd_isearch,
.help =
"isearch <address> <length> [options ...]\n"
" Search for an instruction matching certain search terms. These\n"
" terms may be any of the following:\n"
" opcode <opcode>\n"
" byte|word|aword\n"
" jump|single|double|noarg\n"
" src <value>\n"
" dst <value>\n"
" srcreg <register>\n"
" dstreg <register>\n"
" srcmode R|I|S|&|@|+|#\n"
" dstmode R|I|S|&|@|+|#\n"
" For single-operand instructions, the operand is considered the\n"
" destination operand.\n"
},
{
.name = "cgraph",
.func = cmd_cgraph,
.help =
"cgraph <address> <length> [function]\n"
" Analyse the range given and produce a call graph. Displays a summary\n"
" of all functions if no function address is given.\n"
},
{
.name = "locka",
.func = cmd_locka,
.help =
"locka [set|clear]\n"
" Show or change the status of the LOCKA flash write-protect bit.\n"
},
{
.name = "exit",
.func = cmd_exit,
.help =
"exit\n"
" Exit from MSPDebug.\n"
},
{
.name = "simio",
.func = cmd_simio,
.help =
"simio add <class> <name> [args ...]\n"
" Add a new device to the IO simulator's bus.\n"
"simio del <name>\n"
" Delete a device from the bus.\n"
"simio devices\n"
" Show all devices attached to the bus.\n"
"simio classes\n"
" Show the types of devices which may be attached.\n"
"simio help <class>\n"
" Obtain more information about a device type.\n"
"simio config <name> <param> [args ...]\n"
" Change settings of an attached device.\n"
"simio info <name>\n"
" Print status information for an attached device.\n"
},
{
.name = "alias",
.func = cmd_alias,
.help =
"alias\n"
" List all defined aliases.\n"
"alias <name>\n"
" Remove an alias definition.\n"
"alias <name> <command>\n"
" Define a new alias.\n"
}
};
int cmddb_get(const char *name, struct cmddb_record *ret)
{
int len = strlen(name);
int i;
const struct cmddb_record *found = NULL;
/* First look for an exact match */
for (i = 0; i < ARRAY_LEN(commands); i++) {
const struct cmddb_record *r = &commands[i];
if (!strcasecmp(r->name, name)) {
found = r;
goto done;
}
}
/* Allow partial matches if unambiguous */
for (i = 0; i < ARRAY_LEN(commands); i++) {
const struct cmddb_record *r = &commands[i];
if (!strncasecmp(r->name, name, len)) {
if (found)
return -1;
found = r;
}
}
if (!found)
return -1;
done:
memcpy(ret, found, sizeof(*ret));
return 0;
}
int cmddb_enum(cmddb_enum_func_t func, void *user_data)
{
int i;
for (i = 0; i < ARRAY_LEN(commands); i++)
if (func(user_data, &commands[i]) < 0)
return -1;
return 0;
}