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: Python API questions and use cases


On Wed, Sep 15, 2010 at 7:56 PM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Joel" == Joel Borggrén-Franck <joel.borggren.franck@gmail.com> writes:
>
> Joel> The only working solution I have at the moment is to escape to
> Joel> gdb-script with:
> Joel> gdb.parse_and_eval("myGlobalFoo")
> Joel> is this intended?
>
> This is simplest.
>

Ok. I've approached the Python API as a (eventually) complete replacement
for GDB-script, so whenever I have to use parse_and_eval I feel it's an
(ugly) hack. This is perhaps not the intention?

> Could you file a bug report for this?
>

Done :)

>
> I think the tricky part is getting a Value holding the appropriate
> constant. ?For that you might not have anything better, at present, than
> parse_and_eval.

True. Then I think this would be useful:

gdb.new_address(addr) - returns a new gdb.Value (of type (void *)) pointing
to addr. addr is checked to be within bounds of the address space of the
inferior upon creation.

> Joel> Another usecase for casts would be if I wanted to mask an address
> Joel> in python, given:
> Joel> foo *fooP;
> Joel> how do I do the equivalent of this in pyhton:
> Joel> set $check = ((size_t)foo) & 1
>
> Simplest is to do it using Python math:
>
> ?foo = ...
> ?check = long (foo) & 1
>
> Otherwise you can look up size_t:
>
> ?check = foo.cast (gdb.lookup_type ('size_t')) & 1
>
> If you really want to set a convenience variable, then for the time
> being you will have to use parse_and_eval. ?We don't expose those any
> other way.
>

Oh, thanks. I had overlooked gdb.Value.address. Using that and your
example I have all the tools I need in this last case (no need to set
a convenience var, that was only for the example).

Thanks a lot!

Cheers
Joel


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