如何在GDB中编译C ++代码? [英] How to compile C++ code in GDB?

查看:109
本文介绍了如何在GDB中编译C ++代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遵循本手册:

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?

Does this mean that g++ is not supported? Or I need to configure GDB in some special way?

推荐答案

这很可能是您使用的调试器太旧了. 在7.12之前(甚至更晚),用户听起来无法重新定义compile-gcc符号.结果,似乎没有办法为C ++指定编译器..尽管如此,问题已得到报告并得到解决. 我猜最好的解决方案是通过从

This is very likely that the debugger you are using is too old. It sounds too me that prior to 7.12 (maybe even later), user cannot redefine the compile-gcc symbol. As a result, there seems to be no way to specify a compiler for C++.. Nevertheless, the issue has been reported and addressed. I guess the best solution is to update gdb to a newer version, by compiling it from the official repository.

另一种解决方案是手动预编译代码,然后在gdb中手动注入代码,如此处.听起来很有趣,但不确定这是否简单!

Another solution would be to pre-compile the code manually and inject it manually within gdb, as explained here. Sounds fun but not sure this is the easy way!

这篇关于如何在GDB中编译C ++代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆