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

核能气质少年 提交于 2019-12-04 11:41:26

问题


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?


回答1:


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

'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'.

As an example, the PE file format has 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.




回答2:


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.

The dbghelp API is described here.



来源:https://stackoverflow.com/questions/3694900/can-you-explain-whats-symbols-and-debug-symbols-in-c-world

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!