From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6598 invoked by alias); 17 Jun 2009 15:52:13 -0000 Received: (qmail 6585 invoked by uid 22791); 17 Jun 2009 15:52:12 -0000 X-SWARE-Spam-Status: No, hits=1.1 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_54,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from qw-out-1920.google.com (HELO qw-out-1920.google.com) (74.125.92.144) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 17 Jun 2009 15:52:06 +0000 Received: by qw-out-1920.google.com with SMTP id 9so231789qwj.24 for ; Wed, 17 Jun 2009 08:52:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.72.78 with SMTP id l14mr384952vcj.81.1245253924131; Wed, 17 Jun 2009 08:52:04 -0700 (PDT) In-Reply-To: <629542d40906162251v4a4723f3l9423eec5998d0ee6@mail.gmail.com> References: <629542d40906142322h733ad7ffr3d6daeb7b306ff7a@mail.gmail.com> <629542d40906162251v4a4723f3l9423eec5998d0ee6@mail.gmail.com> Date: Wed, 17 Jun 2009 15:52:00 -0000 Message-ID: <629542d40906170852x60559910ud1f9b90a5069191b@mail.gmail.com> Subject: Re: Modify address of a gdb.Value From: Niko Sams To: gdb Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes 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 X-SW-Source: 2009-06/txt/msg00179.txt.bz2 On Wed, Jun 17, 2009 at 07:51, Niko Sams wrote: >> =A0newval =3D (val.cast(Type('char').pointer()) - payload).cast(val.type) > that is working, thanks. > > >> Nobody has implemented inferior function calls using Value yet. >> So the payload() part is not implementable. >> >> If you know what it returns, or you can compute it in Python, then >> this is no big deal. =A0You can use Value.cast to cast to some other >> type, then do pointer math. > > I tried to implement this payload method in python, the c++ code is > the following: > template > struct QMapPayloadNode > { > =A0 =A0Key key; > =A0 =A0T value; > =A0 =A0QMapData::Node *backward; > }; > static inline int payload() { > =A0 =A0return sizeof(PayloadNode) - sizeof(QMapData::Node *); > } > > the obvious solution would be gdb.lookup_type('QMapPayloadNode<%s, > %s>' % (self.ktype, self.vtype)).sizeof > but that doesn't work, i get this error: > RuntimeError: No type named QMapPayloadNode > This is because that QMapPayloadNode is not instanciated, it's only > used for this sizeof. > > So any idea how i can compute the payload? Ok, here comes my hacky workaround. Tested on amd64 only. def payload (self): #we can't use QMapPayloadNode as it's never instanciated and so= gcc #doesn't include it in debug information. #as a workaround take the sum of sizeof(members) ret =3D self.ktype.sizeof ret +=3D self.vtype.sizeof ret +=3D gdb.lookup_type('void').pointer().sizeof #but because of data alignment the value can be higher #so guess it's aliged by sizeof(void*) #TODO: find a real solution for this problem ret +=3D ret % gdb.lookup_type('void').pointer().sizeof ret -=3D gdb.lookup_type('void').pointer().sizeof return ret Any better idea?