2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
12 const char * Purify_Filename
;
13 const char * Purify_Functionname
;
15 CallStackNode
* Purify_CallStack
;
16 CallStackEntry
* Purify_CurrentFrame
;
18 static int usedEntries
;
19 static int callLevels
;
21 static void _Purify_MakeRoom (void)
23 if (!Purify_CallStack
)
25 Purify_CallStack
= xmalloc (sizeof (CallStackNode
));
26 Purify_CurrentFrame
= &Purify_CallStack
->entries
[0];
28 Purify_CallStack
->next
= NULL
;
34 if (usedEntries
== PURIFY_CSNE
)
36 CallStackNode
* node
= xmalloc (sizeof (CallStackNode
));
38 node
->next
= Purify_CallStack
;
39 Purify_CallStack
= node
;
40 Purify_CurrentFrame
= &Purify_CallStack
->entries
[0];
47 Purify_CurrentFrame
++;
52 void Purify_EnterFunction (const char * filename
, const char * functionname
,
53 int lineno
, const void * fp
)
59 SETPOS(&Purify_CurrentFrame
->caller
);
61 Purify_Filename
= filename
;
62 Purify_Functionname
= functionname
;
63 Purify_Lineno
= lineno
;
65 SETPOS(&Purify_CurrentFrame
->called
);
67 Purify_CurrentFrame
->fp
= fp
;
70 printf ("EnterFunction() usedEntries=%d Purify_CurrentFrame=%p\n",
71 usedEntries
, Purify_CurrentFrame
73 printf ("at " POSINFO_FORMAT
" fp=%p\n",
74 POSINFO_ARG(&Purify_CurrentFrame
->called
),
77 printf ("called from " POSINFO_FORMAT
"\n",
78 POSINFO_ARG(&Purify_CurrentFrame
->caller
)
83 void Purify_LeaveFunction (void)
85 Purify_Filename
= Purify_CurrentFrame
->caller
.filename
;
86 Purify_Functionname
= Purify_CurrentFrame
->caller
.functionname
;
87 Purify_Lineno
= Purify_CurrentFrame
->caller
.lineno
;
90 printf ("LeaveFunction() usedEntries=%d Purify_CurrentFrame=%p\n",
91 usedEntries
, Purify_CurrentFrame
93 printf ("to " POSINFO_FORMAT
"\n",
94 POSINFO_ARG(&Purify_CurrentFrame
->caller
)
102 Purify_CurrentFrame
--;
105 CallStackNode
* node
= Purify_CallStack
;
107 Purify_CallStack
= node
->next
;
111 if (Purify_CallStack
)
113 usedEntries
= PURIFY_CSNE
;
114 Purify_CurrentFrame
= &Purify_CallStack
->entries
[PURIFY_CSNE
-1];
119 Purify_CurrentFrame
= NULL
;
124 void Purify_RememberCallers (RememberData
* rd
)
127 int entry
= usedEntries
;
128 CallStackEntry
* cse
;
130 cse
= Purify_CurrentFrame
;
132 SETPOS(&rd
->current
);
134 while (n
< PURIFY_RememberDepth
&& n
< callLevels
)
136 rd
->stack
[n
] = cse
->caller
;
145 if (!Purify_CallStack
->next
)
149 cse
= &Purify_CallStack
->next
->entries
[PURIFY_CSNE
-1];
156 void Purify_PrintCallers (RememberData
* rd
)
160 if (rd
->nstack
== -1)
163 fprintf (stderr
, "at " POSINFO_FORMAT
"\n",
164 POSINFO_ARG(&rd
->current
)
167 for (t
=0; t
<rd
->nstack
; t
++)
169 fprintf (stderr
, "called by " POSINFO_FORMAT
"\n",
170 POSINFO_ARG(&rd
->stack
[t
])