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: overloading 'print' command.


> 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.


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