5

假设我有一个像

char foo[] = { 0, 1, 1, 0 };

gdb,在 x86 机器上,如果我说

p (short[2])*foo

我明白了

{256, 1}

也就是说,两个字节被解释为short小端序。

有没有一种方便的方法(例如宏)可以将gdb字节数组显示为大端短裤(或任何类型)?

4

1 回答 1

4

使用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) 
于 2013-10-03T06:21:33.153 回答