Commit Graph

38165 Commits

Author SHA1 Message Date
Andrew Burgess cad8e26d2a gdb: Use UNSUPPORTED not XFAIL for unsupported target features
If a target does not support making function calls from GDB then in a
number of test files, we currently report an XFAIL and skip some, or all
of the tests.  This commit changes the XFAIL to an UNSUPPORTED as this
seems more appropriate in these cases.

Some of the tests used bug ID 2416 to be reported in the XFAIL.  In the
current GDB bugzilla bug 2416 has nothing to do with calling target
functions from GDB.

gdb/testsuite/ChangeLog:

	* gdb.base/call-ar-st.exp: Report unsupported rather than xfail
	for unsupported target features.
	* gdb.base/call-rt-st.exp: Likewise.
	* gdb.base/call-sc.exp: Likewise.
	* gdb.base/call-signal-resume.exp: Likewise.
	* gdb.base/call-strs.exp: Likewise.
	* gdb.base/callexit.exp: Likewise.
	* gdb.base/callfuncs.exp: Likewise.
	* gdb.base/nodebug.exp: Likewise.
	* gdb.base/printcmds.exp: Likewise.
	* gdb.base/ptype.exp: Likewise.
	* gdb.base/structs.exp: Likewise.
	* gdb.base/unwindonsignal.exp: Likewise.
	* gdb.cp/gdb2495.exp: Likewise.
	* gdb.cp/templates.exp: Likewise.
	* gdb.cp/virtfunc.exp: Likewise.
	* gdb.threads/hand-call-in-threads.exp: Likewise.
	* gdb.threads/interrupted-hand-call.exp: Likewise.
	* gdb.threads/thread-unwindonsignal.exp: Likewise.
2016-06-13 15:26:26 +01:00
Nick Clifton e46dd0f46b Fix compile time warning about a redundant comparison in an assertion statement.
* gdbtypes.c (replace_type): Fix assertion.
2016-06-13 14:22:21 +01:00
Tom Tromey 695bfa52cc Constify arch_type and friends
While working on the Rust support, I happened to notice that arch_type
and related functions take "char *" arguments, where "const char *"
would be more correct.  This patch fixes this oversight.  Tested by
rebuilding.

2016-06-10  Tom Tromey  <tom@tromey.com>

	* gdbtypes.c (arch_type, arch_integer_type, arch_character_type)
	(arch_boolean_type, arch_float_type, arch_complex_type)
	(arch_flags_type, append_flags_type_field)
	(append_flags_type_flag, arch_composite_type)
	(append_composite_type_field_raw)
	(append_composite_type_field_aligned)
	(append_composite_type_field): Make "name" parameter const.
	* gdbtypes.h (arch_type, arch_integer_type, arch_character_type)
	(arch_boolean_type, arch_float_type, arch_complex_type)
	(append_composite_type_field, append_composite_type_field_aligned)
	(append_composite_type_field_raw, arch_flags_type)
	(append_flags_type_field, append_flags_type_flag): Constify.
2016-06-10 10:10:17 -06:00
Tom Tromey 347dc1025d Fix PR rust/20110
PR rust/20110 concerns the type of an integer constant that is too
large for "i32", the default integer type.  This patch changes the
type of such a constant to i64.  This is important because such values
are often addresses, so truncating them by default is unfriendly.

Built and regtested on x86-64 Fedora 23.

2016-06-10  Tom Tromey  <tom@tromey.com>

	PR rust/20110:
	* rust-exp.y (lex_number): Don't truncate large numbers to i32.

2016-06-10  Tom Tromey  <tom@tromey.com>

	PR rust/20110:
	* gdb.rust/expr.exp: Add test for integer constant larger than
	i32.
2016-06-10 09:57:09 -06:00
Tom Tromey edef7b8cf3 Fix rust-exp handling in makefile
I noticed that the rust-exp handling in the Makefile differed from
that of other .y files.  I believe I noticed this by seeing a stray
"rm" in the build log.

This patch changes the Makefile to bring the rust-exp handling in line
with that of other .y files.

2016-06-10  Tom Tromey  <tom@tromey.com>

	* Makefile.in (COMMON_OBS): Remove rust-exp.o.
	(YYFILES): Add rust-exp.c.
	(YYOBJ): Add rust-exp.o.
	(local-maintainer-clean): Remove rust-exp.c.
2016-06-10 09:57:08 -06:00
Bernhard Heckel 5e13cf2543 Fortran: Testsuite, non-local references in nested functions.
Non-local references in nested functions are usually implemented
by using DWARF static link. This feature was added
with commit 63e43d3aed
(DWARF: handle non-local references in nested functions) but
a testcase was missing in Fortran.

2016-06-10  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/Testsuite/Changelog:
	* gdb.fortran/nested-funcs.exp: New.
	* gdb.fortran/nested-funcs.f90:	New.
2016-06-10 11:16:49 +02:00
Toshihito Kikuchi bb556f1fac
Add negative repeat count to 'x' command
This change adds support for specifying a negative repeat count to
all the formats of the 'x' command to examine memory backward.
A new testcase 'examine-backward' is added to cover this new feature.

Here's the example output from the new feature:

<format 'i'>
(gdb) bt
#0  Func1 (n=42, p=0x40432e "hogehoge") at main.cpp:5
#1  0x00000000004041fa in main (argc=1, argv=0x7fffffffdff8) at main.cpp:19
(gdb) x/-4i 0x4041fa
  0x4041e5 <main(int, char**)+11>: mov   %rsi,-0x10(%rbp)
  0x4041e9 <main(int, char**)+15>: lea   0x13e(%rip),%rsi
  0x4041f0 <main(int, char**)+22>: mov   $0x2a,%edi
  0x4041f5 <main(int, char**)+27>: callq 0x404147

<format 'x'>
(gdb) x/-4xw 0x404200
0x4041f0 <main(int, char**)+22>: 0x00002abf 0xff4de800 0x76e8ffff 0xb8ffffff
(gdb) x/-4
0x4041e0 <main(int, char**)+6>:  0x7d8910ec 0x758948fc 0x358d48f0 0x0000013e

gdb/ChangeLog:

	* NEWS: Mention that GDB now supports a negative repeat count in
	the 'x' command.
	* printcmd.c (decode_format): Allow '-' in the parameter
	"string_ptr" to accept a negative repeat count.
	(find_instruction_backward): New function.
	(read_memory_backward): New function.
	(integer_is_zero): New function.
	(find_string_backward): New function.
	(do_examine): Use new functions to examine memory backward.
	(_initialize_printcmd): Mention that 'x' command supports a negative
	repeat count.

gdb/doc/ChangeLog:

	* gdb.texinfo (Examining Memory): Document negative repeat
	count in the 'x' command.

gdb/testsuite/ChangeLog:

	* gdb.base/examine-backward.c: New file.
	* gdb.base/examine-backward.exp: New file.
2016-06-09 22:50:47 -07:00
Toshihito Kikuchi c040f3fb55
Add myself as a write-after-approval GDB maintainer
gdb/ChangeLog:

	* MAINTAINERS (Write After Approval): Add Toshihito Kikuchi.
2016-06-09 22:01:38 -07:00
Tom Tromey 4dee35314b PR python/19819 - remove unused globals from py-xmethods.c
PR python/19819 concerns some unused global variables in
py-xmethods.c.  This patch deletes the unused globals.

Tested by rebuilding.

2016-06-09  Tom Tromey  <tom@tromey.com>

	PR python/19819:
	* python/py-xmethods.c (invoke_method_name)
	(py_get_result_type_method_name, py_invoke_method_name): Remove.
	(gdbpy_initialize_xmethods): Don't initialize
	py_invoke_method_name, py_get_result_type_method_name.
2016-06-09 14:29:21 -06:00
Simon Marchi 1aec0b6ad6 mi/mi-interp.c: Add missing braces
gdb/ChangeLog:

	* mi/mi-interp.c (mi_record_changed): Add missing braces.
2016-06-07 11:46:25 -04:00
Bernhard Heckel 2091da296f Frame static link: Handle null pointer.
2016-06-07  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/Changelog:
	* findvar.c (follow_static_link): Check for valid pointer.
2016-06-07 13:36:05 +02:00
Simon Marchi 38b022b445 Add method/format information to =record-started
Eclipse CDT now supports enabling execution recording using two methods
(full and btrace) and both formats for btrace (bts and pt).  In the
event that recording is enabled behind the back of the GUI (by the user
on the command line, or a script), we need to know which method/format
are being used, so it can be correctly reflected in the interface.  This
patch adds this information to the =record-started async record.

Before:

  =record-started,thread-group="i1"

After:

  =record-started,thread-group="i1",method="btrace",format="bts"
  =record-started,thread-group="i1",method="btrace",format="pt"
  =record-started,thread-group="i1",method="full"

The "format" field is only present when the current method supports
multiple formats (only the btrace method as of now).

gdb/ChangeLog:

	* NEWS: Mention the new fields in =record-started.
	* common/btrace-common.h (btrace_format_short_string): New function
	declaration.
	* common/btrace-common.c (btrace_format_short_string): New
	function.
	* mi/mi-interp.c (mi_record_changed): Output method and format
	fields in the =record-started record.
	* record-btrace.c (record_btrace_open): Adapt record_changed
	notification.
	* record-full.c (record_full_open): Likewise.
	* record.c (cmd_record_stop): Likewise.

gdb/doc/ChangeLog:

	* gdb.texinfo (GDB/MI Async Records): Document method and
	format fields in =record-started.
	* observer.texi (record_changed): Add method and format
	parameters.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-record-changed.exp: Adjust =record-started output
	matching.
2016-06-06 17:10:18 -04:00
Jon Turney 0ae534d2cf Fix C++ build for Cygwin
gdb/ChangeLog:

2016-06-02  Jon Turney  <jon.turney@dronecode.org.uk>

	* windows-nat.c (handle_output_debug_string): Return type of
	gdb_signal_from_host() is gdb_signal, not an int.
	(windows_get_exec_module_filename): Add pointer casts for C++.

gdb/gdbserver/ChangeLog:

2016-06-02  Jon Turney  <jon.turney@dronecode.org.uk>

	* win32-low.c (win32_create_inferior): Add pointer casts for C++.
2016-06-03 11:29:25 +00:00
Tom Tromey 1b40ec0559 Fix PR python/18984
This fixes PR python/18984.

The bug is that gdbpy_solib_name uses GDB_PY_LL_ARG, whereas it should
use GDB_PY_LLU_ARG to avoid overflow.

Built and tested on x86-64 Fedora 23.

2016-06-02  Tom Tromey  <tom@tromey.com>

	PR python/18984:
	* python/python.c (gdbpy_solib_name): Use GDB_PY_LLU_ARG.

2016-06-02  Tom Tromey  <tom@tromey.com>

	PR python/18984:
	* gdb.python/py-shared.exp: Add solib_name test.
2016-06-02 13:18:42 -06:00
Simon Marchi 193bd37899 mi-memory-changed.exp: Fix filename passed to untested
gdb/testsuite/ChangeLog:

	* gdb.mi/mi-memory-changed.exp: Fix filename passed to untested.
2016-06-02 10:08:28 -04:00
Pedro Alves bb7c96deb1 gdb/remote-fileio.c: Eliminate custom SIGINT signal handler
... and fix Ctrl-C races.

The current remote-fileio.c SIGINT/EINTR code can lose Ctrl-C --
there's a period where SIG_IGN is installed as signal handler, for
example.

Since:

 - remote.c no longer installs a custom SIGINT handler;

 - The current remote-fileio.c SIGINT handler is basically the same as
   the default SIGINT handler (event-top.c:handle_sigint), in
   principle, except that instead of setting the quit flag, it sets a
   separate flag.

I think we should be able to completely remove the remote-fileio.c
SIGINT handler, and centralize on the quit flag, thus fixing the
Ctrl-C race.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* remote-fileio.c (remote_fio_ctrl_c_flag, remote_fio_sa)
	(remote_fio_osa)
	(remote_fio_ofunc, remote_fileio_sig_init, remote_fileio_sig_set)
	(remote_fileio_sig_exit, remote_fileio_ctrl_c_signal_handler):
	Delete.
	(remote_fileio_o_quit_handler): New global.
	(remote_fileio_quit_handler): New function.
	(remote_fileio_reply): Check the quit flag instead of the custom
	'remote_fio_ctrl_c_flag' flag.  Restore the quit handler instead
	of changing the SIGINT handler.
	(do_remote_fileio_request): Override the quit handler instead of
	changing the SIGINT handler.
2016-06-01 16:34:49 +01:00
Nick Clifton 51403f74d9 Add xmalloc_failed() function to common-utils.c in to avoid the need to link in libiberty's xmalloc code. 2016-06-01 11:44:08 +01:00
Markus Metzger e3b5daf9f7 infcmd, btrace: fix crash in 'finish' for tailcall-only frames
Patch 7eb895307f Skip unwritable frames in command "finish"
skips non-writable frames in addition to tailcall frames.

If skip_tailcall_frames already returns NULL, skip_unwritable_frames
will be called with a NULL frame and crash in get_frame_arch.  This is
caught by gdb.btrace/tailcall-only.exp.

Further, if we ever end up with a mixture of tailcall and non-writable
frames, we may not skip all of them, as intended.

Loop over skip_tailcall_frames and skip_unwritable_frames as long as at least
one of them makes progress.

gdb/
	* infcmd.c (skip_finish_frames): New.
	(finish_command): Call skip_finish_frames.
2016-06-01 11:14:02 +02:00
Yao Qi 03d73f1fd9 Wake up interruptible_select in remote_fileio ctrl-c handler
As reported in PR 19998, after type ctrl-c, GDB hang there and does
not send interrupt.  It causes a fail in gdb.base/interrupt.exp.
All targets support remote fileio should be affected.

When we type ctrc-c, SIGINT is handled by remote_fileio_sig_set,
as shown below,

 #0  remote_fileio_sig_set (sigint_func=0x4495d0 <remote_fileio_ctrl_c_signal_handler(int)>) at /home/yao/SourceCode/gnu/gdb/git/gdb/remote-fileio.c:325
 #1  0x00000000004495de in remote_fileio_ctrl_c_signal_handler (signo=<optimised out>) at /home/yao/SourceCode/gnu/gdb/git/gdb/remote-fileio.c:349
 #2  <signal handler called>
 #3  0x00007ffff647ed83 in __select_nocancel () at ../sysdeps/unix/syscall-template.S:81
 #4  0x00000000005530ce in interruptible_select (n=10, readfds=readfds@entry=0x7fffffffd730, writefds=writefds@entry=0x0, exceptfds=exceptfds@entry=0x0,
    timeout=timeout@entry=0x0) at /home/yao/SourceCode/gnu/gdb/git/gdb/event-top.c:1017
 #5  0x000000000061ab20 in stdio_file_read (file=<optimised out>, buf=0x12d02e0 "\n\022-\001", length_buf=16383)
    at /home/yao/SourceCode/gnu/gdb/git/gdb/ui-file.c:577
 #6  0x000000000044a4dc in remote_fileio_func_read (buf=0x12c0360 "") at /home/yao/SourceCode/gnu/gdb/git/gdb/remote-fileio.c:583
 #7  0x0000000000449598 in do_remote_fileio_request (uiout=<optimised out>, buf_arg=buf_arg@entry=0x12c0340)
    at /home/yao/SourceCode/gnu/gdb/git/gdb/remote-fileio.c:1179

we don't set quit_serial_event,

  do
    {
      res = gdb_select (n, readfds, writefds, exceptfds, timeout);
    }
  while (res == -1 && errno == EINTR);

  if (res == 1 && FD_ISSET (fd, readfds))
    {
      errno = EINTR;
      return -1;
    }
  return res;

we can't go out of the loop above, and that is why GDB can't send
interrupt.

Recently, we stop throwing exception from SIGINT handler
(remote_fileio_ctrl_c_signal_handler)
https://sourceware.org/ml/gdb-patches/2016-03/msg00372.html, which
is correct, because gdb_select is interruptible.  However, in the
same patch series, we add interruptible_select later as a wrapper
to gdb_select, https://sourceware.org/ml/gdb-patches/2016-03/msg00375.html
and it is not interruptible (because of the loop in it) unless
select/poll-able file descriptors are marked.

This fix in this patch is to call quit_serial_event_set, so that we can
go out of the loop above, return -1 and set errno to EINTR.

2016-06-01  Yao Qi  <yao.qi@linaro.org>

	PR remote/19998
	* remote-fileio.c (remote_fileio_ctrl_c_signal_handler): Call
	quit_serial_event_set.
2016-06-01 09:33:40 +01:00
Joel Brobecker c799dec78a Document the GDB 7.11.1 release in gdb/ChangeLog
gdb/ChangeLog:

	GDB 7.11.1 released.
2016-05-31 17:49:49 -07:00
Martin Galvan 3326303bf5 [PR gdb/19893] Fix handling of synthetic C++ references
https://sourceware.org/bugzilla/show_bug.cgi?id=19893

I've traced the main source of the problem to pieced_value_funcs.coerce_ref not being
implemented. Since gdb always assumes references are implemented as pointers, this
causes it to think that it's dealing with a NULL pointer, thus breaking any operations
involving synthetic references.

What I did here was implementing pieced_value_funcs.coerce_ref using some of the synthetic
pointer handling code from indirect_pieced_value, as Pedro suggested. I also made a few
adjustments to the reference printing code so that it correctly shows either the address
of the referenced value or (if it's non-addressable) the "<synthetic pointer>" string.

I also wrote some unit tests based on Dwarf::assemble; these took a while to make
because in most cases I needed a synthetic reference to a physical variable. Additionally,
I started working on a unit test for classes that have a vtable, but ran into a few issues
so that'll probably go in a future patch. One thing that should definitely be fixed is that
proc function_range (called for MACRO_AT_func) will always try to compile/link using gcc
with the default options instead of g++, thus breaking C++ compilations that require e.g. libstdc++.

gdb/ChangeLog:

	* dwarf2loc.c (coerce_pieced_ref, indirect_synthetic_pointer,
	fetch_const_value_from_synthetic_pointer): New functions.
	(indirect_pieced_value): Move lower half to indirect_synthetic_pointer.
	(pieced_value_funcs): Implement coerce_ref.
	* valops.c (value_addr): Call coerce_ref for synthetic references.
	* valprint.c (valprint_check_validity): Return true for synthetic
	references.  Also, don't show "<synthetic pointer>" if they reference
	addressable values.
	(generic_val_print_ref): Handle synthetic references.  Also move some
	code to print_ref_address.
	(print_ref_address, get_value_addr_contents): New functions.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/implref.exp: Rename to...
	* gdb.dwarf2/implref-const.exp: ...this.  Also add more test statements.
	* gdb.dwarf2/implref-array.c: New file.
	* gdb.dwarf2/implref-array.exp: Likewise.
	* gdb.dwarf2/implref-global.c: Likewise.
	* gdb.dwarf2/implref-global.exp: Likewise.
	* gdb.dwarf2/implref-struct.c: Likewise.
	* gdb.dwarf2/implref-struct.exp: Likewise.
2016-05-31 15:56:34 -03:00
Antoine Tremblay 825c8ef28f Add tests for 64bit values in trace-condition.exp
This patch adds tests for emit operations with 64 bit values. It takes
special care to avoid mistakes that one could make on a 32bit architecture
using 64bit values.

gdb/testsuite/ChangeLog:

	* gdb.trace/trace-condition.exp: Add 64bit tests.
2016-05-30 12:51:13 -04:00
Antoine Tremblay 2320162a62 Add variable length tests for emit_ref in trace-condition.exp
This patch add variable length tests for emit_ref by reading the variable
passed as argument of 8 to 64 bit.

gdb/testsuite/ChangeLog:

	* gdb.trace/trace-condition.c (marker): Adapt signature to 8 to 64
	bits types.
	(main): Adapt to 8 to 64 bits types.
	* gdb.trace/trace-condition.exp: Add new tests.
2016-05-30 12:51:13 -04:00
Antoine Tremblay a781823347 Add emit_less_unsigned test in trace-condition.exp
This patch adds coverage for emit_less_unsigned.

gdb/testsuite/ChangeLog:

	* gdb.trace/trace-condition.exp: Add emit_less_unsigned test.
2016-05-30 12:51:13 -04:00
Antoine Tremblay 0d33646690 Move trace conditions tests from ftrace.exp to trace-condition.exp
This patch moves conditional tests that were done in ftrace.exp to
trace-condition.exp.

Note that emit_ref is now tested by the anarg local variable there is no
need to test the register directly.

All emit calls have been tested using asserts before / after the move, to
ensure that the tests cover the same functions.

Note that these function were not covered before and are still not:
emit_gt_goto, emit_lt_goto, emit_pop, emit_unsigned_less.

gdb/testsuite/ChangeLog:

	* gdb.trace/ftrace.exp (test_ftrace_condition): Remove.
	Move condition tests...
	* gdb.trace/trace-condition.exp: Here.
2016-05-30 12:51:13 -04:00
Antoine Tremblay 7faeb45ae3 Add counter-cases for trace-condition.exp tests
In trace-condition.exp, tests are done by doing a conditional tracepoint
and validating that the trace contains all the frames that could be
collected if that condition is true.

E.g. test_tracepoints $trace_command "21 + 21 == 42" 10

This will always return true and collect the 10 frames possible to collect
with the test program.

However, if the condition evaluation is broken such that the condition is
unconditional we will not notice this problem.

This patch adds counter-cases to such conditions like so:

$trace_command "21 + 11 == 42" 0

This way such a problem would be noticed.

gdb/testsuite/ChangeLog:

	* gdb.trace/trace-condition.exp: Add counter-case tests.
2016-05-30 12:51:13 -04:00
Jan Kratochvil e385593eef PR 15231: import bare DW_TAG_lexical_block
Local variables in lambdas are not accessible
https://sourceware.org/bugzilla/show_bug.cgi?id=15231

GDB: read_lexical_block_scope
  /* Ignore blocks with missing or invalid low and high pc attributes.  */
[...]
  if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
    return;

But sometimes there is:

FAIL: gcc-5.3.1-6.fc23.x86_64
 <2><92>: Abbrev Number: 11 (DW_TAG_lexical_block)
 <3><9c>: Abbrev Number: 13 (DW_TAG_structure_type)
    <9d>   DW_AT_name        : (indirect string, offset: 0x3c): <lambda()>
    [...]

Where DW_TAG_lexical_block has no attributes.  Such whole subtree is currently
dropped by GDB while I think it should just import all its children DIEs.

It even XFAIL->XPASSes gdb.ada/out_of_line_in_inlined.exp:
	commit 0fa7fe506c
	Author: Joel Brobecker <brobecker@adacore.com>
	    out of line functions nested inside inline functions.
So I have removed that xfail.

gdb/ChangeLog
2016-05-30  Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR c++/15231
	* dwarf2read.c (enum pc_bounds_kind): Add PC_BOUNDS_INVALID.
	(process_psymtab_comp_unit_reader, read_func_scope): Adjust callers.
	(read_lexical_block_scope): Import DIEs from bare DW_TAG_lexical_block.
	(read_call_site_scope): Adjust callers.
	(dwarf2_get_pc_bounds): Implement pc_bounds_invalid.
	(dwarf2_get_subprogram_pc_bounds, get_scope_pc_bounds): Adjust callers.

gdb/testsuite/ChangeLog
2016-05-30  Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR c++/15231
	* gdb.ada/out_of_line_in_inlined.exp: Remove xfails.
	* gdb.dwarf2/dw2-lexical-block-bare.exp: New file.
2016-05-30 14:14:43 +02:00
Jan Kratochvil 3a2b436ae9 Code cleanup: dwarf2_get_pc_bounds: -1/0/+1 -> enum
Make the code (maybe) more readable + primarily prepare it for [patch 2/2]
enum extension.

This change should have no code change impact.

gdb/ChangeLog
2016-05-30  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Code cleanup: dwarf2_get_pc_bounds: -1/0/+1 -> enum
	* dwarf2read.c (enum pc_bounds_kind) New.
	(dwarf2_get_pc_bounds): Use it in the declaration.
	(process_psymtab_comp_unit_reader): Adjust caller.  Rename has_pc_info
	to cu_bounds_kind.
	(read_func_scope, read_lexical_block_scope, read_call_site_scope):
	Adjust callers.
	(dwarf2_get_pc_bounds): Use enum pc_bounds_kind in the definition.
	(dwarf2_get_subprogram_pc_bounds, get_scope_pc_bounds): Adjust callers.
2016-05-30 14:11:43 +02:00
Jan Kratochvil aab3c527d7 NEWS: QCatchSyscalls: simplify
Standardize the QCatchSyscalls NEWS entry.

gdb/ChangeLog
2016-05-29  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* NEWS (QCatchSyscalls): Remove the parameter.  Include ...
	(QCatchSyscalls:1 in qSupported) ... this separate entry which got
	deleted.
2016-05-29 20:45:42 +02:00
Jan Kratochvil c64e0f6165 NEWS: Remove empty line.
gdb/ChangeLog
2016-05-29  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* NEWS (N stop reply): Remove empty line.
2016-05-29 18:42:15 +02:00
Alan Modra 1a72702bb3 Return void from linker callbacks
The ldmain.c implementation of these linker callback functions always
return true, so any code handling a false return is dead.  What's
more, some of the bfd backends abort if ever a false return is seen,
and there seems to be some confusion in gdb's compile-object-load.c.
The return value was never meant to be "oh yes, a multiple_definition
error occurred", but rather "out of memory or other catastrophic
failure".

This patch removes the status return on the callbacks that always
return true.  I kept the return status for "notice" because that one
does happen to need to return "out of memory".

include/
	* bfdlink.h (struct bfd_link_callbacks): Update comments.
	Return void from multiple_definition, multiple_common,
	add_to_set, constructor, warning, undefined_symbol,
	reloc_overflow, reloc_dangerous and unattached_reloc.
bfd/
	* aoutx.h: Adjust linker callback calls throughout file,
	removing dead code.
	* bout.c: Likewise.
	* coff-alpha.c: Likewise.
	* coff-arm.c: Likewise.
	* coff-h8300.c: Likewise.
	* coff-h8500.c: Likewise.
	* coff-i960.c: Likewise.
	* coff-mcore.c: Likewise.
	* coff-mips.c: Likewise.
	* coff-ppc.c: Likewise.
	* coff-rs6000.c: Likewise.
	* coff-sh.c: Likewise.
	* coff-tic80.c: Likewise.
	* coff-w65.c: Likewise.
	* coff-z80.c: Likewise.
	* coff-z8k.c: Likewise.
	* coff64-rs6000.c: Likewise.
	* cofflink.c: Likewise.
	* ecoff.c: Likewise.
	* elf-bfd.h: Likewise.
	* elf-m10200.c: Likewise.
	* elf-m10300.c: Likewise.
	* elf32-arc.c: Likewise.
	* elf32-arm.c: Likewise.
	* elf32-avr.c: Likewise.
	* elf32-bfin.c: Likewise.
	* elf32-cr16.c: Likewise.
	* elf32-cr16c.c: Likewise.
	* elf32-cris.c: Likewise.
	* elf32-crx.c: Likewise.
	* elf32-d10v.c: Likewise.
	* elf32-epiphany.c: Likewise.
	* elf32-fr30.c: Likewise.
	* elf32-frv.c: Likewise.
	* elf32-ft32.c: Likewise.
	* elf32-h8300.c: Likewise.
	* elf32-hppa.c: Likewise.
	* elf32-i370.c: Likewise.
	* elf32-i386.c: Likewise.
	* elf32-i860.c: Likewise.
	* elf32-ip2k.c: Likewise.
	* elf32-iq2000.c: Likewise.
	* elf32-lm32.c: Likewise.
	* elf32-m32c.c: Likewise.
	* elf32-m32r.c: Likewise.
	* elf32-m68hc1x.c: Likewise.
	* elf32-m68k.c: Likewise.
	* elf32-mep.c: Likewise.
	* elf32-metag.c: Likewise.
	* elf32-microblaze.c: Likewise.
	* elf32-moxie.c: Likewise.
	* elf32-msp430.c: Likewise.
	* elf32-mt.c: Likewise.
	* elf32-nds32.c: Likewise.
	* elf32-nios2.c: Likewise.
	* elf32-or1k.c: Likewise.
	* elf32-ppc.c: Likewise.
	* elf32-s390.c: Likewise.
	* elf32-score.c: Likewise.
	* elf32-score7.c: Likewise.
	* elf32-sh.c: Likewise.
	* elf32-sh64.c: Likewise.
	* elf32-spu.c: Likewise.
	* elf32-tic6x.c: Likewise.
	* elf32-tilepro.c: Likewise.
	* elf32-v850.c: Likewise.
	* elf32-vax.c: Likewise.
	* elf32-visium.c: Likewise.
	* elf32-xstormy16.c: Likewise.
	* elf32-xtensa.c: Likewise.
	* elf64-alpha.c: Likewise.
	* elf64-hppa.c: Likewise.
	* elf64-ia64-vms.c: Likewise.
	* elf64-mmix.c: Likewise.
	* elf64-ppc.c: Likewise.
	* elf64-s390.c: Likewise.
	* elf64-sh64.c: Likewise.
	* elf64-x86-64.c: Likewise.
	* elflink.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elfnn-ia64.c: Likewise.
	* elfxx-mips.c: Likewise.
	* elfxx-sparc.c: Likewise.
	* elfxx-tilegx.c: Likewise.
	* linker.c: Likewise.
	* pdp11.c: Likewise.
	* pe-mips.c: Likewise.
	* reloc.c: Likewise.
	* reloc16.c: Likewise.
	* simple.c: Likewise.
	* vms-alpha.c: Likewise.
	* xcofflink.c: Likewise.
	* elf32-rl78.c (get_symbol_value, get_romstart, get_ramstart): Delete
	status param.  Adjust calls to these and linker callbacks throughout.
	* elf32-rx.c: (get_symbol_value, get_gp, get_romstart,
	get_ramstart): Delete status param.  Adjust calls to these and
	linker callbacks throughout.
ld/
	* ldmain.c (multiple_definition, multiple_common, add_to_set,
	constructor_callback, warning_callback, undefined_symbol,
	reloc_overflow, reloc_dangerous, unattached_reloc): Return void.
	* emultempl/elf32.em: Adjust callback calls.
gdb/
	* compile/compile-object-load.c (link_callbacks_multiple_definition,
	link_callbacks_warning, link_callbacks_undefined_symbol,
	link_callbacks_undefined_symbol, link_callbacks_reloc_overflow,
	link_callbacks_reloc_dangerous,
	link_callbacks_unattached_reloc): Return void.
2016-05-28 11:17:20 +09:30
Pedro Alves 744608cc85 Skip attach-many-short-lived-threads.exp on known-broken DejaGnu versions
If the testsuite is run with a DejaGnu version that predates the fix
from last year:

  [PATCH] DejaGnu kills the wrong process due to PID-reuse races
  http://lists.gnu.org/archive/html/dejagnu/2015-07/msg00005.html

... gdb.threads/attach-many-short-lived-threads.exp fails randomly,
often.  Other tests randomly fail due to that issue too, but this one
is _much_ more exposed.

DejaGnu 1.6 was released meanwhile, which includes that DejaGnu fix,
and also some distros backported the fix too.

So skip the test when run with older/broken DejaGnus.

gdb/testsuite/ChangeLog:
2016-05-27  Pedro Alves  <palves@redhat.com>

	* gdb.threads/attach-many-short-lived-threads.exp (bad_dejagnu):
	New procedure.
	(top level): Call it, and bail out of DejaGnu is known to be bad.
2016-05-27 16:18:28 +01:00
Eli Zaretskii c185ba27ca Improve documentation of general query packets
gdb/doc/ChangeLog:

	* gdb.texinfo (General Query Packets): Move the description of the
	response before the long list of the specific 'read' and 'write'
	requests.
2016-05-27 16:59:22 +03:00
Andrew Burgess 51415b9f30 gdb: Forward VALUE_LVAL when avoiding side effects for STRUCTOP_STRUCT
When evaluating an expression with EVAL_AVOID_SIDE_EFFECTS if the value
we return is forced to be of type not_lval then GDB will be unable to
take the address of the returned value.

Instead, we should properly initialise the LVAL of the returned value.

This commit builds on two previous commits 2520f728b7 (Forward
VALUE_LVAL when avoiding side effects for STRUCTOP_STRUCT) and
ac775bf4d3 (gdb: Forward VALUE_LVAL when avoiding side effects for
STRUCTOP_PTR), which in turn build on ac1ca910d7 (Fixes for PR
exp/15364).

This commit is currently untested due to my lack of access to an OpenCL
compiler, however, if follows the same pattern as the first two commits
mentioned above and so I believe that it is correct.

gdb/ChangeLog:

	* opencl-lang.c (evaluate_subexp_opencl): If
	EVAL_AVOID_SIDE_EFFECTS mode, forward the VALUE_LVAL attribute to
	the returned value in the STRUCTOP_STRUCT case.
2016-05-27 13:07:15 +01:00
Andrew Burgess ac775bf4d3 gdb: Forward VALUE_LVAL when avoiding side effects for STRUCTOP_PTR
Assume that we have a C program like this:

  struct foo_type
  {
    int var;
  } foo;

  struct foo_type *foo_ptr = &foo;

  int
  main ()
  {
    return foo_ptr->var;
  }

Then GDB should be able to evaluate the following, however, it currently
does not:

  (gdb) start
  ...
  (gdb) whatis &(foo_ptr->var)
  Attempt to take address of value not located in memory.

The problem is that in EVAL_AVOID_SIDE_EFFECTS mode,
eval.c:evaluate_subexp_standard always returns a not_lval value as the
result for a STRUCTOP_PTR operation. As a consequence, the rest of
the code believes that one cannot take the address of the returned
value.

This patch fixes STRUCTOP_PTR handling so that the VALUE_LVAL
attribute for the returned value is properly initialized.  After this
change, the above session becomes:

  (gdb) start
  ...
  (gdb) whatis &(foo_ptr->var)
  type = int *

This commit is largely the same as commit 2520f728b7 (Forward
VALUE_LVAL when avoiding side effects for STRUCTOP_STRUCT) but applied
to STRUCTOP_PTR rather than STRUCTOP_STRUCT.  Both of these commits are
building on top of commit ac1ca910d7 (Fixes for PR exp/15364).

gdb/ChangeLog:

	* eval.c (evaluate_subexp_standard): If EVAL_AVOID_SIDE_EFFECTS
	mode, forward the VALUE_LVAL attribute to the returned value in
	the STRUCTOP_PTR case.

gdb/testsuite/ChangeLog:

	* gdb.base/whatis.c: Extend the test case.
	* gdb.base/whatis.exp: Add additional tests.
2016-05-27 13:06:25 +01:00
Tom Tromey 7bd787e877 fix spelling of HAVE_LIBPYTHON2_4 in py-value.c
Ulrich pointed out that an earlier patch had misspelled
HAVE_LIBPYTHON2_4, adding an extra "_".  This caused a build failure.
This patch fixes the bug.

2016-05-25  Tom Tromey  <tom@tromey.com>

	* python/py-value.c (value_object_as_number): Use correct spelling
	of HAVE_LIBPYTHON2_4.
2016-05-25 07:54:44 -06:00
Bernhard Heckel 2bbad2ea11 Fortran, typeprint: Forward level of details to be printed for pointers.
Variable "show" was hardcoded to zero for pointer and reference types.
This implementation didn't allow a correct "whatis" print
for those types and results in same output for "ptype" and "whatis".

Before:
(gdb) whatis t3p
type = PTR TO -> ( Type t3
    integer(kind=4) :: t3_i
    Type t2 :: t2_n
End Type t3 )

After:
(gdb) whatis t3p
type = PTR TO -> ( Type t3 )

2016-05-25  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/Changelog:
	* f-typeprint.c (f_type_print_base): Replace 0 by show.

gdb/testsuite/Changelog:
	* gdb.fortran/type.f90: Add pointer variable.
	* gdb.fortran/whatis_type.exp: Add whatis/ptype of pointers.
2016-05-25 08:47:18 +02:00
Bernhard Heckel 8b70175dfa Fortran, testsuite: Fix duplicate testcase name.
2016-05-25  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/testsuite/Changelog:
	* gdb.fortran/vla-type.exp: Fix testcase name.
2016-05-25 08:47:18 +02:00
Bernhard Heckel 86d8a84882 Fortran, testsuite: Add testcases for nested structures.
As as result of printing only the outer elements of nested structures,
some testcases have to be added to check for corner cases with VLA's.

2016-05-25  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/testsuite/Changelog:
	* gdb.fortran/vla-type.exp: Access elements in nested structs.
2016-05-25 08:47:18 +02:00
Bernhard Heckel e188eb3621 Fortran, typeprint: Decrease level of details when printing elements of a structure.
According to the typeprint's description, the level of details is
decreased by one for the typeprint of elements of a structure.

Before:
(gdb) ptype t3v
type = Type t3
    integer(kind=4) :: t3_i
    Type t2
        integer(kind=4) :: t2_i
        Type t1
            integer(kind=4) :: t1_i
            real(kind=4) :: t1_r
        End Type t1 :: t1_n
    End Type t2 :: t2_n
End Type t3

After:
(gdb) ptype t3v
type = Type t3
    integer(kind=4) :: t3_i
    Type t2 :: t2_n
End Type t3

2016-05-25  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/Changelog:
	* f-typeprint.c (f_type_print_base): Decrease show by one.

gdb/testsuite/Changelog:
	* gdb.fortran/type.f90: Add nested structures.
	* gdb.fortran/whatis-type.exp: Whatis/ptype nested structures.
	* gdb.fortran/derived-type.exp: Adapt expected output.
	* gdb.fortran/vla-type.exp: Adapt expected output.
2016-05-25 08:47:17 +02:00
Bernhard Heckel 9b2db1fd27 Fortran, typeprint: Take level of details into account when printing elements of a structure.
According to the typeprint's description, elements of a structure
should not be printed when show is < 1.
This variable is also used to distinguish the level of details
between "ptype" and "whatis" expressions.

Before:
(gdb) whatis t1v
type = Type t1
    integer(kind=4) :: t1_i
    real(kind=4) :: t1_r
End Type t1

After:
(gdb) whatis t1v
type = Type t1

2016-05-25  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/Changelog:
	* f-typeprint.c (f_type_print_base): Don't print fields when show < 0.

gdb/testsuite/Changelog:
	* gdb.fortran/whatis_type.exp: Adapt expected output.
2016-05-25 08:47:17 +02:00
Bernhard Heckel 72b1705502 Fortran, typeprint: Fix wrong indentation when ptype nested structures.
Level of indentation was not proper handled when printing
the elements type's name.

Before:
type = Type t1
integer(kind=4) :: var_1
integer(kind=4) :: var_2
End Type t1

After:
type = Type t1
    integer(kind=4) :: var_1
    integer(kind=4) :: var_2
End Type t1

2016-05-25  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/Changelog:
	* f-typeprint.c (f_type_print_base): Take print level into account.

gdb/testsuite/Changelog:
	* gdb.fortran/print_type.exp: Fix expected output.
	* gdb.fortran/whatis_type.exp: Fix expected output.
2016-05-25 08:47:16 +02:00
Bernhard Heckel 3cd81d8df7 Fortran, testsuite: Use multi_line in whatis_type testcase.
2016-05-25  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/testsuite/Changelog:
	* gdb.fortran/whatis_type.exp: Use multi_line.
2016-05-25 08:47:16 +02:00
Tom Tromey ddae946278 Fix PR python/17386 - add __index__ method to gdb.Value
This patch fixes PR python/17386.

The bug is that gdb.Value does not implement the Python __index__
method.  This method is needed to convert a Python object to an index
and is used by various operations in Python, such as indexing an
array.

The fix is to implement the nb_index method for gdb.Value.

nb_index was added in Python 2.5.  I don't have a good way to test
Python 2.4, but I made an attempt to accomodate it.

I chose to use valpy_long in all cases because this simplifies porting
to Python 3, and because there didn't seem to be any harm.

Built and regtested on x86-64 Fedora 23.

2016-05-24  Tom Tromey  <tom@tromey.com>

	PR python/17386:
	* python/py-value.c (value_object_as_number): Add
	nb_inplace_floor_divide, nb_inplace_true_divide, nb_index.

2016-05-24  Tom Tromey  <tom@tromey.com>

	PR python/17386:
	* gdb.python/py-value.exp (test_value_numeric_ops): Add tests that
	use value as an index.
2016-05-24 10:05:59 -06:00
Tom Tromey e2b7f516fc add nb_inplace_divide for python 2
Python 2's PyNumberMethods has nb_inplace_divide, but Python 3 does
not.  This patch adds it for Python 2.

This buglet didn't cause much fallout because the only non-NULL entry
in value_object_as_number after this is for valpy_divide; and the
missing slot caused it to slide up to nb_floor_divide (where
nb_true_divide was intended).

2016-05-24  Tom Tromey  <tom@tromey.com>

	* python/py-value.c (value_object_as_number): Add
	nb_inplace_divide for Python 2.
2016-05-24 10:05:58 -06:00
Tom Tromey 1957f6b89f Fix PR python/17981
PR python/17981 notes that gdb.breakpoints() returns None when there
are no breakpoints; whereas an empty list or tuple would be more in
keeping with Python and the documentation.

This patch fixes the bug by changing the no-breakpoint return to make
an empty tuple.

Built and regtested on x86-64 Fedora 23.

2016-05-23  Tom Tromey  <tom@tromey.com>

	PR python/17981:
	* python/py-breakpoint.c (gdbpy_breakpoints): Return a new tuple
	when there are no breakpoints.

2016-05-23  Tom Tromey  <tom@tromey.com>

	* python.texi (Basic Python): Document gdb.breakpoints return.

2016-05-23  Tom Tromey  <tom@tromey.com>

	PR python/17981:
	* gdb.python/py-breakpoint.exp (test_bkpt_basic): Add test for
	no-breakpoint case.
2016-05-24 09:55:01 -06:00
Tom Tromey 224f10c1ae PR gdb/19194 - fix typo in the manual
PR gdb/19194 points out a typo in the documentation.  I'm checking
this in as obvious.

2016-05-24  Tom Tromey  <tom@tromey.com>

	PR gdb/19194:
	* gdb.texinfo (gdb man): Fix typo.
2016-05-24 09:41:39 -06:00
Pedro Alves 026a917475 Fix PR gdb/19828: gdb -p <process from a container>: internal error
When GDB attaches to a process, it looks at the /proc/PID/task/ dir
for all clone threads of that process, and attaches to each of them.

Usually, if there is more than one clone thread, it means the program
is multi threaded and linked with pthreads.  Thus when GDB soon after
attaching finds and loads a libthread_db matching the process, it'll
add a thread to the thread list for each of the initially found
lower-level LWPs.

If, however, GDB fails to find/load a matching libthread_db, nothing
is adding the LWPs to the thread list.  And because of that, "detach"
hits an internal error:

  (gdb) PASS: gdb.threads/clone-attach-detach.exp: fg attach 1: attach
  info threads
    Id   Target Id         Frame
  * 1    LWP 6891 "clone-attach-de" 0x00007f87e5fd0790 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:84
  (gdb) FAIL: gdb.threads/clone-attach-detach.exp: fg attach 1: info threads shows two LWPs
  detach
  .../src/gdb/thread.c:1010: internal-error: is_executing: Assertion `tp' failed.
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.
  Quit this debugging session? (y or n)
  FAIL: gdb.threads/clone-attach-detach.exp: fg attach 1: detach (GDB internal error)

From here:

  ...
  #8  0x00000000007ba7cc in internal_error (file=0x98ea68 ".../src/gdb/thread.c", line=1010, fmt=0x98ea30 "%s: Assertion `%s' failed.")
      at .../src/gdb/common/errors.c:55
  #9  0x000000000064bb83 in is_executing (ptid=...) at .../src/gdb/thread.c:1010
  #10 0x00000000004c23bb in get_pending_status (lp=0x12c5cc0, status=0x7fffffffdc0c) at .../src/gdb/linux-nat.c:1235
  #11 0x00000000004c2738 in detach_callback (lp=0x12c5cc0, data=0x0) at .../src/gdb/linux-nat.c:1317
  #12 0x00000000004c1a2a in iterate_over_lwps (filter=..., callback=0x4c2599 <detach_callback>, data=0x0) at .../src/gdb/linux-nat.c:899
  #13 0x00000000004c295c in linux_nat_detach (ops=0xe7bd30, args=0x0, from_tty=1) at .../src/gdb/linux-nat.c:1358
  #14 0x000000000068284d in delegate_detach (self=0xe7bd30, arg1=0x0, arg2=1) at .../src/gdb/target-delegates.c:34
  #15 0x0000000000694141 in target_detach (args=0x0, from_tty=1) at .../src/gdb/target.c:2241
  #16 0x0000000000630582 in detach_command (args=0x0, from_tty=1) at .../src/gdb/infcmd.c:2975
  ...

Tested on x86-64 Fedora 23.  Also confirmed the test passes against
gdbserver with "maint set target-non-stop".

gdb/ChangeLog:
2016-05-24  Pedro Alves  <palves@redhat.com>

	PR gdb/19828
	* linux-nat.c (attach_proc_task_lwp_callback): Mark the lwp
	resumed, and add the thread to GDB's thread list.

testsuite/ChangeLog:
2016-05-24  Pedro Alves  <palves@redhat.com>

	PR gdb/19828
	* gdb.threads/clone-attach-detach.c: New file.
	* gdb.threads/clone-attach-detach.exp: New file.
2016-05-24 14:51:32 +01:00
Pedro Alves 72b049d38c Make gdb/linux-nat.c consider a waitstatus pending on the infrun side
Working on the fix for gdb/19828, I saw
gdb.threads/attach-many-short-lived-threads.exp fail once in an
unusual way.  Unfortunately I didn't keep debug logs, but it's an
issue similar to what's been fixed in remote.c a while ago --
linux-nat.c was not fetching the pending status from the right place.

gdb/ChangeLog:
2016-05-24  Pedro Alves  <palves@redhat.com>

	PR gdb/19828
	* linux-nat.c (get_pending_status): If the thread reported the
	event to the core and it's pending, use the pending status signal
	number.
2016-05-24 14:51:03 +01:00
Pedro Alves 774113b02f [Linux] Optimize PID -> struct lwp_info lookup
Hacking the gdb.threads/attach-many-short-lived-threads.exp test to
spawn thousands of threads instead of dozens, and running gdb under
perf, I saw that GDB was spending most of the time in find_lwp_pid:

   - captured_main
      - 93.61% catch_command_errors
         - 87.41% attach_command
            - 87.40% linux_nat_attach
               - 87.40% linux_proc_attach_tgid_threads
                  - 82.38% attach_proc_task_lwp_callback
                     - 81.01% find_lwp_pid
                          5.30% ptid_get_lwp
                        + 0.10% ptid_lwp_p
                     + 0.64% add_thread
                     + 0.26% set_running
                     + 0.24% set_executing
                       0.12% ptid_get_lwp
                     + 0.01% ptrace
                     + 0.01% add_lwp

attach_proc_task_lwp_callback is called once for each LWP that we
attach to, found by listing the /proc/PID/task/ directory.  In turn,
attach_proc_task_lwp_callback calls find_lwp_pid to check whether the
LWP we're about to try to attach to is already known.  Since
find_lwp_pid does a linear walk over the whole LWP list, this becomes
quadratic.  We do the /proc/PID/task/ listing until we get two
iterations in a row where we found no new threads.  So the second and
following times we walk the /proc/PID/task/ dir, we're going to take
an even worse find_lwp_pid hit.

Fix this by adding a hash table keyed by LWP PID, for fast lookup.

The linked list embedded in the LWP structure itself is kept, and made
a double-linked list, so that removals from that list are O(1).  An
earlier version of this patch got rid of this list altogether, but
that revealed hidden dependencies / assumptions on how the list is
sorted.  For example, killing a process and then waiting for all the
LWPs status using iterate_over_lwps only works as is because the
leader LWP is always last in the list.  So I thought it better to take
an incremental approach and make this patch concern itself _only_ with
the PID lookup optimization.

gdb/ChangeLog:
2016-05-24  Pedro Alves  <palves@redhat.com>

	PR gdb/19828
	* linux-nat.c (lwp_lwpid_htab): New htab.
	(lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create)
	(lwp_lwpid_htab_add_lwp): New functions.
	(lwp_list): Tweak comment.
	(lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New
	functions.
	(purge_lwp_list): Rewrite, using htab_traverse_noresize.
	(add_initial_lwp): Add lwp to htab too.  Use lwp_list_add.
	(delete_lwp): Use lwp_list_remove.  Remove htab too.
	(find_lwp_pid): Search in htab.
	(_initialize_linux_nat): Call lwp_lwpid_htab_create.
	* linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 14:50:37 +01:00
Pedro Alves 1ad3de988d [Linux] Avoid refetching core-of-thread if thread hasn't run
Hacking the gdb.threads/attach-many-short-lived-threads.exp test to
spawn thousands of threads instead of dozens, I saw GDB having trouble
keeping up with threads being spawned too fast, when it tried to stop
them all.  This was because while gdb is doing that, it updates the
thread list to make sure no new thread has sneaked in that might need
to be paused.  It does this a few times until it sees no-new-threads
twice in a row.  The thread listing update itself is not that
expensive, however, in the Linux backend, updating the threads list
calls linux_common_core_of_thread for each LWP to record on which core
each LWP was last seen running, which opens/reads/closes a /proc file
for each LWP which becomes expensive when you need to do it for
thousands of LWPs.

perf shows gdb in linux_common_core_of_thread 44% of the time, in the
stop_all_threads -> update_thread_list path in this use case.

This patch simply makes linux_common_core_of_thread avoid updating the
core the thread is bound to if the thread hasn't run since the last
time we updated that info.  This makes linux_common_core_of_thread
disappear into the noise in the perf report.

gdb/ChangeLog:
2016-05-24  Pedro Alves  <palves@redhat.com>

	PR gdb/19828
	* linux-nat.c (linux_resume_one_lwp_throw): Clear the LWP's core
	field.
	(linux_nat_update_thread_list): Don't fetch the core if already
	known.
2016-05-24 14:48:57 +01:00
Pedro Alves 95e94c3f18 [Linux] Read vDSO range from /proc/PID/task/PID/maps instead of /proc/PID/maps
... as it's _much_ faster.

Hacking the gdb.threads/attach-many-short-lived-threads.exp test to
spawn thousands of threads instead of dozens to stress and debug
timeout problems with gdb.threads/attach-many-short-lived-threads.exp,
I saw that GDB would spend several seconds just reading the
/proc/PID/smaps file, to determine the vDSO mapping range.  GDB opens
and reads the whole file just once, and caches the result, but even
that is too slow.  For example, with almost 8000 threads:

 $ ls /proc/3518/task/ | wc -l
 7906

reading the /proc/PID/smaps file grepping for "vdso" takes over 15
seconds :

 $ time cat /proc/3518/smaps | grep vdso
 7ffdbafee000-7ffdbaff0000 r-xp 00000000 00:00 0                          [vdso]

 real    0m15.371s
 user    0m0.008s
 sys     0m15.017s

Looking around the web for hints, I found a nice description of the
issue here:

 http://backtrace.io/blog/blog/2014/11/12/large-thread-counts-and-slow-process-maps/

The problem is that /proc/PID/smaps wants to show the mappings as
being thread stack, and that has the kernel iterating over all threads
in the thread group, for each mapping.

The fix is to use the "map" file under /proc/PID/task/PID/ instead of
the /proc/PID/ one, as the former doesn't mark thread stacks for all
threads.

That alone drops the timing to the millisecond range on my machine:

 $ time cat /proc/3518/task/3518/smaps | grep vdso
 7ffdbafee000-7ffdbaff0000 r-xp 00000000 00:00 0                          [vdso]

 real    0m0.150s
 user    0m0.009s
 sys     0m0.084s

And since we only need the vdso mapping's address range, we can use
"maps" file instead of "smaps", and it's even cheaper:

/proc/PID/task/PID/maps :

 $ time cat /proc/3518/task/3518/maps | grep vdso
 7ffdbafee000-7ffdbaff0000 r-xp 00000000 00:00 0                          [vdso]

 real    0m0.027s
 user    0m0.000s
 sys     0m0.017s

gdb/ChangeLog:
2016-05-24  Pedro Alves  <palves@redhat.com>

	PR gdb/19828
	* linux-tdep.c (find_mapping_size): Delete.
	(linux_vsyscall_range_raw): Rewrite reading from
	/proc/PID/task/PID/maps directly instead of using
	gdbarch_find_memory_regions.
2016-05-24 14:48:34 +01:00
Pedro Alves aa01bd3689 Linux native thread create/exit events support
A following patch (fix for gdb/19828) makes linux-nat.c add threads to
GDB's thread list earlier in the "attach" sequence, and that causes a
surprising regression on
gdb.threads/attach-many-short-lived-threads.exp on my machine.  The
extra "thread x exited" handling and traffic slows down that test
enough that GDB core has trouble keeping up with new threads that are
spawned while trying to stop existing ones.

I saw the exact same issue with remote/gdbserver a while ago and fixed
it in 65706a29ba (Remote thread create/exit events) so part of the
fix here is the exact same -- add support for thread created events to
gdb/linux-nat.c.  infrun.c:stop_all_threads enables those events when
it tries to stop threads, which ensures that new threads never get a
chance to themselves start new threads, thus fixing the race.

gdb/
2016-05-24  Pedro Alves  <palves@redhat.com>

	PR gdb/19828
	* linux-nat.c (report_thread_events): New global.
	(linux_handle_extended_wait): Report
	TARGET_WAITKIND_THREAD_CREATED if thread event reporting is
	enabled.
	(wait_lwp, linux_nat_filter_event): Report all thread exits if
	thread event reporting is enabled.  Remove comment.
	(filter_exit_event): New function.
	(linux_nat_wait_1): Use it.
	(linux_nat_thread_events): New function.
	(linux_nat_add_target): Install it as target_thread_events method.
2016-05-24 14:47:56 +01:00
Francis Ricci e70a7231e6 Fix syntax error in annota-input-while-running.exp
This patch fixes a syntax error which caused a failure in
annota-input-while-running.exp to crash the test suite runner.

2016-05-24  Francis Ricci  <francisjricci@gmail.com>

	* gdb.base/annota-input-while-running.exp: Fix syntax error.
2016-05-24 12:11:38 +01:00
Yan-Ting Lin 00a3cb9c7c Add myself as a write-after-approval GDB maintainer
gdb/ChangeLog:

	* MAINTAINERS (Write After Approval): Add "Yan-Ting Lin".
2016-05-24 16:47:14 +08:00
Yao Qi 7eb895307f Skip unwritable frames in command "finish"
Nowadays, GDB can't insert breakpoint on the return address of the
exception handler on ARM M-profile, because the address is a magic
one 0xfffffff9,

 (gdb) bt
 #0  CT32B1_IRQHandler () at ../src/timer.c:67
 #1  <signal handler called>
 #2  main () at ../src/timer.c:127

(gdb) info frame
Stack level 0, frame at 0x200ffa8:
 pc = 0x4ec in CT32B1_IRQHandler (../src/timer.c:67); saved pc = 0xfffffff9
 called by frame at 0x200ffc8
 source language c.
 Arglist at 0x200ffa0, args:
 Locals at 0x200ffa0, Previous frame's sp is 0x200ffa8
 Saved registers:
  r7 at 0x200ffa0, lr at 0x200ffa4

(gdb) x/x 0xfffffff9
0xfffffff9:     Cannot access memory at address 0xfffffff9

(gdb) finish
Run till exit from #0  CT32B1_IRQHandler () at ../src/timer.c:67
Ed:15: Target error from Set break/watch: Et:96: Pseudo-address (0xFFFFFFxx) for EXC_RETURN is invalid (GDB error?)

Warning:
Cannot insert hardware breakpoint 0.
Could not insert hardware breakpoints:
You may have requested too many hardware breakpoints/watchpoints.

Command aborted.

even some debug probe can't set hardware breakpoint on the magic
address too,

(gdb) hbreak *0xfffffff9
Hardware assisted breakpoint 2 at 0xfffffff9
(gdb) c
Continuing.
Ed:15: Target error from Set break/watch: Et:96: Pseudo-address (0xFFFFFFxx) for EXC_RETURN is invalid (GDB error?)

Warning:
Cannot insert hardware breakpoint 2.
Could not insert hardware breakpoints:
You may have requested too many hardware breakpoints/watchpoints.

Command aborted.

The problem described above is quite similar to PR 8841, in which GDB
can't set breakpoint on signal trampoline, which is mapped to a read-only
page by kernel.  The rationale of this patch is to skip "unwritable"
frames when looking for caller frames in command "finish", and a new
gdbarch method code_of_frame_writable is added.  This patch fixes
the problem on ARM cortex-m target, but it can be used to fix
PR 8841 too.

gdb:

2016-05-10  Yao Qi  <yao.qi@arm.com>

	* arch-utils.c (default_code_of_frame_writable): New function.
	* arch-utils.h (default_code_of_frame_writable): Declare.
	* arm-tdep.c (arm_code_of_frame_writable): New function.
	(arm_gdbarch_init): Install gdbarch method
	code_of_frame_writable if the target is M-profile.
	* frame.c (skip_unwritable_frames): New function.
	* frame.h (skip_unwritable_frames): Declare.
	* gdbarch.sh (code_of_frame_writable): New.
	* gdbarch.c, gdbarch.h: Re-generated.
	* infcmd.c (finish_command): Call skip_unwritable_frames.
2016-05-23 17:32:56 +01:00
Tom Tromey 0f6ed0e0ef Fix PR python/19438, PR python/18393 - initialize dictionaries
This fixes PR python/19438 and PR python/18393.  Both bugs are about
invoking dir() on some Python object implemented by gdb, and getting a
crash.

The crash happens because the dictionary field of these objects was
not initialized.  Apparently what happens is that this field can be
lazily initialized by Python when assigning to an attribute; and it
can also be handled ok when using dir() but without __dict__ defined;
but gdb defines __dict__ because this isn't supplied automatically by
Python.

The docs on this seem rather sparse, but this patch works ok.

An alternative might be to lazily create the dictionary in
gdb_py_generic_dict, but I went with this approach because it seemed
more straightforward.

Built and regtested on x86-64 Fedora 23.

2016-05-23  Tom Tromey  <tom@tromey.com>

	PR python/19438, PR python/18393:
	* python/py-objfile.c (objfpy_initialize): Initialize self->dict.
	* python/py-progspace.c (pspy_initialize): Initialize self->dict.

2016-05-23  Tom Tromey  <tom@tromey.com>

	PR python/19438, PR python/18393:
	* gdb.python/py-progspace.exp: Add "dir" test.
	* gdb.python/py-objfile.exp: Add "dir" test.
2016-05-23 10:08:34 -06:00
Yao Qi ffd19d610b Use standard_testfile in gdb.arch/thumb-prologue.exp and gdb.arch/thumb2-it.exp
This patch fixes the errors below:

Running /home/yao/SourceCode/gnu/gdb/git/gdb/testsuite/gdb.arch/thumb-prologue.exp ...
gdb compile failed, arm-linux-gnueabihf/bin/ld: cannot open output file /scratch/yao/gdb/build-git/arm-linux-gnueabihf/gdb/testsuite/gdb.arch/thumb-prologue: No such file or directory
collect2: error: ld returned 1 exit status
Running /home/yao/SourceCode/gnu/gdb/git/gdb/testsuite/gdb.arch/thumb2-it.exp ...
gdb compile failed, arm-linux-gnueabihf/bin/ld: cannot open output file /scratch/yao/gdb/build-git/arm-linux-gnueabihf/gdb/testsuite/gdb.arch/thumb2-it: No such file or directory

gdb/testsuite:

2016-05-23  Yao Qi  <yao.qi@linaro.org>

	* gdb.arch/thumb-prologue.exp: Use standard_testfile.
	* gdb.arch/thumb2-it.exp: Likewise.
2016-05-23 15:50:56 +01:00
Gary Benson d0571b9934 Remove unused libthread_db td_thr_validate reference
Native GDB looks up the function td_thr_validate from libthread_db.so
on Linux, but the value is never used.  This commit removes this dead
code.

gdb/ChangeLog:

	* nat/gdb_thread_db.h (td_thr_validate_ftype): Remove typedef.
	* linux-thread-db.c (struct thread_db_info) <td_thr_validate_p>:
	Remove field.
	(try_thread_db_load_1): Remove td_thr_validate initialization.
2016-05-23 13:26:47 +01:00
Jon Boden 37773e7803 Search for libutil-freebsd as alternative to libutil
GDB needs kinfo_getvmmap() on GNU/kFreeBSD systems same as on
pure FreeBSD.  However on these systems the FreeBSD version of libutil
is renamed to libutil-freebsd.

2016-05-23  Jon Boden  <jon@ubuntubsd.org>

	* configure.ac: Search for libutil-freebsd as alternative to libutil.
	* configure: Re-generated.
2016-05-23 08:46:33 +01:00
Andreas Schwab bfb0d950a5 Fix invalid implicit conversions from void *
* ia64-libunwind-tdep.c (libunwind_descr): Add cast from void *.
	(libunwind_frame_set_descr): Likewise.
	(libunwind_frame_cache): Likewise.
	(libunwind_frame_dealloc_cache): Likewise.
	(libunwind_frame_sniffer): Likewise.
	(libunwind_search_unwind_table): Likewise.
	(libunwind_sigtramp_frame_sniffer): Likewise.
	(libunwind_get_reg_special): Likewise.
	(libunwind_load): Likewise.
	* ia64-linux-nat.c (ia64_linux_fetch_register): Likewise.
	(ia64_linux_store_register): Likewise.
	(ia64_linux_xfer_partial): Likewise.
	* ia64-tdep.c (ia64_access_reg): Likewise.
	(ia64_access_fpreg): Likewise.
	(ia64_access_rse_reg): Likewise.
	(ia64_access_rse_fpreg): Likewise.
2016-05-19 15:31:56 +02:00
Tom Tromey 45f4ed92d1 Fix build failure with GCC 4.1.
2016-05-18  Tom Tromey  <tom@tromey.com>

	* rust-lang.c (rust_subscript): Initialize "high".
2016-05-18 11:15:31 -06:00
Simon Marchi 9e8f9b05ad Add mi-threads-interrupt.exp test (PR 20039)
Add a new test for PR 20039.  The test spawns new threads, then tries to
interrupt, continue, and interrupt again.  This use case was fixed by
commit 5fe966540d in master, but gdb 7.11
is affected (so if you try it on the gdb-7.11-branch right now, the test
will fail).

New in v2, the test now handles mi-async on mode properly.  The failure
was specific to mi-async off, but I don't think it's bad to test the
same thing under async on mode.  I added a little hack when running in
async mode to work around bug 20045.

I also removed one continue/interrupt pair, as a single one was enough to
trigger the problem.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-threads-interrupt.c: New file.
	* gdb.mi/mi-threads-interrupt.exp: New file.
2016-05-18 10:13:16 -04:00
Simon Marchi 28addb40c7 Fix double prompt output after run control MI commands with mi-async on (PR 20045)
When you use a run control command (-exec-run, -exec-continue,
-exec-next, ...) with mi-async on, an extra (gdb) prompt is displayed:

  -exec-continue
  ^running
  *running,thread-id="all"
  (gdb)
  (gdb)

It doesn't seem to be a big problem for front-ends, since this behavior
started in gdb 7.9 and we haven't heard anything about that.  However,
it caused me some trouble while writing a test for PR 20039 [1].

The problem comes from an extra (gdb) prompt that we write when running
in mi-async off mode to emulate a past buggy behavior.  When executing a
run control command synchronously, previous gdbs always printed a prompt
right away, even though they are not ready to accept new MI commands
until the target stops.  Only at this time should they display a prompt.
But to keep backwards compatibility apparently, we print it anyway.
Since commit 198297aaf, the condition that decides whether we should
print that "bogus" prompt or not has become true, even when running with
mi-async on.  Since we already print a prompt at the end of the
asynchronous command execution, it results in two prompts for one
command.

The proposed fix is to call target_can_async_p instead of
target_is_async_p, to make the condition:

  if (!target_can_async_p () || sync_execution)
    ... show prompt ...

That shows the prompt if we are emulating a synchronous command on top
of an asynchronous target (sync_execution) or if the target simply can't
run asynchronously (!target_can_async_p ()).

Note that this code is changed and this bug fixed by Pedro's separate
console series, but I think it would be nice to have it fixed in the
mean time.

I ran the gdb.mi directory of the testsuite with mi-async on and off, I
didn't see any regressions.

gdb/ChangeLog:

	* mi/mi-main.c (mi_on_resume): Call target_can_async_p instead
	of target_is_async_p.

[1] https://sourceware.org/ml/gdb-patches/2016-05/msg00075.html
2016-05-18 10:12:54 -04:00
Simon Marchi 61c6156df6 Fix -exec-run not running asynchronously with mi-async on (PR gdb/18077)
When doing -exec-run on a freshly started GDB, the only target on the
target stack at the time the dummy one.  When mi_async_p is called to
know whether the run should be async, it queries whether the current
target (dummy) supports async, and the answer is no.  The fix is to make
the code query the target that will be used for the run, which is not
necessarily the current target.

No regressions in the gdb.mi directory using the unix, native-gdbserver
and native-extended-gdbserver boards.  The test doesn't pass when
forcing maint set target-async off, obviously, since it makes mi-async
have no effect.  It doesn't seem like other tests are checking for that
eventuality, so I didn't in the new test.

gdb/ChangeLog:

	* mi/mi-main.c (run_one_inferior): Use run target to determine
	whether to run async or not.
	(mi_cmd_exec_run): Likewise.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-async-run.exp: New file.
	* gdb.mi/mi-async-run.c: New file.
2016-05-17 16:46:18 -04:00
Tom Tromey 01739a3b6a Rename OP_F90_RANGE to OP_RANGE.
This renames OP_F90_RANGE to OP_RANGE, and similarly renames the
f90_range_type enum.

2016-05-17  Tom Tromey  <tom@tromey.com>

	* std-operator.def (OP_RANGE): Rename from OP_F90_RANGE.
	* rust-lang.c: Don't include f-lang.h.
	(rust_range, rust_compute_range, rust_subscript)
	(rust_evaluate_subexp): Update.
	* rust-exp.y: Don't include f-lang.h.
	(ast_range, convert_ast_to_expression): Update.
	* parse.c (operator_length_standard): Update.
	* f-lang.h (enum f90_range_type): Move to expression.h.
	* f-exp.y: Use OP_RANGE.
	* expression.h (enum range_type): New enum; renamed from
	f90_range_type.
	* expprint.c: Don't include f-lang.h.
	(print_subexp_standard, dump_subexp_body_standard): Use OP_RANGE.
	* eval.c (value_f90_subarray, evaluate_subexp_standard): Update.
2016-05-17 12:02:03 -06:00
Tom Tromey 0bdfa368bc Add Rust documentation
This patch adds documentation for the new Rust support in gdb.

2016-05-17  Tom Tromey  <tom@tromey.com>

	* NEWS: Add Rust item.

2016-05-17  Tom Tromey  <tom@tromey.com>

	* gdb.texinfo (Supported Languages): Mention Rust.  Update menu.
	(Rust): New node.
2016-05-17 12:02:02 -06:00
Tom Tromey 67218854b1 Update gdb test suite for Rust
This updates the gdb test suite for Rust.

2016-05-17  Tom Tromey  <tom@tromey.com>
	    Manish Goregaokar <manishsmail@gmail.com>

	* lib/rust-support.exp: New file.
	* lib/gdb.exp (skip_rust_tests): New proc.
	(build_executable_from_specs): Handle rust.
	* lib/future.exp (gdb_find_rustc): New proc.
	(gdb_default_target_compile): Handle rust.
	* gdb.rust/expr.exp: New file.
	* gdb.rust/generics.exp: New file.
	* gdb.rust/generics.rs: New file.
	* gdb.rust/methods.exp: New file.
	* gdb.rust/methods.rs: New file.
	* gdb.rust/modules.exp: New file.
	* gdb.rust/modules.rs: New file.
	* gdb.rust/simple.exp: New file.
	* gdb.rust/simple.rs: New file.
2016-05-17 12:02:01 -06:00
Tom Tromey c44af4ebc0 Add support for the Rust language
This patch adds support for the Rust language.

2016-05-17  Tom Tromey  <tom@tromey.com>
	    Manish Goregaokar <manishsmail@gmail.com>

	* symtab.c (symbol_find_demangled_name): Handle Rust.
	* symfile.c (init_filename_language_table): Treat ".rs" as Rust.
	* std-operator.def (STRUCTOP_ANONYMOUS, OP_RUST_ARRAY): New
	constants.
	* rust-lang.h: New file.
	* rust-lang.c: New file.
	* rust-exp.y: New file.
	* dwarf2read.c (read_file_scope): Add Rust producer sniffing.
	(dwarf2_compute_name, read_func_scope, read_structure_type)
	(read_base_type, read_subrange_type, set_cu_language)
	(new_symbol_full, determine_prefix): Handle Rust.
	* defs.h (enum language) <language_rust>: New constant.
	* Makefile.in (SFILES): Add rust-exp.y, rust-lang.c.
	(COMMON_OBS): Add rust-exp.o, rust-lang.o.

2016-05-17  Tom Tromey  <tom@tromey.com>

	* gdb.base/default.exp (set language): Add rust.
2016-05-17 12:02:00 -06:00
Tom Tromey 00272ec4b0 Add array start and end strings to generic_val_print_decorations
For Rust value-printing, I wanted to use generic_val_print_array, but
I also wanted to control the starting and ending strings.

This patch adds new strings to generic_val_print_decorations, updates
generic_val_print_array to use them, and updates all the existing
instances of generic_val_print_decorations.

2016-05-17  Tom Tromey  <tom@tromey.com>

	* valprint.h (struct generic_val_print_array) <array_start,
	array_end>: New fields.
	* valprint.c (generic_val_print_array): Add "decorations"
	parameter.  Use "array_start", "array_end".
	(generic_val_print) <TYPE_CODE_ARRAY>: Update.
	* p-valprint.c (p_decorations): Update.
	* m2-valprint.c (m2_decorations): Update.
	* f-valprint.c (f_decorations): Update.
	* c-valprint.c (c_decorations): Update.
2016-05-17 12:02:00 -06:00
Tom Tromey dcd1f97951 Add self-test framework to gdb
I wanted to unit test the Rust lexer, so I added a simple unit testing
command to gdb.

The intent is that self tests will only be compiled into gdb in
development mode.  In release mode they simply won't exist.  So, this
exposes $development to C code as GDB_SELF_TEST.

In development mode, test functions are registered with the self test
module.  A test function is just a function that does some checks, and
throws an exception on failure.

Then this adds a new "maint selftest" command which invokes the test
functions, and a new dejagnu test case that invokes it.

2016-05-17  Tom Tromey  <tom@tromey.com>

	* NEWS: Add "maint selftest" entry.
	* selftest.h: New file.
	* selftest.c: New file.
	* maint.c: Include selftest.h.
	(maintenance_selftest): New function.
	(_initialize_maint_cmds): Add "maint selftest" command.
	* configure.ac (GDB_SELF_TEST): Maybe define.
	* config.in, configure: Rebuild.
	* Makefile.in (SFILES): Add selftest.c.
	(COMMON_OBS): Add selftest.o.

2016-05-17  Tom Tromey  <tom@tromey.com>

	* gdb.texinfo (Maintenance Commands): Document "maint selftest".

2016-05-17  Tom Tromey  <tom@tromey.com>

	* gdb.gdb/unittest.exp: New file.
2016-05-17 12:01:59 -06:00
Tom Tromey e4b8a1c839 Make gdb expression debugging handle OP_F90_RANGE
print_subexp_standard and dump_subexp_body_standard did not handle
OP_F90_RANGE.  Attempting to dump an expression using this opcode
would fail.

This patch adds support for this opcode to these functions.

2016-05-17  Tom Tromey  <tom@tromey.com>

	* expprint.c: Include f-lang.h.
	(print_subexp_standard, dump_subexp_body_standard): Handle
	OP_F90_RANGE.
2016-05-17 12:01:58 -06:00
Tom Tromey 9ab0bb2a67 Fix latent yacc-related bug in gdb/Makefile.in init.c rule
gdb's Makefile.in does not currently scan .y files to add global
initializers from these files to init.c.  However, at least ada-exp.y
tries to use this feature.

This patch fixes the problem.

2016-05-17  Tom Tromey  <tom@tromey.com>

	* Makefile.in (init.c): Search .y files for initialization
	functions.
2016-05-17 12:01:57 -06:00
Yao Qi fcdad592cd Use unsuspend_all_lwps
This patch is to replace find_inferior (&all_threads, unsuspend_one_lwp, NULL)
with unsuspend_all_lwps (NULL), which is shorter.  They are equivalent
to each other.

gdb/gdbserver:

2016-05-17  Yao Qi  <yao.qi@linaro.org>

	* linux-low.c (linux_stabilize_threads): Call unsuspend_all_lwps
	instead of find_inferior.
2016-05-17 08:24:26 +01:00
Yao Qi 155b7f573b Match shell_prompt # in batch-preserve-term-settings.exp
batch-preserve-term-settings.exp fails if the shell prompt isn't $.  It
is # in our testing env.  In fact, the shell prompt can be anything.

The perfect solution would be "set_board_info shell_prompt" in the
host board file, and use board_info shell_prompt in
batch-preserve-term-settings.exp.  This is a little bit overkill to
me, and we still need to figure out the different prompts on different
shells.  I also tried to start shell with the prompt preset, but there is
not unique way to set shell prompt in different shells, so I give up.

It is reasonably simple to match either $ or # for the shell prompt, and
we can easily extend it to match other char, like >.

gdb/testsuite:

2016-05-16  Yao Qi  <yao.qi@linaro.org>

	* gdb.base/batch-preserve-term-settings.exp: Remove variable
	shell_prompt.  Update shell_prompt_re.
2016-05-16 17:32:43 +01:00
Doug Evans 8ddd5a6cd6 PR symtab/19999 gdb unable to resolve vars with fission+PIE
gdb/ChangeLog:

	* dwarf2loc.c (dwarf2_find_location_expression): For DWO files still
	add base_offset.

gdb/testsuite/ChangeLog:

	* lib/dwarf.exp (build_executable_from_fission_assembler): Pass
	$options when building executable.
	* gdb.dwarf2/fission-loclists-pie.c: New file.
	* gdb.dwarf2/fission-loclists-pie.exp: New file.
2016-05-12 09:24:24 -07:00
Trevor Saunders df140a0bc3 fix up two issues with the removal of unused variables
gdb/ChangeLog:

2016-05-10  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* iq2000-tdep.c (iq2000_scan_prologue): Remove if that shouldn't guard
	anything.
	* linespec.c (add_sal_to_sals): Restore call to symtab_to_fullname.
2016-05-10 21:36:02 -04:00
Thomas Preud'homme 39d911fc3c Use getters/setters to access ARM branch type
2016-05-10  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
	* elf32-arm.c (elf32_arm_size_stubs): Use new macros
	ARM_GET_SYM_BRANCH_TYPE and ARM_SET_SYM_BRANCH_TYPE to respectively get
	and set branch type of a symbol.
	(bfd_elf32_arm_process_before_allocation): Likewise.
	(elf32_arm_relocate_section): Likewise and fix identation along the
	way.
	(allocate_dynrelocs_for_symbol): Likewise.
	(elf32_arm_finish_dynamic_symbol): Likewise.
	(elf32_arm_swap_symbol_in): Likewise.
	(elf32_arm_swap_symbol_out): Likewise.

gas/
	* config/tc-arm.c (arm_adjust_symtab): Use ARM_SET_SYM_BRANCH_TYPE to
	set branch type of a symbol.

gdb/
	* arm-tdep.c (arm_elf_make_msymbol_special): Use
	ARM_GET_SYM_BRANCH_TYPE to get branch type of a symbol.

include/
	* arm.h (enum arm_st_branch_type): Add new ST_BRANCH_ENUM_SIZE
	enumerator.
	(NUM_ENUM_ARM_ST_BRANCH_TYPE_BITS): New macro.
	(ENUM_ARM_ST_BRANCH_TYPE_BITMASK): Likewise.
	(ARM_SYM_BRANCH_TYPE): Replace by ...
	(ARM_GET_SYM_BRANCH_TYPE): This and ...
	(ARM_SET_SYM_BRANCH_TYPE): This in two versions depending on whether
	BFD_ASSERT is defined or not.

ld/
	* emultempl/armelf.em (gld${EMULATION_NAME}_finish): Use
	ARM_GET_SYM_BRANCH_TYPE to get branch type of a symbol.

opcodes/
	* arm-dis.c (get_sym_code_type): Use ARM_GET_SYM_BRANCH_TYPE to get
	branch type of a symbol.
	(print_insn): Likewise.
2016-05-10 16:17:04 +01:00
Trevor Saunders 870f88f755 remove trivialy unused variables
gdb/ChangeLog:

2016-05-07  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* aarch64-linux-tdep.c (aarch64_linux_sigframe_init): Remove unused
	variables.
	* aarch64-tdep.c (aarch64_skip_prologue): Likewise.
	(aarch64_scan_prologue): Likewise.
	(aarch64_prologue_prev_register): Likewise.
	(aarch64_dwarf2_prev_register): Likewise.
	(pass_in_v): Likewise.
	(aarch64_push_dummy_call): Likewise.
	(aarch64_breakpoint_from_pc): Likewise.
	(aarch64_return_in_memory): Likewise.
	(aarch64_return_value): Likewise.
	(aarch64_displaced_step_b_cond): Likewise.
	(aarch64_displaced_step_cb): Likewise.
	(aarch64_displaced_step_tb): Likewise.
	(aarch64_gdbarch_init): Likewise.
	(aarch64_process_record): Likewise.
	* alpha-mdebug-tdep.c (alpha_mdebug_init_abi): Likewise.
	* alpha-tdep.c (_initialize_alpha_tdep): Likewise.
	* amd64-dicos-tdep.c (amd64_dicos_init_abi): Likewise.
	* amd64-linux-tdep.c (amd64_dtrace_parse_probe_argument): Likewise.
	* amd64-tdep.c (fixup_riprel): Likewise.
	* amd64-windows-tdep.c (amd64_windows_frame_decode_epilogue): Likewise.
	(amd64_windows_frame_decode_insns): Likewise.
	(amd64_windows_frame_cache): Likewise.
	(amd64_windows_frame_prev_register): Likewise.
	(amd64_windows_frame_this_id): Likewise.
	(amd64_windows_init_abi): Likewise.
	* arm-linux-tdep.c (arm_linux_get_syscall_number): Likewise.
	(arm_linux_get_next_pcs_syscall_next_pc): Likewise.
	* arm-symbian-tdep.c (arm_symbian_init_abi): Likewise.
	* arm-tdep.c (arm_make_epilogue_frame_cache): Likewise.
	(arm_epilogue_frame_prev_register): Likewise.
	(arm_record_vdata_transfer_insn): Likewise.
	(arm_record_exreg_ld_st_insn): Likewise.
	* auto-load.c (execute_script_contents): Likewise.
	(print_scripts): Likewise.
	* avr-tdep.c (avr_frame_prev_register): Likewise.
	(avr_push_dummy_call): Likewise.
	* bfin-linux-tdep.c (bfin_linux_sigframe_init): Likewise.
	* bfin-tdep.c (bfin_gdbarch_init): Likewise.
	* blockframe.c (find_pc_partial_function_gnu_ifunc): Likewise.
	* break-catch-throw.c (fetch_probe_arguments): Likewise.
	* breakpoint.c (breakpoint_xfer_memory): Likewise.
	(breakpoint_init_inferior): Likewise.
	(breakpoint_inserted_here_p): Likewise.
	(software_breakpoint_inserted_here_p): Likewise.
	(hardware_breakpoint_inserted_here_p): Likewise.
	(bpstat_what): Likewise.
	(break_range_command): Likewise.
	(save_breakpoints): Likewise.
	* coffread.c (coff_symfile_read): Likewise.
	* cris-tdep.c (cris_push_dummy_call): Likewise.
	(cris_scan_prologue): Likewise.
	(cris_register_size): Likewise.
	(_initialize_cris_tdep): Likewise.
	* d-exp.y: Likewise.
	* dbxread.c (dbx_read_symtab): Likewise.
	(process_one_symbol): Likewise.
	(coffstab_build_psymtabs): Likewise.
	(elfstab_build_psymtabs): Likewise.
	* dicos-tdep.c (dicos_init_abi): Likewise.
	* disasm.c (do_mixed_source_and_assembly): Likewise.
	(gdb_disassembly): Likewise.
	* dtrace-probe.c (dtrace_process_dof): Likewise.
	* dwarf2read.c (error_check_comp_unit_head): Likewise.
	(build_type_psymtabs_1): Likewise.
	(skip_one_die): Likewise.
	(process_imported_unit_die): Likewise.
	(dwarf2_physname): Likewise.
	(read_file_scope): Likewise.
	(setup_type_unit_groups): Likewise.
	(create_dwo_cu_reader): Likewise.
	(create_dwo_cu): Likewise.
	(create_dwo_unit_in_dwp_v1): Likewise.
	(create_dwo_unit_in_dwp_v2): Likewise.
	(lookup_dwo_unit_in_dwp): Likewise.
	(free_dwo_file): Likewise.
	(check_producer): Likewise.
	(dwarf2_add_typedef): Likewise.
	(dwarf2_add_member_fn): Likewise.
	(read_unsigned_leb128): Likewise.
	(read_signed_leb128): Likewise.
	(dwarf2_const_value): Likewise.
	(follow_die_sig_1): Likewise.
	(dwarf_decode_macro_bytes): Likewise.
	* extension.c (restore_active_ext_lang): Likewise.
	* frv-linux-tdep.c (frv_linux_sigtramp_frame_cache): Likewise.
	* ft32-tdep.c (ft32_analyze_prologue): Likewise.
	* gdbtypes.c (lookup_typename): Likewise.
	(resolve_dynamic_range): Likewise.
	(check_typedef): Likewise.
	* h8300-tdep.c (h8300_is_argument_spill): Likewise.
	(h8300_gdbarch_init): Likewise.
	* hppa-tdep.c (hppa32_push_dummy_call): Likewise.
	(hppa_frame_this_id): Likewise.
	(_initialize_hppa_tdep): Likewise.
	* hppanbsd-tdep.c (hppanbsd_sigtramp_cache_init): Likewise.
	* hppaobsd-tdep.c (hppaobsd_supply_fpregset): Likewise.
	* i386-dicos-tdep.c (i386_dicos_init_abi): Likewise.
	* i386-tdep.c (i386_bnd_type): Likewise.
	(i386_gdbarch_init): Likewise.
	(i386_mpx_bd_base): Likewise.
	* i386nbsd-tdep.c (i386nbsd_sigtramp_cache_init): Likewise.
	* i386obsd-tdep.c (i386obsd_elf_init_abi): Likewise.
	* ia64-tdep.c (examine_prologue): Likewise.
	(ia64_frame_cache): Likewise.
	(ia64_push_dummy_call): Likewise.
	* infcmd.c (finish_command_fsm_async_reply_reason): Likewise.
	(default_print_one_register_info): Likewise.
	* infrun.c (infrun_thread_ptid_changed): Likewise.
	(thread_still_needs_step_over): Likewise.
	(stop_all_threads): Likewise.
	(restart_threads): Likewise.
	(keep_going_stepped_thread): Likewise.
	* iq2000-tdep.c (iq2000_scan_prologue): Likewise.
	* language.c (language_init_primitive_type_symbols): Likewise.
	* linespec.c (add_sal_to_sals): Likewise.
	* linux-nat.c (status_callback): Likewise.
	(kill_unfollowed_fork_children): Likewise.
	(linux_nat_kill): Likewise.
	* linux-tdep.c (linux_fill_prpsinfo): Likewise.
	* linux-thread-db.c (thread_db_notice_clone): Likewise.
	(record_thread): Likewise.
	* location.c (string_to_event_location_basic): Likewise.
	* m32c-tdep.c (m32c_prev_register): Likewise.
	* m32r-linux-tdep.c (m32r_linux_init_abi): Likewise.
	* m32r-tdep.c (decode_prologue): Likewise.
	* m68klinux-tdep.c (m68k_linux_sigtramp_frame_cache): Likewise.
	* machoread.c (macho_symtab_read): Likewise.
	(macho_symfile_read): Likewise.
	(macho_symfile_offsets): Likewise.
	* maint.c (set_per_command_cmd): Likewise.
	* mi/mi-cmd-stack.c (mi_cmd_stack_list_locals): Likewise.
	(mi_cmd_stack_list_variables): Likewise.
	* mi/mi-main.c (mi_cmd_exec_run): Likewise.
	(output_register): Likewise.
	(mi_cmd_execute): Likewise.
	(mi_cmd_trace_define_variable): Likewise.
	(print_variable_or_computed): Likewise.
	* minsyms.c (prim_record_minimal_symbol_full): Likewise.
	* mn10300-tdep.c (mn10300_frame_prev_register): Likewise.
	* msp430-tdep.c (msp430_pseudo_register_write): Likewise.
	* mt-tdep.c (mt_registers_info): Likewise.
	* nios2-tdep.c (nios2_analyze_prologue): Likewise.
	(nios2_push_dummy_call): Likewise.
	(nios2_frame_unwind_cache): Likewise.
	(nios2_stub_frame_cache): Likewise.
	(nios2_stub_frame_sniffer): Likewise.
	(nios2_gdbarch_init): Likewise.
	* ppc-ravenscar-thread.c: Likewise.
	* ppcfbsd-tdep.c (ppcfbsd_sigtramp_frame_cache): Likewise.
	* python/py-evts.c (add_new_registry): Likewise.
	* python/py-finishbreakpoint.c (bpfinishpy_init): Likewise.
	(bpfinishpy_detect_out_scope_cb): Likewise.
	* python/py-framefilter.c (py_print_value): Likewise.
	* python/py-inferior.c (infpy_write_memory): Likewise.
	* python/py-infevents.c (create_inferior_call_event_object): Likewise.
	* python/py-infthread.c (thpy_get_ptid): Likewise.
	* python/py-linetable.c (ltpy_get_pcs_for_line): Likewise.
	(ltpy_get_all_source_lines): Likewise.
	(ltpy_is_valid): Likewise.
	(ltpy_iternext): Likewise.
	* python/py-symtab.c (symtab_and_line_to_sal_object): Likewise.
	* python/py-unwind.c (pyuw_object_attribute_to_pointer): Likewise.
	(unwind_infopy_str): Likewise.
	* python/py-varobj.c (py_varobj_get_iterator): Likewise.
	* ravenscar-thread.c (ravenscar_inferior_created): Likewise.
	* rs6000-aix-tdep.c (rs6000_push_dummy_call): Likewise.
	* rs6000-lynx178-tdep.c (rs6000_lynx178_push_dummy_call): Likewise.
	* rs6000-tdep.c (ppc_deal_with_atomic_sequence): Likewise.
	* s390-linux-tdep.c (s390_supply_tdb_regset): Likewise.
	(s390_frame_prev_register): Likewise.
	(s390_dwarf2_frame_init_reg): Likewise.
	(s390_record_vr): Likewise.
	(s390_process_record): Likewise.
	* score-tdep.c (score_push_dummy_call): Likewise.
	(score3_analyze_prologue): Likewise.
	* sh-tdep.c (sh_extract_return_value_nofpu): Likewise.
	* sh64-tdep.c (sh64_analyze_prologue): Likewise.
	(sh64_push_dummy_call): Likewise.
	(sh64_extract_return_value): Likewise.
	(sh64_do_fp_register): Likewise.
	* solib-aix.c (solib_aix_get_section_offsets): Likewise.
	* solib-darwin.c (darwin_read_exec_load_addr_from_dyld): Likewise.
	(darwin_solib_read_all_image_info_addr): Likewise.
	* solib-dsbt.c (enable_break): Likewise.
	* solib-frv.c (enable_break2): Likewise.
	(frv_fdpic_find_canonical_descriptor): Likewise.
	* solib-svr4.c (svr4_handle_solib_event): Likewise.
	* sparc-tdep.c (sparc_skip_stack_check): Likewise.
	* sparc64-linux-tdep.c (sparc64_linux_get_longjmp_target): Likewise.
	* sparcobsd-tdep.c (sparc32obsd_init_abi): Likewise.
	* spu-tdep.c (info_spu_dma_cmdlist): Likewise.
	* stack.c (read_frame_local): Likewise.
	* symfile.c (symbol_file_add_separate): Likewise.
	(remove_symbol_file_command): Likewise.
	* symmisc.c (maintenance_print_one_line_table): Likewise.
	* symtab.c (symbol_cache_flush): Likewise.
	(basic_lookup_transparent_type): Likewise.
	(sort_search_symbols_remove_dups): Likewise.
	* target.c (target_memory_map): Likewise.
	(target_detach): Likewise.
	(target_resume): Likewise.
	(acquire_fileio_fd): Likewise.
	(target_store_registers): Likewise.
	* thread.c (print_thread_info_1): Likewise.
	* tic6x-tdep.c (tic6x_analyze_prologue): Likewise.
	* tilegx-linux-tdep.c (tilegx_linux_sigframe_init): Likewise.
	* tilegx-tdep.c (tilegx_push_dummy_call): Likewise.
	(tilegx_analyze_prologue): Likewise.
	(tilegx_stack_frame_destroyed_p): Likewise.
	(tilegx_frame_cache): Likewise.
	* tracefile.c (trace_save): Likewise.
	* tracepoint.c (encode_actions_and_make_cleanup): Likewise.
	(start_tracing): Likewise.
	(print_one_static_tracepoint_marker): Likewise.
	* tui/tui.c (tui_enable): Likewise.
	* valops.c (value_struct_elt_bitpos): Likewise.
	(find_overload_match): Likewise.
	(find_oload_champ): Likewise.
	* value.c (value_contents_copy_raw): Likewise.
	* windows-tdep.c (windows_get_tlb_type): Likewise.
	* x86-linux-nat.c (x86_linux_enable_btrace): Likewise.
	* xcoffread.c (record_minimal_symbol): Likewise.
	(scan_xcoff_symtab): Likewise.
	* xtensa-tdep.c (execute_code): Likewise.
	(xtensa_gdbarch_init): Likewise.
	(_initialize_xtensa_tdep): Likewise.
2016-05-07 20:12:53 -04:00
Simon Marchi cbe14bcfad Fix ChangeLog entry format 2016-05-05 09:46:06 -04:00
Yao Qi 9e78496443 Initialize res in get_next_pcs_read_memory_unsigned_integer
This patch initialize res to zero, otherwise, it may have some garbage
bits after the *the_target->read_memory call.

gdb/gdbserver:

2016-05-05  Yao Qi  <yao.qi@linaro.org>

	* linux-arm-low.c (get_next_pcs_read_memory_unsigned_integer):
	Initialize res to zero.
2016-05-05 09:00:56 +01:00
Yao Qi cf2ebb6e09 Change type of cpsr in arm_sigreturn_next_pc
Variable cpsr holds the value of cpsr register, which is 32-bit.  It
is better to explicitly use uint32_t.

gdb/gdbserver:

2016-05-05  Yao Qi  <yao.qi@linaro.org>

	* linux-arm-low.c (arm_sigreturn_next_pc): Change type of cpsr
	to uint32_t.
2016-05-05 09:00:56 +01:00
Ulrich Weigand c1aebf87fd [spu] Fix C++ build problems
ChangeLog:

	* spu-linux-nat.c (spu_bfd_iovec_pread): Add pointer cast for C++.
	(spu_bfd_open): Likewise.

gdbserver/ChangeLog:

	* spu-low.c (fetch_ppc_register): Cast PowerPC-Linux-specific value
	used as first ptrace argument to PTRACE_TYPE_ARG1 for C++.
	(fetch_ppc_memory_1, store_ppc_memory_1): Likewise.
2016-05-04 19:42:09 -04:00
Yao Qi edf689f027 Throw NOT_AVAILABLE_ERROR in read_stack and read_code
Nowadays, read_memory may throw NOT_AVAILABLE_ERROR (it is done by
patch http://sourceware.org/ml/gdb-patches/2013-08/msg00625.html)
however, read_stack and read_code still throws MEMORY_ERROR only.  This
causes PR 19947, that is prologue unwinder is unable unwind because
code memory isn't available, but MEMORY_ERROR is thrown, while unwinder
catches NOT_AVAILABLE_ERROR.

 #0  memory_error (err=err@entry=TARGET_XFER_E_IO, memaddr=memaddr@entry=140737349781158) at /home/yao/SourceCode/gnu/gdb/git/gdb/corefile.c:217
 #1  0x000000000065f5ba in read_code (memaddr=memaddr@entry=140737349781158, myaddr=myaddr@entry=0x7fffffffd7b0 "\340\023<\001", len=len@entry=1)
     at /home/yao/SourceCode/gnu/gdb/git/gdb/corefile.c:288
 #2  0x000000000065f7b5 in read_code_unsigned_integer (memaddr=memaddr@entry=140737349781158, len=len@entry=1, byte_order=byte_order@entry=BFD_ENDIAN_LITTLE)
     at /home/yao/SourceCode/gnu/gdb/git/gdb/corefile.c:363
 #3  0x00000000004717e0 in amd64_analyze_prologue (gdbarch=gdbarch@entry=0x13c13e0, pc=140737349781158, current_pc=140737349781165, cache=cache@entry=0xda0cb0)
     at /home/yao/SourceCode/gnu/gdb/git/gdb/amd64-tdep.c:2267
 #4  0x0000000000471f6d in amd64_frame_cache_1 (cache=0xda0cb0, this_frame=0xda0bf0) at /home/yao/SourceCode/gnu/gdb/git/gdb/amd64-tdep.c:2437
 #5  amd64_frame_cache (this_frame=0xda0bf0, this_cache=<optimised out>) at /home/yao/SourceCode/gnu/gdb/git/gdb/amd64-tdep.c:2508
 #6  0x000000000047214d in amd64_frame_this_id (this_frame=<optimised out>, this_cache=<optimised out>, this_id=0xda0c50)
     at /home/yao/SourceCode/gnu/gdb/git/gdb/amd64-tdep.c:2541
 #7  0x00000000006b94c4 in compute_frame_id (fi=0xda0bf0) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame.c:481
 #8  get_prev_frame_if_no_cycle (this_frame=this_frame@entry=0xda0b20) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame.c:1809
 #9  0x00000000006bb6c9 in get_prev_frame_always_1 (this_frame=0xda0b20) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame.c:1983
 #10 get_prev_frame_always (this_frame=this_frame@entry=0xda0b20) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame.c:1999
 #11 0x00000000006bbe11 in get_prev_frame (this_frame=this_frame@entry=0xda0b20) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame.c:2241
 #12 0x00000000006bc13c in unwind_to_current_frame (ui_out=<optimised out>, args=args@entry=0xda0b20) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame.c:1485

The fix is to let read_stack and read_code throw NOT_AVAILABLE_ERROR too,
in order to align with read_memory.

gdb:

2016-05-04  Yao Qi  <yao.qi@linaro.org>

	PR gdb/19947
	* corefile.c (read_memory): Rename it to ...
	(read_memory_object): ... it.  Add parameter object.
	(read_memory): Call read_memory_object.
	(read_stack): Likewise.
	(read_code): Likewise.
2016-05-04 15:04:01 +01:00
Simon Marchi 02e370d94e Fix solib-display.exp remote check
This test currently uses [is_remote target] to check if the test is
supported.  This is not quite correct, as the limitation is actually
that it requires support for "running", ruling out stub-like targets.
Therefore, it should check for use_gdb_stub.

This has no visible effect right now, but it will once we make the
native-gdbserver board non-dejagnu-remote.

gdb/testsuite/ChangeLog:

	* gdb.base/solib-display.exp: Check for [use_gdb_stub] instead
	of [is_remote target],
2016-05-04 09:29:28 -04:00
Simon Marchi 8929ad8bbc Introduce procedure use_gdb_stub
This patch introduces the use_gdb_stub procedure, which allows getting
the right value of the use_gdb_stub variable/property in any all
situations.

When calling it before the $use_gdb_stub global variable has been set,
it will return the value of the use_gdb_stub property from the board
file.  This happens when tests want to bail out early (even before gdb
has been started) when the current test setup is a stub.

Otherwise, it returns the value of the $use_gdb_stub global.

It's possible for these two to differ when a test file overrides the
value of the global.

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (use_gdb_stub): New procedure.
2016-05-04 09:28:45 -04:00
Doug Evans 6c4474237a PR symtab/19914 fix handling of dwp + split debug
PR symtab/19914
	* dwarf2read.c (open_and_init_dwp_file): Look at backlink if objfile
	is separate debug file.

	testsuite/
	* gdb.dwarf2/dwp-sepdebug.c: New file.
	* gdb.dwarf2/dwp-sepdebug.exp: New file.
2016-05-03 16:30:58 -07:00
Don Breazeal a1ec3d244a Fix typos in gdb_pipe function comment
gdb/ChangeLog:
2016-05-03  Don Breazeal <donb@codesourcery.com>

	* serial.h (gdb_pipe): Fix argument names in comment.
2016-05-03 16:02:34 -07:00
Pedro Alves 86f1abec45 Fix gdb/python/python.c use-after-free
Valgrind shows:

 ==26964== Invalid read of size 1
 ==26964==    at 0x6E14100: __GI_strcmp (strcmp.S:180)
 ==26964==    by 0x6DB55AA: setlocale (setlocale.c:238)
 ==26964==    by 0x4E0455: _initialize_python() (python.c:1731)
 ==26964==    by 0x786731: initialize_all_files() (init.c:319)
 ==26964==    by 0x72EF0A: gdb_init(char*) (top.c:1929)
 ==26964==    by 0x60BCAC: captured_main(void*) (main.c:863)
 ==26964==    by 0x606AD5: catch_errors(int (*)(void*), void*, char*, return_mask) (exceptions.c:234)
 ==26964==    by 0x60C608: gdb_main(captured_main_args*) (main.c:1165)
 ==26964==    by 0x40CAEC: main (gdb.c:32)
 ==26964==  Address 0x81d30a0 is 0 bytes inside a block of size 181 free'd
 ==26964==    at 0x4C29CF0: free (vg_replace_malloc.c:530)
 ==26964==    by 0x6DB5B65: setname (setlocale.c:201)
 ==26964==    by 0x6DB5B65: setlocale (setlocale.c:388)
 ==26964==    by 0x4E037F: _initialize_python() (python.c:1712)
 ==26964==    by 0x786731: initialize_all_files() (init.c:319)
 ==26964==    by 0x72EF0A: gdb_init(char*) (top.c:1929)
 ==26964==    by 0x60BCAC: captured_main(void*) (main.c:863)
 ==26964==    by 0x606AD5: catch_errors(int (*)(void*), void*, char*, return_mask) (exceptions.c:234)
 ==26964==    by 0x60C608: gdb_main(captured_main_args*) (main.c:1165)
 ==26964==    by 0x40CAEC: main (gdb.c:32)

The problem is doing this:

  oldloc = setlocale (LC_ALL, NULL);
  setlocale (LC_ALL, "");
  ...
  setlocale (LC_ALL, oldloc);

I.e., the second setlocale call frees 'oldloc'.

From http://pubs.opengroup.org/onlinepubs/9699919799/functions/setlocale.html :

 "The returned string pointer might be invalidated or the string
 content might be overwritten by a subsequent call to setlocale()."

gdb/ChangeLog:
2016-05-03  Pedro Alves <palves@redhat.com>

	PR python/20037
	* python/python.c (_initialize_python) [IS_PY3K]: xstrdup/xfree
	oldloc.
2016-05-03 12:16:56 +01:00
Pedro Alves 1aa9670288 Remove gdb/python/python.c code that handles strlen failing with -1
This makes no sense -- strlen doesn't really ever fail with -1.

gdb/ChangeLog:
2016-05-03  Pedro Alves <palves@redhat.com>

	* python/python.c (_initialize_python) [IS_PY3K]: Remove dead
	code.
2016-05-03 12:16:55 +01:00
Pedro Alves a4a1c15754 Fix PR gdb/16818, workaround Python's forcing of -export-dynamic
GDB's use of --dynamic-list to only export the proc-service symbols is
broken due to Python's "python-config --ldflags" saying we should link
with -export-dynamic, causing us to export _all_ extern symbols
anyway.  On Fedora 23:

 $ python-config --ldflags
 -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic
 $ python3.4-config --ldflags
  -L/usr/lib64 -lpython3.4m -lpthread -ldl  -lutil -lm  -Xlinker -export-dynamic

Having GDB export all its symbols leads to issues such as PR gdb/16818
(GDB crashes when using name for target remote hostname:port), where a
GDB symbol unintentionally preempts a symbol in one of the NSS modules
glibc loads into the process.  NSS modules should not define symbols
outside the implementation namespace or the relevant standards, but,
alas, that's a longstanding and hard to fix issue.  See libc-alpha
discussion at:

  [symbol name space issues with NSS modules]
  https://sourceware.org/ml/libc-alpha/2016-04/msg00130.html

Python should instead be either using GCC's symbol visibility feature
or -Wl,--dynamic-list as well, to only export Python API symbols, but,
it doesn't.  There are bugs open upstream for that:

  [Use -Wl,--dynamic-list=x.list, not -Xlinker -export-dynamic]
  http://bugs.python.org/issue10112

  [Use GCC visibility attrs in PyAPI_*]
  http://bugs.python.org/issue11410

But that's taking a long while to resolve.

I thought of working around this Python issue by making GDB build with
-fvisibility=hidden, as Jan suggests in Python issue 10112, as then
Python's "-Xlinker -export-dynamic" has no effect.  However, that
would need to be done in the whole source tree (bfd, libiberty, etc.),
and I think that would break GCC plugins, as I believe those have
access to all of GCCs symbols, by "design".  So we'd need a new
configure switch, or have the libraries in the tree detect which of
GCC or GDB is being built, but that doesn't work, because the answer
can be "both" with combined builds...

So this patch instead works around Python's bug, by simply sed'ing
away "-Xlinker -export-dynamic" from the result of python-config.py
--ldflags, making -Wl,--dynamic-list work again as it used to.  It's
ugly, but so is the bug...

Note that if -Wl,--dynamic-list doesn't work, we always link with
-rdynamic, so static Python should still work.

Tested on F23 with --python=python (Python 2.7) and
--python=python3.4.

gdb/ChangeLog:y
2016-05-03  Pedro Alves  <palves@redhat.com>

	* configure.ac (PYTHON_LIBS): Sed away "-Xlinker -export-dynamic".
	* configure: Regenerate.
2016-05-03 10:31:22 +01:00
Pedro Alves 1b4f615e40 Fix "-Wl,--dynamic-list" gdb/configure test
The -Wl,--dynamic-list test is currently broken on Fedora 23, when you
configure with --with-python=python3.4.  We see:

 configure:13741: checking for the dynamic export flag
 configure:13796: gcc -o conftest -g3 -O0  -fno-strict-aliasing -DNDEBUG -fwrapv    -Wl,--dynamic-list=/home/pedro/gdb/mygit/src/gdb/proc-service.list conftest.c -ldl -lncurses -lm -ldl  -lpthread -ldl -lutil -lm -lpython3.4m -Xlinker -export-dynamic >&5
 conftest.c:182:30: fatal error: python3.4/Python.h: No such file or directory
 compilation terminated.
 configure:13796: $? = 1

The correct -I path is in PYTHON_CPPFLAGS:

 PYTHON_CPPFLAGS='-I/usr/include/python3.4m -I/usr/include/python3.4m'

(Other Python-related tests in the file are already doing this.)

gdb/ChangeLog:
2016-05-03  Pedro Alves  <palves@redhat.com>

	* configure.ac (checking for the dynamic export flag): Add
	$PYTHON_CPPFLAGS to CPPFLAGS.
	* configure: Regenerate.
2016-05-03 10:30:51 +01:00
Kyrylo Tkachov b631e59ba0 [gdb] Fix -Wparentheses warnings
2016-05-03  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>

	* symfile.c (find_pc_overlay): Add braces to avoid -Wparentheses
	warning.
	(find_pc_mapped_section): Likewise.
	(list_overlays_command): Likewise.
2016-05-03 09:40:54 +01:00
Simon Marchi 444e826c91 Fix detach.exp remote check
This test seems to work with both native-gdbserver and
native-extended-gdbserver, so I removed the remote check.

When running with native-gdbserver (a stub-like target), detach makes
gdbserver stop and gdb disconnect.  runto_main just spawns a brand new
gdbserver.  So it tests the exact same thing twice.  It doesn't hurt
though.

With native-extended-gdbserver, the test is probably a bit more useful
(and similar to native).  It tests running/detaching twice using the
same gdb/gdbserver instances, since with extended-remote, you can
detach/attach/run all you want, unlike with remote.

gdb/testsuite/ChangeLog:

	* gdb.base/detach.exp: Remove is_remote check.
2016-05-02 13:10:33 -04:00
Simon Marchi 740feeaa20 Fix annota-input-while-running.exp remote check
The comment says that we can't use runto_main here becore it doesn't
know how to handle annotation.  Instead, the test puts a breakpoint at
main and calls run by hand.  Therefore, it can't work with stub targets,
since they can't "run".  The check should be then changed to check the
use_gdb_stub variable instead of [is_remote target].

But as an alternative, we can just use runto_main and enable annotations
after, since the "run to main" part is not really part of what we want
to test.

I also removed the "set test..." line that is unused.

gdb/testsuite/ChangeLog:

	* gdb.base/annota-input-while-running.exp: Don't check for
	[is_remote target].  Enable annotations after running to main.
	Remove unused "set test..." line.
2016-05-02 13:04:56 -04:00
Eli Zaretskii 1270fac69d Fix startup on MS-Windows when 'gdb.ini' is found in $HOME
* windows-nat.c (_initialize_check_for_gdb_ini): Fix off-by-one
	error in allocation of space for "$HOME/.gdbinit" string.  This
	caused GDB to abort on startup whenever a '~/gdb.ini' file was
	actually found, because xsnprintf would hit an assertion
	violation.
2016-05-02 19:37:43 +03:00
Simon Marchi 0400cf2f56 Don't show deprecated commands in help
Just like completion doesn't show deprecated commands, I think that help
should not list them, so that we don't incite users to use them.

gdb/ChangeLog:

	* cli/cli-decode.c (help_cmd_list): Do not list commands that
	are deprecated.
2016-04-28 14:11:51 -04:00
Simon Marchi 9080ac9d99 Add test for tracepoint enable/disable
This patch adds a test for tracepoints enabling/disabling, which
didn't work properly for fast tracepoints on big endian systems.

gdb/testsuite/ChangeLog:

	* gdb.trace/trace-enable-disable.exp: New file.
	* gdb.trace/trace-enable-disable.c: New file.
2016-04-28 12:56:08 -04:00
Par Olsson 35fd2deb69 Fix write endianness/size problem for fast tracepoint enabled flag
I am sending this fix on behalf of Par Olsson, as a follow-up of this
one:

https://www.sourceware.org/ml/gdb-patches/2015-10/msg00196.html

This problem is exposed when enabling/disabling fast tracepoints on big
endian machines.  The flag is defined as an int8_t, but is written from
gdbserver as an integer (usually 32 bits).  When the agent code reads it
as an int8_t, it only considers the most significant byte, which is
always 0.

Also, we were writing 32 bits in an 8 bits field, so the write would
overflow, but since the following bytes are padding (the next field is
an uint64_t), it luckily didn't cause any issue on little endian
systems.

The fix was originally tested on ARM big endian systems, but I don't
have access to such a system.  However, thanks to Marcin's PowerPC fast
tracepoint patches and gcc110 (big endian Power7) on the gcc compile
farm, I was able to reproduce the problem, test the fix and write a
test (the following patch).

gdb/gdbserver/ChangeLog:

YYYY-MM-DD  Par Olsson  <par.olsson@windriver.com>

	* tracepoint.c (write_inferior_int8): New function.
	(cmd_qtenable_disable): Write enable flag using
	write_inferior_int8.
2016-04-28 12:56:05 -04:00
Simon Marchi 952ebca583 ftrace tests: Use gdb_load_shlib result to lookup IPA in info sharedlibrary
Some fast tracepoints tests make sure that the in-process agent library
is properly loaded, by searching for the library name in "info
sharedlibrary".

Originally, it would search for the full path.  Since patch "Make ftrace
tests work with remote targets" [1], the "runtime" location of the IPA,
in the standard output directory, is not the same as the original
location, in the gdbserver build directory.  Therefore, the patch
changed the checks:

  gdb_test "info sharedlibrary" ".*${libipa}.*" "IPA loaded"

to

  gdb_test "info sharedlibrary" ".*[file tail ${libipa}].*" "IPA loaded"

so that only the "libinproctrace.so" part would be searched for.
Antoine (in CC) pointed out that I missed some, so I have to update
them.  In the mean time, I noticed that I missed a few test failures:
adding the SONAME to the IPA makes it possible for the test executable
to erroneously pick up libinproctrace.so from /usr/lib if the test
harness failed to put the libinproctrace.so we want to test in the right
place.  To mitigate that kind of error in the future, we can use the
return value of gdb_load_shlib (the path of the "runtime" version of the
library) and use that to search in the output of info sharedlibrary.

When testing locally, gdb_load_shlib returns the full normalized path of
the destination library, which the test executable should use e.g.:

  /path/to/gdb/testsuite/outputs/gdb.trace/thetest/libinproctrace.so

My testing showed that it was the same path that gdb displayed in info
sharedlibrary.  If the test executable picks up another
libinproctrace.so, the test will fail.

When testing remotely, gdb_load_shlib/gdb_remote_download only returns
us "libinproctrace.so", so the situation doesn't really change.  If
there is a rogue libinproctrace.so in /usr/lib on the target and we fail
to download ours, it might cover up a test failure.  But that situation
is probably still better than the original one, where it wasn't possible
to test remotely using the IPA at all.

[1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=6e774b13c3b81ac2599812adf058796948ce7e95

gdb/testsuite/ChangeLog:

	* gdb.arch/ftrace-insn-reloc.exp: Save gdb_load_shlib result,
	use it in info sharedlibrary test.
	* gdb.trace/ftrace-lock.exp: Likewise.
	* gdb.trace/ftrace.exp: Likewise.
	* gdb.trace/range-stepping.exp: Likewise.
	* gdb.trace/trace-break.exp: Likewise.
	* gdb.trace/trace-condition.exp: Likewise.
	* gdb.trace/trace-mt.exp: Likewise.
2016-04-28 09:49:01 -04:00
Yao Qi f166f943f3 Remove need_step_over from struct lwp_info
Hi,
I happen to see that field need_step_over in struct lwp_info is only
used to print a debug info.  need_step_over is set in linux_wait_1
when breakpoint_here is true, however, we check breakpoint_here too in
need_step_over_p and do the step over.  I think we don't need field
need_step_over, and check breakpoint_here directly in need_step_over_p.

This field was added in this patch
https://sourceware.org/ml/gdb-patches/2010-03/msg00605.html and the code
wasn't changed much since then.

This patch is to remove it.

gdb/gdbserver:

2016-04-28  Yao Qi  <yao.qi@linaro.org>

	* linux-low.h (struct lwp_info) <need_step_over>: Remove.
	* linux-low.c (linux_wait_1): Update.
	(need_step_over_p): Likewise.
2016-04-28 11:52:23 +01:00
Simon Marchi d9019901f8 Rename gdb_load_shlibs to gdb_load_shlib
Rename gdb_load_shlibs to gdb_load_shlib to reflect that it can only
load a single shlib at the time.

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (gdb_load_shlibs): Rename to...
	(gdb_load_shlib): ... this.
	* gdb.arch/ftrace-insn-reloc.exp: Adjust gdb_load_shlibs ->
	gdb_load_shlib.
	* gdb.base/catch-load.exp (one_catch_load_test): Likewise.
	* gdb.base/ctxobj.exp: Likewise.
	* gdb.base/dprintf-pending.exp: Likewise.
	* gdb.base/dso2dso.exp: Likewise.
	* gdb.base/fixsection.exp: Likewise.
	* gdb.base/gcore-relro.exp: Likewise.
	* gdb.base/gdb1555.exp: Likewise.
	* gdb.base/global-var-nested-by-dso.exp: Likewise.
	* gdb.base/gnu-ifunc.exp: Likewise.
	* gdb.base/hbreak-in-shr-unsupported.exp: Likewise.
	* gdb.base/jit-so.exp (one_jit_test): Likewise.
	* gdb.base/pending.exp: Likewise.
	* gdb.base/print-file-var.exp: Likewise.
	* gdb.base/print-symbol-loading.exp: Likewise.
	* gdb.base/shlib-call.exp: Likewise.
	* gdb.base/shreloc.exp: Likewise.
	* gdb.base/so-impl-ld.exp: Likewise.
	* gdb.base/solib-disc.exp: Likewise.
	* gdb.base/solib-nodir.exp: Likewise.
	* gdb.base/solib-overlap.exp: Likewise.
	* gdb.base/solib-symbol.exp: Likewise.
	* gdb.base/solib-weak.exp (do_test): Likewise.
	* gdb.base/sym-file.exp: Likewise.
	* gdb.base/symtab-search-order.exp: Likewise.
	* gdb.base/type-opaque.exp: Likewise.
	* gdb.base/unload.exp: Likewise.
	* gdb.base/watchpoint-solib.exp: Likewise.
	* gdb.compile/compile.exp: Likewise.
	* gdb.cp/gdb2384.exp: Likewise.
	* gdb.cp/infcall-dlopen.exp: Likewise.
	* gdb.cp/re-set-overloaded.exp: Likewise.
	* gdb.fortran/library-module.exp: Likewise.
	* gdb.opt/solib-intra-step.exp: Likewise.
	* gdb.python/py-finish-breakpoint.exp: Likewise.
	* gdb.python/py-shared.exp: Likewise.
	* gdb.reverse/solib-precsave.exp: Likewise.
	* gdb.reverse/solib-reverse.exp: Likewise.
	* gdb.server/solib-list.exp: Likewise.
	* gdb.threads/dlopen-libpthread.exp: Likewise.
	* gdb.threads/tls-shared.exp: Likewise.
	* gdb.threads/tls-so_extern.exp: Likewise.
	* gdb.trace/change-loc.exp: Likewise.
	* gdb.trace/ftrace-lock.exp: Likewise.
	* gdb.trace/ftrace.exp: Likewise.
	* gdb.trace/mi-tracepoint-changed.exp (test_reconnect): Likewise.
	* gdb.trace/pending.exp: Likewise.
	* gdb.trace/range-stepping.exp: Likewise.
	* gdb.trace/strace.exp (strace_remove_socket): Likewise.
	(strace_info_marker): Likewise.
	(strace_probe_marker): Likewise.
	(strace_trace_on_same_addr): Likewise.
	(strace_trace_on_diff_addr): Likewise.
	* gdb.trace/trace-break.exp: Likewise.
	* gdb.trace/trace-condition.exp: Likewise.
	* gdb.trace/trace-mt.exp: Likewise.
2016-04-27 18:09:14 -04:00
Simon Marchi fca4cfd9ec Make gdb_load_shlibs return the destination path of the library
This patch makes gdb_load_shlibs return the destination path of the
copied library.  To make the procedure implementation and interface more
straightforward, it also changes it so that it accepts a single shared
library path at the time.  Therefore, calls that are passed multiple
libraries:

  gdb_load_shlibs $lib1 $lib2

must be changed to separate calls:

  gdb_load_shlibs $lib1
  gdb_load_shlibs $lib2

A subtle impact is the solib-search-path handling.  In the former
version, solib-search-path is set using the directory of the first
passed lib (further calls overwrite the value).  In the later version,
the directory of the library passed to the last call to gdb_load_shlibs
remnains.  I don't think that's a problem in practice, since if we had
tests that needed multiple different paths in solib-search-path, they
wouldn't work in the first place.

Changed in v2:

	* Split behavioural and rename changes in two separate patches.

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (gdb_load_shlibs):  Accept a single argument.  Return
	result of gdb_remote_download.
	* gdb.base/ctxobj.exp: Split gdb_load_shlibs call.
	* gdb.base/dso2dso.exp: Likewise.
	* gdb.base/global-var-nested-by-dso.exp: Likewise.
	* gdb.base/print-file-var.exp: Likewise.
	* gdb.base/shlib-call.exp: Likewise.
	* gdb.base/shreloc.exp: Likewise.
	* gdb.base/solib-overlap.exp: Likewise.
	* gdb.base/solib-weak.exp (do_test): Likewise.
	* gdb.base/unload.exp: Likewise.
2016-04-27 18:09:14 -04:00
Jan Kratochvil 57809e5e5a Workaround gdbserver<7.7 for setfs
With current FSF GDB HEAD and old FSF gdbserver I expected I could do:
	gdb -ex 'file target:/root/redhat/threadit' -ex 'target remote :1234'
(supplying that unsupported qXfer:exec-file:read by "file")
But that does not work because:
	Sending packet: $vFile:setfs:0#bf...Packet received: OK
	Packet vFile:setfs (hostio-setfs) is supported
	...
	Sending packet: $vFile:setfs:104#24...Packet received: OK
	"target:/root/redhat/threadit": could not open as an executable file: Invalid argument

GDB documentation says:
	The valid responses to Host I/O packets are:
	An empty response indicates that this operation is not recognized.

This "empty response" vs. "OK" was a bug in gdbserver < 7.7.  It was fixed by:
	commit e7f0d979dd
	Author: Yao Qi <yao@codesourcery.com>
	Date:   Tue Dec 10 21:59:20 2013 +0800
	    Fix a bug in matching notifications.
	Message-ID: <1386684626-11415-1-git-send-email-yao@codesourcery.com>
	https://sourceware.org/ml/gdb-patches/2013-12/msg00373.html
	2013-12-10  Yao Qi  <yao@codesourcery.com>
		* notif.c (handle_notif_ack): Return 0 if no notification
		matches.

with unpatched old FSF gdbserver and patched FSF GDB HEAD:
	gdb -ex 'file target:/root/redhat/threadit' -ex 'target remote :1234'
	Sending packet: $vFile:setfs:0#bf...Packet received: OK
	Packet vFile:setfs (hostio-setfs) is NOT supported
	...
	(gdb) info sharedlibrary
	From                To                  Syms Read   Shared Object Library
	0x00007ffff7ddbae0  0x00007ffff7df627a  Yes (*)     target:/lib64/ld-linux-x86-64.so.2
	0x00007ffff7bc48a0  0x00007ffff7bcf514  Yes (*)     target:/lib64/libpthread.so.0

gdb/ChangeLog
2016-04-26  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* remote.c (remote_start_remote): Detect PACKET_vFile_setfs.support.
2016-04-27 21:27:40 +02:00
Yao Qi 11cf4ffb5e Skip gdb.base/branch-to-self.exp if gdb,nosignals exists
I get a timeout fail in branch-to-self.exp when it is compiled by a
bare-mental target running qemu, which doesn't have signal.

The test should be skipped if gdb,nosignals exists, and that is
what this patch does.

gdb/testsuite:

2016-04-27  Yao Qi  <yao.qi@linaro.org>

	* gdb.base/branch-to-self.exp: Skip it if gdb,nosignals
	exists.
2016-04-27 16:13:52 +01:00
Martin Galvan 476350ba48 c_value_print: Revert 'val' to a reference for TYPE_CODE_STRUCT
Currently c_value_print will turn struct reference values into pointers before
doing a set of RTTI checks.  This was introduced as a fix to PR c++/15401.
If there's RTTI the pointer will be adjusted and converted back to a reference.
However, if there's no RTTI the value will still be treated as a pointer during
the remainder of the function.
This patch moves the conversion down so that it's always performed when needed.

Notice this currently has not user-visible effects, so can be seen as a small
code cleanup.  However, it'll be necessary for the bug-fix for handling
synthetic C++ references.  It causes no testsuite regressions.

gdb/ChangeLog:
2016-04-26  Martin Galvan  <martin.galvan@tallertechnologies.com>

	* c-valprint.c (c_value_print): Always convert val back to reference
	type if we converted it to a pointer type.
2016-04-27 12:05:43 -03:00
Yao Qi 310cdbb651 Tweak doc on command tfind
Hi,
command "tfind" will find the first trace snapshot if no trace
snapshot is selected, but this behavior isn't documented.

This patch completes the doc of command "tfind" without argument.

gdb/doc:

2016-04-27  Yao Qi  <yao.qi@linaro.org>

	* gdb.texinfo (tfind): Complete doc about tfind without
	argument.
2016-04-27 15:01:20 +01:00
Andreas Arnez 2d681be471 Avoid non-C++-enabled babeltrace versions
In some babeltrace versions before 1.2.0, the header file iterator.h
declares the enum values `BT_SEEK_*' within the struct declaration of
bt_iter_pos.  The enum values are supposed to be globally-scoped, which
works for C, but not for C++.  Later babeltrace versions declare the
enum outside the struct:

  https://lists.lttng.org/pipermail/lttng-dev/2013-September/021411.html

Now that GDB is compiled with C++, the GDB build fails on a system with
an affected babeltrace version: the compiler complains about a missing
declaration of BT_SEEK_BEGIN in ctf.c.

This patch enhances the configure check to recognize such babeltrace
versions as unusable for GDB.

gdb/ChangeLog:

	* configure.ac: Enhance configure check for babeltrace to reject
	non-C++-enabled versions.
	* configure: Regenerate.
2016-04-27 15:52:16 +02:00
Keven Boell 3e2e34f862 fort_dyn_array: Use value constructor instead of raw-buffer manipulation.
Instead of pre-computing indices into a fortran array re-use
the value_* interfaces to subscript a fortran array.
The benefit of using the new interface is that it takes care of
dynamic types and resolve them when needed.
This fixes issues when printing structures with dynamic arrays from toplevel.

Before:
(gdb) p twov
$1 = ( (( ( 6352320, 0, -66, -1, 267) ( 343476, 1, -15, 1, 0) ( 5, 0, 5, 0, 1) ...

After:
(gdb) p twov
$1 = ( (( ( 1, 1, 1, 1, 1) ( 1, 1, 321, 1, 1) ( 1, 1, 1, 1, 1) ...

2016-04-26  Sanimir Agovic  <sanimir.agovic@intel.com>
            Keven Boell  <keven.boell@intel.com>
            Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/Changelog:
	* f-valprint.c (f77_create_arrayprint_offset_tbl): Remove
	function.
	(F77_DIM_SIZE, F77_DIM_OFFSET): Remove macro.
	(f77_print_array_1): Use value_subscript to subscript a
	value array.
	(f77_print_array): Remove call to f77_create_arrayprint_offset_tbl.
	(f_val_print): Use value_field to construct a field value.

gdb/testsuite/Changelog:
	* vla-type.exp: Print structure from toplevel.
2016-04-26 16:48:41 +02:00
Bernhard Heckel 8f07e298b1 fort_dyn_array: Support evaluation of dynamic elements inside arrays.
Resolve type of an array's element to be printed in case it is dynamic.
Otherwise we don't use the correct boundaries nor the right location.

Before:
  ptype fivearr(1)
  type = Type five
      Type one
          integer(kind=4) :: ivla(34196784:34196832,34197072:34197120,34197360:34197408)
      End Type one :: tone
  End Type five

After:
  ptype fivearr(1)
  type = Type five
      Type one
          integer(kind=4) :: ivla(2,4,6)
      End Type one :: tone
  End Type five

2016-04-26  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/Changelog:
	* valarith.c (value_address): Resolve dynamic types.

gdb/testsuite/Changelog:
	* gdb.fortran/vla-type.f90: Add test for static and dynamic arrays
	of dynamic types.
	* gdb.fortran/vla-type.exp: Add test for static and dynamic arrays
	of dynamic types.
2016-04-26 16:38:19 +02:00
Bernhard Heckel 9920b4348e fort_dyn_array: Enable dynamic member types inside a structure.
Fortran supports dynamic types for which bounds, size and location
can vary during their lifetime. As a result of the dynamic
behaviour, they have to be resolved at every query.
This patch will resolve the type of a structure field when it
is dynamic.

2016-04-26  Bernhard Heckel  <bernhard.heckel@intel.com>
2016-04-26  Keven Boell  <keven.boell@intel.com>

Before:
(gdb) print threev%ivla(1)
Cannot access memory at address 0x3
(gdb) print threev%ivla(5)
no such vector element

After:
(gdb) print threev%ivla(1)
$9 = 1
(gdb) print threev%ivla(5)
$10 = 42

gdb/Changelog:

	* NEWS: Add new supported features for fortran.
	* gdbtypes.c (remove_dyn_prop): New.
	(resolve_dynamic_struct): Keep type length for fortran structs.
	* gdbtypes.h: Forward declaration of new function.
	* value.c (value_address): Return dynamic resolved location of a value.
	(set_value_component_location): Adjust the value address
	for single value prints.
	(value_primitive_field): Support value types with a dynamic location.
	(set_internalvar): Remove dynamic location property of
	internal variables.

gdb/testsuite/Changelog:

	* gdb.fortran/vla-type.f90: New file.
	* gdb.fortran/vla-type.exp: New file.
2016-04-26 16:28:43 +02:00
Yao Qi f3abeff575 New test case gdb.base/branch-to-self.exp
gdb/testsuite:

2016-04-25  Yao Qi  <yao.qi@linaro.org>

	* gdb.base/branch-to-self.c: New file.
	* gdb.base/branch-to-self.exp: New file.
2016-04-25 09:53:51 +01:00
Yao Qi 484b3c325d Resume the inferior with signal rather than stepping over
When GDBserver steps over a breakpoint using software single step, it
enqueues the signal, single step and deliver the signal in the next
resume if step over is not needed.  In this way, the program won't
receive the signal if the conditional breakpoint is set a branch to
self instruction, because the step over is always needed.

This patch removes the restriction that don't deliver the signal to
the inferior if we are trying to reinsert a breakpoint for software
single step and change the decision on resume vs. step-over when the
LWP has pending signals to deliver.

gdb/gdbserver:

2016-04-25  Yao Qi  <yao.qi@linaro.org>

	* linux-low.c (lwp_signal_can_be_delivered): Adjust.
	(need_step_over_p): Return zero if the LWP has pending signals
	can be delivered on software single step target.
2016-04-25 09:46:36 +01:00
Yao Qi 85ba7d867a [GDBserver] Don't error in reinsert_raw_breakpoint if bp->inserted
GDBserver steps over a breakpoint while the single step breakpoint
is inserted at the same address, there are two breakpoint objects
using single raw breakpoint, which is inserted (for single step).
When step over is finished, GDBserver reinsert the breakpoint, but
it finds the raw breakpoint is already inserted, and error out
"Breakpoint already inserted at reinsert time."  Even if I change the
order to delete reinsert breakpoints first (which only decreases the
refcount, but leave inserted flag unchanged), the error is still
there.

The fix is to remove the error and return instead.

gdb/gdbserver:

2016-04-25  Yao Qi  <yao.qi@linaro.org>

	* linux-low.c (reinsert_raw_breakpoint): If bp->inserted is true
	return instead of error.
2016-04-25 09:46:36 +01:00
Yao Qi 20249ae455 Insert breakpoint even when the raw breakpoint is found
When GDBserver inserts a breakpoint, it looks for raw breakpoint, if
the raw breakpoint is found, increase its refcount, and return.  This
doesn't work when it steps over a breakpoint using software single
step and the underneath instruction of breakpoint is branch to self.

When stepping over a breakpoint on ADDR using software single step,
GDBserver uninsert the breakpoint, so the corresponding raw breakpoint
RAW's 'inserted' flag is zero.  Then, GDBserver insert single step
breakpoint at the same address ADDR because the instruction is branch
to self, the same raw brekapoint RAW is found, and increase the
refcount.  However, the raw breakpoint is not inserted, and the
program won't stop.

gdb/gdbserver:

2016-04-25  Pedro Alves  <palves@redhat.com>
	    Yao Qi  <yao.qi@linaro.org>

	* mem-break.c (set_raw_breakpoint_at): Create a raw breakpoint
	object.  Insert it if it is not inserted yet.  Increase the
	refcount and link it into the proc's raw breakpoint list.
2016-04-25 09:43:36 +01:00
Yao Qi 21edc42f4e Force to insert software single step breakpoint
GDB doesn't insert software single step breakpoint if the instruction
branches to itself, so that the program can't stop after command "si".

(gdb) b 32
Breakpoint 2 at 0x8680: file git/gdb/testsuite/gdb.base/branch-to-self.c, line 32.
(gdb) c
Continuing.

Breakpoint 2, main () at gdb/git/gdb/testsuite/gdb.base/branch-to-self.c:32
32	  asm (".Lhere: " BRANCH_INSN " .Lhere"); /* loop-line */
(gdb) si
infrun: clear_proceed_status_thread (Thread 3991.3991)
infrun: proceed (addr=0xffffffff, signal=GDB_SIGNAL_DEFAULT)
infrun: step-over queue now empty
infrun: resuming [Thread 3991.3991] for step-over
infrun: skipping breakpoint: stepping past insn at: 0x8680
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sending packet: $Z0,8678,4#f3...Packet received: OK
infrun: skipping breakpoint: stepping past insn at: 0x8680
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sending packet: $Z0,b6fe86c8,4#82...Packet received: OK
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=1, current thread [Thread 3991.3991] at 0x868

breakpoint.c:should_be_inserted thinks the breakpoint shouldn't be
inserted, which is wrong.  This patch restrict the condition that
only skip the non-single-step breakpoints if they are inserted at
the place we are stepping over, however we don't want to skip
single-step breakpoint if its thread is the thread we are stepping
over, so in this patch, I add a thread num in 'struct step_over_info'
to record the thread we're stepping over.

gdb:

2016-04-25  Yao Qi  <yao.qi@linaro.org>

	* breakpoint.c (should_be_inserted): Return 0 if the location's
	owner is not single step breakpoint or single step breakpoint's
	thread isn't the thread which is stepping past a breakpoint.
	* gdbarch.sh (software_single_step): Update comments.
	* gdbarch.h: Regenerated.
	* infrun.c (struct step_over_info) <thread>: New field.
	(set_step_over_info): New argument 'thread'.  Callers updated.
	(clear_step_over_info): Set field thread to -1.
	(thread_is_stepping_over_breakpoint): New function.
	* infrun.h (thread_is_stepping_over_breakpoint): Declaration.
2016-04-25 09:16:21 +01:00
Edjunior Barbosa Machado 0154d99053 Fix checks for VSX and Altivec availability on Power
gdb/ChangeLog

	* ppc-linux-nat.c (ppc_linux_read_description): Use PPC_FEATURE_HAS_VSX
	and PPC_FEATURE_HAS_ALTIVEC to check if such features are available.
2016-04-22 19:39:12 -03:00
Yao Qi 0a5d52f0ec Fix fails in gdb.trace/unavailable.exp
I am seeing some test fails in gdb.trace/unavailable.exp on aarch64-linux,
like this,

print derived_whole^M
$43 = (Derived) {<Middle> = {<Base> = {x = 2}, _vptr.Middle = 0x401860 <VTT for Derived>, y = 3}, _vptr.Derived = 0x401848 <vtable for Derived+32>, z = 4}^M
(gdb) FAIL: gdb.trace/unavailable.exp: collect globals: print object on: print derived_whole

print derived_whole^M
$47 = {<Middle> = {<Base> = {x = 2}, _vptr.Middle = 0x401860 <VTT for Derived>, y = 3}, _vptr.Derived = 0x401848 <vtable for Derived+32>, z = 4}^M
(gdb) FAIL: gdb.trace/unavailable.exp: collect globals: print object off: print derived_whole

these fails are also found by recent x86_64-linux buildbot,
https://sourceware.org/ml/gdb-testers/2016-q2/msg00622.html

The fix is exactly the same as this one
http://www.sourceware.org/ml/gdb-patches/2015-10/msg00252.html (the
extra "VTT" after hex), in which we match extra things after $hex.

gdb/testsuite:

2016-04-22  Yao Qi  <yao.qi@linaro.org>

	* gdb.trace/unavailable.exp (gdb_collect_globals_test_1): Match
	more after $hex.
2016-04-22 17:23:23 +01:00
Yao Qi 6d7e9d3b8d Choose TARGET_OBJECT_STACK_MEMORY and TARGET_OBJECT_MEMORY in read_value_memory
Before this patch
https://sourceware.org/ml/gdb-patches/2014-02/msg00709.html
read_value_memory checks parameter 'stack', and call read_stack or
read_memory respectively.  However, 'stack' is not checked and
TARGET_OBJECT_MEMORY is always used in target_xfer_partial, which is
a mistake in the patch above.

This patch checks parameter 'stack', and choose TARGET_OBJECT_MEMORY
or TARGET_OBJECT_STACK_MEMORY accordingly.

gdb:

2016-04-22  Yao Qi  <yao.qi@linaro.org>

	* valops.c (read_value_memory): New local variable 'stack'.
	Set it to either TARGET_OBJECT_STACK_MEMORY or
	TARGET_OBJECT_MEMORY.
2016-04-22 17:20:24 +01:00
Pedro Alves b3f11165aa Centralize yacc interface names remapping (yyparse, yylex, yyerror, etc)
This factors out all the yy-variables remapping to a single file,
instead of each parser having to do the same, with different prefixes.

With this, a parser just needs to define the prefix they want and
include yy-remap.h, which does the dirty job.

Note this renames the c_error, ada_error, etc. functions.  Writing the
remapping pattern as:

 #define yyerror GDB_YY_REMAP (error)

instead of:

 #define yyerror GDB_YY_REMAP (yyerror)

would have avoided the renaming.  However, that would be problematic
if we have a macro 'foo' in scope, when we write:

 #define yyfoo GDB_YY_REMAP (foo)

as that would expand 'foo'.

The c_yyerror etc. naming end ups indicating that this is a yacc
related function more clearly, so feels like a good change, anyway.

gdb/ChangeLog:
2016-04-22  Pedro Alves  <palves@redhat.com>

	* ada-exp.y: Remove all yy symbol remappings.
	(GDB_YY_REMAP_PREFIX): Define.
	Include "yy-remap.h".
	* ada-lang.c (ada_language_defn): Adjust.
	* ada-lang.h (ada_error): Rename to ...
	(ada_yyerror): ... this.
	* c-exp.y: Remove all yy symbol remappings.
	(GDB_YY_REMAP_PREFIX): Define.
	Include "yy-remap.h".
	* c-lang.c (c_language_defn, cplus_language_defn)
	(asm_language_defn, minimal_language_defn): Adjust.
	* c-lang.h (c_error): Rename to ...
	(c_yyerror): ... this.
	* d-exp.y: Remove all yy symbol remappings.
	(GDB_YY_REMAP_PREFIX): Define.
	Include "yy-remap.h".
	* d-lang.c (d_language_defn): Adjust.
	* d-lang.h (d_error): Rename to ...
	(d_yyerror): ... this.
	* f-exp.y: Remove all yy symbol remappings.
	(GDB_YY_REMAP_PREFIX): Define.
	Include "yy-remap.h".
	* f-lang.c (f_language_defn): Adjust.
	* f-lang.h (f_error): Rename to ...
	(f_yyerror): ... this.
	* go-exp.y: Remove all yy symbol remappings.
	(GDB_YY_REMAP_PREFIX): Define.
	Include "yy-remap.h".
	* go-lang.c (go_language_defn): Adjust.
	* go-lang.h (go_error): Rename to ...
	(go_yyerror): ... this.
	* jv-exp.y: Remove all yy symbol remappings.
	(GDB_YY_REMAP_PREFIX): Define.
	Include "yy-remap.h".
	* jv-lang.c (java_language_defn): Adjust.
	* jv-lang.h (java_error): Rename to ...
	(java_yyerror): ... this.
	* m2-exp.y: Remove all yy symbol remappings.
	(GDB_YY_REMAP_PREFIX): Define.
	Include "yy-remap.h".
	* m2-lang.c (m2_language_defn): Adjust.
	* m2-lang.h (m2_error): Rename to ...
	(m2_yyerror): ... this.
	* objc-exp.y: Remove all yy symbol remappings.
	(GDB_YY_REMAP_PREFIX): Define.
	Include "yy-remap.h".
	* objc-lang.c (objc_language_defn): Adjust.
	* opencl-lang.c (opencl_language_defn): Adjust.
	* p-exp.y: Remove all yy symbol remappings.
	(GDB_YY_REMAP_PREFIX): Define.
	Include "yy-remap.h".
	* p-lang.c (pascal_language_defn): Adjust.
	* p-lang.h (pascal_error): Rename to ...
	(pascal_yyerror): ... this.
	* yy-remap.h: New file.
2016-04-22 16:40:33 +01:00
Pedro Alves 6290672f89 Switch gdb's TRY/CATCH to C++ try/catch
The exceptions-across-readline issue was fixed by the previous commit.
Let's try this again.

gdb/ChangeLog:
2016-04-22  Pedro Alves  <palves@redhat.com>

	* common/common-exceptions.h (GDB_XCPT_TRY): Remove mention of
	the foreign frames issue.
	[__cplusplus] (GDB_XCPT): Define as GDB_XCPT_TRY.
2016-04-22 16:20:49 +01:00
Pedro Alves 89525768cd Propagate GDB/C++ exceptions across readline using sj/lj-based TRY/CATCH
If we map GDB'S TRY/CATCH macros to C++ try/catch, GDB breaks on
systems where readline isn't built with exceptions support.  The
problem is that readline calls into GDB through the callback
interface, and if GDB's callback throws a C++ exception/error, the
system unwinder won't manage to unwind past the readline frame, and
ends up calling std::terminate(), which aborts the process:

 (gdb) whatever-command-that-causes-an-error
 terminate called after throwing an instance of 'gdb_exception_RETURN_MASK_ERROR'
 Aborted
 $

This went unnoticed for so long because:

- the x86-64 ABI requires -fasynchronous-unwind-tables, making it
  possible for exceptions to cross readline with no special handling.
  But e.g., on ARM or AIX, unless you build readline with
  -fexceptions, you trip on the problem.

- TRY/CATCH was mapped to setjmp/longjmp, even in C++ mode, until
  quite recently.

The fix is to catch and save any GDB exception that is thrown inside
the GDB readline callback, and then once the callback returns back to
the GDB code that called into readline in the first place, rethrow the
saved GDB exception.

This is similar in spirit to how we catch/map GDB exceptions at the
GDB/Python and GDB/Guile API boundaries.

The next question is then: if we intercept all exceptions within GDB's
readline callback, should we simply return normally to readline?  The
callback prototype has no way to signal an error back to readline (*).
The answer is no -- if we return normally, we'll be returning to a
loop inside rl_callback_read_char that continues processing pending
input, calling into GDB again, redisplaying the prompt, etc.  Thus if
we want to error out of rl_callback_read_char, we need to long jump
across it, just like we always did before TRY/CATCH were ever mapped
to C++ exceptions.

My first approach built a specialized API to handle this, with a
couple macros to hide the setjmp/longjmp and the struct gdb_exception
saving/rethrowing.

However, I realized that we need to:

 - Handle multiple active rl_callback_read_char invocations.  If,
   while processing input something triggers a secondary prompt, we
   end up in a nested rl_callback_read_char call, through
   gdb_readline_wrapper.

 - Propagate a struct gdb_exception along with the longjmp.

... and that this is exactly what the setjmp/longjmp-based TRY/CATCH
does.

So the fix makes the setjmp/longjmp TRY/CATCH always available under
new TRY_SJLJ/CATCH_SJLJ aliases, even when TRY/CATCH is mapped to C++
try/catch, and then uses TRY_SJLJ/CATCH_SJLJ to propagate GDB
exceptions across the readline callback.

This turns out to be a much better looking fix than my bespoke API
attempt, even.  We'll probably be able to simplify TRY_SJLJ/CATCH_SJLJ
when we finally get rid of TRY/CATCH all over the tree, but until
then, this reuse seems quite nice for avoiding a second parallel
setjmp/longjmp mechanism.

(*) - maybe we could propose a readline API change, but we still need
      to handle current readline, anyway.

gdb/ChangeLog:
2016-04-22  Pedro Alves  <palves@redhat.com>

	* common/common-exceptions.c (enum catcher_state, struct catcher)
	(current_catcher): Define in C++ mode too.
	(exceptions_state_mc_catch): Call throw_exception_sjlj instead of
	throw_exception.
	(throw_exception_sjlj, throw_exception_cxx): New functions,
	factored out from throw_exception.
	(throw_exception): Reimplement.
	* common/common-exceptions.h (exceptions_state_mc_init)
	(exceptions_state_mc_action_iter)
	(exceptions_state_mc_action_iter_1, exceptions_state_mc_catch):
	Declare in C++ mode too.
	(TRY): Rename to ...
	(TRY_SJLJ): ... this.
	(CATCH): Rename to ...
	(CATCH_SJLJ): ... this.
	(END_CATCH): Rename to ...
	(END_CATCH_SJLJ): ... this.
	[GDB_XCPT == GDB_XCPT_SJMP] (TRY, CATCH, END_CATCH): Map to SJLJ
	equivalents.
	(throw_exception): Update comments.
	(throw_exception_sjlj): Declare.
	* event-top.c (gdb_rl_callback_read_char_wrapper): Extend intro
	comment.  Wrap body in TRY_SJLJ/CATCH_SJLJ and rethrow any
	intercepted exception.
	(gdb_rl_callback_handler): New function.
	(gdb_rl_callback_handler_install): Always install
	gdb_rl_callback_handler as readline callback.
2016-04-22 16:20:04 +01:00
Pedro Alves 3c610247ab Rename rl_callback_read_char_wrapper -> gdb_rl_callback_read_char_wrapper
Use the "gdb_rl_" prefix like other gdb readline function wrappers to
make it clear this is a gdb function, not a readline function.

gdb/ChangeLog:
2016-04-22  Pedro Alves  <palves@redhat.com>

	* event-top.c (rl_callback_read_char_wrapper): Rename to ...
	(gdb_rl_callback_read_char_wrapper): ... this.
	(change_line_handler, gdb_setup_readline): Adjust.
2016-04-22 16:18:33 +01:00
Yao Qi 3539aa13fb [ARM] Clear reserved bits in CPSR
Bits 20 ~ 23 of CPSR are reserved (RAZ, read as zero), but they are not
zero if the arm program runs on aarch64-linux.  AArch64 tracer gets PSTATE
from arm 32-bit tracee as CPSR, but bits 20 ~ 23 are used in PSTATE.  I
think kernel should clear these bits when it is read through ptrace, but
the fix in user space is still needed.

This patch fixes these two fails,

-FAIL: gdb.reverse/insn-reverse.exp: ext_reg_push_pop: compare registers on insn 0:vldr	d7, [r11, #-12]
-FAIL: gdb.reverse/insn-reverse.exp: ext_reg_push_pop: compare registers on insn 0:vldr	d7, [r7]

gdb:

2016-04-22  Yao Qi  <yao.qi@linaro.org>

	* aarch32-linux-nat.c (aarch32_gp_regcache_supply): Clear CPSR
	bits 20 to 23.

gdb/gdbserver:

2016-04-22  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch32-low.c (arm_store_gregset): Clear CPSR bits 20
	to 23.
2016-04-22 15:54:43 +01:00
Yao Qi 495346f6f0 Fix fail in gdb.base/annota1.exp and gdb.base/annota3.exp
Hi,

I am seeing the fail below on aarch64-linux with gcc 4.9.2,

break main
Breakpoint 1 at 0x4006e8: file binutils-gdb/gdb/testsuite/gdb.base/annota1.c, line 14.^M
(gdb) FAIL: gdb.base/annota1.exp: breakpoint main

the test expects the breakpoint is set on line 15.  Let us look at
the main function,

12	int
13	main (void)
14	{
15	  int my_array[3] = { 1, 2, 3 };  /* break main */
16
17	  value = 7;
18
19	#ifdef SIGUSR1
20	  signal (SIGUSR1, handle_USR1);
21	#endif

(gdb) disassemble main
Dump of assembler code for function main:
   0x00000000004006e0 <+0>:	stp	x29, x30, [sp,#-48]!
   0x00000000004006e4 <+4>:	mov	x29, sp
   0x00000000004006e8 <+8>:	adrp	x0, 0x411000 <signal@got.plt>
   0x00000000004006ec <+12>:	add	x0, x0, #0x40

the breakpoint is set on the right address after skipping prologue, but
0x00000000004006e8 is mapped to the line 14, as shown below,

(gdb) maintenance info line-table
objfile: /home/yao.qi/source/build-aarch64/gdb/testsuite/outputs/gdb.base/annota1/annota1 ((struct objfile *) 0x2b0e1850)
compunit_symtab: ((struct compunit_symtab *) 0x2b0ded50)
symtab: /home/yao.qi/source/binutils-gdb/gdb/testsuite/gdb.base/annota1.c ((struct symtab *) 0x2b0dedd0)
linetable: ((struct linetable *) 0x2b12c8b0):
INDEX    LINE ADDRESS
0           7 0x00000000004006d0
1           8 0x00000000004006d8
2          14 0x00000000004006e0
3          14 0x00000000004006e8
4          15 0x00000000004006fc

so GDB does nothing wrong.  Program hits breakpoint on either line 14
or line 15 is right to me.  With anther gcc (4.9.3), the line-table looks
correct, and no test fail.  Instead of setting breakpoint on main and
assuming the line is what we get from the source, we can set breakpoint
on that line.  On the other hand, the test prints the values of the
array and check, so we need to set breakpoint on the line setting the
values of array and "next", rather than setting the breakpoint on main.

gdb/testsuite:

2016-04-22  Yao Qi  <yao.qi@linaro.org>

	* gdb.base/annota1.exp: Set breakpoint on line $main_line.
	* gdb.base/annota3.exp: Likewise.
2016-04-22 15:35:07 +01:00
Joel Brobecker 0f60e29b5a Joel Brobecker stepping down as AIX Maintainer
gdb/ChangeLog:

        * MAINTAINERS: Remove myself as AIX Maintainer.
2016-04-22 10:16:31 -04:00
Walfred Tedeschi 7915f48c28 [obv] [PR gdb/19980] Typo in gdbserver/configure.srv
Simple exchange of mpx-avx for avx-mpx.
Other occurrences were not found.

2016-04-22  Walfred Tedeschi  <walfred.tedeschi@intel.com>

gdb/gdbserver/ChangeLog:

	* configure.srv (srv_amd64_xmlfiles): Exchange
	i386/amd64-mpx-avx.xml for i386/amd64-avx-mpx.xml.
2016-04-22 14:23:29 +02:00
Yao Qi 4a7e075c3f Tweak gdb.reverse/step-precsave.exp and gdb.reverse/step-reverse.exp
I see the following test fail in arm-linux with -marm and -fomit-frame-pointer,

 step
 callee () at /home/yao/SourceCode/gnu/gdb/git/gdb/testsuite/gdb.reverse/step-reverse.c:27
 27      }                       /* RETURN FROM CALLEE */
 (gdb) step
 main () at /home/yao/SourceCode/gnu/gdb/git/gdb/testsuite/gdb.reverse/step-reverse.c:58
 58         callee();    /* STEP INTO THIS CALL */
 (gdb) FAIL: gdb.reverse/step-precsave.exp: reverse step into fn call

As we can see, the "step" has already stepped into the function callee,
but in the last line.  The second "step" attempts to step to function
body, but it goes out of callee, which isn't expected.

The program is compiled with -marm and -fomit-frame-pointer, the
function callee is prologue-less, because nothing needs to be saved
on stack,

(gdb) disassemble callee
Dump of assembler code for function callee:
   0x00010680 <+0>:	movw	r3, #2364	; 0x93c
   0x00010684 <+4>:	movt	r3, #2
   0x00010688 <+8>:	ldr	r3, [r3]
   0x0001068c <+12>:	add	r2, r3, #1
   0x00010690 <+16>:	movw	r3, #2364	; 0x93c
   0x00010694 <+20>:	movt	r3, #2
   0x00010698 <+24>:	str	r2, [r3]
   0x0001069c <+28>:	mov	r3, #0
   0x000106a0 <+32>:	mov	r0, r3
   0x000106a4 <+36>:	bx	lr

program stops at the 0x106a0 (passed the epilogue) after the first
"step".  When second "step" is executed, the stepping range is
[0x10680-0x106a0], which starts from the first instruction of function
callee (because it doesn't have prologue).

infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [LWP 2461] at 0x1069c^M
infrun: prepare_to_wait^M
infrun: target_wait (-1.0.0, status) =^M
infrun:   2461.2461.0 [LWP 2461],^M
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP^M
infrun: TARGET_WAITKIND_STOPPED^M
infrun: stop_pc = 0x10698^M
infrun: stepping inside range [0x10680-0x106a0]

When program goes out of the range, it stops at the caller of callee,
and test fails.  IOW, if function callee has prologue, the stepping
range won't start from the first instruction of the function, and
program stops at the prologue and test passes.

IMO, GDB does nothing wrong, but test shouldn't expect the program
stops in callee after the second "step".  I decide to fix test rather
than GDB.  In this patch, I change to test to do one "step", and check
the program is still in callee, then, do multiple "step" until program
goes out of the callee.

gdb/testsuite:

2016-04-22  Yao Qi  <yao.qi@linaro.org>

	* gdb.reverse/step-precsave.exp: Do one step and test program
	stops in "callee" and do multiple steps until program goes out
	of "callee".
	* gdb.reverse/step-reverse.exp: Likewise.
2016-04-22 12:14:40 +01:00
Yao Qi 5b061e9886 Deliver signal in hardware single step
GDBserver doesn't deliver signal when stepping over a breakpoint even
hardware single step is used.  When GDBserver started to step over
(thread creation) breakpoint for mutlit-threaded debugging in 2002 [1],
GDBserver behaves this way.

This behavior gets trouble on conditional breakpoints on branch to
self instruction like this,

   0x00000000004005b6 <+29>:	jmp    0x4005b6 <main+29>

and I set breakpoint

$(gdb) break branch-to-self.c:43 if counter > 3

and the variable counter will be set to 5 in SIGALRM signal handler.
Since GDBserver keeps stepping over breakpoint, the SIGALRM can never
be dequeued and delivered to the inferior, so the program can't stop.
The test can be found in gdb.base/branch-to-self.exp.

GDBserver didn't deliver signal when stepping over a breakpoint because
a tracepoint is collected twice if GDBserver does so in the following
scenario, which can be reproduced by gdb.trace/signal.exp.

 - program stops at tracepoint, and tracepoint is collected,
 - gdbserver starts a step-over,
 - a signal arrives, step-over is canceled, and signal should be passed,
 - gdbserver starts a new step-over again, pass the signal as well,
 - program stops at the entry of signal handler, step-over finished,
 - gdbserver proceeds,
 - program returns from the signal handler, again to the tracepoint,
   and thus is collected again.

The spurious collection isn't that harmful, IMO, so it should be OK
to let GDBserver deliver signal when stepping over a breakpoint.

gdb/gdbserver:

2016-04-22  Yao Qi  <yao.qi@linaro.org>

	* linux-low.c (lwp_signal_can_be_delivered): Don't deliver
	signal when stepping over breakpoint with software single
	step.

gdb/testsuite:

2016-04-22  Yao Qi  <yao.qi@linaro.org>

	* gdb.trace/signal.exp: Also pass if
	$tracepoint_hits($i) > $iterations.
2016-04-22 11:59:18 +01:00
Yao Qi 5c5dc57fcf New test case gdb.trace/signal.exp
This is to test whether GDBserver deliver signal to the inferior while
doing the step over.  Nowadays, GDBserver doesn't deliver signal, so
there won't be spurious collection, however, if GDBserver does deliver
signal, there might be spurious collection.

gdb/testsuite:

2016-04-22  Yao Qi  <yao.qi@linaro.org>

	* gdb.trace/signal.c: New file.
	* gdb.trace/signal.exp: New file.
2016-04-22 11:59:18 +01:00
Maciej W. Rozycki 3877922e56 MIPS: Go back with the default Linux # of registers to 90
Set the number of registers for non-XML-described Linux targets to 90,
reverting a change made here with the addition of DSP register support:

commit 1faeff088b
Author: Maciej W. Rozycki <macro@linux-mips.org>
Date:   Thu Mar 1 22:19:48 2012 +0000

and fixing a regression introduced for legacy `gdbserver' targets
causing a "Remote 'g' packet reply is too long" error message where the
amount of register data received with a `g' packet (90) exceeds the
maximum number of registers expected (79).

Update the setting for XML-described targets, reflecting the actual
number of registers which have been assigned numbers, matching the:

      gdb_assert (gdbarch_num_regs (gdbarch) <= MIPS_RESTART_REGNUM);

requirement in `mips_linux_init_abi'.

	gdb/
	* mips-tdep.c (mips_gdbarch_init): For GDB_OSABI_LINUX set
	`num_regs' to 90 rather than 79.  Where a target description is
	present adjust the setting appropriately.
2016-04-22 01:20:59 +01:00
Pedro Alves 88c3cd8dcb Switch gdb's TRY/CATCH to sjlj again
We don't currently handle the case of gdb's readline callback throwing
gdb C++ exceptions across a readline that wasn't built with
-fexceptions.  The end result is:

 (gdb) whatever-command-that-causes-an-error
 terminate called after throwing an instance of 'gdb_exception_RETURN_MASK_ERROR'
 Aborted
 $

Until that is fixed, revert back to sjlj-based exceptions again.

gdb/ChangeLog:
2016-04-21  Pedro Alves  <palves@redhat.com>

	* common/common-exceptions.h (GDB_XCPT_TRY): Add comment.
	(GDB_XCPT): Always define as GDB_XCPT_SJMP.
2016-04-21 17:28:58 +01:00
Pedro Alves 71829b1a3f Fix AIX gdb build with C++ compiler
We currently get:

 ../../src/gdb/aix-thread.c: In function 'int pdc_read_data(pthdb_user_t, void*, pthdb_addr_t, size_t)':
 ../../src/gdb/aix-thread.c:465:46: error: invalid conversion from 'void*' to 'gdb_byte* {aka unsigned char*}' [-fpermissive]
    status = target_read_memory (addr, buf, len);
					       ^


 ../../src/gdb/aix-thread.c: In function 'void aix_thread_resume(target_ops*, ptid_t, int, gdb_signal)':
 ../../src/gdb/aix-thread.c:1010:46: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
	 gdb_signal_to_host (sig), (void *) tid);
					       ^
 ../../src/gdb/aix-thread.c:243:1: error:   initializing argument 5 of 'int ptrace64aix(int, int, long long int, int, int*)' [-fpermissive]
  ptrace64aix (int req, int id, long long addr, int data, int *buf)


 ../../src/gdb/rs6000-nat.c: In function 'gdb_byte* rs6000_ptrace_ldinfo(ptid_t)':
 ../../src/gdb/rs6000-nat.c:596:36: error: invalid conversion from 'void*' to 'gdb_byte* {aka unsigned char*}' [-fpermissive]
    gdb_byte *ldi = xmalloc (ldi_size);
				     ^
 ../../src/gdb/rs6000-nat.c:615:36: error: invalid conversion from 'void*' to 'gdb_byte* {aka unsigned char*}' [-fpermissive]
	ldi = xrealloc (ldi, ldi_size);
				     ^

(and more instances of the same).

gdb/ChangeLog:
2016-04-21  Pedro Alves  <palves@redhat.com>

	* aix-thread.c (pdc_read_data, pdc_write_data): Add cast.
	(aix_thread_resume): Use PTRACE_TYPE_ARG5.
	* rs6000-nat.c (rs6000_ptrace64): Use PTRACE_TYPE_ARG5.
	(rs6000_ptrace_ldinfo): Change type of 'ldi' local to void
	pointer, and cast return to gdb_byte pointer.
2016-04-21 14:02:20 +01:00
Pedro Alves 3451269c41 Fix s390 GNU/Linux gdb and gdbserver builds
Now that gdb/gdbserver compile as C++ programs by default, the s390
GNU/Linux build started failing with:

 In file included from ../../src/gdb/common/common-defs.h:64:0,
		  from ../../src/gdb/defs.h:28,
		  from ../../src/gdb/s390-linux-nat.c:22:
 ../../src/gdb/s390-linux-nat.c: In function ‘void fetch_regset(regcache*, int, int, int, const regset*)’:
 ../../src/gdb/../include/libiberty.h:711:38: error: invalid conversion from ‘void*’ to ‘gdb_byte* {aka unsigned char*}’ [-fpermissive]
  # define alloca(x) __builtin_alloca(x)
				       ^
 ../../src/gdb/s390-linux-nat.c:297:19: note: in expansion of macro ‘alloca’
    gdb_byte *buf = alloca (regsize);
		    ^

etc.

gdb/ChangeLog:
2016-04-21  Pedro Alves  <palves@redhat.com>

	* s390-linux-nat.c (fetch_regset, store_regset, check_regset): Use
	void * instead of gdb_byte *.

gdb/gdbserver/ChangeLog:
2016-04-21  Pedro Alves  <palves@redhat.com>

	* linux-s390-low.c (s390_collect_ptrace_register)
	(s390_supply_ptrace_register, s390_get_hwcap): Use gdb_byte * and
	add casts.
	(s390_check_regset): Use void * instead of gdb_byte *.
2016-04-21 12:03:53 +01:00
Pedro Alves b36cec19e8 Add missing sentinel 'char *' casts in concat/reconcat calls
The wildebeest-debian-wheezy-i686 buildslave's build is broken due to:

 ../../binutils-gdb/gdb/python/python.c: In function void _initialize_python():
 ../../binutils-gdb/gdb/python/python.c:1709:36: error: missing sentinel in function call [-Werror=format]

Reproduced on Fedora 23 by sticking a few:

 #undef NULL
 #define 0

in build/gdb/build-gnulib/{stddef|signal|stdio}.h.  Hopefully this
caught all instances.

gdb/ChangeLog:
2016-04-21  Pedro Alves  <palves@redhat.com>

	* dwarf2read.c (try_open_dwop_file, open_dwo_file)
	(file_file_name, file_full_name): Add char * cast to sentinel in
	concat/reconcat calls.
	* event-top.c (top_level_prompt): Likewise.
	* guile/guile.c (initialize_scheme_side): Likewise.
	* linux-tdep.c (linux_fill_prpsinfo): Likewise.
	* macrotab.c (macro_source_fullname): Likewise.
	* main.c (get_init_files, captured_main): Likewise.
	* psymtab.c (psymtab_to_fullname): Likewise.
	* python/python.c (_initialize_python)
	(gdbpy_finish_initialization): Likewise.
	* source.c (symtab_to_fullname): Likewise.
2016-04-21 11:34:18 +01:00
Pedro Alves a23585089d Build GDB as a C++ program by default
This makes --enable-build-with-cxx be "yes" by default.

One must now configure with --enable-build-with-cxx=no in order to
build with a C compiler.

gdb/ChangeLog:
2016-04-20  Pedro Alves  <palves@redhat.com>

	* build-with-cxx.m4 (GDB_AC_BUILD_WITH_CXX): Default to yes.
	* configure: Renegerate.

gdb/gdbserver/ChangeLog:
2016-04-20  Pedro Alves  <palves@redhat.com>

	* configure: Renegerate.
2016-04-20 23:20:15 +01:00
Pedro Alves 5ae0055212 Fix host signal vs gdb signal mixup in gdb/darwin-nat.c
Building in C++ mode caught a bug here:

 .../src/gdb/darwin-nat.c: In function 'ptid_t darwin_decode_message(mach_msg_header_t*, darwin_thread_t**, inferior**, target_waitstatus*)':
 .../src/gdb/darwin-nat.c:1016:25: error: invalid conversion from 'int' to 'gdb_signal' [-fpermissive]
      status->value.sig = WTERMSIG (wstatus);
			  ^

gdb/ChangeLog:
2016-04-20  Pedro Alves  <palves@redhat.com>

	* darwin-nat.c (darwin_decode_message): Use gdb_signal_from_host.
2016-04-20 23:01:54 +01:00
Pedro Alves d9436c7c71 Fix "incompatible pointer type" warning in gdb/aarch64-tdep.c
Fixes, with x86_64-apple-darwin15-gcc (gcc 5.3.0):

 .../src/gdb/aarch64-tdep.c: In function 'aarch64_record_load_store':
 .../src/gdb/aarch64-tdep.c:3479:67: error: passing argument 3 of 'regcache_raw_read_unsigned' from incompatible pointer type [-Werror=incompatible-pointer-types]
		       bits (aarch64_insn_r->aarch64_insn, 16, 20), &reg_rm_val);
								    ^
 In file included from .../src/gdb/regcache.h:23:0,
		  from .../src/gdb/gdbarch.h:69,
		  from .../src/gdb/defs.h:620,
		  from .../src/gdb/aarch64-tdep.c:21:
 .../src/gdb/common/common-regcache.h:60:29: note: expected 'ULONGEST * {aka long unsigned int *}' but argument is of type 'uint64_t * {aka long long unsigned int *}'
  extern enum register_status regcache_raw_read_unsigned
			      ^

gdb/ChangeLog:
2016-04-20  Pedro Alves  <palves@redhat.com>

	* aarch64-tdep.c (aarch64_record_load_store): Change type of
	'reg_rm_val' local to ULONGEST.
2016-04-20 22:52:50 +01:00
Pedro Alves 597e448caf gdb/darwin-nat.c: Fix "cast to pointer from integer of different size" warning
Fixes, with gcc 5.3.0:

 .../src/gdb/darwin-nat.c: In function 'void darwin_resume_thread(inferior*, darwin_thread_t*, int, int)':
 .../src/gdb/darwin-nat.c:731:21: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     (caddr_t)thread->gdb_port, nsignal);
		      ^
 .../src/gdb/darwin-nat.c:84:35: note: in definition of macro 'PTRACE'
   darwin_ptrace(#CMD, CMD, (PID), (ADDR), (SIG))
				    ^

thread->gdb_port is an unsigned int, caddr_t is a void pointer.

gdb/ChangeLog:
2016-04-20  Pedro Alves  <palves@redhat.com>

	* darwin-nat.c (darwin_resume_thread): Add uintptr_t cast.
2016-04-20 21:42:57 +01:00
Doug Evans 6c739336e5 symmisc.c (dump_symtab_1): Print owning compunit for identical blockvectors.
* symmisc.c (dump_symtab_1): Print owning compunit for identical
	blockvectors.
2016-04-20 10:17:12 -07:00
Yao Qi 8cef59a2e3 Include arch/arm-linux.h in aarch32-linux-nat.c
Fix the compilation failure by including arch/arm-linux.h in
aarch32-linux-nat.c.

gdb:

2016-04-20  Yao Qi  <yao.qi@linaro.org>

	* aarch32-linux-nat.c: Include "arch/arm-linux.h".
2016-04-20 15:02:54 +01:00
Yao Qi 6885166d99 Move ARM_CPSR_GREGNUM to arch/arm-linux.h
This patch moves macro ARM_CPSR_GREGNUM to arch/arm-linux.h so that it
can be used in GDBserver side.

gdb:

2016-04-20  Yao Qi  <yao.qi@linaro.org>

	* arm-linux-tdep.h (ARM_CPSR_GREGNUM): Move it to ...
	* arch/arm-linux.h: ... here.

gdb/gdbserver:

2016-04-20  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch32-low.c: Include "arch/arm-linux.h".
	(arm_fill_gregset): Use ARM_CPSR_GREGNUM rather than magic
	number 16.
	(arm_store_gregset): Likewise.
2016-04-20 12:32:15 +01:00
John Baldwin 21002a635b Handle void * conversions in FreeBSD/x86 native code to fix C++ build.
gdb/ChangeLog:

	* amd64bsd-nat.c (amd64bsd_fetch_inferior_registers): Change xstateregs
	to void *.
	(amd64bsd_store_inferior_registers): Likewise.
	* fbsd-nat.c (resume_one_thread_cb): Explicitly cast data to ptid_t *.
	(resume_all_threads_cb): Likewise.
	* i386bsd-nat.c (i386bsd_supply_gregset): Cast gregs to char *.
	(i386bsd_collect_gregset): Likewise.
	(i386bsd_fetch_inferior_registers): Change xstateregs to void *.
	(i386bsd_store_inferior_registers): Likewise.
2016-04-19 15:42:17 -07:00
John Baldwin f39c07acc8 Cast the pointer assigned to ss_sp to char *.
FreeBSD versions older than 11.0 use char * as the type of ss_sp in
stack_t instead of the standards-defined void *.  C++ allows a char *
pointer to be converted to a void *, so it is safe to cast the return
value of xmalloc to char * if ss_sp is either a char * or void *.
Just always use the cast to char * since that is less ugly than having
to add a special case.

gdb/ChangeLog:

	* main.c (setup_alternate_signal_stack): Cast to char *.
2016-04-19 15:41:56 -07:00
Doug Evans ee2915c993 Add pr number to earlier entry. 2016-04-19 09:57:04 -07:00
Doug Evans d04c1a59f3 symmisc.c (dump_symtab_1, dump_symtab): Delete arg objfile.
gdb/ChangeLog:

	* symmisc.c (dump_symtab_1, dump_symtab): Delete arg objfile.
	All callers updated.
2016-04-19 09:52:45 -07:00
Doug Evans 85c10f77b7 Fix copyright year, remove linux only test. 2016-04-19 09:06:53 -07:00
Doug Evans a55411b9ff * source.c (is_regular_file): New arg errno_ptr.
gdb/ChangeLog:

	* source.c (is_regular_file): New arg errno_ptr.
	All callers updated.

gdb/testsuite/ChangeLog:

	* gdb.base/bad-file.exp: New file.
2016-04-19 09:01:44 -07:00
Andreas Arnez 73e6209fae linux-record: Squash cases with identical handling
In record_linux_system_call there are some cases with identical
handling.  These are merged together to reduce code duplication.

gdb/ChangeLog:

	* linux-record.c (record_linux_system_call): Merge handling for
	readlink/recv/read and pipe/pipe2.
2016-04-19 16:53:40 +02:00
Walfred Tedeschi f42bf748e4 Re-factor (i386|amd64)mpx target descriptions.
In the previous patch a new set of target descriptions
(i386|amd64)-avx-mpx were added  being same as the (i386|amd64)-mpx.
This patch removes AVX feature from  (i386|amd64)-mpx target
description set.

This way the (i386|amd64)avx_mpx(_linux|) set has AVX and MPX features
and (i386|amd64)mpx(_linux|) only MPX.

2016-04-14  Walfred Tedeschi  <walfred.tedeschi@intel.com>

	* features/i386/amd64-mpx-linux.xml: Remove AVX feature.
	* features/i386/amd64-mpx.xml: Remove AVX feature.
	* features/i386/i386-mpx-linux.xml: Remove AVX feature.
	* features/i386/i386-mpx.xml: Remove AVX feature.
	* features/i386/amd64-mpx-linux.c: Regenerate.
	* features/i386/amd64-mpx.c: Regenerate.
	* features/i386/i386-mpx-linux.c: Regenerate.
	* features/i386/i386-mpx.c: Regenerate.
	* regformats/i386/amd64-mpx-linux.dat: Regenerate.
	* regformats/i386/amd64-mpx.dat: Regenerate.
	* regformats/i386/i386-mpx-linux.dat: Regenerate.
	* regformats/i386/i386-mpx.dat: Regenerate.
2016-04-19 15:45:50 +02:00
Walfred Tedeschi 2b863f512d Add target descriptions for AVX + MPX
The current MPX target descriptions assume that MPX is always combined
with AVX, however that's not correct.  We can have machines with MPX
and without AVX; or machines with AVX and without MPX.

This patch adds new target descriptions for machines that support
both MPX and AVX, as duplicates of the existing MPX descriptions.

The following commit will remove AVX from the MPX-only descriptions.


2016-04-16  Walfred Tedeschi  <walfred.tedeschi@intel.com>

gdb/ChangeLog:

	* amd64-linux-tdep.c (features/i386/amd64-avx-mpx-linux.c):
	New include.
	(amd64_linux_core_read_description): Add case for
	 X86_XSTATE_AVX_MPX_MASK.
	(_initialize_amd64_linux_tdep): Call initialize_tdesc_amd64_avx_mpx_linux.
	* amd64-linux-tdep.h (tdesc_amd64_avx_mpx_linux): New definition.
	* amd64-tdep.c (features/i386/amd64-avx-mpx.c): New include.
	(amd64_target_description): Add case for  X86_XSTATE_AVX_MPX_MASK.
	(_initialize_amd64_tdep): Call initialize_tdesc_amd64_avx_mpx.
	* common/x86-xstate.h (X86_XSTATE_MPX_MASK): Remove AVX bits.
	(X86_XSTATE_AVX_MPX_MASK): New case.
	* features/Makefile (i386/i386-avx-mpx, i386/i386-avx-mpx-linux)
	(i386/amd64-avx-mpx, i386/amd64-avx-mpx-linux): New rules.
	(i386/i386-avx-mpx-expedite, i386/i386-avx-mpx-linux-expedite)
	(i386/amd64-avx-mpx-expedite, i386/amd64-avx-mpx-linux-expedite):
	New expedites.
	* i386-linux-tdep.c (features/i386/i386-avx-mpx-linux.c): New
	include.
	(i386_linux_core_read_description): Add case
	X86_XSTATE_AVX_MPX_MASK.
	(_initialize_i386_linux_tdep): Call
	initialize_tdesc_i386_avx_mpx_linux.
	* i386-linux-tdep.h (tdesc_i386_avx_mpx_linux): New include.
	* i386-tdep.c (features/i386/i386-avx-mpx.c): New include.
	(i386_target_description): Add case for X86_XSTATE_AVX_MPX_MASK.
	* x86-linux-nat.c (x86_linux_read_description): Add case for
	X86_XSTATE_AVX_MPX_MASK.
	* features/i386/amd64-avx-mpx-linux.xml: New file.
	* features/i386/i386-avx-mpx-linux.xml: New file.
	* features/i386/i386-avx-mpx.xml: New file.
	* features/i386/amd64-avx-mpx.xml: New file.
	* features/i386/amd64-avx-mpx-linux.c: Generated.
	* features/i386/amd64-avx-mpx.c: Generated.
	* features/i386/i386-avx-mpx-linux.c: Generated.
	* features/i386/i386-avx-mpx.c: Generated.
	* regformats/i386/amd64-avx-mpx-linux.dat: Generated.
	* regformats/i386/amd64-avx-mpx.dat: Generated.
	* regformats/i386/i386-avx-mpx-linux.dat: Generated.
	* regformats/i386/i386-avx-mpx.dat: Generated.

gdb/gdbserver/ChangeLog:

	* Makefile.in (clean): Add removal for i386-avx-mpx.c,
	i386-avx-mpx-linux.c, amd64-avx-mpx.c and amd64-avx-mpx-linux.c.
	(i386-avx-mpx.c, i386-avx-mpx-linux.c, amd64-avx-mpx.c)
	(amd64-avx-mpx-linux.c): New rules.
	(amd64-avx-mpx-linux-ipa.o, i386-avx-mpx-linux-ipa.o): New rule.
	* configure.srv (srv_i386_regobj): Add i386-avx-mpx.o.
	(srv_i386_linux_regobj): Add i386-avx-mpx-linux.o.
	(srv_amd64_regobj): Add amd64-avx-mpx.o.
	(srv_amd64_linux_regobj): Add amd64-avx-mpx-linux.o.
	(srv_i386_xmlfiles): Add i386/i386-avx-mpx.xml.
	(srv_amd64_xmlfiles): Add i386/amd64-avx-mpx.xml.
	(srv_i386_linux_xmlfiles): Add i386/i386-avx-mpx-linux.xml.
	(srv_amd64_linux_xmlfiles): Add i386/amd64-avx-mpx-linux.xml.
	(ipa_i386_linux_regobj): Add i386-avx-mpx-linux-ipa.o.
	(ipa_amd64_linux_regobj): Add amd64-avx-mpx-linux-ipa.o.
	* linux-x86-low.c (x86_linux_read_description): Add case for
	X86_XSTATE_AVX_MPX_MASK.
	(x86_get_ipa_tdesc_idx): Add cases for avx_mpx.
	(initialize_low_arch): Call init_registers_amd64_avx_mpx_linux and
	init_registers_i386_avx_mpx_linux.
	* linux-i386-ipa.c (get_ipa_tdesc): Add case for avx_mpx.
	(initialize_low_tracepoint): Call
	init_registers_i386_avx_mpx_linux.
	* linux-amd64-ipa.c (get_ipa_tdesc):  Add case for avx_mpx.
	(initialize_low_tracepoint): Call
	init_registers_amd64_avx_mpx_linux.
	* linux-x86-tdesc.h (X86_TDESC_AVX_MPX): New enum value.
	(init_registers_amd64_avx_mpx_linux, tdesc_amd64_avx_mpx_linux)
	(init_registers_i386_avx_mpx_linux, tdesc_i386_avx_mpx_linux): New
	declarations.
2016-04-19 15:44:32 +02:00
Pedro Alves 9b30624b65 Fix PR gdb/19250: ptrace prototype is not detected properly in C++ mode
The ptrace args/return types detection doesn't work properly in C++
mode, on non-GNU/Linux hosts.  For example, on gcc70 (NetBSD 5.1),
where the prototype is:

 int ptrace(int, __pid_t, void*, int);

configure misdetects it as:

 $ grep PTRACE_TYPE config.h
 #define PTRACE_TYPE_ARG1 int
 #define PTRACE_TYPE_ARG3 int *
 #define PTRACE_TYPE_ARG4 int
 /* #undef PTRACE_TYPE_ARG5 */
 #define PTRACE_TYPE_RET int

resulting in:

 ../../src/gdb/amd64bsd-nat.c: In function 'void amd64bsd_fetch_inferior_registers(target_ops*, regcache*, int)':
 ../../src/gdb/amd64bsd-nat.c:56: warning: dereferencing type-punned pointer will break strict-aliasing rules
 ../../src/gdb/amd64bsd-nat.c: In function 'void amd64bsd_store_inferior_registers(target_ops*, regcache*, int)':
 ../../src/gdb/amd64bsd-nat.c:104: warning: dereferencing type-punned pointer will break strict-aliasing rules
 ../../src/gdb/amd64bsd-nat.c:110: warning: dereferencing type-punned pointer will break strict-aliasing rules

We could address this [1], however despite ptrace.m4's claim:

 # Needs to be tested in C++ mode, to detect whether we need to cast
 # the first argument to enum __ptrace_request.

it appears that there's actually no need to test in C++ mode.  Always
running the ptrace tests in C mode works just the same on GNU/Linux.

I remember experimenting with several different ways to handle the
original issue back then, and maybe that was needed in some other
attempt and then I didn't realize it ended up not really necessary.

Confirmed that this fixes the NetBSD 5.1 C++ build, and confirmed that
C and C++ builds on Fedora 23 are unaffected.

[1] - https://sourceware.org/ml/gdb-patches/2016-04/msg00374.html

gdb/ChangeLog:
2016-04-18  Pedro Alves  <palves@redhat.com>

	* ptrace.m4 (GDB_AC_PTRACE): Don't run tests in C++ mode.
	* configure: Regenerate.

gdb/gdbserver/ChangeLog:
2016-04-18  Pedro Alves  <palves@redhat.com>

	* configure: Regenerate.
2016-04-18 17:42:50 +01:00
Martin Galvan a22df60ad2 Fix gdb crash when trying to print the address of a synthetic C++ reference
After compiling a program which uses C++ references some optimizations may
convert the references into synthetic "pointers".  Trying to print the address
of one of such synthetic references causes gdb to crash with the following
error:

(gdb) print &ref
/build/buildd/gdb-7.7.1/gdb/dwarf2loc.c:1624: internal-error: Should not be able to create a lazy value with an enclosing type
A problem internal to GDB has been detected,
further debugging may prove unreliable.

Apparently, what was causing it was that value_addr returns a copy of the value
that represents the reference with its type set to T* instead of T&.  However,
its enclosing_type is left untouched, which fails a check made in
read_pieced_value.  We only see the crash happen for references that are
synthetic because they're treated as pieced values, thus the call to
read_pieced_value.

On a related note, it seems that in general there are all sorts of breakage
when working with synthetic references.  This is reported here:

https://sourceware.org/bugzilla/show_bug.cgi?id=19893

gdb/ChangeLog:
2016-04-18  Martin Galvan  <martin.galvan@tallertechnologies.com>

	* valops.c (value_addr): For C++ references, set the copied value's
	enclosing_type as well.

gdb/testsuite/ChangeLog:
2016-04-18  Martin Galvan  <martin.galvan@tallertechnologies.com>

	* gdb.dwarf2/implref.exp: New file.
2016-04-18 10:58:14 -03:00
Bernhard Heckel 0c13f7e559 fortran: Testsuite, fix different type naming across compilers.
Gfortran and ifort have different names for data types.  Encapsulate
type names in a library to increase number of supported compilers.
gfortran -4.2 : int4
gfortran>=4.3 : integer(kind=4)
ifort         : INTEGER(4)

2016-04-18  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/testsuite/Changelog:
	* gdb.fortran/common-block.exp: Use type naming defined in lib fortran.
	* gdb.fortran/derived-type.exp: Use type naming defined in lib fortran.
	* gdb.fortran/multi-dim.exp: Use type naming defined in lib fortran.
	* gdb.fortran/vla-datatypes.exp: Use type naming defined in lib fortran.
	* gdb.fortran/vla-ptype-sub.exp: Use type naming defined in lib fortran.
	* gdb.fortran/vla-ptype.exp: Use type naming defined in lib fortran.
	* gdb.fortran/whatis_type.exp: Use type naming defined in lib fortran.
	* lib/fortran.exp (fortran_int4): New procedure.
	(fortran_real4, fortran_real8, fortran_complex4): Likewise.
	(fortran_logical4): Likewise.
2016-04-18 14:04:07 +02:00
Bernhard Heckel 9b9b09e902 Testsuite: Fix compiling of shared libraries with ICC.
We are missing "-fpic" flag when compiling shared libraries with ICC.

2016-04-18  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/Testsuite/Changelog:
	* lib/gdb.exp (gdb_compile_shlib): Add flag for ICC compiler.
2016-04-18 13:57:31 +02:00
Bernhard Heckel a14d1f4dfc testsuite: Support detection of Intel compilers via test_compiler_version.
Add Intel specific preprocessor macros to query the version of the compiler.

2016-04-18  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/Testsuite/Changelog:
	* lib/compiler.c: Add Intel specific preprocessor macros.
	* lib/compiler.cc: Likewise.
2016-04-18 13:52:43 +02:00
Yao Qi 5947319ef3 Revert 415fa612
2016-04-18  Yao Qi  <yao.qi@linaro.org>

	Revert:
	2016-04-15  Yao Qi  <yao.qi@linaro.org>

	* arm-tdep.c (thumb_stack_frame_destroyed_p): Return zero if
	PC is far from the end of function.
2016-04-18 08:50:09 +01:00
Pedro Alves 58484447ed gdb/ada-exp.y: Remap yydefred
On:

 $ uname -a
 NetBSD gcc70.fsffrance.org 5.1 NetBSD 5.1 (GENERIC) #0: Sat Nov  6 13:19:33 UTC 2010  builds@b6.netbsd.org:/home/builds/ab/netbsd-5-1-RELEASE/amd64/201011061943Z-obj/home/builds/ab/netbsd-5-1-RELEASE/src/sys/arch/amd64/compile/GENERIC amd64

The link fails with:

 (...)
 d-exp.o: In function `parse_number':
 ../../src/gdb/d-exp.y:762: multiple definition of `yydefred'
 ada-exp.o:/home/palves/gdb/build/gdb/ada-lex.c:925: first defined here
 ld: Warning: size of symbol `yydefred' changed from 464 in ada-exp.o to 336 in d-exp.o
 Makefile:1404: recipe for target 'gdb' failed

NetBSD's yacc uses a "yydefred" symbol that we missed renaming in the
Ada parser.  All other gdb parsers do this already.

gdb/ChangeLog:
2016-04-16  Pedro Alves  <palves@redhat.com>

	* ada-exp.y (yydefred): Define as ada_yydefred.
2016-04-16 01:24:08 +01:00
Pedro Alves 2b2798cc97 Fix gdb build with --enable-build-with-cxx --disable-nls
Compiling gdb with --enable-build-with-cxx --disable-nls, we get:

 .../src/gdb/ada-lang.c:7657:16: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
	type_str = (type != NULL
		 ^
 In file included from .../src/gdb/common/common-defs.h:67:0,
		  from .../src/gdb/defs.h:28,
		  from .../src/gdb/ada-lang.c:21:
 .../src/gdb/common/gdb_locale.h:40:27: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
  # define _(String) (String)
			    ^
 .../src/gdb/ada-lang.c:7730:46: note: in expansion of macro ‘_’
	char *name_str = name != NULL ? name : _("<null>");
					       ^
 Makefile:1140: recipe for target 'ada-lang.o' failed

gdb/ChangeLog:
2016-04-15  Pedro Alves  <palves@redhat.com>

	* ada-lang.c (ada_lookup_struct_elt_type): Constify 'type_str' and
	'name_str' locals.
2016-04-16 00:32:36 +01:00
Pedro Alves d7abe1019d Fix gdb C++ build when libipt is available
With libipt's headers installed, a build with --enable-build-with-cxx
fails with:

 .../src/gdb/btrace.c: In function ‘btrace_insn_flag pt_btrace_insn_flags(const pt_insn*)’:
 .../src/gdb/btrace.c:734:33: error: invalid conversion from ‘int’ to ‘btrace_insn_flag’ [-fpermissive]
    enum btrace_insn_flag flags = 0;
				  ^
 .../src/gdb/btrace.c:737:11: error: invalid conversion from ‘int’ to ‘btrace_insn_flag’ [-fpermissive]
      flags |= BTRACE_INSN_FLAG_SPECULATIVE;
	    ^

gdb/ChangeLog:
2016-04-15  Pedro Alves  <palves@redhat.com>

	* btrace.c (pt_btrace_insn_flags): Change return type to
	btrace_insn_flags.  Use btrace_insn_flags for local.
2016-04-16 00:29:08 +01:00
Pedro Alves 77770d8321 MIPS/Linux: Also recognize TRAP_BRKPT and TRAP_HWBKPT
This makes the MIPS Linux backends recognize TRAP_BRKPT and
TRAP_HWBKPT in siginfo.si_code in addition to SI_KERNEL, since Linux
4.6 now reports the finer-grained si_code values too.

Refs:
 https://sourceware.org/ml/gdb-patches/2016-02/msg00756.html
 https://sourceware.org/ml/gdb-patches/2016-04/msg00090.html

On kernels that report SI_KERNEL (<= 4.5), we'll enter the "ambiguous"
path of save_stop_reason:

	  if (GDB_ARCH_IS_TRAP_BRKPT (siginfo.si_code)
	      && GDB_ARCH_IS_TRAP_HWBKPT (siginfo.si_code))
	    {
	      /* The si_code is ambiguous on this arch -- check debug
		 registers.  */
	      if (!check_stopped_by_watchpoint (lp))
		lp->stop_reason = TARGET_STOPPED_BY_SW_BREAKPOINT;
	    }

while on kernels that report the finer-grained si_code values (>= 4.6),
we'll enter the corresponding branches:

	  else if (GDB_ARCH_IS_TRAP_BRKPT (siginfo.si_code))
	    {
	    }
	  else if (GDB_ARCH_IS_TRAP_HWBKPT (siginfo.si_code))
	    {
	      ...

gdb/ChangeLog:
2016-04-15  Pedro Alves  <palves@redhat.com>

	* nat/linux-ptrace.h [__mips__] (GDB_ARCH_IS_TRAP_BRKPT): Also
	accept TRAP_BRKPT.
	 [__mips__] (GDB_ARCH_IS_TRAP_HWBKPT): Also accept TRAP_HWBKPT.
2016-04-15 23:52:00 +01:00
Yao Qi 415fa61233 [ARM] minor opt in thumb_stack_frame_destroyed_p
thumb_stack_frame_destroyed_p scans the instructions from PC to the
end of the function, but if PC is far from the end of pc, we don't
have to scan, because PC should be in epilogue if it is still
far from the end of the function.  The criterion I use here is 16
bytes, which is more than 4 instructions.

Regression tested on aarch64-linux with mutli-arch debug.

gdb:

2016-04-15  Yao Qi  <yao.qi@linaro.org>

	* arm-tdep.c (thumb_stack_frame_destroyed_p): Return zero if
	PC is far from the end of function.
2016-04-15 15:30:01 +01:00
Pedro Alves 7f31862a8d Avoid "format not a string literal" warnings
On:

 $ uname -a
 NetBSD gcc70.fsffrance.org 5.1 NetBSD 5.1 (GENERIC) #0: Sat Nov  6 13:19:33 UTC 2010  builds@b6.netbsd.org:/home/builds/ab/netbsd-5-1-RELEASE/amd64/201011061943Z-obj/home/builds/ab/netbsd-5-1-RELEASE/src/sys/arch/amd64/compile/GENERIC amd64

With:

 $ g++ -v
 Using built-in specs.
 Target: x86_64--netbsd
 Configured with: /usr/src/tools/gcc/../../gnu/dist/gcc4/configure --enable-long-long --disable-multilib --enable-threads --disable-symvers --build=x86_64-unknown-netbsd4.99.72 --host=x86_64--netbsd --target=x86_64--netbsd --enable-__cxa_atexit
 Thread model: posix
 gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)

I saw:

 cc1plus: warnings being treated as errors
 ../../src/gdb/ctf.c: In function 'void ctf_save_metadata_header(trace_write_handler*)':
 ../../src/gdb/ctf.c:267: warning: format not a string literal, argument types not checked
 cc1plus: warnings being treated as errors
 ../../src/gdb/cli/cli-cmds.c: In function 'void alias_command(char*, int)':
 ../../src/gdb/cli/cli-cmds.c:1428: warning: format not a string literal and no format arguments
 ../../src/gdb/cli/cli-cmds.c:1457: warning: format not a string literal and no format arguments

gdb/ChangeLog:
2016-04-14  Pedro Alves  <palves@redhat.com>

	* cli/cli-cmds.c (alias_usage_error): New function.
	(alias_command): Use it.
	* ctf.c (ctf_save_metadata_header): Inline metadata_fmt local in
	ctf_save_write_metadata call.
2016-04-14 12:59:01 +01:00
Pedro Alves aebf07fc14 Avoid implicit float <-> integer conversion warnings
On:

 $ uname -a
 NetBSD gcc70.fsffrance.org 5.1 NetBSD 5.1 (GENERIC) #0: Sat Nov  6 13:19:33 UTC 2010  builds@b6.netbsd.org:/home/builds/ab/netbsd-5-1-RELEASE/amd64/201011061943Z-obj/home/builds/ab/netbsd-5-1-RELEASE/src/sys/arch/amd64/compile/GENERIC amd64

With:

 $ g++ -v
 Using built-in specs.
 Target: x86_64--netbsd
 Configured with: /usr/src/tools/gcc/../../gnu/dist/gcc4/configure --enable-long-long --disable-multilib --enable-threads --disable-symvers --build=x86_64-unknown-netbsd4.99.72 --host=x86_64--netbsd --target=x86_64--netbsd --enable-__cxa_atexit
 Thread model: posix
 gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)

I saw:

 ../../src/gdb/ada-typeprint.c: In function 'void print_fixed_point_type(type*, ui_file*)':
 ../../src/gdb/ada-typeprint.c:366: warning: passing 'float' for argument 2 to 'DOUBLEST ada_fixed_to_float(type*, LONGEST)'

 ../../src/gdb/value.c: In function 'LONGEST unpack_long(type*, const gdb_byte*)':
 ../../src/gdb/value.c:2833: warning: converting to 'LONGEST' from 'DOUBLEST'
 ../../src/gdb/value.c:2838: warning: converting to 'LONGEST' from 'DOUBLEST'

gdb/ChangeLog:
2016-04-14  Pedro Alves  <palves@redhat.com>

	* ada-typeprint.c (print_fixed_point_type): Don't pass float as
	argument to function expecting LONGEST.
	* value.c (unpack_long): Add casts to LONGEST.
2016-04-14 12:58:03 +01:00
Luis Machado 7d49b1d0b0 Test GDB connection to GDBserver with no symbol files
This test exercises the scenarios where we attempt to connect GDB to GDBserver
in standard remote mode, query the symbol file path, attempt to open said
symbol file on GDB's end and fail, causing the connection to drop abruptly.

Regression-tested on x86-64/Ubuntu.

With an unpatched GDB we should see this:

FAIL: gdb.server/connect-with-no-symbol-file.exp: sysroot=: action=permission: connection to GDBserver succeeded (the program is no longer running)
FAIL: gdb.server/connect-with-no-symbol-file.exp: sysroot=: action=delete: connection to GDBserver succeeded (the program is no longer running)
FAIL: gdb.server/connect-with-no-symbol-file.exp: sysroot=target:: action=permission: connection to GDBserver succeeded (the program is no longer running)
FAIL: gdb.server/connect-with-no-symbol-file.exp: sysroot=target:: action=delete: connection to GDBserver succeeded (the program is no longer running)

A patched GDB should have full passes.

gdb/testsuite/ChangeLog:

2016-04-13  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.server/connect-with-no-symbol-file.c: New file.
	* gdb.server/connect-with-no-symbol-file.exp: New file.
2016-04-13 15:22:14 -05:00
Luis Machado 57d1de9cf3 Debugging without a binary (regression)
When we attempt to debug a process using GDBserver in standard remote mode
without a symbol file on GDB's end, we may run into an issue where GDB cuts
the connection attempt short due to an error. The error is caused by not
being able to open a symbol file, like so:

--

(gdb) set sysroot
(gdb) tar rem :2345
Remote debugging using :2345
/proc/23769/exe: Permission denied.
(gdb) i r
The program has no registers now.
(gdb)

It should've been like this:

(gdb) set sysroot
(gdb) tar rem :2345
Remote debugging using :2345
warning: /tmp/symbol-file: Permission denied.
0xf7ddb2d0 in ?? ()
(gdb) i r
eax            0x0  0
ecx            0x0  0
edx            0x0  0
ebx            0x0  0
esp            0xffffdfa0 0xffffdfa0
ebp            0x0  0x0
esi            0x0  0
edi            0x0  0
eip            0xf7ddb2d0 0xf7ddb2d0
eflags         0x200  [ IF ]
cs             0x33 51
ss             0x2b 43
ds             0x0  0
es             0x0  0
fs             0x0  0
gs             0x0  0
(gdb)

This is caused by a couple of function calls within exec_file_locate_attach
that can potentially throw errors.

The following patch guards both exec_file_attach and symbol_file_add_main to
prevent the errors from disrupting the connection process.

There was also a case where native GDB tripped on this problem, but it was
mostly fixed by bf74e428bc.

Regression-tested on x86-64/Ubuntu.

gdb/ChangeLog:

2016-04-13  Luis Machado  <lgustavo@codesourcery.com>

	* exec.c (exec_file_locate_attach): Guard a couple functions
	that can throw errors.
	(exception_print_same): New helper function.
2016-04-13 15:17:22 -05:00
Antoine Tremblay b8162e5ac9 Fix zero_ext documentation
This patch fixes the documentation for the zero_ext bytecode description.

It removes parts that seemed like a copy/paste from ext, since zero_ext
zeros the bits to the left.

gdb/doc/ChangeLog:

	* agentexpr.texi (zero_ext): Fix zero_ext description.
2016-04-13 12:36:24 -04:00
Simon Marchi 8392fa22d6 Fix and improve comment in gdb_remote_download
This patch fixes the current comment in gdb_remote_download, which is
false (the "except if that's already where it is" part).  It also
improves it, by explaining why pass TOFILE through standard_output_file,
even it is an absolute path.

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (gdb_remote_download): Fix and extend comment.
2016-04-13 10:47:29 -04:00
Simon Marchi 8c4c4aeba6 gdbserver-base.exp: Copy file to standard output directory in ${board}_download
gdbserver-base.exp is used as the base for both native-gdbserver.exp and
native-extended-gdbserver.exp.  (Despite its name, it should really be
considered as a "local-gdbserver-base", as it's not really appropriate to
implement a remote gdbserver board.)

Currently, the _download procedure is implemented as a no-op (it returns
the source file path).  Because of the SONAME change, The fast
tracepoint tests now require the executable and the IPA
(libinproctrace.so) to be located in the same directory (see [1]).  When
using the native-gdbserver board, because _download returns the original
file path, the executable does not end up in the same directory as the
library, and it fails to execute.

In more general terms, with the recent changes, the testsuite now
assumes that when it does

  ${board}_download <source path 1> <destination path 1>
  ${board}_download <source path 2> <destination path 2>

where the destination paths are relative (generally just the file name),
both files will end up in the same base directory.  That assumption does
not hold for the current implementation in gdbserver-base.exp.

The proper fix would be to make native-gdbserver non-remote, so that
gdb_remote_download would not call DejaGnu's remote_download (see [2]).
We could then get rid of ${board}_download in gdbserver-base.exp.
However, that will likely take some time to complete.  In the mean time,
in order to make the fast tracepoint tests pass, we can simply copy the
file to the standard output directory.  Basically, it just mimics what
gdb_remote_download would do if the board wasn't flagged as remote.

Note that I missed these failures originally because I had a
libinproctrace.so in /usr/local/lib.  So, even though libinproctrace.so
wasn't copied to the test output directory, it did find the one in
/usr/local/lib.  It would be nice to find a way to protect against this,
as it could easily happen again...

Regtested with unix, native-gdbserver and native-extended-gdbserver, and
didn't see anything notable, except the ftrace tests now passing for
native-gdbserver.

[1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=6e774b13c3b81ac2599812adf058796948ce7e95
[2] https://sourceware.org/ml/gdb-patches/2016-04/msg00112.html

gdb/testsuite/ChangeLog:

	* boards/gdbserver-base.exp (${board}_download): Copy source file to
	standard output directory.
2016-04-13 10:15:40 -04:00
Antoine Tremblay 45e3745ed0 Fix aarch64 ftrace JIT condition testcase
This patch fixes the following failure:
FAIL: gdb.trace/trace-condition.exp: ftrace: -(21 << 1) == -42: check 10
frames were collected.

This was due to aarch64_emit_sub using the wrong order in its operands, so the
operation would end up being 42 - 0 rather than 0 - 42.

This patch also fixes the order of aarch64_emit_add for clarity.

The test case for emit_sub is fixed so that the proper order of
the operands is needed for the test to pass.

Tested on aarch64-native-extended-gdbserver.

Note: trace-condition.exp was broken a bit so I had to modify it to run
the test. A fix is coming for that in another patch.

gdb/gdbserver/ChangeLog:

	* linux-aarch64-low.c (aarch64_emit_add): Switch x1 and x0.
	(aarch64_emit_sub): Likewise.

gdb/testsuite/ChangeLog:

	* gdb.trace/trace-condition.exp (foreach): Fix emit_sub testcase.
2016-04-13 09:40:00 -04:00
Pedro Alves 3a00c80277 Fix PR remote/19840: gdb crashes on reverse-stepi
Reverse debugging against a remote target that does reverse debugging
itself (with the bs/bc packets) always trips on:

 (gdb) target remote localhost:...
 (gdb) reverse-stepi
 ../../gdb/target.c:602: internal-error: default_execution_direction: to_execution_direction must be implemented for reverse async

I missed adding a to_execution_direction method to remote.c in commit
3223143295 (Adds target_execution_direction to make record targets
support async mode), GDB 7.4 time.  Later, GDB 7.8 switched to
target-async on by default, making the regression user-visible by
default too.

Fix is simply to add the missing to_execution_direction implementation
to target remote.

Tested by Andi Kleen against Simics.

gdb/ChangeLog:
2016-04-13  Pedro Alves  <palves@redhat.com>

	PR remote/19840
	* remote.c (struct remote_state) <last_resume_exec_dir>: New
	field.
	(new_remote_state): Default last_resume_exec_dir to EXEC_FORWARD.
	(remote_open_1): Reset last_resume_exec_dir to EXEC_FORWARD.
	(remote_resume): Store the last execution direction.
	(remote_execution_direction): New function.
	(init_remote_ops): Install it as to_execution_direction target_ops
	method.
2016-04-13 14:34:00 +01:00
Markus Metzger e26b7e4165 btrace: fix test build error in gdb.btrace/instruction_history.c
On systems with a newer version of GCC the gdb.btrace/instruction_history.exp
test fails to build like this:

    Running .../gdb.btrace/instruction_history.exp ...
    gdb compile failed, .../gdb.btrace/instruction_history.c:
    In function 'main': .../gdb.btrace/instruction_history.c:24:3: warning:
    implicit declaration of function 'loop' [-Wimplicit-function-declaration]
       loop ();
       ^

Declare loop to fix it.

testsuite/
	* gdb.btrace/instruction_history.c (loop): Add declaration.
2016-04-13 15:01:14 +02:00
Antoine Tremblay 8ce0946295 Fix typo in ftrace.exp condition testing
This obvious patch replaces "ond" wiht "cond" as the test prefix for
conditional tests.

gdb/testsuite/ChangeLog:

	* gdb.trace/ftrace.exp (proc): Change test prefix from "ond" to "cond".
2016-04-12 15:06:42 -04:00
Pedro Alves 0f41b320ed [C++] Switch TRY/CATCH to real C++ try/catch by default again
Now that we don't ever throw GDB exceptions from signal handlers [1],
we can switch back to having TRY/CATCH implemented in terms of C++
try/catch instead of sigjmp/longjmp.

[1] - https://sourceware.org/ml/gdb-patches/2016-03/msg00351.html

Tested on x86_64 Fedora 23, native and gdbserver.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* common/common-exceptions.h (GDB_XCPT_TRY): Update comment.
	[__cplusplus] (GDB_XCPT): Define as GDB_XCPT_TRY.
2016-04-12 17:49:24 +01:00
Pedro Alves 173981bc49 Use setjmp/longjmp for TRY/CATCH instead of sigsetjmp/siglongjmp
Now that we don't ever throw GDB exceptions from signal handlers [1],
we can switch to have TRY/CATCH implemented in terms of plain
setjmp/longjmp instead of sigsetjmp/siglongjmp.

In https://sourceware.org/ml/gdb-patches/2015-02/msg00114.html, Yichun
Zhang mentions a 11%/14%+ speedup in his GDB python scripts with a
patch that did something similar to only a specific set of TRY/CATCH
calls.

[1] - https://sourceware.org/ml/gdb-patches/2016-03/msg00351.html

Tested on x86_64 Fedora 23, native and gdbserver.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* common/common-exceptions.c (struct catcher) <buf>: Now a
	'jmp_buf' instead of SIGJMP_BUF.
	(exceptions_state_mc_init): Change return type to 'jmp_buf'.
	(throw_exception): Use longjmp instead of SIGLONGJMP.
	* common/common-exceptions.h: Include <setjmp.h> instead of
	"gdb_setjmp.h".
	(exceptions_state_mc_init): Change return type to 'jmp_buf'.
	[GDB_XCPT == GDB_XCPT_SJMP] (TRY): Use setjmp instead of
	SIGSETJMP.
	* cp-support.c: Include "gdb_setjmp.h".
2016-04-12 17:20:04 +01:00
Pedro Alves 2afc13ff80 Eliminate prepare_to_throw_exception
No longer necessary.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* common/common-exceptions.c (exception_rethrow): Remove
	prepare_to_throw_exception call.
	* common/common-exceptions.h (prepare_to_throw_exception): Delete
	declaration.
	* exceptions.c (prepare_to_throw_exception): Delete.

gdb/gdbserver/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* utils.c (prepare_to_throw_exception): Delete.
2016-04-12 17:17:13 +01:00
Pedro Alves cfd0fbddb0 Eliminate target_check_pending_interrupt
This is no longer called anywhere.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* target.c (target_check_pending_interrupt): Delete.
	* target.h (struct target_ops) <to_check_pending_interrupt>:
	Remove method.
	(target_check_pending_interrupt): Remove declaration.
	* target-delegates.c: Regenerate.
2016-04-12 17:02:06 +01:00
Pedro Alves 585a46a2d0 Eliminate immediate_quit
This finally gets rid of immediate_quit (and surrounding
infrustruture), as nothing sets it anymore.

gdb_call_async_signal_handler was only necessary in order to handle
immediate_quit.  We can just call mark_async_signal_handler directly
on all hosts now.

In turn, we can clean up mingw-hdep.c's gdb_select a bit, as
sigint_event / sigint_handler is no longer needed.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* defs.h: Update comments on SIGINT handling.
	(immediate_quit): Delete declaration.
	* event-loop.c (call_async_signal_handler): Delete.
	* event-loop.h (call_async_signal_handler): Delete declaration.
	(mark_async_signal_handler): Update comments.
	(gdb_call_async_signal_handler): Delete declaration.
	* event-top.c (handle_sigint): Call mark_async_signal_handler
	instead of gdb_call_async_signal_handler.
	* exceptions.c (prepare_to_throw_exception): Remove reference to
	immediate_quit.
	(exception_fprintf): Remove comments about immediate_quit.
	* mingw-hdep.c (sigint_event, sigint_handler): Delete.
	(gdb_select): Don't wait on sigint_event.
	(gdb_call_async_signal_handler): Delete.
	(_initialize_mingw_hdep): Delete.
	* posix-hdep.c (gdb_call_async_signal_handler): Delete.
	* utils.c (immediate_quit): Delete.
2016-04-12 17:01:44 +01:00
Pedro Alves 048094accc target remote: Don't rely on immediate_quit (introduce quit handlers)
remote.c is the last user of immediate_quit.  It's relied on to
immediately break the initial remote connection sync up, if the user
does Ctrl-C, assuming that was because the target isn't responding.
At that stage, since the connection isn't synced yet, disconnecting is
the only safe thing to do.  This commit reworks that, to not rely on
throwing from the SIGINT signal handler.

So, this commit:

- Introduces the concept of a "quit handler".  This is used to
  override what does the QUIT macro do when the quit flag is set.

- Makes the "struct serial" reachar / write code call QUIT in the
  partial read/write loops, so the current quit handler is invoked
  whenever a serial->read_prim / serial->write_prim returns EINTR.

- Makes the "struct serial" reachar / write code call
  interruptible_select instead of gdb_select, so that QUITs are
  detected in a race-free manner.

- Stops remote.c from setting immediate_quit during the initial
  connection.

- Instead, we install a custom quit handler whenever we're calling
  into the serial code.  This custom quit handler knows to immediately
  throw a quit when we're in the initial connection setup, and
  otherwise defer handling the quit/Ctrl-C request to later, when
  we're safely out of a packet command/response sequence.  This also
  is what is now responsible for handling "double Ctrl-C because
  target connection is stuck/wedged."

- remote.c no longer installs a specialized SIGINT handlers, and
  instead re-uses the quit flag.  Since we want to rely on the QUIT
  macro, the SIGINT handler must also set the quit.  And the easiest
  is just to not install custom SIGINT handler in remote.c.  Let the
  standard SIGINT handler do its job of setting the quit flag.
  Centralizing SIGINT handlers seems like a good thing to me, anyway.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* defs.h (quit_handler_ftype, quit_handler)
	(make_cleanup_override_quit_handler, default_quit_handler): New.
	(QUIT): Adjust comments.
	* event-top.c (default_quit_handler): New function.
	(quit_handler): New global.
	(struct quit_handler_cleanup_data): New.
	(restore_quit_handler, restore_quit_handler_dtor)
	(make_cleanup_override_quit_handler): New.
	(async_request_quit): Call QUIT.
	* remote.c (struct remote_state) <got_ctrlc_during_io>: New field.
	(async_sigint_remote_twice_token, async_sigint_remote_token):
	Delete.
	(remote_close): Update comments.
	(remote_start_remote): Don't set immediate_quit.  Set starting_up
	earlier.
	(remote_serial_quit_handler, remote_unpush_and_throw): New
	functions.
	(remote_open_1): Clear got_ctrlc_during_io.  Set
	remote_async_terminal_ours_p unconditionally.
	(async_initialize_sigint_signal_handler)
	(async_handle_remote_sigint, async_handle_remote_sigint_twice)
	(remote_check_pending_interrupt, async_remote_interrupt)
	(async_remote_interrupt_twice)
	(async_cleanup_sigint_signal_handler, ofunc)
	(sync_remote_interrupt, sync_remote_interrupt_twice): Delete.
	(remote_terminal_inferior, remote_terminal_ours): Remove async
	checks.
	(remote_wait_as): Don't install a SIGINT handler in sync mode.
	(readchar, remote_serial_write): Override the quit handler with
	remote_serial_quit_handler.
	(getpkt_or_notif_sane_1): Don't call QUIT.
	(initialize_remote_ops): Don't install
	remote_check_pending_interrupt.
	(_initialize_remote): Don't create async_sigint_remote_token and
	async_sigint_remote_twice_token.
	* ser-base.c (ser_base_wait_for): Call QUIT and use
	interruptible_select.
	(ser_base_write): Call QUIT.
	* ser-go32.c (dos_readchar, dos_write): Call QUIT.
	* ser-unix.c (wait_for): Don't use VTIME.  Always take the
	gdb_select path, but call QUIT and interruptible_select.
	* utils.c (maybe_quit): Call the current quit handler.  Don't call
	target_check_pending_interrupt.
	(defaulted_query, prompt_for_continue): Override the quit handler
	with the default quit handler.
2016-04-12 17:01:18 +01:00
Pedro Alves a12ac51333 TUI: GC tui_target_has_run
Nothing actually uses this global.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* tui/tui-hooks.c (tui_target_has_run): Delete.
	(tui_about_to_proceed): Delete.
	(tui_about_to_proceed_observer): Delete.
	(tui_install_hooks, tui_remove_hooks): Don't install/remove an
	about_to_proceed observer.
2016-04-12 17:00:54 +01:00
Pedro Alves 5fe966540d Use target_terminal_ours_for_output in MI
The MI code only does output, so leave raw/cooked mode alone, as well
as the SIGINT handler.  Restore terminal settings after output, while
at it.  Also, a couple events missed calling target_terminal_ours
before output, even.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* mi/mi-interp.c (mi_new_thread): Put
	target_terminal_ours_for_output in effect while outputting.
	(mi_thread_exit): Use target_terminal_ours_for_output instead of
	target_terminal_ours.
	(mi_record_changed, mi_inferior_added, mi_inferior_appeared)
	(mi_inferior_exit, mi_inferior_removed, mi_traceframe_changed)
	(mi_tsv_created, mi_tsv_deleted, mi_tsv_modified)
	(mi_breakpoint_created, mi_breakpoint_deleted)
	(mi_breakpoint_modified, mi_solib_loaded, mi_solib_unloaded)
	(mi_command_param_changed, mi_memory_changed)
	(report_initial_inferior): Use target_terminal_ours_for_output
	instead of target_terminal_ours.  Restore terminal settings.
	* mi/mi-main.c (mi_execute_command): Use
	target_terminal_ours_for_output instead of target_terminal_ours.
	Restore terminal settings.
2016-04-12 17:00:30 +01:00
Pedro Alves 651ce16aa7 Do target_terminal_ours in query & friends instead of in all callers
Any time a caller calls query & friends / prompt_for_continue without
ensuring that gdb owns the terminal for input is a bug.  So do that in
defaulted_query / prompt_for_continue directly instead.

An example of a case where we currently miss calling
target_terminal_ours is internal_error.  Ever since defaulted_query
was made to use gdb_readline_callback, there's no way to answer the
internal error query if the internal error happens while the target is
has the terminal:

  (gdb) c
  Continuing.
  .../src/gdb/linux-nat.c:1676: internal-error: linux_nat_resume: Assertion `dummy_counter < 10' failed.
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.
  Quit this debugging session? (y or n) _

Entering 'y' or 'n' does not work, GDB does not respond.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	PR gdb/19828
	* gnu-nat.c (inf_validate_task_sc): Don't call
	target_terminal_ours / target_terminal_inferior around query.
	* i386-tdep.c (i386_record_lea_modrm, i386_process_record): Don't
	call target_terminal_ours / target_terminal_inferior around
	yquery.
	* linux-record.c (record_linux_system_call): Don't call
	target_terminal_ours / target_terminal_inferior around yquery.
	* nto-procfs.c (interrupt_query): Don't call target_terminal_ours
	/ target_terminal_inferior around query.
	* record-full.c (record_full_check_insn_num): Remove
	'set_terminal' parameter.  Don't call target_terminal_ours /
	target_terminal_inferior around query.
	(record_full_message, record_full_registers_change)
	(record_full_xfer_partial): Adjust.
	* remote.c (interrupt_query): Don't call target_terminal_ours /
	target_terminal_inferior around query.
	* utils.c (defaulted_query): Install cleanup to restore target
	terminal.  Put target_terminal_ours_for_output in effect while
	defaulted producing, and target_terminal_ours in in effect while
	handling input.
	(prompt_for_continue): Install cleanup to restore target terminal.
	Put target_terminal_ours in in effect while handling input.
2016-04-12 17:00:01 +01:00
Pedro Alves 80dbc9fdc7 Add missing cleanups to defaulted_query and prompt_for_continue
Some of the error paths in these functions leak.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* utils.c (defaulted_query, prompt_for_continue): Free temporary
	strings with cleanups, instead of xfree.
2016-04-12 16:59:42 +01:00
Pedro Alves c5ac15402a Use target_terminal_ours_for_output in warning/internal_error
We're only doing output here, so leave raw/cooked mode alone, as well
as the SIGINT handler.

And restore terminal settings, while at it.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* utils.c (vwarning, internal_vproblem): Use
	make_cleanup_restore_target_terminal and
	target_terminal_ours_for_output.
2016-04-12 16:59:13 +01:00
Pedro Alves f8e3ef9dc4 Use target_terminal_ours_for_output in infcmd.c
We're only doing output here, so leave raw/cooked mode alone, as well
as the SIGINT handler.

No need to restore terminal settings, we'll set inferior modes on the
following resume.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* infcmd.c (post_create_inferior, prepare_one_step): Use
	target_terminal_ours_for_output instead of target_terminal_ours.
2016-04-12 16:58:55 +01:00
Pedro Alves 481ac8c9bb Use target_terminal_ours_for_output in exceptions.c
We're only doing output here, so leave raw/cooked mode alone, as well
as the SIGINT handler.

Restore terminal settings after output, while at it.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* exceptions.c (print_flush): Use target_terminal_ours_for_output
	instead of target_terminal_ours, and restore target terminal with
	a cleanup.
2016-04-12 16:58:35 +01:00
Pedro Alves c509f1e1e8 Use target_terminal_ours_for_output in cp-support.c
We're only doing output here, so leave raw/cooked mode alone, as well
as the SIGINT handler.

Restore terminal settings after output, while at it.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* cp-support.c (gdb_demangle): Use target_terminal_ours_for_output
	instead of target_terminal_ours, and restore target terminal with
	a cleanup.
2016-04-12 16:58:14 +01:00
Pedro Alves 99bbb428d4 ada-lang.c: Introduce type_as_string and use it
A couple wrong things here

  - We should not use target_terminal_ours when all we want is output.
    We should use target_terminal_ours_for_output instead, which
    preserves raw/cooked terminal modes, and SIGINT forwarding.

  - Most importantly, relying on stderr output immediately preceding
    the error/exception print isn't correct.  The exception could be
    caught and handled, for example; MI frontends won't display the
    stderr part in an error dialog box.  Etc.

This commit introduces a type_as_string helper that allows building a
full error string including type info.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* ada-lang.c (type_as_string, type_as_string_and_cleanup): New
	functions.
	(ada_lookup_struct_elt_type): Use type_as_string_and_cleanup.
2016-04-12 16:57:56 +01:00
Pedro Alves 75ee59252d Fix inconsistent handling of EINTR in ser-*.c backends
- If serial->write_prim returns EINTR, ser_bas_write returns it to the
  caller.  This just looks wrong to me -- part of the output may have
  already been sent, and there's no way for the caller to know that,
  and thus no way for a caller to handle a partial write correctly.

- While ser-unix.c:ser_unix_read_prim retries on EINTR,
  ser-tcp.c:net_read_prim does not.

This commit moves EINTR handling to the ser_base_write and
ser_base_readchar level, so all serial backends (at least those that
use it) end up handling EINTR consistently.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* ser-base.c (fd_event): Retry read_prim on EINTR.
	(do_ser_base_readchar): Retry read_prim on EINTR.
	(ser_base_write): Retry write_prim on EINTR.
	* ser-unix.c (ser_unix_read_prim): Don't retry on EINTR here.
	(ser_unix_write_prim): Remove comment.
2016-04-12 16:57:33 +01:00
Pedro Alves 93692b589d Pass Ctrl-C to the target in target_terminal_inferior
If the user presses Ctrl-C immediately before target_terminal_inferior
is called and the target is resumed, instead of after, the Ctrl-C ends
up pending in the quit flag until the target next stops.

remote.c has this bit to handle this:

      if (!target_is_async_p ())
	{
	  ofunc = signal (SIGINT, sync_remote_interrupt);
	  /* If the user hit C-c before this packet, or between packets,
	     pretend that it was hit right here.  */
	  if (check_quit_flag ())
	    sync_remote_interrupt (SIGINT);
	}

But that's only reachable if async is off, while async is on by
default nowadays.  It's also obviously not reacheable on native
targets.

This patch generalizes that to all targets.

We can't remove that remote.c bit yet, until we get rid of the sync
SIGINT handler though.  That'll be done later in the series.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* remote.c (remote_pass_ctrlc): New function.
	(init_remote_ops): Install it.
	* target.c (target_terminal_inferior): Pass pending Ctrl-C to the
	target.
	(target_pass_ctrlc, default_target_pass_ctrlc): New functions.
	* target.h (struct target_ops) <to_pass_ctrlc>: New method.
	(target_pass_ctrlc, default_target_pass_ctrlc): New declarations.
	* target-delegates.c: Regenerate.
2016-04-12 16:57:10 +01:00
Pedro Alves e42de8c7f8 Decouple target_interrupt from all-stop/non-stop modes
In non-stop mode, "interrupt" results in a "stop with no signal",
while in all-stop mode, it results in a remote interrupt request /
stop with SIGINT.  This is currently implemented in both the Linux and
remote target backends.  Move it to the core code instead, making
target_interrupt specifically always about "Interrupting as if with
Ctrl-C", just like it is documented.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* infcmd.c (interrupt_target_1): Call target_stop is in non-stop
	mode.
	* linux-nat.c (linux_nat_interrupt): Delete.
	(linux_nat_add_target): Don't install linux_nat_interrupt.
	* remote.c (remote_interrupt_ns): Change return type to void.
	Throw error if interrupting the target is not supported.
	(remote_interrupt): Don't call the remote_stop_ns/remote_stop_as.
2016-04-12 16:56:39 +01:00
Pedro Alves a149683b0c Eliminate clear_quit_flag
Nothing calls this anymore.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* defs.h (clear_quit_flag): Remove declaration.
	* extension-priv.h (struct extension_language_ops)
	<clear_quit_flag>: Remove field and update comments.
	* extension.c (clear_quit_flag): Delete.
	* guile/guile.c (guile_extension_ops): Adjust.
	* python/python.c (python_extension_ops): Adjust.
	(gdbpy_clear_quit_flag): Delete.
2016-04-12 16:56:15 +01:00
Pedro Alves da1e5f545c Don't call clear_quit_flag in captured_main
This call seems pointless.  For instance, a SIGINT handler is only
installed later on.  And if wasn't, I can't see why we'd want to lose
a Ctrl-C request.

Getting rid of this allows getting rid of clear_quit_flag.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* main.c (captured_main): Don't clear the quit flag.
2016-04-12 16:55:52 +01:00
Pedro Alves 0af679c6e0 Don't call clear_quit_flag in prepare_to_throw_exception
I think this is reminiscent of the time when a longjmp would always
jump to the top level.  Nowaways code that throw exceptions other than
a quit, which may even be caught and handled without reaching the top
level.  Certainly such exceptions shouldn't clear an interrupt
request...

(We also need to get rid of prepare_to_throw_exception in order to be
able to just do "throw ex;" in C++.)

One could argue that we should clear the quit flag when we throw a
quit from the SIGINT handler, when immediate_quit is in effect, to
handle a race, here:

 immediate_quit++;
 QUIT;

... that's the usual pattern code must use when enabling
immediate_quit.  The QUIT is there to catch the case of Ctrl-C having
already been pressed before immediate_quit was enabled.  However, this
can happen:

 immediate_quit++;
<< Ctrl-C pressed here too.
 QUIT;

And in that case, if the quit flag was already set, it'll stay set
even after throwing a quit from the SIGINT handler.  The end result is
a double quit.  But OTOH, the user did press Ctrl-C two times.  Since
I'm getting rid of immediate_quit, I'm not bothering with this.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* exceptions.c (prepare_to_throw_exception): Don't clear the quit
	flag.
2016-04-12 16:55:35 +01:00
Pedro Alves 4a81fd47b3 Don't call clear_quit_flag in command_handler
This just looks totally wrong to me, for completetly discarding a
user-requested Ctrl-C.  I can't think of why we'd want do this here.

Actually, I digged the history, and found out that this has been here
since at least 7b4ac7e1ed (gdb-2.4, the initial revision, 1988), at
a time were we had a top level setjmp/longjmp, long before that got
wrapped in throw_exception and friends, and this code was in an
explicit loop, with the quit_flag cleared on every iteration, before
executing a command...

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* event-top.c (command_handler): Don't call clear_quit_flag.
2016-04-12 16:55:16 +01:00
Pedro Alves abf009ef94 Don't call clear_quit_flag after check_quit_flag
Obviously not necessary since check_quit_flag clears the flag as side
effect.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* remote-sim.c (gdb_os_poll_quit): Don't call clear_quit_flag.
	* remote.c (remote_wait_as): Don't call clear_quit_flag.
2016-04-12 16:54:49 +01:00
Pedro Alves 6eddd09a12 Make Python use a struct serial event
Now that we have an abstract for wakeable events, use it instead of a
(heavier) serial pipe.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* python/python.c: Include "ser-event.h".
	(gdbpy_event_fds): Delete.
	(gdbpy_serial_event): New.
	(gdbpy_run_events): Change prototype.  Use serial_event_clear
	instead of serial_readchar.
	(gdbpy_post_event): Use serial_event_set instead of serial_write.
	(gdbpy_initialize_events): Use make_serial_event instead of
	serial_pipe.
2016-04-12 16:54:25 +01:00
Pedro Alves f0881b37b6 Introduce interruptible_select
We have places where we call a blocking gdb_select expecting that a
Ctrl-C will unblock it.  However, if the Ctrl-C is pressed just before
gdb_select, the SIGINT handler runs before gdb_select, and thus
gdb_select won't return.

For example gdb_readline_no_editing:

       QUIT;

       /* Wait until at least one byte of data is available.  Control-C
          can interrupt gdb_select, but not fgetc.  */
       FD_ZERO (&readfds);
       FD_SET (fd, &readfds);
       if (gdb_select (fd + 1, &readfds, NULL, NULL, NULL) == -1)

and stdio_file_read:

     /* For the benefit of Windows, call gdb_select before reading from
	the file.  Wait until at least one byte of data is available.
	Control-C can interrupt gdb_select, but not read.  */
     {
       fd_set readfds;
       FD_ZERO (&readfds);
       FD_SET (stdio->fd, &readfds);
       if (gdb_select (stdio->fd + 1, &readfds, NULL, NULL, NULL) == -1)
	 return -1;
     }
     return read (stdio->fd, buf, length_buf);


This is a race classically fixed with either the self-pipe trick, or
by blocking SIGINT and then using pselect instead of select.

Blocking SIGINT most of the time would mean that check_quit_flag (and
thus QUIT) would need to do a syscall every time it is called, which
sounds best avoided, since QUIT is called in many loops.  Thus we take
the self-pipe trick route (wrapped in a serial event).

Instead of having all places that need this manually add an extra file
descriptor to the set of gdb_select's watched file descriptors, we
introduce a wrapper, interruptible_select, that does that.

The Windows version of gdb_select actually does not suffer from this,
because mingw-hdep.c:gdb_call_async_signal_handler sets a Windows
event that gdb_select always waits on.  So this patch can be seen as
generalization of that technique.  We can't remove that extra event
from mingw-hdep.c until we get rid of immediate_quit though.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* defs.h: Extend QUIT-related comments to mention
	interruptible_select.
	(quit_serial_event_set, quit_serial_event_clear): Declare.
	* event-top.c: Include "ser-event.h" and "gdb_select.h".
	(quit_serial_event): New global.
	(async_init_signals): Make quit_serial_event.
	(quit_serial_event_set, quit_serial_event_clear)
	(quit_serial_event_fd, interruptible_select): New functions.
	* extension.c (set_quit_flag): Set the quit serial event.
	(check_quit_flag): Clear the quit serial event.
	* gdb_select.h (interruptible_select): New declaration.
	* guile/scm-ports.c (ioscm_input_waiting): Use
	interruptible_select instead of gdb_select.
	* top.c (gdb_readline_no_editing): Likewise.
	* ui-file.c (stdio_file_read): Likewise.
2016-04-12 16:54:03 +01:00
Pedro Alves 5cc3ce8b5f Fix signal handler/event-loop races
GDB's core signal handling suffers from a classical signal handler /
mainline code race:

  int
  gdb_do_one_event (void)
  {
  ...
  /* First let's see if there are any asynchronous signal handlers
       that are ready.  These would be the result of invoking any of the
       signal handlers.  */
    if (invoke_async_signal_handlers ())
      return 1;
  ...
    /* Block waiting for a new event.  (...).  */

    if (gdb_wait_for_event (1) < 0)
      return -1;
  ...
  }

If a signal is delivered while gdb is blocked in the poll/select
inside gdb_wait_for_event, then the select/poll breaks with EINTR,
we'll loop back around and call invoke_async_signal_handlers.

However, if the signal handler runs between
invoke_async_signal_handlers and gdb_wait_for_event,
gdb_wait_for_event will block, until the next unrelated event...

The fix is to a struct serial_event, and register it in the set of
files that select/poll in gdb_wait_for_event waits on.  The signal
handlers that defer work to invoke_async_signal_handlers call
mark_async_signal_handler, which is adjusted to also set the new
serial event in addition to setting a flag, and is thus now is
garanteed to immediately unblock the next gdb_select/poll call, up
until invoke_async_signal_handlers is called and the event is cleared.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* event-loop.c: Include "ser-event.h".
	(async_signal_handlers_serial_event): New global.
	(async_signals_handler, initialize_async_signal_handlers): New
	functions.
	(mark_async_signal_handler): Set
	async_signal_handlers_serial_event.
	(invoke_async_signal_handlers): Clear
	async_signal_handlers_serial_event.
	* event-top.c (async_init_signals): Call
	initialize_async_signal_handlers.
2016-04-12 16:53:40 +01:00
Pedro Alves 00340e1b91 Introduce a serial interface for select'able events
This patch adds a new "event" struct serial type, that is an
abstraction specifically for waking up blocking waits/selects,
implemented on top of a pipe on POSIX, and on top of a native Windows
event (CreateEvent, etc.) on Windows.

This will be used to plug signal handler / mainline code races.

For example, GDB can indefinitely delay handling a quit request if the
user presses Ctrl-C between the last QUIT call and the next (blocking)
gdb_select call in the event loop:

      QUIT;
                  <<< press ctrl-c here and end up blocked in gdb_select
		      indefinitely.

      gdb_select (...); // whoops, SIGINT was already handled, no EINTR.

A global alone (either the quit flag, or the "ready" flag of the async
signal handlers in the event loop) is not sufficient.

To plug races such as these on POSIX systems, we have to register some
waitable file descriptor in the set of files gdb_select waits on, and
write to it from the signal handler.  This is classically a pipe, and
the pattern called the self-pipe trick.  On Linux, it could be a more
efficient eventfd instead, but I'm sticking with a pipe for
simplifity, as we need it for portability anyway.

(Alternatively, we could use pselect/ppoll, and block signals until
the pselect.  The latter is not a design I think GDB could use,
because we want the QUIT macro to be super cheap, as it is used in
loops.  Plus, Windows.)

This is a "struct serial" because Windows's gdb_select relies on that.
Windows's gdb_select, our "select" replacement, knows how to wait on
all kinds of handles (regular files, pipes, sockets, console, etc.)
unlike the native Windows "select" function, which can only wait on
sockets.  Each file descriptor for a "serial" type that is not
normally waitable with WaitForMultipleObjects must have a
corresponding struct serial instance.  gdb_select then internally
looks up the struct serial instance that wraps each file descriptor,
and asks it for the corresponding Windows waitable handle.

We could use serial_pipe() to create a "struct serial"-wrapped pipe
that is usable everywhere, including Windows.  That's what currently
python/python.c uses for cross-thread posting of events.

However, serial_write and serial_readchar are not designed to be
async-signal-safe on POSIX hosts.  It's easier to bypass those when
setting/clearing the event source.

And writing and a serial pipe is a bit heavy weight on Windows.
gdb_select requires an extra thread to wait on the pipe and several
Windows events, when a single manual-reset Windows event, with no
extra thread is sufficient.

The intended usage is simply:

- Call make_serial_event to create a serial event object.

- From the signal handler call serial_event_set to set the event.

- From mainline code, have select/poll wait for serial_event_fd(), in
  addition to whatever other files you're about to wait for.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* Makefile.in (SFILES): Add ser-event.c.
	(HFILES_NO_SRCDIR): Add ser-event.h.
	(COMMON_OBS): Add ser-event.o.
	* ser-event.c, ser-event.h: New files.
	* serial.c (new_serial): New function, factored out from
	(serial_fdopen_ops): ... this.
	(serial_open_ops_1): New function, factored out from
	(serial_open): ... this.
	(serial_open_ops): New function.
	* serial.h (struct serial): Forware declare.
	(serial_open_ops): New declaration.
2016-04-12 16:53:21 +01:00
Pedro Alves 5f5219fc34 Remove unused struct serial::name field
Not used by anything.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* serial.c (serial_open, serial_fdopen_ops, do_serial_close):
	Remove references to name.
	* serial.h (struct serial) <name>: Delete.
2016-04-12 16:53:01 +01:00
Pedro Alves acd5494dd8 Stop remote-fileio.c from throwing from SIGINT handler
This code installs a custom signal handler that throws a quit
exception if remote_fio_no_longjmp is not set.

AFAICS, the only real reason for this might have been to unblock the
ui_file_read call, in remote_fileio_func_read.  But ever since:

  2009-11-13  Daniel Jacobowitz  <dan@codesourcery.com>

	* ui-file.c (stdio_file_read): Call gdb_select before read.

at:

  https://sourceware.org/ml/gdb-patches/2009-11/msg00321.html

that call is interruptible.

This is not only useful for switching to native C++ exceptions, but
AFAICS, also fixes a potential mess up of the remote protocol
connection, since there are target_read_memory calls done while
remote_fio_no_longjmp is clear.  If the user presses ctrl-c while GDB
is sending or receiving a packet, we'll stop the communication
immediately, at a point where it isn't safe.

gdbserver doesn't support the File I/O remote protocol extension so I
can't test this.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* remote-fileio.c (sigint_fileio_token, remote_fio_no_longjmp):
	Delete.
	(async_remote_fileio_interrupt): Delete.
	(remote_fileio_ctrl_c_signal_handler): Don't call the async signal
	handler.  Instead just always set the ctrl_c flag.
	(remote_fileio_reply): Clear remote_fio_ctrl_c_flag before
	re-enabling the SIGINT handler.
	(remote_fileio_func_open, remote_fileio_func_close)
	(remote_fileio_func_read, remote_fileio_func_write)
	(remote_fileio_func_lseek, remote_fileio_func_rename)
	(remote_fileio_func_unlink, remote_fileio_func_stat)
	(remote_fileio_func_fstat, remote_fileio_func_gettimeofday)
	(remote_fileio_func_isatty, remote_fileio_func_system)
	(remote_fileio_request): Remove references to
	remote_fio_no_longjmp.
	(initialize_remote_fileio): Don't create an async signal handler.
2016-04-12 16:52:36 +01:00
Pedro Alves d2acc30bb6 Don't set immediate_quit in prompt_for_continue
immediate_quit used to be necessary back when prompt_for_continue used
blocking fread, but nowadays it uses gdb_readline_wrapper, which is
implemented in terms of a nested event loop, which already knows how
to react to SIGINT:

 #0  throw_it (reason=RETURN_QUIT, error=GDB_NO_ERROR, fmt=0x9d6d7e "Quit", ap=0x7fffffffcb88)
     at .../src/gdb/common/common-exceptions.c:324
 #1  0x00000000007bab5d in throw_vquit (fmt=0x9d6d7e "Quit", ap=0x7fffffffcb88) at .../src/gdb/common/common-exceptions.c:366
 #2  0x00000000007bac9f in throw_quit (fmt=0x9d6d7e "Quit") at .../src/gdb/common/common-exceptions.c:385
 #3  0x0000000000773a2d in quit () at .../src/gdb/utils.c:1039
 #4  0x000000000065d81b in async_request_quit (arg=0x0) at .../src/gdb/event-top.c:893
 #5  0x000000000065c27b in invoke_async_signal_handlers () at .../src/gdb/event-loop.c:949
 #6  0x000000000065aeef in gdb_do_one_event () at .../src/gdb/event-loop.c:280
 #7  0x0000000000770838 in gdb_readline_wrapper (prompt=0x7fffffffcd40 "---Type <return> to continue, or q <return> to quit---")
     at .../src/gdb/top.c:873

The need for the QUIT in stdin_event_handler is then exposed by the
gdb.base/double-prompt-target-event-error.exp test, which has:

	# We're now stopped in a pagination query while handling a
	# target event (printing where the program stopped).  Quitting
	# the pagination should result in only one prompt being
	# output.
	send_gdb "\003p 1\n"

Without that change we'd get:

 Continuing.
 ---Type <return> to continue, or q <return> to quit---PASS: gdb.base/double-prompt-target-event-error.exp: ctrlc target event: continue: continue to pagination
 ^CpQuit
 (gdb)  1
 Undefined command: "1".  Try "help".
 (gdb) PASS: gdb.base/double-prompt-target-event-error.exp: ctrlc target event: continue: first prompt
 ERROR: Undefined command "".
 UNRESOLVED: gdb.base/double-prompt-target-event-error.exp: ctrlc target event: continue: no double prompt

Vs:

 Continuing.
 ---Type <return> to continue, or q <return> to quit---PASS: gdb.base/double-prompt-target-event-error.exp: ctrlc target event: continue: continue to pagination
 ^CQuit
 (gdb) p 1
 $1 = 1
 (gdb) PASS: gdb.base/double-prompt-target-event-error.exp: ctrlc target event: continue: first prompt
 PASS: gdb.base/double-prompt-target-event-error.exp: ctrlc target event: continue: no double prompt

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* event-top.c (stdin_event_handler): Call QUIT;
	(prompt_for_continue): Don't run with immediate_quit set.
2016-04-12 16:51:18 +01:00
Pedro Alves ab33ab13aa TUI: check whether in secondary prompt instead of immediate_quit
As can be seen in the tui_redisplay_readline comment:

 "The command could call prompt_for_continue and we must not restore
 SingleKey so that the prompt and normal keymap are used."

immediate_quit is being used as proxy for "secondary prompt".

We have a better predicate nowadays, so use it.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* tui/tui-io.c (tui_redisplay_readline): Check
	gdb_in_secondary_prompt_p instead of immediate_quit.
	* tui/tui.c: Include top.h.
	(tui_rl_startup_hook): Check gdb_in_secondary_prompt_p instead of
	immediate_quit.
2016-04-12 16:50:59 +01:00
Pedro Alves faa4ebe148 Inline command_loop in read_command_line
read_command_line is the only caller, and here we can assume we're
reading a regular file, not stdin.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* top.c (read_command_file): Inline command_loop here.
	(command_loop): Delete.
2016-04-12 16:50:41 +01:00
Pedro Alves 3212b85845 Don't rely on immediate_quit in command_line_input
AFAICS, immediate_quit was only needed here nowdays to be able to
interrupt gdb_readline_no_editing.

command_line_input can also take the gdb_readline_wrapper path, but
since that is built on top of the event loop (gdb_select / poll and
asynchronous signal handlers), it can be interrupted.

gdb/ChangeLog:
2016-04-12  Pedro Alves  <palves@redhat.com>

	* top.c: Include "gdb_select.h".
	(gdb_readline_no_editing): Wait for input with gdb_select instead
	of blocking in fgetc.
	(command_line_input): Don't set immediate_quit.
2016-04-12 16:49:29 +01:00
Simon Marchi 2e88a1ea30 gdb.python/py-mi-events-gdb.py: Add parentheses to print
Required for Python 3

gdb/testsuite/ChangeLog:

	* gdb.python/py-mi-events-gdb.py (signal_stop_handler): Add
	parentheses to print.
	(continue_handler): Likewise.
2016-04-09 08:41:41 -04:00
Simon Marchi f48e22e3f2 Make gdb.server/solib-list.exp work for remote targets
There are a few small changes needed to make it work with a real remote
target.

 - Remove the [is_remote target] check.
 - Remove soname setting when building the lib, it's done by default now
   anyway.
 - In the compilation of the executable, pass the shared lib using the
   shlib option, so that RPATH is set.
 - Download the program to the target using gdb_remote_download, and
   record the remote path.  Remove loading of the program using
   gdb_load_shlibs, which was not really appropriate anyway.
 - Run the remote path through readlink (see comment in the code).
 - Start gdbserver with the remote path.

Also, don't set executable and objfile variables, as they are unused.

Tested with native, native-gdbserver, native-extended-gdbserver, and a
remote gdbserver.

gdb/testsuite/ChangeLog:

	* gdb.server/solib-list.exp: Remove is_remote check.
	Pass shlib= to gdb_compile.  Don't link shared library with
	-soname.  Call gdb_remote_download instead of gdb_load_shlibs.
	Run binary filename through "readlink -f" on the target.
2016-04-08 18:45:29 -04:00
Pedro Alves 096be756aa Fix gdb.server/solib-list.exp regression
Commit 7817ea4614 (Improve gdb_remote_download, remove gdb_download)
caused:

 FAIL: gdb.server/solib-list.exp: non-stop 0: target extended-remote (timeout)
 FAIL: gdb.server/solib-list.exp: non-stop 0: continue (the program is no longer running)
 FAIL: gdb.server/solib-list.exp: non-stop 0: p libvar
 FAIL: gdb.server/solib-list.exp: non-stop 1: target extended-remote (timeout)
 FAIL: gdb.server/solib-list.exp: non-stop 1: continue (the program is no longer running)
 FAIL: gdb.server/solib-list.exp: non-stop 1: p libvar

gdb.log shows:

 system interpreter is: /lib64/ld-linux-x86-64.so.2
 ...
 spawn ../gdbserver/gdbserver --once :2347 /home/pedro/brno/pedro/gdb/mygit/build/gdb/testsuite/outputs/gdb.server/solib-list/ld-linux-x86-64.so.2 /home/pedro/brno/pedro/gdb/mygit/build/gdb/testsuite/outputs/gdb.server/solib-list/solib-list
 Process /home/pedro/brno/pedro/gdb/mygit/build/gdb/testsuite/outputs/gdb.server/solib-list/ld-linux-x86-64.so.2 created; pid = 18637
 Cannot exec /home/pedro/brno/pedro/gdb/mygit/build/gdb/testsuite/outputs/gdb.server/solib-list/ld-linux-x86-64.so.2: No such file or directory.
 ...

The test copied the interpreter to the outputs directory, however
ld-linux-x86-64.so.2 is a relative symlink that when copied points
nowhere:

 $ ls -l testsuite/outputs/gdb.server/solib-list/
 total 52
 -rwxrwxr-x. 1 pedro pedro 13450 Apr  7 10:52 gdb.log
 -rw-rw-r--. 1 pedro pedro  1512 Apr  7 10:52 gdb.sum
 lrwxrwxrwx. 1 pedro pedro    10 Apr  7 11:39 ld-linux-x86-64.so.2 -> ld-2.22.so
 -rwxrwxr-x. 1 pedro pedro  9464 Apr  7 11:39 solib-list
 -rw-rw-r--. 1 pedro pedro  3472 Apr  7 11:39 solib-list-lib.c.o
 -rw-rw-r--. 1 pedro pedro  2760 Apr  7 11:39 solib-list.o
 -rwxrwxr-x. 1 pedro pedro  9232 Apr  7 11:39 solib-list.so

The copying comes from gdbserver_spawn ->
gdbserver_download_current_prog -> gdb_remote_download.

There's actually no need to download the interpreter to the target -
it's part of the target system/environment.  So fix this by making the
test just not use gdb_load (and gdb_file_cmd as consequence) at all,
and instead pass the interpreter filename to gdbserver as an argument.

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

	* gdb.server/solib-list.exp: Don't use gdb_load.  Instead pass the
	interpreter filename as argument to gdbserver_spawn.
	* lib/gdbserver-support.exp (gdbserver_download_current_prog):
	Return empty if $last_loaded_file does not exist.
2016-04-08 19:40:01 +01:00
Martin Galvan 4bf7b526be value: Make accessor methods' parameters const-correct
I did a quick pass over value.c and value.h and made some of the accessor methods'
pass-by-reference parameters const-correct. Besides the obvious benefits, this is
required if we want to use them on values that are already declared as const
(such as the parameters to lval_funcs).

There's probably a lot more stuff that can be made const, here and elsewhere.

gdb/ChangeLog:
2016-04-08  Martin Galvan  <martin.galvan@tallertechnologies.com>

    * value.c (value_next): Make pass-by-reference parameters const-correct.
    (value_parent): Likewise.
    (value_enclosing_type): Likewise.
    (value_lazy): Likewise.
    (value_stack): Likewise.
    (value_embedded_offset): Likewise.
    (value_pointed_to_offset): Likewise.
    (value_raw_address): Likewise.
    (deprecated_value_modifiable): Likewise.
    (value_free_to_mark): Likewise.
    (value_release_to_mark): Likewise.
    (internalvar_name): Likewise.
    (readjust_indirect_value_type): Likewise.
    (value_initialized): Likewise.
    * value.h (value_next): Likewise.
    (value_parent): Likewise.
    (value_enclosing_type): Likewise.
    (value_lazy): Likewise.
    (value_stack): Likewise.
    (value_embedded_offset): Likewise.
    (value_pointed_to_offset): Likewise.
    (value_raw_address): Likewise.
    (deprecated_value_modifiable): Likewise.
    (value_free_to_mark): Likewise.
    (value_release_to_mark): Likewise.
    (internalvar_name): Likewise.
    (readjust_indirect_value_type): Likewise.
    (value_initialized): Likewise.
2016-04-08 15:06:56 -03:00
Jan Kratochvil 0650053364 testsuite: Fix for gcc-4.8: gdb.base/jit.exp gdb.base/jit-so.exp
on CentOS-7.2 I get

Running /home/jkratoch/redhat/gdb-test-reg/gdb/testsuite/gdb.base/jit.exp ...
FAIL: gdb.base/jit.exp: one_jit_test-1: continue to breakpoint: break here 2 (the program exited)
FAIL: gdb.base/jit.exp: one_jit_test-2: continue to breakpoint: break here 2 (the program exited)
FAIL: gdb.base/jit.exp: attach: one_jit_test-2: continue to breakpoint: break here 2 (the program exited)
FAIL: gdb.base/jit.exp: attach: one_jit_test-2: break here 2: set var wait_for_gdb = 1
FAIL: gdb.base/jit.exp: attach: one_jit_test-2: break here 2: detach (the program is no longer running)
FAIL: gdb.base/jit.exp: attach: one_jit_test-2: break here 2: attach
FAIL: gdb.base/jit.exp: attach: one_jit_test-2: break here 2: set var wait_for_gdb = 0
FAIL: gdb.base/jit.exp: PIE: one_jit_test-1: continue to breakpoint: break here 2 (the program exited)
Running /home/jkratoch/redhat/gdb-test-reg/gdb/testsuite/gdb.base/jit-so.exp ...
FAIL: gdb.base/jit-so.exp: one_jit_test-1: continue to breakpoint: break here 2 (the program exited)
FAIL: gdb.base/jit-so.exp: one_jit_test-2: continue to breakpoint: break here 2 (the program exited)

since:

85af34ee0211eedf8d30a5c44dfc59dddf8b512a is the first bad commit
commit 85af34ee0211eedf8d30a5c44dfc59dddf8b512a
Author: Pedro Alves <palves@redhat.com>
Date:   Thu Mar 31 19:28:47 2016 +0100
    Add regression test for PR gdb/19858 (JIT code registration on attach)

The compiled code's .debug_line is wrong (for the simplistic approach of GDB
to put a breakpoint on the first address belonging to that source line) and so
GDB misses the breakpoint at the last line:
          WAIT_FOR_GDB; return 0;  /* gdb break here 2  */

Most of the patch is just about reindentation, no changes there.

gdb/testsuite/ChangeLog
2016-04-08  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix compatibility with gcc-4.8.5-4.el7.x86_64.
	* gdb.base/jit-main.c: Use exit after usage.
2016-04-08 15:38:53 +02:00
Jan Kratochvil 2d35e87127 testsuite: Fix false FAILs with .bashrc GDBHISTFILE=...
$ GDBHISTFILE=/tmp/gdbhistfile runtest gdb.base/gdbhistsize-history.exp gdb.base/gdbinit-history.exp
Running ./gdb.base/gdbinit-history.exp ...
FAIL: gdb.base/gdbinit-history.exp: home=gdbinit-history/unlimited gdbhistsize=1000: show commands
FAIL: gdb.base/gdbinit-history.exp: home=gdbinit-history/unlimited gdbhistsize=foo: show commands
Running ./gdb.base/gdbhistsize-history.exp ...
FAIL: gdb.base/gdbhistsize-history.exp: histsize=: show commands
FAIL: gdb.base/gdbhistsize-history.exp: histsize=20: show commands
FAIL: gdb.base/gdbhistsize-history.exp: histsize= 20 : show commands
FAIL: gdb.base/gdbhistsize-history.exp: histsize=-5: show commands
FAIL: gdb.base/gdbhistsize-history.exp: histsize=not_an_integer: show commands
FAIL: gdb.base/gdbhistsize-history.exp: histsize=10zab: show commands
FAIL: gdb.base/gdbhistsize-history.exp: histsize=-5ab: show commands
FAIL: gdb.base/gdbhistsize-history.exp: histsize=99999999999999999999999999999999999: show commands
FAIL: gdb.base/gdbhistsize-history.exp: histsize=50: show commands

This happens for my setup due to my:
	$ grep GDB ~/.bashrc
	export GDBHISTFILE="$HOME/.gdb_history"

gdb/testsuite/ChangeLog
2016-04-07  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.base/gdbhistsize-history.exp: Save and unset GDBHISTFILE and
	GDBHISTSIZE prior to the tests.
	* gdb.base/gdbinit-history.exp: Likewise.
2016-04-07 22:18:49 +02:00
Pedro Alves 9553661a5f Fix gdb.compile/compile.exp shlib regression
Commit 6e774b13c3 (Make ftrace tests work with remote targets) made
a few gdb.compile/compile.exp tests disappear:

 -PASS: gdb.compile/compile.exp: call shared library function
 -PASS: gdb.compile/compile.exp: expect 1
 -PASS: gdb.compile/compile.exp: modify shared library variable
 -PASS: gdb.compile/compile.exp: expect 15

This is because the test uses ldflags instead of using the shlib
option, so it misses linking with -rpath, resulting in:

 (gdb) run
 Starting program: .../compile/compile-shlib
 .../compile/compile-shlib: error while loading shared libraries: compile-shlib.so: cannot open shared object file: No such file or directory
 [Inferior 1 (process 18014) exited with code 0177]

We were missing a gdb_load_shlibs call, which is needed for remote
testing.

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

	* gdb.compile/compile.exp: Use gdb_compile with "shlib=" option
	instead of build_executable.  Use gdb_load_shlibs.
2016-04-07 19:28:40 +01:00
Yao Qi c8064e7e9b Fix gdb.reverse/finish-reverse-bkpt.exp
I see the following fail on aarch64-linux

 break void_func
 Breakpoint 2 at 0x4007a0: file gdb/testsuite/gdb.reverse/finish-reverse.c, line 44.
 (gdb) PASS: gdb.reverse/finish-reverse-bkpt.exp: set breakpoint on void_func
 continue
 Continuing.

 Breakpoint 2, void_func () at gdb/testsuite/gdb.reverse/finish-reverse.c:44^M
 44        void_test = 1;                /* VOID FUNC */^M
 (gdb) PASS: gdb.reverse/finish-reverse-bkpt.exp: continue to breakpoint: void_func
 break *void_func^M
 Note: breakpoint 2 also set at pc 0x4007a0.^M
 Breakpoint 3 at 0x4007a0: file gdb/testsuite/gdb.reverse/finish-reverse.c, line 44.
 (gdb) PASS: gdb.reverse/finish-reverse-bkpt.exp: set breakpoint at void_func's entry
 reverse-finish^M
 Run back to call of #0  void_func () at gdb/testsuite/gdb.reverse/finish-reverse.c:44
 main (argc=1, argv=0x7ffffffb78) at gdb/testsuite/gdb.reverse/finish-reverse.c:98
 98        void_func ();                                 /* call to void_func */^M
 (gdb) FAIL: gdb.reverse/finish-reverse-bkpt.exp: reverse-finish from void_func trips breakpoint at entry

The test assumes that brekapoints on "void_func" and "*void_func" are
set on different places because of function prologue.  However, on
aarch64-linux, there is no prologue in void_func, so two breakpoints
are set at the same place (0x4007a0).

(gdb) disassemble void_func
Dump of assembler code for function void_func:
   0x00000000004007a0 <+0>:	adrp	x0, 0x410000
   0x00000000004007a4 <+4>:	add	x0, x0, #0xc14
   0x00000000004007a8 <+8>:	mov	w1, #0x1
   0x00000000004007ac <+12>:	str	w1, [x0]
   0x00000000004007b0 <+16>:	ret

The fix to this problem is to single step forward before setting
breakpoint on *void_func.

gdb/testsuite:

2016-04-07  Yao Qi  <yao.qi@linaro.org>

	* gdb.reverse/finish-reverse-bkpt.exp: Use temporary breakpoint.
	Execute "si" command.
2016-04-07 17:06:14 +01:00
Yao Qi bde475616e Fix gdb.reverse/next-reverse-bkpt-over-sr.exp
I see the fail on aarch64-linux,

(gdb) reverse-next

Breakpoint 2, callee () at /home/yao/SourceCode/gnu/gdb/git/gdb/testsuite/gdb.reverse/step-reverse.c:26^M
26        myglob++; return 0;   /* ARRIVED IN CALLEE */
(gdb) FAIL: gdb.reverse/next-reverse-bkpt-over-sr.exp: reverse-next over call trips user breakpoint at function entry

The test expects program stops at line 25, but program stops at line 26.

(gdb) maintenance info line-table
objfile: /scratch/yao/gdb/build-git/aarch64-linux-gnu/gdb/testsuite/outputs/gdb.reverse/next-reverse-bkpt-over-sr/next-reverse-bkpt-over-sr ((struct objfile *) 0x613000002880)
compunit_symtab: ((struct compunit_symtab *) 0x621000121760)
symtab: /home/yao/SourceCode/gnu/gdb/git/gdb/testsuite/gdb.reverse/step-reverse.c ((struct symtab *) 0x6210001217e0)
linetable: ((struct linetable *) 0x6210001520d0):
INDEX    LINE ADDRESS
0          25 0x0000000000400890
1          26 0x0000000000400890
2          27 0x00000000004008b0

(gdb) disassemble callee
Dump of assembler code for function callee:
   0x0000000000400890 <+0>:     adrp    x0, 0x410000
   0x0000000000400894 <+4>:     add     x0, x0, #0xcac

the line-table show that the first instruction of function callee is
mapped line 25 and 26.  I am not sure the line-table is correct, but
it is not the point of this test.  The goal of this test is to test
program hits the breakpoint on the first instruction of function after
'reverse-next', so I change this test to expect the breakpoint number
the program hits.

gdb/testsuite:

2016-04-07  Yao Qi  <yao.qi@linaro.org>

	* gdb.reverse/next-reverse-bkpt-over-sr.exp: Match the breakpoint
	number instead of the comments on some line.
2016-04-07 16:57:09 +01:00
Yao Qi e390720bdc Make breakpoint handling in record-full idempotent
Some test fails in gdb.reverse/break-reverse.exp on arm-linux lead me
seeing the following error message,

continue^M
Continuing.^M
Cannot remove breakpoints because program is no longer writable.^M
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Further execution is probably impossible.^M
^M
Breakpoint 3, bar () at /home/yao/SourceCode/gnu/gdb/git/gdb/testsuite/gdb.reverse/break-reverse.c:22^M
22        xyz = 2; /* break in bar */^M
(gdb) PASS: gdb.reverse/break-reverse.exp: continue to breakpoint: bar backward

this is caused by two entries in record_full_breakpoints, and their addr
is the same, but in_target_beneath is different.

during the record, we do continue,

Continuing.
infrun: clear_proceed_status_thread (Thread 13772.13772)
infrun: proceed (addr=0xffffffff, signal=GDB_SIGNAL_DEFAULT)
infrun: step-over queue now empty
infrun: resuming [Thread 13772.13772] for step-over
infrun: skipping breakpoint: stepping past insn at: 0x8620
Sending packet: $Z0,85f4,4#1d...Packet received: OK  <----
.....
Sending packet: $vCont;c#a8...infrun: target_wait (-1.0.0, status) =
infrun:   -1.0.0 [process -1],
infrun:   status->kind = ignore
infrun: TARGET_WAITKIND_IGNORE
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   -1.0.0 [process -1],
infrun:   status->kind = ignore
infrun: TARGET_WAITKIND_IGNORE
infrun: prepare_to_wait
Packet received: T05swbreak:;0b:9cf5ffbe;0d:9cf5ffbe;0f:f4850000;thread:p35cc.35cc;core:1;
Sending packet: $Z0,85f4,4#1d...Packet received: OK <-----
....
Sending packet: $z0,85f4,4#3d...Packet received: OK <-----

we can see breakpoint on 0x85f4 are inserted *twice*, but only removed
once.  That is fine to remote target, because Z/z packets are
idempotent, but there is a leftover in record_full_breakpoints
in record-full target.  The flow can be described as below,

                                record_full_breakpoints   remote target
  -----------------------------------------------------------------------
  forward execution, continue,    in_target_beneath 1     breakpoint inserted
  insert breakpoints on 0x85f4    in_target_beneath 1
  twice

  program stops,
  remove breakpoint on 0x85f4     in_target_beneath 1     breakpoint removed

  reverse execution, continue,    in_target_beneath 1     none is requested
  insert breakpoints on 0x85f4,   in_target_beneath 0

  program stops,
  remote breakpoint on 0x85f4,    in_target_beneath 0     request to remove,
                                                          but GDBserver
							  doesn't know

now, the question is why breakoint on 0x85f4 is inserted twice?  One
is the normal breakpoint, and the other is the single step breakpoint.
GDB inserts single step breakpoint to do single step.  When program
stops at 0x85f4, both of them are set on 0x85f4, and GDB deletes
single step breakpoint, so in update_global_location_list, this
breakpoint location is no longer found, GDB call
force_breakpoint_reinsertion to mark it condition_updated, and insert
it again.

The reason force_breakpoint_reinsertion is called to update the
conditions in the target side, because the conditions may be
changed.  My original fix is to not call force_breakpoint_reinsertion
if OLD_LOC->cond is NULL, but it is not correct if another location
on the same address has condition, GDB doesn't produce condition for
target side, but GDB should do.

Then, I change my mind back to make record-full handling breakpoint
idempotent, to align with remote target.  Before insert a new entry
into record_full_breakpoints, look for existing one on the same
address first.  I also add an assert on
"bp->in_target_beneath == in_target_beneath", to be safer.

gdb:

2016-04-07  Yao Qi  <yao.qi@linaro.org>

	* record-full.c (record_full_insert_breakpoint): Return
	early if entry on the address is found in
	record_full_breakpoints.
2016-04-07 16:51:31 +01:00
Yao Qi 1ccd06e498 Set bp_tgt->reqstd_address and bp_tgt->placed_size in record_full_insert_breakpoint
I notice that bp_tgt won't be fully initialized if to_insert_breakpoint
isn't called in record_full_insert_breakpoint, and bp_tgt->reqstd_address
is zero, so an entry is added to record_full_breakpoints, but its address
is zero, which is wrong.  This patch is to call gdbarch_breakpoint_from_pc
in the else branch to set bp_tgt->reqstd_address and bp_tgt->placed_size.

gdb:

2016-04-07  Yao Qi  <yao.qi@linaro.org>

	* record-full.c (record_full_insert_breakpoint): Set
	bp_tgt->reqstd_address and bp_tgt->placed_size.
2016-04-07 16:51:30 +01:00
Don Breazeal ecf2e90cd6 Eliminate -var-create error for optzd ptr to struct
This patch eliminates an error thrown when accessing the value of a
pointer to a structure where the pointer has been optimized out and
'set print object' is 'on'.  The error shows up as the rather ugly
value of the pointer variable in Eclipse.

If 'set print object' is 'on', GDB tries to determine the actual
(derived) type of the object rather than the declared type, which
requires dereferencing the pointer, which in this cases throws an
error because the pointer has been optimized out.

The fix is to simply ignore the 'print object on' setting for
pointers or references to structures when they have been optimized
out.  This means we just get the declared type instead of the actual
type, because in this case that's the best that we can do.

To implement the fix, value_optimized_out was modified so that it
no longer throws an error when it fails to fetch the specified
value.  Instead, it just checks value->optimized_out.  If we can't
definitively say that the value is optimized out, then we assume
it is not.

gdb/ChangeLog:
2016-04-06  Don Breazeal  <donb@codesourcery.com>

	* value.c (value_actual_type): Don't try to get rtti type
	of the value if it has been optimized out.
	(value_optimized_out): If a memory access error occurs,
	just check vaue->optimized_out.
2016-04-06 14:30:22 -07:00
Don Breazeal b16f8a3b1e Optimized-out pointer: New test for error handling
This patch implements a test that ensures that with "set print object
on", -var-create returns "<optimized out>" for an optimized out pointer
to structure, rather than throwing an error, while also ensuring that
any attempt to dereference the pointer *will* throw an error.

It uses the dwarf assembler to construct the appropriate debug info
to represent a pointer-to-struct in the program as optimized out,
and then accesses that pointer in various ways.  The test uses both
the console interpreter and the MI interpreter.

gdb/testsuite/ChangeLog:
2016-04-06  Don Breazeal  <donb@codesourcery.com>

	* gdb.dwarf2/dw2-opt-structptr.c: New test program.
	* gdb.dwarf2/dw2-opt-structptr.exp: New test script.
2016-04-06 14:30:20 -07:00
Simon Marchi c2f901dfb6 Fix gdb.threads/dlopen-libpthread.exp crash
Following, commit

  6e774b13c3 Make ftrace tests work with remote targets

the test gdb.threads/dlopen-libpthread.exp started to fail with:

  ERROR: error copying "/home/emaisin/build/binutils-gdb/gdb/testsuite/gdb.threads/dlopen-libpthread.so": no such file or directory

This is because the library path is not computed using
standard_output_file, so we try to gdb_load_shlibs an unexisting file.

gdb/testsuite/ChangeLog:

	* gdb.threads/dlopen-libpthread.exp: Set binfile_lib using
	standard_output_file.  Remove unused binfile variable.
2016-04-06 16:49:38 -04:00
Jan Kratochvil 147316171d Revert the previous commit adding unknown_v_replies_ok.
It broke the compatibility with gdbserver-7.6 due to:
	warning: remote target does not support file transfer, attempting to access files from local filesystem.

gdb/ChangeLog
2016-04-06  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Revert the previous commit adding unknown_v_replies_ok.
2016-04-06 21:05:16 +02:00
Jan Kratochvil 319cb5d0cf Workaround gdbserver<7.7 for setfs
With current FSF GDB HEAD and old FSF gdbserver I expected I could do:
	gdb -ex 'file target:/root/redhat/threadit' -ex 'target remote :1234'
(supplying that unsupported qXfer:exec-file:read by "file")
But that does not work because:
	Sending packet: $vFile:setfs:0#bf...Packet received: OK
	Packet vFile:setfs (hostio-setfs) is supported
	...
	Sending packet: $vFile:setfs:104#24...Packet received: OK
	"target:/root/redhat/threadit": could not open as an executable file: Invalid argument

GDB documentation says:
	The valid responses to Host I/O packets are:
	An empty response indicates that this operation is not recognized.

This "empty response" vs. "OK" was a bug in gdbserver < 7.7.  It was fixed by:
	commit e7f0d979dd
	Author: Yao Qi <yao@codesourcery.com>
	Date:   Tue Dec 10 21:59:20 2013 +0800
	    Fix a bug in matching notifications.
	Message-ID: <1386684626-11415-1-git-send-email-yao@codesourcery.com>
	https://sourceware.org/ml/gdb-patches/2013-12/msg00373.html
	2013-12-10  Yao Qi  <yao@codesourcery.com>
		* notif.c (handle_notif_ack): Return 0 if no notification
		matches.

with unpatched old FSF gdbserver and patched FSF GDB HEAD:
	gdb -ex 'file target:/root/redhat/threadit' -ex 'target remote :1234'
	Sending packet: $vFile:setfs:0#bf...Packet received: OK
	Packet vFile:setfs (hostio-setfs) is NOT supported
	...
	(gdb) info sharedlibrary
	From                To                  Syms Read   Shared Object Library
	0x00007ffff7ddbae0  0x00007ffff7df627a  Yes (*)     target:/lib64/ld-linux-x86-64.so.2
	0x00007ffff7bc48a0  0x00007ffff7bcf514  Yes (*)     target:/lib64/libpthread.so.0

gdb/ChangeLog
2016-04-06  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* remote.c (struct remote_state): New field unknown_v_replies_ok.
	(packet_config_support): Read it.
	(remote_start_remote): Set it.
2016-04-06 17:18:21 +02:00
Jan Kratochvil 052d2eb254 Revert check-in by a mistake in the previous commit.
gdb/ChangeLog
2016-04-06  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* remote.c: Revert check-in by a mistake in the previous commit.
2016-04-06 16:48:27 +02:00
Jan Kratochvil fef3cb9f3a Print the "file" command suggestion in exec_file_locate_attach
currently:
	$ gdbserver-7.9 :1234 true &
	$ gdb -q -ex 'target remote :1234' # that -q is not relevant here
	Remote debugging using :1234
	warning: Could not load vsyscall page because no executable was specified
	try using the "file" command first.
	0x00007ffff7ddcc80 in ?? ()
	(gdb) b main
	No symbol table is loaded.  Use the "file" command.
	Make breakpoint pending on future shared library load? (y or [n]) _

Provide more suggestive message to use the "file" command.

gdb/ChangeLog
2016-04-06  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* exec.c (exec_file_locate_attach): Print warning for unsupported
	target_pid_to_exec_file.
	* symfile-mem.c (add_vsyscall_page): Remove the "file" command
	message part.
2016-04-06 15:57:08 +02:00
Catalin Udma ac17fda08b testsuite: Update py-mi-objfile to expect console format print
Starting with this commit:

  commit e7ea3ec7c6
  Author: Catalin Udma <catalin.udma@freescale.com>
  Date:   Mon Feb 29 16:16:19 2016 +0200

    python: Use console format for output of gdb.execute command

the python script would use console format for gdb.execute output.
This patch fixes py-mi-objfile to expect the console format when is
checking for gdb.execute printing.

gdb/testsuite/ChangeLog:
2016-04-05  Catalin Udma  <catalin.udma@freescale.com>

        * gdb.python/py-mi-objfile-gdb.py: Use "list main" command.
        * gdb.python/py-mi-objfile.exp: Match "list main" output
        in console format.

Signed-off-by: Catalin Udma <catalin.udma@freescale.com>
2016-04-06 09:39:16 +03:00
Simon Marchi 03a8c4dfc2 Fix IPA detection in ftrace-insn-reloc.exp
In commit 6e774b13c3, I forgot to update this test.

gdb/testsuite/ChangeLog:

	* gdb.arch/ftrace-insn-reloc.exp: Check for IPA basename instead of
	absolute.
2016-04-05 20:37:05 -04:00
Simon Marchi 6e774b13c3 Make ftrace tests work with remote targets
When we build a shared library for testing, it is built differently
whether it is meant for the local system or a remote one.  When it is
for the local system, the library is built with no SONAME.  So when the
executable is built, roughly in this way:

  $ gcc testfile.c /path/to/library.so

the executable will contain an absolute reference to the library.  For
example:

  $ readelf -a testsuite/gdb.python/py-shared | grep NEEDED
   0x0000000000000001 (NEEDED)             Shared library: [/home/emaisin/build/binutils-gdb/gdb/testsuite/gdb.python/py-shared-sl.sl]

When testing is done remotely, the absolute path obviously doesn't work.
Therefore, we build the library with an SONAME:

  $ readelf -a testsuite/gdb.python/py-shared-sl.sl | grep SONAME
   0x000000000000000e (SONAME)             Library soname: [py-shared-sl.sl]

which ends up in the executable's NEEDED field:

  $ readelf -a testsuite/gdb.python/py-shared | grep NEEDED
   0x0000000000000001 (NEEDED)             Shared library: [py-shared-sl.sl]

The executable and the library are then uploaded side-by-side on the
remote system.  To allow the dynamic linker to find the shared library,
we have to add the special RPATH value $ORIGIN, which tells it to search
in the executable's directory:

  $ readelf -a testsuite/gdb.python/py-shared | grep ORIGIN
   0x000000000000000f (RPATH)              Library rpath: [$ORIGIN]

The problem with the IPA library is that it doesn't have an SONAME,
making it very difficult to do testing on a remote board.  When a
test executable is linked with it, it contains an absolute reference to
the library path.  Therefore, unless the paths on the target are the
same as on the build system, it won't work.

To make it possible for tests using the IPA library to run test on
remote boards, I suggest adding an SONAME to libinproctrace.so.  I don't
think it should be a big problem for users.  All the libraries installed
on my system have an SONAME, so it should be fine if libinproctrace.so
does too.

As a consequence, native testing does not work anymore, since
executables do not contain the absolute path to the library anymore.  To
keep them working, we can have gdb_load_shlibs copy the library to the
test directory when testing natively.  That's done by modifying
gdb_load_shlibs.  We also have to add RPATH=$ORIGIN to executables, even
when testing natively.

I think it's a good change in general, as it reduces the differences
between testing a native and a remote target.  To further reduce those
differences, we can also always build test shared libraries with an
SONAME.

ftrace.exp and ftrace-lock.exp need to be modified slightly.  The code
checks that the IPA library is loaded using the absolute path on the
build machine.  That obviously doesn't work if the test is done
remotely, as the path will be different.  I changed the tests to only
search for the library basename (e.g. libinproctrace.so).

gdb/gdbserver/ChangeLog:

	* Makefile.in ($(IPA_LIB)): Set SONAME of the IPA lib.

gdb/testsuite/ChangeLog:

	* gdb.trace/ftrace-lock.exp: Check for IPA basename instead of
	absolute.
	* gdb.trace/ftrace.exp: Likewise.
	* lib/gdb.exp (gdb_compile): Set rpath $ORIGIN for non-remote
	targets as well.
	(gdb_compile_shlib): Set SONAME for non-remote targets as well.
	(gdb_load_shlibs): Copy libraries to test directory when testing
	natively.  Only set solib-search-path if testing remotely.
	* lib/mi-support.exp (mi_load_shlibs): Likewise.
2016-04-05 13:59:50 -04:00
Simon Marchi 7817ea4614 Improve gdb_remote_download, remove gdb_download
This patch removes gdb_download in favor of gdb_remote_download, since
they are very close in functionality.  Also, in preparation for the
following patch about shared library handling during tests, it improves
gdb_remote_download so that it uses standard_output_file for any
destination board that is local, not only host.

If the destination board is remote, gdb_remote_download will use the
standard remote_download from DejaGnu, resulting in the file being
transferred on the remote system.

If the destination is local, gdb_remote_download will copy the file to
the standard test directory (found using standard_output_file).  Tcl's
file copy seems to handle gracefully cases where the source file is the
same as the destination, so I don't think it's necessary to check for
that case ourselves, as a previous version of the patch did.

I'd prefer to keep the name gdb_download instead of gdb_remote_download,
since I don't like the fact that gdb_remote_download implies that the
destination is remote, when it's not always the case.  However,
gdb_remote_download is used at many more places than gdb_download, so
it's easier to reuse that.  Also, since it's a wrapper around DejaGnu's
remote_download, it might be better to keep that name.  I don't know.

I ran the testsuite native, with native-gdbserver and with a
remote gdbserver, and didn't see any related failure.

gdb/testsuite/ChangeLog:

	* gdb.base/jit-so.exp: Use gdb_remote_download instead of
	gdb_download.  Use it even if the target is not remote.
	* gdb.base/jit.exp (compile_jit_test): Likewise.
	* lib/gdb.exp (gdb_remote_download): Copy files to the standard
	output directory if the destination board is local, otherwise use
	the standard remote_download from DejaGnu.
	(gdb_download): Remove.
	(gdb_load_shlibs): Use gdb_remote_download instead of
	gdb_download.
	* lib/gdbserver-support.exp (gdbserver_download_current_prog):
	Use gdb_remote_download instead of gdb_download.  Use it even if
	the target is not remote.
	* lib/mi-support.exp (mi_load_shlibs): Use gdb_remote_download
	instead of gdb_download.
2016-04-05 13:59:49 -04:00
Marcin Kościelnicki 4dca19f828 IPA: Move getauxval out of #ifndef IN_PROCESS_AGENT
The getauxval code was wrongly included in code area only compiled for
gdbserver.  Move it to a #ifdef IN_PROCESS_AGENT area that already
contains lots of IPA-only code.

gdb/gdbserver/ChangeLog:

	* tracepoint.c (getauxval): Move to #ifdef IN_PROCESS_AGENT.
2016-04-05 18:04:53 +02:00
Simon Marchi 2aa08bd1f9 Obvious function doc and formatting
gdb/ChangeLog:

	* cli/cli-decode.c (help_cmd_list): Fix function doc and remove
	trailing spaces.
2016-04-04 16:46:36 -04:00
Simon Marchi 7beb7f68a0 Fix gdb.mi/mi-breakpoint-changed.exp for remote targets
The libraries are never downloaded to the target for the first test
(test_insert_delete_modify), so the executable can't run properly.

I also added some with_test_prefix to help differentiate between the
different test case phases.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-breakpoint-changed.exp: Add some with_test_prefix.
	(test_insert_delete_modify): Call mi_load_shlibs before trying to
	run.
2016-04-04 10:31:30 -04:00
Marcin Kościelnicki d0a9981f37 IPA: Fix build problem on !HAVE_GETAUXVAL
These files need AT_PHDR, which is defined in elf.h.  If HAVE_GETAUXVAL
is set, it's implicitely included by sys/auxv.h.  Include it manually
for the opposite case.

gdb/gdbserver/ChangeLog:

	* linux-aarch64-ipa.c: Add <elf.h> include.
	* linux-ppc-ipa.c: Add <elf.h> include.
	* linux-s390-ipa.c: Add <elf.h> include.
2016-04-03 18:27:50 +02:00
Artemiy Volkov cc63428a4c gdb: allow enumeration constants as second operand of BINOP_REPEAT
This patch adds support for TYPE_CODE_ENUM values to be supplied
as right-hand side operand of the BINOP_REPEAT (@) operator. The
following should now work:

enum {
  sz = 17
};

int
main ()
{
  int arr[sz + 1] = { 0 };
  return 0; /* line 9 here */
}

(gdb) b 9
(gdb) r
(gdb) p arr@sz
$1 = {0 <repeats 17 times>}
(gdb)

A couple of tests is also included in this patch to demonstrate that it is
working as intended.

gdb/Changelog:

2016-04-01  Artemiy Volkov  <artemiyv@acm.org>

	PR gdb/19820
	* eval.c (evaluate_subexp_standard): Allow TYPE_CODE_ENUM to be
        the type of BINOP_REPEAT's second operand.

gdb/testsuite/Changelog:

2016-04-01  Artemiy Volkov  <artemiyv@acm.org>

	PR gdb/19820
	* gdb.base/printcmds.exp: Add artificial arrays tests.
2016-04-01 16:00:59 +01:00
Marcin Kościelnicki 252db07e1d gdbserver: Fix C++ build errors in tracepoint.c
These were introduced by 1cda151268
and a13c46966d .  One is a simple
missing cast, the other is const usage on global function pointers
exported from IPA: in C++, consts are static, and thus won't be
exported from the DSO (the build error was because of non-applicable
visibility("default")).

gdb/gdbserver/ChangeLog:

	* tracepoint.c (gdb_collect_ptr): Remove const qualifier.
	(get_raw_reg_ptr): Likewise.
	(get_trace_state_variable_value_ptr): Likewise.
	(set_trace_state_variable_value_ptr): Likewise.
	(initialize_tracepoint): Cast alloc_jump_pad_buffer result to
	char *.
2016-03-31 23:38:03 +02:00
Pedro Alves 64cdf930d9 Add regression test for PR gdb/19858 (JIT code registration on attach)
This test would fail without the previous gdb/jit.c fix:

  (gdb) attach 23031
  Attaching to program: .../build/gdb/testsuite/outputs/gdb.base/jit/jit-main, process 23031
  [...]
  207           WAIT_FOR_GDB; i = 0;  /* gdb break here 1 */
  (gdb) PASS: gdb.base/jit.exp: attach: one_jit_test-2: attach
  set var wait_for_gdb = 0
  (gdb) PASS: gdb.base/jit.exp: attach: one_jit_test-2: set var wait_for_gdb = 0
  info function ^jit_function
  All functions matching regular expression "^jit_function":
  (gdb) FAIL: gdb.base/jit.exp: attach: one_jit_test-2: info function ^jit_function

gdb/testsuite/ChangeLog:
2016-03-31  Pedro Alves  <palves@redhat.com>

	PR gdb/19858
	* gdb.base/jit-main.c: Include unistd.h.
	(ATTACH): Define to 0 if not already defined.
	(wait_for_gdb, mypid): New globals.
	(WAIT_FOR_GDB): New macro.
	(MAIN): Set an alarm.  Store the process's pid.  Wait for GDB at
	some breakpoint locations.
	* gdb.base/jit.exp (clean_reattach, continue_to_test_location):
	New procedures.
	(one_jit_test): Add REATTACH parameter, and handle it.  Use
	continue_to_test_location.
	(top level): Test attach, and adjusts calls to one_jit_test.
2016-03-31 19:28:47 +01:00
Pedro Alves 40dea8cbf6 Make gdb.base/jit.exp binaries unique
This testcase compiles the same program and library differently
multiple times using the same file names.  Make them unique, to make
it easier to debug test problems.

gdb/testsuite/ChangeLog:
2016-03-31  Pedro Alves  <palves@redhat.com>

	PR gdb/19858
	* gdb.base/jit.exp (compile_jit_test): Add intro comment.  Add
	BINSUFFIX parameter, and handle it.
	(top level): Adjust calls compile_jit_test.
2016-03-31 19:28:47 +01:00
Yichao Yu 9bb84c9f97 Fix PR gdb/19858: GDB doesn't register the JIT libraries on attach
Ref: https://sourceware.org/ml/gdb/2016-03/msg00023.html

GDB currently fails to fetch the list of already-registered JIT
modules on attach.

Nothing is calling jit_inferior_init, which is what is responsible for
walking the JIT object list at init time.

Despite the misleading naming, jit_inferior_created_hook ->
jit_inferior_init is only called when the inferior execs.

This regressed with the fix for PR gdb/13431 (03bef283c2):
 https://sourceware.org/ml/gdb-patches/2012-02/msg00023.html which
removed the inferior_created (jit_inferior_created_observer)
observer.

Adding an inferior_created observer back fixes the issue.

In turn, this exposes a bug in jit_breakpoint_re_set_internal as well,
which is returning the wrong result when we already have the
breakpoint at the right address.

gdb/ChangeLog:
2016-03-31  Yichao Yu  <yyc1992@gmail.com>

	PR gdb/19858
	* jit.c (jit_breakpoint_re_set_internal): Return 0 if we already
	got the breakpoint at the right address.
	(jit_inferior_created): New function.
	(_initialize_jit): Install jit_inferior_created as
	inferior_created observer.

Signed-off-by: Pedro Alves <palves@redhat.com>
2016-03-31 19:28:47 +01:00
Marcin Kościelnicki 22084c425e gdb/NEWS: Add mention of powerpc*-linux tracepoints.
gdb/ChangeLog:

	* NEWS: Mention support for tracepoints on powerpc*-linux.
2016-03-31 15:49:25 +02:00
Marcin Kościelnicki 14e2b6d93d gdbserver: Add emit_ops for powerpc.
gdb/gdbserver/ChangeLog:

2016-03-31  Wei-cheng Wang  <cole945@gmail.com>
	    Marcin Kościelnicki  <koriakin@0x04.net>

	PR/17221
	* linux-ppc-low.c (emit_insns): New function.
	(__EMIT_ASM, _EMIT_ASM, EMIT_ASM): New macros.
	(ppc_emit_prologue): New function.
	(ppc_emit_epilogue): New function.
	(ppc_emit_add): New function.
	(ppc_emit_sub): New function.
	(ppc_emit_mul): New function.
	(ppc_emit_lsh): New function.
	(ppc_emit_rsh_signed): New function.
	(ppc_emit_rsh_unsigned): New function.
	(ppc_emit_ext): New function.
	(ppc_emit_zero_ext): New function.
	(ppc_emit_log_not): New function.
	(ppc_emit_bit_and): New function.
	(ppc_emit_bit_or): New function.
	(ppc_emit_bit_xor): New function.
	(ppc_emit_bit_not): New function.
	(ppc_emit_equal): New function.
	(ppc_emit_less_signed): New function.
	(ppc_emit_less_unsigned): New function.
	(ppc_emit_ref): New function.
	(ppc_emit_const): New function.
	(ppc_emit_reg): New function.
	(ppc_emit_pop): New function.
	(ppc_emit_stack_flush): New function.
	(ppc_emit_swap): New function.
	(ppc_emit_stack_adjust): New function.
	(ppc_emit_call): New function.
	(ppc_emit_int_call_1): New function.
	(ppc_emit_void_call_2): New function.
	(ppc_emit_if_goto): New function.
	(ppc_emit_goto): New function.
	(ppc_emit_eq_goto): New function.
	(ppc_emit_ne_goto): New function.
	(ppc_emit_lt_goto): New function.
	(ppc_emit_le_goto): New function.
	(ppc_emit_gt_goto): New function.
	(ppc_emit_ge_goto): New function.
	(ppc_write_goto_address): New function.
	(ppc_emit_ops_impl): New static variable.
	(ppc64v1_emit_prologue): New function.
	(ppc64v2_emit_prologue): New function.
	(ppc64_emit_epilogue): New function.
	(ppc64_emit_add): New function.
	(ppc64_emit_sub): New function.
	(ppc64_emit_mul): New function.
	(ppc64_emit_lsh): New function.
	(ppc64_emit_rsh_signed): New function.
	(ppc64_emit_rsh_unsigned): New function.
	(ppc64_emit_ext): New function.
	(ppc64_emit_zero_ext): New function.
	(ppc64_emit_log_not): New function.
	(ppc64_emit_bit_and): New function.
	(ppc64_emit_bit_or): New function.
	(ppc64_emit_bit_xor): New function.
	(ppc64_emit_bit_not): New function.
	(ppc64_emit_equal): New function.
	(ppc64_emit_less_signed): New function.
	(ppc64_emit_less_unsigned): New function.
	(ppc64_emit_ref): New function.
	(ppc64_emit_const): New function.
	(ppc64v1_emit_reg): New function.
	(ppc64v2_emit_reg): New function.
	(ppc64_emit_pop): New function.
	(ppc64_emit_stack_flush): New function.
	(ppc64_emit_swap): New function.
	(ppc64v1_emit_call): New function.
	(ppc64v2_emit_call): New function.
	(ppc64v1_emit_int_call_1): New function.
	(ppc64v2_emit_int_call_1): New function.
	(ppc64v1_emit_void_call_2): New function.
	(ppc64v2_emit_void_call_2): New function.
	(ppc64_emit_if_goto): New function.
	(ppc64_emit_eq_goto): New function.
	(ppc64_emit_ne_goto): New function.
	(ppc64_emit_lt_goto): New function.
	(ppc64_emit_le_goto): New function.
	(ppc64_emit_gt_goto): New function.
	(ppc64_emit_ge_goto): New function.
	(ppc64v1_emit_ops_impl): New static variable.
	(ppc64v2_emit_ops_impl): New static variable.
	(ppc_emit_ops): New function.
	(linux_low_target): Wire in ppc_emit_ops.
2016-03-31 15:39:45 +02:00
Marcin Kościelnicki a2174ba452 gdbserver: Add powerpc fast tracepoint support.
gdb/gdbserver/ChangeLog:

2016-03-31  Wei-cheng Wang  <cole945@gmail.com>
	    Marcin Kościelnicki  <koriakin@0x04.net>

	PR/17221
	* Makefile.in: Add powerpc-*-ipa.o
	* configure.srv: Add ipa_obj for powerpc*-linux.
	* linux-ppc-ipa.c: New file.
	* linux-ppc-low.c: Added linux-ppc-tdesc.h, ax.h, tracepoint.h
	includes.
	(PPC_FIELD): New macro.
	(PPC_SEXT): New macro.
	(PPC_OP6): New macro.
	(PPC_BO): New macro.
	(PPC_LI): New macro.
	(PPC_BD): New macro.
	(init_registers_*): Move prototype to linux-ppc-tdesc.h.
	(tdesc_*): Move declaration to linux-ppc-tdesc.h.
	(ppc_get_hwcap): Rename to ppc_get_auxv and add type parameter.
	(ppc_get_thread_area): New function.
	(is_elfv2_inferior): New function.
	(gen_ds_form): New function.
	(GEN_STD): New macro.
	(GEN_STDU): New macro.
	(GEN_LD): New macro.
	(GEN_LDU): New macro.
	(gen_d_form): New function.
	(GEN_ADDI): New macro.
	(GEN_ADDIS): New macro.
	(GEN_LI): New macro.
	(GEN_LIS): New macro.
	(GEN_ORI): New macro.
	(GEN_ORIS): New macro.
	(GEN_LWZ): New macro.
	(GEN_STW): New macro.
	(GEN_STWU): New macro.
	(gen_xfx_form): New function.
	(GEN_MFSPR): New macro.
	(GEN_MTSPR): New macro.
	(GEN_MFCR): New macro.
	(GEN_MTCR): New macro.
	(GEN_SYNC): New macro.
	(GEN_LWSYNC): New macro.
	(gen_x_form): New function.
	(GEN_OR): New macro.
	(GEN_MR): New macro.
	(GEN_LWARX): New macro.
	(GEN_STWCX): New macro.
	(GEN_CMPW): New macro.
	(gen_md_form): New function.
	(GEN_RLDICL): New macro.
	(GEN_RLDICR): New macro.
	(gen_i_form): New function.
	(GEN_B): New macro.
	(GEN_BL): New macro.
	(gen_b_form): New function.
	(GEN_BNE): New macro.
	(GEN_LOAD): New macro.
	(GEN_STORE): New macro.
	(gen_limm): New function.
	(gen_atomic_xchg): New function.
	(gen_call): New function.
	(ppc_relocate_instruction): New function.
	(ppc_install_fast_tracepoint_jump_pad): New function.
	(ppc_get_min_fast_tracepoint_insn_len): New function.
	(ppc_get_ipa_tdesc_idx): New function.
	(the_low_target): Wire in the new functions.
	(initialize_low_arch) [!__powerpc64__]: Don'it initialize 64-bit
	tdescs.
	* linux-ppc-tdesc.h: New file.
2016-03-31 15:39:23 +02:00
Marcin Kościelnicki a13c46966d IPA: Add alloc_jump_pad_buffer target hook.
Targets may have various requirements on the required location of the jump
pad area.  Currently IPA allocates it at the lowest possible address,
so that it is reachable by branches from the executable.  However, this
fails on powerpc, which has executable link address (0x10000000) much
larger than branch reach (+/- 32MiB).

This makes jump pad buffer allocation a target hook instead.  The current
implementations are as follows:

- i386 and s390: Branches can reach anywhere, so just mmap it.  This
  avoids the linear search dance.
- x86_64: Branches have +/-2GiB of reach, and executable is loaded low,
  so just call mmap with MAP_32BIT.  Likewise avoids the linear search.
- aarch64: Branches have +-128MiB of reach, executable loaded at 4MiB.
  Do a linear search from 4MiB-size downwards to page_size.
- s390x: Branches have +-4GiB of reach, executable loaded at 2GiB.
  Do like on aarch64.

gdb/gdbserver/ChangeLog:

	* linux-aarch64-ipa.c: Add <sys/mman.h> and <sys/auxv.h> includes.
	(alloc_jump_pad_buffer): New function.
	* linux-amd64-ipa.c: Add <sys/mman.h> include.
	(alloc_jump_pad_buffer): New function.
	* linux-i386-ipa.c (alloc_jump_pad_buffer): New function.
	* linux-s390-ipa.c: Add <sys/mman.h> and <sys/auxv.h> includes.
	(alloc_jump_pad_buffer): New function.
	* tracepoint.c (getauxval) [!HAVE_GETAUXVAL]: New function.
	(initialize_tracepoint): Delegate to alloc_jump_pad_buffer.
	* tracepoint.h (alloc_jump_pad_buffer): New prototype.
	(getauxval) [!HAVE_GETAUXVAL]: New prototype.
2016-03-31 15:36:38 +02:00
Catalin Udma e7ea3ec7c6 python: Use console format for output of gdb.execute command
When gdb is started in MI mode, the output of gdb.execute
command is in MI-format in case when it is executed from python stop
handler while for all other cases the output is in console-format.

To assure consistent output format, this is fixed by using the console
format for all python gdb command executions.

PR python/19743

gdb/ChangeLog:
2016-03-31  Catalin Udma  <catalin.udma@freescale.com>

	PR python/19743
	* python/python.c (execute_gdb_command): Use console uiout
	when executing gdb command.
	* utils.c (restore_ui_out_closure): New structure.
	(do_restore_ui_out): New function.
	(make_cleanup_restore_ui_out): Likewise.
	* utils.h (make_cleanup_restore_ui_out): Declare.

gdb/testsuite/ChangeLog:
2016-03-31  Catalin Udma  <catalin.udma@freescale.com>

	PR python/19743
	* gdb.python/py-mi-events-gdb.py: New file.
	* gdb.python/py-mi-events.c: New file.
	* gdb.python/py-mi-events.exp: New file.

Signed-off-by: Catalin Udma <catalin.udma@freescale.com>
2016-03-31 15:32:38 +03:00
Pedro Alves f7c382926d Remove support for "target m32rsdi" and "target mips/pmon/ddb/rockhopper/lsi"
This removes support for:

 | target            | source                |
 |-------------------+-----------------------|
 | target m32rsdi    | gdb/remote-m32r-sdi.c |
 | target mips       | gdb/remote-mips.c     |
 | target pmon       | gdb/remote-mips.c     |
 | target ddb        | gdb/remote-mips.c     |
 | target rockhopper | gdb/remote-mips.c     |
 | target lsi        | gdb/remote-mips.c     |

That is:

 - Remote M32R debugging over SDI.

 - Debugging boards using the MIPS remote debugging protocol
   over a serial line, PMON, and a few variants.

These are the last non-"target remote" remote targets in the tree, if
you don't count "target sim".

Refs:

 https://sourceware.org/ml/gdb/2016-03/msg00004.html
 https://sourceware.org/ml/gdb-patches/2016-03/msg00580.html

gdb/ChangeLog:
2016-03-31  Pedro Alves  <palves@redhat.com>

	* NEWS: Mention that support for "target m32rsdi", "target mips",
	"target pmon", "target ddb", "target rockhopper", and "target lsi"
	was removed.
	* Makefile.in (ALL_TARGET_OBS): Remove remote-m32r-sdi.o and
	remote-mips.o.
	(ALLDEPFILES): Remove remote-m32r-sdi.c and remote-mips.c.
	* configure.tgt: Remove all references to remote-m32r-sdi.o and
	remote-mips.o.
	* mips-tdep.c (deprecated_mips_set_processor_regs_hack): Delete
	function.
	* mips-tdep.h (deprecated_mips_set_processor_regs_hack): Delete
	declaration.
	* remote-m32r-sdi.c, remote-mips.c: Delete files.
	* symfile.c (generic_load, generic_load): Remove comments.

gdb/doc/ChangeLog:
2016-03-31  Pedro Alves  <palves@redhat.com>

	* gdb.texinfo (M32R/SDI): Delete node.
	(MIPS Embedded): Remove references to the MIPS remote debugging
	protocol, PMON and variants, and the associated commands.
2016-03-31 13:24:34 +01:00
Marcin Kościelnicki 1cda151268 gdbserver/IPA: Export some functions via global function pointers.
On powerpc64, qSymbol for a function returns the function code address,
and not the descriptor address.  Since we emit code calling gdb_collect
and some other functions, we need the descriptor (no way to know the
proper TOC address without it).  To get the descriptor address, make
global function pointer variables in the IPA pointing to the relevant
functions and read them instead of asking for them directly via qSymbol.

gdb/gdbserver/ChangeLog:

	* linux-aarch64-ipa.c: Rename gdb_agent_get_raw_reg to get_raw_reg.
	* linux-amd64-ipa.c: Likewise.
	* linux-i386-ipa.c: Likewise.
	* linux-s390-ipa.c: Likewise.
	* tracepoint.c: IPA-export gdb_collect_ptr instead of gdb_collect,
	ditto for get_raw_reg_ptr, get_trace_state_variable_value_ptr,
	set_trace_state_variable_value_ptr.
	(struct ipa_sym_addresses): Likewise.
	(symbol_list): Likewise.
	(install_fast_tracepoint): Dereference gdb_collect_ptr instead of
	accessing gdb_collect directly.
	(gdb_collect_ptr_type): New typedef.
	(get_raw_reg_ptr_type): New typedef.
	(get_trace_state_variable_value_ptr_type): New typedef.
	(set_trace_state_variable_value_ptr_type): New typedef.
	(gdb_collect_ptr): New global.
	(get_raw_reg_ptr): New global.
	(get_trace_state_variable_value_ptr): New global.
	(set_trace_state_variable_value_ptr): New global.
	(get_raw_reg_func_addr): Dereference get_raw_reg_ptr instead of
	accessing get_raw_reg directly.
	(get_get_tsv_func_addr): Likewise for
	get_trace_state_variable_value_ptr.
	(get_set_tsv_func_addr): Likewise for
	set_trace_state_variable_value_ptr.
	* tracepoint.h: Rename gdb_agent_get_raw_reg to get_raw_reg.
2016-03-30 23:48:47 +02:00
Yao Qi fb3f3d25c3 Check func against 0 rather than NULL
Variable 'func''s type is CORE_ADDR, so it should be compared with 0
rather than NULL.  This causes a build error.

This patch fixes this.

gdb:

2016-03-30  Yao Qi  <yao.qi@linaro.org>

	* arm-tdep.c (arm_epilogue_frame_this_id): Check 'func' against
	0 rather than NULL.
2016-03-30 17:03:29 +01:00
Yao Qi 779aa56f2c Add arm epilogue unwinder
Nowadays, GDB can't unwind successfully from epilogue on arm,

 (gdb) bt
 #0  0x76ff65a2 in shr1 () from /home/yao/Source/gnu/build/gdb/testsuite/gdb.reverse/shr1.sl
 #1  0x0000869e in main () at /home/yao/Source/gnu/build/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.reverse/solib-reverse.c:34
 Backtrace stopped: previous frame inner to this frame (corrupt stack?)

(gdb) disassemble shr1
Dump of assembler code for function shr1:
   ....
   0x76ff659a <+10>:	adds	r7, #12
   0x76ff659c <+12>:	mov	sp, r7
   0x76ff659e <+14>:	ldr.w	r7, [sp], #4
   0x76ff65a2 <+18>:	bx	lr
End of assembler dump.

in this case, prologue unwinder is used.  It analyzes the prologue and
get the offsets of saved registers to SP.  However, in epilogue, the
SP has been restored, prologue unwinder gets the registers from the
wrong address, and even the frame id is wrong.

In reverse debugging, this case (program stops at the last instruction
of function) happens quite frequently due to the reverse execution.
There are many test fails due to missing epilogue unwinder.

This adds epilogue unwinder, but the frame cache is still get by
prologue unwinder except that SP is fixed up separately, because SP
is restored in epilogue.

This patch fixes many fails in solib-precsave.exp, and solib-reverse.exp.

gdb:

2016-03-30  Yao Qi  <yao.qi@linaro.org>

	* arm-tdep.c: (arm_make_epilogue_frame_cache): New function.
	(arm_epilogue_frame_this_id): New function.
	(arm_epilogue_frame_prev_register): New function.
	(arm_epilogue_frame_sniffer): New function.
	(arm_epilogue_frame_unwind): New.
	(arm_gdbarch_init): Append unwinder arm_epilogue_frame_unwind.
2016-03-30 16:44:24 +01:00
Yao Qi c58b006a7e Refactor arm_stack_frame_destroyed_p
This patch is to refactor arm_stack_frame_destroyed_p, so that the code
can be used in both arm_stack_frame_destroyed_p and arm epilogue
unwinder I am going to add in the next patch.  In fact, the code
is the same in two places, but checking whether it is thumb mode
is slightly different.  arm_stack_frame_destroyed_p uses
arm_pc_is_thumb, and epilogue unwinder should use arm_frame_is_thumb.

gdb:

2016-03-30  Yao Qi  <yao.qi@linaro.org>

	* arm-tdep.c (arm_stack_frame_destroyed_p): Rename it ...
	(arm_stack_frame_destroyed_p_1): ... here.  Don't call
	arm_pc_is_thumb.
	(arm_stack_frame_destroyed_p): Call
	thumb_stack_frame_destroyed_p and
	arm_stack_frame_destroyed_p_1.
2016-03-30 16:44:24 +01:00
Yao Qi e6359af3fd Simplify gdb.reverse/until-reverse.c
Nowadays, functions fprintf, printf and malloc are executed in
gdb.reverse/until-reverse.c, so that it takes much time to record
instructions inside them.  This may cause timeout, and we had several
fixes to bump the timeout,

 https://sourceware.org/ml/gdb-patches/2012-02/msg00038.html
 https://sourceware.org/ml/gdb-patches/2015-08/msg00186.html

also I still see this on arm-linux,

 continue
 Continuing.
 Do you want to auto delete previous execution log entries when record/replay buffer becomes full (record full stop-at-limit)?([y] or n) n
 Process record: stopped by user.

 Program stopped.
 0xf77021e6 in __linkin_atfork (newp=0xf7751748 <atfork_mem>) at ../nptl/sysdeps/unix/sysv/linux/register-atfork.c:117
 117     ../nptl/sysdeps/unix/sysv/linux/register-atfork.c: No such file or directory.
 (gdb) FAIL: gdb.reverse/until-precsave.exp: run to end of main (got interactive prompt)

however, I can't figure out how these functions (fprintf, printf and
malloc) are related to the test itself.  marker1 is a function from
shared library too so we don't need these complicated libc functions
at all.  IMO, recording the instructions in these libc functions has
nothing to do with the test itself except slow down the test.  This
patch is to remove the usage of fprintf and printf, and also move
malloc to a dead code path.

gdb/testsuite:

2016-03-30  Yao Qi  <yao.qi@linaro.org>

	* gdb.reverse/until-precsave.exp: Match function name only.
	* gdb.reverse/until-reverse.c (main): Don't call fprintf nor printf.
	Move malloc to a condition block.
	* gdb.reverse/until-reverse.exp: Match function name only.
2016-03-30 16:36:51 +01:00
Simon Marchi 72fb548884 gdbserver/tracepoint.c: Remove whitespace
gdb/gdbserver/ChangeLog:

	* tracepoint.c (cmd_qtenable_disable): Remove whitespace.
2016-03-30 10:54:28 -04:00
Yao Qi 1e6697eab9 Move CL entries from gdb/ChangeLog to gdb/testsuite/ChangeLog
Two ChangeLog entries in gdb/ChangeLog should be placed in
gdb/testsuite/ChangeLog.  This patch moves them to the right
place.
2016-03-30 09:32:59 +01:00