1. Detailed information on all segments (code, data and other).
2. Link line numbers to code
With MAP file, you can easy to know where is your function, This will be help you easy to do auto game!
Explore My Other Channel for More Cool and Valuable Insights
👉 Youtube Learn Tech Tips👉 Tiktok
👉 Facebook:Creating a MAP file
Well first of all, you'll need a MAP file. If you don't have one, it will be nearly impossible to find where your application crashed using the crash address. So first, I'll show you how to create a good MAP file. For this, I will create a new project (MAPFILE). You can do the same, or adjust your own project. I create a new project using the Win32 Application option in VC++ 6.0, selecting the 'typical "Hello Word!" application' to keep the size of the MAP file reasonable for explanation.
Once created we need to adjust the project settings for the release version. In the C/C++ tab, select "Line Numbers Only" for Debug Info
Many people forget this, but you'll need this option if you want a good MAP file. This will not affect your release in any way. Next is the Link tab. Here you need to select the "Generate mapfile" option. Also, type the switches /MAPINFO:LINES and /MAPINFO:EXPORTS in the Project Options edit box.
Now, you're ready to compile and link your project. After linking, you will find a .map file in your intermediate directory (together with your exe).
If you using Microsoft Visual Studio 2005, 2008, 2010, 2012, 2015. Right click to projects properties -> choose Linker -> Debugging -> Generate Map File -> Yes (/MAP)
Example:
I have one project, after I gen this code with map file, you can see this
// MouseUtilDlg.cpp : implementation file
//
/* ********************************************************
* Author: Zidane (huuvi168@gmail.com)
* Last Modified: 2015-08-13
* *******************************************************/
#include "stdafx.h"
#include "MouseUtil.h"
#include "MouseUtilDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CMouseUtilDlg dialog
CMouseUtilDlg::CMouseUtilDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMouseUtilDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMouseUtilDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CMouseUtilDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// CMouseUtilDlg message handlers
BOOL CMouseUtilDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMouseUtilDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMouseUtilDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMouseUtilDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CMouseUtilDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
CString csMouseMsg;
csMouseMsg.Format(L"X %d Y %d", point.x, point.y);
AfxMessageBox(csMouseMsg);
CWnd::OnLButtonDown(nFlags, point);
}
Here is my map file, If you have this file, you can easy to view all projects data, structure in map file. Let's see
MouseUtil
Timestamp is 55cc6bde (Thu Aug 13 17:05:18 2015)
Preferred load address is 00400000
Start Length Name Class
0001:00000000 005a12fbH .text CODE
0001:005a1300 000350daH .text$x CODE
0001:005d63e0 00003c7eH .text$yc CODE
0001:005da060 00001e74H .text$yd CODE
0002:00000000 00000104H .CRT$XCA DATA
0002:00000104 0000011cH .CRT$XCC DATA
0002:00000220 000001f4H .CRT$XCL DATA
0002:00000414 0000043eH .CRT$XCU DATA
0002:00000854 00000104H .CRT$XCZ DATA
0002:00000958 00000104H .CRT$XIA DATA
0002:00000a5c 0000011cH .CRT$XIC DATA
0002:00000b78 00000104H .CRT$XIY DATA
0002:00000c7c 00000104H .CRT$XIZ DATA
0002:00000d80 00000104H .CRT$XPA DATA
0002:00000e84 00000109H .CRT$XPX DATA
0002:00000f90 00000104H .CRT$XPXA DATA
0002:00001094 00000104H .CRT$XPZ DATA
0002:00001198 00000104H .CRT$XTA DATA
0002:0000129c 00000104H .CRT$XTZ DATA
0002:000013a0 00083191H .rdata DATA
0002:00084534 00000173H .rdata$debug DATA
0002:000846a8 00010963H .rdata$r DATA
0002:00095010 000032b9H .rdata$sxdata DATA
0002:000982cc 00000104H .rtc$IAA DATA
0002:000983d0 00000769H .rtc$IMZ DATA
0002:00098b3c 00000104H .rtc$IZZ DATA
0002:00098c40 00000104H .rtc$TAA DATA
0002:00098d44 00000769H .rtc$TMZ DATA
0002:000994b0 00000104H .rtc$TZZ DATA
0002:000995b8 0002ff84H .xdata$x DATA
0002:000c953c 00000104H ATL$__a DATA
0002:000c9640 00000104H ATL$__z DATA
0002:000c9744 00000000H .edata DATA
0003:00000000 0000a3b2H .data DATA
0003:0000a3c0 000084c4H .bss DATA
0004:00000000 0000017cH .idata$2 DATA
0004:0000017c 00000014H .idata$3 DATA
0004:00000190 00001480H .idata$4 DATA
0004:00001610 00001480H .idata$5 DATA
0004:00002a90 000046b4H .idata$6 DATA
0005:00000000 00001129H .rsrc$01 DATA
0005:00001130 000185c3H .rsrc$02 DATA
Address Publics by Value Rva+Base Lib:Object
0000:00000000 __except_list 00000000 <absolute>
0000:00000a5c ___safe_se_handler_count 00000a5c <absolute>
0000:00000000 ___ImageBase 00400000 <linker-defined>
0001:00000370 ??0CMouseUtilApp@@QAE@XZ 00401370 f MouseUtil.obj
0001:000003d0 ??1CMouseUtilApp@@UAE@XZ 004013d0 f i MouseUtil.obj
0001:00000420 ??1CMouseUtilDlg@@UAE@XZ 00401420 f i MouseUtil.obj
0001:00000470 ??_GCMouseUtilApp@@UAEPAXI@Z 00401470 f i MouseUtil.obj
0001:00000470 ??_ECMouseUtilApp@@UAEPAXI@Z 00401470 f i MouseUtil.obj
0001:000004e0 ?GetApplicationRecoveryParameter@CWinApp@@UAEPAXXZ 004014e0 f i MouseUtil.obj
0001:00000520 ?GetApplicationRecoveryPingInterval@CWinApp@@UAEKXZ 00401520 f i MouseUtil.obj
0001:00000560 ?GetApplicationRestartFlags@CWinApp@@UAEKXZ 00401560 f i MouseUtil.obj
0001:000005a0 ?GetMessageMap@CMouseUtilApp@@MBEPBUAFX_MSGMAP@@XZ 004015a0 f MouseUtil.obj
0001:000005f0 ?GetThisMessageMap@CMouseUtilApp@@KGPBUAFX_MSGMAP@@XZ 004015f0 f MouseUtil.obj
0001:00000630 ?InitInstance@CMouseUtilApp@@UAEHXZ 00401630 f MouseUtil.obj
0001:000007c0 ?LoadCustomState@CWinAppEx@@MAEXXZ 004017c0 f i MouseUtil.obj
0001:00000800 ?OnWorkspaceIdle@CWinAppEx@@UAEHPAVCWnd@@@Z 00401800 f i MouseUtil.obj
0001:00000840 ?PreLoadState@CWinAppEx@@MAEXXZ 00401840 f i MouseUtil.obj
0001:00000880 ?PreSaveState@CWinAppEx@@MAEXXZ 00401880 f i MouseUtil.obj
0001:000008c0 ?ReopenPreviousFilesAtRestart@CWinApp@@UBEHXZ 004018c0 f i MouseUtil.obj
...
Thank you for reading this post. I hope you found it helpful and easy to follow. If you have any feedback or questions about
A Simple Way to Generate a Map File in C++ ,
please share them in the comments below. I would love to hear from you and discuss this topic further
✋✋✋✋
Webzone Tech Tips Zidane, all things tech tips web development
- I am Zidane, See you next time soon ✋✋✋✋