Просмотр исходного кода

Merge branch 'bugfix/coredump_warnings' into 'master'

coredump: minor fixes of warnings

See merge request espressif/esp-idf!18306
Anton Maklakov 3 лет назад
Родитель
Сommit
b965264e68

+ 8 - 14
components/espcoredump/src/port/riscv/core_dump_port.c

@@ -1,16 +1,8 @@
-// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+/*
+ * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
 
 /**
  * @file
@@ -40,6 +32,7 @@ const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump_port"
 #if CONFIG_ESP_COREDUMP_ENABLE
 
 #define min(a,b) ((a) < (b) ? (a) : (b))
+#define max(a,b) ((a) < (b) ? (b) : (a))
 
 /**
  * Union representing the registers of the CPU as they will be written
@@ -259,8 +252,9 @@ bool esp_core_dump_check_stack(core_dump_task_header_t *task)
 uint32_t esp_core_dump_get_stack(core_dump_task_header_t *task,
                                  uint32_t* stk_vaddr, uint32_t* stk_paddr)
 {
-    const uint32_t stack_len = abs(task->stack_start - task->stack_end);
     const uint32_t stack_addr = min(task->stack_start, task->stack_end);
+    const uint32_t stack_addr2 = max(task->stack_start, task->stack_end);
+    const uint32_t stack_len = stack_addr2 - stack_addr;
 
     ESP_COREDUMP_DEBUG_ASSERT(stk_paddr != NULL && stk_vaddr != NULL);
 

+ 13 - 1
components/espcoredump/src/port/xtensa/core_dump_port.c

@@ -24,6 +24,7 @@
 const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump_port";
 
 #define min(a,b) ((a) < (b) ? (a) : (b))
+#define max(a,b) ((a) < (b) ? (b) : (a))
 
 #define COREDUMP_EM_XTENSA                  0x5E
 #define COREDUMP_INVALID_CAUSE_VALUE        0xFFFF
@@ -156,7 +157,12 @@ static void *esp_core_dump_get_fake_stack(uint32_t *stk_len)
 
 static core_dump_reg_pair_t *esp_core_dump_get_epc_regs(core_dump_reg_pair_t* src)
 {
+#pragma GCC diagnostic push
+#if     __GNUC__ >= 9
+#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
+#endif
     uint32_t* reg_ptr = (uint32_t*)src;
+#pragma GCC diagnostic pop
     // get InterruptException program counter registers
     COREDUMP_GET_EPC(EPC_1, reg_ptr);
     COREDUMP_GET_EPC(EPC_2, reg_ptr);
@@ -170,7 +176,12 @@ static core_dump_reg_pair_t *esp_core_dump_get_epc_regs(core_dump_reg_pair_t* sr
 
 static core_dump_reg_pair_t *esp_core_dump_get_eps_regs(core_dump_reg_pair_t* src)
 {
+#pragma GCC diagnostic push
+#if     __GNUC__ >= 9
+#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
+#endif
     uint32_t* reg_ptr = (uint32_t*)src;
+#pragma GCC diagnostic pop
     // get InterruptException processor state registers
     COREDUMP_GET_EPS(EPS_2, reg_ptr);
     COREDUMP_GET_EPS(EPS_3, reg_ptr);
@@ -339,8 +350,9 @@ bool esp_core_dump_mem_seg_is_sane(uint32_t addr, uint32_t sz)
 uint32_t esp_core_dump_get_stack(core_dump_task_header_t *task,
                                  uint32_t* stk_vaddr, uint32_t* stk_paddr)
 {
-    const uint32_t stack_len = abs(task->stack_start - task->stack_end);
     const uint32_t stack_addr = min(task->stack_start, task->stack_end);
+    const uint32_t stack_addr2 = max(task->stack_start, task->stack_end);
+    const uint32_t stack_len = stack_addr2 - stack_addr;
 
     ESP_COREDUMP_DEBUG_ASSERT(stk_paddr != NULL && stk_vaddr != NULL);
 

+ 0 - 1
tools/ci/check_copyright_ignore.txt

@@ -727,7 +727,6 @@ components/espcoredump/include_core_dump/port/xtensa/esp_core_dump_port_impl.h
 components/espcoredump/src/core_dump_binary.c
 components/espcoredump/src/core_dump_flash.c
 components/espcoredump/src/core_dump_uart.c
-components/espcoredump/src/port/riscv/core_dump_port.c
 components/espcoredump/test_apps/main/test_core_dump.c
 components/fatfs/diskio/diskio.c
 components/fatfs/diskio/diskio_impl.h