public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Compiling and injecting code in GDB: C++ in addition to C?
@ 2023-02-08 16:34 Robin Whittle
  2023-02-10 17:01 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Robin Whittle @ 2023-02-08 16:34 UTC (permalink / raw)
  To: gdb

[-- Attachment #1: Type: text/plain, Size: 1593 bytes --]

A more detailed description of my experiences is at: 
https://stackoverflow.com/questions/75387541/compiling-and-injecting-code-in-gdb-c-rather-than-c 
.  Briefly:

    I am running gdb 10.1.90.20210103-git and gcc/g++ 10.2.1 20210110 on
    x86-64 Debian 11.

    I can compile C code and have it run in the context of the paused
    inferior, but as soon as I introduce one or more lines of C++ code,
    no compilation or at least no run of the code occurs.  I get no
    error messages.

    https://www.sourceware.org/gdb/news/ mentions that GDB 8.3.1 was
    released on 2019-09-20, with: "Experimental support for compilation
    and injection of C++ source code into the inferior (requires GCC 7.1
    or higher, built with libcp1.so)."

    I have /usr/lib/x86_64-linux-gnu/libcc1.so.o but no libcp1.so
    there.  Little seems to have changed in libcp1.so in recent years:
    https://github.com/gcc-mirror/gcc/commits/master/libcc1/libcp1.cc .

Is it possible to inject C++ code, with any version of gdb and gcc/g++?

Is there any other documentation I should be looking at?  The main gdb 
documentation of code compilation and injection 
https://sourceware.org/gdb/onlinedocs/gdb/Compiling-and-Injecting-Code.html#set-debug-compile 
only gives C examples.

I want this capability so I can easily dump the contents of large, 
complex, vectors of class objects to a text file, likely multiple times 
the middle of a debug session.  Also I would like to be able to modify 
such data programmatically.

Thanks very much for gdb and gcc!


   Best regards

     Robin Whittle


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-02-11  9:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-08 16:34 Compiling and injecting code in GDB: C++ in addition to C? Robin Whittle
2023-02-10 17:01 ` Tom Tromey
2023-02-11  9:03   ` Robin Whittle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).