gpt4 book ai didi

c++ - gdb 从函数打印静态变量

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:28:45 27 4
gpt4 key购买 nike

我们有一个 C++ 程序,例如:

int&
Instance()
{
static int test;
return test;
}

int
main( int argc, char ** argv )
{
int& test = Instance();
printf("%d\n",test);

return 0;
}

现在我正在尝试打印 Instance::test,正如某些 gdb 文档所建议的那样:https://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_52.html

然而,这会产生:

(gdb) p Instance::test

No symbol "test" in specified context.

我正在使用 -O0 -g 进行编译。

最佳答案

(gdb) p 'Instance()::test'

适用于 Ubuntu 14.04、gdb 7.7、g++ 4.8.2。我怎么知道那是符号?

$ nm -C a.out | grep test
0000000000601040 d Instance()::test

关于c++ - gdb 从函数打印静态变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25273727/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com