Sometimes our program crash will display a crash interface prompting us where we are interrupted. How can we find the corresponding line number based on the interrupt address?
To achieve this goal, you must first configure some engineering properties.
C/C ++-> General-> debugging information format-> program database
C/C ++-> Optimization-> disable
Linker-> debug-> Generate debugging information-> Yes
-> Generate a ing file-> Yes
-> Ing file name-> $ (outdir)/$ (projectname). Map
-> Ing export-> Yes
-> Ing row-> Yes
int main (int argc, char* argv[]){ char * p = 0; *p = 'c'; return 0;}
When the program is executed, the following error occurs: 0xc000005: Access conflict occurs when the write location 0x00000000"
Now let's take a look at the map file. First, you can see the reference loading address: preferred load address is 00400000.
Timestamp is 4639462c (Thu May 03 10:17:16 2007) Preferred load address is 00400000 Start Length Name Class 0001:00000000 00003b58H .text CODE 0002:00000000 000000c4H .idata$5 DATA 0002:000000d0 00000c40H .rdata DATA 0002:00000d10 00000048H .rdata$debug DATA 0002:00000d60 00000008H .rdata$sxdata DATA 0002:00000d68 00000004H .rtc$IAA DATA 0002:00000d6c 00000004H .rtc$IZZ DATA 0002:00000d70 00000004H .rtc$TAA DATA 0002:00000d74 00000004H .rtc$TZZ DATA 0002:00000d78 00000014H .idata$2 DATA 0002:00000d8c 00000014H .idata$3 DATA 0002:00000da0 000000c4H .idata$4 DATA 0002:00000e64 00000366H .idata$6 DATA 0002:000011ca 00000000H .edata DATA 0003:00000000 00000004H .CRT$XCA DATA 0003:00000004 00000004H .CRT$XCAA DATA 0003:00000008 00000004H .CRT$XCZ DATA 0003:0000000c 00000004H .CRT$XIA DATA 0003:00000010 00000008H .CRT$XIC DATA 0003:00000018 00000004H .CRT$XIZ DATA 0003:0000001c 00000004H .CRT$XPA DATA 0003:00000020 00000004H .CRT$XPZ DATA 0003:00000024 00000004H .CRT$XTA DATA 0003:00000028 00000004H .CRT$XTZ DATA 0003:00000030 00000274H .data DATA 0003:000002c0 00000598H .bss DATA
Crash address calculation:
Calculation: crash_address-preferred_load_address-0x1000
0x0040100e-0x00400000-0x1000 = 0x0000000e
Then find the corresponding OBJ in the map.
Address Publics by Value Rva+Base Lib:Object 0000:00000000 __except_list 00000000 <absolute> 0000:00000002 ___safe_se_handler_count 00000002 <absolute> 0001:00000000 _main 00401000 f test1.obj 0001:00000017 __amsg_exit 00401017 f LIBC:crt0.obj 0001:0000003c _mainCRTStartup 0040103c f LIBC:crt0.obj 0001:00000203 ___crtExitProcess 00401203 f LIBC:crt0dat.obj
Finally, find the first location that is less than the value calculated by OBJ and the calculated value in map.
Line numbers for./release/test1.obj (D:/test/test1/test1/test1.cpp) segment. Text 2 0001:00000000 3 0001:00000004 4 0001: 0000000b 5 0001:00000011
Then, find the first location in. Map that is smaller than the value we calculated.
So our interrupt location is at line 1.
Note: This article Reprinted from: http://blog.sina.com.cn/s/blog_4ae178ba0100w3sa.html