Calling Scheme code from gdb fails horribly
On some machines (e.g. my laptop at home), when I try to call into Scheme code to print a Scheme value inside gdb, even with a trivial Scheme function, the process dies with a SIGSEGV. On others, like my workstation at work, there's no problem. I've attached some code to demonstrate the problem; use "make run" to run it and see if it dies.
Both machines are running versions of Debian x86_64. The one that dies is has gdb 8.2-0ubuntu1 using Kubuntu 18.10 with kernel version 4.18.0-25-generic running inside VirtualBox 6.0.10 on a Windows 10 host, and the one that works is using a proprietary Debian-based distro on an HP Z840 with a patched kernel version based on 4.19.37 and a patched gdb based on 8.3. I know the problem isn't in the compiler toolchain because I can copy the binary from one machine to another and see the difference in behavior.
I tried debugging the problem at the assembly level, but I wasn't able to figure out much, except that debugging a function called from gdb itself is weird. If I wrap the Scheme function in a separate C function and call that from gdb, the Scheme function executes and returns to the C code just fine, but the problem occurs as soon as the C function executes its final "ret" instruction.
I've developed a workaround that's incredibly ugly but does what I need it to: I made the function I want to run from gdb fork off a child process, which executes the Scheme code and delivers its result to the parent process by writing its output to a temporary file.