Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* QUERY: Pretty-printing C++ classes in gdb
@ 2002-03-08 16:56 Bradford Chamberlain
  2002-03-08 18:58 ` Daniel Jacobowitz
  0 siblings, 1 reply; 2+ messages in thread
From: Bradford Chamberlain @ 2002-03-08 16:56 UTC (permalink / raw)
  To: gdb


(I hope the following is not a FAQ.  I didn't find one on the gdb page.)

I am curious whether gdb has hooks that would allow me to provide a means
of pretty-printing C++ classes without modifying the gdb source code.  
For example, imagine that I am supplying you with a C++ class library, and
want to save you the hassle of inspecting the guts of my classes and
understanding their inner workings when debugging your code that uses
them.  Rather, I'd like to cause "p instanceOfClassFoo" to give you a
clean view of the class that doesn't require understanding its
implementation.

One way to do this would be to hack the source, perhaps treating my
library as a new language.  However, I'd like to avoid changing the gdb
source both for simplicity and so that I don't have to ship users a new
copy of gdb.  So is there a less intrusive way that I can hook my pretty
printing in?  For example, I could imagine that a well-defined method name
or operator<< overload might be utilized by gdb if it exists.  Or that
perhaps I can give you a dot-file that will be used at load time to
configure the behavior.

Any information on whether such a feature exists, or other possible
workarounds would be appreciated.

Thanks very much,
-Brad Chamberlain


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

* Re: QUERY: Pretty-printing C++ classes in gdb
  2002-03-08 16:56 QUERY: Pretty-printing C++ classes in gdb Bradford Chamberlain
@ 2002-03-08 18:58 ` Daniel Jacobowitz
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Jacobowitz @ 2002-03-08 18:58 UTC (permalink / raw)
  To: Bradford Chamberlain; +Cc: gdb

On Fri, Mar 08, 2002 at 04:56:43PM -0800, Bradford Chamberlain wrote:
> 
> (I hope the following is not a FAQ.  I didn't find one on the gdb page.)
> 
> I am curious whether gdb has hooks that would allow me to provide a means
> of pretty-printing C++ classes without modifying the gdb source code.  
> For example, imagine that I am supplying you with a C++ class library, and
> want to save you the hassle of inspecting the guts of my classes and
> understanding their inner workings when debugging your code that uses
> them.  Rather, I'd like to cause "p instanceOfClassFoo" to give you a
> clean view of the class that doesn't require understanding its
> implementation.
> 
> One way to do this would be to hack the source, perhaps treating my
> library as a new language.  However, I'd like to avoid changing the gdb
> source both for simplicity and so that I don't have to ship users a new
> copy of gdb.  So is there a less intrusive way that I can hook my pretty
> printing in?  For example, I could imagine that a well-defined method name
> or operator<< overload might be utilized by gdb if it exists.  Or that
> perhaps I can give you a dot-file that will be used at load time to
> configure the behavior.
> 
> Any information on whether such a feature exists, or other possible
> workarounds would be appreciated.

The standard way to do this is:

  - Provide a .gdbinit.  Placed in the current working directory or in
$HOME, it lets you specify commands to be executed.

  - Provide utility functions or methods to print each class however
you wish.

  - Provide aliases in the former to call the latter.

GDB will probably never do this by default for some method name or
operator overload; it is not appropriate (what if the functions affect
state?).  Be sure to write the print functions carefully.


-- 
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer


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

end of thread, other threads:[~2002-03-09  2:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-08 16:56 QUERY: Pretty-printing C++ classes in gdb Bradford Chamberlain
2002-03-08 18:58 ` Daniel Jacobowitz

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