From 2662239b0f36c180999cef4011cf8d10b458205b Mon Sep 17 00:00:00 2001 From: Dong Heng Date: Fri, 12 Oct 2018 10:47:00 +0800 Subject: [PATCH] fix(heap): Fix heap trace check error Closes https://github.com/espressif/ESP8266_RTOS_SDK/issues/335 --- components/heap/include/esp_heap_caps.h | 3 --- .../esp8266}/include/priv/esp_heap_caps_priv.h | 12 ++++++++++-- components/heap/src/esp_heap_trace.c | 15 ++++++++------- 3 files changed, 18 insertions(+), 12 deletions(-) rename components/heap/{ => port/esp8266}/include/priv/esp_heap_caps_priv.h (92%) diff --git a/components/heap/include/esp_heap_caps.h b/components/heap/include/esp_heap_caps.h index 587f510c..e93a17b4 100644 --- a/components/heap/include/esp_heap_caps.h +++ b/components/heap/include/esp_heap_caps.h @@ -35,9 +35,6 @@ extern "C" { #define MALLOC_CAP_8BIT (1 << 2) ///< Memory must allow for 8-bit data accesses #define MALLOC_CAP_DMA (1 << 3) ///< Memory must be able to accessed by DMA -#define MEM_BLK_TAG 0x80000000 ///< Mark the memory block used -#define MEM_BLK_TRACE 0x80000000 ///< Mark the memory block traced - #define MEM_HEAD_SIZE sizeof(mem_blk_t) ///< Size of first type memory block #define MEM2_HEAD_SIZE sizeof(mem2_blk_t) ///< Size of second type memory block diff --git a/components/heap/include/priv/esp_heap_caps_priv.h b/components/heap/port/esp8266/include/priv/esp_heap_caps_priv.h similarity index 92% rename from components/heap/include/priv/esp_heap_caps_priv.h rename to components/heap/port/esp8266/include/priv/esp_heap_caps_priv.h index a286f50f..2c2916d9 100644 --- a/components/heap/include/priv/esp_heap_caps_priv.h +++ b/components/heap/port/esp8266/include/priv/esp_heap_caps_priv.h @@ -20,6 +20,9 @@ extern "C" { #endif +#define MEM_BLK_TAG 0x80000000 ///< Mark the memory block used +#define MEM_BLK_TRACE 0x80000000 ///< Mark the memory block traced + #define _mem_blk_get_ptr(_mem_blk, _offset, _mask) \ ((mem_blk_t *)((((uint32_t *)(_mem_blk))[_offset]) & (~_mask))) @@ -49,7 +52,7 @@ static inline void mem_blk_set_traced(mem2_blk_t *mem_blk, const char *file, siz *val |= MEM_BLK_TRACE; mem_blk->file = file; - mem_blk->line = line; + mem_blk->line = line | MEM_BLK_TRACE; } static inline void mem_blk_set_untraced(mem2_blk_t *mem_blk) @@ -123,7 +126,7 @@ static inline bool ptr_is_traced(void *ptr) { uint32_t *p = (uint32_t *)ptr - 1; - return p[0] & 0xf0000000 ? false : true; + return p[0] & MEM_BLK_TRACE ? true : false; } static inline mem_blk_t *ptr2blk(void *ptr, bool trace) @@ -149,6 +152,11 @@ static inline size_t ptr_size(void *ptr) return size; } +static inline size_t mem2_blk_line(mem2_blk_t *mem2_blk) +{ + return mem2_blk->line & ~MEM_BLK_TRACE; +} + #ifdef __cplusplus } #endif diff --git a/components/heap/src/esp_heap_trace.c b/components/heap/src/esp_heap_trace.c index e17e8ed4..54de9289 100644 --- a/components/heap/src/esp_heap_trace.c +++ b/components/heap/src/esp_heap_trace.c @@ -108,18 +108,19 @@ void heap_trace_dump(void) _heap_caps_lock(num); - ESP_EARLY_LOGI(TAG, "\r\n\r\n"); - ESP_EARLY_LOGD(TAG, "start %p end %p", mem_start, mem_end); - ESP_EARLY_LOGD(TAG, "free blk %p", g_heap_region[num].free_blk); - ESP_EARLY_LOGD(TAG, "size %d mini size %d", g_heap_region[num].free_bytes, g_heap_region[num].min_free_bytes); + ESP_LOGI(TAG, "\r\n\r\n"); + ESP_LOGD(TAG, "start %p end %p", mem_start, mem_end); + ESP_LOGD(TAG, "free blk %p", g_heap_region[num].free_blk); + ESP_LOGD(TAG, "size %d mini size %d", g_heap_region[num].free_bytes, g_heap_region[num].min_free_bytes); p = mem_start; while (p != mem_end) { if (mem_blk_is_used(p) && mem_blk_is_traced(p)) { mem2_blk_t *mem2_blk = (mem2_blk_t *)p; + size_t line = mem2_blk_line(mem2_blk); - if (!mem2_blk->line) { - ESP_EARLY_LOGI(TAG, HEAP_INFO " caller func %p", HEAP_INFO_PARAM(p), mem2_blk->file); + if (!line) { + ESP_LOGI(TAG, HEAP_INFO " caller func %p", HEAP_INFO_PARAM(p), mem2_blk->file); } else { const char *file = rindex(mem2_blk->file, '/'); if (file) @@ -127,7 +128,7 @@ void heap_trace_dump(void) else file = mem2_blk->file; - ESP_EARLY_LOGI(TAG, HEAP_INFO " caller file %s line %d", HEAP_INFO_PARAM(p), file, mem2_blk->line); + ESP_LOGI(TAG, HEAP_INFO " caller file %s line %d", HEAP_INFO_PARAM(p), file, line); } } #ifdef CONFIG_TRACE_ALL