Commit Graph

40336 Commits

Author SHA1 Message Date
Simon Marchi 9e5b9d2b29 Basic c++ification of varobj
This patch does a basic c++ification or the varobj data structure.

  - varobj: add constructor and destructor, initialize fields
  - varobj_root: initialize fields
  - varobj_dynamic: initialize fields

This allows getting rid of new_variable, new_root_variable.
free_variable essentially becomes varobj's destructor.  This also allows
getting rid of a cleanup, make_cleanup_free_variable, which was only
used in varobj_create in case the varobj creation fails.  It is replaced
with a unique_ptr.

gdb/ChangeLog:

	* varobj.h (struct varobj): Add constructor and destructor,
	initialize fields.
	* varobj.c (struct varobj_root): Initialize fields.
	(struct varobj_dynamic): Initialize fields.
	(varobj_create): Use unique_ptr instead of cleanup.  Create
	varobj with new instead of new_root_variable.
	(delete_variable_1): Free variable with delete instead of
	free_variable.
	(create_child_with_value): Create variable with new instead of
	new_variable.
	(varobj::varobj): New.
	(varobj::~varobj): New (body mostly coming from free_variable).
	(new_variable): Remove.
	(free_variable): Remove.
	(do_free_variable_cleanup): Remove.
	(make_cleanup_free_variable): Remove.
2017-11-22 15:08:05 -05:00
Ulrich Weigand fc35dab1a6 Remove obsolete core-regset.c
The last target that used core-regset.c (FreeBSD/alpha) has been
removed with GDB 8.0, and since then this file is obsolete.
2017-11-22 19:57:05 +01:00
Yao Qi 1daad298d6 [testsuite] Pass pthreads in prepare_for_testing
"pthreads" in the right flag to pass in prepare_for_testing to linker,
instead of additional_flags.  Without this patch, the test case can't be
complied by clang.

gdb compile failed, clang: warning: -lpthread: 'linker' input unused

gdb/testsuite:

2017-11-22  Yao Qi  <yao.qi@linaro.org>

	* gdb.base/info-os.exp: Pass pthreads.
	* gdb.multi/multi-attach.exp: Likewise.
2017-11-22 16:50:53 +00:00
Yao Qi 88465e872c [testsuite] Don't skip gdb.dwarf2/pr10770.exp for non-gcc compiler
gdb.dwarf2/pr10770.exp can be used for non-gcc compiler, at least clang.
This patch removes the restriction to only use gcc.  If other compilers,
like xlc or icc, can't compile the .c file, test result is not changed.

gdb/testsuite:

2017-11-22  Yao Qi  <yao.qi@linaro.org>

	* gdb.dwarf2/pr10770.exp: Remove code skipping non-gcc
	compiler.
2017-11-22 14:47:42 +00:00
Yao Qi dc196b230b [testsuite] Pass -pie in ldflags
-pie is a linker flag, it should be passed via "ldflags", instead
of "additional_flags".  Otherwise, clang complains,

clang: warning: argument unused during compilation: '-pie'

gdb/testsuite:

2017-11-22  Yao Qi  <yao.qi@linaro.org>

	* gdb.base/attach-pie-noexec.exp: Pass "-pie" in ldflags.
	* gdb.base/break-interp.exp: Likewise.
	* gdb.base/jit-attach-pie.exp: Likewise.
2017-11-22 14:35:01 +00:00
Ulrich Weigand 2400729ecf Target FP: Make use of MPFR if available
This second patch introduces mfpr_float_ops, an new implementation
of target_float_ops.  This implements precise emulation of target
floating-point formats using the MPFR library.  This is then used
to perform operations on types that do not match any host type.

Note that use of MPFR is still not required.  The patch adds
a configure option --with-mpfr similar to --with-expat.  If use of
MPFR is disabled via the option or MPFR is not available, code will
fall back to current behavior.  This means that operations on types
that do not match any host type will be implemented on the host
long double type instead.

A new test case verifies that we can correctly print the largest
__float128 value now.

gdb/ChangeLog:
2017-11-22  Ulrich Weigand  <uweigand@de.ibm.com>

	* NEWS: Document use of GNU MPFR.
	* README: Likewise.

	* Makefile.in (LIBMPFR): Add define.
	(CLIBS): Add $(LIBMPFR).
	* configure.ac: Add --with-mpfr configure option.
	* configure: Regenerate.
	* config.in: Regenerate.

	* target-float.c [HAVE_LIBMPFR]: Include <mpfr.h>.
	(class mpfr_float_ops): New type.
	(mpfr_float_ops::from_target): Two new overloaded functions.
	(mpfr_float_ops::to_target): Likewise.
	(mpfr_float_ops::to_string): New function.
	(mpfr_float_ops::from_string): Likewise.
	(mpfr_float_ops::to_longest): Likewise.
	(mpfr_float_ops::from_longest): Likewise.
	(mpfr_float_ops::from_ulongest): Likewise.
	(mpfr_float_ops::to_host_double): Likewise.
	(mpfr_float_ops::from_host_double): Likewise.
	(mpfr_float_ops::convert): Likewise.
	(mpfr_float_ops::binop): Likewise.
	(mpfr_float_ops::compare): Likewise.
	(get_target_float_ops): Use mpfr_float_ops if available.

gdb/doc/ChangeLog:
2017-11-22  Ulrich Weigand  <uweigand@de.ibm.com>

	* gdb.texinfo (Requirements): Document use of GNU MPFR.

gdb/testsuite/ChangeLog:
2017-11-22  Ulrich Weigand  <uweigand@de.ibm.com>

	* gdb.base/float128.c (large128): New variable.
	* gdb.base/float128.exp: Add test to print largest __float128 value.
2017-11-22 13:53:43 +01:00
Ulrich Weigand 7a26362d36 Target FP: Refactor use of host floating-point arithmetic
Prepare for using MPFR to implement floating-point arithmetic by
refactoring the way host floating-point arithmetic is currently used.

In particular, fix the following two problems that cause different
(and incorrect) results due to using host arithmetic:

- Current processing always uses host "long double", and then converts
  back to the actual target format.  This may introduce rounding errors.

- Conversion of FP values to LONGEST simply does a host C++ type cast.
  However the result of such a cast is undefined if the source value
  is outside the representable range.  MPFR always has defined behavior
  here (returns the minimum or maximum representable value).

To fix the first issue, I've now created not just one set of routines
using host FP arithmetic (on long double), but instead three different
sets of routines, one each for host float, double, and long double.
Operations can then be performed in the desired type directly, avoiding
the extra rounding step.  Using C++ templates, the three sets can all
share the same source code without duplication.

To fix the second issue, I'm simply enforcing the same conversion rule
(which makes sense anyway) when converting out-of-range values from
FP to LONGEST.

To contain the code complexity with the variety of options now possible,
I've created a new class "target_float_ops".  There are a total of five
separate implementations of this:

  host_float_ops<float>        Implemented via host FP in given type
  host_float_ops<double>
  host_float_ops<long double>
  mpfr_float_ops               Implemented via MPFR if available
  decimal_float_ops            Implemented via libdecnumber

Note instead of using the DOUBLEST define, this always just uses the
"long double" data type.  But since we now require C++11 anyway, this
type must in any case be avaialble unconditionally.

Most target floating-point operations simply dispatch to a (virtual)
member routine of this class.  Which implementation to choose is
determined from the target types involved, and whether they match
some host type or not.  E.g. any operation on a single type that
matches a host type is performed in that type.  Operations involving
two types that both match host types are performed in the larger one
(according to C/C++ implicit conversion rules).  Operations that
involve any type that does not match a host type are performed using
MPFR.  (And of course operations involving decimal FP are performed
using libdecnumber.)

This first patch implements the refactoring of target-float.c as
described above, introduing the host_float_ops and decimal_float_ops
classes, and using them.  Use of MPFR is introduced in the second patch.
A bit of special-case handling code is moved around to as to avoid
code duplication between host_float_ops and mpfr_float_ops.

Note that due to the changes mentioned above, I've had to update (fix)
the floating-point register values tested in the gdb.arch/vsx-regs.exp
test case.  (The new values now work both with host arithmetic and MPFR.)

gdb/ChangeLog:
2017-11-22  Ulrich Weigand  <uweigand@de.ibm.com>

	* target-float.c: Do not include <math.h>.
	Include <cmath> and <limits>.
	(DOUBLEST): Do not define.
	(class target_float_ops): New type.
	(class host_float_ops): New templated type.
	(class decimal_float_ops): New type.

	(floatformat_to_doublest): Rename to ...
	(host_float_ops<T>::from_target): ... this.  Use template type T
	instead of DOUBLEST.  Use C++ math routines.  Update recursive calls.
	(host_float_ops<T>::from_target): New overload using a type argument.
	(floatformat_from_doublest): Rename to ...
	(host_float_ops<T>::to_target): ... this.  Use template type T
	instead of DOUBLEST.  Use C++ math routines.  Update recursive calls.
	(host_float_ops<T>::to_target): New overload using a type argument.
	(floatformat_printf_format): New function.
	(struct printf_length_modifier): New templated type.
	(floatformat_to_string): Rename to ...
	(host_float_ops<T>::to_string): ... this.  Use type instead of
	floatformat argument.  Use floatformat_printf_format and
	printf_length_modifier.  Remove special handling of invalid numbers,
	infinities and NaN (moved to target_float_to_string).
	(struct scanf_length_modifier): New templated type.
	(floatformat_from_string): Rename to ...
	(host_float_ops<T>::from_string): ... this.  Use type instead of
	floatformat argument.  Use scanf_length_modifier.
	(floatformat_to_longest): Rename to ...
	(host_float_ops<T>::to_longest): ... this.  Use type instead of
	floatformat argument.  Handle out-of-range values deterministically.
	(floatformat_from_longest): Rename to ...
	(host_float_ops<T>::from_longest): ... this.  Use type instead of
	floatformat argument.
	(floatformat_from_ulongest): Rename to ...
	(host_float_ops<T>::from_ulongest): ... this.  Use type instead of
	floatformat argument.
	(floatformat_to_host_double): Rename to ...
	(host_float_ops<T>::to_host_double): ... this.  Use type instead of
	floatformat argument.
	(floatformat_from_host_double): Rename to ...
	(host_float_ops<T>::from_host_double): ... this.  Use type instead of
	floatformat argument.
	(floatformat_convert): Rename to ...
	(host_float_ops<T>::convert): ... this.  Use type instead of
	floatformat arguments.  Remove handling of no-op conversions.
	(floatformat_binop): Rename to ...
	(host_float_ops<T>::binop): ... this.  Use type instead of
	floatformat arguments.
	(floatformat_compare): Rename to ...
	(host_float_ops<T>::compare): ... this.  Use type instead of
	floatformat arguments.

	(match_endianness): Use type instead of length/byte_order arguments.
	(set_decnumber_context): Likewise.
	(decimal_from_number): Likewise.  Update calls.
	(decimal_to_number): Likewise.
	(decimal_is_zero): Likewise.  Update calls.  Move to earlier in file.
	(decimal_float_ops::to_host_double): New dummy function.
	(decimal_float_ops::from_host_double): Likewise.
	(decimal_to_string): Rename to ...
	(decimal_float_ops::to_string): ... this.  Use type instead of
	length/byte_order arguments.  Update calls.
	(decimal_from_string): Rename to ...
	(decimal_float_ops::from_string): ... this.  Use type instead of
	length/byte_order arguments.  Update calls.
	(decimal_from_longest): Rename to ...
	(decimal_float_ops::from_longest): ... this.  Use type instead of
	length/byte_order arguments.  Update calls.
	(decimal_from_ulongest): Rename to ...
	(decimal_float_ops::from_ulongest): ... this.  Use type instead of
	length/byte_order arguments.  Update calls.
	(decimal_to_longest): Rename to ...
	(decimal_float_ops::to_longest): ... this.  Use type instead of
	length/byte_order arguments.  Update calls.
	(decimal_binop): Rename to ...
	(decimal_float_ops::binop): ... this.  Use type instead of
	length/byte_order arguments.  Update calls.
	(decimal_compare): Rename to ...
	(decimal_float_ops::compare): ... this.  Use type instead of
	length/byte_order arguments.  Update calls.
	(decimal_convert): Rename to ...
	(decimal_float_ops::convert): ... this.  Use type instead of
	length/byte_order arguments.  Update calls.

	(target_float_same_category_p): New function.
	(target_float_same_format_p): Likewise.
	(target_float_format_length): Likewise.
	(enum target_float_ops_kind): New type.
	(get_target_float_ops_kind): New function.
	(get_target_float_ops): Three new overloaded functions.

	(target_float_is_zero): Update call.
	(target_float_to_string): Add special handling of invalid numbers,
	infinities and NaN (moved from floatformat_to_string).  Use
	target_float_ops callback.
	(target_float_from_string): Use target_float_ops callback.
	(target_float_to_longest): Likewise.
	(target_float_from_longest): Likewise.
	(target_float_from_ulongest): Likewise.
	(target_float_to_host_double): Likewise.
	(target_float_from_host_double): Likewise.
	(target_float_convert): Add special case for no-op conversions.
	Use target_float_ops callback.
	(target_float_binop): Use target_float_ops callback.
	(target_float_compare): Likewise.

gdb/testsuite/ChangeLog:
2017-11-22  Ulrich Weigand  <uweigand@de.ibm.com>

	* gdb.arch/vsx-regs.exp: Update register content checks.
2017-11-22 13:51:49 +01:00
Yao Qi a9f26f609e Fix build with GCC 8: strncpy ->strcpy
Recent gcc 8 trunk emits the warning below,

../../binutils-gdb/gdb/python/py-gdb-readline.c:79:15: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
       strncpy (q, p, n);
       ~~~~~~~~^~~~~~~~~
../../binutils-gdb/gdb/python/py-gdb-readline.c:73:14: note: length computed here
   n = strlen (p);
       ~~~~~~~^~~

gdb:

2017-11-22  Yao Qi  <yao.qi@linaro.org>

	* python/py-gdb-readline.c (gdbpy_readline_wrapper): Use strcpy.
2017-11-22 12:22:11 +00:00
Yao Qi 29f9a56737 Fix build with GCC 8: strncpy -> memcpy
Recent gcc 8 trunk emits the warning below,

../../../binutils-gdb/gdb/gdbserver/remote-utils.c:1204:14: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying 6 bytes from a string of the same length [-Werror=stringop-truncation]
      strncpy (buf, "watch:", 6);
      ~~~~~~~~^~~~~~~~~~~~~~~~~~

../../binutils-gdb/gdb/cli/cli-decode.c:1118:15: error: ‘char* strncpy(char*, const char*, size_t)’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
       strncpy (cmdtype1 + 1, cmdtype, len - 1);
       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../binutils-gdb/gdb/cli/cli-decode.c:1110:16: note: length computed here
   len = strlen (cmdtype);
         ~~~~~~~^~~~~~~~~
../../binutils-gdb/gdb/cli/cli-decode.c:1120:15: error: ‘char* strncpy(char*, const char*, size_t)’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
       strncpy (cmdtype2, cmdtype, len - 1);
       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../binutils-gdb/gdb/cli/cli-decode.c:1110:16: note: length computed here
   len = strlen (cmdtype);
         ~~~~~~~^~~~~~~~~

../../binutils-gdb/gdb/cp-namespace.c:1071:11: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying 2 bytes from a string of the same length [-Werror=stringop-truncation]
   strncpy (full_name + scope_length, "::", 2);
   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This patch fixes it by using memcpy instead of strncpy.

gdb:

2017-11-22  Yao Qi  <yao.qi@linaro.org>

	* cli/cli-decode.c (help_list): Use memcpy instead of strncpy.
	* cp-namespace.c (cp_lookup_transparent_type_loop): Likewise.

gdb/gdbserver:

2017-11-22  Yao Qi  <yao.qi@linaro.org>

	* remote-utils.c (prepare_resume_reply): Use memcpy.
2017-11-22 12:22:11 +00:00
Jerome Guitton 3b1b69bffe ravenscar: update inferior ptid with event ptid
When debugging a program using a ravenscar runtime, the thread
layer sometimes gets confused, and even missing some threads.
This was traced to an assumption that ravenscar_wait was making,
which is that calling the "to_wait" target_ops method would
set the inferior_ptid, so that we could then use that assumption
to update our thread_list and current ptid. However, this has not
been the case for quite a while now. This patch fixes the problem
by assigning inferior_ptid the ptid returned by "to_wait".

gdb/ChangeLog:

	* ravenscar-thread.c (ravenscar_wait): Update inferior ptid
	with event ptid from the lower layer before doing the
	ravenscar-specific update.
2017-11-21 14:34:30 -08:00
Joel Brobecker 54aa6c67f5 (Ada) crash connecting to TSIM simulator
Connecting to a TSIM simulator over the remote protocol causes GDB
to crash with the following failed assertion:

    (gdb) tar remote :1234
    Remote debugging using :1234
    /[...]/gdb/ravenscar-thread.c:182: internal-error: ravenscar_update_inferior_ptid: Assertion `!is_ravenscar_task (inferior_ptid)' failed.
    A problem internal to GDB has been detected,
    further debugging may prove unreliable.
    Quit this debugging session? (y or n) y

What happens is the following. Upon connection to the target, GDB
sends a 'qfThreadInfo' query, which is the query asking the target
for the ID of the first thread, and TSIM replies 'm0':

    Sending packet: $qfThreadInfo#bb...Ack
    Packet received: m0

As a result of this, GDB takes the '0' as the TID, and because of it,
constructs a ptid whose value is {42000, 0, 0}. This trips our
!is_ravenscar_task check, because all it does to identify threads
corresponding to ravenscar tasks is that their lwp is null, because
that's how we construct their ptid.

But this is unfortunatly not sufficient when debugging with TSIM,
because the thread ID that TSIM returns causes the creation of
a ptid whose lwp is zero, which matches the current identification
scheme and yet is clearly not a ravenscar task.

The fix is to also make sure that the ptid's tid field is nonzero.

gdb/ChangeLog:

        * ravenscar-thread.c (is_ravenscar_task): Also verify that
        the ptid's TID is nonzero.
2017-11-21 14:33:31 -08:00
Joel Brobecker cf3fbed4a0 problem debugging ravenscar programs if runtime is stripped
Trying to debug a program using a stripped version of the ravenscar
runtime, we can get the following error:

    (gdb) cont
    Continuing.
    Cannot find Ada_Task_Control_Block type. Aborting

This is because the ravenscar-thread layer makes the assumption that
the runtime is built the way we expect it, meaning that the Ada tasking
units we rely on for Ada tasking debugging, are built with debugging
information, and that this debug information has not been stripped from
the runtime.

When this assumption is not true, resuming such a program can trigger
the error above, which then leads GDB a little confused. For instance,
we can see things like:

     (gdb) bt
     Target is executing.

This patch fixes the issue by disabling the ravenscar thread layer
if we detect that the runtime is missing some of the debugging info
we need in order to support Ada task debugging. This is the best
we can do, as the ravenscar-thread layer actually depends on the
ada-tasks layer to implement thread debugging.

gdb/ChangeLog:

        * ada-lang.h (ada_get_tcb_types_info): Add declaration.
        * ada-tasks.c (ada_get_tcb_types_info): Renames get_tcb_types_info.
        Make non-static.  Change return type to char *.  Adjust code
        accordingly.  Rewrite the function's documentation.
        (read_atcb): Adjust call to get_tcb_types_info accordingly.
        * ravenscar-thread.c (ravenscar_inferior_created): Check that
        we have enough debugging information in the runtime to support
        Ada task debugging before we enable the ravenscar-thread layer.
2017-11-21 14:32:48 -08:00
Joel Brobecker 9edcc12f9b Add multiple-CPU support in ravenscar-thread.c
This patch reworks the ravenscar-thread layer to remove the
assumption that the target only has 1 CPU. In particular,
when connected to a QEMU target over the remote protocol,
QEMU reports each CPU as one thread. This patch adapts
the ravenscar-thread layer to this, and adds a large comment
explaining the general design of this unit.

gdb/ChangeLog:

        * ada-lang.h (ada_get_task_info_from_ptid): Add declaration.
        * ada-tasks.c (ada_get_task_info_from_ptid): New function.
        * ravenscar-thread.c: Add into comment.
        (base_magic_null_ptid): Delete.
        (base_ptid): Change documentation.
        (ravenscar_active_task): Renames ravenscar_running_thread.
        All callers updated throughout.
        (is_ravenscar_task, ravenscar_get_thread_base_cpu): New function.
        (ravenscar_task_is_currently_active): Likewise.
        (get_base_thread_from_ravenscar_task): Ditto.
        (ravenscar_update_inferior_ptid): Adjust to handle multiple CPUs.
        (ravenscar_runtime_initialized): Likewise.
        (get_running_thread_id): Add new parameter "cpu".  Adjust
        implementation to handle this new parameter.
        (ravenscar_fetch_registers): Small adjustment to use
        is_ravenscar_task and ravenscar_task_is_currently_active in
        order to decide whether to use the target beneath or this
        module's arch_ops.
        (ravenscar_store_registers, ravenscar_prepare_to_store): Likewise.
        (ravenscar_stopped_by_sw_breakpoint): Use
        get_base_thread_from_ravenscar_task to get the underlying
        thread, rather than using base_ptid.
        (ravenscar_stopped_by_hw_breakpoint, ravenscar_stopped_by_watchpoint)
        (ravenscar_stopped_data_address, ravenscar_core_of_thread):
        Likewise.
        (ravenscar_inferior_created): Do not set base_magic_null_ptid.
2017-11-21 14:32:10 -08:00
Joel Brobecker 65d40437e2 Provide the "Base CPU" in output of "info task" (if set by runtime).
At the user level, this patch enhances the debugger to print the ID
of the base CPU a task is running on:

        (gdb) info task 3
        Ada Task: 0x13268
        Name: raven1
        Thread: 0x13280
        LWP: 0
 !!!->  Base CPU: 1
        No parent
        Base Priority: 127
        State: Runnable

This new field is only printed when the base CPU is nonzero or, in
other words, if the base CPU info is being provided by the runtime.
For instance, on native systems, where threads/processes can "jump"
from CPU to CPU, the info is not available, and the output of the
command above then remains unchanged.

At the internal level, the real purpose of this change is to prepare
the way for ravenscar-thread to start handling SMP systems. For that,
we'll need to know which CPU each task is running on...  More info
on that in the commit that actually adds support for it.

gdb/ChangeLog:

        * ada-lang.h (struct ada_task_info) <base_cpu>: New field.
        * ada-lang.c (struct atcb_fieldno) <base_cpu>: New field.
        (get_tcb_types_info): Set fieldnos.base_cpu.
        (read_atcb): Set task_info->base_cpu.
        (info_task): Print "Base CPU" info if set by runtime.
2017-11-21 14:31:32 -08:00
Joel Brobecker e02544b292 watchpoint regression debugging with remote protocol (bare metal)
We have noticed a regression in our watchpoint support when debugging
through the remote protocol a program running on a bare metal platform,
when the program uses what we call the Ravenscar Runtime.

This runtime is a subset of the Ada runtime defined by the Ravenscar
Profile.  One of the nice things about this runtime is that it provides
tasking, which is equivalent to the concept of threads in C (it is
actually often mapped to threads, when available). For bare metal
targets, however, there is no OS, and therefore no thread layer.
What we did, then, was add a ravenscar-thread layer, which has insider
knowledge of the runtime to get the list of threads, but also all
necessary info to perform thread switching.

For the record, the commit which caused the regression is:

    commit 799a2abe61
    Date:   Mon Nov 30 16:05:16 2015 +0000
    Subject: remote: stop reason and watchpoint data address per thread

    Running local-watch-wrong-thread.exp with "maint set target-non-stop
    on" exposes that gdb/remote.c only records whether the target stopped
    for a breakpoint/watchpoint plus the watchpoint data address *for the
    last reported remote event*.  But in non-stop mode, we need to keep
    that info per-thread, as each thread can end up with its own
    last-status pending.

Our testcase is very simple. We have a package defining a global
variable named "Watch"...

    package Pck is
       Watch : Integer := 1974;
    end Pck;

... and a main subprogram which changes its value

    procedure Foo is
    begin
       Pck.Watch := Pck.Watch + 1;
    end Foo;

To reproduce, we built our program as usual, started it in QEMU,
and then connected GDB to QEMU...

    (gdb) target remote :4444
    (gdb) break _ada_foo
    (gdb) cont  <--- this is to make sure the program is started
                     and the variable we want to watch is initialized

... at which point we try to use a watchpoint on our global variable:

    (gdb) watch watch

... but, upon resuming the execution with a "cont", we expected to
get a watchpoint-hit notification, such as...

    (gdb) cont
    Hardware watchpoint 2: watch

    Old value = 1974
    New value = 1975
    0xfff00258 in foo () at /[...]/foo.adb:6
    6       end Foo;

... but unfortunately, we get a SIGTRAP instead:

    (gdb) cont
    Program received signal SIGTRAP, Trace/breakpoint trap.
    foo () at /[...]/foo.adb:6
        6   end Foo;

What happens is that, on the one hand, the change in remote.c
now stores the watchpoint-hit notification info in the thread
that received it; and on the other hand, we have a ravenscar-thread
layer which manages the thread list on top of the remote protocol
layer. The two of them get disconnected, and this eventually results
in GDB not realizing that we hit a watchpoint.  Below is how:

First, once connected and just before inserting our watchpoint,
we have the ravenscar-thread layer which built the list of threads
by extracting some info from inferior memory, giving us the following
two threads:

      (gdb) info threads
      Id   Target Id         Frame
      1    Thread 0 "0Q@" (Ravenscar task) foo () at /[...]/foo.adb:5
    * 2    Thread 0x24618 (Ravenscar task) foo () at /[...]/foo.adb:5

The first thread is the only thread QEMU told GDB about. The second
one is a thread that the ravenscar-thread added. QEMU has now way
to know about those threads, since they are really embedded inside
the program; that's why we have the ravenscar layer, which uses
inside-knowledge to extract the list of threads.

Next, we insert a watchpoint, which applies to all threads. No problem
so far.

Then, we continue; meaning that GDB sends a Z2 packet to QEMU to
get the watchpoint inserted, then a vCont to resume the program's
execution. The program hits the watchpoints, and thererfore QEMU
reports it back:

        Packet received: T05thread:01;watch:000022c4;

Since QEMU knows about one thread and one thread only, it stands
to reason that it would say that the event applies to thread:01,
which is our first thread in the "info threads" listing. That
thread has a ptid of {42000, lwp=1, tid=0}.

This is where Pedro's change kicks in: Seeing this event, and
having determined that the event was reported for thread 01,
and therefore ptid {42000, lwp=1, tid=0}, it saves the watchpoint-hit
event info in the private area of that thread/ptid. Once this is
done, remote.c's event-wait layer returns.

Enter the ravenscar-thread layer of the event-wait, which does
a little dance to delegate the wait to underlying layers with
ptids that those layers know about, and then when the target_beneath's
to_wait is done, tries to figure out which thread is now the active
thread. The code looks like this:

  1.    inferior_ptid = base_ptid;
  2.    beneath->to_wait (beneath, base_ptid, status, 0);
  3.    [...]
  4.        ravenscar_update_inferior_ptid ();
  5.
  6.    return inferior_ptid;

Line 1 is where we reset inferior_ptid to the ptid that
the target_beneath layer knows about, allowing us to then
call its to_wait implementation (line 2). And then, upon
return, we call ravenscar_update_inferior_ptid, which reads
inferior memory to determine which thread is actually active,
setting inferior_ptid accordingly. Then we return that
inferior_ptid (which, again, neither QEMU and therefore nor
the remote.c layer knows about).

Upon return, we eventually arrive to the part where we try
to handle the inferior event: we discover that we got a SIGTRAP
and, as part of its handling, we call watchpoints_triggered,
which calls target_stopped_by_watchpoint, which eventually
remote_stopped_by_watchpoint, where Pedro's change kicks in
again:

    struct thread_info *thread = inferior_thread ();
    return (thread->priv != NULL
            && thread->priv->stop_reason == TARGET_STOPPED_BY_WATCHPOINT);

Because the ravenscar-thread layer changed the inferior_ptid
to the ptid of the active thread, inferior_thread now returns
the private data of that thread. This is not the thread that
QEMU reported the watchpoint-hit on, and thus, the function
returns "no watchpoint hit, mister". Hence GDB not understanding
the SIGTRAP, thus reporting it verbatim.

The way we chose to fix the issue is by making sure that the
ravenscar-thread layer doesn't let the remote layer be called
with inferior_ptid being set to a thread that the remote layer
does not know about.

gdb/ChangeLog:

        * ravenscar-thread.c (ravenscar_stopped_by_sw_breakpoint)
        (ravenscar_stopped_by_hw_breakpoint, ravenscar_stopped_by_watchpoint)
        (ravenscar_stopped_data_address, ravenscar_core_of_thread):
        New functions.
        (init_ravenscar_thread_ops): Set the to_stopped_by_sw_breakpoint,
        to_stopped_by_hw_breakpoint, to_stopped_by_watchpoint,
        to_stopped_data_address and to_core_of_thread fields of
        ravenscar_ops.
2017-11-21 14:30:55 -08:00
Ulrich Weigand ed0f427344 [PowerPC] Detect different long double floating-point formats
Current versions of GCC support switching the format used for "long double"
to either IBM double double or IEEE-128.  The resulting binary is marked
via different setting of the Tag_GNU_Power_ABI_FP GNU attribute.

This patch checks this attribute to detect the format of the default
"long double" type and sets GDB's notion of the format accordingly.

The patch also adds support for the "__ibm128" type, which always uses
IBM double double format independent of the format used for "long double".

A new test case verifies that all three types, "long double", "__float128",
and "__ibm128" are correctly detected in all three compiler settings,
the default setting, -mabi=ieeelongdouble, and -mabi=ibmlongdouble.

gdb/ChangeLog:
2017-11-21  Ulrich Weigand  <uweigand@de.ibm.com>

	* ppc-tdep.h (enum powerpc_long_double_abi): New data type.
	(struct gdbarch_tdep): New member long_double_abi.
	* rs6000-tdep.c (rs6000_gdbarch_init): Initialize long_double_abi
	member of tdep struct based on Tag_GNU_Power_ABI_FP attribute.
	* ppc-linux-tdep.c (ppc_linux_init_abi): Install long double data
	format depending on long_double_abi tdep member.
	(ppc_floatformat_for_type): Handle __ibm128 type.

gdb/testsuite/ChangeLog:
2017-11-21  Ulrich Weigand  <uweigand@de.ibm.com>

	* gdb.arch/ppc-longdouble.exp: New file.
	* gdb.arch/ppc-longdouble.c: Likewise.
2017-11-21 18:50:59 +01:00
Pedro Alves a25d69c6dc gdb.ada/minsyms.exp: Don't hardcode the variable's address
This new testcase has a test that fails like this here:

  $1 = (<data variable, no debug info> *) 0x60208c <some_minsym>
  (gdb) FAIL: gdb.ada/minsyms.exp: print &some_minsym

The problem is that the testcase hardcodes an expected address for the
"some_minsym" variable, which obviously isn't stable.

Fix that by expecting $hex instead.

gdb/testsuite/ChangeLog:
2017-11-21  Pedro Alves  <palves@redhat.com>

	* gdb.ada/minsyms.exp: Accept any address for 'some_minsym'.
2017-11-21 16:04:42 +00:00
Simon Marchi 0fc7642151 Fix build failure in darwin-nat.c
Fix:

/Users/simark/src/binutils-gdb/gdb/darwin-nat.c:2404:3: error: no matching function for call to 'add_setshow_boolean_cmd'
  add_setshow_boolean_cmd ("mach-exceptions", class_support,
  ^~~~~~~~~~~~~~~~~~~~~~~

gdb/ChangeLog:

	* darwin-nat.c (set_enable_mach_exceptions): Constify parameter.
2017-11-20 23:29:10 -05:00
Pedro Alves e6b2f5efa9 Fix mapped_index::find_name_components_bounds upper bound computation
Here we want to find where we'd insert "after", so we want
std::lower_bound, not std::upper_bound.

gdb/ChangeLog:
2017-11-21  Pedro Alves  <palves@redhat.com>

	* dwarf2read.c (mapped_index::find_name_components_bounds)
	<completion mode, upper bound>: Use std::lower_bound instead of
	std::upper_bound.
	(test_mapped_index_find_name_component_bounds): Remove incorrect
	"t1_fund" from expected symbols.
2017-11-21 00:03:27 +00:00
Pedro Alves 5c58de74c9 Unit test name-component bounds searching directly
This commit factors out the name-components-vector building and bounds
searching out of dw2_expand_symtabs_matching_symbol into separate
functions, and adds unit tests that:

 - expose both the latent bug mentioned in the previous commit, and
   also,

 - for completeness exercise the 0xff character handling fixed in the
   previous commit more directly.

The actual fix for the now-exposed bug is left for the following
patch.

gdb/ChangeLog:
2017-11-21  Pedro Alves  <palves@redhat.com>

	* dwarf2read.c (mapped_index::name_components_casing): New field.
	(mapped_index) <build_name_components,
	find_name_components_bounds): Declare new methods.
	(mapped_index::find_name_components_bounds)
	(mapped_index::build_name_components): New methods, factored out
	from dw2_expand_symtabs_matching_symbol.
	(check_find_bounds_finds)
	(test_mapped_index_find_name_component_bounds): New.
	(run_test): Rename to ...
	(test_dw2_expand_symtabs_matching_symbol): ... this.
	(run_test): Reimplement.
2017-11-21 00:03:10 +00:00
Pedro Alves e1ef7d7a51 0xff chars in name components table; cp-name-parser lex UTF-8 identifiers
The find-upper-bound-for-completion algorithm in the name components
accelerator table in dwarf2read.c increments a char in a string, and
asserts that it's not incrementing a 0xff char, but that's incorrect.

First, we shouldn't be calling gdb_assert on input.

Then, if "char" is signed, comparing a caracther with "0xff" will
never yield true, which is caught by Clang with:

  error: comparison of constant 255 with expression of type '....' (aka 'char') is always true [-Werror,-Wtautological-constant-out-of-range-compare]
	    gdb_assert (after.back () != 0xff);
			~~~~~~~~~~~~~ ^  ~~~~

And then, 0xff is a valid character on non-UTF-8/ASCII character sets.
E.g., it's 'ÿ' in Latin1.  While GCC nor Clang support !ASCII &&
!UTF-8 characters in identifiers (GCC supports UTF-8 characters only
via UCNs, see https://gcc.gnu.org/onlinedocs/cpp/Character-sets.html),
but other compilers might (Visual Studio?), so it doesn't hurt to
handle it correctly.  Testing is covered by extending the
dw2_expand_symtabs_matching unit tests with relevant cases.

However, without further changes, the unit tests still fail...  The
problem is that cp-name-parser.y assumes that identifiers are ASCII
(via ISALPHA/ISALNUM).  This commit fixes that too, so that we can
unit test the dwarf2read.c changes.  (The regular C/C++ lexer in
c-lang.y needs a similar treatment, but I'm leaving that for another
patch.)

While doing this, I noticed a thinko in the computation of the upper
bound for completion in dw2_expand_symtabs_matching_symbol.  We're
using std::upper_bound but we should use std::lower_bound.  I extended
the unit test with a case that I thought would expose it, this one:

 +  /* These are used to check that the increment-last-char in the
 +     matching algorithm for completion doesn't match "t1_fund" when
 +     completing "t1_func".  */
 +  "t1_func",
 +  "t1_func1",
 +  "t1_fund",
 +  "t1_fund1",

The algorithm actually returns "t1_fund1" as lower bound, so "t1_fund"
matches incorrectly.  But turns out the problem is masked because
later here:

  for (;lower != upper; ++lower)
    {
      const char *qualified = index.symbol_name_at (lower->idx);

      if (!lookup_name_matcher.matches (qualified)

the lookup_name_matcher.matches check above filters out "t1_fund"
because that doesn't start with "t1_func".

I'll fix the latent bug in follow up patches, after factoring things
out a bit in a way that allows unit testing the relevant code more
directly.

gdb/ChangeLog:
2017-11-21  Pedro Alves  <palves@redhat.com>

	* cp-name-parser.y (cp_ident_is_alpha, cp_ident_is_alnum): New.
	(symbol_end): Use cp_ident_is_alnum.
	(yylex): Use cp_ident_is_alpha and cp_ident_is_alnum.
	* dwarf2read.c (make_sort_after_prefix_name): New function.
	(dw2_expand_symtabs_matching_symbol): Use it.
	(test_symbols): Add more symbols.
	(run_test): Add tests.
2017-11-21 00:02:46 +00:00
Pedro Alves 73fcf6418d Fix gdb.base/whatis-ptype-typedefs.exp on 32-bit archs
The gdb.base/whatis-ptype-typedefs.exp testcase has several tests that
fail on 32-bit architectures.  E.g., on 'x86-64 -m32', I see:

 ...
 FAIL: gdb.base/whatis-ptype-typedefs.exp: lang=c: cast: whatis (float_typedef) v_uchar_array_t_struct_typedef (invalid)
 FAIL: gdb.base/whatis-ptype-typedefs.exp: lang=c: cast: ptype (float_typedef) v_uchar_array_t_struct_typedef (invalid)
 ...

gdb.log:

 (gdb) whatis (float_typedef) v_uchar_array_t_struct_typedef
 type = float_typedef
 (gdb) FAIL: gdb.base/whatis-ptype-typedefs.exp: lang=c: cast: whatis (float_typedef) v_uchar_array_t_struct_typedef (invalid)

As Simon explained [1], the issue boils down to the fact that on
64-bit, this is an invalid cast:

 (gdb) p (float_typedef) v_uchar_array_t_struct_typedef
 Invalid cast.

while on 32 bits it is valid:

 (gdb) p (float_typedef) v_uchar_array_t_struct_typedef
 $1 = 1.16251721e-41

The expression basically tries to cast an array (which decays to a
pointer) to a float.  The cast works on 32 bits because a float and a
pointer are of the same size, and value_cast works in that case:

~~~
   More general than a C cast: accepts any two types of the same length,
   and if ARG2 is an lvalue it can be cast into anything at all.  */
~~~

On 64 bits, they are not the same size, so it ends throwing the
"Invalid cast" error.

The testcase is expecting the invalid cast behavior, thus the FAILs.

A point of these tests was to cover as many code paths in value_cast
as possible, as a sort of documentation of the current behavior:

    # The main idea here is testing all the different paths in the
    # value casting code in GDB (value_cast), making sure typedefs are
    # preserved.
...
    # We try all combinations, even those that don't parse, or are
    # invalid, to catch the case of a regression making them
    # inadvertently valid.  For example, these convertions are
    # invalid:
...

In that spirit, this commit makes the testcase adjust itself depending
on size of floats and pointers, and also test floats of different
sizes.

Passes cleanly on x86-64 GNU/Linux both -m64/-m32.

[1] - https://sourceware.org/ml/gdb-patches/2017-11/msg00382.html

gdb/ChangeLog:
2017-11-20  Pedro Alves  <palves@redhat.com>

	* gdb.base/whatis-ptype-typedefs.c (double_typedef)
	(long_double_typedef): New typedefs.
	Use DEF on double and long double.
	* gdb.base/whatis-ptype-typedefs.exp: Add double and long double
	cases.
	(run_tests): New 'float_ptr_same_size', 'double_ptr_same_size',
	and 'long_double_ptr_same_size' locals.  Use them to decide
	whether cast from array/function to float is valid/invalid.
2017-11-20 23:03:17 +00:00
Simon Marchi 578290ecaf Remove usage of find_inferior when calling kill_one_lwp_callback
Replace with for_each_thread.

gdb/gdbserver/ChangeLog:

	* linux-low.c (kill_one_lwp_callback): Return void, take
	argument directly, don't filter on pid.
	(linux_kill): Use for_each_thread.
2017-11-19 22:23:28 -05:00
Simon Marchi eca55aec1d Remove usages of find_thread when calling need_step_over_p
Replace with find_thread.

gdb/gdbserver/ChangeLog:

	* linux-low.c (need_step_over_p): Return bool, remove dummy
	argument.
	(linux_resume, proceed_all_lwps): Use find_thread.
2017-11-19 22:23:27 -05:00
Simon Marchi 25c28b4d15 Remove usage of find_thread when calling resume_status_pending_p
Replace with find_thread.  Instead of setting the flag in the callback,
make the callback return true/false, and check the result against NULL
in the caller.

gdb/gdbserver/ChangeLog:

	* linux-low.c (resume_status_pending_p): Return bool, remove
	flag_p argument.
	(linux_resume): Use find_thread.
2017-11-19 22:23:27 -05:00
Simon Marchi 5fdda39248 Remove usage of find_inferior when calling linux_set_resume_request
Replace it with for_each_thread.

gdb/gdbserver/ChangeLog:

	* linux-low.c (struct thread_resume_array): Remove.
	(linux_set_resume_request): Return void, take arguments
	directly.
	(linux_resume): Use for_each_thread.
2017-11-19 22:23:26 -05:00
Simon Marchi fcb056a58d Remove usage of find_inferior in linux_stabilize_threads
Simply replace with find_thread.

gdb/gdbserver/ChangeLog:

	* linux-low.c (stuck_in_jump_pad_callback): Change prototype,
	return bool, remove data argument.
	(linux_stabilize_threads): Use find_thread.
2017-11-19 22:23:25 -05:00
Simon Marchi 139720c5b3 Remove usage of find_inferior in unsuspend_all_lwps
Replace with for_each_thread.  I inlined unsuspend_one_lwp in
unsuspend_all_lwps, since it is very simple.

gdb/gdbserver/ChangeLog:

	* linux-low.c (unsuspend_one_lwp): Remove.
	(unsuspend_all_lwps): Use for_each_thread, inline code from
	unsuspend_one_lwp.
2017-11-19 22:23:24 -05:00
Simon Marchi 6d1e5673fe Remove usage of find_inferior in iterate_over_lwps
Replace find_inferior with find_thread.  Since it may be useful in the
future, I added another overload to find_thread which filters based on a
ptid (using ptid_t::matches), so now iterate_over_lwps doesn't have to
do the filtering itself.  iterate_over_lwps_filter is removed and
inlined into iterate_over_lwps.

gdb/gdbserver/ChangeLog:

	* gdbthread.h (find_thread): Add overload with ptid_t filter.
	* linux-low.c (struct iterate_over_lwps_args): Remove.
	(iterate_over_lwps_filter): Remove.
	(iterate_over_lwps): Use find_thread.
2017-11-19 22:23:23 -05:00
Simon Marchi bbf550d50e Remove usage of find_inferior in reset_lwp_ptrace_options_callback
Replace with for_each_thread, and inline code from
reset_lwp_ptrace_options_callback.

gdb/gdbserver/ChangeLog:

	* linux-low.c (reset_lwp_ptrace_options_callback): Remove.
	(linux_handle_new_gdb_connection): Use for_each_thread, inline
	code from reset_lwp_ptrace_options_callback.
2017-11-19 22:23:23 -05:00
Simon Marchi 00192f7717 Remove usages of find_inferior in linux-arm-low.c
Replace two usages with the overload of for_each_thread that filters on
pid.  It allows to simplify the callback a little bit.

gdb/gdbserver/ChangeLog:

	* linux-arm-low.c (struct update_registers_data): Remove.
	(update_registers_callback): Return void, take arguments
	directly, don't check thread's pid.
	(arm_insert_point, arm_remove_point): Use for_each_thread.
2017-11-19 22:23:22 -05:00
Simon Marchi 2bee2b6ca4 Remove usage of find_inferior in win32-low.c
Replace with for_each_thread.

gdb/gdbserver/ChangeLog:

	* win32-low.c (continue_one_thread): Return void, take argument
	directly.
	(child_continue): Use for_each_thread.
2017-11-19 22:23:21 -05:00
Simon Marchi 0b360f1926 Remove usage of find_inferior in win32-i386-low.c
Straightforward replacement of find_inferior with the overload of
for_each_thread that filters on pid.  I am able to build-test this
patch, but not run it.

gdb/gdbserver/ChangeLog:

	* win32-i386-low.c (update_debug_registers_callback): Rename
	to ...
	(update_debug_registers): ... this, return void, remove pid_p arg.
	(x86_dr_low_set_addr, x86_dr_low_set_control): Use for_each_thread.
2017-11-19 22:23:20 -05:00
Tom Tromey cf724bc93e Use an enum to represent subclasses of symbol
This changes struct symbol to use an enum to encode the concrete
subclass of a particular symbol.  Note that "enum class" doesn't work
properly with bitfields, so a plain enum is used.

2017-11-17  Tom Tromey  <tom@tromey.com>

	* symtab.h (enum symbol_subclass_kind): New.
	(struct symbol) <is_cplus_template_function, is_rust_vtable>:
	Remove.
	<subclass>: New member.
	(SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION): Update.
	* rust-lang.c (rust_get_trait_object_pointer): Update.
	* dwarf2read.c (read_func_scope): Update.
	(read_variable): Update.
2017-11-17 14:34:14 -07:00
Tom Tromey 68e745e38e Make template_symbol derive from symbol
This changes template_symbol to derive from symbol, which seems a bit
cleaner; and also more consistent with rust_vtable_symbol.

2017-11-17  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (read_func_scope): Update.
	* symtab.h (struct template_symbol): Derive from symbol.
	<base>: Remove.
2017-11-17 14:34:14 -07:00
Tom Tromey 71a3c36949 Handle dereferencing Rust trait objects
In Rust, virtual tables work a bit differently than they do in C++.  In
C++, as you know, they are connected to a particular class hierarchy.
Rust, instead, can generate a virtual table for potentially any type --
in fact, one such virtual table for each trait (a trait is similar to an
abstract class or to a Java interface) that a type implements.

Objects that are referenced via a trait can't currently be inspected by
gdb.  This patch implements the Rust equivalent of "set print object".

gdb relies heavily on the C++ ABI to decode virtual tables; primarily to
make "set print object" work; but also "info vtbl".  However, Rust does
not currently have a specified ABI, so this approach seems unwise to
emulate.

Instead, I've changed the Rust compiler to emit some DWARF that
describes trait objects (previously their internal structure was
opaque), vtables (currently just a size -- but I hope to expand this in
the future), and the concrete type for which a vtable was emitted.

The concrete type is expressed as a DW_AT_containing_type on the
vtable's type.  This is a small extension to DWARF.

This patch adds a new entry to quick_symbol_functions to return the
symtab that holds a data address.  Previously there was no way in gdb to
look up a full (only minimal) non-text symbol by address.  The psymbol
implementation of this method works by lazily filling in a map that is
added to the objfile.  This avoids slowing down psymbol reading for a
feature that is likely to not be used too frequently.

I did not update .gdb_index.  My thinking here is that the DWARF 5
indices will obsolete .gdb_index soon-ish, meaning that adding a new
feature to them is probably wasted work.  If necessary I can update the
DWARF 5 index code when it lands in gdb.

Regression tested on x86-64 Fedora 25.

2017-11-17  Tom Tromey  <tom@tromey.com>

	* symtab.h (struct symbol) <is_rust_vtable>: New member.
	(struct rust_vtable_symbol): New.
	(find_symbol_at_address): Declare.
	* symtab.c (find_symbol_at_address): New function.
	* symfile.h (struct quick_symbol_functions)
	<find_compunit_symtab_by_address>: New member.
	* symfile-debug.c (debug_qf_find_compunit_symtab_by_address): New
	function.
	(debug_sym_quick_functions): Link to
	debug_qf_find_compunit_symtab_by_address.
	* rust-lang.c (rust_get_trait_object_pointer): New function.
	(rust_evaluate_subexp) <case UNOP_IND>: New case.  Call
	rust_get_trait_object_pointer.
	* psymtab.c (psym_relocate): Clear psymbol_map.
	(psym_fill_psymbol_map, psym_find_compunit_symtab_by_address): New
	functions.
	(psym_functions): Link to psym_find_compunit_symtab_by_address.
	* objfiles.h (struct objfile) <psymbol_map>: New member.
	* dwarf2read.c (dwarf2_gdb_index_functions): Update.
	(process_die) <DW_TAG_variable>: New case.  Call read_variable.
	(rust_containing_type, read_variable): New functions.

2017-11-17  Tom Tromey  <tom@tromey.com>

	* gdb.rust/traits.rs: New file.
	* gdb.rust/traits.exp: New file.
2017-11-17 14:34:14 -07:00
Simon Marchi 7468702dcb Remove DEF_VEC_I (int)
Now that all its usages are removed, we can get rid of DEF_VEC_I (int).

gdb/ChangeLog:

	* common/gdb_vecs.h (DEF_VEC_I (int)): Remove.
2017-11-17 13:03:34 -05:00
Simon Marchi f27866ba9c Make process_info::syscalls_to_catch an std::vector
This patch makes the syscalls_to_catch field of process_info an
std::vector<int>.  The process_info structure must now be
newed/deleted.

In handle_extended_wait, the code that handles exec events destroys the
existing process_info and creates a new one.  It moves the content of
syscalls_to_catch from the old to the new vector.  I used std::move for
that (through an intermediary variable), which should have the same
behavior as the old code.

gdb/gdbserver/ChangeLog:

	* inferiors.h (struct process_info): Add constructor, initialize
	fields..
	<syscalls_to_catch>: Change type to std::vector<int>.
	* inferiors.c (add_process): Allocate process_info with new.
	(remove_process): Free process_info with delete.
	* linux-low.c (handle_extended_wait): Adjust.
	(gdb_catching_syscalls_p, gdb_catch_this_syscall_p): Adjust.
	* server.c (handle_general_set): Adjust.
2017-11-17 13:03:34 -05:00
Simon Marchi 37269bc92c Make open_fds an std::vector
Simple replacement of VEC with std::vector.

gdb/ChangeLog:

	* common/filestuff.c: Include <algorithm>.
	(open_fds): Change type to std::vector<int>.
	(do_mark_open_fd): Adjust.
	(unmark_fd_no_cloexec): Adjust.
	(do_close): Adjust.
2017-11-17 13:03:34 -05:00
Simon Marchi 5c63242595 Make output_thread_groups take an std::vector<int>
A simple replacement of VEC with std::vector.

gdb/ChangeLog:

	* breakpoint.c (output_thread_groups): Take an std::vector.
	(print_one_breakpoint_location): Adjust.
2017-11-17 13:03:34 -05:00
Joel Brobecker ced9779b4c (Ada) fix handling of minimal symbols (UNOP_CAST and UNOP_ADDR)
Consider a program which provides a symbol without debugging
information. For instance, compiling the following code without -g:

    Some_Minimal_Symbol : Integer := 1234;
    pragma Export (C, Some_Minimal_Symbol, "some_minsym");

Trying to print this variable with GDB now causes an error, which
is now expected:

    (gdb) p some_minsym
    'some_minsym' has unknown type; cast it to its declared type

However, trying to cast this symbol, or to take its address
does not work:

    (gdb) p integer(some_minsym)
    'some_minsym' has unknown type; cast it to its declared type
    (gdb) p &some_minsym
    'some_minsym' has unknown type; cast it to its declared type

Another manisfestation of this issue can be seen when trying to
insert an Ada exception catchpoint for a specific standard exception
(this only occurs if the Ada runtime is built without debugging
information, which is the default).  For instance:

    $ (gdb) catch exception constraint_error
    warning: failed to reevaluate internal exception condition for catchpoint 0: 'constraint_error' has unknown type; cast it to its declared type

This is because, internally, the cachtpoint uses a condition referencing
a minimal symbol, more precisely:

   long_integer (e) = long_integer (&constraint_error)

This patch fixes all issues listed above:

  1. resolve_subexp: Special-case the handling of OP_VAR_MSYM_VALUE
     expression elements, where there are no ambiguities to be resolved
     in that situation;

  2. ada_evaluate_subexp: Enhance the handling of the UNOP_CAST
     handling so as to process the case where the target of
     the cast is a minimal symbol (as well as a symbol with debugging
     information). This mimics what's done in C.

gdb/ChangeLog:

        * ada-lang.c (resolve_subexp): Add handling of OP_VAR_MSYM_VALUE.
        (ada_evaluate_subexp_for_cast): New function.
        (ada_evaluate_subexp) <UNOP_CAST>: Replace code by call to
        ada_evaluate_subexp_for_cast.
        (ada_evaluate_subexp) <nosideret>: Replace code by call to
        eval_skip_value.
        * eval.c (evaluate_var_value): Make non-static.
        (evaluate_var_msym_value, eval_skip_value): Likewise.
        * value.h (evaluate_var_value, evaluate_var_msym_value)
        (eval_skip_value): Declare.

gdb/testsuite/ChangeLog:

        * gdb.ada/minsyms: New testcase.

Tested on x86_64-linux. No regression. Fixes the following failures:

    catch_ex.exp: continuing to Program_Error exception
    catch_ex.exp: continuing to failed assertion
    catch_ex.exp: continuing to unhandled exception
    catch_ex.exp: continuing to program completion
    complete.exp: p <Exported_Capitalized>
    complete.exp: p Exported_Capitalized
    complete.exp: p exported_capitalized
    mi_catch_ex.exp: catch Program_Error (unexpected output)
    mi_catch_ex.exp: continue to exception catchpoint hit (unknown output after running)
    mi_catch_ex.exp: continue to assert failure catchpoint hit (unknown output after running)
    mi_catch_ex.exp: continue to unhandled exception catchpoint hit (unknown output after running)
    mi_ex_cond.exp: catch C_E if i = 2 (unexpected output)
2017-11-17 12:45:43 -05:00
Joel Brobecker b7e2285082 ada-lang.c::ada_value_cast: remove unused parameter noside
gdb/ChangeLog:

        * ada-lang.c (ada_value_cast): Remove parameter "noside".
        Update all callers.
2017-11-16 19:26:20 -05:00
Pedro Alves a0922d80df Test breakpoint commands w/ "continue" + Ctrl-C
This adds the testcase that exposed the multiple problems with Ctrl-C
handling fixed by the previous patches, when run against both native
and gdbserver GNU/Linux.

gdb/ChangeLog:
2017-11-16  Pedro Alves  <palves@redhat.com>

	* gdb.base/bp-cmds-continue-ctrl-c.c: New file.
	* gdb.base/bp-cmds-continue-ctrl-c.exp: New file.
2017-11-16 18:44:44 +00:00
Pedro Alves 9ccabccd15 Python unwinder sniffer: PyExc_KeyboardInterrupt -> Quit
If you happen to press Ctrl-C while GDB is running the Python unwinder
machinery, the Ctrl-C is swallowed by the Python unwinder machinery.

For example, with:

 break foo
 commands
 > c
 > end

and

  while (1)
    foo ();

and then let the inferior hit "foo" repeatedly, sometimes Ctrl-C
results in:

~~~
  23        usleep (100);

  Breakpoint 2, foo () at gdb.base/bp-cmds-continue-ctrl-c.c:23
  23        usleep (100);
  ^C
  Breakpoint 2, Python Exception <class 'KeyboardInterrupt'> <class 'KeyboardInterrupt'>:
  foo () at gdb.base/bp-cmds-continue-ctrl-c.c:23
  23        usleep (100);

  Breakpoint 2, foo () at gdb.base/bp-cmds-continue-ctrl-c.c:23
  23        usleep (100);

  Breakpoint 2, foo () at gdb.base/bp-cmds-continue-ctrl-c.c:23
  23        usleep (100);
~~~

Notice the Python exception above.  The interesting thing here is that
GDB continues as if nothing happened, doesn't really stop and give
back control to the user.  Instead, the Ctrl-C aborted the Python
unwinder sniffer and GDB moved on to just use another unwinder.

Fix this by translating a PyExc_KeyboardInterrupt back into a Quit
exception once back in GDB.

This was exposed by the new gdb.base/bp-cmds-continue-ctrl-c.exp
testcase added later in the series.

gdb/ChangeLog:
2017-11-16  Pedro Alves  <palves@redhat.com>

	* python/py-unwind.c (pyuw_sniffer): Translate
	PyExc_KeyboardInterrupt to a GDB Quit exception.
2017-11-16 18:44:44 +00:00
Pedro Alves d930703d68 Don't ever Quit out of resume
If you have a breakpoint command that re-resumes the target, like:

  break foo
  commands
  > c
  > end

and then let the inferior run, hitting the breakpoint, and then press
Ctrl-C at just the right time, between GDB processing the stop at
"foo", and re-resuming the target, you'll hit the QUIT call in
infrun.c:resume.

With this hack, we can reproduce the bad case consistently:

  --- a/gdb/inf-loop.c
  +++ b/gdb/inf-loop.c
  @@ -31,6 +31,8 @@
   #include "top.h"
   #include "observer.h"

  +bool continue_hack;
  +
   /* General function to handle events in the inferior.  */

   void
  @@ -64,6 +66,8 @@ inferior_event_handler (enum inferior_event_type event_type,
	  {
	    check_frame_language_change ();

  +         continue_hack = true;
  +
	    /* Don't propagate breakpoint commands errors.  Either we're
	       stopping or some command resumes the inferior.  The user will
	       be informed.  */
  diff --git a/gdb/infrun.c b/gdb/infrun.c
  index d425664..c74b14c 100644
  --- a/gdb/infrun.c
  +++ b/gdb/infrun.c
  @@ -2403,6 +2403,10 @@ resume (enum gdb_signal sig)
     gdb_assert (!tp->stop_requested);
     gdb_assert (!thread_is_in_step_over_chain (tp));

  +  extern bool continue_hack;
  +
  +  if (continue_hack)
  +    set_quit_flag ();
     QUIT;

The GDB backtrace looks like this:

  (top-gdb) bt
  ...
  #3  0x0000000000612e8b in throw_quit(char const*, ...) (fmt=0xaf84a1 "Quit") at src/gdb/common/common-exceptions.c:408
  #4  0x00000000007fc104 in quit() () at src/gdb/utils.c:748
  #5  0x00000000006a79d2 in default_quit_handler() () at src/gdb/event-top.c:954
  #6  0x00000000007fc134 in maybe_quit() () at src/gdb/utils.c:762
  #7  0x00000000006f66a3 in resume(gdb_signal) (sig=GDB_SIGNAL_0) at src/gdb/infrun.c:2406
  #8  0x0000000000700c3d in keep_going_pass_signal(execution_control_state*) (ecs=0x7ffcf3744e60) at src/gdb/infrun.c:7793
  #9  0x00000000006f5fcd in start_step_over() () at src/gdb/infrun.c:2145
  #10 0x00000000006f7b1f in proceed(unsigned long, gdb_signal) (addr=18446744073709551615, siggnal=GDB_SIGNAL_DEFAULT)
      at src/gdb/infrun.c:3135
  #11 0x00000000006ebdd4 in continue_1(int) (all_threads=0) at src/gdb/infcmd.c:842
  #12 0x00000000006ec097 in continue_command(char*, int) (args=0x0, from_tty=0) at src/gdb/infcmd.c:938
  #13 0x00000000004b5140 in do_cfunc(cmd_list_element*, char*, int) (c=0x2d18570, args=0x0, from_tty=0)
      at src/gdb/cli/cli-decode.c:106
  #14 0x00000000004b8219 in cmd_func(cmd_list_element*, char*, int) (cmd=0x2d18570, args=0x0, from_tty=0)
      at src/gdb/cli/cli-decode.c:1952
  #15 0x00000000007f1532 in execute_command(char*, int) (p=0x7ffcf37452b1 "", from_tty=0) at src/gdb/top.c:608
  #16 0x00000000004bd127 in execute_control_command(command_line*) (cmd=0x3a88ef0) at src/gdb/cli/cli-script.c:485
  #17 0x00000000005cae0c in bpstat_do_actions_1(bpstat*) (bsp=0x37edcf0) at src/gdb/breakpoint.c:4513
  #18 0x00000000005caf67 in bpstat_do_actions() () at src/gdb/breakpoint.c:4563
  #19 0x00000000006e8798 in inferior_event_handler(inferior_event_type, void*) (event_type=INF_EXEC_COMPLETE, client_data=0x0)
      at src/gdb/inf-loop.c:72
  #20 0x00000000006f9447 in fetch_inferior_event(void*) (client_data=0x0) at src/gdb/infrun.c:3970
  #21 0x00000000006e870e in inferior_event_handler(inferior_event_type, void*) (event_type=INF_REG_EVENT, client_data=0x0)
      at src/gdb/inf-loop.c:43
  #22 0x0000000000494d58 in remote_async_serial_handler(serial*, void*) (scb=0x3585ca0, context=0x2cd1b80)
      at src/gdb/remote.c:13820
  #23 0x000000000044d682 in run_async_handler_and_reschedule(serial*) (scb=0x3585ca0) at src/gdb/ser-base.c:137
  #24 0x000000000044d767 in fd_event(int, void*) (error=0, context=0x3585ca0) at src/gdb/ser-base.c:188
  #25 0x00000000006a5686 in handle_file_event(file_handler*, int) (file_ptr=0x45997d0, ready_mask=1)
      at src/gdb/event-loop.c:733
  #26 0x00000000006a5c29 in gdb_wait_for_event(int) (block=1) at src/gdb/event-loop.c:859
  #27 0x00000000006a4aa6 in gdb_do_one_event() () at src/gdb/event-loop.c:347
  #28 0x00000000006a4ade in start_event_loop() () at src/gdb/event-loop.c:371

and when that happens, you end up with GDB's run control in quite a
messed up state.  Something like this:

  thread_function1 (arg=0x1) at threads.c:107
  107             usleep (SLEEP);  /* Loop increment.  */
  Quit
  (gdb) c
  Continuing.
  ** nothing happens, time passes..., press ctrl-c again **
  ^CQuit
  (gdb) info threads
    Id   Target Id         Frame
    1    Thread 1462.1462 "threads" (running)
  * 2    Thread 1462.1466 "threads" (running)
    3    Thread 1462.1465 "function0" (running)
  (gdb) c
  Cannot execute this command while the selected thread is running.
  (gdb)

The first "Quit" above is thrown from within "resume", and cancels run
control while GDB is in the middle of stepping over a breakpoint.
with step_over_info_valid_p() true.  The next "c" didn't actually
resume anything, because GDB throught that the step-over was still in
progress.  It wasn't, because the thread that was supposed to be
stepping over the breakpoint wasn't actually resumed.

So at this point, we press Ctrl-C again, and this time, the default
quit handler is called directly from the event loop
(event-top.c:default_quit_handler -> quit()), because gdb was left
owning the terminal (because the previous resume was cancelled before
we reach target_resume -> target_terminal::inferior()).

Note that the exception called from within resume ends up calling
normal_stop via resume_cleanups.  That's very borked though, because
normal_stop is going to re-handle whatever was the last reported
event, possibly even re-running a hook stop...  I think that the only
sane way to safely cancel the run control state machinery is to push
an event via handle_inferior_event like all other events.

The fix here does two things, and either alone would fix the problem
at hand:

#1 - passes the terminal to the inferior earlier, so that any QUIT
     call from the point we declare the target as running goes to the
     inferior directly, protecting run control from unsafe QUIT calls.

#2 - gets rid of this QUIT call in resume and of its related unsafe
     resume_cleanups.

Aboout #2, the comment describing resume says:

  /* Resume the inferior, but allow a QUIT.  This is useful if the user
     wants to interrupt some lengthy single-stepping operation
     (for child processes, the SIGINT goes to the inferior, and so
     we get a SIGINT random_signal, but for remote debugging and perhaps
     other targets, that's not true).

but that's a really old comment that predates a lot of fixes to Ctrl-C
handling throughout both GDB core and the remote target, that made
sure that a Ctrl-C isn't ever lost.  In any case, if some target
depended on this, a much better fix would be to make the target return
a SIGINT stop out of target_wait the next time that is called.

This was exposed by the new gdb.base/bp-cmds-continue-ctrl-c.exp
testcase added later in the series.

gdb/ChangeLog:
2017-11-16  Pedro Alves  <palves@redhat.com>

	* infrun.c (resume_cleanups): Delete.
	(resume): No longer install a resume_cleanups cleanup nor call
	QUIT.
	(proceed): Pass the terminal to the inferior.
	(keep_going_pass_signal): No longer install a resume_cleanups
	cleanup.
2017-11-16 18:44:43 +00:00
Pedro Alves 38dc2859c4 Fix stdin ending up not registered after a Quit
If you press Ctrl-C while GDB is processing breakpoint commands the
TRY/CATCH in inferior_event_handler catches the Quit exception and
prints it, and then if the interpreter was running a foreground
execution command, nothing re-adds stdin back in the event loop,
meaning the debug session ends up busted, because the user can't type
anything...

This was exposed by the new gdb.base/bp-cmds-continue-ctrl-c.exp
testcase added later in the series.

gdb/ChangeLog:
2017-11-16  Pedro Alves  <palves@redhat.com>

	* inf-loop.c (inferior_event_handler): Don't swallow the exception
	if the prompt is blocked.
2017-11-16 18:44:43 +00:00
Pedro Alves 688fca4fe6 Fix swallowed "Quit" when inserting breakpoints
If GDB is inserting a breakpoint and you type Ctrl-C at the exact
"right" time, you'll hit a QUIT call in target_read, and the
breakpoint insertion is cancelled.  However, the related TRY/CATCH
code in insert_bp_location does:

 		  CATCH (e, RETURN_MASK_ALL)
 		    {
		      bp_err = e.error;
		      bp_err_message = e.message;
		    }

The problem with that is that a RETURN_QUIT exception has e.error ==
0, which means that further below, in the places that check for error
with:

      if (bp_err != GDB_NO_ERROR)

because GDB_NO_ERROR == 0, GDB continues as if the breakpoint was
inserted succesfully, and resumes the inferior.  Since the breakpoint
wasn't inserted the inferior runs free, out of our control...

Fix this by having insert_bp_location store a copy of the whole
exception instead of just a error/message parts, and then checking
"gdb_exception::reason" instead.

This was exposed by the new gdb.base/bp-cmds-continue-ctrl-c.exp
testcase added later in the series.

gdb/ChangeLog:
2017-11-16  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (insert_bp_location): Replace bp_err and
	bp_err_message locals by a gdb_exception local.
2017-11-16 18:44:42 +00:00
Pedro Alves e2c33ac745 gdb/inflow.c: Move SIGTTOU temporary ignoring to a RAII class
I expect to use this in more places (in inflow.c) in follow up
patches, but I think this is still good on its own.

gdb/ChangeLog:
2017-11-16  Pedro Alves  <palves@redhat.com>

	* inflow.c (scoped_ignore_sigttou): New class.
	(child_terminal_ours_1, new_tty): Use it.
2017-11-16 18:44:42 +00:00
Pedro Alves ea04e54ca8 Fix testing gdb.rust/modules.exp against gdbserver
Currently several tests in gdb.rust/modules.exp fail with
 --target_board=native-gdbserver:

 Running src/gdb/testsuite/gdb.rust/modules.exp ...
 FAIL: gdb.rust/modules.exp: call f3()
 FAIL: gdb.rust/modules.exp: call self::f2()
 FAIL: gdb.rust/modules.exp: call self::super::f2()
 FAIL: gdb.rust/modules.exp: call super::f2()
 FAIL: gdb.rust/modules.exp: call self::super::super::f2()
 FAIL: gdb.rust/modules.exp: call super::super::f2()
 FAIL: gdb.rust/modules.exp: call ::f2()
 FAIL: gdb.rust/modules.exp: call extern modules::mod1::f2()

This is because these tests rely on matching inferior output.
However, when testing with gdbserver, inferior output goes to a
separate terminal instead of to gdb's terminal, and so gdb_test won't
cut it, as that is only reading from gdb's pty/gdb_spawn_id:

 (gdb) call f3()
 (gdb) FAIL: gdb.rust/modules.exp: call f3()
 call self::f2()
 (gdb) FAIL: gdb.rust/modules.exp: call self::f2()

Fix this by using gdb_test_stdio instead, which handles output coming
out of gdbserver's pty.

Also, skip the tests if the target/board doesn't support inferior I/O
at all.

gdb/ChangeLog:
2017-11-16  Pedro Alves  <palves@redhat.com>

	* gdb.rust/modules.exp: Skip tests that rely on inferior I/O if
	gdb,noinferiorio is set, and use gdb_test_stdio otherwise.
2017-11-16 18:07:41 +00:00
Ulrich Weigand d723696126 Refactor endian handling in DFP routines
This patch moves endian conversion into the decimal_from_number and
decimal_to_number routines, and removes it from all their callers,
making the code simpler overall.  No functional change.

gdb/ChangeLog:
2017-11-16  Ulrich Weigand  <uweigand@de.ibm.com>

	* target-float.c (decimal_from_number): Add byte_order argument and
	call match_endianness.  Error if unknown floating-point type.
	(decimal_to_number): Add byte_order argument and call match_endianness.
	(decimal_from_longest): Update call.  Do not call match_endianness.
	(decimal_from_ulongest): Likewise.
	(decimal_binop): Likewise.
	(decimal_is_zero): Likewise.
	(decimal_compare): Likewise.
	(decimal_convert): Likewise.
2017-11-16 18:49:11 +01:00
Pedro Alves e849ea896b GDBserver: Fix ignored Ctrl-C after reconnection
This fixes the issue reported by Dmitry Antipov <dantipov@nvidia.com>
here:
  https://sourceware.org/ml/gdb/2017-10/msg00048.html

The problem is that GDBserver stops listening to Ctrl-C/interrupt
requests if you disconnect and reconnect back.

Dmitry wrote:

~~~
Currently gdbserver installs SIGIO handler just once, in
initialize_async_io() called from captured_main(), and this handler is
removed when remote_desc is closed in remote_close().  Next, when a
new instance of remote_desc is fetched from accept() and has '\003'
arrived, input_interrupt() is never called because it is not
registered as SIGIO handler.
~~~

The fix here is not remove the SIGIO handler in the first place, thus
going back to the original before-first-connection state.

(I haven't gone back to try it, but I think this was a regression
caused by commit 8b20733984 ("[GDBserver] Block and unblock SIGIO"),
which was what made remote_close remove the signal handler.)

New test included.

gdb/gdbserver/ChangeLog:
2017-11-16  Pedro Alves  <palves@redhat.com>

	* remote-utils.c (remote_close): Block SIGIO signals instead of
	uninstalling the SIGIO handler.

gdb/testsuite/ChangeLog:
2017-11-16  Pedro Alves  <palves@redhat.com>

	* gdb.server/reconnect-ctrl-c.c: New file.
	* gdb.server/reconnect-ctrl-c.exp: New file.
2017-11-16 14:58:51 +00:00
Phil Muldoon d8ae99a7b0 Add Python rbreak command.
gdb/Changelog

2017-11-16  Phil Muldoon  <pmuldoon@redhat.com>

	* python/python.c (gdbpy_rbreak): New function.
        * NEWS: Document Python rbreak feature.

testsuite/Changelog

2017-11-16  Phil Muldoon  <pmuldoon@redhat.com>

	* gdb.python/py-rbreak.exp: New file.
	* gdb.python/py-rbreak.c: New file.
	* gdb.python/py-rbreak-func2.c: New file.

doc/Changelog

2017-11-16  Phil Muldoon  <pmuldoon@redhat.com>

	* python.texi (Basic Python): Add rbreak documentation.
2017-11-16 14:14:03 +00:00
Pedro Alves 968a13f836 Fix gdb.base/starti.exp racy test
This commit fixes a couple problems with gdb.base/starti.exp, causing
spurious FAILs.

The first is a double-prompt problem:

~~~
 (gdb) PASS: gdb.base/starti.exp: hook-stop
 starti
 [....]
 gdb_expect_list pattern: /\$1 = 0/
 $1 = 0

 gdb_expect_list pattern: //
 0x00007ffff7ddcc80 in _start () from /lib64/ld-linux-x86-64.so.2

 (gdb)                                         # EXPECTED PROMPT
 (gdb) PASS: gdb.base/starti.exp: starti       # ANOTHER PROMPT!
 break main
~~~

This happens because the test uses gdb_test_sequence with no command,
like this:

 gdb_test_sequence "" "starti" {
     "Program stopped."
     "\\$1 = 0"
 }

but gdb_test_sequence doesn't have a check for empty command like
gdb_test_multiple does, and so sends "\n" to GDB:

 proc gdb_test_sequence { command test_name expected_output_list } {
     global gdb_prompt
     if { $test_name == "" } {
	 set test_name $command
     }
     lappend expected_output_list ""; # implicit ".*" before gdb prompt
     send_gdb "$command\n"
     return [gdb_expect_list $test_name "$gdb_prompt $" $expected_output_list]
 }

"starti" is a no-repeat command, so pressing <ret> just makes another
prompt appear, confusing the following gdb_test/gdb_test_multiple/etc.

Even with that fixed, the testcase is still racy though.

The second problem is that sometimes the "continue" test times out
here:

~~~
 continue
 Continuing.
 $2 = 1


 gdb_expect_list pattern: /.*Breakpoint .*main \(\) at .*starti.c.*/
 Breakpoint 1, main () at /home/pedro/src/gdb/testsuite/gdb.base/starti.c:29
 29	  return 0;
 (gdb) gdb_expect_list pattern: //
 * hung here *
~~~

The problem is that the too-greedy ".*" trailing match in
gdb_expect_list's pattern ends up consuming GDB's prompt too soon.
Fix that by removing the unnecessary trailing ".*".  While at it,
remove all ".*"s to be stricter.

Tested on x86_64 GNU/Linux.

gdb/testsuite/ChangeLog:
2017-11-16  Pedro Alves  <palves@redhat.com>

	* gdb.base/starti.exp ("continue" test): Remove ".*"s from
	pattern.
	* lib/gdb.exp (gdb_test_sequence): Don't send empty command to
	GDB.
2017-11-16 11:57:01 +00:00
Yao Qi c632b6456b Remove non-linux tic6x target descriptions
They are not used by GDB nor by GDBserver.  This patch removes them.

gdb:

2017-11-16  Yao Qi  <yao.qi@linaro.org>

	* features/tic6x-c62x.xml: Remove.
	* features/tic6x-c64x.xml: Remove.
	* features/tic6x-c64xp.xml: Remove.
2017-11-16 10:17:25 +00:00
Alan Hayward 1d0aa65c24 Allow osabi to be optional in target descriptions
gdbserver/
	* tdesc.c (tdesc_get_features_xml): Allow null osabi.
2017-11-16 10:09:17 +00:00
Yao Qi 3491a34c4f Fix tic6x-uclinux GDBserver build failure
I can't find a c6x-uclinux c++ compiler, so I use my host g++ to build
tic6x-uclinux GDBserver, and find the following build failures.  They are
not target specific, so I believe they are real errors.  This patch fixes
them.

../binutils-gdb/gdb/gdbserver/linux-tic6x-low.c:313:34: error: invalid
conversion from 'void*' to 'tic6x_register*' [-fpermissive]
   union tic6x_register *regset = buf;
                                  ^
../binutils-gdb/gdb/gdbserver/linux-tic6x-low.c: In function 'void tic6x_store_gregset(regcache*, const void*)':
../binutils-gdb/gdb/gdbserver/linux-tic6x-low.c:324:40: error: invalid
conversion from 'const void*' to 'const tic6x_register*' [-fpermissive]
   const union tic6x_register *regset = buf;
                                        ^

../binutils-gdb/gdb/gdbserver/linux-tic6x-low.c: At global scope:
../binutils-gdb/gdb/gdbserver/linux-tic6x-low.c:359:28: error: redefinition of 'usrregs_info tic6x_usrregs_info'
 static struct usrregs_info tic6x_usrregs_info =
                            ^
../binutils-gdb/gdb/gdbserver/linux-tic6x-low.c:186:28: note: 'usrregs_info tic6x_usrregs_info' previously declared here
 static struct usrregs_info tic6x_usrregs_info;
                            ^

gdb/gdbserver:

2017-11-16  Yao Qi  <yao.qi@linaro.org>

	* linux-tic6x-low.c (tic6x_fill_gregset): Cast buf.
	(tic6x_store_gregset): Likewise.
	(tic6x_usrregs_info): Move it up.
2017-11-16 10:05:27 +00:00
John Baldwin a014b87a9a Include <array> to declare std::array<>.
gdb/ChangeLog:

	* symtab.h: Include <array>.
2017-11-15 11:36:42 -08:00
John Baldwin 9476501135 Constify the 'arg' passed to commands in bsd-kvm.c.
gdb/ChangeLog:

	* bsd-kvm.c (bsd_kvm_cmd): Constify 'arg'.
	(bsd_kvm_proc_cmd): Likewise.
2017-11-15 11:35:15 -08:00
Simon Marchi 625ad4406d tui-win: Replace VEC with std::vector
This patch replaces an instance of VEC (const_char_ptr) with
std::vector<const char *>.  Tested by running gdb.tui/completion.exp,
which exercises this function.

gdb/ChangeLog:

	* tui/tui-win.c (window_name_completer): Replace VEC with
	std::vector.
2017-11-15 11:08:53 -05:00
Simon Marchi 71774bc994 Fix gdb.tui/completion.exp test
When I run it locally, the test gdb.tui/completion.exp test fails
because of a timeout:

Running /home/emaisin/src/binutils-gdb/gdb/testsuite/gdb.tui/completion.exp ...
FAIL: gdb.tui/completion.exp: completion of layout names: tab completion (timeout)

The problem seems to be this regex, which confirms that after doing
layout<TAB>, "layout" is printed again after the gdb prompt:

  -re "^$input_line$"

The problem is that there's a trailing space in the output after
"layout".  Since the regex has an anchored end (the $), it doesn't
match.  Adding a space fixes the test.

gdb/testsuite/ChangeLog:

	* gdb.tui/completionn.exp (test_tab_completion): Add space in
	regex.
2017-11-15 11:07:02 -05:00
Andrew Cagney c0c11fa91d Remove no-longer applicable maintainer entries
2017-11-15  Andrew Cagney  <cagney@gnu.org>

       * MAINTAINERS: Remove no-longer applicable entries.
2017-11-15 10:26:59 -05:00
Andrew Cagney 34a7ebaff9 Move self to Past Maintainers.
2017-11-15  Andrew Cagney  <cagney@gnu.org>

      * MAINTAINERS: Move self to Past Maintainers.
2017-11-15 10:13:41 -05:00
Yao Qi 5334ef3907 Remove features/nios2-linux.c
tdesc_nios2_linux is not used at all.  Remove features/nios2-linux.c,
and don't generate it anymore.

gdb:

2017-11-15  Yao Qi  <yao.qi@linaro.org>

	* features/Makefile (XMLTOC): Remove nios2-linux.xml.
	* features/nios2-linux.c: Remove.
	* nios2-linux-tdep.c (_initialize_nios2_linux_tdep): Don't call
	initialize_tdesc_nios2_linux.
2017-11-15 12:03:03 +00:00
Alan Hayward a602f924c8 Better make rule for arch/ files built for IPA
gdbserver/
	* Makefile.in: Update arch rules.
	* configure.srv: Explicitly mark arch/ files.
2017-11-15 09:59:12 +00:00
Yao Qi a714b0d692 Fix M68HC11_NUM_REGS
M68HC11_LAST_HARD_REG is 8, but m68hc11 register number is started from 0,
so there are 9 raw registers, but M68HC11_NUM_REGS is 8 by mistake.

My following unit test can find this issue (GDB is built with asan)

=================================================================
==15555==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000113150 at pc 0x51393f bp 0x7fffcec36f60 sp 0x7fffcec36f58
WRITE of size 2 at 0x602000113150 thread T0
    #0 0x51393e in m68hc11_pseudo_register_read gdb/m68hc11-tdep.c:320
    #1 0xc4b620 in gdbarch_pseudo_register_read(gdbarch*, regcache*, int, unsigned char*) gdb/gdbarch.c:1974
    #2 0xddad88 in regcache::cooked_read(int, unsigned char*) gdb/regcache.c:710
    #3 0xddff2b in cooked_read_test gdb/regcache.c:1850
    #4 0xdf8cfb in selftests::gdbarch_selftest::operator()() const gdb/selftest-arch.c:73

gdb:

2017-11-15  Yao Qi  <yao.qi@linaro.org>

	* m68hc11-tdep.c (M68HC11_NUM_REGS): Change it to
	M68HC11_LAST_HARD_REG + 1.
2017-11-15 09:36:51 +00:00
Paul Carroll 92ffd47519 Fix 'xfered>0' assertion in target.c for remote connection
We have a customer who is using a Corelis gdb server to connect to gdb.
Occasionally, the gdb server will send a 0-byte block of memory for a
read.  When this happens, gdb gives an assertion from target.c:

internal-error: target_xfer_partial: Assertion `*xfered_len > 0' failed.

This problem is almost identical to that fixed in
https://sourceware.org/ml/gdb-patches/2014-02/msg00636.html

In this case, remote.c needs to be modified to return TARGET_XFER_EOF
instead of TARGET_XFER_OK or TARGET_XFER_UNAVAILABLE when 0 bytes are
transferred.

gdb/ChangeLog:

	PR gdb/22388
	* remote.c (remote_write_bytes_aux, remote_read_bytes_1,
	remote_read_bytes, remote_write_qxfer, remote_xfer_partial):
	Return TARGET_XFER_EOF if size of returned data is 0.
2017-11-14 17:39:24 -05:00
Simon Marchi 0743190874 Fix mem region parsing regression and add test
In my patch

  Get rid of VEC (mem_region)
  a664f67e50

I introduced a regression, where the length of the memory region is
assigned to the "hi" field.  It should obviously be computed as "start +
length".  To my defense, no test had caught this :).  As a penance, I
wrote one.

gdb/ChangeLog:

	* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
	memory-map-selftests.c.
	(SUBDIR_UNITTESTS_OBS): Add memory-map-selftests.o.
	* memory-map.c (memory_map_start_memory): Fix computation of hi
	address.
	* unittests/memory-map-selftests.c: New file.
2017-11-14 16:42:08 -05:00
Simon Marchi ddbb44cf36 gdb.opt/inline-locals.exp: Remove trailing parentheses in test names
Test names should not end with parentheses, since the buildbot strips
those.

gdb/testsuite/ChangeLog:

	* gdb.opt/inline-locals.exp: Remove trailing parentheses from
	test names.
2017-11-13 22:06:02 -05:00
Andreas Schwab 5616b6c32f Enable hardware single step for m68k in GDBServer
* linux-m68k-low.c (m68k_supports_hardware_single_step): New
function.
(struct linux_target_ops) <supports_hardware_single_step>: Initialize.
2017-11-13 16:03:36 +01:00
Pedro Alves 584a564f36 Fix racy output matching in gdb.tui/tui-completion.exp
'make check-read1 TESTS="gdb.tui/tui-completion.exp"' exposes this test race:

  (gdb) PASS: gdb.tui/completion.exp: set max-completions unlimited
  layout ^G
  asm    next   prev   regs   split  src
  (gdb) FAIL: gdb.tui/completion.exp: completion of layout names: tab completion
  Quit
  (gdb) PASS: gdb.tui/completion.exp: completion of layout names: quit command input
  focus ^G
  cmd   next  prev  src
  (gdb) FAIL: gdb.tui/completion.exp: completion of focus command: tab completion
  Quit

This is caused by expecting "$gdb_prompt layout $".
gdb_test_multiple's internal prompt regexp can match first if expect's
internal buffer is filled with partial output.  Fix that by splitting
the gdb_test_multiple in question in two.  Since the same problem/code
appears twice in the file, factor out a common procedure.

gdb/testsuite/ChangeLog:
2017-11-09  Pedro Alves  <palves@redhat.com>

	* gdb.tui/tui-completion.exp (test_tab_completion): New procedure,
	factored out from ...
	(top level): ... here, and adjusted to avoid expecting beyond the
	prompt in a single gdb_test_multiple.
2017-11-09 22:47:16 +00:00
Pedro Alves 5ed7a928ac Fix racy output matching in gdb.base/multi-attach.exp, gdb.server/ext-{attach, restart, ext-run}.exp
This commit fixes this same problem in several places:

  (gdb) PASS: gdb.multi/multi-attach.exp: backtrace 2
  kill
  Kill the program being debugged? (y or n) y
  (gdb) FAIL: gdb.multi/multi-attach.exp: kill inferior 2 (got interactive prompt)

This is just another case of the gdb_test_multiple's internal "got
interactive prompt" pattern matching because the testcase misses
matching enough.

gdb/testsuite/ChangeLog:
2017-11-09  Pedro Alves  <palves@redhat.com>

	* gdb.multi/multi-attach.exp ("kill" test): Match the whole query
	output.
	* gdb.server/ext-attach.exp ("kill" test): Likewise.
	* gdb.server/ext-restart.exp ("kill" test): Likewise.
	* gdb.server/ext-run.exp ("kill" test): Likewise.
	* gdb.server/ext-wrapper.exp ("kill" test): Likewise.
2017-11-09 22:46:44 +00:00
Pedro Alves a60e07381c Fix racy output matching in gdb.base/cpcompletion.exp
With:

 $ make check-read1 TESTS="gdb.cp/cpcompletion.exp"

we get (from gdb.log):

 (gdb) complete break Foo::
 break Foo::Foo()
 break Foo::Foofoo()
 break Foo::get_foo()
 break Foo::set_foo(int)
 break Foo::~Foo()
 (gdb) FAIL: gdb.cp/cpcompletion.exp: complete class methods (Foo not found)

The problem is that the
  "break ${class}::\[A-Za-z0-9_~\]+"
regexp patches partial input, like:
  break Foo::F
  break Foo::Fo
  break Foo::Foo
etc.

Fix that by expecting each whole line.

gdb/testsuite/ChangeLog:
2017-11-09  Pedro Alves  <palves@redhat.com>

	* gdb.cp/cpcompletion.exp (test_class_complete): Tighten regex to
	match till end of line.
2017-11-09 22:46:06 +00:00
Pedro Alves 2c88253fc4 Fix racy output matching in gdb.base/memattr.exp
Testing with:
 $ make check-read1 TESTS="gdb.base/memattr.exp"


Exposes a testcase bug that can result in racy fails:

  info mem
  Using user-defined memory regions.
  Num Enb Low Addr           High Addr          Attrs
  1   y   0x0000000000601060 0x0000000000601160 wo nocache
  2   y   0x0000000000601180 0x0000000000601280 ro nocache
  4   y   0x0000000000601280 0x0000000000601380 rw nocache
  3   y   0x0000000000601380 0x0000000000601480 rw nocache
  5   y   0x0000000000601480 0x0000000000601580 rw nocache
  (gdb) FAIL: gdb.base/memattr.exp: info mem (1)

The problem is that:

  "Attrs\[^\n\r]*.."

matches:

  "Attrs \r"

when the output buffer is filled with partial output like this:

  "info mem\r\nUsing user-defined memory regions.\r\nNum Enb Low Addr           High Addr          Attrs \r"

gdb/testsuite/ChangeLog:
2017-11-09  Pedro Alves  <palves@redhat.com>

	* gdb.base/memattr.exp: Tighten regexes to match the end line.
2017-11-09 22:45:39 +00:00
Pedro Alves c7a3851716 Fix racy output matching in gdb.base/completion.exp
Testing with:
 $ make check-read1 TESTS="gdb.base/completion.exp"

Exposes a testcase bug that can result in racy fails:

  FAIL: gdb.base/completion.exp: command-name completion limiting using tab character
  ERROR: Undefined command "".
  FAIL: gdb.base/completion.exp: symbol-name completion limiting using tab character
  FAIL: gdb.base/completion.exp: symbol-name completion limiting using complete command

testsuite/gdb.log shows:

  (gdb) PASS: gdb.base/completion.exp: set max-completions 5
  p^G
  passcount     path          print         print-object  printf
  *** List may be truncated, max-completions reached. ***
  (gdb) FAIL: gdb.base/completion.exp: command-name completion limiting using tab character
  pcomplete p
  Undefined command: "pcomplete".  Try "help".
  (gdb) ERROR: Undefined command "".

The problem is that the expect buffer can get filled with partial
output that ends in the gdb prompt, and so the default FAIL inside
gdb_test_multiple matches.

Fix that by splitting the gdb_test_multiple in two stages.  Since that
is done in more than one place in the testcase, move the otherwise
duplicate code to helper procedures.

gdb/testsuite/ChangeLog:
2017-11-09  Pedro Alves  <palves@redhat.com>

	* gdb.base/completion.exp (ignore_and_resync, test_tab_complete):
	New procedures, factored out from ...
	(top level): ... here, and adjusted to avoid expecting beyond the
	prompt in one go.
2017-11-09 22:45:06 +00:00
Pedro Alves f29f4b6ba1 Fix racy output matching in gdb.asm/asm-source.exp
Testing with:
 $ make check-read1 TESTS="gdb.asm/asm-source.exp"

Exposes a testcase bug that can result in racy fails:

 (gdb) PASS: gdb.asm/asm-source.exp: next over foo3
 return
 Make selected stack frame return now? (y or n) y
 n
 #0  main () at /home/pedro/gdb/mygit/src/gdb/testsuite/gdb.asm/asmsrc1.s:53
 53              gdbasm_exit0
 (gdb) FAIL: gdb.asm/asm-source.exp: return from foo2 (got interactive prompt)
 n

The problem is that the "return now\?.*" regex can match partial
output like this:

 "Make selected stack frame return no"

and then we send the 'y' too early, and then the next time around we
hit gdb_test_multiple's internal "got interactive prompt" regex.

Also, note we match "return no" instead of "return now" because the
regex is missing one quote level.

gdb/testsuite/ChangeLog:
2017-11-09  Pedro Alves  <palves@redhat.com>

	* gdb.asm/asm-source.exp ("kill" test): Match the whole query
	output.  Fix '?' match.
2017-11-09 22:44:08 +00:00
Joel Brobecker 31432a672f fix typos in ada-lang.c comment
gdb/ChangeLog:

        * ada-lang.c: Fix some typos in the general command documenting
        how Ada expressions are being evaluated and how their result
        is printed.
2017-11-09 12:02:27 -08:00
Tom Tromey e793c052f9 Simplify the psymbol hash function
This patch simplifies the psymbol_hash function, by changing it not to
examine the contents of the symbol's name.  This change just mirrors
what psymbol_compare already does -- it is checking for name equality,
which is ok because symbol names are interned in symbol_set_names.

This change speeds up psymbol reading.  "gdb -nx -batch gdb"
previously took ~1.8 seconds on my machine, and with this patch it now
takes ~1.7 seconds.

gdb/ChangeLog
2017-11-09  Tom Tromey  <tom@tromey.com>

	* psymtab.c (psymbol_hash): Do not hash string contents.
	(psymbol_compare): Add comment.
2017-11-09 08:31:40 -07:00
Tom Tromey 7e8835c5f4 Speed up dict_hash
This speeds up dict_hash a bit, by moving the "TKB" check into the
switch in the loop.

For "gdb -nx -readnow -batch gdb", this improves the time from ~9.8s
before to ~8.5s afterward.

gdb/ChangeLog
2017-11-09  Tom Tromey  <tom@tromey.com>

	* dictionary.c (dict_hash): Move "TKB" check into the "switch".
2017-11-09 08:31:40 -07:00
Joel Brobecker 286acbb5c2 local variable watchpoint not deleted after leaving scope
When debugging an Ada program, and inserting a watchpoint tracking
a local variable, the watchpoint doesn't get automatically deleted
upon leaving that variable's scope. This watchpoint then starts
creating problems later on, when trying to resume the program's
execution from a location outside of the watchpoint's scope:

    (gdb) c
    Continuing.

    Breakpoint 2, foo_p708_025 () at foo_p708_025.adb:7
    7	   Do_Nothing (Val);
    (gdb) n
    No frame is currently executing in block pck.get_val.
    Command aborted.
    (gdb) c
    Continuing.
    No frame is currently executing in block pck.get_val.
    Command aborted.

The expected output is the following:

  - The program's execution after the first continue should stop
    as soon as we reach the end of the watchpoint's scope, and
    the debugger should be deleting it.

  - Then we can continue until reaching breakpoint 2 above;

  - After which we should be able to do next/continue as usual.

The reason the watchpoint is not automatically deleted at scope exit
is because the watchpoint is not marked as being scope-specific
(b->exp_valid_block is equal NULL), and this is because the
symbol lookup for our local variable failed to set the innermost_block
global variable during the lookup.

More precisely, if we look at watch_command_1, we do the following:

  innermost_block = NULL;
  [...]
  exp = parse_exp_1 (&arg, 0, 0, 0);
  [...]
  exp_valid_block = innermost_block;

Currently, innermost_block stays NULL after the call to parse_exp_1.

Digging further, this innermost_block is typically set during symbol
lookup when the symbol is considered to have a frame-relative address.
For instance, in c-exp.y, we see some code like the following:

   if (symbol_read_needs_frame (sym.symbol))
     {
       if (innermost_block == 0
           || contained_in (sym.block,
                            innermost_block))
         innermost_block = sym.block;
     }

We actually have the exact same mechanism in ada-exp.y, except
that it vhas accidently been turned off. See write_var_from_sym,
where we start with:

   if (orig_left_context == NULL && symbol_read_needs_frame (sym))
     {
       if (innermost_block == 0
           || contained_in (block, innermost_block))
         innermost_block = block;
     }

In this case, orig_left_context is a parameter, and looking at
the point of call in write_var_or_type, we see:

          if (nsyms == 1)
            {
              write_var_from_sym (par_state, block, syms[0].block,
                                  syms[0].symbol);

In the call above, the paramater we are interested in is "block",
which is a parameter for write_var_or_type as well, except we
explicitly override its value at the beginning when found to be NULL:

  if (block == NULL)
    block = expression_context_block;

So the block we pass to write_var_from_sym is not NULL, and
we therefore don't set innermost_block, which leads to the watchpoint
no longer being marked as scope-specific.

The handling of orig_left_context in write_var_from_sym was there
to handle the case where a user writes an expression where the symbol
is qualified with a scope (Eg: "function::variable"). But it appears
that handling this is specifically here is no longer necessary,
so this patch simply removes that parameter and the associated check,
and then updates all the points of calls.

Interestingly, this also affects GDB/MI, and in particular varobjs,
because local variables are now properly reported as having a block,
which causes the associated varob to have a "thread-id" field.
This patch also adjusts a couple of Ada/gdb-mi tests.

gdb/ChangeLog:

        * ada-exp.y (write_var_from_sym): Remove parameter
        "orig_left_context".  Update all callers.

gdb/testsuite/ChangeLog:

        * gdb.ada/scoped_watch: New testcase.
        * gdb.ada/watch_arg.exp: Adjust expected behavior to the behavior
        which is actually correct.
        * gdb.ada/mi_interface.exp: Add missing thread-id in expected varobj.
        * gdb.ada/mi_var_array.exp: Add missing thread-id in expected varobj.
2017-11-08 19:52:28 -05:00
Simon Marchi b44ec61915 Make encode_actions_rsp use std::vector
Currently, encode_actions_rsp returns two malloc'ed arrays of malloc'ed
strings (char *) by pointer.  Change this to use
std::vector<std::string>.  This eliminates some cleanups in remote.c.

Regtested on the buildbot.

gdb/ChangeLog:

	* tracepoint.h (class collection_list) <stringify>: Return
	std::vector<std::string>.
	(encode_actions_rsp): Change parameters to
	std::vector<std::string> *.
	* tracepoint.c (collection_list::stringify): Return
	std::vector<std::string> and adjust accordingly.
	(encode_actions_rsp): Changee parameters to
	std::vector<std::string> and adjust accordingly.
	* remote.c (free_actions_list),
	free_actions_list_cleanup_wrapper): Remove.
	(remote_download_tracepoint): Adjust to std::vector.
2017-11-08 19:42:08 -05:00
Pedro Alves 62d7ae9234 Avoid expensive complaint calls when complaints are disabled
Running perf on "gdb -nx -readnow -batch gdb", I'm seeing a lot of
time (24%.75!) spent in gettext, via complaints.  'perf report -g' shows:

 -   86.23%     0.00%  gdb      gdb                     [.] gdb_main
    - gdb_main
       - 85.60% catch_command_errors
            symbol_file_add_main_adapter
            symbol_file_add_main
            symbol_file_add_main_1
            symbol_file_add
          - symbol_file_add_with_addrs
             - 84.31% dw2_expand_all_symtabs
                - dw2_instantiate_symtab
                   - 83.79% dw2_do_instantiate_symtab
                      - 70.85% process_die
                         - 41.11% dwarf_decode_macros
                            - 41.09% dwarf_decode_macro_bytes
                               - 39.74% dwarf_decode_macro_bytes
   >>>>>>>>>>>>>>>>>>>>>>>        + 24.75% __dcigettext              <<<<<<<
                                  + 7.37% macro_define_object_internal
                                  + 3.16% macro_define_function
                                    0.77% splay_tree_insert
                                  + 0.76% savestring
                                  + 0.58% free
                                    0.53% read_indirect_string_at_offset_from
                                 0.54% macro_define_object_internal
                                 0.51% macro_start_file
                         + 25.57% process_die
                         + 4.07% dwarf_decode_lines
                      + 4.28% compute_delayed_physnames
                      + 3.85% end_symtab_from_static_block
                      + 3.38% load_cu
                      + 1.29% end_symtab_get_static_block
                   + 0.52% do_my_cleanups
             + 1.29% read_symbols
       + 0.54% gdb_init

The problem is that we're always computing the arguments to pass to
complaint, including passing the format strings through gettext, even
when complaints are disabled.  As seen above, gettext can be quite
expensive.

Fix this by wrapping complaint in a macro that skips the real
complaint call when complaints are disabled.

This improves "gdb -nx -readnow -batch gdb" from
 ~11.0s => ~7.8s with -O2 -g3, and
  ~6.0s => ~5.3s with -O2 -g.
w/ gcc 5.3.1, on x86_64, for me.

gdb/ChangeLog:
2017-11-08  Pedro Alves  <palves@redhat.com>

	* complaints.c (stop_whining): Make extern.
	(complaint): Rename to ...
	(complaint_internal): ... this.
	* complaints.h (complaint): Rename to ...
	(complaint_internal): ... this.
	(complaint): Reimplement as macro around complaint_internal.

gdb/testsuite/ChangeLog:
2017-11-08  Pedro Alves  <palves@redhat.com>

	* gdb.gdb/complaints.exp (test_initial_complaints)
	(test_serial_complaints, test_short_complaints): Call
	complaint_internal instead of complaint.
2017-11-08 23:42:11 +00:00
Djordje Todorovic 280ca31f4d Add test for fetching TLS from core file
A correct PID is needed by `libthread_db' library supplied with
glibc repository revisions before commit c579f48edba8 ("Remove
cached PID/TID in clone") or versions before 2.25 release for
GDB to fetch value of TLS variable from core file.  On MIPS
platforms it was omitted and fetching value of TLS variable was not
available.

This adds a new test in order to be sure if GDB on native platforms
can successfully fetch value of TLS variable.

gdb/testsuite:

	* gdb.threads/tls-core.c: New file.
	* gdb.threads/tls-core.exp: Likewise.
2017-11-08 21:19:05 +00:00
Tom Tromey 2f4732b0e6 Remove symbolp vector
This removes the symbolp typedef from dwarf2read.c and converts the
associated VEC uses to std::vector.  This fixes a latent possible
memory leak if an exception were thrown, because there were no
cleanups installed for these VECs.

Regression tested on the buildbot.

gdb/ChangeLog
2017-11-08  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (symbolp): Remove typedef.
	(read_func_scope): Use std::vector.
	(process_structure_scope): Use std::vector.
2017-11-08 11:20:14 -07:00
Pedro Alves f9d67a2239 Make the linespec/location completer ignore data symbols
Currently "b foo[TAB]" offers data symbols as completion candidates.
This doesn't make sense, since you can't set a breakpoint on data
symbols, only on code symbols.

 (gdb) b globa[TAB]
 (gdb) b global [ENTER]
 Function "global" not defined.
 Make breakpoint pending on future shared library load? (y or [n]) n
 (gdb) info symbol global
 global in section .rodata

So this patch makes linespec completion ignore data symbols.

gdb/ChangeLog:
2017-11-08  Pedro Alves  <palves@redhat.com>

	* ada-lang.c (ada_make_symbol_completion_list): Use
	completion_skip_symbol.
	* symtab.c (symbol_is_function_or_method(minimal_symbol*)): New.
	(symbol_is_function_or_method(symbol*)): New.
	(add_symtab_completions): Add complete_symbol_mode parameter.  Use
	completion_skip_symbol.
	(default_collect_symbol_completion_matches_break_on): Use
	completion_skip_symbol.  Pass down mode.
	(collect_file_symbol_completion_matches): Pass down mode.
	* symtab.h (symbol_is_function_or_method): New declarations.
	(completion_skip_symbol): New template function.
2017-11-08 16:06:25 +00:00
Pedro Alves 56d87ef769 Use search_domain::FUNCTIONS_DOMAIN when setting breakpoints
While working on C++ support for wild matching, I noticed that
attaching to my system's Firefox (which uses .gdb_index), setting a
break at main and bailing, like:

  $ gdb --batch -q -p `pidof firefox` -ex "b main"

would get substancially slower.  It'd take around 20s when currently
it takes 3s.

The problem is that gdb would expand more symtabs than currently,
because Firefox has symbols named like "nsHtml5Atoms::main",
"nsGkAtoms::main", etc., which given wild matching, match.

However, these are not function symbols, [they're "(nsIAtom *)"], so
it seems silly that they'd cause expansion in the first place.

The .gdb_index code (dwarf2read.c:dw2_expand_marked_cus) filters out
symbols matches based on search_domain:

  case VARIABLES_DOMAIN:
    if (symbol_kind != GDB_INDEX_SYMBOL_KIND_VARIABLE)
      continue;
    break;
  case FUNCTIONS_DOMAIN:
    if (symbol_kind != GDB_INDEX_SYMBOL_KIND_FUNCTION)
      continue;
    break;
  case TYPES_DOMAIN:
    if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE)
      continue;
    break;
  default:
    break;

however, we're currently passing down search_domain::ALL_DOMAIN when
we know we're looking for functions, for no good reason.  This patch
fixes that.

It seems like search_domain is underutilized throughout, but I'll
leave using it more for another pass.

gdb/ChangeLog:
2017-11-08  Pedro Alves  <palves@redhat.com>

	* linespec.c (iterate_over_all_matching_symtabs): Add
	search_domain parameter.  Pass it down to expand_symtabs_matching.
	(decode_objc): Request FUNCTIONS_DOMAIN symbols only.
	(lookup_prefix_sym): Adjust by passing ALL_DOMAIN as
	search_domain.
	(add_all_symbol_names_from_pspace): Add search_domain parameter.
	Pass it down.
	(find_method, find_function_symbols): Request FUNCTIONS_DOMAIN
	symbols.
	(add_matching_symbols_to_info): Add search_domain parameter.  Pass
	it down.
2017-11-08 16:05:46 +00:00
Pedro Alves 1b0261195e Simplify completion_list_add_name | remove sym_text / sym_text_len
sym_text_len existed to strip parameters out of the lookup name.  Now
that that's handled by the lookup_name_info objects, the
sym_text/sym_text_len parameters are no longer necessary.

gdb/ChangeLog:
2017-11-08  Pedro Alves  <palves@redhat.com>

	* ada-lang.c (ada_make_symbol_completion_list): Remove text and
	text_len locals and don't pass them down.
	* symtab.c (completion_list_add_name): Remove
	sym_text/sym_text_len parameters and adjust.
	(completion_list_add_symbol, completion_list_add_msymbol)
	(completion_list_objc_symbol, completion_list_add_fields)
	(add_symtab_completions): Likewise.
	(default_collect_symbol_completion_matches_break_on)
	(collect_file_symbol_completion_matches): Remove sym_text_len
	local and don't pass it down.
	* symtab.h (completion_list_add_name): Remove
	sym_text/sym_text_len parameters.
2017-11-08 16:05:45 +00:00
Pedro Alves c62446b12b lookup_name_info::make_ignore_params
A few places in the completion code look for a "(" to find a
function's parameter list, in order to strip it, because psymtabs (and
gdb index) don't include parameter info in the symbol names.

See compare_symbol_name and
default_collect_symbol_completion_matches_break_on.

This is too naive.  Consider:

 ns_overload2_test::([TAB]

We'd want to complete that to:
 ns_overload2_test::(anonymous namespace)::struct_overload2_test

Or:

 b (anonymous namespace)::[TAB]

That currently completes to:

 b (anonymous namespace)

Which is obviously broken.  This patch makes that work.

Also, the current compare_symbol_name hack means that while this
works:

 "b function([TAB]"  ->  "b function()"

This does not:

 "b function ([TAB]"

This patch fixes that.  Whitespace "ignoring" now Just Works, i.e.,
assuming a symbol named "function(int, long)", this:
 b function (   int , lon[TAB]
completes to:
 b function (   int , long)

To address all of this, this patch builds on top of the rest of the
series, and pushes the responsibility of stripping parameters from a
lookup name to the new lookup_name_info object, where we can apply
per-language rules.  Also note that we now only make a version of the
lookup name with parameters stripped out where it's actually required
to do that, in the psymtab and GDB index code.

For C++, the right way to strip parameters is with "cp_remove_params",
which uses a real parser (cp-name-parser.y) to split the name into a
component tree and then discards parameters.

The trouble for completion is that in that case we have an incomplete
name, like "foo::func(int" and thus cp_remove_params throws an error.

This patch sorts that by adding a cp_remove_params_if_any variant of
cp_remove_params that tries removing characters from the end of the
string until cp_remove_params works.  So cp_remove_params_if_any
behaves like this:

With a complete name:

   "foo::func(int)"  => foo::func(int)  # cp_remove_params_1 succeeds the first time.

With an incomplete name:

   "foo::func(int"  => NULL             # cp_remove_params fails the first time.
   "foo::func(in"   => NULL             # and again...
   "foo::func(i"    => NULL             # and again...
   "foo::func("     => NULL             # and again...
   "foo::func"      => "foo::func"      # success!

Note that even if this approach removes significant rightmost
characters, it's still OK, because this parameter stripping is only
necessary for psymtabs and gdb index, where we're determining whether
to expand a symbol table.  Say cp_remove_params_if_any returned
"foo::" above for "foo::func(int".  That'd cause us to expand more
symtabs than ideal (because we'd expand all symtabs with symbols that
start with "foo::", not just "foo::func"), but then when we actually
look for completion matches, we'd still use the original lookup name,
with parameter information ["foo::func(int"], and thus we'll return no
false positive to the user.  Whether the stripping works as intended
and doesn't strip too much is thus covered by a unit test instead of a
testsuite test.

The "if_any" part of the name refers to the fact that while
cp_remove_params returns NULL if the input name has no parameters in
the first place, like:

   "foo::func"      => NULL         # cp_remove_params

cp_remove_params_if_any still returns the function name:

   "foo::func"      => "foo::func"  # cp_remove_params_if_any

gdb/ChangeLog:
2017-11-08  Pedro Alves  <palves@redhat.com>

	* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
	unittests/lookup_name_info-selftests.c.
	(SUBDIR_UNITTESTS_OBS): Add lookup_name_info-selftests.o.
	* cp-support.c: Include "selftest.h".
	(cp_remove_params_1): Rename from cp_remove_params.  Add
	'require_param' parameter, and handle it.
	(cp_remove_params): Reimplement.
	(cp_remove_params_if_any): New.
	(selftests::quote): New.
	(selftests::check_remove_params): New.
	(selftests::test_cp_remove_params): New.
	(_initialize_cp_support): Install
	selftests::test_cp_remove_params.
	* cp-support.h (cp_remove_params_if_any): Declare.
	* dwarf2read.c :Include "selftest.h".
	(dw2_expand_symtabs_matching_symbol): Use
	lookup_name_info::make_ignore_params.
	(selftests::dw2_expand_symtabs_matching::mock_mapped_index)
	(selftests::dw2_expand_symtabs_matching::string_or_null)
	(selftests::dw2_expand_symtabs_matching::check_match)
	(selftests::dw2_expand_symtabs_matching::test_symbols)
	(selftests::dw2_expand_symtabs_matching::run_test): New.
	(_initialize_dwarf2_read): Register
	selftests::dw2_expand_symtabs_matching::run_test.
	* psymtab.c (psym_expand_symtabs_matching): Use
	lookup_name_info::make_ignore_params.
	* symtab.c (demangle_for_lookup_info::demangle_for_lookup_info):
	If the lookup name wants to ignore parameters, strip them.
	(compare_symbol_name): Remove sym_text/sym_text_len parameters and
	code handling '('.
	(completion_list_add_name): Don't pass down sym_text/sym_text_len.
	(default_collect_symbol_completion_matches_break_on): Don't try to
	strip parameters.
	* symtab.h (lookup_name_info::lookup_name_info): Add
	'ignore_parameters' parameter.
	(lookup_name_info::ignore_parameters)
	(lookup_name_info::make_ignore_params): New methods.
	(lookup_name_info::m_ignore_parameters): New field.
	* unittests/lookup_name_info-selftests.c: New file.
2017-11-08 16:02:24 +00:00
Pedro Alves 61920122ba Reorder/reindent dw2_expand_symtabs_matching & friends
The previous patch had added dw2_expand_symtabs_matching_symbol and
dw2_expand_marked_cus forward declarations and did not reindent
dw2_expand_marked_cus to avoid moving the code around while changing
it at the same time.

gdb/ChangeLog:
2017-11-08  Pedro Alves  <palves@redhat.com>

	* dwarf2read.c (dw2_expand_marked_cus)
	(dw2_expand_symtabs_matching_symbol): Remove forward declarations.
	(dw2_expand_symtabs_matching): Move further below.
	(dw2_expand_marked_cus): Reindent.
2017-11-08 16:02:24 +00:00
Pedro Alves 3f563c840a Optimize .gdb_index symbol name searching
As mentioned in the previous patch, .gdb_index name lookup got
significantly slower with the previous patch.

This patch addresses that, and in the process makes .gdb_index name
searching faster than what we had before the previous patch, even.
Using the same test:

 $ cat script.cmd
 set pagination off
 set $count = 0
 while $count < 400
   complete b string_prin
   printf "count = %d\n", $count
   set $count = $count + 1
 end

 $ time gdb --batch -q ./gdb-with-index -ex "source script.cmd"

I got, before the previous patch (-O2, x86-64):

 real    0m1.773s
 user    0m1.737s
 sys     0m0.040s

and after this patch:

 real    0m1.361s
 user    0m1.315s
 sys     0m0.040s

The basic idea here is simple: instead of always iterating over all
the symbol names in the index, we build an accelerator/sorted name
table and binary search names in it.

Later in the series, we'll want to support wild matching for C++ too,
so this mechanism already considers that.  For example, say that
you're looking up functions/methods named "func", no matter the
containing namespace/class.  If we sorted the table by qualified name,
then we obviously wouldn't be able to find those symbols with a binary
search:

  func
  ns1:🅰️🅱️:func
  ns1:🅱️:func
  ns2::func

(function symbol names in .gdb_index have no parameter info, like psymbols)

To address that out, we put an entry for each name component in the
sorted table.  something like this:

  Table Entry       Actual symbol
  ---------------------------------
  func              func

  func              ns1:🅰️🅱️:func
  b::func           ns1:🅰️🅱️:func
  a:🅱️:func        ns1:🅰️🅱️:func
  ns1:🅰️🅱️:func   ns1:🅰️🅱️:func

  func              ns1:🅱️:func
  b::func           ns1:🅱️:func
  ns1:🅱️:func      ns1:🅱️:func

  func              ns2::func
  ns2::func         ns2::func

Which sorted results in this:

  Table Entry       Actual symbol
  ---------------------------------
  a:🅱️:func        ns1:🅰️🅱️:func
  b::func           ns1:🅰️🅱️:func
  b::func           ns1:🅱️:func
  func              func
  func              ns1:🅰️🅱️:func
  func              ns1:🅱️:func
  func              ns2::func
  ns1:🅰️🅱️:func   ns1:🅰️🅱️:func
  ns1:🅱️:func      ns1:🅱️:func
  ns2::func         ns2::func

And we can binary search this.

Note that a binary search approach works for both completion and
regular lookup, while a name hashing approach only works for normal
symbol looking, since obviously "fun" and "func" have different
hashes.

At first I was a bit wary of these tables potentially growing GDB's
memory significantly.  But I did an experiment that convinced it's not
a worry at all.  I hacked gdb to count the total number of entries in
all the tables, attached that gdb to my system/Fedora's Firefox
(Fedora's debug packages uses .gdb_index), did "set max-completions
unlimited", and then hit "b [TAB]" to cause everything to expand.

That resulted in 1351355 name_components.  Each entry takes 8 bytes,
so that's 10810840 bytes (ignoring std::vector overhead), or ~10.3 MB.
That's IMO too small to worry about, given GDB was using over 7400MB
total at that point.  I.e., we're talking about 0.1% increase.

dw2_expand_symtabs_matching unit tests covering this will be added in
a follow up patch.

If the size of this table turns out to be a concern, I have an idea to
reduce the size of the table further at the expense of a bit more code
-- the vast majority of the name offsets are either 0 or fit in
8-bits:

 total name_component = 1351355, of which,
 name_component::name_offset instances need  0 bits = 679531
 name_component::name_offset instances need  8 bits = 669526
 name_component::name_offset instances need 16 bits = 2298
 name_component::name_offset instances need 32 bits = 0
 name_component::idx instances need 0 bits  = 51
 name_component::idx instances need 8 bits  = 8361
 name_component::idx instances need 16 bits = 280329
 name_component::idx instances need 32 bits = 1062614

so we could have separate tables for 0 name_offset, 8-bit name_offset
and 32-bit name_offset.  That'd give us roughly:

 679531 * 0 + 669526 * 1 + 2298 * 4 + 1062614 * 4 = 4929174, or ~4.7MB

with only 8-bit and 32-bit tables, that'd be:

 1349057 * 1 + 2298 * 4 + 4 * 1351355 = 6763669 bytes, or ~6.5MB.

I don't think we need to bother though.

I also timed:

 $ time gdb --batch -q -p `pidof firefox`
 $ time gdb --batch -q -p `pidof firefox` -ex "b main"
 $ time gdb --batch -q -p `pidof firefox` -ex "set max-completion unlimited" -ex "complete b "

and compared before previous patch vs this patch, and I didn't see a
significant difference, seemingly because time to read debug info
dominates.  The "complete b " variant of the test takes ~2min
currently...  (I have a follow up series that speeds that up
somewhat.)

gdb/ChangeLog:
2017-11-08  Pedro Alves  <palves@redhat.com>

	* dwarf2read.c (byte_swap, MAYBE_SWAP): Move higher up in file.
	(struct name_component): New.
	(mapped_index::name_components): New field.
	(mapped_index::symbol_name_at): New method.
	(dwarf2_read_index): Call mapped_index ctor.
	(dw2_map_matching_symbols): Add comment about name_components
	table.
	(dw2_expand_symtabs_matching): Factor part to...
	(dw2_expand_symtabs_matching_symbol): ... this new function.
	Build name components table, and lookup symbols in it before
	calling the name matcher.
	(dw2_expand_marked_cus): New, factored out from
	dw2_expand_symtabs_matching.
	(dwarf2_per_objfile_free): Call the mapped_index's dtor.
2017-11-08 16:02:24 +00:00
Pedro Alves b5ec771e60 Introduce lookup_name_info and generalize Ada's FULL/WILD name matching
Summary:
 - This is preparation for supporting wild name matching on C++ too.
 - This is also preparation for TAB-completion fixes.
 - Makes symbol name matching (think strcmp_iw) be based on a per-language method.
 - Merges completion and non-completion name comparison (think
   language_ops::la_get_symbol_name_cmp generalized).
 - Avoid re-hashing lookup name multiple times
 - Centralizes preparing a name for lookup (Ada name encoding / C++ Demangling),
   both completion and non-completion.
 - Fixes Ada latent bug with verbatim name matches in expressions
 - Makes ada-lang.c use common|symtab.c completion code a bit more.

Ada's wild matching basically means that

 "(gdb) break foo"

will find all methods named "foo" in all packages.  Translating to
C++, it's roughly the same as saying that "break klass::method" sets
breakpoints on all "klass::method" methods of all classes, no matter
the namespace.  A following patch will teach GDB about fullname vs
wild matching for C++ too.  This patch is preparatory work to get
there.

Another idea here is to do symbol name matching based on the symbol
language's algorithm.  I.e., avoid dependency on current language set.

This allows for example doing

  (gdb) b foo::bar< int > (<tab>

and having gdb name match the C++ symbols correctly even if the
current language is C or Assembly (or Rust, or Ada, or ...), which can
easily happen if you step into an Assembly/C runtime library frame.

By encapsulating all the information related to a lookup name in a
class, we can also cache hash computation for a given language in the
lookup name object, to avoid recomputing it over and over.

Similarly, because we don't really know upfront which languages the
lookup name will be matched against, for each language we store the
lookup name transformed into a search name.  E.g., for C++, that means
demangling the name.  But for Ada, it means encoding the name.  This
actually forces us to centralize all the different lookup name
encoding in a central place, resulting in clearer code, IMO.  See
e.g., the new ada_lookup_name_info class.

The lookup name -> symbol search name computation is also done only
once per language.

The old language->la_get_symbol_name_cmp / symbol_name_cmp_ftype are
generalized to work with both completion, and normal symbol look up.

At some point early on, I had separate completion vs non-completion
language vector entry points, but a single method ends up being better
IMO for simplifying things -- the more we merge the completion /
non-completion name lookup code paths, the less changes for bugs
causing completion vs normal lookup finding different symbols.

The ada-lex.l change is necessary because when doing

  (gdb) p <UpperCase>

then the name that is passed to write_ write_var_or_type ->
ada_lookup_symbol_list misses the "<>", i.e., it's just "UpperCase",
and we end up doing a wild match against "UpperCase" lowercased by
ada_lookup_name_info's constructor.  I.e., "uppercase" wouldn't ever
match "UpperCase", and the symbol lookup fails.

This wouldn't cause any regression in the testsuite, but I added a new
test that would pass before the patch and fail after, if it weren't
for that fix.

This is latent bug that happens to go unnoticed because that
particular path was inconsistent with the rest of Ada symbol lookup by
not lowercasing the lookup name.

Ada's symbol_completion_add is deleted, replaced by using common
code's completion_list_add_name.  To make the latter work for Ada, we
needed to add a new output parameter, because Ada wants to return back
a custom completion candidates that are not the symbol name.

With this patch, minimal symbol demangled name hashing is made
consistent with regular symbol hashing.  I.e., it now goes via the
language vector's search_name_hash method too, as I had suggested in a
previous patch.

dw2_expand_symtabs_matching / .gdb_index symbol names were a
challenge.  The problem is that we have no way to telling what is the
language of each symbol name found in the index, until we expand the
corresponding full symbol, which is off course what we're trying to
avoid.  Language information is simply not considered in the index
format...  Since the symbol name hashing and comparison routines are
per-language, we now have a problem.  The patch sorts this out by
matching each name against all languages.  This is inneficient, and
indeed slows down completion several times.  E.g., with:

 $ cat script.cmd
 set pagination off
 set $count = 0
 while $count < 400
   complete b string_prin
   printf "count = %d\n", $count
   set $count = $count + 1
 end

 $ time gdb --batch -q ./gdb-with-index -ex "source script-string_printf.cmd"

I get, before patch (-O2, x86-64):

 real    0m1.773s
 user    0m1.737s
 sys     0m0.040s

While after patch (-O2, x86-64):

 real    0m9.843s
 user    0m9.482s
 sys     0m0.034s

However, the following patch will optimize this, and will actually
make this use case faster compared to the "before patch" above:

 real    0m1.321s
 user    0m1.285s
 sys     0m0.039s

gdb/ChangeLog:
2017-11-08   Pedro Alves  <palves@redhat.com>

	* ada-lang.c (ada_encode): Rename to ..
	(ada_encode_1): ... this.  Add throw_errors parameter and handle
	it.
	(ada_encode): Reimplement.
	(match_name): Delete, folded into full_name.
	(resolve_subexp): No longer pass the encoded name to
	ada_lookup_symbol_list.
	(should_use_wild_match): Delete.
	(name_match_type_from_name): New.
	(ada_lookup_simple_minsym): Use lookup_name_info and the
	language's symbol_name_matcher_ftype.
	(add_symbols_from_enclosing_procs, ada_add_local_symbols)
	(ada_add_block_renamings): Adjust to use lookup_name_info.
	(ada_lookup_name): New.
	(add_nonlocal_symbols, ada_add_all_symbols)
	(ada_lookup_symbol_list_worker, ada_lookup_symbol_list)
	(ada_iterate_over_symbols): Adjust to use lookup_name_info.
	(ada_name_for_lookup): Delete.
	(ada_lookup_encoded_symbol): Construct a verbatim name.
	(wild_match): Reverse sense of return type.  Use bool.
	(full_match): Reverse sense of return type.  Inline bits of old
	match_name here.
	(ada_add_block_symbols): Adjust to use lookup_name_info.
	(symbol_completion_match): Delete, folded into...
	(ada_lookup_name_info::matches): ... .this new method.
	(symbol_completion_add): Delete.
	(ada_collect_symbol_completion_matches): Add name_match_type
	parameter.  Adjust to use lookup_name_info and
	completion_list_add_name.
	(get_var_value, ada_add_global_exceptions): Adjust to use
	lookup_name_info.
	(ada_get_symbol_name_cmp): Delete.
	(do_wild_match, do_full_match): New functions.
	(ada_lookup_name_info::ada_lookup_name_info): New method.
	(ada_symbol_name_matches, ada_get_symbol_name_matcher): New
	functions.
	(ada_language_defn): Install ada_get_symbol_name_matcher.
	* ada-lex.l (processId): If name starts with '<', copy it
	verbatim.
	* block.c (block_iter_match_step, block_iter_match_first)
	(block_iter_match_next, block_lookup_symbol)
	(block_lookup_symbol_primary, block_find_symbol): Adjust to use
	lookup_name_info.
	* block.h (block_iter_match_first, block_iter_match_next)
	(ALL_BLOCK_SYMBOLS_WITH_NAME): Adjust to use lookup_name_info.
	* c-lang.c (c_language_defn, cplus_language_defn)
	(asm_language_defn, minimal_language_defn): Adjust comments to
	refer to la_get_symbol_name_matcher.
	* completer.c (complete_files_symbols)
	(collect_explicit_location_matches, symbol_completer): Pass a
	symbol_name_match_type down.
	* completer.h (class completion_match, completion_match_result):
	New classes.
	(completion_tracker::reset_completion_match_result): New method.
	(completion_tracker::m_completion_match_result): New field.
	* cp-support.c (make_symbol_overload_list_block): Adjust to use
	lookup_name_info.
	(cp_fq_symbol_name_matches, cp_get_symbol_name_matcher): New
	functions.
	* cp-support.h (cp_get_symbol_name_matcher): New declaration.
	* d-lang.c: Adjust comments to refer to
	la_get_symbol_name_matcher.
	* dictionary.c (dict_vector) <iter_match_first, iter_match_next>:
	Adjust to use lookup_name_info.
	(dict_iter_match_first, dict_iter_match_next)
	(iter_match_first_hashed, iter_match_next_hashed)
	(iter_match_first_linear, iter_match_next_linear): Adjust to work
	with a lookup_name_info.
	* dictionary.h (dict_iter_match_first, dict_iter_match_next):
	Likewise.
	* dwarf2read.c (dw2_lookup_symbol): Adjust to use lookup_name_info.
	(dw2_map_matching_symbols): Adjust to use symbol_name_match_type.
	(gdb_index_symbol_name_matcher): New class.
	(dw2_expand_symtabs_matching) Adjust to use lookup_name_info and
	gdb_index_symbol_name_matcher.  Accept a NULL symbol_matcher.
	* f-lang.c (f_collect_symbol_completion_matches): Adjust to work
	with a symbol_name_match_type.
	(f_language_defn): Adjust comments to refer to
	la_get_symbol_name_matcher.
	* go-lang.c (go_language_defn): Adjust comments to refer to
	la_get_symbol_name_matcher.
	* language.c (default_symbol_name_matcher)
	(language_get_symbol_name_matcher): New functions.
	(unknown_language_defn, auto_language_defn): Adjust comments to
	refer to la_get_symbol_name_matcher.
	* language.h (symbol_name_cmp_ftype): Delete.
	(language_defn) <la_collect_symbol_completion_matches>: Add match
	type parameter.
	<la_get_symbol_name_cmp>: Delete field.
	<la_get_symbol_name_matcher>: New field.
	<la_iterate_over_symbols>: Adjust to use lookup_name_info.
	(default_symbol_name_matcher, language_get_symbol_name_matcher):
	Declare.
	* linespec.c (iterate_over_all_matching_symtabs)
	(iterate_over_file_blocks): Adjust to use lookup_name_info.
	(find_methods): Add language parameter, and use lookup_name_info
	and the language's symbol_name_matcher_ftype.
	(linespec_complete_function): Adjust.
	(lookup_prefix_sym): Use lookup_name_info.
	(add_all_symbol_names_from_pspace): Adjust.
	(find_superclass_methods): Add language parameter and pass it
	down.
	(find_method): Pass symbol language down.
	(find_linespec_symbols): Don't demangle or Ada encode here.
	(search_minsyms_for_name): Add lookup_name_info parameter.
	(add_matching_symbols_to_info): Add name_match_type parameter.
	Use lookup_name_info.
	* m2-lang.c (m2_language_defn): Adjust comments to refer to
	la_get_symbol_name_matcher.
	* minsyms.c: Include <algorithm>.
	(add_minsym_to_demangled_hash_table): Remove table parameter and
	add objfile parameter.  Use search_name_hash, and add language to
	demangled languages vector.
	(struct found_minimal_symbols): New struct.
	(lookup_minimal_symbol_mangled, lookup_minimal_symbol_demangled):
	New functions.
	(lookup_minimal_symbol): Adjust to use them.  Don't canonicalize
	input names here.  Use lookup_name_info instead.  Lookup up
	demangled names once for each language in the demangled names
	vector.
	(iterate_over_minimal_symbols): Use lookup_name_info.  Lookup up
	demangled names once for each language in the demangled names
	vector.
	(build_minimal_symbol_hash_tables): Adjust.
	* minsyms.h (iterate_over_minimal_symbols): Adjust to pass down a
	lookup_name_info.
	* objc-lang.c (objc_language_defn): Adjust comment to refer to
	la_get_symbol_name_matcher.
	* objfiles.h: Include <vector>.
	(objfile_per_bfd_storage) <demangled_hash_languages>: New field.
	* opencl-lang.c (opencl_language_defn): Adjust comment to refer to
	la_get_symbol_name_matcher.
	* p-lang.c (pascal_language_defn): Adjust comment to refer to
	la_get_symbol_name_matcher.
	* psymtab.c (psym_lookup_symbol): Use lookup_name_info.
	(match_partial_symbol): Use symbol_name_match_type,
	lookup_name_info and psymbol_name_matches.
	(lookup_partial_symbol): Use lookup_name_info.
	(map_block): Use symbol_name_match_type and lookup_name_info.
	(psym_map_matching_symbols): Use symbol_name_match_type.
	(psymbol_name_matches): New.
	(recursively_search_psymtabs): Use lookup_name_info and
	psymbol_name_matches.  Rename 'kind' parameter to 'domain'.
	(psym_expand_symtabs_matching): Use lookup_name_info.  Rename
	'kind' parameter to 'domain'.
	* rust-lang.c (rust_language_defn): Adjust comment to refer to
	la_get_symbol_name_matcher.
	* symfile-debug.c (debug_qf_map_matching_symbols)
	(debug_qf_map_matching_symbols): Use symbol_name_match_type.
	(debug_qf_expand_symtabs_matching): Use lookup_name_info.
	* symfile.c (expand_symtabs_matching): Use lookup_name_info.
	* symfile.h (quick_symbol_functions) <map_matching_symbols>:
	Adjust to use symbol_name_match_type.
	<expand_symtabs_matching>: Adjust to use lookup_name_info.
	(expand_symtabs_matching): Adjust to use lookup_name_info.
	* symmisc.c (maintenance_expand_symtabs): Use
	lookup_name_info::match_any ().
	* symtab.c (symbol_matches_search_name): New.
	(eq_symbol_entry): Adjust to use lookup_name_info and the
	language's matcher.
	(demangle_for_lookup_info::demangle_for_lookup_info): New.
	(lookup_name_info::match_any): New.
	(iterate_over_symbols, search_symbols): Use lookup_name_info.
	(compare_symbol_name): Add language, lookup_name_info and
	completion_match_result parameters, and use them.
	(completion_list_add_name): Make extern.  Add language and
	lookup_name_info parameters.  Use them.
	(completion_list_add_symbol, completion_list_add_msymbol)
	(completion_list_objc_symbol): Add lookup_name_info parameters and
	adjust.  Pass down language.
	(completion_list_add_fields): Add lookup_name_info parameters and
	adjust.  Pass down language.
	(add_symtab_completions): Add lookup_name_info parameters and
	adjust.
	(default_collect_symbol_completion_matches_break_on): Add
	name_match_type parameter, and use it.  Use lookup_name_info.
	(default_collect_symbol_completion_matches)
	(collect_symbol_completion_matches): Add name_match_type
	parameter, and pass it down.
	(collect_symbol_completion_matches_type): Adjust.
	(collect_file_symbol_completion_matches): Add name_match_type
	parameter, and use lookup_name_info.
	* symtab.h: Include <string> and "common/gdb_optional.h".
	(enum class symbol_name_match_type): New.
	(class ada_lookup_name_info): New.
	(struct demangle_for_lookup_info): New.
	(class lookup_name_info): New.
	(symbol_name_matcher_ftype): New.
	(SYMBOL_MATCHES_SEARCH_NAME): Use symbol_matches_search_name.
	(symbol_matches_search_name): Declare.
	(MSYMBOL_MATCHES_SEARCH_NAME): Delete.
	(default_collect_symbol_completion_matches)
	(collect_symbol_completion_matches)
	(collect_file_symbol_completion_matches): Add name_match_type
	parameter.
	(iterate_over_symbols): Use lookup_name_info.
	(completion_list_add_name): Declare.
	* utils.c (enum class strncmp_iw_mode): Moved to utils.h.
	(strncmp_iw_with_mode): Now extern.
	* utils.h (enum class strncmp_iw_mode): Moved from utils.c.
	(strncmp_iw_with_mode): Declare.

gdb/testsuite/ChangeLog:
2017-11-08   Pedro Alves  <palves@redhat.com>

	* gdb.ada/complete.exp (p <Exported_Capitalized>): New test.
	(p Exported_Capitalized): New test.
	(p exported_capitalized): New test.
2017-11-08 16:02:24 +00:00
Pedro Alves 5ffa079369 Per-language symbol name hashing algorithm
Currently, we have a mess of symbol name hashing/comparison routines.
There's msymbol_hash for mangled names, and dict_hash and
msymbol_hash_iw for demangled names.  Then there's strcmp_iw,
strcmp_iw_ordered and Ada's full_match/wild_match, which all have to
agree with the hashing routines.  That's why dict_hash is really about
Ada names.  From the inconsistency department, minimal symbol hashing
doesn't go via dict_hash, so Ada's wild matching can't ever work with
minimal symbols.

This patch starts fixing this, by doing two things:

#1 - adds a language vector method to let each language decide how to
     compute a symbol name hash.

#2 - makes dictionaries know the language of the symbols they hold,
     and then use the dictionaries language to decide which hashing
     method to use.

For now, this is just scaffolding, since all languages install the
default method.  The series will make C++ install its own hashing
method later on, and will add per-language symbol name comparison
routines too.

This patch was originally based on a patch that Keith wrote for the
libcc1/C++ WIP support.

gdb/ChangeLog:
2017-11-08  Keith Seitz  <keiths@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* ada-lang.c (ada_language_defn): Install
	default_search_name_hash.
	* buildsym.c (struct buildsym_compunit): <language>: New field.
	(finish_block_internal): Pass language when creating dictionaries.
	(start_buildsym_compunit, start_symtab): New language parameters.
	Use them.
	(restart_symtab): Pass down compilation unit's language.
	* buildsym.h (enum language): Forward declare.
	(start_symtab): New 'language' parameter.
	* c-lang.c (c_language_defn, cplus_language_defn)
	(asm_language_defn, minimal_language_defn): Install
	default_search_name_hash.
	* coffread.c (coff_start_symtab): Adjust.
	* d-lang.c (d_language_defn): Install default_search_name_hash.
	* dbxread.c (struct symloc): Add 'pst_language' field.
	(PST_LANGUAGE): Define.
	(start_psymtab, read_ofile_symtab): Use it.
	(process_one_symbol): New 'language' parameter.  Pass it down.
	* dictionary.c (struct dictionary) <language>: New field.
	(DICT_LANGUAGE): Define.
	(dict_create_hashed, dict_create_hashed_expandable)
	(dict_create_linear, dict_create_linear_expandable): New parameter
	'language'.  Set the dictionary's language.
	(iter_match_first_hashed): Adjust to rename.
	(insert_symbol_hashed): Assert we don't see mismatching
	languages.  Adjust to rename.
	(dict_hash): Rename to ...
	(default_search_name_hash): ... this and make extern.
	* dictionary.h (struct language_defn): Forward declare.
	(dict_create_hashed): New parameter 'language'.
	* dwarf2read.c (dwarf2_start_symtab): Pass down language.
	* f-lang.c (f_language_defn): Install default_search_name_hash.
	* go-lang.c (go_language_defn): Install default_search_name_hash.
	* jit.c (finalize_symtab): Pass compunit's language to dictionary
	creation.
	* language.c (unknown_language_defn, auto_language_defn):
	* language.h (language_defn::la_search_name_hash): New field.
	(default_search_name_hash): Declare.
	* m2-lang.c (m2_language_defn): Install default_search_name_hash.
	* mdebugread.c (new_block): New parameter 'language'.
	* mdebugread.c (parse_symbol): Pass symbol language to block
	allocation.
	(psymtab_to_symtab_1): Pass down language.
	(new_symtab): Pass compunit's language to block allocation.
	* objc-lang.c (objc_language_defn): Install
	default_search_name_hash.
	* opencl-lang.c (opencl_language_defn):
	* p-lang.c (pascal_language_defn): Install
	default_search_name_hash.
	* rust-lang.c (rust_language_defn): Install
	default_search_name_hash.
	* stabsread.h (enum language): Forward declare.
	(process_one_symbol): Add 'language' parameter.
	* symtab.c (search_name_hash): New function.
	* symtab.h (search_name_hash): Declare.
	* xcoffread.c (read_xcoff_symtab): Pass language to start_symtab.
2017-11-08 16:02:24 +00:00
Pedro Alves 2a1dde5da2 Fix "make test-cp-name-parser"
src/gdb/cp-name-parser.y: In function ‘int main(int, char**)’:
src/gdb/cp-name-parser.y:2132:30: error: ISO C++ forbids converting a string constant to ‘char*’ [-Werror=write-strings]
   char *str2, *extra_chars = "", c;
                              ^

Simply don't initialize the variable, it's not necessary.

gdb/ChangeLog:
2017-11-08  Pedro Alves  <palves@redhat.com>

	* cp-name-parser.y (main): Don't initialize extra_chars.
2017-11-08 15:28:50 +00:00
Tom Tromey 95a6b0a106 Constify execute_command
This constifies execute_command and fixes up the callers.

gdb/ChangeLog
2017-11-07  Tom Tromey  <tom@tromey.com>

	* event-top.h (command_handler): Constify.
	* record-full.c (cmd_record_full_start): Update.
	* thread.c (thread_apply_all_command): Update.
	* printcmd.c (eval_command): Update.
	* mi/mi-main.c (mi_execute_cli_command): Update.
	(mi_execute_async_cli_command): Update.
	* tui/tui-stack.c (tui_update_command): Update.
	* cli/cli-interp.c (safe_execute_command): Constify.
	* record.c (record_start): Update.
	(record_start, record_stop, cmd_record_start): Update.
	* record-btrace.c (cmd_record_btrace_bts_start): Update.
	(cmd_record_btrace_pt_start): Update.
	(cmd_record_btrace_start): Update.
	(cmd_record_btrace_start): Update.
	* reverse.c (exec_reverse_once): Update.
	* python/python.c (execute_gdb_command): Don't copy the command.
	* event-top.c (command_line_handler): Update.
	(command_handler): Constify.
	* defs.h (deprecated_call_command_hook): Constify.
	* cli/cli-script.h (execute_user_command): Constify.
	* cli/cli-script.c (execute_user_command): Constify.
	(execute_cmd_pre_hook, execute_cmd_post_hook): Constify.
	(enum command_control_type): Update.
	* main.c (catch_command_errors): Remove non-const overload.
	(catch_command_errors_ftype): Remove.
	* python/py-cmd.c (cmdpy_function): Constify.
	* guile/scm-cmd.c (cmdscm_function): Constify.
	* cli/cli-dump.c (call_dump_func): Constify.
	* cli/cli-decode.c (do_const_cfunc): Constify.
	(do_sfunc): Constify.
	(cmd_func): Constify.
	* gdbcmd.h (execute_command, execute_command_to_string): Constify.
	* top.h (execute_command): Constify.
	* top.c (execute_command): Constify.
	(execute_command_to_string): Constify.
	(deprecated_call_command_hook): Constify.
	* command.h (cmd_func): Constify.
	* cli/cli-decode.h (struct cmd_list_element) <func>: Constify.
2017-11-07 13:59:09 -07:00
Tom Tromey eb4c3f4aaa Constify add_setshow_*
This constifies the add_setshow_* family of functions, and then fixes
up the fallout.  The bulk of this patch was written by script.

gdb/ChangeLog
2017-11-07  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (catch_ada_exception_command): Constify.
	(catch_assert_command): Constify.
	* break-catch-throw.c (catch_catch_command, catch_throw_command)
	(catch_rethrow_command): Constify.
	(catch_exception_command_1): Constify.
	* breakpoint.h (add_catch_command): Constify.
	* break-catch-syscall.c (catch_syscall_command_1): Constify.
	(catch_syscall_split_args): Constify.
	* break-catch-sig.c (catch_signal_command): Constify.
	(catch_signal_split_args): Constify.
	* cli/cli-decode.h (struct cmd_list_element) <function>: Use
	cmd_const_sfunc_ftype.
	* cli/cli-decode.c (add_setshow_cmd_full): Constify.
	(add_setshow_enum_cmd, add_setshow_auto_boolean_cmd)
	(add_setshow_boolean_cmd, add_setshow_filename_cmd)
	(add_setshow_string_cmd, struct cmd_list_element)
	(add_setshow_optional_filename_cmd, add_setshow_integer_cmd)
	(add_setshow_uinteger_cmd, add_setshow_zinteger_cmd)
	(add_setshow_zuinteger_unlimited_cmd, add_setshow_zuinteger_cmd):
	Constify.
	(set_cmd_sfunc): Constify.
	(empty_sfunc): Constify.
	* command.h (add_setshow_enum_cmd, add_setshow_auto_boolean_cmd)
	(add_setshow_boolean_cmd, add_setshow_filename_cmd)
	(add_setshow_string_cmd, add_setshow_string_noescape_cmd)
	(add_setshow_optional_filename_cmd, add_setshow_integer_cmd)
	(add_setshow_uinteger_cmd, add_setshow_zinteger_cmd)
	(add_setshow_zuinteger_cmd, add_setshow_zuinteger_unlimited_cmd):
	Constify.
	(set_cmd_sfunc): Constify.
	(cmd_sfunc_ftype): Remove.
	* compile/compile.c (set_compile_args): Constify.
	* infrun.c (set_disable_randomization): Constify.
	* infcmd.c (set_args_command, set_cwd_command): Constify.
	* breakpoint.c (set_condition_evaluation_mode): Constify.
	(add_catch_command): Constify.
	(catch_fork_command_1, catch_exec_command_1)
	(catch_load_command_1, catch_unload_command_1): Constify.
	(catch_load_or_unload): Constify.
	* guile/scm-param.c (pascm_set_func): Constify.
	(add_setshow_generic): Constify.
	* python/py-param.c (get_set_value): Constify.
	* top.h (set_verbose): Constify.
	* tui/tui-win.c (tui_set_var_cmd): Constify.
	* mi/mi-main.c (set_mi_async_command): Constify.
	* cli/cli-logging.c (set_logging_overwrite)
	(set_logging_redirect): Constify.
	* value.c (set_max_value_size): Constify.
	* valprint.c (set_input_radix, set_output_radix): Constify.
	* utils.c (set_width_command, set_height_command): Constify.
	* typeprint.c (set_print_type_methods, set_print_type_typedefs): Constify.
	* tracepoint.c (set_disconnected_tracing)
	(set_circular_trace_buffer, set_trace_buffer_size)
	(set_trace_user, set_trace_notes, set_trace_stop_notes): Constify.
	* top.c (set_history_size_command, set_verbose, set_editing)
	(set_gdb_datadir, set_history_filename): Constify.
	* target.c (set_targetdebug, maint_set_target_async_command)
	(maint_set_target_non_stop_command, set_target_permissions)
	(set_write_memory_permission): Constify.
	(open_target): Constify.
	* target-descriptions.c (set_tdesc_filename_cmd): Constify.
	* target-dcache.c (set_stack_cache, set_code_cache): Constify.
	* symtab.c (set_symbol_cache_size_handler): Constify.
	* symfile.c (set_ext_lang_command): Constify.
	* symfile-debug.c (set_debug_symfile): Constify.
	* source.c (set_directories_command): Constify.
	* solib.c (reload_shared_libraries, gdb_sysroot_changed): Constify.
	* serial.c (set_parity): Constify.
	* rs6000-tdep.c (powerpc_set_soft_float, powerpc_set_vector_abi): Constify.
	* remote.c (set_remote_exec_file, set_remotebreak)
	(set_remote_protocol_Z_packet_cmd, set_range_stepping): Constify.
	* record.c (set_record_insn_history_size)
	(set_record_call_history_size): Constify.
	* record-full.c (set_record_full_insn_max_num): Constify.
	* proc-api.c (set_procfs_trace_cmd, set_procfs_file_cmd): Constify.
	* osabi.c (set_osabi): Constify.
	* mips-tdep.c (set_mips64_transfers_32bit_regs)
	(reinit_frame_cache_sfunc, mips_abi_update): Constify.
	* maint.c (maintenance_set_profile_cmd): Constify.
	* linux-thread-db.c (set_libthread_db_search_path): Constify.
	* language.c (set_language_command, set_range_command)
	(set_case_command): Constify.
	* infrun.c (set_non_stop, set_observer_mode)
	(set_stop_on_solib_events, set_schedlock_func)
	(set_exec_direction_func): Constify.
	* infcmd.c (set_inferior_tty_command): Constify.
	* disasm.c (set_disassembler_options_sfunc): Constify.
	* demangle.c (set_demangling_command): Constify.
	* dcache.c (set_dcache_size, set_dcache_line_size): Constify.
	* cris-tdep.c (set_cris_version, set_cris_mode)
	(set_cris_dwarf2_cfi): Constify.
	* corefile.c (set_gnutarget_command): Constify.
	* charset.c (set_host_charset_sfunc, set_target_charset_sfunc)
	(set_target_wide_charset_sfunc): Constify.
	* breakpoint.c (update_dprintf_commands): Constify.
	* auto-load.c (set_auto_load_dir, set_auto_load_safe_path): Constify.
	* arm-tdep.c (set_fp_model_sfunc, arm_set_abi)
	(set_disassembly_style_sfunc): Constify.
	* arch-utils.c (set_endian, set_architecture): Constify.
	* alpha-tdep.c (reinit_frame_cache_sfunc): Constify.
	* agent.c (set_can_use_agent): Constify.
2017-11-07 13:59:09 -07:00
Tom Tromey 5fed81ff35 Remove cmd_cfunc_ftype
This removes cmd_cfunc_ftype and the non-const overload of add_cmd;
then fixes up the fallout.

For the most part this patch is straightforward.  There are a few
files (go32-nat.c, windows-nat.c, and gnu-nat.c) that I could not
compile; so I made a best effort there.

gdb/ChangeLog
2017-11-07  Tom Tromey  <tom@tromey.com>

	* go32-nat.c (go32_sysinfo, go32_sldt, go32_sgdt, go32_sidt)
	(go32_pde, go32_pte, go32_pte_for_address): Constify.
	* gnu-nat.c (_parse_bool_arg, show_thread_default_pause_cmd)
	(set_thread_default_pause_cmd, set_thread_default_run_cmd)
	(show_thread_default_run_cmd, set_thread_default_detach_sc_cmd)
	(parse_int_arg, show_thread_default_detach_sc_cmd)
	(set_signals_cmd, show_signals_cmd, set_sig_thread_cmd)
	(show_sig_thread_cmd, set_stopped_cmd, show_stopped_cmd)
	(set_exceptions_cmd, show_exceptions_cmd, set_task_pause_cmd)
	(show_task_pause_cmd, set_task_detach_sc_cmd)
	(show_task_detach_sc_cmd, set_task_exc_port_cmd)
	(set_noninvasive_cmd, set_thread_pause_cmd)
	(show_thread_pause_cmd, set_thread_run_cmd, show_thread_run_cmd)
	(set_thread_detach_sc_cmd, show_thread_detach_sc_cmd)
	(set_thread_exc_port_cmd, thread_takeover_sc_cmd): Constify.
	* windows-nat.c (display_selectors): Constify.
	* cli/cli-decode.h (struct cmd_list_element) <function>: Remove
	non-const "cfunc".
	* cli/cli-decode.c (set_cmd_cfunc): Remove non-const overload.
	(cmd_cfunc_eq): Likewise.
	(struct cmd_list_element): Likewise.
	(do_cfunc): Remove.
	(cli_user_command_p): Update.
	* command.h (add_cmd): Remove non-const overload.
	(cmd_cfunc_ftype): Remove typedef.
	(cmd_cfunc_eq): Remove non-const overload.
	* value.c (show_values): Constify.
	* thread.c (thread_apply_all_command): Constify.
	* symfile.c (load_command): Constify.
	* source.c (directory_command): Constify.
	* maint.c (maintenance_internal_error)
	(maintenance_demangler_warning, maintenance_space_display)
	(maintenance_print_architecture, maintenance_translate_address)
	(maintenance_info_selftests, maintenance_internal_warning):
	Constify.
	* breakpoint.c (disable_trace_command, enable_trace_command):
	Constify.
	* auto-load.c (info_auto_load_local_gdbinit, add_auto_load_dir):
	Constify.
	(add_auto_load_safe_path): Constify.
	* guile/scm-auto-load.c (info_auto_load_guile_scripts): Constify.
	* top.h (show_commands): Constify.
	* linux-thread-db.c (info_auto_load_libthread_db): Constify.
	* sparc64-tdep.c (adi_examine_command): Constify.
	(adi_assign_command): Constify.
2017-11-07 13:59:09 -07:00
Tom Tromey 1d12d88f18 Constify add_info
This patch constifies add_info and updates all the info commands.  The
bulk of this patch was written using a script; and then I did a manual
pass to fix up the remaining compilation errors.

I could not compile every changed file; in particular nto-procfs.c,
gnu-nat.c, and darwin-nat-info.c; but I at least tried to check the
correctness by inspection.

gdb/ChangeLog
2017-11-07  Tom Tromey  <tom@tromey.com>

	* frame.h (info_locals_command, info_args_command): Constify.
	* auto-load.h (auto_load_info_scripts): Constify.
	* inferior.h (registers_info): Constify.
	* copying.c: Rebuild.
	* copying.awk: Constify generated commands.
	* auto-load.c (auto_load_info_scripts)
	(info_auto_load_gdb_scripts): Constify.
	* cli/cli-decode.c (struct cmd_list_element): Take a
	cmd_const_cfunc_ftype.
	* command.h (add_info): Take a cmd_const_cfunc_ftype.
	* tui/tui-win.c (tui_all_windows_info): Constify.
	* python/py-auto-load.c (info_auto_load_python_scripts):
	Constify.
	* cli/cli-cmds.c (show_command): Remove non-const overload.
	* tracepoint.c (info_tvariables_command, info_scope_command):
	Constify.
	(info_static_tracepoint_markers_command): Constify.
	* thread.c (info_threads_command): Constify.
	(print_thread_info_1): Constify.
	* target.c (info_target_command): Constify.
	* symtab.c (info_sources_command, info_functions_command)
	(info_types_command): Constify.
	(info_variables_command): Remove non-const overload.
	* symfile.c (info_ext_lang_command): Constify.
	* stack.c (info_frame_command, info_locals_command)
	(info_args_command): Constify.
	(backtrace_command): Remove non-const overload.
	* source.c (info_source_command, info_line_command): Constify.
	* solib.c (info_sharedlibrary_command): Constify.
	* skip.c (info_skip_command): Constify.
	* ser-go32.c (info_serial_command): Constify.
	* reverse.c (info_bookmarks_command): Constify.
	* printcmd.c (info_symbol_command, info_address_command)
	(info_display_command): Constify.
	* osdata.c (info_osdata_command): Constify.
	* objc-lang.c (info_selectors_command, info_classes_command):
	Constify.
	* nto-procfs.c (procfs_pidlist, procfs_meminfo): Constify.
	* memattr.c (info_mem_command): Constify.
	* macrocmd.c (info_macro_command, info_macros_command): Constify.
	* linux-fork.c (info_checkpoints_command): Constify.
	* infrun.c (info_signals_command): Constify.
	* inflow.c (info_terminal_command): Constify.
	* inferior.c (info_inferiors_command): Constify.
	(print_inferior): Constify.
	* infcmd.c (info_program_command, info_all_registers_command)
	(info_registers_command, info_vector_command)
	(info_float_command): Constify.
	(registers_info): Constify.
	* gnu-nat.c (info_send_rights_cmd, info_recv_rights_cmd)
	(info_port_sets_cmd, info_dead_names_cmd, info_port_rights_cmd):
	Constify.
	* f-valprint.c (info_common_command): Constify.
	* dcache.c (info_dcache_command): Constify.
	(dcache_info_1): Constify.
	* darwin-nat-info.c (info_mach_tasks_command)
	(info_mach_task_command, info_mach_ports_command)
	(info_mach_port_command, info_mach_threads_command)
	(info_mach_thread_command, info_mach_regions_command)
	(info_mach_regions_recurse_command, info_mach_region_command)
	(info_mach_exceptions_command): Constify.
	(get_task_from_args): Constify.
	* cp-support.c (info_vtbl_command): Constify.
	* breakpoint.c (info_watchpoints_command)
	(info_tracepoints_command): Constify.
	(info_breakpoints_command): Remove non-const overload.
	* avr-tdep.c (avr_io_reg_read_command): Constify.
	* auxv.c (info_auxv_command): Constify.
	* ada-tasks.c (info_tasks_command): Constify.
	(info_task): Constify.
	* ada-lang.c (info_exceptions_command): Constify.
2017-11-07 13:59:09 -07:00
Tom Tromey 0b39b52e6e Constify add_com
This changes add_com to take a cmd_const_cfunc_ftype, and then fixes
up all the command implementations.

In most cases this is trivial.

In a couple of places I had to again introduce a temporary non-const
overload.  These overloads will be removed when add_info is
constified.

gdb/ChangeLog
2017-11-07  Tom Tromey  <tom@tromey.com>

	* solib.h (no_shared_libraries): Constify.
	* frame.h (return_command): Constify.
	* cli/cli-cmds.h (quit_command): Constify.
	* top.h (quit_command, execute_command): Constify.
	* target.h (flash_erase_command): Constify.
	* inferior.h (set_inferior_args, attach_command): Constify.
	* tracepoint.h (start_tracing, stop_tracing): Constify.
	* breakpoint.h (break_command, tbreak_command)
	(hbreak_command_wrapper, thbreak_command_wrapper)
	(rbreak_command_wrapper, watch_command_wrapper)
	(awatch_command_wrapper, rwatch_command_wrapper)
	(get_tracepoint_by_number): Constify.
	* symtab.c (info_variables_command, rbreak_command)
	(symtab_symbol_info): Constify.
	(info_variables_command): Add non-const overload.
	* top.c (dont_repeat_command): Constify.
	* breakpoint.c (ignore_command, commands_command)
	(condition_command, tbreak_command, hbreak_command)
	(thbreak_command, clear_command, break_command)
	(info_breakpoints_command, watch_command, rwatch_command)
	(awatch_command, trace_command, ftrace_command, strace_command)
	(trace_pass_command, break_range_command, dprintf_command)
	(agent_printf_command, get_tracepoint_by_number)
	(watch_maybe_just_location, trace_pass_command): Constify.
	(info_breakpoints_command): Add non-const overload.
	* tracefile.c (tsave_command): Constify.
	* infcmd.c (attach_command, disconnect_command, signal_command)
	(queue_signal_command, stepi_command, nexti_command)
	(finish_command, next_command, step_command, until_command)
	(advance_command, jump_command, continue_command, run_command)
	(start_command, starti_command, interrupt_command)
	(run_command_1, set_inferior_args, step_1): Constify.
	* inferior.c (add_inferior_command, remove_inferior_command)
	(clone_inferior_command): Constify.
	* linux-fork.c (checkpoint_command, restart_command): Constify.
	* windows-nat.c (signal_event_command): Constify.
	* guile/guile.c (guile_repl_command, guile_command): Constify.
	* printcmd.c (x_command, display_command, printf_command)
	(output_command, set_command, call_command, print_command)
	(eval_command): Constify.
	(non_const_set_command): Remove.
	(_initialize_printcmd): Update.
	* source.c (forward_search_command, reverse_search_command):
	Constify.
	* jit.c (jit_reader_load_command, jit_reader_unload_command):
	Constify.
	* infrun.c (handle_command): Constify.
	* memattr.c (mem_command): Constify.
	* stack.c (return_command, up_command, up_silently_command)
	(down_command, down_silently_command, frame_command)
	(backtrace_command, func_command, backtrace_command_1): Constify.
	(backtrace_command): Add non-const overload.
	* remote-sim.c (simulator_command): Constify.
	* exec.c (set_section_command): Constify.
	* tracepoint.c (tdump_command, trace_variable_command)
	(tstatus_command, tstop_command, tstart_command)
	(end_actions_pseudocommand, while_stepping_pseudocommand)
	(collect_pseudocommand, teval_pseudocommand, actions_command)
	(start_tracing, stop_tracing): Constify.
	* value.c (init_if_undefined_command): Constify.
	* tui/tui-stack.c (tui_update_command): Constify.
	* tui/tui-win.c (tui_refresh_all_command)
	(tui_set_tab_width_command, tui_set_win_height_command)
	(tui_set_focus_command, tui_scroll_forward_command)
	(tui_scroll_backward_command, tui_scroll_left_command)
	(tui_scroll_right_command, parse_scrolling_args, tui_set_focus)
	(tui_set_win_height): Constify.
	* tui/tui-layout.c (tui_layout_command): Constify.
	* procfs.c (proc_trace_syscalls, proc_trace_sysentry_cmd)
	(proc_trace_sysexit_cmd, proc_untrace_sysentry_cmd)
	(proc_untrace_sysexit_cmd): Constify.
	* remote.c (threadlist_test_cmd, threadinfo_test_cmd)
	(threadset_test_cmd, threadlist_update_test_cmd)
	(threadalive_test): Constify.
	* objc-lang.c (print_object_command): Constify.
	* command.h (add_com): Constify.
	* cli/cli-dump.c (restore_command): Constify.
	* cli/cli-cmds.c (pwd_command, echo_command, quit_command)
	(help_command, complete_command, shell_command, edit_command)
	(list_command, disassemble_command, make_command)
	(apropos_command, alias_command): Constify.
	* cli/cli-script.c (document_command, define_command)
	(while_command, if_command, validate_comname): Constify.
	* cli/cli-decode.c (struct cmd_list_element): Change type of
	"fun".
	* target.c (do_monitor_command, flash_erase_command): Constify.
	* regcache.c (reg_flush_command): Constify.
	* reverse.c (reverse_step, reverse_next, reverse_stepi)
	(reverse_nexti, reverse_continue, reverse_finish)
	(save_bookmark_command, goto_bookmark_command)
	(exec_reverse_once): Constify.
	* python/python.c (python_interactive_command, python_command):
	Constify.
	* typeprint.c (ptype_command, whatis_command, whatis_exp):
	Constify.
	* solib.c (sharedlibrary_command, no_shared_libraries): Constify.
	* gcore.c (gcore_command): Constify.
2017-11-07 13:59:09 -07:00
Tom Tromey 85c4be7c83 Add set_repeat_arguments function
The "x", "list", and "show commands" commands have special repetition
behavior: repeating the command doesn't re-run it with the same
arguments

This is currently implemented by modifying the passed-in argument; but
that won't work properly with const arguments (and seems pretty
obscure besides).

This patch adds a new "set_repeat_arguments" function and changes the
relevant places to call it.

gdb/ChangeLog
2017-11-07  Tom Tromey  <tom@tromey.com>

	* printcmd.c (x_command): Call set_repeat_arguments.
	* cli/cli-cmds.c (list_command): Call set_repeat_arguments.
	* top.c (repeat_arguments): New global.
	(set_repeat_arguments): New function.
	(execute_command): Handle repeat_arguments.
	(show_commands): Calls set_repeat_arguments.
	* command.h (set_repeat_arguments): Declare.
2017-11-07 13:59:09 -07:00
Tom Tromey 022643b445 Remove cleanup from backtrace_command
This removes a cleanup from backtrace_command, replacing it with
std::string.  This patch temporarily changes backtrace_command so that
the parameter is named "args_in" and is immediately constified; this
is fixed again in the constification patch.

gdb/ChangeLog
2017-11-07  Tom Tromey  <tom@tromey.com>

	* stack.c (backtrace_command): Use std::string.
	(backtrace_command_1): Make "count_exp" const.
2017-11-07 13:59:09 -07:00
Tom Tromey 5614fb7720 Constify add_path and friends
This constifies add_path, mod_path, and directory_switch.

gdb/ChangeLog
2017-11-07  Tom Tromey  <tom@tromey.com>

	* source.c (directory_switch, mod_path, add_path): Constify.
	* defs.h (add_path, mod_path, directory_switch): Constify.
	* mi/mi-cmd-env.c (env_mod_path): Constify.
2017-11-07 13:59:09 -07:00
Tom Tromey 6be9a197d9 Make strip_bg_char return a unique_xmalloc_ptr
This changes strip_bg_char to return a unique_xmalloc_ptr and removes
several cleanups.

gdb/ChangeLog
2017-11-07  Tom Tromey  <tom@tromey.com>

	* infcmd.c (strip_bg_char): Return gdb::unique_xmalloc_ptr.
	(run_command_1, continue_command, step_1, jump_command)
	(signal_command, until_command, advance_command, finish_command)
	(attach_command): Update.
2017-11-07 13:59:09 -07:00
Tom Tromey c2252c0dd8 Make set_cmd_cfunc private
set_cmd_cfunc is only used in cli-decode.c, and I don't think there is
a good reason to expose it directly.  So, this patch makes it private.

gdb/ChangeLog
2017-11-07  Tom Tromey  <tom@tromey.com>

	* command.h (set_cmd_cfunc): Don't declare.
	* cli/cli-decode.c (set_cmd_cfunc): Now static.
2017-11-07 13:59:08 -07:00
Tom Tromey 1ee870c524 Constify add_com_suppress_notification
This constifies add_com_suppress_notification and fixes the one
caller.

gdb/ChangeLog
2017-11-07  Tom Tromey  <tom@tromey.com>

	* stack.c (select_frame_command): Constify.
	* cli/cli-decode.c (add_com_suppress_notification): Constify.
	* command.h (add_com_suppress_notification): Constify.
2017-11-07 13:59:08 -07:00
Tom Tromey ee7ddd7132 Constify add_abbrev_prefix_cmd
This changes add_abbrev_prefix_cmd to take a const-taking callback
function and then fixes the one caller.

gdb/ChangeLog
2017-11-07  Tom Tromey  <tom@tromey.com>

	* breakpoint.c (stop_command): Constify.
	* cli/cli-decode.c (struct cmd_list_element): Constify.
	* command.h (add_abbrev_prefix_cmd): Constify.
2017-11-07 13:59:08 -07:00
Pedro Alves a02b41a7e6 Add some more breakpoint/location range tests
Some extra thoroughness tests that I had over here.

gdb/testsuite/ChangeLog:
2017-11-07  Pedro Alves  <palves@redhat.com>

	* gdb.cp/ena-dis-br-range.exp: Add more tests.
2017-11-07 11:16:09 +00:00
Pedro Alves 95e95a6de2 Make breakpoint/location number parsing error output consistent
... and also make GDB catch a few more cases of invalid input.

This fixes the inconsistency in GDB's output (e.g., "bad" vs "Bad")
exposed by the new tests added in the previous commit.

Also, makes the "0-0" and "inverted range" cases be loud errors.

Also makes GDB reject negative breakpoint number in ranges.  We
already rejected negative number literals, but you could still subvert
that via convenience variables, like:

  (gdb) set $bp -1
  (gdb) disable $bp.1-2

The change to get_number_trailer fixes a bug exposed by the new tests.
The function did not handle parsing "-$num".  [This wasn't visible in
the gdb.multi/tids.exp (which has similar tests) because the TID range
parsing is implemented differently.]

gdb/ChangeLog:
2017-11-07  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (extract_bp_kind): New enum.
	(extract_bp_num, extract_bp_or_bp_range): New functions, partially
	factored out from ...
	(extract_bp_number_and_location): ... here.
	* cli/cli-utils.c (get_number_trailer): Handle '-$variable'.

gdb/testsuite/ChangeLog:
2017-11-07  Pedro Alves  <palves@redhat.com>

	* gdb.base/ena-dis-br.exp (test_ena_dis_br): Adjust test.
	* gdb.cp/ena-dis-br-range.exp: Adjust tests.
	(disable_invalid, disable_inverted, disable_negative): New
	procedures.
	("bad numbers"): New set of tests.
2017-11-07 11:07:19 +00:00
Pedro Alves cee62dbd87 Add base 'enable/disable invalid location range' tests
This adds tests that exercise the "bad breakpoint number" paths.
Specifically:

 - malformed ranges
 - use of explicit 0 as bp/loc number.
 - inverted ranges

I'm adding this as a baseline to improve.  This shows that there's a
lot of inconsistency in GDB's output (e.g., "bad" vs "Bad").

Also, IMO, the "0-0" and inverted range cases should be loud errors.

That and more will all be addressed in the next patch.

gdb/testsuite/ChangeLog:
2017-11-07  Pedro Alves  <palves@redhat.com>

	* gdb.cp/ena-dis-br-range.exp: Add tests.
2017-11-07 11:06:49 +00:00
Pedro Alves cc638e867c Breakpoint location parsing: always error instead of warning
It's odd that when parsing a breakpoint or location number, we error out
in most cases, but warn in others.

  (gdb) disable 1-
  bad breakpoint number at or near: '1-'
  (gdb) disable -1
  bad breakpoint number at or near: '-1'
  (gdb) disable .foo
  bad breakpoint number at or near: '.foo'
  (gdb) disable foo.1
  Bad breakpoint number 'foo.1'
  (gdb) disable 1.foo
  warning: bad breakpoint number at or near '1.foo'

This changes GDB to always error out.  It required touching one testcase
that expected the warning.

gdb/ChangeLog:
2017-11-07  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (extract_bp_number_and_location): Change return
	type to void.  Throw error instead of warning.
	(enable_disable_command): Adjust.

gdb/testsuite/ChangeLog:
2017-11-07  Pedro Alves  <palves@redhat.com>

	* gdb.base/ena-dis-br.exp: Don't expect "warning:".
2017-11-07 11:06:00 +00:00
Xavier Roirand d0fe47010f Allow enabling/disabling breakpoint location ranges
When a breakpoint has multiple locations, like e.g.:

 Num  Type       Disp Enb  Address    What
 1    breakpoint keep y    <MULTIPLE>
 1.1                  y    0x080486a2 in void foo<int>()...
 1.2                  y    0x080486ca in void foo<double>()...
 [....]
 1.5                  y    0x080487fa in void foo<long>()...

it's possible to enable/disable the individual locations using the
'<breakpoint_number>.<location_number>' syntax, like e.g.:

 (gdb) disable 1.2 1.3 1.4 1.5

That's inconvenient when you have a long list of locations to disable,
however.

This patch adds shorthand for the above, by making it possible to
specify a range of locations with the following syntax (similar to
thread id ranges):

 <breakpoint_number>.<first_location_number>-<last_location_number>

For example, the command above can now be simplified to:

 (gdb) disable 1.2-5

gdb/ChangeLog:
2017-11-07  Xavier Roirand  <roirand@adacore.com>
	    Pedro Alves  <palves@redhat.com>

	* breakpoint.c (map_breakpoint_number_range): New, factored out
	from ...
	(map_breakpoint_numbers): ... here.
	(find_location_by_number): Change parameters from string to
	breakpoint number and location.
	(extract_bp_number_and_location): New function.
	(enable_disable_bp_num_loc)
	(enable_disable_breakpoint_location_range)
	(enable_disable_command): New functions, factored out ...
	(enable_command, disable_command): ... these functions, and
	adjusted to support ranges.
	* NEWS: Document enable/disable breakpoint location range feature.

gdb/doc/ChangeLog:
2017-11-07  Xavier Roirand  <roirand@adacore.com>
	    Pedro Alves  <palves@redhat.com>

	* gdb.texinfo (Set Breaks): Document support for breakpoint
	location ranges in the enable/disable commands.

gdb/testsuite/ChangeLog:
2017-11-07  Xavier Roirand  <roirand@adacore.com>
	    Pedro Alves  <palves@redhat.com>

	* gdb.base/ena-dis-br.exp: Add reference to
	gdb.cp/ena-dis-br-range.exp.
	* gdb.cp/ena-dis-br-range.exp: New file.
	* gdb.cp/ena-dis-br-range.cc: New file.
2017-11-07 11:00:31 +00:00
Luis Machado 635dc5b2e5 Update my e-mail address.
gdb/ChangeLog:
2017-11-06  Luis Machado  <luis.machado@linaro.org>

	* MAINTAINERS (Write After Approval): Update my e-mail address.
2017-11-06 15:39:09 -02:00
Pedro Alves 556e5da513 Simplify child_terminal_inferior
The comment about Lynx in child_terminal_init reads a bit odd, since
it's not exactly clear what "This" in "This is for Lynx" is referring
to.  Looking back in history makes it clearer.  When the comment was
originally added, in commit 91ecc8efa9, back in 1994, the code
looked like this:

~~~
#ifdef PROCESS_GROUP_TYPE
#ifdef PIDGET
      /* This is for Lynx, and should be cleaned up by having Lynx be
         a separate debugging target with a version of
         target_terminal_init_inferior which passes in the process
         group to a generic routine which does all the work (and the
         non-threaded child_terminal_init_inferior can just pass in
         inferior_pid to the same routine).  */
      inferior_process_group = PIDGET (inferior_pid);
#else
      inferior_process_group = inferior_pid;
#endif
#endif
~~~

So this looked like it was about when GDB was growing support for
multi-threading, and inferior_pid was still a single int for most
ports.

Eventually we got ptid_t, so the comment isn't really useful today.
Particularly more so since we no longer support Lynx as a GDB host.

The only caller left of child_terminal_init_with_pgrp is gnu-nat.c
(the Hurd), and that target uses fork-child, so when we reach
gnu_terminal_init after spawning a new child, the current inferior
must already have the PID set, and the child must be a process group
leader.

We can't add a 'getpgid(inf->pid) == inf->pid' assertion to
child_terminal_init though (like a previous version of this patch was
doing [1]), because child_terminal_init is also reached after
attaching to a process.  If we did, the new
gdb.base/attach-non-pgrp-leader.exp test would fail, with:

  (gdb) attach 12415
  Attaching to program: build/gdb/testsuite/outputs/gdb.base/attach-non-pgrp-leader/attach-non-pgrp-leader, process 12415
  src/gdb/inflow.c:180: internal-error: void child_terminal_init(target_ops*): Assertion `getpgid (inf->pid) == inf->pid' failed.
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.
  Quit this debugging session? (y or n) FAIL: gdb.base/attach-non-pgrp-leader.exp: child: attach to child (GDB internal error)

I'm not making GDB save the pgid for attached processes with getpgid
for now, because the saved process group affects other things which
I'm leaving for following patches, like e.g., the "interrupt" command.

[1] - https://sourceware.org/ml/gdb-patches/2017-11/msg00039.html

gdb/ChangeLog:
2017-11-06  Pedro Alves  <palves@redhat.com>

	* gnu-nat.c (gnu_terminal_init): Delete.
	(gnu_target): Don't install gnu_terminal_init.
	* inflow.c (child_terminal_init_with_pgrp): Delete, merged with ...
	(child_terminal_init): ... this function.
2017-11-06 16:59:13 +00:00
Pedro Alves 46f67f80dd Test attaching to a process that isn't a process group leader
The patch at
<https://sourceware.org/ml/gdb-patches/2017-11/msg00039.html> was
proposing to add an assertion to child_terminal_init that turns out
would fail if you tried to attach to a process that isn't a process
group leader.

Since the testsuite failed to catch the problem, this commit adds a
new testcase that would catch it, like:

  (gdb) attach 12415
  Attaching to program: build/gdb/testsuite/outputs/gdb.base/attach-non-pgrp-leader/attach-non-pgrp-leader, process 12415
  src/gdb/inflow.c:180: internal-error: void child_terminal_init(target_ops*): Assertion `getpgid (inf->pid) == inf->pid' failed.
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.
  Quit this debugging session? (y or n) FAIL: gdb.base/attach-non-pgrp-leader.exp: child: attach to child (GDB internal error)

gdb/testsuite/ChangeLog:
2017-11-06  Pedro Alves  <palves@redhat.com>

	* gdb.base/attach-non-pgrp-leader.c: New.
	* gdb.base/attach-non-pgrp-leader.exp: New.
2017-11-06 16:32:04 +00:00
Pedro Alves d1928160a3 Don't check termio.h and sgtty.h in common/common.m4 either
common/common.m4 still had checks for termio.h/sgtty.h that are stale
now.  Remove them.

gdb/ChangeLog:
2017-11-06  Pedro Alves  <palves@redhat.com>

	* common/common.m4 (GDB_AC_COMMON): No longer check termio.h nor
	sgtty.h.
	* config.in, configure: Regenerate.

gdb/gdbserver/ChangeLog:
2017-11-06  Pedro Alves  <palves@redhat.com>

	* config.in, configure: Regenerate.
2017-11-06 16:19:12 +00:00
Pedro Alves 6aa899ce25 Eliminate STOP_SIGNAL, use SIGTSTP directly
The STOP_SIGNAL macro was originally added for Convex Unix
(https://en.wikipedia.org/wiki/Convex_Computer).

In:

  git show 7a67dd45ca1c:gdb/m-convex.h

we see:

~~~
  /* Use SIGCONT rather than SIGTSTP because convex Unix occasionally
     turkeys SIGTSTP.  I think.  */

  #define STOP_SIGNAL SIGCONT
~~~

That's gdb-3.5, 1990...  In gdb/ChangeLog-3.x we see:

~~~
Tue Apr 18 13:43:37 1989  Randall Smith  (randy at apple-gunkies.ai.mit.edu)

        Various changes involved in 1) getting gdb to work on the convex,
	[...]
        Made whatever signal indicates a stop configurable (via macro
        STOP_SIGNAL).
        (main): Setup use of above as a signal handler.  Added check for
        "-nw" in args already processed.
        (command_line_input): SIGTSTP ==>STOP_SIGNAL.
~~~

Support for Convex Unix is long gone, and nothing else overrides
STOP_SIGNAL.  So just use SIGTSTP directly, removing a little
obfuscation.

(I don't really understand why we override [1] readline's SIGTSTP
handler (only) when reading scripts (and then fail to restore it
properly, assuming SIG_DFL...), but I'll leave that for another pass.

[1] - Actually, starting with readline 6.3, readline is no longer
installing its handlers while GDB is in control...)

gdb/ChangeLog:
2017-11-06  Pedro Alves  <palves@redhat.com>

	* event-top.c: Check SIGTSTP instead of STOP_SIGNAL thoughout.
	(async_init_signals): Adjust.
	(handle_stop_sig): Rename to ...
	(handle_sigtstp): ... this.
	(async_stop_sig): Rename to ...
	(async_sigtstp_handler): ... this, and delete STOP_SIGNAL !=
	SIGTSTP path.
	* event-top.h: Move signal.h include to the top.  Check SIGTSTP
	instead of STOP_SIGNAL thoughout.
	(handle_stop_sig): Rename to ...
	(handle_sigtstp): ... this.
	* top.c (command_line_input): Replace STOP_SIGNAL -> SIGTSTP.
2017-11-06 16:13:05 +00:00
Pedro Alves a94799ac1e Don't set terminal flags twice in a row
I find this odd 'set flags twice' ancient code and comment annoyingly
distracting.  It may well be that the reason for the double-set was
simply a copy/paste mistake, and that we've been doing this for
decades [1] for no good reason.  Let's just get rid of it, and if we
find a real reason, add it back with a comment explaining why it's
necessary.

[1] This double-set was already in gdb 2.4 / 1988, the oldest release
we have sources for, and imported in git.  From 'git show 7b4ac7e1ed
inflow.c':

   +void
   +terminal_inferior ()
   +{
   +  if (terminal_is_ours)   /*  && inferior_thisrun_terminal == 0) */
   +    {
   +      fcntl (0, F_SETFL, tflags_inferior);
   +      fcntl (0, F_SETFL, tflags_inferior);

The "is there a reason" comment was added in 1993, by:

  commit a88797b5ea
  Author:     Fred Fish <fnf@specifix.com>
  AuthorDate: Thu Aug 5 01:33:45 1993 +0000

gdb/ChangeLog:
2017-11-06  Pedro Alves  <palves@redhat.com>

	* inflow.c (child_terminal_inferior, child_terminal_ours_1): No
	longer set flags twice in row.
2017-11-06 16:12:25 +00:00
Pedro Alves 726e13564b Assume termios is available, remove support for termio and sgtty
This commit garbage collects the termio and sgtty support.

GDB's terminal handling code still has support for the old termio and
sgtty interfaces in addition to termios.  However, I think it's pretty
safe to assume that for a long, long time, Unix-like systems provide
termios.  GNU/Linux, Solaris, Cygwin, AIX, DJGPP, macOS and the BSDs
all have had termios.h for many years.  Looking around the web, I
found discussions about FreeBSD folks trying to get rid of old sgtty.h
a decade ago:

  https://lists.freebsd.org/pipermail/freebsd-hackers/2007-March/019983.html

So I think support for termio and sgtty in GDB is just dead code that
is never compiled anywhere and is just getting in the way.  For
example, serial_noflush_set_tty_state and the raw<->cooked concerns
mentioned in inflow.c only exist because of sgtty (see
hardwire_noflush_set_tty_state).

Regtested on GNU/Linux.

Confirmed that I can still build Solaris, DJGPP and AIX GDB and that
the resulting GDBs still include the termios.h-guarded code.
Confirmed mingw-w64 GDB still builds and skips the termios.h-guarded
code.

gdb/ChangeLog:
2017-11-06  Pedro Alves  <palves@redhat.com>

	* Makefile.in (SER_HARDWIRE): Update comment.
	(HFILES_NO_SRCDIR): Remove gdb_termios.h.
	* common/gdb_termios.h: Delete file.
	* common/job-control.c: Include termios.h and unistd.h instead of
	gdb_termios.h.
	(gdb_setpgid): Remove HAVE_TERMIOS || TIOCGPGRP preprocessor
	check.
	(have_job_control): Check HAVE_TERMIOS_H instead of HAVE_TERMIOS.
	Remove sgtty code.
	* configure.ac: No longer check for termio.h and sgtty.h.
	* configure: Regenerate.
	* inflow.c: Include termios.h instead of gdb_termios.h.  Replace
	PROCESS_GROUP_TYPE checks with HAVE_TERMIOS_H checks throughout.
	Replace PROCESS_GROUP_TYPE references with pid_t references
	throughout.
	(gdb_getpgrp): Delete.
	(set_initial_gdb_ttystate): Use tcgetpgrp instead of gdb_getpgrp.
	(child_terminal_inferior): Remove comment.  Remove sgtty code.
	(child_terminal_ours_1): Use tcgetpgrp directly instead of
	gdb_getpgrp.  Use serial_set_tty_state instead aof
	serial_noflush_set_tty_state.  Remove sgtty code.
	* inflow.h: Include unistd.h instead of gdb_termios.h.  Replace
	PROCESS_GROUP_TYPE check with HAVE_TERMIOS_H check.
	(inferior_process_group): Now returns pid_t.
	* ser-base.c (ser_base_noflush_set_tty_state): Delete.
	* ser-base.h (ser_base_noflush_set_tty_state): Delete.
	* ser-event.c (serial_event_ops): Update.
	* ser-go32.c (dos_noflush_set_tty_state): Delete.
	(dos_ops): Update.
	* ser-mingw.c (hardwire_ops, tty_ops, pipe_ops, tcp_ops): Update.
	* ser-pipe.c (pipe_ops): Update.
	* ser-tcp.c (tcp_ops): Update.
	* ser-unix.c: Include termios.h instead of gdb_termios.h.  Remove
	HAVE_TERMIOS checks.
	[HAVE_TERMIO] (struct hardwire_ttystate): Delete.
	[HAVE_SGTTY] (struct hardwire_ttystate): Delete.
	(get_tty_state, set_tty_state): Drop termio and sgtty code, and
	assume termios.
	(hardwire_noflush_set_tty_state): Delete.
	(hardwire_print_tty_state, hardwire_drain_output)
	(hardwire_flush_output, hardwire_flush_input)
	(hardwire_send_break, hardwire_raw, hardwire_setbaudrate)
	(hardwire_setstopbits, hardwire_setparity): Drop termio and sgtty
	code, and assume termios.
	(hardwire_ops): Update.
	(_initialize_ser_hardwire): Remove HAVE_TERMIOS check.
	* serial.c (serial_noflush_set_tty_state): Delete.
	* serial.h (serial_noflush_set_tty_state): Delete.
	(serial_ops::noflush_set_tty_state): Delete.

gdb/gdbserver/ChangeLog:
2017-11-06  Pedro Alves  <palves@redhat.com>

	* configure.ac: No longer check for termio.h and sgtty.h.
	* configure: Regenerate.
	* remote-utils.c: Include termios.h instead of gdb_termios.h.
	(remote_open): Check HAVE_TERMIOS_H instead of HAVE_TERMIOS.
	Remove termio and sgtty code.
2017-11-06 15:36:46 +00:00
Ulrich Weigand 1cfb73dbb7 Target FP: Merge doublest.c and dfp.c into target-float.c
Now that all target FP operations are performed via target-float.c,
this file remains the sole caller of functions in doublest.c and dfp.c.
Therefore, this patch merges the latter files into the former and
makes all their function static there.

gdb/ChangeLog:
2017-11-06  Ulrich Weigand  <uweigand@de.ibm.com>

	* Makefile.in (SFILES): Remove doublest.c and dfp.c.
	(HFILES_NO_SRCDIR): Remove doublest.h and dfp.h.
	(COMMON_OBS): Remove doublest.o and dfp.o.
	Do not build target-float.c (instead of doublest.c)
	with -Wformat-nonliteral.

	* doublest.c: Remove file.
	* doublest.h: Remove file.
	* dfp.c: Remove file.
	* dfp.h: Remove file.

	* target-float.c: Do not include "doublest.h" and "dfp.h".
	(DOUBLEST): Move here from doublest.h.
	(enum float_kind): Likewise.
	(FLOATFORMAT_CHAR_BIT): Likewise.
	(FLOATFORMAT_LARGEST_BYTES): Likewise.
	(floatformat_totalsize_bytes): Move here from doublest.c.  Make static.
	(floatformat_precision): Likewise.
	(floatformat_normalize_byteorder, get_field, put_field): Likewise.
	(floatformat_is_negative, floatformat_classify, floatformat_mantissa):
	Likewise.
	(host_float_format, host_double_format, host_long_double_format):
	Likewise.
	(floatformat_to_string, floatformat_from_string): Likewise.
	(floatformat_to_doublest): Likewise.  Also, inline the original
	convert_floatformat_to_doublest.
	(floatformat_from_doublest): Likewise.  Also, inline the original
	convert_floatformat_from_doublest.

	Include "dpd/decimal128.h", "dpd/decimal64.h", and "dpd/decimal32.h".
	(MAX_DECIMAL_STRING): Move here from dfp.c.
	(match_endianness): Likewise.
	(set_decnumber_context, decimal_check_errors): Likewise.
	(decimal_from_number, decimal_to_number): Likewise.
	(decimal_to_string, decimal_from_string): Likewise.  Make static.
	(decimal_from_longest, decimal_from_ulongest): Likewise.
	(decimal_to_longest): Likewise.
	(decimal_binop, decimal_is_zero, decimal_compare): Likewise.
	(decimal_convert): Likewise.
2017-11-06 16:04:03 +01:00
Ulrich Weigand b07e9c466e Target FP: Remove unused floating-point routines
This patch removes the following routines, which now have no remaining
users in GDB:
 - extract_typed_floating
 - store_typed_floating
 - convert_typed_floating
 - decimal_from_doublest
 - decimal_to_doublest
 - value_as_double
 - unpack_double
 - value_from_double
 - value_from_decfloat

This completes removal of DOUBLEST from all files except doublest.{c,h}
and target-float.c.

gdb/ChangeLog:
2017-11-06  Ulrich Weigand  <uweigand@de.ibm.com>

	* doublest.c: Do not include "gdbtypes.h".
	(extract_typed_floating): Remove.
	(store_typed_floating): Remove.
	(convert_typed_floating): Remove.
	* doublest.h (struct type): Remove.
	(DOUBLEST_PRINT_FORMAT): Remove.
	(DOUBLEST_SCAN_FORMAT): Remove.
	(extract_typed_floating): Remove.
	(store_typed_floating): Remove.
	(convert_typed_floating): Remove.

	* dfp.c (decimal_from_doublest): Remove.
	(decimal_to_doublest): Remove.
	* dfp.h: Do not include "doublest.h".
	(decimal_from_doublest): Remove.
	(decimal_to_doublest): Remove.

	* value.c: Do not include "doublest.h" and "dfp.h".
	(value_as_double): Remove.
	(unpack_double): Remove.
	(value_from_double): Remove.
	(value_from_decfloat): Remove.
	* value.h: Do not include "doublest.h".
	(value_as_double): Remove.
	(unpack_double): Remove.
	(value_from_double): Remove.
	(value_from_decfloat): Remove.
2017-11-06 16:02:33 +01:00
Ulrich Weigand 3b2ca8248c Target FP: Remove convert_typed_floating from tdep files
This patch mechanically replaces convert_typed_floating with the
equivalent target_float_convert throughout tdep files, to prepare
for the removal of doublest.{c,h}.

No functional change intended.

gdb/ChangeLog:
2017-11-06  Ulrich Weigand  <uweigand@de.ibm.com>

	* i386-tdep.c: Include "target-float.h".  Do not include "doublest.h".
	(i386_extract_return_value): Use target_float_convert.
	(i386_store_return_value): Likewise.
	* i387-tdep.c (i387_register_to_value): Use target_float_convert.
	(i387_value_to_register): Likewise.
	* ia64-tdep.c: Include "target-float.h".  Do not include "doublest.h".
	(ia64_register_to_value): Use target_float_convert.
	(ia64_value_to_register): Likewise.
	(ia64_extract_return_value): Likewise.
	(ia64_store_return_value): Likewise.
	(ia64_push_dummy_call): Likewise.
	* m68k-tdep.c: Include "target-float.h".
	(m68k_register_to_value): Use target_float_convert.
	(m68k_value_to_register): Likewise.
	(m68k_svr4_extract_return_value): Likewise.
	(m68k_svr4_store_return_value): Likewise.
	* ppc-sysv-tdep.c: Include "target-float.h".
	(ppc_sysv_abi_push_dummy_call): Use target_float_convert.
	(do_ppc_sysv_return_value): Likewise.
	(ppc64_sysv_abi_push_freg): Likewise.
	(ppc64_sysv_abi_return_value_base): Likewise.
	* rs6000-aix-tdep.c: Include "target-float.h".
	(rs6000_push_dummy_call): Use target_float_convert.
	(rs6000_return_value): Likewise.
	* rs6000-lynx178-tdep.c: Include "target-float.h".
	(rs6000_lynx178_push_dummy_call): Use target_float_convert.
	(rs6000_lynx178_return_value): Likewise.
	* rs6000-tdep.c: Include "target-float.h".  Do not include "doublest.h".
	(rs6000_register_to_value): Use target_float_convert.
	(rs6000_value_to_register): Likewise.
	* arm-tdep.c: Include "target-float.h".  Do not include "doublest.h".
	(arm_extract_return_value): Use target_float_convert.
	(arm_store_return_value): Likewise.
	* sh-tdep.c: Include "target-float.h".  Do not include "doublest.h".
	(sh_register_convert_to_virtual): Use target_float_convert.
	(sh_register_convert_to_raw): Likewise.
	* sh64-tdep.c: Include "target-float.h".
	(sh64_extract_return_value): Use target_float_convert.
	(sh64_register_convert_to_virtual): Likewise.
	(sh64_register_convert_to_raw): Likewise.  Fix argument types.
2017-11-06 16:01:37 +01:00
Ulrich Weigand 14ad931172 Target FP: Handle interfaces to scripting languages
The last remaing use for DOUBLEST is in the code that interfaces to the
scripting languages (Python and Guile).  The problem here is that we
expose interfaces to convert a GDB value to and from native values of
floating-point type in those languages, and those by definition use
the host floating-point format.

While we cannot completely eliminate conversions to/from the host
floating-point format here, we still need to get rid of the uses
of value_as_double / value_from_double, since those will go away.

This patch implements two new target-float.c routine:
 - target_float_to_host_double
 - target_float_from_host_double
which convert to/from a host "double".  Those should only ever be
used where a host "double" is mandated by an external interface.

gdb/ChangeLog:
2017-11-06  Ulrich Weigand  <uweigand@de.ibm.com>

	* target-float.c (floatformat_to_host_double): New function.
	(floatformat_from_host_double): Likewise.
	(target_float_to_host_double): Likewise.
	(target_float_from_host_double): Likewise.
	* target-float.h (target_float_to_host_double): Add prototype.
	(target_float_from_host_double): Likewise.

	* guile/scm-value.c: Include "target-float.h".
	(gdbscm_value_to_real): Use target_float_to_host_double.
	Handle integer source values via value_as_long.
	* guile/scm-math.c: Include "target-float.h".  Do not include
	"doublest.h", "dfp.h", and "expression.h".
	(vlscm_convert_typed_number): Use target_float_from_host_double.
	(vlscm_convert_number): Likewise.

	* python/py-value.c (valpy_float): Use target_float_to_host_double.
	(convert_value_from_python): Use target_float_from_host_double.
2017-11-06 16:00:47 +01:00
Ulrich Weigand 50eff16b85 Target FP: Perform Ada fixed-point scaling in target format
One of the few still remaining uses of DOUBLEST in GDB is the Ada front-end
code that handles scaling of Ada fixed-point types.  The target format for
those types is some integer format; to convert those values to standard
floating-point representation, that integer needs to be multiplied by a
rational scale factor, given as a pair of numerator and denominator.

To avoid having to deal with long integer arithmetic, the current Ada
front-end code currently performs those scaling operations in host
DOUBLEST arithmetic.  To eliminate this use of DOUBLEST, this patch
changes the front-end to instead perform those operations in the
*target* floating-point format (chosing to use the target "long double").

The implementation is mostly straight-forward, using value_cast and
value_binop to perform the target operations.

Scanning in the scale numerator and denominator is now done into
a host "long long" instead of a DOUBLEST, which should be large
enough to hold all possible values.  (Otherwise, this can be replaced
by target-format target_float_from_string operations as well.)

Printing fixed-point types and values should be completely unchanges,
using target_float_to_string with the same format strings as current code.

gdb/ChangeLog:
2017-11-06  Ulrich Weigand  <uweigand@de.ibm.com>

	* ada-lang.c (cast_to_fixed): Reimplement in target arithmetic.
	(cast_from_fixed): Likewise.
	(ada_scaling_type): New function.
	(ada_delta): Return value instead of DOUBLEST.  Perform target
	arithmetic instead of host arithmetic.
	(scaling_factor): Rename to ...
	(ada_scaling_factor) ... this.  Make non-static.  Return value instead
	of DOUBLEST.  Perform target arithmetic instead of host arithmetic.
	(ada_fixed_to_float): Remove.
	(ada_float_to_fixed): Remove.
	* ada-lang.h (ada_fixed_to_float): Remove.
	(ada_float_to_fixed): Remove.
	(ada_delta): Return value instead of DOUBLEST.
	(ada_scaling_factor): Add prototype.

	* ada-typeprint.c: Include "target-float.h".
	(print_fixed_point_type): Perform target arithmetic instead of
	host arithmetic.
	* ada-valprint.c: Include "target-float.h".
	(ada_val_print_num): Perform target arithmetic instead of
	host arithmetic for fixed-point types.
2017-11-06 16:00:12 +01:00
Ulrich Weigand 66c02b9ed1 Target FP: Add binop and compare routines to target-float.{c,h}
This patch adds the following target floating-point routines:
 - target_float_binop
 - target_float_compare
which call the equivalent decimal_ routines to handle decimal FP,
and call helper routines that currently still go via DOUBLEST to
handle binary FP (derived from current valarith.c code).

These routines are used to handle both binary and decimal FP types
in scalar_binop, value_equal, and value_less, mostly following the
method currently used for decimal FP.  The existing value_args_as_decimal
helper is renamed to value_args_as_target_float and extended to handle
both binary and decimal types.

The unary operations value_pos and value_neg are also simplified,
the former by using a simple copy for all scalar types, the latter
by using value_binop (... BINOP_SUB) to implement negation as
subtraction from zero.

ChangeLog:
2017-11-06  Ulrich Weigand  <uweigand@de.ibm.com>

	* target-float.c: Include <math.h>.
	(floatformat_binop): New function.
	(floatformat_compare): Likewise.
	(target_float_binop): Likewise.
	(target_float_compare): Likewise.
	* target-float.h: Include "expression.h".
	(target_float_binop): Add prototype.
	(target_float_compare): Likewise.

	* valarith.c: Do not include "doublest.h" and "dfp.h".
	Include "common/byte-vector.h".
	(value_args_as_decimal): Remove, replace by ...
	(value_args_as_target_float): ... this function.  Handle both
	binary and decimal target floating-point formats.
	(scalar_binop): Handle both binary and decimal FP using
	value_args_as_target_float and target_float_binop.
	(value_equal): Handle both binary and decimal FP using
	value_args_as_target_float and target_float_compare.
	(value_less): Likewise.
	(value_pos): Handle all scalar types as simple copy.
	(value_neg): Handle all scalar types via BINOP_SUB from 0.
	* dfp.c (decimal_binop): Throw error instead of internal_error
	when called with an unsupported operation code.
2017-11-06 15:58:46 +01:00
Ulrich Weigand 50637b26f8 Target FP: Add conversion routines to target-float.{c,h}
This patch adds the following conversion routines:
 - target_float_to_longest
 - target_float_from_longest
 - target_float_from_ulongest
 - target_float_convert
which call the equivalent decimal_ routines to handle decimal FP,
and call helper routines that currently still go via DOUBLEST to
handle binary FP.

The target_float_convert routine not only handles BFP<->BFP and
DFP<->DFP conversions, but also BFP<->DFP, which are implemented
by converting to a string and back.

These helpers are used in particular to implement conversion
from and to FP in value_cast, without going through DOUBLEST there.
In order to implement this for the FP<-integer case, the
pack_long / pack_unsigned_long routines are extended to support
floating-point values as output (thereby allowing use of
value_from_[u]longest with a floating-point target type).

This latter change also allows simplification of value_one.

gdb/ChangeLog:
2017-11-06  Ulrich Weigand  <uweigand@de.ibm.com>

	* target-float.c (floatformat_to_longest): New function.
	(floatformat_from_longest, floatformat_from_ulongest): Likewise.
	(floatformat_convert): Likewise.
	(target_float_to_longest): Likewise.
	(target_float_from_longest, target_float_from_ulongest): Likewise.
	(target_float_convert): Likewise.
	* target-float.h (target_float_to_longest): Add prototype.
	(target_float_from_longest, target_float_from_ulongest): Likewise.
	(target_float_convert): Likewise.

	* value.c (unpack_long): Use target_float_to_longest.
	(pack_long): Allow FP types.  Use target_float_from_longest.
	(pack_unsigned_long): Likewise using target_float_from_ulongest.
	* valops.c: Include "target-float.h".  Do not include "dfp.h".
	(value_cast): Handle conversions to FP using target_float_convert,
	value_from_ulongest, and value_from_longest.
	(value_one): Use value_from_longest for FP types as well.
2017-11-06 15:57:31 +01:00
Ulrich Weigand f69fdf9bca Target FP: Add string routines to target-float.{c,h}
This adds target_float_to_string and target_float_from_string,
which dispatch to the corresponding floatformat_ or decimal_ routines.

Existing users of those routines are changed to use the new
target-float routines instead (most of those places already handle
both binary and decimal FP).

In addition, two other places are changes to use target_float_from_string:

- define_symbol in stabsread.c, when parsing a floating-point literal
  from stabs debug info

- gdbarch-selftest.c when initializing a target format values (to
  eliminate use of DOUBLEST there).

gdb/ChangeLog:
2017-11-06  Ulrich Weigand  <uweigand@de.ibm.com>

	* target-float.c (target_float_to_string): New function.
	(target_float_from_string): New function.
	* target-float.h (target_float_to_string): Add prototype.
	(target_float_from_string): Add prototype.

	* valprint.c: Include "target-float.h".  Do not include
	"doublest.h" and "dfp.h".
	(print_floating): Use target_float_to_string.
	* printcmd.c: Include "target-float.h".  Do not include "dfp.h".
	(printf_floating): Use target_float_to_string.
	* i387-tdep.c: Include "target-float.h".  Do not include "doublest.h".
	(print_i387_value): Use target_float_to_string.
	* mips-tdep.c: Include "target-float.h".
	(mips_print_fp_register): Use target_float_to_string.
	* sh64-tdep.c: Include "target-float.h".
	(sh64_do_fp_register): Use target_float_to_string.

	* parse.c: Include "target-float.h".  Do not include
	"doublest.h" and "dfp.h".
	(parse_float): Use target_float_from_string.
	* stabsread.c: Include "target-float.h".  Do not include "doublest.h".
	(define_symbol): Use target_float_from_string.
	* gdbarch-selftests.c: Include "target-float.h".
	(register_to_value_test): Use target_float_from_string.
2017-11-06 15:56:35 +01:00
Ulrich Weigand 701000146a Target FP: Introduce target-float.{c,h}
This patch introduces the new set of target floating-point handling routines
in target-float.{c,h}.  In the end, the intention is that this file will
contain support for all operations in target FP format, fully replacing
both the current doublest.{c,h} and dfp.{c,h}.

To begin with, this patch only adds a target_float_is_zero routine,
which handles the equivalent of decimal_is_zero for both binary and
decimal FP.  For the binary case, to avoid conversion to DOUBLEST,
this is implemented using the floatformat_classify routine.

However, it turns out that floatformat_classify actually has a bug
(it was not used to check for zero before), so this is fixed as well.

The new routine is used in both value_logical_not and valpy_nonzero.

There is one extra twist: the code previously used value_as_double
to convert to DOUBLEST and then compare against zero.  That routine
performs an extra task: it detects invalid floating-point values
and raises an error.  In any place where value_as_double is removed
in favor of some target-float.c routine, we need to replace that check.

To keep this check centralized in one place, I've added a new routine
is_floating_value, which returns a boolean determining whether a
value's type is floating point (binary or decimal), and if so, also
performs the validity check.  Since we need to check whether a value
is FP before calling any of the target-float routines anyway, this
seems a good place to add the check without much code size overhead.

In some places where we only want to check for floating-point types
and not perform a validity check (e.g. for the *output* of an operation),
we can use the new is_floating_type routine (in gdbarch) instead.

The validity check itself is done by a new target_float_is_valid
routine in target-float, encapsulating floatformat_is_valid.

ChangeLog:
2017-11-06  Ulrich Weigand  <uweigand@de.ibm.com>

	* Makefile.c (SFILES): Add target-float.c.
	(HFILES_NO_SRCDIR): Add target-float.h.
	(COMMON_OBS): Add target-float.o.
	* target-float.h: New file.
	* target-float.c: New file.

	* doublest.c (floatformat_classify): Fix detection of float_zero.

	* gdbtypes.c (is_floating_type): New function.
	* gdbtypes.h (is_floating_type): Add prototype.

	* value.c: Do not include "floatformat.h".
	(unpack_double): Use target_float_is_valid.
	(is_floating_value): New function.
	* value.h (is_floating_value): Add prototype-

	* valarith.c: Include "target-float.h".
	(value_logical_not): Use target_float_is_zero.

	* python/py-value.c: Include "target-float.h".
	(valpy_nonzero): Use target_float_is_zero.
2017-11-06 15:56:02 +01:00
Tom Tromey ab4b1c4699 Use std::vector in h8300-tdep.c
This changes h8300-tdep.c to use std::vector, allowing the removal of
a cleanup.

gdb/ChangeLog
2017-11-04  Tom Tromey  <tom@tromey.com>

	* h8300-tdep.c (h8300_push_dummy_call): Use std::vector.
2017-11-04 10:27:20 -06:00
Tom Tromey 454dafbdf2 Introduce gdb_breakpoint_up
This introduces gdb_breakpoint_up, a unique_ptr typedef that owns a
breakpoint.  It then changes set_momentary_breakpoint to return a
gdb_breakpoint_up and fixes up the fallout.  This then allows the
removal of make_cleanup_delete_breakpoint.

Once breakpoints are fully C++-ified, this typedef can be removed in
favor of a plain std::unique_ptr.

gdb/ChangeLog
2017-11-04  Tom Tromey  <tom@tromey.com>

	* breakpoint.c (set_momentary_breakpoint): Return
	breakpoint_up.
	(until_break_command): Update.
	(new_until_break_fsm): Change argument types to
	breakpoint_up.
	(set_momentary_breakpoint_at_pc): Return breakpoint_up.
	(do_delete_breakpoint_cleanup, make_cleanup_delete_breakpoint):
	Remove.
	* infcmd.c (finish_forward): Update.
	* breakpoint.h (set_momentary_breakpoint)
	(set_momentary_breakpoint_at_pc): Return breakpoint_up.
	(make_cleanup_delete_breakpoint): Remove.
	(struct breakpoint_deleter): New.
	(breakpoint_up): New typedef.
	* infrun.c (insert_step_resume_breakpoint_at_sal_1): Update.
	(insert_exception_resume_breakpoint): Update.
	(insert_exception_resume_from_probe): Update.
	(insert_longjmp_resume_breakpoint): Update.
	* arm-linux-tdep.c (arm_linux_copy_svc): Update.
	* elfread.c (elf_gnu_ifunc_resolver_stop): Update.
	* infcall.c (call_function_by_hand_dummy): Update
2017-11-04 10:27:20 -06:00
Tom Tromey 331b71e5ee Use unique_xmalloc_ptr in c_type_print_base
This changes c_type_print_base to use unique_xmalloc_ptr, removing a
cleanup.

gdb/ChangeLog
2017-11-04  Tom Tromey  <tom@tromey.com>

	* c-typeprint.c (c_type_print_base): Use gdb::unique_xmalloc_ptr.
2017-11-04 10:27:19 -06:00
Tom Tromey 9f584b37e3 Remove cleanups from linux-tdep.c
This removes some cleanups from linux-tdep.c, replacing them with
def_vector or byte_vector as appropriate.

gdb/ChangeLog
2017-11-04  Tom Tromey  <tom@tromey.com>

	* linux-tdep.c (linux_core_info_proc_mappings): Use
	gdb::def_vector.
	(linux_get_siginfo_data): Return gdb::byte_vector.  Remove
	"size" argument.
	(linux_corefile_thread): Update.
	(linux_make_corefile_notes): Remove unused variable.
2017-11-04 10:27:19 -06:00
Tom Tromey 779bc38eca Use gdb::byte_vector in ppc-linux-tdep.c
This removes a cleanup from ppc-linux-tdep.c, replacing it with
gdb::byte_vector.

gdb/ChangeLog
2017-11-04  Tom Tromey  <tom@tromey.com>

	* ppc-linux-tdep.c (ppc_linux_get_syscall_number): Use
	gdb::byte_vector.
2017-11-04 10:27:18 -06:00
Tom Tromey ed2b3126d1 Remove make_cleanup_free_objfile
This replaces make_cleanup_free_objfile with std::unique_ptr.

gdb/ChangeLog
2017-11-04  Tom Tromey  <tom@tromey.com>

	* objfiles.c (do_free_objfile_cleanup): Remove.
	* compile/compile-object-load.c (compile_object_load): Update.
	* objfiles.h (make_cleanup_free_objfile): Remove.
2017-11-04 10:27:18 -06:00
Tom Tromey 7f6743fd09 Use gdb::def_vector in sparc64-tdep.c
This removes a cleanup from sparc64-tdep.c, replacing it with
gdb::def_vector.

gdb/ChangeLog
2017-11-04  Tom Tromey  <tom@tromey.com>

	* sparc64-tdep.c (do_examine): Use gdb::def_vector.
	(adi_read_versions): Change "tags" to "gdb_byte *".
	(adi_print_versions): Likewise.
2017-11-04 10:27:17 -06:00
Tom Tromey c80049d3b6 Replace start_rbreak_breakpoints and end_rbreak_breakpoints
This replaces start_rbreak_breakpoints and end_rbreak_breakpoints with
a new scoped class.  This allows the removal of a cleanup.

This also fixes an earlier memory leak regression, by changing
"string" to be a std::string.

gdb/ChangeLog
2017-11-04  Tom Tromey  <tom@tromey.com>

	* breakpoint.c
	(scoped_rbreak_breakpoints::scoped_rbreak_breakpoints): Rename
	from start_rbreak_breakpoints.
	(scoped_rbreak_breakpoints): Rename from end_rbreak_breakpoints.
	* breakpoint.h (class scoped_rbreak_breakpoints): New.
	(start_rbreak_breakpoints, end_rbreak_breakpoints): Remove.
	* symtab.c (do_end_rbreak_breakpoints): Remove.
	(rbreak_command): Use scoped_rbreak_breakpoints, std::string.
2017-11-04 10:27:17 -06:00
Tom Tromey 167b0be1b5 Remove directive-searched cleanups
This removes a few cleanups related to the "searched" field in
struct using_direct, replacing these with scoped_restore.

gdb/ChangeLog
2017-11-04  Tom Tromey  <tom@tromey.com>

	* cp-namespace.c (reset_directive_searched): Remove.
	(cp_lookup_symbol_via_imports): Use scoped_restore.
	* cp-support.c (reset_directive_searched): Remove.
	(make_symbol_overload_list_using): Use scoped_restore.
	* d-namespace.c (d_lookup_symbol_imports): Use scoped_restore.
	(reset_directive_searched): Remove.
2017-11-04 10:27:16 -06:00
Tom Tromey 5eae7aeaf7 Use unique_xmalloc_ptr in find_separate_debug_file_by_debuglink
This changes find_separate_debug_file_by_debuglink to use
unique_xmalloc_ptr, removing some cleanups.

gdb/ChangeLog
2017-11-04  Tom Tromey  <tom@tromey.com>

	* symfile.c (find_separate_debug_file_by_debuglink): Use
	unique_xmalloc_ptr.
2017-11-04 10:27:16 -06:00
Tom Tromey c6bcad5ffc Use std::vector in compile-loc2c.c
This changes compile-loc2c.c to use std::vector, removing some
cleanups.

gdb/ChangeLog
2017-11-04  Tom Tromey  <tom@tromey.com>

	* compile/compile-loc2c.c (compute_stack_depth_worker): Change
	type of "info".
	(compute_stack_depth): Likewise.
	(do_compile_dwarf_expr_to_c): Use std::vector.
2017-11-04 10:27:15 -06:00
Tom Tromey 20dcd8cae7 Remove cleanups from link_callbacks_einfo
This removes a cleanup from link_callbacks_einfo by using std::string.

gdb/ChangeLog
2017-11-04  Tom Tromey  <tom@tromey.com>

	* compile/compile-object-load.c (link_callbacks_einfo): Use
	std::string.
2017-11-04 10:27:15 -06:00
Tom Tromey 33c7c59df0 Replace really_free_pendings with a scoped_ class
This introduces scoped_free_pendings, and changes users of
really_free_pendings to use it instead, removing some clenaups.

I tried to examine the affected code to ensure there aren't dangling
cleanups in the vicinity.

gdb/ChangeLog
2017-11-04  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (process_full_comp_unit, process_full_type_unit):
	Use scoped_free_pendings.
	* dbxread.c (dbx_symfile_read, dbx_psymtab_to_symtab_1): Use
	scoped_free_pendings.
	* xcoffread.c (xcoff_psymtab_to_symtab_1): Use scoped_free_pendings.
	(xcoff_initial_scan): Likewise.
	* buildsym.c (reset_symtab_globals): Update comment.
	(scoped_free_pendings): Rename from really_free_pendings.
	(prepare_for_building): Update comment.
	(buildsym_init): Likewise.
	* buildsym.h (class scoped_free_pendings): New class.
	(really_free_pendings): Don't declare.
2017-11-04 10:27:15 -06:00
Ulrich Weigand 67fa57cfa5 Fix regression on ARM after Target FP patches
Commit edd079d9f6 exposed a pre-existing bug
in convert_doublest_to_floatformat.  In the specific case of converting
a zero value to a floatformat using a "special" byteorder (i.e. neither
floatformat_little nor floatformat_big), the output buffer was actually
left uninitialized.

gdb/ChangeLog:
2017-11-03  Ulrich Weigand  <uweigand@de.ibm.com>

	* doublest.c (convert_doublest_to_floatformat): Fix uninitialized
	output when converting a zero value to a special byteorder format.
2017-11-03 16:07:23 +01:00
Yao Qi 50ab6ace38 Skip gdb.mi/list-thread-groups-available.exp if no xml support
I see the following test fail in gdb (configured --with-expat=no),

-list-thread-groups --available^M
&"warning: Can not parse XML OS data; XML support was disabled at compile time\n"^M
^error,msg="Can not fetch data now."^M
(gdb) ^M
FAIL: gdb.mi/list-thread-groups-available.exp: list available thread groups (unexpected output)

This patch skips it if XML parsing in GDB is disabled, like what you did
in gdb.mi/mi-info-os.exp.

gdb/testsuite:

2017-11-03  Yao Qi  <yao.qi@linaro.org>

	* gdb.mi/list-thread-groups-available.exp: Skip it if XML parsing
	in GDB is disabled.
2017-11-03 12:53:53 +00:00
Yao Qi 8e68731c8a Skip gdb.python/py-thrhandle.exp if python is not enabled.
gdb/testsuite:

2017-11-03  Yao Qi  <yao.qi@linaro.org>

	* gdb.python/py-thrhandle.exp: Skip it if python is not
	enabled.
2017-11-03 10:41:03 +00:00
Yao Qi f26ae15b47 Construct readonly regcache without address space
The address space is useless to readonly regcache, so this patch removes
the parameter to construct readonly regcache.

address_space was added in regcache by 6c95b8d, but for read-write
regcache.  regcache::aspace is used for various breakpoint/watchpoint
checking, and these regcache are not read-only regcache.

gdb:

2017-11-02  Yao Qi  <yao.qi@linaro.org>

	* frame.c (do_frame_register_read): Remove aspace.
	* jit.c (jit_frame_sniffer): Likwise.
	* ppc-linux-tdep.c (ppu2spu_sniffer): Likewise.
	* regcache.c (regcache::regcache): Pass nullptr.
	(regcache_print): Caller updated.
	* regcache.h (regcache::regcache): Remove one constructor
	parameter aspace.
2017-11-02 15:15:42 +00:00
Yao Qi 6c6e9412e9 const-fy regcache::m_readonly_p
gdb:

2017-11-02  Yao Qi  <yao.qi@linaro.org>

	* regcache.h (regcache) <m_readonly_p>: Change it to const bool.
2017-11-02 15:15:42 +00:00
Yao Qi 8b86c95921 const-fy regcache::m_aspace
regcache::m_aspace is a const, never changed during the lifetime of
regcache object.  The address_space object is a const object too.

gdb:

2017-11-02  Yao Qi  <yao.qi@linaro.org>

	* breakpoint.c (insert_single_step_breakpoints): Update.
	* frame.c (struct frame_info) <aspace>: Add const.
	(frame_save_as_regcache): Add const.
	(get_frame_address_space): Return const address_space *.
	* frame.h (get_frame_address_space): Update declaration.
	* infrun.c (struct step_over_info) <aspace>: Add const.
	(set_step_over_info): Make aspace const.
	(displaced_step_prepare_throw): Change variable const.
	(resume): Likewise.
	(proceed): Likewise.
	(adjust_pc_after_break): Likewise.
	(save_waitstatus): Likewise.
	(handle_signal_stop): Likewise.
	(keep_going_pass_signal): Likewise.
	* jit.c (jit_frame_sniffer): Add const.
	* mips-tdep.c (mips_single_step_through_delay): Likewise.
	* ppc-linux-tdep.c (ppu2spu_sniffer): Likewise.
	* record-full.c (record_full_wait_1): Likewise.
	* regcache.c (regcache::regcache): Change parameter to const.
	* regcache.h (regcache::regcache): Likewise.
	(regcache::aspace): Return const address_space *.
	(regcache) <m_aspace>: Add const.
2017-11-02 15:15:42 +00:00
Yao Qi a01bda5221 s/get_regcache_aspace (regcache)/regcache->aspace ()/g
and remove get_regcache_aspace.

gdb:

2017-11-02  Yao Qi  <yao.qi@linaro.org>

	* darwin-nat.c (cancel_breakpoint): Use regcache->aspace ().
	* frame.c (create_sentinel_frame): Likewise.
	* infrun.c (displaced_step_prepare_throw): Likewise.
	(resume): Likewise.
	(thread_still_needs_step_over_bp): Likewise.
	(proceed): Likewise.
	(do_target_wait): Likewise.
	(adjust_pc_after_break): Likewise.
	(handle_syscall_event): Likewise.
	(save_waitstatus): Likewise.
	(handle_inferior_event_1): Likewise.
	(handle_signal_stop): Likewise.
	(keep_going_pass_signal): Likewise.
	* linux-nat.c (status_callback): Likewise.
	(save_stop_reason): Likewise.
	(resume_stopped_resumed_lwps): Likewise.
	* record-full.c (record_full_exec_insn): Likewise.
	(record_full_wait_1): Likewise.
	* regcache.c (get_regcache_aspace): Remove.
	* regcache.h (get_regcache_aspace): Remove.
2017-11-02 15:15:41 +00:00
Yao Qi d999647bc4 Remove regcache_descr::nr_raw_registers
struct regcache_descr has fields nr_raw_registers and gdbarch, and
nr_raw_registers can be got via gdbarch_num_regs (gdbarch), so it looks
nr_raw_registers is redundant.  This patch removes it and adds a protected
method num_raw_registers.

gdb:

2017-11-02  Yao Qi  <yao.qi@linaro.org>

	* regcache.c (struct regcache_descr) <nr_raw_registers>: Remove.
	(init_regcache_descr): Use gdbarch_num_regs.
	(regcache::regcache): Likewise.
	(regcache::get_register_status): Likewise.
	(regcache::assert_raw_regnum): Likewise.
	(regcache::cooked_read): Likewise.
	(regcache::cooked_read_value): Likewise.
	(regcache::cooked_write): Likewise.
	(regcache::dump): Likewise.
	(regcache::num_raw_registers): New method.
	* regcache.h (class regcache) <num_raw_registers>: New.
2017-11-02 15:15:41 +00:00
Yao Qi 4e888c281c New method regcache::assert_regnum
class regcache has some methods checking the range of register number,
this patch is to move it in a new method assert_regnum.

gdb:

2017-11-02  Yao Qi  <yao.qi@linaro.org>

	* regcache.c (regcache::assert_regnum): New method.
	(regcache::invalidate): Call assert_regnum.
	(regcache::raw_update): Likewise.
	(regcache::raw_write): Likewise.
	(regcache::raw_read_part): Likewise.
	(regcache::raw_write_part): Likewise.
	(regcache::raw_supply): Likewise.
	(regcache::raw_supply_integer): Likewise.
	(regcache::raw_supply_zeroed): Likewise.
	(regcache::raw_collect): Likewise.
	(regcache::raw_collect_integer): Likewise.
	* regcache.h (regcache::assert_regnum): Declare.
2017-11-02 15:15:41 +00:00
Yao Qi 2e1b49b32a Remove code wrapped by "#if 0"
These code wrapped by "#if 0" was added by af030b9a, which added the new
command to dump registers in 2002.  The email didn't mention this either
https://sourceware.org/ml/gdb-patches/2002-08/msg00227.html  It was there
for 15 years, and nobody needs it, so we can remove it.

gdb:

2017-11-02  Yao Qi  <yao.qi@linaro.org>

	* regcache.c (regcache::dump): Remove code.
2017-11-02 15:15:41 +00:00
Yao Qi 6c5218dfdb Remove regcache_descr fields sizeof_raw_register_status and sizeof_cooked_register_status
struct regcache_descr has two fields sizeof_raw_register_status
and sizeof_cooked_register_status, but they equal to nr_cooked_registers
and nr_raw_registers respectively, so this patch removes them.

gdb:

2017-11-02  Yao Qi  <yao.qi@linaro.org>

	* regcache.c (struct regcache_descr) <sizeof_raw_register_status>:
	Remove.
	<sizeof_cooked_register_status>: Remove.
	(init_regcache_descr): Update.
	(regcache::regcache): Use nr_cooked_registers and nr_raw_registers.
	(regcache::save): Likewise.
	(regcache::dump): Likewise.
2017-11-02 15:05:12 +00:00
James Bowman dcc31d286a FT32: support for FT32B processor - part 2/2
FT32B is a new FT32 family member.
This patch adds support for the compressed instructions to gdb and sim.

gdb/ChangeLog:
        * ft32-tdep.c (ft32_fetch_instruction): New function.
        (ft32_analyze_prologue): Use ft32_fetch_instruction().

sim/ChangeLog:
        * ft32/interp.c (step_once): Add ft32 shortcode decoder.
2017-11-01 18:36:51 -07:00
Simon Marchi 3a87ae656c Use console uiout when executing breakpoint commands
As reported here

  https://sourceware.org/ml/gdb/2017-10/msg00020.html

the output of certain commands, like backtrace, doesn't appear anywhere
when it is run as a breakpoint command and when using MI.

The reason is that the current_uiout is set to the mi_ui_out while these
commands run, whereas we want the output as CLI output.  Some commands
like "print" work, because they use printf_filtered (gdb_stdout, ...)
directly, bypassing the current ui_out.

The fix I did is to force setting the cli_uiout as the current_uiout
when calling execute_control_command.  I am not sure if this is the
right way to fix the problem, comments about the approach would be
appreciated.

I enhanced gdb.mi/mi-break.exp to test the backtrace command.

Regtested on the buildbot.

gdb/ChangeLog:

	* cli/cli-script.c (execute_control_command): Rename to ...
	(execute_control_command_1): ... this.
	(execute_control_command): New function.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-break.exp (test_breakpoint_commands): Test backtrace
	as a breakpoint command.
2017-10-31 21:34:24 -04:00
Simon Marchi 09b847f3a8 tracepoint: Remove unnecessary const_cast
We are passing a const char * to a const char * parameter, the
const_cast is not necessary.

gdb/ChangeLog:

	* tracepoint.c (tfind_command): Remove const_cast.
2017-10-31 14:29:25 -04:00
Mike Gulick f871c4853a gdb/Makefile.in: fix 'make tags' failure
'make tags' fails with the following error:

  make[2]: Entering directory '/local-ssd/mgulick/gdb/git/binutils-gdb/gdb'
  make[2]: *** No rule to make target 'gdb.h', needed by 'TAGS'.  Stop.
  make[2]: Leaving directory '/local-ssd/mgulick/gdb/git/binutils-gdb/gdb'

The file gdb/gdb.h was removed in commit
65630365f7.

gdb/ChangeLog:

2017-10-30  Mike Gulick  <mgulick@mathworks.com>

	* Makefile.in (HFILES_NO_SRCDIR): Remove reference to gdb.h.
2017-10-30 21:30:10 -04:00
Simon Marchi b020ff8074 Introduce in_inclusive_range, fix -Wtautological-compare warnings
When compiling with clang or gcc 8, we see warnings like this:

/home/emaisin/src/binutils-gdb/gdb/arm-tdep.c:10013:13: error: comparison of 0 <= unsigned expression is always true [-Werror,-Wtautological-compare]
      if (0 <= insn_op1 && 3 >= insn_op1)
          ~ ^  ~~~~~~~~
/home/emaisin/src/binutils-gdb/gdb/arm-tdep.c:11722:20: error: comparison of unsigned expression >= 0 is always true [-Werror,-Wtautological-compare]
      else if (opB >= 0 && opB <= 2)
               ~~~ ^  ~

This is because an unsigned integer (opB in this case) will always be >=
0.  It is still useful to keep both bounds of the range in the
expression, even if one is at the edge of the data type range.  This
patch introduces a utility function in_inclusive_range that gets rid of
the warning while conveying that we are checking for a range.

Tested by rebuilding.

gdb/ChangeLog:

	* common/common-utils.h (in_inclusive_range): New function.
	* arm-tdep.c (arm_record_extension_space): Use
	in_inclusive_range.
	(thumb_record_ld_st_reg_offset): Use in_inclusive_range.
	* cris-tdep.c (cris_spec_reg_applicable): Use
	in_inclusive_range.
2017-10-30 14:27:38 -04:00
Pedro Alves 1b81856f5b remote.c, QCatchSyscalls: Build std::string instead of unique_xmalloc_ptr
Simplify the code a little bit using std::string + string_appendf.

gdb/ChangeLog:
2017-10-30  Pedro Alves  <palves@redhat.com>
	    Simon Marchi <simon.marchi@ericsson.com>

	* remote.c (remote_set_syscall_catchpoint): Build a std::string
	instead of a gdb::unique_xmalloc_ptr, using string_appendf.
2017-10-30 11:41:34 +00:00
Pedro Alves 31b833b3ea Introduce string_appendf/string_vappendf
string_appendf is like string_printf, but instead of allocating a new
string, it appends to an existing string.  This allows reusing a
std::string's memory buffer across several calls, for example.

gdb/ChangeLog:
2017-10-30  Pedro Alves  <palves@redhat.com>

	* common/common-utils.c (string_appendf, string_vappendf): New
	functions.
	* common/common-utils.h (string_appendf, string_vappendf): New
	declarations.
	* unittests/common-utils-selftests.c (string_appendf_func)
	(test_appendf_func, string_vappendf_wrapper, string_appendf_tests)
	(string_vappendf_tests): New functions.
	(_initialize_common_utils_selftests): Register "string_appendf" and
	"string_vappendf tests".
2017-10-30 11:41:34 +00:00
Pedro Alves 4a25033455 Merge/shared string_printf and string_vprintf unit tests
Merge the string_printf and string_vprintf tests, running them all
against both functions.

gdb/ChangeLog:
2017-10-30  Pedro Alves  <palves@redhat.com>

	* unittests/common-utils-selftests.c (format_func): New typedef.
	(string_printf_tests, string_vprintf_tests): Tests factored out
	and merged to ...
	(test_format_func): ... this new function.
	(string_printf_tests, string_vprintf_tests): Reimplement on top of
	test_format_func.
2017-10-30 11:41:34 +00:00
Simon Marchi 16c5c17e43 darwin-nat: Remove gdb.h include
gdb.h has been removed in

  Eliminate catch_exceptions/catch_exceptions_with_msg
  65630365f7

Remove the include in darwin-nat.c.  Tested by rebuilding.

gdb/ChangeLog:

	* darwin-nat.c: Remove include of gdb.h.
2017-10-29 22:40:01 -04:00
Simon Marchi 7ca51576b9 xtensa-xtregs: Fix formatting issues
Fix a few formatting issues in that file.

gdb/ChangeLog:

	* xtensa-xtregs.c: Fix formatting issues.
2017-10-29 13:02:29 -04:00
Simon Marchi c1342859dc xtensa-xtregs: Constify field
Fix:

In file included from /home/emaisin/src/binutils-gdb/gdb/xtensa-linux-nat.c:46:0:
/home/emaisin/src/binutils-gdb/gdb/xtensa-xtregs.c:37:1: error: ISO C++ forbids converting a string constant to 'char*' [-Werror=write-strings]
 };
 ^

gdb/ChangeLog:

	* xtensa-xtregs.c (xtensa_regtable_t) <name>: Constify.
2017-10-29 01:13:33 -04:00
Maksim Dzabraev 484d8d361d Make gdb.selected_thread().inferior return a new reference
thpy_get_inferior function should return a new reference to the
existing inferior object, and therefore should increment its refcount.

Fixed bug looks like this.
If multiple time call gdb.selected_thread ().inferior, gdb throws exception:

(gdb) pi gdb.selected_thread().inferior
<gdb.Inferior object at 0x7f1952bea698>
(gdb) pi gdb.selected_thread().inferior
Python Exception <type 'exceptions.AttributeError'> 'NoneType' object
has no attribute 'inferior':
Error while executing Python code.
(gdb) info threads
  Id   Target Id         Frame
* 1    Thread 0x7f54f0474740 (LWP 584) "mc" 0x00007f54ef055c33 in
2017-10-28 14:19:08 -04:00
Simon Marchi bac608e7e1 Remove find_inferior usage for thread_search
Replace it with for_each_thread.  While at it, we can inline the
callback code.  One little change is that I am using the
prev_general_thread variable instead of current_gen_ptid, since they
should have the same value.

gdb/gdbserver/ChangeLog:

	* target.c (struct thread_search): Remove.
	(thread_search_callback): Remove.
	(prepare_to_access_memory): Use for_each_thread instead of
	find_inferior.  Inline code from thread_search_callback.
2017-10-27 23:44:12 -04:00
Simon Marchi eaddb42592 Remove usage of find_inferior in resume
Change find_inferior with find_thread.  Since we can now pass arguments
directly instead of through a void pointer, we don't need the
visit_actioned_threads_data structure anymore.

gdb/gdbserver/ChangeLog:

	* server.c (struct visit_actioned_threads_data): Remove.
	(visit_actioned_threads): Change prototype to take arguments
	directly.
	(resume): Use find_thread instead of find_inferior.
2017-10-27 23:43:11 -04:00
Simon Marchi 99078d344d Remove usages of find_inferior in handle_status
Replace one with find_thread, the other with for_each_thread.

gdb/gdbserver/ChangeLog:

	* server.c (queue_stop_reply_callback): Change prototype, return
	void.
	(find_status_pending_thread_callback): Remove.
	(handle_status): Replace find_inferior with find_thread and
	for_each_thread.
2017-10-27 23:41:49 -04:00
Simon Marchi b5540b5f2b common-utils-selftests.c: Add ATTRIBUTE_PRINTF
Fix this, when building with clang:

/home/emaisin/src/binutils-gdb/gdb/unittests/common-utils-selftests.c:50:40: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
  std::string result = string_vprintf (fmt, vp);
                                       ^~~
gdb/ChangeLog:

	* unittests/common-utils-selftests.c (format): Add
	ATTRIBUTE_PRINTF.
2017-10-27 23:36:45 -04:00
Simon Marchi 5a9dcda14c C++ify xml-syscall.c
This patch C++ifies the structures in xml-syscall.c, by using
std::vector instead of VEC, and std::string instead of char*.
Using a unique_ptr in syscall_parse_xml allows to remove a cleanup.

Something that seems strange with the existing code, if you look at
syscalls_info_free_syscalls_desc and
syscalls_info_free_syscall_group_desc, they free the structure elements
(the strings and vectors), but they don't free the syscall_desc and
syscall_group_desc structure themselves.  I don't see anything freeing
those currently.  Any idea why?  According to the comment above
syscalls_info_free_syscall_group_desc, it kinda looks like it's on
purpose.  With this patch, those structures are deleted when the vector
that contains them gets deleted.

The only time I'm aware a syscalls_info structure gets deleted is in the
case the data directory changes during runtime, in init_syscalls_info.
If tried that use case (including under valgrind):

 (gdb) catch syscall
 (gdb) set data-directory another-data-directory
 (gdb) catch syscall

I confirmed that the syscalls_info structure got deleted and recreated,
and everything seemed fine.

Regtested on the buildbot.

gdb/ChangeLog:

	* xml-syscall.c (struct syscall_desc): Add constructor.
	<name>: Change type to std::string.
	(syscall_desc_up): New typedef.
	(syscall_desc_p): Remove typeder.
	(DEF_VEC_P(syscall_desc_p)): Remove.
	(struct syscall_group_desc): Add constructor.
	<name>: Change type to std::string.
	<syscalls>: Change type to std::vector.
	(syscall_group_desc_up): New typedef.
	(syscall_group_desc_p): Remove typedef.
	(DEF_VEC_P(syscall_group_desc_p)): Remove.
	(struct syscalls_info) <syscalls>: Change type to std::vector of
	unique_ptr.
	<groups>: Likewise.
	<my_gdb_datadir>: Change type to std::string.
	(syscalls_info_up): New typedef.
	(allocate_syscalls_info): Remove.
	(syscalls_info_free_syscalls_desc): Remove.
	(syscalls_info_free_syscall_group_desc): Remove.
	(free_syscalls_info): Remove.
	(make_cleanup_free_syscalls_info): Remove.
	(syscall_group_create_syscall_group_desc): Adjust.
	(syscall_group_add_syscall): Adjust.
	(syscall_create_syscall_desc): Adjust.
	(syscall_parse_xml): Adjust, use unique_ptr instead of cleanup.
	(init_syscalls_info): Adjust.
	(syscall_group_get_group_by_name): Adjust.
	(xml_get_syscall_number): Adjust.
	(xml_get_syscall_name): Adjust.
	(xml_list_of_syscalls): Adjust.
	(xml_list_syscalls_by_group): Adjust.
	(xml_list_of_groups): Adjust.
2017-10-27 22:23:48 -04:00
Simon Marchi 45461e0dca Get rid of VEC(probe_p)
Replace the remaining usages of VEC(probe_p) with std::vector.

Regtested on the buildbot.

gdb/ChangeLog:

	* probe.h: Don't include gdb_vecs.h.
	(DEF_VEC_P (probe_p)): Remove.
	(find_probes_in_objfile): Return an std::vector.
	* probe.c (find_probes_in_objfile): Likewise.
	* breakpoint.c (breakpoint_objfile_data)
	<longjmp_probes>: Change type to std::vector.
	<exception_probes>: Likewise.
	(free_breakpoint_probes): Don't manually free vectors.
	(create_longjmp_master_breakpoint): Adjust.
	(create_exception_master_breakpoint): Adjust.
	* solib-svr4.c (svr4_create_probe_breakpoints): Change
	parameter type, adjust.
	(svr4_create_solib_event_breakpoints): Adjust.
2017-10-27 22:12:01 -04:00
Simon Marchi 43dce43945 Allocate breakpoint_objfile_data with new
Allocate with new and free with delete.  This allows using an
std::vector in the following patch.

I renamed free_breakpoint_probes to free_breakpoint_objfile_data,
because it now doesn't only free the probes vector, but also the
breakpoint_objfile_data structure itself.

gdb/ChangeLog:

	* breakpoint.c (breakpoint_objfile_data): Initialize fields.
	(get_breakpoint_objfile_data): Allocate breakpoint_objfile_data
	with new.
	(free_breakpoint_probes): Rename to ...
	(free_breakpoint_objfile_data): ... this, and call delete on
	bp_objfile_data..
2017-10-27 22:01:21 -04:00
Simon Marchi 6a1b9516d8 Get rid of VEC(loaded_script_ptr)
Direct replacement with std::vector.  This allows removing a cleanup as
well.

Regtested on the buildbot.

gdb/ChangeLog:

	* auto-load.c: Don't include gdb_vecs.h, include algorithm.
	(loaded_script_ptr): Remove typedef.
	(DEF_VEC_P (loaded_script_ptr)): Remove.
	(struct collect_matching_scripts_data): Add constructor.
	<scripts_p>: Change type to (pointer to) std::vector.
	(collect_matching_scripts_data): Adjust.
	(sort_scripts_by_name): Make suitable for std::sort.
	(print_scripts): Don't sort vector, adjust to std::vector.
	(auto_load_info_scripts): Sort vectors, adjust to std::vector.
2017-10-27 21:55:43 -04:00
Simon Marchi 593e3209f3 Get rid of VEC(filename_language)
This patch removes VEC(filename_language), replacing its usage with
std::vector.  filename_language::ext is changed to an std::string at the
same time.

Regtested on the buildbot.

gdb/ChangeLog:

	* symfile.c (filename_language): Make struct, not typedef.  Add
	constructor.
	<ext>: Change type to std::string.
	(DEF_VEC_O (filename_language)): Remove.
	(filename_language_table): Change type to std::vector.
	(add_filename_language): Adjust.
	(set_ext_lang_command): Adjust.
	(info_ext_lang_command): Adjust.
	(deduce_language_from_filename): Adjust.
	(class scoped_restore_filename_language_table): Remove.
	(test_filename_language): Use scoped_restore.
	(test_set_ext_lang_command): Use scoped_restore, adjust to
	std::vector change.
2017-10-27 21:47:30 -04:00
Simon Marchi 32fa66eb88 Add tests for filename_language
The next patch touches the filename_language area, but I noticed there
is no test exercising that.  This patch adds some selftests for
add_filename_language, deduce_language_from_filename and
set_ext_lang_command.  Because these tests add entries to the global
filename_language_table vector, it is not possible to run them
successfully multiple times in a same GDB instance.  They can
potentially interfere with each other for the same reason.  I therefore
added the scoped_restore_filename_language_table class that is used to
make sure tests leave that global vector in the same state they found it
(it is replaced in the following patch by a simple scoped_restore).

gdb/ChangeLog:

	* symfile.c: Include selftest.h.
	(class scoped_restore_filename_language_table): New.
	(test_filename_language): New test.
	(test_set_ext_lang_command): New test.
	(_initialize_symfile): Register tests.
2017-10-27 21:46:49 -04:00
Keith Seitz 4a27f119f5 Use SaL symbol name when reporting breakpoint locations
Currently, "info break" can show some (perhaps) unexpected results when
setting a breakpoint on an inlined function:

(gdb) list
1	#include <stdio.h>
2
3	static inline void foo()
4	{
5	        printf("Hello world\n");
6	}
7
8	int main()
9	{
10	        foo();
11	        return 0;
12	}
13
(gdb) b foo
Breakpoint 1 at 0x400434: file foo.c, line 5.
(gdb) i b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x0000000000400434 in main at foo.c:5

GDB reported that we understood what "foo" was, but we then report that the
breakpoint is actually set in main. While that is literally true, we can
do a little better.

This is accomplished by copying the symbol for which the breakpoint was set
into the bp_location.  From there, print_breakpoint_location can use this
information to print out symbol information (if available) instead of calling
find_pc_sect_function.

With the patch installed,

(gdb) i b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x0000000000400434 in foo at foo.c:5

gdb/ChangeLog:

	* breakpoint.c (print_breakpoint_location): Use the symbol saved
	in the bp_location, falling back to find_pc_sect_function when
	needed.
	(add_location_to_breakpoint): Save sal->symbol.
	* breakpoint.h (struct bp_location) <symbol>: New field.
	* symtab.c (find_function_start_sal): Save the symbol into the SaL.
	* symtab.h (struct symtab_and_line) <symbol>: New field.

gdb/testsuite/ChangeLog:

	* gdb.opt/inline-break.exp (break_info_1): New procedure.
	Test "info break" for every inlined function breakpoint.
2017-10-27 10:57:23 -07:00
Yao Qi bb11dd5839 [AArch64] Mark LR clobbered by BL in inline asm
LR is a caller-save register, so, if inline asm does BL (which touches
LR), we should mark LR clobbered.

gdb/testsuite:

2017-10-27  Yao Qi  <yao.qi@linaro.org>

	* gdb.arch/insn-reloc.c (can_relocate_bl): Mark "x30" clobbered.
2017-10-27 15:29:24 +01:00
Simon Marchi 7453e6b2ea Add PR mention to previous commit 2017-10-27 08:58:43 -04:00
Patrick Frants a43f3893f6 Fix broken recursion detection when printing static members
Recursion detection for static members was broken.  The implementation
uses a growing (and shrinking) obstack object to simulate a stack of
addresses (CORE_ADDR).  Pushing addresses is implemented by calling
obstack_grow(), while popping is implemented by calling obstack_free().
The latter is problematic because obstack_free() expects a pointer to
the base of an object.  When popping elements of the stack however,
obstack_free() was called with the new top, which potentially is not the
same as the base of the stack.  This is unintended use and the effect is
that obstack->next_free and obstack->object_base members are assigned
the value of the new top, which equals an empty stack.  Summary: popping
elements would always result in an empty stack, which breaks the
recursion detection.

The fix shrinks the stack using obstack_blank_fast() with a negative
value as described at the bottom of this page:
https://gcc.gnu.org/onlinedocs/libiberty/Extra-Fast-Growing.html "You
can use obstack_blank_fast with a “negative” size argument to make the
current object smaller.  Just don’t try to shrink it beyond zero
length—there’s no telling what will happen if you do that. Earlier
versions of obstacks allowed you to use obstack_blank to shrink objects.
This will no longer work."

The reproducer is added to gdb.cp/classes.exp, which fails without this
patch.

gdb/ChangeLog:

	* cp-valprint.c (cp_print_value_fields): Use obstack_blank_fast
	to rewind obstack.

gdb/testsuite/ChangeLog:

	* gdb.cp/classes.exp (test_static_members): Test printing
	Outer::instance.
	* gdb.cp/classes.c (struct Inner, struct Outer): New.
	(Inner::instance, Outer::instance): New.
2017-10-26 22:26:08 -04:00
Pedro Alves 23cc4e1b28 Garbage collect remote.c:remote_async_terminal_ours_p
remote.c:remote_async_terminal_ours_p stopped being useful after
048094accc ("target remote: Don't rely on immediate_quit (introduce
quit handlers)") and commit 41fd2b0f5d ("Make input_fd be per UI"),
which turned remote's terminal_inferior/ours methods into nops.

gdb/ChangeLog:
2017-10-26  Pedro Alves  <palves@redhat.com>

	* remote.c (remote_async_terminal_ours_p): Delete.
	(remote_open_1, remote_terminal_inferior, remote_terminal_ours):
	Remove references to 'remote_async_terminal_ours_p'.
2017-10-26 19:53:03 +01:00
Yao Qi 6abc18bbbf Remove regular_breakpoint_inserted_here_p declaration
There is no regular_breakpoint_inserted_here_p definition at all, so
this patch removes the declaration.

gdb:

2017-10-26  Yao Qi  <yao.qi@linaro.org>

	* breakpoint.h (regular_breakpoint_inserted_here_p): Remove.
2017-10-26 09:53:38 +01:00
Yao Qi bd5225139c const-fy breakpoint_ops->breakpoint_hit parameter aspace
gdb:

2017-10-26  Yao Qi  <yao.qi@linaro.org>

	* break-catch-sig.c (signal_catchpoint_breakpoint_hit): Make
	aspace const.
	* break-catch-syscall.c (breakpoint_hit_catch_syscall):
	Likewise.
	* breakpoint.c (bpstat_check_location): Remove cast.
	(breakpoint_hit_catch_fork): Make aspce const.
	(breakpoint_hit_catch_solib): Likewise.
	(breakpoint_hit_catch_exec): Likewise.
	(breakpoint_hit_ranged_breakpoint): Likewise.
	(breakpoint_hit_watchpoint): Likewise.
	(base_breakpoint_breakpoint_hit): Likewise.
	(bkpt_breakpoint_hit): Likewise.
	(dprintf_breakpoint_hit): Likewise.
	(tracepoint_breakpoint_hit): Likewise.
	* breakpoint.h (breakpoint_ops) <breakpoint_hit>: Likewise.
2017-10-26 09:46:16 +01:00
Yao Qi accd0bcdfe const-fy function parameter struct address_space *aspace
This patch changes the parameter "struct address_space *aspace" to "const
address_space *aspace" in many functions.

gdb:

2017-10-26  Yao Qi  <yao.qi@linaro.org>

	* breakpoint.c (breakpoint_location_address_match): Change
	"struct address_space *" to "const address_space".
	(breakpoint_location_address_range_overlap): Likewise.
	(breakpoint_here_p): Likewise.
	(breakpoint_in_range_p): Likewise.
	(moribund_breakpoint_here_p): Likewise.
	(bp_location_inserted_here_p): Likewise.
	(software_breakpoint_inserted_here_p): Likewise.
	(hardware_breakpoint_inserted_here_p): Likewise.
	(hardware_watchpoint_inserted_in_range): Likewise.
	(bpstat_check_location): Likewise.
	(bpstat_stop_status): Likewise.
	(breakpoint_address_match): Likewise.
	(breakpoint_address_match_range): Likewise.
	(breakpoint_location_address_match): Likewise.
	(breakpoint_location_address_range_overlap): Likewise.
	(insert_single_step_breakpoint): Likewise.
	(breakpoint_has_location_inserted_here): Likewise.
	(single_step_breakpoint_inserted_here_p): Likewise.
	(pc_at_non_inline_function): Likewise.
	* breakpoint.h (bpstat_stop_status): Update declaration.
	(breakpoint_here_p): Likewise.
	(breakpoint_in_range_p): Likewise.
	(moribund_breakpoint_here_p): Likewise.
	(breakpoint_inserted_here_p): Likewise.
	(software_breakpoint_inserted_here_p): Likewise.
	(hardware_breakpoint_inserted_here_p): Likewise.
	(breakpoint_has_location_inserted_here): Likewise.
	(single_step_breakpoint_inserted_here_p): Likewise.
	(hardware_watchpoint_inserted_in_range): Likewise.
	(breakpoint_address_match): Likewise.
	(insert_single_step_breakpoint): Likewise.
	(pc_at_non_inline_function): Likewise.
	* gdbthread.h (thread_has_single_step_breakpoint_here): Likewise.
	* record.c (record_check_stopped_by_breakpoint): Likewise.
	* record.h (record_check_stopped_by_breakpoint): Likewise.
	* thread.c (thread_has_single_step_breakpoint_here): Likewise.
2017-10-26 09:46:16 +01:00
Yao Qi ac7936dfd0 s/get_regcache_arch (regcache)/regcache->arch ()/g
This patches removes get_regcache_arch, and use regache->arch () instead.
The motivation of this change is that I am going to move some basic stuff
into a base class of regcache.  I don't need to update "client" code
regcache->arch ().  On the other hand, this patch shortens the code a
little bit.

gdb:

2017-10-25  Yao Qi  <yao.qi@linaro.org>

	* aarch32-linux-nat.c (aarch32_gp_regcache_supply): Use
	regcache->arch () instead get_regcache_arch.
	* aarch64-fbsd-nat.c (aarch64_fbsd_fetch_inferior_registers):
	Likewise.
	(aarch64_fbsd_store_inferior_registers): Likewise.
	* aarch64-linux-nat.c (fetch_gregs_from_thread): Likewise.
	(store_gregs_to_thread): Likewise.
	(fetch_fpregs_from_thread): Likewise.
	(store_fpregs_to_thread): Likewise.
	* aarch64-tdep.c (aarch64_extract_return_value): Likewise.
	(aarch64_store_return_value): Likewise.
	(aarch64_software_single_step): Likewise.
	* aix-thread.c (aix_thread_wait): Likewise.
	(supply_reg32): Likewise.
	(supply_sprs64): Likewise.
	(supply_sprs32): Likewise.
	(fill_gprs64): Likewise.
	(fill_gprs32): Likewise.
	(fill_sprs64): Likewise.
	(fill_sprs32): Likewise.
	(store_regs_user_thread): Likewise.
	(store_regs_kernel_thread): Likewise.
	* alpha-bsd-nat.c (alphabsd_fetch_inferior_registers): Likewise.
	(alphabsd_store_inferior_registers): Likewise.
	* alpha-tdep.c (alpha_extract_return_value): Likewise.
	(alpha_store_return_value): Likewise.
	(alpha_deal_with_atomic_sequence): Likewise.
	(alpha_next_pc): Likewise.
	(alpha_software_single_step): Likewise.
	* amd64-bsd-nat.c (amd64bsd_fetch_inferior_registers): Likewise.
	(amd64bsd_store_inferior_registers): Likewise.
	* amd64-linux-nat.c (amd64_linux_fetch_inferior_registers):
	Likewise.
	(amd64_linux_store_inferior_registers): Likewise.
	* amd64-nat.c (amd64_supply_native_gregset): Likewise.
	(amd64_collect_native_gregset): Likewise.
	* amd64-obsd-tdep.c (amd64obsd_supply_uthread): Likewise.
	(amd64obsd_collect_uthread): Likewise.
	* amd64-tdep.c (amd64_supply_fpregset): Likewise.
	(amd64_collect_fpregset): Likewise.
	(amd64_supply_fxsave): Likewise.
	(amd64_supply_xsave): Likewise.
	(amd64_collect_fxsave): Likewise.
	(amd64_collect_xsave): Likewise.
	* arc-tdep.c (arc_write_pc): Likewise.
	* arch-utils.c (default_skip_permanent_breakpoint): Likewise.
	* arm-fbsd-nat.c (arm_fbsd_fetch_inferior_registers): Likewise.
	(arm_fbsd_store_inferior_registers): Likewise.
	* arm-linux-nat.c (fetch_vfp_regs): Likewise.
	(store_vfp_regs): Likewise.
	(arm_linux_fetch_inferior_registers): Likewise.
	(arm_linux_store_inferior_registers): Likewise.
	* arm-linux-tdep.c (arm_linux_supply_gregset): Likewise.
	(arm_linux_sigreturn_next_pc): Likewise.
	(arm_linux_get_next_pcs_syscall_next_pc): Likewise.
	* arm-nbsd-nat.c (arm_supply_gregset): Likewise.
	(fetch_register): Likewise.
	(store_register): Likewise.
	* arm-tdep.c (arm_is_thumb): Likewise.
	(displaced_in_arm_mode): Likewise.
	(bx_write_pc): Likewise.
	(arm_get_next_pcs_addr_bits_remove): Likewise.
	(arm_software_single_step): Likewise.
	(arm_extract_return_value): Likewise.
	(arm_store_return_value): Likewise.
	(arm_write_pc): Likewise.
	* bfin-tdep.c (bfin_extract_return_value): Likewise.
	* bsd-uthread.c (bsd_uthread_fetch_registers): Likewise.
	(bsd_uthread_store_registers): Likewise.
	* core-regset.c (fetch_core_registers): Likewise.
	* corelow.c (get_core_registers): Likewise.
	* cris-tdep.c (cris_store_return_value): Likewise.
	(cris_extract_return_value): Likewise.
	(find_step_target): Likewise.
	(find_step_target): Likewise.
	(cris_software_single_step): Likewise.
	* ctf.c (ctf_fetch_registers): Likewise.
	* darwin-nat.c (cancel_breakpoint): Likewise.
	* fbsd-tdep.c (fbsd_collect_thread_registers): Likewise.
	* frv-tdep.c (frv_extract_return_value): Likewise.
	* ft32-tdep.c (ft32_store_return_value): Likewise.
	(ft32_extract_return_value): Likewise.
	* go32-nat.c (fetch_register): Likewise.
	(go32_fetch_registers): Likewise.
	(go32_store_registers): Likewise.
	(store_register): Likewise.
	* h8300-tdep.c (h8300_extract_return_value): Likewise.
	(h8300_store_return_value): Likewise.
	* hppa-linux-nat.c (fetch_register): Likewise.
	(store_register): Likewise.
	(hppa_linux_fetch_inferior_registers): Likewise.
	(hppa_linux_store_inferior_registers): Likewise.
	* i386-darwin-nat.c (i386_darwin_fetch_inferior_registers): Likewise.
	(i386_darwin_store_inferior_registers): Likewise.
	* i386-gnu-nat.c (gnu_fetch_registers): Likewise.
	(gnu_store_registers): Likewise.
	* i386-linux-nat.c (fetch_register): Likewise.
	(store_register): Likewise.
	(supply_gregset): Likewise.
	(fill_gregset): Likewise.
	(i386_linux_fetch_inferior_registers): Likewise.
	(i386_linux_store_inferior_registers): Likewise.
	(i386_linux_resume): Likewise.
	* i386-linux-tdep.c (i386_linux_get_syscall_number_from_regcache):
	Likewise.
	* i386-nto-tdep.c (i386nto_supply_gregset): Likewise.
	* i386-obsd-nat.c (i386obsd_supply_pcb): Likewise.
	* i386-obsd-tdep.c (i386obsd_supply_uthread): Likewise.
	(i386obsd_collect_uthread): Likewise.
	* i386-tdep.c (i386_mmx_regnum_to_fp_regnum): Likewise.
	(i386_supply_gregset): Likewise.
	(i386_collect_gregset): Likewise.
	(i386_supply_fpregset): Likewise.
	(i386_collect_fpregset): Likewise.
	(i386_mpx_bd_base): Likewise.
	* i386-v4-nat.c	(supply_fpregset): Likewise.
	(fill_fpregset): Likewise.
	* i387-tdep.c (i387_supply_fsave): Likewise.
	(i387_collect_fsave): Likewise.
	(i387_supply_fxsave): Likewise.
	(i387_collect_fxsave): Likewise.
	(i387_supply_xsave): Likewise.
	(i387_collect_xsave): Likewise.
	* ia64-linux-nat.c (ia64_linux_fetch_registers): Likewise.
	(ia64_linux_store_registers): Likewise.
	* ia64-tdep.c (ia64_access_rse_reg): Likewise.
	(ia64_extract_return_value): Likewise.
	(ia64_store_return_value): Likewise.
	(find_func_descr): Likewise.
	* inf-child.c (inf_child_fetch_inferior_registers): Likewise.
	* inf-ptrace.c (inf_ptrace_fetch_registers): Likewise.
	(inf_ptrace_store_registers): Likewise.
	* infrun.c (use_displaced_stepping): Likewise.
	(displaced_step_prepare_throw): Likewise.
	(resume): Likewise.
	(proceed): Likewise.
	(do_target_wait): Likewise.
	(adjust_pc_after_break): Likewise.
	(handle_inferior_event_1): Likewise.
	(handle_signal_stop): Likewise.
	(save_infcall_suspend_state): Likewise.
	(restore_infcall_suspend_state): Likewise.
	* iq2000-tdep.c (iq2000_extract_return_value): Likewise.
	* jit.c (jit_frame_prev_register): Likewise.
	* linux-nat.c (save_stop_reason): Likewise.
	(linux_nat_wait_1): Likewise.
	(resume_stopped_resumed_lwps): Likewise.
	* linux-record.c (record_linux_sockaddr): Likewise.
	(record_linux_msghdr): Likewise.
	(record_linux_system_call): Likewise.
	* linux-tdep.c (linux_collect_thread_registers): Likewise.
	* lm32-tdep.c (lm32_extract_return_value): Likewise.
	(lm32_store_return_value): Likewise.
	* m32c-tdep.c (m32c_read_flg): Likewise.
	(m32c_pseudo_register_read): Likewise.
	(m32c_pseudo_register_write): Likewise.
	* m32r-linux-tdep.c (m32r_linux_supply_gregset): Likewise.
	(m32r_linux_collect_gregset): Likewise.
	* m32r-tdep.c (m32r_store_return_value): Likewise.
	(m32r_extract_return_value): Likewise.
	* m68k-bsd-nat.c (m68kbsd_supply_fpregset): Likewise.
	(m68kbsd_collect_fpregset): Likewise.
	* m68k-bsd-tdep.c (m68kbsd_supply_fpregset): Likewise.
	* m68k-linux-nat.c (fetch_register): Likewise.
	(old_fetch_inferior_registers): Likewise.
	(old_store_inferior_registers): Likewise.
	(store_regs): Likewise.
	* m68k-tdep.c (m68k_svr4_extract_return_value): Likewise.
	(m68k_svr4_store_return_value): Likewise.
	* m88k-tdep.c (m88k_store_arguments): Likewise.
	* mi/mi-main.c (mi_cmd_data_list_changed_registers): Likewise.
	(mi_cmd_data_write_register_values): Likewise.
	* mips-fbsd-nat.c (mips_fbsd_fetch_inferior_registers): Likewise.
	(mips_fbsd_store_inferior_registers): Likewise.
	* mips-fbsd-tdep.c (mips_fbsd_supply_fpregs): Likewise.
	(mips_fbsd_supply_gregs): Likewise.
	(mips_fbsd_collect_fpregs): Likewise.
	(mips_fbsd_collect_gregs): Likewise.
	(mips_fbsd_supply_fpregset): Likewise.
	(mips_fbsd_collect_fpregset): Likewise.
	(mips_fbsd_supply_gregset): Likewise.
	(mips_fbsd_collect_gregset): Likewise.
	* mips-linux-nat.c (supply_gregset): Likewise.
	(fill_gregset): Likewise.
	(supply_fpregset): Likewise.
	(fill_fpregset): Likewise.
	* mips-linux-tdep.c (mips_supply_gregset): Likewise.
	(mips_fill_gregset): Likewise.
	(mips_supply_fpregset): Likewise.
	(mips_fill_fpregset): Likewise.
	(mips64_supply_gregset): Likewise.
	(micromips_linux_sigframe_validate): Likewise.
	* mips-nbsd-nat.c (mipsnbsd_fetch_inferior_registers): Likewise.
	(mipsnbsd_fetch_inferior_registers): Likewise.
	(mipsnbsd_store_inferior_registers): Likewise.
	* mips-nbsd-tdep.c (mipsnbsd_supply_fpregset): Likewise.
	(mipsnbsd_supply_gregset): Likewise.
	(mipsnbsd_iterate_over_regset_sections): Likewise.
	(mipsnbsd_supply_reg): Likewise.
	(mipsnbsd_supply_fpreg): Likewise.
	* mips-tdep.c (mips_in_frame_stub): Likewise.
	(mips_dummy_id): Likewise.
	(is_octeon_bbit_op): Likewise.
	(micromips_bc1_pc): Likewise.
	(extended_mips16_next_pc): Likewise.
	(mips16_next_pc): Likewise.
	(deal_with_atomic_sequence): Likewise.
	* moxie-tdep.c (moxie_process_readu): Likewise.
	* nios2-tdep.c (nios2_get_next_pc): Likewise.
	* nto-procfs.c (procfs_store_registers): Likewise.
	* ppc-fbsd-nat.c (ppcfbsd_fetch_inferior_registers): Likewise.
	(ppcfbsd_store_inferior_registers): Likewise.
	* ppc-linux-nat.c (fetch_vsx_register): Likewise.
	(fetch_altivec_register): Likewise.
	(get_spe_registers): Likewise.
	(fetch_spe_register): Likewise.
	(fetch_altivec_registers): Likewise.
	(fetch_all_gp_regs): Likewise.
	(fetch_all_fp_regs): Likewise.
	(store_vsx_register): Likewise.
	(store_altivec_register): Likewise.
	(set_spe_registers): Likewise.
	(store_spe_register): Likewise.
	(store_altivec_registers): Likewise.
	(store_all_gp_regs): Likewise.
	(store_all_fp_regs): Likewise.
	* ppc-linux-tdep.c (ppc_linux_supply_gregset): Likewise.
	(ppc_linux_collect_gregset): Likewise.
	(ppc_canonicalize_syscall): Likewise.
	(ppc_linux_record_signal): Likewise.
	(ppu2spu_prev_register): Likewise.
	* ppc-nbsd-nat.c (ppcnbsd_supply_pcb): Likewise.
	* ppc-obsd-nat.c (ppcobsd_fetch_registers): Likewise.
	(ppcobsd_store_registers): Likewise.
	* ppc-ravenscar-thread.c (ppc_ravenscar_generic_fetch_registers):
	Likewise.
	(ppc_ravenscar_generic_store_registers): Likewise.
	* procfs.c (procfs_fetch_registers): Likewise.
	(procfs_store_registers): Likewise.
	* ravenscar-thread.c (ravenscar_fetch_registers): Likewise.
	(ravenscar_store_registers): Likewise.
	(ravenscar_prepare_to_store): Likewise.
	* record-btrace.c (record_btrace_fetch_registers): Likewise.
	* record-full.c (record_full_wait_1): Likewise.
	(record_full_registers_change): Likewise.
	(record_full_store_registers): Likewise.
	(record_full_core_fetch_registers): Likewise.
	(record_full_save): Likewise.
	(record_full_goto_insn): Likewise.
	* regcache.c (regcache_register_size): Likewise.
	(get_regcache_arch): Remove.
	(regcache_read_pc): Likewise.
	* regcache.h (get_regcache_arch): Remove.
	* remote-sim.c (gdbsim_fetch_register): Likewise.
	(gdbsim_store_register): Likewise.
	* remote.c (fetch_register_using_p): Likewise.
	(send_g_packet): Likewise.
	(remote_prepare_to_store): Likewise.
	(store_registers_using_G): Likewise.
	* reverse.c (save_bookmark_command): Likewise.
	(goto_bookmark_command): Likewise.
	* rs6000-aix-tdep.c (branch_dest): Likewise.
	* rs6000-nat.c (rs6000_ptrace64): Likewise.
	(fetch_register): Likewise.
	* rs6000-tdep.c (ppc_supply_reg): Likewise.
	(ppc_collect_reg): Likewise.
	(ppc_collect_gregset): Likewise.
	(ppc_collect_fpregset): Likewise.
	(ppc_collect_vsxregset): Likewise.
	(ppc_collect_vrregset): Likewise.
	(ppc_displaced_step_hw_singlestep): Likewise.
	(rs6000_pseudo_register_read): Likewise.
	(rs6000_pseudo_register_write): Likewise.
	* s390-linux-nat.c (supply_gregset): Likewise.
	(fill_gregset): Likewise.
	(s390_linux_fetch_inferior_registers): Likewise.
	* s390-linux-tdep.c (s390_write_pc): Likewise.
	(s390_software_single_step): Likewise.
	(s390_all_but_pc_registers_record): Likewise.
	(s390_linux_syscall_record): Likewise.
	* sentinel-frame.c (sentinel_frame_prev_arch): Likewise.
	* sh-nbsd-nat.c (shnbsd_fetch_inferior_registers): Likewise.
	(shnbsd_store_inferior_registers): Likewise.
	* sh-tdep.c (sh_extract_return_value_nofpu): Likewise.
	(sh_extract_return_value_fpu): Likewise.
	(sh_store_return_value_nofpu): Likewise.
	(sh_corefile_supply_regset): Likewise.
	(sh_corefile_collect_regset): Likewise.
	* sh64-tdep.c (sh64_extract_return_value): Likewise.
	(sh64_store_return_value): Likewise.
	* sparc-linux-tdep.c (sparc32_linux_collect_core_fpregset): Likewise.
	* sparc-nat.c (sparc_fetch_inferior_registers): Likewise.
	(sparc_store_inferior_registers): Likewise.
	* sparc-ravenscar-thread.c (register_in_thread_descriptor_p): Likewise.
	(sparc_ravenscar_prepare_to_store): Likewise.
	* sparc-tdep.c (sparc32_store_arguments): Likewise.
	(sparc_analyze_control_transfer): Likewise.
	(sparc_step_trap): Likewise.
	(sparc_software_single_step): Likewise.
	(sparc32_gdbarch_init): Likewise.
	(sparc_supply_rwindow): Likewise.
	(sparc_collect_rwindow): Likewise.
	* sparc64-linux-tdep.c (sparc64_linux_collect_core_fpregset): Likewise.
	* sparc64-nbsd-nat.c (sparc64nbsd_supply_gregset): Likewise.
	(sparc64nbsd_collect_gregset): Likewise.
	(sparc64nbsd_supply_fpregset): Likewise.
	(sparc64nbsd_collect_fpregset): Likewise.
	* sparc64-tdep.c (sparc64_store_arguments): Likewise.
	(sparc64_supply_gregset): Likewise.
	(sparc64_collect_gregset): Likewise.
	(sparc64_supply_fpregset): Likewise.
	(sparc64_collect_fpregset): Likewise.
	* spu-linux-nat.c (spu_fetch_inferior_registers): Likewise.
	* spu-tdep.c (spu_unwind_sp): Likewise.
	(spu2ppu_prev_register): Likewise.
	(spu_memory_remove_breakpoint): Likewise.
	* stack.c (return_command): Likewise.
	* tic6x-tdep.c (tic6x_extract_signed_field): Likewise.
	* tracefile-tfile.c (tfile_fetch_registers): Likewise.
	* tracefile.c (trace_save_ctf): Likewise.
	* windows-nat.c (do_windows_fetch_inferior_registers): Likewise.
	(do_windows_store_inferior_registers): Likewise.
	(windows_resume): Likewise.
	* xtensa-linux-nat.c (fill_gregset): Likewise.
	(supply_gregset_reg): Likewise.
	* xtensa-tdep.c (xtensa_register_write_masked): Likewise.
	(xtensa_register_read_masked): Likewise.
	(xtensa_supply_gregset): Likewise.
	(xtensa_extract_return_value): Likewise.
	(xtensa_store_return_value): Likewise.
2017-10-25 16:37:03 +01:00
Ulrich Weigand edd079d9f6 Target FP: Use target format throughout expression parsing
When parsing floating-point literals, the language parsers currently
use parse_float or some equivalent routine to parse the input string
into a DOUBLEST, which is then stored within a OP_DOUBLE expression
node.  When evaluating the expression, the OP_DOUBLE is finally
converted into a value in target format.

On the other hand, *decimal* floating-point literals are parsed
directly into target format and stored that way in a OP_DECFLOAT
expression node.  In order to eliminate the DOUBLEST, this patch
therefore unifies the handling of binary and decimal floating-
point literals and stores them both in target format within a
new OP_FLOAT expression node, replacing both OP_DOUBLE and
OP_DECFLOAT.

In order to store literals in target format, the parse_float
routine needs to know the type of the literal.  All parsers
therefore need to be changed to determine the appropriate type
(e.g. by detecting suffixes) *before* calling parse_float,
instead of after it as today.  However, this change is mostly
straightforward -- again, this is already done for decimal FP
today.

The core of the literal parsing is moved into a new routine
floatformat_from_string, mirroring floatformat_to_string.
The parse_float routine now calls either floatformat_from_string
or decimal_from_sting, allowing it to handle any type of FP
literal.

All language parsers need to be updated.  Some notes on
specific changes to the various languages:

- C: Decimal FP is now handled in parse_float, and no longer
  needs to be handled specially.

- D: Straightforward.

- Fortran: Still used a hard-coded "atof", also replaced by
  parse_float now.  Continues to always use builtin_real_s8
  as the type of literal, even though this is probably wrong.

- Go: This used to handle "f" and "l" suffixes, even though
  the Go language actually doesn't support those.  I kept this
  support for now -- maybe revisit later.  Note the the GDB
  test suite for some reason actually *verifies* that GDB supports
  those unsupported suffixes ...

- Pascal: Likewise -- this handles suffixes that are not
  supported in the language standard.

- Modula-2: Like Fortran, used to use "atof".

- Rust: Mostly straightforward, except for a unit-testing hitch.
  The code use to set a special "unit_testing" flag which would
  cause "rust_type" to always return NULL.  This makes it not
  possible to encode a literal into target format (which type?).
  The reason for this flag appears to have been that during
  unit testing, there is no "rust_parser" context set up, which
  means no "gdbarch" is available to use its types.  To fix this,
  I removed the unit_testing flag, and instead simply just set up
  a dummy rust_parser context during unit testing.

- Ada: This used to check sizeof (DOUBLEST) to determine which
  type to use for floating-point literal.  This seems questionable
  to begin with (since DOUBLEST is quite unrelated to target formats),
  and in any case we need to get rid of DOUBLEST.  I'm now simply
  always using the largest type (builtin_long_double).

gdb/ChangeLog:
2017-10-25  Ulrich Weigand  <uweigand@de.ibm.com>

	* doublest.c (floatformat_from_string): New function.
	* doublest.h (floatformat_from_string): Add prototype.

	* std-operator.def (OP_DOUBLE, OP_DECFLOAT): Remove, replace by ...
	(OP_FLOAT): ... this.
	* expression.h: Do not include "doublest.h".
	(union exp_element): Replace doubleconst and decfloatconst by
	new element floatconst.
	* ada-lang.c (resolve_subexp): Handle OP_FLOAT instead of OP_DOUBLE.
	(ada_evaluate_subexp): Likewise.
	* eval.c (evaluate_subexp_standard): Handle OP_FLOAT instead of
	OP_DOUBLE and OP_DECFLOAT.
	* expprint.c (print_subexp_standard): Likewise.
	(dump_subexp_body_standard): Likewise.
	* breakpoint.c (watchpoint_exp_is_const): Likewise.

	* parse.c: Include "dfp.h".
	(write_exp_elt_dblcst, write_exp_elt_decfloatcst): Remove.
	(write_exp_elt_floatcst): New function.
	(operator_length_standard): Handle OP_FLOAT instead of OP_DOUBLE
	and OP_DECFLOAT.
	(operator_check_standard): Likewise.
	(parse_float): Do not accept suffix.  Take type as input.  Return bool.
	Return target format buffer instead of host DOUBLEST.
	Use floatformat_from_string and decimal_from_string to parse
	either binary or decimal floating-point types.
	(parse_c_float): Remove.
	* parser-defs.h: Do not include "doublest.h".
	(write_exp_elt_dblcst, write_exp_elt_decfloatcst): Remove.
	(write_exp_elt_floatcst): Add prototype.
	(parse_float): Update prototype.
	(parse_c_float): Remove.

	* c-exp.y: Do not include "dfp.h".
	(typed_val_float): Use byte buffer instead of DOUBLEST.
	(typed_val_decfloat): Remove.
	(DECFLOAT): Remove.
	(FLOAT): Use OP_FLOAT and write_exp_elt_floatcst.
	(parse_number): Update to new parse_float interface.
	Parse suffixes and determine type before calling parse_float.
	Handle decimal and binary FP types the same way.

	* d-exp.y (typed_val_float): Use byte buffer instead of DOUBLEST.
	(FLOAT_LITERAL): Use OP_FLOAT and write_exp_elt_floatcst.
	(parse_number): Update to new parse_float interface.
	Parse suffixes and determine type before calling parse_float.

	* f-exp.y: Replace dval by typed_val_float.
	(FLOAT): Use OP_FLOAT and write_exp_elt_floatcst.
	(parse_number): Use parse_float instead of atof.

	* go-exp.y (typed_val_float): Use byte buffer instead of DOUBLEST.
	(parse_go_float): Remove.
	(FLOAT): Use OP_FLOAT and write_exp_elt_floatcst.
	(parse_number): Call parse_float instead of parse_go_float.
	Parse suffixes and determine type before calling parse_float.

	* p-exp.y (typed_val_float): Use byte buffer instead of DOUBLEST.
	(FLOAT): Use OP_FLOAT and write_exp_elt_floatcst.
	(parse_number): Update to new parse_float interface.
	Parse suffixes and determine type before calling parse_float.

	* m2-exp.y: Replace dval by byte buffer val.
	(FLOAT): Use OP_FLOAT and write_exp_elt_floatcst.
	(parse_number): Call parse_float instead of atof.

	* rust-exp.y (typed_val_float): Use byte buffer instead of DOUBLEST.
	(lex_number): Call parse_float instead of strtod.
	(ast_dliteral): Use OP_FLOAT instead of OP_DOUBLE.
	(convert_ast_to_expression): Handle OP_FLOAT instead of OP_DOUBLE.
	Use write_exp_elt_floatcst.
	(unit_testing): Remove static variable.
	(rust_type): Do not check unit_testing.
	(rust_lex_tests): Do not set uint_testing.  Set up dummy rust_parser.

	* ada-exp.y (type_float, type_double): Remove.
	(typed_val_float): Use byte buffer instead of DOUBLEST.
	(FLOAT): Use OP_FLOAT and write_exp_elt_floatcst.
	* ada-lex.l (processReal): Use parse_float instead of sscanf.
2017-10-25 15:32:23 +02:00
Alan Hayward cc628f3dbb Add common AARCH64 REGNUM defines
gdb/
	* aarch64-tdep.h (enum aarch64_regnum): Remove.
	* arch/aarch64.h: New file.

gdbserver/
	* linux-aarch64-low.c (aarch64_fill_gregset): Replace defines
	with REGNO.
	(aarch64_store_gregset): Likewise.
	(aarch64_fill_fpregset): Likewise.
	(aarch64_store_fpregset): Likewise.
2017-10-25 09:06:41 +01:00
Pedro Alves 792ccf005f Fix racy test in gdb.base/new-ui.exp
I noticed gdb.base/new-ui.exp failing once here with:

 FAIL: gdb.base/new-ui.exp: do_test: delete all breakpoints on extra console (got interactive prompt)
 FAIL: gdb.base/new-ui.exp: do_test: main console: next causes no spurious output on other console
 FAIL: gdb.base/new-ui.exp: do_test: main console: breakpoint hit reported on other console

The problem is 100% reproducible with check-read1:
  $ make check-read1 TESTS="gdb.*/new-ui.exp"

testsuite/gdb.log shows:
  delete
  Delete all breakpoints? (y or n) [answered Y; input not from terminal]
  (gdb) FAIL: gdb.base/new-ui.exp: do_test: delete all breakpoints on extra console (got interactive prompt)

This commit fixes the problem.

gdb/testsuite/ChangeLog:
2017-10-24  Pedro Alves  <palves@redhat.com>

	* gdb.base/new-ui.exp (do_test): Split "delete all breakpoints on
	extra console" test in two stages.
2017-10-24 23:22:56 +01:00
Ulrich Weigand 09a7c6aa7a Use const reference for decimal_from_string argument
No functional change.

gdb/ChangeLog:
2017-10-24  Ulrich Weigand  <uweigand@de.ibm.com>

	* dfp.h (decimal_from_string): Use const reference for argument.
	* dfp.c (decimal_from_string): Likewise.
2017-10-24 18:34:41 +02:00
Ulrich Weigand 8ba0dd515c Target FP printing: Use floatformat_to_string in tdep code
A few tdep files use target-specific printing routines to output values in
the floating-point registers.  To get rid of host floating-point code,
this patch changes them to use floatformat_to_string instead.

No functional change intended, the resulting output should look the same.

ChangeLog:
2017-10-24  Ulrich Weigand  <uweigand@de.ibm.com>

	* i387-tdep.c (print_i387_value): Use floatformat_to_string.
	* sh64-tdep.c (sh64_do_fp_register): Likewise.
	* mips-tdep.c (mips_print_fp_register): Likewise.
2017-10-24 18:01:39 +02:00
Ulrich Weigand 16e812b29e Target FP printing: Simplify and fix ui_printf
This patch adds support for handling format strings to both
floatformat_to_string and decimal_to_string, and then uses
those routines to implement ui_printf formatted printing.

There is already a subroutine printf_decfloat that ui_printf uses to
handle decimal FP.  This is renamed to printf_floating and updated
to handle both binary and decimal FP.  This includes the following
set of changes:

- printf_decfloat currently parses the format string again to determine
  the intended target format.  This seems superfluous since the common
  parsing code in parse_format_string already did this, but then did
  not pass the result on to its users.  Fixed by splitting the decfloat_arg
  argument class into three distinct classes, and passing them through.

- Now we can rename printf_decfloat to printf_floating and also call it
  for the argument classes representing binary FP types.

- The code will now use the argclass to detect the type the value should
  be printed at, and converts the input value to this type if necessary.
  To remain compatible with current behavior, for binary FP the code
  instead tries to re-interpret the input value as a FP type of the
  same size if that exists.  (Maybe this behavior is more confusing
  than useful -- but this can be changed later if we want to ...)

- Finally, we can use floatformat_to_string / decimal_to_string passing
  the format string to perform the formatted output using the desired
  target FP type.

Note that we no longer generate different code depending on whether or not
the host supports "long double" -- this check is obsolete anyway since C++11
mandates "long double", and in any case a %lg format string is intended to
refer to the *target* long double type, not the host version.

Note also that formatted printing of DFP numbers may not work correctly,
since it attempts to use the host printf to do so (and makes unwarranted
assumptions about the host ABI while doing so!).  This is no change to
the current behavior -- I simply moved the code from printf_decfloat to
the decimal_to_string routine in dfp.c.  If we want to fix it in the
future, that is a more appropriate place anyway.

ChangeLog:
2017-10-24  Ulrich Weigand  <uweigand@de.ibm.com>

	* common/format.h (enum argclass): Replace decfloat_arg by
	dec32float_arg, dec64float_arg, and dec128float_arg.
	* common/format.c (parse_format_string): Update to return
	new decimal float argument classes.

	* printcmd.c (printf_decfloat): Rename to ...
	(printf_floating): ... this.  Add argclass argument, and use it
	instead of parsing the format string again.  Add support for
	binary floating-point values, using floatformat_to_string.
	Convert value to the target format if it doesn't already match.
	(ui_printf): Call printf_floating instead of printf_decfloat,
	also for double_arg / long_double_arg.  Pass argclass.

	* dfp.c (decimal_to_string): Add format string argument.
	* dfp.h (decimal_to_string): Likewise.

	* doublest.c (floatformat_to_string): Add format string argument.
	* doublest.h (floatformat_to_string): Likewise.
2017-10-24 18:00:50 +02:00
Ulrich Weigand fdf0cbc2b7 Target FP printing: Simplify and fix print_floating
The print_floating routine currently makes a lot of assumptions about host
and target floating point formats.  This patch cleans up many of those.

One problem is that print_floating may currently be called with types
that are not actually floating-point types, and it tries hard to output
those as floating-point values anyway.  However, there is only one single
caller of print_floating where this can ever happen: print_scalar_formatted.
And in fact, it is much simpler to handle the case where the value to be
printed is not already of floating-point type right there.

So this patch changes print_scalar_formatted to handle the 'f' format
as follows:

- If the value to be printed is already of floating-point type, just
  call print_floating on it.

- Otherwise, if there is a standard target floating-point type of
  the same size as the value, call print_floating using that type.

- Otherwise, just print the value as if the 'f' format had not been
  specified at all.

This has the overall effect to printing everything the same way as
the old code did, but is overall a lot simpler.  (Also, it would
allow us to change the above strategy more easily, if that might
be a more intuitive user interface.  For example, in the third
case above, maybe an error would be more appropriate?)

Given that change, print_floating can become much simpler.  In particular,
we now always have a floating-point format that we can consult.  This
means we can use the floating-point format to programmatically determine
the number of digits necessary to print the value.

The current code uses a hard-coded value of 9, 17, or 35 digits.  Note
that this matches the DECIMAL_DIG values for IEEE-32, IEEE-64, and
IEEE-128.  (Actually, for IEEE-128 the correct value is 36 -- the 35
seems to be an oversight.)  The DECIMAL_DIG value is defined to be
the smallest number so that any number in the target format, when
printed to this number of digits and then scanned back into a binary
floating-point number, will result in the original value.

Now that we always have a FP format, we can just compute the DECIMAL_DIG
value using the formula from the C standard.  This will be correct for
*all* FP formats, not just the above list, and it will be correct (as
opposed to current code) if the target formats differ from the host ones.

The patch moves the new logic to a new floatformat_to_string routine
(analogous to the existing decimal_to_string).  The print_floating
routine now calls floatformat_to_string or decimal_to_string, making
the separate print_decimal_floating and generic_val_print_decfloat routines
unnecessary.

gdb/ChangeLog:
2017-10-24  Ulrich Weigand  <uweigand@de.ibm.com>

	* doublest.c (floatformat_precision): New routine.
	(floatformat_to_string): Likewise.
	* doublest.c (floatformat_to_string): Add prototype.

	* printcmd.c (print_scalar_formatted): Only call print_floating
	on floating-point types.
	* valprint.c: Do not include "floatformat.h".
	(generic_val_print_decfloat): Remove.
	(generic_val_print): Call generic_val_print_float for both
	TYPE_CODE_FLT and TYPE_CODE_DECFLOAT.
	(print_floating): Use floatformat_to_string.  Handle decimal float.
	(print_decimal_floating): Remove, merge into floatformat_to_string.
	* value.h (print_decimal_floating): Remove.

	* Makefile.in: Do not build doublest.c with -Wformat-nonliteral.
2017-10-24 17:59:22 +02:00
Ulrich Weigand 5033013f17 Fix gdb.opt/inline-cmds.exp regressions
When sorting pending blocks in end_symtab_get_static_block, blocks
with the same starting address must remain in the original order
to preserve inline function caller/callee relationships.

The original code seems to have implicitly relied on the fact that the
glibc qsort implemention actually (in the common case) provides a stable
sort, although this is not guaranteed by the standard.  But the GNU
libstdc++ std::sort implementation is *not* stable.

gdb/ChangeLog:
2017-10-24  Ulrich Weigand  <uweigand@de.ibm.com>

	* buildsym.c (end_symtab_get_static_block): Use std::stable_sort.
2017-10-24 16:33:53 +02:00
Pedro Alves eb2bfbadc1 Reindent gdb.threads/attach-into-signal.exp
A previous patch removed one nesting level.

gdb/testsuite/ChangeLog:
2017-10-24  Pedro Alves  <palves@redhat.com>

	* gdb.threads/attach-into-signal.exp (corefunc): Reindent.
2017-10-24 10:55:50 +01:00
Pedro Alves 1f75a6516a Drop /proc/PID/status polling from gdb.threads/attach-into-signal.exp
I noticed that the 'with_test_prefix "stoppedtry $stoppedtry"' prefix
in this testcase is unnecessary, because inside that block there are
no pass/fail calls.  In fact the block includes a comment saying:

  # No PASS message as we may be looping in multiple
  # attempts.

but looking deeper at this I noticed a few odd things with this code
block:

1. This code is assuming that the second line in the /proc/PID/status
   files is the "State:" line, which may have been true when this was
   originally written, but is not true on my machine at least (Linux
   4.8.13).

     $ cat /proc/self/status
     Name:   cat
     Umask:  0002
     State:  R (running)

   So nowadays, that 'string match "*(stopped)*"' is running against
   the "Umask:" line and thus always returns false, meaning the loop
   always breaks on $stoppedtry == 0.

2. The loop seems to be waiting for the process to become "(stopped)",
   but if so then that 'if {![string match]}' check is reversed, it
   should be checking 'if {[string match]}' instead, because "string
   match" returns true if the string matches, not 0.

3. But if we fixed all that, we'd still run into the simple fact that
   nothing is actually stopping the test's inferior process before GDB
   attaches...  The top of the testcase says:

    # This test was created by modifying attach-stopped.exp.

   ... and attach-stopped.exp does have:

       # Stop the program
       remote_exec build "kill -s STOP ${testpid}"

   but then attach-stopped.exp doesn't have an equivalent
   /proc/PID/status poll loop...  (Maybe it could.)

So remove this whole loop as useless.

gdb/testsuite/ChangeLog:
2017-10-24  Pedro Alves  <palves@redhat.com>

	* gdb.threads/attach-into-signal.exp: Remove whole "stoppedtry"
	loop.
2017-10-24 10:54:56 +01:00
Pedro Alves 779990d9f0 Fix unstable test names in gdb.threads/attach-into-signal.exp
Currently, if you diff testsuite/gdb.sum of two testsuite runs you'll
often see spurious hunks like these:

  -PASS: gdb.threads/attach-into-signal.exp: nonthreaded: attempt 2: attach (pass 2), pending signal catch
  +PASS: gdb.threads/attach-into-signal.exp: nonthreaded: attempt 1: attach (pass 2), pending signal catch
   PASS: gdb.threads/attach-into-signal.exp: successfully compiled posix threads test case
   PASS: gdb.threads/attach-into-signal.exp: threaded: handle SIGALRM stop print pass
  -PASS: gdb.threads/attach-into-signal.exp: threaded: attempt 1: attach (pass 1), pending signal catch
  -PASS: gdb.threads/attach-into-signal.exp: threaded: attempt 1: attach (pass 2), pending signal catch
  +PASS: gdb.threads/attach-into-signal.exp: threaded: attempt 2: attach (pass 1), pending signal catch
  +PASS: gdb.threads/attach-into-signal.exp: threaded: attempt 4: attach (pass 2), pending signal catch

Fix this by removing the "attempt $attempt" test prefix.  The attempt
number can be retrieved from gdb.log instead, since the testcase is
already using "verbose -log" to that effect.

(The 'with_test_prefix "stoppedtry $stoppedtry"' prefix is unnecessary
too, because inside that block there are no pass/fail calls.  In fact
the block includes a comment saying:

  # No PASS message as we may be looping in multiple
  # attempts.

but I'll drop that whole loop in the next patch instead.)

After this commit we'll show:

  PASS: gdb.threads/attach-into-signal.exp: nonthreaded: handle SIGALRM stop print pass
  PASS: gdb.threads/attach-into-signal.exp: nonthreaded: attach (pass 1), pending signal catch
  PASS: gdb.threads/attach-into-signal.exp: nonthreaded: attach (pass 2), pending signal catch
  PASS: gdb.threads/attach-into-signal.exp: successfully compiled posix threads test case
  PASS: gdb.threads/attach-into-signal.exp: threaded: handle SIGALRM stop print pass
  PASS: gdb.threads/attach-into-signal.exp: threaded: attach (pass 1), pending signal catch
  PASS: gdb.threads/attach-into-signal.exp: threaded: attach (pass 2), pending signal catch

(I've avoided reindenting to make the patch easier to maintain/read.
I'll reindent the blocks after this is in.)

gdb/testsuite/ChangeLog:
2017-10-24  Pedro Alves  <palves@redhat.com>

	* gdb.threads/attach-into-signal.exp (corefunc): Remove "attach
	$attempt" test prefix.
2017-10-24 10:54:12 +01:00
Pedro Alves ad9b8f5d02 Fix unstable test names in gdb.python/py-objfile.exp
Currently, if you diff testsuite/gdb.sum of different builds you see
this spurious hunk:

  -PASS: gdb.python/py-objfile.exp: get python valueof "sep_objfile.build_id" (6a0bfcab663f9810ccff33c756afdebb940037d4)
  +PASS: gdb.python/py-objfile.exp: get python valueof "sep_objfile.build_id" (1f5531c657c57777b05fc95baa0025fd1d115c3b)

Fix this by syncing get_python_valueof with get_integer_valueof, which
stopped outputting the value in commit 2f20e312aa
("get_integer_valueof: Don't output value in test name").

After this commit we'll show:

  PASS: gdb.python/py-objfile.exp: get python valueof "sep_objfile.build_id"

As the comment explicitly says get_python_valueof is modeled on
get_integer_valueof, I went ahead and also added the optional 'test'
parameter while at it.

gdb/testsuite/ChangeLog:
2017-10-24  Pedro Alves  <palves@redhat.com>

	* lib/gdb-python.exp (get_python_valueof): Add 'test' optional
	parameter and handle it.  Don't output read value in test name.
2017-10-24 10:53:29 +01:00
Pedro Alves fee6da6e1d Fix unstable test names in gdb.gdb/unittest.exp
Currently, if you diff testsuite/gdb.sum of two builds built from different
source directories you see this spurious hunk:

  -PASS: gdb.gdb/unittest.exp: maintenance check xml-descriptions /home/pedro/gdb1/src/gdb/testsuite/../features
  +PASS: gdb.gdb/unittest.exp: maintenance check xml-descriptions /home/pedro/gdb2/src/gdb/testsuite/../features

After this commit we'll show instead:

  PASS: gdb.gdb/unittest.exp: maintenance check xml-descriptions ${srcdir}/../features

gdb/testsuite/ChangeLog:
2017-10-24  Pedro Alves  <palves@redhat.com>

	* gdb.gdb/unittest.exp ('maintenance check xml-descriptions'): Use
	custom test name.
2017-10-24 10:53:03 +01:00
Pedro Alves 10389c2c8b Fix unstable test names in gdb.base/startup-with-shell.exp
Currently, if you diff testsuite/gdb.sum of two builds in different
directories you see these spurious hunks:

  -PASS: gdb.base/startup-with-shell.exp: touch /home/pedro/gdb1/build/gdb/testsuite/outputs/gdb.base/startup-with-shell/unique-file.unique-extension
  +PASS: gdb.base/startup-with-shell.exp: touch /home/pedro/gdb2/build/gdb/testsuite/outputs/gdb.base/startup-with-shell/unique-file.unique-extension

  -PASS: gdb.base/startup-with-shell.exp: startup_with_shell = on; run_args = *.unique-extension: set args /home/pedro/gdb1/build/gdb/testsuite/outputs/gdb.base/startup-with-shell/*.unique-extension
  +PASS: gdb.base/startup-with-shell.exp: startup_with_shell = on; run_args = *.unique-extension: set args /home/pedro/gdb2/build/gdb/testsuite/outputs/gdb.base/startup-with-shell/*.unique-extension

  -PASS: gdb.base/startup-with-shell.exp: startup_with_shell = off; run_args = *.unique-extension: set args /home/pedro/gdb1/build/gdb/testsuite/outputs/gdb.base/startup-with-shell/*.unique-extension
  +PASS: gdb.base/startup-with-shell.exp: startup_with_shell = off; run_args = *.unique-extension: set args /home/pedro/gdb2/build/gdb/testsuite/outputs/gdb.base/startup-with-shell/*.unique-extension

Since the run_args arguments are already shown in the test prefix, we
can change the "set args" test name to literally "set args $run_args".
I.e., after this commit we'll show:

  PASS: gdb.base/startup-with-shell.exp: startup_with_shell = on; run_args = *.unique-extension: set args $run_args
  PASS: gdb.base/startup-with-shell.exp: startup_with_shell = off; run_args = *.unique-extension: set args $run_args
  PASS: gdb.base/startup-with-shell.exp: startup_with_shell = on; run_args = $TEST: set args $run_args
  PASS: gdb.base/startup-with-shell.exp: startup_with_shell = off; run_args = $TEST: set args $run_args

gdb/testsuite/ChangeLog:
2017-10-24  Pedro Alves  <palves@redhat.com>

	* gdb.base/startup-with-shell.exp ('touch $unique_file'): Don't
	include the unstable output directory name in the test's name.
	(initial_setup_simple) <'set args'>: Use custom test name.
2017-10-24 10:52:09 +01:00
Pedro Alves a80e65a9d5 Fix unstable test names in gdb.arch/arc-tdesc-cpu.exp
Currently if you diff testsuite/gdb.sum of two builds built from
different source trees you see this spurious hunk:

  -PASS: gdb.arch/arc-tdesc-cpu.exp: set tdesc filename /home/pedro/gdb1/src/gdb/testsuite/gdb.arch/arc-tdesc-cpu.xml
  +PASS: gdb.arch/arc-tdesc-cpu.exp: set tdesc filename /home/pedro/gdb2/src/gdb/testsuite/gdb.arch/arc-tdesc-cpu.xml

After this commit we'll show this instead in gdb.sum:
  PASS: gdb.arch/arc-tdesc-cpu.exp: set tdesc filename $srcdir/gdb.arch/arc-tdesc-cpu.xml

gdb/testsuite/ChangeLog:
2017-10-24  Pedro Alves  <palves@redhat.com>

	* gdb.arch/arc-tdesc-cpu.exp ('set tdesc filename'): Use gdb_test
	with explicit test name.
2017-10-24 10:43:33 +01:00
Simon Marchi 4d3bb80e5d Add overloads of for_each_thread/find_thread that filter on pid
It happens often that we want to iterate or find threads restricted to a
given pid.  I think it's worth having an overload to help with this.
Right now there is a single user of each of the find_thread and
for_each_thread overload, but as we replace the usages of find_inferior
with for_each_thread/find_thread, more usages will pop up.

gdb/gdbserver/ChangeLog:

	* gdbthread.h (find_thread, for_each_thread): New functions.
	* inferiors.c (thread_of_pid): Remove.
	(find_any_thread_of_pid): Use find_thread.
	* linux-low.c (num_lwps): Use for_each_thread.
2017-10-21 12:20:21 -04:00
Simon Marchi a664f67e50 Get rid of VEC (mem_region)
This patch removes VEC (mem_region).  Doing so requires touching a lot
of little things here and there.

The fields in mem_attrib are now initialized during construction.  The
values match those that were in default_mem_attrib (now removed).
unknown_mem_attrib is also removed, and replaced with a static method
(mem_attrib::unknown) that returns the equivalent.

mem_region is initialized in a way similar to mem_region_init (now
removed) did.

I found the organization of mem_region_list and target_mem_region_list a
bit confusing.  Sometimes mem_region_list points to the same vector as
target_mem_region_list (and therefore does not own it), and sometimes
(when the user manually edits the mem regions) points to another vector,
and in this case owns it.  To avoid this ambiguity, I think it is
simpler to have two vectors, one for target-defined regions and one for
user-defined regions, and have mem_region_list point to one or the
other.  There are now no vector objects dynamically allocated, both are
static.

The make-target-delegates script does not generate valid code when a
target method returns a type with a parameter list.  For this reason, I
created a typedef (mem_region_vector) that's only used in the target_ops
structure.  If you speak perl, you are welcome to improve the script!

Regtested on the buildbot.

gdb/ChangeLog:

	* memattr.h: Don't include vec.h.
	(struct mem_attrib): Initialize fields.
	<unknown>: New static method.
	(struct mem_region): Add constructors, operator<, initialize
	fields.
	* memattr.c: Include algorithm.
	(default_mem_attrib, unknown_mem_attrib): Remove.
	(user_mem_region_list): New global.
	(target_mem_region_list, mem_region_list): Change type to
	std::vector<mem_region>.
	(mem_use_target): Now a function.
	(target_mem_regions_valid): Change type to bool.
	(mem_region_lessthan, mem_region_cmp, mem_region_init): Remove.
	(require_user_regions): Adjust.
	(require_target_regions): Adjust.
	(create_mem_region): Adjust.
	(lookup_mem_region): Adjust.
	(invalidate_target_mem_regions): Adjust.
	(mem_clear): Rename to...
	(user_mem_clear): ... this, and adjust.
	(mem_command): Adjust.
	(info_mem_command): Adjust.
	(mem_enable, enable_mem_command, mem_disable,
	disable_mem_command): Adjust.
	(mem_delete): Adjust.
	(delete_mem_command): Adjust.
	* memory-map.h (parse_memory_map): Return an std::vector.
	* memory-map.c (parse_memory_map): Likewise.
	(struct memory_map_parsing_data): Add constructor.
	<memory_map>: Point to std::vector.
	(memory_map_start_memory): Adjust.
	(memory_map_end_memory): Adjust.
	(memory_map_end_property): Adjust.
	(clear_result): Remove.
	* remote.c (remote_memory_map): Return an std::vector.
	* target-debug.h (target_debug_print_VEC_mem_region_s__p):
	Remove.
	(target_debug_print_mem_region_vector): New.
	* target-delegates.c: Regenerate.
	* target.h (mem_region_vector): New typedef.
	(to_memory_map): Return mem_region_vector.
	(target_memory_map): Return an std::vector.
	* target.c (target_memory_map): Return an std::vector.
	(flash_erase_command): Adjust.
2017-10-21 12:15:42 -04:00
Simon Marchi 6e17c56511 Use std::string in memory_map_parsing_data
Replace the fixed-size array with a string.

gdb/ChangeLog:

	* memory-map.c (struct memory_map_parsing_data) <property_name>:
	Change type to std::string.
	(memory_map_start_property): Adjust.
	(memory_map_end_property): Adjust.
2017-10-21 12:06:22 -04:00
Simon Marchi cfba98720f Create a displaced_step_closure class hierarchy
displaced_step_closure is a type defined in multiple -tdep.c files.
Trying to xfree it from the common code (infrun.c) is a problem when we
try to poison xfree for non-POD types.  Because there can be multiple of
these types in the same build, this patch makes a hierarchy of classes
with a virtual destructor.  When the common code deletes the object
through a displaced_step_closure pointer, it will invoke the right
destructor.

The amd64 used a last-member array with a variable size.  That doesn't
work with new, so I changed it for an std::vector.  Other architectures
which used a simple byte buffer as a closure now use a shared
buf_displaced_step_closure, a closure type that only contains a
gdb::byte_vector.

Reg-tested on the buildbot.

gdb/ChangeLog:

	* infrun.h: Include common/byte-vector.h.
	(struct displaced_step_closure): New struct.
	(struct buf_displaced_step_closure): New struct.
	* infrun.c (displaced_step_closure::~displaced_step_closure):
	Provide default implementation.
	(displaced_step_clear): Deallocate step closure with delete.
	* aarch64-tdep.c (displaced_step_closure): Rename to ...
	(aarch64_displaced_step_closure): ... this, extend
	displaced_step_closure.
	(aarch64_displaced_step_data) <dsc>: Change type to
	aarch64_displaced_step_closure.
	(aarch64_displaced_step_copy_insn): Adjust to type change, use
	unique_ptr.
	(aarch64_displaced_step_fixup): Add cast for displaced step
	closure.
	* amd64-tdep.c (displaced_step_closure): Rename to ...
	(amd64_displaced_step_closure): ... this, extend
	displaced_step_closure.
	<insn_buf>: Change type to std::vector<gdb_byte>.
	<max_len>: Remove.
	(fixup_riprel): Change type of DSC parameter, adjust to type
	change of insn_buf.
	(fixup_displaced_copy): Change type of DSC parameter.
	(amd64_displaced_step_copy_insn): Instantiate
	amd64_displaced_step_closure.
	(amd64_displaced_step_fixup): Add cast for closure type, adjust
	to type change of insn_buf.
	* arm-linux-tdep.c (arm_linux_cleanup_svc): Change type of
	parameter DSC.
	(arm_linux_copy_svc): Likewise.
	(cleanup_kernel_helper_return): Likewise.
	(arm_catch_kernel_helper_return): Likewise.
	(arm_linux_displaced_step_copy_insn): Instantiate
	arm_displaced_step_closure.
	* arm-tdep.c (arm_pc_is_thumb): Add cast for closure.
	(displaced_read_reg): Change type of parameter DSC.
	(branch_write_pc): Likewise.
	(load_write_pc): Likewise.
	(alu_write_pc): Likewise.
	(displaced_write_reg): Likewise.
	(arm_copy_unmodified): Likewise.
	(thumb_copy_unmodified_32bit): Likewise.
	(thumb_copy_unmodified_16bit): Likewise.
	(cleanup_preload): Likewise.
	(install_preload): Likewise.
	(arm_copy_preload): Likewise.
	(thumb2_copy_preload): Likewise.
	(install_preload_reg): Likewise.
	(arm_copy_preload_reg): Likewise.
	(cleanup_copro_load_store): Likewise.
	(install_copro_load_store): Likewise.
	(arm_copy_copro_load_store) Likewise.
	(thumb2_copy_copro_load_store): Likewise.
	(cleanup_branch): Likewise.
	(install_b_bl_blx): Likewise.
	(arm_copy_b_bl_blx): Likewise.
	(thumb2_copy_b_bl_blx): Likewise.
	(thumb_copy_b): Likewise.
	(install_bx_blx_reg): Likewise.
	(arm_copy_bx_blx_reg): Likewise.
	(thumb_copy_bx_blx_reg): Likewise.
	(cleanup_alu_imm): Likewise.
	(arm_copy_alu_imm): Likewise.
	(thumb2_copy_alu_imm): Likewise.
	(cleanup_alu_reg): Likewise.
	(install_alu_reg): Likewise.
	(arm_copy_alu_reg): Likewise.
	(thumb_copy_alu_reg): Likewise.
	(cleanup_alu_shifted_reg): Likewise.
	(install_alu_shifted_reg): Likewise.
	(arm_copy_alu_shifted_reg): Likewise.
	(cleanup_load): Likewise.
	(cleanup_store): Likewise.
	(arm_copy_extra_ld_st): Likewise.
	(install_load_store): Likewise.
	(thumb2_copy_load_literal): Likewise.
	(thumb2_copy_load_reg_imm): Likewise.
	(arm_copy_ldr_str_ldrb_strb): Likewise.
	(cleanup_block_load_all): Likewise.
	(cleanup_block_store_pc): Likewise.
	(cleanup_block_load_pc): Likewise.
	(arm_copy_block_xfer): Likewise.
	(thumb2_copy_block_xfer): Likewise.
	(cleanup_svc): Likewise.
	(install_svc): Likewise.
	(arm_copy_svc): Likewise.
	(thumb_copy_svc): Likewise.
	(arm_copy_undef): Likewise.
	(thumb_32bit_copy_undef): Likewise.
	(arm_copy_unpred): Likewise.
	(arm_decode_misc_memhint_neon): Likewise.
	(arm_decode_unconditional): Likewise.
	(arm_decode_miscellaneous): Likewise.
	(arm_decode_dp_misc): Likewise.
	(arm_decode_ld_st_word_ubyte): Likewise.
	(arm_decode_media): Likewise.
	(arm_decode_b_bl_ldmstm): Likewise.
	(arm_decode_ext_reg_ld_st): Likewise.
	(thumb2_decode_dp_shift_reg): Likewise.
	(thumb2_decode_ext_reg_ld_st): Likewise.
	(arm_decode_svc_copro): Likewise.
	(thumb2_decode_svc_copro): Likewise.
	(install_pc_relative): Likewise.
	(thumb_copy_pc_relative_16bit): Likewise.
	(thumb_decode_pc_relative_16bit): Likewise.
	(thumb_copy_pc_relative_32bit): Likewise.
	(thumb_copy_16bit_ldr_literal): Likewise.
	(thumb_copy_cbnz_cbz): Likewise.
	(thumb2_copy_table_branch): Likewise.
	(cleanup_pop_pc_16bit_all): Likewise.
	(thumb_copy_pop_pc_16bit): Likewise.
	(thumb_process_displaced_16bit_insn): Likewise.
	(decode_thumb_32bit_ld_mem_hints): Likewise.
	(thumb_process_displaced_32bit_insn): Likewise.
	(thumb_process_displaced_insn): Likewise.
	(arm_process_displaced_insn): Likewise.
	(arm_displaced_init_closure): Likewise.
	(arm_displaced_step_fixup): Add cast for closure.
	* arm-tdep.h: Include infrun.h.
	(displaced_step_closure): Rename to ...
	(arm_displaced_step_closure): ... this, extend
	displaced_step_closure.
	<u::svc::copy_svc_os>: Change type of parameter DSC.
	<cleanup>: Likewise.
	(arm_process_displaced_insn): Likewise.
	(arm_displaced_init_closure): Likewise.
	(displaced_read_reg): Likewise.
	(displaced_write_reg): Likewise.
	* i386-linux-tdep.c (i386_linux_displaced_step_copy_insn):
	Adjust.
	* i386-tdep.h: Include infrun.h.
	(i386_displaced_step_closure): New typedef.
	* i386-tdep.c (i386_displaced_step_copy_insn): Use
	i386_displaced_step_closure.
	(i386_displaced_step_fixup): Adjust.
	* rs6000-tdep.c (ppc_displaced_step_closure): New typedef.
	(ppc_displaced_step_copy_insn): Use ppc_displaced_step_closure
	and unique_ptr.
	(ppc_displaced_step_fixup): Adjust.
	* s390-linux-tdep.c (s390_displaced_step_closure): New typedef.
	(s390_displaced_step_copy_insn): Use s390_displaced_step_closure
	and unique_ptr.
	(s390_displaced_step_fixup): Adjust.
2017-10-21 11:27:52 -04:00
Simon Marchi b392b304b9 Remove leftover declarations in interps.h
The corresponding definitions have already been removed.

gdb/ChangeLog:

	* interps.h (interp_resume, interp_suspend, interp_set_temp):
	Remove declarations.
2017-10-21 10:15:48 -04:00
Tom Tromey d5833c62d9 Use std::vector in gdb_bfd_data
This changes gdb_bfd_data to use std::vector rather than VEC.

ChangeLog
2017-10-20  Tom Tromey  <tom@tromey.com>

	* gdb_bfd.c (struct gdb_bfd_data) <included_bfds>: Now a
	std::vector.
	(gdb_bfd_record_inclusion): Update.
	(bfdp): Remove typedef.
2017-10-20 09:01:04 -06:00
Tom Tromey 06d5bbc8e5 Use "new" to allocate gdb_bfd_data
This changes gdb_bfd_data to be allocated with new and destroyed with
delete.

ChangeLog
2017-10-20  Tom Tromey  <tom@tromey.com>

	* gdb_bfd.c (gdb_bfd_ref): Use new.
	(struct gdb_bfd_data): Add constructor, destructor, and member
	initializers.
	(gdb_bfd_unref): Use delete.
2017-10-20 09:01:03 -06:00
Tom Tromey 2712ce2e65 Introduce new_bfd_ref
This introduces a helper function, new_bfd_ref, that calls gdb_bfd_ref
and returns a gdb_bfd_ref_ptr.  Then it updates several places to use
this.

ChangeLog
2017-10-20  Tom Tromey  <tom@tromey.com>

	* exec.c (exec_file_attach): Use new_bfd_ref.
	* symfile-mem.c (symbol_file_add_from_memory): Use new_bfd_ref.
	* gdb_bfd.c (gdb_bfd_open, gdb_bfd_fopen, gdb_bfd_openr)
	(gdb_bfd_openw, gdb_bfd_openr_iovec, gdb_bfd_fdopenr): Use
	new_bfd_ref.
	* gdb_bfd.h (new_bfd_ref): New function.
2017-10-20 09:01:03 -06:00
Pedro Alves 15763a09d4 Fix 'gdb.base/quit.exp hangs forever' if the test fails
The [wait -i $gdb_spawn_id] in the test is dangerous in the sense that
it won't be subject to timeout logic.  So if GDB fails quiting, this
testcase hangs forever, hanging the test run with it.  See:
  https://sourceware.org/ml/gdb-patches/2016-10/msg00728.html

Instead of 'wait'ing directly, use gdb_test_multiple and expect 'eof'.

Tested that the testcase no longer hangs by hacking the test to send
"info threads" instead of "quit".

Tested with
  --target_board={unix, native-gdbserver,native-extended-gdbserver}
and tested with
  --host_board=local-remote-host
as well.

gdb/testsuite/ChangeLog:
2017-10-20  Pedro Alves  <palves@redhat.com>

	* gdb.base/quit.exp: Use gdb_test_multiple and expect 'eof' before
	'wait -i'.  Use gdb_assert and remote_close.
2017-10-20 15:33:57 +01:00
Pedro Alves fcc8fb2f3d Fix gdb.gdb/ selftest tests when testing optimized GDB builds
After commit bf46927112 ("Eliminate catch_errors"), GCC started
inlining captured_command_loop in captured_main.  And setting a
breakpoint on captured_command_loop makes the inferior GDB stop in
captured_main, _after_ captured_command_loop's call to
interp_pre_command_loop, which prints the inferior GDB's prompt, has
already executed, confusing the gdb.gdb/ selftest tests:

  (gdb) FAIL: gdb.gdb/complaints.exp: run until breakpoint at captured_command_loop
  WARNING: Couldn't test self

Debugging GDB with GDB manually, we see:

  (top-gdb) b captured_command_loop
  Breakpoint 1 at 0x71ee60: file src/gdb/main.c, line 324.
  (top-gdb) r
  [....]
  (gdb)                  <<<<<< PROMPT HERE
  Thread 1 "gdb" hit Breakpoint 1, captured_main (data=<optimized out>) at src/gdb/main.c:1147
  1147              captured_command_loop ();
  (top-gdb)

Note the stop at 'captured_main', and the "PROMPT HERE" line.  That
prompt does not show up when debugging a non-optimized build of GDB.

Fix this by preventing inlining of captured_command_loop.

Ref: https://sourceware.org/ml/gdb-patches/2017-10/msg00522.html

gdb/ChangeLog:
2017-10-20  Pedro Alves  <palves@redhat.com>

	* main.c (captured_command_loop): Add attribute noinline.
2017-10-20 14:47:24 +01:00
Simon Marchi 4c2287b0bd Get rid of VEC(interp_factory_p)
Replace it with an std::vector.

gdb/ChangeLog:

	* interps.c (struct interp_factory): Add constructor.
	(interp_factory_p): Remove typedef.
	(DEF_VEC_P(interp_factory_p)): Remove.
	(interpreter_factories): Change type to std::vector.
	(interp_factory_register): Adjust.
	(interp_lookup): Adjust.
	(interpreter_completer): Adjust.
2017-10-19 22:07:15 -04:00
Tom Tromey 3d415c26ba Remove cleanups from break-catch-syscall.c
This removes the remaining cleanups from break-catch-syscall.c by
storing temporary strings in a vector.

ChangeLog
2017-10-19  Tom Tromey  <tom@tromey.com>

	* break-catch-syscall.c (catch_syscall_completer): Use
	std::string, gdb::unique_xmalloc_ptr.
2017-10-19 15:58:43 -06:00
Tom Tromey 395423c418 Remove cleanup from call_function_by_hand_dummy
This changes call_function_by_hand_dummy to use std::string, removing
a cleanup.

ChangeLog
2017-10-19  Tom Tromey  <tom@tromey.com>

	* infcall.c (call_function_by_hand_dummy): Use std::string.
2017-10-19 15:58:12 -06:00
Tom Tromey 54f70bc145 Remove cleanups from prepare_execute_command
This changes prepare_execute_command to return a scoped_value_mark
rather than a cleanup.

ChangeLog
2017-10-19  Tom Tromey  <tom@tromey.com>

	* mi/mi-main.c (mi_cmd_execute): Update.
	* top.h (prepare_execute_command): Return scoped_value_mark.
	* value.h (class scoped_value_mark): Use DISABLE_COPY_AND_ASSIGN.
	Add move constructor.
	* top.c (prepare_execute_command): Return scoped_value_mark.
	(execute_command): Update.
2017-10-19 15:58:11 -06:00
Andrew Burgess 49a4ce2eae gdb: Remove hard-coded line number from test
Removes the use of a hard-coded line number from a test.

gdb/testsuite/ChangeLog:

	* gdb.linespec/ls-errs.exp (do_test): Update comment, use line
	number from variable rather than hard-coded.
2017-10-19 20:50:42 +01:00
Pedro Alves 63929e843d Fix build breakage in gdb/xml-support.c
The buildbots are showing that the previous change to
xml_fetch_content_from_file causes __wur warnings/errors:

  ../../binutils-gdb/gdb/xml-support.c: In function gdb::unique_xmalloc_ptr<char> xml_fetch_content_from_file(const char*, void*):
  ../../binutils-gdb/gdb/xml-support.c:1028:43: error: ignoring return value of size_t fread(void*, size_t, size_t, FILE*), declared with attribute warn_unused_result [-Werror=unused-result]
     fread (text.get (), 1, len, file.get ());
					     ^

This commit fixes it.

gdb/ChangeLog:
2017-10-19  Pedro Alves  <palves@redhat.com>

	* xml-support.c (xml_fetch_content_from_file): Check fread's
	return.
2017-10-19 18:12:03 +01:00
Pedro Alves a75868f50b Fix inferior deadlock with "target remote | CMD"
Comparing test results between

  --target_board=native-gdbserver
  --target_board=native-stdio-gdbserver

I noticed that gdb.base/bigcore.exp is failing with native-stdio-gdbserver:

  Running src/gdb/testsuite/gdb.base/bigcore.exp ...
  FAIL: gdb.base/bigcore.exp: continue (timeout)
  ...

The problem is that:

  1. When debugging with "target remote | CMD", the inferior's
     stdout/stderr streams are connected to a pipe.

  2. The bigcore.c program prints a lot to the screen before it
     reaches the breakpoint location that the "continue" shown above
     wants to reach.

  3. GDB is not flushing the inferior's output pipe while the inferior
     is running.

  4. The pipe becomes full.

  5. The inferior thus deadlocks.

The bug is #3 above, which is what this commit fixes.  A new test is
added, that specifically exercises this scenario.  The test fails
before the fix, and passes after, and gdb.base/bigcore.exp also starts
passing.

gdb/ChangeLog:
2017-10-19  Pedro Alves  <palves@redhat.com>

	* ser-base.c (ser_base_read_error_fd): Delete the file handler if
	async.
	(handle_error_fd): New function.
	(ser_base_async): Add/delete an event loop file handler for
	error_fd.

gdb/testsuite/ChangeLog:
2017-10-19  Pedro Alves  <palves@redhat.com>

	* gdb.base/long-inferior-output.c: New file.
	* gdb.base/long-inferior-output.exp: New file.
2017-10-19 16:00:21 +01:00
Pedro Alves 2edf834e29 xml_fetch_content_from_file: Read in whole file in one go
There doesn't seem to be a good reason we're reading the file one
chunk at a time.

gdb/ChangeLog:
2017-10-19  Pedro Alves  <palves@redhat.com>

	* xml-support.c (xml_fetch_content_from_file): Don't read in
	chunks.  Instead use fseek to determine the file's size, and read
	it in one go.
2017-10-19 15:25:59 +01:00
Keith Seitz c8ba13ad37 Canonicalize conversion operators
Consider a conversion operator such as:

operator foo const* const* ();

There are two small parser problems, highlighted by this test:

(gdb) p operator foo const* const*
There is no field named operatorfoo const* const *

GDB is looking up the symbol "operatorfoo const* const*" -- it is missing a
space between the keyword "operator" and the type name "foo const* const*".

Additionally, this input of the user-defined type needs to be canonicalized
so that different "spellings" of the type are recognized:

(gdb) p operator const foo* const *
There is no field named operator const foo* const *

gdb/ChangeLog:

	* c-exp.y (oper): Canonicalize conversion operators of user-defined
	types.
	Add whitespace to front of type name.

gdb/testsuite/ChangeLog:

	* gdb.cp/cpexprs.cc (base) <operator fluff const* const*>: New
	method.
	(main): Call it.
	* gdb.cp/cpexprs.exp: Add new conversion operator to test matrix.
	Add additional user-defined conversion operator tests.
2017-10-18 11:26:02 -07:00
Keith Seitz 3753468682 Issue complaint instead of assert for invalid/unhandled DW_AT_accessibility
A previous patch called gdb_assert_not_reached whenever reading
the accessibility of a nested typedef definition. Wisely, Pedro has asked me
not do this.

This patch changes the previous one so that it issues a complaint instead.

gdb/ChangeLog:

	* dwarf2read.c (dwarf2_add_typedef): Issue a complaint on unhandled
	DW_AT_accessibility.
2017-10-18 10:14:01 -07:00
Yao Qi 28c7c15876 Remove features/tic6x-c62x-linux.c
c40c7bf (Remove features/tic6x-*.c files) doesn't remove
features/tic6x-c62x-linux.c.  This patch removes it.

gdb:

2017-10-18  Yao Qi  <yao.qi@linaro.org>

	* features/tic6x-c62x-linux.c: Remove.
2017-10-18 12:48:12 +01:00
Pedro Alves b27de576d4 Really make the native-stdio-gdbserver board non-remote
I've noticed now that due to a last-minute change, commit 739b3f1d8f
("Make native gdbserver boards no longer be "remote" (in DejaGnu
terms)") managed to miss loading "local-board" in the
native-stdio-gdbserver board...

gdb/testsuite/ChangeLog:
2017-10-17  Pedro Alves  <palves@redhat.com>

	* boards/native-stdio-gdbserver.exp: Load "local-board".
2017-10-17 19:45:35 +01:00
Pedro Alves 8484c95545 Add several "quit with live inferior" tests
In my multi-target branch, I had managed to break GDB exiting
successfuly in response to "quit" or SIGHUP/SIGTERM when:

 - you're debugging with "target extended-remote",
 - have more than one inferior loaded in gdb, some running, and at
   least one not running, and,
 - quit gdb with the inferior that is not running yet selected.

The testsuite still passed cleanly anyway.  I only noticed because I
was left with a bunch of core dumps in the gdb/testsuite/ directory --
the testsuite infrastructure closes GDB's pty after running each
testcase, which results in GDB getting a SIGHUP and should make GDB
exit gracefully.  If GDB crashes at that point though, there's no
indication about it in gdb.sum/gdb.log.

This commit adds a multitude of tests exercising quitting GDB with
live inferiors, some of which would have caught the problem.

gdb/testsuite/ChangeLog:
2017-10-17  Pedro Alves  <palves@redhat.com>

	* gdb.base/quit-live.c: New file.
	* gdb.base/quit-live.exp: New file.
2017-10-17 14:58:54 +01:00
Tom Tromey 30f0b10158 Remove cleanups from disasm.c
This changes the remaining spots in disasm.c to use the RAII ui-out
emitters, removing a few cleanups.  This also fixes a regression that
Simon pointed out.

2017-10-17  Tom Tromey  <tom@tromey.com>

	* disasm.c (do_mixed_source_and_assembly_deprecated): Use
	gdb::optional, ui_out_emit_list, ui_out_emit_tuple.
	(do_mixed_source_and_assembly): Likewise.
2017-10-17 06:43:33 -06:00
Tom Tromey 57e12da97f Remove obsolete assertion from regcache.c
When building I got:

../../binutils-gdb/gdb/regcache.c:935:24: error: the address of ‘ssize_t read(int, void*, size_t)’ will never be NULL [-Werror=address]

This happens because "read" used to be a parameter to this function,
which was then removed; but the assertion wasn't updated.

I don't think the assertion is relevant any more, to this removes it.
I'm checking it in as obvious.

2017-10-17  Tom Tromey  <tom@tromey.com>

	* regcache.c (regcache::xfer_part): Remove assertion.
2017-10-17 06:42:36 -06:00
Pedro Alves 7b7009999a Fix double-free corruption
Fixes a double-free regression introduced by commit b7b030adc4
("Return unique_xmalloc_ptr from target_read_stralloc"):

gdb.sum:
  Running src/gdb/testsuite/gdb.base/catch-syscall.exp ...
  ERROR: Process no longer exists

Valgrind shows:

  (gdb) catch syscall
  ==3687== Thread 1:
  ==3687== Invalid free() / delete / delete[] / realloc()
  ==3687==    at 0x4C29CF0: free (vg_replace_malloc.c:530)
  ==3687==    by 0x610862: xfree(void*) (common-utils.c:101)
  ==3687==    by 0x440D5D: gdb::xfree_deleter<char>::operator()(char*) const (gdb_unique_ptr.h:34)
  ==3687==    by 0x446CC6: std::unique_ptr<char, gdb::xfree_deleter<char> >::reset(char*) (unique_ptr.h:344)
  ==3687==    by 0x81BE50: xml_fetch_content_from_file(char const*, void*) (xml-support.c:1042)
  ==3687==    by 0x81DA86: xml_init_syscalls_info(char const*) (xml-syscall.c:366)
  ==3687==    by 0x81DBDD: init_syscalls_info(gdbarch*) (xml-syscall.c:398)
  ==3687==    by 0x81E131: get_syscall_by_number(gdbarch*, int, syscall*) (xml-syscall.c:599)
  ==3687==    by 0x5BE86F: catch_syscall_command_1(char*, int, cmd_list_element*) (break-catch-syscall.c:481)
  ==3687==    by 0x4B46B1: do_sfunc(cmd_list_element*, char*, int) (cli-decode.c:138)
  ==3687==    by 0x4B76B8: cmd_func(cmd_list_element*, char*, int) (cli-decode.c:1952)
  ==3687==    by 0x7E91C7: execute_command(char*, int) (top.c:615)
  ==3687==  Address 0x14332ae0 is 0 bytes inside a block of size 4,096 free'd
  ==3687==    at 0x4C2AB8B: realloc (vg_replace_malloc.c:785)
  ==3687==    by 0x610792: xrealloc (common-utils.c:62)
  ==3687==    by 0x81BE3E: xml_fetch_content_from_file(char const*, void*) (xml-support.c:1042)
  ==3687==    by 0x81DA86: xml_init_syscalls_info(char const*) (xml-syscall.c:366)
  ==3687==    by 0x81DBDD: init_syscalls_info(gdbarch*) (xml-syscall.c:398)
  ==3687==    by 0x81E131: get_syscall_by_number(gdbarch*, int, syscall*) (xml-syscall.c:599)
  ==3687==    by 0x5BE86F: catch_syscall_command_1(char*, int, cmd_list_element*) (break-catch-syscall.c:481)
  ==3687==    by 0x4B46B1: do_sfunc(cmd_list_element*, char*, int) (cli-decode.c:138)
  ==3687==    by 0x4B76B8: cmd_func(cmd_list_element*, char*, int) (cli-decode.c:1952)
  ==3687==    by 0x7E91C7: execute_command(char*, int) (top.c:615)
  ==3687==    by 0x6A422D: command_handler(char*) (event-top.c:583)
  ==3687==    by 0x6A45F2: command_line_handler(char*) (event-top.c:773)
  [...]

The problem is that if xrealloc decides it needs a new memory block,
it frees the previous block/pointer, and then text.reset() frees it
again.

gdb/ChangeLog:
2017-10-17  Pedro Alves  <palves@redhat.com>

	* xml-support.c (xml_fetch_content_from_file): Call
	unique_ptr::release() instead unique_ptr::get() when passing
	through xrealloc.
2017-10-17 12:41:00 +01:00
Yao Qi d3037ba6a3 Simplify regcache::xfer_part
Since xfer_part is already a class method, and only
{raw,cooked}_{read,write} are passed to it.  We can remove these two
arguments, but add a bool argument is_raw, indicating raw registers or
cooked registers are accessed.

gdb:

2017-10-17  Yao Qi  <yao.qi@linaro.org>

	* regcache.c (regcache::xfer_part): Remove parameters read and
	write, add parameter is_raw.  All callers are updated.
2017-10-17 12:29:26 +01:00
Yao Qi 7a7cdfa04b [GDBserver] Move aarch64-insn.o to arch/ and remove one Makefile rule
gdb/gdbserver:

2017-10-17  Yao Qi  <yao.qi@linaro.org>

	* Makefile.in: Remove one rule.
	* configure.srv: Rename aarch64-insn.o with arch/aarch64-insn.o.
2017-10-17 12:12:04 +01:00
Yao Qi e675d1703f [GDBserver] Move arm-linux.o and arm-get-next-pcs.o to arch/
gdb/gdbserver:

2017-10-17  Yao Qi  <yao.qi@linaro.org>

	* configure.srv: Rename arm-linux.o with arch/arm-linux.o.
	Rename arm-get-next-pcs.o with arch/arm-get-next-pcs.o.
2017-10-17 12:12:04 +01:00
Yao Qi 7eb4e0f956 [GDBserver] Move arm.o to arch/arm.o
gdb/gdbserver:

2017-10-17  Yao Qi  <yao.qi@linaro.org>

	* configure.srv: Rename arm.o with arch/arm.o.
2017-10-17 12:12:04 +01:00
Yao Qi 60d6cfc99e [GDBserver] Replicate src dir in build dir
Similar to f38307f5 (Replicate src dir in build dir), this patch change
configure and Makefile to generate object files in arch/ directory.

gdb/gdbserver:

2017-10-17  Yao Qi  <yao.qi@linaro.org>

	* Makefile.in (CONFIG_SRC_SUBDIR): New variable.
	(clean): Remove .o files in CONFIG_SRC_SUBDIR.
	(distclean): Remove DEPDIR in CONFIG_SRC_SUBDIR.
	(arch-i386.o, arch-amd64.o): Remove rules.
	(arch/%.o): New rule.
	Update POSTCOMPILE and COMPILE.pre.
	* configure.ac: Invoke AC_CONFIG_COMMANDS.
	* configure: Re-generated.
	* configure.srv: Replace arch-i386.o with arch/i386.o.
	Replace arch-amd64.o with arch/amd64.o.
2017-10-17 12:12:04 +01:00
Keith Seitz 83d5a34dd4 Add missing ChangeLog entries. 2017-10-16 22:19:55 -07:00
Keith Seitz c191a6875b Record and output access specifiers for nested typedefs
We currently do not record access information for typedefs defined inside
classes.  Consider:

struct foo
{
   typedef int PUBLIC;
 private:
   typedef int PRIVATE;
   PRIVATE b;
};

(gdb) ptype foo
type = struct foo {
  private:
    PRIVATE b;

    typedef int PRIVATE;
    typedef int PUBLIC;
}

This patch fixes this:

(gdb) ptype foo
type = struct foo {
  private:
    PRIVATE b;

    typedef int PRIVATE;
  public:
    typedef int PUBLIC;
}

gdb/ChangeLog:

	* c-typeprint.c (enum access_specifier): Moved here from
	c_type_print_base.
	(output_access_specifier): New function.
	(c_type_print_base): Consider typedefs when assessing
	whether access labels are needed.
	Use output_access_specifier as needed.
	Output access specifier for typedefs, if needed.
	* dwarf2read.c (dwarf2_add_typedef): Record DW_AT_accessibility.
	* gdbtypes.h (struct typedef_field) <is_protected, is_private>: New
	fields.
	(TYPE_TYPEDEF_FIELD_PROTECTED, TYPE_TYPEDEF_FIELD_PRIVATE): New
	accessor macros.

gdb/testsuite/ChangeLog:

	* gdb.cp/classes.cc (class_with_typedefs, class_with_public_typedef)
	(class_with_protected_typedef, class_with_private_typedef)
	(struct_with_public_typedef, struct_with_protected_typedef)
	(struct_with_private_typedef): New classes/structs.
	* gdb.cp/classes.exp (test_ptype_class_objects): Add tests for
	typedefs and access specifiers.
2017-10-16 17:19:29 -07:00
Tom Tromey 87028b8739 Return unique_xmalloc_ptr from target_fileio_read_stralloc
Change target_fileio_read_stralloc to return unique_xmalloc_ptr and
fix up the callers.  This removes a number of cleanups.

ChangeLog
2017-10-16  Tom Tromey  <tom@tromey.com>

	* linux-tdep.c (linux_info_proc, linux_find_memory_regions_full)
	(linux_fill_prpsinfo, linux_vsyscall_range_raw): Update.
	* target.c (target_fileio_read_stralloc): Update.
	* sparc64-tdep.c (adi_is_addr_mapped): Update.
	* target.h (target_fileio_read_stralloc): Return
	unique_xmalloc_ptr.
2017-10-16 16:10:21 -06:00
Tom Tromey b7b030adc4 Return unique_xmalloc_ptr from target_read_stralloc
This changes target_read_stralloc to return a unique_xmalloc_ptr, and
then fixes all the callers.  unique_xmalloc_ptr is used, rather than
std::string, because target_read_stralloc gives a special meaning to a
NULL return.

ChangeLog
2017-10-16  Tom Tromey  <tom@tromey.com>

	* xml-syscall.c (xml_init_syscalls_info): Update.
	* xml-support.c (xinclude_start_include): Update.
	(xml_fetch_content_from_file): Return unique_xmalloc_ptr.
	* xml-support.h (xml_fetch_another): Return unique_xmalloc_ptr.
	(xml_fetch_content_from_file): Likewise.
	* osdata.c (get_osdata): Update.
	* target.h (target_read_stralloc, target_get_osdata): Return
	unique_xmalloc_ptr.
	* solib-aix.c (solib_aix_get_library_list): Update.
	* solib-target.c (solib_target_current_sos): Update.
	* solib-svr4.c (svr4_current_sos_via_xfer_libraries): Update.
	* xml-tdesc.c (fetch_available_features_from_target): Update.
	(target_fetch_description_xml): Update.
	(file_read_description_xml): Update.
	* remote.c (remote_get_threads_with_qxfer, remote_memory_map)
	(remote_traceframe_info, btrace_read_config, remote_read_btrace)
	(remote_pid_to_exec_file): Update.
	* target.c (target_read_stralloc): Return unique_xmalloc_ptr.
	(target_get_osdata): Likewise.
2017-10-16 16:10:21 -06:00
Tom Tromey b80406accc Simple cleanup removals in remote.c
This removes a few cleanups in remote.c using the usual techniques:
std::vector, unique_xmalloc_ptr, and gdb::def_vector.

ChangeLog
2017-10-16  Tom Tromey  <tom@tromey.com>

	* remote.c (remote_register_number_and_offset): Use std::vector.
	(remote_set_syscall_catchpoint): Use gdb::unique_xmalloc_ptr.
	(putpkt_binary): Use gdb::def_vector.
	(compare_sections_command): Use gdb::byte_vector.
2017-10-16 16:10:20 -06:00
Tom Tromey a90ecff85a Remove cleanup from ppc-linux-nat.c
This removes a cleanup from ppc-linux-nat.c, by using
unique_xmalloc_ptr.  It also slightly simplifies the code by using
XDUP rather than XNEW and memcpy.

ChangeLog
2017-10-16  Tom Tromey  <tom@tromey.com>

	* ppc-linux-nat.c (hwdebug_insert_point): Use
	gdb::unique_xmalloc_ptr, XDUP.
2017-10-16 16:10:20 -06:00
Tom Tromey 2dc0e21971 Remove some cleanups from probe.c
This removes some cleanups from parse_probes by using std::string; and
removes some unnecessary cleanups from elsewhere in probe.c.

ChangeLog
2017-10-16  Tom Tromey  <tom@tromey.com>

	* probe.c (parse_probes): Use std::string.
	(info_probes_for_ops, enable_probes_command)
	(disable_probes_command): Remove cleanups.
2017-10-16 16:10:19 -06:00
Tom Tromey b05628f0a8 Use std::vector in end_symtab_get_static_block
Change end_symtab_get_static_block to use std::vector.  This removes a
cleanup.

ChangeLog
2017-10-16  Tom Tromey  <tom@tromey.com>

	* buildsym.c (block_compar): Remove.
	(end_symtab_get_static_block): Use std::vector.
2017-10-16 16:10:19 -06:00
Pedro Alves 739b3f1d8f Make native gdbserver boards no longer be "remote" (in DejaGnu terms)
This commit finally clears the "isremote" flag in the native-gdbserver
and native-stdio-gdbserver boards.  The goal is to make all "native"
boards be considered not remote in DejaGnu terms, like the
native-extended-gdbserver board is too.

DejaGnu automatically considers boards remote if their names don't
match the local hostname.  That means that native-gdbserver and
native-extended-gdbserver are considered remote by default by DejaGnu,
even though they run locally.  native-extended-gdbserver, however,
overrides its isremote flag to force it to be not remote.  So we are
in that weird state where native-gdbserver is considered remote, and
native-extended-gdbserver is considered not remote.

A recent set of commits fixed all the problems (and some more) exposed
by testing with --target_board=native-gdbserver and
--target_board=native-stdio-gdbserver with isremote forced off on
x86-64 GNU/Linux.  I believe we're good to go now.

The native-stdio-gdbserver.exp/remote-stdio-gdbserver.exp boards
required deep non-obvious modifications unfortunately...  The problem
is that if a board is not remote, then DejaGnu doesn't call
${board}_spawn / ${board}_exec at all, and the
native-stdio-gdbserver.exp board relies on those procedures being
called.  To fix that, this commit redesigns how the stdio boards hook
into the testing framework to spawn gdbserver.  IMO, this is a good
change anyway, because the way its done currently is a bit of a hack,
and the result turns out to be simpler, even.  With this commit, they
now no longer load the "gdbserver" generic config, and hook at the
mi_gdb_target_load/gdb_reload level instead, making them more like
traditional board files.

To share code between native-stdio-gdbserver.exp and
remote-stdio-gdbserver.exp, a new shared stdio-gdbserver-base.exp file
is created.

Instead of having each native board clear isremote manually, boards
source the new "local-board.exp" file.

This also adds a new section to testsuite/README file discussing
local/remote/native, so that we can easily refer to it.

gdb/testsuite/ChangeLog:
2017-10-16  Pedro Alves  <palves@redhat.com>
	    Simon Marchi  <simon.marchi@polymtl.ca>

	* README (Local vs Remote vs Native): New section.
	* boards/local-board.exp: New file, with bits factored out from
	...
	* boards/native-extended-gdbserver.exp: ... here.  Load
	"local-board".
	* boards/native-gdbserver.exp: Load "local-board".
	(${board}_spawn, ${board}_exec): Delete.
	* boards/native-stdio-gdbserver.exp: Most contents factored out to
	...
	* boards/stdio-gdbserver-base.exp: ... this new file.
	* boards/native-stdio-gdbserver.exp: Reimplement, by loading
	"stdio-gdbserver-base" and defining a get_target_remote_pipe_cmd
	procedure.
	* boards/remote-stdio-gdbserver.exp: Load stdio-gdbserver-base
	instead of native-stdio-gdbserver.  Don't set gdb_server_prog nor
	stdio_gdbserver_command.
	(${board}_get_remote_address, ${board}_get_comm_port)
	(${board}_download, ${board}_upload): Delete.
	(get_target_remote_pipe_cmd): New.
2017-10-16 20:24:21 +01:00
Simon Marchi fe68b9530f Use proc_with_prefix in py-breakpoint.exp
Use proc_with_prefix to avoid having to call with_test_prefix with a
duplicate of the proc name.  The diff is mostly lines being re-indented.

gdb/testsuite/ChangeLog:

	* gdb.python/py-breakpoint.exp (test_bkpt_basic,
	test_bkpt_deletion, test_bkpt_cond_and_cmds,
	test_bkpt_invisible, test_watchpoints, test_bkpt_internal,
	test_bkpt_eval_funcs, test_bkpt_temporary, test_bkpt_address,
	test_bkpt_pending, test_bkpt_events): Use proc_with_prefix,
	remove with_test_prefix.
2017-10-16 15:06:14 -04:00
Simon Marchi a79b1bc6f6 Get rid of VEC(mem_range_s)
This patch replaces the last usages of VEC(mem_range_s) with
std::vector<mem_range>.  This allows getting rid of a few cleanups and
of the DEF_VEC_O(mem_range_s).

I added a test for normalize_mem_ranges to make sure I didn't break
anything there.

Regtested on the buildbot.

gdb/ChangeLog:

	* memrange.h (struct mem_range): Define operator< and operator==.
	(mem_range_s): Remove.
	(DEF_VEC_O (mem_range_s)): Remove.
	(normalize_mem_ranges): Change parameter type to std::vector.
	* memrange.c (compare_mem_ranges): Remove.
	(normalize_mem_ranges): Change parameter type to std::vector,
	adjust to vector change.
	* exec.c (section_table_available_memory): Return vector, remove
	parameter.
	(section_table_read_available_memory): Adjust to std::vector
	change.
	* remote.c (remote_read_bytes): Adjust to std::vector
	change.
	* tracepoint.h (traceframe_available_memory): Change parameter
	type to std::vector.
	* tracepoint.c (traceframe_available_memory): Change parameter
	type to std::vector, adjust.
	* gdb/mi/mi-main.c (mi_cmd_trace_frame_collected): Adjust to
	std::vector change.
	* gdb/Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
	unittests/memrange-selftests.c.
	(SUBDIR_UNITTESTS_OBS): Add memrange-selftests.o.
	* gdb/unittests/memrange-selftests.c: New file.
2017-10-16 11:07:18 -04:00
Pedro Alves 63f0e930d4 Work around GCC 6.3.1 bug
This commit works around a GCC 6.3.1 bug several people are hitting:

  https://sourceware.org/ml/gdb-patches/2017-09/msg00270.html
  https://sourceware.org/ml/gdb-patches/2017-10/msg00418.html

It manifests like this:

  ../../../binutils-gdb/gdb/probe.c:68:12: error: types may not be defined in a for-range-declaration [-Werror]
	 for (struct probe *probe : probes)
	      ^~~~~~

Fix it by renaming the range-for named variables to something different
from their type's name.

gdb/ChangeLog:
2017-10-16  Pedro Alves  <palves@redhat.com>

	* elfread.c (probe_key_free): Rename range-for variable.
	* probe.c (parse_probes_in_pspace, find_probes_in_objfile)
	(find_probe_by_pc, collect_probes): Rename range-for variable.
2017-10-16 13:39:12 +01:00
Yao Qi 5bfda25568 Regenerate gdbserver/configure
4fa7574 (Fix gdb 8.1 Solaris compilation) changes warning.m4 and updates
configure, but gdbserver/configure is not updated.

gdb/gdbserver:

2017-10-16  Yao Qi  <yao.qi@linaro.org>

	* configure: Regenerated.
2017-10-16 11:26:38 +01:00
Yao Qi c40c7bfcf1 Remove features/tic6x-*.c files
features/*.c are generated from *.xml files, in order to get pre-defined
target descriptions, (for native debugging, for example).  However, these
pre-generated tdesc_tic6x_* are not used in GDB at all.  This patch removes
features/tic6x-*.c files.

gdb:

2017-10-16  Yao Qi  <yao.qi@linaro.org>

	* features/Makefile (XMLTOC): Remove tic6x-*.xml.
	* features/tic6x-c62x.c: Remove.
	* features/tic6x-c64x-linux.c: Remove.
	* features/tic6x-c64x.c: Remove.
	* features/tic6x-c64xp-linux.c: Remove.
	* features/tic6x-c64xp.c: Remove.
	* tic6x-linux-tdep.c (_initialize_tic6x_linux_tdep): Don't call
	initialize_tdesc_tic6x_*_linux functions.
	* tic6x-tdep.c (_initialize_tic6x_tdep): Don't call
	initialize_tdesc_tic6x_* functions.
2017-10-16 09:27:43 +01:00
Yao Qi df27ae6a09 Remove regformats/tic6x-{c62x,c64x,c64xp}.dat
tic6x-uclinux GDBserver uses linux target descriptions, instead of these
non-linux target descriptions.  So we can remove these *.dat files.

gdb:

2017-10-16  Yao Qi  <yao.qi@linaro.org>

	* features/Makefile (WHICH): Remove tic6x-c64xp, tic6x-c64x
	tic6x-c62x.
	* regformats/tic6x-c62x.dat: Remove.
	* regformats/tic6x-c64x.dat: Remove.
	* regformats/tic6x-c64xp.dat: Remove.
2017-10-16 09:15:07 +01:00
Simon Marchi 8676616596 Fix GDB build without expat
An earlier patch of mine changed parse_traceframe_info to make it return
a unique_ptr.  I forgot to update the version of the function used in an
expat-less build, this patch fixes it.

gdb/ChangeLog:

	* tracepoint.c (parse_traceframe_info): Return a unique_ptr
	(the !HAVE_LIBEXPAT version).
2017-10-15 22:13:23 -04:00
Simon Marchi 824dfcc311 Fix build failure in linux-osdata.c
Commit

  Use std::vector in linux_xfer_osdata_processgroups
  b129dcac88

broke the build with older gcc (at least 4.7 and 4.8):

In file included from /usr/include/c++/4.7/algorithm:63:0,
                 from /home/emaisin/src/binutils-gdb/gdb/nat/linux-osdata.c:40:
/usr/include/c++/4.7/bits/stl_algo.h: In instantiation of ‘_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, const _Tp&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pid_pgid_entry*, std::vector<pid_pgid_entry> >; _Tp = pid_pgid_entry]’:
/usr/include/c++/4.7/bits/stl_algo.h:2315:70:   required from ‘_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pid_pgid_entry*, std::vector<pid_pgid_entry> >]’
/usr/include/c++/4.7/bits/stl_algo.h:2347:54:   required from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pid_pgid_entry*, std::vector<pid_pgid_entry> >; _Size = long int]’
/usr/include/c++/4.7/bits/stl_algo.h:5483:4:   required from ‘void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<pid_pgid_entry*, std::vector<pid_pgid_entry> >]’
/home/emaisin/src/binutils-gdb/gdb/nat/linux-osdata.c:480:57:   required from here
/usr/include/c++/4.7/bits/stl_algo.h:2277:4: error: passing ‘const pid_pgid_entry’ as ‘this’ argument of ‘bool pid_pgid_entry::operator<(const pid_pgid_entry&)’ discards qualifiers [-fpermissive]

Making the operator< method const fixes it.

gdb/ChangeLog:

	* nat/linux-osdata.c (struct pid_pgid_entry) <operator<>: Make
	const.
2017-10-14 09:28:07 -04:00
Simon Marchi 9c80ecd646 gdbserver: use std::list for all_threads
Remove the usage of inferior_list for the all_threads list in
gdbserver.  The entry field in thread_info is removed, and replaced by a
simple ptid field.

I added some functions to iterate (for_each_thread) and find threads
(find_thread).  However, changing all the users of find_inferior & co to
use these new functions would have made the patch way too big.  So I
opted instead to make find_inferior & co some shims, so that the
existing code only needs to be updated minimally.  We can then update
the existing code to use the new functions incrementally (I've started
to do the work, but I'll post it afterwards, see [1] if you want a peek).

This patch has been built-tested on all relevant platforms, except
lynx.  I also regtested using the native-gdbserver and
native-extended-gdbserver boards on x86.

[1] https://github.com/simark/binutils-gdb/commits/kill-inferior-list-entry

gdb/gdbserver/ChangeLog:

	* inferiors.h: (struct inferior_list): Remove.
	(struct inferior_list_entry); Remove.
	(add_inferior_to_list, clear_inferior_list, one_inferior_p,
	A_I_NEXT, ALL_INFERIORS_TYPE, ALL_INFERIORS, remove_inferior,
	get_first_inferior): Remove.
	(for_each_inferior, for_each_inferior_with_data, find_inferior,
	find_inferior_id, find_inferior_in_random): Change signature.
	* inferiors.c (all_threads): Change type to
	std::list<thread_info *>.
	(get_thread): Remove macro.
	(find_inferior, find_inferior_id): Change signature, implement
	using find_thread.
	(find_inferior_in_random): Change signature, implement using
	find_thread_in_random.
	(for_each_inferior, for_each_inferior_with_data): Change
	signature, implement using for_each_thread.
	(add_inferior_to_list, remove_inferior): Remove.
	(add_thread, get_first_thread, thread_of_pid,
	find_any_thread_of_pid, free_one_thread, remove_thread): Update.
	(get_first_inferior, one_inferior_p, clear_inferior_list):
	Remove.
	(clear_inferiors, get_thread_process): Update.
	* gdbthread.h: Include <list>.
	(struct thread_info) <entry>: Remove field.
	<id>: New field.
	(all_threads): Change type to std::list<thread_info *>.
	(get_first_inferior): Add doc.
	(find_thread, for_each_thread, find_thread_in_random): New
	functions.
	(current_ptid, pid_of, ptid_of, lwpid_of): Update.
	* linux-arm-low.c (update_registers_callback): Update.
	* linux-low.c (second_thread_of_pid_p): Update.
	(kill_one_lwp_callback, linux_detach_lwp_callback,
	delete_lwp_callback, status_pending_p_callback, same_lwp,
	find_lwp_pid, num_lwps, iterate_over_lwps_filter,
	iterate_over_lwps, not_stopped_callback,
	resume_stopped_resumed_lwps, count_events_callback,
	select_singlestep_lwp_callback, select_event_lwp_callback,
	unsuspend_one_lwp, linux_wait_1, send_sigstop_callback,
	suspend_and_send_sigstop_callback, wait_for_sigstop,
	stuck_in_jump_pad_callback, move_out_of_jump_pad_callback,
	lwp_running, linux_set_resume_request, resume_status_pending_p,
	need_step_over_p, start_step_over, linux_resume_one_thread,
	proceed_one_lwp, unsuspend_and_proceed_one_lwp,
	reset_lwp_ptrace_options_callback): Update.
	* linux-mips-low.c (update_watch_registers_callback): Update.
	* regcache.c (regcache_invalidate_one, regcache_invalidate):
	Update.
	(free_register_cache_thread_one): Remove.
	(regcache_release): Update.
	* server.c (handle_btrace_enable_bts, handle_btrace_enable_pt,
	handle_qxfer_threads_worker): Update.
	(handle_query): Update, use list iterator.
	(visit_actioned_threads, handle_pending_status,
	queue_stop_reply_callback, gdb_wants_all_threads_stopped,
	clear_pending_status_callback, set_pending_status_callback,
	find_status_pending_thread_callback, handle_status,
	process_serial_event): Update.
	* target.c (thread_search_callback): Update.
	* thread-db.c (thread_db_get_tls_address): Update.
	* tracepoint.c (tracepoint_finished_step, tracepoint_was_hit):
	Update.
	* win32-i386-low.c (update_debug_registers_callback): Update.
	* win32-low.c (delete_thread_info, child_delete_thread,
	continue_one_thread, suspend_one_thread,
	get_child_debug_event): Adjust.
2017-10-14 09:11:12 -04:00
Simon Marchi 9179355e65 gdbserver: Use std::list for all_processes
Remove the usage of inferior_list for the all_processes list in
gdbserver, replace it with an std::list. The entry field in process_info
is removed, and replaced by a simple pid field.

The pid_of macro, used for both processes and threads, is replaced with
separate functions.  For completeness, I changed ptid_of and lwpid_of to
functions as well.

gdb/gdbserver/ChangeLog:

	* gdbthread.h (ptid_of, pid_of, lwpid_of): New functions.
	* inferiors.h: Include <list>.
	(struct process_info) <entry>: Remove field.
	<pid>: New field.
	(pid_of): Change macro to function.
	(ptid_of, lwpid_of): Remove macro.
	(all_processes): Change type to std::list<process_info *>.
	(ALL_PROCESSES): Remove macro.
	(for_each_process, find_process): New function.
	* inferiors.c (all_processes): Change type to
	std::list<process_info *>.
	(find_thread_process): Adjust.
	(add_process): Likewise.
	(remove_process): Likewise.
	(find_process_pid): Likewise.
	(get_first_process): Likewise.
	(started_inferior_callback): Remove.
	(have_started_inferiors_p): Adjust.
	(attached_inferior_callback): Remove.
	(have_attached_inferiors_p): Adjust.
	* linux-low.c (check_zombie_leaders): Likewise.
	* linux-x86-low.c (x86_arch_setup_process_callback): Remove.
	(x86_linux_update_xmltarget): Adjust.
	* server.c (handle_query): Likewise.
	(gdb_reattached_process): Remove.
	(handle_status): Adjust.
	(kill_inferior_callback): Likewise.
	(detach_or_kill_inferior): Remove.
	(print_started_pid): Likewise.
	(print_attached_pid): Likewise.
	(detach_or_kill_for_exit): Update.
	(process_serial_event): Likewise.
	* linux-arm-low.c (arm_new_fork): Likewise.
2017-10-14 09:10:42 -04:00
Simon Marchi c9cb8905b4 gdbserver: Use std::list for all_dlls
As a small step towards removing inferior_list/inferior_list_entry, this
patch replaces the usage of inferior_list for the list of dlls by an
std::list.  The dll_info type now uses an std::string for name and has a
simple constructor.

I am able to build gdbserver with mingw on Linux, but I am not able to
test this on a Windows machine (the only platform that uses this code).

gdb/gdbserver/ChangeLog:

	* dll.h: Include <list>.
	(struct dll_info): Add constructor.
	<entry>: Remove field.
	(all_dlls): Change type to std::list<dll_info>.
	* dll.c: Include <algorithm>.
	(get_dll): Remove macro.
	(all_dlls): Change type to std::list<dll_info *>.
	(free_one_dll): Remove.
	(match_dll): Likewise.
	(loaded_dll): Adjust.
	(unloaded_dll): Adjust to all_dlls type change, use
	std::find_if.  Inline code from match_dll.
	(clear_dlls): Adjust to all_dlls type change.
	* server.c (emit_dll_description): Remove.
	(handle_qxfer_libraries): Adjust to all_dlls type change,
	integrate emit_dll_description's functionality.
2017-10-14 09:09:22 -04:00
Simon Marchi 2098b39391 Make to_traceframe_info return a unique_ptr
Since this target method returns an allocated object, return a
unique_ptr.  It allows getting rid a some cleanups here and there.

I had to shuffle the includes around.  First, target.h now needs to
include tracepoint.h, to get the definition of traceframe_info_up.
However, the definition of enum trace_find_type was later in target, so
I had to move it to tracepoint.h, so that the declaration of tfind_1
could know about it.  I then had to remove the include of target.h from
tracepoint.h, which caused a circular dependency (it was probably
included to get enum trace_find_type in the first place anyway).

Regression tested on the buildbot.

gdb/ChangeLog:

	* target.h: Include tracepoint.h.
	(enum trace_find_type): Move to tracepoint.h.
	(struct target_ops) <to_traceframe_info>: Return a unique ptr.
	* tracepoint.h: Don't include target.h
	(enum trace_find_type): Move from target.h.
	(parse_traceframe_info): Return a unique ptr.
	* tracepoint.c (current_traceframe_info): Change type to unique
	ptr.
	(free_traceframe_info): Remove.
	(clear_traceframe_info): Don't manually free
	current_traceframe_info.
	(free_result): Remove.
	(parse_traceframe_info): Return a unique ptr.
	(get_traceframe_info): Adjust to unique ptr.
	* ctf.c (ctf_traceframe_info): Return a unique ptr.
	* remote.c (remote_traceframe_info): Return a unique ptr.
	* tracefile-tfile.c (tfile_traceframe_info): Return a unique
	ptr.
	* target-debug.h (target_debug_print_traceframe_info_up): New
	macro.
	* target-delegates.c: Regenerate.
2017-10-14 08:47:44 -04:00
Simon Marchi 4cdd21a8d3 Use std::vector for traceframe_info::memory
Straightforward change from a VEC to std::vector.  This allows making
the destruction of a traceframe_info trivial.

I added a constructor with parameters to mem_range to be able to
emplace_back directly with the values.  It is necessary to leave a
default constructor there because mem_range is still used in a VEC.

gdb/ChangeLog:

	* memrange.h (struct mem_range): Add constructors.
	* tracepoint.h (struct traceframe_info) <memory>: Change type to
	std::vector<mem_range>.
	* tracepoint.c (free_traceframe_info): Don't manually free
	vector.
	(traceframe_info_start_memory): Adjust to vector change.
	(traceframe_available_memory): Likewise.
	* tracefile-tfile.c (build_traceframe_info): Likewise.
	* ctf.c (ctf_traceframe_info): Likewise.
2017-10-14 08:43:55 -04:00
Simon Marchi d0d292a274 Use std::vector for traceframe_info::tvars
Straightforward change to get rid of a VEC.  We need to new/delete
traceframe_info instead of malloc/free it.  I found three places that
allocate a traceframe_info (ctf_traceframe_info, tfile_traceframe_info
and parse_traceframe_info) and only one that frees it
(free_traceframe_info).

gdb/ChangeLog:

	* tracepoint.h (struct traceframe_info) <tvars>: Change type to
	std::vector<int>.
	* tracepoint.c (free_traceframe_info): Deallocate with delete.
	(traceframe_info_start_tvar): Adjust to vector change.
	(parse_traceframe_info): Allocate with new.
	* ctf.c (ctf_traceframe_info): Allocate with new, adjust to
	vector change.
	* tracefile-tfile.c (build_traceframe_info): Adjust to vector
	change.
	tfile_traceframe_info): Allocate with new.
	* mi/mi-main.c (mi_cmd_trace_frame_collected): Adjust to vector
	change.
2017-10-14 08:42:23 -04:00
Simon Marchi 8d3c73ef6b Rename traceframe_info variable to current_traceframe_info
... so it doesn't shadow the traceframe_info type.  It think it's a
clearer name anyway.

gdb/ChangeLog:

	* tracepoint.c (traceframe_info): Rename to...
	(current_traceframe_info): ...this.
	(clear_traceframe_info): Adjust.
	(get_traceframe_info): Adjust.
2017-10-14 08:41:01 -04:00