Commit Graph

1478 Commits

Author SHA1 Message Date
Andreas Arnez 782c112285 S390 gdbserver: Mark local funcs/vars as static
Compiling with '-Wmissing-declarations' yields warnings in
linux-s390-low.c.  To fix this, mark appropriate functions as static.

gdb/gdbserver/ChangeLog:

	* linux-s390-low.c (s390_emit_eq_goto): Mark function static.
	(s390_emit_ne_goto): Likewise.
	(s390_emit_lt_goto): Likewise.
	(s390_emit_le_goto): Likewise.
	(s390_emit_gt_goto): Likewise.
	(s390_emit_ge_goto): Likewise.
	(s390x_emit_eq_goto): Likewise.
	(s390x_emit_ne_goto): Likewise.
	(s390x_emit_lt_goto): Likewise.
	(s390x_emit_le_goto): Likewise.
	(s390x_emit_gt_goto): Likewise.
	(s390x_emit_ge_goto): Likewise.
	(s390_emit_ops_impl): Mark variable static.
	(s390x_emit_ops): Likewise.
2016-06-21 13:26:11 +02:00
Yao Qi 2e7b624b85 Handle reinsert breakpoints for vforked child
When a thread is doing step-over with reinsert breakpoint, and the
instruction executed is a syscall doing vfork, both parent and child
share the memory, so the reinsert breakpoint in the space is visible
to both of them.  Also, removing the reinsert breakpoints from the
child will effectively remove them from the parent.  We should
carefully manipulate reinsert breakpoints for both processes.

What we are doing here is that

 - uninsert reinsert breakpoints from the parent before cloning the
   breakpoint list.  We use "uninsert" instead of "remove", because
   we need to "reinsert" them back after vfork is done.  In fact,
   "uninsert" removes them from both child and parent process space.
 - reinsert breakpoints in parent process are still copied to child's
   breakpoint list,
 - remove them from child's breakpoint list as what we did for fork,
   at this point, reinsert breakpoints are removed from the child and
   the parent, but they are still tracked by the parent's breakpoint
   list,
 - once vfork is done, "reinsert" them back to the parent,

gdb/gdbserver:

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

	* linux-low.c (handle_extended_wait): Call
	uninsert_reinsert_breakpoints for the parent process.  Remove
	reinsert breakpoints from the child process.  Reinsert them to
	the parent process when vfork is done.
	* mem-break.c (uninsert_reinsert_breakpoints): New function.
	(reinsert_reinsert_breakpoints): New function.
	* mem-break.h (uninsert_reinsert_breakpoints): Declare
	(reinsert_reinsert_breakpoints): Declare.
2016-06-17 10:38:55 +01:00
Yao Qi 8a81c5d7a7 Delete reinsert breakpoints from forked child
When a thread is stepping over a syscall instruction with software
single step, GDBserver inserts reinsert breakpoints at the next pcs.
If the syscall call is fork, the forked child has reinsert breakpoint
in its space, and GDBserver clones parent's breakpoint list to child's.
When GDBserver resumes the child, its bp_reinsert is zero, but has
reinsert breakpoints, so the following assert is triggered if I apply
the patch extending step-over-syscall.exp.

gdb/gdbserver/linux-low.c:4292: A problem internal to GDBserver has been detected.^M
void linux_resume_one_lwp_throw(lwp_info*, int, int, siginfo_t*): Assertion `!has_reinsert_breakpoints (proc)' failed.

gdb/gdbserver:

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

	* linux-low.c (handle_extended_wait): If the parent is doing
	step-over, remove the reinsert breakpoints from the forked child.
2016-06-17 10:38:55 +01:00
Yao Qi f50bf8e515 Step over exit with reinsert breakpoints
This patch fixes a GDBserver crash when one thread is stepping over
a syscall instruction which is exit.  Step-over isn't finished due
to the exit, but GDBserver doesn't clean up the state of step-over,
so in the wait next time, GDBserver will wait on step_over_bkpt,
which is already exited, and GDBserver crashes because
'requested_child' is NULL.  See gdbserver logs below,

Need step over [LWP 14858]? yes, found breakpoint at 0x2aaaaad91307^M
proceed_all_lwps: found thread 14858 needing a step-over^M
Starting step-over on LWP 14858.  Stopping all threads^M
>>>> entering void stop_all_lwps(int, lwp_info*)
....
<<<< exiting void stop_all_lwps(int, lwp_info*)^M
Done stopping all threads for step-over.^M
pc is 0x2aaaaad91307^M
Writing 0f to 0x2aaaaad91307 in process 14858^M
Could not find fast tracepoint jump at 0x2aaaaad91307 in list (uninserting).^M
  pending reinsert at 0x2aaaaad91307^M
  step from pc 0x2aaaaad91307^M
Resuming lwp 14858 (step, signal 0, stop not expected)^M

 # Start step-over for LWP 14858

>>>> entering ptid_t linux_wait_1(ptid_t, target_waitstatus*, int)
....
LLFE: 14858 exited.
...
<<<< exiting ptid_t linux_wait_1(ptid_t, target_waitstatus*, int)

  # LWP 14858 exited
.....
>>>> entering ptid_t linux_wait_1(ptid_t, target_waitstatus*, int)^M
linux_wait_1: [<all threads>]^M
step_over_bkpt set [LWP 14858.14858], doing a blocking wait

  # but step_over_bkpt is still LWP 14858, which is wrong

The fix is to finish step-over if it is ongoing, and unsuspend other
threads.  Without the fix in linux-low.c, GDBserver will crash in
with running gdb.base/step-over-exit.exp.

gdb/gdbserver:

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

	* linux-low.c (unsuspend_all_lwps): Declare.
	(linux_low_filter_event): If thread exited, call finish_step_over.
	If step-over is finished, unsuspend other threads.

gdb/testsuite:

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

	* gdb.base/step-over-exit.c: New.
	* gdb.base/step-over-exit.exp: New.
2016-06-17 10:38:55 +01:00
Yao Qi 8376a3cbf7 More assert checks on reinsert breakpoint
This patch adds more asserts, so the incorrect or sub-optimal
reinsert breakpoints manipulations (from the tests in the following
patches) can trigger them.

gdb/gdbserver:

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

	* linux-low.c (linux_resume_one_lwp_throw): Assert
	has_reinsert_breakpoints returns false.
	* mem-break.c (delete_disabled_breakpoints): Assert
	bp type isn't reinsert_breakpoint.
2016-06-17 10:38:19 +01:00
Yao Qi f79b145de3 Switch to current thread in finish_step_over
This patch adds some sanity check that reinsert breakpoints must be
there when doing step-over on software single step target.  The check
triggers an assert when running forking-threads-plus-breakpoint.exp
on arm-linux target,

 gdb/gdbserver/linux-low.c:4714: A problem internal to GDBserver has been detected.^M
 int finish_step_over(lwp_info*): Assertion `has_reinsert_breakpoints ()' failed.

the error happens when GDBserver has already resumed a thread of
process A for step-over (and wait for it hitting reinsert breakpoint),
but receives detach request for process B from GDB, which is shown in
the backtrace below,

 (gdb) bt
 #2  0x000228aa in finish_step_over (lwp=0x12bbd98) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:4703
 #3  0x00025a50 in finish_step_over (lwp=0x12bbd98) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:4749
 #4  complete_ongoing_step_over () at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:4760
 #5  linux_detach (pid=25228) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:1503
 #6  0x00012bae in process_serial_event () at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/server.c:3974
 #7  handle_serial_event (err=<optimized out>, client_data=<optimized out>) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/server.c:4347
 #8  0x00016d68 in handle_file_event (event_file_desc=<optimized out>) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/event-loop.c:429
 #9  0x000173ea in process_event () at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/event-loop.c:184
 #10 start_event_loop () at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/event-loop.c:547
 #11 0x0000aa2c in captured_main (argv=<optimized out>, argc=<optimized out>) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/server.c:3719
 #12 main (argc=<optimized out>, argv=<optimized out>) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/server.c:3804

the sanity check tries to find the reinsert breakpoint from process B,
but nothing is found.  It is wrong, we need to search in process A,
since we started step-over of a thread of process A.

 (gdb) p lwp->thread->entry.id
 $3 = {pid = 25120, lwp = 25131, tid = 0}
 (gdb) p current_thread->entry.id
 $4 = {pid = 25228, lwp = 25228, tid = 0}

This patch switched current_thread to the thread we are doing step-over
in finish_step_over.

gdb/gdbserver:

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

	* linux-low.c (maybe_hw_step): New function.
	(linux_resume_one_lwp_throw): Call maybe_hw_step.
	(finish_step_over): Switch current_thread to lwp temporarily,
	and assert has_reinsert_breakpoints returns true.
	(proceed_one_lwp): Call maybe_hw_step.
	* mem-break.c (has_reinsert_breakpoints): New function.
	* mem-break.h (has_reinsert_breakpoints): Declare.
2016-06-17 10:38:19 +01:00
Jon Turney 0ae534d2cf Fix C++ build for Cygwin
gdb/ChangeLog:

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

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

gdb/gdbserver/ChangeLog:

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

	* win32-low.c (win32_create_inferior): Add pointer casts for C++.
2016-06-03 11:29:25 +00:00
Yao Qi fcdad592cd Use unsuspend_all_lwps
This patch is to replace find_inferior (&all_threads, unsuspend_one_lwp, NULL)
with unsuspend_all_lwps (NULL), which is shorter.  They are equivalent
to each other.

gdb/gdbserver:

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

	* linux-low.c (linux_stabilize_threads): Call unsuspend_all_lwps
	instead of find_inferior.
2016-05-17 08:24:26 +01:00
Simon Marchi cbe14bcfad Fix ChangeLog entry format 2016-05-05 09:46:06 -04:00
Yao Qi 9e78496443 Initialize res in get_next_pcs_read_memory_unsigned_integer
This patch initialize res to zero, otherwise, it may have some garbage
bits after the *the_target->read_memory call.

gdb/gdbserver:

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

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

gdb/gdbserver:

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

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

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

gdbserver/ChangeLog:

	* spu-low.c (fetch_ppc_register): Cast PowerPC-Linux-specific value
	used as first ptrace argument to PTRACE_TYPE_ARG1 for C++.
	(fetch_ppc_memory_1, store_ppc_memory_1): Likewise.
2016-05-04 19:42:09 -04:00
Par Olsson 35fd2deb69 Fix write endianness/size problem for fast tracepoint enabled flag
I am sending this fix on behalf of Par Olsson, as a follow-up of this
one:

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

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

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

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

gdb/gdbserver/ChangeLog:

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

	* tracepoint.c (write_inferior_int8): New function.
	(cmd_qtenable_disable): Write enable flag using
	write_inferior_int8.
2016-04-28 12:56:05 -04:00
Yao Qi f166f943f3 Remove need_step_over from struct lwp_info
Hi,
I happen to see that field need_step_over in struct lwp_info is only
used to print a debug info.  need_step_over is set in linux_wait_1
when breakpoint_here is true, however, we check breakpoint_here too in
need_step_over_p and do the step over.  I think we don't need field
need_step_over, and check breakpoint_here directly in need_step_over_p.

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

This patch is to remove it.

gdb/gdbserver:

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

	* linux-low.h (struct lwp_info) <need_step_over>: Remove.
	* linux-low.c (linux_wait_1): Update.
	(need_step_over_p): Likewise.
2016-04-28 11:52:23 +01:00
Yao Qi 484b3c325d Resume the inferior with signal rather than stepping over
When GDBserver steps over a breakpoint using software single step, it
enqueues the signal, single step and deliver the signal in the next
resume if step over is not needed.  In this way, the program won't
receive the signal if the conditional breakpoint is set a branch to
self instruction, because the step over is always needed.

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

gdb/gdbserver:

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

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

The fix is to remove the error and return instead.

gdb/gdbserver:

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

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

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

gdb/gdbserver:

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

	* mem-break.c (set_raw_breakpoint_at): Create a raw breakpoint
	object.  Insert it if it is not inserted yet.  Increase the
	refcount and link it into the proc's raw breakpoint list.
2016-04-25 09:43:36 +01:00
Yao Qi 3539aa13fb [ARM] Clear reserved bits in CPSR
Bits 20 ~ 23 of CPSR are reserved (RAZ, read as zero), but they are not
zero if the arm program runs on aarch64-linux.  AArch64 tracer gets PSTATE
from arm 32-bit tracee as CPSR, but bits 20 ~ 23 are used in PSTATE.  I
think kernel should clear these bits when it is read through ptrace, but
the fix in user space is still needed.

This patch fixes these two fails,

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

gdb:

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

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

gdb/gdbserver:

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

	* linux-aarch32-low.c (arm_store_gregset): Clear CPSR bits 20
	to 23.
2016-04-22 15:54:43 +01:00
Walfred Tedeschi 7915f48c28 [obv] [PR gdb/19980] Typo in gdbserver/configure.srv
Simple exchange of mpx-avx for avx-mpx.
Other occurrences were not found.

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

gdb/gdbserver/ChangeLog:

	* configure.srv (srv_amd64_xmlfiles): Exchange
	i386/amd64-mpx-avx.xml for i386/amd64-avx-mpx.xml.
2016-04-22 14:23:29 +02:00
Yao Qi 5b061e9886 Deliver signal in hardware single step
GDBserver doesn't deliver signal when stepping over a breakpoint even
hardware single step is used.  When GDBserver started to step over
(thread creation) breakpoint for mutlit-threaded debugging in 2002 [1],
GDBserver behaves this way.

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

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

and I set breakpoint

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

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

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

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

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

gdb/gdbserver:

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

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

gdb/testsuite:

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

	* gdb.trace/signal.exp: Also pass if
	$tracepoint_hits($i) > $iterations.
2016-04-22 11:59:18 +01:00
Pedro Alves 3451269c41 Fix s390 GNU/Linux gdb and gdbserver builds
Now that gdb/gdbserver compile as C++ programs by default, the s390
GNU/Linux build started failing with:

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

etc.

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

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

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

	* linux-s390-low.c (s390_collect_ptrace_register)
	(s390_supply_ptrace_register, s390_get_hwcap): Use gdb_byte * and
	add casts.
	(s390_check_regset): Use void * instead of gdb_byte *.
2016-04-21 12:03:53 +01:00
Pedro Alves a23585089d Build GDB as a C++ program by default
This makes --enable-build-with-cxx be "yes" by default.

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

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

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

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

	* configure: Renegerate.
2016-04-20 23:20:15 +01:00
Yao Qi 6885166d99 Move ARM_CPSR_GREGNUM to arch/arm-linux.h
This patch moves macro ARM_CPSR_GREGNUM to arch/arm-linux.h so that it
can be used in GDBserver side.

gdb:

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

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

gdb/gdbserver:

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

	* linux-aarch32-low.c: Include "arch/arm-linux.h".
	(arm_fill_gregset): Use ARM_CPSR_GREGNUM rather than magic
	number 16.
	(arm_store_gregset): Likewise.
2016-04-20 12:32:15 +01:00
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
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 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
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
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
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
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
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
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
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
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
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
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
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
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 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
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
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