Tips on using gdbstub with Arduino IDE
Posted: Thu Jan 28, 2016 9:31 pm
I thought I would share this with you, as I have spent two days trying to get gdb and gdbstub working using Arduino IDE (or Eclipse IDE with Arduino libraries; same thing in this case)...
I saw this post :http://hackaday.com/2015/12/12/squash-your-esp-8266-bugs-with-esp-gdbstub/ and thought I would try using the approach with my Eclipse IDE with Arduino libs setup...
I modified core_esp8266_main.c adding a call to gdbstub_init() after the call to uart_div_modify(). Changed the compiler flags etc, etc. Compiled fine.
Using gdb on /dev/ttyUSB0, the initial startup looked correct and I could view the breakpoint, see where gdbstub_init had been called. However once I did a 'continue' gdb seemed to hang and it would report 'putpkt .... Junk' received errors if I had set a watch or breakpoint which got executed. Gdb would never return to a prompt and I had to crtl-C to exit.
This is a case of me not knowing enough about the Arduino IDE library config and integration aspects of the esp8266, as well as how gdb and the stub operate, but eventually I found out what the problem was.
Subsequent to the gdbstub_init() call in core_esp8266_main.c, a call is then made to init() which in turn calls initPins() in core_esp8266_wiring.c. initPins() disables the UART interrupts, thus disabling gdbstub's hook into the uart's interrupts, this is what causes the problem since the gdbstub never gets triggered on a uart interrupt and gdb just hangs waiting.
My temporary solution for now, is to remove the disabling in initPins() when I am debugging. I could instead just ensure that the interrupts are re-enabled after initPins() is called, but I'm not entirely sure how to do that and it's bedtime now
So, I just thought I would document this in case anyone else has problems or wants to use gdb with Arduino core software.
I saw this post :http://hackaday.com/2015/12/12/squash-your-esp-8266-bugs-with-esp-gdbstub/ and thought I would try using the approach with my Eclipse IDE with Arduino libs setup...
I modified core_esp8266_main.c adding a call to gdbstub_init() after the call to uart_div_modify(). Changed the compiler flags etc, etc. Compiled fine.
Using gdb on /dev/ttyUSB0, the initial startup looked correct and I could view the breakpoint, see where gdbstub_init had been called. However once I did a 'continue' gdb seemed to hang and it would report 'putpkt .... Junk' received errors if I had set a watch or breakpoint which got executed. Gdb would never return to a prompt and I had to crtl-C to exit.
This is a case of me not knowing enough about the Arduino IDE library config and integration aspects of the esp8266, as well as how gdb and the stub operate, but eventually I found out what the problem was.
Subsequent to the gdbstub_init() call in core_esp8266_main.c, a call is then made to init() which in turn calls initPins() in core_esp8266_wiring.c. initPins() disables the UART interrupts, thus disabling gdbstub's hook into the uart's interrupts, this is what causes the problem since the gdbstub never gets triggered on a uart interrupt and gdb just hangs waiting.
My temporary solution for now, is to remove the disabling in initPins() when I am debugging. I could instead just ensure that the interrupts are re-enabled after initPins() is called, but I'm not entirely sure how to do that and it's bedtime now
So, I just thought I would document this in case anyone else has problems or wants to use gdb with Arduino core software.