public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* gdb user defined function
@ 2012-01-15  2:51 Sinbad
  2012-01-16 20:46 ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: Sinbad @ 2012-01-15  2:51 UTC (permalink / raw)
  To: gdb

i am trying to write a user-defined function in gdb.
while analyzing the core is it possible to see if a
pointer variable is accessible or not inside a gdb
user-defined function. for example.
(gdb) p *ptr
cannot access memory at address 0x35336
is there any way to find this inside a gdb function.
i need something as follows
define sub
   is_accessible(ptr)
end

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

* Re: gdb user defined function
  2012-01-15  2:51 gdb user defined function Sinbad
@ 2012-01-16 20:46 ` Tom Tromey
  2012-01-17  6:10   ` Sinbad
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2012-01-16 20:46 UTC (permalink / raw)
  To: Sinbad; +Cc: gdb

>>>>> "Sinbad" == Sinbad  <sinbad.sinbad@gmail.com> writes:

Sinbad> i am trying to write a user-defined function in gdb.
Sinbad> while analyzing the core is it possible to see if a
Sinbad> pointer variable is accessible or not inside a gdb
Sinbad> user-defined function. for example.
Sinbad> (gdb) p *ptr
Sinbad> cannot access memory at address 0x35336
Sinbad> is there any way to find this inside a gdb function.
Sinbad> i need something as follows
Sinbad> define sub
Sinbad>    is_accessible(ptr)
Sinbad> end

I can't think of an easy way to do this from the gdb CLI, but you can do
it from Python by catching the exception.

You could straightforwardly write a $is_valid function that examines a
pointer for validity.

Tom

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

* Re: gdb user defined function
  2012-01-16 20:46 ` Tom Tromey
@ 2012-01-17  6:10   ` Sinbad
  2012-01-17 16:29     ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: Sinbad @ 2012-01-17  6:10 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb

hi tom,

i've never used python with gdb or python at all. but i want to learn
enough of python to achieve the following. how do one use python
with gdb, will gdb become slow, can you give me some pointers
on how to achieve the following using python.

Please don't yell ;)

thanks


On Tue, Jan 17, 2012 at 2:16 AM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Sinbad" == Sinbad  <sinbad.sinbad@gmail.com> writes:
>
> Sinbad> i am trying to write a user-defined function in gdb.
> Sinbad> while analyzing the core is it possible to see if a
> Sinbad> pointer variable is accessible or not inside a gdb
> Sinbad> user-defined function. for example.
> Sinbad> (gdb) p *ptr
> Sinbad> cannot access memory at address 0x35336
> Sinbad> is there any way to find this inside a gdb function.
> Sinbad> i need something as follows
> Sinbad> define sub
> Sinbad>    is_accessible(ptr)
> Sinbad> end
>
> I can't think of an easy way to do this from the gdb CLI, but you can do
> it from Python by catching the exception.
>
> You could straightforwardly write a $is_valid function that examines a
> pointer for validity.
>
> Tom

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

* Re: gdb user defined function
  2012-01-17  6:10   ` Sinbad
@ 2012-01-17 16:29     ` Tom Tromey
  2012-01-17 16:31       ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2012-01-17 16:29 UTC (permalink / raw)
  To: Sinbad; +Cc: gdb

>>>>> "Sinbad" == Sinbad  <sinbad.sinbad@gmail.com> writes:

Sinbad> i've never used python with gdb or python at all. but i want to learn
Sinbad> enough of python to achieve the following. how do one use python
Sinbad> with gdb, will gdb become slow, can you give me some pointers
Sinbad> on how to achieve the following using python.

There are plenty of docs:

    http://sourceware.org/gdb/onlinedocs/gdb/Python.html

What you want is the stuff about writing a function:

    http://sourceware.org/gdb/onlinedocs/gdb/Functions-In-Python.html#Functions-In-Python

and also the Value API.

The core of your function will probably be something along these lines:

    try:
      arg = arg.deref()
      return 1
    except:
      return 0

Untested of course.

About speed... well, evaluating Python does have a cost.  I wouldn't
worry about it in advance; especially if the alternative is using the
gdb CLI, which in general is less well-tuned than Python.  If your
situation is truly performance critical, then (1) measure the effects of
Python, and (2) if it is too slow, write a convenience function in C
instead.

Sinbad> Please don't yell ;)

Don't worry.

Tom

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

* Re: gdb user defined function
  2012-01-17 16:29     ` Tom Tromey
@ 2012-01-17 16:31       ` Tom Tromey
  0 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2012-01-17 16:31 UTC (permalink / raw)
  To: Sinbad; +Cc: gdb

Tom>       arg = arg.deref()

Oops.  The method is really named 'dereference'.

Tom

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

end of thread, other threads:[~2012-01-17 16:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-15  2:51 gdb user defined function Sinbad
2012-01-16 20:46 ` Tom Tromey
2012-01-17  6:10   ` Sinbad
2012-01-17 16:29     ` Tom Tromey
2012-01-17 16:31       ` 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).