public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <drow@false.org>
To: Anitha Boyapati <anithab@sankhya.com>
Cc: gdb@sourceware.org
Subject: Re: conditional breakpoints for strings
Date: Wed, 24 Oct 2007 11:53:00 -0000	[thread overview]
Message-ID: <20071024115310.GA19251@caradoc.them.org> (raw)
In-Reply-To: <Pine.LNX.4.44.0710241217020.1037-100000@linux42.sankhya.com>

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

  reply	other threads:[~2007-10-24 11:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-24  6:51 Anitha Boyapati
2007-10-24 11:53 ` Daniel Jacobowitz [this message]
2007-10-24 12:22   ` Anitha Boyapati
2007-10-24 12:36     ` Daniel Jacobowitz
2007-10-24 13:05       ` Anitha Boyapati
2007-10-24 14:26       ` Dave Korn
2007-10-24 14:35         ` 'Daniel Jacobowitz'

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071024115310.GA19251@caradoc.them.org \
    --to=drow@false.org \
    --cc=anithab@sankhya.com \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).