1 /*** Debug.h : Simple ressource tracking for Memory allocation
2 **** Written by T.Pierron june 27, 2001
5 #if DEBUG /* Do not include this code if DEBUG isn't defined */
8 #ifdef DEBUG_STUFF /* One arbitrary file must defined this macro */
10 #ifdef AllocVec /* Disable recursiv call! */
15 /* Track calling times of Alloc & Free */
16 static nballoc
= 0, nbfree
= 0;
17 void * my_alloc(unsigned long size
, unsigned long type
)
21 result
= (void *)AllocVec(size
, type
);
25 void my_free(void * ptr
)
30 #else /* simply redirect calls */
32 void * my_alloc (unsigned long, unsigned long);
33 void my_free (void *);
35 /** Redirect original calls **/
36 #define AllocMem(x,y) my_alloc(x,y)
37 #define FreeMem(x,y) my_free(x)
41 /** Redirect original calls **/
42 #define AllocVec(x,y) my_alloc(x,y)
43 #define FreeVec(x) my_free(x)
46 #ifdef DEBUG_UNDO_STUFF /* For undo/redo tracking */
47 extern UBYTE SizeOf
[];
51 void print_n(char *p
, int n
)
60 case '\n': msg
= "\\n"; break;
61 case '\t': msg
= "\\t"; break;
62 case '\r': msg
= "\\r"; break;
63 case 27: msg
= "\\e"; break;
65 if(msg
) printf("\e[1m%s\e[0m",msg
);
66 else printf("\e[1m\\%02x\e[0m", *p
);
73 void print_rbseg_buf( ULONG sz
)
76 /* The line in the rollback segment may be spread over several chunk */
78 print_n(rbs
->data
+ (rbsz
-= sz
), sz
);
81 print_n(rbs
->data
, rbsz
);
83 rbsz
= (rbs
= rbs
->prev
)->max
;
88 int get_ln(Project p
, LINE
*ln
)
90 LINE
* l
= p
->the_line
;
92 while( l
&& l
!= ln
) l
= l
->next
, n
++;
96 /** Show content of rollback segments (note: this is quick and dirty) **/
97 void show_modifs( JBuf jb
)
99 RBOps buf
; UWORD size
, op
, i
= 0;
103 printf("\e[1mRBSeg info: size=%d (0x%08lx) rbsz:%d (0x%08lx)\e[0m\n",
104 jb
->size
,jb
->ops
,jb
->rbsz
,jb
->rbseg
);
106 for(buf
= jb
->ops
, size
= jb
->size
; buf
; size
=buf
->size
, buf
=buf
->prev
)
110 op
= LAST_TYPE(buf
->data
+ size
);
111 size
-= SizeOf
[ op
];
116 AddChar buf2
= (AddChar
) (buf
->data
+ size
);
117 printf("%d \e[4mcharacters added\e[0m line %d, pos %d : ", buf2
->nbc
,
118 get_ln(PRJ(jb
),buf2
->line
), buf2
->pos
);
119 print_n(buf2
->line
->stream
+buf2
->pos
, buf2
->nbc
);
123 RemChar buf2
= (RemChar
) (buf
->data
+ size
);
124 printf("%d \e[4mcharacters removed\e[0m line %d, pos %d : ", buf2
->nbc
,
125 get_ln(PRJ(jb
),buf2
->line
), buf2
->pos
);
126 print_rbseg_buf(buf2
->nbc
);
129 printf("\e[4mLine removed\e[0m\n");
132 { JoinLine buf2
= (JoinLine
) (buf
->data
+ size
);
133 printf("\e[4mLine joined\e[0m pos %d\n", buf2
->pos
);
136 printf("\e[4m%s\e[0m of group\n", i
&1 ? "End" : "Start"); i
++;
139 printf("\e[2mUnsupported operation\e[0m (0x%x - size = %d)!\n", op
, size
);