Sign in to follow this  
hiigara

"access violation". How can I get a stack trace?

Recommended Posts

hiigara    108
Hello My app runs ok in debug mode, but in release mode it throws an access violation exception. I know the exact point in the code where it is happening and why. I am dereferencing a NULL pointer. But that code is inside a function which is called from hundreds of places and I don't know who is passing the NULL pointer to the function. The windows diagnostic report is not user friendly and I cannot read the stack from there. Can you help? Thanks

Share this post


Link to post
Share on other sites
TheUnbeliever    963
IDE? Debugger?

Assuming you're using Visual Studio - build a release version, and hit F5; when the access violation occurs, select the option to break in. You'll have a stack trace (you may need to enable debug symbols even in release mode for it to be useful - just set the option in the project settings).

Note that if you try to do much in the way of debugging release mode, it's worth remembering that some variables, expressions or statements will be optimized away, so the flow of execution will simply appear to skip over it.

Share this post


Link to post
Share on other sites
hiigara    108
I am using Visual C++ 6.0 . If i enable debug symbols in release, it won't be a release build will it? Anyways here is the screenshoot when the release crashes.
The stack is not right. I am going to try enabling symbols.

description of your image

Share this post


Link to post
Share on other sites
Adam_42    3629
From the look of that disassembly and callstack a kernel function has called back to your code, with a null (or otherwise invalid) pointer, which you've dereferenced to compare the contents with something.

You can enable symbols in release mode, and it won't affect the code generation. The only thing it changes is that a path to the .pdb file is stored in the exe. I'd recommend always leaving them on.

Share this post


Link to post
Share on other sites
Zahlman    1682
Quote:
Original post by hiigara
I am using Visual C++ 6.0 .


You do know that's ten years old, right?

Have you considered the possibility that your knowledge of the language is comparably out of date, BTW? Usually, the best way to avoid being passed a NULL pointer (assuming that this isn't a situation you're specifically allowing for) is to use actual references to accomplish pass-by-reference.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this