commit 7c994dd1bd1c95d5a6fde1c6ee0a96ace8c9fb5b
parent 7a543b60f89a8a22b89485a57cbb58c45f6070fc
Author: Brian Swetland <swetland@frotz.net>
Date:   Sat, 27 Jun 2015 01:47:51 -0700
debugger: log command to enable/disable logging
Diffstat:
4 files changed, 53 insertions(+), 30 deletions(-)
diff --git a/tools/debugger-commands.c b/tools/debugger-commands.c
@@ -690,33 +690,52 @@ int do_erase(int argc, param *argv) {
 	return run_flash_agent(argv[0].n, NULL, argv[1].n);
 }
 
+int do_log(int argc, param *argv) {
+	unsigned flags = 0;
+	while (argc > 0) {
+		if (!strcmp(argv[0].s, "gdb")) {
+			flags |= LF_GDB;
+		} else if (!strcmp(argv[0].s, "swd")) {
+			flags |= LF_SWD;
+		} else {
+			xprintf("error: allowed flags: gdb swd\n");
+			return -1;
+		}
+		argc--;
+		argv++;
+	}
+	log_flags = flags;
+	return 0;
+}
+
 struct debugger_command debugger_commands[] = {
-	{ "exit",	"", do_exit,	"" },
-	{ "attach",	"", do_attach,	"attach/reattach to sw-dp" },
-	{ "regs",	"", do_regs,	"show cpu registers" },
-	{ "stop",	"", do_stop,	"halt cpu" },
-	{ "step",	"", do_step,	"single-step cpu" },
-	{ "go",		"", do_resume,	"resume cpu" },
-	{ "dw",		"", do_dw,	"dump words" },
-	{ "db",		"", do_db,	"dump bytes" },
-	{ "dr",		"", do_dr,	"dump register" },
-	{ "wr",		"", do_wr,	"write register" },
-	{ "download",	"", do_download,"download file to device" },
-	{ "flash",	"", do_flash,	"write file to device flash" },
-	{ "erase",	"", do_erase,	"erase flash" },
-	{ "reset",	"", do_reset,	"reset target" },
-	{ "reset-stop",	"", do_reset_stop, "reset target and halt cpu" },
-	{ "reset-hw",	"", do_reset_hw, "strobe /RESET pin" },
-	{ "watch-pc",	"", do_watch_pc, "set watchpoint at addr" },
-	{ "watch-rw",	"", do_watch_rw, "set watchpoint at addr" },
-	{ "watch-off",	"", do_watch_off, "disable watchpoint" },
-	{ "print",	"", do_print,	"print numeric arguments" },
-	{ "echo",	"", do_echo, "echo command line" },
-	{ "bootloader", "", do_bootloader, "reboot into bootloader" },
-	{ "setclock",	"", do_setclock, "set clock rate (khz)" },
-	{ "arch",	"", do_setarch, "set architecture for flash agent" },
-	{ "text",	"", do_text, "dump text" },
-	{ "help",	"", do_help, "help" },
+	{ "exit",	"", do_exit,		"" },
+	{ "attach",	"", do_attach,		"attach/reattach to sw-dp" },
+	{ "regs",	"", do_regs,		"show cpu registers" },
+	{ "stop",	"", do_stop,		"halt cpu" },
+	{ "step",	"", do_step,		"single-step cpu" },
+	{ "go",		"", do_resume,		"resume cpu" },
+	{ "dw",		"", do_dw,		"dump words" },
+	{ "db",		"", do_db,		"dump bytes" },
+	{ "dr",		"", do_dr,		"dump register" },
+	{ "wr",		"", do_wr,		"write register" },
+	{ "download",	"", do_download,	"download file to device" },
+	{ "flash",	"", do_flash,		"write file to device flash" },
+	{ "erase",	"", do_erase,		"erase flash" },
+	{ "reset",	"", do_reset,		"reset target" },
+	{ "reset-stop",	"", do_reset_stop,	"reset target and halt cpu" },
+	{ "reset-hw",	"", do_reset_hw,	"strobe /RESET pin" },
+	{ "watch-pc",	"", do_watch_pc,	"set watchpoint at addr" },
+	{ "watch-rw",	"", do_watch_rw,	"set watchpoint at addr" },
+	{ "watch-off",	"", do_watch_off,	"disable watchpoint" },
+	{ "log",	"", do_log,		"enable/disable logging" },
+	{ "print",	"", do_print,		"print numeric arguments" },
+	{ "echo",	"", do_echo,		"echo command line" },
+	{ "bootloader", "", do_bootloader,	"reboot into bootloader" },
+	{ "setclock",	"", do_setclock,	"set clock rate (khz)" },
+	{ "arch",	"", do_setarch,		"set architecture for flash agent" },
+	{ "text",	"", do_text,		"dump text" },
+	{ "help",	"", do_help,		"help" },
 	{ 0, 0, 0, 0 },
 };
 
diff --git a/tools/debugger.c b/tools/debugger.c
@@ -30,6 +30,8 @@
 #include "linenoise.h"
 #include "debugger.h"
 
+unsigned log_flags = 0;
+
 void linenoiseInit(void);
 
 static const char *scriptfile = NULL;
diff --git a/tools/debugger.h b/tools/debugger.h
@@ -24,6 +24,11 @@ extern void xprintf(const char *fmt, ...);
 #define ERROR		-1
 #define ERROR_UNKNOWN 	-2
 
+#define LF_SWD		1
+#define LF_GDB		2
+
+extern unsigned log_flags;
+
 struct funcline {
 	struct funcline *next;
 	char text[0];
diff --git a/tools/gdb-bridge.c b/tools/gdb-bridge.c
@@ -43,7 +43,6 @@
 #define S_CHK2		3
 
 #define F_ACK		1
-#define F_TRACE		2
 #define F_RUNNING	4
 #define F_CONSOLE	8
 
@@ -147,7 +146,7 @@ void gdb_puthex(struct gdbcnxn *gc, const void *ptr, unsigned len) {
 void handle_command(struct gdbcnxn *gc, unsigned char *cmd);
 
 void gdb_recv_cmd(struct gdbcnxn *gc) {
-	if (gc->flags & F_TRACE) {
+	if (log_flags & LF_GDB) {
 		zprintf("PKT: %s\n", gc->rxbuf);
 	}
 	debugger_lock();
@@ -706,8 +705,6 @@ void gdb_server(int fd) {
 	zprintf("[ gdb connected ]\n");
 	debugger_unlock();
 
-//	gc.flags |= F_TRACE;
-
 	for (;;) {
 
 		fds[0].fd = fd;