首页 文章

打印所有全局变量/局部变量?

提问于
浏览
271

如何打印所有全局变量/局部变量?这可能在gdb中吗?

3 回答

  • 19

    输入info variables列出"All global and static variable names" .

    键入info locals以列出"Local variables of current stack frame"(名称和值),包括该函数中的静态变量 .

    键入info args以列出"Arguments of the current stack frame"(名称和值) .

  • 408

    如果你想看到调用函数的局部变量,请在 info locals 之前使用 select-frame

    例如 . :

    (gdb) bt
    #0  0xfec3c0b5 in _lwp_kill () from /lib/libc.so.1
    #1  0xfec36f39 in thr_kill () from /lib/libc.so.1
    #2  0xfebe3603 in raise () from /lib/libc.so.1
    #3  0xfebc2961 in abort () from /lib/libc.so.1
    #4  0xfebc2bef in _assert_c99 () from /lib/libc.so.1
    #5  0x08053260 in main (argc=1, argv=0x8047958) at ber.c:480
    (gdb) info locals
    No symbol table info available.
    (gdb) select-frame 5
    (gdb) info locals
    i = 28
    (gdb)
    
  • 89

    此外,由于 info locals 不显示您所在函数的参数,因此请使用

    (gdb) info args
    

    例如:

    int main(int argc, char *argv[]) {
        argc = 6*7;    //Break here.
        return 0;
    }
    

    argcargv 将不会被 info locals 显示 . 该消息将是"No locals."

    参考:info locals command .

相关问题