{{ message }}
Repository navigation
stacktrace: Don't allocate module paths when no frame has a line - #2436
Open
gabrielmancini wants to merge 1 commit into
Open
gabrielmancini wants to merge 1 commit into
gabrielmancini wants to merge 1 commit into
Conversation
stacktrace_build() allocated num_mods module path pairs, one per frame with line information, and returned the raw stacktrace when malloc failed. With no such frame num_mods is 0, and malloc(0) returns NULL on ESP-IDF, so every stacktrace of modules without line information came back raw, with "Unable to allocate space for module paths" on stderr. Allocate only when there is something to store. The ESP32 test project now creates stacktraces like the firmware build does, so test_stacktrace sees what a device sees. Signed-off-by: Gabriel Mancini <gabriel.mancini@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

stacktrace_build()allocatesnum_modsmodule path pairs, one per frame location with line information, and returns the raw stacktrace whenmallocfails. When no frame has line information,num_modsis 0, and on ESP-IDFmalloc(0)returnsNULL(heap_caps_base.c), so the stacktrace comes back raw ({NumFrames, 0, 0, 0, [{ModIndex, Offset}, ...], Class}) instead of a list, and stderr shows:That covers every application packed without line information on ESP32: we saw it on all our boards (ESP32 and ESP32-S3 with 8 MB of PSRAM), never related to memory. glibc returns a non-NULL pointer for
malloc(0), which is why generic_unix never shows it.The fix allocates only when
num_mods > 0. With 0 the loop never touchesmodule_paths, andfree(NULL)is fine.Test.
test_stacktrace(ESP32) raises in a module compiled withno_line_infoand checks that the stacktrace is a list with a frame of that module. The ESP32 test project never declaredAVM_CREATE_STACKTRACES, so stacktraces wereundefinedthere; it now enables it assrc/platforms/esp32/CMakeLists.txtdoes, which is what a device runs with.{not_a_list,{2,0,0,0,[{0,25},{0,20,erlang,error,1}],error}}; with it,test_stacktracepasses (test_socketfails here as it does on plain release-0.7, no network inside QEMU).test-erlang: all pass.These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license).
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later