简体   繁体   English

你能解释一下c ++世界中的符号和调试符号吗?

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

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? 如何理解符号?

A very high level explanation follows: 以下是一个非常高级的解释:

Firstly symbols are not in C++ world alone. 首先,符号不仅仅在C ++世界中。 They exist in binaries of several high level languages like C, C++ etc when built with some specified settings. 当使用某些指定的设置构建时,它们存在于几种高级语言(如C,C ++等)的二进制文件中。 Let's take the definition 我们来看看定义

'int i = 2;' 'int i = 2;'

In the binary, 'i' is just a memory location (eg 0x10203040) which is being initialized with 2. There is no memory location called 'i'. 在二进制文件中,'i'只是一个用2初始化的内存位置(例如0x10203040)。没有名为'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”分配给该内存位置,该符号将“内存位置”的映射维护为“源级别名称”。

As an example, the PE file format has provision for Debug Directory which stores information about debug symbols. 例如, PE文件格式提供了调试目录,该目录存储有关调试符号的信息。 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. 这些在调试时非常有用,因为在没有这样的调试符号的情况下,仅根据binray 0和1进行调试将是一个非常非常挑剔的任务。 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. 因此,当您调试使用调试标志构建的这样的二进制文件(具有上述'i'的定义)时,调试器通过PE中的调试目录知道内存位置'0x10203040'对应于'i'文件。

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. 在Windows上,调试信息通常存储在单独的文件(.pdb)中。 A piece of debug data from that file about a function or a variable in your program is called a symbol. 来自该文件的关于程序中的函数或变量的调试数据称为符号。

The dbghelp API is described here . 这里描述了 dbghelp API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM