From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 52363 invoked by alias); 9 Oct 2015 06:08:07 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 52347 invoked by uid 89); 9 Oct 2015 06:08:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.6 required=5.0 tests=AWL,BAYES_50,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wi0-f178.google.com Received: from mail-wi0-f178.google.com (HELO mail-wi0-f178.google.com) (209.85.212.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 09 Oct 2015 06:08:04 +0000 Received: by wicge5 with SMTP id ge5so53497837wic.0 for ; Thu, 08 Oct 2015 23:08:01 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.180.106.229 with SMTP id gx5mr8618555wib.24.1444370881336; Thu, 08 Oct 2015 23:08:01 -0700 (PDT) Received: by 10.27.142.215 with HTTP; Thu, 8 Oct 2015 23:08:01 -0700 (PDT) In-Reply-To: References: Date: Fri, 09 Oct 2015 06:08:00 -0000 Message-ID: Subject: Re: Using C++ code inside gdb From: Ashutosh To: Duane Ellis Cc: Klaus Rudolph , gdb@sourceware.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2015-10/txt/msg00029.txt.bz2 Hi Duane, I am actually interfacing gdb with a specific target (agent-less) and not going the RSP way. But still, thanks for the pointer; I will see if I can make use of it. Regarding using C++, I just hit upon the following conversation on the gdb-patches list: https://sourceware.org/ml/gdb-patches/2015-02/msg00202.html where it seems that there's some work going on compiling gdb sources with g++. Any idea if this support is available in some form already in gdb 7.10 or when is it planned to be released? Thanks and Regards, ash On Fri, Oct 9, 2015 at 9:59 AM, Duane Ellis wrote: > >> On Oct 8, 2015, at 8:20 PM, Ashutosh wrote: >> >> Hi Klaus, >> >> Thanks for your reply. Actually, I want to extend gdb to support >> targets with multiple memories and for that I wanted to add this >> module inside gdb code. This module would be called from with-in the >> gdb code, for example, when a user prints a variable on the >> command-line, gdb before issuing a request to the target to read the >> corresponding memory address, would first call my module to get some >> memory-specific info. And, I want the module to be contained inside a >> namespace like C++ class. So, basically, I want to add C++ code inside >> the gdb code and was looking for any guidelines/caveats regarding the >> same. > > > Why do you think this is important? What problem does this solve? > > I ask this, because generally - GDB already supports this some what alrea= dy > > For example in the GDB remote case, GDB attempts to read (or write) the t= arget, and the target replies with an ERROR > > GDB happens to handle this very well. > > In the LINUX case, you could have a pointer that points at a =E2=80=9Cra= ndom crazy address=E2=80=9D - this is normal, if the pointer is not initial= ized. > Assume you have a GUI front end (like Eclipse) you mouse over over the po= inter, and it tries to pop up the content of the pointer > > This is by design=E2=80=A6 > > My question is: Why do you want to do this? What problem are you trying t= o solve? > > =3D=3D=3D=3D=3D=3D=3D > > GDB 7.9.1 Generally has this sort of support now, very common in the emb= edded world. > > look in the GDB file: =E2=80=9Cgdb/remote.c=E2=80=9D > Also source file called: gdb/memory-map.c > > Specifically search for this snip of code, this asks a remote target for = the =E2=80=9Ctarget xml memory map" > > case TARGET_OBJECT_MEMORY_MAP: > gdb_assert (annex =3D=3D NULL); > return remote_read_qxfer (ops, "memory-map", annex, readbuf, offset= , len, > xfered_len, > &remote_protocol_packets[PACKET_qXfer_mem= ory_map]); > > This existing feature is used in the embedded world to handle programing = FLASH memory in a micro controller and has existed for quite some time. > > =3D=3D=3D=3D=3D=3D=3D=3D=3D > > I did this quite a few years ago for an internal version of GDB =E2=80=A6= things may have changed > but the general process is this: > > 1) You=E2=80=99ll also need to wrap various GDB header files with extern= =E2=80=9CC=E2=80=9D=E2=80=9D statements > > 2) I=E2=80=99m not sure if GDB is linked with =E2=80=9Cg++=E2=80=9D or = =E2=80=9Cgcc=E2=80=9D - if it is using gcc you must change the build system= to use g++ instead. If you do not, your C++ constructors will not work ver= y well. > > 3) you=E2=80=99ll also have to add various autoconf features for C++ com= pilation (if required) > > 4) And add various rules to the Makefile system. > > Start with something *REALLY* simple - > > Create a simple C++ class, and have it statically initialize it s= elf. > In the constructor do a simple =E2=80=9Cprintf()=E2=80=9D or > Create a file like: =E2=80=9Ctesting-duane.txt" and write= data to it, the close the file > In effect, this is a =E2=80=9CHello world=E2=80=9D from a static = constructor in GDB > > Somewhere in the startup sequence in GDB - > call a C function that in turn calls another constructor= for another simple object. > Print some messages, or create a simple text file > > In effect, this is a =E2=80=9CHello world=E2=80=9D from a dynamic= constructor in GDB > > WHY do I say create a simple text file > Some things modify the STDOUT so that it can be captured > Depending on where you put your code, =E2=80=9Cstdout=E2=80=9D mi= ght be in an odd ball state. > Thus - if you create a file it will not be in an odd ball state. > This just simplifies things - thats all. > > Make these two =E2=80=9Creally simple=E2=80=9D cases work before you atte= mpt to write any other C++ code. > > =3D=3D=3D=3D=3D=3D=3D=3D > > Have fun. > > it might be easer to write your C++ code in C =E2=80=A6 this is pretty c= ommon. > > -Duane. > > > >