1
6
7
12
13
14
15
16
17
18
19
20
21
22
28
29
32
33
34
35
40
41
42
43
44
45
46
47
48
49
50
51
66
67
68
69
79
80
81
82
83
84
88
89
90
/* ... */
#include <string.h>
#include <sys/param.h>
#include "esp_system.h"
#include "soc/soc_memory_layout.h"
#include "esp_private/cache_utils.h"5 includes
#define ASSERT_STR "assert failed: "
#define CACHE_DISABLED_STR "<cached disabled>"
#if __XTENSA__
#define INST_LEN 3
#elif __riscv
#define INST_LEN 4
#endif
static inline void ra_to_str(char *addr)
{
addr[0] = '0';
addr[1] = 'x';
itoa((uint32_t)(__builtin_return_address(0) - INST_LEN), addr + 2, 16);
}{ ... }
/* ... */
void __attribute__((noreturn)) __assert_func(const char *file, int line, const char *func, const char *expr)
{
#if CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT
char buff[sizeof(ASSERT_STR) + 11 + 1] = ASSERT_STR;
ra_to_str(&buff[sizeof(ASSERT_STR) - 1]);
esp_system_abort(buff);/* ... */
#else
char addr[11] = { 0 };
char buff[200];
char lbuf[5];
uint32_t rem_len = sizeof(buff) - 1;
uint32_t off = 0;
itoa(line, lbuf, 10);
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
if (!spi_flash_cache_enabled())
#endif
{
if (esp_ptr_in_drom(file)) {
file = CACHE_DISABLED_STR;
}{...}
if (esp_ptr_in_drom(func)) {
ra_to_str(addr);
func = addr;
}{...}
if (esp_ptr_in_drom(expr)) {
expr = CACHE_DISABLED_STR;
}{...}
}{...}
const char *str[] = {ASSERT_STR, func ? func : "\b", " ", file, ":", lbuf, " (", expr, ")"};
for (int i = 0; i < sizeof(str) / sizeof(str[0]); i++) {
uint32_t len = strlen(str[i]);
uint32_t cpy_len = MIN(len, rem_len);
memcpy(buff + off, str[i], cpy_len);
rem_len -= cpy_len;
off += cpy_len;
if (rem_len == 0) {
break;
}{...}
}{...}
buff[off] = '\0';
esp_system_abort(buff);/* ... */
#endif
}{ ... }
void __attribute__((noreturn)) __assert(const char *file, int line, const char *failedexpr)
{
__assert_func(file, line, NULL, failedexpr);
}{ ... }
void newlib_include_assert_impl(void)
{
}{ ... }