On Fri, Mar 10, 2023 at 09:35:44AM -0800, Bakul Shah wrote:
During development the runtime should simply invoke a
debugger in this case. This should be perfectly doable but for some reason it is
considered acceptable to crash a program! I don???t want to run a program *under a
debugger* but want it invoked at the right time!
Indeed.
void
gdb_backtrace(void)
{
FILE *f;
char *cmd;
unless (getenv("_BK_BACKTRACE")) return;
unless ((f = efopen("BK_TTYPRINTF")) ||
(f = fopen(DEV_TTY, "w"))) {
f = stderr;
}
cmd = aprintf("gdb -batch -ex backtrace '%s/bk' %u 1>&%d
2>&%d",
bin, getpid(), fileno(f), fileno(f));
system(cmd);
free(cmd);
if (f != stderr) fclose(f);
}