王朝网络
分享
 
 
 

Convert access violation address to line no.

王朝delphi·作者佚名  2006-01-29
宽屏版  字体: |||超大  

Convert access violation address to line no.

Convert access violation address to line no in Delphi 3.

It is possible to take the address given when an access violation occurs in a running application and convert this back to a unit name, function name and line number in source code. This is done using a detailed map file generated when application was compiled.

Creating a map file.

First you need to create map file for project as follows:

1. First make sure code optimization is switch off in Project|Options dialog Compiler tab.

2. Then switch on detailed map file in the Project|Options dialog Linker tab.

3. Now rebuild your application with a Project|Build All. A map file will be generated with the same name as the project.exe e.g. project.map.

Converting access violation address.

Now if you get a access violation here's how to convert the address given back to unit name, function name and source code line no using the a detailed map file:

1. Take the value in Project|Options dialog Linker tab Image Base and add $1000 to it, note both values are in hexadecimal. The resulting value is the offset:

Offset = Linker|Memory Sizes|Image Base value + $1000 (standard value is $401000)

Now subtract this offset from the address given in the access violation to give you the map file address:

Map file address = Access violation address - Offset

E.g. If a access violation address was $00437575 then

Offset = $400000 + $1000 = $401000 and

Map file address = $00437575 - $401000 = $36575.

2. Open the map file using any text editor, if using Delphi just open in IDE. Note the map file is just a text file.

3. Finding unit name. Within the map file find the section containing unit names under the heading of 'Detailed map of segments', at top of file after segment map. This section contains a list of segment, start address, length, other info and unit name in address order. This maps out where each compiled unit resides in memory. To find unit name where AV occurred find the map file address in the list using start address and length. E.g. If the AV map file address is $36575 the unit name would be 'Unit1' given by the following line in the map file:

0001:00035184 00001448 C=CODE S=.text G=(none) M=Unit1 ACBP=A9

Note: Unit1 is in address range $35184 up to $365CC = ($35184 + $1448) $1448 = length.

4. Finding function name. Within the map file there are two sections listing functions, one in function name order titled 'Publics by Name' and one in address order titled 'Publics by Value'. Both list segment, function start address and function name. To find the function name where the AV occurred use the 'Publics by Value' section locating the map file address in the list. The address may not match up exactly as the AV may have occurred anywhere in the function, so look for the highest address before the map file address, that is the start address of the function. E.g. if the AV. map file address is $36575 the function name would be 'TForm1.Button11Click' given the following lines in the map file:

0001:0003642C TForm1.Button9Click

0001:00036484 TForm1.Button10Click

0001:00036564 TForm1.Button11Click

0001:0003657C Finalization

0001:000365C4 Unit1

5. Finding line no. At the end of the map file there will be a section for each compiled unit giving the the source line no, segment and start address in line address order, four line no's to a line in the map file. These map compiled address to source code line no. Find the section for the unit name found in step (3). Then to find the line no where the AV occurred find the highest address before the map file address. E.g. if the AV map file address is $36575 the line no would be 367 given the following line in the map file for 'Line numbers for Unit1(Unit1.pas)':

366 0001:00036564 367 0001:00036570 368 0001:00036578 370 0001:000365CB

Conclusion.

You should have now the unit name, function name and source code line no where the given access violation occurred.

Note 1:

If the access violation occurred in code other than yours, e.g. in SysUtils you will not be able to determine the function and line no unless you compile your application using the VCL source code. This does not mean that the AV was caused by a bug in the VCL but the AV just surfaced within some VCL code, in all probability the cause of the AV is still your code calling the VCL incorrectly.

Note 2:

You must always use the map file created for the exe when trying to locate source of AV using this technique. Ever time you recompile the map file could change, so using say newly compiled map file against a exe compiled several version ago in a project you will get erroneous result.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
>>返回首页<<
推荐阅读
 
 
频道精选
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有