You can define a command in gdb do do what you want as shown:
(gdb) define CheckDefined
Type commands for definition of "CheckDefined".
End with a line saying just "end".
>set $CheckDefined_DefinedOr1 = $arg0
>init-if-undefined $CheckDefined_DefinedOr1 = 1
>set $CheckDefined_DefinedOr2 = $arg0
>init-if-undefined $CheckDefined_DefinedOr2 = 2
>set $arg1 = ($CheckDefined_DefinedOr1 == $CheckDefined_DefinedOr2)
>end
Now that you have defined CheckDefined, you can use it as shown, to check whether a given convenience variable, in this case $fluffy, is defined, storing the result of the check in $fluffyIsDefined:
(gdb) CheckDefined $fluffy $fluffyIsDefined
(gdb) print $fluffyIsDefined
$17 = 0
If you now define the previously undefined variable, $fluffy, CheckDefined will yield a different result:
(gdb) set $fluffy = 92
(gdb) CheckDefined $fluffy $fluffyIsDefined
(gdb) print $fluffyIsDefined
$18 = 1
This use of the function has the advantage that you don't have to clobber the variable that you want to check. So to rewrite your original construct:
(gdb) CheckDefined $_exitcode $exitCodeIsDefined
(gdb) if (! $exitCodeIsDefined)
>quit
>end