Gdb: mapping a char array as large trailing shorts

Suppose I have an array like

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

In gdb, on an x86 machine, if I say

p (short[2])*foo

I get

{256, 1}

these are two bytes that are interpreted as shortin a small trailing order.

Is there a convenient way (like a macro) to render gdbbytearray as large trailing shorts (or any other type) instead?

+4
source share
1 answer

Use set endian big. Use set endian autoto return to automatic selection.

(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) 
+2
source

All Articles