VC ++ 6.0 access violation on startup in the debugger

I am trying to add improvements to the 4-year-old VC ++ 6.0 program. Debugging is done from the command line, but not in the debugger: it crashes with access violation inside printf (). If I skip printf, it crashes in malloc () (called from fopen ()), and I can't skip this.

This means that I cannot work in the debugger and must rely on old printf statements to find out what is happening. This obviously makes it much harder.

Any idea why printf () and malloc () did not execute when running under the VC ++ debugger? I'm not good at this low level stuff!

The following is a call stack after an access violation:

_heap_alloc_dbg(unsigned int 24, int 2, const char * 0x0046b3d8 `string', int 225) line 394 + 8 bytes
_nh_malloc_dbg(unsigned int 24, int 0, int 2, const char * 0x0046b3d8 `string', int 225) line 242 + 21 bytes
_malloc_dbg(unsigned int 24, int 2, const char * 0x0046b3d8 `string', int 225) line 163 + 27 bytes
_lock(int 2) line 225 + 19 bytes
_getstream() line 55 + 7 bytes
_fsopen(const char * 0x00468000 `string', const char * 0x00466280 `string', int 64) line 61 + 5 bytes
fopen(const char * 0x00468000 `string', const char * 0x00466280 `string') line 104 + 15 bytes
open_new_log(const char * 0x00468000 `string') line 66 + 14 bytes
log_open(const char * 0x00468000 `string', int 0) line 106 + 9 bytes
Xlog_open(const char * 0x00468000 `string', int 0) line 51 + 13 bytes
service_start(unsigned long 1, char * * 0x009a0e50) line 3152 + 12 bytes
service_init2(char * 0x00471fcc char * NTPROGRAM, char * 0x004723c4 char * NTSERVICE, char * 0x00466540 `string', unsigned long 1, char * * 0x009a0e50) line 508 + 13 bytes
service_init(char * 0x00471fcc char * NTPROGRAM, char * 0x004723c4 char * NTSERVICE, unsigned long 2, char * * 0x009a0e50) line 548
main(unsigned long 2, char * * 0x009a0e50) line 3131
mainCRTStartup() line 206 + 25 bytes
KERNEL32! 7c817067()

Here is the debug debugging before the operation in progress:

0041EA7E   jmp         _heap_alloc_dbg+2B3h (0041eb23)
0041EA83   mov         edx,dword ptr [_lTotalAlloc (004b4294)]
0041EA89   add         edx,dword ptr [nSize]
0041EA8C   mov         dword ptr [_lTotalAlloc (004b4294)],edx
0041EA92   mov         eax,[_lCurAlloc (004b429c)]
0041EA97   add         eax,dword ptr [nSize]
0041EA9A   mov         [_lCurAlloc (004b429c)],eax
0041EA9F   mov         ecx,dword ptr [_lCurAlloc (004b429c)]
0041EAA5   cmp         ecx,dword ptr [_lMaxAlloc (004b42a0)]
0041EAAB   jbe         _heap_alloc_dbg+249h (0041eab9)
0041EAAD   mov         edx,dword ptr [_lCurAlloc (004b429c)]
0041EAB3   mov         dword ptr [_lMaxAlloc (004b42a0)],edx
0041EAB9   cmp         dword ptr [_pFirstBlock (004b4298)],0
0041EAC0   je          _heap_alloc_dbg+25Fh (0041eacf)
0041EAC2   mov         eax,[_pFirstBlock (004b4298)]
0041EAC7   mov         ecx,dword ptr [pHead]
0041EACA   mov         dword ptr [eax+4],ecx

Here is our source for calling fopen () and crashing in malloc ()

FILE *open_new_log( const char *logfile )
{
    FILE *fp;
    int retry = 0;

    while( ( fp = fopen( logfile, "w" ) ) == NULL && ++retry < 300 )
        Sleep( 1000 );

    return( fp );
}

, ,

Unhandled exception inPISCOOP.exe: 0xC00000005: Access Violation

,

--- .

+1
6
+3

; . , , , .

, " " Win32 " " V++; , . . , .

, , , , , .

+3

. , open_new_log().

+1

, jmattias . , , - , .

.

  • ( ) .
  • , .
  • ( ) RTL.
  • .
  • .., ..,

Visual ++, _CrtSetDbgFlag() , . malloc . , , .

_CrtSetDbgFlag .

+1

( , ) , ( , , , , , , ).

, Windows, gflags, :

gflags[.exe] /p /enable yourapp.exe /full

. (.. !)
- . , , , () .

:

gflags[.exe] /p /enable yourapp.exe /full /backwards

.

/p- .

+1

, DLL, ++, . , " XXX " "/" ". .

0

All Articles