From fc808485c21789bab0d5427c3353acf4f1d059ea Mon Sep 17 00:00:00 2001 From: Daniel Beer Date: Tue, 12 Oct 2010 11:26:36 +1300 Subject: [PATCH] Allow the default input radix to be specified (iradix). --- devcmd.c | 34 ++++++++++++++++++++-------------- expr.c | 18 ++++++++++++------ gdb.c | 9 ++++++--- mspdebug.man | 10 ++++++++-- opdb.c | 10 +++++++++- 5 files changed, 55 insertions(+), 26 deletions(-) diff --git a/devcmd.c b/devcmd.c index f24680f..9a85211 100644 --- a/devcmd.c +++ b/devcmd.c @@ -175,16 +175,19 @@ int cmd_erase(char **arg) int cmd_step(char **arg) { char *count_text = get_arg(arg); - int count = 1; + address_t count = 1; + int i; - if (count_text) - count = atoi(count_text); + if (count_text) { + if (expr_eval(stab_default, count_text, &count) < 0) { + printc_err("step: can't parse count: %s\n", count_text); + return -1; + } + } - while (count > 0) { + for (i = 0; i < count; i++) if (device_default->ctl(device_default, DEVICE_CTL_STEP) < 0) return -1; - count--; - } return cmd_regs(NULL); } @@ -557,13 +560,15 @@ int cmd_setbreak(char **arg) } if (index_text) { - index = atoi(index_text); + address_t val; - if (index < 0 || index >= device_default->max_breakpoints) { - printc_err("setbreak: invalid breakpoint " - "slot: %d\n", index); + if (expr_eval(stab_default, index_text, &val) < 0 || + val >= device_default->max_breakpoints) { + printc("setbreak: invalid breakpoint slot: %d\n", val); return -1; } + + index = val; } index = device_setbrk(device_default, index, 1, addr); @@ -583,11 +588,12 @@ int cmd_delbreak(char **arg) int ret = 0; if (index_text) { - int index = atoi(index_text); + address_t index; - if (index < 0 || index >= device_default->max_breakpoints) { - printc_err("delbreak: invalid breakpoint " - "slot: %d\n", index); + if (expr_eval(stab_default, index_text, &index) < 0 || + index >= device_default->max_breakpoints) { + printc("delbreak: invalid breakpoint slot: %d\n", + index); return -1; } diff --git a/expr.c b/expr.c index 5ff387e..2c283e5 100644 --- a/expr.c +++ b/expr.c @@ -28,6 +28,7 @@ #include "stab.h" #include "util.h" #include "output.h" +#include "opdb.h" /************************************************************************ * Address expression parsing. @@ -52,13 +53,18 @@ static int addr_exp_data(stab_t stab, } /* Hex value */ - if (*text == '0' && text[1] == 'x') + if (*text == '0' && text[1] == 'x') { value = strtoul(text + 2, NULL, 16); - else if (isdigit(*text)) - value = atoi(text); - else if (stab_get(stab, text, &value) < 0) { - printc_err("can't parse token: %s\n", text); - return -1; + } else if (*text == '0' && text[1] == 'd') { + value = atoi(text + 2); + } else if (stab_get(stab, text, &value) < 0) { + char *end; + + value = strtol(text, &end, opdb_get_numeric("iradix")); + if (*end) { + printc_err("can't parse token: %s\n", text); + return -1; + } } if (s->data_stack_size + 1 > ARRAY_LEN(s->data_stack)) { diff --git a/gdb.c b/gdb.c index f17c2e2..77f87a2 100644 --- a/gdb.c +++ b/gdb.c @@ -33,6 +33,7 @@ #include "gdb.h" #include "output.h" #include "reader.h" +#include "expr.h" #define MAX_MEM_XFER 8192 @@ -698,10 +699,12 @@ static int gdb_server(int port) int cmd_gdb(char **arg) { char *port_text = get_arg(arg); - int port = 2000; + address_t port = 2000; - if (port_text) - port = atoi(port_text); + if (port_text && expr_eval(stab_default, port_text, &port) < 0) { + printc_err("gdb: can't parse port: %s\n", port_text); + return -1; + } if (port <= 0 || port > 65535) { printc_err("gdb: invalid port: %d\n", port); diff --git a/mspdebug.man b/mspdebug.man index 64fccff..5ca0862 100644 --- a/mspdebug.man +++ b/mspdebug.man @@ -389,8 +389,10 @@ Any command which accepts a memory address, length or register value as an argument may be given an address expression. An address expression consists of an algebraic combination of values. -An address value may be either a decimal value, a hexadecimal value -preceeded by the prefix \fB0x\fR, or a symbol name. +An address value may be either a symbol name, a hex value preceeded +with the specifier "0x", a decimal value preceeded with the specifier +"0d", or a number in the default input radix (without a specifier). See +the option \fBiradix\fR for more information. The operators recognised are the usual algebraic operators: \fB+\fR, \fB-\fR, \fB*\fR, \fB/\fR, \fB%\fR, \fB(\fR and \fB)\fR. Operator precedence is the @@ -416,6 +418,10 @@ If true, MSPDebug will colorize debugging output. Automatically restart the GDB server after disconnection. If this option is set, then the GDB server keeps running until an error occurs, or the user interrupts with Ctrl+C. +.IP "\fBiradix\fR (numeric)" +Default input radix for address expressions. For address values with +no radix specifier, this value gives the input radix, which is +10 (decimal) by default. .IP "\fBquiet\fR (boolean)" If set, MSPDebug will supress most of its debug-related output. This option defaults to false, but can be set true on start-up using the \fB-q\fR diff --git a/opdb.c b/opdb.c index 429fb88..6a0c77a 100644 --- a/opdb.c +++ b/opdb.c @@ -43,10 +43,18 @@ const static struct opdb_key keys[] = { { .name = "quiet", .type = OPDB_TYPE_BOOLEAN, - .help = "Supress debugging output\n", + .help = "Supress debugging output.\n", .defval = { .boolean = 0 } + }, + { + .name = "iradix", + .type = OPDB_TYPE_NUMERIC, + .help = "Default input radix.\n", + .defval = { + .numeric = 10 + } } };