This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: conditional breakpoints for strings
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