windows 你能解释一下什么是 C++ 世界中的符号和调试符号吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3694900/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:14:31  来源:igfitidea点击:

Can you explain what's symbols and debug symbols in c++ world?

c++windowssymbols

提问by COMer

Is it true that binary files like executables are composed of symbols and debug symbol is one kind of them?

像可执行文件这样的二进制文件是由符号组成的,调试符号是其中的一种吗?

How to understand the symbol?

如何理解符号?

回答by Chubsdad

A very high level explanation follows:

一个非常高级的解释如下:

Firstly symbols are not in C++ world alone. They exist in binaries of several high level languages like C, C++ etc when built with some specified settings. Let's take the definition

首先,符号不仅仅存在于 C++ 世界中。当使用某些指定设置构建时,它们存在于几种高级语言(如 C、C++ 等)的二进制文件中。让我们来定义

'int i = 2;'

'int i = 2;'

In the binary, 'i' is just a memory location (e.g. 0x10203040) which is being initialized with 2. There is no memory location called 'i'. The name 'i' is assigned to that memory location by virtue of debug symbols that are loaded with binaries (when built with certain flags), which maintain a map of 'memory location' to the 'source level names'.

在二进制文件中,'i' 只是一个内存位置(例如 0x10203040),它被初始化为 2。没有名为 'i' 的内存位置。名称“i”通过加载二进制文件(当使用某些标志构建时)的调试符号分配给该内存位置,该符号维护“内存位置”到“源级别名称”的映射。

As an example, the PE file formathas provision for Debug Directory which stores information about debug symbols. These are very useful while debugging because in absence of such debug symbols, debugging just in terms of binray 0s and 1s would be a really very very challening task. So when you debug such a binary (which has the above definition of 'i') which has been built with debug flags, the debugger knows that the memory location '0x10203040' corresponds to 'i' by virtue of the Debug Directory in the PE file.

例如,PE 文件格式提供了用于存储有关调试符号信息的调试目录。这些在调试时非常有用,因为如果没有这样的调试符号,仅根据 binray 0 和 1 进行调试将是一项非常非常具有挑战性的任务。因此,当您调试使用调试标志构建的此类二进制文件(具有上述“i”的定义)时,调试器通过 PE 中的调试目录知道内存位置“0x10203040”对应于“i”文件。

回答by Hans Passant

Erm, no. Executable files contain machine code. And initialization values for global variables. On Windows, the debugging information is normally stored in a separate file, a .pdb. A piece of debug data from that file about a function or a variable in your program is called a symbol.

嗯,没有。可执行文件包含机器代码。以及全局变量的初始化值。在 Windows 上,调试信息通常存储在单独的文件 .pdb 中。该文件中有关程序中函数或变量的一段调试数据称为符号。

The dbghelp API is described here.

dbghelp API在这里描述