Skip to content

[libc] Enhance debug function tracing#2615

Merged
ghaerr merged 2 commits intomasterfrom
ftrace
Feb 12, 2026
Merged

[libc] Enhance debug function tracing#2615
ghaerr merged 2 commits intomasterfrom
ftrace

Conversation

@ghaerr
Copy link
Copy Markdown
Owner

@ghaerr ghaerr commented Feb 12, 2026

Adds additional stack-backtrace option for specially-compiled ELKS applications to display a stack backtrace in addition to the existing function tracing capability. This option can be turned on either through export FTRACE=2 or --ftrace2 as the first argument command. Normal function tracing remains available through export FTRACE or --ftrace command line.

Applications must be compiled with the following additional ia16-elf-gcc command line options in order to link in runtime function tracing:

    -fno-omit-frame-pointer -fno-optimize-sibling-calls -finstrument-functions-simple

The combined stack tracing was developed to track down a stack corruption bug in DCC (Open DeSmet C Compiler for ELKS) which is a work in progress. This particular C compiler is able to compile itself on ELKS, possibly providing the capability of compiling the toolchain itself inside ELKS, slowly marching towards a self-replicating system.

Some examples of the usage of function tracing output follow.

DCC --ftrace function tracing showing recursive descent parser functions being called:
C88 parse ftrace1

ELKS kernel catching stack underflow as the result of SP being clobbered (pretty cool for non-MMU system):
C88 parse segfault ftrace1

DCC --ftrace2 stack backtrace display showing BP being zeroed (clobbered) directly before tree4() is called from heir25(). This information finally allowed finding the buggy source code, which ended up being that of writing outside the bounds of a local array which clobbered BP and SP in the addresses directly above the array variable:
C88 parse BP overwrite ftrace2 copy

@ghaerr ghaerr merged commit 5184807 into master Feb 12, 2026
1 check passed
@ghaerr ghaerr deleted the ftrace branch February 12, 2026 00:27
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.

1 participant