foss-for-synopsys-dwc-arc-processors/openocd — pull request #6 by anthony-kolesov (2013-08-29 15:17:14+00:00)
Title: ARC: Set target state to HALTED before calling callbacks for event

Both arc_dbg_resume() and arc_dbg_step() functions change target state to
RUNNING (DEBUG_RUNNING in case of step) and none of them set it back to HALTED.
Target state is set to HALTED only when doing reset and by arc_ocd_poll()
function witch runs on intervals. This is not the problem for arc_dbg_resume(),
but arc_dbg_step() works differently and after stepping it invokes callbacks for
event HALTED but it does not set target state to HALTED, this will be done only
on the following call to arc_ocd_poll(). Callack to event HALTED will cause
gdb_server to send a response to GDB client that execution halted. This leaves a
time window for GDB to send back some command that requires target to be already
halted before arc_ocd_poll() will change target state. This will cause a failure
on OpenOCD side. That is what was happening here - upon getting info that
target stepped GDB was requesting read from memory, which wasn't possible
because arc_ocd_poll() hasn't been executed yet.

This patch sets target state to HALTED before executing callback for HALTED
event. Interestingly none of the other targets except for ARM11 do this in
step() function (ARM11 does this in debug_entry()), that is they call callbacks
for HALTED event without setting target state to HALTED. May be somewhow they
ensure that poll() is called before running callbacks, but'm not sure how this
can be done. May be they are also affected by this issue, but it wasn't observed
by other because of specific condition required for it appearence.

Signed-off-by: Anton Kolesov