public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* passing gdb.Value pointers to ctypes function calls
@ 2011-04-12  9:44 Christoph Mathys
  2011-04-12 21:17 ` Phil Muldoon
  2011-04-13 14:26 ` Tom Tromey
  0 siblings, 2 replies; 5+ messages in thread
From: Christoph Mathys @ 2011-04-12  9:44 UTC (permalink / raw)
  To: gdb

Hello!

I'm trying to write a pretty printer for gdb 7.2 using python, to be
concrete I would like to print an Xml node (libxml2) as text. I've
managed to get the pointers to node and document. Now I'm trying to
call libxml using ctypes module, passing the pointer values as
c_void_p. But gdb keeps crashing on me. Is this supposed to work at
all? I allocate some buffer, pass it to libxml functions along with
some addresses I obtain from the debugged process using gdb, and as a
result I expect the string representation of the node in the buffer.

For converting between gdb.Value and ctypes usable stuff I use something like:
ptr = int(str(gdbValNode), 16)
c_void_p(ptr)

I'm attached to the running process. But as far as I understand, this
should work on the running process as well as the core file.

Thanks for insight!
Christoph

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: passing gdb.Value pointers to ctypes function calls
  2011-04-12  9:44 passing gdb.Value pointers to ctypes function calls Christoph Mathys
@ 2011-04-12 21:17 ` Phil Muldoon
  2011-04-13  7:22   ` Christoph Mathys
  2011-04-13 14:27   ` Tom Tromey
  2011-04-13 14:26 ` Tom Tromey
  1 sibling, 2 replies; 5+ messages in thread
From: Phil Muldoon @ 2011-04-12 21:17 UTC (permalink / raw)
  To: Christoph Mathys; +Cc: gdb

Christoph Mathys <eraserix@gmail.com> writes:

> Hello!
>
> I'm trying to write a pretty printer for gdb 7.2 using python, to be
> concrete I would like to print an Xml node (libxml2) as text. I've
> managed to get the pointers to node and document. Now I'm trying to
> call libxml using ctypes module, passing the pointer values as
> c_void_p. But gdb keeps crashing on me.

If GDB ever crashes it is a bug.  Can you file a bug for this?  


>  Is this supposed to work at
> all? I allocate some buffer, pass it to libxml functions along with
> some addresses I obtain from the debugged process using gdb, and as a
> result I expect the string representation of the node in the buffer.
>
> For converting between gdb.Value and ctypes usable stuff I use something like:
> ptr = int(str(gdbValNode), 16)
> c_void_p(ptr)
>
> I'm attached to the running process. But as far as I understand, this
> should work on the running process as well as the core file.

It should, but without more concrete information it is difficult to
diagnose the issue.  I am concerned about the GDB crash though, that
should be fixed.

Cheers,

Phil

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: passing gdb.Value pointers to ctypes function calls
  2011-04-12 21:17 ` Phil Muldoon
@ 2011-04-13  7:22   ` Christoph Mathys
  2011-04-13 14:27   ` Tom Tromey
  1 sibling, 0 replies; 5+ messages in thread
From: Christoph Mathys @ 2011-04-13  7:22 UTC (permalink / raw)
  To: gdb

On Tue, Apr 12, 2011 at 11:17 PM, Phil Muldoon <pmuldoon@redhat.com> wrote:
> Christoph Mathys <eraserix@gmail.com> writes:
>
>> call libxml using ctypes module, passing the pointer values as
>> c_void_p. But gdb keeps crashing on me.
>
> If GDB ever crashes it is a bug.  Can you file a bug for this?

I don't mind filing a bug report, but I'm not sure what else gdb
should do considering what I'm doing: Accessing possibly invalid
memory inside gdb itself. The code below is what I think happens in my
script. The difference is that I have a more complicated way of
getting the wrong pointer and call a different C function.

This is in crash.py:
from ctypes import *

ptr = c_void_p(1)
libc = CDLL('libc.so.6')
libc.printf('%s\n', ptr)

Fire up gdb and do: python execfile('crash.py'). For me, this crashes
gdb, but this is somewhat expected.

> It should, but without more concrete information it is difficult to
> diagnose the issue.  I am concerned about the GDB crash though, that
> should be fixed.

It was suggested that what I'm trying to do can't work. gdb lives in
another address space than my inferior, so pointers from my inferior
don't make sense to a library loaded into gdbs address space.

Christoph

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: passing gdb.Value pointers to ctypes function calls
  2011-04-12  9:44 passing gdb.Value pointers to ctypes function calls Christoph Mathys
  2011-04-12 21:17 ` Phil Muldoon
@ 2011-04-13 14:26 ` Tom Tromey
  1 sibling, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2011-04-13 14:26 UTC (permalink / raw)
  To: Christoph Mathys; +Cc: gdb

>>>>> "Christoph" == Christoph Mathys <eraserix@gmail.com> writes:

Christoph> I'm trying to write a pretty printer for gdb 7.2 using python, to be
Christoph> concrete I would like to print an Xml node (libxml2) as text. I've
Christoph> managed to get the pointers to node and document. Now I'm trying to
Christoph> call libxml using ctypes module, passing the pointer values as
Christoph> c_void_p. But gdb keeps crashing on me. Is this supposed to work at
Christoph> all?

Nope, this won't work.

A gdb.Value represents a value in the inferior.  If you look at its
address, you are getting an address in some other process, not in gdb.

Tom

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: passing gdb.Value pointers to ctypes function calls
  2011-04-12 21:17 ` Phil Muldoon
  2011-04-13  7:22   ` Christoph Mathys
@ 2011-04-13 14:27   ` Tom Tromey
  1 sibling, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2011-04-13 14:27 UTC (permalink / raw)
  To: pmuldoon; +Cc: Christoph Mathys, gdb

>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:

>> I'm trying to write a pretty printer for gdb 7.2 using python, to be
>> concrete I would like to print an Xml node (libxml2) as text. I've
>> managed to get the pointers to node and document. Now I'm trying to
>> call libxml using ctypes module, passing the pointer values as
>> c_void_p. But gdb keeps crashing on me.

Phil> If GDB ever crashes it is a bug.  Can you file a bug for this?  

Usually this is true, but ctypes is special.  It lets you make pretty
much unrestricted C calls from Python.  We can't guard against all of
those.

Tom

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-04-13 14:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-12  9:44 passing gdb.Value pointers to ctypes function calls Christoph Mathys
2011-04-12 21:17 ` Phil Muldoon
2011-04-13  7:22   ` Christoph Mathys
2011-04-13 14:27   ` Tom Tromey
2011-04-13 14:26 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).