如何在GDB中编译C++代码?

3
我正在遵循这个手册:

https://sourceware.org/gdb/onlinedocs/gdb/Compiling-and-Injecting-Code.html

$ gdb ./test
(gdb) break main
(gdb) run
(gdb) compile code std::cout << "Hello world\n";
No compiler support for language c++.
(gdb) compile code print("hello world")
No compiler support for language c++.

这是否意味着 g++ 不受支持?或者我需要以某种特殊的方式配置 GDB?


你正在使用哪个操作系统? - Raptor
Ubuntu 16.04,g++ 5.2,gdb 7.11 - random
尝试运行 sudo apt-get update && sudo apt-get install build-essentials - Raptor
ArchLInux,g++ 8.2.0,gdb 8.2.1也存在问题... - recolic
1个回答

1
很可能您使用的调试器太旧了。在7.12之前(甚至更晚),用户无法重新定义compile-gcc符号。因此,似乎没有办法为C++指定编译器。但是,问题已经报告并得到解决。我想最好的解决方案是通过从官方存储库编译更新的gdb版本。
另一种解决方案是手动预编译代码并在gdb中手动注入,如这里所述。听起来很有趣,但不确定这是否是简单的方法!

在Ubuntu 19.04 GDB 8.2.91上,我可以使用简单的编译,例如compile code i = 1,但是当我尝试使用compile code std::cout << "Hello world\n";时,它失败了,并显示错误信息:internal compiler error: in plugin_build_decl, at libcc1/libcp1plugin.cc:1059。最小示例请参见:https://dev59.com/1VXTa4cB1Zd3GeqP4LRs#31709579。 - Ciro Santilli OurBigBook.com

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接