Skip to content

Commit a662e81

Browse files
earlephilhowerigrr
authored andcommitted
Move ASSERT() macro file text to PMEM (#3477)
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 f5b6e16 commit a662e81

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;
@@ -55,6 +57,14 @@ extern void __custom_crash_callback( struct rst_info * rst_info, uint32_t stack,
5557

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

60+
static void ets_puts_P(const char *romString) {
61+
char c = pgm_read_byte(romString++);
62+
while (c) {
63+
ets_putc(c);
64+
c = pgm_read_byte(romString++);
65+
}
66+
}
67+
5868
void __wrap_system_restart_local() {
5969
if (crash_for_gdb) *((int*)0) = 0;
6070
register uint32_t sp asm("a1");
@@ -71,17 +81,21 @@ void __wrap_system_restart_local() {
7181
ets_install_putc1(&uart_write_char_d);
7282

7383
if (s_panic_line) {
74-
ets_printf("\nPanic %s:%d %s\n", s_panic_file, s_panic_line, s_panic_func);
84+
ets_puts_P(PSTR("\nPanic "));
85+
ets_puts_P(s_panic_file);
86+
ets_printf(":%d ", s_panic_line);
87+
ets_puts_P(s_panic_func);
88+
ets_puts_P(PSTR("\n"));
7589
}
7690
else if (s_abort_called) {
77-
ets_printf("Abort called\n");
91+
ets_puts_P(PSTR("Abort called\n"));
7892
}
7993
else if (rst_info.reason == REASON_EXCEPTION_RST) {
8094
ets_printf("\nException (%d):\nepc1=0x%08x epc2=0x%08x epc3=0x%08x excvaddr=0x%08x depc=0x%08x\n",
8195
rst_info.exccause, rst_info.epc1, rst_info.epc2, rst_info.epc3, rst_info.excvaddr, rst_info.depc);
8296
}
8397
else if (rst_info.reason == REASON_SOFT_WDT_RST) {
84-
ets_printf("\nSoft WDT reset\n");
98+
ets_puts_P(PSTR("\nSoft WDT reset\n"));
8599
}
86100

87101
uint32_t cont_stack_start = (uint32_t) &(g_cont.stack);
@@ -103,11 +117,11 @@ void __wrap_system_restart_local() {
103117
}
104118

105119
if (sp > cont_stack_start && sp < cont_stack_end) {
106-
ets_printf("\nctx: cont \n");
120+
ets_puts_P(PSTR("\nctx: cont \n"));
107121
stack_end = cont_stack_end;
108122
}
109123
else {
110-
ets_printf("\nctx: sys \n");
124+
ets_puts_P(("\nctx: sys \n"));
111125
stack_end = 0x3fffffb0;
112126
// it's actually 0x3ffffff0, but the stuff below ets_run
113127
// is likely not really relevant to the crash
@@ -126,7 +140,7 @@ void __wrap_system_restart_local() {
126140

127141

128142
static void print_stack(uint32_t start, uint32_t end) {
129-
ets_printf("\n>>>stack>>>\n");
143+
ets_puts_P(PSTR("\n>>>stack>>>\n"));
130144
for (uint32_t pos = start; pos < end; pos += 0x10) {
131145
uint32_t* values = (uint32_t*)(pos);
132146

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

142156
/*

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)