Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I debug an Access violation in the field?

Tags:

delphi

An application in the field is getting this message intermittently:

alt text

I am not able to reproduce this on my machine. I have also traced what I believe is the relevant code and can't find any access to uninitialized objects.

I've never had to deal with this kind of problem.

I did a build with madExcept and unfortunately the program does not crash once it is bundled.

Any opinions on madExcept vs EurekaLog for finding this kind of thing? I've never used FastMM. Would it be useful in his situation? (Delphi 2010) Any suggested flags to set in FastMM? Any other recommendations?

like image 829
RobertFrank Avatar asked Dec 27 '10 03:12

RobertFrank


People also ask

What is access violation Delphi?

It means your code is accessing some part of the memory it isn't allowed to. That usually means you have a pointer or object reference pointing to the wrong memory. Maybe because it is not initialized or is already released. Use a debugger, like Delphi.

What is the code of access violation?

An access violation occurs in unmanaged or unsafe code when the code attempts to read or write to memory that has not been allocated, or to which it does not have access. This usually occurs because a pointer has a bad value.

What is a read access violation?

Jan 29, 2018. A Read or Write Access Violation occurs when the application attempts to read or write memory from a memory address that is invalid. To be valid, the memory page must have a valid state, protection and type. The memory must be in the MEM_COMMIT state.

What is an access violation C++?

As its name says, this error occurs whenever you try to access a location that you are not allowed to access in the first place. In other words, whenever you will try to violate the norms of accessing a writing location set up by the C++ programming language, you will always come across this error.


3 Answers

Note the very low address you are attempting to read. This sort of error almost certainly means you attempted to dereference a nil pointer even if you can't find one.

Given your description of the behavior I would suspect you've got a memory stomp going on--something is blasting a zero on top of the pointer to an object. When you change things you move things around and the stomp moves to someplace harmless.

Turn on both range checking and overflow checking.

Note the offending object must be at least 3C0 bytes in size--this should help narrow it down, most objects will be smaller than this.

What I have done in the past with such errors that only show in the field is put logging checkpoints in--a bunch of lines that display something in an out of the way place--a simple sequence of numbers is fine. Find out what number is showing when it crashes and you know which of you checkpoints was the last to execute. If that doesn't narrow it down enough you can repeat the process now that you've narrowed it down.

like image 130
Loren Pechtel Avatar answered Sep 24 '22 12:09

Loren Pechtel


With a full map file you can identify the exact point in the code where this occurs. I hope you have a full map file for this image! Subtract $00401000 from the address at which the exception is raised ($007ADE8B in your case) and that corresponds to the values in the map file.

Having done that you know which object is nil and from there it is usually not too hard to work out what is going on.

One of the most common ways for this to occur is when a constructor raises an exception. When this occurs the destructor runs. If you access, in a destructor, a field that has not been initialised, and do anything other than call Free on it, then you will get an exception like this.

like image 26
David Heffernan Avatar answered Sep 22 '22 12:09

David Heffernan


Looks like a memory overwrite where changing memory layout (your machine vs field machine or adding madExcept) makes the overwrite change something harmless.

FastMM is great at of making this kind of problems happen more consistently (and finding their source). Download the full version of FastMM, add it as the first unit of your project, and turn on FullDebugMode on its settings.

It might cause the problem to be reproduceable in your machine right away. If not, don't forget to deploy FastMM_FullDebugMode.dll with your application for testing. Keep madExcept on and let it embed the .map file for call stacks.

like image 3
Leonel Avatar answered Sep 22 '22 12:09

Leonel