os_malloc causes Fatal exception 29(StoreProhibitedCause)
Posted: Thu Apr 06, 2017 5:58 pm
Hi all!
I'm trying to compile using C++ in ESP8266. After lots of searchs, I've managed to install xtensa c++ compiler from jcmvbkbc (awesome job, certainly), among other things like:
After some code changes and many experiments, I found out that the creation of an object causes the exception. In order to get more information, I used GDB Stub from Espressif Github. Then, I tried to create an object just after the gdbstub_init() and I checked every line of code using the step function within GDB, and I got this output:
So, it seems that pvPortMalloc causes the exception.
Any ideas?
Thanks in advance.
PD: I attach the makefile, the linker script and some source code files.
I'm trying to compile using C++ in ESP8266. After lots of searchs, I've managed to install xtensa c++ compiler from jcmvbkbc (awesome job, certainly), among other things like:
- Writing a makefile in order to compile C and C++ files
Editing the linker script in order to put c++ code into the ROM memory (idea from Arduino linker script)
I understood that some C functions in SDK are not defined with a complete prototype (as os_malloc) and I know that I have to declare their prototypes with the extern "C" keyword.
I can compile C code and use it with no problem.
I overloaded new and delete operators in order to use classes and objects.
After some code changes and many experiments, I found out that the creation of an object causes the exception. In order to get more information, I used GDB Stub from Espressif Github. Then, I tried to create an object just after the gdbstub_init() and I checked every line of code using the step function within GDB, and I got this output:
Code: Select all
0x4010730b in gdbstub_do_break_breakpoint_addr ()
(gdb) step
Single stepping until exit from function gdbstub_do_break_breakpoint_addr,
which has no line number information.
sgdbstub_init () at gdb/gdbstub.c:785
785 }
(gdb) step
user_init () at user_main.cpp:156
156 initProc();
(gdb) step
Warning:
Cannot insert breakpoint 0.
Error accessing memory address 0x4023e0b3: Error de entrada/salida.
initProc () at user_main.cpp:22
22 void ICACHE_FLASH_ATTR initProc(){
(gdb) step
23 proc = new MQTTProcessor();
(gdb) step
22 void ICACHE_FLASH_ATTR initProc(){
(gdb) step
23 proc = new MQTTProcessor();
(gdb) step
Warning:
Cannot insert breakpoint 0.
Error accessing memory address 0x4023e282: Error de entrada/salida.
operator new (size=32) at cplusplus.cpp:13
13 return os_malloc(size);
(gdb) step
12 size = ((size + 3) & ~((size_t)0x3));
(gdb) step
13 return os_malloc(size);
(gdb) step
11 void* ICACHE_FLASH_ATTR operator new(size_t size) {
(gdb) step
13 return os_malloc(size);
(gdb) step
11 void* ICACHE_FLASH_ATTR operator new(size_t size) {
(gdb) step
13 return os_malloc(size);
(gdb) step
Warning:
Cannot insert breakpoint 0.
Error accessing memory address 0x4023e298: Error de entrada/salida.
0x40100cd4 in pvPortMalloc ()
(gdb) step
Single stepping until exit from function pvPortMalloc,
which has no line number information.
Program received signal SIGILL, Illegal instruction.
0x40100ced in pvPortMalloc ()
(gdb) step
Single stepping until exit from function pvPortMalloc,
which has no line number information.
Can't send signals to this remote system. SIGILL not sent.
0x4010728d in gdbstub_icount_ena_single_step ()
(gdb) step
Single stepping until exit from function gdbstub_icount_ena_single_step,
which has no line number information.
gdbHandleCommand (cmd=0x3ffee9e1 <cmd> "m3ffee9e9,8", len=<optimized out>)
at gdb/gdbstub.c:395
395 return ST_CONT;
(gdb) step
gdbReadCommand () at gdb/gdbstub.c:516
516 }
(gdb) step
gdb_exception_handler (frame=0x3ffff970) at gdb/gdbstub.c:630
630 ets_wdt_enable();
(gdb) step
Program received signal SIGINT, Interrupt.
0x4000df68 in ?? ()
(gdb) step
Cannot find bounds of current function
(gdb)
So, it seems that pvPortMalloc causes the exception.
Any ideas?
Thanks in advance.
PD: I attach the makefile, the linker script and some source code files.