Commit Graph

37597 Commits

Author SHA1 Message Date
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
Marcin Kościelnicki b00b61e1fd gdbserver/s390: Advertise Z0 packet support.
This is necessary for upcoming tracepoint support - otherwise, setting
a tracepoint and a breakpoint on the same address will fail, since gdbserver
won't know about gdb's breakpoint.

Tested on s390x-ibm-linux-gnu and s390-ibm-linux-gnu, RHEL 7.2.

gdb/gdbserver/ChangeLog:

	* linux-s390-low.c (s390_supports_z_point_type): New function.
	(struct linux_target_ops): Wire s390_supports_z_point_type in.
2016-02-17 10:45:58 +01:00
Doug Evans 21b1f8d2fc Whitespace cleanup for skip testcase.
gdb/testsuite/ChangeLog:

	* gdb.base/skip.c: Add copyright.  Whitespace cleanup.
	* gdb.base/skip1.c: Ditto.
	* gdb.base/skip.exp: Whitespace cleanup.
2016-02-16 12:39:16 -08:00
Don Breazeal 4041ed7780 PR remote/19496, internal err forking-threads-plus-bkpt
This patch fixes an internal error that occurs in
gdb.threads/forking-threads-plus-breakpoint.exp:

/blah/binutils-gdb/gdb/target.c:2723: internal-error: Can't determine the
current address space of thread Thread 3170.3170

In default_thread_address_space, find_inferior_ptid couldn't find 3170.3170
because it had been overwritten in inferior_appeared, called as follows:

inferior_appeared
  remote_add_inferior
    remote_notice_new_inferior
      remote_update_thread_list

The cause of the problem was the following sequence of events:

* GDB knows only about the main thread

* the first fork event is reported to GDB, saved as pending_event

* qXfer:threads:read gets the threads from the remote.
  remove_new_fork_children id's the fork child from the pending event
  and removes it from the list reported to GDB.  All the rest of the
  threads, including the fork parent, are added to the GDB thread list.

* GDB stops all the threads.  All the stop events are pushed onto the
  stop reply queue behind the pending fork event.  The fork waitstatus
  is saved in the fork parent thread's pending status field
  thread_info.suspend.

* remote_wait_ns calls queued_stop_reply and process_stop_reply to
  remove the fork event from the front of the stop reply queue and save
  event information in the thread_info structure for the fork parent
  thread.  Unfortunately, none of the information saved in this way is
  the fork-specific information.

* A subsequent qXfer:threads:read packet gets the thread list including
  the fork parent and fork child.  remove_new_fork_children checks the
  thread list to see if there is a fork parent, doesn't find one, checks
  the stop reply queue for a pending fork event, doesn't find one, and
  allows the fork child thread to be reported to GDB before the fork
  event has been handled.  remote_update_thread_list calls
  remote_notice_new_thread and overwrites the current (main) thread in
  inferior_appeared.

So the fork event has been reported out of target_wait but it was left
pending on the infrun side (infrun.c:save_waitstatus).  IOW, the fork
event hasn't been processed by handle_inferior_event yet, so it hasn't
made it to tp->pending_follow yet.

The fix is to check thread_info.suspend along with the
thread_info.pending_follow in remote.c:remove_new_fork_children, to
prevent premature reporting of the fork child thread creation.

gdb/ChangeLog:

	PR remote/19496
	* remote.c (remove_new_fork_children): Check for pending
	fork status in thread_info.suspend.

gdb/testsuite/ChangeLog:

	PR remote/19496
	* gdb.threads/forking-threads-plus-breakpoint.exp (do_test):
	Remove kfail for PR remote/19496.
2016-02-16 08:56:06 -08:00
Simon Marchi c4ef31bf6f testsuite: Make standard_temp_file use invocation-specific directories
Just like standard_output_file, standard_temp_file should use multiple
directories to make the tests parallel-safe.  However,
standard_temp_file is sometimes called in some procedures that are not
test-specific.  For example, gdb_init uses it, but is called once before
all test files are ran.  Therefore, we can't organize it in a
temp/gdb.subdir/testname layout, like standard_output_file.

Because it's just meant for temporary files that don't really need to be
inspected after the test, we can just put them in a directory based on
the runtest pid.  There is always a single exp file being executed by a
particular runtest invocation at any given time, so it should be safe.

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (standard_temp_file): Return a path specific to
	the runtest invocation.
2016-02-16 09:01:38 -05:00
Simon Marchi 266b65b33e testsuite: Fix save-trace.exp writing outside standard output directory
In save-trace.exp, we want to test loading of a tracepoint definition
file with a relative path (I am not sure why in fact).  We currently use
"savetrace-relative.tr", which ends up directly in testsuite/.  If we
use [standard_output_file] on that path, it becomes absolute.  I decided
to just replace [pwd] with . (a dot) in the path given by
standard_output_file to make it relative.  However, this trick only
works because [pwd] is a prefix of the standard output directory.  So I
added a check to verify that precondition.

gdb/testsuite/ChangeLog:

	* gdb.trace/save-trace.exp: Change relative path to be in the
	standard output directory.
2016-02-16 09:01:38 -05:00
Yao Qi b442c911ee Fix cleanup in arm_linux_software_single_step
I see the following error in testing aarch64 GDB debugging arm
program.

(gdb) PASS: gdb.reverse/readv-reverse.exp: set breakpoint at marker2
continue
Continuing.
=================================================================
==32273==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x000000ce4c00 in thread T0
    #0 0x2ba5615645c7 in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x545c7)^M
    #1 0x4be8b5 in VEC_CORE_ADDR_cleanup /home/yao/SourceCode/gnu/gdb/git/gdb/common/gdb_vecs.h:34^M
    #2 0x5e6d95 in do_my_cleanups /home/yao/SourceCode/gnu/gdb/git/gdb/common/cleanups.c:154^M
    #3 0x64c99a in fetch_inferior_event /home/yao/SourceCode/gnu/gdb/git/gdb/infrun.c:3975^M
    #4 0x678437 in inferior_event_handler /home/yao/SourceCode/gnu/gdb/git/gdb/inf-loop.c:44^M
    #5 0x5078f6 in remote_async_serial_handler /home/yao/SourceCode/gnu/gdb/git/gdb/remote.c:13223^M
    #6 0x4cecfd in run_async_handler_and_reschedule /home/yao/SourceCode/gnu/gdb/git/gdb/ser-base.c:137^M
    #7 0x676864 in gdb_wait_for_event /home/yao/SourceCode/gnu/gdb/git/gdb/event-loop.c:834^M
    #8 0x676a27 in gdb_do_one_event /home/yao/SourceCode/gnu/gdb/git/gdb/event-loop.c:323^M
    #9 0x676aed in start_event_loop /home/yao/SourceCode/gnu/gdb/git/gdb/event-loop.c:347^M
    #10 0x6706d2 in captured_command_loop /home/yao/SourceCode/gnu/gdb/git/gdb/main.c:318^M
    #11 0x66db8c in catch_errors /home/yao/SourceCode/gnu/gdb/git/gdb/exceptions.c:240^M
    #12 0x6716dd in captured_main /home/yao/SourceCode/gnu/gdb/git/gdb/main.c:1157^M
    #13 0x66db8c in catch_errors /home/yao/SourceCode/gnu/gdb/git/gdb/exceptions.c:240^M
    #14 0x671b7a in gdb_main /home/yao/SourceCode/gnu/gdb/git/gdb/main.c:1165^M
    #15 0x467684 in main /home/yao/SourceCode/gnu/gdb/git/gdb/gdb.c:32^M
    #16 0x2ba563ed7ec4 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21ec4)^M
    #17 0x4676b2 (/scratch/yao/gdb/build-git/aarch64-linux-gnu/gdb/gdb+0x4676b2)

looks we should discard cleanup if function
arm_linux_software_single_step returns early, or create cleanup when
it is needed.

gdb:

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

	* arm-linux-tdep.c (arm_linux_software_single_step): Assign
	'old_chain' later.
2016-02-16 13:53:35 +00:00
Yao Qi 553cb5270f Remove PC from syscall_next_pc
Method syscall_next_pc of struct arm_get_next_pcs_ops has an argument
PC, which is not necessary, because PC can be got from regcache in
'struct arm_get_next_pcs'.  This patch removes the PC argument of
syscall_next_pc.

gdb:

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

	* arch/arm-get-next-pcs.h (struct arm_get_next_pcs_ops)
	<syscall_next_pc>: Remove argument PC.  Callers updated.
	* arm-linux-tdep.c (arm_linux_get_next_pcs_syscall_next_pc):
	Remove argument PC.  Get pc from regcache_read_pc.
	* arm-tdep.c (arm_get_next_pcs_syscall_next_pc): Remove
	argument PC.

gdb/gdbserver:

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

	* linux-arm-low.c (get_next_pcs_syscall_next_pc): Remove argument
	PC.  Get pc from regcache_read_pc.
2016-02-16 13:47:17 +00:00
Jan Kratochvil a7a0a6a95b Add missing gdb.arch/i386-prologue.c prototypes
The testfile has not ran because:
gdb.arch/i386-prologue.c:34:3: warning: implicit declaration of function 'standard' [-Wimplicit-function-declaration]
   standard ();
   ^
gdb.arch/i386-prologue.c:35:3: warning: implicit declaration of function 'stack_align_ecx' [-Wimplicit-function-declaration]
   stack_align_ecx ();
   ^
gdb.arch/i386-prologue.c:36:3: warning: implicit declaration of function 'stack_align_edx' [-Wimplicit-function-declaration]
   stack_align_edx ();
   ^
gdb.arch/i386-prologue.c:37:3: warning: implicit declaration of function 'stack_align_eax' [-Wimplicit-function-declaration]
   stack_align_eax ();
   ^

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

	* gdb.arch/i386-prologue.c: Add missing prototypes.
2016-02-15 19:01:03 +01:00
Jan Kratochvil c99dbb4246 Fix more testcases with standard_output_file.
Since
	commit 2151ccc56c
	Author: Simon Marchi <simon.marchi@ericsson.com>
	Date:   Mon Feb 8 14:02:36 2016 -0500
	    Always organize test artifacts in a directory hierarchy
these testfiles could not build.

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

	* gdb.arch/i386-gnu-cfi.exp: Use standard_output_file.
	* gdb.arch/i386-prologue.exp: Likewise.
	* gdb.arch/i386-size.exp: Likewise.
2016-02-15 18:54:03 +01:00
Simon Marchi aa4803559b testsuite: Fix some tests that write outside of the standard output directory
gdb/testsuite/ChangeLog:

	* gdb.base/wrong_frame_bt_full.exp: Use standard_output_file to
	define object file path.
	* gdb.btrace/gcore.exp: Use standard_output_file to define core
	file path.
	* lib/opencl.exp (gdb_compile_opencl_hostapp): Use
	standard_output_file to define binfile.
2016-02-15 11:46:10 -05:00
Yao Qi 0a0da55626 Don't print 0x for core_addr_to_string_nz
core_addr_to_string_nz returns string which has "0x" prefix, so don't
need to print "0x" again.  This patch is to remove the "0x".

gdb:

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

	* aarch64-tdep.c (aarch64_analyze_prologue): Remove "0x".
2016-02-15 10:05:56 +00:00
Jan Kratochvil ba881f505b testsuite: Fix false Fortran regressions with recent gcc
gcc-4.9.2-6.fc21.x86_64 -> gcc-5.3.1-2.fc23.x86_64

-PASS: gdb.fortran/vla-ptype.exp: ptype pvla not initialized
+FAIL: gdb.fortran/vla-ptype.exp: ptype pvla not initialized
-PASS: gdb.fortran/vla-history.exp: print vla1 allocated
+FAIL: gdb.fortran/vla-history.exp: print vla1 allocated
-PASS: gdb.fortran/vla-history.exp: print $2
+FAIL: gdb.fortran/vla-history.exp: print $2
-PASS: gdb.fortran/vla-value.exp: print undefined pvla
+FAIL: gdb.fortran/vla-value.exp: print undefined pvla
-PASS: gdb.fortran/vla-value.exp: print non-associated &pvla
+FAIL: gdb.fortran/vla-value.exp: print non-associated &pvla
-PASS: gdb.fortran/vla-value.exp: print undefined pvla(1,3,8)
+FAIL: gdb.fortran/vla-value.exp: print undefined pvla(1,3,8)

These issues get fixed (or removed if no longer applicable) by attached patch.

It is based on Googled:
	http://www.cs.rpi.edu/~szymansk/OOF90/bugs.html#5
	When a pointer is declared its status is undefined, and cannot be
	safely queried with the associated intrinsic.
	-> nullify(VARNAME)
+
	https://software.intel.com/en-us/forums/intel-fortran-compiler-for-linux-and-mac-os-x/topic/268786
	ALLOCATE is not supposed to initialize the array.
	-> Remove checks like an initial print is: \\( *0, *0, *0...\\)

These regressions remain:
	-PASS: gdb.fortran/library-module.exp: print var_i in lib
	+FAIL: gdb.fortran/library-module.exp: print var_i in lib
	-PASS: gdb.fortran/library-module.exp: print var_i in main
	+FAIL: gdb.fortran/library-module.exp: print var_i in main
I believe it is more a GDB bug (in a code contributed by me), filed:
	gdb.fortran/library-module.exp false regression on GCC upgrade
	https://sourceware.org/bugzilla/show_bug.cgi?id=19635

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

	Fix compatibility with recent gfortran-5.3.1.
	* gdb.fortran/vla-history.exp (print vla1 allocated)
	(print vla2 allocated, print $2, print $3): Remove
	(print $4): Rename to ...
	(print $2): ... here.
	(print $9): Rename to ...
	(print $5): ... here.
	(print $10): Rename to ...
	(print $6): ... here.
	* gdb.fortran/vla.f90: Add pvla initialization.
2016-02-14 09:21:18 +01:00
Jan Kratochvil e9fb005c0e testsuite regression: gdb.fortran/vla-value-sub.exp gdb.fortran/vla-value-sub-finish.exp
> +static int max_value_size = 65536; /* 64k bytes */

FAIL: gdb.fortran/vla-value-sub.exp: print array2 in foo after it was filled (passed fixed array)
FAIL: gdb.fortran/vla-value-sub.exp: print array2 in foo after it was mofified in debugger (passed fixed array)
FAIL: gdb.fortran/vla-value-sub-finish.exp: print array2 in foo after it was filled
FAIL: gdb.fortran/vla-value-sub-finish.exp: print array2 in foo after it was mofified in debugger

print array2
value requires 296352 bytes, which is more than max-value-size
(gdb) FAIL: gdb.fortran/vla-value-sub.exp: print array2 in foo after it was filled (passed fixed array)

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

	* gdb.fortran/vla-value-sub-finish.exp (set max-value-size 1024*1024):
	New test.
	* gdb.fortran/vla-value-sub.exp: Likewise.
2016-02-14 09:10:59 +01:00
Marcin Kościelnicki e44e00ffff gdb.trace/tfile-avx.c: Change ymm15 to xmm15 for old gcc.
gcc older than 4.9 doesn't understand ymm15 as a register name.  Use
xmm15 instead.

gdb/testsuite/ChangeLog:

	* gdb.trace/tfile-avx.c (main): Change ymm15 to xmm15.
2016-02-12 21:51:37 +01:00
Simon Marchi 97e9415187 i386-biarch-core.exp: Use standard_output_file
Fix the core file path to use the standard output directory.

gdb/testsuite/ChangeLog:

	* i386-biarch-core.exp: Define corefile using
	standard_output_file.
2016-02-12 13:56:21 -05:00
Yao Qi a5652c21a8 [gdbserver, aarch64] Use linux_{set,get}_pc_{64,32}bit
We can use shared functions linux_{set,get}_pc_{64,32}bit in
linux-aarch64-low.c to write and read pc.

gdb/gdbserver:

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

	* linux-aarch64-low.c (aarch64_get_pc): Call linux_get_pc_64bit
	or linux_get_pc_32bit.
	(aarch64_set_pc): Call linux_set_pc_64bit or linux_set_pc_32bit.
2016-02-12 16:08:25 +00:00
Yao Qi 01113bc1c5 [ARM] Software single step cross kernel helpers
GDB step cross kernel helpers only works if the kernel helpers are tail
called, which is the case how it is used in glibc.  See __aeabi_read_tp
in sysdeps/unix/sysv/linux/arm/aeabi_read_tp.S.  In __aeabi_read_tp,
branch/jump to the kernel helper is the last instruction, and the next
instruction address is in LR, which is in caller function.  GDB can
handle this correctly.  For example, glibc function __GI___ctype_init
calls __aeabi_read_tp

   0xb6e19b30 <__GI___ctype_init+4>:	ldr	r3, [pc, #80]	;
   0xb6e19b34 <__GI___ctype_init+8>:	bl	0xb6e0a6e0 <__aeabi_read_tp>
   0xb6e19b38 <__GI___ctype_init+12>:	ldr	r3, [pc, r3]

and __aeabi_read_tp calls kernel helper,

(gdb) disassemble __aeabi_read_tp
   0xb6fef5d0 <+0>:	mvn	r0, #61440	; 0xf000
   0xb6fef5d4 <+4>:	sub	pc, r0, #31

once GDB or GDBserver single step instruction on 0xb6fef5d4, LR is
0xb6e19b38, which is right address of next instruction to set breakpoint
on.

However, if the kernel helpers are not tail-called, the LR is still the
address in the caller function of kernel helper's caller, which isn't
the right address of next instruction to set breakpoint on.  For example,
we use kernel helper in main,

(gdb) disassemble main
....
   0x00008624 <+32>:    mov     r3, #4064       ; 0xfe0^M
   0x00008628 <+36>:    movt    r3, #65535      ; 0xffff^M
   0x0000862c <+40>:    blx     r3
   0x00008630 <+44>:    ldr     r3, [r11, #-8]

kernel helper is called on 0x0000862c and the expected next instruction
address is 0x00008630, but the LR now is the return address of main.
The problem here is LR may not have the right address because when we
single step the instruction, it isn't executed yet, so the LR isn't
updated.  This patch fix this problem by decoding instruction, if the
instruction updates LR (BL and BLX), the next instruction address is
PC + INSN_SIZE, otherwise, get the address of next instruction from LR.

gdb:

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

	* arch/arm-linux.c (arm_linux_get_next_pcs_fixup): Calculate
	nextpc according to instruction.

gdb/testsuite:

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

	* gdb.arch/arm-single-step-kernel-helper.c: New.
	* gdb.arch/arm-single-step-kernel-helper.exp: New.
2016-02-12 15:58:56 +00:00
Yao Qi ed443b61e1 [ARM] Fixup PC in software single step
When I exercise GDBserver software single step, I see the following
error, which has been already handled by GDB properly.

In GDBserver log, we can see, GDBserver tries to single step instruction
on 0xb6e0a6e4, and destination address is 0xffff0fe0,

 stop pc is 0xb6e0a6e4
 Writing f001f0e7 to 0xffff0fe0 in process 7132
 Failed to insert breakpoint at 0xffff0fe0 (Input/output error).
 Failed to insert breakpoint at 0xffff0fe0 (-1).

(gdb) disassemble __aeabi_read_tp,+8
Dump of assembler code from 0xb6e0a6e0 to 0xb6e0a6e8:
   0xb6e0a6e0 <__aeabi_read_tp+0>:	mvn	r0, #61440	; 0xf000
   0xb6e0a6e4 <__aeabi_read_tp+4>:	sub	pc, r0, #31

however, it fails inserting breakpoint there.  This problem has already
fixed by GDB, see comments in arm-linux-tdep.c:arm_linux_software_single_step

      /* The Linux kernel offers some user-mode helpers in a high page.  We can
	 not read this page (as of 2.6.23), and even if we could then we
	 couldn't set breakpoints in it, and even if we could then the atomic
	 operations would fail when interrupted.  They are all called as
	 functions and return to the address in LR, so step to there
	 instead.  */

so we need to do the same thing in GDB side as well.  This patch adds
a new field fixup in arm_get_next_pcs_ops, so that we can fix up PC
for arm-linux target.  In this way, both GDB and GDBserver can single
step instructions going to kernel helpers.

gdb:

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

	* arch/arm-get-next-pcs.c (arm_get_next_pcs): Call
	self->ops->fixup if it isn't NULL.
	* arch/arm-get-next-pcs.h: Include gdb_vecs.h.
	(struct arm_get_next_pcs_ops) <fixup>: New field.
	* arch/arm-linux.c: Include common-regcache.h and
	arch/arm-get-next-pcs.h.
	(arm_linux_get_next_pcs_fixup): New function.
	* arch/arm-linux.h (arm_linux_get_next_pcs_fixup): Declare.
	* arm-linux-tdep.c (arm_linux_get_next_pcs_ops): Initialize
	it with arm_linux_get_next_pcs_fixup.
	(arm_linux_software_single_step): Move code to
	arm_linux_get_next_pcs_fixup.
	* arm-tdep.c (arm_get_next_pcs_ops): Initialize it.

gdb/gdbserver:

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

	* linux-arm-low.c (get_next_pcs_ops): Initialize it with
	arm_linux_get_next_pcs_fixup.
2016-02-12 15:58:52 +00:00
Marcin Kościelnicki 020ecd38e7 gdb.trace: Deduplicate write_inferior_data_ptr.
This function is now basically identical to write_inferior_data_pointer,
remove it and change all references.

gdb/gdbserver/ChangeLog:

	* tracepoint.c (x_tracepoint_action_download): Change
	write_inferior_data_ptr to write_inferior_data_pointer.
	(cmd_qtstart): Likewise.
	(write_inferior_data_ptr): Remove.
	(download_agent_expr): Change write_inferior_data_ptr to
	write_inferior_data_pointer.
	(download_tracepoint_1): Likewise.
	(download_tracepoint): Likewise.
	(download_trace_state_variables): Likewise.
2016-02-12 12:35:14 +01:00
Marcin Kościelnicki d21b5f15d9 gdb: Fix build failure in xml-tdesc.c without expat.
Introduced by 18d3cec54e.

gdb/ChangeLog:

	* xml-tdesc.c (target_fetch_description_xml) [!HAVE_LIBEXPAT]: Warn
	and return NULL.
2016-02-12 11:21:00 +01:00
Markus Metzger 33b4777ca1 btrace, frame: fix crash in get_frame_type
In skip_artificial_frames we repeatedly call get_prev_frame_always until we get
a non-inline and non-tailcall frame assuming that there must be such a frame
eventually.

For record targets, however, we may have a frame chain that consists only of
artificial frames.  This leads to a crash in get_frame_type when dereferencing a
NULL frame pointer.

Change skip_artificial_frames and skip_tailcall_frames to return NULL in such a
case and modify each caller to cope with a NULL return.

In frame_unwind_caller_pc and frame_unwind_caller_arch, we simply assert that
the returned value is not NULL.  Their caller was supposed to check
frame_unwind_caller_id before calling those functions.

In other cases, we thrown an error.

In infcmd further move the skip_tailcall_frames call to the forward-stepping
case since we don't need a frame for reverse execution and we don't want to fail
because of that.  Reverse-finish does make sense for a tailcall frame.

gdb/
	* frame.h (skip_tailcall_frames): Update comment.
	* frame.c (skip_artificial_frames, skip_tailcall_frames): Return NULL
	if only	artificial frames are found.  Update comment.
	(frame_unwind_caller_id): Handle NULL return.
	(frame_unwind_caller_pc, frame_unwind_caller_arch): Assert that
	skip_artificial_frames does not return NULL.
	(frame_pop): Add an error if only tailcall frames are found.
	* infcmd.c (finish_command): Move skip_tailcall_frames call into forward-
	execution case.  Add an error if only tailcall frames are found.

testsuite/
	* gdb.btrace/tailcall-only.exp: New.
	* gdb.btrace/tailcall-only.c: New.
	* gdb.btrace/x86_64-tailcall-only.S: New.
	* gdb.btrace/i686-tailcall-only.S: New.
2016-02-12 09:49:48 +01:00