-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.c
140 lines (100 loc) · 2.88 KB
/
debug.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* debug routines, and structure dump
*
* Copyright ©1996-2008 pinc Software. All Rights Reserved.
* Licensed under the terms of the GNU General Public License, version 3.
*/
#include "types.h"
#include <stdarg.h>
#ifdef DEBUG
void
panic(const char *format, ...)
{
char text[256];
va_list args;
va_start(args, format);
vsprintf(text, format, args);
va_end(args);
bug(text);
//exit(-1);
}
void
check_project_pointer(struct Mappe *map)
{
struct Mappe *item;
ASSERT(map != NULL);
foreach (&gProjects, item) {
if (map == item)
// pointer is valid
return;
}
panic("map pointer invalid 0x%08lx!\n", map);
}
void
check_page_pointer(struct Page *page)
{
struct Page *item;
ASSERT(page != NULL);
check_project_pointer(page->pg_Mappe);
foreach (&page->pg_Mappe->mp_Pages, item) {
if (page == item)
// pointer is valid
return;
}
panic("page pointer is invalid 0x%08lx!\n", page);
}
void
dump_diagrams(struct Page *page)
{
struct gDiagram *diagram;
check_page_pointer(page);
bug("diagrams for page \"%s\" (0x%08lx)\n", page->pg_Node.ln_Name, page);
foreach (&page->pg_gDiagrams, diagram) {
bug("\t0x%08lx\n", diagram);
}
}
void
dump_object(struct gObject *object, bool nullPageAllowed)
{
struct Link *link;
bug("gObject at 0x%08lx\n", object);
bug("\tname = \"%s\"\n", object->go_Node.ln_Name);
bug("\tpos = %ld\n", object->go_Pos);
bug("\ttype = %d\n", object->go_Type);
bug("\tflags = %d\n", object->go_Flags);
bug("\tpage = 0x%08lx\n", object->go_Page);
bug("\twindow = 0x%08lx\n", object->go_Window);
bug("\tundo = 0x%08lx\n", object->go_Undo);
bug("\tclass = 0x%08lx\n", object->go_Class);
bug("\treferenced by:\n");
foreach (&object->go_ReferencedBy, link)
bug("\t 0x%08lx -> 0x%08lx\n", link, link->l_Link);
if (!nullPageAllowed || object->go_Page != NULL)
check_page_pointer(object->go_Page);
}
void
dump_diagram(struct gDiagram *diagram, bool nullPageAllowed)
{
struct gLink *link;
bug("gDiagram at 0x%08lx\n", diagram);
dump_object(diagram, nullPageAllowed);
bug("\t--- diagram ---\n");
if ((diagram->gd_Object.go_Class->gc_Node.in_Type & GCT_DIAGRAM) == 0) {
bug("\tdump_diagram() called on normal object!\n");
return;
}
bug("\tflags = %d\n", diagram->gd_Flags);
bug("\tread data = %d\n", diagram->gd_ReadData);
bug("\trange = \"%s\" (0x%08lx)\n", diagram->gd_Range, diagram->gd_Range);
bug("\treference = 0x%08lx\n", diagram->gd_Reference);
foreach (&diagram->gd_Values, link) {
bug("\t 0x%08lx value = %ld\n", link, (long)link->gl_Value);
}
bug("\tlinks = 0x%08lx\n", diagram->gd_Links);
bug("\tlegendX = 0x%08lx\n", diagram->gd_LegendX);
bug("\tlegendY = 0x%08lx\n", diagram->gd_LegendY);
bug("\tcols = %ld\n", diagram->gd_Cols);
bug("\trows = %ld\n", diagram->gd_Rows);
bug("\tdata page = 0x%08lx\n", diagram->gd_DataPage);
bug("\tpage number = %ld\n", diagram->gd_PageNumber);
}
#endif // only if DEBUG