From 59cab6dd40b856d106ea9d1e7171789dc31939c1 Mon Sep 17 00:00:00 2001 From: Erhan Kurubas Date: Sat, 17 Feb 2024 23:43:23 +0100 Subject: [PATCH] fix(gcov): avoid multiple tick hook registration --- components/app_trace/gcov/gcov_rtio.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/components/app_trace/gcov/gcov_rtio.c b/components/app_trace/gcov/gcov_rtio.c index c18d678cb9..fd42dfad8d 100644 --- a/components/app_trace/gcov/gcov_rtio.c +++ b/components/app_trace/gcov/gcov_rtio.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -106,12 +106,16 @@ static int esp_dbg_stub_gcov_entry(void) void gcov_rtio_init(void) { - uint32_t capabilities = 0; + uint32_t stub_entry = 0; ESP_EARLY_LOGV(TAG, "%s", __FUNCTION__); - esp_dbg_stub_entry_set(ESP_DBG_STUB_ENTRY_GCOV, (uint32_t)&esp_dbg_stub_gcov_entry); - if (esp_dbg_stub_entry_get(ESP_DBG_STUB_ENTRY_CAPABILITIES, &capabilities) == ESP_OK) { - esp_dbg_stub_entry_set(ESP_DBG_STUB_ENTRY_CAPABILITIES, capabilities | ESP_DBG_STUB_CAP_GCOV_TASK); + assert(esp_dbg_stub_entry_get(ESP_DBG_STUB_ENTRY_GCOV, &stub_entry) == ESP_OK); + if (stub_entry != 0) { + /* "__gcov_init()" can be called several times. We must avoid multiple tick hook registration */ + return; } + esp_dbg_stub_entry_set(ESP_DBG_STUB_ENTRY_GCOV, (uint32_t)&esp_dbg_stub_gcov_entry); + assert(esp_dbg_stub_entry_get(ESP_DBG_STUB_ENTRY_CAPABILITIES, &stub_entry) == ESP_OK); + esp_dbg_stub_entry_set(ESP_DBG_STUB_ENTRY_CAPABILITIES, stub_entry | ESP_DBG_STUB_CAP_GCOV_TASK); esp_register_freertos_tick_hook(gcov_create_task_tick_hook); }