Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 637
COMer Avatar asked Sep 12 '10 12:09

COMer


People also ask

What is debug symbols in C?

A debug symbol is a special kind of symbol that attaches additional information to the symbol table of an object file, such as a shared library or an executable.

What are debugging symbols and what purpose do they serve?

A set of special characters generated when a program is compiled and containing information about the location of variables and functions in the resulting binary file, plus other service information. This data set can be used for step-by-step debugging of the program or examining third-party code.

What are debugging symbols in GDB?

A debugging symbol table is information included in the binary file that maps the compiled instructions to the corresponding line, function, and/or variable in the original source code. This is not something you would want to do with your final builds of any code, as it makes the final executable larger and slower.

What are symbols in CPP?

Special symbols: There are a variety of special symbols available in C++ like mathematical, logical and relational operators like +,-, *, /, \, ^, %, !, @, #, ^, &, (, ), [, ], ; and many more.


2 Answers

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.

like image 82
Chubsdad Avatar answered Oct 21 '22 01:10

Chubsdad


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.

like image 25
Hans Passant Avatar answered Oct 20 '22 23:10

Hans Passant