Skip to content

Commit 09015f5

Browse files
Move ASSERT() macro file text to PMEM
Every assert() includes a __FILE__ constant string to RODATA which can be quite large as it includes the complete path as well as the filename. Move that string into PMEM, and update the postmortem to work with either PMEM or RAM strings for dumping abort/assert/exception information.
1 parent a01638f commit 09015f5

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

cores/esp8266/core_esp8266_postmortem.c

+21-7
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727
#include "user_interface.h"
2828
#include "esp8266_peri.h"
2929
#include "cont.h"
30+
#include "pgmspace.h"
3031

3132
extern void __real_system_restart_local();
3233
extern void gdb_do_break();
3334

3435
extern cont_t g_cont;
3536

37+
// These will be pointers to PROGMEM const strings
3638
static const char* s_panic_file = 0;
3739
static int s_panic_line = 0;
3840
static const char* s_panic_func = 0;
@@ -53,6 +55,14 @@ extern void __custom_crash_callback( struct rst_info * rst_info, uint32_t stack,
5355

5456
extern void custom_crash_callback( struct rst_info * rst_info, uint32_t stack, uint32_t stack_end ) __attribute__ ((weak, alias("__custom_crash_callback")));
5557

58+
static void ets_puts_P(const char *romString) {
59+
char c = pgm_read_byte(romString++);
60+
while (c) {
61+
ets_putc(c);
62+
c = pgm_read_byte(romString++);
63+
}
64+
}
65+
5666
void __wrap_system_restart_local() {
5767
register uint32_t sp asm("a1");
5868

@@ -68,17 +78,21 @@ void __wrap_system_restart_local() {
6878
ets_install_putc1(&uart_write_char_d);
6979

7080
if (s_panic_line) {
71-
ets_printf("\nPanic %s:%d %s\n", s_panic_file, s_panic_line, s_panic_func);
81+
ets_puts_P(PSTR("\nPanic "));
82+
ets_puts_P(s_panic_file);
83+
ets_printf(":%d ", s_panic_line);
84+
ets_puts_P(s_panic_func);
85+
ets_puts_P(PSTR("\n"));
7286
}
7387
else if (s_abort_called) {
74-
ets_printf("Abort called\n");
88+
ets_puts_P(PSTR("Abort called\n"));
7589
}
7690
else if (rst_info.reason == REASON_EXCEPTION_RST) {
7791
ets_printf("\nException (%d):\nepc1=0x%08x epc2=0x%08x epc3=0x%08x excvaddr=0x%08x depc=0x%08x\n",
7892
rst_info.exccause, rst_info.epc1, rst_info.epc2, rst_info.epc3, rst_info.excvaddr, rst_info.depc);
7993
}
8094
else if (rst_info.reason == REASON_SOFT_WDT_RST) {
81-
ets_printf("\nSoft WDT reset\n");
95+
ets_puts_P(PSTR("\nSoft WDT reset\n"));
8296
}
8397

8498
uint32_t cont_stack_start = (uint32_t) &(g_cont.stack);
@@ -100,11 +114,11 @@ void __wrap_system_restart_local() {
100114
}
101115

102116
if (sp > cont_stack_start && sp < cont_stack_end) {
103-
ets_printf("\nctx: cont \n");
117+
ets_puts_P(PSTR("\nctx: cont \n"));
104118
stack_end = cont_stack_end;
105119
}
106120
else {
107-
ets_printf("\nctx: sys \n");
121+
ets_puts_P(("\nctx: sys \n"));
108122
stack_end = 0x3fffffb0;
109123
// it's actually 0x3ffffff0, but the stuff below ets_run
110124
// is likely not really relevant to the crash
@@ -123,7 +137,7 @@ void __wrap_system_restart_local() {
123137

124138

125139
static void print_stack(uint32_t start, uint32_t end) {
126-
ets_printf("\n>>>stack>>>\n");
140+
ets_puts_P(PSTR("\n>>>stack>>>\n"));
127141
for (uint32_t pos = start; pos < end; pos += 0x10) {
128142
uint32_t* values = (uint32_t*)(pos);
129143

@@ -133,7 +147,7 @@ static void print_stack(uint32_t start, uint32_t end) {
133147
ets_printf("%08x: %08x %08x %08x %08x %c\n",
134148
pos, values[0], values[1], values[2], values[3], (looksLikeStackFrame)?'<':' ');
135149
}
136-
ets_printf("<<<stack<<<\n");
150+
ets_puts_P(PSTR("<<<stack<<<\n"));
137151
}
138152

139153
/*

tools/sdk/libc/xtensa-lx106-elf/include/assert.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ extern "C" {
77
#endif
88

99
#include "_ansi.h"
10+
#include <pgmspace.h>
1011

1112
#undef assert
1213

1314
#ifdef NDEBUG /* required by ANSI standard */
1415
# define assert(__e) ((void)0)
1516
#else
16-
# define assert(__e) ((__e) ? (void)0 : __assert_func (__FILE__, __LINE__, \
17+
# define assert(__e) ((__e) ? (void)0 : __assert_func (PSTR(__FILE__), __LINE__, \
1718
__ASSERT_FUNC, #__e))
1819

1920
# ifndef __ASSERT_FUNC

0 commit comments

Comments
 (0)