-
Notifications
You must be signed in to change notification settings - Fork 3
/
prdebug.c
111 lines (93 loc) · 2.21 KB
/
prdebug.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* prdebug.c */
/* Functions that might help you to find a bug with a source-level debugger.
12/21/91 dump_stack renamed dump_ancestors
*/
#include <stdio.h>
#ifndef MEGAMAX
#include <assert.h>
#endif
#include "prtypes.h"
#include "prlex.h"
#include "prmachine.h"
#include "prprint.h"
#include "prlush.h"
#ifndef NDEBUG
#define CHK(X) if(!check_object(X))INTERNAL_ERROR("wild pointer");
#endif
/* Print the offset of a variable */
void pr_offset(nodeptr)
node_ptr_t nodeptr;
{
if(NODEPTR_TYPE(nodeptr)!= VAR)
{
pr_string("non var\n");
}
else
printf("%d",NODEPTR_OFFSET(nodeptr));
}
/* print all open files */
void pr_ofiles()
{
extern struct named_ofile Open_ofiles[];
int i;
char *name;
for(i = 0; i < MAXOPEN; i++)
{
name = (Open_ofiles[i].o_filename);
if(*name){
tty_pr_string(name);
tty_pr_string("\n");
}
}
}
void stack_dump()
{
extern dyn_ptr_t LastCframe;
if (LastCframe == NULL)
return;
dump_ancestors( LastCframe );
}
#ifdef HUNTBUGS
/* The function below was used to look for a bug
* - bughunt(__LINE__,__FILE__,..) was inserted in various parts of the program
*/
atom_ptr_t Mischievous, hash_search();
extern atom_ptr_t Predicate;
int Bug_hunt_flag = 0; /* see do_builtin() in prlush */
static unsigned long Sum;
unsigned long sum_bytes()
{
unsigned long result;
char *p;
char *start_watch_zone, *end_watch_zone;
start_watch_zone = (char *)hash_search("eq");/* last predicate in sprolog.ini */
end_watch_zone = (char *)hash_search("log-session");/* last predicate in sprolog.ini */
assert(start_watch_zone != NULL);
assert(end_watch_zone != NULL);
assert(start_watch_zone != end_watch_zone);
for(result = 0L , p = start_watch_zone; p <= end_watch_zone; p++)
result += *p;
return(result);
}
int bughunt(int line, char *file, char *msg)
{
static int first_time = 1;
if(Bug_hunt_flag == 0)return 1;
if(first_time){
Sum = sum_bytes();
first_time = 0;
return(1);
}
else
if(Sum != sum_bytes())
{
printf("bughunt error %s line %d %s\n", file, line, msg);
getchar();
stack_dump();
Sum = sum_bytes();
return(0);
}
/* printf("Sum = %lu\n", Sum); */
return (1);
}
#endif