Pointer dereferencing causes crash, only in Release mode, x86 Assembly related  
Author Message
Celios





PostPosted: Visual C++ General, Pointer dereferencing causes crash, only in Release mode, x86 Assembly related Top

Hi.

My application reads a file and suddenly it crashes when executing an x86 assembly command.
The assembly command dereferenced a word pointer and suddenly crashed.

The error message from Windows is :
The instruction at "0x00421121" referenced memory at "0x041db000". The memory could not be "read".

The instruction is a simple one :
movd mm3, [esi]

where mm3 is used to hold temporary values and esi is the offset of a DWORD within the file.

If the application is build using Debug profile, it does not crash.
Only when built with Release profile with optimizations does it crash.
My guess is that the value of [esi] is 0xFF and when in Debug mode, this value is automatically replaced with 0x00 while in Release mode this is not done.

Problem is that I do not know how to handle this.
Even one peek at the faulty memory value causes crash immediately, so I cannot even compare it with 0xFF.
Can anybody show me how to detect this faulty memory value without causing it crash in x86 Assembly

Thanks.

Celios


Visual C++13  
 
 
einaros





PostPosted: Visual C++ General, Pointer dereferencing causes crash, only in Release mode, x86 Assembly related Top

This may be a code generation problem, or an overflow / out of bounds write or any number of other things.

Why don't you launch the application through a de****, cause it to crash and inspect the stack trace If you've got the source code (which I assume you do), you should be able to at least trace back to the offending region of your application. From there it should also be fairly straight forward to examine the difference in the machine code generated for debug and release builds.

Also, I wouldn't worry too much about the value at [ESI] for now, but rather the value of ESI. Find out where that's coming from, and if it makes any sense.



 
 
Celios





PostPosted: Visual C++ General, Pointer dereferencing causes crash, only in Release mode, x86 Assembly related Top

Thanks for the advice.

The thing is that esi is changed a lot in loop.
As I said before, running the program in Debug mode does not cause crash.
Running Release mode inside VS De**** also does not crash.
The only de**** that I can rely on right now for this purpose is WinDBG.
It is rather hard to pinpoint which addresses gives error.

I will see what I can do.

 
 
einaros





PostPosted: Visual C++ General, Pointer dereferencing causes crash, only in Release mode, x86 Assembly related Top

This can really be anything from a problem with code generation to buffer bounds overstepping. In the latter case, the fact that the crash doesn't happen in debug mode, but does in release, may simply be because of memory layout differences.

When it comes to the de****, I prefer Ollydbg ( http://www.hide-link.com/ ) to WinDBG for usermode / local debugging. You should give that one a try, if you haven't already.



 
 
Celios





PostPosted: Visual C++ General, Pointer dereferencing causes crash, only in Release mode, x86 Assembly related Top

einaros,

It really is the buffer bounds overstepping case.
It was hard to see because it was in Assembly and I am no Assembly expert, but
finally I have found the bug.

Thanks very much for your guidance !!!