PDA

View Full Version : Detect an misterious acess violation [SOLVED]



arthurprs
24-03-2008, 08:06 PM
1 in 100 times (not really, just guessing) i run my program (debugging inside the IDE), my app trows an access violation (the debugger does not react to it) and the app closes after i close the access violation dialog

i already double checked the routines involved and i can't find it -.-'

someone can help me


Specs:
Delphi 7
win XP PRO

Robert Kosek
24-03-2008, 08:12 PM
Have you any idea about where it might have occurred within the source? If you have an idea of the problem region then you might reproduce it, and if you can reproduce it then you can track it down.

Do you even know what may be going on behind the scenes when it throws this exception?

arthurprs
24-03-2008, 08:54 PM
The error is after the window is showed at the screen (at this time nothing critical is happening in background)

Robert Kosek
24-03-2008, 09:48 PM
Can you be a little more specific what is happening, what components are on the form (if any), and what you might be doing in the source at that time? If it isn't proprietary then I can't be of much help without seeing the source to the OnCreate event.

JSoftware
24-03-2008, 09:55 PM
Notice what address you get the violation on and dump the disassembly your executable. make sure you have not stripped the symbols of the executable you dump the output of.

arthurprs
25-03-2008, 02:08 AM
Notice what address you get the violation on and dump the disassembly your executable. make sure you have not stripped the symbols of the executable you dump the output of.

:oops: how can i do that?

Mirage
25-03-2008, 05:20 AM
arthurprs, In D7 there is a Search=>Find Error menu option where you can enter the address where an AV happened. And it will show you the corresponding line in your source code.

JSoftware
25-03-2008, 05:50 AM
Notice what address you get the violation on and dump the disassembly your executable. make sure you have not stripped the symbols of the executable you dump the output of.

:oops: how can i do that?

I suppose you have binutils already, if not you can find them somewhere in binary form(they also come with fpc). Simply call

objdump -D project1.exe > disasm.txt
This will disassemble your executable and place the corresponding symbols(function names, variable names, etc) at the places in the assembler where they really are.

The access violation you get say something like "Access violation at address xxxxxxxx". This address should be somewhere in the dump

Memphis
25-03-2008, 03:01 PM
also what does the access violation state? read, write? file or what? when you get the error on the dialog box hit ctrl+c then paste here ?

arthurprs
25-03-2008, 07:05 PM
i "think" i have found the problem,

delphi does not initialize initialize global var of class types with nil (like i said 1/100 of the time)

not sure, but the problem seems to be solved

arthurprs
25-03-2008, 07:23 PM
arthurprs, In D7 there is a Search=>Find Error menu option where you can enter the address where an AV happened. And it will show you the corresponding line in your source code.
AWESOME TIP!

thanks =D

Robert Kosek
25-03-2008, 08:28 PM
i "think" i have found the problem,

delphi does not initialize initialize global var of class types with nil (like i said 1/100 of the time)

not sure, but the problem seems to be solvedYes, I never trust Delphi to explicitly initialize anything, local or global. For this reason I decided to always set it to nil if I do any testing upon it for nil, and to use FreeAndNil() to dispose of said object too.