-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Capture stack trace and reset after startup? #1152
Comments
for the reset reason: ESP.getResetInfo();
//or
ESP.getResetInfoPtr(); Lines 128 to 129 in 342c4ae
Lines 301 to 312 in f1a8287
|
You can also register a crash callback (see this commit) Edit: when defining |
Thanks guys, What does "careful" mean ? What happens if the crash handler crashes ? |
Pretty much, yes. Don't use dynamic memory allocation, don't use blocking functions (delay, Serial, network), don't spend too much time inside the interrupt handler (because hardware watchdog timer is still ticking). |
Are there any plans to incorporate this saving to flash of the stack as a ready-made function or at least an example or some more pointers on how to implement such a thing? It seems a bit over my head since I didn't dabble with memory before... Background: I would like to be able to send a stack dump over the net after a reset, since I have an ESP that basically gets a hardware WDT reset every 10-20 hours and which isn't easily accessible. |
I got it working. Below is the code that I used. I'm not the best coder, so any comments are welcome. At least it is working, now still have to make it better. What it is doing:
Then in setup():
This is the loadStack function:
|
For the interested, with the above code I got results. See below for a SOFT_WDT, EXCEPTION and WDT result. When these are decode with the ESP Exception Decoder they give the expected results. I implemented 3 test functions that run on the ESP Webserver and cause these 3 cases. Fatal+exception%3A4+flag%3A3+%28SOFT%5FWDT%29+epc1%3A0x4020e9c9+epc2%3A0x00000000+epc3%3A0x00000000+excvaddr%3A0x00000000+depc%3A0x00000000ctx%253A%2Bsys%2Bsp%253A%2B3fff3d80%2Bend%253A%2B3fff3ec0%2Boffset%253A%2B01b0%250A%2B3fff3d80%253A%2B%2B3ffe8c70%2B00000007%2B3fff164c%2B4020e9d8%2B%2B3fff3d90%253A%2B%2B00000002%2B00000001%2B3ffe8ca0%2B4020709a%2B%2B3fff3da0%253A%2B%2B00000000%2B00000000%2B00000000%2B4010068c%2B%2B3fff3db0%253A%2B%2B00000000%2B00000000%2B3fff622c%2B4020cb9e%2B%2B3fff3dc0%253A%2B%2B3fff622c%2B3fff0db0%2B3fff622c%2B4020cbda%2B%2B3fff3dd0%253A%2B%2B00000000%2B00000000%2B00000000%2B4020f3f0%2B%2B3fff3de0%253A%2B%2B3fff622c%2B3fff0db0%2B3fff0d70%2B4020cc69%2B%2B3fff3df0%253A%2B%2B3fff648c%2B0000000f%2B00000007%2B40209728%2B%2B3fff3e00%253A%2B%2B00000000%2B00000004%2B00000004%2B00000001%2B%2B3fff3e10%253A%2B%2B00000002%2B00000004%2B0000000e%2B3fff2ea0%2B%2B3fff3e20%253A%2B%2B00000000%2B00000000%2B3fff0d70%2B3fff2e8c%2B%2B3fff3e30%253A%2B%2B00000001%2B3fff0d94%2B3fff0d70%2B4020ce77%2B%2B3fff3e40%253A%2B%2B3ffe9168%2B00000000%2B000003e8%2B4020a964%2B%2B3fff3e50%253A%2B%2B00000000%2B3fff6534%2B000003e8%2B4020a9e2%2B%2B3fff3e60%253A%2B%2B3fffdad0%2B00000000%2B3fff2e85%2B4020874f%2B%2B3fff3e70%253A%2B%2B00000000%2B00000000%2B00000000%2B00000000%2B%2B3fff3e80%253A%2B%2B00000000%2B00000000%2B402073e4%2B40208484%2B%2B3fff3e90%253A%2B%2B00000000%2B00000000%2B00000001%2B3fff2e8c%2B%2B3fff3ea0%253A%2B%2B3fffdad0%2B00000000%2B3fff2e85%2B4020fdb0%2B%2B3fff3eb0%253A%2B%2Bfeefeffe%2Bfeefeffe%2B3fff2ea0%2B40100718%2B%2B%2B%253Cnull%253E Fatal+exception%3A28+flag%3A2+%28EXCEPTION%29+epc1%3A0x402071b2+epc2%3A0x00000000+epc3%3A0x00000000+excvaddr%3A0x00000000+depc%3A0x00000000ctx%253A%2Bsys%2Bsp%253A%2B3fff3d90%2Bend%253A%2B3fff3ec0%2Boffset%253A%2B01a0%250A%2B3fff3d90%253A%2B%2B00000002%2B00000001%2B00000000%2B402071b0%2B%2B3fff3da0%253A%2B%2B32317830%2B36353433%2B00000000%2B4010068c%2B%2B3fff3db0%253A%2B%2B00000000%2B00000000%2B3fff606c%2B4020cb9e%2B%2B3fff3dc0%253A%2B%2B3fff606c%2B3fff0db0%2B3fff606c%2B4020cbda%2B%2B3fff3dd0%253A%2B%2B00000000%2B00000000%2B00000000%2B4020f3f0%2B%2B3fff3de0%253A%2B%2B3fff606c%2B3fff0db0%2B3fff0d70%2B4020cc69%2B%2B3fff3df0%253A%2B%2B3fff6624%2B0000000f%2B00000006%2B40209728%2B%2B3fff3e00%253A%2B%2B00000000%2B00000004%2B00000004%2B00000001%2B%2B3fff3e10%253A%2B%2B00000002%2B00000004%2B0000000e%2B3fff2ea0%2B%2B3fff3e20%253A%2B%2B00000000%2B00000000%2B3fff0d70%2B3fff2e8c%2B%2B3fff3e30%253A%2B%2B00000001%2B3fff0d94%2B3fff0d70%2B4020ce77%2B%2B3fff3e40%253A%2B%2B3ffe9168%2B00000000%2B000003e8%2B4020a964%2B%2B3fff3e50%253A%2B%2B00000000%2B3fff65e4%2B000003e8%2B4020a9e2%2B%2B3fff3e60%253A%2B%2B3fffdad0%2B00000000%2B3fff2e85%2B4020874f%2B%2B3fff3e70%253A%2B%2B00000000%2B00000000%2B00000000%2B00000000%2B%2B3fff3e80%253A%2B%2B00000000%2B00000000%2B402073e4%2B40208484%2B%2B3fff3e90%253A%2B%2B00000000%2B00000000%2B00000001%2B3fff2e8c%2B%2B3fff3ea0%253A%2B%2B3fffdad0%2B00000000%2B3fff2e85%2B4020fdb0%2B%2B3fff3eb0%253A%2B%2Bfeefeffe%2Bfeefeffe%2B3fff2ea0%2B40100718%2B%2B%2B%253Cnull%253E Fatal+exception%3A4+flag%3A1+%28WDT%29+epc1%3A0x402097c7+epc2%3A0x00000000+epc3%3A0x00000000+excvaddr%3A0x00000000+depc%3A0x00000000 |
I want to do some more testing with these functions. I have the ability to call a URL like http://ESP IP:80/crash and then execute code that causes a crash. All examples that I used give the correct stack trace after startup and when decoded also give the correct information. This is what I have: server.on("/crash", { And then: void crashme(){ void crashme2(){ |
Hello interested people, I created a minimal Arduino sketch with the following functionality:
Simply do the following:
Then call the next URL's in a row, for example by using curl:
The stack printed at startup can be given to ESP Exception Decoder and there you have your stack in human readble format. The output I receive is attached. It can be seen that after startup the reasot reason and stack are available. |
@TheAustrian and @penfold42: could you have a try with this sketch I created? |
Cool! This morning I had a crash and got the crash below in my inbox. So, is seems to be working fine. I was able to decode it in ESP Exception Decoder. Fatal exception:28 flag:2 (EXCEPTION) epc1:0x4022a136 epc2:0x00000000 epc3:0x00000000 excvaddr:0x00000008 depc:0x00000000 |
@djoele Awesome, thanks! I'll have a go at it in a few days and report back. |
@TheAustrian: have you been able to check the sketch? |
Hello everybody, this question is over half a year old. The original poster has not responded and one person has but did not reply with some results of testing the sketch. Is there anybody interested or should we marked the question as closed? |
Hi! I'm still interested and have tested the sketch you provided and it seems it works (thanks for that and sorry I did not immediately respond!), but I haven't had the time to adapt the sketch to my needs i.e. either integrate it into my existing program and transmit the crash info with websocket to the website I use or log it in a database on my server. Work has been a pain lately (everyone wants everything ready before the holidays, it seems)... |
Good that it worked. Let us know when you're done putting it in your own sketch. |
@TheAustrian: did you find any time to work on your sketch? Has anybody else tried it? |
Hi @djoele, I believe your sketch is a very useful tool. I have encountered cases like @penfold42, when I like to debug some exception / ESP restarts that occur infrequently / at remote location so it has no sense or it is not practical to watch at serial monitor waiting for it to happen. This thread and your sketch in particular inspired me to write a library to convert what you have developed into some general functionality. I am tied up with some other tasks now but I am planning to return to it in next coupe of weeks. If anybody is interested then share your thoughts. Thank you for development of this functionality and sharing! Krzysztof |
@krzychb: I appreciate it that you pick up where I left. Looking forward to see the results of the library you are making. Perhaps the code as I wrote it could be improved as well. |
@krzychb: have you made any progress on your library? |
Hi @djoele, |
No problem :) Looking forward to your first release. |
Hi @djoele, I have prepared preliminary version of library to capture and save crash information https://github.com/krzychb/EspSaveCrash. There are also examples attached. They allow to crash ESP and then show captured data on a serial monitor. There is also an example to show crash information with a web browser. I plan to redo this one and prepare a more compelling version 😄 Krzysztof |
This is done in a good way, I think. I created something similar for your web browser functionality. I created a call that is handled when my server tries to get the crash information from the ESP device. Good job! |
Thank you for quickly checking it and good news! |
I think having this in its own repo is ok. Thank you, I use it myself. |
I'm not sure if I was careful enough in that callback but I made little lib to save esp8266 exception trace in a spiffs file, in case someone is interested, very useful if you run a server or if you have long stack traces ;) , based on Krzysztof work : |
@popok75 I've developed your code a little bit further. May you and other interested hackers checkout my EspSaveCrashSpiffs lib. It's based on @krzychb EEPROM lib, but uses the filesystem for creating crash log files everytime a crash occurs. Thereby the files stay small and you can almost create as many crashes as you want |
Is there any way or any function which will be called right before esp shuts down because of power loss. |
Maybe because something is not written before boot (default value on cold boot means power-on, other values are written right before reboots). Anyway I personally am not aware such function and I'm pretty sure there's none. I would use a 3v3powersupply->schottky diode->supercapacitor-on-vcc, |
Is there any way to capture the reset reason and stack trace after a restart in my sketch ?
I want to send this over the network rather than capture it on the serial interface.
Thanks !
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: