评估GDB变量/函数 [英] evaluate variable/function in gdb

查看:97
本文介绍了评估GDB变量/函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code,

...
char* seg = mmap(0, ...)
printf("seg=%x\n", seg);
...

该程序打印与 SEG = b7ffd000 。而在GDB(同一执行),使用时点/ X SEG ,它打印 $ 2 =为0x0 。我在这里混淆。是不是同一变种 SEG ?为什么不同的值。

The program prints with seg=b7ffd000. While in gdb (for the same execution), when using p/x seg, it prints $2 = 0x0. I am confused here. Isn't it the same var seg? why are the values different.

PS:在 MMAP ,第一个参数是映射内存和返回值preferably地址映射内存的实际地址

PS: in mmap, the first argument is the preferably address of mapped memory and the return value is the actual address of mapped memory.

推荐答案

现在,你已经回答了我的问题的意见,我可以回答!

Now that you've answered my question in the comments, I can answer!

这是你看到的的printf的的结果值是真实地址。您所看到的 0 作为,因为启用优化时 SEG 在调试器中的值,编译器是免费做各种奇怪的事情(这通常会使一步一步的调试技巧)。在可观察的行为应始终是正确的,但(假设你不依赖于任何未定义行为)。

The value that you see as the result of the printf is the real address. You are seeing 0 as the value of seg in the debugger because when optimizations are enabled, the compiler is free to do all sorts of weird things (which generally makes step-by-step debugging tricky). The "observable" behaviour should always be correct, though (assuming you're not relying on any undefined behaviour).

这篇关于评估GDB变量/函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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