gdb地址与“真实”地址之间的区别地址? [英] Difference between gdb addresses and "real" addresses?

查看:251
本文介绍了gdb地址与“真实”地址之间的区别地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在gdb中运行C / C ++程序(使用-g标志编译后),然后检查某些变量,参数等的地址,然后在gdb之外运行它(使用 ./ )这些地址是否与我在gdb中看到的地址相同?如果他们不同,他们通常是相似的,或者他们会有很大的不同?

If I run a C/C++ program in gdb (after compiling with the -g flag) and I examine the addresses of certain variables, arguments...etc, and then I run it outside of gdb (using ./) will these addresses be the same as the ones I saw in gdb? If they're different are they usually similar or will they be drastically different?

我问这是因为我有一个缓冲区溢出程序,在gdb中完美工作(有和没有但是当我尝试在gdb之外运行它时,它不起作用。

I ask this because I have a buffer overflow program that works perfectly in gdb (with and without breakpoints), however when I try to run it outside of gdb it doesn't work.

推荐答案


我检查某些变量,参数等等的地址,然后在gdb之外运行它(使用./)这些地址是否与我在gdb中看到的地址相同

I examine the addresses of certain variables, arguments...etc, and then I run it outside of gdb (using ./) will these addresses be the same as the ones I saw in gdb

它取决于。


  1. 主可执行文件中定义的全局变量将停留在相同的地址(除非可执行文件使用 -fpie 构建,并与 -pie 标记链接。

  2. 由于 ASLR 原因,其他共享库中定义的全局变量可能具有截然不同的地址。

  3. Lo由于ASLR,cal变量和参数可能会移动几个K字节。
  4. 堆分配的变量也可能由于ASLR或者您的程序是多线程而急剧移动。
  5. li>
  1. Global variables defined in the main executable will stay at the same address (unless the executable is built with -fpie and linked with -pie flags.
  2. Global variables defined in other shared libraries may have drastically different addresses due to ASLR.
  3. Local variables and parameters may move around by several K-bytes due to ASLR.
  4. Heap-allocated variables may also drastically move due to ASLR, or if your program is multi-threaded.

请注意,默认情况下,Linux上的GDB将禁用ASLR,以便于调试。您可以在GDB下重新启用ASLR,并将设置禁用随机化关闭。这可能会让你在GDB下重现这个问题。

Note that GDB on Linux by default disables ASLR, to make debugging easier. You can re-enable ASLR under GDB with set disable-randomization off. That may allow you to reproduce the problem under GDB.


我有一个缓冲区溢出

I have a buffer overflow

另请注意,像 Valgrind Address Sanitizer 对于查找缓冲区溢出比在GDB下运行更为有效。地址Sanitizer特别是很好,因为它在全局和堆栈中发现缓冲区溢出(Valgrind没有)。

Also note, that tools like Valgrind and Address Sanitizer are often significantly more effective for finding buffer overflows than running under GDB. Address Sanitizer in particular is great in that it finds buffer overflows in globals and on stack (Valgrind doesn't).

这篇关于gdb地址与“真实”地址之间的区别地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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