From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 76275 invoked by alias); 9 Oct 2015 04:29:40 -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 76257 invoked by uid 89); 9 Oct 2015 04:29:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.8 required=5.0 tests=AWL,BAYES_50,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE autolearn=no version=3.3.2 X-HELO: p3plsmtpa11-05.prod.phx3.secureserver.net Received: from p3plsmtpa11-05.prod.phx3.secureserver.net (HELO p3plsmtpa11-05.prod.phx3.secureserver.net) (68.178.252.106) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 09 Oct 2015 04:29:37 +0000 Received: from [10.0.0.101] ([99.26.121.120]) by p3plsmtpa11-05.prod.phx3.secureserver.net with id SsVb1r0092bxR8r01sVb4u; Thu, 08 Oct 2015 21:29:36 -0700 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 9.0 \(3094\)) Subject: Re: Using C++ code inside gdb From: Duane Ellis In-Reply-To: Date: Fri, 09 Oct 2015 04:29:00 -0000 Cc: Klaus Rudolph , gdb@sourceware.org Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Ashutosh X-IsSubscribed: yes X-SW-Source: 2015-10/txt/msg00028.txt.bz2 > On Oct 8, 2015, at 8:20 PM, Ashutosh wrote: >=20 > Hi Klaus, >=20 > 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 already For example in the GDB remote case, GDB attempts to read (or write) the tar= get, 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=9Crand= om crazy address=E2=80=9D - this is normal, if the pointer is not initializ= ed. Assume you have a GUI front end (like Eclipse) you mouse over over the poin= ter, and it tries to pop up the content of the pointer This is by design=E2=80=A6=20 My question is: Why do you want to do this? What problem are you trying to = solve? =3D=3D=3D=3D=3D=3D=3D GDB 7.9.1 Generally has this sort of support now, very common in the embed= ded world. look in the GDB file: =E2=80=9Cgdb/remote.c=E2=80=9D Also source file called: gdb/memory-map.c=20 Specifically search for this snip of code, this asks a remote target for th= e =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_memory_map]); This existing feature is used in the embedded world to handle programing FL= ASH 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 t= hings 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 very w= ell. 3) you=E2=80=99ll also have to add various autoconf features for C++ compi= lation (if required) 4) And add various rules to the Makefile system. Start with something *REALLY* simple -=20 Create a simple C++ class, and have it statically initialize it self. In the constructor do a simple =E2=80=9Cprintf()=E2=80=9D or=20 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 construct= or in GDB Somewhere in the startup sequence in GDB - call a C function that in turn calls another constructor for another sim= ple 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 construc= tor 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 might 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 attemp= t 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 com= mon. -Duane.