8000 Update documentation and arduino debug options by mhightower83 · Pull Request #8837 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

Update documentation and arduino debug options #8837

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

Merged
merged 22 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e67c95c
Update documentation
mhightower83 Jan 29, 2023
f91d547
Added d-a-v's code. And updated description and debug macro.
mhightower83 Jan 30, 2023
679038d
Update doc
mhightower83 Jan 30, 2023
33bbf8b
Fixed code formatting
mhightower83 Jan 31, 2023
d135c64
Merge branch 'master' into pr-doc-debug
mhightower83 Jan 31, 2023
c453382
Merge branch 'pr-doc-debug' of github.com:mhightower83/Arduino into p…
mhightower83 Jan 31, 2023
2e062ae
Fixed example
mhightower83 Jan 31, 2023
1a92df1
Proposed "Debug port" menu change
mhightower83 Jan 31, 2023
9157394
Update boards.txt.py and docs - WIP
mhightower83 Feb 2, 2023
2ee9eb5
Merge branch 'master' into pr-doc-debug
mhightower83 Feb 2, 2023
9a6ea12
Improve organization of optimization content.
mhightower83 Feb 2, 2023
8e49b33
Add fallback value for build.debug_optim to platform.txt
mhightower83 Feb 2, 2023
aab4d56
update text and undo changes to platformio-build.py
mhightower83 Feb 3, 2023
94e165d
tweak text
mhightower83 Feb 4, 2023
e51f134
Merge branch 'master' into pr-doc-debug
d-a-v Feb 5, 2023
ab7a02a
Added ':orphan:' mark to a06-global-build-options.rst
mhightower83 Feb 5, 2023
58ad384
Update doc. Added link in page index to 'Improving Exception Decoder …
mhightower83 Feb 13, 2023
073ff6e
Merge branch 'master' into pr-doc-debug
mhightower83 Feb 25, 2023
f2a6150
Merge branch 'master' into pr-doc-debug
mhightower83 Mar 11, 2023
633550f
Merge branch 'master' into pr-doc-debug
mhightower83 Mar 28, 2023
462252f
Update text to reference PR#8868 improvements for leaf function.
mhightower83 Mar 29, 2023
1bc6c4c
Merge branch 'master' into pr-doc-debug
d-a-v Mar 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update doc
Updated platform.txt - positioned -Os such that it can be overridden by `build.opt`.

Add suggestion of using `-Og` which may improve the Decoder's line number correlation
with the problem in the source code.

Untested adjustments to platformio-build.py
  • Loading branch information
mhightower83 committed Jan 31, 2023
commit 679038d9772cacaca0aab46f977be72c816f8bd7
2 changes: 1 addition & 1 deletion doc/Troubleshooting/stack_dump.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ It's possible to decode the Stack to readable information. For more info see the

ESP Exception Decoder

For more on troubleshooting, read `My ESP Crashes <../faq/a02-my-esp-crashes.rst>`__.
For more on troubleshooting, read `FAQ: My ESP Crashes <../faq/a02-my-esp-crashes.rst>`__.
60 changes: 33 additions & 27 deletions doc/faq/a02-my-esp-crashes.rst
8000
Original file line number Diff line number Diff line change
Expand Up @@ -271,38 +271,44 @@ Decoder <https://github.com/me-no-dev/EspExceptionDecoder>`__ you can
track down where the module is crashing whenever you see the stack trace
dropped. The same procedure applies to crashes caused by exceptions.

Notes:

To decode the exact line of code where the application
Note, to decode the exact line of code where the application
crashed, you need to use ESP Exception Decoder in context of sketch
you have just loaded to the module for diagnosis. Decoder is not
able to correctly decode the stack trace dropped by some other
application not compiled and loaded from your Arduino IDE.

When you select a ``Debug port:`` on the Arduino IDE Tools menu, it turns off
``optimize-sibling-calls``. Turning off this optimization allows more caller
addresses to be written to the stack, improving the results from the
Exception Decoder. Without this option, the callers involved in the crash
may be missing from the results. Because of the limited stack space, there
is the remote possibility that removing this optimization could lead to more
frequent stack overflows. You only want to do this in a debug setting.

If you are not using the "Debug port" and need to improve the results of the
Exception Decoder, you can add ``-fno-optimize-sibling-calls`` to your build
options. For details on how to do this, review `Global Build Options
<a06-global-build-options.rst>`__.

For non-Arduino IDE build platforms, you may need to research how to add
build options.

A crash in a leaf function may not leave the caller's address on the stack.
The return address can stay in a register for the duration of the call.
Resulting in a crash report identifying the crashing function without a
trace of who called. You can encourage the compiler to save the caller's
return address by adding an inline assembly trick
``__asm__ __volatile__("" ::: "a0", "memory");`` at the beginning of the
function's body. Or instead, for a debug build conditional option, use the
macro ``DEBUG_LEAF_FUNCTION()`` from ``#include <debug.h>``.

Improving Exception Decoder Results
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When you select a ``Debug port`` on the Arduino IDE Tools menu, it turns off
``optimize-sibling-calls``. Turning off this optimization allows more caller
addresses to be written to the stack, improving the results from the
Exception Decoder. Without this option, the callers involved in the crash
may be missing from the results. Because of the limited stack space, there
is the remote possibility that removing this optimization could lead to more
frequent stack overflows. You only want to do this in a debug setting.

If you are not using the ``Debug port`` and need to improve the results of the
Exception Decoder, you can add ``-Og`` or ``-fno-optimize-sibling-calls``
to your build options. For details on how to do this, review
`Global Build Options <a06-global-build-options.rst>`__.

For non-Arduino IDE build platforms, you may need to research how to add
build options.

For projects that become too large to flash with a global debug build option,
you could target the optimization to specific modules of interest by adding
`#pragma GCC optimize("Og")`.

A crash in a leaf function may not leave the caller's address on the stack.
The return address can stay in a register for the duration of the call.
Resulting in a crash report identifying the crashing function without a
trace of who called. You can encourage the compiler to save the caller's
return address by adding an inline assembly trick
``__asm__ __volatile__("" ::: "a0", "memory");`` at the beginning of the
function's body. Or instead, for a debug build conditional option, use the
macro ``DEBUG_LEAF_FUNCTION()`` from ``#include <debug.h>``.


Other Causes for Crashes
Expand Down
8 changes: 4 additions & 4 deletions platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,24 @@ compiler.path={runtime.tools.xtensa-lx106-elf-gcc.path}/bin/
compiler.sdk.path={runtime.platform.path}/tools/sdk

compiler.libc.path={runtime.platform.path}/tools/sdk/libc/xtensa-lx106-elf
compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ -D_GNU_SOURCE -DESP8266 {build.opt.flags} "-I{compiler.sdk.path}/include" "-I{compiler.sdk.path}/{build.lwip_include}" "-I{compiler.libc.path}/include" "-I{build.path}/core"
compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ -D_GNU_SOURCE -DESP8266 -Os {build.opt.flags} "-I{compiler.sdk.path}/include" "-I{compiler.sdk.path}/{build.lwip_include}" "-I{compiler.libc.path}/include" "-I{build.path}/core"

# support precompiled libraries in IDE v1.8.6+
compiler.libraries.ldflags=

compiler.c.cmd=xtensa-lx106-elf-gcc
compiler.c.flags=-c "{compiler.warning_flags}-cflags" -std=gnu17 {build.stacksmash_flags} -Os -g -free -fipa-pta -Werror=return-type -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} {build.mmuflags} {build.non32xferflags}
compiler.c.flags=-c "{compiler.warning_flags}-cflags" -std=gnu17 {build.stacksmash_flags} -g -free -fipa-pta -Werror=return-type -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} {build.mmuflags} {build.non32xferflags}

compiler.S.cmd=xtensa-lx106-elf-gcc
compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls "-I{runtime.tools.xtensa-lx106-elf-gcc.path}/include/"

compiler.c.elf.flags=-g "{compiler.warning_flags}-cflags" -Os -nostdlib -Wl,--no-check-sections -u app_entry {build.float} -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/lib/{build.sdk}" "-L{build.path}" "-L{compiler.libc.path}/lib" "-Tlocal.eagle.flash.ld" -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read
compiler.c.elf.flags=-g "{compiler.warning_flags}-cflags" -nostdlib -Wl,--no-check-sections -u app_entry {build.float} -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/lib/{build.sdk}" "-L{build.path}" "-L{compiler.libc.path}/lib" "-Tlocal.eagle.flash.ld" -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read

compiler.c.elf.cmd=xtensa-lx106-elf-gcc
compiler.c.elf.libs=-lhal -lphy -lpp -lnet80211 {build.lwip_lib} -lwpa -lcrypto -lmain -lwps -lbearssl -lespnow -lsmartconfig -lairkiss -lwpa2 {build.stdcpp_lib} -lm -lc -lgcc

compiler.cpp.cmd=xtensa-lx106-elf-g++
compiler.cpp.flags=-c "{compiler.warning_flags}-cppflags" {build.stacksmash_flags} -Os -g -free -fipa-pta -Werror=return-type -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 {build.stdcpp_level} -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} {build.mmuflags} {build.non32xferflags}
compiler.cpp.flags=-c "{compiler.warning_flags}-cppflags" {build.stacksmash_flags} -g -free -fipa-pta -Werror=return-type -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 {build.stdcpp_level} -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} {build.mmuflags} {build.non32xferflags}

compiler.as.cmd=xtensa-lx106-elf-as

Expand Down
14 changes: 6 additions & 8 deletions tools/platformio-build.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,6 @@ def scons_patched_match_splitext(path, suffixes=None):
LIBPATH=[NONOSDK_LIBPATH],
)

#
# debug
#
for define in env["CCFLAGS"]:
if "DEBUG_ESP_PORT" in define:
env.Append(CCFLAGS=["-fno-optimize-sibling-calls"])
break

#
# lwIP
#
Expand Down Expand Up @@ -257,6 +249,12 @@ def scons_patched_match_splitext(path, suffixes=None):
)
lwip_lib = "lwip2-536-feat"

#
# debug
#
if "DEBUG_ESP_PORT" in flatten_cppdefines:
env.Append(CCFLAGS=["-fno-optimize-sibling-calls"])

#
# Waveform
#
Expand Down
0