From 0172df94acf4ea13626808a2f3da7be0d254f4db Mon Sep 17 00:00:00 2001 From: Alexey Lapshin Date: Wed, 26 Jul 2023 14:31:43 +0400 Subject: [PATCH] fix(app_trace): fix gcov for gcc 13.1.0 --- components/app_trace/gcov/gcov_rtio.c | 8 +++- components/app_trace/gcov/io_sym.map | 1 + components/app_trace/host_file_io.c | 49 ++++++++++++++++++-- components/app_trace/include/esp_app_trace.h | 13 +++++- 4 files changed, 66 insertions(+), 5 deletions(-) diff --git a/components/app_trace/gcov/gcov_rtio.c b/components/app_trace/gcov/gcov_rtio.c index 8dd9e0d0cb..f61c45bd16 100644 --- a/components/app_trace/gcov/gcov_rtio.c +++ b/components/app_trace/gcov/gcov_rtio.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -173,6 +173,12 @@ long gcov_rtio_ftell(void *stream) return ret; } +int gcov_rtio_feof(void *stream) +{ + ESP_EARLY_LOGV(TAG, "%s", __FUNCTION__); + return 0; // esp_apptrace_feof(ESP_APPTRACE_DEST_TRAX, stream); // TODO IDF-7920 +} + void gcov_rtio_setbuf(void *arg1 __attribute__ ((unused)), void *arg2 __attribute__ ((unused))) { return; diff --git a/components/app_trace/gcov/io_sym.map b/components/app_trace/gcov/io_sym.map index 727766648b..7dd3aa0ac3 100644 --- a/components/app_trace/gcov/io_sym.map +++ b/components/app_trace/gcov/io_sym.map @@ -5,3 +5,4 @@ fread gcov_rtio_fread fseek gcov_rtio_fseek ftell gcov_rtio_ftell setbuf gcov_rtio_setbuf +feof gcov_rtio_feof diff --git a/components/app_trace/host_file_io.c b/components/app_trace/host_file_io.c index a36ed8969f..5ccc062edd 100644 --- a/components/app_trace/host_file_io.c +++ b/components/app_trace/host_file_io.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -29,6 +29,7 @@ const static char *TAG = "esp_host_file_io"; #define ESP_APPTRACE_FILE_CMD_FSEEK 0x4 #define ESP_APPTRACE_FILE_CMD_FTELL 0x5 #define ESP_APPTRACE_FILE_CMD_STOP 0x6 // indicates that there is no files to transfer +#define ESP_APPTRACE_FILE_CMD_FEOF 0x7 /** File operation header */ typedef struct { @@ -68,6 +69,11 @@ typedef struct { void * file; } esp_apptrace_fseek_args_t; +/** Helper structure for feof */ +typedef struct { + void *file; +} esp_apptrace_feof_args_t; + /** Helper structure for ftell */ typedef struct { void *file; @@ -228,8 +234,11 @@ size_t esp_apptrace_fwrite(esp_apptrace_dest_t dest, const void *ptr, size_t siz ESP_EARLY_LOGE(TAG, "Failed to read response (%d)!", ret); return 0; } - - return resp/size; // return the number of items written + /* OpenOCD writes it like that: + * fwrite(buf, size, 1, file); + * So, if 1 was returned that means fwrite succeed + */ + return resp == 1 ? nmemb : 0; } static void esp_apptrace_fread_args_prepare(uint8_t *buf, void *priv) @@ -275,6 +284,10 @@ size_t esp_apptrace_fread(esp_apptrace_dest_t dest, void *ptr, size_t size, size ESP_EARLY_LOGE(TAG, "Failed to read file data (%d)!", ret); return 0; } + /* OpenOCD reads it like that: + * fread(buf, 1 ,size, file); + * So, total read bytes count returns + */ return resp/size; // return the number of items read } @@ -354,4 +367,34 @@ int esp_apptrace_fstop(esp_apptrace_dest_t dest) return ret; } +static void esp_apptrace_feof_args_prepare(uint8_t *buf, void *priv) +{ + esp_apptrace_feof_args_t *args = priv; + + memcpy(buf, &args->file, sizeof(args->file)); +} + +int esp_apptrace_feof(esp_apptrace_dest_t dest, void *stream) +{ + esp_apptrace_feof_args_t cmd_args; + + cmd_args.file = stream; + esp_err_t ret = esp_apptrace_file_cmd_send(dest, ESP_APPTRACE_FILE_CMD_FEOF, esp_apptrace_feof_args_prepare, + &cmd_args, sizeof(cmd_args)); + if (ret != ESP_OK) { + ESP_EARLY_LOGE(TAG, "Failed to send file cmd (%d)!", ret); + return EOF; + } + + // now read the answer + int resp; + ret = esp_apptrace_file_rsp_recv(dest, (uint8_t *)&resp, sizeof(resp)); + if (ret != ESP_OK) { + ESP_EARLY_LOGE(TAG, "Failed to read response (%d)!", ret); + return EOF; + } + + return resp; +} + #endif diff --git a/components/app_trace/include/esp_app_trace.h b/components/app_trace/include/esp_app_trace.h index 18a533f937..d581b0eb89 100644 --- a/components/app_trace/include/esp_app_trace.h +++ b/components/app_trace/include/esp_app_trace.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -255,6 +255,17 @@ int esp_apptrace_ftell(esp_apptrace_dest_t dest, void *stream); */ int esp_apptrace_fstop(esp_apptrace_dest_t dest); +/** + * @brief Test end-of-file indicator on a stream. + * This function has the same semantic as 'feof' except for the first argument. + * + * @param dest Indicates HW interface to use. + * @param stream File handle returned by esp_apptrace_fopen. + * + * @return Non-Zero if end-of-file indicator is set for stream. See feof for details. + */ +int esp_apptrace_feof(esp_apptrace_dest_t dest, void *stream); + /** * @brief Triggers gcov info dump. * This function waits for the host to connect to target before dumping data.