Delphi finds memory address error code in the map file in the row

Source: Internet
Author: User

What is a map file

What is a MAP file? Simply put, a MAP file is a unique textual representation of the program's global symbols, source files, and code line number information, which can be used anywhere, at any time, without the need for additional programs to support it. And it's the only savior who can find out where the program crashed.

If you are looking for a code line number, you need to do some hexadecimal subtraction using the following formula:

Crash Line offset = crash address (Crash addresses)-base address (ImageBase address)-0x1000

Why did you do it? The crash addresses we get are all derived from the offset address + base site, so the base address is subtracted when calculating the line number, in general, the value of the base address is 0x00400000 . Also, since the code snippet for a generic PE file starts with a 0x1000 offset, you must subtract 0x1000.

The method of generating map file under the second Delphi

Map file selection detailed, Linker, options, Project. The generated location is in the same directory as the EXE file.

Three examples

Code

Procedure Tform1.button1click (Sender:tobject);
Var
I, J:integer;
P:pchar;
Begin
I: = ten
;
J: = 0
;
P: =
nil;
p^: = ' A ';  41 lines. There will be an error
.
End

Error when running

Here you can find the error address is:$004ac0e2

Based on: Crash line offset = crash address (Crash addresses)-base address (ImageBase address)-0x1000

=$004ac0e2 -$00400000-$1000

=$000ab0e2

Open the generated map file with Notepad


Line numbers for Unit1 (Unit1.pas) segment. Text

0001:000AB0C4 0001:000ab0ce 0001:000ab0e0 0001:000ab0e2
0001:000ab0e5 0001:000ab118 0001:000ab11f

So, by finding the maximum value in the map file that is less than or equal to $00000a51, we are going to get the crash line offset.

This gets the error line in the 41 line of the UNIT1 unit.   This is exactly the line: p^: = ' A ';  36 lines. There will be an error.

This is a way of looking for errors, you can quickly locate the error code line based on your map file, and then analyze the cause of the error.

Delphi finds memory address error code in the map file in the row

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.