Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: "Joel Borggrén-Franck" <joel.borggren.franck@gmail.com>
To: gdb@sourceware.org
Subject: Python API questions and use cases
Date: Wed, 15 Sep 2010 13:43:00 -0000	[thread overview]
Message-ID: <AANLkTim24XZssayO6-wvf9WoywRauqXRbUdQi5LjyO9F@mail.gmail.com> (raw)

Hi

I'm testing out the new Python API for GDB, and have a couple of use cases
that I don't know how to solve entirely from python. I hope this is the
right mailing list.

In all these cases I'm working on debugging a core.

1) Getting the value of a global

given:

typedef struct foo {
  int bar;
  int baz;
} foo;

foo myGlobalFoo;

in some C file, how do I access the value of myGlobalFoo from python?

The only working solution I have at the moment is to escape to gdb-script
with:

gdb.parse_and_eval("myGlobalFoo")

is this intended?

I know I can iterate over symbols in the symbol table, but I haven't found
a way to go from symbol to value.

2) Casts

given that I know that at address 0xdeadbeef there will be a struct of type
foo how do I get that struct (or a pointer to that struct) as a gdb.Value
object?

Currently i have written a cast function:

def cast(type_string, address):
    """Returns a gdb.Value object with type 'type_string' from memory
    starting at 'address'."""
    return gdb.parse_and_eval("(%s)((void *)%s)" % (type_string, address))

that I think works, but is there some other way?

Another usecase for casts would be if I wanted to mask an address in python,
given:

foo *fooP;

how do I do the equivalent of this in pyhton:

set $check = ((size_t)foo) & 1

I know there is the a cast in the API but that requires that I have a
gdb.Type which I don't know how to get.

I'd be happy to help out adding solutions to these use-cases!

Cheers
Joel


             reply	other threads:[~2010-09-15 13:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-15 13:43 Joel Borggrén-Franck [this message]
2010-09-15 18:01 ` Tom Tromey
2010-09-15 19:04   ` Phil Muldoon
2010-09-16  6:13     ` Joel Borggrén-Franck
2010-09-16  7:33   ` Joel Borggrén-Franck
2010-09-16  9:30     ` Joachim Protze
2010-09-16  9:57       ` André Pönitz
2010-09-16  9:49     ` André Pönitz
2010-09-16 11:56       ` Joel Borggrén-Franck
2010-09-16 19:11         ` Tom Tromey
2010-09-17  7:35           ` Joel Borggrén-Franck
2010-09-21 18:02             ` Tom Tromey
2010-09-16 19:09     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTim24XZssayO6-wvf9WoywRauqXRbUdQi5LjyO9F@mail.gmail.com \
    --to=joel.borggren.franck@gmail.com \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox