Find the exact address of variable Buf

后端 未结 3 382
甜味超标
甜味超标 2021-02-03 22:48

As reference, I\'m using the following code:

#include 
#include 

int main (void) {
    char buf[100]; // ------> How do I find         


        
3条回答
  •  庸人自扰
    2021-02-03 23:19

    The & operator will work when gdb is set to C language mode (and Objective-C).

    In any language mode you can use

    (gdb) info address buf
    Symbol "buf" is static storage at address 0x903278.
    

    (The output does not correspond exactly to your code.) I am writing this answer because this question is found even by people looking for the answer for other languages (including myself). One can also always switch to the C mode by set language c, but the symbol names may be different after this change.

提交回复
热议问题