Commit Graph

38018 Commits

Author SHA1 Message Date
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
Doug Evans 4ae6cc1962 python/py-utils.c (host_string_to_python_string): New function.
gdb/ChangeLog:

	* python/py-utils.c (host_string_to_python_string): New function.
	* python/python-internal.h (host_string_to_python_string): Declare it.
	* python/py-*.c (*): Update all calls to
	PyString_Decode (str, strlen (str), host_charset (), NULL);
	to use host_string_to_python_string instead.
2016-03-29 23:48:35 -07:00
Marcin Kościelnicki 28170b88cc gdbserver: Handle 'v' packet while processing qSymbol.
On powerpc64, qSymbol query may require gdb to read a function
descriptor, sending a vFile packet to gdbserver.  Thus, we need
to handle 'v' packet in look_up_one_symbol.

vFile replies may be quite long, and require reallocating own_buf.
Since handle_v_requests assumes the buffer is the static global own_buf
from server.c and reallocates it, we need to make own_buf global and
use it from look_up_one_symbol instead of using our own auto variable.
I've also done the same change in relocate_instruction, just in case.

On gdb side, in remote_check_symbols, rs->buf may be clobbered by vFile
handling, yet we need its contents for the reply (the symbol name is
stored there).  Allocate a new buffer instead.

This broke fast tracepoints on powerpc64, due to errors in reading IPA
symbols.

gdb/ChangeLog:

	* remote.c (remote_check_symbols): Allocate own buffer for reply.

gdbserver/ChangeLog:

	* remote-utils.c (look_up_one_symbol): Remove own_buf, handle 'v'
	packets.
	(relocate_instruction): Remove own_buf.
	* server.c (own_buf): Make global.
	(handle_v_requests): Make global.
	* server.h (own_buf): New declaration.
	(handle_v_requests): New prototype.
2016-03-30 01:51:06 +02:00
Max Filippov a08b52b5c4 gdb: xtensa: fix frame initialization when PC is invalid
When gdb is used on core dump and PC is not pointing to a readable
memory read_memory_integer call in the xtensa_frame_cache throws an
error, making register inspection/backtracing impossible in that thread.

Use safe_read_memory_integer instead.

2016-03-29  Max Filippov  <jcmvbkbc@gmail.com>
gdb/
	* xtensa-tdep.c (xtensa_frame_cache): Change op1 type to LONGEST.
	Use safe_read_memory_integer instead of read_memory_integer.
2016-03-30 02:17:24 +03:00
Marcin Kościelnicki c37c0ba69b gdb/NEWS: Add mention of s390*-linux tracepoints.
gdb/ChangeLog:

	* NEWS: Mention support for tracepoints on s390*-linux.
2016-03-29 23:39:52 +02:00
Marcin Kościelnicki f39e874354 gdbserver/s390: Add support for compiled agent expressions.
These sequences assume a z900+ CPU, like the rest of fast tracepoint
support.

gdb/gdbserver/ChangeLog:

	PR 18377
	* linux-s390-low.c (add_insns): New function.
	(s390_emit_prologue): New function.
	(s390_emit_epilogue): New function.
	(s390_emit_add): New function.
	(s390_emit_sub): New function.
	(s390_emit_mul): New function.
	(s390_emit_lsh): New function.
	(s390_emit_rsh_signed): New function.
	(s390_emit_rsh_unsigned): New function.
	(s390_emit_ext): New function.
	(s390_emit_log_not): New function.
	(s390_emit_bit_and): New function.
	(s390_emit_bit_or): New function.
	(s390_emit_bit_xor): New function.
	(s390_emit_bit_not): New function.
	(s390_emit_equal): New function.
	(s390_emit_less_signed): New function.
	(s390_emit_less_unsigned): New function.
	(s390_emit_ref): New function.
	(s390_emit_if_goto): New function.
	(s390_emit_goto): New function.
	(s390_write_goto_address): New function.
	(s390_emit_litpool): New function.
	(s390_emit_const): New function.
	(s390_emit_call): New function.
	(s390_emit_reg): New function.
	(s390_emit_pop): New function.
	(s390_emit_stack_flush): New function.
	(s390_emit_zero_ext): New function.
	(s390_emit_swap): New function.
	(s390_emit_stack_adjust): New function.
	(s390_emit_set_r2): New function.
	(s390_emit_int_call_1): New function.
	(s390_emit_void_call_2): New function.
	(s390_emit_eq_goto): New function.
	(s390_emit_ne_goto): New function.
	(s390_emit_lt_goto): New function.
	(s390_emit_le_goto): New function.
	(s390_emit_gt_goto): New function.
	(s390_emit_ge_goto): New function.
	(s390x_emit_prologue): New function.
	(s390x_emit_epilogue): New function.
	(s390x_emit_add): New function.
	(s390x_emit_sub): New function.
	(s390x_emit_mul): New function.
	(s390x_emit_lsh): New function.
	(s390x_emit_rsh_signed): New function.
	(s390x_emit_rsh_unsigned): New function.
	(s390x_emit_ext): New function.
	(s390x_emit_log_not): New function.
	(s390x_emit_bit_and): New function.
	(s390x_emit_bit_or): New function.
	(s390x_emit_bit_xor): New function.
	(s390x_emit_bit_not): New function.
	(s390x_emit_equal): New function.
	(s390x_emit_less_signed): New function.
	(s390x_emit_less_unsigned): New function.
	(s390x_emit_ref): New function.
	(s390x_emit_if_goto): New function.
	(s390x_emit_const): New function.
	(s390x_emit_call): New function.
	(s390x_emit_reg): New function.
	(s390x_emit_pop): New function.
	(s390x_emit_stack_flush): New function.
	(s390x_emit_zero_ext): New function.
	(s390x_emit_swap): New function.
	(s390x_emit_stack_adjust): New function.
	(s390x_emit_int_call_1): New function.
	(s390x_emit_void_call_2): New function.
	(s390x_emit_eq_goto): New function.
	(s390x_emit_ne_goto): New function.
	(s390x_emit_lt_goto): New function.
	(s390x_emit_le_goto): New function.
	(s390x_emit_gt_goto): New function.
	(s390x_emit_ge_goto): New function.
	(s390_emit_ops): New function.
	(struct linux_target_ops): Fill in emit_ops hook.
2016-03-29 23:39:46 +02:00
Marcin Kościelnicki abd9baf9c6 gdbserver/s390: Add fast tracepoint support.
Fast tracepoints will only work on 6-byte intructions, and assume at least
a z900 CPU.  s390 also has 4-byte jump instructions, which also work on
pre-z900, but their range is limitted to +-64kiB, which is not very useful
(and wouldn't work at all with current jump pad allocation).

There's a little problem with s390_relocate_instruction function: it
converts BRAS/BRASL instructions to LARL of the return address + JG
to the target address.  On 31-bit, this sets the high bit of the target
register to 0, while BRAS/BRASL would set it to 1.  While this is not
a problem when the result is only used to address memory, it could
possibly break something that expects to compare such addresses for
equality without first masking the bit off.  In particular, I'm not sure
whether leaving the return address high bit unset is ABI-compliant
(could confuse some unwinder?).  If that's a problem, it could be fixed
by handling it in the jump pad (since at that point we can just modify
the GPRs in the save area without having to worry about preserving
CCs and only having that one GPR to work with - I'm not sure if it's
even possible to set the high bit with such constraints).

gdb/gdbserver/ChangeLog:

	PR 18377
	* Makefile.in: Add s390 IPA files.
	* configure.srv: Build IPA for s390.
	* linux-s390-ipa.c: New file.
	* linux-s390-low.c: New includes - inttypes.h and linux-s390-tdesc.h.
	(init_registers_s390_linux32): Move declaration to linux-s390-tdesc.h.
	(tdesc_s390_linux32): Likewise.
	(init_registers_s390_linux32v1): Likewise.
	(tdesc_s390_linux32v1): Likewise.
	(init_registers_s390_linux32v2): Likewise.
	(tdesc_s390_linux32v2): Likewise.
	(init_registers_s390_linux64): Likewise.
	(tdesc_s390_linux64): Likewise.
	(init_registers_s390_linux64v1): Likewise.
	(tdesc_s390_linux64v1): Likewise.
	(init_registers_s390_linux64v2): Likewise.
	(tdesc_s390_linux64v2): Likewise.
	(init_registers_s390_te_linux64): Likewise.
	(tdesc_s390_te_linux64): Likewise.
	(init_registers_s390_vx_linux64): Likewise.
	(tdesc_s390_vx_linux64): Likewise.
	(init_registers_s390_tevx_linux64): Likewise.
	(tdesc_s390_tevx_linux64): Likewise.
	(init_registers_s390x_linux64): Likewise.
	(tdesc_s390x_linux64): Likewise.
	(init_registers_s390x_linux64v1): Likewise.
	(tdesc_s390x_linux64v1): Likewise.
	(init_registers_s390x_linux64v2): Likewise.
	(tdesc_s390x_linux64v2): Likewise.
	(init_registers_s390x_te_linux64): Likewise.
	(tdesc_s390x_te_linux64): Likewise.
	(init_registers_s390x_vx_linux64): Likewise.
	(tdesc_s390x_vx_linux64): Likewise.
	(init_registers_s390x_tevx_linux64): Likewise.
	(tdesc_s390x_tevx_linux64): Likewise.
	(have_hwcap_s390_vx): New static variable.
	(s390_arch_setup): Fill have_hwcap_s390_vx.
	(s390_get_thread_area): New function.
	(s390_ft_entry_gpr_esa): New const.
	(s390_ft_entry_gpr_zarch): New const.
	(s390_ft_entry_misc): New const.
	(s390_ft_entry_fr): New const.
	(s390_ft_entry_vr): New const.
	(s390_ft_main_31): New const.
	(s390_ft_main_64): New const.
	(s390_ft_exit_fr): New const.
	(s390_ft_exit_vr): New const.
	(s390_ft_exit_misc): New const.
	(s390_ft_exit_gpr_esa): New const.
	(s390_ft_exit_gpr_zarch): New const.
	(append_insns): New function.
	(s390_relocate_instruction): New function.
	(s390_install_fast_tracepoint_jump_pad): New function.
	(s390_get_min_fast_tracepoint_insn_len): New function.
	(s390_get_ipa_tdesc_idx): New function.
	(struct linux_target_ops): Wire in the above functions.
	(initialize_low_arch) [!__s390x__]: Don't initialize s390x tdescs.
	* linux-s390-tdesc.h: New file.
2016-03-29 23:39:00 +02:00
Marcin Kościelnicki a4105d04e1 gdbserver/s390: Switch on tracepoint support.
Also adds s390 support to gdb.trace testsuite.

gdb/gdbserver/ChangeLog:

	* linux-s390-low.c (s390_supports_tracepoints): New function.
	(struct linux_target_ops): Fill supports_tracepoints hook.

gdb/testsuite/ChangeLog:

	* gdb.trace/ftrace.exp: Set arg0exp for s390.
	* gdb.trace/mi-trace-frame-collected.exp: Expect 4 registers on s390.
	* gdb.trace/mi-trace-unavailable.exp: Set pcnum for s390, add gpr0num
	variable for GPR 0 instead of assuming it is register 0.
	* gdb.trace/trace-common.h: Add s390 fast tracepoint placeholder.
	* lib/trace-support.exp: Add s390 registers.
2016-03-29 23:08:05 +02:00
Don Breazeal 444bca650a 2016-03-29 Don Breazeal <donb@codesourcery.com>
* gdb/value.c (value_actual_type): Fix formatting issue.
2016-03-29 10:36:07 -07:00
Yao Qi bfa6adb959 Compile gdb.arch/arm-neon.exp with debug info
Pass "debug" to prepare_for_testing otherwise, some tests fail.

gdb/testsuite:

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

	* gdb.arch/arm-neon.exp: Pass debug to prepare_for_testing.
2016-03-29 14:53:25 +01:00
Yao Qi dfa3faca36 Add quotation mark in test message
I happen to see a quotation mark is missing the following test,

 gdb_test "break $end_location" \
     "Breakpoint $decimal at .* line $end_location\." \
     set breakpoint at end of main"

so the test result is

PASS: gdb.reverse/break-reverse.exp: set

This patch is to add the missing quotation mark back, and the test
result becomes

PASS: gdb.reverse/break-reverse.exp: set breakpoint at end of main

gdb/testsuite:

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

	* gdb.reverse/break-reverse.exp: Add quotation mark in the
	test message.
2016-03-24 09:53:50 +00:00
Yao Qi cc651c1cdd Remove comments on software_single_step in gdbarch.sh
This comment is out of date.  We've already done that.  Patch is to remove
it.

gdb:

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

	* gdbarch.sh (software_single_step): Remove comments.
	* gdbarch.h: Regenerated.
2016-03-23 11:21:20 +00:00
Yao Qi c55978a67a ARM process record: median instructions
This patch is to support some ARM median instructions in process
record.  With this patch applied, these fails are fixed:

 -FAIL: gdb.reverse/break-precsave.exp: run to end of main
 -FAIL: gdb.reverse/break-precsave.exp: go to end of main forward
 -FAIL: gdb.reverse/break-precsave.exp: end of record log
 -FAIL: gdb.reverse/break-reverse.exp: continue to breakpoint: end
 -FAIL: gdb.reverse/break-reverse.exp: end of record log
 -FAIL: gdb.reverse/until-precsave.exp: run to end of main
 -FAIL: gdb.reverse/until-precsave.exp: advance to marker2
 -FAIL: gdb.reverse/until-precsave.exp: until func, not called by current frame
 -FAIL: gdb.reverse/until-precsave.exp: reverse-advance to marker2
 -FAIL: gdb.reverse/until-precsave.exp: reverse-finish from marker2
 -FAIL: gdb.reverse/until-precsave.exp: reverse-advance to final return of factorial
 -FAIL: gdb.reverse/until-precsave.exp: reverse-until to entry of factorial
 -FAIL: gdb.reverse/until-reverse.exp: advance to marker2
 -FAIL: gdb.reverse/until-reverse.exp: until func, not called by current frame
 -FAIL: gdb.reverse/until-reverse.exp: reverse-advance to marker2
 -FAIL: gdb.reverse/until-reverse.exp: reverse-finish from marker2
 -FAIL: gdb.reverse/until-reverse.exp: reverse-advance to final return of factorial
 -FAIL: gdb.reverse/until-reverse.exp: reverse-until to entry of factorial

gdb:

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

	* arm-tdep.c (arm_record_media): New.
	(arm_record_ld_st_reg_offset): Call arm_record_media.
2016-03-21 10:41:38 +00:00
Yao Qi 479fe002f5 Canonicalize more arm linux syscalls
This patch is to canonicalize more syscalls on arm linux in process
record.  In this patch, I also comment out some syscalls which isn't
handled by GDB now.  With this patch applied, two fails are fixed.

-FAIL: gdb.reverse/fstatat-reverse.exp: continue to breakpoint: marker2
-FAIL: gdb.reverse/recvmsg-reverse.exp: continue to breakpoint: marker2

gdb:

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

	* arm-linux-tdep.c (arm_canonicalize_syscall): Canonicalize
	more syscalls.
2016-03-21 10:22:59 +00:00
Yao Qi 9c3f22346d Make sparc_software_single_step static
sparc_software_single_step is not used out of sparc-tdep.c, so this
patch makes it static.

gdb:

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

	* sparc-tdep.c (sparc_software_single_step): Make it static.
	* sparc-tdep.h (sparc_software_single_step): Remove declaration.
2016-03-18 15:01:47 +00:00
Yao Qi 941319d151 [spu] throw error when target_read_memory fails
I happen to see that 1 is returned in spu_software_single_step when
target_read_memory returns 1.  It must be wrong.  That patch changes
it to throwing an error.  Note that I choose to throw error because I
find the code in the end of spu_software_single_step throws errors.

gdb:

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

	* spu-tdep.c (spu_software_single_step): Throw error when
	target_read_memory fails.
2016-03-18 14:39:09 +00:00
Yao Qi 35ac8b3e2d Check lwp_signal_can_be_delivered for enqueue/dequeue pending signals
The enqueue and dequeue signals in linux_resume_one_lwp_throw use one
condition and its inverted one.  This patch is to move the condition
into a function lwp_signal_can_be_delivered, so that the next patch can
change the condition in one place.

gdb/gdbserver:

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

	* linux-low.c (lwp_signal_can_be_delivered): New function.
	(linux_resume_one_lwp_throw): Use lwp_signal_can_be_delivered.
2016-03-18 14:34:37 +00:00
Yao Qi 94610ec4ee Set signal to 0 after enqueue_pending_signal
Today, we enqueue signal in linux_resume_one_lwp_throw, but set
variable 'signal' many lines below with the comment

      /* Postpone any pending signal.  It was enqueued above.  */
      signal = 0;

I feel difficult to associate code across many lines, and we should
move the code close to enqueue_pending_signal call.  This is what
this patch does in general.  After this change, variable 'signal'
is set to zero very early, so the 'signal' value in the following
debugging message makes no sense, so I remove it from the debugging
message.  The function returns early if lwp->status_pending_p is
true, so 'signal' value in the debugging message doesn't matter,
AFAICS.  Also, I move one debugging message several lines below to
make it close the real ptrace call,

  if (debug_threads)
    debug_printf ("Resuming lwp %ld (%s, signal %d, stop %s)\n",
		  lwpid_of (thread), step ? "step" : "continue", signal,
		  lwp->stop_expected ? "expected" : "not expected");

so that the debugging message can reflect what GDBserver does.  This
is a code refactor and only debugging messages are affected.

gdb/gdbserver:

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

	* linux-low.c (linux_resume_one_lwp_throw): Set 'signal' to
	0 if signal is enqueued.  Remove 'signal' from one debugging
	message.  Move one debugging message to some lines below.
	Remove code setting 'signal' to 0.
2016-03-18 14:31:40 +00:00
Yao Qi 80aea927cc Remove redundant WIFSTOPPED check
WIFSTOPPED is checked linux_wstatus_maybe_breakpoint, so WIFSTOPPED
in "WIFSTOPPED (wstat) && linux_wstatus_maybe_breakpoint (wstat)"
is redundant.  This patch removes WIFSTOPPED check.

gdb/gdbserver:

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

	* linux-low.c (linux_low_filter_event): Remove redundant
	WIFSTOPPED check together with linux_wstatus_maybe_breakpoint.
2016-03-18 14:28:14 +00:00
Jan Kratochvil 708bf0a14b Suggest running gdbserver for a PID in container
currently
	gdb -p <pid from a container>
will print:
	warning: Target and debugger are in different PID namespaces; thread lists and other data are likely unreliable

It correctly states the problem but it does not say how to solve it.

Originally I wanted to suggest also the Docker "-p 1234:1234" parameter but
I see the containers are more general topic than just Docker (even LxC etc.).

According to Gary future GDBs should be able to work even without gdbserver.
But currently gdbserver is still required.

gdb/ChangeLog
2016-03-17  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* linux-thread-db.c (check_pid_namespace_match): Extend the message.
2016-03-17 18:17:30 +01:00
Pedro Alves 0d5b594f86 PR remote/19496, timeout in forking-threads-plus-bkpt
This patch addresses a failure in
gdb.threads/forking-threads-plus-breakpoint.exp:

FAIL: gdb.threads/forking-threads-plus-breakpoint.exp: cond_bp_target=1:
detach_on_fork=on: inferior 1 exited (timeout)

Cause:

A fork event was reported to GDB before GDB knew about the parent
thread, followed immediately by a breakpoint event in a different
thread.  The parent thread was subsequently added via
remote_notice_new_inferior in process_stop_reply, but when the thread
was added the thread_info.state was set to THREAD_STOPPED.  The fork
event was then handled correctly, but when the fork parent was resumed
via a call to keep_going, the state was unchanged.

The breakpoint event was then handled, which caused all the
non-breakpoint threads to be stopped.  When the breakpoint thread was
resumed, all the non-breakpoint threads were resumed via
infrun.c:restart_threads.  Our old fork parent wasn't restarted,
because it still had thread_info.state set to THREAD_STOPPED.
Ultimately the program under debug hung waiting for a pthread_join
while the old fork parent was stopped forever by GDB.

Fix:

Since this is non-stop, then the bug is that the thread should have
been added in THREAD_RUNNING state.  Consider that infrun may be
pulling target events out of the target_ops backend into its own event
queue, but, not process them immediately.  E.g., infrun may be
stopping all threads temporarily for a step-over-breakpoint operation
for thread A (stop_all_threads).  The waitstatus of all threads is
thus left pending in the thread structure (save_status), including the
fork event of thread B.  Right at this point, if the user does "info
threads", that should show thread B (the fork parent) running, not
stopped, even if internally, gdb is holding it paused for a little
bit.

Thus if in non-stop mode, always add new threads in the external
user-visible THREAD_RUNNING state.  Change remote_notice_new_inferior
to accept the internal executing state of the thread instead, with
EXECUTING set to 1 when we discover a thread that is running on the
target (such as through remote_update_thread_list), and 0 when the
thread is really paused (such as when we see a stop reply).

Tested on x86_64 Linux and Nios II Linux target with x86 Linux host.

gdb/ChangeLog:
2016-03-17  Pedro Alves  <palves@redhat.com>
	    Don Breazeal  <donb@codesourcery.com>

	PR remote/19496
	* infcmd.c (notice_new_inferior): Use the 'leave_running' argument
	instead of checking the 'non_stop' global.
	* remote.c (remote_add_thread): New parameter 'executing'.  Use it
	to set the new thread's executing state.
	(remote_notice_new_inferior): Rename parameter 'running' to
	'executing'.  Always set the thread state to THREAD_RUNNING in
	non-stop mode, and to THREAD_STOPPED in all-stop mode.  Pass
	EXECUTING to remote_add_thread and notice_new_inferior.
	(remote_update_thread_list): Update to pass executing state, not
	running state.
2016-03-17 10:21:37 +00:00
Andreas Arnez bba960fc4b S390: Add syscall info for syscalls up to 374
Represent new Linux syscalls for s390 and s390x in GDB's syscall info.
Add the syscalls from 355 (userfaultfd) up to 374 (mlock2) as well as
the previously reserved NUMA syscalls 268-270, 287, and 310.

gdb/ChangeLog:

	* syscalls/s390-linux.xml: Add NUMA syscalls and new syscalls up
	to 374.
	* syscalls/s390x-linux.xml: Likewise.
2016-03-17 10:55:55 +01:00
Andreas Arnez 64bcd522de S390: Fix output path for s390-multiarch test case
Since test artifacts are organized in a directory hierarchy, the
s390-multiarch test case is not executed correctly any more.  This is
because it uses an obsolete way of constructing the output paths.

This fix invokes standard_testfile instead.

gdb/testsuite/ChangeLog:

	* gdb.arch/s390-multiarch.exp: Use standard_testfile instead of
	maintaining separate logic for constructing the output path.
2016-03-17 10:55:55 +01:00
Andreas Arnez 5fd0888aff linux-record: Simplify with record_mem_at_reg()
The function record_linux_system_call() often records a memory area
whose address is contained in a register.  So far this required two
function calls: one for fetching the register value, and another one for
recording the memory area.  These two function calls are now merged into
a new local helper function, and all occurrences are adjusted.  This
reduces the source code and makes it more readable.

gdb/ChangeLog:

	* linux-record.c (record_mem_at_reg): New helper function.
	(record_linux_system_call): Exploit new helper function where
	applicable.
2016-03-17 09:58:57 +01:00
Andreas Arnez 0fc8f115fd linux-record.c: Fix whitespace issues
This patch changes whitespace only, fixing whitespace issues in
linux-record.c.

gdb/ChangeLog:

	* linux-record.c: Fix whitespace issues; tabify, remove trailing
	spaces.
2016-03-17 09:58:57 +01:00
Andreas Arnez afdab91654 linux-record: Fix bad fall-through for pipe/pipe2
This patch added handling for some syscalls to linux-record.c:

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

But for both `pipe' and `pipe2' the patch lacks a statement after an
`if', such that the following `break' is interpreted as the `if'-body
instead.

This adds the missing (return-) statements for the conditionals.

gdb/ChangeLog:

	* linux-record.c (record_linux_system_call): Add missing return
	statements to handling of pipe and pipe2 syscalls.
2016-03-17 09:58:56 +01:00
Don Breazeal 7868401b7b PR remote/19496, interrupted syscall in forking-threads-plus-bkpt
This patch addresses "fork:Interrupted system call" (or wait:) failures
in gdb.threads/forking-threads-plus-breakpoint.exp.

The test program spawns ten threads, each of which do ten fork/waitpid
sequences.  The cause of the problem was that when one of the fork
children exited before the corresponding fork parent could initiate its
waitpid for that child, a SIGCHLD and/or SIGSTOP was delivered and
interrupted a fork or waitpid in another thread.

The fix was to wrap the system calls in a loop to retry the call if
it was interrupted, like:

do
  {
    pid = fork ();
  }
while (pid == -1 && errno == EINTR);

Since this is a Linux-only test I figure it is OK to use errno and EINTR.
I tried a number of alternative fixes using SIG_IGN, SA_RESTART,
pthread_sigblock, and bsd_signal, but none of these worked as well.

Tested on Nios II Linux target with x86 Linux host.

gdb/testsuite/ChangeLog:
2016-03-16  Don Breazeal  <donb@codesourcery.com>

	* gdb.threads/forking-threads-plus-breakpoint.c (thread_forks):
	Retry fork and waitpid on interrupted system call errors.
	* gdb.threads/forking-threads-plus-breakpoint.exp: (do_test):
	Use with_timeout_factor to increase timeout to 90.
2016-03-16 15:13:44 -07:00
Doug Evans bfeeb14b84 xml-tdesc.c (tdesc_start_enum): Fix c++ build.
gdb/ChangeLog:

	* xml-tdesc.c (tdesc_start_enum): Fix c++ build.
2016-03-16 10:30:41 -07:00
Yao Qi 6b94a855be Process record: Fix arm-linux syscall arguments
Arguments are passed in r0-r6 on arm linux syscall (both EABI and OABI).
This patch is to set arm_linux_record_tdep.arg{1-7} to the right
register number.

This patch fixes the following test failures...

-FAIL: gdb.reverse/getresuid-reverse.exp: check ruid record
-FAIL: gdb.reverse/getresuid-reverse.exp: check rgid record
-FAIL: gdb.reverse/pipe-reverse.exp: check pipe record
-FAIL: gdb.reverse/readv-reverse.exp: check readv record
-FAIL: gdb.reverse/readv-reverse.exp: check readv record
-FAIL: gdb.reverse/readv-reverse.exp: check readv record
-FAIL: gdb.reverse/readv-reverse.exp: check readv record
-FAIL: gdb.reverse/waitpid-reverse.exp: check waitpid record

gdb:

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

	* arm-linux-tdep.c (arm_linux_init_abi): Fix
	arm_linux_record_tdep.arg1, arm_linux_record_tdep.arg2 and
	arm_linux_record_tdep.arg3.  Set arm_linux_record_tdep.arg4,
	arm_linux_record_tdep.arg5, arm_linux_record_tdep.arg6, and
	arm_linux_record_tdep.arg7.
2016-03-16 14:55:56 +00:00
Don Breazeal 1cafadb4e4 PR 18303, Tolerate malformed input for lookup_symbol-called functions
lookup_symbol is often called with user input.  Consequently, any
function called from lookup_symbol{,_in_language} should attempt to
deal with malformed input gracefully.  After all, malformed user
input is not a programming/API error.

This patch does not attempt to find/correct all instances of this.  It
only fixes locations in the code that trigger test suite failures.

This patch fixes PR breakpoints/18303, "Assertion: -breakpoint-insert
with windows paths of file in non-current directory".

The patch includes three new tests related to this.  One is just
gdb.linespec/ls-errs.exp copied and converted to use C++ instead of C, and
to add a case using a file name containing a Windows-style logical drive
specifier.  The others include an MI test to provide a regression test for
the specific case reported in PR 18303, and a C++ test for proper error
handling of access to a program variable when using a file scope specifier
that refers to a non-existent file.

Tested on x86_64 native Linux.

gdb/ChangeLog
2016-01-28  Keith Seitz  <keiths@redhat.com>

	PR breakpoints/18303
	* cp-namespace.c (cp_lookup_bare_symbol): Change assertion to
	look for "::" instead of simply ":".
	(cp_search_static_and_baseclasses): Return null_block_symbol for
	malformed input.
	Remove assertions.
	* cp-support.c (cp_find_first_component_aux): Do not return
	a prefix length for ':' unless the next character is also ':'.

gdb/testsuite/ChangeLog
2016-01-28  Don Breazeal  <donb@codesourcery.com>

	* gdb.cp/scope-err.cc: New test program.
	* gdb.cp/scope-err.exp: New test script.
	* gdb.linespec/ls-errs.c (myfunction): Expanded to have multiple
	lines and "set breakpoint here" comment.
	* gdb.linespec/ls-errs.exp: Added C++ testing and new test case.
	Fixed some whitespace and format issues.
	* gdb.mi/mi-linespec-err-cp.cc: New test program.
	* gdb.mi/mi-linespec-err-cp.exp: New test script.
2016-03-15 15:25:15 -07:00
Doug Evans 79427bd2f8 Add cole945@ to earlier entry. Fix typo in same entry. 2016-03-15 15:02:13 -07:00
Doug Evans 89c200ed1b Add cpsr_flags to aarch64 core regs.
gdb/ChangeLog:

	* features/aarch64-core.xml (cpsr_flags): New flags type.
	(cpsr): Use it.
	* features/aarch64.c: Regenerate.
2016-03-15 14:43:49 -07:00
Doug Evans 49b7ae7bb8 Remove "end" spec.
gdb/ChangeLog:

	* features/i386/32bit-core.xml (i386_eflags): Remove "end" spec.
	* features/i386/32bit-sse.xml (i386_eflags): Ditto.
	* features/i386/64bit-core.xml (i386_eflags): Ditto.
	* features/i386/64bit-sse.xml (i386_eflags): Ditto.
	* features/i386/x32-core.xml (i386_eflags): Ditto.
2016-03-15 14:41:52 -07:00
Doug Evans 8151645076 Extend flags to support multibit and enum bitfields.
gdb/ChangeLog:

	Extend flags to support multibit and enum bitfields.
	NEWS: Document new features.
	* c-typeprint.c (c_type_print_varspec_prefix): Handle TYPE_CODE_FLAGS.
	(c_type_print_varspec_suffix, c_type_print_base): Ditto.
	* gdbtypes.c (arch_flags_type): Don't assume all fields are one bit.
	(append_flags_type_field): New function.
	(append_flags_type_flag): Call it.
	* gdbtypes.h (append_flags_type_field): Declare.
	* target-descriptions.c (struct tdesc_type_flag): Delete.
	(enum tdesc_type_kind) <TDESC_TYPE_BOOL>: New enum value.
	(enum tdesc_type_kind) <TDESC_TYPE_ENUM>: Ditto.
	(struct tdesc_type) <u.f>: Delete.
	(tdesc_predefined_types): Add "bool".
	(tdesc_predefined_type): New function.
	(tdesc_gdb_type): Handle TDESC_TYPE_BOOL, TDESC_TYPE_ENUM.
	Update TDESC_TYPE_FLAGS support.
	(tdesc_free_type): Handle TDESC_TYPE_ENUM.  Update TDESC_TYPE_FLAGS.
	(tdesc_create_flags): Update.
	(tdesc_create_enum): New function.
	(tdesc_add_field): Initialize start,end to -1.
	(tdesc_add_typed_bitfield): New function.
	(tdesc_add_bitfield): Call it.
	(tdesc_add_flag): Allow TDESC_TYPE_STRUCT.  Update.
	(tdesc_add_enum_value): New function.
	(maint_print_c_tdesc_cmd): Fold TDESC_TYPE_FLAGS support into
	TDESC_TYPE_STRUCT.  Handle TDESC_TYPE_ENUM.
	* target-descriptions.h (tdesc_create_enum): Declare.
	(tdesc_add_typed_bitfield, tdesc_add_enum_value): Declare.
	* valprint.c (generic_val_print_enum_1): New function.
	(generic_val_print_enum): Call it.
	(val_print_type_code_flags): Make static.  Handle multibit bitfields
	and enum bitfields.
	* valprint.h (val_print_type_code_flags): Delete.
	* xml-tdesc.c (struct tdesc_parsing_data) <current_type_is_flags>:
	Delete.  All uses removed.
	(tdesc_start_enum): New function.
	(tdesc_start_field): Handle multibit and enum bitfields.
	(tdesc_start_enum_value): New function.
	(enum_value_attributes, enum_children, enum_attributes): New static
	globals.
	(feature_children): Add "enum".
	* features/gdb-target.dtd (enum, evalue): New elements.

gdb/doc/ChangeLog:

	* gdb.texinfo (Target Descriptions): New menu item "Enum Target Types".
	(Target Description Format): Mention enum types.  Update docs on
	flags types.
	(Predefined Target Types): Add "bool".
	(Enum Target Types): New node.

gdb/testsuite/ChangeLog:

	* gdb.xml/extra-regs.xml: Add enum, mixed_flags values.
	* gdb.xml/tdesc-regs.exp (load_description): New arg xml_file.
	All callers updated.  Add tests for enums, mixed flags register.
2016-03-15 14:37:29 -07:00
Doug Evans 54157a25aa Use int instead of LONGEST in tdesc_type sizes.
gdb/ChangeLog:

	* target-descriptions.c (struct tdesc_type) <u.u.size>: Change type
	from LONGEST to int.
	(struct tdesc_type) <u.f.size>: Ditto.
	(tdesc_set_struct_size): Change type of "size" arg from LONGEST
	to int.  Add assertion size > 0.
	(tdesc_create_flags): Ditto.
	* target-descriptions.h (tdesc_set_struct_size): Update.
	(tdesc_create_flags): Update.
	* xml-tdesc.c (MAX_FIELD_SIZE, MAX_FIELD_BITSIZE): New macros.
	(MAX_VECTOR_SIZE): New macro.
	(tdesc_start_struct): Catch conversion errors from LONGEST to int.
	(tdesc_start_flags, tdesc_start_field, tdesc_start_vector): Ditto.
2016-03-15 12:57:06 -07:00
Doug Evans 73b4f516a0 maint_print_c_tdesc_cmd: Use type for TYPE_CODE_FLAGS instead of field_type.
gdb/ChangeLog:

	* target-descriptions.c (maint_print_c_tdesc_cmd): Use "type" for
	TYPE_CODE_FLAGS instead of "field_type", for consistency.
	* features/i386/amd64-avx-linux.c: Regenerate.
	* features/i386/amd64-avx.c: Regenerate.
	* features/i386/amd64-avx512-linux.c: Regenerate.
	* features/i386/amd64-avx512.c: Regenerate.
	* features/i386/amd64-linux.c: Regenerate.
	* features/i386/amd64-mpx-linux.c: Regenerate.
	* features/i386/amd64-mpx.c: Regenerate.
	* features/i386/amd64.c: Regenerate.
	* features/i386/i386-avx-linux.c: Regenerate.
	* features/i386/i386-avx.c: Regenerate.
	* features/i386/i386-avx512-linux.c: Regenerate.
	* features/i386/i386-avx512.c: Regenerate.
	* features/i386/i386-linux.c: Regenerate.
	* features/i386/i386-mmx-linux.c: Regenerate.
	* features/i386/i386-mmx.c: Regenerate.
	* features/i386/i386-mpx-linux.c: Regenerate.
	* features/i386/i386-mpx.c: Regenerate.
	* features/i386/i386.c: Regenerate.
	* features/i386/x32-avx-linux.c: Regenerate.
	* features/i386/x32-avx.c: Regenerate.
	* features/i386/x32-avx512-linux.c: Regenerate.
	* features/i386/x32-avx512.c: Regenerate.
	* features/i386/x32-linux.c: Regenerate.
	* features/i386/x32.c: Regenerate.
2016-03-15 12:53:55 -07:00
Doug Evans aa52b601cc Remove hand-called function from test.
gdb/testsuite/ChangeLog:

	* gdb.base/skip.c (main): Call test_skip_file_and_function.
	* gdb.base/skip.exp: Remove hand calling test_skip_file_and_function.
2016-03-15 12:44:34 -07:00
Pedro Alves 1eb2dbb8d7 Fix PR gdb/19676: Internal error in linux-thread.db.c if /proc not mounted
If /proc is not mounted, GDB fails an assertion in find_new_threads_once:

 Continuing.
 .../src/gdb/linux-thread-db.c:1249: internal-error: find_new_threads_once: Assertion `!target_has_execution' failed.
 A problem internal to GDB has been detected,
 further debugging may prove unreliable.
 Quit this debugging session? (y or n)

That was supposed to catch misuses of td_ta_thr_iter, which is unsafe
for live debugging.  However, if /proc is not mounted, we still
fallback to using it.

I didn't bother with a warning, because GDB already prints several
others related to failing to open /proc files.

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

	PR gdb/19676
	* linux-thread-db.c (try_thread_db_load_1): Leave
	info->td_ta_thr_iter_p NULL iff debugging a live process and we
	have /proc access.
	(find_new_threads_once): Assert that we have a non-NULL
	info->td_ta_thr_iter_p instead of checking whether the target has
	execution.
2016-03-15 16:33:04 +00:00
Pedro Alves 16b4184277 Fix PR gdb/19676: Disable displaced stepping if /proc not mounted
On GNU/Linux archs that support displaced stepping, if /proc is not
mounted, GDB gets stuck not able to step past breakpoints:

 (gdb) c
 Continuing.
 dl_main (phdr=<optimized out>, phnum=<optimized out>, user_entry=<optimized out>, auxv=<optimized out>) at rtld.c:2163
 2163      LIBC_PROBE (init_complete, 2, LM_ID_BASE, r);
 Cannot find AT_ENTRY auxiliary vector entry.
 (gdb) c
 Continuing.
 dl_main (phdr=<optimized out>, phnum=<optimized out>, user_entry=<optimized out>, auxv=<optimized out>) at rtld.c:2163
 2163      LIBC_PROBE (init_complete, 2, LM_ID_BASE, r);
 Cannot find AT_ENTRY auxiliary vector entry.
 (gdb)

That's because GDB can't figure out where the scratch pad is.

This is a regression introduced by the earlier changes to make the
Linux native target always work in non-stop mode.

This commit makes GDB detect the case and fallback to stepping over
breakpoints in-line.

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

	PR gdb/19676
	* infrun.c (displaced_step_prepare): Also disable displaced
	stepping on NOT_SUPPORTED_ERROR.
	* linux-tdep.c (linux_displaced_step_location): If reading auxv
	fails, throw NOT_SUPPORTED_ERROR instead of generic error.
2016-03-15 16:33:04 +00:00
Pedro Alves 2a60e18f8f Fix typo in previous gdb/doc/ commit
Should be s/reliability/reliably/.

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

	* gdb.texinfo (Tracepoint Actions): Fix typo.
2016-03-15 11:29:03 +00:00
Pedro Alves 45fa2529db Document possible unreliability of '$_ret'
gdb/doc/ChangeLog:
2016-03-15  Pedro Alves  <palves@redhat.com>
	    Andreas Arnez  <arnez@linux.vnet.ibm.com>
	    Marcin Kościelnicki  <koriakin@0x04.net>

	* gdb.texinfo (Tracepoint Actions): Document possible
	unreliability of '$_ret'.
2016-03-15 11:08:52 +00:00
Simon Marchi fa4ff31331 gdb.base/default.exp: Add missing $_as_string to "show convenience" test
When adding the $_as_string convenience function, I missed a new test
failure in default.exp.  The tests lists the convenience functions, so
$_as_string should be added to the expected list.

Fixes:

+FAIL: gdb.base/default.exp: show convenience ($_caller_is = <internal function _caller_is> not found)

gdb/testsuite/ChangeLog:

	* gdb.base/default.exp: Add $_as_string to the list of expected
	convenience functions.
2016-03-14 12:43:39 -04:00
Marcin Kościelnicki 70104a9087 gdb/s390: Fill gen_return_address hook.
gdb/ChangeLog:

	* s390-linux-tdep.c (s390_gen_return_address): New function.
	(s390_gdbarch_init): Fill gen_return_address hook.
2016-03-13 10:52:26 +01:00
Andrew Burgess f2403c3934 gdb: New maint info line-table command.
Add a new command 'maint info line-table' to display the contents of
GDB's internal line table structure.  Useful when trying to understand
problems (within gdb) relating to line tables.

gdb/ChangeLog:

	* symmisc.c (maintenance_info_line_tables): New function.
	(maintenance_print_one_line_table): New function.
	(_initialize_symmisc): Register 'maint info line-table' command.
	* NEWS: Mention new command.

gdb/doc/ChangeLog:

	* gdb.texinfo (Symbols): Document new 'maint info line-table'
	command.

gdb/testsuite/ChangeLog:

	* gdb.base/maint.exp: New tests for 'maint info line-table'.
2016-03-11 22:48:21 +00:00
Marcin Kościelnicki c4b3e547d5 gdb/s390: Fill pseudo register agent expression hooks.
gdb/ChangeLog:

	* s390-linux-tdep.c (s390_ax_pseudo_register_collect): New function.
	(s390_ax_pseudo_register_push_stack): New function.
	(s390_gdbarch_init): Fill ax_pseudo_register_collect and
	ax_pseudo_register_push_stack hooks.
2016-03-11 11:02:49 +01:00
Simon Marchi f2f3ccb9f8 Add $_as_string convenience function
This patch is a follow-up to "Add printf format specifier for printing
enumerator":

  https://sourceware.org/ml/gdb-patches/2016-02/msg00144.html

Instead of having a solution specific to the printf command, Pedro
suggested adding a general purpose function $_as_string() that would
cover this use case and more.

So, in order to print the textual label of an enum, one can use:

  (gdb) printf "Visiting node of type %s\n", $_as_string(node)
  Visiting node of type NODE_INTEGER

gdb/ChangeLog:

	* data-directory/Makefile.in (PYTHON_FILE_LIST): Install
	gdb/function/as_string.py.
	* python/lib/gdb/function/as_string.py: New file.
	* NEWS: Mention the new $_as_string function.

gdb/testsuite/ChangeLog:

	* gdb.python/py-as-string.exp: New file.
	* gdb.python/py-as-string.c: New file.

gdb/doc/ChangeLog:

	* gdb.texinfo (Convenience Functions): Document $_as_string.
2016-03-10 17:12:30 -05:00
Pedro Alves 00dbd492e4 More "Program" -> "Thread NN received signal" testsuite adjustment
These tests should have been adjusted by f303dbd60d (Fix PR
threads/19422 - show which thread caused stop), but clearly I had
missed grepping for potential-fail cases.

gdb/testsuite/ChangeLog
2016-03-09  Pedro Alves  <palves@redhat.com>

	* gdb.threads/attach-into-signal.exp: Adjust to "Program received
	signal" -> "Thread NN received signal" output change.
	* gdb.threads/ia64-sigill.exp: Likewise.
	* gdb.threads/linux-dp.exp: Likewise.
	* gdb.threads/manythreads.exp: Likewise.
	* gdb.threads/pending-step.exp: Likewise.
	* gdb.threads/print-threads.exp: Likewise.
	* gdb.threads/sigstep-threads.exp: Likewise.
	* gdb.threads/staticthreads.exp: Likewise.
	* gdb.threads/tls.exp: Likewise.
2016-03-09 20:24:14 +00:00
Jose E. Marchesi 2343b78a77 gdb: fix doc string of target_can_use_hardware_watchpoint.
gdb/ChangeLog

2016-03-09  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* target.h: Fix doc string of target_can_use_hardware_watchpoint.
2016-03-09 11:17:54 -08:00
Pedro Alves b69d38afde Command line input handling TLC
I didn't manage to usefully split this further into smaller
independent pieces, so:

 - Use "struct buffer" more.

 - Split out the responsibility of composing a complete command line
   from multiple input lines split with backslash

    (
    E.g.:

       (gdb) print \
       1 + \
       2
       $1 = 3
       (gdb)
    )

   to a separate function.  Note we don't need the separate
   readline_input_state and more_to_come globals at all.  They were
   just obfuscating the logic.

 - Factor out the tricky mostly duplicated code in
   command_line_handler and command_line_input.

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

	* event-top.c (more_to_come): Delete.
	(struct readline_input_state): Delete.
	(readline_input_state): Delete.
	(get_command_line_buffer): New function.
	(command_handler): Update comments.  Don't handle NULL commands
	here.  Do not execute commented lines.
	(command_line_append_input_line): New function.
	(handle_line_of_input): New function, partly based on
	command_line_handler and command_line_input.
	(command_line_handler): Rewrite.
	* event-top.h (command_handler): New declaration.
	(command_loop): Defer command execution to command_handler.
	(command_line_input): Update comments.  Simplify, using struct
	buffer and handle_line_of_input.
	* top.h (struct buffer): New forward declaration.
	(handle_line_of_input): New declaration.
2016-03-09 18:25:00 +00:00
Pedro Alves 2669cade3d Simplify saved_command_line handling
There doesn't seem to be much point in trying to reuse this buffer.
Prefer simplicity instead.

(In case you're wondering whether this fixes an off-by-one: linelength
is misnamed; it's really a size including terminating null char.)

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

	* event-top.c (command_line_handler): Use xfree + xstrdup instead
	of xrealloc + strcpy.
	* main.c (captured_main): Use xstrdup instead of xmalloc plus
	manual clear.
	* top.c (saved_command_line): Rewrite comment.
	(saved_command_line_size): Delete.
	(command_line_input): Use xfree + xstrdup instead of xrealloc +
	strcpy.
	* top.h (saved_command_line_size): Delete declaration.
2016-03-09 18:25:00 +00:00
Pedro Alves 187212b3c1 Use struct buffer in gdb_readline_no_editing_callback
gdb/ChangeLog:
2016-03-09  Pedro Alves  <palves@redhat.com>

	* event-top.c: Include buffer.h.
	(gdb_readline_no_editing_callback): Use struct buffer instead
	of xrealloc.
2016-03-09 18:25:00 +00:00
Pedro Alves 7a3bde34bc Use struct buffer in gdb_readline_no_editing
gdb/ChangeLog:
2016-03-09  Pedro Alves  <palves@redhat.com>

	* common/buffer.h (buffer_grow_char): New function.
	* top.c: Include buffer.h.
	(gdb_readline_no_editing): Rename 'prompt_arg' parameter to
	'prompt'.  Use struct buffer instead of xrealloc.
2016-03-09 18:25:00 +00:00
Pedro Alves c5c136ea94 gdb_readline -> gdb_readline_no_editing
Name this such that it's clearer that this is not a wrapper for the
real readline, but instead a replacement that provides no command line
editing features.

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

	* defs.h (gdb_readline): Delete declaration.
	* top.c (gdb_readline): Rename to ...
	(gdb_readline_no_editing): ... this, and make static.
2016-03-09 18:24:59 +00:00
Pedro Alves 720d2e96b4 Update prompt_for_continue comments
These comments are out of date -- we no longer call gdb_readline.  And
I think that mentioning the event loop is more useful here than
whatever GO32 issue had with gdb_readline, which may even no longer be
an issue.

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

	* utils.c (prompt_for_continue): Update comments.
2016-03-09 18:24:59 +00:00
Pedro Alves 608ff013aa Eliminate async_annotation_suffix
The comments and existence of this global are a bit of misleading
obfuscation, since this is only ever used to print the prompt
annotation, and never changes.  Just hardcode "prompt" where
necessary, as done for most other annotations.

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

	* event-top.c (async_annotation_suffix): Delete.
	(top_level_prompt, command_line_handler): Don't use
	'async_annotation_suffix' and simplify.
	* event-top.h (async_annotation_suffix): Delete declaration.
	(init_main): Remove reference to 'async_annotation_suffix'.
2016-03-09 18:24:59 +00:00
Pedro Alves c70061cf94 gdb_readline2 -> gdb_readline_no_editing_callback
The "2" in "gdb_readline2" doesn't really convey much.  Rename for
clarity.

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

	* event-top.c (gdb_readline2): Rename to ...
	(gdb_readline_no_editing_callback): ... this.
	(change_line_handler, stdin_event_handler)
	(gdb_setup_readline): Adjust.
	* event-top.h (gdb_readline2): Rename to ...
	(gdb_readline_no_editing_callback): ... this, and move closer to
	other readline-related declarations.
	* mi/mi-interp.c (mi_interpreter_resume): Adjust.
2016-03-09 18:24:59 +00:00
Pedro Alves 8a24383254 Garbage collect window_hook
I checked, and Insight doesn't set this.

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

	* top.c (window_hook): Delete.
	(command_loop): Remove references to window_hook.
2016-03-09 18:24:59 +00:00
Pedro Alves c32e87066a Test issuing a command split in multiple lines with continuation chars
I happened to break this locally and the testsuite didn't notice it.
Add some tests.

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

	* gdb.base/command-line-input.exp: New file.
2016-03-09 18:24:58 +00:00
Marcin Kościelnicki b04fd3bec9 gdb: Add tracepoint support for powerpc.
gdb/gdbserver/ChangeLog:

	* linux-ppc-low.c (ppc_supports_tracepoints): New function.
	(struct linux_target_ops): Wire in the above.

gdb/testsuite/ChangeLog:

	* gdb.trace/ftrace.exp: Set arg0exp for ppc.
	* gdb.trace/mi-trace-unavailable.exp: Set pcnum for ppc.
	* gdb.trace/pending.exp: Accept leading dot before function name.
	* gdb.trace/trace-common.h: Add fast tracepoint dummy insn for ppc.
	* lib/trace-support.exp: Set registers for ppc.
2016-03-09 18:47:46 +01:00
Marcin Kościelnicki 98fa59e9b0 gdb.trace/entry-values.exp: Fixes for powerpc64.
On powerpc64, "disassemble foo" doesn't work properly on object files
(it can't process the relocations in .opd section) - instead, let's
link it into an executable and load that.

Also, backtrace displays .main, not main.  Accept both.

gdb/testsuite/ChangeLog:

	* gdb.trace/entry-values.exp: Link ${binfile}1.o to ${binfile}1 and
	use it for disassembly; accept .main in addition to main in backtrace.
2016-03-09 18:47:11 +01:00
Marcin Kościelnicki f77198c878 gdb.trace/tfind.exp: Force call via global entry point on ppc64le.
tfind.exp sets a breakpoint on *gdb_recursion_test, which is the global
entry point on ppc64le, and won't be hit, since the call uses
the local entry.  Fix by calling the function via a pointer in a global
variable, forcing use of the global entry.

This patch is a slightly modified hunk extracted from
https://sourceware.org/ml/gdb-patches/2015-07/msg00353.html

gdb/testsuite/ChangeLog:

2016-03-09  Wei-cheng Wang  <cole945@gmail.com>
	    Marcin Kościelnicki  <koriakin@0x04.net>

	* gdb.trace/actions.c (gdb_recursion_test_fp): New typedef.
	(gdb_recursion_test_ptr): New global variable.
	(gdb_recursion_test): Call gdb_recursion_test_ptr instead of
	gdb_recursion_test.
	(gdb_c_test): Ditto.
2016-03-09 18:46:12 +01:00
Marcin Kościelnicki ba84e0da35 gdb.trace/change-loc.exp: Don't depend on tracepoint ordering.
powerpc (32-bit) loads shared libraries below the main executable, so
the PENDING location is the first one, which the current regex doesn't
match.  Split it into two tests instead, one looking for the pending
tracepoint location, and the other for two installed locations.

gdb/testsuite/ChangeLog:

	* gdb.trace/change-loc.exp: Don't depend on tracepoint location
	ordering.
2016-03-09 18:45:19 +01:00
Marcin Kościelnicki 4366d36e46 gdb.trace: Use manually-defined start labels in unavailable-dwarf-piece.exp
On powerpc64, foo/bar point to a function descriptor, not to function code.
Since there are no global labels pointing at the actual function code,
let's make our own.

Regression-tested on x86_64.

gdb/testsuite/ChangeLog:

	* gdb.trace/unavailable-dwarf-piece.c (foo): Add foo_start_lbl label.
	(bar): Add bar_start_lbl label.
	* gdb.trace/unavailable-dwarf-piece.exp: Use foo/bar_start_lbl instead
	of foo/bar for emitting DWARF and tracing.
2016-03-09 18:44:57 +01:00
Marcin Kościelnicki cc2c4da881 gdb/rs6000: Read backchain as unsigned.
Previously, backchain was read as a signed quantity, resulting in
addresses like 0xfffffffffffeded0 instead of 0xfffeded0 returned by
unwinder on 32-bit powerpc.  While normally such addresses are masked
off, this causes problems for tracepoints, since 0xfffffffffffeded0
is considered unavailable.

Fixes a test failure in gdb.trace/entry-values.exp.

gdb/ChangeLog:

	* corefile.c (safe_read_memory_unsigned_integer): New function.
	* gdbcore.h (safe_read_memory_unsigned_integer): New prototype.
	* rs6000-tdep.c (rs6000_frame_cache): Read backchain as unsigned.
2016-03-09 18:43:54 +01:00
Marcin Kościelnicki a67914defb gdb: Add gen_return_address for powerpc.
gdb/ChangeLog:

	* rs6000-tdep.c: Add "ax.h" and "ax-gdb.h" includes.
	(rs6000_gen_return_address): New function.
	(rs6000_gdbarch_init): Wire in the above.
2016-03-09 18:43:02 +01:00
Marcin Kościelnicki 2a2fa07bd1 gdb: Add ax_pseudo_register_collect for powerpc.
gdb/ChangeLog:

	* rs6000-tdep.c (rs6000_ax_pseudo_register_collect): New function.
	(rs6000_gdbarch_init): Wire in the above.
2016-03-09 18:41:53 +01:00
Andreas Arnez bc0e3f49c8 S390: Recognize special jumps in prologue parser
Functions compiled with the gcc option `-mhotpatch' may start with a
branch-never BRCL instruction as a 6-byte NOP.  And functions compiled
with `-mstack-size' contain a BRC instruction in their prologue that is
actually a conditional trap.  Both of these special jumps cause the
prologue parser to stop and yield bad unwinding results.

This change makes the prologue analyzer recognize such special jumps and
ignore them.

gdb/ChangeLog:

	* s390-linux-tdep.c (s390_analyze_prologue): Ignore BRC and BRCL
	instructions that do nothing or are conditional traps.
2016-03-09 17:12:29 +01:00
Andreas Arnez 6d53bec88f S390: Add use of unavailable-stack frame ID
When determining the frame ID of an inline frame, GDB currently asserts
that a valid ID of the underlying real frame is found, and that it does
not match outer_frame_id.  From inline_frame_this_id():

  /* For now, require we don't match outer_frame_id either (see
     comment above).  */
  gdb_assert (!frame_id_eq (*this_id, outer_frame_id));

However, this assertion may fail when the real frame's unwinder can not
determine the frame ID.  This happened on an s390x target with a binary
that lacked call frame information and also confused the prologue
analyzer, because then s390_frame_this_id() left the frame ID at its
default.

To fix this, this change enhances s390_frame_this_id such that an
unavailable-stack frame ID is built if no frame base can be determined
but the function address is available.

gdb/ChangeLog:

	* s390-linux-tdep.c (s390_prologue_frame_unwind_cache): Store
	frame func's PC in info->func before any other failure can occur.
	(s390_frame_this_id): Use frame_id_build_unavailable_stack if
	info->func has been filled out.
2016-03-09 17:12:29 +01:00
Pedro Alves f7990f1690 Avoid spaces in osabi names
It's not possible today to select some of the osabis by name.
Specifically, those that have spaces in their names and then the first
word is ambiguous...

For example:
 (gdb) set osabi <TAB>
 [...]
 FreeBSD ELF
 FreeBSD a.out
 [...]
 (gdb) set osabi FreeBSD ELF
 Ambiguous item "FreeBSD ELF".

In reality, because "set osabi" is an enum command, that was
equivalent to trying "set osabi FreeBSD", which is then obviously
ambiguous, because of "FreeBSD ELF" and "FreeBSD a.out".

Also, even if the first word is not ambiguous, we actually ignore
whatever comes after the first word:

 (gdb) set osabi GNU/Linux
 (gdb) show osabi
 The current OS ABI is "GNU/Linux".
 The default OS ABI is "GNU/Linux".
 (gdb) set osabi Windows SomeNonsense
                         ^^^^^^^^^^^^
 (gdb) show osabi
 The current OS ABI is "Windows CE".
 The default OS ABI is "GNU/Linux".
 (gdb)

Fix this by avoiding spaces in osabi names.

We could instead make "set osabi" have a custom set hook, or
alternatively make the enum set hook (in cli-setshow.c) handle values
with spaces, but OTOH, I have a feeling that could cause trouble.
E.g., in cases where we might want to write more than one enum value
in the same line.  We could support quoting as workaround, but, not
sure we want that.  "No spaces" seems like a simpler rule.

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

	* osabi.c (gdb_osabi_names): Avoid spaces in osabi names.
2016-03-09 15:52:43 +00:00
Pedro Alves 087ccc6a4f [FR-V] Handle FR300
Even though "set architecture" presents fr300 as option:

 (gdb) set architecture fr<TAB>
 fr300  fr400  fr450  fr500  fr550  frv

Actually selecting fr300 doesn't work:

 (gdb) set architecture fr300
 Architecture `fr300' not recognized.
 The target architecture is set automatically (currently i386)
 (gdb)

This just looks like an obvious oversight.  Looking around gcc and
binutils sources, FR300 is basically a FR500 specialized for DSP and
low power.

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

	* frv-tdep.c (frv_gdbarch_init): Handle bfd_mach_fr300.
2016-03-09 15:46:31 +00:00
Pedro Alves 114d7832b0 [CRIS] Don't internal error if forced big endian
This fixes:

  $ ./gdb -q -ex "set endian big" -ex "set architecture cris"
  The target is assumed to be big endian
  .../src/gdb/cris-tdep.c:4051: internal-error: cris_gdbarch_init: big endian byte order in info
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.
  Quit this debugging session? (y or n)

The "set cris-version" command can likewise cause internal errors.

The gdbarch init routine should be returning 0 to reject the
architecture instead of internal erroring on user input.

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

	* cris-tdep.c (cris_gdbarch_init): Return 0 if the info's byte
	order is BFD_ENDIAN_BIG or if the cris version is unsupported.
2016-03-09 03:14:07 +00:00
Pedro Alves d7a87b5e43 Fix floating conversion buffer overrun when host/target format matches
Running the testsuite with a gdb configured with --enable-libmcheck
reveals a problem:

  (gdb) ptype 3 * 2.0
  type = <12-byte float>
  memory clobbered past end of allocated block
  ERROR: Process no longer exists
  UNRESOLVED: gdb.ada/ptype_arith_binop.exp: ptype 3 * 2.0

  (gdb) PASS: gdb.dlang/expression.exp: ptype 0x1.FFFFFFFFFFFFFp1023
  ptype 0x1p-52L
  type = real
  memory clobbered past end of allocated block
  ERROR: Process no longer exists
  UNRESOLVED: gdb.dlang/expression.exp: ptype 0x1p-52L

Even though this shows up with Ada and D, it's easy to reproduce in C
too.  We just need to print a long double, when the current arch is
32-bit, which is the default when gdb starts up:

 $ ./gdb -q -ex "ptype 1.0L"
 type = long double
 memory clobbered past end of allocated block
 Aborted (core dumped)

Valgrind shows:

 ==22159== Invalid write of size 8
 ==22159==    at 0x8464A9: floatformat_from_doublest (doublest.c:756)
 ==22159==    by 0x846822: store_typed_floating (doublest.c:867)
 ==22159==    by 0x6A7959: value_from_double (value.c:3662)
 ==22159==    by 0x6A9F2D: evaluate_subexp_standard (eval.c:745)
 ==22159==    by 0x7F31AF: evaluate_subexp_c (c-lang.c:716)
 ==22159==    by 0x6A8986: evaluate_subexp (eval.c:79)
 ==22159==    by 0x6A8BA3: evaluate_type (eval.c:174)
 ==22159==    by 0x817CCF: whatis_exp (typeprint.c:456)
 ==22159==    by 0x817EAA: ptype_command (typeprint.c:508)
 ==22159==    by 0x5F267B: do_cfunc (cli-decode.c:105)
 ==22159==    by 0x5F5618: cmd_func (cli-decode.c:1885)
 ==22159==    by 0x83622A: execute_command (top.c:475)
 ==22159==  Address 0x8c6cb28 is 8 bytes inside a block of size 12 alloc'd
 ==22159==    at 0x4C2AA98: calloc (vg_replace_malloc.c:711)
 ==22159==    by 0x87384A: xcalloc (common-utils.c:83)
 ==22159==    by 0x873889: xzalloc (common-utils.c:93)
 ==22159==    by 0x6A34CB: allocate_value_contents (value.c:1036)
 ==22159==    by 0x6A3501: allocate_value (value.c:1047)
 ==22159==    by 0x6A790A: value_from_double (value.c:3656)
 ==22159==    by 0x6A9F2D: evaluate_subexp_standard (eval.c:745)
 ==22159==    by 0x7F31AF: evaluate_subexp_c (c-lang.c:716)
 ==22159==    by 0x6A8986: evaluate_subexp (eval.c:79)
 ==22159==    by 0x6A8BA3: evaluate_type (eval.c:174)
 ==22159==    by 0x817CCF: whatis_exp (typeprint.c:456)
 ==22159==    by 0x817EAA: ptype_command (typeprint.c:508)
 ==22159==
 type = long double
 (gdb)

Even if the target and host floating-point formats match, the length
of the types might still be different.  On x86, long double is the
80-bit extended precision type on both 32-bit and 64-bit ABIs, but by
default it is stored as 12 bytes on 32-bit, and 16 bytes on 64-bit,
for alignment reasons.  Several places in doublest.c already consider
this, but floatformat_to_doublest and floatformat_from_doublest miss
it.  E.g., convert_typed_floating and store_typed_floating,

Tested on x86-64 Fedora 23 with --enable-libmcheck, where it fixes the
crashed above.

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

	* doublest.c: Extend comments.
	(floatformat_to_doublest, floatformat_from_doublest): Copy the
	floatformat's total size, not the host type's size.
2016-03-09 03:01:06 +00:00
Pedro Alves b79497cb1c Assert that a floating type's length is at least as long as its format
This would have caught the HP/PA bug fixed in the previous patch:

 .../src/gdb/gdbtypes.c:4690: internal-error: arch_float_type: Assertion `len >= floatformat_totalsize_bytes (floatformats[0])' failed.
 A problem internal to GDB has been detected,
 further debugging may prove unreliable.
 Quit this debugging session? (y or n)

Tested on x86-64 Fedora 23, --enable-targets=all.

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

	* doublest.c (floatformat_totalsize_bytes): New function.
	(floatformat_from_type): Assert that the type's length is at least
	as long as the floatformat's totalsize.
	* doublest.h (floatformat_totalsize_bytes): New declaration.
	* gdbtypes.c (arch_float_type): Assert that the type's length is
	at least as long as the floatformat's totalsize.
2016-03-09 02:47:40 +00:00
Pedro Alves aacca8a7a9 Fix HP/PA GNU/Linux "long double" format
This:

 $ ./gdb -ex "set architecture hppa1.0" -ex "set osabi GNU/Linux" -ex "ptype 1.0L"

Shows that HPPA/Linux support for long doubles is broken.  It causes
GDB to access memory out of bounds.  With Valgrind, we see:

 The target architecture is assumed to be hppa1.0
 ==4371== Invalid write of size 8
 ==4371==    at 0x4C2F21F: memset (vg_replace_strmem.c:1224)
 ==4371==    by 0x8451C4: convert_doublest_to_floatformat (doublest.c:362)
 ==4371==    by 0x845F86: floatformat_from_doublest (doublest.c:769)
 ==4371==    by 0x84628E: store_typed_floating (doublest.c:873)
 ==4371==    by 0x6A7C3D: value_from_double (value.c:3662)
 ==4371==    by 0x6AA211: evaluate_subexp_standard (eval.c:745)
 ==4371==    by 0x7F306D: evaluate_subexp_c (c-lang.c:716)
 ==4371==    by 0x6A8C6A: evaluate_subexp (eval.c:79)
 ==4371==    by 0x6A8E87: evaluate_type (eval.c:174)
 ==4371==    by 0x817B8D: whatis_exp (typeprint.c:456)
 ==4371==    by 0x817D68: ptype_command (typeprint.c:508)
 ==4371==    by 0x5F2977: do_cfunc (cli-decode.c:105)
 ==4371==  Address 0x8998d18 is 0 bytes after a block of size 8 alloc'd
 ==4371==    at 0x4C2AA98: calloc (vg_replace_malloc.c:711)
 ==4371==    by 0x8732B6: xcalloc (common-utils.c:83)
 ==4371==    by 0x8732F5: xzalloc (common-utils.c:93)
 ==4371==    by 0x6A37AF: allocate_value_contents (value.c:1036)
 ==4371==    by 0x6A37E5: allocate_value (value.c:1047)
 ==4371==    by 0x6A7BEE: value_from_double (value.c:3656)
 ==4371==    by 0x6AA211: evaluate_subexp_standard (eval.c:745)
 ==4371==    by 0x7F306D: evaluate_subexp_c (c-lang.c:716)
 ==4371==    by 0x6A8C6A: evaluate_subexp (eval.c:79)
 ==4371==    by 0x6A8E87: evaluate_type (eval.c:174)
 ==4371==    by 0x817B8D: whatis_exp (typeprint.c:456)
 ==4371==    by 0x817D68: ptype_command (typeprint.c:508)

The trouble is that hppa_linux_init_abi overrides the default
long_double_bit set by the generic hppa-tdep.c:

  set_gdbarch_long_double_bit (gdbarch, 128);
  set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);

with:

  /* On hppa-linux, currently, sizeof(long double) == 8.  There has been
     some discussions to support 128-bit long double, but it requires some
     more work in gcc and glibc first.  */
  set_gdbarch_long_double_bit (gdbarch, 64);

which misses overriding the long_double_format, so we end with a weird
combination of:

  set_gdbarch_long_double_bit (gdbarch, 64);
  set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);

Weird because floatformats_ia64_quad's totalsize is longer than 64-bits.

The floatformat conversion routines use the struct floatformat's
totalsize (in bits) to know how much to copy/convert, thus the buffer
overruns.

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

	* hppa-linux-tdep.c (hppa_linux_init_abi): Set the long double
	format to floatformats_ieee_double.
2016-03-09 01:50:02 +00:00
Pedro Alves e6c2f47b45 Fix "set architecture mips:10000" crash
Fix this GDB crash:

  $ gdb -ex "set architecture mips:10000"
  Segmentation fault (core dumped)

Backtrace:

  Program received signal SIGSEGV, Segmentation fault.
  0x0000000000495b1b in mips_gdbarch_init (info=..., arches=0x0) at /home/pedro/gdb/mygit/cxx-convertion/src/gdb/mips-tdep.c:8436
  8436              if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
  (top-gdb) bt
  #0  0x0000000000495b1b in mips_gdbarch_init (info=..., arches=0x0) at .../src/gdb/mips-tdep.c:8436
  #1  0x00000000007348a6 in gdbarch_find_by_info (info=...) at .../src/gdb/gdbarch.c:5155
  #2  0x000000000073563c in gdbarch_update_p (info=...) at .../src/gdb/arch-utils.c:522
  #3  0x0000000000735585 in set_architecture (ignore_args=0x0, from_tty=1, c=0x26bc870) at .../src/gdb/arch-utils.c:496
  #4  0x00000000005f29fd in do_sfunc (c=0x26bc870, args=0x0, from_tty=1) at .../src/gdb/cli/cli-decode.c:121
  #5  0x00000000005fd3f3 in do_set_command (arg=0x7fffffffdcdd "mips:10000", from_tty=1, c=0x26bc870) at .../src/gdb/cli/cli-setshow.c:455
  #6  0x0000000000836157 in execute_command (p=0x7fffffffdcdd "mips:10000", from_tty=1) at .../src/gdb/top.c:460
  #7  0x000000000071abfb in catch_command_errors (command=0x835f6b <execute_command>, arg=0x7fffffffdccc "set architecture mips:10000", from_tty=1)
      at .../src/gdb/main.c:368
  #8  0x000000000071bf4f in captured_main (data=0x7fffffffd750) at .../src/gdb/main.c:1132
  #9  0x0000000000716737 in catch_errors (func=0x71af44 <captured_main>, func_args=0x7fffffffd750, errstring=0x106b9a1 "", mask=RETURN_MASK_ALL)
      at .../src/gdb/exceptions.c:240
  #10 0x000000000071bfe6 in gdb_main (args=0x7fffffffd750) at .../src/gdb/main.c:1164
  #11 0x000000000040a6ad in main (argc=4, argv=0x7fffffffd858) at .../src/gdb/gdb.c:32
  (top-gdb)

We already check whether info.abfd is NULL before all other
bfd_get_flavour calls in the same function.  Just this one case was
missing.

(This was exposed by a WIP test that tries all "set architecture ARCH"
values.)

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

	* mips-tdep.c (mips_gdbarch_init): Check whether info.abfd is NULL
	before calling bfd_get_flavour.
2016-03-07 16:37:53 +00:00
Sergio Durigan Junior 5eb264df40 Set executable bit on analyze-racy-logs.py
I forgot to do it in my previous commit.  This is necessary because we
execute the script directly on gdb/testsuite/Makefile.in.

gdb/testsuite/ChangeLog:
2016-03-06  Sergio Durigan Junior  <sergiodj@redhat.com>

	* analyze-racy-logs.py: Set executable bit.
2016-03-06 17:30:19 -05:00
Sergio Durigan Junior fb6a751f5f Improve analysis of racy testcases
This is an initial attempt to introduce some mechanisms to identify
racy testcases present in our testsuite.  As can be seen in previous
discussions, racy tests are really bothersome and cause our BuildBot
to pollute the gdb-testers mailing list with hundreds of
false-positives messages every month.  Hopefully, identifying these
racy tests in advance (and automatically) will contribute to the
reduction of noise traffic to gdb-testers, maybe to the point where we
will be able to send the failure messages directly to the authors of
the commits.

I spent some time trying to decide the best way to tackle this
problem, and decided that there is no silver bullet.  Racy tests are
tricky and it is difficult to catch them, so the best solution I could
find (for now?) is to run our testsuite a number of times in a row,
and then compare the results (i.e., the gdb.sum files generated during
each run).  The more times you run the tests, the more racy tests you
are likely to detect (at the expense of waiting longer and longer).
You can also run the tests in parallel, which makes things faster (and
contribute to catching more racy tests, because your machine will have
less resources for each test and some of them are likely to fail when
this happens).  I did some tests in my machine (8-core i7, 16GB RAM),
and running the whole GDB testsuite 5 times using -j6 took 23 minutes.
Not bad.

In order to run the racy test machinery, you need to specify the
RACY_ITER environment variable.  You will assign a number to this
variable, which represents the number of times you want to run the
tests.  So, for example, if you want to run the whole testsuite 3
times in parallel (using 2 cores), you will do:

  make check RACY_ITER=3 -j2

It is also possible to use the TESTS variable and specify which tests
you want to run:

  make check TEST='gdb.base/default.exp' RACY_ITER=3 -j2

And so on.  The output files will be put at the directory
gdb/testsuite/racy_outputs/.

After make invokes the necessary rules to run the tests, it finally
runs a Python script that will analyze the resulting gdb.sum files.
This Python script will read each file, and construct a series of sets
based on the results of the tests (one set for FAIL's, one for
PASS'es, one for KFAIL's, etc.).  It will then do some set operations
and come up with a list of unique, sorted testcases that are racy.
The algorithm behind this is:

  for state in PASS, FAIL, XFAIL, XPASS...; do
    if a test's state in every sumfile is $state; then
      it is not racy
    else
      it is racy

(The algorithm is actually a bit more complex than that, because it
takes into account other things in order to decide whether the test
should be ignored or not).

IOW, a test must have the same state in every sumfile.

After processing everything, the script prints the racy tests it could
identify on stdout.  I am redirecting this to a file named racy.sum.

Something else that I wasn't sure how to deal with was non-unique
messages in our testsuite.  I decided to do the same thing I do in our
BuildBot: include a unique identifier in the end of message, like:

  gdb.base/xyz.exp: non-unique message
  gdb.base/xyz.exp: non-unique message <<2>>

This means that you will have to be careful about them when you use
the racy.sum file.

I ran the script several times here, and it did a good job catching
some well-known racy tests.  Overall, I am satisfied with this
approach and I think it will be helpful to have it upstream'ed.  I
also intend to extend our BuildBot and create new, specialized
builders that will be responsible for detecting the racy tests every X
number of days.

2016-03-05  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (DEFAULT_RACY_ITER): New variable.
	(CHECK_TARGET_TMP): Likewise.
	(check-single-racy): New rule.
	(check-parallel-racy): Likewise.
	(TEST_TARGETS): Adjust rule to account for RACY_ITER.
	(do-check-parallel-racy): New rule.
	(check-racy/%.exp): Likewise.
	* README (Racy testcases): New section.
	* analyze-racy-logs.py: New file.
2016-03-05 20:43:40 -05:00
Denis Chertykov cb86f3880e Fix argument passing for call
When calling function with argument of size more than 8 bytes fails with
an error "That operation is not available on integers of more than 8 bytes.".
avr-gdb considers only 8 bytes (sizeof(long long)) in case of passing the
argument in registers. When the argument is of size more than 8 byte
then the utility function to extract bytes failed with the above error.

    gdb/
	* avr-tdep.c (AVR_LAST_ARG_REGNUM): Define.
        (avr_push_dummy_call): Correct last needed argument register.
        Write MSB of argument into register and subsequent bytes into
        other registers in decreasing order.
2016-03-05 15:17:15 +03:00
Yao Qi f1771dcebf ARM process record: VMOV
ARM process record gets the wrong register number for VMOV (from core
register to single-precision register).  That is, we should record
the D register rather than the S pseudo register.  The patch also
removes the condition "bit (arm_insn_r->arm_insn, 20)" check, which
has been checked above.

It fixes the following internal error,

(gdb) PASS: gdb.reverse/finish-precsave.exp: BP at end of main
continue^M
Continuing.^M
../../binutils-gdb/gdb/regcache.c:649: internal-error: regcache_raw_read: Assertion `regnum >= 0 && regnum < regcache->descr->nr_raw_registers' failed.^M
A problem internal to GDB has been detected,FAIL: gdb.reverse/finish-precsave.exp: run to end of main (GDB internal error)

gdb:

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

	* arm-tdep.c (arm_record_vdata_transfer_insn): Simplify the
	condition check.  Record the right D register number.
2016-03-04 16:02:15 +00:00
Yao Qi ca92db2d58 Tweak ARM process record
This patch removes the printing "Process record does not support",
and do the print by calling arm_record_unsupported_insn in the
caller.  Also, call arm_record_extension_space only when condition
is 0xf.

gdb:

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

	* arm-tdep.c (arm_record_extension_space): Remove code
	printing "Process record does not support".
	(arm_record_data_proc_misc_ld_str): Likewise.
	(decode_insn): Call arm_record_extension_space if condition
	is 0xf.  Call arm_record_unsupported_insn if ret isn't
	ARM_RECORD_SUCCESS.  Use 'ret' instead of 'insn_id' to hold
	the value of thumb2_record_decode_insn_handler.
2016-03-04 15:57:55 +00:00
Simon Marchi 73519cce7c feature_to_c.sh: Print help when passing no arguments
I found that odd that passing no arguments to feature_to_c.sh produces
this:

$ ./feature_to_c.sh
./feature_to_c.sh: 23: shift: can't shift that many

but passing one argument shows the help:

$ ./feature_to_c.sh hello
Usage: ./feature_to_c.sh OUTPUTFILE INPUTFILE...

This patch changes the script to show the help in both cases.

gdb/ChangeLog:

	* features/feature_to_c.sh: Print the help when passing no
	argument.
2016-03-04 10:03:06 -05:00
Doug Evans bdf7e23048 gdb.base/skip.exp: Use with_test_prefix.
gdb/testsuite/ChangeLog:

	* gdb.base/skip.exp: Use with_test_prefix.
2016-03-03 10:49:28 -08:00
Yao Qi c40c8d4b67 Update comments to start_step_over
I happen to see that comments to start_step_over isn't in sync with
code, so this patch is to update the comments.

gdb/gdbserver:

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

	* linux-low.c: Update comments to start_step_over.
2016-03-03 09:28:19 +00:00
Yao Qi 4719d415b9 New test about step over clone syscall
This patch adds a new test for stepping over clone syscall.

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

	* gdb.base/step-over-syscall.exp (step_over_syscall): Kfail.
	Invoke step_over_syscall "clone" and break_cond_on_syscall
	"clone".
	* gdb.base/step-over-clone.c: New file.
2016-03-03 09:17:45 +00:00
Yao Qi ea50786226 Reformat gdb.base/step-over-syscall.exp
gdb/testsuite:

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

	* gdb.base/step-over-syscall.exp (disp_step_cross_syscall): Fix
	code format.
2016-03-03 09:17:45 +00:00
Yao Qi 8fc8cbdaf6 Rename disp-step-syscall.exp to step-over-syscall.exp
disp-step-syscall.exp is extended for stepping over syscall instruction
in different cases, with or without displaced stepping, and stepping
over by GDBserver.

This patch rename disp-step-syscall.exp to step-over-syscall.exp to
reflect this.

gdb/testsuite:

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

	* gdb.base/disp-step-fork.c: Rename to ...
	* gdb.base/step-over-fork.c: ... it.  New file.
	* gdb.base/disp-step-vfork.c: Rename to ...
	* gdb.base/step-over-vfork.c: ... it.  New file.
	* gdb.base/disp-step-syscall.exp: Rename to ...
	* gdb.base/step-over-syscall.exp: ... it.  New file.
	(disp_step_cross_syscall): Rename to ...
	(step_over_syscall): ... it.
2016-03-03 09:17:45 +00:00
Yao Qi 92fa70b0bd Step over fork/vfork syscall insn in gdbserver
We can also extend disp-step-syscall.exp to test GDBserver step over
breakpoint on syscall instruction.  That is, we set a breakpoint
with a false condition on syscall instruction, so that GDBserver will
step over it.

This test triggers a GDBserver internal error, which can be fixed by
this series.

(gdb) PASS: gdb.base/disp-step-syscall.exp: fork: break cond on target: break on syscall insns
continue^M
Continuing.^M
Remote connection closed^M
(gdb) FAIL: gdb.base/disp-step-syscall.exp: fork: break cond on target: continue to fork again

In GDBserver, there is an internal error,

/home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:1922: A problem internal to GDBserver has been detected.
unsuspend LWP 25554, suspended=-1

the simplified reproducer is like,

$ ./gdb ./testsuite/outputs/gdb.base/disp-step-syscall/disp-step-fork
(gdb) b main
(gdb) c
(gdb) disassemble fork // in order to find the address of insn 'syscall'
....
   0x00007ffff7ad6023 <+179>:	syscall
(gdb) b *0x00007ffff7ad6023 if main == 0
(gdb) c

gdb/testsuite:

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

	* gdb.base/disp-step-syscall.exp (break_cond_on_syscall): New.
	If target supports condition evaluation on target, invoke
	break_cond_on_syscall for fork and vfork.
2016-03-03 09:17:44 +00:00
Yao Qi e197ad3c87 Step over syscalll insn with disp-step on and off
disp-step-syscall.exp was added to test displaced stepping over syscall
instructions, in which we set breakpoint on syscall instruction, and
step over it.  In fact, we can extend the test to non-displaced-stepping
case.  This patch wraps the test with displaced stepping on and off.
Note that the indentation and format isn't adjusted here to make this
patch easy to read.  The following patch will fix the format separately.

gdb/testsuite:

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

	* gdb.base/disp-step-syscall.exp: Don't invoke
	support_displaced_stepping.
	(disp_step_cross_syscall): Test with displaced stepping off and
	on if supported.
2016-03-03 09:17:44 +00:00
Yao Qi 0b47da9f17 Refactor gdb.base/disp-step-syscall.exp for general step over test
This patch moves some code out of disp_step_cross_syscall to a new proc
check_pc_after_cross_syscall and setup.  Procedure setup is to start a
fresh GDB and compute the syscall instruction address.

gdb/testsuite:

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

	* gdb.base/disp-step-syscall.exp (check_pc_after_cross_syscall): New
	proc.
	(setup): New proc.
	(disp_step_cross_syscall): Move code to check_pc_after_cross_syscall
	and setup.
2016-03-03 09:17:44 +00:00
Yao Qi 0f8288ae82 [GDBserver] Leave child suspended when step over parent
I see the following GDBserver internal error in two cases,

 gdb/gdbserver/linux-low.c:1922: A problem internal to GDBserver has been detected.
 unsuspend LWP 17200, suspended=-1

 1. step over a breakpoint on fork/vfork syscall instruction,
 2. step over a breakpoint on clone syscall instruction and child
    threads hits a breakpoint,

the stack backtrace is

 #0  internal_error (file=file@entry=0x44c4c0 "gdb/gdbserver/linux-low.c", line=line@entry=1922,
    fmt=fmt@entry=0x44c7d0 "unsuspend LWP %ld, suspended=%d\n") at gdb/gdbserver/../common/errors.c:51
 #1  0x0000000000424014 in lwp_suspended_decr (lwp=<optimised out>, lwp=<optimised out>) at gdb/gdbserver/linux-low.c:1922
 #2  0x000000000042403a in unsuspend_one_lwp (entry=<optimised out>, except=0x66e8c0) at gdb/gdbserver/linux-low.c:2885
 #3  0x0000000000405f45 in find_inferior (list=<optimised out>, func=func@entry=0x424020 <unsuspend_one_lwp>, arg=arg@entry=0x66e8c0)
    at gdb/gdbserver/inferiors.c:243
 #4  0x00000000004297de in unsuspend_all_lwps (except=0x66e8c0) at gdb/gdbserver/linux-low.c:2895
 #5  linux_wait_1 (ptid=..., ourstatus=ourstatus@entry=0x665ec0 <last_status>, target_options=target_options@entry=0)
    at gdb/gdbserver/linux-low.c:3632
 #6  0x000000000042a764 in linux_wait (ptid=..., ourstatus=0x665ec0 <last_status>, target_options=0)
    at gdb/gdbserver/linux-low.c:3770
 #7  0x0000000000411163 in mywait (ptid=..., ourstatus=ourstatus@entry=0x665ec0 <last_status>, options=options@entry=0, connected_wait=connected_wait@entry=1)
    at gdb/gdbserver/target.c:214
 #8  0x000000000040b1f2 in resume (actions=0x66f800, num_actions=1) at gdb/gdbserver/server.c:2757
 #9  0x000000000040f660 in handle_v_cont (own_buf=0x66a630 "vCont;c:p45e9.-1") at gdb/gdbserver/server.c:2719

when GDBserver steps over a thread, other threads have been suspended,
the "stepping" thread may create new thread, but GDBserver doesn't set
it suspend count to 1.  When GDBserver unsuspend threads, the child's
suspend count goes to -1, and the assert is triggered.  In fact, GDBserver
has already taken care of suspend count of new thread when GDBserver is
suspending all threads except the one GDBserver wants to step over by
https://sourceware.org/ml/gdb-patches/2015-07/msg00946.html

+	  /* If we're suspending all threads, leave this one suspended
+	     too.  */
+	  if (stopping_threads == STOPPING_AND_SUSPENDING_THREADS)
+	    {
+	      if (debug_threads)
+		debug_printf ("HEW: leaving child suspended\n");
+	      child_lwp->suspended = 1;
+	    }

but that is not enough, because new thread is still can be spawned in
the thread which is being stepped over.  This patch extends the
condition that GDBserver set child's suspend count to one if it is
suspending threads or stepping over the thread.

gdb/gdbserver:

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

	PR server/19736
	* linux-low.c (handle_extended_wait): Set child suspended
	if event_lwp->bp_reinsert isn't zero.
2016-03-03 09:17:44 +00:00
Yao Qi fdbd04a8ad Call enqueue_pending_signal in linux_resume_one_lwp_throw
Replace the code which is exactly what enqueue_pending_signal does.

gdb/gdbserver:

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

	* linux-low.c (linux_resume_one_lwp_throw): Replace code with
	enqueue_pending_signal.
2016-03-02 17:27:58 +00:00
Marcin Kościelnicki 6896a8fa1e [OBV] gdbserver: Only write ipa_tdesc_idx if agent is actually loaded.
Fixes rather embarassing gdb.trace regressions.

gdb/gdbserver/ChangeLog:

	* tracepoint.c (cmd_qtstart): Only set ipa_tdesc_idx if agent
	is actually loaded.
2016-03-02 17:18:29 +01:00
Bernhard Heckel 065ab6dc80 testsuite: Remove unnecessary code in fortran vla-history test.
testsuite: Remove unnecessary code in fortran vla-history test.

2016-03-02  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/testsuite/Changelog:

     * gdb.fortran/vla-history.exp: Remove breakpoint.
2016-03-02 16:48:06 +01:00
bernhard.heckel 07e448ade1 testsuite: Fix timeout issues during print of vla-arrays.
Printing and resolving of dynamic array's causes sporadic timeout issues on loaded systems.

2016-03-02  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/testsuite/Changelog:

     * gdb.fortran/vla-history.exp: Lookup array elements and printing exceeds timeout.
2016-03-02 16:44:06 +01:00
bernhard.heckel 9ac2d526d9 testsuite: Fix run to main issue introduced by GCC 5.x.
Adding a dummy assignment as a new breakpoint anchor because
breakpoint on return statement doesn't work for GCC 5.x.

2016-03-02  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/testsuite/Changelog:

     * gdb.cp/vla-cxx.cc: Insert dummy assignment as anchor for an breakpoint.
2016-03-02 16:40:55 +01:00
Bernhard Heckel 178073690a testsuite: Nullify pointers before first usage.
Nullify pointers to avoid an undefined association status.

2016-03-02  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/testsuite/Changelog:

     * gdb.mi/vla.f90: Nullify pointer after declaration.
2016-03-02 16:36:37 +01:00
Bernhard Heckel 650beae39d Add new maintainer to Write After Approval.
Add new maintainer to Write After Approval.

2016-03-02  Bernhard Heckel  <bernhard.heckel@intel.com>

    * MAINTAINERS (Write After Approval): Add Bernhard Heckel.
2016-03-02 16:20:02 +01:00
Bernhard Heckel 285866651c Fix detection of gfortran compilers.
Newer gfortran compilers changed naming convention in DW_AT_producer tag.
For example "GNU Fortran 4.6.3" vs "GNU Fortran2008 5.3.0"

2016-03-02  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/Changelog:

     * dwarf2read.c (new_symbol_full): Fix detection of gfortran compilers.
2016-03-02 15:31:20 +01:00
Pedro Alves 86e501afd4 Fix gdb.trace/ftrace-lock.c compilation
Fixes, on F23:

 .../src/gdb/testsuite/gdb.trace/ftrace-lock.c: In function 'gdb_agent_gdb_collect':
 .../src/gdb/testsuite/gdb.trace/ftrace-lock.c:50:3: warning: implicit declaration of function 'sleep' [-Wimplicit-function-declaration]
    sleep (1);
    ^

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

	* gdb.trace/ftrace-lock.c: Include <unistd.h>.
2016-03-01 17:42:47 +00:00
Pedro Alves 1e903e3203 Fix gdb.threads/watchpoint-fork*.c compilation
This testcase currently fails to compile on Fedora 23:

 .../src/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c: In function 'start':
 .../src/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c:70:11: warning: implicit declaration of function 'pthread_yield' [-Wimplicit-function-declaration]
	i = pthread_yield ();
	    ^
 .../src/gdb/testsuite/gdb.threads/watchpoint-fork-child.c: In function 'forkoff':
 .../src/gdb/testsuite/gdb.threads/watchpoint-fork-child.c:114:8: warning: implicit declaration of function 'pthread_yield' [-Wimplicit-function-declaratio
 n]
     i = pthread_yield ();
	 ^
 /tmp/ccUkNIsI.o: In function `start':
 .../src/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c:70: undefined reference to `pthread_yield'
 (...)
 collect2: error: ld returned 1 exit status

 UNSUPPORTED: gdb.threads/watchpoint-fork.exp: child: multithreaded: Couldn't compile watchpoint-fork-child.c: unrecognized error
 UNTESTED: gdb.threads/watchpoint-fork.exp: child: multithreaded: watchpoint-fork.exp
 testcase .../src/gdb/testsuite/gdb.threads/watchpoint-fork.exp completed i

The glibc manual says, on _GNU_SOURCE:

 "You should define these macros by using ‘#define’ preprocessor
 directives at the top of your source code files. These directives must
 come before any #include of a system header file."

I instead put it in the header all the .c files of the testcase must
include anyway.

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

	* gdb.threads/watchpoint-fork-child.c: Include "watchpoint-fork.h"
	before anything else.
	* gdb.threads/watchpoint-fork-mt.c: Likewise.  Don't define
	_GNU_SOURCE here.
	* gdb.threads/watchpoint-fork-st.c: Include "watchpoint-fork.h"
	before anything else.
	* gdb.threads/watchpoint-fork.h: Define _GNU_SOURCE.
2016-03-01 17:25:56 +00:00
Pedro Alves 6ccb54e2a8 Fix gdb.base/catch-fork-kill.c compilation
Fixes:

 Running .../src/gdb/testsuite/gdb.base/catch-fork-kill.exp ...
 gdb compile failed, .../src/gdb/testsuite/gdb.base/catch-fork-kill.c: In function 'main':
 .../src/gdb/testsuite/gdb.base/catch-fork-kill.c:81:4: warning: implicit declaration of function 'wait' [-Wimplicit-function-declaration]
     wait (NULL);
     ^

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

	* gdb.base/catch-fork-kill.c: Include <sys/wait.h>.
2016-03-01 17:11:57 +00:00
Yao Qi 30ca9da119 Fix output path for arm-disp-step.exp
This patch fixes the following error,

ERROR: (/scratch/yao/gdb/build-git/arm-linux-gnueabihf/gdb/testsuite/outputs/gdb.arch/arm-disp-step/arm-disp-step) No such file or directory
FAIL: gdb.arch/arm-disp-step.exp: Can't run to main

gdb/testsuite:

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

	* gdb.arch/arm-disp-step.exp: Use standard_testfile and
	prepare_for_testing.
2016-03-01 15:21:42 +00:00
Yao Qi dc856b3820 Compile gdb.arch/arm-neon.c with "quiet"
When we compile gdb.arch/arm-neon.c with options that don't enable NEON,
there are many error/warnings emitted into gdb.sum, which is annoying.
This patch fixes it by passing quiet to prepare_for_testing.

gdb/testsuite:

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

	* gdb.arch/arm-neon.exp: Pass quiet to prepare_for_testing.
2016-03-01 15:18:48 +00:00
Andreas Arnez 4a93215950 S390: Fix output path for s390-tdbregs test case
Since test artifacts are always organized in a directory hierarchy, the
s390-tdbregs test case is not executed correctly any more.  This is
because it uses an obsolete way of constructing the executable's path.

This change invokes prepare_for_testing instead.

gdb/testsuite/ChangeLog:

	* gdb.arch/s390-tdbregs.exp: Use prepare_for_testing instead of
	manually constructing the output path.
2016-03-01 12:43:55 +01:00
Andreas Arnez f24894771e S390: Fix internal error with stackless inferior
This fixes a GDB internal error that may occur when the inferior has no
valid stack pointer in r15.

gdb/testsuite/ChangeLog:

	* gdb.arch/s390-stackless.S: New.
	* gdb.arch/s390-stackless.exp: New.

gdb/ChangeLog:

	* s390-linux-tdep.c (s390_backchain_frame_unwind_cache): Avoid
	exception when attempting to access the inferior's backchain.
2016-03-01 12:43:55 +01:00
Yao Qi d521906965 aarch64-linux process record: more syscalls
The last patch supports several syscalls in linux-record.c, so now
GDB aarch64-linux backend can return these canonicalized syscall numbers
per aarch64 syscall number.

This patch fixes the following fails,

Process record and replay target doesn't support syscall number 59^M
Process record: failed to record execution log.^M
^M
Program stopped.^M
0x00000020000eab28 in pipe () from /lib/aarch64-linux-gnu/libc.so.6^M
(gdb) FAIL: gdb.reverse/pipe-reverse.exp: continue to breakpoint: marker2

Process record and replay target doesn't support syscall number 59^M
Process record: failed to record execution log.^M
^M
Program stopped.^M
0x00000020000eab28 in pipe () from /lib/aarch64-linux-gnu/libc.so.6^M
(gdb) FAIL: gdb.reverse/readv-reverse.exp: continue to breakpoint: marker2

gdb:

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

	* aarch64-linux-tdep.c (aarch64_canonicalize_syscall): Support
	eventfd2, eventfd2, dup3, inotify_init1, fallocate and pipe2.
	Return gdb_sys_epoll_create1 instead of gdb_sys_epoll_create
	for aarch64_sys_epoll_create1.
2016-02-29 16:44:54 +00:00
Yao Qi 253b4d3a09 Support more syscalls in linux-record: pipe2 epoll_create1 eventfd2 fallocate dup3 and inotify_init1
This patch adds more syscalls in linux-record.

gdb:

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

	* linux-record.h (enum gdb_syscall) <gdb_sys_fallocate>: New.
	<gdb_sys_eventfd2, gdb_sys_epoll_create1, gdb_sys_dup3>: New.
	<gdb_sys_pipe2, gdb_sys_inotify_init1>: New.
	* linux-record.c (record_linux_system_call): Handle them.
2016-02-29 16:44:50 +00:00
Iain Buclaw 38899f16e1 Don't recursively look for a symbol in all imports of imported modules.
Given two or more modules that import each other's scope, the current symbol
lookup routines would go round in circles looking through each import from
each module, possibly checking the same module twice or more until all possible
paths are marked as "searched".

Given enough modules, this causes an exponential slowdown in time taken to find
symbols that do exist, and infinite recursion when they don't.

gdb/ChangeLog:
	* d-namespace.c (d_lookup_symbol_imports): Avoid recursive lookups from
	cyclic imports.

gdb/testsuite/ChangeLog:
	* gdb.dlang/circular.c: New file.
	* gdb.dlang/circular.exp: New file.
2016-02-28 16:11:26 +01:00
Keith Seitz 1ed0c2a4bb Fix CXX invalid cast from void *.
This is an obvious patch to fix the following build error seen with
--enable-build-with-cxx:

../../src/gdb/rs6000-tdep.c: In function ‘rs6000_frame_cache* rs6000_frame_cache(frame_info*, void**)’:
../../src/gdb/rs6000-tdep.c:3242:15: error: invalid conversion from ‘void*’ to ‘rs6000_frame_cache*’ [-fpermissive]
       return (*this_cache);
              ~^~~~~~~~~~~~

gdb/ChangeLog

	* rs6000-tdep.c (rs6000_frame_cache): Explicitly cast return result
	to avoid invalid conversion from void *.
2016-02-26 12:42:28 -08:00
Joel Sherrill 12a132db16 Add aarch64-*-rtems* target 2016-02-26 14:07:27 -06:00
Joel Sherrill f73dbb0e48 Add x86_64-*-rtems* target
ld/configure.tgt: Also add stanza for x86_64-*-elf.
2016-02-26 14:07:26 -06:00
Yao Qi 9fde51ed30 Fix various bugs in arm_record_exreg_ld_st_insn
This patch fixes various bugs in arm_record_exreg_ld_st_insn, and use
gdb.reverse/insn-reverse.c to test more arm instructions.

 - Set flag SINGLE_REG correctly.  In the arch reference manual,
   SING_REG is true when the bit 8 of instruction is zero.
 - Record the right D registers for instructions changing S registers.
 - Fix the order of length and address in record_buf_mem array.
 - Shift the offset by 2 instead of by 24.

This patch also fixes one internal error,

(gdb) PASS: gdb.reverse/finish-precsave.exp: BP at end of main
continue^M
Continuing.^M
../../binutils-gdb/gdb/utils.c:1072: internal-error: virtual memory exhausted.^M
A problem internal to GDB has been detected,FAIL: gdb.reverse/finish-precsave.exp: run to end of main (GDB internal error)

gdb:

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

	* arm-tdep.c (arm_record_exreg_ld_st_insn): Set 'single_reg'
	per bit 8.  Check bit 20 instead of bit 4 for VMOV
	instruction.  Record D registers for instructions changing
	S registers.  Change of the order of length and address
	in record_buf_mem array.

gdb/testsuite:

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

	* gdb.reverse/insn-reverse.c [__arm__] (ext_reg_load): New.
	[__arm__] (ext_reg_mov, ext_reg_push_pop): New.
	(testcases): Update.
2016-02-26 15:00:36 +00:00
Yao Qi 1f33efec7c Record right reg num of thumb special data instructions
When GDB decodes these thumb special data instructions, such as 'mov sp, r7'
the Rd is got incorrectly.  According to the arch reference manual, the Rd
is DN:Rdn, in which DN is bit 7 and Rdn is bits 0 to 2.  This patch fixes it.

gdb:

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

	* arm-tdep.c (thumb_record_ld_st_reg_offset): Fix the register
	number of Rd.
2016-02-26 15:00:36 +00:00
Yao Qi ce90fefec9 Rename gdb.reverse/aarch64.{exp,c} to gdb.reverse/insn-reverse.{exp,c}
gdb/testsuite:

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

	* gdb.reverse/aarch64.c: Rename to ...
	* gdb.reverse/insn-reverse.c: ... it.
	* gdb.reverse/aarch64.exp: Rename to ...
	* gdb.reverse/insn-reverse.exp: ... it.
2016-02-26 15:00:36 +00:00
Yao Qi 3263bceb4f Generalize gdb.reverse/aarch64.exp
I said we can generialize gdb.reverse/aarch64.exp for other
architectures https://sourceware.org/ml/gdb-patches/2015-05/msg00482.html
and here is the patch to change aarch64.exp so that it can be used to
test for other architectures as well.

gdb/testsuite:

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

	* gdb.reverse/aarch64.c: [__aarch64__] Include arm_neon.h.
	(testcase_ftype): New.
	(testcases): New array.
	(n_testcases): New.
	(main): Call each element in testcases.
	* gdb.reverse/aarch64.exp: Remove is_aarch64_target check.
	(read_testcase): New.
	Do the tests in a loop.
2016-02-26 15:00:36 +00:00
Marcin Kościelnicki ab50308758 gdbserver/s390: Enable high GPRs, VX, TDB with 31-bit gdbserver.
Currently, 31-bit gdbserver doesn't support collecting/supplying high
GPRs, VX registers, and TDB data.  This is not much of a problem now,
since machines that have them usually have a 64-bit gdbserver that can
be used to debug 31-bit targets just fine.  However, with fast
tracepoints, it's not possible to use a 64-bit gdbserver with a 31-bit
IPA (and thus a 31-bit target), so 31-bit gdbserver has to be used
for 31-bit targets.  Thus, this patch is needed to allow collecting
high GPRs and VX registers on 31-bit targets via fast tracepoints.

gdb/gdbserver/ChangeLog:

	* linux-s390-low.c (s390_num_regs_3264): Define on 31-bit too.
	(s390_regmap_3264) [!__s390x__]: New global.
	(s390_collect_ptrace_register): Skip map entries containing -1.
	(s390_supply_ptrace_register): Ditto.
	(s390_fill_gprs_high): New function.
	(s390_store_gprs_high): New function.
	(s390_regsets): Add NT_S390_HIGH_GPRS.
	(s390_get_hwcap): Enable on 31-bit.
	(have_hwcap_s390_high_gprs): Enable on 31-bit.
	(s390_arch_setup): Enable detection of high GPRs, TDB, VX on 31-bit.
	Detect NT_S390_HIGH_GPRS.
	(s390_usrregs_info_3264): Enable on 31-bit.
	(s390_regs_info): Enable regs_info_3264 on 31-bit.
	(initialize_low_arch): Initialize s390_regsets_info_3264 on 31-bit.
2016-02-25 20:05:38 +01:00
Doug Evans 1547ef6456 avoid compiler warnings in remote-m32r-sdi.c
gdb/ChangeLog:

	* remote-m32r-sdi.c (recv_char_data): Initialize val to avoid
	compiler warning.
	(recv_long_data): Ditto.
2016-02-25 09:30:22 -08:00
Yao Qi 6cb59ff111 Remove gdb.base/branches.c
This patch removes gdb.base/branches.c which was added by the following
commit, but it is not used at all.

commit ea8122af14
Author: John Metzler <jmetzler@cygnus>
Date:   Thu Apr 16 17:56:11 1998 +0000

    Thu Apr 16 10:52:34 1998  John Metzler  <jmetzler@cygnus.com>

        * gdb.base/branches.c: Code with lots of loops and
        subroutines. Used to test gdbs ability to single step through PC
        changes, especially to test mips-tdep.c:mips_next_pc

gdb/testsuite:

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

	* gdb.base/branches.c: Remove.
2016-02-25 17:01:23 +00:00
Marcin Kościelnicki ae91f62539 [PR gdb/13808] gdb.trace: Pass tdesc selected in gdbserver to IPA.
If gdbserver and IPA are using different tdesc, they will disagree
about 'R' trace packet size.  This results in mangled traces.

To make sure they pick the same tdesc, gdbserver pokes the tdesc
(specified as an index in a target-specific list) into a global
variable in IPA.  In theory, IPA could find out the tdesc on its
own, but that may be complex (in particular, I don't know how to
tell whether we have LAST_BREAK on s390 without messing with ptrace),
and we'd have to duplicate the logic.

Tested on i386 and x86_64.  On i386, it fixes two FAILs in ftrace.exp.
On x86_64, these failures have been KFAILed - one of them works now,
but the other now fails due to an unrelated reason (ugh).

gdb/gdbserver/ChangeLog:

	PR gdb/13808
	* Makefile.in: Add i386-*-linux-ipa.o and amd64-*-linux-ipa.o.
	* configure.srv: Ditto.
	* linux-aarch64-ipa.c (get_ipa_tdesc): New function.
	(initialize_low_tracepoint): Remove ipa_tdesc assignment.
	* linux-amd64-ipa.c: Add "linux-x86-tdesc.h" include.
	(init_registers_amd64_linux): Remove prototype.
	(tdesc_amd64_linux): Remove declaration.
	(get_ipa_tdesc): New function.
	(initialize_low_tracepoint): Remove ipa_tdesc assignment,
	initialize remaining tdescs.
	* linux-i386-ipa.c: Add "linux-x86-tdesc.h" include.
	(init_registers_i386_linux): Remove prototype.
	(tdesc_i386_linux): Remove declaration.
	(get_ipa_tdesc): New function.
	(initialize_low_tracepoint): Remove ipa_tdesc assignment,
	initialize remaining tdescs.
	* linux-low.c (linux_get_ipa_tdesc_idx): New function.
	(linux_target_ops): wire in linux_get_ipa_tdesc_idx.
	* linux-low.h (struct linux_target_ops): Add get_ipa_tdesc_idx.
	* linux-x86-low.c: Move tdesc declarations to linux-x86-tdesc.h.
	(x86_get_ipa_tdesc_idx): New function.
	(the_low_target): Wire in x86_get_ipa_tdesc_idx.
	* linux-x86-tdesc.h: New file.
	* target.h (struct target_ops): Add get_ipa_tdesc_idx.
	(target_get_ipa_tdesc_idx): New macro.
	* tracepoint.c (ipa_tdesc_idx): New macro.
	(struct ipa_sym_addresses): Add addr_ipa_tdesc_idx.
	(symbol_list): Add ipa_tdesc_idx.
	(cmd_qtstart): Write ipa_tdesc_idx in the target.
	(ipa_tdesc): Remove.
	(ipa_tdesc_idx): New variable.
	(get_context_regcache): Use get_ipa_tdesc.
	(gdb_collect): Ditto.
	(gdb_probe): Ditto.
	* tracepoint.h (get_ipa_tdesc): New prototype.
	(ipa_tdesc): Remove.

gdb/testsuite/ChangeLog:

	PR gdb/13808
	* gdb.trace/ftrace.exp (test_fast_tracepoints): Remove kfail.
2016-02-25 17:57:28 +01:00
Simon Marchi 166616ce00 Initialize variables in i386_linux_handle_segmentation_fault
We see this error when building with gcc 4.3.

../../gdb/i386-linux-tdep.c: In function ‘i386_linux_handle_segmentation_fault’:
../../gdb/i386-linux-tdep.c:399: error: ‘access’ may be used uninitialized in this function
../../gdb/i386-linux-tdep.c:399: error: ‘upper_bound’ may be used uninitialized in this function
../../gdb/i386-linux-tdep.c:399: error: ‘lower_bound’ may be used uninitialized in this function

It's a false positive, since the variables will always get initialized
in the TRY clause, and the CATCH returns.

gdb/ChangeLog:

	* i386-linux-tdep.c (i386_linux_handle_segmentation_fault):
	Initialize variables.
2016-02-25 11:03:23 -05:00
Marcin Kościelnicki 678b48b7cf gdb.trace: Remove unnecessary target check from ftrace.exp.
The check used hardcoded targets and wasn't doing anything useful anyway,
since unsupported architectures blow up on link due to missing the IPA
library before they ever get to that check.

gdb/testsuite/ChangeLog:

	* gdb.trace/ftrace.exp: Remove unnecessary target check.
2016-02-25 16:11:33 +01:00
Marcin Kościelnicki 7337a6f229 gdb.trace: Surround $call_insn with \y in entry-values.exp
The PPC64 tracepoint patch added \y at the end of the call_insn pattern -
without that, it embarassed itself and matched the 'bl' in "Dump of
assem*bl*er code for function" as the powerpc call opcode.  Since that
sounds like a generally good idea, I've added \y before and after
call_insn for every target.  As a result, I had to change x86_64's mnemonic
to 'callq'.

gdb/testsuite/ChangeLog:

	* gdb.trace/entry-values.exp: Surround $call_insn with '\y',
	change x86_64 call_insn to 'callq'.
2016-02-25 16:11:29 +01:00
Antoine Tremblay 1eb7c2d886 Map registers to remote numbers when encoding an ax_reg or ax_reg_mask operation
When encoding the agent expression operation ax_reg or ax_reg_mask, the
register number used is internal to GDB. However GDBServer expects a tdesc
based number.

This usually does not cause a problem since at the moment, for raw
registers GDBServer R trace action ignores the register mask and just
collects all registers.

It can be a problem, however with pseudo registers on some platforms if the
tdesc number doesn't match the GDB internal register number.

This is the case with ARM, the upcoming ARM tracepoint support, fails
these test cases without this patch:

gdb.trace/collection.exp: collect register locals collectively:*

GDBSever would exit with: unhandled register size
Since the register number is not mapped.

This patch fixes these issues by calling gdbarch_remote_register_number
before encoding the register number in the ax_reg or ax_reg_mask operation.

Tested on x86 native-gdbserver no regressions observed.

gdb/ChangeLog:

	* ax-general.c (ax_reg): Call gdbarch_remote_register_number.
	(ax_reg_mask): Likewise.
2016-02-25 09:34:30 -05:00
Pedro Alves e7ad2f145c Handle MIPS Linux SIGTRAP siginfo.si_code values
This unbreaks pending/delayed breakpoints handling, as well as
hardware watchpoints, on MIPS.

Ref: https://sourceware.org/ml/gdb-patches/2016-02/msg00681.html

The MIPS kernel reports SI_KERNEL for all kernel generated traps,
instead of TRAP_BRKPT / TRAP_HWBKPT, but GDB isn't aware of this.

Basically, this commit:

- Folds watchpoints logic into check_stopped_by_breakpoint, and
  renames it to save_stop_reason.

- Adds GDB_ARCH_IS_TRAP_HWBKPT.

- Makes MIPS set both GDB_ARCH_IS_TRAP_BRPT and
  GDB_ARCH_IS_TRAP_HWBKPT to SI_KERNEL.  In save_stop_reason, we
  handle the case of the same si_code returning true for both
  TRAP_BRPT and TRAP_HWBKPT by looking at what the debug registers
  say.

Tested on x86-64 Fedora 20, native and gdbserver.

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

	* linux-nat.c (save_sigtrap) Delete.
	(stop_wait_callback): Call save_stop_reason instead of
	save_sigtrap.
	(check_stopped_by_breakpoint): Rename to ...
	(save_stop_reason): ... this.  Bits of save_sigtrap folded here.
	Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous
	GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT.  Factor out
	common code between the USE_SIGTRAP_SIGINFO and
	!USE_SIGTRAP_SIGINFO blocks.
	(linux_nat_filter_event): Call save_stop_reason instead of
	save_sigtrap.
	* nat/linux-ptrace.h: Check for both SI_KERNEL and TRAP_BRKPT
	si_code for MIPS.
	* nat/linux-ptrace.h: Fix "TRAP_HWBPT" typo in x86 table.  Add
	comments on MIPS behavior.
	(GDB_ARCH_IS_TRAP_HWBKPT): Define for all archs.

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

	* linux-low.c (check_stopped_by_breakpoint): Rename to ...
	(save_stop_reason): ... this.  Use GDB_ARCH_IS_TRAP_HWBKPT and
	handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT.
	Factor out common code between the USE_SIGTRAP_SIGINFO and
	!USE_SIGTRAP_SIGINFO blocks.
	(linux_low_filter_event): Call save_stop_reason instead of
	check_stopped_by_breakpoint and check_stopped_by_watchpoint.
	Update comments.
	(linux_wait_1): Update comments.
2016-02-24 22:52:06 +00:00
Marcin Kościelnicki 338435ef10 [OBV] gdb/rs6000: Fix maybe-uninitialized warning.
Introduced by 657f9cde9d.

gdb/ChangeLog:

	* rs6000-tdep.c (rs6000_frame_cache): Initialize frame and pc to 0
	to avoid spurious warnings.
2016-02-24 22:02:53 +01:00
Antoine Tremblay 861ca91fc6 Move tfile-avx.exp to tracefile-pseudo-reg.exp
As it is planned to add more architectures to this test, rename to a more
generic name.

gdb/testsuite/ChangeLog:

	* gdb.trace/tfile-avx.c: Move to...
	* gdb.trace/tracefile-pseudo-reg.c: Here.
	* gdb.trace/tfile-avx.exp: Move to...
	* gdb.trace/tracefile-pseudo-reg.exp: Here.
2016-02-24 14:23:47 -05:00
Doug Evans d2dffb8d3b Move new skip features to proper section (post 7.11). 2016-02-24 10:19:50 -08:00
Wei-cheng Wang 657f9cde9d powerpc: Support z-point type in gdbserver.
Support z-point, so tracepoints and breakpoints can be inserted at the same
location.

gdb/gdbserver/ChangeLog:

2016-02-24  Wei-cheng Wang  <cole945@gmail.com>

	* linux-ppc-low.c (ppc_supports_z_point_type): New function:
	(ppc_insert_point, ppc_remove_point): Insert/remove z-packet breakpoints.
	(ppc64_emit_ops_vector): Add target ops - ppc_supports_z_point_type,
	ppc_insert_point, ppc_remove_point.
2016-02-24 18:38:42 +01:00
Gary Benson bf74e428bc Fix logic in exec_file_locate_attach
This commit fixes an error in exec_file_locate_attach where
the main executable could be loaded from outside the sysroot
if a nonempty, non-"target:" sysroot was set but the discovered
executable filename did not exist in that sysroot and did exist
on the main filesystem.

gdb/ChangeLog:

	* exec.c (exec_file_locate_attach): Do not attempt to
	locate main executable locally if not found in sysroot.

gdb/testsuite/ChangeLog:

	* gdb.base/attach-pie-noexec.exp: Do not expect an error
	message on attach.
2016-02-24 11:31:58 +00:00
Joel Brobecker 62fb310b95 Document the GDB 7.11 release in gdb/ChangeLog
gdb/ChangeLog:

	GDB 7.11 released.
2016-02-24 11:07:27 +01:00
Wei-cheng Wang 50ae56ec46 Build unavailable-stack frames for tracepoint.
gdb/ChangeLog:

2016-02-24  Wei-cheng Wang  <cole945@gmail.com>

	* rs6000-tdep.c (rs6000_frame_cache, rs6000_frame_this_id): Handle
	unavailable PC/SP to build unavailable frame.
2016-02-24 04:16:46 +01:00
Doug Evans cce0e92333 Extend "skip" command to support -file, -gfile, -function, -rfunction.
gdb/ChangeLog:

	Extend "skip" command to support -file, -gfile, -function, -rfunction.
	* NEWS: Document new features.
	* skip.c: #include "fnmatch.h", "gdb_regex.h".
	(skiplist_entry) <file>: Renamed from filename.
	<function>: Renamed from function_name.
	<file_is_glob, function_is_regexp>: New members.
	<compiled_function_regexp, compiled_function_regexp_is_valid>:
	New members.
	(make_skip_entry): New function.
	(free_skiplist_entry, free_skiplist_entry_cleanup): New functions.
	(make_free_skiplist_entry_cleanup): New function.
	(skip_file_command): Update.
	(skip_function, skip_function_command): Update.
	(compile_skip_regexp): New functions.
	(skip_command): Add support for new options.
	(skip_info): Update.
	(skip_file_p, skip_gfile_p): New functions.
	(skip_function_p, skip_rfunction_p): New functions.
	(function_name_is_marked_for_skip): Update and simplify.
	(_initialize_step_skip): Update.
	* symtab.c: #include "fnmatch.h".
	(compare_glob_filenames_for_search): New function.
	* symtab.h (compare_glob_filenames_for_search): Declare.
	* utils.c (count_path_elements): New function.
	(strip_leading_path_elements): New function.
	* utils.h (count_path_elements): Declare.
	(strip_leading_path_elements): Declare.

gdb/doc/ChangeLog:

	* gdb.texinfo (Skipping Over Functions and Files): Document new
	options to "skip" command.  Update docs of output of "info skip".

gdb/testsuite/ChangeLog:

	* gdb.base/skip.c (test_skip): New function.
	(end_test_skip_file_and_function): New function.
	(test_skip_file_and_function): New function.
	* gdb.base/skip1.c (test_skip): New function.
	(skip1_test_skip_file_and_function): New function.
	* gdb.base/skip.exp: Add tests for new skip options.
	* gdb.base/skip-solib.exp: Update expected output.
	* gdb.perf/skip-command.cc: New file.
	* gdb.perf/skip-command.exp: New file.
	* gdb.perf/skip-command.py: New file.
2016-02-23 13:25:18 -08:00
Simon Marchi 1254566561 arm-tdep.c: Remove unused "to" parameters
gdb/ChangeLog:

	* arm-tdep.c (arm_decode_svc_copro): Remove "to" parameter.
	(thumb_process_displaced_insn): Likewise.
	(arm_process_displaced_insn): Adjust calls.
2016-02-23 13:21:59 -05:00
Yao Qi c955ae7389 Process record for aarch64-linux syscall
This patch updates the syscalls in sync with syscalls/aarch64-linux.xml.
Some syscalls are still not supported by gdb/linux-record.c yet.  Mark
them UNSUPPORTED_SYSCALL_MAP.

This patch fixes the following test fail,

Process record and replay target doesn't support syscall number 56^M
Process record: failed to record execution log.^M
^M
Program stopped.^M
0x00000020000e9dfc in open () from /lib/aarch64-linux-gnu/libc.so.6^M
(gdb) FAIL: gdb.reverse/fstatat-reverse.exp: continue to breakpoint: marker2

gdb:

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

	* aarch64-linux-tdep.c (enum aarch64_syscall) <aarch64_sys_mknod>:
	Remove.
	<aarch64_sys_mkdir, aarch64_sys_unlink, aarch64_sys_symlink>: Remove.
	<aarch64_sys_link, aarch64_sys_rename, aarch64_sys_faccess>: Remove.
	<aarch64_sys_mknodat, aarch64_sys_mkdirat>: New.
	<aarch64_sys_unlinkat, aarch64_sys_symlinkat>: New.
	<aarch64_sys_linkat, aarch64_sys_renameat, aarch64_sys_faccessat>: New.
	<aarch64_sys_open, aarch64_sys_readlink, aarch64_sys_fstatat>: Remove.
	<aarch64_sys_openat, aarch64_sys_readlinkat>: New.
	<aarch64_sys_newfstatat>: New.
	(UNSUPPORTED_SYSCALL_MAP): New macro.
	(aarch64_canonicalize_syscall): Add missing syscalls.
2016-02-23 09:21:09 +00:00
Marcin Kościelnicki 4000e47e2f gdb.trace: Fix unavailable.exp if last register happens to be PC.
unavailable.exp executes "info registers", expecting to find at least
two instances of "<unavailable>".  However, it uses
"<unavailable>.*<unavailable>" as the pattern, which doesn't match
when the last register happens to be available (eg. PC).  Change it
to ".*<unavailable>.*<unavailable>.*" instead.

Noticed on s390, no regression on x86_64.

gdb/testsuite/ChangeLog:

	* gdb.trace/unavailable.exp (gdb_unavailable_registers_test_1): Fix
	info registers pattern.
2016-02-22 18:56:51 +01:00
Jan Kratochvil ac46107c5c gdb-gdb.py: SyntaxError: Missing parentheses in call to 'print'
After building GDB
	--with-python=/usr/bin/python3
and for example stripping ./gdb and running:
	./gdb -data-directory data-directory/ -iex "add-auto-load-safe-path $PWD/gdb-gdb.gdb" -iex "add-auto-load-safe-path $PWD/gdb-gdb.
py" ./gdb
I get:
	Make breakpoint pending on future shared library load? (y or [n]) [answered N; input not from terminal]
	  File "/home/jkratoch/redhat/gdb-test-python3/gdb/gdb-gdb.py", line 91
	    print "Warning: Cannot find enum type_flag_value type."
								  ^
	SyntaxError: Missing parentheses in call to 'print'
	(top-gdb) q

gdb/ChangeLog
2016-02-22  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb-gdb.py (class TypeFlagsPrinter): Use parentheses for print.
2016-02-22 17:15:14 +01:00
Yao Qi 01e57735b0 Fix arm process record code format
This patch fixes the various code format issues in arm process record
in arm-tdep.c, such as using tab instead of spaces.

gdb:

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

	* arm-tdep.c: Fix code format issues.
2016-02-22 12:08:51 +00:00
Iain Buclaw e08db6db1d Also update recursive call to d_lookup_symbol_imports. 2016-02-21 22:05:49 +01:00
Iain Buclaw 30a6a7f035 Remove search_parents parameter from d_lookup_symbol_imports.
gdb/ChangeLog:

	* d-namespace.c (d_lookup_symbol_imports): Remove argument
	'search_parents'.  All callers updated.
2016-02-21 21:38:34 +01:00
Iain Buclaw 24f75eadab Add D support to gdb_default_target_compile.
gdb/testsuite/ChangeLog:

	* lib/future.exp: Add D support.
	(gdb_find_gdc): New proc.
	(gdb_default_target_compile): Add D support.
2016-02-18 22:02:04 +01:00
Wei-cheng Wang fbb7bcbeaa Determine the iteration count based on wallclock instead of user+system time.
gdb/testsuite/ChangeLog:

2016-02-18  Wei-cheng Wang  <cole945@gmail.com>

	* gdb.trace/tspeed.c (myclock): Return wallclock instead of
	user+system time.
	(trace_speed_test): Determine the iteration count for a time
	between 15..30 seconds.
2016-02-18 20:23:00 +01:00
Marcin Kościelnicki f79a3bae87 gdb/s390: Fill guess_tracepoint_registers hook.
gdb/ChangeLog:

	* s390-linux-tdep.c (s390_guess_tracepoint_registers): New function.
	(s390_gdbarch_init): Fill guess_tracepoint_registers hook.
2016-02-18 17:53:00 +01:00
Walfred Tedeschi 012b3a217a Intel MPX bound violation handling
With Intel Memory Protection Extensions it was introduced the concept of
boundary violation.  A boundary violations is presented to the inferior as
a segmentation fault having SIGCODE 3.  This patch adds a
handler for a boundary violation extending the information displayed
when a bound violation is presented to the inferior.  In the stop mode
case the debugger will also display the kind of violation: "upper" or
"lower", bounds and the address accessed.
On no stop mode the information will still remain unchanged.  Additional
information about bound violations are not meaningful in that case user
does not know the line in which violation occurred as well.

When the segmentation fault handler is stop mode the out puts will be
changed as exemplified below.

The usual output of a segfault is:
Program received signal SIGSEGV, Segmentation fault
0x0000000000400d7c in upper (p=0x603010, a=0x603030, b=0x603050,
c=0x603070, d=0x603090, len=7) at i386-mpx-sigsegv.c:68
68        value = *(p + len);

In case it is a bound violation it will be presented as:
Program received signal SIGSEGV, Segmentation fault
Upper bound violation while accessing address 0x7fffffffc3b3
Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
0x0000000000400d7c in upper (p=0x603010, a=0x603030, b=0x603050,
c=0x603070, d=0x603090, len=7) at i386-mpx-sigsegv.c:68
68        value = *(p + len);

In mi mode the output of a segfault is:
*stopped,reason="signal-received",signal-name="SIGSEGV",
signal-meaning="Segmentation fault", frame={addr="0x0000000000400d7c",
func="upper",args=[{name="p", value="0x603010"},{name="a",value="0x603030"}
,{name="b",value="0x603050"}, {name="c",value="0x603070"},
{name="d",value="0x603090"},{name="len",value="7"}],
file="i386-mpx-sigsegv.c",fullname="i386-mpx-sigsegv.c",line="68"},
thread-id="1",stopped-threads="all",core="6"

in the case of a bound violation:
*stopped,reason="signal-received",signal-name="SIGSEGV",
signal-meaning="Segmentation fault",
sigcode-meaning="Upper bound violation",
lower-bound="0x603010",upper-bound="0x603023",bound-access="0x60302f",
frame={addr="0x0000000000400d7c",func="upper",args=[{name="p",
value="0x603010"},{name="a",value="0x603030"},{name="b",value="0x603050"},
{name="c",value="0x603070"},{name="d",value="0x603090"},
{name="len",value="7"}],file="i386-mpx-sigsegv.c",
fullname="i386-mpx-sigsegv.c",line="68"},thread-id="1",
stopped-threads="all",core="6"

2016-02-18  Walfred Tedeschi  <walfred.tedeschi@intel.com>

gdb/ChangeLog:

	* NEWS: Add entry for bound violation.
	* amd64-linux-tdep.c (amd64_linux_init_abi_common):
	Add handler for segmentation fault.
	* gdbarch.sh (handle_segmentation_fault): New.
	* gdbarch.c: Regenerate.
	* gdbarch.h: Regenerate.
	* i386-linux-tdep.c (i386_linux_handle_segmentation_fault): New.
	(SIG_CODE_BONDARY_FAULT): New define.
	(i386_linux_init_abi): Use i386_mpx_bound_violation_handler.
	* i386-linux-tdep.h (i386_linux_handle_segmentation_fault) New.
	* i386-tdep.c (i386_mpx_enabled): Add as external.
	* i386-tdep.c (i386_mpx_enabled): Add as external.
	* infrun.c (handle_segmentation_fault): New function.
	(print_signal_received_reason): Use handle_segmentation_fault.

gdb/testsuite/ChangeLog:

	* gdb.arch/i386-mpx-sigsegv.c: New file.
	* gdb.arch/i386-mpx-sigsegv.exp: New file.
	* gdb.arch/i386-mpx-simple_segv.c: New file.
	* gdb.arch/i386-mpx-simple_segv.exp: New file.

gdb/doc/ChangeLog:

	* gdb.texinfo (Signals): Add bound violation display hints for
	a SIGSEGV.
2016-02-18 17:25:49 +01:00
Marcin Kościelnicki 5f034a78b9 gdb: Add guess_tracepoint_registers hook to gdbarch.
When we're looking at a tracefile trace frame where registers are not
available, and the tracepoint has only one location, we supply
the location's address as the PC register.  However, this only works
if PC is not a pseudo register, and individual architectures may want
to guess more registers.  Add a gdbarch hook that will handle that.

gdb/ChangeLog:

	* arch-utils.c (default_guess_tracepoint_registers): New function.
	* arch-utils.h (default_guess_tracepoint_registers): New prototype.
	* gdbarch.c: Regenerate.
	* gdbarch.h: Regenerate.
	* gdbarch.sh: Add guess_tracepoint_registers hook.
	* tracefile.c (tracefile_fetch_registers): Use the new gdbarch hook.
2016-02-18 17:21:22 +01:00
Yao Qi 2d5189bd3a Remove setup_kfail server/13796 in disp-step-syscall.exp
This patch series add fork support in target remote,

  [PATCH v2 0/3] Target remote mode fork and exec support
  https://sourceware.org/ml/gdb-patches/2015-12/msg00144.html

so GDB can be informed about the child, and adjust child correctly in
displaced stepping.  The PR server/13796 was fixed by this patch
series actually.  Test results on buildbot show this KFAIL->KPASS
change https://sourceware.org/ml/gdb-testers/2015-q4/msg10128.html

gdb/testsuite:

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

	* gdb.base/disp-step-syscall.exp (disp_step_cross_syscall):
	Don't call setup_kfail.
2016-02-18 13:02:12 +00:00
Yao Qi 40fb20d037 Set breakpoint condition-evaluation in forking-threads-plus-breakpoint.exp
Proc do_test in forking-threads-plus-breakpoint.exp has an argument
cond_bp_target, but the test doesn't use it to set
"breakpoint condition-evaluation", which is an oversight in the test.

This patch fixes it by setting "breakpoint condition-evaluation" per
$cond_bp_target.

gdb/testsuite:

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

	* gdb.threads/forking-threads-plus-breakpoint.exp (do_test):
	Set "set breakpoint condition-evaluation" per $cond_bp_target.
2016-02-18 12:04:32 +00:00
Marcin Kościelnicki 0748bf3e58 gdb/doc: Add documentation for tfile description section lines.
gdb/doc/ChangeLog:

	* gdb.texinfo (Trace File Format): Add documentation for description
	section lines.
2016-02-18 09:27:29 +01:00
Gary Benson 88178e828a Add missing cleanup in exec_file_locate_attach
exec_file_locate_attach allocates memory for full_exec_path (using
either exec_file_find, source_full_path_of or xstrdup) but this
memory is never freed.  This commit adds the necessary cleanup.

gdb/ChangeLog:

	* exec.c (exec_file_locate_attach): Add missing cleanup.
2016-02-17 16:47:11 +00:00