[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 419
  • Last Modified:

How to debug this?

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
markdot
Asked:
markdot
  • 8
  • 4
  • 2
  • +5
1 Solution
 
cypherljkCommented:
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
 
jhanceCommented:
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
 
markdotAuthor Commented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jhanceCommented:
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
 
markdotAuthor Commented:
Hi jhance,

???????perhaps ... and I don't know what is Visual Studio DEBUGGER !!
0
 
jhanceCommented:
For the 3rd time:

1) Choose the DEBUG build.

2) Build

3) Hit F5
0
 
ShaunWildeCommented:
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
 
markdotAuthor Commented:
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
 
jhanceCommented:
Debug the DEBUG BUILD, not the RELEASE BUILD!
0
 
markdotAuthor Commented:
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
 
markdotAuthor Commented:
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
 
BeyondWuCommented:
There must have overflow in your code.Check your code with each array,list,string and any other things which maybe cause overflow.
0
 
xu2000Commented:
Is that an ODBC app?
Make sure close all database connection and recordset.

Xu
0
 
PacmanCommented:
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
 
MichaelSCommented:
>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
 
markdotAuthor Commented:
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
 
PacmanCommented:
BoundsChecker is a real "must have" for professional developers.
Visit http://www.numega.com to check it out!

regards
Pacman
0
 
MichaelSCommented:
what's about _malloc_dbg and _malloc_free?
0
 
xu2000Commented:
>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
 
markdotAuthor Commented:
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
 
markdotAuthor Commented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 8
  • 4
  • 2
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now