Solved

How to debug this?

Posted on 2001-08-22
21
406 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
ID: 6415114
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
ID: 6415163
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
ID: 6415201
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 32

Expert Comment

by:jhance
ID: 6415229
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
ID: 6415247
Hi jhance,

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

Expert Comment

by:jhance
ID: 6415293
For the 3rd time:

1) Choose the DEBUG build.

2) Build

3) Hit F5
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6415302
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
ID: 6415445
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
ID: 6415459
Debug the DEBUG BUILD, not the RELEASE BUILD!
0
 

Author Comment

by:markdot
ID: 6415568
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
 

Author Comment

by:markdot
ID: 6415594
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
ID: 6416085
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
ID: 6416344
Is that an ODBC app?
Make sure close all database connection and recordset.

Xu
0
 
LVL 9

Expert Comment

by:Pacman
ID: 6416478
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
ID: 6416600
>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
ID: 6416975
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
ID: 6417014
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
ID: 6417147
what's about _malloc_dbg and _malloc_free?
0
 
LVL 2

Expert Comment

by:xu2000
ID: 6418124
>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
ID: 6424996
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
ID: 6434494
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 124
Expand LInux Boot partition remotly 3 90
Sed question 2 84
Making an alias 7 94
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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 shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

785 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