7 const char * Purify_Filename
;
8 const char * Purify_Functionname
;
10 CallStackNode
* Purify_CallStack
;
11 CallStackEntry
* Purify_CurrentFrame
;
13 static int usedEntries
;
14 static int callLevels
;
16 static void _Purify_MakeRoom (void)
18 if (!Purify_CallStack
)
20 Purify_CallStack
= xmalloc (sizeof (CallStackNode
));
21 Purify_CurrentFrame
= &Purify_CallStack
->entries
[0];
23 Purify_CallStack
->next
= NULL
;
29 if (usedEntries
== PURIFY_CSNE
)
31 CallStackNode
* node
= xmalloc (sizeof (CallStackNode
));
33 node
->next
= Purify_CallStack
;
34 Purify_CallStack
= node
;
35 Purify_CurrentFrame
= &Purify_CallStack
->entries
[0];
42 Purify_CurrentFrame
++;
47 void Purify_EnterFunction (const char * filename
, const char * functionname
,
48 int lineno
, const void * fp
)
54 SETPOS(&Purify_CurrentFrame
->caller
);
56 Purify_Filename
= filename
;
57 Purify_Functionname
= functionname
;
58 Purify_Lineno
= lineno
;
60 SETPOS(&Purify_CurrentFrame
->called
);
62 Purify_CurrentFrame
->fp
= fp
;
65 printf ("EnterFunction() usedEntries=%d Purify_CurrentFrame=%p\n",
66 usedEntries
, Purify_CurrentFrame
68 printf ("at " POSINFO_FORMAT
" fp=%p\n",
69 POSINFO_ARG(&Purify_CurrentFrame
->called
),
72 printf ("called from " POSINFO_FORMAT
"\n",
73 POSINFO_ARG(&Purify_CurrentFrame
->caller
)
78 void Purify_LeaveFunction (void)
80 Purify_Filename
= Purify_CurrentFrame
->caller
.filename
;
81 Purify_Functionname
= Purify_CurrentFrame
->caller
.functionname
;
82 Purify_Lineno
= Purify_CurrentFrame
->caller
.lineno
;
85 printf ("LeaveFunction() usedEntries=%d Purify_CurrentFrame=%p\n",
86 usedEntries
, Purify_CurrentFrame
88 printf ("to " POSINFO_FORMAT
"\n",
89 POSINFO_ARG(&Purify_CurrentFrame
->caller
)
97 Purify_CurrentFrame
--;
100 CallStackNode
* node
= Purify_CallStack
;
102 Purify_CallStack
= node
->next
;
106 if (Purify_CallStack
)
108 usedEntries
= PURIFY_CSNE
;
109 Purify_CurrentFrame
= &Purify_CallStack
->entries
[PURIFY_CSNE
-1];
114 Purify_CurrentFrame
= NULL
;
119 void Purify_RememberCallers (RememberData
* rd
)
122 int entry
= usedEntries
;
123 CallStackEntry
* cse
;
125 cse
= Purify_CurrentFrame
;
127 SETPOS(&rd
->current
);
129 while (n
< PURIFY_RememberDepth
&& n
< callLevels
)
131 rd
->stack
[n
] = cse
->caller
;
140 if (!Purify_CallStack
->next
)
144 cse
= &Purify_CallStack
->next
->entries
[PURIFY_CSNE
-1];
151 void Purify_PrintCallers (RememberData
* rd
)
155 if (rd
->nstack
== -1)
158 fprintf (stderr
, "at " POSINFO_FORMAT
"\n",
159 POSINFO_ARG(&rd
->current
)
162 for (t
=0; t
<rd
->nstack
; t
++)
164 fprintf (stderr
, "called by " POSINFO_FORMAT
"\n",
165 POSINFO_ARG(&rd
->stack
[t
])