fix(app_trace): fix gcov for gcc 13.1.0

This commit is contained in:
Alexey Lapshin 2023-07-26 14:31:43 +04:00
parent 8bbcc224dd
commit 0172df94ac
4 changed files with 66 additions and 5 deletions

View File

@ -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;

View File

@ -5,3 +5,4 @@ fread gcov_rtio_fread
fseek gcov_rtio_fseek
ftell gcov_rtio_ftell
setbuf gcov_rtio_setbuf
feof gcov_rtio_feof

View File

@ -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

View File

@ -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.