你能解释一下什么是 C++ 世界中的符号和调试符号吗? [英] Can you explain what's symbols and debug symbols in c++ world?

查看:33
本文介绍了你能解释一下什么是 C++ 世界中的符号和调试符号吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

如何理解符号?

推荐答案

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

A very high level explanation follows:

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

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

'int i = 2;'

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

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

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

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.

这篇关于你能解释一下什么是 C++ 世界中的符号和调试符号吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆