aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtins/functions.c23
-rw-r--r--compile.c14
-rw-r--r--tomo.c5
3 files changed, 35 insertions, 7 deletions
diff --git a/builtins/functions.c b/builtins/functions.c
index 4ff7a1a5..d366736e 100644
--- a/builtins/functions.c
+++ b/builtins/functions.c
@@ -1,9 +1,10 @@
// Built-in functions
+#include <errno.h>
+#include <execinfo.h>
#include <gc.h>
#include <gc/cord.h>
#include <stdbool.h>
#include <stdint.h>
-#include <errno.h>
#include <stdlib.h>
#include <sys/param.h>
#include <uninorm.h>
@@ -33,6 +34,26 @@ public void fail(CORD fmt, ...)
CORD_vfprintf(stderr, fmt, args);
fputs("\n", stderr);
va_end(args);
+
+ // Print stack trace:
+ fprintf(stderr, "\x1b[34m");
+ fflush(stderr);
+ void *array[1024];
+ size_t size = backtrace(array, sizeof(array)/sizeof(array[0]));
+ char **strings = strings = backtrace_symbols(array, size);
+ for (size_t i = 1; i < size; i++) {
+ char *filename = strings[i];
+ const char *cmd = heap_strf("addr2line -e %.*s -fip | sed 's/\\$/./g;s/ at /() at /' >&2", strcspn(filename, "("), filename);
+ FILE *fp = popen(cmd, "w");
+ if (fp) {
+ char *paren = strchrnul(strings[i], '(');
+ fprintf(fp, "%.*s\n", strcspn(paren + 1, ")"), paren + 1);
+ }
+ pclose(fp);
+ }
+ fprintf(stderr, "\x1b[m");
+ fflush(stderr);
+
raise(SIGABRT);
}
diff --git a/compile.c b/compile.c
index 8de13b2c..4c31bcad 100644
--- a/compile.c
+++ b/compile.c
@@ -776,10 +776,16 @@ CORD compile_statement(env_t *env, ast_t *ast)
default:
return CORD_asprintf("(void)%r;", compile(env, ast));
}
- // int64_t line = get_line_number(ast->file, ast->start);
- // return stmt ? CORD_asprintf("#line %ld\n%r", line, stmt) : stmt;
}
+// CORD compile_statement(env_t *env, ast_t *ast) {
+// CORD stmt = _compile_statement(env, ast);
+// if (!stmt)
+// return stmt;
+// int64_t line = get_line_number(ast->file, ast->start);
+// return CORD_asprintf("#line %ld\n%r", line, stmt);
+// }
+
CORD expr_as_text(env_t *env, CORD expr, type_t *t, CORD color)
{
switch (t->tag) {
@@ -2091,14 +2097,14 @@ module_code_t compile_file(ast_t *ast)
.module_name=name,
.object_files=env->code->object_files,
.header=CORD_all(
- // CORD_asprintf("#line 0 %r\n", Text$quoted(ast->file->filename, false)),
+ // CORD_asprintf("#line 1 %r\n", Text$quoted(ast->file->filename, false)),
"#include <tomo/tomo.h>\n",
env->code->typedefs, "\n",
env->code->typecode, "\n",
env->code->fndefs, "\n"
),
.c_file=CORD_all(
- // CORD_asprintf("#line 0 %r\n", Text$quoted(ast->file->filename, false)),
+ // CORD_asprintf("#line 1 %r\n", Text$quoted(ast->file->filename, false)),
env->code->imports, "\n",
env->code->staticdefs, "\n",
env->code->funcs, "\n",
diff --git a/tomo.c b/tomo.c
index 1713cc5d..834732e6 100644
--- a/tomo.c
+++ b/tomo.c
@@ -84,7 +84,8 @@ int main(int argc, char *argv[])
cconfig = getenv("CCONFIG");
if (!cconfig)
- cconfig = "-std=c11 -fdollars-in-identifiers -fsanitize=signed-integer-overflow -fno-sanitize-recover -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE";
+ cconfig = "-std=c11 -fdollars-in-identifiers -fsanitize=signed-integer-overflow -fno-sanitize-recover"
+ " -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE";
const char *optimization = getenv("O");
if (!optimization || !optimization[0]) optimization = "-O1";
@@ -337,7 +338,7 @@ int compile_executable(const char *filename, const char *object_files)
int status = pclose(runner);
if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
if (verbose)
- printf("Compiled executable: %s\n", filename);
+ printf("Compiled executable: %s\n", bin_name);
}
return WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE;
}