From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.firstpr.com.au (mx1.firstpr.com.au [149.28.173.46]) by sourceware.org (Postfix) with ESMTP id EF4983858D39 for ; Wed, 8 Feb 2023 16:34:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EF4983858D39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=firstpr.com.au Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=firstpr.com.au Received: from [127.0.0.1] (localhost [IPv6:::1]) by mx1.firstpr.com.au (Postfix) with ESMTP id 799BC1F5AF for ; Wed, 8 Feb 2023 16:34:45 +0000 (UTC) Content-Type: multipart/alternative; boundary="------------k3RHYaUe52ZjyfsdNDfEMiiO" Message-ID: <1575f29a-498f-5c65-41cc-3ee134108d48@firstpr.com.au> Date: Thu, 9 Feb 2023 03:34:43 +1100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 To: "gdb@sourceware.org" Content-Language: en-US From: Robin Whittle Subject: Compiling and injecting code in GDB: C++ in addition to C? X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,HTML_MESSAGE,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This is a multi-part message in MIME format. --------------k3RHYaUe52ZjyfsdNDfEMiiO Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 --------------k3RHYaUe52ZjyfsdNDfEMiiO--