Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb: displaying char array as big endian shorts

Let's assume 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}

this is, two bytes are interpreted as a short in little endian order.

Is there a convenient way (e.g. a macro) to make gdb display a bytearray as big endian shorts (or whatever type) instead?

like image 639
lemzwerg Avatar asked Oct 03 '22 19:10

lemzwerg


1 Answers

Use set endian big. Use set endian auto to switch back to automatic endianess 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) 
like image 70
jxh Avatar answered Oct 05 '22 10:10

jxh