Added RC file processing on startup.
This commit is contained in:
parent
757a9fb799
commit
b12e0f5ddb
33
main.c
33
main.c
|
@ -34,10 +34,10 @@
|
||||||
static void usage(const char *progname)
|
static void usage(const char *progname)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Usage: %s -R [-v voltage] [command ...]\n"
|
"Usage: %s [options] -R [-v voltage] [command ...]\n"
|
||||||
" %s -u <device> [-j] [-v voltage] [command ...]\n"
|
" %s [options] -u <device> [-j] [-v voltage] [command ...]\n"
|
||||||
" %s -B <device> [command ...]\n"
|
" %s [options] -B <device> [command ...]\n"
|
||||||
" %s -s [command ...]\n"
|
" %s [options] -s [command ...]\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -R\n"
|
" -R\n"
|
||||||
" Open the first available RF2500 device on the USB bus.\n"
|
" Open the first available RF2500 device on the USB bus.\n"
|
||||||
|
@ -51,6 +51,10 @@ static void usage(const char *progname)
|
||||||
" Debug the FET itself through the bootloader.\n"
|
" Debug the FET itself through the bootloader.\n"
|
||||||
" -s\n"
|
" -s\n"
|
||||||
" Start in simulation mode.\n"
|
" Start in simulation mode.\n"
|
||||||
|
" -n\n"
|
||||||
|
" Do not read ~/.mspdebug on startup.\n"
|
||||||
|
" -?\n"
|
||||||
|
" Show this help text.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"By default, the first RF2500 device on the USB bus is opened.\n"
|
"By default, the first RF2500 device on the USB bus is opened.\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
@ -59,6 +63,18 @@ static void usage(const char *progname)
|
||||||
progname, progname, progname, progname);
|
progname, progname, progname, progname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void process_rc_file(void)
|
||||||
|
{
|
||||||
|
const char *home = getenv("HOME");
|
||||||
|
char text[256];
|
||||||
|
|
||||||
|
if (!home)
|
||||||
|
return;
|
||||||
|
|
||||||
|
snprintf(text, sizeof(text), "%s/.mspdebug", home);
|
||||||
|
process_file(text);
|
||||||
|
}
|
||||||
|
|
||||||
#define MODE_RF2500 0x01
|
#define MODE_RF2500 0x01
|
||||||
#define MODE_UIF 0x02
|
#define MODE_UIF 0x02
|
||||||
#define MODE_UIF_BSL 0x04
|
#define MODE_UIF_BSL 0x04
|
||||||
|
@ -71,6 +87,7 @@ int main(int argc, char **argv)
|
||||||
const char *bsl_device = NULL;
|
const char *bsl_device = NULL;
|
||||||
const struct device *msp430_dev = NULL;
|
const struct device *msp430_dev = NULL;
|
||||||
int opt;
|
int opt;
|
||||||
|
int no_rc = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
int want_jtag = 0;
|
int want_jtag = 0;
|
||||||
|
@ -84,7 +101,7 @@ int main(int argc, char **argv)
|
||||||
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
|
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
|
||||||
|
|
||||||
/* Parse arguments */
|
/* Parse arguments */
|
||||||
while ((opt = getopt(argc, argv, "u:jv:B:sR?")) >= 0)
|
while ((opt = getopt(argc, argv, "u:jv:B:sR?n")) >= 0)
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'R':
|
case 'R':
|
||||||
mode |= MODE_RF2500;
|
mode |= MODE_RF2500;
|
||||||
|
@ -112,6 +129,10 @@ int main(int argc, char **argv)
|
||||||
mode |= MODE_SIM;
|
mode |= MODE_SIM;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'n':
|
||||||
|
no_rc = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -171,6 +192,8 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
device_init(msp430_dev);
|
device_init(msp430_dev);
|
||||||
|
if (!no_rc)
|
||||||
|
process_rc_file();
|
||||||
|
|
||||||
/* Process commands */
|
/* Process commands */
|
||||||
if (optind < argc) {
|
if (optind < argc) {
|
||||||
|
|
17
mspdebug.man
17
mspdebug.man
|
@ -2,13 +2,13 @@
|
||||||
.SH NAME
|
.SH NAME
|
||||||
MSPDebug - debugging tool for MSP430 MCUs
|
MSPDebug - debugging tool for MSP430 MCUs
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
\fBmspdebug\fR \-R [\-v \fIvoltage\fR] [\fIcommand\fR ...]
|
\fBmspdebug\fR [options] \-R [\-v \fIvoltage\fR] [\fIcommand\fR ...]
|
||||||
.br
|
.br
|
||||||
\fBmspdebug\fR \-u \fIdevice\fR [\-j] [\-v \fIvoltage\fR] [\fIcommand\fR ...]
|
\fBmspdebug\fR [options] \-u \fIdevice\fR [\-j] [\-v \fIvoltage\fR] [\fIcommand\fR ...]
|
||||||
.br
|
.br
|
||||||
\fBmspdebug\fR \-B \fIdevice\fR [\fIcommand\fR ...]
|
\fBmspdebug\fR [options] \-B \fIdevice\fR [\fIcommand\fR ...]
|
||||||
.br
|
.br
|
||||||
\fBmspdebug\fR \-s [\fIcommand\fR ...]
|
\fBmspdebug\fR [options] \-s [\fIcommand\fR ...]
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
MSPDebug is a command-line tool designed for debugging and programming
|
MSPDebug is a command-line tool designed for debugging and programming
|
||||||
the MSP430 family of MCUs. It supports the eZ430-F2013, eZ430-RF2500
|
the MSP430 family of MCUs. It supports the eZ430-F2013, eZ430-RF2500
|
||||||
|
@ -24,6 +24,11 @@ run to breakpoint).
|
||||||
It supports ELF32, Intel HEX and BSD-style symbol tables (such as the
|
It supports ELF32, Intel HEX and BSD-style symbol tables (such as the
|
||||||
output produced by \fBnm\fR(1)). It can also be used as a remote stub
|
output produced by \fBnm\fR(1)). It can also be used as a remote stub
|
||||||
for \fBgdb\fR(1).
|
for \fBgdb\fR(1).
|
||||||
|
|
||||||
|
On startup, MSPDebug will look for a file called .mspdebug in the user's
|
||||||
|
home directory. If it exists, commands will be read and executed from this
|
||||||
|
file before executing any other commands or starting the interactive
|
||||||
|
reader.
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
Command-line options accepted by MSPDebug are described below. If
|
Command-line options accepted by MSPDebug are described below. If
|
||||||
commands are specified on the end of the command-line, then they are
|
commands are specified on the end of the command-line, then they are
|
||||||
|
@ -75,6 +80,10 @@ request and stop execution.
|
||||||
This mode is intended for testing of changes to MSPDebug, and for
|
This mode is intended for testing of changes to MSPDebug, and for
|
||||||
aiding the disassembly of MSP430 binaries (as all binary and symbol
|
aiding the disassembly of MSP430 binaries (as all binary and symbol
|
||||||
table formats are still usable in this mode).
|
table formats are still usable in this mode).
|
||||||
|
.IP "\-n"
|
||||||
|
Do not process the startup file (~/.mspdebug).
|
||||||
|
.IP "\-?"
|
||||||
|
Display a brief help message and exit.
|
||||||
.SH COMMANDS
|
.SH COMMANDS
|
||||||
MSPDebug can accept commands either through an interactive prompt, or
|
MSPDebug can accept commands either through an interactive prompt, or
|
||||||
non-interactively when specified on the command line. The supported
|
non-interactively when specified on the command line. The supported
|
||||||
|
|
27
util.c
27
util.c
|
@ -410,16 +410,11 @@ static struct command command_opt = {
|
||||||
" available options.\n"
|
" available options.\n"
|
||||||
};
|
};
|
||||||
|
|
||||||
static int cmd_read(char **arg)
|
int process_file(const char *filename)
|
||||||
{
|
{
|
||||||
char *filename = get_arg(arg);
|
|
||||||
FILE *in;
|
FILE *in;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
int line_no = 0;
|
||||||
if (!filename) {
|
|
||||||
fprintf(stderr, "read: filename must be specified\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
in = fopen(filename, "r");
|
in = fopen(filename, "r");
|
||||||
if (!in) {
|
if (!in) {
|
||||||
|
@ -431,6 +426,8 @@ static int cmd_read(char **arg)
|
||||||
while (fgets(buf, sizeof(buf), in)) {
|
while (fgets(buf, sizeof(buf), in)) {
|
||||||
char *cmd = buf;
|
char *cmd = buf;
|
||||||
|
|
||||||
|
line_no++;
|
||||||
|
|
||||||
while (*cmd && isspace(*cmd))
|
while (*cmd && isspace(*cmd))
|
||||||
cmd++;
|
cmd++;
|
||||||
|
|
||||||
|
@ -438,8 +435,8 @@ static int cmd_read(char **arg)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (process_command(cmd, 0) < 0) {
|
if (process_command(cmd, 0) < 0) {
|
||||||
fprintf(stderr, "read: error processing %s\n",
|
fprintf(stderr, "read: error processing %s (line %d)\n",
|
||||||
filename);
|
filename, line_no);
|
||||||
fclose(in);
|
fclose(in);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -449,6 +446,18 @@ static int cmd_read(char **arg)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int cmd_read(char **arg)
|
||||||
|
{
|
||||||
|
char *filename = get_arg(arg);
|
||||||
|
|
||||||
|
if (!filename) {
|
||||||
|
fprintf(stderr, "read: filename must be specified\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return process_file(filename);
|
||||||
|
}
|
||||||
|
|
||||||
static struct command command_read = {
|
static struct command command_read = {
|
||||||
.name = "read",
|
.name = "read",
|
||||||
.func = cmd_read,
|
.func = cmd_read,
|
||||||
|
|
1
util.h
1
util.h
|
@ -46,6 +46,7 @@ char *get_arg(char **text);
|
||||||
* should be executed in an interactive context.
|
* should be executed in an interactive context.
|
||||||
*/
|
*/
|
||||||
int process_command(char *arg, int interactive);
|
int process_command(char *arg, int interactive);
|
||||||
|
int process_file(const char *filename);
|
||||||
|
|
||||||
/* Run the reader loop, exiting when the user presses Ctrl+D.
|
/* Run the reader loop, exiting when the user presses Ctrl+D.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue