What is Access Violation? How can I debug it?

zhaozj2021-02-11  175

What is AV error? How do I debug it?

When you have an AV (Access Violaion) wrong, this means that your program is trying to access a piece.

No more effective memory, please note that "no longer" is valid. In most cases, this error occurs because you try to access a memory that has been released, or you want to use a pointer that has not yet created an object.

Fortunately: Win32's memory system uses separate address spaces between different processes (Process). So we don't have to worry about the address space that will visit other processes, (there is this potential danger in Win 16). This means we can correctly utilize the information in the error dialog.

When we get an AV error dialog, there will be, for example, the words of av at ddress ????, as shown in the figure:

Write this address (as shown in: 0x4006A620), return to the program and open the debugged CPU window, right click "Goto Address", you will find an error information structure.

Of course, the CPU window appears in assembly language (askSEMBLY). You may be familiar with this. So you can scroll through the window to see which function is called. This way you can set breakpoints in this place.

Unfortunately, not every error is so easy to capture. Relatively speaking. The pointer problem is difficult to debug. There is a conventional law here that after the object is deleted. Please set it to NULL. So when you call, you can first look at whether this pointer is null. If it is null, you can output some debugging information in this place to facilitate you to find this place when you have an AV error.

/ / =========================================================================================================================================================================================== ==

Translator Note: For example, this:

IF (PNAME == NULL)

MessageBox ("Pointer PNAME IS NULL", "Hint", MB_OK;

This will be wrong when you pop up this dialog.

/ / =========================================================================================================================================================================================== =====

The last way to compare insurance is to set breakpoints as much as possible to see if it is NULL.

Translator Note:

This article tells us what is AV, generally generated causes and how to capture. I think it is just some of the relatively universal rules. There is no such thing as it is. For example, everyone knows that the object that is automatically destroyed by the system does not necessarily NULL.

In this case, this situation is not suitable by determining the value of the value of the pointer. Another aspect is another case of AV: The pointer has not been initialized (INITALIZATION) did not mention it, of course, this should be prevented by the writer.

In addition, the delete object referred to in the article is that the needle should be strong, this is also advocated, this is also mentioned by Scott Meyers, after all, deleting a NULL pointer is safe, and deleting a deleted pointer " Unpredictable. Article Source: http://community.borland.com/Article/0,1410,26406,00.html

转载请注明原文地址:https://www.9cbs.com/read-5364.html

New Post(0)