From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31766 invoked by alias); 24 Oct 2007 11:53:21 -0000 Received: (qmail 31742 invoked by uid 22791); 24 Oct 2007 11:53:19 -0000 X-Spam-Check-By: sourceware.org Received: from NaN.false.org (HELO nan.false.org) (208.75.86.248) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 24 Oct 2007 11:53:12 +0000 Received: from nan.false.org (localhost [127.0.0.1]) by nan.false.org (Postfix) with ESMTP id 3A97D98340; Wed, 24 Oct 2007 11:53:11 +0000 (GMT) Received: from caradoc.them.org (22.svnf5.xdsl.nauticom.net [209.195.183.55]) by nan.false.org (Postfix) with ESMTP id 2172F981F2; Wed, 24 Oct 2007 11:53:11 +0000 (GMT) Received: from drow by caradoc.them.org with local (Exim 4.68) (envelope-from ) id 1IkenO-00055b-5i; Wed, 24 Oct 2007 07:53:10 -0400 Date: Wed, 24 Oct 2007 11:53:00 -0000 From: Daniel Jacobowitz To: Anitha Boyapati Cc: gdb@sourceware.org Subject: Re: conditional breakpoints for strings Message-ID: <20071024115310.GA19251@caradoc.them.org> Mail-Followup-To: Anitha Boyapati , gdb@sourceware.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.15 (2007-04-09) 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: 2007-10/txt/msg00192.txt.bz2 On Wed, Oct 24, 2007 at 12:27:38PM +0530, Anitha Boyapati wrote: > > Hi, > > Here's a sample program in C++ being debugged in GDB. It tries to stop if > string matches "hello" in a breakpoint. Now I am getting a segmentation > fault. But the same works fine for numerical comparisions(the code is > slightly changed as int i = 10 and a conditional BP is set if i==10). Is > this a bug or did I do something wrong ? You probably want to use at least one temporary variable to do this sort of thing. GDB evaluates C++ expressions with user defined operators by calling the operators, and it evaluates strings by calling malloc in the program. I believe there are three function calls in s == "hello" - one for malloc(6), one for char * to string conversion, and one to operator==. I see that it's GDB segfaulting, not your program. If this still happens with a newer version of GDB, we could look into it. But I get: Error in testing breakpoint condition: Invalid cast. GDB probably doesn't support the char* -> string constructor. That's one of the parts of C++ that's very hard to support in the debugger. -- Daniel Jacobowitz CodeSourcery