Commit Graph

1009 Commits

Author SHA1 Message Date
Pedro Alves 932539e3ab [GDBserver] Move Z packet defines and type convertion routines to shared code.
The Aarch64, MIPS and x86 Linux backends all have Z packet number
defines and corresponding protocol number to internal type convertion
routines.  Factor them all out to gdbserver's core code, so we only
have one shared copy.

Tested on x86_64 Fedora 20, and also cross built for aarch64-linux-gnu
and mips-linux-gnu.

gdb/gdbserver/
2014-05-20  Pedro Alves  <palves@redhat.com>

	* mem-break.h: Include break-common.h.
	(Z_PACKET_SW_BP, Z_PACKET_HW_BP, Z_PACKET_WRITE_WP)
	(Z_PACKET_READ_WP, Z_PACKET_ACCESS_WP): New defines.
	(Z_packet_to_target_hw_bp_type): New declaration.
	* mem-break.c (Z_packet_to_target_hw_bp_type): New function.
	* i386-low.c (Z_PACKET_HW_BP, Z_PACKET_WRITE_WP, Z_PACKET_READ_WP)
	(Z_PACKET_ACCESS_WP): Delete macros.
	(Z_packet_to_hw_type): Delete function.
	* i386-low.h: Don't include break-common.h here.
	(Z_packet_to_hw_type): Delete declaration.
	* linux-x86-low.c (x86_insert_point, x86_insert_point): Call
	Z_packet_to_target_hw_bp_type instead of Z_packet_to_hw_type.
	* win32-i386-low.c (i386_insert_point, i386_remove_point): Call
	Z_packet_to_target_hw_bp_type instead of Z_packet_to_hw_type.
	* linux-aarch64-low.c: Don't include break-common.h here.
	(Z_PACKET_SW_BP, Z_PACKET_HW_BP, Z_PACKET_WRITE_WP)
	(Z_PACKET_READ_WP, Z_PACKET_ACCESS_WP): Delete macros.
	(Z_packet_to_target_hw_bp_type): Delete function.
	* linux-mips-low.c (rsp_bp_type_to_target_hw_bp_type): Delete
	function.
	(mips_insert_point, mips_remove_point): Use
	Z_packet_to_target_hw_bp_type.
2014-05-20 18:41:41 +01:00
Pedro Alves 4ff0d3d82d [GDBserver][AArch64] Make watchpoint support use target_hw_bp_type.
This makes linux-aarch64-low.c use target_hw_bp_type, like gdb's
aarch64-linux-nat.c.  The original motivation is decoupling
insert_point/remove_point from Z packet numbers, but I think making
the files a little bit more similar is a good thing on its own right.
Ideally we'd merge these files even...  The
aarch64_point_encode_ctrl_reg change is taken straight from GDB's
copy.

I confirmed with a cross compiler that this builds, but it's otherwise
untested.

gdb/gdbserver/
2014-05-20  Pedro Alves  <palves@redhat.com>

	* linux-aarch64-low.c: Include break-common.h.
	(enum target_point_type): Delete.
	(Z_packet_to_point_type): Rename to ...
	(Z_packet_to_target_hw_bp_type): ... this, and return a
	target_hw_bp_type instead.
	(aarch64_show_debug_reg_state): Take an enum target_hw_bp_type
	instead of an enum target_point_type.
	(aarch64_point_encode_ctrl_reg): Likewise.  Compute type mask from
	breakpoint type.
	(aarch64_dr_state_insert_one_point)
	(aarch64_dr_state_remove_one_point, aarch64_handle_breakpoint)
	(aarch64_handle_aligned_watchpoint)
	(aarch64_handle_unaligned_watchpoint, aarch64_handle_watchpoint):
	Take an enum target_hw_bp_type instead of an enum
	target_point_type.
	(aarch64_supports_z_point_type): New function.
	(aarch64_insert_point, aarch64_remove_point): Use it.  Adjust to
	use Z_packet_to_target_hw_bp_type.
2014-05-20 18:24:27 +01:00
Joel Brobecker 786dc51990 Do not build gdbserver with -Werror by default if development=false
On GDB release branches, we change $development in gdb/development.sh
to false, in order to build the GDB release without -Werror by default,
thus avoiding harmless compiler warnings from breaking the build of
someone who's only interested in building GDB rather than working
on it.

This patch implements the same strategy for gdbserver, using the exact
same method.

gdb/gdbserver/ChangeLog:

        * configure.ac: Only use -Werror by default when DEVELOPMENT
        is true.
        * configure: Regenerate.

Tested on x86_64-linux, by rebuilding GDBserver first with development
set to true, and then doing it again with development set to false.
Werror was used in the first case, but not in the second.
2014-05-20 06:25:10 -07:00
Jan Kratochvil 9e0aa64f55 Fix gdbserver qGetTLSAddr for x86_64 -m32
gdbserver makes libthread_db to access uninitialized memory.  Surprisingly it
does not harm normally, even -fsanitize=address works with current gdbserver.
I have found just valgrind detects it as a very first warning for gdbserver:

Syscall param ptrace(addr) contains uninitialised byte(s)
   at 0x3721EECEBE: ptrace (ptrace.c:45)
   by 0x436EE5: ps_get_thread_area (linux-x86-low.c:252)
   by 0x5559D02: __td_ta_lookup_th_unique (td_ta_map_lwp2thr.c:157)
   by 0x5559EC3: td_ta_map_lwp2thr (td_ta_map_lwp2thr.c:207)
   by 0x43F87D: find_one_thread (thread-db.c:281)
   by 0x440038: thread_db_get_tls_address (thread-db.c:505)
   by 0x40F6D0: handle_query (server.c:2004)
   by 0x4124CF: process_serial_event (server.c:3445)
   by 0x4136B6: handle_serial_event (server.c:3889)
   by 0x419571: handle_file_event (event-loop.c:434)
   by 0x418D38: process_event (event-loop.c:189)
   by 0x419AB7: start_event_loop (event-loop.c:552)

Reproducible with:
cd gdb/testsuite
g++ -o gdb.threads/tls gdb.threads/tls{,2}.c -m32 -pthread
../gdbserver/gdbserver :1234 gdb.threads/tls
../gdb -batch gdb.threads/tls -ex 'target remote :1234' -ex 'b spin' -ex c -ex 'p a_thread_local'

It is more easily reproducible even without valgrind using s/0x00/0xff/ in the
attached patch.  It will then turn the output of reproducer above:
$1 = 0
->
Cannot find thread-local storage for Thread 29044, executable file .../gdb/testsuite/gdb.threads/tls:
Remote target failed to process qGetTLSAddr request

gdb/gdbserver/
2014-05-19  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix gdbserver qGetTLSAddr for x86_64 -m32.
	* linux-x86-low.c (X86_64_USER_REGS): New.
	(x86_fill_gregset): Call memset for BUF first in x86_64 -m32 case.

Message-ID: <20140410114901.GA16411@host2.jankratochvil.net>
2014-05-19 20:20:27 +02:00
Yao Qi 2b577b92f0 [gdbserver] Correctly generate i386-avx512.c
The makefile rule i386-avx512.c is to generate i386-avx512.c, but it
is written to i386-avx.c by mistake.  This patch is to fix this typo.

gdb/gdbserver:

2014-04-28  Yao Qi  <yao@codesourcery.com>

	* Makefile.in (i386-avx512.c): Fix the typo of generated file
	name.
2014-04-28 20:26:00 +08:00
Pedro Alves 94611da240 Add missing gdbserver/ChangeLog entry for previous commit.
2014-04-25  Pedro Alves  <palves@redhat.com>

	PR server/16255
	* linux-low.c (linux_attach_fail_reason_string): New function.
	(linux_attach_lwp): Delete.
	(linux_attach_lwp_1): Rename to ...
	(linux_attach_lwp): ... this.  Take a ptid instead of a pid as
	argument.  Remove "initial" parameter.  Return int instead of
	void.  Don't error or warn here.
	(linux_attach): Adjust to call linux_attach_lwp.  Call error on
	failure to attach to the tgid.  Call warning when failing to
	attach to an lwp.
	* linux-low.h (linux_attach_lwp): Take a ptid instead of a pid as
	argument.  Remove "initial" parameter.  Return int instead of
	void.  Don't error or warn here.
	(linux_attach_fail_reason_string): New declaration.
	* thread-db.c (attach_thread): Adjust to linux_attach_lwp's
	interface change.  Use linux_attach_fail_reason_string.
2014-04-25 19:22:27 +01:00
Pedro Alves 7ae1a6a6cc PR server/16255: gdbserver cannot attach to a second inferior that is multi-threaded.
On Linux, we need to explicitly ptrace attach to all lwps of a
process.  Because GDB might not be connected yet when an attach is
requested, and thus it may not be possible to activate thread_db, as
that requires access to symbols (IOW, gdbserver --attach), a while ago
we make linux_attach loop over the lwps as listed by /proc/PID/task to
find the lwps to attach to.

linux_attach_lwp_1 has:

...
  if (initial)
    /* If lwp is the tgid, we handle adding existing threads later.
       Otherwise we just add lwp without bothering about any other
       threads.  */
    ptid = ptid_build (lwpid, lwpid, 0);
  else
    {
      /* Note that extracting the pid from the current inferior is
	 safe, since we're always called in the context of the same
	 process as this new thread.  */
      int pid = pid_of (current_inferior);
      ptid = ptid_build (pid, lwpid, 0);
    }

That "safe" comment referred to linux_attach_lwp being called by
thread-db.c.  But this was clearly missed when a new call to
linux_attach_lwp_1 was added to linux_attach.  As a result,
current_inferior will be set to some random process, and non-initial
lwps of the second inferior get assigned the pid of the wrong
inferior.  E.g., in the case of attaching to two inferiors, for the
second inferior (and so on), non-initial lwps of the second inferior
get assigned the pid of the first inferior.  This doesn't trigger on
the first inferior, when current_inferior is NULL, add_thread switches
the current inferior to the newly added thread.

Rather than making linux_attach switch current_inferior temporarily
(thus avoiding further reliance on global state), or making
linux_attach_lwp_1 get the tgid from /proc, which add extra syscalls,
and will be wrong in case of the user having originally attached
directly to a non-tgid lwp, and then that lwp spawning new clones (the
ptid.pid field of further new clones should be the same as the
original lwp's pid, which is not the tgid), we note that callers of
linux_attach_lwp/linux_attach_lwp_1 always have the right pid handy
already, so they can pass it down along with the lwpid.

The only other reason for the "initial" parameter is to error out
instead of warn in case of attach failure, when we're first attaching
to a process.  There are only three callers of
linux_attach_lwp/linux_attach_lwp_1, and each wants to print a
different warn/error string, so we can just move the error/warn out of
linux_attach_lwp_1 to the callers, thus getting rid of the "initial"
parameter.

There really nothing gdbserver-specific about attaching to two
threaded processes, so this adds a new test under gdb.multi/.  The
test passes cleanly against the native GNU/Linux target, but
fails/triggers the bug against GDBserver (before the patch), with the
native-extended-remote board (as plain remote doesn't support
multi-process).

Tested on x86_64 Fedora 17, with the native-extended-gdbserver board.

gdb/gdbserver/
2014-04-25  Pedro Alves  <palves@redhat.com>

	PR server/16255
	* linux-low.c (linux_attach_fail_reason_string): New function.
	(linux_attach_lwp): Delete.
	(linux_attach_lwp_1): Rename to ...
	(linux_attach_lwp): ... this.  Take a ptid instead of a pid as
	argument.  Remove "initial" parameter.  Return int instead of
	void.  Don't error or warn here.
	(linux_attach): Adjust to call linux_attach_lwp.  Call error on
	failure to attach to the tgid.  Call warning when failing to
	attach to an lwp.
	* linux-low.h (linux_attach_lwp): Take a ptid instead of a pid as
	argument.  Remove "initial" parameter.  Return int instead of
	void.  Don't error or warn here.
	(linux_attach_fail_reason_string): New declaration.
	* thread-db.c (attach_thread): Adjust to linux_attach_lwp's
	interface change.  Use linux_attach_fail_reason_string.

gdb/
2014-04-25  Pedro Alves  <palves@redhat.com>

	PR server/16255
	* common/linux-ptrace.c (linux_ptrace_attach_warnings): Rename to ...
	(linux_ptrace_attach_fail_reason): ... this.  Remove "warning: "
	and newline from built string.
	* common/linux-ptrace.h (linux_ptrace_attach_warnings): Rename to ...
	(linux_ptrace_attach_fail_reason): ... this.
	* linux-nat.c (linux_nat_attach): Adjust to use
	linux_ptrace_attach_fail_reason.

gdb/testsuite/
2014-04-25  Simon Marchi  <simon.marchi@ericsson.com>
	    Pedro Alves  <palves@redhat.com>

	PR server/16255
	* gdb.multi/multi-attach.c: New file.
	* gdb.multi/multi-attach.exp: New file.
2014-04-25 19:07:33 +01:00
Michael Sturm 01f9f808e2 Add AVX512 registers support to GDB and GDBserver.
This patch adds support for the Intel(R) Advanced Vector
Extensions 512 (Intel(R) AVX-512) registers.  Native and remote
debugging are covered by this patch.

Intel(R) AVX-512 is an extension to AVX to support 512-bit wide
SIMD registers in 64-bit mode (XMM0-XMM31, YMM0-YMM31, ZMM0-ZMM31).
The number of available registers in 32-bit mode is still 8
(XMM0-7, YMM0-7, ZMM0-7).  The lower 256-bits of the ZMM registers
are aliased to the respective 256-bit YMM registers.  The lower
128-bits are aliased to the respective 128-bit XMM registers.

There are also 8 new, dedicated mask registers (K0-K7) in both 32-bit
mode and 64-bit mode.

For more information please see
Intel(R) Developer Zone: Intel(R) AVX
http://software.intel.com/en-us/intel-isa-extensions#pid-16007-1495

Intel(R) Architecture Instruction Set Extensions Programming Reference:
http://software.intel.com/en-us/file/319433-017pdf

2014-04-24  Michael Sturm  <michael.sturm@mintel.com>
            Walfred Tedeschi  <walfred.tedeschi@intel.com>

     * amd64-linux-nat.c (amd64_linux_gregset32_reg_offset): Add
     AVX512 registers.
     (amd64_linux_read_description): Add code to handle AVX512 xstate
     mask and return respective tdesc.
     * amd64-linux-tdep.c: Include features/i386/amd64-avx512-linux.c
     and features/i386/x32-avx512-linux.c.
     (amd64_linux_gregset_reg_offset): Add AVX512 registers.
     (amd64_linux_core_read_description): Add code to handle AVX512
     xstate mask and return respective tdesc.
     (_initialize_amd64_linux_tdep): Initialize AVX512 tdesc.
     * amd64-linux-tdep.h (AMD64_LINUX_ORIG_RAX_REGNUM): Adjust regnum
     calculation.
     (AMD64_LINUX_NUM_REGS): Adjust to new number of registers.
     (tdesc_amd64_avx512_linux): New prototype.
     (tdesc_x32_avx512_linux): Likewise.
     * amd64-tdep.c: Include features/i386/amd64-avx512.c and
     features/i386/x32-avx512.c.
     (amd64_ymm_avx512_names): New register names for pseudo
     registers YMM16-31.
     (amd64_ymmh_avx512_names): New register names for raw registers
     YMMH16-31.
     (amd64_k_names): New register names for K registers.
     (amd64_zmmh_names): New register names for ZMM raw registers.
     (amd64_zmm_names): New registers names for ZMM pseudo registers.
     (amd64_xmm_avx512_names): New register names for XMM16-31
     registers.
     (amd64_pseudo_register_name): Add code to return AVX512 pseudo
     registers.
     (amd64_init_abi): Add code to intitialize AVX512 tdep variables
     if feature is present.
     (_initialize_amd64_tdep): Call AVX512 tdesc initializers.
     * amd64-tdep.h (enum amd64_regnum): Add AVX512 registers.
     (AMD64_NUM_REGS): Adjust to new number of registers.
     * i386-linux-nat.c (GETXSTATEREGS_SUPPLIES): Extend range of
     registers supplied via XSTATE by AVX512 registers.
     (i386_linux_read_description): Add case for AVX512.
     * i386-linux-tdep.c: Include i386-avx512-linux.c.
     (i386_linux_gregset_reg_offset): Add AVX512 registers.
     (i386_linux_core_read_description): Add case for AVX512.
     (i386_linux_init_abi): Install supported register note section
     for AVX512.
     (_initialize_i386_linux_tdep): Add call to tdesc init function for
     AVX512.
     * i386-linux-tdep.h (I386_LINUX_NUM_REGS): Set number of
     registers to be number of zmm7h + 1.
     (tdesc_i386_avx512_linux): Add tdesc for AVX512 registers.
     * i386-tdep.c: Include features/i386/i386-avx512.c.
     (i386_zmm_names): Add ZMM pseudo register names array.
     (i386_zmmh_names): Add ZMM raw register names array.
     (i386_k_names): Add K raw register names array.
     (num_lower_zmm_regs): Add constant for the number of lower ZMM
     registers. AVX512 has 16 more ZMM registers than there are YMM
     registers.
     (i386_zmmh_regnum_p): Add function to look up register number of
     ZMM raw registers.
     (i386_zmm_regnum_p): Likewise for ZMM pseudo registers.
     (i386_k_regnum_p): Likewise for K raw registers.
     (i386_ymmh_avx512_regnum_p): Likewise for additional YMM raw
     registers added by AVX512.
     (i386_ymm_avx512_regnum_p): Likewise for additional YMM pseudo
     registers added by AVX512.
     (i386_xmm_avx512_regnum_p): Likewise for additional XMM registers
     added by AVX512.
     (i386_register_name): Add code to hide YMMH16-31 and ZMMH0-31.
     (i386_pseudo_register_name): Add ZMM pseudo registers.
     (i386_zmm_type): Construct and return vector registers type for ZMM
     registers.
     (i386_pseudo_register_type): Return appropriate type for YMM16-31,
     ZMM0-31 pseudo registers and K registers.
     (i386_pseudo_register_read_into_value): Add code to read K, ZMM
     and YMM16-31 registers from register cache.
     (i386_pseudo_register_write): Add code to write  K, ZMM and
     YMM16-31 registers.
     (i386_register_reggroup_p): Add code to include/exclude AVX512
     registers in/from respective register groups.
     (i386_validate_tdesc_p): Handle AVX512 feature, add AVX512
     registers if feature is present in xcr0.
     (i386_gdbarch_init): Add code to initialize AVX512 feature
     variables in tdep structure, wire in pseudo registers and call
     initialize_tdesc_i386_avx512.
     * i386-tdep.h (struct gdbarch_tdep): Add AVX512 related
     variables.
     (i386_regnum): Add AVX512 registers.
     (I386_SSE_NUM_REGS): New define for number of SSE registers.
     (I386_AVX_NUM_REGS): Likewise for AVX registers.
     (I386_AVX512_NUM_REGS): Likewise for AVX512 registers.
     (I386_MAX_REGISTER_SIZE): Change to 64 bytes, ZMM registers are
     512 bits wide.
     (i386_xmm_avx512_regnum_p): New prototype for register look up.
     (i386_ymm_avx512_regnum_p): Likewise.
     (i386_k_regnum_p): Likewise.
     (i386_zmm_regnum_p): Likewise.
     (i386_zmmh_regnum_p): Likewise.
     * i387-tdep.c : Update year in copyright notice.
     (xsave_ymm_avx512_offset): New table for YMM16-31 offsets in
     XSAVE buffer.
     (XSAVE_YMM_AVX512_ADDR): New macro.
     (xsave_xmm_avx512_offset): New table for XMM16-31 offsets in
     XSAVE buffer.
     (XSAVE_XMM_AVX512_ADDR): New macro.
     (xsave_avx512_k_offset): New table for K register offsets in
     XSAVE buffer.
     (XSAVE_AVX512_K_ADDR): New macro.
     (xsave_avx512_zmm_h_offset): New table for ZMM register offsets
     in XSAVE buffer.
     (XSAVE_AVX512_ZMM_H_ADDR): New macro.
     (i387_supply_xsave): Add code to supply AVX512 registers to XSAVE
     buffer.
     (i387_collect_xsave): Add code to collect AVX512 registers from
     XSAVE buffer.
     * i387-tdep.h (I387_NUM_XMM_AVX512_REGS): New define for number
     of XMM16-31 registers.
     (I387_NUM_K_REGS): New define for number of K registers.
     (I387_K0_REGNUM): New define for K0 register number.
     (I387_NUM_ZMMH_REGS): New define for number of ZMMH registers.
     (I387_ZMM0H_REGNUM): New define for ZMM0H register number.
     (I387_NUM_YMM_AVX512_REGS): New define for number of YMM16-31
     registers.
     (I387_YMM16H_REGNUM): New define for YMM16H register number.
     (I387_XMM16_REGNUM): New define for XMM16 register number.
     (I387_YMM0_REGNUM): New define for YMM0 register number.
     (I387_KEND_REGNUM): New define for last K register number.
     (I387_ZMMENDH_REGNUM): New define for last ZMMH register number.
     (I387_YMMH_AVX512_END_REGNUM): New define for YMM31 register
     number.
     (I387_XMM_AVX512_END_REGNUM): New define for XMM31 register
     number.
     * common/i386-xstate.h: Add AVX 3.1 feature bits, mask and XSTATE
     size.
     * features/Makefile: Add AVX512 related files.
     * features/i386/32bit-avx512.xml: New file.
     * features/i386/64bit-avx512.xml: Likewise.
     * features/i386/amd64-avx512-linux.c: Likewise.
     * features/i386/amd64-avx512-linux.xml: Likewise.
     * features/i386/amd64-avx512.c: Likewise.
     * features/i386/amd64-avx512.xml: Likewise.
     * features/i386/i386-avx512-linux.c: Likewise.
     * features/i386/i386-avx512-linux.xml: Likewise.
     * features/i386/i386-avx512.c: Likewise.
     * features/i386/i386-avx512.xml: Likewise.
     * features/i386/x32-avx512-linux.c: Likewise.
     * features/i386/x32-avx512-linux.xml: Likewise.
     * features/i386/x32-avx512.c: Likewise.
     * features/i386/x32-avx512.xml: Likewise.
     * regformats/i386/amd64-avx512-linux.dat: New file.
     * regformats/i386/amd64-avx512.dat: Likewise.
     * regformats/i386/i386-avx512-linux.dat: Likewise.
     * regformats/i386/i386-avx512.dat: Likewise.
     * regformats/i386/x32-avx512-linux.dat: Likewise.
     * regformats/i386/x32-avx512.dat: Likewise.
     * NEWS: Add note about new support for AVX512.

testsuite/
     * Makefile.in (EXECUTABLES): Added i386-avx512.
     * gdb.arch/i386-avx512.c: New file.
     * gdb.arch/i386-avx512.exp: Likewise.

gdbserver/
     * Makefile.in: Added rules to handle new files
     i386-avx512.c i386-avx512-linux.c amd64-avx512.c
     amd64-avx512-linux.c x32-avx512.c x32-avx512-linux.c.
     * configure.srv (srv_i386_regobj): Add i386-avx512.o.
     (srv_i386_linux_regobj): Add i386-avx512-linux.o.
     (srv_amd64_regobj): Add amd64-avx512.o and x32-avx512.o.
     (srv_amd64_linux_regobj): Add amd64-avx512-linux.o and
     x32-avx512-linux.o.
     (srv_i386_32bit_xmlfiles): Add i386/32bit-avx512.xml.
     (srv_i386_64bit_xmlfiles): Add i386/64bit-avx512.xml.
     (srv_amd64_xmlfiles): Add i386/amd64-avx512.xml and
     i386/x32-avx512.xml.
     (srv_i386_linux_xmlfiles): Add i386/i386-avx512-linux.xml.
     (srv_amd64_linux_xmlfiles): Add i386/amd64-avx512-linux.xml and
     i386/x32-avx512-linux.xml.
     * i387-fp.c (num_avx512_k_registers): New constant for number
     of K registers.
     (num_avx512_zmmh_low_registers): New constant for number of
     lower ZMM registers (0-15).
     (num_avx512_zmmh_high_registers): New constant for number of
     higher ZMM registers (16-31).
     (num_avx512_ymmh_registers): New contant for number of higher
     YMM registers (ymm16-31 added by avx521 on x86_64).
     (num_avx512_xmm_registers): New constant for number of higher
     XMM registers (xmm16-31 added by AVX512 on x86_64).
     (struct i387_xsave): Add space for AVX512 registers.
     (i387_cache_to_xsave): Change raw buffer size to 64 characters.
     Add code to handle AVX512 registers.
     (i387_xsave_to_cache): Add code to handle AVX512 registers.
     * linux-x86-low.c (init_registers_amd64_avx512_linux): New
     prototypei from generated file.
     (tdesc_amd64_avx512_linux): Likewise.
     (init_registers_x32_avx512_linux): Likewise.
     (tdesc_x32_avx512_linux): Likewise.
     (init_registers_i386_avx512_linux): Likewise.
     (tdesc_i386_avx512_linux): Likewise.
     (x86_64_regmap): Add AVX512 registers.
     (x86_linux_read_description): Add code to handle AVX512 XSTATE
     mask.
     (initialize_low_arch): Add code to initialize AVX512 registers.

doc/
     * gdb.texinfo (i386 Features): Add description of AVX512
     registers.

Change-Id: Ifc4c08c76b85dbec18d02efdbe6182e851584438
Signed-off-by: Michael Sturm <michael.sturm@intel.com>
2014-04-24 16:30:03 +02:00
Pedro Alves 51aa91f979 [gdbserver] mem-break.c:find_gdb_breakpoint_at: Make static.
Nothing calls this outside mem-break.c.

gdb/gdbserver/
2014-04-23  Pedro Alves  <palves@redhat.com>

	* mem-break.c (find_gdb_breakpoint_at): Make static.
	* mem-break.h (find_gdb_breakpoint_at): Delete declaration.
2014-04-23 18:53:36 +01:00
Pedro Alves a4165e94f4 gdbserver: decouple x86 watchpoint / hw breakpoint routines from Z packet numbers.
My main motivation here is moving in the direction of decoupling
insert_point/remove_point from packet numbers, though this bit alone
should make it a little bit easier to merge gdb/gdbserver/i386-low.c
and gdb/i386-nat.c (which are largely the same).

Tested on x86_64 Fedora 17, and cross built for i686-mingw32 too.

gdb/gdbserver/
2014-04-23  Pedro Alves  <palves@redhat.com>

	* i386-low.c: Don't include break-common.h here.
	(i386_low_insert_watchpoint, i386_low_remove_watchpoint): Change
	prototype to take target_hw_bp_type as argument instead of a Z
	packet char.
	* i386-low.h: Include break-common.h here.
	(Z_packet_to_hw_type): Declare.
	(i386_low_insert_watchpoint, i386_low_remove_watchpoint): Change
	prototypes.
	* linux-x86-low.c (x86_insert_point): Convert the packet number to
	a target_hw_bp_type before calling i386_low_insert_watchpoint.
	(x86_remove_point): Convert the packet number to a
	target_hw_bp_type before calling i386_low_remove_watchpoint.
	* win32-i386-low.c (i386_insert_point): Convert the packet number
	to a target_hw_bp_type before calling i386_low_insert_watchpoint.
	(i386_remove_point): Convert the packet number to a
	target_hw_bp_type before calling i386_low_remove_watchpoint.
2014-04-23 18:33:52 +01:00
Pedro Alves b8acf84369 gdbserver: perror_with_name: Add ATTRIBUTE_NORETURN.
perror_with_name doesn't return, but unlike gdb's version, it wasn't
marked that way.

gdb/gdbserver/
2014-04-23  Pedro Alves  <palves@redhat.com>

	* utils.h (perror_with_name): Add ATTRIBUTE_NORETURN.
2014-04-23 17:29:54 +01:00
Pedro Alves d708bcd102 Conditional Z1 breakpoint hangs GDBserver.
While trying to fix hbreak2.exp against GDBserver I noticed this...

 (gdb) hbreak main if 1
 Sending packet: $m400580,40#2e...Packet received: e8d2ffffff5dc3554889e54883ec10c745fc00000000eb0eb800000000e8c1ffffff8345fc01817dfce70300007ee9b800000000c9c3662e0f1f840000000000
 Sending packet: $m40058f,1#31...Packet received: c7
 Hardware assisted breakpoint 1 at 0x40058f: file ../../../src/gdb/testsuite/gdb.base/break-idempotent.c, line 46.
 Sending packet: $Z1,40058f,1;X3,220127#9b...
 *hangs forever*

The issue is that nothing advances the packet pointer if
add_breakpoint_condition either fails to parse the agent expression,
or fails to find the breakpoint, resulting in an infinite loop in
process_point_options.  The latter case should really be fixed by
GDBserver tracking GDB Z1 breakpoints in its breakpoint structures
like Z0 breakpoints are, but the latter case still needs handling.
add_breakpoint_commands has the same issue, though at present I don't
know any way to trigger it other than sending a manually cooked
packet.

Unbelievably, it doesn't look like we have any test that tries setting
a conditional hardware breakpoint.  Looking at cond-eval-mode.exp, it
looks like the file was meant to actually test something, but it's
mostly empty today.  This patch adds tests that tries all sorts of
conditional breakpoints and watchpoints.  The test hangs/fails without
the GDBserver fix.

Tested on x86_64 Fedora 17.

gdb/gdbserver/
2014-04-10  Pedro Alves  <palves@redhat.com>

	* mem-break.c (add_breakpoint_condition, add_breakpoint_commands):
	Check if the condition or command is NULL before checking if the
	breakpoint is known.  On success, return true.
	* mem-break.h (add_breakpoint_condition): Document return.
	(add_breakpoint_commands): Add describing comment.
	* server.c (skip_to_semicolon): New function.
	(process_point_options): Use it.

gdb/testsuite/
2014-04-10  Pedro Alves  <palves@redhat.com>

	* gdb.base/cond-eval-mode.c: New file.
	* gdb.base/cond-eval-mode.exp: Use standard_testfile.  Adjust
	prepare_for_testing to build the new file.  Check result of
	runto_main.
	(test_break, test_watch): New procedures.
	(top level): Use them.
2014-04-10 17:14:12 +01:00
Pedro Alves 2eec7d5ba1 [GDBserver] Fix SH/Linux build.
sh-linux-gnu-gcc (...) src/gdb/gdbserver/linux-low.c
 .../src/gdb/gdbserver/linux-low.c: In function 'linux_read_loadmap':
 .../src/gdb/gdbserver/linux-low.c:5284:13: error: 'struct lwp_info' has no member named 'entry'
 make[1]: *** [linux-low.o] Error 1

gdb/gdbserver/
2014-04-09  Pedro Alves  <palves@redhat.com>

	* linux-low.c (linux_read_loadmap): Pass current_inferior directly
	to lwpid_of.
2014-04-09 16:12:33 +01:00
Pedro Alves fa96cb382c Teach GDBserver's Linux backend about no unwaited-for children (TARGET_WAITKIND_NO_RESUMED).
GDBserver currently hangs forever in waitpid if the leader thread
exits before other threads, or if all resumed threads exit - e.g.,
next over a thread exit with sched-locking on.  This is exposed by
leader-exit.exp.  leader-exit.exp is part of a series of tests for a
set of related problems.  See
<http://www.sourceware.org/ml/gdb-patches/2011-10/msg00704.html>:

 "
 To recap, on the Linux kernel, ptrace/waitpid don't allow reaping the
 leader thread until all other threads in the group are reaped.  When
 the leader exits, it goes zombie, but waitpid will not return an exit
 status until the other threads are gone.  This is presently exercised
 by the gdb.threads/leader-exit.exp test.  The fix for that test, in
 linux-nat.c:wait_lwp, handles the case where we see the leader gone
 when we're stopping all threads to report an event to some other
 thread to the core.

 (...)

 The latter bit about not blocking if there no resumed threads in the
 process also applies to some other thread exiting, not just the main
 thread.  E.g., this test starts a thread, and runs to a breakpoint in
 that thread:

 ...
 (gdb) c
 Continuing.
 [New Thread 0x7ffff75a4700 (LWP 23397)]
 [Switching to Thread 0x7ffff75a4700 (LWP 23397)]

 Breakpoint 2, thread_a (arg=0x0) at ../../../src/gdb/testsuite/gdb.threads/no-unwaited-for-left.c:28
 28        return 0; /* break-here */
 (gdb) info threads
 * 2 Thread 0x7ffff75a4700 (LWP 23397)  thread_a (arg=0x0) at ../../../src/gdb/testsuite/gdb.threads/no-unwaited-for-left.c:28
   1 Thread 0x7ffff7fcb720 (LWP 23391)  0x00007ffff7bc606d in pthread_join (threadid=140737343276800, thread_return=0x0) at pthread_join.c:89

 The thread will exit as soon as we resume it.  But if we only resume
 that thread, leaving the rest of the threads stopped:

 (gdb) set scheduler-locking on
 (gdb) c
 Continuing.
 ^C^C^C^C^C^C^C^C
 "

This patch fixes the issues by implementing TARGET_WAITKIND_NO_RESUMED
on GDBserver, similarly to what the patch above did for native
Linux GDB.

gdb.threads/leader-exit.exp now passes.

gdb.threads/no-unwaited-for-left.exp now at least errors out instead
of hanging:

 continue
 Continuing.
 warning: Remote failure reply: E.No unwaited-for children left.

 [Thread 15454] #1 stopped.
 0x00000034cf408e60 in pthread_join (threadid=140737353922368, thread_return=0x0) at pthread_join.c:93
 93          lll_wait_tid (pd->tid);
 (gdb) FAIL: gdb.threads/no-unwaited-for-left.exp: continue stops when the main thread exits

The gdb.threads/non-ldr-exc-*.exp tests are skipped because GDBserver
unfortunately doesn't support fork/exec yet, but I'm confident this
fixes the related issues.

I'm leaving modeling TARGET_WAITKIND_NO_RESUMED in the RSP for a
separate pass.

(BTW, in case of error in response to a vCont, it would be better for
GDB to query the target for the current thread, or re-select one,
instead of assuming current inferior_ptid is still the selected
thread.)

This implementation is a little different from GDB's, because I'm
avoiding bringing in more of this broken use of waitpid(PID) into
GDBserver.  Specifically, this avoids waitpid(PID) when stopping all
threads.  There's really no need for wait_for_sigstop to wait for each
LWP in turn.  Instead, with some refactoring, we make it reuse
linux_wait_for_event.

gdb/gdbserver/
2014-02-27  Pedro Alves  <palves@redhat.com>

	PR 12702
	* inferiors.h (A_I_NEXT, ALL_INFERIORS_TYPE, ALL_PROCESSES): New
	macros.
	* linux-low.c (delete_lwp, handle_extended_wait): Add debug
	output.
	(last_thread_of_process_p): Take a PID argument instead of a
	thread pointer.
	(linux_wait_for_lwp): Delete.
	(num_lwps, check_zombie_leaders, not_stopped_callback): New
	functions.
	(linux_low_filter_event): New function, party factored out from
	linux_wait_for_event.
	(linux_wait_for_event): Rename to ...
	(linux_wait_for_event_filtered): ... this.  Add new filter ptid
	argument.  Partly rewrite.  Always use waitpid(-1, WNOHANG) and
	sigsuspend.  Check for zombie leaders.
	(linux_wait_for_event): Reimplement as wrapper around
	linux_wait_for_event_filtered.
	(linux_wait_1): Handle TARGET_WAITKIND_NO_RESUMED.  Assume that if
	a normal or signal exit is seen, it's the whole process exiting.
	(wait_for_sigstop): No longer a for_each_inferior callback.
	Rewrite on top of linux_wait_for_event_filtered.
	(stop_all_lwps): Call wait_for_sigstop directly.
	* server.c (resume, handle_target_event): Handle
	TARGET_WAITKIND_NO_RESUMED.
2014-02-27 14:30:08 +00:00
Joel Brobecker d763de106f gdbserver/Windows: Rely purely on event info when handling DLL load event
This is the GDBserver counterpart of a change we recently made in
GDB to only rely on get_image_name to determine its name.

This simplification, in turn, allows us to remove a fair amount of
functions and globals which now become unused.

gdb/gdbserver/ChangeLog:

	* win32-low.c (psapi_get_dll_name,
	* win32_CreateToolhelp32Snapshot): Delete.
	(win32_CreateToolhelp32Snapshot, win32_Module32First)
	(win32_Module32Next, load_toolhelp, toolhelp_get_dll_name):
	Delete.
	(handle_load_dll): Add function description.
	Remove code using psapi_get_dll_name and toolhelp_get_dll_name.
2014-02-26 12:05:18 -08:00
Joel Brobecker 850a0f76c2 windows: Factorize handling of DLL load address offset
This patch is a small cleanup that moves the magic 0x1000 offset
to apply to a DLL's base address inside the win32_add_one_solib
function, rather than delegate that reponsibility to its callers.

gdb/gdbserver/ChangeLog:

	* win32-low.c (win32_add_one_solib): Add 0x1000 to load_addr.
	Add comment.
	(win32_add_all_dlls): Remove 0x1000 offset applied to DLL
	base address when calling win32_add_one_solib.
	(handle_load_dll): Delete local variable load_addr.
	Remove 0x1000 offset applied to DLL base address when calling
	win32_add_one_solib.
	(handle_unload_dll): Add comment.
2014-02-26 12:03:52 -08:00
Joel Brobecker f25b3fc334 gdbserver/windows: Ignore DLL load/unload events during child initialization.
This GDBserver patch mirrors a change made in GDB wich aims at
simplifying DLL handling during the inferior initialization
(process creation during the "run", or during an "attach").
Instead of processing each DLL load event, which is sometimes
incomplete, we ignore these events until the inferior has completed
its startup phase, and then just iterate over all DLLs via
EnumProcessModules.

As a side-effect, it fixes a small bug where win32_ensure_ntdll_loaded
was missing a 0x1000 offset in the DLL base address. This problem
should only be visible on the 64bit version of Windows 8.1, since
this is the only platform where win32_ensure_ntdll_loaded is actually
needed.

gdb/gdbserver/ChangeLog:

	* win32-low.c (win32_add_all_dlls): Renames
	win32_ensure_ntdll_loaded.  Rewrite function documentation.
	Adjust implementation to always load all DLLs.
	Add 0x1000 offset to DLL base address when calling
	win32_add_one_solib.
	(child_initialization_done): New static global.
	(do_initial_child_stuff): Set child_initialization_done to
	zero during child initialization, and 1 after.  Replace call
	to win32_ensure_ntdll_loaded by call to win32_add_all_dlls.
	Add comment.
	(match_dll_by_basename, dll_is_loaded_by_basename): Delete.
	(handle_unload_dll): Add function documentation.
	(get_child_debug_event): Ignore load and unload DLL events
	during child initialization.
2014-02-26 12:02:44 -08:00
Doug Evans 3bc32da325 Add single sentence description to top of entry of previous commit. 2014-02-20 13:33:44 -08:00
Doug Evans d86d4aafd4 Remove all_lwps global.
* inferiors.h (ptid_of): Move here from linux-low.h.
	(pid_of, lwpid_of): Ditto.
	* linux-aarch64-low.c (debug_reg_change_callback): Update, "entry"
	parameter is a struct thread_info * now.
	(aarch64_notify_debug_reg_change): Fetch pid from current_inferior
	directly.  Pass &all_threads to find_inferior instead of &all_lwps.
	(aarch64_stopped_data_address): Fetch lwpid from current_inferior
	directly.
	(aarch64_linux_prepare_to_resume): Fetch ptid from thread.
	(aarch64_arch_setup): Fetch lwpid from current_inferior directly.
	* linux-arm-low.c (update_registers_callback): Update, "entry"
	parameter is a struct thread_info * now.
	Fetch lwpid from current_inferior directly.
	(arm_insert_point): Pass &all_threads to find_inferior instead of
	&all_lwps.
	(arm_remove_point): Ditto.
	(arm_stopped_by_watchpoint): Fetch lwp from current_inferior.
	(arm_prepare_to_resume): Fetch pid from thread.
	(arm_read_description): Fetch lwpid from current_inferior directly.
	* linux-low.c (all_lwps): Delete.
	(delete_lwp): Delete call to remove_inferior.
	(handle_extended_wait): Fetch lwpid from thread.
	(add_lwp): Don't set lwp->entry.id.  Remove call to
	add_inferior_to_list.
	(linux_attach_lwp_1): Fetch pid from current_inferior directly.
	(linux_kill_one_lwp): Fetch ptid,lwpid from thread.
	(kill_one_lwp_callback): Ditto.
	(linux_kill): Don't dereference NULL pointer.
	Fetch ptid,lwpid from thread.
	(get_detach_signal): Fetch ptid from thread.
	(linux_detach_one_lwp): Fetch ptid,lwpid from thread.
	Simplify call to regcache_invalidate_thread.
	(delete_lwp_callback): Update, "entry" parameter is a
	struct thread_info * now.  Fetch pid from thread.
	(linux_mourn): Pass &all_threads to find_inferior instead of &all_lwps.
	(status_pending_p_callback): Update, "entry" parameter is a
	struct thread_info * now.  Fetch ptid from thread.
	(find_lwp_pid): Update, "entry" parameter is a
	struct thread_info * now.
	(linux_wait_for_lwp): Fetch pid from thread.
	(linux_fast_tracepoint_collecting): Fetch lwpid from thread.
	(maybe_move_out_of_jump_pad): Fetch lwpid from current_inferior.
	(enqueue_one_deferred_signal): Fetch lwpid from thread.
	(dequeue_one_deferred_signal): Ditto.
	(cancel_breakpoint): Fetch ptid from current_inferior.
	(linux_wait_for_event): Pass &all_threads to find_inferior,
	not &all_lwps.  Fetch ptid, lwpid from thread.
	(count_events_callback): Update, "entry" parameter is a
	struct thread_info * now.
	(select_singlestep_lwp_callback): Ditto.
	(select_event_lwp_callback): Ditto.
	(cancel_breakpoints_callback): Ditto.
	(linux_cancel_breakpoints): Pass &all_threads to find_inferior,
	not &all_lwps.
	(select_event_lwp): Ditto.  Fetch ptid from event_thread.
	(unsuspend_one_lwp): Update, "entry" parameter is a
	struct thread_info * now.
	(unsuspend_all_lwps): Pass &all_threads to find_inferior,
	not &all_lwps.
	(linux_stabilize_threads): Ditto.  And for for_each_inferior.
	Fetch lwpid from thread, not lwp.
	(linux_wait_1): Fetch ptid, lwpid from current_inferior.
	Pass &all_threads to find_inferior, not &all_lwps.
	(send_sigstop): Fetch lwpid from thread, not lwp.
	(send_sigstop_callback): Update, "entry" parameter is a
	struct thread_info * now.
	(suspend_and_send_sigstop_callback): Ditto.
	(wait_for_sigstop): Ditto.  Fetch ptid, lwpid from thread, lwp.
	(stuck_in_jump_pad_callback): Update, "entry" parameter is a
	struct thread_info * now.
	(move_out_of_jump_pad_callback): Ditto.  Fetch ptid, lwpid
	from thread, lwp.
	(lwp_running): Update, "entry" parameter is a
	struct thread_info * now.
	(stop_all_lwps): Fetch ptid from thread.
	Pass &all_threads to find_inferior, for_each_inferior, not &all_lwps.
	(linux_resume_one_lwp): Fetch lwpid from thread.
	(linux_set_resume_request): Update, "entry" parameter is a
	struct thread_info * now.  Fetch pid, lwpid from thread.
	(resume_status_pending_p): Update, "entry" parameter is a
	struct thread_info * now.
	(need_step_over_p): Ditto.  Fetch lwpid from thread.
	(start_step_over): Fetch lwpid from thread.
	(linux_resume_one_thread): Update, "entry" parameter is a
	struct thread_info * now.  Fetch lwpid from thread.
	(linux_resume): Pass &all_threads to find_inferior, not &all_lwps.
	(proceed_one_lwp): Update, "entry" parameter is a
	struct thread_info * now.  Fetch lwpid from thread.
	(unsuspend_and_proceed_one_lwp): Update, "entry" parameter is a
	struct thread_info * now.
	(proceed_all_lwps): Pass &all_threads to find_inferior, not &all_lwps.
	(unstop_all_lwps): Ditto.  Fetch lwpid from thread.
	(regsets_fetch_inferior_registers): Fetch lwpid from current_inferior
	directly.
	(regsets_store_inferior_registers): Ditto.
	(fetch_register, store_register): Ditto.
	(linux_read_memory, linux_write_memory): Ditto.
	(linux_request_interrupt): Ditto.
	(linux_read_auxv): Ditto.
	(linux_xfer_siginfo): Ditto.
	(linux_qxfer_spu): Ditto.
	(linux_qxfer_libraries_svr4): Ditto.
	* linux-low.h (ptid_of, pid_of, lwpid_of): Delete,
	moved to inferiors.h.
	(get_lwp): Delete.
	(get_thread_lwp): Update.
	(struct lwp_info): Delete member "entry".  Simplify comment for
	member "thread".
	(all_lwps): Delete.
	* linux-mips-low.c (mips_read_description): Fetch lwpid from
	current_inferior directly.
	(update_watch_registers_callback): Update, "entry" parameter is a
	struct thread_info * now.  Fetch pid from thread.
	(mips_linux_prepare_to_resume): Fetch ptid from thread.
	(mips_insert_point): Fetch lwpid from current_inferior.
	Pass &all_threads to find_inferior, not &all_lwps.
	(mips_remove_point): Pass &all_threads to find_inferior, not &all_lwps.
	(mips_stopped_by_watchpoint): Fetch lwpid from current_inferior
	directly.
	(mips_stopped_data_address): Ditto.
	* linux-s390-low.c (s390_arch_setup): Fetch pid from current_inferior
	directly.
	* linux-tile-low.c (tile_arch_setup): Ditto.
	* linux-x86-low.c (x86_get_thread_area): Fetch lwpid from thread.
	(update_debug_registers_callback): Update, "entry" parameter is a
	struct thread_info * now.  Fetch pid from thread.
	(i386_dr_low_set_addr): Fetch pid from current_inferior directly.
	Pass &all_threads to find_inferior, not &all_lwps.
	(i386_dr_low_get_addr): Fetch ptid from current_inferior directly.
	(i386_dr_low_set_control): Fetch pid from current_inferior directly.
	Pass &all_threads to find_inferior, not &all_lwps.
	(i386_dr_low_get_control): Fetch ptid from current_inferior directly.
	(i386_dr_low_get_status): Ditto.
	(x86_linux_prepare_to_resume): Fetch ptid from thread.
	(x86_siginfo_fixup): Fetch lwpid from current_inferior directly.
	(x86_linux_read_description): Ditto.
	* proc-service.c (ps_getpid): Fetch pid from current_inferior directly.
2014-02-20 12:25:18 -08:00
Doug Evans 3b8361aa0f * inferiors.c (get_first_inferior): Fix buglet. 2014-02-20 11:11:34 -08:00
Doug Evans f7667f0de6 Add backlink from lwp_info to thread_info.
* gdbthread.h (add_thread): Change result type to struct thread_info *.
	* inferiors.c (add_thread): Change result type to struct thread_info *.
	All callers updated.
	(add_lwp): Call add_thread here instead of in callers.
	All callers updated.
	* linux-low.h (get_lwp_thread): Rewrite.
	(struct lwp_info): New member "thread".

This speeds up gdbserver attach in non-stop mode because now get_lwp_thread
doesn't do a linear search for the corresponding thread_info object.
2014-02-19 16:38:44 -08:00
Doug Evans b3312d8019 * linux-low.c (add_lwp): Change result to struct lwp_info *.
All callers updated.
2014-02-19 16:22:51 -08:00
Doug Evans ecc6f45c3b * inferiors.c (add_thread): Fix whitespace. 2014-02-19 16:19:10 -08:00
Doug Evans 649ebbcaef Replace code accessing list implementation details with API calls.
* dll.c (clear_dlls): Replace accessing list implemention details
	with API function.
	* gdbthread.h (get_first_thread): Declare.
	* inferiors.c (for_each_inferior_with_data): New function.
	(get_first_thread): New function.
	(find_thread_ptid): Simplify.
	(get_first_inferior): New function.
	(clear_list): Delete.
	(one_inferior_p): New function.
	(clear_inferior_list): New function.
	(clear_inferiors): Update.
	* inferiors.h (for_each_inferior_with_data): Declare.
	(clear_inferior_list): Declare.
	(one_inferior_p): Declare.
	(get_first_inferior): Declare.
	* linux-low.c (linux_wait_for_event): Replace accessing list
	implemention details with API function.
	* server.c (target_running): Ditto.
	(accumulate_file_name_length): New function.
	(emit_dll_description): New function.
	(handle_qxfer_libraries): Replace accessing list implemention
	details with API function.
	(handle_qxfer_threads_worker): New function.
	(handle_qxfer_threads_proper): Replace accessing list implemention
	details with API function.
	(handle_query): Ditto.
	(visit_actioned_threads_callback_ftype): New typedef.
	(visit_actioned_threads_data): New struct.
	(visit_actioned_threads): Rewrite to be find_inferior callback.
	(resume): Call find_inferior.
	(handle_status): Replace accessing list implemention
	details with API function.
	(process_serial_event): Replace accessing list implemention details
	with API function.
	* target.c (set_desired_inferior): Replace accessing list implemention
	details with API function.
	* tracepoint.c (same_process_p): New function.
	(gdb_agent_about_to_close): Replace accessing list implemention
	details with API function.
	* win32-low.c (child_delete_thread): Replace accessing list
	implemention details with API function.
	(match_dll_by_basename): New function.
	(dll_is_loaded_by_basename): New function.
	(win32_ensure_ntdll_loaded): Replace accessing list implemention
	details call to dll_is_loaded_by_basename.
2014-02-19 15:30:38 -08:00
Doug Evans 80894984a6 Rename inferior_list_entry uses from "head" to "entry" for consistency.
* dll.h (struct dll_info): Add comment.
	* gdbthread.h (struct thread_info): Add comment.
	(current_ptid): Simplify.
	* inferiors.c (add_process): Update.
	(remove_process): Update.
	* inferiors.h (struct process_info): Rename member "head" to "entry".
	* linux-low.c (delete_lwp): Update.
	(add_lwp): Update.
	(last_thread_of_process_p): Update.
	(kill_one_lwp_callback, linux_kill): Update.
	(status_pending_p_callback): Update.
	(wait_for_sigstop): Update.  Simplify read of ptid.
	(start_step_over): Update.
	* linux-low.h (ptid_of, pid_of, lwpid_of): Update.
	(get_lwp_thread): Update.
	(struct lwp_info): Rename member "head" to "entry".
	* regcache.h (inferior_list_entry): Delete.
	* server.c (kill_inferior_callback): Update.
	(detach_or_kill_inferior_callback): Update.
	(print_started_pid): Update.
	(print_attached_pid): Update.
	(process_serial_event): Simplify read of ptid.
	* thread-db.c (thread_db_create_event): Update.
	(thread_db_get_tls_address): Update.
	* win32-low.c (current_inferior_ptid): Simplify.
2014-02-19 14:51:55 -08:00
Tom Tromey 46917d26c8 convert to_supports_btrace
This adds a "self" argument to to_supports_btrace.  Due to how one
implementation of this method is shared with gdbserver this required a
small change to gdbserver as well.

2014-02-19  Tom Tromey  <tromey@redhat.com>

	* common/linux-btrace.c (linux_supports_btrace): Add "ops"
	argument.
	* common/linux-btrace.h (linux_supports_btrace): Update.
	* remote.c (remote_supports_btrace): Add "self" argument.
	* target-delegates.c: Rebuild.
	* target.c (target_supports_btrace): Remove.
	* target.h (struct target_ops) <to_supports_btrace>: Add
	target_ops argument.
	(target_supports_btrace): New define.

2014-02-19  Tom Tromey  <tromey@redhat.com>

	* target.h (struct target_ops) <supports_btrace>: Add target_ops
	argument.
	(target_supports_btrace): Update.
2014-02-19 07:45:26 -07:00
Yao Qi 0759a81e85 Compile rsp-low.c for IPA
gdb/gdbserver:

2014-02-14  Yao Qi  <yao@codesourcery.com>

	* Makefile.in (IPA_OBJS): Append rsp-low-ipa.o.
	(rsp-low-ipa.o): New target.
2014-02-14 09:53:51 +08:00
Tom Tromey a7191e8bd7 replace convert_ascii_to_int with hex2bin
convert_ascii_to_int is identical to hex2bin.
This removes the former.

2014-02-12  Tom Tromey  <tromey@redhat.com>

	* common/rsp-low.c (convert_ascii_to_int): Remove.
	* common/rsp-low.h (convert_ascii_to_int): Don't declare.

2014-02-12  Tom Tromey  <tromey@redhat.com>

	* ax.c (gdb_parse_agent_expr): Use hex2bin, not
	convert_ascii_to_int.
	* regcache.c (registers_to_string): Likewise.
	* remote-utils.c (decode_M_packet): Likewise.
	* server.c (process_serial_event): Likewise.
2014-02-12 09:59:20 -07:00
Tom Tromey ff0e980e6f replace unhexify with hex2bin
unhexify and hex2bin are identical, so this removes unhexify.  The
particular choice of which to keep was made on the basis of
parallelism with the earlier patch that removed hexify.

2014-02-12  Tom Tromey  <tromey@redhat.com>

	* common/rsp-low.h (unhexify): Don't declare.
	* common/rsp-low.c (unhexify): Remove.

2014-02-12  Tom Tromey  <tromey@redhat.com>

	* server.c (handle_query, handle_v_run): Use hex2bin, not
	unhexify.
	* tracepoint.c (cmd_qtdpsrc, cmd_qtdv, cmd_qtnotes): Likewise.
2014-02-12 09:59:19 -07:00
Tom Tromey e9371aff2d replace convert_int_to_ascii with bin2hex
convert_int_to_ascii is identical to bin2hex.  This removes the
former.  In this case I made the choice of which to keep on the basis
that I consider the name bin2hex to be superior to
convert_int_to_ascii.

2014-02-12  Tom Tromey  <tromey@redhat.com>

	* common/rsp-low.h (convert_int_to_ascii): Don't declare.
	* common/rsp-low.c (convert_int_to_ascii): Remove.

2014-02-12  Tom Tromey  <tromey@redhat.com>

	* ax.c (gdb_unparse_agent_expr): Use bin2hex, not
	convert_int_to_ascii.
	* regcache.c (registers_to_string, collect_register_as_string):
	Likewise.
	* remote-utils.c (look_up_one_symbol, relocate_instruction):
	Likewise.
	* server.c (process_serial_event): Likewise.
	* tracepoint.c (cmd_qtstatus, response_source, response_tsv)
	(cmd_qtbuffer, cstr_to_hexstr): Likewise.
2014-02-12 09:59:18 -07:00
Tom Tromey 971dc0b89d replace hexify with bin2hex
This removes hexify in favor of bin2hex.
The choice of which to keep was arbitrary.

2014-02-12  Tom Tromey  <tromey@redhat.com>

	* common/rsp-low.h (hexify): Don't declare.
	* common/rsp-low.c (hexify): Remove.

2014-02-12  Tom Tromey  <tromey@redhat.com>

	* remote-utils.c (look_up_one_symbol, monitor_output): Use
	bin2hex, not hexify.
	* tracepoint.c (cmd_qtstatus): Likewise.
2014-02-12 09:59:17 -07:00
Tom Tromey 0a822afbcd don't let hexify call strlen
hexify had the same issue as bin2hex; and the fix is the same.

2014-02-12  Tom Tromey  <tromey@redhat.com>

	* common/rsp-low.c (hexify): Never take strlen of argument.

2014-02-12  Tom Tromey  <tromey@redhat.com>

	* remote-utils.c (monitor_output): Pass explicit length to
	hexify.
2014-02-12 09:59:16 -07:00
Tom Tromey 9c3d65319a move some rsp bits into rsp-low.h
This moves various low-level remote serial protocol bits into
common/rsp-low.[ch].

This is as close to a pure move as possible.  There are some
redundancies remaining but those will be dealt with in a subsequent
patch.

Note that the two variants of remote_escape_output disagreed on the
treatment of "*".  On the theory that quoting cannot hurt but the
absence possibly can, I chose the gdbserver variant to be the
canonical one.

2014-02-12  Tom Tromey  <tromey@redhat.com>

	* tracepoint.c: Include rsp-low.h.
	* remote.h (hex2bin, bin2hex, unpack_varlen_hex): Don't declare.
	* remote.c: Include rsp-low.h.
	(hexchars, ishex, unpack_varlen_hex, pack_nibble, pack_hex_byte)
	(fromhex, hex2bin, tohex, bin2hex, remote_escape_output)
	(remote_unescape_input): Move to common/rsp-low.c.
	* common/rsp-low.h: New file.
	* common/rsp-low.c: New file.
	* Makefile.in (SFILES): Add common/rsp-low.c.
	(HFILES_NO_SRCDIR): Add common/rsp-low.h.
	(COMMON_OBS): Add rsp-low.o.
	(rsp-low.o): New target.

2014-02-12  Tom Tromey  <tromey@redhat.com>

	* tracepoint.c: Include rsp-low.h.
	* server.c: Include rsp-low.h.
	* remote-utils.h (convert_ascii_to_int, convert_int_to_ascii)
	(unhexify, hexify, remote_escape_output, unpack_varlen_hex): Don't
	declare.
	* remote-utils.c: Include rsp-low.h.
	(fromhex, hexchars, ishex, unhexify, tohex, hexify)
	(remote_escape_output, remote_unescape_input, unpack_varlen_hex)
	(convert_int_to_ascii, convert_ascii_to_int): Move to
	common/rsp-low.c.
	* regcache.c: Include rsp-low.h.
	* ax.c: Include rsp-low.h.
	* Makefile.in (SFILES): Add common/rsp-low.c.
	(OBS): Add rsp-low.o.
	(rsp-low.o): New target.
2014-02-12 09:59:14 -07:00
Tom Tromey 01fd3ea573 share "cell" code
The "cell"-based printing code, like phex, was duplicated in both gdb
and gdbserver.  This patch merges the two implementations into a new
file in common/.

2014-02-12  Tom Tromey  <tromey@redhat.com>

	* utils.h: Include print-utils.h.
	(host_address_to_string, plongest, pulongest, phex, phex_nz)
	(int_string, core_addr_to_string, core_addr_to_string_nz)
	(hex_string, hex_string_custom): Don't declare.
	* utils.c (NUMCELLS, CELLSIZE, get_cell, decimal2str, pulongest)
	(plongest, thirty_two, phex, phex_nz, octal2str, hex_string)
	(hex_string_custom, int_string, core_addr_to_string)
	(core_addr_to_string_nz, host_address_to_string): Move to
	common/print-utils.c.
	* common/print-utils.h: New file.
	* common/print-utils.c: New file
	* Makefile.in (SFILES): Add common/print-utils.c.
	(HFILES_NO_SRCDIR): Add common/print-utils.h.
	(COMMON_OBS): Add print-utils.o.
	(print-utils.o): New target.

2014-02-12  Tom Tromey  <tromey@redhat.com>

	* utils.h (pulongest, plongest, phex_nz): Don't declare.
	Include print-utils.h.
	* utils.c (NUMCELLS, CELLSIZE, get_cell, decimal2str, pulongest)
	(plongest, thirty_two, phex_nz): Remove.
	* Makefile.in (SFILES): Add common/print-utils.c.
	(OBS): Add print-utils.o.
	(print-utils-ipa.o): New target.
	(print-utils.o): New target.
	(IPA_OBJS): Add print-utils-ipa.o.
2014-02-12 09:59:13 -07:00
Tom Tromey e99dc82053 indentation fixlet in gdbserver/Makefile.in.
This fixes a minor indentation issue in gdbserver/Makefile.in.

2014-02-06  Tom Tromey  <tromey@redhat.com>

	* Makefile.in (SFILES): Fix indentation.
2014-02-06 12:04:50 -07:00
Doug Evans ee1e2d4fb6 Keep current_inferior in sync with event_child.
* linux-low.c (linux_wait_for_event): Improve comment.
	(linux_wait_1): Keep current_inferior in sync with event_child.
2014-02-05 16:08:59 -08:00
Doug Evans f5a0277332 * gdbthread.h (gdb_id_to_thread): Delete, unused. 2014-01-22 16:42:07 -08:00
Doug Evans 87ce2a04c5 New gdbserver option --debug-format=timestamp.
* NEWS: Mention it.

	gdbserver/
	* configure.ac (AC_CHECK_FUNCS): Add test for gettimeofday.
	* configure: Regenerate.
	* config.in: Regenerate.
	* Makefile.in (SFILES): Add debug.c.
	(OBS): Add debug.o.
	* debug.c: New file.
	* debug.h: New file.
	* linux-aarch64-low.c (*): Update all debugging printfs to use
	debug_printf instead of fprintf.
	* linux-arm-low.c (*): Ditto.
	* linux-cris-low.c (*): Ditto.
	* linux-crisv32-low.c (*): Ditto.
	* linux-m32r-low.c (*): Ditto.
	* linux-sparc-low.c (*): Ditto.
	* linux-x86.c (*): Ditto.
	* linux-low.c (*): Ditto.
	(linux_wait_1): Add calls to debug_enter, debug_exit.
	(linux_wait): Remove redundant debugging printf.
	(stop_all_lwps): Add calls to debug_enter, debug_exit.
	(linux_resume, unstop_all_lwps): Ditto.
	* mem-break.c (*): Update all debugging printfs to use
	debug_printf instead of fprintf.
	* remote-utils.c (*): Ditto.
	* thread-db.c (*): Ditto.
	* server.c #include <ctype.h>, "gdb_vecs.h".
	(debug_threads): Moved to debug.c.
	(*): Update all debugging printfs to use debug_printf instead of
	fprintf.
	(start_inferior): Replace call to fflush with call to debug_flush.
	(monitor_show_help): Mention set debug-format.
	(parse_debug_format_options): New function.
	(handle_monitor_command): Handle "monitor set debug-format".
	(gdbserver_usage): Mention --debug-format.
	(main): Parse --debug-format.
	* server.h (debug_threads): Declaration moved to debug.h.
	#include "debug.h".
	* tracepoint.c (trace_debug_1) [!IN_PROCESS_AGENT]: Add version of
	trace_debug_1 that uses debug_printf.
	(tracepoint_look_up_symbols): Update all debugging printfs to use
	debug_printf instead of fprintf.

	doc/
	* gdb.texinfo (Server): Mention --debug-format=all|none|timestamp.
	(gdbserver man): Ditto.

	testsuite/
	* gdb.server/server-mon.exp: Add tests for "set debug-format".
2014-01-22 14:17:39 -08:00
Baruch Siach e671835b7a gdb: xtensa: fix linux ptrace includes
Currently, xtensa code using the Linux ptrace interface only include
sys/ptrace.h.  This file comes from the C library (glibc and uClibc,
at least), and includes a declaration of the ptrace() functions, along
with some cross architecture constants that are mostly copied from the
file located at include/uapi/linux/ptrace.h in recent Linux kernels.

For xtensa specific constants like PTRACE_GETXTREGS and
PTRACE_SETXTREGS the asm/ptrace.h include from the Linux kernel UAPI
is needed.  The code in gdbserver xtensa specific part doesn't call
ptrace() directly, so we can remove the unneeded sys/ptrace.h include.
The gdb xtensa specific code needs both headers, since it calls
ptrace().

gdb/
	* xtensa-linux-nat.c: Include asm/ptrace.h.

gdb/gdbserver/
	* linux-xtensa-low.c: Include asm/ptrace.h instead of
	sys/ptrace.h.
2014-01-20 11:43:44 +00:00
Pedro Alves ea38d2a92e Fix PR mention in gdb/gdbserver/ChangeLog's previous change. 2014-01-17 16:28:38 +00:00
Pedro Alves c7faa97a85 Fix silly ChangeLog entry in previous change. 2014-01-17 15:27:43 +00:00
Pedro Alves b5737fa98a Fix PR PR16445 - gdbserver build failure on x86.
If gdb_proc_service.h ends up including linux/elf.h, we'll trip on
duplicate definitions:

 In file included from ../../../gdb/gdbserver/linux-x86-low.c:29:0:
 ../../../gdb/gdbserver/../../include/elf/common.h:36:0: error: "ELFMAG0"
                 redefined [-Werror]
 ... etc ...

Handle this the same way linux-low.c and linux-arm-low.c handle this.

gdb/gdbserver/
2014-01-17  Pedro Alves  <palves@redhat.com>

	PR PR16445
	* linux-x86-low.c (linux-x86-low.c): Don't include elf/common.h if
	ELFMAG0 is defined after including gdb_proc_service.h.
2014-01-17 13:33:30 +00:00
Doug Evans 40ed484e74 * dll.c (UNSPECIFIED_CORE_ADDR): New macro.
(match_dll): Use it.
2014-01-16 15:47:43 -08:00
Markus Metzger 969c39fbcd btrace, gdbserver: read branch trace incrementally
Read branch trace data incrementally and extend the current trace rather than
discarding it and reading the entire trace buffer each time.

If the branch trace buffer overflowed, we can't extend the current trace so we
discard it and start anew by reading the entire branch trace buffer.

2014-01-16  Markus Metzger  <markus.t.metzger@intel.com>

	* common/linux-btrace.c (perf_event_read_bts, linux_read_btrace):
	Support delta reads.
	(linux_disable_btrace): Change return type.
	* common/linux-btrace.h (linux_read_btrace): Change parameters
	and return type to allow error reporting.  Update users.
	(linux_disable_btrace): Change return type.  Update users.
	* common/btrace-common.h (btrace_read_type) <BTRACE_READ_DELTA>:
	New.
	(btrace_error): New.
	(btrace_block) <begin>: Comment on BEGIN == 0.
	* btrace.c (btrace_compute_ftrace): Start from the end of
	the current trace.
	(btrace_stitch_trace, btrace_clear_history): New.
	(btrace_fetch): Read delta trace, return if replaying.
	(btrace_clear): Move clear history code to btrace_clear_history.
	(parse_xml_btrace): Throw an error if parsing failed.
	* target.h (struct target_ops) <to_read_btrace>: Change parameters
	and return type to allow error reporting.
	(target_read_btrace): Change parameters and return type to allow
	error reporting.
	* target.c (target_read_btrace): Update.
	* remote.c (remote_read_btrace): Support delta reads.  Pass
	errors on.
	* NEWS: Announce it.

gdbserver/
	* target.h (target_ops) <read_btrace>: Change parameters and
	return type to allow error reporting.
	* server.c (handle_qxfer_btrace): Support delta reads.  Pass
	trace reading errors on.
	* linux-low.c (linux_low_read_btrace): Pass trace reading
	errors on.
	(linux_low_disable_btrace): New.
2014-01-16 13:11:42 +01:00
Markus Metzger 864089d2f6 btrace: uppercase btrace_read_type
2014-01-16  Markus Metzger  <markus.t.metzger@intel.com>

	* common/btrace-common.h (btrace_read_type) <btrace_read_all>:
	Change to ...
	(btrace_read_type) <BTRACE_READ_ALL>: ... this.  Update users.
	(btrace_read_type) <btrace_read_new>: Change to ...
	(btrace_read_type) <BTRACE_READ_NEW>: ... this.  Update users.
2014-01-16 12:45:10 +01:00
Doug Evans ab7f45ba10 delete thread_id_to_gdb_id, unused
* inferiors.c (thread_id_to_gdb_id): Delete.
	* inferiors.h (thread_id_to_gdb_id): Delete.
2014-01-15 16:35:37 -08:00
Eli Zaretskii 66af0f440b Fix MinGW compilation errors in gdbserver/.
gdb/gdbserver/Makefile.in (INCLUDE_CFLAGS): Remove trailing slash from
"-I$(srcdir)/../".  Fixes MinGW compilation errors with old GCC versions.
2014-01-13 20:54:47 +02:00
Pedro Alves 9939e1314f GDBserver: Discard previous queued events when GDB disconnects.
... not when a new GDB connection sends the status packet ('?').
Mainly just a cleanup/simplification, as GDB always sends '?' first.

Tested on x86_64 Fedora 17.

2014-01-08  Pedro Alves  <palves@redhat.com>

	* server.c (handle_status): Don't discard previous queued stop
	replies or thread's pending status here.
	(main) <disconnection>: Do it here instead.
2014-01-08 20:34:26 +00:00
Pedro Alves b7ea362b02 [remote/gdbserver] Don't lose signals when reconnecting.
Currently, when GDB connects in all-stop mode, GDBserver always
responds to the status packet with a GDB_SIGNAL_TRAP, even if the
program is actually stopped for some other signal.

 (gdb) tar rem ...
 ...
 (gdb) c
 Program received signal SIGUSR1, User defined signal 1.
 (gdb) disconnect
 (gdb) tar rem ...
 (gdb) c

(Or a GDB crash instead of an explicit disconnect.)

This results in the program losing that signal on that last continue,
because gdb will tell the target to resume with no signal (to suppress
the GDB_SIGNAL_TRAP, due to 'handle SISGTRAP nopass'), and that will
actually suppress the real signal the program had stopped for
(SIGUSR1).  To fix that, I think we should make GDBserver report the
real signal the thread had stopped for in response to the status
packet:

 @item ?
 @cindex @samp{?} packet
 Indicate the reason the target halted.  The reply is the same as for
 step and continue.

But, that raises the question -- which thread are we reporting the
status for?  Due to how the RSP in all-stop works, we can only report
one status.  The status packet's response is a stop reply packet, so
it includes the thread identifier, so it's not a problem packet-wise.
However, GDBserver is currently always reporting the status for first
thread in the thread list, even though that may well not be the thread
that got the signal that caused the program to stop.  So the next
logical step would be to report the status for the
last_ptid/last_status thread (the last event reported to gdb), if it's
still around; and if not, fallback to some other thread.

There's an issue on the GDB side with that, though...

GDB currently always adds the thread reported in response to the
status query as the first thread in its list.  That means that if we
start with e.g.,

 (gdb) info threads
   3 Thread 1003 ...
 * 2 Thread 1002 ...
   1 Thread 1001 ...

And reconnect:

 (gdb) disconnect
 (gdb) tar rem ...

We end up with:

 (gdb) info threads
   3 Thread 1003 ...
   2 Thread 1001 ...
 * 1 Thread 1002 ...

Not a real big issue, but it's reasonably fixable, by having GDB
fetch/sync the thread list before fetching the status/'?', and then
using the status to select the right thread as current on the GDB
side.  Holes in the thread numbers are squashed before/after
reconnection (e.g., 2,3,5 becomes 1,2,3), but the order is preserved,
which I think is both good, and good enough.

However (yes, there's more...), the previous GDB that was connected
might have had gdbserver running in non-stop mode, or could have left
gdbserver doing disconnected tracing (which also forces non-stop), and
if the new gdb/connection is in all-stop mode, we can end up with more
than one thread with a signal to report back to gdb.  As we can only
report one thread/status (in the all-stop RSP variant; the non-stop
variant doesn't have this issue), we get to do what we do at every
other place we have this situation -- leave events we can't report
right now as pending, so that the next resume picks them up.

Note all this ammounts to a QoI change, within the existing framework.
There's really no RSP change here.

The only user visible change (other than that the signal is program is
stopped at isn't lost / is passed to the program), is in "info
program", that now can show the signal the program stopped for.  Of
course, the next resume will respect the pass/nopass setting for the
signal in question.  It'd be reasonable to have the initial connection
tell the user the program was stopped with a signal, similar to when
we load a core to debug, but I'm leaving that out for a future change.
I think we'll need to either change how handle_inferior_event & co
handle stop_soon, or maybe bypass them completely (like
fork-child.c:startup_inferior) for that.

Tested on x86_64 Fedora 17.

gdb/gdbserver/
2014-01-08  Pedro Alves  <palves@redhat.com>

	* gdbthread.h (struct thread_info) <status_pending_p>: New field.
	* server.c (visit_actioned_threads, handle_pending_status): New
	function.
	(handle_v_cont): Factor out parts to ...
	(resume): ... this new function.  If in all-stop, and a thread
	being resumed has a pending status, report it without actually
	resuming.
	(myresume): Adjust to use the new 'resume' function.
	(clear_pending_status_callback, set_pending_status_callback)
	(find_status_pending_thread_callback): New functions.
	(handle_status): Handle the case of multiple threads having
	interesting statuses to report.  Report threads' real last signal
	instead of always reporting GDB_SIGNAL_TRAP.  Look for a thread
	with an interesting thread to report the status for, instead of
	always reporting the status of the first thread.

gdb/
2014-01-08  Pedro Alves  <palves@redhat.com>

	* remote.c (remote_add_thread): Add threads silently if starting
	up.
	(remote_notice_new_inferior): If in all-stop, and starting up,
	don't call notice_new_inferior.
	(get_current_thread): New function, factored out from ...
	(add_current_inferior_and_thread): ... this.  Adjust.
	(remote_start_remote) <all-stop>: Fetch the thread list.  If we
	found any thread, then select the remote's current thread as GDB's
	current thread too.

gdb/testsuite/
2014-01-08  Pedro Alves  <palves@redhat.com>

	* gdb.threads/reconnect-signal.c: New file.
	* gdb.threads/reconnect-signal.exp: New file.
2014-01-08 18:55:51 +00:00
Joel Brobecker ecd75fc8ee Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00