aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristopher Head <chead@zaber.com>2019-06-14 15:35:31 -0700
committerAntonio Borneo <borneo.antonio@gmail.com>2020-10-30 22:01:07 +0000
commitd05ef53cbd08972f89bd13e8ce2739de68965a05 (patch)
tree83fdcb7301b4916551cd64655587d04657065be3 /src
parentd3aa2d35363faeec4976b34fd5cb3127820ebc8d (diff)
downloadriscv-openocd-d05ef53cbd08972f89bd13e8ce2739de68965a05.zip
riscv-openocd-d05ef53cbd08972f89bd13e8ce2739de68965a05.tar.gz
riscv-openocd-d05ef53cbd08972f89bd13e8ce2739de68965a05.tar.bz2
target: restore last run state after profiling
Now that it’s possible to start profiling from either a running or a halted state, rather than unconditionally halting after profiling finishes, it makes more sense to restore the processor to whatever state (running or halted) it was in before profiling started. Change-Id: If6f6e70a1a365c1ce3b348a306c435c220b8bf12 Signed-off-by: Christopher Head <chead@zaber.com> Reviewed-on: http://openocd.zylin.com/5237 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/target/target.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/target/target.c b/src/target/target.c
index e64004f..53d3e82 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -4097,6 +4097,7 @@ COMMAND_HANDLER(handle_profile_command)
uint32_t offset;
uint32_t num_of_samples;
int retval = ERROR_OK;
+ bool halted_before_profiling = target->state == TARGET_HALTED;
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], offset);
@@ -4127,12 +4128,23 @@ COMMAND_HANDLER(handle_profile_command)
free(samples);
return retval;
}
- if (target->state == TARGET_RUNNING) {
+
+ if (target->state == TARGET_RUNNING && halted_before_profiling) {
+ /* The target was halted before we started and is running now. Halt it,
+ * for consistency. */
retval = target_halt(target);
if (retval != ERROR_OK) {
free(samples);
return retval;
}
+ } else if (target->state == TARGET_HALTED && !halted_before_profiling) {
+ /* The target was running before we started and is halted now. Resume
+ * it, for consistency. */
+ retval = target_resume(target, 1, 0, 0, 0);
+ if (retval != ERROR_OK) {
+ free(samples);
+ return retval;
+ }
}
retval = target_poll(target);