2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
2016-07-31 10:42:00 +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 *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#include "Yap.h"
|
|
|
|
|
|
|
|
#ifdef LOW_LEVEL_TRACER
|
|
|
|
|
2009-10-23 14:22:17 +01:00
|
|
|
#include "YapHeap.h"
|
2016-08-30 17:01:55 +01:00
|
|
|
#include "YapText.h"
|
2016-03-29 01:55:12 +01:00
|
|
|
#include "Yatom.h"
|
2009-02-26 23:06:27 +00:00
|
|
|
#include "attvar.h"
|
2011-08-31 21:59:30 +01:00
|
|
|
#include "clause.h"
|
2016-07-31 10:42:00 +01:00
|
|
|
#include "iopreds.h"
|
2016-08-30 17:01:55 +01:00
|
|
|
#include "tracer.h"
|
|
|
|
#include "yapio.h"
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2017-02-20 15:21:48 +00:00
|
|
|
static char *send_tracer_message(char *start, char *name, arity_t arity,
|
|
|
|
char *mname, CELL *args, char **s0, char *s,
|
|
|
|
char **top) {
|
|
|
|
bool expand = false;
|
|
|
|
size_t max = *top - (s + 1);
|
|
|
|
int d, min = 1024;
|
|
|
|
char *s1 = s;
|
|
|
|
do {
|
|
|
|
if (expand || max < 32) {
|
|
|
|
Int cbeg = s1 - *s0;
|
|
|
|
max = *top - *s0;
|
|
|
|
max += min;
|
|
|
|
*s0 = Realloc(*s0, max);
|
|
|
|
|
|
|
|
*top = *s0 + max;
|
|
|
|
max--;
|
|
|
|
s1 = *s0 + cbeg;
|
|
|
|
s = s1;
|
|
|
|
expand = false;
|
|
|
|
}
|
|
|
|
min = 1024;
|
|
|
|
if (name == NULL) {
|
2015-10-22 00:45:21 +01:00
|
|
|
#ifdef YAPOR
|
2017-02-20 15:21:48 +00:00
|
|
|
d = snprintf(s, max, "(%d)%s", worker_id, start);
|
2001-04-09 20:54:03 +01:00
|
|
|
#else
|
2017-02-20 15:21:48 +00:00
|
|
|
d = snprintf(s, max, "%s", start);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
} else {
|
2017-02-20 15:21:48 +00:00
|
|
|
|
|
|
|
if (arity) {
|
|
|
|
if (args)
|
|
|
|
d = snprintf(s, max, "%s %s:%s(", start, mname, name);
|
|
|
|
else
|
|
|
|
d = snprintf(s, max, "%s %s:%s/%lu", start, mname, name,
|
|
|
|
(unsigned long int)arity);
|
|
|
|
} else {
|
|
|
|
d = snprintf(s, max, "%s %s:%s", start, mname, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (d >= max) {
|
|
|
|
expand = true;
|
|
|
|
min = d + 1024;
|
|
|
|
continue;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2017-02-20 15:21:48 +00:00
|
|
|
max -= d;
|
|
|
|
s += d;
|
2008-09-14 05:11:35 +01:00
|
|
|
if (args) {
|
2017-02-20 15:21:48 +00:00
|
|
|
int i;
|
2015-10-22 00:45:21 +01:00
|
|
|
for (i = 0; i < arity; i++) {
|
2017-02-20 15:21:48 +00:00
|
|
|
if (i > 0) {
|
|
|
|
if (max > 16) {
|
|
|
|
*s++ = ',';
|
|
|
|
*s++ = ' ';
|
|
|
|
max-=2;
|
|
|
|
} else {
|
|
|
|
expand = true;
|
|
|
|
continue;
|
|
|
|
}
|
2016-08-30 17:01:55 +01:00
|
|
|
}
|
2017-02-20 15:21:48 +00:00
|
|
|
const char *sn = Yap_TermToString(args[i], NULL, LOCAL_encoding,
|
2016-08-30 17:01:55 +01:00
|
|
|
Quote_illegal_f | Handle_vars_f);
|
2016-09-09 04:34:45 +01:00
|
|
|
size_t sz;
|
2017-02-20 15:21:48 +00:00
|
|
|
if (sn == NULL) {
|
|
|
|
sn = "<* error *>";
|
|
|
|
}
|
|
|
|
sz = strlen(sn);
|
|
|
|
if (max <= sz) {
|
|
|
|
min = sz + 1024;
|
|
|
|
expand = true;
|
|
|
|
continue;
|
2016-08-30 17:01:55 +01:00
|
|
|
}
|
2017-02-20 15:21:48 +00:00
|
|
|
strcpy(s, sn);
|
2016-09-09 04:34:45 +01:00
|
|
|
s += sz;
|
2017-02-20 15:21:48 +00:00
|
|
|
max -= sz;
|
2008-09-14 05:11:35 +01:00
|
|
|
}
|
2008-09-23 22:49:44 +01:00
|
|
|
if (arity) {
|
2017-02-20 15:21:48 +00:00
|
|
|
*s++ = ' ';
|
2016-08-30 17:01:55 +01:00
|
|
|
*s++ = ')';
|
2017-02-20 15:21:48 +00:00
|
|
|
max -= 2;
|
2008-09-23 22:49:44 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2017-02-20 15:21:48 +00:00
|
|
|
} while (expand);
|
2016-09-09 04:34:45 +01:00
|
|
|
s[0] = '\0';
|
2016-08-30 17:01:55 +01:00
|
|
|
return s;
|
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
|
|
|
|
2004-02-21 20:25:45 +00:00
|
|
|
#if THREADS
|
|
|
|
static int thread_trace;
|
|
|
|
#endif
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/*
|
|
|
|
static int
|
|
|
|
check_trail_consistency(void) {
|
|
|
|
tr_fr_ptr ptr = TR;
|
2011-05-23 16:19:47 +01:00
|
|
|
while (ptr > (CELL *)LOCAL_TrailBase) {
|
2001-04-09 20:54:03 +01:00
|
|
|
ptr = --ptr;
|
|
|
|
if (!IsVarTerm(TrailTerm(ptr))) {
|
|
|
|
if (IsApplTerm(TrailTerm(ptr))) {
|
2015-10-22 00:45:21 +01:00
|
|
|
CELL *cptr = (CELL *)ptr;
|
|
|
|
ptr = (tr_fr_ptr)(cptr-1);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2015-10-22 00:45:21 +01:00
|
|
|
if (IsPairTerm(TrailTerm(ptr))) {
|
|
|
|
CELL *p = RepPair(TrailTerm(ptr));
|
|
|
|
if IsAttVar(p) continue;
|
|
|
|
}
|
|
|
|
printf("Oops at call %ld, B->cp(%p) TR(%p) pt(%p)\n",
|
|
|
|
vsc_count,B->cp_tr, TR, ptr);
|
|
|
|
return(FALSE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2015-07-06 11:59:50 +01:00
|
|
|
volatile int v;
|
2001-05-08 21:39:01 +01:00
|
|
|
|
2003-11-12 12:33:31 +00:00
|
|
|
CELL old_value = 0L, old_value2 = 0L;
|
|
|
|
|
2015-06-19 10:10:02 +01:00
|
|
|
void jmp_deb(int), jmp_deb2(void);
|
2005-11-15 00:50:49 +00:00
|
|
|
|
2015-10-22 00:45:21 +01:00
|
|
|
void jmp_deb2(void) { fprintf(stderr, "Here\n"); }
|
2015-06-19 10:10:02 +01:00
|
|
|
|
2015-10-22 00:45:21 +01:00
|
|
|
void jmp_deb(int i) {
|
|
|
|
if (i)
|
2017-06-12 18:00:47 +01:00
|
|
|
printf("Here we go " Int_FORMAT "\n", old_value++);
|
2015-10-22 00:45:21 +01:00
|
|
|
if (old_value == 716)
|
|
|
|
jmp_deb2();
|
2015-10-13 02:21:30 +01:00
|
|
|
}
|
2004-06-17 23:07:23 +01:00
|
|
|
|
2005-11-04 01:17:17 +00:00
|
|
|
struct various_codes *sc;
|
|
|
|
|
2006-04-28 14:23:23 +01:00
|
|
|
/*
|
|
|
|
CELL array[332];
|
|
|
|
|
|
|
|
int found = FALSE;
|
|
|
|
|
|
|
|
static void
|
|
|
|
check_area(void)
|
|
|
|
{
|
|
|
|
int i, first = -1;
|
|
|
|
for (i= 0; i < 332; i++) {
|
|
|
|
if (array[i] !=((CELL *)0x187a800)[i]) {
|
|
|
|
if (first != -1) {
|
2015-10-22 00:45:21 +01:00
|
|
|
first = i;
|
|
|
|
found = TRUE;
|
2006-04-28 14:23:23 +01:00
|
|
|
}
|
2015-06-19 01:30:13 +01:00
|
|
|
fprintf(stderr,"%lld changed %d\n",vsc_count,i);
|
2006-04-28 14:23:23 +01:00
|
|
|
}
|
|
|
|
array[i] = ((CELL *)0x187a800)[i];
|
|
|
|
}
|
|
|
|
if (first != -1)
|
|
|
|
jmp_deb(i);
|
|
|
|
}
|
|
|
|
*/
|
2016-03-29 01:55:12 +01:00
|
|
|
// PredEntry *old_p[10000];
|
|
|
|
// Term old_x1[10000], old_x2[10000], old_x3[10000];
|
2008-01-24 22:47:14 +00:00
|
|
|
|
2016-08-30 17:01:55 +01:00
|
|
|
// static CELL oldv = 0;
|
2014-09-02 20:19:23 +01:00
|
|
|
|
2017-02-20 15:21:48 +00:00
|
|
|
bool low_level_trace__(yap_low_level_port port, PredEntry *pred, CELL *args) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2001-04-09 20:54:03 +01:00
|
|
|
char *s;
|
|
|
|
char *mname;
|
|
|
|
Int arity;
|
2017-02-20 15:21:48 +00:00
|
|
|
int l = push_text_stack();
|
2002-01-18 15:55:33 +00:00
|
|
|
/* extern int gc_calls; */
|
2014-01-24 19:59:42 +00:00
|
|
|
vsc_count++;
|
2016-08-30 17:01:55 +01:00
|
|
|
// if (HR < ASP ) return;
|
|
|
|
// fif (vsc_count == 12534) jmp_deb( 2 );
|
2017-02-20 15:21:48 +00:00
|
|
|
char *buf = Malloc(512), *top = buf + 511, *b = buf;
|
2013-11-25 22:59:52 +00:00
|
|
|
|
|
|
|
// if (!worker_id) return;
|
2016-01-06 12:40:01 +00:00
|
|
|
LOCK(Yap_low_level_trace_lock);
|
2005-11-04 01:17:17 +00:00
|
|
|
sc = Yap_heap_regs;
|
2016-01-03 02:06:09 +00:00
|
|
|
// if (vsc_count == 161862) jmp_deb(1);
|
|
|
|
#ifdef THREADS
|
2013-11-16 23:52:04 +00:00
|
|
|
LOCAL_ThreadHandle.thread_inst_count++;
|
2015-10-22 00:45:21 +01:00
|
|
|
#endif
|
2013-11-16 23:52:04 +00:00
|
|
|
#ifdef COMMENTED
|
2016-08-30 17:01:55 +01:00
|
|
|
b = snprintf(b, top - b, "in %p\n");
|
2015-10-22 00:45:21 +01:00
|
|
|
CELL *gc_ENV = ENV;
|
|
|
|
while (gc_ENV != NULL) { /* no more environments */
|
2016-08-30 17:01:55 +01:00
|
|
|
b = snprintf(b, top - b, "%ld\n", LCL0 - gc_ENV);
|
2015-10-22 00:45:21 +01:00
|
|
|
gc_ENV = (CELL *)gc_ENV[E_E]; /* link to prev
|
|
|
|
* environment */
|
2013-11-15 01:10:25 +00:00
|
|
|
}
|
|
|
|
return;
|
2011-08-31 21:59:30 +01:00
|
|
|
{
|
|
|
|
choiceptr b_p = B;
|
|
|
|
while (b_p) {
|
2016-08-30 17:01:55 +01:00
|
|
|
b = snprintf(b, top - b, "%p %ld\n", b_p,
|
|
|
|
Yap_op_from_opcode(b_p->cp_ap->opc));
|
2011-08-31 21:59:30 +01:00
|
|
|
b_p = b_p->cp_b;
|
|
|
|
}
|
|
|
|
}
|
2015-10-22 00:45:21 +01:00
|
|
|
{
|
|
|
|
choiceptr myB = B;
|
|
|
|
while (myB)
|
|
|
|
myB = myB->cp_b;
|
2011-02-14 19:29:20 +00:00
|
|
|
}
|
2015-10-22 00:45:21 +01:00
|
|
|
//*(H0+(0xb65f2850-0xb64b2008)/sizeof(CELL))==0xc ||
|
|
|
|
// 0x4fd4d
|
2006-12-27 01:32:38 +00:00
|
|
|
if (vsc_count > 1388060LL && vsc_count < 1388070LL) {
|
2015-10-22 00:45:21 +01:00
|
|
|
if (vsc_count == 1388061LL)
|
2006-12-27 01:32:38 +00:00
|
|
|
jmp_deb(1);
|
|
|
|
if (vsc_count % 1LL == 0) {
|
|
|
|
UInt sz = Yap_regp->H0_[17];
|
2015-10-22 00:45:21 +01:00
|
|
|
UInt end = sizeof(MP_INT) / sizeof(CELL) + sz + 1;
|
2016-08-30 17:01:55 +01:00
|
|
|
b = snprintf(b, top - b, "VAL %lld %d %x/%x\n", vsc_count, sz, H0[16],
|
|
|
|
H0[16 + end]);
|
2006-12-27 01:32:38 +00:00
|
|
|
}
|
2015-10-22 00:45:21 +01:00
|
|
|
} else
|
|
|
|
return;
|
2011-04-22 12:20:52 +01:00
|
|
|
{
|
2011-05-23 16:19:47 +01:00
|
|
|
tr_fr_ptr pt = (tr_fr_ptr)LOCAL_TrailBase;
|
2011-04-22 12:20:52 +01:00
|
|
|
if (pt[140].term == 0 && pt[140].value != 0)
|
|
|
|
jmp_deb(1);
|
|
|
|
}
|
2015-10-22 00:45:21 +01:00
|
|
|
if (worker_id != 04 || worker_id != 03)
|
|
|
|
return;
|
2004-02-19 19:24:46 +00:00
|
|
|
// if (vsc_count == 218280)
|
|
|
|
// vsc_xstop = 1;
|
2004-04-20 23:08:57 +01:00
|
|
|
if (vsc_count < 1468068888) {
|
2004-12-02 06:06:47 +00:00
|
|
|
UNLOCK(Yap_heap_regs->low_level_trace_lock);
|
2004-02-19 19:24:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-10-22 00:45:21 +01:00
|
|
|
if (port != enter_pred || !pred || pred->ArityOfPE != 4 ||
|
|
|
|
strcmp(RepAtom(NameOfFunctor(pred->FunctorOfPred))->StrOfAE,
|
|
|
|
"in_between_target_phrases")) {
|
2006-04-20 18:29:46 +01:00
|
|
|
UNLOCK(Yap_heap_regs->low_level_trace_lock);
|
2003-11-12 12:33:31 +00:00
|
|
|
return;
|
2006-04-20 18:29:46 +01:00
|
|
|
}
|
|
|
|
if (vsc_count < 1246949400LL) {
|
|
|
|
UNLOCK(Yap_heap_regs->low_level_trace_lock);
|
2003-11-12 12:33:31 +00:00
|
|
|
return;
|
2006-04-20 18:29:46 +01:00
|
|
|
}
|
2003-11-12 12:33:31 +00:00
|
|
|
if (vsc_count == 1246949493LL)
|
|
|
|
vsc_xstop = TRUE;
|
2006-04-20 18:29:46 +01:00
|
|
|
if (vsc_count < 5646100000LL) {
|
|
|
|
UNLOCK(Yap_heap_regs->low_level_trace_lock);
|
2003-10-30 22:52:46 +00:00
|
|
|
return;
|
2006-04-20 18:29:46 +01:00
|
|
|
}
|
2003-10-30 22:52:46 +00:00
|
|
|
if (vsc_count == 5646100441LL)
|
|
|
|
vsc_xstop = TRUE;
|
2003-10-28 01:16:03 +00:00
|
|
|
if (vsc_count < 2923351500LL) {
|
2006-04-20 18:29:46 +01:00
|
|
|
UNLOCK(Yap_heap_regs->low_level_trace_lock);
|
2003-09-15 18:56:27 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-10-22 00:45:21 +01:00
|
|
|
if (vsc_count == 123536441LL)
|
|
|
|
vsc_xstop = 1;
|
2003-08-27 14:37:10 +01:00
|
|
|
if (vsc_count < 5530257LL) {
|
2006-04-20 18:29:46 +01:00
|
|
|
UNLOCK(Yap_heap_regs->low_level_trace_lock);
|
2003-08-27 14:37:10 +01:00
|
|
|
return;
|
|
|
|
}
|
2004-04-29 04:45:50 +01:00
|
|
|
if (vsc_count == 9414280LL) {
|
2003-08-27 14:37:10 +01:00
|
|
|
vsc_xstop = TRUE;
|
|
|
|
}
|
|
|
|
if (vsc_count < 3399741LL) {
|
2006-04-20 18:29:46 +01:00
|
|
|
UNLOCK(Yap_heap_regs->low_level_trace_lock);
|
2003-08-27 14:37:10 +01:00
|
|
|
return;
|
|
|
|
}
|
2011-04-22 12:20:52 +01:00
|
|
|
if (TR_FZ > TR)
|
|
|
|
jmp_deb(1);
|
|
|
|
{
|
2011-05-23 16:19:47 +01:00
|
|
|
tr_fr_ptr pt = (tr_fr_ptr)LOCAL_TrailBase;
|
2015-10-22 00:45:21 +01:00
|
|
|
if (pt[153].term == 0 && pt[153].value == 0 && pt[154].term != 0 &&
|
|
|
|
pt[154].value != 0 && (TR > pt + 154 || TR_FZ > pt + 154))
|
2011-04-22 12:20:52 +01:00
|
|
|
jmp_deb(2);
|
2015-10-22 00:45:21 +01:00
|
|
|
if (pt[635].term == 0 && pt[635].value == 0 && pt[636].term != 0 &&
|
|
|
|
pt[636].value != 0 && (TR > pt + 636 || TR_FZ > pt + 636))
|
2011-04-22 12:20:52 +01:00
|
|
|
jmp_deb(3);
|
2015-10-22 00:45:21 +01:00
|
|
|
if (pt[138].term == 0 && pt[138].value == 0 && pt[139].term != 0 &&
|
|
|
|
pt[139].value != 0 && (TR > pt + 138 || TR_FZ > pt + 138))
|
2011-04-22 12:20:52 +01:00
|
|
|
jmp_deb(4);
|
|
|
|
}
|
|
|
|
if (vsc_count == 287939LL)
|
|
|
|
jmp_deb(1);
|
|
|
|
if (vsc_count == 173118LL)
|
|
|
|
jmp_deb(1);
|
|
|
|
if (!(vsc_count >= 287934LL && vsc_count <= 287939LL) &&
|
2016-07-31 10:42:00 +01:00
|
|
|
!(vsc_count >= 173100LL && vsc_count <= 173239LL) && vsc_count != -1) {
|
2011-04-22 12:20:52 +01:00
|
|
|
return;
|
2016-07-31 10:42:00 +01:00
|
|
|
}
|
2003-08-27 14:37:10 +01:00
|
|
|
if (vsc_count == 51021) {
|
|
|
|
printf("Here I go\n");
|
|
|
|
}
|
2006-04-20 18:29:46 +01:00
|
|
|
if (vsc_count < 52000) {
|
|
|
|
UNLOCK(Yap_heap_regs->low_level_trace_lock);
|
|
|
|
return;
|
|
|
|
}
|
2015-10-22 00:45:21 +01:00
|
|
|
if (vsc_count > 52000)
|
|
|
|
exit(0);
|
2006-04-20 18:29:46 +01:00
|
|
|
UNLOCK(Yap_heap_regs->low_level_trace_lock);
|
2003-04-30 18:46:05 +01:00
|
|
|
return;
|
2003-08-27 14:37:10 +01:00
|
|
|
if (vsc_count == 837074) {
|
2003-02-11 16:33:24 +00:00
|
|
|
printf("Here I go\n");
|
2015-10-22 00:45:21 +01:00
|
|
|
}
|
2006-04-20 18:29:46 +01:00
|
|
|
if (gc_calls < 1) {
|
|
|
|
UNLOCK(Yap_heap_regs->low_level_trace_lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
{
|
2015-10-22 00:45:21 +01:00
|
|
|
CELL *env_ptr = ENV;
|
2006-04-20 18:29:46 +01:00
|
|
|
PredEntry *p;
|
|
|
|
|
|
|
|
while (env_ptr) {
|
|
|
|
PredEntry *pe = EnvPreg(env_ptr[E_CP]);
|
|
|
|
|
|
|
|
if (p == pe) {
|
2015-10-22 00:45:21 +01:00
|
|
|
UNLOCK(Yap_heap_regs->low_level_trace_lock);
|
2017-02-20 15:21:48 +00:00
|
|
|
pop_text_stack(l);
|
|
|
|
ReleaseAndReturn(true);
|
2004-06-09 04:32:03 +01:00
|
|
|
}
|
2006-04-20 18:29:46 +01:00
|
|
|
if (env_ptr != NULL)
|
2015-10-22 00:45:21 +01:00
|
|
|
env_ptr = (CELL *)(env_ptr[E_E]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
2003-02-11 16:33:24 +00:00
|
|
|
#endif
|
2017-09-06 01:13:00 +01:00
|
|
|
b += snprintf(b, top - b, "%llud "UInt_FORMAT " ", vsc_count, LCL0 - (CELL *)B);
|
2017-06-12 18:00:47 +01:00
|
|
|
b += snprintf(b, top - b, Int_FORMAT " ", LCL0 - (CELL *)Yap_REGS.CUT_C_TOP);
|
2004-01-23 02:23:51 +00:00
|
|
|
#if defined(THREADS) || defined(YAPOR)
|
2016-08-30 17:01:55 +01:00
|
|
|
b += snprintf(b, top - b, "(%d)", worker_id);
|
2002-01-14 22:26:53 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
/* check_trail_consistency(); */
|
2006-04-20 18:29:46 +01:00
|
|
|
if (pred == NULL) {
|
2016-01-06 12:40:01 +00:00
|
|
|
UNLOCK(Yap_low_level_trace_lock);
|
2017-02-20 15:21:48 +00:00
|
|
|
pop_text_stack(l);
|
|
|
|
ReleaseAndReturn(true);
|
2006-04-20 18:29:46 +01:00
|
|
|
}
|
2016-01-31 10:22:24 +00:00
|
|
|
if (pred->ModuleOfPred == PROLOG_MODULE) {
|
|
|
|
if (!LOCAL_do_trace_primitives) {
|
2016-03-29 01:55:12 +01:00
|
|
|
UNLOCK(Yap_low_level_trace_lock);
|
2017-02-20 15:21:48 +00:00
|
|
|
ReleaseAndReturn(true);
|
2016-01-31 10:22:24 +00:00
|
|
|
}
|
|
|
|
mname = "prolog";
|
|
|
|
} else {
|
2016-03-29 01:55:12 +01:00
|
|
|
mname = RepAtom(AtomOfTerm(Yap_Module_Name(pred)))->StrOfAE;
|
2006-04-20 18:29:46 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
switch (port) {
|
|
|
|
case enter_pred:
|
|
|
|
arity = pred->ArityOfPE;
|
2016-01-31 10:22:24 +00:00
|
|
|
if (arity == 0) {
|
2015-09-21 23:05:36 +01:00
|
|
|
s = (char *)RepAtom((Atom)pred->FunctorOfPred)->StrOfAE;
|
2016-01-31 10:22:24 +00:00
|
|
|
} else {
|
2015-09-21 23:05:36 +01:00
|
|
|
s = (char *)RepAtom(NameOfFunctor((pred->FunctorOfPred)))->StrOfAE;
|
2016-01-31 10:22:24 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
/* if ((pred->ModuleOfPred == 0) && (s[0] == '$'))
|
2015-10-22 00:45:21 +01:00
|
|
|
return; */
|
2017-02-20 15:21:48 +00:00
|
|
|
b = send_tracer_message("CALL: ", s, arity, mname, args, &buf, b, &top);
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
case try_or:
|
2017-02-20 15:21:48 +00:00
|
|
|
b = send_tracer_message("TRY_OR ", NULL, 0, NULL, args, &buf, b, &top);
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
case retry_or:
|
2017-02-20 15:21:48 +00:00
|
|
|
b = send_tracer_message("FAIL ", NULL, 0, NULL, args, &buf, b, &top);
|
|
|
|
b = send_tracer_message("RETRY_OR ", NULL, 0, NULL, args, &buf, b, &top);
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
2005-07-06 20:34:12 +01:00
|
|
|
case retry_table_generator:
|
2017-02-20 15:21:48 +00:00
|
|
|
b = send_tracer_message("FAIL ", NULL, 0, NULL, args, &buf, b, &top);
|
2015-09-21 23:05:36 +01:00
|
|
|
mname = (char *)RepAtom(AtomOfTerm(Yap_Module_Name(pred)))->StrOfAE;
|
2005-07-06 20:34:12 +01:00
|
|
|
arity = pred->ArityOfPE;
|
|
|
|
if (arity == 0)
|
2015-09-21 23:05:36 +01:00
|
|
|
s = (char *)RepAtom((Atom)pred->FunctorOfPred)->StrOfAE;
|
2005-07-06 20:34:12 +01:00
|
|
|
else
|
2015-09-21 23:05:36 +01:00
|
|
|
s = (char *)RepAtom(NameOfFunctor((pred->FunctorOfPred)))->StrOfAE;
|
2017-02-20 15:21:48 +00:00
|
|
|
b = send_tracer_message("RETRY GENERATOR: ", s, arity, mname, args, &buf, b,
|
|
|
|
&top);
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
case retry_table_consumer:
|
2017-02-20 15:21:48 +00:00
|
|
|
b = send_tracer_message("FAIL ", NULL, 0, NULL, args, &buf, b, &top);
|
2015-09-21 23:05:36 +01:00
|
|
|
mname = (char *)RepAtom(AtomOfTerm(Yap_Module_Name(pred)))->StrOfAE;
|
2005-07-06 20:34:12 +01:00
|
|
|
arity = pred->ArityOfPE;
|
2015-10-22 00:45:21 +01:00
|
|
|
if (arity == 0) {
|
2015-09-21 23:05:36 +01:00
|
|
|
s = (char *)RepAtom((Atom)pred->FunctorOfPred)->StrOfAE;
|
2017-02-20 15:21:48 +00:00
|
|
|
b = send_tracer_message("RETRY CONSUMER: ", s, 0, mname, NULL, &buf, b,
|
|
|
|
&top);
|
2008-09-14 05:11:35 +01:00
|
|
|
} else {
|
2015-09-21 23:05:36 +01:00
|
|
|
s = (char *)RepAtom(NameOfFunctor((pred->FunctorOfPred)))->StrOfAE;
|
2016-08-30 17:01:55 +01:00
|
|
|
b = send_tracer_message("RETRY CONSUMER: ", s, pred->ArityOfPE, mname,
|
2017-02-20 15:21:48 +00:00
|
|
|
NULL, &buf, b, &top);
|
2008-09-14 05:11:35 +01:00
|
|
|
}
|
2005-07-06 20:34:12 +01:00
|
|
|
break;
|
|
|
|
case retry_table_loader:
|
2017-02-20 15:21:48 +00:00
|
|
|
b = send_tracer_message("FAIL ", NULL, 0, NULL, args, &buf, b, &top);
|
2005-07-06 20:34:12 +01:00
|
|
|
if (pred == UndefCode) {
|
2017-02-20 15:21:48 +00:00
|
|
|
b = send_tracer_message("RETRY LOADER ", NULL, 0, NULL, NULL, &buf, b,
|
|
|
|
&top);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2015-09-21 23:05:36 +01:00
|
|
|
mname = (char *)RepAtom(AtomOfTerm(Yap_Module_Name(pred)))->StrOfAE;
|
2001-04-09 20:54:03 +01:00
|
|
|
arity = pred->ArityOfPE;
|
2001-10-30 16:42:05 +00:00
|
|
|
if (arity == 0)
|
2015-10-22 00:45:21 +01:00
|
|
|
s = (char *)RepAtom((Atom)pred->FunctorOfPred)->StrOfAE;
|
2001-10-30 16:42:05 +00:00
|
|
|
else
|
2015-10-22 00:45:21 +01:00
|
|
|
s = (char *)RepAtom(NameOfFunctor((pred->FunctorOfPred)))->StrOfAE;
|
2017-02-20 15:21:48 +00:00
|
|
|
b = send_tracer_message("RETRY LOADER: ", s, 0, mname, NULL, &buf, b,
|
|
|
|
&top);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case retry_pred:
|
2017-02-20 15:21:48 +00:00
|
|
|
b = send_tracer_message("FAIL ", NULL, 0, NULL, args, &buf, b, &top);
|
2003-10-28 16:20:44 +00:00
|
|
|
if (pred != NULL) {
|
2015-09-21 23:05:36 +01:00
|
|
|
mname = (char *)RepAtom(AtomOfTerm(Yap_Module_Name(pred)))->StrOfAE;
|
2003-10-28 16:20:44 +00:00
|
|
|
arity = pred->ArityOfPE;
|
2004-02-12 12:37:12 +00:00
|
|
|
if (pred->ModuleOfPred == IDB_MODULE) {
|
2015-10-22 00:45:21 +01:00
|
|
|
s = "recorded";
|
|
|
|
arity = 3;
|
2003-10-28 16:20:44 +00:00
|
|
|
} else if (arity == 0) {
|
2015-10-22 00:45:21 +01:00
|
|
|
s = (char *)RepAtom((Atom)pred->FunctorOfPred)->StrOfAE;
|
2003-10-28 16:20:44 +00:00
|
|
|
} else {
|
2015-10-22 00:45:21 +01:00
|
|
|
s = (char *)RepAtom(NameOfFunctor((pred->FunctorOfPred)))->StrOfAE;
|
2003-10-28 16:20:44 +00:00
|
|
|
}
|
2017-02-20 15:21:48 +00:00
|
|
|
b = send_tracer_message("RETRY: ", s, arity, mname, args, &buf, b, &top);
|
2003-08-27 14:37:10 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
}
|
2016-01-06 12:40:01 +00:00
|
|
|
UNLOCK(Yap_low_level_trace_lock);
|
2016-08-30 17:01:55 +01:00
|
|
|
#if __ANDROID__
|
2016-09-09 04:34:45 +01:00
|
|
|
__android_log_print(ANDROID_LOG_DEBUG, "YAPDroid", "%s\n", buf);
|
2016-08-30 17:01:55 +01:00
|
|
|
#else
|
2016-09-09 04:34:45 +01:00
|
|
|
*b++ = '\n';
|
2017-02-20 15:21:48 +00:00
|
|
|
*b = '\0';
|
2016-08-30 17:01:55 +01:00
|
|
|
fputs(buf, stderr);
|
|
|
|
#endif
|
2017-02-20 15:21:48 +00:00
|
|
|
pop_text_stack(l);
|
|
|
|
ReleaseAndReturn(true);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:45:21 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-10-22 00:45:21 +01:00
|
|
|
static Int start_low_level_trace(USES_REGS1) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_do_low_level_trace = TRUE;
|
2015-10-22 00:45:21 +01:00
|
|
|
return (TRUE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:45:21 +01:00
|
|
|
static Int total_choicepoints(USES_REGS1) {
|
|
|
|
return Yap_unify(MkIntegerTerm(LOCAL_total_choicepoints), ARG1);
|
2011-02-08 21:02:10 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:45:21 +01:00
|
|
|
static Int reset_total_choicepoints(USES_REGS1) {
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_total_choicepoints = 0;
|
2011-03-02 09:17:43 +00:00
|
|
|
return TRUE;
|
2011-02-08 21:02:10 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:45:21 +01:00
|
|
|
static Int show_low_level_trace(USES_REGS1) {
|
2017-09-06 01:13:00 +01:00
|
|
|
fprintf(stderr, "Call counter=%lld\n", vsc_count);
|
2015-10-22 00:45:21 +01:00
|
|
|
return (TRUE);
|
2008-08-06 18:32:22 +01:00
|
|
|
}
|
|
|
|
|
2004-02-21 20:25:45 +00:00
|
|
|
#ifdef THREADS
|
2015-10-22 00:45:21 +01:00
|
|
|
static Int start_low_level_trace2(USES_REGS1) {
|
|
|
|
thread_trace = IntegerOfTerm(Deref(ARG1)) + 1;
|
2004-02-21 20:25:45 +00:00
|
|
|
Yap_do_low_level_trace = TRUE;
|
2015-10-22 00:45:21 +01:00
|
|
|
return (TRUE);
|
2004-02-21 20:25:45 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-05-10 10:21:56 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2015-06-19 01:30:13 +01:00
|
|
|
/** @pred stop_low_level_trace
|
|
|
|
|
|
|
|
Stop displaying messages at procedure entry and retry.
|
|
|
|
|
2015-10-22 00:45:21 +01:00
|
|
|
Note that using this compile-time option will slow down execution, even if
|
|
|
|
messages are
|
2015-06-19 01:30:13 +01:00
|
|
|
not being output.
|
|
|
|
|
|
|
|
*/
|
2015-10-22 00:45:21 +01:00
|
|
|
static Int stop_low_level_trace(USES_REGS1) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_do_low_level_trace = FALSE;
|
2011-05-25 16:40:36 +01:00
|
|
|
LOCAL_do_trace_primitives = TRUE;
|
2014-03-06 14:07:33 +00:00
|
|
|
#if DEBUG_LOCKS
|
2014-03-06 02:09:48 +00:00
|
|
|
debug_locks = TRUE;
|
2014-03-06 14:07:33 +00:00
|
|
|
#endif
|
2015-10-22 00:45:21 +01:00
|
|
|
return (TRUE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-06-19 01:30:13 +01:00
|
|
|
volatile int v_wait;
|
2006-08-05 04:06:31 +01:00
|
|
|
|
2015-10-22 00:45:21 +01:00
|
|
|
static Int vsc_wait(USES_REGS1) {
|
|
|
|
while (!v_wait)
|
|
|
|
;
|
2015-06-19 01:30:13 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:45:21 +01:00
|
|
|
static Int vsc_go(USES_REGS1) {
|
|
|
|
v_wait = 1;
|
2015-06-19 01:30:13 +01:00
|
|
|
return true;
|
2006-08-05 04:06:31 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:45:21 +01:00
|
|
|
void Yap_InitLowLevelTrace(void) {
|
|
|
|
Yap_InitCPred("start_low_level_trace", 0, start_low_level_trace,
|
|
|
|
SafePredFlag);
|
2016-01-03 02:06:09 +00:00
|
|
|
Yap_InitCPred("$start_low_level_trace", 0, start_low_level_trace,
|
|
|
|
SafePredFlag);
|
2015-10-22 00:45:21 +01:00
|
|
|
/** @pred start_low_level_trace
|
2014-09-11 20:06:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
Begin display of messages at procedure entry and retry.
|
|
|
|
|
2015-10-22 00:45:21 +01:00
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
*/
|
2004-02-21 20:25:45 +00:00
|
|
|
#if THREADS
|
2015-10-22 00:45:21 +01:00
|
|
|
Yap_InitCPred("start_low_level_trace", 1, start_low_level_trace2,
|
|
|
|
SafePredFlag);
|
2004-02-21 20:25:45 +00:00
|
|
|
#endif
|
2015-06-19 01:30:13 +01:00
|
|
|
Yap_InitCPred("stop_low_level_trace", 0, stop_low_level_trace, SafePredFlag);
|
|
|
|
Yap_InitCPred("show_low_level_trace", 0, show_low_level_trace, SafePredFlag);
|
2016-01-03 02:06:09 +00:00
|
|
|
Yap_InitCPred("$stop_low_level_trace", 0, stop_low_level_trace, SafePredFlag);
|
2015-06-19 01:30:13 +01:00
|
|
|
Yap_InitCPred("total_choicepoints", 1, total_choicepoints, SafePredFlag);
|
2015-10-22 00:45:21 +01:00
|
|
|
Yap_InitCPred("reset_total_choicepoints", 0, reset_total_choicepoints,
|
|
|
|
SafePredFlag);
|
2015-06-19 01:30:13 +01:00
|
|
|
Yap_InitCPred("vsc_wait", 0, vsc_wait, SafePredFlag);
|
|
|
|
Yap_InitCPred("vsc_go", 0, vsc_go, SafePredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
static null(USES_REGS1) { return true; }
|
|
|
|
|
|
|
|
void Yap_InitLowLevelTrace(void) {
|
|
|
|
Yap_InitCPred("$start_low_level_trace", 0, null,
|
|
|
|
SafePredFlag | HiddenPredFlag);
|
|
|
|
Yap_InitCPred("$stop_low_level_trace", 0, null,
|
|
|
|
SafePredFlag | HiddenPredFlag);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|