jtag: linuxgpiod: drop extra parenthesis
[openocd.git] / src / target / esirisc_trace.c
index 4e0a15529c41c8732cf16fe61966974a9eb86565..376ea1db746d43fe2cd1b06ca6ff8b3e9369c90c 100644 (file)
@@ -1,19 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
 /***************************************************************************
  *   Copyright (C) 2018 by Square, Inc.                                    *
  *   Steven Stallion <stallion@squareup.com>                               *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -385,9 +374,9 @@ static int esirisc_trace_read_buffer(struct target *target, uint8_t *buffer)
                        buffer_cur - trace_info->buffer_start, buffer);
 }
 
-static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t *buffer, uint32_t size)
+static int esirisc_trace_analyze_full(struct command_invocation *cmd, uint8_t *buffer, uint32_t size)
 {
-       struct target *target = get_current_target(cmd_ctx);
+       struct target *target = get_current_target(cmd->ctx);
        const uint32_t num_bits = size * 8;
        int retval;
 
@@ -403,7 +392,7 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t *
                        case ESIRISC_TRACE_ID_EXECUTE:
                        case ESIRISC_TRACE_ID_STALL:
                        case ESIRISC_TRACE_ID_BRANCH:
-                               command_print(cmd_ctx, "%s", esirisc_trace_id_strings[id]);
+                               command_print(cmd, "%s", esirisc_trace_id_strings[id]);
                                break;
 
                        case ESIRISC_TRACE_ID_EXTENDED: {
@@ -417,7 +406,7 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t *
                                        case ESIRISC_TRACE_EXT_ID_STOP:
                                        case ESIRISC_TRACE_EXT_ID_WAIT:
                                        case ESIRISC_TRACE_EXT_ID_MULTICYCLE:
-                                               command_print(cmd_ctx, "%s", esirisc_trace_ext_id_strings[ext_id]);
+                                               command_print(cmd, "%s", esirisc_trace_ext_id_strings[ext_id]);
                                                break;
 
                                        case ESIRISC_TRACE_EXT_ID_ERET:
@@ -430,11 +419,11 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t *
                                                if (retval != ERROR_OK)
                                                        goto fail;
 
-                                               command_print(cmd_ctx, "%s PC: 0x%" PRIx32,
+                                               command_print(cmd, "%s PC: 0x%" PRIx32,
                                                                esirisc_trace_ext_id_strings[ext_id], pc);
 
                                                if (ext_id == ESIRISC_TRACE_EXT_ID_END_PC) {
-                                                       command_print(cmd_ctx, "--- end of trace ---");
+                                                       command_print(cmd, "--- end of trace ---");
                                                        return ERROR_OK;
                                                }
                                                break;
@@ -450,7 +439,7 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t *
                                                if (retval != ERROR_OK)
                                                        goto fail;
 
-                                               command_print(cmd_ctx, "%s EID: 0x%" PRIx32 ", EPC: 0x%" PRIx32,
+                                               command_print(cmd, "%s EID: 0x%" PRIx32 ", EPC: 0x%" PRIx32,
                                                                esirisc_trace_ext_id_strings[ext_id], eid, epc);
                                                break;
                                        }
@@ -461,34 +450,34 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t *
                                                if (retval != ERROR_OK)
                                                        goto fail;
 
-                                               command_print(cmd_ctx, "repeats %" PRId32 " %s", count,
+                                               command_print(cmd, "repeats %" PRIu32 " %s", count,
                                                                (count == 1) ? "time" : "times");
                                                break;
                                        }
                                        case ESIRISC_TRACE_EXT_ID_END:
-                                               command_print(cmd_ctx, "--- end of trace ---");
+                                               command_print(cmd, "--- end of trace ---");
                                                return ERROR_OK;
 
                                        default:
-                                               command_print(cmd_ctx, "invalid extended trace ID: %" PRId32, ext_id);
+                                               command_print(cmd, "invalid extended trace ID: %" PRIu32, ext_id);
                                                return ERROR_FAIL;
                                }
                                break;
                        }
                        default:
-                               command_print(cmd_ctx, "invalid trace ID: %" PRId32, id);
+                               command_print(cmd, "invalid trace ID: %" PRIu32, id);
                                return ERROR_FAIL;
                }
        }
 
 fail:
-       command_print(cmd_ctx, "trace buffer too small");
+       command_print(cmd, "trace buffer too small");
        return ERROR_BUF_TOO_SMALL;
 }
 
-static int esirisc_trace_analyze_simple(struct command_context *cmd_ctx, uint8_t *buffer, uint32_t size)
+static int esirisc_trace_analyze_simple(struct command_invocation *cmd, uint8_t *buffer, uint32_t size)
 {
-       struct target *target = get_current_target(cmd_ctx);
+       struct target *target = get_current_target(cmd->ctx);
        struct esirisc_common *esirisc = target_to_esirisc(target);
        struct esirisc_trace *trace_info = &esirisc->trace_info;
        const uint32_t end_of_trace = BIT_MASK(trace_info->pc_bits) << 1;
@@ -504,45 +493,45 @@ static int esirisc_trace_analyze_simple(struct command_context *cmd_ctx, uint8_t
                        break;
 
                if (pc == end_of_trace) {
-                       command_print(cmd_ctx, "--- end of trace ---");
+                       command_print(cmd, "--- end of trace ---");
                        return ERROR_OK;
                }
 
-               command_print(cmd_ctx, "PC: 0x%" PRIx32, pc);
+               command_print(cmd, "PC: 0x%" PRIx32, pc);
        }
 
-       command_print(cmd_ctx, "trace buffer too small");
+       command_print(cmd, "trace buffer too small");
        return ERROR_BUF_TOO_SMALL;
 }
 
-static int esirisc_trace_analyze(struct command_context *cmd_ctx, uint8_t *buffer, uint32_t size)
+static int esirisc_trace_analyze(struct command_invocation *cmd, uint8_t *buffer, uint32_t size)
 {
-       struct target *target = get_current_target(cmd_ctx);
+       struct target *target = get_current_target(cmd->ctx);
        struct esirisc_common *esirisc = target_to_esirisc(target);
        struct esirisc_trace *trace_info = &esirisc->trace_info;
 
        switch (trace_info->format) {
                case ESIRISC_TRACE_FORMAT_FULL:
-                       command_print(cmd_ctx, "--- full pipeline ---");
-                       return esirisc_trace_analyze_full(cmd_ctx, buffer, size);
+                       command_print(cmd, "--- full pipeline ---");
+                       return esirisc_trace_analyze_full(cmd, buffer, size);
 
                case ESIRISC_TRACE_FORMAT_BRANCH:
-                       command_print(cmd_ctx, "--- branches taken ---");
-                       return esirisc_trace_analyze_full(cmd_ctx, buffer, size);
+                       command_print(cmd, "--- branches taken ---");
+                       return esirisc_trace_analyze_full(cmd, buffer, size);
 
                case ESIRISC_TRACE_FORMAT_ICACHE:
-                       command_print(cmd_ctx, "--- icache misses ---");
-                       return esirisc_trace_analyze_simple(cmd_ctx, buffer, size);
+                       command_print(cmd, "--- icache misses ---");
+                       return esirisc_trace_analyze_simple(cmd, buffer, size);
 
                default:
-                       command_print(cmd_ctx, "invalid trace format: %i", trace_info->format);
+                       command_print(cmd, "invalid trace format: %i", trace_info->format);
                        return ERROR_FAIL;
        }
 }
 
-static int esirisc_trace_analyze_buffer(struct command_context *cmd_ctx)
+static int esirisc_trace_analyze_buffer(struct command_invocation *cmd)
 {
-       struct target *target = get_current_target(cmd_ctx);
+       struct target *target = get_current_target(cmd->ctx);
        struct esirisc_common *esirisc = target_to_esirisc(target);
        struct esirisc_trace *trace_info = &esirisc->trace_info;
        uint8_t *buffer;
@@ -551,8 +540,8 @@ static int esirisc_trace_analyze_buffer(struct command_context *cmd_ctx)
 
        size = esirisc_trace_buffer_size(trace_info);
        buffer = calloc(1, size);
-       if (buffer == NULL) {
-               command_print(cmd_ctx, "out of memory");
+       if (!buffer) {
+               command_print(cmd, "out of memory");
                return ERROR_FAIL;
        }
 
@@ -560,7 +549,7 @@ static int esirisc_trace_analyze_buffer(struct command_context *cmd_ctx)
        if (retval != ERROR_OK)
                goto done;
 
-       retval = esirisc_trace_analyze(cmd_ctx, buffer, size);
+       retval = esirisc_trace_analyze(cmd, buffer, size);
 
 done:
        free(buffer);
@@ -568,16 +557,16 @@ done:
        return retval;
 }
 
-static int esirisc_trace_analyze_memory(struct command_context *cmd_ctx,
+static int esirisc_trace_analyze_memory(struct command_invocation *cmd,
                target_addr_t address, uint32_t size)
 {
-       struct target *target = get_current_target(cmd_ctx);
+       struct target *target = get_current_target(cmd->ctx);
        uint8_t *buffer;
        int retval;
 
        buffer = calloc(1, size);
-       if (buffer == NULL) {
-               command_print(cmd_ctx, "out of memory");
+       if (!buffer) {
+               command_print(cmd, "out of memory");
                return ERROR_FAIL;
        }
 
@@ -585,7 +574,7 @@ static int esirisc_trace_analyze_memory(struct command_context *cmd_ctx,
        if (retval != ERROR_OK)
                goto done;
 
-       retval = esirisc_trace_analyze(cmd_ctx, buffer, size);
+       retval = esirisc_trace_analyze(cmd, buffer, size);
 
 done:
        free(buffer);
@@ -593,7 +582,7 @@ done:
        return retval;
 }
 
-static int esirisc_trace_dump(struct command_context *cmd_ctx, const char *filename,
+static int esirisc_trace_dump(struct command_invocation *cmd, const char *filename,
                uint8_t *buffer, uint32_t size)
 {
        struct fileio *fileio;
@@ -602,24 +591,24 @@ static int esirisc_trace_dump(struct command_context *cmd_ctx, const char *filen
 
        retval = fileio_open(&fileio, filename, FILEIO_WRITE, FILEIO_BINARY);
        if (retval != ERROR_OK) {
-               command_print(cmd_ctx, "could not open dump file: %s", filename);
+               command_print(cmd, "could not open dump file: %s", filename);
                return retval;
        }
 
        retval = fileio_write(fileio, size, buffer, &size_written);
        if (retval == ERROR_OK)
-               command_print(cmd_ctx, "trace data dumped to: %s", filename);
+               command_print(cmd, "trace data dumped to: %s", filename);
        else
-               command_print(cmd_ctx, "could not write dump file: %s", filename);
+               command_print(cmd, "could not write dump file: %s", filename);
 
        fileio_close(fileio);
 
        return retval;
 }
 
-static int esirisc_trace_dump_buffer(struct command_context *cmd_ctx, const char *filename)
+static int esirisc_trace_dump_buffer(struct command_invocation *cmd, const char *filename)
 {
-       struct target *target = get_current_target(cmd_ctx);
+       struct target *target = get_current_target(cmd->ctx);
        struct esirisc_common *esirisc = target_to_esirisc(target);
        struct esirisc_trace *trace_info = &esirisc->trace_info;
        uint8_t *buffer;
@@ -628,8 +617,8 @@ static int esirisc_trace_dump_buffer(struct command_context *cmd_ctx, const char
 
        size = esirisc_trace_buffer_size(trace_info);
        buffer = calloc(1, size);
-       if (buffer == NULL) {
-               command_print(cmd_ctx, "out of memory");
+       if (!buffer) {
+               command_print(cmd, "out of memory");
                return ERROR_FAIL;
        }
 
@@ -637,7 +626,7 @@ static int esirisc_trace_dump_buffer(struct command_context *cmd_ctx, const char
        if (retval != ERROR_OK)
                goto done;
 
-       retval = esirisc_trace_dump(cmd_ctx, filename, buffer, size);
+       retval = esirisc_trace_dump(cmd, filename, buffer, size);
 
 done:
        free(buffer);
@@ -645,16 +634,16 @@ done:
        return retval;
 }
 
-static int esirisc_trace_dump_memory(struct command_context *cmd_ctx, const char *filename,
+static int esirisc_trace_dump_memory(struct command_invocation *cmd, const char *filename,
                target_addr_t address, uint32_t size)
 {
-       struct target *target = get_current_target(cmd_ctx);
+       struct target *target = get_current_target(cmd->ctx);
        uint8_t *buffer;
        int retval;
 
        buffer = calloc(1, size);
-       if (buffer == NULL) {
-               command_print(cmd_ctx, "out of memory");
+       if (!buffer) {
+               command_print(cmd, "out of memory");
                return ERROR_FAIL;
        }
 
@@ -662,7 +651,7 @@ static int esirisc_trace_dump_memory(struct command_context *cmd_ctx, const char
        if (retval != ERROR_OK)
                goto done;
 
-       retval = esirisc_trace_dump(cmd_ctx, filename, buffer, size);
+       retval = esirisc_trace_dump(cmd, filename, buffer, size);
 
 done:
        free(buffer);
@@ -676,13 +665,13 @@ COMMAND_HANDLER(handle_esirisc_trace_init_command)
        struct esirisc_common *esirisc = target_to_esirisc(target);
 
        if (!esirisc->has_trace) {
-               command_print(CMD_CTX, "target does not support trace");
+               command_print(CMD, "target does not support trace");
                return ERROR_FAIL;
        }
 
        int retval = esirisc_trace_init(target);
        if (retval == ERROR_OK)
-               command_print(CMD_CTX, "trace initialized");
+               command_print(CMD, "trace initialized");
 
        return retval;
 }
@@ -694,42 +683,42 @@ COMMAND_HANDLER(handle_esirisc_trace_info_command)
        struct esirisc_trace *trace_info = &esirisc->trace_info;
 
        if (!esirisc->has_trace) {
-               command_print(CMD_CTX, "target does not support trace");
+               command_print(CMD, "target does not support trace");
                return ERROR_FAIL;
        }
 
        if (esirisc_trace_is_fifo(trace_info))
-               command_print(CMD_CTX, "trace FIFO address: 0x%" TARGET_PRIxADDR,
+               command_print(CMD, "trace FIFO address: 0x%" TARGET_PRIxADDR,
                                trace_info->buffer_start);
        else {
-               command_print(CMD_CTX, "trace buffer start: 0x%" TARGET_PRIxADDR,
+               command_print(CMD, "trace buffer start: 0x%" TARGET_PRIxADDR,
                                trace_info->buffer_start);
-               command_print(CMD_CTX, "trace buffer end: 0x%" TARGET_PRIxADDR,
+               command_print(CMD, "trace buffer end: 0x%" TARGET_PRIxADDR,
                                trace_info->buffer_end);
-               command_print(CMD_CTX, "trace buffer will %swrap",
+               command_print(CMD, "trace buffer will %swrap",
                                trace_info->buffer_wrap ? "" : "not ");
        }
 
-       command_print(CMD_CTX, "flow control: %s",
+       command_print(CMD, "flow control: %s",
                        trace_info->flow_control ? "enabled" : "disabled");
 
-       command_print(CMD_CTX, "trace format: %s",
+       command_print(CMD, "trace format: %s",
                        esirisc_trace_format_strings[trace_info->format]);
-       command_print(CMD_CTX, "number of PC bits: %i", trace_info->pc_bits);
+       command_print(CMD, "number of PC bits: %i", trace_info->pc_bits);
 
-       command_print(CMD_CTX, "start trigger: %s",
+       command_print(CMD, "start trigger: %s",
                        esirisc_trace_trigger_strings[trace_info->start_trigger]);
-       command_print(CMD_CTX, "start data: 0x%" PRIx32, trace_info->start_data);
-       command_print(CMD_CTX, "start mask: 0x%" PRIx32, trace_info->start_mask);
+       command_print(CMD, "start data: 0x%" PRIx32, trace_info->start_data);
+       command_print(CMD, "start mask: 0x%" PRIx32, trace_info->start_mask);
 
-       command_print(CMD_CTX, "stop trigger: %s",
+       command_print(CMD, "stop trigger: %s",
                        esirisc_trace_trigger_strings[trace_info->stop_trigger]);
-       command_print(CMD_CTX, "stop data: 0x%" PRIx32, trace_info->stop_data);
-       command_print(CMD_CTX, "stop mask: 0x%" PRIx32, trace_info->stop_mask);
+       command_print(CMD, "stop data: 0x%" PRIx32, trace_info->stop_data);
+       command_print(CMD, "stop mask: 0x%" PRIx32, trace_info->stop_mask);
 
-       command_print(CMD_CTX, "trigger delay: %s",
+       command_print(CMD, "trigger delay: %s",
                        esirisc_trace_delay_strings[trace_info->delay]);
-       command_print(CMD_CTX, "trigger delay cycles: %i", trace_info->delay_cycles);
+       command_print(CMD, "trigger delay cycles: %" PRIu32, trace_info->delay_cycles);
 
        return ERROR_OK;
 }
@@ -741,7 +730,7 @@ COMMAND_HANDLER(handle_esirisc_trace_status_command)
        uint32_t status;
 
        if (!esirisc->has_trace) {
-               command_print(CMD_CTX, "target does not support trace");
+               command_print(CMD, "target does not support trace");
                return ERROR_FAIL;
        }
 
@@ -749,7 +738,7 @@ COMMAND_HANDLER(handle_esirisc_trace_status_command)
        if (retval != ERROR_OK)
                return retval;
 
-       command_print(CMD_CTX, "trace is %s%s%s%s",
+       command_print(CMD, "trace is %s%s%s%s",
                        (status & STATUS_T)  ? "started" : "stopped",
                        (status & STATUS_TD) ? ", disabled"   : "",
                        (status & STATUS_W)  ? ", wrapped"    : "",
@@ -764,13 +753,13 @@ COMMAND_HANDLER(handle_esirisc_trace_start_command)
        struct esirisc_common *esirisc = target_to_esirisc(target);
 
        if (!esirisc->has_trace) {
-               command_print(CMD_CTX, "target does not support trace");
+               command_print(CMD, "target does not support trace");
                return ERROR_FAIL;
        }
 
        int retval = esirisc_trace_start(target);
        if (retval == ERROR_OK)
-               command_print(CMD_CTX, "trace started");
+               command_print(CMD, "trace started");
 
        return retval;
 }
@@ -781,13 +770,13 @@ COMMAND_HANDLER(handle_esirisc_trace_stop_command)
        struct esirisc_common *esirisc = target_to_esirisc(target);
 
        if (!esirisc->has_trace) {
-               command_print(CMD_CTX, "target does not support trace");
+               command_print(CMD, "target does not support trace");
                return ERROR_FAIL;
        }
 
        int retval = esirisc_trace_stop(target);
        if (retval == ERROR_OK)
-               command_print(CMD_CTX, "trace stopped");
+               command_print(CMD, "trace stopped");
 
        return retval;
 }
@@ -801,7 +790,7 @@ COMMAND_HANDLER(handle_esirisc_trace_analyze_command)
        uint32_t size;
 
        if (!esirisc->has_trace) {
-               command_print(CMD_CTX, "target does not support trace");
+               command_print(CMD, "target does not support trace");
                return ERROR_FAIL;
        }
 
@@ -817,16 +806,16 @@ COMMAND_HANDLER(handle_esirisc_trace_analyze_command)
                 * as arguments as a workaround.
                 */
                if (esirisc_trace_is_fifo(trace_info)) {
-                       command_print(CMD_CTX, "analyze from FIFO not supported");
+                       command_print(CMD, "analyze from FIFO not supported");
                        return ERROR_FAIL;
                }
 
-               return esirisc_trace_analyze_buffer(CMD_CTX);
+               return esirisc_trace_analyze_buffer(CMD);
        } else {
                COMMAND_PARSE_ADDRESS(CMD_ARGV[0], address);
                COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], size);
 
-               return esirisc_trace_analyze_memory(CMD_CTX, address, size);
+               return esirisc_trace_analyze_memory(CMD, address, size);
        }
 }
 
@@ -839,7 +828,7 @@ COMMAND_HANDLER(handle_esirisc_trace_dump_command)
        uint32_t size;
 
        if (!esirisc->has_trace) {
-               command_print(CMD_CTX, "target does not support trace");
+               command_print(CMD, "target does not support trace");
                return ERROR_FAIL;
        }
 
@@ -849,16 +838,16 @@ COMMAND_HANDLER(handle_esirisc_trace_dump_command)
        if (CMD_ARGC == 1) {
                /* also see: handle_esirisc_trace_analyze_command() */
                if (esirisc_trace_is_fifo(trace_info)) {
-                       command_print(CMD_CTX, "dump from FIFO not supported");
+                       command_print(CMD, "dump from FIFO not supported");
                        return ERROR_FAIL;
                }
 
-               return esirisc_trace_dump_buffer(CMD_CTX, CMD_ARGV[0]);
+               return esirisc_trace_dump_buffer(CMD, CMD_ARGV[0]);
        } else {
                COMMAND_PARSE_ADDRESS(CMD_ARGV[0], address);
                COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], size);
 
-               return esirisc_trace_dump_memory(CMD_CTX, CMD_ARGV[2], address, size);
+               return esirisc_trace_dump_memory(CMD, CMD_ARGV[2], address, size);
        }
 }
 
@@ -946,7 +935,7 @@ COMMAND_HANDLER(handle_esirisc_trace_format_command)
        COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], pc_bits);
 
        if (pc_bits < 1 || pc_bits > 31) {
-               command_print(CMD_CTX, "invalid pc_bits: %i; must be 1..31", pc_bits);
+               command_print(CMD, "invalid pc_bits: %i; must be 1..31", pc_bits);
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
 

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)