I was trying to use MAP to debug suddenly found something is missing after some searching here is what I found.
Couple of years back VC++ developers where using this method to debug applications.
This was using
/MAP,
/MAPINFO: EXPORTS linker switches and
/MAPINFO: LINES compiler switch
Unfortunately /MAPINFO: LINES has been deprecated starting VS 2003.
So here is how to achieve the same result with VS 2005 and above.
First the required settings :
- We need to do the following settings in the linker section need to select the
- Generate MAP file
- MAP file exports
As shown in the fig below.
- Do the following settings in the C++ section of the project.
- Assembler output: add the compiler switch /FAcs
This will output a .cod file which will contain both the machine code , assembly code along with Source. As shown in the figure below.
Next the actual debugging.
- The following will be the code snippet I plan to use to simulate the exception.
char* chCrash=NULL;
*chCrash='x';
- Once you run the faulty program you will end up with access violation dialog as shown below.
- You can address in this exception is 0x00040106c.
- Open the MAP file you will find the preferred load address.
Preferred load address is 0x00400000
- Exception address – Load address = offset where the exception has happened. Which would be : 0x106c.
- But the actual WinMain starts at 0x1000 from 0x00400000
- So the actual offset would be 0x6c
- This offset lies between the
0001:00000000 _wWinMain@16 00401000 f DebuggingUsingMAP_AND_COD.obj
0001:00000100 ?MyRegisterClass@@YAGPAUHINSTANCE__@@@Z 00401100 f DebuggingUsingMAP_AND_COD.obj
As shown in the above two lines from the .MAP file.
- So now open the .COD file and go to an offset 0x6c from _wWinMain@16
0006c c6 00 78 mov BYTE PTR [eax], 120 ; 00000078H
Here 120 is the ascii value of ‘x’, which corresponds to *chCrash='x';
That is it! For now hopefully I have revived some old memories.