From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17675 invoked by alias); 30 Aug 2006 12:46:48 -0000 Received: (qmail 17626 invoked by uid 22791); 30 Aug 2006 12:46:47 -0000 X-Spam-Check-By: sourceware.org Received: from nevyn.them.org (HELO nevyn.them.org) (66.93.172.17) by sourceware.org (qpsmtpd/0.31.1) with ESMTP; Wed, 30 Aug 2006 12:46:43 +0000 Received: from drow by nevyn.them.org with local (Exim 4.54) id 1GIPSq-0005C5-Mn; Wed, 30 Aug 2006 08:46:40 -0400 Date: Wed, 30 Aug 2006 12:46:00 -0000 From: Daniel Jacobowitz To: Michael Veksler Cc: gdb@sourceware.org Subject: Re: How to call operator<< functions? Message-ID: <20060830124640.GC19163@nevyn.them.org> Mail-Followup-To: Michael Veksler , gdb@sourceware.org References: <44F5645F.4000301@tx.technion.ac.il> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <44F5645F.4000301@tx.technion.ac.il> User-Agent: Mutt/1.5.11+cvs20060403 X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2006-08/txt/msg00242.txt.bz2 As a general note: the most useful thing to accompany any bug report is a test case! :-) We can't fix them without tests. On Wed, Aug 30, 2006 at 01:11:43PM +0300, Michael Veksler wrote: > Passing 'std::cout' seems impossible. Any attempt to pass std::cout > crashes. To overcome this I define my own global > ostream gecLog(cout.rdbuf()); > (or something similar) and recompile the code. This lets me pass gecLog > instead of cout, and it _sometimes_ works: Fred's response seems reasonable; that might be the problem, or it might be something else. If you have a testcase, please post it. > (gdb) p pd.Print(gecLog) > Cannot resolve method (null)Print to any overloaded instance Ditto. I've never seen this error before. > -------------------------------------- > I wanted to do the same for operator<<: > (gdb) p 'operator<<(std::ostream&, MyClass const&)' > $17 = {ostream &(ostream &, const class MyClass > &)} 0x8068a00 > (gdb) p $17(gecLog, *pd) > Program received signal SIGSEGV, Segmentation fault. > ----------------------- You can just use "print gecLog << *pd". Does that work better? Anyway, I would have expected calling the operator to work. With tests for these bugs we can make the next GDB release the best ever for C++. > Print(cerr). Sometimes, while debugging a piece of code, that a vital > object has <<, but no DebugPrint, and *that* really frustrates me - > especially when I loose a 60 minutes debugging session to a SIGSEGV. You might want to use set unwindonsignal, then, as it suggests. There's some risk associated, but it usually works. You can also use "return" to get out of the called function, but make sure you tell GDB not to pass the sigsegv when you continue. -- Daniel Jacobowitz CodeSourcery