ghaerr / elks

Embeddable Linux Kernel Subset - Linux for 8086
Other
1.02k stars 108 forks source link

[libc] Get --ftrace option working on all commands #2025

Closed ghaerr closed 2 months ago

ghaerr commented 2 months ago

Setting CONFIG_APPS_FTRACE=y now builds all applications, including the shell, with a full symbol table, allowing for symbolic function tracing during execution. Setting FTRACE=1 in /bootopts will turn on function tracing for all apps, or any app can be started with --ftrace as the first argument and it will display it execution to /dev/console.

While some of this was already present, it is now debugged. Turns out that /bin/sh actually has function nesting depth of over 100 and was overflowing the stack.

The stripped-down "tiny_printf.c" had to be slightly reworked for this to work, and it was then found that GCC was replacing some calls to printf with calls to puts or fputs, which complicated matters and unknowingly increased code size. The -fno-builtin-printf was added to stop that.

The debug option in /bootopts now turns on some basic debugging, showing which files are being exec'd, which is helpful when running a system ftrace. If you really want to see what's going on, set CONFIG_TRACE=y and strace in /bootopts, along with FTRACE=1. This will trace all system calls and all function calls for every program. Set console=/dev/ttyS0 also in /bootopts and widen the terminal emulator window to 200 columns for best clarity.

When CONFIG_APPS_FTRACE=y, the disk image is so large that 2880k floppy or HD must be selected also, and man pages aren't added so there's enough space.