Solved

How to debug this?

Posted on 2001-08-22
21
402 Views
Last Modified: 2013-11-20
Hi experts,

In Debug modal, I compiled my project and run it and cannot see any problem. However, when closed it I got:
Unhadled exception in myProject.exe: 0xC000005: Access violation.
Then, I tried to compile the same project in Release modal. This time I got the same error message during run time.
How to debug my project?

Thank you in advance.
0
Comment
Question by:markdot
  • 8
  • 4
  • 2
  • +5
21 Comments
 
LVL 3

Expert Comment

by:cypherljk
Comment Utility
1.) I would 1st check the destructor for classes and anything that handles the WM_CLOSE message. (this is the message sent to you app when it is being closed)
2.) Also check anywhere you are deallocating any resources (database, files memory ect...)

When it give the error message it should show some more information in the bottom window pane about the error. If you post more info we can be more helpful

My 2 cents..
0
 
LVL 32

Expert Comment

by:jhance
Comment Utility
Go back to your DEBUG build and run it under the Visual Studio DEBUGGER.  BUILD > Start Debug > Go (or hit F5)

Then when the error happens it will take you right to the line in your program that is causing it.  An ACCESS Violation Error is most often caused by an invalid or uninitialized pointer.
0
 

Author Comment

by:markdot
Comment Utility
Hi cypherljk,

That error message is the all, nothing else! Well....after I close that errow message, VC++ showed me a file window and said:
Please enter the path for DBGHAP.C
What is that?
--------------------------------

Hi jhance,

How can I know ehich line? That error happened after I close the program!
0
 
LVL 32

Expert Comment

by:jhance
Comment Utility
Did you run under the debugger or did you just run the DEBUG build?  There is a DIFFERENCE.

Please build DEBUG and hit F5.  This will run under the debugger and wil display your fault and give you the chance to view the source line and the call stack.
0
 

Author Comment

by:markdot
Comment Utility
Hi jhance,

???????perhaps ... and I don't know what is Visual Studio DEBUGGER !!
0
 
LVL 32

Expert Comment

by:jhance
Comment Utility
For the 3rd time:

1) Choose the DEBUG build.

2) Build

3) Hit F5
0
 
LVL 9

Expert Comment

by:ShaunWilde
Comment Utility
What do you use to write/compile in relase/debug the program - rather than use Execute use 'GO' or F5 or Build/Start Debug/Go

then when program crash it will give you a stack (a list of function calls) the will help you discover the crash - if you lucky it will even go to the line of the crash
0
 

Author Comment

by:markdot
Comment Utility
Hi Experts,

I was doing Build | Start Debug | Go
after I clicked the 'x' button in my form (window), the error appeared.....I can then find the Call Stuck from menu View | Debug Windows:
VAL! 004412c5()
VAL! 004418b2()
VAL! 00464cd4()
VAL! 00464d9f()
VAL! 004db9af()
VAL! 00464dcf()
VAL! 00464d4c()
VAL! 004423ff()
VAL! 00442360()
VAL! 00444ad2()
KERNEL32! bff8b560()
KERNEL32! bff8b412()
KERNEL32! bff89dd5()

One more strange thing was: I got no error onece...
0
 
LVL 32

Expert Comment

by:jhance
Comment Utility
Debug the DEBUG BUILD, not the RELEASE BUILD!
0
 

Author Comment

by:markdot
Comment Utility
Hi experts,

I checked 'Generate debug info' in  'Project | (Win32 Debug) Link', after closed the program, I got the Call Stack:

_CrtMemCheckpoint(_CrtMemState * 0x007cfd10) line 1734 + 3 bytes
_CrtDumpMemoryLeaks() line 1928 + 9 bytes
_AFX_DEBUG_STATE::~_AFX_DEBUG_STATE() line 132
_AFX_DEBUG_STATE::`scalar deleting destructor'(unsigned int 1) + 15 bytes
CProcessLocalObject::~CProcessLocalObject() line 458 + 38 bytes
CProcessLocal<_AFX_DEBUG_STATE>::~CProcessLocal<_AFX_DEBUG_STATE>() + 15 bytes
$E372() + 13 bytes
doexit(int 0, int 0, int 0) line 353
exit(int 0) line 279 + 13 bytes
WinMainCRTStartup() line 212
KERNEL32! bff8b560()
KERNEL32! bff8b412()
KERNEL32! bff89dd5()
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:markdot
Comment Utility
Hi jhance,

I think I was running in degub becase I set a stop pint in a line of the program and that did stopped the runnining at htat line.
0
 
LVL 9

Accepted Solution

by:
BeyondWu earned 40 total points
Comment Utility
There must have overflow in your code.Check your code with each array,list,string and any other things which maybe cause overflow.
0
 
LVL 2

Expert Comment

by:xu2000
Comment Utility
Is that an ODBC app?
Make sure close all database connection and recordset.

Xu
0
 
LVL 9

Expert Comment

by:Pacman
Comment Utility
A piece of your code wrote to a memory area to which you shouldn't write data.
This kind of errors are pretty hard to locate.
Unfortunately the debugger couldn't help you because the system crashed somewhere outside of your code with no usable call stack.

I see 2 possibilites for you:

1. check your code
Check pointers, arrays, ...

2. use BoundsChecker
Let BoundsChecker check your code.
BoundsChecker will show you exactly the line of code which caused the trouble.

hope this helps
Pacman
0
 
LVL 6

Expert Comment

by:MichaelS
Comment Utility
>A piece of your code wrote to a memory area to which you shouldn't write data.
>This kind of errors are pretty hard to locate.
>Unfortunately the debugger couldn't help you because the system crashed somewhere outside of your code
>with no usable call stack.

In such case you can use "_malloc_dbg" instead of "new" and "_free_dbg" instead of "delete". If you overload operators new and delete than you will get a place where not allocated memory gets damaged. Check MSDN for details or ask here if you like to use that way.
0
 

Author Comment

by:markdot
Comment Utility
Hi experts,

Thank you so much for your suggestions.

Firstly, where to find BoundsChecker? I believe that would be helpfull for my project.

My project includes malloc-free for the C code part and new-delete for the MFC part.

No database in the project. Many arrays, structures, pointers and dialog boxes.

I have found if I commete a few line code, the problem dissapeared....but when I commented a dialog box and uncomment the above few lines, the problem also not happend....
0
 
LVL 9

Expert Comment

by:Pacman
Comment Utility
BoundsChecker is a real "must have" for professional developers.
Visit http://www.numega.com to check it out!

regards
Pacman
0
 
LVL 6

Expert Comment

by:MichaelS
Comment Utility
what's about _malloc_dbg and _malloc_free?
0
 
LVL 2

Expert Comment

by:xu2000
Comment Utility
>I have found if I commete a few line code, the
>problem dissapeared....but when I commented a dialog
>box and uncomment the above few lines, the problem also not happend....

So post these code.

Xu
0
 

Author Comment

by:markdot
Comment Utility
Hi Experts,

I have found the problem:
The memory allocation for an array was not big enough!

This project was running in Borland C++ and in VC++ console mode without any problem. The error happend when I put it in MFC AppWizard(exe) mode and added some dialog boxes.

Thank you for all experts helped me in this question. I am going to split the points for xu2000, Pacman, BeyondWu and cypherljk. Please let me know if you don't agree:-)
0
 

Author Comment

by:markdot
Comment Utility
Hi experts,

I have increased and then splited the points for
xu2000, Pacman, BeyondWu and cypherljk, 40 each:-)

I accept BeyondWu's comment as answer.

xu2000, Pacman and cypherljk please find the question titled "points for ...." and response that for your points.

Thanks a lot for the others experts as well.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video discusses moving either the default database or any database to a new volume.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now