Mail Archives: djgpp/1995/01/17/03:03:57
Hi,
A good way to debug graphics programs, is to make an after-execution report
of what happened. You can do that with the two files Debug.H and Debug.C
that follow.
You init the debugging session with InitDebug(). You must specify
DebugOpen, and DebugPermanent or DebugTemporaire. With DebugTemporaire, the
report file will be OK, even if your application crashes, whereas with
DebugPermanent,the report file will be lost.
You end the debugging session with DoneDebug().
When you want to know the value of a variable or any else report, just
use Debug() the same way as a printf().
Example :
int main(...)
{ InitDebug(DebugON | DebugPermanent);
...
int Value=5;
float fValue=2.3;
...
Debug("I want to know what the values are\nValue=%d\nfValue=%f\n",
Value,fValue);
...
DoneDebug();
}
AND after execution, you will find in the file C:\DEBUG.TXT :
SWORD 2.0. Debugging file
-------------------------
I want to know what the values are
Value=5
fValue=2.3
With that Debug.C, you will be able to see everything that happened during
execution of graphics programs.
I hope it will help.
Bye.
###### DEBUG.H ############################################################
/* Project S!W!O!R!D
V2.0
SubSystem : Basic functions usefull for all the system
File : Include/Common/Debug.H
Author : Eric NICOLAS
Overview : Debugging system with spy file.
History : 23/10/94 - Creation
** Copyright (C) 1993,1995 Eric NICOLAS
**
** This file is distributed under the terms listed in the document
** "copying.en". A copy of "copying.en" should accompany this file.
** if not, a copy should be available from where this file was obtained.
** This file may not be distributed without a verbatim copy of "copying.en".
**
** This file is distributed WITHOUT ANY WARRANTY; without even the implied
** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef _COMMON_DEBUG_H_
#define _COMMON_DEBUG_H_
#define DebugON 1
#define DebugOFF 0
#define DebugPermanent 0
#define DebugTemporaire 1
#ifdef __cplusplus
extern "C" {
#endif
void InitDebug(char Modes);
void DoneDebug(void);
void Debug(va_list arg_list, ...);
#ifdef __cplusplus
}
#endif
#endif
###### DEBUG.C ############################################################
/* Project S!W!O!R!D
V2.0
SubSystem : Basic functions usefull for all the system
File : LibSrc/Common/Debug.C
Author : Eric NICOLAS
Overview : Debugging system with spy file.
History : 23/10/94 - Creation
** Copyright (C) 1993,1995 Eric NICOLAS
**
** This file is distributed under the terms listed in the document
** "copying.en". A copy of "copying.en" should accompany this file.
** if not, a copy should be available from where this file was obtained.
** This file may not be distributed without a verbatim copy of "copying.en".
**
** This file is distributed WITHOUT ANY WARRANTY; without even the implied
** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <stdio.h>
#include <stdarg.h>
#include "Common/Debug.H"
#define OpenDebug FileDebug=fopen("C:/DEBUG.TXT","at+")
#define CreateDebug FileDebug=fopen("C:/DEBUG.TXT","wt")
#define CloseDebug fclose(FileDebug)
FILE *FileDebug;
char ModeDebug;
void InitDebug(char Mode)
{ ModeDebug=Mode;
if (ModeDebug & DebugON)
{ CreateDebug;
fprintf(FileDebug,"SWORD 2.0. Debugging file\n"
"-------------------------\n\n");
if (ModeDebug & DebugTemporaire) CloseDebug;
}
}
void DoneDebug()
{ if (ModeDebug & DebugON)
{ if (!(ModeDebug & DebugTemporaire)) CloseDebug;
}
}
void Debug(va_list arg_list, ...)
{ va_list arg_ptr ;
char *format;
if (ModeDebug & DebugTemporaire) OpenDebug;
va_start(arg_ptr, arg_list);
format = (char*)arg_list;
vfprintf(FileDebug,format, arg_ptr);
fflush(FileDebug);
if (ModeDebug & DebugTemporaire) CloseDebug;
}
###########################################################################
- Raw text -