简体   繁体   English

一种在gdb中使用内存地址打印的方法

[英]A way to print with memory address in gdb

Is there a way to include the memory address whenever printing something in gdb.有没有办法在 gdb 中打印内容时包含内存地址。 For example:例如:

>>> p __libc_argc
$4 = 1

Instead, I'd like to have:相反,我想要:

>>> p __libc_argc
$4 = 0x7fffffffec63  1

To print the memory address of a variable just add & before its name.要打印变量的内存地址,只需在其名称前添加& If you often want to print both the variable address and its value it might be worth creating a command for that.如果您经常想打印变量地址及其值,可能值得为此创建一个命令。 For instance, add the code below to your .gdbinit file例如,将下面的代码添加到您的.gdbinit文件中

define pwa
  print &$arg0
  print $arg0
end

With this, you will have a pwa command (short for "print with address") that you can use instead of the standard print command whenever you want both the address and the value to be printed.有了这个,您将拥有一个pwa命令(“print with address”的缩写),只要您想要print地址和值,就可以使用它来代替标准的print命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM