3

I'm following this manual:

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++.

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

random
  • 3,868
  • 3
  • 22
  • 39

1 Answers1

1

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.

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!

Thomas Legris
  • 124
  • 1
  • 9
  • On Ubuntu 19.04 GDB 8.2.91, I can use simple compiles such as `compile code i = 1`, but when I tried to `compile code std::cout << "Hello world\n"; ` it failed with: `internal compiler error: in plugin_build_decl, at libcc1/libcp1plugin.cc:1059`, minimal example at: https://stackoverflow.com/questions/5480868/how-to-call-assembly-in-gdb/31709579#31709579 – Ciro Santilli OurBigBook.com Sep 16 '19 at 10:54