Find the exact address of variable Buf

后端 未结 3 380
甜味超标
甜味超标 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条回答
  •  旧时难觅i
    2021-02-03 23:30

    If you enter the following into gdb, you'll get the address:

    start
    p &buf
    

    as in the following transcript:

    pax$ gdb ./qq.exe
    GNU gdb 6.8.0.20080328-cvs (cygwin-special)
    Copyright (C) 2008 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later 
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "i686-pc-cygwin"...
    (gdb) start
    Breakpoint 1 at 0x401144: file qq.c, line 2.
    Starting program: /home/pax/qq.exe
    [New thread 2912.0xf9c]
    [New thread 2912.0x518]
    main () at qq.c:2
    2       int main (int argc, char **argv) {
    (gdb) p &buf
    $1 = (char (*)[100]) 0x22ccd0
    (gdb)
    

提交回复
热议问题