From: Robin Whittle <rw@firstpr.com.au>
To: "gdb@sourceware.org" <gdb@sourceware.org>
Subject: Compiling and injecting code in GDB: C++ in addition to C?
Date: Thu, 9 Feb 2023 03:34:43 +1100 [thread overview]
Message-ID: <1575f29a-498f-5c65-41cc-3ee134108d48@firstpr.com.au> (raw)
[-- 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
next reply other threads:[~2023-02-08 16:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-08 16:34 Robin Whittle [this message]
2023-02-10 17:01 ` Tom Tromey
2023-02-11 9:03 ` Robin Whittle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1575f29a-498f-5c65-41cc-3ee134108d48@firstpr.com.au \
--to=rw@firstpr.com.au \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).