Skip to content
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

Replace addr2line with GDB to get accurate line #s #31

Merged
merged 2 commits into from
Mar 26, 2018

Conversation

earlephilhower
Copy link
Contributor

This works around issue #23 that @igrr and @me-no-dev reported where addr2line has issues on xtensa.

...snip...
Addr2line on the xtensa seems to have trouble with identifying the
proper file:line number for an exception address. Until there is a
fix, the workaround is to use GDB to locate them.

See jcmvbkbc/binutils-gdb-xtensa#5 .

Replace the addr2line processing/formatting with gdb's formatting,
leaving the output identical with one exception: addresses with
no source code (i.e. not code, but constant data somewhere or just
random variables on the stack) will not print. They're silently
ignored in the output.

An updated ESP8266 panic function can print out the calling function/line
and size requested for the last malloc/realloc/calloc/new allocation that
failed, without the overhead of full the OOM stack.

Add parsing for this line, when present, and output the function, file,
line, and amount of memory requested to the display.  When not present,
do nothing different.
Copy link

@igrr igrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good to me!

@@ -96,9 +97,34 @@ public String getMenuTitle() {
return "ESP Exception Decoder";
}

// Need custom one to redirect STDERR to STDOUT
Copy link

@igrr igrr Jan 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add something like "Parts of the code are derived from Arduino project" near the top of the source file (the original file doesn't have an explicit copyright which we could keep).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added reference to where it came from in latest push.

@igrr
Copy link

igrr commented Jan 23, 2018

@earlephilhower Since you have the EspExceptionDecoder open for surgery, may I ask you to add one more thing — printing out (and decoding) the program counter at the point of the exception (epc1 in the exception message) and also printing out excvaddr? These can be useful to diagnose a crash and they are currently missing from issue reports we receive.

@earlephilhower
Copy link
Contributor Author

You're actually getting this info already, just not nicely formatted. The existing decoder is very robust and tries to decode anything, anywhere, that looks like an address starting with 40XXXX. So the first line in "Decoding..." is normally the PC, followed by any other registers that have 40xxxx in them, then followed by addresses in the stack dump.

Let me think a bit for a clean way to do this. Regexps could probably work, but are unwieldy and hard to maintain. A state machine (more brittle, though, than existing method) may be saner.

@igrr
Copy link

igrr commented Jan 24, 2018

Thanks, I didn't notice it also decoded the epc1. I think it would be valuable to print excvaddr, as its value sometimes tells more about the cause of the exception (helps distinguish between a null pointer dereference and garbage/corrupted memory, for instance).

@earlephilhower
Copy link
Contributor Author

ESP8266 crash w/new commit, PC and EXEVADDR separated properly instead of looking like they're on the call stack:
image

ESP32 crash (had to force this one!):
image

Addr2line on the xtensa seems to have trouble with identifying the
proper file:line number for an exception address.  Until there is a
fix, the workaround is to use GDB to locate them.

See jcmvbkbc/binutils-gdb-xtensa#5 .

Replace the addr2line processing/formatting with gdb's formatting,
leaving the output identical with one exception:  addresses with
no source code (i.e. not code, but constant data somewhere or just
random variables on the stack) *will not print*.  They're silently
ignored in the output.

This also now presents the EPC1/PC and EXCVADDR on their own
lines hilighted at the top of the dump.

Additionally, handle the case where the exception dumper itself
on the ESP8266 hits the WDT (i.e. during dump of an infinite
recursion).  In this case the final "<<<stack<<<" line may not be
generated, so simply parse everything from ">>>stack>>>" to the end.
@earlephilhower
Copy link
Contributor Author

@me-no-dev Would you be able to take a look at this PR? We've just done a commit into the Arduino-ESP8266 repo which can be used with this new stack dump method to get better info on OOM errors (sadly very common even in the libs).

It'll also help the ESP-32 since it works around the bugs in the Xtensa toolchain which don't seem to have a quick fix.

@me-no-dev me-no-dev merged commit afcc935 into me-no-dev:master Mar 26, 2018
@me-no-dev
Copy link
Owner

Done :) Sorry for the delay!

@earlephilhower
Copy link
Contributor Author

Thanks again! Hope it helps until the toolchain can be fixed...

@earlephilhower earlephilhower deleted the use_gdb branch March 26, 2018 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants