Take #2 of this patch, now tested as per below.

I'll be committing this unless there are any major protests.

The target & gdb can be out of sync. The attached patch improves the
case where the target is in the running state already when a stepi/continue
packet is executed.

1. Case: target is running. Connect to it and issue a stepi. The
warning tells the
user that any "set $cpsr=0x1234", etc. will be discarded. The "^C" was me
stopping the target.

(gdb) target remote 10.0.0.136:3333
Remote debugging using 10.0.0.136:3333
0xda42c8f4 in ?? ()
(gdb) stepi
WARNING! The target is already running. All changes GDB did to
registers will be discarded! Waiting for target to halt.
^C
Program received signal SIGINT, Interrupt.
0xda42c5b8 in ?? ()

2. Connect to target that is in the halted stated. The first stepi
simply syncs up the
GDB registers.

(gdb) target remote 10.0.0.136:3333
Remote debugging using 10.0.0.136:3333
0xda42c5b8 in ?? ()
(gdb) stepi
stepi ignored. GDB will now fetch the register state from the target.

Program received signal SIGINT, Interrupt.
0xda42c5b8 in ?? ()
(gdb) stepi
0xda42c5bc in ?? ()

3. Resuming target "out of bounds" so GDB is out of sync. Checking that stepi
will simply sync up.

(gdb) monitor resume
(gdb) monitor poll
background polling: on
TAP: str710.cpu (enabled)
target state: running
(gdb) stepi
WARNING! The target is already running. All changes GDB did to
registers will be discarded! Waiting for target to halt.
^C
Program received signal SIGINT, Interrupt.
0xda42e074 in ?? ()
(gdb) stepi
0xda42e078 in ?? ()



-- 
Øyvind Harboe
US toll free 1-866-980-3434 / International +47 51 63 25 00
http://www.zylin.com/zy1000.html
ARM7 ARM9 ARM11 XScale Cortex
JTAG debugger and flash programmer
From c3a9f95c05eb065483ed455c33a2c8e0dcfbd025 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?=C3=98yvind=20Harboe?= <oyvind.har...@zylin.com>
Date: Wed, 20 Jan 2010 23:36:57 +0100
Subject: [PATCH] gdb_server: handle stepi/continue packet while target is running with more grace
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

Rather than issuing a halt and then stepi/resume, just
wait for target to halt.

Issue a sterner warning via gdb console that any gdb
register changes will be ignored in this case.

Signed-off-by: Øyvind Harboe <oyvind.har...@zylin.com>
---
 src/server/gdb_server.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c
index f3e0575..7900064 100644
--- a/src/server/gdb_server.c
+++ b/src/server/gdb_server.c
@@ -2212,12 +2212,13 @@ static int gdb_input_inner(struct connection *connection)
 						log_add_callback(gdb_log_callback, connection);
 
 						bool nostep = false;
+						bool already_running = false;
 						if (target->state == TARGET_RUNNING)
 						{
-							LOG_WARNING("The target is already running. Halt target before stepi/continue.");
-							retval = target_halt(target);
-							if (retval == ERROR_OK)
-								retval = target_wait_state(target, TARGET_HALTED, 100);
+							LOG_WARNING("WARNING! The target is already running. "
+									"All changes GDB did to registers will be discarded! "
+									"Waiting for target to halt.");
+							already_running = true;
 						} else if (target->state != TARGET_HALTED)
 						{
 							LOG_WARNING("The target is not in the halted nor running stated, stepi/continue ignored.");
@@ -2246,6 +2247,9 @@ static int gdb_input_inner(struct connection *connection)
 
 							/* stop forwarding log packets! */
 							log_remove_callback(gdb_log_callback, connection);
+						} else if (already_running)
+						{
+							/* we are already running, we'll wait for the target to halt */
 						} else
 						{
 							/* We're running/stepping, in which case we can
-- 
1.6.3.3

_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to