Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* overloading 'print' command.
@ 2009-05-14 11:46 Paweł Sikora
  2009-05-14 23:17 ` Paul Pluzhnikov
  0 siblings, 1 reply; 6+ messages in thread
From: Paweł Sikora @ 2009-05-14 11:46 UTC (permalink / raw)
  To: gdb

Hi,
I'd like to ask about overloading gdb's 'print' command.
e.g. I've defined a macro 'ps' for printing std::string:

define ps
p $arg0.c_str()
end

Now, I'd like to avoid calling 'ps' and just use the 'p' command
in top-macros for printing more complex data structures.
Is it possible in gdb to register some hooks for type-based
printing?

Thanks for all hints.


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

* Re: overloading 'print' command.
  2009-05-14 11:46 overloading 'print' command Paweł Sikora
@ 2009-05-14 23:17 ` Paul Pluzhnikov
  2009-05-15  7:06   ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Pluzhnikov @ 2009-05-14 23:17 UTC (permalink / raw)
  To: Paweł Sikora; +Cc: gdb

2009/5/14 Paweł Sikora <pluto@agmk.net>:

> I'd like to ask about overloading gdb's 'print' command.
> e.g. I've defined a macro 'ps' for printing std::string:
>
> define ps
> p $arg0.c_str()
> end
>
> Now, I'd like to avoid calling 'ps' and just use the 'p' command
> in top-macros for printing more complex data structures.
> Is it possible in gdb to register some hooks for type-based
> printing?

Support for doing *exactly* this is coming to mainline GDB, but you can
get it now from the archer-tromey-python branch:
  http://sourceware.org/gdb/wiki/PythonGdb

It is significantly more powerful than what you can do with simple 'define'.

Cheers,
-- 
Paul Pluzhnikov


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

* Re: overloading 'print' command.
  2009-05-14 23:17 ` Paul Pluzhnikov
@ 2009-05-15  7:06   ` Eli Zaretskii
  2009-05-15 14:07     ` Paul Pluzhnikov
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2009-05-15  7:06 UTC (permalink / raw)
  To: Paul Pluzhnikov; +Cc: pluto, gdb

> Date: Thu, 14 May 2009 16:17:07 -0700
> From: Paul Pluzhnikov <ppluzhnikov@google.com>
> Cc: gdb@sourceware.org
> 
> 2009/5/14 PaweÂł Sikora <pluto@agmk.net>:
> 
> > I'd like to ask about overloading gdb's 'print' command.
> > e.g. I've defined a macro 'ps' for printing std::string:
> >
> > define ps
> > p $arg0.c_str()
> > end
> >
> > Now, I'd like to avoid calling 'ps' and just use the 'p' command
> > in top-macros for printing more complex data structures.
> > Is it possible in gdb to register some hooks for type-based
> > printing?
> 
> Support for doing *exactly* this is coming to mainline GDB, but you can
> get it now from the archer-tromey-python branch:
>   http://sourceware.org/gdb/wiki/PythonGdb

But I think what the OP wants does not justify waiting a few months
until GDB 7 is released.

To the OP: yes, you should be able to use the user-defined hooks
machinery to do what you want.  If you define a command called
`hook-print', it will be run before `print', and if you define a
command called `hookpost-print', it will be run after `print'.  See
the node "Hooks" in the GDB manual for more information on hooks.


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

* Re: overloading 'print' command.
  2009-05-15  7:06   ` Eli Zaretskii
@ 2009-05-15 14:07     ` Paul Pluzhnikov
  2009-05-15 14:42       ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Pluzhnikov @ 2009-05-15 14:07 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: pluto, gdb

2009/5/15 Eli Zaretskii <eliz@gnu.org>:
>> Date: Thu, 14 May 2009 16:17:07 -0700
>> From: Paul Pluzhnikov <ppluzhnikov@google.com>
>> 2009/5/14 Paweł Sikora <pluto@agmk.net>:
...
>> > Is it possible in gdb to register some hooks for
>> > type-based printing?
^^^^^^^^^^^^^^^^^^^^^^^^^
>> Support for doing *exactly* this is coming to mainline GDB, but you can
>> get it now from the archer-tromey-python branch:
>>   http://sourceware.org/gdb/wiki/PythonGdb
>
> But I think what the OP wants does not justify waiting a few months
> until GDB 7 is released.

He can get it now from the archer branch.

> To the OP: yes, you should be able to use the user-defined hooks
> machinery to do what you want.

I don't see how hook-print can help OP to do something special for
std::string. The manual says hook-print doesn't get any arguments, so
it can't even tell what is being printed. What am I missing?

Cheers,
-- 
Paul Pluzhnikov


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

* Re: overloading 'print' command.
  2009-05-15 14:07     ` Paul Pluzhnikov
@ 2009-05-15 14:42       ` Eli Zaretskii
  2009-05-15 15:53         ` Joel Brobecker
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2009-05-15 14:42 UTC (permalink / raw)
  To: Paul Pluzhnikov; +Cc: pluto, gdb

> Date: Fri, 15 May 2009 07:07:16 -0700
> From: Paul Pluzhnikov <ppluzhnikov@google.com>
> Cc: pluto@agmk.net, gdb@sourceware.org
> 
> I don't see how hook-print can help OP to do something special for
> std::string. The manual says hook-print doesn't get any arguments, so
> it can't even tell what is being printed. What am I missing?

Looks like I was missing something: the fact that hooks don't have
access to the arguments of the hooked command.  Sounds like a bad
limitation to me.


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

* Re: overloading 'print' command.
  2009-05-15 14:42       ` Eli Zaretskii
@ 2009-05-15 15:53         ` Joel Brobecker
  0 siblings, 0 replies; 6+ messages in thread
From: Joel Brobecker @ 2009-05-15 15:53 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Paul Pluzhnikov, pluto, gdb

> > I don't see how hook-print can help OP to do something special for
> > std::string. The manual says hook-print doesn't get any arguments, so
> > it can't even tell what is being printed. What am I missing?
> 
> Looks like I was missing something: the fact that hooks don't have
> access to the arguments of the hooked command.  Sounds like a bad
> limitation to me.

I think that the hooks mechanism is quickly going to be overtaken
by python support, so I personally wouldn't spend any more time
on improving the hooks - especially when the feature is already
available in today's FSF sources.

-- 
Joel


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

end of thread, other threads:[~2009-05-15 15:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-14 11:46 overloading 'print' command Paweł Sikora
2009-05-14 23:17 ` Paul Pluzhnikov
2009-05-15  7:06   ` Eli Zaretskii
2009-05-15 14:07     ` Paul Pluzhnikov
2009-05-15 14:42       ` Eli Zaretskii
2009-05-15 15:53         ` Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox