gdb日常

查看内存地址的值

  • 命令examine/x

Examine memory: x/FMT ADDRESS.

ADDRESS is an expression for the memory address to examine.
FMT is a repeat count followed by a format letter and a size letter.
Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),
t(binary), f(float), a(address), i(instruction), c(char), s(string)
and z(hex, zero padded on the left).
Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).
The specified number of objects of the specified size are printed
according to the format. If a negative number is specified, memory is
examined backward from the address.
Defaults for format and size letters are those previously used.
Default count is 1. Default address is following last thing printed
with this command or “print”.

格式x/nfu addr

  • n:输出单元的个数
  • f:是输出格式。比如x是以16进制形式输出,o是以8进制形式输出
  • u:标明一个单元的长度。b是一个byte,h是两个byte(halfword),w是四个byte(word),g是八个byte(giant word)

以下面代码为例,查看

#include<iostream>
#include<string>
using namespace std;
int main() {
    int t[] = {1,2,3,4,5,6,7,8,9,10,11,12,1024,14,15,16,17,18,19,20};
    cout << t << endl;
}
(gdb) list
1       #include<iostream>
2       #include<string>
3       using namespace std;
4       int main() {
5           int t[] = {1,2,3,4,5,6,7,8,9,10,11,12,1024,14,15,16,17,18,19,20};
6           cout << t << endl;
7       }
8
(gdb) b main
Breakpoint 1 at 0x902: file test.cpp, line 4.
(gdb) r
Starting program: /home/liguo/code/gdb/a.out

Breakpoint 1, main () at test.cpp:4
4       int main() {
(gdb) n
5           int t[] = {1,2,3,4,5,6,7,8,9,10,11,12,1024,14,15,16,17,18,19,20};
(gdb) n
6           cout << t << endl;
(gdb) n
0x7ffffffee3b0
7       }
(gdb) x/20x 0x7ffffffee3b0
0x7ffffffee3b0: 0x00000001      0x00000002      0x00000003      0x00000004
0x7ffffffee3c0: 0x00000005      0x00000006      0x00000007      0x00000008
0x7ffffffee3d0: 0x00000009      0x0000000a      0x0000000b      0x0000000c
0x7ffffffee3e0: 0x00000400      0x0000000e      0x0000000f      0x00000010
0x7ffffffee3f0: 0x00000011      0x00000012      0x00000013      0x00000014
(gdb) x/20d 0x7ffffffee3b0
0x7ffffffee3b0: 1       2       3       4
0x7ffffffee3c0: 5       6       7       8
0x7ffffffee3d0: 9       10      11      12
0x7ffffffee3e0: 1024    14      15      16
0x7ffffffee3f0: 17      18      19      20
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值