【发布时间】:2013-03-21 03:05:33
【问题描述】:
如果我知道内存位置,有没有办法从 GDB 中查看内存内容?
也就是说,我正在调试我为操作系统课程编写的 x86 汇编程序。现在,我正在尝试使用 C 和 gas(GNU 汇编器)为 x86 上的 Linux 编写用户级线程库。我分配了自己的堆栈,并使 esp 寄存器指向该内存位置。现在我想读取内存以查看我分配的堆栈中的内容。
【问题讨论】:
标签: linux operating-system x86 gdb
如果我知道内存位置,有没有办法从 GDB 中查看内存内容?
也就是说,我正在调试我为操作系统课程编写的 x86 汇编程序。现在,我正在尝试使用 C 和 gas(GNU 汇编器)为 x86 上的 Linux 编写用户级线程库。我分配了自己的堆栈,并使 esp 寄存器指向该内存位置。现在我想读取内存以查看我分配的堆栈中的内容。
【问题讨论】:
标签: linux operating-system x86 gdb
我会尝试以下命令(在gdb 下)
p (int*)$esp
x /20x $esp
p ((int*)$esp)[3]
【讨论】:
x 允许您指定块大小(字节、16 位、32 位、64 位),默认值是您上次使用的任何值。最初是 32 位,GCC 将其称为“单词”,即使在 x86 上,这不是 x86 ISA 术语中“单词”的含义。
使用x addr了解更多详情,请查看https://visualgdb.com/gdbreference/commands/x
x command
Displays the memory contents at a given address using the specified format.
Syntax
x [Address expression]
x /[Format] [Address expression]
x /[Length][Format] [Address expression]
x
Parameters
Address expression
Specifies the memory address which contents will be displayed. This can be the address itself or any C/C++ expression evaluating to address. The expression can include registers (e.g. $eip) and pseudoregisters (e.g. $pc). If the address expression is not specified, the command will continue displaying memory contents from the address where the previous instance of this command has finished.
Format
If specified, allows overriding the output format used by the command. Valid format specifiers are:
o - octal
x - hexadecimal
d - decimal
u - unsigned decimal
t - binary
f - floating point
a - address
c - char
s - string
i - instruction
The following size modifiers are supported:
b - byte
h - halfword (16-bit value)
w - word (32-bit value)
g - giant word (64-bit value)
Length
Specifies the number of elements that will be displayed by this command.
【讨论】: