Wednesday 6 September 2017

How to find structure member offset in gdb


(gdb) print (int)&((struct A*)0)->a

Above command can be used to find structure member offset 

For example your structure is 

struct node {
  int a;
  char b;
  short c;
};

If you want to find relative offset of char b then you need to run

(gdb) print (int)&((struct A*)0)->b
$2 = 4