This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA] Emit a warning for ineffective set VAR = EXP command
On Mon, 7 May 2012, Tristan Gingold wrote:
> > This warns about "set variable $j++" presumably -- should the warning be
> > disabled for pre/post increments/decrements?
>
> I am not opposed to disable warnings for pre/post inc/dec.
> But this usage is dubious (the help explicitly mentions VAR=EXP !)
>
> Opinion ?
I think this is a bit too pedantic, there's no doubt these operators
imply an assignment in C. I think the help text is clear enough with:
"Evaluate expression EXP and assign result to variable VAR, using
assignment syntax appropriate for the current language (VAR = EXP or VAR
:= EXP for example)."
-- it quotes examples but these are by no means exhaustive and one can
imply any assignment valid according to the language selected is going to
be accepted. And there's quite a bunch of assignment operators defined
for C. Note that this help text does not mention "VAR <<= EXP" either and
there's no doubt this is a valid assignment in C too. If you're concerned
about this then perhaps the offline manual could be more elaborate.
I think one of our principles is to make debugging fast and efficient
rather than picky about the input style and with that in mind we should
accept any reasonable input from the user, sometimes even where it is not
perfectly valid for the given language, e.g. you can ask GDB like this:
(gdb) p/x (char[4])somevar
to print SOMEVAR (e.g. an INT) as a 4-element character array even though
this is really not something the C compiler would normally accept. I
recall seeing this principle written down somewhere, but cannot track it
down right now.
I use such constructs all the time, especially when referring to CPU
registers and I think it would be an unnecessary burden if rather than:
(gdb) set $a0++
I had to write:
(gdb) set $a0 += 1
or maybe even:
(gdb) set $a0 = $a0 + 1
That's IMHO an unnecessary waste of time, keyboard, etc. (note that += is
actually explicitly mentioned in the manual).
Maciej