From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8832 invoked by alias); 15 May 2009 07:06:58 -0000 Received: (qmail 8823 invoked by uid 22791); 15 May 2009 07:06:54 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,SPF_SOFTFAIL X-Spam-Check-By: sourceware.org Received: from mtaout4.012.net.il (HELO mtaout3.012.net.il) (84.95.2.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 15 May 2009 07:06:49 +0000 Received: from conversion-daemon.i_mtaout3.012.net.il by i_mtaout3.012.net.il (HyperSendmail v2004.12) id <0KJO00J00BI86900@i_mtaout3.012.net.il> for gdb@sourceware.org; Fri, 15 May 2009 10:06:46 +0300 (IDT) Received: from HOME-C4E4A596F7 ([84.228.73.80]) by i_mtaout3.012.net.il (HyperSendmail v2004.12) with ESMTPA id <0KJO00G4RBR9VWG0@i_mtaout3.012.net.il>; Fri, 15 May 2009 10:06:46 +0300 (IDT) Date: Fri, 15 May 2009 07:06:00 -0000 From: Eli Zaretskii Subject: Re: overloading 'print' command. In-reply-to: <8ac60eac0905141617g1db278e5l906eef8f5b899ed4@mail.gmail.com> To: Paul Pluzhnikov Cc: pluto@agmk.net, gdb@sourceware.org Reply-to: Eli Zaretskii Message-id: <83preargj6.fsf@gnu.org> MIME-version: 1.0 Content-type: text/plain; charset=iso-8859-2 Content-transfer-encoding: 8BIT References: <8ac60eac0905141617g1db278e5l906eef8f5b899ed4@mail.gmail.com> X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2009-05/txt/msg00081.txt.bz2 > Date: Thu, 14 May 2009 16:17:07 -0700 > From: Paul Pluzhnikov > Cc: gdb@sourceware.org > > 2009/5/14 Pawe³ Sikora : > > > 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.