Commit Graph

40336 Commits

Author SHA1 Message Date
Simon Marchi 454296a2c1 Remove usage of find_inferior in find_lwp_pid
Replace with find_thread.  We could almost use find_thread_ptid, except
that find_lwp_pid uses the pid of the input ptid of the lwp is 0, so the
behavior is not quite the same.

gdb/gdbserver/ChangeLog:

	* linux-low.c (same_lwp): Remove.
	(find_lwp_pid): Use find_thread.
2017-12-02 20:36:38 -05:00
Simon Marchi 6b2a85daf5 Remove usage of find_inferior in linux_mourn
Replace with for_each_thread with pid filtering.  The callback becomes
trivial enough that it's better to inline it.

gdb/gdbserver/ChangeLog:

	* linux-low.c (delete_lwp_callback): Remove.
	(linux_mourn): Use for_each_thread.
2017-12-02 20:36:37 -05:00
Simon Marchi 798a38e8de Remove usage of find_inferior in linux_detach
Replace with for_each_thread with pid filtering.

gdb/gdbserver/ChangeLog:

	* linux-low.c (linux_detach_lwp_callback): Return void, remove
	args parameter, don't check for pid.
	(linux_detach): Use for_each_thread.
2017-12-02 20:36:36 -05:00
Simon Marchi e4eb0dec0b Remove usage of find_inferior in last_thread_of_process_p
Replace it with find_thread.  I also modified the code a bit to use a
lambda and a boolean.

gdb/gdbserver/ChangeLog:

	* linux-low.c (struct counter): Remove.
	(second_thread_of_pid_p): Remove.
	(last_thread_of_process_p): Use find_thread.
2017-12-02 20:36:36 -05:00
Simon Marchi 83e1b6c13a Remove find_inferior_in_random
Replace with find_thread_in_random.

gdb/gdbserver/ChangeLog:

	* inferiors.c (find_inferior_in_random): Remove.
	* inferiors.h (find_inferior_in_random): Remove.
	* linux-low.c (status_pending_p_callback): Return bool, accept
	parameter ptid directly.
	(linux_wait_for_event_filtered): Use find_thread_in_random.
	(linux_wait_1): Likewise.
2017-12-02 20:36:35 -05:00
Simon Marchi 8dc7b443a6 Remove find_inferior_id
Remove find_inferior_id, replacing its usages with find_thread_ptid.
find_thread_ptid was implemented using find_inferior_id, so move the
implementation there instead.

gdb/gdbserver/ChangeLog:

	* inferiors.c (find_inferior_id): Remove.
	(find_thread_ptid): Move implemention from find_inferior_id to
	here.
	* inferiors.h (find_inferior_id): Remove.
	* server.c (handle_status): Use find_thread_ptid.
	(process_serial_event): Likewise.
	* thread-db.c (find_one_thread): Likewise.
	(thread_db_thread_handle): Likewise.
	* win32-low.c (thread_rec): Likewise.
	(child_delete_thread): Likewise.
	(win32_thread_alive): Likewise.
	(get_child_debug_event): Likewise.
2017-12-02 20:36:34 -05:00
Simon Marchi da25033cd9 Remove usages of find_inferior in linux-mips-low.c
Replace with for_each_thread with pid filtering.  This allows
simplifying the callback a little bit.

gdb/gdbserver/ChangeLog:

	* linux-mips-low.c (update_watch_registers_callback): Return
	void, remove pid_p parameter, don't check for pid.
	(mips_insert_point, mips_remove_point): Use for_each_thread.
2017-12-02 20:36:33 -05:00
Simon Marchi c91bb56b06 Remove usage of find_inferior in lynx_mourn
Replace it with for_each_thread with pid filtering.  We can remove
lynx_delete_thread_callback and pass remove_thread directly.

I can't build/test this change, but it should be obvious enough.

gdb/gdbserver/ChangeLog:

	* lynx.low (lynx_delete_thread_callback): Remove.
	(lynx_mourn): Use for_each_thread.
2017-12-02 20:36:32 -05:00
Simon Marchi 634a3254c8 Remove usage of find_inferior in regcache_invalidate_pid
Replace with for_each_thread with pid filtering.
regcache_invalidate_one is not longer needed, as it was only used to
filter the pid.  We can call regcache_invalidate_thread directly.

gdb/gdbserver/ChangeLog:

	* regcache.c (regcache_invalidate_one): Remove.
	(regcache_invalidate_pid): use for_each_thread.
2017-12-02 20:36:32 -05:00
Simon Marchi 6d83e819df Fix typo in poison.h
gdb/ChangeLog:

	* common/poison.h (XDELETE): Fix typo.
2017-12-02 20:28:41 -05:00
Sergio Durigan Junior 97cbe998d0 Add support for the readnever concept
The purpose of this concept is to turn the load of debugging
information off, either globally (via the '--readnever' option), or
objfile-specific.  The implementation proposed here is an extension of
the patch distributed with Fedora GDB; looking at the Fedora patch
itself and the history, one can see some reasons why it was never
resubmitted:

  - The patch appears to have been introduced as a workaround, at
    least initially;
  - The patch is far from perfect, as it simply shunts the load of
    DWARF debugging information, without really worrying about the
    other debug format.
  - Who really does non-symbolic debugging anyways?

One use of this feature is when a user simply wants to do the
following sequence: attach, dump core, detach.  Loading the debugging
information in this case is an unnecessary cause of delay.

This patch expands the version shipped with Fedora GDB in order to
make the feature available for all the debuginfo backends, not only
for DWARF.  It also implements a per-objfile flag which can be
activated by using the "-readnever" command when using the
'add-symbol-file' or 'symbol-file' commands.

It's also worth mentioning that this patch tests whether GDB correctly
fails to initialize if both '--readnow' and '--readnever' options are
passed.

Tested on the BuildBot.

gdb/ChangeLog:

2017-12-01  Andrew Cagney  <cagney@redhat.com>
	    Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>

	* NEWS (Changes since GDB 8.0: Mention new '--readnever'
	feature.
	* coffread.c (coff_symfile_read): Do not map over sections with
	'coff_locate_sections' if readnever is on.
	* dwarf2read.c (dwarf2_has_info): Return 0 if
	readnever is on.
	* elfread.c (elf_symfile_read): Do not map over sections with
	'elf_locate_sections' if readnever is on.
	* main.c (validate_readnow_readnever): New function.
	(captured_main_1): Add support for --readnever.
	(print_gdb_help): Document --readnever.
	* objfile-flags.h (enum objfile_flag) <OBJF_READNEVER>: New
	flag.
	* symfile.c (readnever_symbol_files): New global.
	(symbol_file_add_with_addrs): Set 'OBJF_READNEVER' when
	'READNEVER_SYMBOL_FILES' is set.
	(validate_readnow_readnever): New function.
	(symbol_file_command): Handle '-readnever' option.
	Call 'validate_readnow_readnever'.
	(add_symbol_file_command): Handle '-readnever' option.
	Call 'validate_readnow_readnever'.
	(_initialize_symfile): Document new '-readnever' option for
	both 'symbol-file' and 'add-symbol-file' commands.
	* top.h (readnever_symbol_files): New extern global.
	* xcoffread.c (xcoff_initial_scan): Do not read debug
	information if readnever is on.

gdb/doc/ChangeLog:

2017-12-01  Andrew Cagney  <cagney@redhat.com>
	    Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.texinfo (File Options): Document --readnever.
	(Commands to Specify Files): Likewise, for 'symbol-file' and
	'add-symbol-file'.

gdb/testsuite/ChangeLog:

2017-12-01  Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* gdb.base/readnever.c, gdb.base/readnever.exp: New files.
2017-12-01 21:28:31 -05:00
Sergio Durigan Junior 40fc416f4e Make '{add-,}symbol-file' not care about the position of command line arguments
This is a bug that's been detected while doing the readnever work.

If you use 'symbol-file' or 'add-symbol-file', the position of each
argument passed to the command matters.  This means that if you do:

  (gdb) symbol-file -readnow /foo/bar

The symbol file specified will (correctly) have all of its symbols
read by GDB (because of the -readnow flag).  However, if you do:

  (gdb) symbol-file /foo/bar -readnow

GDB will silently ignore the -readnow flag, because it was specified
after the filename.  This is not a good thing to do and may confuse
the user.

To address that, I've modified the argument parsing mechanisms of
symbol_file_command and add_symbol_file_command to be
"position-independent".  I have also added one error call at the end
of add_symbol_file_command's argument parsing logic, which now clearly
complains if no filename has been specified.  Both commands now
support the "--" option to stop argument processing.

This patch provides a testcase for both commands, in order to make
sure that the argument order does not matter.  It has been
regression-tested on BuildBot.

gdb/ChangeLog:

2017-12-01  Sergio Durigan Junior  <sergiodj@redhat.com>

	* symfile.c (symbol_file_command): Call
	'symbol_file_add_main_1' only after processing all command
	line options.
	(add_symbol_file_command): Modify logic to make arguments
	position-independent.

gdb/testsuite/ChangeLog:

2017-12-01  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.base/relocate.exp: Add tests to guarantee that arguments
	to 'symbol-file' and 'add-symbol-file' can be
	position-independent.
2017-12-01 17:01:24 -05:00
Sergio Durigan Junior 7f0f8ac8b1 Revert "Add support for the readnever concept"
This reverts commit e2e321740c.

It was mistakenly pushed.
2017-12-01 16:58:47 -05:00
Joel Brobecker ec6a20c268 (Ada) GDB crash printing expression with type casting
One of our users reported that trying to print the following expression,
caused GDB to SEGV:

    (gdb) print some_package.some_type (val)

In this particular instance, the crash occurred inside ada_args_match
because it is given a NULL "func", leading to the SEGV because of:

    struct type *func_type = SYMBOL_TYPE (func);

This NULL symbol comes from a list of symbols which was given to
ada_resolve_function (parameter called "syms") which then iterates
over each of them to discard the ones that don't match the actuals:

     for (k = 0; k < nsyms; k += 1)
       {
         struct type *type = ada_check_typedef (SYMBOL_TYPE (syms[k].symbol));

         if (ada_args_match (syms[k].symbol, args, nargs)
             && (fallback || return_match (type, context_type)))
         [...]
       }

What's really interesting is that, when entering the block above for
the first time, all entries in SYMS have a valid (non-NULL) symbol.
However, once we return from the call to ada_check_typedef, the first
entry of our SYMS table gets set to all zeros:

    (gdb) p syms[0]
    $2 = {symbol = 0x0, block = 0x0}

Hence the call to ada_args_match with a NULL symbol, and the ensuing
SEGV.

To find out why this happen, we need to step back a little and look
at how syms was allocated. This list of symbols comes from a symbol
lookup, which means ada_lookup_symbol_list_worker. We have our first
hint when we look at the function's documentation and see:

    This vector is transient---good only to the next call of
    ada_lookup_symbol_list.

Implementation-wise, this is done by using a static global obstack,
which we just re-initialize each time ada_lookup_symbol_list_worker
gets called:

    obstack_free (&symbol_list_obstack, NULL);
    obstack_init (&symbol_list_obstack);

This property was probably established in order to facilitate the use
of the returned vector, since the users of that function would not have
to worry about releasing that memory when no longer needed. However,
I found during this investigation that it is all to easy to indirectly
trigger another symbol lookup while still using the results of a previous
lookup.

In our particular case, there is the call to ada_check_typedef, which
leads to check_typedef. As it happens, my first symbol had a type which
was a typedef to a stub type, so check_typedef calls lookup_symbol to
find the non-stub version. This in turn eventually leads us back to
ada_lookup_symbol_list_worker, where the first thing it does is free
the memory area when our list of symbols have been residing and then
recreates a new one. in other words, SYMS then becomes a dangling
pointer!

This patch fixes the issue by having ada_lookup_symbol_list_worker
return a copy of the list of symbols, with the responsibility of
deallocating that list now transfered to the users of that list.

More generally speaking, it is absolutely amazing that we haven't seen
consequences of this issue before. This can happen fairly frequently.
For instance, I found that ada-exp.y::write_var_or_type calls
ada_lookup_symbol_list, and then, while processing that list, calls
select_possible_type_sym, which leads to ada_prefer_type, eventually
leading to ada_check_typedef again (via eg. ada_is_array_descriptor_type).

Even more amazing is the fact that, while I was able to produce multiple
scenarios where the corruption occurs, none of them leads to incorrect
behavior at the user level. In other words, it requires a very precise
set of conditions for the corruption to become user-visible, and
despite having a megalarge program where the crash occured, using that
as a template for creating a reproducer did not work (pb goes away).
This is why this patch does not come with a reproducer. On the other hand,
this should not be a problem in terms of testing coverage, as the changes
are made in common areas which, at least for the most part, are routinely
exercised during testing.

gdb/ChangeLog:

        * ada-lang.c (symbol_list_obstack): Delete.
        (resolve_subexp): Make sure "candidates" gets xfree'ed.
        (ada_lookup_symbol_list_worker): Remove the limitation that
        the result is only good until the next call, now making it
        the responsibility of the caller to free the result when no
        longer needed.  Adjust the function's intro comment accordingly.
        (ada_lookup_symbol_list): Adjust the function's intro comment.
        (ada_iterate_over_symbols): Make sure "results" gets xfree'ed.
        (ada_lookup_encoded_symbol, get_var_value): Likewise.
        (_initialize_ada_language): Remove symbol_list_obstack
        initialization.
        * ada-exp.y (block_lookup): Make sure "syms" gets xfree'ed.
        (write_var_or_type, write_name_assoc): Likewise.

Tested on x86_64-linux.
2017-12-01 16:18:30 -05:00
Sergio Durigan Junior e2e321740c Add support for the readnever concept
The purpose of this concept is to turn the load of debugging
information off, either globally (via the '--readnever' option), or
objfile-specific.  The implementation proposed here is an extension of
the patch distributed with Fedora GDB; looking at the Fedora patch
itself and the history, one can see some reasons why it was never
resubmitted:

  - The patch appears to have been introduced as a workaround, at
    least initially;
  - The patch is far from perfect, as it simply shunts the load of
    DWARF debugging information, without really worrying about the
    other debug format.
  - Who really does non-symbolic debugging anyways?

One use of this feature is when a user simply wants to do the
following sequence: attach, dump core, detach.  Loading the debugging
information in this case is an unnecessary cause of delay.

This patch expands the version shipped with Fedora GDB in order to
make the feature available for all the debuginfo backends, not only
for DWARF.  It also implements a per-objfile flag which can be
activated by using the "-readnever" command when using the
'add-symbol-file' or 'symbol-file' commands.

It's also worth mentioning that this patch tests whether GDB correctly
fails to initialize if both '--readnow' and '--readnever' options are
passed.

Tested on the BuildBot.

gdb/ChangeLog:

2017-12-01  Andrew Cagney  <cagney@redhat.com>
	    Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>

	* NEWS (Changes since GDB 8.0: Mention new '--readnever'
	feature.
	* coffread.c (coff_symfile_read): Do not map over sections with
	'coff_locate_sections' if readnever is on.
	* dwarf2read.c (dwarf2_has_info): Return 0 if
	readnever is on.
	* elfread.c (elf_symfile_read): Do not map over sections with
	'elf_locate_sections' if readnever is on.
	* main.c (validate_readnow_readnever): New function.
	(captured_main_1): Add support for --readnever.
	(print_gdb_help): Document --readnever.
	* objfile-flags.h (enum objfile_flag) <OBJF_READNEVER>: New
	flag.
	* symfile.c (readnever_symbol_files): New global.
	(symbol_file_add_with_addrs): Set 'OBJF_READNEVER' when
	'READNEVER_SYMBOL_FILES' is set.
	(validate_readnow_readnever): New function.
	(symbol_file_command): Handle '-readnever' option.
	Call 'validate_readnow_readnever'.
	(add_symbol_file_command): Handle '-readnever' option.
	Call 'validate_readnow_readnever'.
	(_initialize_symfile): Document new '-readnever' option for
	both 'symbol-file' and 'add-symbol-file' commands.
	* top.h (readnever_symbol_files): New extern global.
	* xcoffread.c (xcoff_initial_scan): Do not read debug
	information if readnever is on.

gdb/doc/ChangeLog:

2017-12-01  Andrew Cagney  <cagney@redhat.com>
	    Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.texinfo (File Options): Document --readnever.
	(Commands to Specify Files): Likewise, for 'symbol-file' and
	'add-symbol-file'.

gdb/testsuite/ChangeLog:

2017-12-01  Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* gdb.base/readnever.c, gdb.base/readnever.exp: New files.
2017-12-01 12:23:30 -05:00
Tom Tromey d0df06af9b Fix dependency tracking for objects in subdirectories
On irc, Pedro pointed out that dependencies for objects in
subdirectories didn't seem to be working.

The bug was that the "-include" for .deps files was using the wrong file
name for subdirectory objects; e.g., for cli/cli-decode.o it was trying
to open .deps/cli/cli-decode.o, whereas the correct file is
cli/.deps/cli-decode.o.

This patch changes how the dep files are found.  Tested by touching a
source file and rebuilding cli/cli-decode.o.

2017-12-01  Tom Tromey  <tom@tromey.com>

	* Makefile.in (all_deps_files): New variable.
	Include .Po files using all_deps_files.
2017-12-01 07:56:11 -07:00
Joel Brobecker 2ee0c9b3ee Update GDB's list of maintainers to reflect today's reality
gdb/ChangeLog:

       * MAINTAINERS: Update list of maintainers, moving those who
       stepped down or became inactive to the "Past Maintainers"
       section.
2017-12-01 08:35:56 -05:00
Yao Qi 1cc75e929f Replace mail address with the URL in copyright header
The copyright header in most of GDB files were changed from mail address
to the URL in the conversion to GPLv3 in Aug 2007.  However, some files
still use mail address instead of the URL.  This patch fixes them.

gdb/testsuite:

2017-12-01  Yao Qi  <yao.qi@linaro.org>

	* gdb.arch/aarch64-atomic-inst.exp: Replace mail address with
	the URL in copyright header.
	* gdb.arch/aarch64-fp.exp: Likewise.
	* gdb.arch/ppc64-atomic-inst.exp: Likewise.
	* gdb.arch/ppc64-isa207-atomic-inst.exp: Likewise.
	* gdb.base/expand-psymtabs.exp: Likewise.
	* gdb.cp/expand-psymtabs-cxx.exp: Likewise.
	* gdb.fortran/common-block.exp: Likewise.
	* gdb.fortran/common-block.f90: Likewise.
	* gdb.fortran/logical.exp: Likewise.
	* gdb.fortran/vla-datatypes.f90: Likewise.
	* gdb.fortran/vla-sub.f90: Likewise.
2017-12-01 11:34:14 +00:00
Joel Brobecker 875fb7a785 New gdb.ada/repeat_dyn testcase.
This patch introduces a testcase that exercises a scenario
which used to trigger an internal-error, but no longer does:

Consider the following array:

   type Small is new Integer range Ident (1) .. Ident (10);
   type Table is array (1 .. 3) of Small;
   A1 : Table := (3, 5, 8);

The particularity of this array is that the type of each element
is a range type whose bounds are dynamic, since they depend on
the value returned by Ident (1) and Ident (10). Trying to apply
the repeat operator ('@') on one of its elements used to yield
an internal error:

    (gdb) p a1(1)@3
    $1 =
    /[...]/gdbtypes.c:4512: internal-error:
    copy_type: Assertion `TYPE_OBJFILE_OWNED (type)' failed.

Although the issue no longer appears, the testcase is still
interesting to have.

gdb/testsuite/ChangeLog:

        * gdb.ada/repeat_dyn: New testcase.

Tested on x86_64-linux with clean results.
2017-11-30 18:46:45 -05:00
Ulrich Weigand 6f14765f9f [spu] Some additional test fixes
Now that the ppc64 breakpoint regression is fixed, running the
gdb.cell test suite showed a few more test case problems, caused
by tests that haven't been updated to adapt to GDB changes.

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

	* gdb.cell/gcore.exp: Fix typo when setting spu_bin.
	Update for changed thread numbering.
	* gdb.cell/bt.exp: Update for changed GDB output.
2017-11-30 18:35:54 +01:00
Simon Marchi f1af7b94c1 Use boards/local-board.exp more
local-board.exp was introduced recently, containing the code required to
force the gdbserver boards to be non-remote (from the DejaGNU point of
view).  Other board files use the same trick of forcing isremote to 0.
Instead of doing it by hand in each file, include local-board.exp.

gdb/testsuite/ChangeLog:

	* boards/cc-with-tweaks.exp: Include local-board.exp instead of
	setting isremote by hand.
	* boards/dwarf4-gdb-index.exp: Likewise.
	* boards/fission.exp: Likewise.
	* boards/stabs.exp: Likewise.
2017-11-30 11:39:31 -05:00
Pedro Alves e3919f3e89 Fix gdb.linespec/cpls-ops.exp on 32-bit
gdb.linespec/cpls-ops.exp is currently failing on x86-64 -m32 and other
32-bit ports:

 b test_op_new::operator new(unsigned int) FAIL: gdb.linespec/cpls-ops.exp: operator-new: tab complete "b test_op_new::operator" (timeout)
 ^CQuit
 (gdb) complete b test_op_new::operator
 b test_op_new::operator new(unsigned int)
 (gdb) FAIL: gdb.linespec/cpls-ops.exp: operator-new: cmd complete "b test_op_new::operator"

The problem is simply that the testcase incorrectly assumes that
size_t is "unsigned long".

Fix this by extracting the right type with the "ptype" command.

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

	* gdb.linespec/cpls-ops.exp
	(check_explicit_skips_function_argument): Extract the underlying
	type of size_t instead of hardcoding it.
2017-11-30 16:32:10 +00:00
Rainer Orth 44122162ae Remove ioctl-based procfs support on Solaris
This is the previously mentioned patch to get rid of
unstructured/ioctl-based procfs support in procfs.c.  Given that support
for structured procfs was introduced in Solaris 2.6 back in 1997 and
we're just removing support for Solaris < 10, there's no point in
carrying that baggage (and tons of support for IRIX and OSF/1 as well)
around any longer.

Most of the patch should be straightforward (removing support for
!NEW_PROC_API, non-Solaris OSes and pre-Solaris 10 quirks).

Only a few points need explanations:

* <sys/syscall.h> was already included unconditionally in most places,
  so there's no need to have guards in a few remaining ones.

* configure.host already obsoletes i?86-*-sysv4.2, i?86-*-sysv5, so
  NEW_PROC_API detection for those in configure.ac can go.

* I'm still including <sys/procfs.h> with #define _STRUCTURED_PROC 1.
  Theoretically, it would be better to include <procfs.h> on Solaris
  (which includes that define), but that breaks the build over
  <procfs.h> vs. gdb's "procfs.h", and doesn't exist on Linux.

* I've regenerated syscall_table[] in proc-events.c with a small script
  from Solaris 10, 11.3, 11.4 <sys/syscall.h>, so there should be no
  traces of older Solaris versions and other OSes left.

* prsysent_t and DYNAMIC_SYSCALLS was only used for AIX 5, but AIX
  doesn't use procfs.c any longer, so all related code can go.

The patch was generated with diff -w so one can easier see changes
without being distracted by simple reindentations.

So far, it has only been compiled and smoke-tested on
amd64-pc-solaris2.1[01], sparcv9-sun-solaris2.1[01], and
x86_64-pc-linux-gnu.  Certainly needs more testing (Solaris 11.3
vs. 11.4, 32-bit gdb, testsuite once I've figured out what's wrong on
Solaris 10 etc.), but it's enough to get a first impression how much
cleanup is possible here.

	* configure.ac Don't check for sys/fault.h, sys/syscall.h,
	sys/proc.h.
	(NEW_PROC_API): Remove.
	(prsysent_t, pr_sigset_t, pr_sigaction64_t, pr_siginfo64_t):
	Likewise.
	* common/common.m4 (GDB_AC_COMMON): Don't check for sys/syscall.h.
	* configure: Regenerate.
	* config.in: Regenerate.
	* gdbserver/configure: Regenerate.
	* gdbserver/config.in: Regenerate.

	* i386-sol2-nat.c (_initialize_amd64_sol2_nat): Remove
	NEW_PROC_API test.
	* sparc-sol2-nat.c (_initialize_sparc_sol2_nat): Likewise.

	* linux-btrace.c: Remove HAVE_SYS_SYSCALL_H test.

	* proc-api.c: Remove !NEW_PROC_API support.
	Remove HAVE_SYS_PROC_H and HAVE_SYS_USER_H tests.
	Remove tests for macros always defined on Solaris.
	* proc-events.c: Remove !NEW_PROC_API support.
	Remove Remove HAVE_SYS_SYSCALL_H, HAVE_SYS_PROC_H and
	HAVE_SYS_USER_H tests.
	(init_syscall_table): Remove non-Solaris syscalls.
	Remove tests for syscalls present on all Solaris versions.
	Add missing Solaris 10+ syscalls.
	(signal_table): Remove non-Solaris signals.
	Remove tests for signals present on all Solaris versions.
	(fault_table): Remove non-Solaris faults.
	Remove tests for faults present on all Solaris versions.
	* proc-flags.c: Remove !NEW_PROC_API support.
	(pr_flag_table): Remove non-Solaris and pre-Solaris 7 comments.
	Remove non-Solaris flags.
	* proc-why.c: Remove !NEW_PROC_API support.
	(pr_why_table): Remove meaningless comments.
	Remove tests for reasons present on all Solaris versions.
	Remove OSF/1 cases.
	(proc_prettyfprint_why): Likewise.

	* procfs.c: Remove !NEW_PROC_API and DYNAMIC_SYSCALLS support.
	Remove HAVE_SYS_FAULT_H and HAVE_SYS_SYSCALL_H tests.
	Remove WA_READ test, IRIX watchpoint support.
	(gdb_sigset_t, gdb_sigaction_t, gdb_siginfo_t): Replace by base
	types.  Change users.
	(gdb_praddset, gdb_prdelset, gdb_premptysysset, gdb_praddsysset)
	(gdb_prdelset, gdb_pr_issyssetmember): Replace by base macros.
	Change callers.
	Remove CTL_PROC_NAME_FMT tests.
	(gdb_prstatus_t, gdb_lwpstatus_t): Replace by base types.  Change
	users.
	(sysset_t_size): Remove.  Use sizeof (sysset_t) in callers.
	Remove PROCFS_DONT_PIOCSSIG_CURSIG support.
	(proc_modify_flag): Replace GDBRESET by PCUNSET.
	Remove PR_ASYNC, PR_KLC tests.
	(proc_unset_inherit_on_fork): Remove PR_ASYNC test.
	(proc_parent_pid): Remove PCWATCH etc. tests.
	(proc_set_watchpoint): Remove !PCWATCH && !PIOCSWATCH support.
	Remove PCAGENT test.
	(proc_get_nthreads) [PIOCNTHR && PIOCTLIST]: Remove.
	Remove SYS_lwpcreate || SYS_lwp_create test.
	(proc_get_current_thread): Likewise.
	[PIOCNTHR && PIOCTLIST]: Remove.
	[PIOCLSTATUS]: Remove.
	(procfs_debug_inferior): Remove non-Solaris cases, conditionals.
	[PRFS_STOPEXEC]: Remove.
	(syscall_is_lwp_exit): Remove non-Solaris cases, conditionals.
	(syscall_is_exit): Likewise.
	(syscall_is_exec): Likewise.
	(syscall_is_lwp_create): Likewise.
	Remove SYS_syssgi support.
	(procfs_wait): Remove PR_ASYNC, !PIOCSSPCACT tests.
	[SYS_syssgi]: Remove.
	Remove non-Solaris cases, conditionals.
	(unconditionally_kill_inferior) [PROCFS_NEED_PIOCSSIG_FOR_KILL]:
	Remove.
	(procfs_init_inferior) [SYS_syssgi]: Remove.
	(procfs_set_exec_trap) [PRFS_STOPEXEC]: Remove.
	(procfs_inferior_created) [SYS_syssgi]: Remove.
	(procfs_set_watchpoint): Remove !AIX5 test.
	(procfs_stopped_by_watchpoint): Remove FLTWATCH test, FLTKWATCH
	case.
	(mappingflags) [MA_PHYS]: Remove.
	(info_mappings_callback): Remove PCAGENT test.
	Remove PIOCOPENLWP || PCAGENT test.
2017-11-30 16:05:30 +01:00
Rainer Orth e8020e54f4 Fix sol-thread.c compilation on Solaris
Building current gdb mainline with gcc 7.1 on Solaris 11.4 fails:

/vol/src/gnu/gdb/gdb/dist/gdb/sol-thread.c: In function `void _initialize_sol_thread()':
/vol/src/gnu/gdb/gdb/dist/gdb/sol-thread.c:1229:66: error: invalid conversion from `void (*)(char*, int)' to `void (*)(const char*, int)' [-fpermissive]
     _("Show info on Solaris user threads."), &maintenanceinfolist);
                                                                  ^
In file included from /vol/src/gnu/gdb/gdb/dist/gdb/completer.h:21:0,
                 from /vol/src/gnu/gdb/gdb/dist/gdb/symtab.h:31,
                 from /vol/src/gnu/gdb/gdb/dist/gdb/language.h:26,
                 from /vol/src/gnu/gdb/gdb/dist/gdb/frame.h:72,
                 from /vol/src/gnu/gdb/gdb/dist/gdb/gdbarch.h:39,
                 from /vol/src/gnu/gdb/gdb/dist/gdb/defs.h:557,
                 from /vol/src/gnu/gdb/gdb/dist/gdb/sol-thread.c:51:
/vol/src/gnu/gdb/gdb/dist/gdb/command.h:140:33: note:   initializing argument 3 of `cmd_list_element* add_cmd(const char*, command_class, void (*)(const char*, int), const char*, cmd_list_element**)'
 extern struct cmd_list_element *add_cmd (const char *, enum command_class,
                                 ^~~~~~~

The following patch allows compilation to succeed on i386-pc-solaris2.11
and sparc-sun-solaris2.11.

	* sol-thread.c (info_solthreads): Constify args.
	Cast args to void *.
2017-11-30 10:57:04 +01:00
John Baldwin 7505954411 Define MPFR_USE_INTMAX_T so that mpfr.h assumes intmax_t is available.
mpfr.h uses a non-portable test to guess if intmax_t is available and
if API functions using intmax_t should be exposed.  Define
MPFR_USE_INTMAX_T to override the non-portable test and always expose
these functions.  This fixes the build on platforms where the test
guesses incorrectly.

gdb/ChangeLog:

	* target-float.c [HAVE_LIBMPFR]: Define MPFR_USE_INTMAX_T.
2017-11-29 16:28:01 -08:00
Joel Brobecker f5a9147212 preserve type length in ada-lang.c::to_fixed_range_type
This patch fixes a potential issue which was noticed by code inspection:
ada-lang.c::to_fixed_range_type uses gdbtypes.c::create_static_range_type
to create most of the range type, which relies on create_range_type to
do most of the work. The latter has the following piece of code which
sets the length of the range type to match the length of the index_type:

    if (TYPE_STUB (index_type))
      TYPE_TARGET_STUB (result_type) = 1;
    else
      TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));

In Ada, it is actually possible to have a range type whose size
is smaller than its base type. For instance, with:

    type Unsigned2_T is  range 0 .. 2 ** 16 - 1;
    for Unsigned2_T'SIZE use 16;

The compiler generates the following DWARF:

        .uleb128 0x3    # (DIE (0x4e) DW_TAG_subrange_type)
        .byte   0x2     # DW_AT_byte_size
        .byte   0       # DW_AT_lower_bound
        .value  0xffff  # DW_AT_upper_bound
        .long   .LASF64 # DW_AT_name: "try__unsigned2_t___XDLU_0__65535"
        .long   0x616   # DW_AT_type

... which points to the following base type...

        .uleb128 0x1d   # (DIE (0x616) DW_TAG_base_type)
        .byte   0x4     # DW_AT_byte_size
        .byte   0x5     # DW_AT_encoding
        .long   .LASF57 # DW_AT_name: "try__Tunsigned2_tB"
                        # DW_AT_artificial

... which has a size of 4 bytes.

With a type like this one, create_range_type returns a type whose
size is 4 bytes, instead of 2, which is not what we we would normally
expect.

Currently, this function is only used to handle array index types,
so the length of the type actually does not matter and there should
not be any user-visible consequences of the current behavior. But
it seems best to plug this latent bug now, rather than wait for it
to surface....

gdb/ChangeLog:

        * ada-lang.c (to_fixed_range_type): Make sure that the size
        of the range type being returned is the same as the size
        of the range type being fixed.

Tested on x86_64-linux, no regression.
2017-11-29 18:32:17 -05:00
Pedro Alves bd69330db8 Breakpoints in symbols with ABI tags (PR c++/19436)
Trying to set a breakpoint in a function with an ABI tag does not work
currently.  E.g., debugging gdb itself, we see this with the
"string_printf" function:

 (top-gdb) b string_print                               [TAB]
 (top-gdb) b string_printf[abi:cxx11](char const*, ...) [RET]
 No source file named string_printf[abi.
 Make breakpoint pending on future shared library load? (y or [n])

Quoting doesn't help:
 (top-gdb) b 'string_printf[abi:cxx11]'(char const*, ...)
 malformed linespec error: unexpected string, "(char const*, ...)"
 (top-gdb) b 'string_printf[abi:cxx11](char const*, ...)'
 No source file named string_printf[abi.
 Make breakpoint pending on future shared library load? (y or [n]) n

This patch fixes this, and takes it a bit further.

The actual symbol name as demangled by libiberty's demangler is really

 string_printf[abi:cxx11](char const*, ...)

however, this patch makes it possible to set the breakpoint with

 string_printf(char const*, ...)

too.  I.e., ignoring the ABI tag.

And to match, it teaches the completer to complete the symbol name
without the ABI tag, i.e.,

  "string_pri<TAB>"  -> "string_printf(char const*, ...)"

If however, you really want to break on a symbol with the tag, then
you simply start writing the tag, and GDB will preserve it, like:

  "string_printf[a<TAB>"  -> "string_printf[abi:cxx11](char const*, ...)"

Grows the gdb.linespec/ tests like this:

  -# of expected passes           8977
  +# of expected passes           9176

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

	PR c++/19436
	* NEWS: Mention setting breakpoints on functions with C++ ABI
	tags.
	* completer.h (completion_match_for_lcd) <match,
	mark_ignored_range>: New methods.
	<finish>: Consider ignored ranges.
	<clear>: Clear ignored ranges.
	<m_ignored_ranges, m_finished_storage>: New fields.
	* cp-support.c (cp_search_name_hash): Ignore ABI tags.
	(cp_symbol_name_matches_1, cp_fq_symbol_name_matches): Pass the
	completion_match_for_lcd pointer to strncmp_iw_with_mode.
	(test_cp_symbol_name_cmp): Add [abi:...] tags unit tests.
	* language.c (default_symbol_name_matcher): Pass the
	completion_match_for_lcd pointer to strncmp_iw_with_mode.
	* linespec.c (linespec_lexer_lex_string): Don't tokenize ABI tags.
	* utils.c (skip_abi_tag): New function.
	(strncmp_iw_with_mode): Add completion_match_for_lcd parameter.
	Handle ABI tags.
	* utils.h (strncmp_iw_with_mode): Add completion_match_for_lcd
	parameter.

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

	PR c++/19436
	* gdb.linespec/cpls-abi-tag.cc: New file.
	* gdb.linespec/cpls-abi-tag.exp: New file.

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

	PR c++/19436
	* gdb.texinfo (Debugging C Plus Plus): Document setting
	breakpoints in functions with ABI tags.
2017-11-29 19:46:41 +00:00
Pedro Alves a20714ff39 Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching]
This patch teaches GDB about setting breakpoints in all scopes
(namespaces and classes) by default.

Here's a contrived example:

  (gdb) b func<tab>
  (anonymous namespace)::A::function()            Bn::(anonymous namespace)::B::function()        function(int, int)
  (anonymous namespace)::B::function()            Bn::(anonymous namespace)::function()           gdb::(anonymous namespace)::A::function()
  (anonymous namespace)::B::function() const      Bn::(anonymous namespace)::function(int, int)   gdb::(anonymous namespace)::function()
  (anonymous namespace)::function()               Bn::B::func()                                   gdb::(anonymous namespace)::function(int, int)
  (anonymous namespace)::function(int, int)       Bn::B::function()                               gdb::A::func()
  A::func()                                       Bn::func()                                      gdb::A::function()
  A::function()                                   Bn::function()                                  gdb::func()
  B::func()                                       Bn::function(int, int)                          gdb::function()
  B::function()                                   Bn::function(long)                              gdb::function(int, int)
  B::function() const                             func()                                          gdb::function(long)
  B::function_const() const                       function()
  (gdb) b function
  Breakpoint 1 at 0x4005ce: function. (26 locations)

  (gdb) b B::function<tab>
  (anonymous namespace)::B::function()        B::function() const                         Bn::B::function()
  (anonymous namespace)::B::function() const  B::function_const() const
  B::function()                               Bn::(anonymous namespace)::B::function()
  (gdb) b B::function
  Breakpoint 1 at 0x40072c: B::function. (6 locations)

To get back the original behavior of interpreting the function name as
a fully-qualified name, you can use the new "-qualified" (or "-q")
option/flag (added by this commit).  For example:

 (gdb) b B::function
 (anonymous namespace)::B::function()        B::function() const                         Bn::B::function()
 (anonymous namespace)::B::function() const  B::function_const() const
 B::function()                               Bn::(anonymous namespace)::B::function()

vs:

 (gdb) b -qualified B::function
 B::function()              B::function() const        B::function_const() const

I've chosen "-qualified" / "-q" because "-f" (for "full" or
"fully-qualified") is already taken for "-function".

Note: the "-qualified" option works with both linespecs and explicit
locations.  I.e., these are equivalent:

 (gdb) b -q func
 (gdb) b -q -f func

and so are these:

 (gdb) b -q filename.cc:func
 (gdb) b -q -s filename.cc -f func
 (gdb) b -s filename.cc -q -f func
 (gdb) b -s filename.cc -f func -q

To better understand why I consider wild matching the better default,
consider what happens when we get to the point when _all_ of GDB is
wrapped under "namespace gdb {}".  I have a patch series that does
that, and when I started debugging that GDB, I immediately became
frustrated.  You'd have to write "b gdb::internal_error", "b
gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty
quickly.  OTOH, consider how this makes it very easy to set
breakpoints in classes wrapped in anonymous namespaces.  You just
don't think of them, GDB finds the symbols for you automatically.

(At the Cauldron a couple months ago, several people told me that they
run into a similar issue when debugging other C++ projects.  One
example was when debugging LLVM, which puts all its code under the
"llvm" namespace.)

Implementation-wise, what the patch does is:

  - makes C++ symbol name hashing only consider the last component of
    a symbol name. (so that we can look up symbol names by
    last-component name only).

  - adds a C++ symbol name matcher for symbol_name_match_type::WILD,
    which ignores missing leading specifiers / components.

  - adjusts a few preexisting testsuite tests to use "-qualified" when
    they mean it.

  - adds new testsuite tests.

  - adds unit tests.

Grows the gdb.linespec/ tests like this:

  -# of expected passes           7823
  +# of expected passes           8977

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

	* NEWS: Mention that breakpoints on C++ functions are now set on
	on all namespaces/classes by default, and mention "break
	-qualified".
	* ax-gdb.c (agent_command_1): Adjust to pass a
	symbol_name_match_type to new_linespec_location.
	* breakpoint.c (parse_breakpoint_sals): Adjust to
	get_linespec_location's return type change.
	(strace_marker_create_sals_from_location): Adjust to pass a
	symbol_name_match_type to new_linespec_location.
	(strace_marker_decode_location): Adjust to get_linespec_location's
	return type change.
	(strace_command): Adjust to pass a symbol_name_match_type to
	new_linespec_location.
	(LOCATION_HELP_STRING): Add paragraph about wildmatching, and
	mention "-qualified".
	* c-lang.c (cplus_language_defn): Install cp_search_name_hash.
	* completer.c (explicit_location_match_type::MATCH_QUALIFIED): New
	enumerator.
	(complete_address_and_linespec_locations): New parameter
	'match_type'.  Pass it down.
	(explicit_options): Add "-qualified".
	(collect_explicit_location_matches): Pass the requested match type
	to the linespec completers.  Handle MATCH_QUALIFIED.
	(location_completer): Handle "-qualified" combined with linespecs.
	* cp-support.c (cp_search_name_hash): New.
	(cp_symbol_name_matches_1): Implement wild matching for C++.
	(cp_fq_symbol_name_matches): Reimplement.
	(cp_get_symbol_name_matcher): Return different matchers depending
	on the lookup name's match type.
	(selftests::test_cp_symbol_name_matches): Add wild matching tests.
	* cp-support.h (cp_search_name_hash): New declaration.
	* dwarf2read.c
	(selftests::dw2_expand_symtabs_matching::test_symbols): Add
	symbols.
	(test_dw2_expand_symtabs_matching_symbol): Add wild matching
	tests.
	* guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to
	pass a symbol_name_match_type to new_linespec_location.
	* linespec.c (linespec_parse_basic): Lookup function symbols using
	the parser's symbol name match type.
	(convert_explicit_location_to_linespec): New
	symbol_name_match_type parameter.  Pass it down to
	find_linespec_symbols.
	(convert_explicit_location_to_sals): Pass the location's name
	match type to convert_explicit_location_to_linespec.
	(parse_linespec): New match_type parameter.  Save it in the
	parser.
	(linespec_parser_new): Default to symbol_name_match_type::WILD.
	(linespec_complete_function): New symbol_name_match_type
	parameter.  Use it.
	(complete_linespec_component): Pass down the parser's recorded
	name match type.
	(linespec_complete_label): New symbol_name_match_type parameter.
	Use it.
	(linespec_complete): New symbol_name_match_type parameter.  Save
	it in the parser and pass it down.  Adjust to
	get_linespec_location's prototype change.
	(find_function_symbols, find_linespec_symbols): New
	symbol_name_match_type parameter.  Pass it down instead of
	assuming symbol_name_match_type::WILD.
	* linespec.h (linespec_complete, linespec_complete_function)
	(linespec_complete_label): New symbol_name_match_type parameter.
	* location.c (event_location::linespec_location): Now a struct
	linespec_location.
	(EL_LINESPEC): Adjust.
	(initialize_explicit_location): Default to
	symbol_name_match_type::WILD.
	(new_linespec_location): New symbol_name_match_type parameter.
	Record it in the location.
	(get_linespec_location): Now returns a struct linespec_location.
	(new_explicit_location): Also copy func_name_match_type.
	(explicit_to_string_internal)
	(string_to_explicit_location): Handle "-qualified".
	(copy_event_location): Adjust to LINESPEC_LOCATION type change.
	Copy symbol_name_match_type fields.
	(event_location_deleter::operator()): Adjust to LINESPEC_LOCATION
	type change.
	(event_location_to_string): Adjust to LINESPEC_LOCATION type
	change.  Handle "-qualfied".
	(string_to_explicit_location): Handle "-qualified".
	(string_to_event_location_basic): New symbol_name_match_type
	parameter.  Pass it down.
	(string_to_event_location): Handle "-qualified".
	* location.h (struct linespec_location): New.
	(explicit_location::func_name_match_type): New field.
	(new_linespec_location): Now returns a const linespec_location *.
	(string_to_event_location_basic): New symbol_name_match_type
	parameter.
	(explicit_completion_info::saw_explicit_location_option): New
	field.
	* mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a
	symbol_name_match_type to new_linespec_location.
	* python/py-breakpoint.c (bppy_init): Likewise.
	* python/python.c (gdbpy_decode_line): Likewise.

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

	* gdb.base/langs.exp: Use -qualified.
	* gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without
	it.
	* gdb.cp/namespace.exp: Use -qualified.
	* gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2)
	(overload-3, template-overload, template-ret-type, const-overload)
	(const-overload-quoted, anon-ns, ambiguous-prefix): New
	procedures.
	(test_driver): Call them.
	* gdb.cp/save-bp-qualified.cc: New.
	* gdb.cp/save-bp-qualified.exp: New.
	* gdb.linespec/explicit.exp: Test -qualified.
	* lib/completion-support.exp (completion::explicit_opts_list): Add
	"-qualified".
	* lib/gdb.exp (gdb_breakpoint): Handle "qualified".

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

	* gdb.texinfo (Linespec Locations): Document how "function" is
	interpreted in C++ and Ada.  Document "-qualified".
	(Explicit Locations): Document how "-function" is interpreted in
	C++ and Ada.  Document "-qualified".
2017-11-29 19:43:48 +00:00
Pedro Alves a207cff2da Handle custom completion match prefix / LCD
A following patch will add support for wild matching for C++ symbols,
making completing on "b push_ba" on a C++ program complete to
std::vector<...>::push_back, std::string::push_back etc., like:

 (gdb) b push_ba[TAB]
 std::vector<...>::push_back(....)
 std::string<...>::push_back(....)

Currently, we compute the "lowest common denominator" between all
completion candidates (what the input line is adjusted to) as the
common prefix of all matches.  That's problematic with wild matching
as above, as then we'd end up with TAB changing the input line to
"b std::", losing the original input, like:

 (gdb) b push_ba[TAB]
 std::vector<...>::push_back(....)
 std::string<...>::push_back(....)
 (gdb) b std::

while obviously we'd want it to adjust itself to "b push_back(" instead:

 (gdb) b push_ba[TAB]
 std::vector<...>::push_back(....)
 std::string<...>::push_back(....)
 (gdb) b push_back(

This patch adds the core code necessary to support this, though
nothing really makes use of it yet in this patch.

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

	* ada-lang.c (ada_lookup_name_info::matches): Change type of
	parameter from completion_match to completion_match_result.
	Adjust.
	(do_wild_match, do_full_match, ada_symbol_name_matches): Likewise.
	* completer.c (completion_tracker::maybe_add_completion): Add
	match_for_lcd parameter and use it.
	(completion_tracker::add_completion): Likewise.
	* completer.h (class completion_match_for_lcd): New class.
	(completion_match_result::match_for_lcd): New field.
	(completion_match_result::set_match): New method.
	(completion_tracker): Add comments.
	(completion_tracker::add_completion): Add match_for_lcd parameter.
	(completion_tracker::reset_completion_match_result): Reset
	match_for_lcd too.
	(completion_tracker::maybe_add_completion): Add match_for_lcd
	parameter.
	(completion_tracker::m_lowest_common_denominator_unique): Extend
	comments.
	* cp-support.c (cp_symbol_name_matches_1)
	(cp_fq_symbol_name_matches): Change type of parameter from
	completion_match to completion_match_result.  Adjust.
	* language.c (default_symbol_name_matcher): Change type of
	parameter from completion_match to completion_match_result.
	Adjust.
	* language.h (completion_match_for_lcd): Forward declare.
	(default_symbol_name_matcher): Change type of parameter from
	completion_match to completion_match_result.
	* symtab.c (compare_symbol_name): Adjust.
	(completion_list_add_name): Pass the match_for_lcd to the tracker.
	* symtab.h (ada_lookup_name_info::matches): Change type of
	parameter from completion_match to completion_match_result.
	(symbol_name_matcher_ftype): Likewise, and update comments.
2017-11-29 19:33:23 +00:00
Pedro Alves 4024cf2b8d Fix setting-breakpoints regression on PPC64 (function descriptors)
The recent-ish commit e5f25bc5d6 ('Fix "list ambiguous_variable"')
caused a serious regression on PPC64.  See
<https://sourceware.org/ml/gdb-patches/2017-11/msg00666.html>.

Basically, after that patch, GDB sets breakpoints in function
descriptors instead of where the descriptors point to, which is
incorrect.

The problem is that GDB now only runs a minsym's address through
gdbarch_convert_from_func_ptr_addr if msymbol_is_text returns true.
However, if the symbol points to a function descriptor,
msymbol_is_text is false since function descriptors are in fact
outside the text section.

The fix is to also run a non-text address through
gdbarch_convert_from_func_ptr_addr, and if that detects that it was
indeed a function descriptor, treat the resulting address as a
function.

While implementing that directly in linespec.c:minsym_found (where the
bad msymbol_is_text check is) fixes the issue, I noticed that
linespec.c:add_minsym has some code that also basically needs to do
the same checks, however it's implemented differently.  Also,
add_minsym is calling find_pc_sect_line on non-function symbols, which
also doesn't look right.

So I introduced msymbol_is_function, so that we have a simple place to
consider minsyms and function descriptors.

And then, the only other use of msymbol_is_text is in
find_function_alias_target, which turns out to also be incorrect.
Changing that one to use msymbol_is_function, i.e., to consider
function descriptors too fixes (on PPC64):

  -FAIL: gdb.base/symbol-alias.exp: p func_alias
  -FAIL: gdb.base/symbol-alias.exp: p *func_alias()
  +PASS: gdb.base/symbol-alias.exp: p func_alias
  +PASS: gdb.base/symbol-alias.exp: p *func_alias()

And then after that, msymbol_is_text is no longer used anywhere, so it
can be removed.

Tested on x86_64 GNU/Linux, no regressions.  Tested on PPC64 GNU/Linux
and results compared to a testrun of e5f25bc5d6db^ (before the
offending commit), also no regressions.  (there's a couple new FAILs
and some new symbol name matching unit tests are crashing, but that
looks unrelated).

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

	* linespec.c (minsym_found, add_minsym): Use msymbol_is_function.
	* minsyms.c (msymbol_is_text): Delete.
	(msymbol_is_function): New function.
	* minsyms.h (msymbol_is_text): Delete.
	(msymbol_is_function): New declaration.
	* symtab.c (find_function_alias_target): Use msymbol_is_function.
2017-11-29 19:25:58 +00:00
Tom Tromey 5dcf52c19f Fix gdb snapshots
Joel pointed out that gdb snapshots were broken by my Makefile patch
series.  The bug is that rmdir in distclean was failing, because the
directory did not exist.  This fixes the bug by only invoking rmdir when
the directory exists.

Tested using "src-release.sh gdb".

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

	* Makefile.in (distclean): Handle the case where rmdir fails.
2017-11-29 11:56:40 -07:00
Phil Muldoon f6f1d339d4 Fix Python rbreak tests setting too many breakpoints when glibc debug info is installed.
2017-11-29  Phil Muldoon  <pmuldoon@redhat.com>

	* gdb.python/py-rbreak.exp: Set nosharedlibrary before tests.
2017-11-29 16:50:36 +00:00
Tom Tromey 8ca2f0b9ac Update usage text for add-symbol-file, symbol-file, and load
This updates the usage text for the add-symbol-file, symbol-file, and
load commands.

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

	* symfile.c (_initialize_symfile): Update usage text for
	add-symbol-file, symbol-file, load.
2017-11-29 09:21:43 -07:00
Tom Tromey 02ca603a48 Fix add-symbol-file usage and errors
This patch updates add-symbol-file help and error text.

It changes add-symbol-file to throw an exception if "-s" is seen but
not all of the arguments are given.  Previously this was silently
ignored.

It changes the unrecognized argument message to more clearly state
what went wrong.

Finally, it updates the usage line in the help text to follow GNU
style regarding "metasyntactic variables"; a change I believe should
be made to all gdb help messages.

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

	* symfile.c (add_symbol_file_command): Error if some arguments to
	-s are missing.  Change unrecognized-argument error message.
	(_initialize_symfile): Fix usage text for add-symbol-file.

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

	* gdb.base/relocate.exp: Update invalid argument test.
	Add new tests for invalid arguments.
2017-11-29 09:21:43 -07:00
Thomas Preud'homme ed6c0bfb26 [gdb/testsuite] Fix return type of psymtab-parameter
As pointed out by Pedro Alves, psymtab-parameter testcase rely on the
return type being long. This patch revert the changes made in
f106e10e5e and change psymtab-parameter.cc
to return 0 long instead.

2017-11-29  Thomas Preud'homme  <thomas.preudhomme@arm.com>

gdb/testsuite/
	* gdb.cp/psymtab-parameter.cc (func): Change return type back to long.
	Return 0 as a long.
	* gdb.cp/psymtab-parameter.exp: Change func's return type back to long.
2017-11-29 13:41:32 +00:00
Thomas Preud'homme f106e10e5e [gdb/testsuite] Fix wrong return type in tests
The following tests are marked untested with latest GCC due to a warning
being emitted for a mismatch between their return type and what the lack
of return statement:

* gdb.cp/breakpoint.exp
* gdb.cp/psymtab-parameter.exp
* gdb.cp/shadow.exp

This patch fix the return type to match the function definitions.

2017-11-29  Thomas Preud'homme  <thomas.preudhomme@arm.com>

gdb/testsuite/
	* gdb.cp/breakpoint.cc (bar): Set return type to void.
	* gdb.cp/psymtab-parameter.cc (func): Likewise.
	* gdb.cp/psymtab-parameter.exp: Update comment regarding prototype of
	func ().
	* gdb.cp/shadow.cc (B.func): Return 0.
2017-11-29 10:45:31 +00:00
Tom Tromey 18ca73470a Remove REMOTE_OBS
This removes REMOTE_OBS from the Makefile.  It is no longer needed, as
remote support is always built into gdb.  The relevant sources are now
added to COMMON_SFILES, where they are treated like other ordinary
sources.

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

	* Makefile.in (REMOTE_OBS): Remove.
	(SFILES): Remove remote sources.
	(COMMON_SFILES): Add remote sources.
	(ALLDEPFILES): Remove dcache.c.
2017-11-27 16:53:27 -07:00
Tom Tromey 66599a7dc0 Move target object files to target subdirectory
Move the object files corresponding to target/*.c to the target
subdirectory in the build tree.

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

	* Makefile.in (SUBDIR_TARGET_SRCS, SUBDIR_TARGET_OBS): New
	variables.
	(SFILES): Use SUBDIR_TARGET_SRCS.
	(COMMON_OBS): Use SUBDIR_TARGET_OBS.  Remove waitstatus.o.
	(CONFIG_SRC_SUBDIR): Add target.
	(%.o): Remove target rule.
2017-11-27 16:53:27 -07:00
Tom Tromey 4f04fba813 Add missing files to COMMON_SFILES
While working on the previous patch, I found a few .o files whose
corresponding .c file was not mentioned in Makefile.in.  This patch
fixes the problem.  I pulled this out separately to make it simpler to
review.

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

	* Makefile.in (COMMON_OBS): Remove filename-seen-cache.o,
	registry.o, thread-fsm.o, debug.o.
	(COMMON_SFILES): Add filename-seen-cache.c, registry.c,
	thread-fsm.c, debug.c.
2017-11-27 16:53:26 -07:00
Tom Tromey b5adff3b5e Simplify COMMON_OBS by using list of sources
This introduces a new COMMON_SFILES variable, and then defines some of
COMMON_OBS in terms of this new variable.  This simpifies adding a new
ordinary source file.

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

	* Makefile.in (COMMON_SFILES): New.
	(SFILES): Move some entries to COMMON_SFILES.
	(COMMON_OBS): Use COMMON_SFILES.
2017-11-27 16:53:26 -07:00
Tom Tromey afa0a41159 Define YYOBJ in terms of YYFILES
Change YYOBJ to be defined in terms of YYFILES.

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

	* Makefile.in (YYFILES): Update comment.
	(YYOBJ): Redefine.
2017-11-27 16:53:25 -07:00
Tom Tromey 8fd8d003de Move python object files to python subdirectory
Move the object files corresponding to python/*.c to the python
subdirectory in the build tree.

Because special CFLAGS are passed just to Python compilations, this
patch also required the addition of a pattern rule to update
INTERNAL_CFLAGS for here.

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

	* Makefile.in (SUBDIR_PYTHON_OBS): Redefine.
	(CONFIG_SRC_SUBDIR): Add python.
	(%.o): Remove python rule.
	(python/%.o): New rule.
	* configure: Rebuild.
	* configure.ac (CONFIG_OBS): Refer to python/python.o
2017-11-27 16:53:25 -07:00
Tom Tromey bd810fff78 Move guile object files to guile subdirectory
Move the object files corresponding to guile/*.c to the guile
subdirectory in the build tree.

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

	* configure: Rebuild.
	* configure.ac (CONFIG_OBS): Refer to guile/guile.o.
	* Makefile.in (SUBDIR_GUILE_OBS): Redefine.
	(CONFIG_SRC_SUBDIR): Add guile.
	(%.o): Remove guile rule.
2017-11-27 16:53:24 -07:00
Tom Tromey 75787ac19c Move unittests object files to unittests subdirectory
Move the object files corresponding to unittests/*.c to the unittests
subdirectory in the build tree.

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

	* Makefile.in (SUBDIR_UNITTESTS_OBS): Redefine.
	(%.o): Remove unittests rule.
	(CONFIG_SRC_SUBDIR): Add unittests.
2017-11-27 16:53:24 -07:00
Tom Tromey 5c8a943144 Move tui object files to tui subdirectory
Move the object files corresponding to tui/*.c to the tui subdirectory
in the build tree.

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

	* Makefile.in (SUBDIR_TUI_OBS): Redefine.
	(CONFIG_SRC_SUBDIR): Add tui.
	(%.o): Remove tui rule.
2017-11-27 16:53:23 -07:00
Tom Tromey a26aa30cc5 Move compile object files to compile subdirectory
Move the object files corresponding to compile/*.c to the compile
subdirectory in the build tree.

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

	* Makefile.in (SUBDIR_GCC_COMPILE_OBS): Redefine.
	(%.o): Remove compile rule.
	(CONFIG_SRC_SUBDIR): Add compile.
2017-11-27 16:53:23 -07:00
Tom Tromey 6f3cdf9a3b Move mi objects to mi subdirectory
Move object files corresponding to mi/*.c to a subdirectory in the
build tree.

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

	* Makefile.in (SUBDIR_MI_OBS): Redefine.
	(%.o): Remove mi rule.
	(CONFIG_SRC_SUBDIR): Add mi.
	(COMMON_OBS): Use mi/mi-common.o
2017-11-27 16:53:22 -07:00
Tom Tromey f06afa5336 Move cli object files to cli subdirectory
Following the "arch" move, this moves the object files corresponding
to the cli/*.c source files to the "cli" build directory.

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

	* Makefile.in (SUBDIR_CLI_OBS): Redefine.
	(%.o): Remove cli rule.
	(CONFIG_SRC_SUBDIR): Add cli.
2017-11-27 16:53:22 -07:00
Tom Tromey b22c88c2ca A simpler way to make the "arch" build directory
This implements a simpler way to make the "arch" build directory --
namely, now it is done as an order-only dependency in the Makefile,
rather than being created when config.status is run.  This simpler
because it means that the build directories can be changed without
re-running autoconf.

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

	* configure.ac (CONFIG_SRC_SUBDIR): Don't subst.
	* configure: Rebuild.
	* Makefile.in (CONFIG_SRC_SUBDIR): Redefine.
	(CONFIG_DEP_SUBDIR): New variable.
	(%.o): Add order-only dependency.
	($(CONFIG_DEP_SUBDIR)): New target.
2017-11-27 16:53:21 -07:00
Joel Brobecker 10329bb27f fix two issues in gdb.ada/mi_catch_ex.exp (re: "exception-message")
The following patch introduced a new feature related to Ada exception
catchpoints:

    commit e547c119d0
    Author: Joel Brobecker <brobecker@adacore.com>
    Date:   Fri Nov 24 17:09:42 2017 -0500
    Subject: (Ada) provide the exception message when hitting an exception catchpoint

Unfortunately, the patch left 2 errors in gdb.ada/mi_catch_ex.exp,
both inside the "continue_to_exception" function:

  1. The exception message on the console can include the exception
     message, and thus this patch adjust the expected output in
     the corresponding gdb_expect call to allow it;
     to allow it.

  2. There was a TCL syntax confusion in "$exception_name(..."
     that caused TCL to evaluate "exception_name as an array,
     rather than as a variable. This patch fixes this by escaping
     the '(' (and the corresponding closing parenthesis, for
     consistency).

gdb/testsuite/ChangeLog:

        * gdb.ada/mi_catch_ex.exp (continue_to_exception): Adjust
        expected output in gdb_expect call to allow the exception
        message to be present as well.  Fix syntax confusion to avoid
        TCL thinking that exception_name is an array.

Tested on x86_64-linux, with:

    DejaGnu version  1.6
    Expect version   5.45
    Tcl version      8.6
2017-11-27 11:39:45 -08:00
Dominik Czarnota ee9a09e959 Update find command help and search memory docs
This patch updates the `find` command help and docs description to show
how to search for not null terminated strings when current language's
strings includes it.

gdb/ChangeLog:

	PR gdb/21945
	* findcmd.c (_initialize_mem_search): Update find command help
	text.

gdb/doc/ChangeLog:

	PR gdb/21945
	* gdb.texinfo (Search Memory): Update description and example
	about how to search a string without NULL terminator.
2017-11-26 22:42:19 -05:00
Simon Marchi e8e7d10c39 python: Fix memleak in do_start_initialization
While playing with valgrind, I noticed that with Python 3, the progname
variable in do_start_initialization is not being freed (concat returns a
malloc'ed string).  This patch uses unique_xmalloc_ptr to manage it.
With Python 2, we pass progname it directly to Py_SetProgramName, so it
should not be freed.  We therefore release it before passing it.

gdb/ChangeLog:

	* python/python.c (do_start_initialization): Change progname
	type to gdb::unique_xmalloc_ptr.  Release the pointer when using
	Python 2.
2017-11-26 19:32:47 -05:00
Tom Tromey 6a997029fb Add include guards to common/format.h
This adds include guards to common/format.h.

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

	* common/format.h: Add include guards.
2017-11-26 12:02:40 -07:00
Tom Tromey 41272101db Change maybe_disable_address_space_randomization to a class
This changes maybe_disable_address_space_randomization to be an RAII
class, rather than having it return a cleanup.

Regression tested by the buildbot.

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

	* nat/linux-personality.h (class
	maybe_disable_address_space_randomization): New class.
	(maybe_disable_address_space_randomization): Don't declare
	function.
	* nat/linux-personality.c (restore_personality)
	(make_disable_asr_cleanup): Remove.
	(maybe_disable_address_space_randomization): Now a constructor.
	(~maybe_disable_address_space_randomization): New destructor.
	* linux-nat.c (linux_nat_create_inferior): Update.

gdbserver/ChangeLog
2017-11-26  Tom Tromey  <tom@tromey.com>

	* linux-low.c (linux_create_inferior): Update.
2017-11-26 10:42:15 -07:00
Tom Tromey 44287fd890 Removes a cleanup from gcore.c
This removes a cleanup from gcore.c, replacing it with
unique_xmalloc_ptr.

Regression tested by the buildbot.

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

	* gcore.c (write_gcore_file_1): Use gdb::unique_xmalloc_ptr.
2017-11-26 10:41:13 -07:00
Ulrich Weigand 58f7f0bf54 Fix broken ChangeLog entry for last commit. 2017-11-26 17:29:00 +01:00
Ulrich Weigand 617cd4bc36 [spu] Fix various test cases
The SPU-specific test cases were not modified to use standard_output_file
and therefore all were no longer being executed.  Fixing this exposed a
few other bugs in spu-info noticed by using a more recent compiler, which
are also fixed here.

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

	* gdb.arch/spu-info.c: Include <unistd.h>.
	(do_signal_test): Fix broken calls to write.
	* gdb.arch/spu-info.exp: Use prepare_for_testing.
	Fix checks for empty mailboxes.  Update signal tests for corrected
	do_signal_test routine.  Allow nonzero event status.
2017-11-26 17:19:57 +01:00
Ulrich Weigand 5ffd2cb722 [spu] Fix single-stepping regression
Switching spu_software_single_step to use a regcache instead of a frame:
https://sourceware.org/ml/gdb-patches/2016-11/msg00355.html
cause a serious regression to SPU single-stepping.

There were two separate problems:
- SPU_LSLR_REGNUM is a pseudo register, so we must use the "cooked"
  regcache methods instead of the "raw" ones to access it.
- When accessing a branch target register, we must only use the first
  four bytes of the 16-byte vector register.  This was done automatically
  by the frame routines, but not by the regcache routines.

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

	* spu-tdep.c (spu_software_single_step): Access SPU_LSLR_REGNUM as
	"cooked" register.  Access only first four bytes of branch target
	registers.
2017-11-26 17:15:25 +01:00
Sergio Durigan Junior 0e5457dca1 Adding ChangeLog entry for the last commit. 2017-11-25 10:57:58 -05:00
Sergio Durigan Junior 685de8c299 Fix PR gdb/22491: Regression when setting SystemTap probe semaphores
Pedro has kindly pointed out that
gdb.arch/amd64-stap-optional-prefix.exp was failing after my
C++-ification patches touching the probe interface.  The failure is
kind of cryptic:

 77 break -pstap bar
 78 Breakpoint 3 at 0x40048d
 79 (gdb) PASS: gdb.arch/amd64-stap-optional-prefix.exp: bar: break -pstap bar
 80 continue
 81 Continuing.
 82
 83 Program received signal SIGILL, Illegal instruction.
 84 main () at amd64-stap-optional-prefix.S:26
 85 26              STAP_PROBE1(probe, foo, (%rsp))

It took me a while to figure out where this SIGILL is coming from.
Initially I thought it was something related to writing registers to
the inferior when dealing with probe arguments, but I discarded this
since the arguments were not touching any registers.

In the end, this was a mistake that was introduced during the review
process of the patch.  When setting/clearing a SystemTap probe's
semaphore, the code was using 'm_address' (which refers the probe's
address) instead of 'm_sem_addr' (which refers to the semaphore's
address).  This caused GDB to write a bogus value in the wrong memory
position, which in turn caused the SIGILL.

I am pushing this patch to correct the mistake.

On a side note: I told Pedro that the BuildBot hadn't caught the
failure during my try build, and for a moment there was a suspicion
that the BuildBot might be at fault here.  However, I investigate this
and noticed that I only did one try build, with a patch that was
correctly using 'm_sem_addr' where applicable, and therefore no
failure should have happened indeed.  I probably should have requested
another try build after addressing the review's comments, but they
were mostly basic and I didn't think it was needed.  Oh, well.

2017-11-25  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR gdb/22491
	* stap-probe.c (relocate_address): New function.
	(stap_probe::get_relocated_address): Use 'relocate_address'.
	(stap_probe::set_semaphore): Use 'relocate_address' and pass
	'm_sem_addr'.
	(stap_probe::clear_semaphore): Likewise.
2017-11-25 01:13:03 -05:00
Pedro Alves deeeba559b Use TOLOWER in SYMBOL_HASH_NEXT
The support for setting breakpoint in functions with ABI tags patch
will add a use of SYMBOL_HASH_NEXT in cp-support.c, which fails to
compile with:

  src/gdb/cp-support.c:38:0:
  src/gdb/cp-support.c: In function ‘unsigned int cp_search_name_hash(const char*)’:
  src/gdb/../include/safe-ctype.h:148:20: error: ‘do_not_use_tolower_with_safe_ctype’ was not declared in this scope
   #define tolower(c) do_not_use_tolower_with_safe_ctype
		      ^
  src/gdb/minsyms.h:174:18: note: in expansion of macro ‘tolower’
     ((hash) * 67 + tolower ((unsigned char) (c)) - 113)
		    ^
  src/gdb/cp-support.c:1677:14: note: in expansion of macro ‘SYMBOL_HASH_NEXT’
	 hash = SYMBOL_HASH_NEXT (hash, *string);
		^

This fixes the problem before it happens.

I was somewhat worried about whether this might have an impact with
languages that are case insensitive, but I convinced myself that it
doesn't.  As bonus, this improves GDB's minsym interning performance a
bit (3%-10%).  See
<https://sourceware.org/ml/gdb/2017-11/msg00021.html>.

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

	* dictionary.c: Include "safe-ctype.h".
	* minsyms.c: Include "safe-ctype.h".
	* minsyms.c (SYMBOL_HASH_NEXT): Use TOLOWER instead of tolower.
2017-11-25 00:33:05 +00:00
Pedro Alves a81aaca057 Fix completing an empty string
Earlier while working on the big completer rework series, I managed to
break

 (gdb) [TAB]

locally, and make GDB crash, but only notice a few weeks down the
road, because we have no test for that...

I also noticed that:

 (gdb)     [TAB]

didn't work (didn't show all commands as matches), even though
entering a command with leading whitespace works:

 (gdb)     help

This commit fixes the latter and adds a testcase that covers both
issues.

The gdb.base/completion.exp change is necessary because the new test
has a file name that also starts with "gdb.base/complet", making that
particular test ambiguous.  Adding another letter disambiguates.

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

	* completer.c (complete_line_internal_1): Skip spaces until the
	start of the command.

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

	* gdb.base/complete-empty.exp: New file.
	* gdb.base/completion.exp: Adjust.
2017-11-25 00:20:31 +00:00
Pedro Alves 6a3c6ee418 Add comprehensive C++ operator linespec/location/completion tests
This exercises the special handling C++ operators require in several
places in the linespec parser, both the linespec and explicit location
completers, symbol lookup, etc.  Particularly, makes sure all that
works without quoting.

Note that despite the apparent smallish size, this adds thousands of
tests to the testsuite, due to combination explosion (linespecs,
explicit locations, tab completion, complete command, completion at
different points in each function, etc.)

Grows the gdb.linespec/ tests like this:

 -# of expected passes           3464
 +# of expected passes           7823

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

	* gdb.linespec/cpls-ops.cc: New file.
	* gdb.linespec/cpls-ops.exp: New file.
	* lib/completion-support.exp (test_complete_prefix_range_re): New,
	factored out from ...
	(test_complete_prefix_range): ... this.
2017-11-25 00:09:25 +00:00
Pedro Alves 8955eb2da3 Comprehensive C++ linespec/completer tests
Exercises all sorts of aspects fixed by previous patches, going back a
few months.

 - Exercises label completion, linespecs and explicit locations.

 - Exercises both quoting vs non-quoting, source filenames, function
   names, labels, with both linespecs and explicit locations.

 - Tests corner cases around not-quoting function names, and
   whitespace and/and completing inside a parameter or template
   argument list, anonymous namespace awareness, etc.

   E.g.,

     "break foo<[TAB]"          -> "break foo<int>()"
     "break bar ( int[TAB]"     -> "break bar ( int)
     "break ( anon"             -> "break ( anonymous namespace)::func()"
     "b cfunc() [tab]"          -> "b cfunc() const"
     "b rettype templfunc[tab]" -> "b rettype templfunc<bar>()"

   ... and others.

 - Tests the "b source.c[TAB] -> b source.cc:" feature.  I.e., colon
   auto-appending.

 - Exercises corner cases around C++ "operator<" / "operator<<".
   (Much more extensive C++ operator completion/linespec handling in a
   separate patch.)

 - Exercises both tab completion and "complete" command completion,
   using routines that handle it automatically, to ensure no test
   forgets either mode.

 - Many of the completion tests test completion at at prefix of a
   given tricky name, to make sure all corner cases are covered.
   E.g., completing before, at and after ":", "(", "<".

 - Exercises "keyword" completion.  I.e., "b function() [TAB]"
   displaying "if task thread" as completion match list.  Likewise for
   display explicit location options matches at the appropriate
   points.

 - Ensures that the completer finds the same breakpoint locations that
   setting a breakpoint finds.

 - Tests that linespec/location completion doesn't find data symbols.

 - Tests that expression completion still kicks in after a
   linespec/location keyword.  I.e., this:

     "b function () if global1 + global[TAB]"

   knows that after "if", you're completing on an expression, and thus
   breaks words after "if" as an expression and matches on "global" as
   a data symbol.

 - Adds common routines to help with all the above, to be used by
   multiple completion and linespec/location test cases.

 - More...

Grows the gdb.linespec/ tests like this:

  -# of expected passes           573
  +# of expected passes           3464

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

	* gdb.linespec/cpcompletion.exp: New file.
	* gdb.linespec/cpls-hyphen.cc: New file.
	* gdb.linespec/cpls.cc: New file.
	* gdb.linespec/cpls2.cc: New file.
	* gdb.linespec/explicit.exp: Load completion-support.exp.  Adjust
	test to use test_gdb_complete_unique.  Add label completion,
	keyword completion and explicit location completion tests.
	* lib/completion-support.exp: New file.
2017-11-24 23:41:12 +00:00
Pedro Alves 0662b6a7c1 Make strcmp_iw NOT ignore whitespace in the middle of tokens
currently "b func tion" manages to set a breakpoint at "function" !

All these years I had never noticed this, but now that the linespec
completer actually works, this easily happens by accident, with:

  "b func t<tab>"

expecting to get "thread", but getting instead:

  "b func tion"

...

Also, this:

  "b rettypefunc<int>"

manages to set a breakpoint on "rettype func<int>()".

These things happen due to strcmp_iw "magic".

Fix it by teaching strcmp_iw about when can it skip whitespace.  This
required handling user-defined operators, and scope operators,
complicating the code a bit, unfortunately.  I added unit tests for
all the corner cases I stumbled on, as I was developing this, and then
in the end wrote a testsuite testcase covering many of the same things
and more (to be added later).

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

	* cp-support.c (cp_symbol_name_matches_1): New, factored out from
	cp_fq_symbol_name_matches.  Pass language_cplus to
	strncmp_with_mode.
	(cp_fq_symbol_name_matches): Call cp_symbol_name_matches_1.
	(selftests::test_cp_symbol_name_cmp): New.
	(_initialize_cp_support): Register "cp_symbol_name_matches"
	selftests.
	* language.c (default_symbol_name_matcher): Pass language_minimal
	to strncmp_iw_with_mode.
	* utils.c: Include "cp-support.h" and <algorithm>.
	(valid_identifier_name_char, cp_skip_operator_token, skip_ws)
	(cp_is_operator): New functions.
	(strncmp_iw_with_mode): Use them.  Add language parameter.  Don't
	skip whitespace in the symbol name when the lookup name doesn't
	have spaces, and vice versa.
	(strncmp_iw, strcmp_iw): Pass language to strncmp_iw_with_mode.
	* utils.h (strncmp_iw_with_mode): Add language parameter.
2017-11-24 23:30:04 +00:00
Joel Brobecker e547c119d0 (Ada) provide the exception message when hitting an exception catchpoint
This patch enhances the debugger to print the exception message, when
available, as part of an exception catchpoint hit notification (both
GDB/CLI and GDB/MI). For instance, with the following code...

    procedure A is
    begin
       raise Constraint_Error with "hello world";
    end A;

... instead of printing...

    Catchpoint 1, CONSTRAINT_ERROR at 0x000000000040245c in a () at a.adb:3

... it now prints:

    Catchpoint 1, CONSTRAINT_ERROR (hello world) at 0x000000000040245c in a ()
                                   ^^^^^^^^^^^^^

This enhancement requires runtime support. If not present, the debugger
just behaves as before.

In GDB/MI mode, if the exception message is available, it is provided
as an extra field named "exception-message" in the catchpoint notification:

    *stopped,bkptno="1",[...],exception-name="CONSTRAINT_ERROR",
       exception-message="hello world",[...]

gdb/ChangeLog:

        * ada-lang.c (ada_exception_message_1, ada_exception_message):
        New functions.
        (print_it_exception): If available, display the exception
        message as well.
        * NEWS: Document new feature.

gdb/doc/ChangeLog:

        * gdb.texinfo (GDB/MI Ada Exception Information): Document
        new "exception-message" field.

gdb/testsuite/ChangeLog:

        * gdb.ada/catch_ex.exp, gdb.ada/mi_catch_ex.exp,
        gdb.ada/mi_ex_cond.exp: Accept optional exception message in
        when hitting an exception catchpoint.
2017-11-24 17:15:30 -05:00
Simon Marchi 5f1ca24acd Fix issues with gdb-memory-map.dtd
While writing a unit test for parse_memory_map, I tried to validate my
test input against gdb-memory-map.dtd, and found a few problems with it.
This doesn't influence how gdb parses it (AFAIK it doesn't use the
linked dtd), but if you edit the xml file in an editor that supports
dtds, you'll get plenty of errors.

  - The <memory-map> element accepts exactly one <memory> OR <property>
    as a child.  This is a problem because you can't have multiple
    <memory> elements and you shouldn't be able to have <property> elements
    as direct children of <memory-map>.
  - The <memory> element wants exactly one <property> child.  This is
    wrong, since you could have zero or more (even though we only
    support one kind of property currently).
  - I have no idea wht the device attribute of <memory> is, GDB doesn't
    read that.  I searched back in time a bit but couldn't find a trace
    of it.

I took the opportunity to tighten what is accepted as a value of the
memory type and property name attributes.  We currently accept any
string, but we can restrict them to the values GDB really accepts (and
which are documented).

AFAIK, this "file" only exists in the documentation, in gdb.texinfo, so
this is what I modified.  However, it's also available at
http://sourceware.org/gdb/gdb-memory-map.dtd.  This one should be
updated too, but I don't know how that should be done.

gdb/doc/ChangeLog:

	* gdb.texinfo (Memory Map Format): Update gdb-memory-map.dtd.
2017-11-24 17:14:07 -05:00
Ulrich Weigand f5291a6f32 [spu] Fix spu-linux gdbserver build
Fix a typo in a newly added argument name.

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

	* spu-low.c (spu_create_inferior): Fix typo in argument name.
2017-11-24 22:04:41 +01:00
Ulrich Weigand d7fcdff980 [spu] Fix spu-linux native build
Add missing file to NATDEPFILES.

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

	* configure.nat <spu-linux>: Add fork-inferior.o to NATDEPFILES.
2017-11-24 22:03:28 +01:00
Philipp Rudo 30649c1451 Workaround build bug with GCC 6.2.1
Building GDB with GCC 6.2.1 gives multiple errors like

gdb/dtrace-probe.c: In member function ‘void dtrace_probe::build_arg_exprs(gdbarch*)’:
gdb/dtrace-probe.c:627:8: error: types may not be defined in a for-range-declaration [-Werror]
    for (struct dtrace_probe_arg &arg : m_args

Fix it by removing the 'struct' keyword.

A similar Bug was already fixed for GCC 6.3.1
https://sourceware.org/ml/gdb-patches/2017-10/msg00442.html

gdb/ChangeLog:

	* dtrace-probe.c (dtrace_probe::build_arg_exprs)
	(dtrace_probe::is_enabled, dtrace_probe::enable)
	(dtrace_probe::disable): Remove keyword 'struct' at for-range
	variable
	* probe.c (gen_ui_out_table_header_info)
	(print_ui_out_not_applicables):  Remove keyword 'struct' at
	for-range variable
2017-11-24 11:16:37 -05:00
Alan Hayward 7696f5c957 Fix aarch64-none-elf build error
gdb/
	* configure.tgt: Add arch/aarch64.o
2017-11-24 15:56:34 +00:00
Simon Marchi 8172f16b5b Poison XNEW and friends for types that should use new/delete
This patch (finally!) makes it so that trying to use XNEW with a type
that requires "new" will cause a compilation error.  The criterion I
initially used to allow a type to use XNEW (which calls malloc in the
end) was std::is_trivially_constructible, but then realized that gcc 4.8
did not have it.  Instead, I went with:

  using IsMallocatable = std::is_pod<T>;

which is just a bit more strict, which doesn't hurt.  A similar thing is
done for macros that free instead of allocated, the criterion is:

  using IsFreeable = gdb::Or<std::is_trivially_destructible<T>, std::is_void<T>>;

Trying to use XNEW on a type that requires new will result in an error
like this:

    In file included from /home/simark/src/binutils-gdb/gdb/common/common-utils.h:26:0,
                     from /home/simark/src/binutils-gdb/gdb/common/common-defs.h:78,
                     from /home/simark/src/binutils-gdb/gdb/defs.h:28,
                     from /home/simark/src/binutils-gdb/gdb/lala.c:1:
    /home/simark/src/binutils-gdb/gdb/common/poison.h: In instantiation of ‘T* xnew() [with T = bar]’:
    /home/simark/src/binutils-gdb/gdb/lala.c:13:3:   required from here
    /home/simark/src/binutils-gdb/gdb/common/poison.h:103:3: error: static assertion failed: Trying to use XNEW with a non-POD data type.  Use operator new instead.
       static_assert (IsMallocatable<T>::value, "Trying to use XNEW with a non-POD\
       ^~~~~~~~~~~~~

Generated-code-wise, it adds one more function call (xnew<T>) when using
XNEW and building with -O0, but it all goes away with optimizations
enabled.

gdb/ChangeLog:

	* common/common-utils.h: Include poison.h.
	(xfree): Remove declaration, add definition with static_assert.
	* common/common-utils.c (xfree): Remove.
	* common/poison.h (IsMallocatable): Define.
	(IsFreeable): Define.
	(free): Delete for non-freeable types.
	(xnew): New.
	(XNEW): Undef and redefine.
	(xcnew): New.
	(XCNEW): Undef and redefine.
	(xdelete): New.
	(XDELETE): Undef and redefine.
	(xnewvec): New.
	(XNEWVEC): Undef and redefine.
	(xcnewvec): New.
	(XCNEWVEC): Undef and redefine.
	(xresizevec): New.
	(XRESIZEVEC): Undef and redefine.
	(xdeletevec): New.
	(XDELETEVEC): Undef and redefine.
	(xnewvar): New.
	(XNEWVAR): Undef and redefine.
	(xcnewvar): New.
	(XCNEWVAR): Undef and redefine.
	(xresizevar): New.
	(XRESIZEVAR): Undef and redefine.
2017-11-24 10:42:25 -05:00
Simon Marchi 7aabaf9d4a Create private_thread_info hierarchy
There are multiple definitions of the private_thread_info structure
compiled in the same GDB build.  Because of the one definition rule, we
need to change this if we want to be able to make them non-POD (e.g. use
std::vector fields).  This patch creates a class hierarchy, with
private_thread_info being an abstract base class, and all the specific
implementations inheriting from it.

In order to poison XNEW/xfree for non-POD types, it is also needed to
get rid of the xfree in thread_info::~thread_info, which operates on an
opaque type.  This is replaced by thread_info::priv now being a
unique_ptr, which calls the destructor of the private_thread_info
subclass when the thread is being destroyed.

Including gdbthread.h from darwin-nat.h gave these errors:

/Users/simark/src/binutils-gdb/gdb/gdbthread.h:609:3: error: must use 'class' tag to refer to type 'thread_info' in this scope
  thread_info *m_thread;
  ^
  class
/usr/include/mach/thread_act.h:240:15: note: class 'thread_info' is hidden by a non-type declaration of 'thread_info' here
kern_return_t thread_info
              ^

It turns out that there is a thread_info function in the Darwin/XNU/mach API:

  http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/thread_info.html

Therefore, I had to add the class keyword at a couple of places in gdbthread.h,
I don't really see a way around it.

gdb/ChangeLog:

	* gdbthread.h (private_thread_info): Define structure type, add
	virtual pure destructor.
	(thread_info) <priv>: Change type to unique_ptr.
	<private_dtor>: Remove.
	* thread.c (add_thread_with_info): Adjust to use of unique_ptr.
	(private_thread_info::~private_thread_info): Provide default
	implementation.
	(thread_info::~thread_info): Don't call private_dtor nor
	manually free priv.
	* aix-thread.c (private_thread_info): Rename to ...
	(aix_thread_info): ... this.
	(get_aix_thread_info): New.
	(sync_threadlists): Adjust.
	(iter_tid): Adjust.
	(aix_thread_resume): Adjust.
	(aix_thread_fetch_registers): Adjust.
	(aix_thread_store_registers): Adjust.
	(aix_thread_extra_thread_info): Adjust.
	* darwin-nat.h (private_thread_info): Rename to ...
	(darwin_thread_info): ... this.
	(get_darwin_thread_info): New.
	* darwin-nat.c (darwin_init_thread_list): Adjust.
	(darwin_check_new_threads): Adjust.
	(thread_info_from_private_thread_info): Adjust.
	* linux-thread-db.c (private_thread_info): Rename to ...
	(thread_db_thread_info): ... this, initialize fields.
	(get_thread_db_thread_info): New.
	<dying>: Change type to bool.
	(update_thread_state): Adjust to type rename.
	(record_thread): Adjust to type rename an use of unique_ptr.
	(thread_db_pid_to_str): Likewise.
	(thread_db_extra_thread_info): Likewise.
	(thread_db_thread_handle_to_thread_info): Likewise.
	(thread_db_get_thread_local_address): Likewise.
	* nto-tdep.h (private_thread_info): Rename to ...
	(nto_thread_info): ... this, initialize fields.
	(get_nto_thread_info): New.
	<name>: Change type to std::string.
	* nto-tdep.c (nto_extra_thread_info): Adjust to type rename and
	use of unique_ptr.
	* nto-procfs.c (update_thread_private_data_name): Adjust to
	std::string change, allocate nto_private_thread_info with new.
	(update_thread_private_data): Adjust to unique_ptr.
	* remote.c (private_thread_info): Rename to ...
	(remote_thread_info): ... this, initialize data members with
	default values.
	<extra, name>: Change type to std::string.
	<thread_handle>: Change type to non-pointer.
	(free_private_thread_info): Remove.
	(get_private_info_thread): Rename to...
	(get_remote_thread_info): ... this, change return type, adjust to
	use of unique_ptr, use remote_thread_info constructor.
	(remote_add_thread): Adjust.
	(get_private_info_ptid): Rename to...
	(get_remote_thread_info): ...this, change return type.
	(remote_thread_name): Use get_remote_thread_info, adjust to
	change to std::string.
	(struct thread_item) <~thread_item>: Remove.
	<thread_handle>: Make non pointer.
	(start_thread): Adjust to thread_item::thread_handle type
	change.
	(remote_update_thread_list): Adjust to type name change, move
	strings from temporary to long-lived object instead of
	duplicating.
	(remote_threads_extra_info): Use get_remote_thread_info.
	(process_initial_stop_replies): Likewise.
	(resume_clear_thread_private_info): Likewise.
	(remote_resume): Adjust to type name change.
	(remote_commit_resume): Use get_remote_thread_info.
	(process_stop_reply): Adjust to type name change.
	(remote_stopped_by_sw_breakpoint): Use get_remote_thread_info.
	(remote_stopped_by_hw_breakpoint): Likewise.
	(remote_stopped_by_watchpoint): Likewise.
	(remote_stopped_data_address): Likewise.
	(remote_core_of_thread): Likewise.
	(remote_thread_handle_to_thread_info): Use
	get_private_info_thread, adjust to thread_handle field type
	change.
2017-11-24 10:40:31 -05:00
Simon Marchi 21fe1c752e remote: C++ify thread_item and threads_listing_context
This patch C++ifies the thread_item and threads_listing_context
structures in remote.c.  thread_item::{extra,name} are changed to
std::string.  As a result, there's a bit of awkwardness in
remote_update_thread_list, where we have to xstrdup those strings when
filling the private_thread_info structure.  This is removed in the
following patch, where private_thread_info is also C++ified and its
corresponding fields made std::string too.  The xstrdup then becomes an
std::move.

Other than that there's nothing really special, it's a usual day-to-day
VEC -> vector and char* -> std::string change.  It allows removing a
cleanup in remote_update_thread_list.

Note that an overload of hex2bin that returns a gdb::byte_vector is
added, with corresponding selftests.

gdb/ChangeLog:

	* remote.c (struct thread_item): Add constructor, disable copy
	construction and copy assignment, define default move
	construction and move assignment.
	<extra, name>: Change type to std::string.
	<core>: Initialize.
	<thread_handle>: Make non-pointer.
	(thread_item_t): Remove typedef.
	(DEF_VEC_O(thread_item_t)): Remove.
	(threads_listing_context) <contains_thread>: New method.
	<remove_thread>: New method.
	<items>: Change type to std::vector.
	(clear_threads_listing_context): Remove.
	(threads_listing_context_remove): Remove.
	(remote_newthread_step): Use thread_item constructor, adjust to
	change to std::vector.
	(start_thread): Use thread_item constructor, adjust to change to
	std::vector.
	(end_thread): Adjust to change to std::vector and std::string.
	(remote_get_threads_with_qthreadinfo): Use thread_item
	constructor, adjust to std::vector.
	(remote_update_thread_list): Adjust to change to std::vector and
	std::string, use threads_listing_context methods.
	(remove_child_of_pending_fork): Adjust.
	(remove_new_fork_children): Adjust.
	* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add rsp-low-selftests.c.
	(SUBDIR_UNITTESTS_OBS): Add rsp-low-selftests.o.
	* unittests/rsp-low-selftests.c: New file.
	* common/rsp-low.h: Include common/byte-vector.h.
	(hex2bin): New overload.
	* common/rsp-low.c (hex2bin): New overload.
2017-11-24 10:40:15 -05:00
Simon Marchi 089354bb06 Create private_inferior class hierarchy
There are currently multiple definitions of private_inferior, defined in
remote.c and darwin-nat.h.  The patch that poisons XNEW and friends for
non-POD types trips on that, because private_inferior is freed in
~inferior(), where it is an opaque type.  Since the compiler can't tell
whether the type is POD, it gives an error.  Also, we can't start using
C++ features in these structures (make them non-POD) as long as there
are multiple definitions with the same name.  For these reasons, this
patch makes a class hierarchy, with private_inferior being the abstract
base class, and darwin_inferior & remote_inferior inheriting from it.
Destruction is done through the virtual destructor.

I stumbled on some suspicious code in the darwin implementation though.
darwin_check_new_threads does an XCNEW(darwin_thread_t) when it finds a
new thread, allocating a new structure for it (darwin_thread_t is a
typedef for private_thread_info).  It then VEC_safe_pushes it in a
vector defined as DEF_VEC_O (a vector of objects).  This means that the
structure content gets copied in the vector.  The thread_info object is
created with the XCNEW'ed structure as the private thread info, while
the rest of the code works with the instance in the vector.  We have
therefore two distinct instances of darwin_thread_t/private_thread_info
for each thread.  This is not really a problem in practice, because
thread_info::priv is not used in the darwin code.  I still find it weird
and far from ideal, so I tried to fix it by changing the vector to be a
vector of pointers.  There should now be a single instance of the
structure for each thread.  The deallocation of the
darwin_thread_t/private_thread_info structure is done by the thread_info
destructor.

I am able to build on macOS, but not really test, since the port seems a
bit broken.  I am not able to debug reliably on the machine I have
access to, which runs macOS 10.12.6.

gdb/ChangeLog:

	* inferior.h (private_inferior): Define structure type, add
	virtual pure destructor.
	(inferior) <priv>: Change type to unique_ptr.
	* inferior.c (private_inferior::~private_inferior): Provide
	default implementation.
	(inferior::~inferior): Don't free priv field.
	(exit_inferior_1): Likewise.
	* darwin-nat.h (struct darwin_exception_info): Initialize fields.
	(darwin_exception_info): Remove typedef.
	(DEF_VEC_O (darwin_thread_t)); Remove.
	(private_inferior): Rename to ...
	(darwin_private_inferior): ... this, extend private_inferior.
	(get_darwin_inferior): New.
	<threads>: Change type to std::vector of darwin_thread_t pointers.
	* darwin-nat.c (darwin_check_new_threads): Adjust.
	(find_inferior_task_it): Adjust.
	(darwin_find_thread); Adjust.
	(darwin_suspend_inferior): Adjust.
	(darwin_resume_inferior): Adjust.
	(darwin_find_new_inferior): Adjust.
	(darwin_decode_notify_message): Adjust.
	(darwin_send_reply): Adjust.
	(darwin_resume_inferior_threads): Adjust.
	(darwin_suspend_inferior_threads): Adjust.
	(darwin_decode_message): Adjust.
	(darwin_wait): Adjust.
	(darwin_interrupt): Adjust.
	(darwin_deallocate_threads): Adjust.
	(darwin_mourn_inferior): Adjust, don't free private data.
	(darwin_reply_to_all_pending_messages): Adjust.
	(darwin_stop_inferior): Adjust.
	(darwin_setup_exceptions): Adjust.
	(darwin_kill_inferior): Adjust.
	(darwin_setup_request_notification): Adjust.
	(darwin_attach_pid): Adjust.
	(darwin_init_thread_list): Adjust.
	(darwin_setup_fake_stop_event): Adjust.
	(darwin_attach): Adjust.
	(darwin_detach): Adjust.
	(darwin_xfer_partial): Adjust.
	(set_enable_mach_exceptions): Adjust.
	(darwin_pid_to_exec_file): Adjust.
	(darwin_get_ada_task_ptid): Adjust.
	* darwin-nat-info.c (get_task_from_args): Adjust.
	(info_mach_ports_command): Adjust.
	(info_mach_region_command): Adjust.
	(info_mach_exceptions_command): Adjust.
	* remote.c (private_inferior): Rename to ...
	(remote_private_inferior): ... this, initialize fields.
	(get_remote_inferior); New.
	(remote_commit_resume): Use get_remote_inferior.
	(check_pending_event_prevents_wildcard_vcont_callback): Likewise.
2017-11-24 10:39:31 -05:00
Pedro Alves d044bac8ce Document linespec/explicit locations & completion improvements (manual + NEWS)
gdb/ChangeLog:
2017-11-24  Pedro Alves  <palves@redhat.com>

	* NEWS: Mention linespecs and explicit locations, and completion
	improvements.

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

	* gdb.texinfo (Completion): Update need-quoting examples.  Remove
	false claim that GDB inserts quoting automatically.
	(Symbols): Add anchor.
2017-11-24 15:21:16 +00:00
Yao Qi e8d58cbaac Remove dead code in regcache::dump
footnote_register_size in regcache::dump is a constant zero, so the
condition check against footnote_register_size is dead code.  The code
writing to footnote_register_size was removed by 01e1877.

This patche removes footnote_register_size and the dead code.

gdb:

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

	* regcache.c (regcache::dump): Remove footnote_register_size.
2017-11-24 14:59:02 +00:00
Yao Qi a63f2d2fee cooked_read test for readonly regcache
This patch adds a test to check cooked_read for readonly regcache.  For
raw registers, cooked_read get either REG_VALID or REG_UNKNOWN, depends on
the raw register is in save_reggroup or not.  For pseudo register,
cooked_read get different result in different ports.

gdb:

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

	* regcache.c (cooked_read_test): Add more test for readonly
	regcache.
2017-11-24 13:04:30 +00:00
Yao Qi 1b30aaa566 regcache::cooked_read unit test
This patch adds a unit test to regcache::cooked_read.  This unit test is a
little different from normal unit test, it is more about conformance test
or interaction test.  This test pass both raw register number and pseudo
register number to regcache::cooked_read, in order to inspect 1) return
value of cooked_read, 2) how are target_ops to_xfer_partial,
to_{fetch,store}_registers called (because regcache is updated by means of
these three target_ops methods).  With this test here, we have a clear
picture about how each port of GDB get cooked registers.

This patch also shares some code on mock target.

gdb:

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

	* gdbarch-selftests.c (test_target_has_registers): Move it to
	target.c.
	(test_target_has_stack): Likewise.
	(test_target_has_memory): Likewise.
	(test_target_prepare_to_store): Likewise.
	(test_target_store_registers): Likewise.
	(test_target_ops): Likewise.
	* regcache.c: Include selftest-arch.h and gdbthread.h.
	(target_ops_no_register): New class.
	(test_target_fetch_registers): New.
	(test_target_store_registers): New.
	(test_target_xfer_partial): New.
	(readwrite_regcache): New.
	(cooked_read_test): New.
	(_initialize_regcache): Register the test.
	* target.c: (test_target_has_registers): Moved from
	gdbarch-selftests.c.
	(test_target_has_stack): Likewise.
	(test_target_has_memory): Likewise.
	(test_target_prepare_to_store): Likewise.
	(test_target_store_registers): Likewise.
	* target.h (test_target_ops): New class.
2017-11-24 13:04:30 +00:00
Alan Hayward 6654d750c7 Add xml selftests for aarch64 target description.
gdb/
	* aarch64-tdep.c (_initialize_aarch64_tdep): Add target desc
	selftest.

gdbserver/
	* configure.srv: Add linux-aarch64-tdesc-selftest.o.
	* linux-aarch64-low.c (initialize_low_arch): Call init func.
	* linux-aarch64-tdesc-selftest.c: New file.
	* linux-aarch64-tdesc.h (initialize_low_tdesc): New declaration.
2017-11-24 11:18:19 +00:00
Alan Hayward 49bdb7ee48 Use flexible target descriptors for aarch64
gdb/
	* aarch64-tdep.c (_initialize_aarch64_tdep): Remove init.
	* arch/aarch64.c (aarch64_create_target_description): Create
	new target description.
	* features/Makefile: Add new files.
	* features/aarch64.c: Remove file.
	* features/aarch64-core.c: New autogenerated file.
	* features/aarch64-fpu.c: New autogenerated file.
	* target-descriptions.c (maint_print_c_tdesc_cmd): Check for aarch64.

gdbserver/
	* linux-aarch64-ipa.c (initialize_low_tracepoint): Remove init.
	* linux-aarch64-low.c (initialize_low_arch): Remove init.
	* linux-aarch64-tdesc.c (aarch64_linux_read_description): Add init.
2017-11-24 11:18:19 +00:00
Alan Hayward d6d7ce5623 gdbserver: add aarch64_create_target_description
gdbserver/
	* configure.srv: Add new files.
	* linux-aarch64-ipa.c (get_ipa_tdesc): Call
	aarch64_linux_read_description.
	* linux-aarch64-low.c (aarch64_linux_read_description):
	Merge with aarch64_arch_setup.
	(aarch64_arch_setup): Call aarch64_linux_read_description.
	* linux-aarch64-tdesc.c: New file.
	* linux-aarch64-tdesc.h: New file.
2017-11-24 11:18:19 +00:00
Alan Hayward da434ccbc3 Add aarch64_create_target_description
gdb/
	* Makefile.in: Add new files.
	* aarch64-linux-nat.c (aarch64_linux_read_description): Call
	aarch64_read_description.
	* aarch64-linux-tdep.c (aarch64_linux_core_read_description):
	Call aarch64_read_description.
	* aarch64-tdep.c (aarch64_read_description): New function.
	(aarch64_gdbarch_init): Call aarch64_read_description.
	* aarch64-tdep.h (aarch64_read_description): New function.
	* arch/aarch64.c: New file.
	* configure.tgt: Add new files.
2017-11-24 11:18:19 +00:00
Yao Qi 98ead37e97 Change value_contents_eq return bool
This patch changes value_contents_eq return type from int to bool.

gdb:

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

	* mi/mi-main.c (register_changed_p): Update.
	* value.c (value_contents_bits_eq): Change return type.
	(value_contents_eq): Likewise.
	* value.h: Update comments.
2017-11-24 10:47:27 +00:00
Yao Qi 62ad7ce71b Change register_changed_p returns bool
register_changed_p actually returns bool, but return type is still int.
This patch changes the return type to bool.  The caller of
register_changed_p also checked whether the return value can be negative,
which is not needed now.  Such check was added in fb40c2090 in 2000,
at that moment, register_changed_p returns -1 when
read_relative_register_raw_bytes fails.  I can tell from its name that
it reads register contents, but we don't have this function called inside
register_changed_p, and the regcache is read-only.

gdb:

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

	* mi/mi-main.c (mi_cmd_data_list_changed_registers): Remove
	local 'changed'.  Remove error.
	(register_changed_p): Change return type to bool.
2017-11-24 10:47:27 +00:00
Yao Qi 506fe5f499 Change tic6x target descriptions
This patch changes tic6x target descriptions to be more flexible.  Rebuild
tic6x-uclinux GDBserver with my x86 g++, and the unit test passes.

gdb:

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

	* arch/tic6x.c: New file.
	* arch/tic6x.h: New file.
	* features/Makefile (FEATURE_XMLFILES): Add tic6x-c6xp.xml,
	tic6x-core.xml and tic6x-gp.xml.
	* features/tic6x-c6xp.c: Generated.
	* features/tic6x-core.c: Generated.
	* features/tic6x-gp.c: Generated.
	* target-descriptions.c (maint_print_c_tdesc_cmd): Match
	"tic6x-".

gdb/gdbserver:

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

	* configure.srv: Set $srv_regobj for tic6x-linux.
	* linux-tic6x-low.c: Include "arch/tic6x.h" and "tdesc.h".
	(tic6x_read_description): Move some code to tic6x_arch_setup.
	(tic6x_tdesc_test): New function.
	(initialize_low_arch): Call selftests::register_test.
2017-11-24 09:29:43 +00:00
Simon Marchi 00ea2e2ad3 Fix memory leak in list_available_thread_groups
Commit

  C++ify osdata
  479f8de1b3

introduced a memory leak.  We allocate std::vectors and insert them in a
map, but never free them.  Instead, the map value type can be
std::vector objects directly.

gdb/ChangeLog:

	* mi/mi-main.c (list_available_thread_groups): Change map value
	type to std::vector.
2017-11-23 21:56:19 -05:00
Simon Marchi f45e2a7704 Fix clang warnings about copy elision
When building with clang, I get:

/home/emaisin/src/binutils-gdb/gdb/osdata.c:107:9: error: moving a temporary object prevents copy elision [-Werror,-Wpessimizing-move]
                             std::move (std::string (body_text)));
                             ^
/home/emaisin/src/binutils-gdb/gdb/osdata.c:107:9: note: remove std::move call here
                             std::move (std::string (body_text)));
                             ^~~~~~~~~~~                       ~
/home/emaisin/src/binutils-gdb/gdb/osdata.c:181:10: error: moving a local object in a return statement prevents copy elision [-Werror,-Wpessimizing-move]
  return std::move (osdata);
         ^
/home/emaisin/src/binutils-gdb/gdb/osdata.c:181:10: note: remove std::move call here
  return std::move (osdata);
         ^~~~~~~~~~~      ~

Indeed, those two std::move are unnecessary.

gdb/ChangeLog:

	* osdata.c (osdata_end_column, get_osdata): Remove std::move.
2017-11-23 13:52:28 -05:00
Simon Marchi bd046f64a1 Revert unexpected rename in previous patch
While working on the previous patch, I renamed variables whose type I
changed to let the compiler help me find their usages, but I forgot to
rename one back to its original name.  This patch fixes it.

gdb/ChangeLog:

	* varobj.c (struct varobj_dynamic) <children_requested_>: Rename
	back to...
	<children_requested>: ... this.
	(varobj_get_num_children, varobj_update): Adjust.
2017-11-23 11:05:22 -05:00
Simon Marchi 4c37490d92 Change int -> bool where applicable throughout varobj
This patch changes all the "int" I could find in varobj.{c,h} that are
really boolean values to use bool.  I followed the ramifications
(parameters and return values of exported functions), so the changes
spilled a bit on other, related files (ada-varobj.c and c-varobj.c).

gdb/ChangeLog:

	* ada-varobj.c (ada_value_is_changeable_p): Change int to bool where applicable.
	(ada_value_has_mutated): Likewise.
	* c-varobj.c (varobj_is_anonymous_child): Likewise.
	(c_is_path_expr_parent): Likewise.
	* mi/mi-cmd-var.c (varobj_update_one): Likewise.
	(mi_cmd_var_set_frozen): Likewise.
	(mi_cmd_var_update_iter): Likewise.
	(mi_cmd_var_update): Likewise.
	* varobj.c (pretty_printing): Likewise.
	(varobj_enable_pretty_printing): Likewise.
	(struct varobj_root) <floating, is_valid>: Likewise.
	(struct varobj_dynamic) <children_requested>: Likewise.
	(delete_variable): Likewise.
	(delete_variable_1): Likewise.
	(install_variable): Likewise.
	(update_type_if_necessary): Likewise.
	(install_new_value): Likewise.
	(value_of_root): Likewise.
	(is_root_p): Likewise.
	(varobj_create): Likewise.
	(varobj_delete): Likewise.
	(varobj_has_more): Likewise.
	(varobj_set_frozen): Likewise.
	(varobj_get_frozen): Likewise.
	(install_dynamic_child): Likewise.
	(dynamic_varobj_has_child_method): Likewise.
	(update_dynamic_varobj_children): Likewise.
	(varobj_get_num_children): Likewise.
	(varobj_list_children): Likewise.
	(is_path_expr_parent): Likewise.
	(varobj_default_is_path_expr_parent): Likewise.
	(varobj_is_dynamic_p): Likewise.
	(varobj_set_value): Likewise.
	(varobj_value_has_mutated): Likewise.
	(varobj_update): Likewise.
	(check_scope): Likewise.
	(value_of_root_1): Likewise.
	(varobj_value_get_print_value): Likewise.
	(varobj_editable_p): Likewise.
	(varobj_value_is_changeable_p): Likewise.
	(varobj_floating_p): Likewise.
	(varobj_default_value_is_changeable_p): Likewise.
	(varobj_invalidate_iter): Likewise.
	* varobj.h (struct varobj_update_result) <type_changed,
	children_changed, changed, value_installed>: Likewise.
	(struct varobj) <updated, frozen, not_fetched>: Likewise.
	(struct lang_varobj_ops) <value_is_changeable_p,
	value_has_mutated, is_path_expr_parent>: Likewise.
	(varobj_delete): Likewise.
	(varobj_set_frozen): Likewise.
	(varobj_get_frozen): Likewise.
	(varobj_set_value): Likewise.
	(varobj_update): Likewise.
	(varobj_editable_p): Likewise.
	(varobj_floating_p): Likewise.
	(varobj_has_more): Likewise.
	(varobj_is_dynamic_p): Likewise.
	(varobj_default_value_is_changeable_p): Likewise.
	(varobj_value_is_changeable_p): Likewise.
	(varobj_is_anonymous_child): Likewise.
	(varobj_default_is_path_expr_parent): Likewise.
2017-11-23 11:00:56 -05:00
Yao Qi 7c3c1aa885 [testsuite] Pass -g3 to clang in gdb.base/macscp.exp
clang accepts option -g3 too.  I checked the manual of xlc and icc, looks
they don't accept -g3 option, so I don't pass -g3 for them.

gdb/testsuite:

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

	* gdb.base/macscp.exp: Append -g3 to additional_flags for clang.
2017-11-23 15:31:13 +00:00
Sergio Durigan Junior 9c23b42ffa Convert DTrace probe interface to C++ (and perform some cleanups)
This patch converts the DTrace probe
interface (gdb/dtrace-probe.[ch]) to C++, and also performs some
cleanups that were on my TODO list for a while.

The main changes were the conversion of 'struct dtrace_probe' to 'class
dtrace_probe', and a new 'class dtrace_static_probe_ops' to replace the
use of 'dtrace_probe_ops'.  Both classes implement the virtual methods
exported by their parents, 'class probe' and 'class static_probe_ops',
respectively.  I believe it's now a bit simpler to understand the
logic behind the dtrace-probe interface.

There are several helper functions used to parse parts of a dtrace
probe, and since they are generic and don't need to know about the
probe they're working on, I decided to leave them as simple static
functions (instead of e.g. converting them to class methods).

I've also converted a few uses of "VEC" to "std::vector", which makes
the code simpler and easier to maintain.  And, as usual, some cleanups
here and there.

Even though I'm sending a series of patches, they need to be tested
and committed as a single unit, because of inter-dependencies.  But it
should be easier to review in separate logical units.

I wasn't able to test these modifications because the current test
framework for DTrace probes is not working.  See
<https://sourceware.org/bugzilla/show_bug.cgi?id=22420>.

gdb/ChangeLog:
2017-11-22  Sergio Durigan Junior  <sergiodj@redhat.com>

	* dtrace-probe.c (struct probe_ops dtrace_probe_ops): Delete.
	(struct dtrace_probe_arg) <dtrace_probe_arg>: New constructor.
	<type_str>: Convert to 'std::string'.
	<expr>: Convert to 'expression_up'.
	(dtrace_probe_arg_s): Delete type and VEC.
	(dtrace_probe_enabler_s): Likewise.
	(struct dtrace_probe): Replace by...
	(class dtrace_static_probe_ops): ...this and...
	(class dtrace_probe): ...this.
	(dtrace_probe_is_linespec): Rename to...
	(dtrace_static_probe_ops::is_linespec): ...this.  Adjust code
	to reflect change.
	(dtrace_process_dof_probe): Use 'std::vector' instead of VEC.
	Adjust code.  Create new instance of 'dtrace_probe'.
	(dtrace_build_arg_exprs): Rename to...
	(dtrace_probe::build_arg_exprs): ...this.  Adjust code to
	reflect change.
	(dtrace_get_probes): Rename to...
	(dtrace_static_probe_ops::get_probes): ...this.  Adjust code
	to reflect change.
	(dtrace_get_arg): Rename to...
	(dtrace_probe::get_arg_by_number): ...this.  Adjust code to
	reflect change.
	(dtrace_probe_is_enabled): Rename to...
	(dtrace_probe::is_enabled): ...this.  Adjust code to reflect
	change.
	(dtrace_get_probe_address): Rename to...
	(dtrace_probe::get_relocated_address): ...this.  Adjust code
	to reflect change.
	(dtrace_get_probe_argument_count): Rename to...
	(dtrace_probe::get_argument_count): ...this.  Adjust code to
	reflect change.
	(dtrace_can_evaluate_probe_arguments): Rename to...
	(dtrace_probe::can_evaluate_arguments): ...this.  Adjust code
	to reflect change.
	(dtrace_evaluate_probe_argument): Rename to...
	(dtrace_probe::evaluate_argument): ...this.  Adjust code to
	reflect change.
	(dtrace_compile_to_ax): Rename to...
	(dtrace_probe::compile_to_ax): ...this.  Adjust code to
	reflect change.
	(dtrace_probe_destroy): Delete.
	(dtrace_type_name): Rename to...
	(dtrace_static_probe_ops::type_name): ...this.  Adjust code to
	reflect change.
	(dtrace_probe::get_static_ops): New method.
	(dtrace_gen_info_probes_table_header): Rename to...
	(dtrace_static_probe_ops::gen_info_probes_table_header):
	...this.  Adjust code to reflect change.
	(dtrace_gen_info_probes_table_values): Rename to...
	(dtrace_probe::gen_info_probes_table_values): ...this.  Adjust
	code to reflect change.
	(dtrace_enable_probe): Rename to...
	(dtrace_probe::enable_probe): ...this.  Adjust code to reflect
	change.
	(dtrace_disable_probe): Rename to...
	(dtrace_probe::disable_probe): ...this.  Adjust code to reflect
	change.
	(struct probe_ops dtrace_probe_ops): Delete.
	(info_probes_dtrace_command): Call 'info_probes_for_spops'
	instead of 'info_probes_for_ops'.
	(_initialize_dtrace_probe): Use 'all_static_probe_ops' instead
	of 'all_probe_ops'.
2017-11-22 19:13:46 -05:00
Sergio Durigan Junior 0e9ae10f5f Convert SystemTap probe interface to C++ (and perform some cleanups)
This patch converts the SystemTap probe
interface (gdb/stap-probe.[ch]) to C++, and also performs some
cleanups that were on my TODO list for a while.

The main changes were the conversion of 'struct stap_probe' to 'class
stap_probe', and a new 'class stap_static_probe_ops' to replace the
use of 'stap_probe_ops'.  Both classes implement the virtual methods
exported by their parents, 'class probe' and 'class static_probe_ops',
respectively.  I believe it's now a bit simpler to understand the
logic behind the stap-probe interface.

There are several helper functions used to parse parts of a stap
probe, and since they are generic and don't need to know about the
probe they're working on, I decided to leave them as simple static
functions (instead of e.g. converting them to class methods).

I've also converted a few uses of "VEC" to "std::vector", which makes
the code simpler and easier to maintain.  And, as usual, some cleanups
here and there.

Even though I'm sending a series of patches, they need to be tested
and committed as a single unit, because of inter-dependencies.  But it
should be easier to review in separate logical units.

I've regtested this patch on BuildBot, no regressions found.

gdb/ChangeLog:
2017-11-22  Sergio Durigan Junior  <sergiodj@redhat.com>
	    Simon Marchi  <simark@simark.ca>

	* stap-probe.c (struct probe_ops stap_probe_ops): Delete
	variable.
	(struct stap_probe_arg) <stap_probe_arg>: New constructor.
	<aexpr>: Change type to 'expression_up'.
	(stap_probe_arg_s): Delete type and VEC.
	(struct stap_probe): Delete.  Replace by...
	(class stap_static_probe_ops): ...this and...
	(class stap_probe): ...this.  Rename variables to add 'm_'
	prefix.  Do not use 'union' for arguments anymore.
	(stap_get_expected_argument_type): Receive probe name instead
	of 'struct stap_probe'.  Adjust code.
	(stap_parse_probe_arguments): Rename to...
	(stap_probe::parse_arguments): ...this.  Adjust code to
	reflect change.
	(stap_get_probe_address): Rename to...
	(stap_probe::get_relocated_address): ...this.  Adjust code
	to reflect change.
	(stap_get_probe_argument_count): Rename to...
	(stap_probe::get_argument_count): ...this.  Adjust code
	to reflect change.
	(stap_get_arg): Rename to...
	(stap_probe::get_arg_by_number'): ...this. Adjust code to
	reflect change.
	(can_evaluate_probe_arguments): Rename to...
	(stap_probe::can_evaluate_arguments): ...this.  Adjust code
	to reflect change.
	(stap_evaluate_probe_argument): Rename to...
	(stap_probe::evaluate_argument): ...this.  Adjust code
	to reflect change.
	(stap_compile_to_ax): Rename to...
	(stap_probe::compile_to_ax): ...this.  Adjust code to
	reflect change.
	(stap_probe_destroy): Delete.
	(stap_modify_semaphore): Adjust comment.
	(stap_set_semaphore): Rename to...
	(stap_probe::set_semaphore): ...this.  Adjust code to reflect
	change.
	(stap_clear_semaphore): Rename to...
	(stap_probe::clear_semaphore): ...this.  Adjust code to
	reflect	change.
	(stap_probe::get_static_ops): New method.
	(handle_stap_probe): Adjust code to create instance of
	'stap_probe'.
	(stap_get_probes): Rename to...
	(stap_static_probe_ops::get_probes): ...this.  Adjust code to
	reflect change.
	(stap_probe_is_linespec): Rename to...
	(stap_static_probe_ops::is_linespec): ...this.  Adjust code to
	reflect change.
	(stap_type_name): Rename to...
	(stap_static_probe_ops::type_name): ...this.  Adjust code to
	reflect change.
	(stap_gen_info_probes_table_header): Rename to...
	(stap_static_probe_ops::gen_info_probes_table_header):
	...this.  Adjust code to reflect change.
	(stap_gen_info_probes_table_values): Rename to...
	(stap_probe::gen_info_probes_table_values): ...this.  Adjust
	code to reflect change.
	(struct probe_ops stap_probe_ops): Delete.
	(info_probes_stap_command): Use 'info_probes_for_spops'
	instead of 'info_probes_for_ops'.
	(_initialize_stap_probe): Use 'all_static_probe_ops' instead
	of 'all_probe_ops'.
2017-11-22 19:13:45 -05:00
Sergio Durigan Junior 935676c92f Convert generic probe interface to C++ (and perform some cleanups)
This patch converts the generic probe interface (gdb/probe.[ch]) to
C++, and also performs some cleanups that were on my TODO list for a
while.

The main changes were the conversion of 'struct probe' to 'class
probe', and 'struct probe_ops' to 'class static_probe_ops'.  The
former now contains all the "dynamic", generic methods that act on a
probe + the generic data related to it; the latter encapsulates a
bunch of "static" methods that relate to the probe type, but not to a
specific probe itself.

I've had to do a few renamings (e.g., on 'struct bound_probe' the
field is called 'probe *prob' now, instead of 'struct probe *probe')
because GCC was complaining about naming the field using the same name
as the class.  Nothing major, though.  Generally speaking, the logic
behind and the design behind the code are the same.

Even though I'm sending a series of patches, they need to be tested
and committed as a single unit, because of inter-dependencies.  But it
should be easier to review in separate logical units.

I've regtested this patch on BuildBot, no regressions found.

gdb/ChangeLog:
2017-11-22  Sergio Durigan Junior  <sergiodj@redhat.com>

	* break-catch-throw.c (fetch_probe_arguments): Use
	'probe.prob' instead of 'probe.probe'.
	* breakpoint.c (create_longjmp_master_breakpoint): Call
	'can_evaluate_arguments' and 'get_relocated_address' methods
	from probe.
	(create_exception_master_breakpoint): Likewise.
	(add_location_to_breakpoint): Use 'sal->prob' instead of
	'sal->probe'.
	(bkpt_probe_insert_location): Call 'set_semaphore' method from
	probe.
	(bkpt_probe_remove_location): Likewise, for 'clear_semaphore'.
	* elfread.c (elf_get_probes): Use 'static_probe_ops' instead
	of 'probe_ops'.
	(probe_key_free): Call 'delete' on probe.
	(check_exception_resume): Use 'probe.prob' instead of
	'probe.probe'.
	* location.c (string_to_event_location_basic): Call
	'probe_linespec_to_static_ops'.
	* probe.c (class any_static_probe_ops): New class.
	(any_static_probe_ops any_static_probe_ops): New variable.
	(parse_probes_in_pspace): Receive 'static_probe_ops' as
	argument.  Adjust code to reflect change.
	(parse_probes): Use 'static_probe_ops' instead of
	'probe_ops'.  Adjust code to reflect change.
	(find_probes_in_objfile): Call methods to get name and
	provider from probe.
	(find_probe_by_pc): Use 'result.prob' instead of
	'result.probe'.  Call 'get_relocated_address' method from
	probe.
	(collect_probes): Adjust comment and argument list to receive
	'static_probe_ops' instead of 'probe_ops'.  Adjust code to
	reflect change.  Call necessary methods from probe.
	(compare_probes): Call methods to get name and provider from
	probes.
	(gen_ui_out_table_header_info): Receive 'static_probe_ops'
	instead of 'probe_ops'.  Use 'std::vector' instead of VEC,
	adjust code accordingly.
	(print_ui_out_not_applicables): Likewise.
	(info_probes_for_ops): Rename to...
	(info_probes_for_spops): ...this.  Receive 'static_probe_ops'
	as argument instead of 'probe_ops'.  Adjust code.  Call
	necessary methods from probe.
	(info_probes_command): Use 'info_probes_for_spops'.
	(enable_probes_command): Pass correct argument to
	'collect_probes'.  Call methods from probe.
	(disable_probes_command): Likewise.
	(get_probe_address): Move to 'any_static_probe_ops::get_address'.
	(get_probe_argument_count): Move to
	'any_static_probe_ops::get_argument_count'.
	(can_evaluate_probe_arguments): Move to
	'any_static_probe_ops::can_evaluate_arguments'.
	(evaluate_probe_argument): Move to
	'any_static_probe_ops::evaluate_argument'.
	(probe_safe_evaluate_at_pc): Use 'probe.prob' instead of
	'probe.probe'.
	(probe_linespec_to_ops): Rename to...
	(probe_linespec_to_static_ops): ...this.  Adjust code.
	(probe_any_is_linespec): Rename to...
	(any_static_probe_ops::is_linespec): ...this.
	(probe_any_get_probes): Rename to...
	(any_static_probe_ops::get_probes): ...this.
	(any_static_probe_ops::type_name): New method.
	(any_static_probe_ops::gen_info_probes_table_header): New
	method.
	(compute_probe_arg): Use 'pc_probe.prob' instead of
	'pc_probe.probe'.  Call methods from probe.
	(compile_probe_arg): Likewise.
	(std::vector<const probe_ops *> all_probe_ops): Delete.
	(std::vector<const static_probe_ops *> all_static_probe_ops):
	New variable.
	(_initialize_probe): Use 'all_static_probe_ops' instead of
	'all_probe_ops'.
	* probe.h (struct info_probe_column) <field_name>: Delete
	extraneous newline
	(info_probe_column_s): Delete type and VEC.
	(struct probe_ops): Delete.  Replace with...
	(class static_probe_ops): ...this and...
	(clas probe): ...this.
	(struct bound_probe) <bound_probe>: Delete extraneous
	newline.  Adjust constructor to receive 'probe' instead of
	'struct probe'.
	<probe>: Rename to...
	<prob>: ...this.  Delete extraneous newline.
	<objfile>: Delete extraneous newline.
	(register_probe_ops): Delete unused prototype.
	(info_probes_for_ops): Rename to...
	(info_probes_for_spops): ...this.  Adjust comment.
	(get_probe_address): Move to 'probe::get_address'.
	(get_probe_argument_count): Move to
	'probe::get_argument_count'.
	(can_evaluate_probe_arguments): Move to
	'probe::can_evaluate_arguments'.
	(evaluate_probe_argument): Move to 'probe::evaluate_argument'.
	* solib-svr4.c (struct svr4_info): Adjust comment.
	(struct probe_and_action) <probe>: Rename to...
	<prob>: ...this.
	(register_solib_event_probe): Receive 'probe' instead of
	'struct probe' as argument.  Use 'prob' instead of 'probe'
	when applicable.
	(solib_event_probe_action): Call 'get_argument_count' method
	from probe.  Adjust comment.
	(svr4_handle_solib_event): Adjust comment.  Call
	'evaluate_argument' method from probe.
	(svr4_create_probe_breakpoints): Call 'get_relocated_address'
	from probe.
	(svr4_create_solib_event_breakpoints): Use 'probe' instead of
	'struct probe'.  Call 'can_evaluate_arguments' from probe.
	* symfile.h: Forward declare 'class probe' instead of 'struct
	probe'.
	* symtab.h: Likewise.
	(struct symtab_and_line) <probe>: Rename to...
	<prob>: ...this.
	* tracepoint.c (start_tracing): Use 'prob' when applicable.
	Call probe methods.
	(stop_tracing): Likewise.
2017-11-22 19:13:44 -05:00
Joel Brobecker 8f6cb6c338 (Ada) ravenscar-thread.c: remove unwanted trailing \n in call to warning
A recent patch introduced a call to warning, and the string used
had a trailing newline, which is not correct; the nightly ARI run
caught it, so this patch removes it.

gdb/ChangeLog:

        * ravenscar-thread.c (ravenscar_inferior_created): Remove
        trailing newline at end of string in call to warning.

Tested on powerpc-eabispe, no regression.
2017-11-22 14:36:55 -08:00
Simon Marchi 479f8de1b3 C++ify osdata
This patch c++ifies the osdata structure: osdata_column, osdata_item and
osdata.  char* are replaced with std::string and VEC are replaced with
std::vector.  This allows to get rid of a great deal of cleanup and
free'ing code.

I replaced the splay tree in list_available_thread_groups with an
std::map.  Unless there's a good advantage to keep using a splay tree,
I think using the standard type should make things simpler to
understand.

gdb/ChangeLog:

	* osdata.h: Include vector isntead of vec.h.
	(osdata_column_s): Remove typedef.
	(struct osdata_column): Add constructor.
	<name, value>: Change type to std::string.
	(DEF_VEC_O (osdata_column_s)): Remove.
	(osdata_item_s): Remove typedef.
	(struct osdata_item) <columns>: Change type to std::vector.
	(DEF_VEC_O (osdata_item_s)): Remove.
	(struct osdata): Add constructor.
	<type>: Change type to std::string.
	<items>: Change type to std::vector.
	(osdata_p): Remove typedef.
	(DEF_VEC_P (osdata_p)): Remove.
	(osdata_parse): Return a unique_ptr.
	(osdata_free): Remove.
	(make_cleanup_osdata_free): Remove.
	(get_osdata): Return a unique_ptr.
	(get_osdata_column): Return pointer to std::string, take a
	reference to osdata_item as parameter.
	* osdata.c (struct osdata_parsing_data) <osdata>: Change type to
	unique_ptr.
	<property_name>: Change type to std::string.
	(osdata_start_osdata): Allocate osdata with new and adjust.
	(osdata_start_item): Adjust.
	(osdata_start_column): Adjust.
	(osdata_end_column): Adjust.
	(clear_parsing_data): Remove.
	(osdata_parse): Return a unique_ptr and adjust, remove cleanup.
	(osdata_item_clear): Remove.
	(get_osdata): return a unique_ptr and adjust.
	(get_osdata_column): Return a pointer to std::string and adjust.
	(info_osdata): Adjust.
	* mi/mi-main.c: Include <map>.
	(free_vector_of_osdata_items): Remove.
	(list_available_thread_groups): Adjust, use std::map instead of
	splay tree.
2017-11-22 16:12:06 -05:00
Simon Marchi 41bd68f52c Show optimized out local variables in "info locals"
Currently, optimized out variables are not shown when doing "info
locals".  Some users found that confusing, thinking GDB forgot to print
their variable.  This patch adds them to the "info locals" output.  I
added a test in gdb.dwarf2 to test for that behavior.  I think doing a
synthetic DWARF test is the easiest way to have an optimized out local
variable for sure.

However, this change reveals what I think is a bug in GDB, see:

http://lists.dwarfstd.org/pipermail/dwarf-discuss-dwarfstd.org/2017-September/004394.html

This patch marks the tests in inline-locals.exp that start failing as
KFAIL.  I'd like to tackle this bug eventually, but I don't have the
time right now.  I think it's still better to show an extra erroneous
entry than to not show the optimized out variables at all.  I haven't
created a bug in bugzilla yet, but if we agree it's indeed a bug,  I'll
create one and update the setup_kfail lines with the actual bug number
before pushing.

gdb/ChangeLog:

	* stack.c (iterate_over_block_locals): Add LOC_OPTIMIZED_OUT
	case in switch.

gdb/testsuite/ChangeLog:

	* gdb.opt/inline-locals.exp: Mark tests as KFAIL.
	* gdb.dwarf2/info-locals-optimized-out.exp: New file.
	* gdb.dwarf2/info-locals-optimized-out.c: New file.
2017-11-22 15:51:44 -05:00
Simon Marchi 7e2fd2f47b Remove DEF_VEC_P (varobj_p)
The last patch removed the last usage of this type, so we can remove it.

gdb/ChangeLog:

	* varobj.h (DEF_VEC_P (varobj_p)): Remove.
2017-11-22 15:08:07 -05:00
Simon Marchi 0604393c22 Replace VEC (varobj_update_result) with std::vector
This patch replaces makes varobj_update return an std::vector, and
updates the fallouts.

To make that easier, the varobj_update_result is c++ified a bit.  I
added a constructor and initialized its fields in-class.  The newobj
vector is also made an std::vector, so that it's automatically freed
when varobj_update_result is destroyed and handled correctly by the
default move constructor.  I disabled copy constructor and assignment
for that structure, because normally it never needs to be copied, only
moved.

As a result, the newobj parameter of update_dynamic_varobj_children must
be changed to an std::vector.  The patch converts the other vector
parameters of update_dynamic_varobj_children to std::vector.  It's not
strictly necessary to do it in the same patch, but I think it makes
sense to do it.

gdb/ChangeLog:

	* varobj.h (struct varobj_update_result): Add constructor, add
	move constructor, disable copy and assign, initialize fields.
	<newobj>: Change type to std::vector.
	(varobj_update): Return std::vector.
	* varobj.c (install_dynamic_child): Change VEC parameters to
	std::vector and adjust.
	(update_dynamic_varobj_children): Likewise.
	(varobj_update): Return std::vector and adjust.
	* mi/mi-cmd-var.c (varobj_update_one): Adjust to vector changes.
2017-11-22 15:08:06 -05:00
Simon Marchi ddf0ea085b Make varobj::children an std::vector
This patch makes the children field of varobj an std::vector, and
updates the fallout.

One note is that varobj::parent must be made non-const.  The reason is
that when a child deletes itself, it modifies its writes NULL to its
slot in its parent's children vector.  With the VEC, the const didn't
made the parent's children vector content const, only the pointer to it,
but with std::vector, even the content is.

gdb/ChangeLog:

	* varobj.h (struct varobj) <parent>: Remove const.
	<children>: Change type to std::vector.
	(varobj_list_children): Return std::vector const reference.
	(varobj_restrict_range): Change parameter type to std::vector
	const reference.
	* varobj.c (varobj_has_more): Adjust.
	(varobj_restrict_range): Change parameter type to std::vector
	const reference and adjust.
	(install_dynamic_child): Adjust.
	(update_dynamic_varobj_children): Adjust.
	(varobj_list_children): Return std::vector const reference and
	adjust.
	(varobj_add_child): Adjust.
	(update_type_if_necessary): Adjust.
	(varobj_update): Adjust.
	(delete_variable_1): Adjust.
	* ada-varobj.c (ada_value_has_mutated): Adjust.
	* mi/mi-cmd-var.c (mi_cmd_var_list_children): Adjust.
2017-11-22 15:08:06 -05:00
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