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

我们假设我有一个类似的数组

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

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

p (short[2])*foo

我明白了

{256, 1}

也就是说,两个字节被解释为小端序的短路.

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

最佳答案 使用
set endian big.使用set endian auto切换回自动endianess选择.

(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) 
点赞