views:

1501

answers:

2

I'm debugging a software which crashes eventually with one of the following messages:

1. DAMAGE: after normal block (#24729280) at 0x00D710E0
2. Debug Assertion Failed
   Program: D:\Soft\Test.exe
   File: dbgheap.c
   Line: 1017

   Expression: _BLOCK_TYPE_IS_VALID(phead->nBlockUse)

This software is really old but changing it now is not an option. It's written on Visual C++ 6.0. We are guessing it's some kind of buffer overflow, so we are trying to find ways to detect where it is happening.

I have found information about PageHeap (which seems to be able to tell me what I want) and GFlags, but it seems I can't make it work.

I created a test program:

char* test;
test = new char[5];
test[5] = 'a';
delete[] test;

which raises an error:

DAMAGE: after normal block (#55) at 0x1671920

Then, I tried attaching PageHeap to it by running:

gflags.exe /p /enable MemoryTest.exe /full

and then rerunning it (both through Visual C++ 6.0 interface and through the windows explorer), which resulted on the same error.

Then I tried to compile the release version, and ran it through the Visual C++ 6.0 interface to get the error:

User breakpoint called from code at 0x7c90120e

And from the windows explorer, I just got the windows dialog asking me to send an error report.

What am I missing?

A: 

Before using gFlags/PageHeap I suggest you to check for Access Violation exception. First attach the process by using Build->Start Debug->Attach to process option. Once it is attached enable the access violation exception by going to Debug->Exceptions select Access Violation and select the check box Stop Always. Then check whether your debugger catches any access violation exceptions.

Naveen
For the real program (not the test one), it caught some exceptions regarding a CTreeView component, but I don't think it's the source of my problems.When I tried it with my test program, it didn't caught nothing and crashed as usual, with the same error.
Rodrigo
+1  A: 

You can run your application in release mode by attaching to Windbg.

  • Enable the gflags ( As you mentioned)
  • Start the application in release mode.
  • Attach it to Windbg using Attach to process option in Windbg.
  • Configure the correct path for release PDBs.
  • Reload the PDB manually using .reload /f in case of automatic loading fails.
  • Perform the use case.

WinDbg would stop the execution whenever an exception occurs. For every first chance exception, analyze the reasons. It could be one of the error for crash.

aJ
I'm trying to use this to debug the example program i've built. Managed to get to step 5 (reload the PDB file), then I press f5. That's when I get two errors: corrupted suffix pattern and corrupted heap block, but I can't understand how or why thet happened...
Rodrigo
You can try by starting the exe with debugger attached. This you can achieve using gflags.exe. When you run th gflags.exe, 1.Goto "Image File" Tab 2) Give full path to your exe in Image textbox 3) press Tab to enable 4) Give full path to windbg -g in Debugger textbox.
aJ
I tried openning gflags.exe, going to the image files, selected my exe and selected the debug option filling it with C:\DebugTools\windbg.exe -g. Then I tried pressing OK, but nothing happened. Then I pressed launch, but no debug was shown.
Rodrigo
Sorry, I didn't quite get your point. Did you start application after the configuration? Once you configure the windbg path in gflags, you need to start the application. Application would get started with windbg attached.
aJ
I tried starting it with the launch button on gflags.exe
Rodrigo
No need to press launch button. Once you configure the windbg path, press Apply and close the gflags window. Later, you need to start your application. The application would get started with windbg attached.
aJ