C++ 链接器生成的 .map 文件有什么用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/755783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the use of .map files the linker produces?
提问by sharptooth
What is the use of .map files VC++ linker produces when /MAP parameter or "Generate map file" project setting is used? When do I need them and how do I benefit from them?
使用 /MAP 参数或“生成映射文件”项目设置时,VC++ 链接器生成的 .map 文件有何用途?我什么时候需要它们,我如何从它们中受益?
采纳答案by Canopus
A nice article on how to use map files for finding crashes.
一篇关于如何使用地图文件查找崩溃的好文章。
http://www.codeproject.com/KB/debug/mapfile.aspx
http://www.codeproject.com/KB/debug/mapfile.aspx
Manually doing all this is very uninteresting.
手动完成所有这些非常无趣。
I am not aware of any tools which can read map file and help in finding the crash location. If anybody knows please update us.
我不知道有任何可以读取地图文件并帮助查找崩溃位置的工具。如果有人知道请更新我们。
回答by Jason S
For embedded systems, map files are a lot more useful. (Although you wouldn't be using Visual C++ for that ;)
对于嵌入式系统,地图文件更有用。(尽管您不会为此使用 Visual C++ ;)
Things like knowing how close you are to running out of program/data memory, and what location a particular variable resides in, are important.
诸如了解程序/数据内存即将耗尽以及特定变量驻留的位置之类的事情很重要。
回答by Dennis
WinDBG uses .map and .pdb files to help debug crashes, when analysing .hdmp and .mdmp crash dumps.
在分析 .hdmp 和 .mdmp 崩溃转储时,WinDBG 使用 .map 和 .pdb 文件来帮助调试崩溃。
Basically they map memory addresses to functions and variables within the .exe (or .dll). Very useful in general.
基本上,它们将内存地址映射到 .exe(或 .dll)中的函数和变量。一般非常有用。
EDIT: The most useful way to debug "after the fact" crashes is using WinDbg for me (windows platform). Open it up, and open the crash dump. Then set the source path to point at the code (if you have it), the symbol path to point at your .map and .pdb and the image path to the .exe, and type "!analyse -v" in the command line. Now you have a full stack trace with lines of code and everything.
It's even better if you have the MS symbol server in the path, and if the full page heap was turned on or adplus was running. See these two favourite WinDbg resources of mine:
First stop :: http://www.microsoft.com/whdc/devtools/debugging/debugstart.mspx
Force load the symbols :: http://www.osronline.com/ShowThread.cfm?link=182377
Useful site :: http://www.dumpanalysis.org/blog/index.php/category/windbg-tips-and-tricks/page/7/
编辑:调试“事后”崩溃的最有用的方法是为我使用 WinDbg(Windows 平台)。打开它,然后打开故障转储。然后设置源路径指向代码(如果你有的话),符号路径指向你的 .map 和 .pdb 以及指向 .exe 的图像路径,然后在命令行中输入“!分析 -v” . 现在,您拥有包含代码行和所有内容的完整堆栈跟踪。
如果路径中有 MS 符号服务器,并且整页堆已打开或 adplus 正在运行,那就更好了。查看我最喜欢的这两个 WinDbg 资源:
第一站 :: http://www.microsoft.com/whdc/devtools/debugging/debugstart.mspx
强制加载符号 :: http://www.osronline.com/ShowThread。 cfm?link=182377
有用的站点 ::http://www.dumpanalysis.org/blog/index.php/category/windbg-tips-and-tricks/page/7/
回答by Toon Krijthe
You need them rarely, but they can be handy debugging some problems because they give information on the location of functions and data.
您很少需要它们,但它们可以方便地调试一些问题,因为它们提供有关函数和数据位置的信息。
For example:
例如:
- detailed information on all segments (code, data and other).
- link line numbers to code
- 所有段(代码、数据和其他)的详细信息。
- 将行号链接到代码
You can use map files for debugging tools.
您可以将映射文件用于调试工具。
回答by Dmitry Grigoryev
Linker maps can be very useful in large projects when you need to track dependencies between compilation units and libraries. Typically, a linker will report a symbol which caused problems, and more often than not, a simple search for this symbol name won't return any results (or will return tons of false positives for symbols like read
).
当您需要跟踪编译单元和库之间的依赖关系时,链接器映射在大型项目中非常有用。通常,链接器会报告导致问题的符号,而且通常情况下,对该符号名称的简单搜索不会返回任何结果(或者会返回大量误报,例如read
)。
Without a linker map, the only option you have is to analyze all available source files (after preprocessing pass if macros were used, which is typically the case) and hope that you find the relevant spot.
如果没有链接器映射,您唯一的选择是分析所有可用的源文件(如果使用了宏,则在预处理过程之后,通常是这种情况)并希望您找到相关的位置。
Linker maps usually have a section called "reference by file/symbol" which tells you which object file was required by another object file of your project, and which symbol exactly was referenced.
链接器映射通常有一个名为“按文件/符号引用”的部分,它告诉您项目的另一个目标文件需要哪个目标文件,以及确切引用了哪个符号。
I was once working on a project which had to be ported on a system without locale support. The linker was reporting "undefined reference to _localeconv_r
" errors, which would have been a pain to track down by searching through the sources. Luckily, a GCC linker map file generated with -Map=output.map
revealed all problematic functions with a single search.
我曾经从事过一个项目,该项目必须在没有语言环境支持的系统上进行移植。链接器报告“未定义的引用_localeconv_r
”错误,通过搜索源来追踪会很痛苦。幸运的是,生成的 GCC 链接器映射文件通过-Map=output.map
一次搜索揭示了所有有问题的函数。