picrin/debug.c

70 lines
1.7 KiB
C
Raw Normal View History

2014-08-25 00:38:09 -04:00
/**
* See Copyright Notice in picrin.h
*/
#include "picrin.h"
#include "picrin/string.h"
#include "picrin/error.h"
#include "picrin/proc.h"
pic_str *
pic_get_backtrace(pic_state *pic)
{
size_t ai = pic_gc_arena_preserve(pic);
pic_callinfo *ci;
pic_str *trace;
2014-09-12 06:52:49 -04:00
trace = pic_make_str(pic, NULL, 0);
2014-08-25 00:38:09 -04:00
for (ci = pic->ci; ci != pic->cibase; --ci) {
struct pic_proc *proc = pic_proc_ptr(ci->fp[0]);
2014-09-12 06:52:49 -04:00
trace = pic_strcat(pic, trace, pic_make_str_cstr(pic, " at "));
trace = pic_strcat(pic, trace, pic_make_str_cstr(pic, pic_symbol_name(pic, pic_proc_name(proc))));
2014-08-25 00:38:09 -04:00
if (pic_proc_func_p(proc)) {
2014-09-12 06:52:49 -04:00
trace = pic_strcat(pic, trace, pic_make_str_cstr(pic, " (native function)\n"));
2014-08-25 00:38:09 -04:00
} else if (pic_proc_irep_p(proc)) {
2014-09-12 06:52:49 -04:00
trace = pic_strcat(pic, trace, pic_make_str_cstr(pic, " (unknown location)\n")); /* TODO */
2014-08-25 00:38:09 -04:00
}
}
pic_gc_arena_restore(pic, ai);
pic_gc_protect(pic, pic_obj_value(trace));
return trace;
}
void
2014-09-16 11:28:55 -04:00
pic_print_backtrace(pic_state *pic)
2014-08-25 00:38:09 -04:00
{
size_t ai = pic_gc_arena_preserve(pic);
pic_str *trace;
2014-09-16 11:28:55 -04:00
assert(! pic_undef_p(pic->err));
2014-08-25 00:38:09 -04:00
2014-09-16 11:28:55 -04:00
if (! pic_error_p(pic->err)) {
trace = pic_format(pic, "raised: ~s", pic->err);
} else {
struct pic_error *e;
2014-08-25 00:38:09 -04:00
2014-09-16 11:28:55 -04:00
e = pic_error_ptr(pic->err);
if (e->type != pic_intern_cstr(pic, "")) {
Squashed 'extlib/benz/' changes from 414f790..057b5f2 057b5f2 Merge pull request #245 from picrin-scheme/heap-symbol c91f6cd [bugfix] build failure in debug mode b1849c4 pic_sym is not a pointer e353b07 s/pic_sym/pic_sym_ptr/g a11fb91 [bugfix] irep->name is missed to mark 1820a25 [bugfix] wrong type specified for cxt->syms b8d2b8e better error messages against invalid use of auxiliary syntax d9ade33 mark only interned symbols and some specisl uninterned symbols da2217b move symbol constants to pic_state 78b035b [bugfix] pic_intern must count up reference of the return value bbdc663 rename internal object ba01821 s/SYMBOL_P/SYMBOLP/g, s/PAIR_P/PAIRP/g 1af32d1 improve error message dd09fbf don't malloc in pic_interned_p 7f51070 turn on GC 7460e81 add gc on/off flag f3742db move symbol-related macros to symbol.h ded6759 remove pic_sym_value ec97d07 remove pic_symbol_value 28bd059 heap symbol seems working (with GC stopped) e0d6fe9 change pic_intern interface 6750693 remove pic_ungensym 4ea7d3c add irep->syms ede7a99 use dictionary for senv->map b3cb50c use dictionaries for temporary import table fc698b5 use dictionary for rec->data 1b814d4 use dictionary for lib->exports 7ae1af4 use dictionaries for pic->globals and pic->macros 74f9979 remove 'struct pic_macro'. define-syntax spec is changed. 86136c5 some procedures are moved to contrib/ da99761 gather all includes of standard headers into picrin.h 7df8d77 add dictionary-map and dictionary-for-each b625ff8 revert 48f0ec90. dicitonary is now symbol-to-object structure f7657d7 [prepare] dictionary is to be changed to have only symbols for its keys git-subtree-dir: extlib/benz git-subtree-split: 057b5f29110ab3f75513573d291ea18acb782357
2015-01-20 03:44:06 -05:00
trace = pic_format(pic, "~s ", pic_obj_value(e->type));
2014-09-16 11:28:55 -04:00
} else {
trace = pic_make_str(pic, NULL, 0);
}
trace = pic_strcat(pic, trace, pic_format(pic, "error: ~s", pic_obj_value(e->msg)));
2014-08-25 00:38:09 -04:00
2014-09-16 11:28:55 -04:00
/* TODO: print error irritants */
2014-08-25 00:38:09 -04:00
2014-09-16 11:28:55 -04:00
trace = pic_strcat(pic, trace, pic_make_str(pic, "\n", 1));
trace = pic_strcat(pic, trace, e->stack);
}
2014-08-25 00:38:09 -04:00
/* print! */
2014-09-19 04:11:59 -04:00
xfprintf(xstderr, "%s", pic_str_cstr(trace));
2014-08-25 00:38:09 -04:00
pic_gc_arena_restore(pic, ai);
}