tkchia / gcc-ia16

Fork of Lambertsen & Jenner (& al.)'s IA-16 (Intel 16-bit x86) port of GNU compilers ― added far pointers & more • use https://github.com/tkchia/build-ia16 to build • Ubuntu binaries at https://launchpad.net/%7Etkchia/+archive/ubuntu/build-ia16/ • DJGPP/MS-DOS binaries at https://gitlab.com/tkchia/build-ia16/-/releases • mirror of https://gitlab.com/tkchia/gcc-ia16
GNU General Public License v2.0
173 stars 13 forks source link

Stacktraces #147

Open Azhagen opened 4 months ago

Azhagen commented 4 months ago

Hello,

It is currently very hard to get stacktraces, as %si and %di can be pushed before %bp. I suggest to push %bp first, so that getting the return address of the function gets easier.

Thank you, Azhagen

ghaerr commented 4 months ago

Hello @Azhagen,

Yes, it can be hard to determine a function start address when running code without a symbol table and/or compiled without certain compiler options. I ended up writing a full stack backtrace set of functions that allow displaying stack traces both with and without symbol tables (See screenshot in https://github.com/ghaerr/elks/pull/1843). In the case of no symbol table, the _get_fn_start_address function reads the instruction stream backwards, recognizing all ia16-elf-gcc generated function prologues full list shown here and returns a function start address at runtime. See also Stack backtrace in C library and Enable symbolic debugging.

I'm not sure exactly the problem you are trying to solve, but for stack backtraces to always work the -fno-omit-frame-pointer and -fno-optimize-sibling-calls compiler options should be set so that full proper function prologues are always generated. If a function needs to know its return (IP) address or frame (BP) address it can call __builtin_return_address(0) or __builtin_frame_address(0) respectively.

Thank you!