Click to See Complete Forum and Search --> : exception


milli
February 28th, 2002, 03:37 AM
Hi,
J would like help please, in fact j have a EXCEPTION_ACCESS_VIOLATION who
apear when my programm is running for few days.

look my code, and my result file (at the end of this mail). J would like
know, where appear the bug (dll, and function), please

Thank for your help.

Millieret xavier


code for exceptions.

/*****************************************************************************
* But de la fonction : Creation d'un main
* --------------------
* Parametres :
* ------------
*
* entree : argument du main
*
* sortie : aucun
*
* return : aucun
*
* Fonctions externes utilisees : CreerBal
* DetruireBal
* ClassTache_P->Gerer
*
* Points particuliers :
*
*****************************************************************************/
void T_ClassTache::CreerMain (void *Arg_P)
{
EXCEPTION_RECORD SavedExceptRec_L;
CONTEXT SavedContext_L;

/* Gestion de exceptions */
_try
{

// créer la trace du main
CreerTrace ();

// creer la bal du main
CreerBal ();

// entrer dans le main
Gerer (Arg_P);

// destruction de la bal
DetruireBal ();

// Destruction de la trace
DetruireTrace ();
}
_except ((GetExceptionCode() == INTFSYS_EXCEPTION_CONTINUE) ?
EXCEPTION_CONTINUE_EXECUTION :
(SavedExceptRec_L = *(GetExceptionInformation())->ExceptionRecord,
SavedContext_L = *(GetExceptionInformation())->ContextRecord,
EXCEPTION_EXECUTE_HANDLER))
{
MessageBeep (MB_OK);
MyTermHandler (&SavedExceptRec_L, &SavedContext_L);
}
}


code for format the result file.

/*****************************************************************************
* But de la fonction : Gestion des Exceptions
* --------------------
* Parametres :
* ------------
*
* entree : Pointeur sur l'exception record
* Pointeur sur le context record
*
* sortie : aucun
*
* return : aucun
*
* Fonctions externes utilisees :
*
* Points particuliers :
*
*****************************************************************************/
void MyTermHandler (PEXCEPTION_RECORD p1, PCONTEXT p2)
{
char String_L[200];
SYSTEMTIME DateTime_L;
DWORD ThreadId_L;
DWORD ProcessId_L;
HANDLE FileHandle_L;
ULONG Action_L;
DWORD Wrote_L;
ULONG Taille_L;
BOOL Rc_L;
DWORD Error_L;
DWORD i;

/* Initialisation */
ThreadId_L=0;
Action_L = 0;

// ouvrir le fichier trace
FileHandle_L = CreateFile ("halt.txt", // Nom du fichier.
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
Error_L = GetLastError();
if (FileHandle_L != INVALID_HANDLE_VALUE)
{
SetFilePointer(FileHandle_L,0,NULL,FILE_END);

/* On recupere la date/time system */
GetLocalTime(&DateTime_L);

/* On prepare la chaine */
sprintf (String_L, "\r\n *** EXCEPTION : %2.2d:%2.2d:%2.2d %2.2d/%2.2d/%4.4d\r\n",
DateTime_L.wHour, DateTime_L.wMinute, DateTime_L.wSecond,
DateTime_L.wDay, DateTime_L.wMonth, DateTime_L.wYear);

Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);

// Process Id
ProcessId_L = GetCurrentProcessId();
sprintf (String_L, " Process : %d\r\n", ProcessId_L);
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);

// thread Id
ThreadId_L = GetCurrentThreadId ();
sprintf (String_L, " Thread : %d\r\n", ThreadId_L);
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);

sprintf (String_L, "\r\n EXCEPTION REPORT RECORD\r\n");
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);


sprintf (String_L,
" ExceptionCode = %8.8X\r\n",
p1->ExceptionCode);
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);

sprintf (String_L,
" ExceptionFlags = %8.8X\r\n",
p1->ExceptionFlags); /* Handler flags. */
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);

sprintf (String_L,
" ExceptionAddress = %8.8X\r\n",
(ULONG)p1->ExceptionAddress); /* Address of the exception. */
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);


sprintf (String_L,
" NumberParameters = %8.8X\r\n",
p1->NumberParameters); /* Size of exception specific information. */
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);

if ( p1->NumberParameters != 0 )
{
sprintf (String_L,
" ExceptionInfo ="); /* Exception specific information. */
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);


for ( i = 0 ; i < p1->NumberParameters ; i++ )
{
sprintf (String_L,
" %8.8X",
p1->ExceptionInformation[i]); /* Exception specific information. */
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);

}

sprintf (String_L, "\r\n");
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);
}

sprintf (String_L, "\r\n CONTEXT RECORD\r\n");
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);

sprintf (String_L,
" ContextFlags=%8.8X\r\n",
p2->ContextFlags); /* Flags which control the contents of the context record. */
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);


sprintf (String_L,
" DEBUG REGISTERS DR0=%8.8X DR1=%8.8X DR2=%8.8X\r\n",
p2->Dr0,
p2->Dr1,
p2->Dr2);
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L, // File handle
String_L, // User buffer
Taille_L, // Buffer length
&Wrote_L, // Bytes written
NULL);

sprintf (String_L,
" DR3=%8.8X DR6=%8.8X DR7=%8.8X\r\n",
p2->Dr3,
p2->Dr6,
p2->Dr7);
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L, // File handle
String_L, // User buffer
Taille_L, // Buffer length
&Wrote_L, // Bytes written
NULL);


sprintf (String_L,
" SEGMENT REGISTERS GS=%8.8X FS=%8.8X ES=%8.8X DS=%8.8X\r\n",
p2->SegGs, /* Gs register. */
p2->SegFs, /* Fs register. */
p2->SegEs, /* ES register. */
p2->SegDs); /* DS register. */
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);

sprintf (String_L,
" ESI=%8.8X EDI=%8.8X\r\n",
p2->Esi, /* ESI register. */
p2->Edi); /* EDI register. */
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);

sprintf (String_L,
" REGISTERS EBX=%8.8X EDX=%8.8X\r\n",
p2->Ebx, /* EBX register. */
p2->Edx); /* EDX register. */
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);

sprintf (String_L,
" BP =%8.8X IP =%8.8X\r\n",
p2->Ebp, /* BP register. */
p2->Eip); /* IP register. */
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);

sprintf (String_L,
" CS=%8.8X FLG=%8.8X\r\n",
p2->SegCs, /* CS register. */
p2->EFlags); /* EFLAGS register. */
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);


switch ( p1->ExceptionCode )
{
case EXCEPTION_ACCESS_VIOLATION:
sprintf (String_L, "\r\n Violation Memoire (%s) a l'adresse : %x\r\n",
(p1->ExceptionInformation[0]) ? "read" : "write",
p1->ExceptionInformation[1]);
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);
break;

case INTFSYS_EXCEPTION_STOP:
sprintf (String_L, "\r\n Exception Intfsys \r\n");
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);
break;

default:
break;
}

sprintf (String_L, "\r\n TRACE \r\n");
Taille_L = strlen (String_L);
Rc_L = WriteFile (FileHandle_L,
String_L,
Taille_L,
&Wrote_L,
NULL);

EcrireTrace (FileHandle_L);

/* Fermer le fichier */
CloseHandle (FileHandle_L);
}

#ifndef _DEBUG
/* Test de la presence de la variable d'environnement */
memset (String_L, 0, 200);
GetEnvironmentVariable ("REBOOT_SUR_ERREUR", String_L, 200);

/* Si variable d'environnement absente ou a zero */
if (atoi (String_L) != 0)
{
/* On arrete le systeme */
ArreterSysteme ();

// Reboot de la session
ExitWindowsEx (EWX_FORCE,0);
}
#endif

/* On sort de l'application */
_exit (0);
}


Result file.

*** EXCEPTION : 08:00:26 25/02/2002
Process : 92
Thread : 105

EXCEPTION REPORT RECORD
ExceptionCode = C0000005
ExceptionFlags = 00000000
ExceptionAddress = 00234A4E
NumberParameters = 00000002
ExceptionInfo = 00000001 FFFFFCE8

CONTEXT RECORD
ContextFlags=0001001F
DEBUG REGISTERS DR0=00000000 DR1=45891051 DR2=00000000
DR3=00000000 DR6=00000005 DR7=00000000
SEGMENT REGISTERS GS=00000000 FS=00000038 ES=00000023 DS=00000023
ESI=007D0690 EDI=00000020
REGISTERS EBX=007D0690 EDX=00000002
BP =00000000 IP =00234A4E
CS=0000001B FLG=00010212

Violation Memoire (read) a l'adresse : fffffce8