How to get the relative address of a field in a structure dump. [C]

后端 未结 4 531
鱼传尺愫
鱼传尺愫 2021-01-31 11:50

We\'re working on a C program compiled with arm-eabi-gcc under Linux.

We\'re using a dump of a large structure and we\'re having problems determining at which adress we

4条回答
  •  情话喂你
    2021-01-31 12:29

    You can do it from a C program using the standard offsetof() macro, defined in stddef.h. However I'm not sure this is what you want, since you may be unable to run it (compiling it on the host will likely return wrong offsets).

    #include 
    #include 
    
    struct A {
      int a;
      char b;
      short c;
    };
    
    int main() {
        printf("Offset of b in A is %zu\n", offsetof(struct A, b));
        return 0;
    }
    

    However, you may be able to employ some hacks to get the offset from a compiled binary without executing it. Maybe assign a static variable the offset value, and find some way of getting its value.

提交回复
热议问题