[RFA] Real C++ operator validation

Keith Seitz keiths@redhat.com
Fri Sep 18 23:05:00 GMT 2009


Hi,

C++ operators have been sorely neglected in gdb's C++ code, especially 
the parser and decode_line, the two biggest interfaces to the user.

This patch is an attempt to mitigate the later by validating operator 
names. For example, one cannot break/list on a function named 
"operator_1", since gdb assumes that anything starting with "operator" 
is an operator.

Originally, I set out (in CVS HEAD) to fix an annoying bug concerning an 
error message when the user attempted to call decode_line with an 
undefined operator. Turns out the fix for this is a little more complex 
than I was hoping, but since I am trying to get all my branch patches 
accepted/committed here, I thought, "What the heck?" :-)

As a result, this patch from my archer-keiths-expr-cumulative branch has 
several (good) side-effects:

1) It properly ignores spaces in operator names. "break operator ++" is 
now valid. [NOTE: No single quotes!]
2) It adds the ability to list/break on conversion operators, e.g., 
"break foo::operator char*". [NOTE: No single quotes!]
3) (The bug I was attempting to fix) It now outputs "the class foo does 
not have any method named operator int*" instead of "the class foo does 
not have any method named operator ator".
4) It removes the assumption that functions starting with the word 
"operator" are really operators. If they are not, it treats them as 
"normal" functions.

I have regression tested this on x86 linux, and there are no 
regressions. [I thought I would explicitly mention this. I always do 
this anyway.]

Ok?/Comments?/Concerns?

Keith

PS. Shortly I'm planning to submit my "realcpp" tests which offers 
substantially more thorough testing of this and a lot more. Consequently 
I've intentionally kept the testing in this patch restricted to the bug 
I originally set out to fix.

ChangeLog
2009-09-18  Keith Seitz  <keiths@redhat.com>

	* cp-support.h (cp_validate_operator): Declare new function.
	* cp-support.c (cp_validate_operator): New function.
	* linespec.c (decode_compound): For C++ check for a valid operator.

testsuite/ChangeLog

2009-09-18  Keith Seitz  <keiths@redhat.com>

	* gdb.cp/cplusfuncs.exp (do_tests): Add check for proper error message
	with invalid operator.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cp_validate_operator.patch
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20090918/97264613/attachment.ksh>


More information about the Gdb-patches mailing list