Add --enable-build-with-cxx

This new option, disabled by default for now, allows specifying
whether to build GDB, GDBserver, and friends with a C++ compiler.

Adding -fpermissive to build_warnings makes errors like these be
warnings instead:

  gdb/infrun.c:6597:1: error:   initializing argument 1 of ‘void sig_print_info(gdb_signal)’ [-fpermissive]
   sig_print_info (enum gdb_signal oursig)
   ^
  gdb/infrun.c: In function ‘void do_restore_infcall_suspend_state_cleanup(void*)’:
  gdb/infrun.c:7164:39: error: invalid conversion from ‘void*’ to ‘infcall_suspend_state*’ [-fpermissive]
     restore_infcall_suspend_state (state);
				 ^

so that the compiler carries on compiling the file.  -Werror still
catches the warnings, so nothing is lost, only our lifes are made
easier by concentrating on fixing other more important things first.

There's no way to quiet those warnings, until all these are fixed,
configure with --disable-werror, or build with 'make
WERROR_CFLAGS=""'.


Adding -Wno-narrowing suppresses thousands of instances of this warning:

  gdb/arm-linux-tdep.c:439:1: error: narrowing conversion of ‘-1’ from ‘int’ to ‘ULONGEST {aka long unsigned int}’ inside { } is ill-formed in C++11 [-Werror=narrowing]
  gdb/arm-linux-tdep.c:439:1: error: narrowing conversion of ‘-1l’ from ‘LONGEST {aka long int}’ to ‘ULONGEST {aka long unsigned int}’ inside { } is ill-formed in C++11 [-Werror=narrowing]
  gdb/arm-linux-tdep.c:450:1: error: narrowing conversion of ‘-1’ from ‘int’ to ‘ULONGEST {aka long unsigned int}’ inside { } is ill-formed in C++11 [-Werror=narrowing]

We can defer handling that for a while as we're currently targetting
C++98/03, only.


Adding -Wno-sign-compare suppresses thousands of instances of this warning:

  gdb/linux-record.c:1763:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
	 if (tmpulongest == tdep->fcntl_F_GETLK64)
				  ^

And adding -Wno-write-strings suppresses thousands of instances of this warning:

  gdb/mi/mi-cmd-var.c: In function ‘void mi_cmd_var_show_attributes(char*, char**, int)’:
  gdb/mi/mi-cmd-var.c:514:12: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
       attstr = "editable";
	      ^
  gdb/mi/mi-cmd-var.c:516:12: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
       attstr = "noneditable";
	      ^


For now, I'd rather hide these warnings from view until we're
'-fpermissive'-clean, and can thus build with -Werror.  The C compiler
manages to build working GDB's, with these issues in the code, so a
C++ compiler should too.
c++ keyword cleanliness, auto-generated

merged with:

fix "this" in gdbarch.sh; this was botched earlier
fix struct, union, and enum nesting
remove duplicate declaration errors

palves:
  removed a few more.
/home/pedro/gdb/mygit/src/gdb/python/python.c: At global scope:
/home/pedro/gdb/mygit/src/gdb/python/python.c:106:31: error: storage size of ‘GdbMethods’ isn’t known
 static PyMethodDef GdbMethods[];
                               ^
Add a few extern "C"s

TODO: The ones that are around headers should be pushed down to the headers themselves.
proc-service, extern "C"

linux-thread-db.c looks up symbols in the client, through the
proc-service interface.  These routines must have extern "C" linkage
to they're not mangled.
move exception_none to common code
catch_command_errors: mask argument not necessary
Normalize TRY_CATCH exception handling block

This normalizes all exception catch blocks that check for ex.reason to
look like this:

~~~
  volatile gdb_exception ex;

  TRY_CATCH (ex, RETURN_MASK_ALL)
    {
      ...
    }
  if (ex.reason < 0)
    {
      ...
    }
~~~

This is a preparation step for running a script that converts all
TRY_CATCH uses to look like this instead:

~~~
  TRY
    {
      ...
    }
  CATCH (ex, RETURN_MASK_ALL)
    {
      ...
    }
  END_CATCH
~~~

The motivation for that change is being able to reimplent TRY/CATCH in
terms of C++ try/catch.

The commit makes sure that:

 - no condition other than ex.reason < 0 checked in the if

 - no "else" block to check whether no exception was caught

 - no code between the TRY_CATCH (TRY) block and the
   'if (ex.reason < 0)' block (CATCH).

 - the exception object is no longer referred to outside the if/catch
   block. Note the volatile exception object declared in the function
   will disappear.  In cases it's more convenient to still refer to
   the exception outside the catch block, a new non-volatile local is
   added and copy to that object is made within the catch block.
replace TRY_CATCH wrapper macros
Split TRY_CATCH into TRY + CATCH

This patch splits the TRY_CATCH macro into three, so that we go from this:

~~~
  volatile gdb_exception ex;

  TRY_CATCH (ex, RETURN_MASK_ERROR)
    {
    }
  if (ex.reason < 0)
    {
    }
~~~

to this:

~~~
  TRY
    {
    }
  CATCH (ex, RETURN_MASK_ERROR)
    {
    }
  END_CATCH
~~~

(This patch just converts the framework, but doesn't adjust any caller
yet.  Subsequent patches will do that.  They'll all be squashed into a
single commit to avoid breaking bisects.)

Thus, we'll be getting rid of the local volatile exception object, and
declaring the caught exception in the catch block.

This allows reimplementing TRY/CATCH in terms of C++ exceptions when
building in C++ mode, while still allowing to build GDB in C mode
(using setjmp/longjmp), as an transition step.

TBC, after this patch, is it _not_ valid to have code between the TRY
and the CATCH blocks, like:

  TRY
    {
    }

  // some code here.

  CATCH (ex, RETURN_MASK_ERROR)
    {
    }
  END_CATCH

Just like it wouldn't be valid with C++'s try/catch.

By switching to creating an exception object local to the CATCH block,
we can get rid of all the explicitly allocated volatile exception
objects all over the place, and map the CATCH block more directly to
C++'s catch blocks.

END_CATCH is necessary because we name the exception object in the
CATCH block, which requires creating a scope, which in turn must be
closed somewhere.  Declaring the exception variable in the initializer
field of a for block, like:

  #define CATCH(EXCEPTION, mask) \
    for (struct gdb_exception EXCEPTION; \
         exceptions_state_mc_catch (&EXCEPTION, MASK); \
	 EXCEPTION = exception_none)

would avoid needing END_CATCH, but alas, we build with C90, which
doesn't allow declaring variables like that.

IMO, this still makes the codebase clearer, so IMO worth it even if we
weren't considering C++.

After we require C++, we can trivially sed END_CATCH away, but we'll
still need TRY/CATCH until cleanups are completely phased out --
TRY/CATCH in C++ mode will save/restore the current cleanup chain,
like in C mode, so that C++ cleanups and exceptions can coexist.
TRY_CATCH -> TRY+CATCH+END_CATCH everywhere

This converts all TRY_CATCH callers to TRY + CATCH + END_CATCH.

This was all done with script, no manual editing involved, but I
audited the patch to make sure things were converted as expected.
TRY_CATCH -> TRY+CATCH+END_CATCH, the manual conversions

This fixes the cases where we're using the exception object outside of
a the CATCH block, and cases where we were using "else" after a CATCH.

FIXME: These should actually be done _before_ running the script, and
then the script rerun.
more making TRY/CATCH callers look more like real C++ try/catch blocks

All these were caught by actually making TRY/CATCH use try/catch
behind the scenes, which complained about code between try and catch.

As with the prior patch, this should probably be done _before_ running
the TRY_CATCH conversion script.
kill volatile struct gdb_exception

This is the last remaining use of a volatile struct gdb_exception.
Kill it, as it's troublesome for C++ -- we can't assign volatile <->
non-volatile without copy constructors / assignment operators that do
that, which I'd rather avoid.
Make TRY/CATCH use real C++ try/catch in C++ mode

Although the current TRY/CATCH works in C++ mode too, setjmp/longjmp
bypass calling destructors of objects on the stack, which is obviously
bad for C++.

This commit makes TRY/CATCH use real try/catch in C++ mode behind the
scenes, which fixes the destructor problem.  The way this is done
allows RAII and cleanups to coexist while we phase out the later,
instead of requiring a flag day.
src/gdb/target.h:753:10: error: use of enum ‘exec_direction_kind’ without previous declaration
do not increment or decrement enum types

/home/pedro/gdb/mygit/src/gdb/i386-tdep.c: In function ‘int i386_stap_parse_special_token(gdbarch*, stap_parse_info*)’:
/home/pedro/gdb/mygit/src/gdb/i386-tdep.c:4309:7: error: no match for ‘operator++’ (operand type is ‘i386_stap_parse_special_token(gdbarch*, stap_parse_info*)::<anonymous enum>’)
       ++current_state;
       ^

...

/home/pedro/gdb/mygit/src/gdb/rs6000-tdep.c:4265:18: error: no match for ‘operator++’ (operand type is ‘powerpc_vector_abi’)
/home/pedro/gdb/mygit/src/gdb/arm-tdep.c:9428:71: error: no match for ‘operator++’ (operand type is ‘arm_float_model’)
/home/pedro/gdb/mygit/src/gdb/arm-tdep.c:9465:64: error: no match for ‘operator++’ (operand type is ‘arm_abi_kind’)

...
fix remote_insert_watchpoint interface

don't forward declare enum, and use target_hw_bp_type in the target methods

We need to fix all targets, though.