gdb:它如何知道变量类型和大小? [英] gdb: how does it know the variable type and size?

查看:218
本文介绍了gdb:它如何知道变量类型和大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



示例C代码:

/ p>

  typedef struct _B 
{
A aa;
double b;
char c [LEN];
int d;
char * a_ptr [10];
} B;

B this_b;

如果我用 gcc -g gdb a.out 之后, gdb 确切地知道什么和哪里 a_ptr
pre $(gdb)p&(this_b.a_ptr)
$ 1 =(char *( *)[10])0x804a084

它是怎么做到的?我可以通过其他实用程序来做同样的事情(知道它的地址和类型)吗?

解决方案

当您使用 -g 标志,GCC(和大多数其他编译器)在你的二进制文件中存储额外的调试信息( a.out )。

您可以使用GDB以外的工具检查该信息。例如, readelf -w a.out (假设您在Linux或其他 ELF 平台上)。



您也可以比较 a.out 在使用或不使用 -g 。调试二进制文件的大小是5到10倍。


I'm trying to figure this out as I'm trying to do the same thing (hopefully) with a home grown script:

Example C code:

typedef struct _B
{
    A aa;
    double b;
    char c[LEN];
    int d;
    char *a_ptr[10];
 } B;

 B this_b;

If I compile this with gcc -g and gdb a.out afterwards, gdb knows exactly what and where a_ptr is:

(gdb) p &(this_b.a_ptr)
$1 = (char *(*)[10]) 0x804a084

how does it do that? And can I do the same thing (knowing it's address and type) through other utilities?

解决方案

When you build with the -g flag, GCC (and most other compilers) stores additional "debugging info" in your binary (a.out).

You can examine that info with tools other than GDB. For example, readelf -w a.out (assuming you are on Linux or another ELF platform).

You can also compare the size of a.out when built with and without -g. It is not uncommon for the debug binary to be 5 to 10 times larger.

这篇关于gdb:它如何知道变量类型和大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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