2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog @(#)amidefs.h 1.3 3/15/90
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: tracer.h *
|
|
|
|
* Last rev: *
|
|
|
|
* mods: *
|
|
|
|
* comments: definitions for low level tracer *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "Yap.h"
|
|
|
|
|
|
|
|
#ifdef LOW_LEVEL_TRACER
|
|
|
|
|
|
|
|
#include "Yatom.h"
|
2001-08-08 22:17:27 +01:00
|
|
|
#include "Heap.h"
|
2001-04-09 20:54:03 +01:00
|
|
|
#include "yapio.h"
|
|
|
|
#include "tracer.h"
|
|
|
|
|
|
|
|
STATIC_PROTO(int TracePutchar, (int, int));
|
|
|
|
STATIC_PROTO(void send_tracer_message, (char *, char *, Int, char *, CELL *));
|
|
|
|
|
|
|
|
static int do_trace_primitives = TRUE;
|
|
|
|
|
2001-06-13 18:52:33 +01:00
|
|
|
static int
|
2001-04-09 20:54:03 +01:00
|
|
|
TracePutchar(int sno, int ch)
|
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
return(putc(ch, Yap_stderr)); /* use standard error stream, which is supposed to be 2*/
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
send_tracer_message(char *start, char *name, Int arity, char *mname, CELL *args)
|
|
|
|
{
|
|
|
|
if (name == NULL) {
|
|
|
|
#ifdef YAPOR
|
2002-11-18 18:18:05 +00:00
|
|
|
fprintf(Yap_stderr, "(%d)%s", worker_id, start);
|
2001-04-09 20:54:03 +01:00
|
|
|
#else
|
2002-11-18 18:18:05 +00:00
|
|
|
fprintf(Yap_stderr, "%s", start);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (arity) {
|
2002-11-18 18:18:05 +00:00
|
|
|
fprintf(Yap_stderr, "%s %s:%s(", start, mname, name);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
fprintf(Yap_stderr, "%s %s:%s", start, mname, name);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
for (i= 0; i < arity; i++) {
|
2002-11-18 18:18:05 +00:00
|
|
|
if (i > 0) fprintf(Yap_stderr, ",");
|
2001-04-09 20:54:03 +01:00
|
|
|
#if DEBUG
|
|
|
|
#if COROUTINING
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Portray_delays = TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_plwrite(args[i], TracePutchar, Handle_vars_f);
|
2001-04-09 20:54:03 +01:00
|
|
|
#if DEBUG
|
|
|
|
#if COROUTINING
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Portray_delays = FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
if (arity) fprintf(Yap_stderr, ")");
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
fprintf(Yap_stderr, "\n");
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-01-03 16:27:00 +00:00
|
|
|
#if defined(__GNUC__)
|
|
|
|
unsigned long long vsc_count;
|
|
|
|
#else
|
2001-04-09 20:54:03 +01:00
|
|
|
unsigned long vsc_count;
|
2002-01-03 16:27:00 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
static int
|
|
|
|
check_trail_consistency(void) {
|
|
|
|
tr_fr_ptr ptr = TR;
|
2002-11-18 18:18:05 +00:00
|
|
|
while (ptr > (CELL *)Yap_TrailBase) {
|
2001-04-09 20:54:03 +01:00
|
|
|
ptr = --ptr;
|
|
|
|
if (!IsVarTerm(TrailTerm(ptr))) {
|
|
|
|
if (IsApplTerm(TrailTerm(ptr))) {
|
|
|
|
CELL *cptr = (CELL *)ptr;
|
|
|
|
ptr = (tr_fr_ptr)(cptr-1);
|
|
|
|
} else {
|
|
|
|
if (IsPairTerm(TrailTerm(ptr))) {
|
|
|
|
CELL *p = RepPair(TrailTerm(ptr));
|
|
|
|
if (p < H0) continue;
|
|
|
|
}
|
|
|
|
printf("Oops at call %ld, B->cp(%p) TR(%p) pt(%p)\n", vsc_count,B->cp_tr, TR, ptr);
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2001-05-08 21:39:01 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
void
|
|
|
|
low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
char *mname;
|
|
|
|
Int arity;
|
2002-01-18 15:55:33 +00:00
|
|
|
/* extern int gc_calls; */
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
vsc_count++;
|
2002-10-17 01:05:29 +01:00
|
|
|
/* return;*/
|
2003-02-11 16:33:24 +00:00
|
|
|
#ifdef COMMENTED
|
2003-02-12 14:02:42 +00:00
|
|
|
if (vsc_count < 124840LL) return;
|
|
|
|
if (vsc_count == 124881LL) {
|
2003-02-11 16:33:24 +00:00
|
|
|
printf("Here I go\n");
|
|
|
|
}
|
|
|
|
if (vsc_count > 500000) exit(0);
|
|
|
|
if (gc_calls < 1) return;
|
|
|
|
#endif
|
2002-01-14 22:26:53 +00:00
|
|
|
#if defined(__GNUC__)
|
2003-02-11 16:33:24 +00:00
|
|
|
fprintf(Yap_stderr,"%llu ", vsc_count);
|
2002-01-14 22:26:53 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
/* check_trail_consistency(); */
|
|
|
|
if (pred == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pred->ModuleOfPred == 0 && !do_trace_primitives) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (port) {
|
|
|
|
case enter_pred:
|
2002-11-18 18:18:05 +00:00
|
|
|
mname = RepAtom(AtomOfTerm(Yap_Module_Name((CODEADDR)pred)))->StrOfAE;
|
2001-04-09 20:54:03 +01:00
|
|
|
arity = pred->ArityOfPE;
|
2001-10-30 16:42:05 +00:00
|
|
|
if (arity == 0)
|
|
|
|
s = RepAtom((Atom)pred->FunctorOfPred)->StrOfAE;
|
|
|
|
else
|
2001-10-03 14:39:16 +01:00
|
|
|
s = RepAtom(NameOfFunctor((pred->FunctorOfPred)))->StrOfAE;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* if ((pred->ModuleOfPred == 0) && (s[0] == '$'))
|
|
|
|
return; */
|
|
|
|
send_tracer_message("CALL: ", s, arity, mname, args);
|
|
|
|
break;
|
|
|
|
case try_or:
|
|
|
|
send_tracer_message("TRY_OR ", NULL, 0, NULL, args);
|
|
|
|
break;
|
|
|
|
case retry_or:
|
|
|
|
send_tracer_message("FAIL ", NULL, 0, NULL, args);
|
|
|
|
send_tracer_message("RETRY_OR ", NULL, 0, NULL, args);
|
|
|
|
break;
|
|
|
|
case retry_table_producer:
|
|
|
|
send_tracer_message("FAIL ", NULL, 0, NULL, args);
|
|
|
|
/* HANDLE METACALLS */
|
|
|
|
if (pred == NULL) {
|
|
|
|
send_tracer_message("RETRY TABLE: ", NULL, 0, NULL, args);
|
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
mname = RepAtom(AtomOfTerm(Yap_Module_Name((CODEADDR)pred)))->StrOfAE;
|
2001-04-09 20:54:03 +01:00
|
|
|
arity = pred->ArityOfPE;
|
2001-10-30 16:42:05 +00:00
|
|
|
if (arity == 0)
|
|
|
|
s = RepAtom((Atom)pred->FunctorOfPred)->StrOfAE;
|
|
|
|
else
|
|
|
|
s = RepAtom(NameOfFunctor((pred->FunctorOfPred)))->StrOfAE;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* if ((pred->ModuleOfPred == 0) && (s[0] == '$'))
|
|
|
|
return; */
|
|
|
|
send_tracer_message("RETRY PRODUCER: ", s, 0, mname, NULL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case retry_table_consumer:
|
|
|
|
send_tracer_message("FAIL ", NULL, 0, NULL, args);
|
|
|
|
/* HANDLE METACALLS */
|
|
|
|
if (pred == NULL) {
|
|
|
|
send_tracer_message("RETRY TABLE: ", NULL, 0, NULL, args);
|
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
mname = RepAtom(AtomOfTerm(Yap_Module_Name((CODEADDR)pred)))->StrOfAE;
|
2001-04-09 20:54:03 +01:00
|
|
|
arity = pred->ArityOfPE;
|
2001-10-30 16:42:05 +00:00
|
|
|
if (arity == 0)
|
|
|
|
s = RepAtom((Atom)pred->FunctorOfPred)->StrOfAE;
|
|
|
|
else
|
|
|
|
s = RepAtom(NameOfFunctor((pred->FunctorOfPred)))->StrOfAE;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* if ((pred->ModuleOfPred == 0) && (s[0] == '$'))
|
|
|
|
return; */
|
|
|
|
send_tracer_message("RETRY CONSUMER: ", s, 0, mname, NULL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case retry_pred:
|
2002-11-18 18:18:05 +00:00
|
|
|
mname = RepAtom(AtomOfTerm(Yap_Module_Name((CODEADDR)pred)))->StrOfAE;
|
2001-04-09 20:54:03 +01:00
|
|
|
arity = pred->ArityOfPE;
|
2001-10-30 16:42:05 +00:00
|
|
|
if (arity == 0)
|
|
|
|
s = RepAtom((Atom)pred->FunctorOfPred)->StrOfAE;
|
|
|
|
else
|
|
|
|
s = RepAtom(NameOfFunctor((pred->FunctorOfPred)))->StrOfAE;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* if ((pred->ModuleOfPred == 0) && (s[0] == '$'))
|
|
|
|
return; */
|
|
|
|
send_tracer_message("FAIL ", NULL, 0, NULL, args);
|
|
|
|
send_tracer_message("RETRY: ", s, arity, mname, args);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
toggle_low_level_trace(void)
|
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_do_low_level_trace = !Yap_do_low_level_trace;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int p_start_low_level_trace(void)
|
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_do_low_level_trace = TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Int p_stop_low_level_trace(void)
|
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_do_low_level_trace = FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
do_trace_primitives = TRUE;
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitLowLevelTrace(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPred("start_low_level_trace", 0, p_start_low_level_trace, SafePredFlag);
|
|
|
|
Yap_InitCPred("stop_low_level_trace", 0, p_stop_low_level_trace, SafePredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|