From de153bd4791598d659cb212bbfd4d4e5cbd4a5f5 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Thu, 28 Mar 2019 14:06:16 +0000 Subject: [PATCH] errors --- os/streams.c | 21 +++++++++ .../python/yap_kernel/yap_ipython/yapi.py | 1 - pl/debug.yap | 44 ++++++++++++------- pl/errors.yap | 1 - pl/messages.yap | 5 +-- pl/spy.yap | 19 ++++---- pl/top.yap | 38 ++++++++-------- 7 files changed, 81 insertions(+), 48 deletions(-) diff --git a/os/streams.c b/os/streams.c index 1173e66c6..051d9d7c1 100644 --- a/os/streams.c +++ b/os/streams.c @@ -93,6 +93,9 @@ static char SccsId[] = "%W% %G%"; #endif #endif #include "iopreds.h" +#if HAVE_EXECINFO_H +#include +#endif #if _MSC_VER || defined(__MINGW32__) #define SYSTEM_STAT _stat @@ -128,6 +131,7 @@ FILE *Yap_GetOutputStream(Term t, const char *msg) { return rc; } +cmax =7; int GetFreeStreamD(void) { CACHE_REGS LOCK(GLOBAL_StreamDescLock); @@ -137,6 +141,23 @@ int GetFreeStreamD(void) { break; } } +#if HAVE_BACKTRACEX + void *callstack[256]; + int i; + if (sno > cmax) { + cmax++; + for (i=7; i< sno; i++) + fprintf(stderr," %d %x\n", i,GLOBAL_Stream[i].status); + } + fprintf(stderr, "++++ got %d\n", sno); + int frames = backtrace(callstack, 256); + char **strs = backtrace_symbols(callstack, frames); + fprintf(stderr, "Execution stack:\n"); + for (i = 0; i < 5; ++i) { + fprintf(stderr, " %s\n", strs[i]); + } + free(strs); +#endif if (sno == MaxStreams) { UNLOCK(GLOBAL_StreamDescLock); return -1; diff --git a/packages/python/yap_kernel/yap_ipython/yapi.py b/packages/python/yap_kernel/yap_ipython/yapi.py index 2be1ba7ff..e83ee0fa6 100644 --- a/packages/python/yap_kernel/yap_ipython/yapi.py +++ b/packages/python/yap_kernel/yap_ipython/yapi.py @@ -700,7 +700,6 @@ class YAPRun(InteractiveShell): # can fill in the output value. self.shell.displayhook.exec_result = result (program,squery,_ ,howmany) = self.prolog_cell(cell) - print("program",program, "q", squery, "h",howmany) if howmany <= 0 and not program: return result if self.syntaxErrors(program+squery+".\n") : diff --git a/pl/debug.yap b/pl/debug.yap index 212d59afe..4e40fdeee 100644 --- a/pl/debug.yap +++ b/pl/debug.yap @@ -299,7 +299,7 @@ be lost. * @return `call(Goal)` */ '$trace'(Mod:G) :- - '$trace_is_off'(Mod:G,_GN0), + '$creep_is_off'(Mod:G,_GN0), !, '$execute_nonstop'(G,Mod). '$trace'(Mod:G) :- @@ -460,7 +460,7 @@ be lost. %% Actuallb sy debugs a %% goal! '$trace_goal'(G, M, GoalNumber, _H) :- - '$trace_is_off'(M:G,GoalNumber), + '$creep_is_off'(M:G,GoalNumber), !, '$execute_nonstop'(G,M). '$trace_goal'(G, M, _GoalNumber, _H) :- @@ -556,7 +556,7 @@ be lost. */ '$debug'(_, G, M, _H) :- - '__NB_getval__'('$debug_status',state(zip,_Border,Spy), fail), + '__NB_getval__'('$debug_status',state(zip,_Border,Spy,_Trace), fail), ( Spy == stop -> \+ '$pred_being_spied'(G,M) ; true ), !, '$execute_nonstop'( G, M ). @@ -608,10 +608,10 @@ be lost. '$trace_port'(Port, GoalNumber, G, Module, _CalledFromDebugger, Info) :- '$stop_creeping'(_) , current_prolog_flag(debug, true), - '__NB_getval__'('$debug_status',state(Skip,Border,_), fail), + '__NB_getval__'('$debug_status',state(Skip,Border,_,Trace), fail), ( Skip == creep -> true; '$id_goal'(GoalNumber), GoalNumber =< Border), !, - '__NB_setval__'('$debug_status', state(creep, 0, stop)), + '__NB_setval__'('$debug_status', state(creep, 0, stop,Trace)), '$trace_port_'(Port, GoalNumber, G, Module, Info). '$trace_port'(_Port, _GoalNumber, _G, _Module, _CalledFromDebugger, _Info). @@ -697,7 +697,7 @@ be lost. Goal. '$port'(_P, _G, _M,GoalNumber,_Determinic, _Info ) :- %%> leap - '__NB_getval__'('$debug_status',state(leap,Border,_), fail), + '__NB_getval__'('$debug_status',state(leap,Border,_,_), fail), GoalNumber > Border, !. '$port'(P,G,Module,L,Deterministic, Info) :- @@ -752,7 +752,8 @@ be lost. get_char( debugger_input,C), '$action'(C,P,CallNumber,G,Module,H). '$action'('\n',_,_,_,_,_) :- !, % newline creep - '__NB_setval__'('$debug_status', state(creep, 0, stop)). + '__NB_getval__'('$trace',Trace,fail), + '__Nb_setval__'('$debug_status', state(creep, 0, stop, Trace)). '$action'(!,_,_,_,_,_) :- !, % ! 'g execute read(debugger_input, G), % don't allow yourself to be caught by creep. @@ -772,7 +773,8 @@ be lost. lists:memberchk( call_tracer, Opts), !, % <'Depth skip( debugger_input, 10), - '__NB_setval__'('$debug_status', state(creep, 0, stop)). + '__NB_getval__'('$trace',Trace,fail), + '__NB_setval__'('$debug_status', state(creep, 0, stop,Trace)). '$action'(^,_,_,G,_,_) :- !, % ' '$print_deb_sterm'(G), skip( debugger_input, 10), @@ -793,7 +795,8 @@ be lost. fail. '$action'(c,_,_,_,_,_) :- !, % 'c creep skip( debugger_input, 10), - '__NB_setval__'('$debug_status',status(creep,0,stop)). + '__NB_getval__'('$trace',Trace,fail), + '__NB_setval__'('$debug_status',status(creep,0,stop,Trace)). '$action'(e,_,_,_,_,_) :- !, % 'e exit halt. '$action'(f,_,CallNumber,_,_,_) :- !, % 'f fail @@ -827,19 +830,23 @@ be lost. '$action'(l,_,CallNumber,_,_,_) :- !, % 'l leap '$scan_number'(ScanNumber), ( ScanNumber == 0 -> Goal = CallNumber ; Goal = ScanNumber ), - '__NB_setval__'('$debug_status', state(leap, Goal, stop)). + '__NB_getval__'('$trace',Trace,fail), + '__NB_setval__'('$debug_status', state(leap, Goal, stop,Trace)). '$action'(z,_,_allNumber,_,_,_H) :- !, % 'z zip, fast leap - '__NB_setval__'('$debug_status', state(zip, 0, stop)). + '__NB_getval__'('$trace',Trace,fail), + '__NB_setval__'('$debug_status', state(zip, 0, stop, Trace)). % skip first call (for current goal), % stop next time. '$action'(k,_,_CallNumber,_,_,_) :- !, % 'k zip, fast leap - '__NB_setval__'('$debug_status', state(zip, 0, stop)). + '__NB_getval__'('$trace',Trace,fail), + '__NB_setval__'('$debug_status', state(zip, 0, stop, Trace)). % skip first call (for current goal), % stop next time. '$action'(n,_,_,_,_,_) :- !, % 'n nodebug skip( debugger_input, 10), % ' % tell debugger never to stop. - '__NB_setval__'('$debug_status', state(zip, 0, ignore)), + '__NB_getval__'('$trace',Trace,fail), + '__NB_setval__'('$debug_status', state(zip, 0, ignore, Trace)), nodebug. '$action'(r,_,CallNumber,_,_,_) :- !, % r retry '$scan_number'(ScanNumber), @@ -849,21 +856,24 @@ be lost. '$scan_number'(ScanNumber), ( ScanNumber == 0 -> Goal = CallNumber ; Goal = ScanNumber ), ( (P==call; P==redo) -> - '__NB_setval__'('$debug_status', state(leap, Goal, ignore) ) ; + '__NB_getval__'('$trace',Trace,fail), + '__NB_setval__'('$debug_status', state(leap, Goal, ignore,Trace) ) ; '$ilgl'(s) % ' ). '$action'(t,P,CallNumber,_,_,_) :- !, % 't fast skip '$scan_number'(ScanNumber), ( ScanNumber == 0 -> Goal = CallNumber ; Goal = ScanNumber ), - ( (P=call; P=redo) -> - '__NB_setval__'('$debug_status', state(zip, Goal, ignore)) ; + ( (P=call; P=redo) -> + '__NB_getval__'('$trace',Trace,fail), + '__NB_setval__'('$debug_status', state(zip, Goal, ignore,Trace)) ; '$ilgl'(t) % ' ). '$action'(q,P,CallNumber,_,_,_) :- !, % 'qst skip '$scan_number'(ScanNumber), ( ScanNumber == 0 -> Goal = CallNumber ; Goal = ScanNumber ), ( (P=call; P=redo) -> - '__NB_setval__'('$debug_status', state(leap, Goal, stop)) ; + '__NB_getval__'('$trace',Trace,fail), + '__NB_setval__'('$debug_status', state(leap, Goal, stop, Trace)) ; '$ilgl'(t) % ' ). '$action'(+,_,_,G,M,_) :- !, %% spy this diff --git a/pl/errors.yap b/pl/errors.yap index f4000aef9..ce0824b00 100644 --- a/pl/errors.yap +++ b/pl/errors.yap @@ -94,7 +94,6 @@ error_handler(Error, Level) :- '$LoopError'(Error, Level). '$LoopError'(_, _) :- - stop_low_level_trace, flush_output(user_output), flush_output(user_error), fail. diff --git a/pl/messages.yap b/pl/messages.yap index 08ffcc55c..e0e2dc9c7 100644 --- a/pl/messages.yap +++ b/pl/messages.yap @@ -206,7 +206,6 @@ compose_message(error(E, Exc), Level) --> { '$show_consult_level'(LC) }, - print_exception(Exc), location(error(E, Exc), Level, LC), main_message(error(E,Exc) , Level, LC ), c_goal( error(E, Exc), Level ), @@ -273,7 +272,7 @@ location(style_check(A,LN,FileName,B ), Level , LC) --> !, display_consulting( FileName, Level,style_check(A,LN,FileName,B ), LC ), [ '~a:~d:0: ~a: ' - [FileName,LN,Level] ] . -location( error(_,Info), Level, LC ) --> +location( error(_,Info), Level, _LC ) --> { '$error_descriptor'(Info, Desc) }, { query_exception(prologPredFile, Desc, File), @@ -285,7 +284,7 @@ location( error(_,Info), Level, LC ) --> !, {simplify_pred(M:Na/Ar,FF)}, [ '~a:~d:0 ~a while executing ~q:'-[File, FilePos,Level,FF] ]. -location( error(_,Info), Level, LC ) --> +location( error(_,Info), Level, _LC ) --> { '$error_descriptor'(Info, Desc) }, { query_exception(errorFile, Desc, File), diff --git a/pl/spy.yap b/pl/spy.yap index 5a1c61dd4..3a6a41920 100644 --- a/pl/spy.yap +++ b/pl/spy.yap @@ -403,23 +403,26 @@ notrace(G) :- '$enable_debugging':- current_prolog_flag(debug, false), !. '$enable_debugging' :- - nb_setval('$debug_status', state(creep, 0, stop)), - '$trace_on', !, + '__NB_getval__'('$trace',Trace,fail), + nb_setval('$debug_status', state(creep, 0, stop,Trace)), + Trace = on, !, '$creep'. '$enable_debugging'. '$trace_on' :- - '__NB_getval__'('$debug_status', state(_Creep, GN, Spy), fail), - nb_setval('$debug_status', state(zip, GN, Spy)). + '__NB_getval__'('$debug_status', state(_Creep, GN, Spy,_), fail), + '__NB_setval__'('$trace',on), + nb_setval('$debug_status', state(creep, GN, Spy, on)). '$trace_off' :- '__NB_getval__'('$debug_status', state(_Creep, GN, Spy), fail), - nb_setval('$debug_status', state(zip, GN, Spy)). + '__NB_setval__'('$trace',off), + nb_setval('$debug_status', state(zip, GN, Spy,off)). -'$trace_is_off'(_,_) :- +'$creep_is_off'(_,_) :- current_prolog_flag(debug, false), !. -'$trace_is_off'(Module:G, GN0) :- - '__NB_getval__'('$debug_status',state(zip, GN, Spy), fail), +'$creep_is_off'(Module:G, GN0) :- + '__NB_getval__'('$debug_status',state(zip, GN, Spy,_), fail), ( '$pred_being_spied'(G,Module) diff --git a/pl/top.yap b/pl/top.yap index d21fac56d..8031ca654 100644 --- a/pl/top.yap +++ b/pl/top.yap @@ -82,7 +82,8 @@ live :- % stop at spy-points if debugging is on. nb_setval('$debug_run',off), nb_setval('$debug_jump',off), - nb_setval('$debug_status', state(zip, 0, stop)), + '__NB_setval__'('$trace',off), + nb_setval('$debug_status', state(zip, 0, stop,off)), '$command'(Command,Varnames,Pos,top), current_prolog_flag(break_level, BreakLevel), ( @@ -1016,28 +1017,29 @@ log_event( String, Args ) :- LF = ['Break (level ', BreakLevel, ')'|LD] ), current_prolog_flag(debug, DBON), + ( + DBON = true + -> ( - '$trace_on' - -> - ( - var(LF) - -> - LD = ['trace'|LP] - ; - LD = [', trace '|LP] - ) + '__NB_getval__'('$debug_status',state(_, _, _,on), fail), + ( + var(LF) + -> + LD = ['trace'|LP] + ; + LD = [', trace '|LP] + ) ; - DBON == true + (var(LF) -> - (var(LF) - -> - LD = ['debug'|LP] - ; - LD = [', debug'|LP] - ) + LD = ['debug'|LP] + ; + LD = [', debug'|LP] + ) + ) ; LD = LP - ), + ), ( var(LF) ->