Copyright clean-up (part 1):
[AROS.git] / compiler / purify / src / error.c
blobd1599dd2b0d6eead8e9ee7d1c3071f44afa9df06
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <stdio.h>
7 #include <stdarg.h>
8 #include "error.h"
9 #include "hash.h"
10 #include "posinfo.h"
11 #include "memory.h"
13 static char * _Purify_MemTypeNames[] =
15 "Heap",
16 "Stack",
17 "Code",
18 "Data"
21 int Purify_Error;
23 static const char * purify_ErrorMsgs[] =
25 #undef _ERROR_DEF
26 #define _ERROR_DEF(n,s) s,
27 #include "error.def"
30 void Purify_PrePrintError (void)
32 RememberData rd;
34 Purify_RememberCallers (&rd);
36 fprintf (stderr, "*** Purify %s ***\n", purify_ErrorMsgs[Purify_Error]);
37 Purify_PrintCallers (&rd);
40 void Purify_PostPrintError (void)
42 fprintf (stderr, "***\n");
45 void Purify_PrintError (const char * fmt, ...)
47 va_list args;
49 Purify_PrePrintError ();
50 va_start (args, fmt);
51 vfprintf (stderr, fmt, args);
52 va_end (args);
53 putc ('\n', stderr);
54 Purify_PostPrintError ();
57 void Purify_PrintAccessError (const char * access, const void * addr, int size)
59 if (Purify_LastNode)
61 long offset = (long)addr - (long)(Purify_LastNode->mem);
63 if (Purify_LastNode->type != PURIFY_MemType_Heap)
65 Purify_PrintError (
66 "%s of %d bytes at %p. This is %d bytes into the block\n"
67 "%s%s%sat %p with the size of %d bytes (type=%s)",
68 access, size, addr, offset,
69 Purify_LastNode->data ? "\"" : "",
70 Purify_LastNode->data ? (char *)Purify_LastNode->data : "",
71 Purify_LastNode->data ? "\" " : "",
72 Purify_LastNode->mem, Purify_LastNode->size,
73 _Purify_MemTypeNames[Purify_LastNode->type]
76 else
78 PMemoryNode * node = (PMemoryNode *)Purify_LastNode->data;
80 Purify_PrePrintError ();
81 fprintf (stderr,
82 "%s of %d bytes at %p. This is %ld bytes into the block\n"
83 "allocated at %p with the size of %d bytes (type=%s)\n"
84 "The block was allocated ",
85 access, size, addr, offset,
86 Purify_LastNode->mem, Purify_LastNode->size,
87 _Purify_MemTypeNames[Purify_LastNode->type]
89 Purify_PrintCallers (&node->alloc);
90 if (node->free.nstack != -1)
92 fprintf (stderr, "It was freed ");
93 Purify_PrintCallers (&node->free);
95 Purify_PostPrintError ();
98 else
100 int offset;
101 MemHash * next = Purify_FindNextMemory (addr, &offset);
103 if (next->type != PURIFY_MemType_Heap)
105 Purify_PrintError (
106 "%s of %d bytes at %p. This is %d bytes %s the block\n"
107 "%s%s%sat %p with the size of %d bytes (type=%s)",
108 access, size, addr, offset, (offset < 0 ? "before" : "after"),
109 next->data ? "\"" : "",
110 next->data ? (char *)next->data : "",
111 next->data ? "\" " : "",
112 next->mem, next->size,
113 _Purify_MemTypeNames[next->type]
116 else
118 PMemoryNode * node = (PMemoryNode *)next->data;
120 Purify_PrePrintError ();
121 fprintf (stderr,
122 "%s of %d bytes at %p. This is %d bytes %s the block\n"
123 "allocated at %p with the size of %d bytes (type=%s)\n"
124 "The block was allocated ",
125 access, size, addr, offset, (offset < 0 ? "before" : "after"),
126 next->mem, next->size,
127 _Purify_MemTypeNames[next->type]
129 Purify_PrintCallers (&node->alloc);
130 if (node->free.nstack != -1)
132 fprintf (stderr, "It was freed ");
133 Purify_PrintCallers (&node->free);
135 Purify_PostPrintError ();