target: restore last run state after profiling 37/5237/5
authorChristopher Head <chead@zaber.com>
Fri, 14 Jun 2019 22:35:31 +0000 (15:35 -0700)
committerAntonio Borneo <borneo.antonio@gmail.com>
Fri, 30 Oct 2020 22:01:07 +0000 (22:01 +0000)
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>
src/target/target.c

index e64004fe56d3f228c2282418f0fae9f202e7f267..53d3e82d7e7f0d752dcbc8a336640b5146942aab 100644 (file)
@@ -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);

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)