This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Modify address of a gdb.Value


On Wed, Jun 17, 2009 at 07:51, Niko Sams<niko.sams@gmail.com> wrote:
>> ?newval = (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. ?You 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 <class Key, class T>
> struct QMapPayloadNode
> {
> ? ?Key key;
> ? ?T value;
> ? ?QMapData::Node *backward;
> };
> static inline int payload() {
> ? ?return 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<int, QString *>
> 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 = self.ktype.sizeof
            ret += self.vtype.sizeof
            ret += 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 += ret % gdb.lookup_type('void').pointer().sizeof

            ret -= gdb.lookup_type('void').pointer().sizeof
            return ret

Any better idea?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]