gdb:将char数组显示为big endian short

时间:2013-10-03 06:09:47

标签: c debugging gdb endianness

我们假设我有一个类似

的数组
char foo[] = { 0, 1, 1, 0 };

gdb中,在x86计算机上,如果我说

p (short[2])*foo

我得到了

{256, 1}

这是两个字节,以小端顺序解释为short

是否有一种方便的方法(例如宏)使gdb显示一个bytearray作为大端短裤(或任何类型)?

1 个答案:

答案 0 :(得分:3)

使用set endian big。使用set endian auto切换回自动字节选择。

(gdb) p (short[2])*foo
$1 = {256, 1}
(gdb) set endian big
The target is assumed to be big endian
(gdb) p (short[2])*foo
$2 = {1, 256}
(gdb) set endian auto
The target endianness is set automatically (currently little endian)
(gdb) p (short[2])*foo
$3 = {256, 1}
(gdb)