Commit Graph

38145 Commits

Author SHA1 Message Date
Pedro Alves e5ca03b41d Fix PR gdb/20295: GDB segfaults printing bitfield member of optimized out value
With something like:

  struct A { int bitfield:4; } var;

If 'var' ends up wholly-optimized out, printing 'var.bitfield' crashes
gdb here:

 (top-gdb) bt
 #0  0x000000000058b89f in extract_unsigned_integer (addr=0x2 <error: Cannot access memory at address 0x2>, len=2, byte_order=BFD_ENDIAN_LITTLE)
     at /home/pedro/gdb/mygit/src/gdb/findvar.c:109
 #1  0x00000000005a187a in unpack_bits_as_long (field_type=0x16cff70, valaddr=0x0, bitpos=16, bitsize=12) at /home/pedro/gdb/mygit/src/gdb/value.c:3347
 #2  0x00000000005a1b9d in unpack_value_bitfield (dest_val=0x1b5d9d0, bitpos=16, bitsize=12, valaddr=0x0, embedded_offset=0, val=0x1b5d8d0)
     at /home/pedro/gdb/mygit/src/gdb/value.c:3441
 #3  0x00000000005a2a5f in value_fetch_lazy (val=0x1b5d9d0) at /home/pedro/gdb/mygit/src/gdb/value.c:3958
 #4  0x00000000005a10a7 in value_primitive_field (arg1=0x1b5d8d0, offset=0, fieldno=0, arg_type=0x16d04c0) at /home/pedro/gdb/mygit/src/gdb/value.c:3161
 #5  0x00000000005b01e5 in do_search_struct_field (name=0x1727c60 "bitfield", arg1=0x1b5d8d0, offset=0, type=0x16d04c0, looking_for_baseclass=0, result_ptr=0x7fffffffcaf8,
 [...]

unpack_value_bitfield is already optimized-out/unavailable -aware:

   (...) VALADDR points to the contents of VAL.  If the VAL's contents
   required to extract the bitfield from are unavailable/optimized
   out, DEST_VAL is correspondingly marked unavailable/optimized out.

however, it is not considering the case of the value having no
contents buffer at all, as can happen through
allocate_optimized_out_value.

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

	* value.c (unpack_value_bitfield): Skip unpacking if the parent
	has no contents buffer to begin with.

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

	* gdb.dwarf2/bitfield-parent-optimized-out.exp: New file.
2016-08-09 12:04:48 +01:00
Pedro Alves 6a17ca318b Regenerate some target description files
I regenerated all target description .c files from scratch, and got
this spurious diff.

It's a simple mid-air collision - these files were clearly generated
before commit 73b4f516a0 ("maint_print_c_tdesc_cmd: Use type for
TYPE_CODE_FLAGS instead of field_type."), which did the global
s/field_type/type/, and pushed to master afterwards.

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

	* features/i386/amd64-avx-mpx-linux.c: Regenerate.
	* features/i386/amd64-avx-mpx.c: Regenerate.
	* features/i386/i386-avx-mpx-linux.c: Regenerate.
	* features/i386/i386-avx-mpx.c: Regenerate.
2016-08-08 15:09:46 +01:00
Simon Marchi c632e428c2 Remove unused cli_command_loop declaration
This declaration is not used anymore.

gdb/ChangeLog:

	* event-top.h (cli_command_loop): Remove.
2016-08-05 16:26:18 -04:00
Pedro Alves 3906a8fc77 Fix PR remote/20398: File-IO write always outputs "Quit"
Commit bb7c96deb1 ("gdb/remote-fileio.c: Eliminate custom SIGINT
signal handler") regressed the File-IO support.

Failed output:

  (gdb) target remote :8888
  Remote debugging using :8888
  0x00008098 in _start ()
  (gdb) c
  Continuing.
  Quit
  Quit
  Quit
  Quit
  Quit
  Quit
  Quit
  Quit
  Quit
  Quit
  Quit
  [Inferior 1 (Remote target) exited normally]

Expected output:

  (gdb) target remote :8888
  Remote debugging using :8888
  0x00008098 in _start ()
  (gdb) c
  Continuing.
  i: 0
  i: 1
  i: 2
  i: 3
  i: 4
  i: 5
  i: 6
  i: 7
  i: 8
  i: 9
  [Inferior 1 (Remote target) exited normally]

The problem that the new File-IO quit handler forgets to check the
quit flag before calling throwing a quit.

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

	PR remote/20398
	* remote-fileio.c (remote_fileio_quit_handler): Check the quit
	flag before calling quit.
2016-08-05 19:54:11 +01:00
Pedro Alves 69ffd7f270 gdb/NEWS: Mention that C++ is now the default
gdb/ChangeLog:
2016-08-05  Pedro Alves  <palves@redhat.com>

	* NEWS: Mention that GDB and GDBserver build with a C++ compiler
	by default.
2016-08-05 17:09:31 +01:00
Pedro Alves 1baf514936 gdb/configure --help: suggest --disable-build-with-cxx instead of --enable...
We build by default with a C++ compiler, but "configure --help" still
says "--enable-build-with-cxx", which hints that it is by default
disabled.  Update the --help text.

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

	* build-with-cxx.m4: Change help string to be in terms of
	--disable-build-with-cxx.
	* configure: Regenerate.

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

	* configure: Regenerate.
2016-08-05 16:54:29 +01:00
Yao Qi 6f67973b42 Determine target description for native aarch64
I find the following test fail when I test native aarch64 gdb with
arm program,

(gdb) PASS: gdb.base/attach-pie-noexec.exp: attach
set architecture arm^M
warning: Selected architecture arm is not compatible with reported target architecture aarch64^M
Architecture `arm' not recognized.^M
The target architecture is set automatically (currently aarch64)^M
(gdb) FAIL: gdb.base/attach-pie-noexec.exp: set architecture arm

GDB thinks the target is aarch64, but it isn't.  Nowadays, we are
using some entries AT_PHENT and AT_HWCAP in auxv to determine whether
the process is a 32-bit arm one or 64-bit aarch64 one, and get the
right gdbarch.  However, in the process of parsing auxv (in
inf_ptrace_auxv_parse), the size of int and data pointer of
target_gdbarch is used.  If debug program exists (in most of cases),
target_gdbarch is already set according to the debug program, which
is arm in my case.  Then, GDB can parse auxv successfully.  However,
in gdb.base/attach-pie-noexec.exp, the debug program is removed,
target_gdbarch is aarch64 when GDB parse auxv, so GDB can't parse
it successfully.

Instead of using auxv, we check the return value of ptrace NT_ARM_VFP.
If the program is an arm process, NT_ARM_VFP is OK, otherwise, error
is returned.

Additionally, we only return tdesc_arm_with_neon for arm process,
because neon is mandatory on ARMv8.

gdb:

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

	* aarch64-linux-nat.c (tdesc_arm_with_vfpv3): Remove the
	declaration.
	(aarch64_linux_read_description): Remove code on getting
	auxv and select target description on it.  Select target
	description by the result of NT_ARM_VFP ptrace request.
2016-08-04 11:39:19 +01:00
Yao Qi fcd4a73d7d Quiet ptrace error ESRCH in regsets_fetch_inferior_registers
When I run process-dies-while-detaching.exp with GDBserver, I see many
warnings printed by GDBserver,

ptrace(regsets_fetch_inferior_registers) PID=26183: No such process
ptrace(regsets_fetch_inferior_registers) PID=26183: No such process
ptrace(regsets_fetch_inferior_registers) PID=26184: No such process
ptrace(regsets_fetch_inferior_registers) PID=26184: No such process

regsets_fetch_inferior_registers is called when GDBserver resumes each
lwp.

 #2  0x0000000000428260 in regsets_fetch_inferior_registers (regsets_info=0x4690d0 <aarch64_regsets_info>, regcache=0x31832020)
    at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:5412
 #3  0x00000000004070e8 in get_thread_regcache (thread=0x31832940, fetch=fetch@entry=1) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/regcache.c:58
 #4  0x0000000000429c40 in linux_resume_one_lwp_throw (info=<optimized out>, signal=0, step=0, lwp=0x31832830)
    at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:4463
 #5  linux_resume_one_lwp (lwp=0x31832830, step=<optimized out>, signal=<optimized out>, info=<optimized out>)
    at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:4573

The is the case that threads are disappeared when GDB/GDBserver resumes
them.  We check errno for ESRCH, and don't print error messages, like
what we are doing in regsets_store_inferior_registers.

gdb/gdbserver:

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

	* linux-low.c (regsets_fetch_inferior_registers): Check
	errno is ESRCH or not.
2016-08-04 10:44:18 +01:00
Tom Tromey 282a0691a7 PR python/18565 - make Frame.function work for inline frames
PR python/18565 notes that calling frame filters don't work properly for
inlined functions.  This happens because Frame.function on an inline
frame will yield the wrong result.  This patch changes this code to use
find_frame_funname instead, which handles inline frames properly.

Built and regtested on x86-64 Fedora 24.

2016-08-03  Tom Tromey  <tom@tromey.com>

	PR python/18565:
	* python/py-frame.c (frapy_function): Use find_frame_funname.

2016-08-03  Tom Tromey  <tom@tromey.com>

	PR python/18565:
	* gdb.python/py-frame-inline.exp: Add Frame.function test.
2016-08-03 09:04:08 -06:00
Tom Tromey d10153cfc6 Avoid potential memory leak in find_frame_funname
The PR 18565 thread pointed out that, if cp_remove_params can throw
(we aren't quite sure), then find_frame_funname could leak some
memory.  This patch avoids any potential issue by rearranging some
code in find_frame_funname.

Built and regtested on x86-64 Fedora 24.

2016-08-03  Tom Tromey  <tom@tromey.com>

	* stack.c (find_frame_funname): Avoid any possible leak in case
	cp_remove_params can throw.
2016-08-03 09:04:08 -06:00
Tom Tromey 8d2a0a14e5 Update NEWS to mention Python breakpoint events
An earlier patch added three new breakpoint-related events to the
Python API.  However, at that time, I forgot to update NEWS.  This
patch supplies the missing entry.

2016-08-03  Tom Tromey  <tom@tromey.com>

	* NEWS: Mention new Python breakpoint events.
2016-08-03 08:14:23 -06:00
Tom Tromey 33541b2e56 Add myself as Rust maintainer
A while ago, Pedro announced that I would be the Rust maintainer for
gdb.  However, I neglected to update the MAINTAINERS file until now.

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

	* MAINTAINERS (Core): Add self as Rust maintainer.
2016-08-02 16:58:37 -06:00
Yao Qi 979659d084 [GDBserver] Remove td_ta_event_addr td_ta_set_event and td_ta_event_getmsg
As a result of this commit,

  9b4c5f878f
  (Remove support for thread events without PTRACE_EVENT_CLONE in GDBServer.)

the last usage of td_ta_event_addr td_ta_set_event and
td_ta_event_getmsg were removed.  They are no longer used.  This patch
is to remove them.

gdb/gdbserver:

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

	* thread-db.c (struct thread_db) <td_ta_event_getmsg_p>: Remove.
	<td_ta_set_event_p, td_ta_event_addr_p>: Remove.
	(thread_db_load_search): Update.
	(try_thread_db_load_1): Don't look for td_ta_event_addr,
	td_ta_set_event and td_ta_event_getmsg.
2016-08-02 16:04:09 +01:00
Joel Brobecker 751b375e01 Update NEWS post GDB 7.12 branch creation.
gdb/ChangeLog:

	* NEWS: Create a new section for the next release branch.
	Rename the section of the current branch, now that it has
	been cut.
2016-08-01 08:28:26 -07:00
Joel Brobecker b2bd7787d3 Bump version to 7.12.50.DATE-git.
Now that the GDB 7.12 branch has been created, we can
bump the version number.

gdb/ChangeLog:

	GDB 7.12 branch created (41bfcd638a):
	* version.in: Bump version to 7.12.50.DATE-git.
2016-08-01 08:23:20 -07:00
Yao Qi 41bfcd638a Swap "single-process" and "multi-process" in process-dies-while-detaching.exp
"single-process" and "multi-process" are used in the test message of
process-dies-while-detaching.exp, but they are misplaced due to

    set mode [expr {$multi_process ? "single-process" : "multi-process"}]

This patch is to swap them.

gdb/testsuite:

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

	* gdb.threads/process-dies-while-detaching.exp (do_test): Set
	variable mode to "multi-process" if $multi_process is 1, otherwise
	set it to "single-process".
2016-08-01 10:00:31 +01:00
Yao Qi e3465b24a2 Tweak gdb.cp tests for aarch32
There are some gdb.cp/ tests fails if the program is compiled for arm
32-bit but GDB/GDBserver is aarch64 64-bit program, because target triplet
doesn't match "arm*-*-*".  Instead, we can use is_aarch32_target.

gdb/testsuite:

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

	* gdb.cp/anon-struct.exp: Check is_aarch32_target.
	* gdb.cp/cpexprs.exp: Likewise.
	* gdb.cp/m-static.exp: Likewise.
2016-08-01 09:32:06 +01:00
Alan Modra 293acfae4e Wean gdb and sim off private libbfd.h header
The major reason this header was needed, bfd_default_set_arch_mach,
has now moved to bfd.h.

gdb/
	* amd64-darwin-tdep.c: Don't include libbfd.h.
	* i386-darwin-tdep.c: Likewise.
	* rs6000-nat.c: Likewise.
	* rs6000-tdep.c: Likewise.
sim/aarch64/
	* memory.c: Don't include libbfd.h.
sim/rl78/
	* load.c: Don't include libbfd.h.
	(rl78_load): Don't use private iovec seek or read.
sim/rx/
	* load.c: Don't include libbfd.h.
	(rx_load): Don't use private iovec seek or read.
2016-07-27 09:01:45 +09:30
Pedro Alves 6598661d14 Fix PR server/20414 - x32 gdbserver always crashes inferior
Debugging an x32 process with an x32 gdbserver always results in:

 (gdb) c
 Continuing.

 Program received signal SIGSEGV, Segmentation fault.
 0xf7de9600 in _dl_debug_state () from target:/libx32/ld-linux-x32.so.2
 (gdb)

Looking at the remote debug logs reveals the problem, here:

  Packet received: T05swbreak:;06:a0d4ffff00000000;07:b8d3ffff00000000;10:0096def701000000;thread:p7d7a.7d7a;core:1;
                                                                          ^^^^^^^^^^^^^^^^

The underlined value is the expedited value of RIP (in little endian).
But notice that 01 in 0x01f7de9600, while gdb says the program stopped
at 0xf7de9600.  0x01ffffffff is over 32 bits, which indicates that
something wen't wrong somewhere in gdbserver.

The problem turns out to be in gdbserver's x86_get_pc / x86_set_pc
routines, where "unsigned long" is used assuming that it can fit a
64-bit value, while unsigned long is actually 32-bit on x32.  The
result is that collect_register_by_name / supply_register_by_name end
up reading/writing random bytes off the stack.

Fix this by using explicit uint64_t instead of unsigned long.
For consistency, use uint32_t instead of unsigned int in the 32-bit
paths.

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

	PR server/20414
	* linux-x86-low.c (x86_get_pc, x86_set_pc): Use uint64_t instead
	of unsigned long for 64-bit registers and use uint32_t instead of
	unsigned int for 32-bit registers.
2016-07-26 22:21:27 +01:00
Tom Tromey 0b31a4bcec PR python/20190 - compute TLS symbol without a frame
PR python/20190 arose from an exception I noticed when trying to use
the Python unwinder for Spider Monkey in Firefox.

The problem is that the unwinder wants to examine the value of a
thread-local variable.  However, sympy_value rejects this because
symbol_read_needs_frame returns true for a TLS variable.

This problem arose once before, though in a different context:

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

At the time Pedro and Daniel pointed out a simpler way to fix that bug
(see links in 20190 if you are interested); but for this new bug I
couldn't think of a similar fix and ended up implementing Daniel's
other suggestion:

https://sourceware.org/ml/gdb-patches/2010-07/msg00393.html

That is, this patch makes it possible to detect whether a symbol needs
a specific frame, or whether it just needs the inferior to have
registers.

Built and regtested on x86-64 Fedora 24.

2016-07-26  Tom Tromey  <tom@tromey.com>

	* symtab.c (register_symbol_computed_impl): Update.
	PR python/20190:
	* value.h (symbol_read_needs): Declare.
	(symbol_read_needs_frame): Add comment.
	* symtab.h (struct symbol_computed_ops) <read_variable>: Update
	comment.
	<get_symbol_read_needs>: Rename.  Change return type.
	* findvar.c (symbol_read_needs): New function.
	(symbol_read_needs_frame): Rewrite.
	(default_read_var_value): Use symbol_read_needs.
	* dwarf2loc.c (struct symbol_needs_baton): Rename.
	<needs>: Renamed from needs_frame.  Changed type.
	(needs_frame_read_addr_from_reg, symbol_needs_get_reg_value)
	(symbol_needs_read_mem, symbol_needs_frame_base)
	(symbol_needs_frame_cfa, symbol_needs_tls_address)
	(symbol_needs_dwarf_call): Rename.
	(needs_dwarf_reg_entry_value): Update.
	(symbol_needs_ctx_funcs, dwarf2_loc_desc_get_symbol_read_needs):
	Rename and update.
	(locexpr_get_symbol_read_needs, loclist_symbol_needs): Likewise.
	(dwarf2_locexpr_funcs, dwarf2_loclist_funcs): Update.
	* defs.h (enum symbol_needs_kind): New.

2016-07-26  Tom Tromey  <tom@tromey.com>

	PR python/20190:
	* gdb.threads/tls.exp (check_thread_local): Add python symbol
	test.
2016-07-26 13:43:27 -06:00
Pedro Alves 40c31709c6 Fix PR gdb/20413 - x32: linux_ptrace_test_ret_to_nx: Cannot PTRACE_PEEKUSER
An x32 gdb always issues this warning:

 (gdb) start
 Temporary breakpoint 1 at 0x4043e9: file foo.c, line 25.
 Starting program: a.out
 warning: linux_ptrace_test_ret_to_nx: Cannot PTRACE_PEEKUSER: Input/output error

 Temporary breakpoint 1, main (argc=1, argv=0xffffd544) at foo.c:25
 25      {
 (gdb)

As described in Linux commit 55283e253771 (x32: Add ptrace for x32):

    [...] PTRACE_PEEKUSR and PTRACE_POKEUSR are only allowed to access
    segment and debug registers. [...]

The fix is to use PTRACE_GETREGS instead.

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

	* nat/linux-ptrace.c: Include "gregset.h".
	(linux_ptrace_test_ret_to_nx): Use PTRACE_GETREGS instead of
	PTRACE_PEEKUSER.
2016-07-26 19:38:13 +01:00
Pedro Alves 9cf12d57c5 Fix PR gdb/20287 - x32 and "gdb_static_assert (sizeof (nat_siginfo_t) == sizeof (siginfo_t))"
Building an x32 gdb trips on a static assertion:

  In file included from .../src/gdb/common/common-defs.h:71:0,
		   from .../src/gdb/nat/amd64-linux-siginfo.c:21:
  .../src/gdb/common/gdb_assert.h:26:66: error: size of array ‘never_defined_just_used_for_checking’ is negative
     extern int never_defined_just_used_for_checking[(expr) ? 1 : -1]
								    ^
  .../src/gdb/nat/amd64-linux-siginfo.c:113:1: note: in expansion of macro ‘gdb_static_assert’
   gdb_static_assert (sizeof (nat_siginfo_t) == sizeof (siginfo_t));
   ^

The problem is that the way nat_siginfo_t is defined, it can only
match the host's siginfo_t object when gdb is built as a 64-bit
program.

Several bits of nat_siginfo_t are off:

- nat_siginfo_t's _pad field's definition is:

   int _pad[((128 / sizeof (int)) - 4)];

  while /usr/include/bits/siginfo.h has:

   # define __SI_MAX_SIZE     128
   # if __WORDSIZE == 64
   #  define __SI_PAD_SIZE     ((__SI_MAX_SIZE / sizeof (int)) - 4)
   # else
   #  define __SI_PAD_SIZE     ((__SI_MAX_SIZE / sizeof (int)) - 3)
   # endif

  and __WORDSIZE == 32 for x32.  This is what causes the size of
  nat_siginfo_t to be wrong and the assertion to fail.

- the nat_clock_t type is incorrect for 64-bit.  We have this:

   /* For native 64-bit, clock_t in _sigchld is 64bit aligned at 4 bytes.  */
   typedef long __attribute__ ((__aligned__ (4))) nat_clock_t;

  however, /usr/include/bits/siginfo.h has:

   # if defined __x86_64__ && __WORDSIZE == 32
   /* si_utime and si_stime must be 4 byte aligned for x32 to match the
      kernel.  We align siginfo_t to 8 bytes so that si_utime and si_stime
      are actually aligned to 8 bytes since their offsets are multiple of
      8 bytes.  */
   typedef __clock_t __attribute__ ((__aligned__ (4))) __sigchld_clock_t;
   #  define __SI_ALIGNMENT __attribute__ ((__aligned__ (8)))
   # else
   typedef __clock_t __sigchld_clock_t;
   #  define __SI_ALIGNMENT
   # endif

  So we're currently forcing 4-byte alignment on clock_t, when it
  should only be so for x32, not 64-bit.

The fix:

 - Leaves nat_siginfo_t strictly for the 64-bit ABI.

 - Adds a new typedef for the siginfo type that ptrace uses
   (ptrace_siginfo_t).  An x32 gdb always gets/sets an x32 siginfo_t
   type with PTRACE_GETSIGINFO/PTRACE_SETSIGINFO.

 - Uses this new ptrace_siginfo_t type instead of nat_siginfo_t as the
   intermediate conversion type.

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

	* amd64-linux-nat.c (amd64_linux_siginfo_fixup): Rename 'native'
	parameter to 'ptrace'.
	* nat/amd64-linux-siginfo.c (GDB_SI_SIZE): New define.
	(nat_uptr_t): New an unsigned long.
	(nat_clock_t): Remove attribute __aligned__.
	(struct nat_timeval): Delete.
	(nat_siginfo_t): Remove attribute __aligned__.
	(ptrace_siginfo_t): Define.
	(compat_siginfo_from_siginfo, siginfo_from_compat_siginfo)
	(compat_x32_siginfo_from_siginfo)
	(siginfo_from_compat_x32_siginfo): Make 'from' parameter const.
	Convert through a ptrace_siginfo_t instead of a nat_siginfo_t.
	Remove casts.
	(amd64_linux_siginfo_fixup_common): Rename 'native' parameter to
	'ptrace'.  Remove static assertions.
	(top level): New static assertions.

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

	* linux-x86-low.c (x86_siginfo_fixup): Rename 'native' parameter
	to 'ptrace'.
2016-07-26 19:35:40 +01:00
Markus Metzger e0461dbb65 btrace, testsuite: fix assembly source file selection
Some btrace tests use assembly source files.  They use the target triplet to
distinguish between x86_64 and ia32 ISA.  This does not work for -m32 tests
without setting the target triplet to i686-?-?.

Instead use is_amd64_regs_target to distinguish between x86_64 and ia32 ISA.

See also https://sourceware.org/ml/gdb-patches/2016-07/msg00256.html.

testsuite/
	* gdb.btrace/record_goto.exp: Use is_amd64_regs_target for selecting
	assembly source files.
	* gdb.btrace/stepi.exp: Use is_amd64_regs_target for selecting
	assembly source files.
	* gdb.btrace/tailcall.exp: Use is_amd64_regs_target for selecting
	assembly source files.
	* gdb.btrace/tailcall-only.exp: Use is_amd64_regs_target for selecting
	assembly source files.
2016-07-26 13:56:27 +02:00
Simon Marchi 8194e927cc Handle correctly passing a bad interpreter name to new-ui
When a bad interpreter name is passed to new-ui, such as:

  (gdb)  new-ui bloop /dev/pts/10

A partially created UI is left in the UI list, with interp set to NULL.
Trying to do anything that will print on this UI (such as "start") will
cause a segmentation fault.

Changes in v2:

  - Use with_test_prefix to namespace test procedures
  - Give an explicit stable test name
  - Add a "bad terminal path" test
  - Remove useless runto_main
  - Add missing intro comments

I did not factor out the pty spawn, as there is some magic involved I
don't quite understand.  But it wouldn't bring that much anyway.

gdb/ChangeLog:

	* top.h (make_delete_ui_cleanup): New declaration.
	* top.c (delete_ui_cleanup): New function.
	(make_delete_ui_cleanup): New function.
	(new_ui_command): Create restore_ui cleanup earlier, create a
	delete_ui cleanup and discard it on success.

gdb/testsuite/ChangeLog:

	* gdb.base/new-ui.exp (do_test_invalid_args): New
	procedure.
2016-07-25 11:01:54 -04:00
Pedro Alves 0e1a6a5169 linux-procfs: Handle lowercase "t (tracing stop)" state
Since Linux 2.6.33, /proc/PID/status shows "t (tracing stop)", with
lowercase 't'.  Because GDB is only expecting "T (tracing stop)", GDB
can incorrectly suppress errors in check_ptrace_stopped_lwp_gone:

 1578          if (!check_ptrace_stopped_lwp_gone (lp))
 1579            throw_exception (ex);

Ref: https://sourceware.org/ml/gdb-patches/2016-06/msg00072.html

2016-07-25  Pedro Alves  <palves@redhat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	* nat/linux-procfs.c (parse_proc_status_state): Handle lowercase
	't'.
2016-07-25 12:58:38 +01:00
Pedro Alves d617208bb0 linux-procfs: Introduce enum proc_state
Parse the process's /proc/PID/status state into an enum instead of the
current scheme of passing state strings around.

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

	* nat/linux-procfs.c (enum proc_state): New enum.
	(parse_proc_status_state): New function.
	(linux_proc_pid_get_state): Replace output string buffer parameter
	with an output proc_state parameter.  Use parse_proc_status_state.
	(linux_proc_pid_is_gone): Adjust to use proc_state values.
	(linux_proc_pid_has_state): Change type of 'state' parameter; now
	an enum proc_state.  Adjust to linux_proc_pid_get_state interface
	change.
	(linux_proc_pid_is_stopped)
	(linux_proc_pid_is_trace_stopped_nowarn)
	(linux_proc_pid_is_zombie_maybe_warn): Adjust to
	linux_proc_pid_get_state interface change.
2016-07-25 12:42:17 +01:00
Tim Wiederhake 3a1518e4f3 Add myself as a write-after-approval GDB maintainer. 2016-07-25 11:31:41 +02:00
Tim Wiederhake c0272db585 btrace: Resume recording after disconnect.
This patch allows gdbserver to continue recording after disconnect.  On
reconnect, the recorded data is accessible to gdb as if no disconnect happened.

A possible application for this feature is remotely examine bugs that occur
at irregular intervals, where maintaining a gdb connection is inconvenient.

This also fixes the issue mentioned here:
https://sourceware.org/ml/gdb-patches/2015-11/msg00424.html

Signed-off-by: Tim Wiederhake <tim.wiederhake@intel.com>

gdb/ChangeLog:
	* NEWS: Resume btrace on reconnect.
	* record-btrace.c: Added record-btrace.h include.
	(record_btrace_open): Split into this and ...
	(record_btrace_push_target): ... this.
	(record_btrace_disconnect): New function.
	(init_record_btrace_ops): Use record_btrace_disconnect.
	* record-btrace.h: New file.
	* remote.c: Added record-btrace.h include.
	(remote_start_remote): Check recording status.
	(remote_btrace_maybe_reopen): New function.

gdb/doc/ChangeLog:
	* gdb.texinfo: Resume btrace on reconnect.

gdb/testsuite/ChangeLog:

	* gdb.btrace/reconnect.c: New file.
	* gdb.btrace/reconnect.exp: New file.

Change-Id: I95e8b0ab8a89e58591aba0e63818cee82fd211bc
2016-07-25 11:03:43 +02:00
Gabriel Krisman Bertazi e34879080d Implement catch syscall group
Implement support to add catchpoints for a group of related syscalls
using the syntax:

(gdb) catch syscall group:<group>
or
(gdb) catch syscall g:<group>

Several groups are predefined in the xml files for all architectures
supported by GDB over Linux.  They are based on the groups defined by
strace.

gdb/

	* xml-syscall.c (get_syscalls_by_group): New.
	(get_syscall_group_names): New.
	(struct syscall_group_desc): New structure to store group data.
	(struct syscalls_info): Include field to store the group list.
	(sysinfo_free_syscall_group_desc): New.
	(free_syscalls_info): Free group list.
	(syscall_group_create_syscall_group_desc): New.
	(syscall_group_add_syscall): New.
	(syscall_create_syscall_desc): Add syscall to its groups.
	(syscall_start_syscall): Load group attribute.
	(syscall_group_get_group_by_name): New.
	(xml_list_syscalls_by_group): New.
	(xml_list_of_groups): New.
	* xml-syscall.h (get_syscalls_by_group): Export function
	to retrieve a list of syscalls filtered by the group name.
	(get_syscall_group_names): Export function to retrieve the list
	of syscall groups.
	* break-catch-syscall.c (catch_syscall_split_args): Verify if
	argument is a syscall group and expand it to a list of syscalls
	when creating catchpoints.
	(catch_syscall_completer): Add word completion for system call
	groups.
	* configure.ac: Include dependency for xsltproc when building
	in maintainer-mode.
	* break-catch-syscall.c (_initialize_breakpoint): Update catch
	syscall command documentation.
	* NEWS: Include section about catching groups of syscalls.
	* configure: Regenerate.
	* data-directory/Makefile.in: Generate syscall xml when building
	in maintainer mode.
	* syscalls/gdb-syscalls.dtd: Include group attribute to the
	syscall element.
	* syscalls/apply-defaults.xsl: New.
	* syscalls/linux-defaults.xml.in: New.
	* syscalls/aarch64-linux.xml: Rename to aarch64-linux.xml.in.
	* syscalls/amd64-linux.xml: Rename to amd64-linux.xml.in.
	* syscalls/arm-linux.xml: Rename to arm-linux.xml.in.
	* syscalls/bfin-linux.xml: Rename to bfin-linux.xml.in.
	* syscalls/i386-linux.xml: Rename to i386-linux.xml.in.
	* syscalls/mips-n32-linux.xml: Rename to mips-n32-linux.xml.in.
	* syscalls/mips-n64-linux.xml: Rename to mips-n64-linux.xml.in.
	* syscalls/mips-o32-linux.xml: Rename to mips-o32-linux.xml.in.
	* syscalls/ppc-linux.xml: Rename to ppc-linux.xml.in.
	* syscalls/ppc64-linux.xml: Rename to ppc64-linux.xml.in.
	* syscalls/s390-linux.xml: Rename to s390-linux.xml.in.
	* syscalls/s390x-linux.xml: Rename to s390x-linux.xml.in.
	* syscalls/sparc-linux.xml: Rename to sparc-linux.xml.in.
	* syscalls/sparc64-linux.xml: Rename to sparc64-linux.xml.in.
	* syscalls/aarch64-linux.xml: Regenerate.
	* syscalls/amd64-linux.xml: Regenerate.
	* syscalls/arm-linux.xml: Regenerate.
	* syscalls/i386-linux.xml: Regenerate.
	* syscalls/mips-n32-linux.xml: Regenerate.
	* syscalls/mips-n64-linux.xml: Regenerate.
	* syscalls/mips-o32-linux.xml: Regenerate.
	* syscalls/ppc-linux.xml: Regenerate.
	* syscalls/ppc64-linux.xml: Regenerate.
	* syscalls/s390-linux.xml: Regenerate.
	* syscalls/s390x-linux.xml: Regenerate.
	* syscalls/sparc-linux.xml: Regenerate.
	* syscalls/sparc64-linux.xml: Regenerate.

gdb/testsuite/

	* gdb.base/catch-syscall.exp (do_syscall_tests): Add call
	to test_catch_syscall_group.
	(test_catch_syscall_group): New.

gdb/doc/

	* gdb.texinfo (Set Catchpoints): Add 'group' argument to catch
	syscall.
2016-07-23 18:38:24 -03:00
Andrew Pinski 49ecef2a7d Fix ARMv8.1/v8.2 for hw watchpoint and breakpoint
The problem here is ARMv8.1 (and ARMv8.2) define a
different debug version than ARMv8 (7 and 8 respectively).
This fixes hw watchpoints and breakpoints by checking
for those debug versions too.

Committed as obvious after a test on aarch64-linux-gnu
(on a ThunderX machine which has ARMv8.1 support enabled).

ChangeLog:
	* nat/aarch64-linux-hw-point.c
	(aarch64_linux_get_debug_reg_capacity): Handle
	ARMv8.1 and ARMv8.2 debug versions.
	* nat/aarch64-linux-hw-point.h
	(AARCH64_DEBUG_ARCH_V8_1): New define.
	(AARCH64_DEBUG_ARCH_V8_2): New define.

Signed-off-by: Andrew Pinski <apinski@cavium.com>
2016-07-23 10:10:32 -07:00
Руслан Ижбулатов 463888ab6b Support JIT debugging on MS-Windows
gdb/ChangeLog:
2016-06-30  Руслан Ижбулатов  <lrn1986@gmail.com>

	PR gdb/14529
	* windows-nat.c (signal_event_command): New command 'signal-event'
	for W32 JIT debug support.
	* NEWS: Add an entry about the new 'signal-event' command.

gdb/doc/ChangeLog:
2016-06-30  Руслан Ижбулатов  <lrn1986@gmail.com>

	* gdb.texinfo (Cygwin Native): Document the new 'signal-event'
	command.
2016-07-23 11:38:03 +03:00
Tom Tromey e98c9e7ce1 PR rust/20162 - fix gdb regressions caused by rust 1.10
PR rust/20162 started life as a reminder to test gdb with versions of
rust after 1.8; but now concerns some gdb regressions seen with rust
1.10 ("beta") and 1.11 ("nightly").

The failures turn out to be a discrepancy between how rustc emits
DWARF and how gdb interprets it.  In particular, rustc will emit DWARF
like:

 <2><bc>: Abbrev Number: 9 (DW_TAG_structure_type)
    <bd>   DW_AT_name        : (indirect string, offset: 0x46a): HasMethods
    <c1>   DW_AT_byte_size   : 4
...
 <3><cc>: Abbrev Number: 11 (DW_TAG_subprogram)
...
    <df>   DW_AT_name        : (indirect string, offset: 0x514f): new

gdb wants to see a separate top-level DW_TAG_subprogram that refers to
this one via DW_AT_specification; but rustc doesn't emit one.  By my
reading of DWARF 4 5.5.7, this is ok, and gdb is incorrect here.

Fixing this involved a new case in scan_partial_symbols, and then a
further change in process_structure_scope to account for the fact
that, in Rust, such functions are not methods and should not be
attached to the structure type.

Next, it turns out that rust is emitting bad values for
DW_AT_linkage_name, e.g.:

    <db>   DW_AT_linkage_name: (indirect string, offset: 0x422): _ZN7methods8{{impl}}3newE

The the "{{impl}}" stuff is apparently some side effect of a change to
the compiler's internal representation.  Oops!

This also had a simple fix -- disregard these mangled names.

With these changes, there are no regressions in the gdb Rust tests
with either 1.10 or 1.11.  1.9, the stable release, is still pretty
broken, but I think there's nothing much to do about that.

These changes are a bit hackish, but no worse, I think, than other
kinds of quirk handling already done in the DWARF parser.  I have
reported all the rustc bugs upstream.  I plan to remove these hacks
from gdb some suitable time after they have been fixed in released
versions of Rust.

2016-07-22  Tom Tromey  <tom@tromey.com>

	PR rust/20162:
	* dwarf2read.c (scan_partial_symbols) <DW_TAG_structure_type>:
	Call scan_partial_symbols for children when reading a Rust CU.
	(dwarf2_physname): Ignore invalid DW_AT_linkage_name generated by
	rustc.
	(process_structure_scope) <DW_TAG_subprogram>: Call
	read_func_scope for Rust.
2016-07-22 11:42:08 -06:00
Yao Qi eed2386e45 Get "num" as unsigned in ctf
I see the following fail due to the warning,

-trace-frame-collected^M
[warning] Extracting signed value from an unsigned int (num)^M
....
FAIL: gdb.trace/mi-trace-frame-collected.exp: ctf: -trace-frame-collected

In ctf metadata, "num" in "tsv" is defined as unint32_t,

  ctf_save_write_metadata (&writer->tcs,
			   "event {\n\tname = \"tsv\";\n\tid = %u;\n"
			   "\tfields := struct { \n"
			   "\t\tuint64_t val;\n"
			   "\t\tuint32_t num;\n"
			   "\t};\n"
			   "};\n", CTF_EVENT_ID_TSV);

so we should read it as unsigned.  The patch below fixes the fail by
changing to bt_ctf_get_uint64.

gdb:

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

	* ctf.c (ctf_traceframe_info): Call bt_ctf_get_uint64 rather than
	bt_ctf_get_int64.
2016-07-22 16:31:41 +01:00
Tom Tromey 12df5c002d Allow empty struct expressions in Rust
I learned recently that empty struct expressions, like "X{}", have been
promoted from experimental to stable in Rust.  This patch changes the
Rust expression parser to allow this case.

New test case included.
Built and regtested on x86-64 Fedora 23, using Rust 1.11 beta.

2016-07-21  Tom Tromey  <tom@tromey.com>

	* rust-lang.c (rust_tuple_struct_type_p): Return false for empty
	structs.
	* rust-exp.y (struct_expr_list): Allow empty elements.

2016-07-21  Tom Tromey  <tom@tromey.com>

	* gdb.rust/simple.rs (main): Use empty struct expression.
	* gdb.rust/simple.exp: Add tests for empty struct expression.
2016-07-21 15:16:04 -06:00
Tom Tromey 305450edd3 Add -Wunused-but-set-* to build
This adds -Wunused-but-set-variable and -Wunused-but-set-parameter to
configure.

2016-07-21  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
	* warning.m4 (AM_GDB_WARNINGS) <build_warnings>: Add
	-Wunused-but-set-parameter, -Wunused-but-set-variable.

2016-07-21  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
2016-07-21 13:07:23 -06:00
Pedro Alves f515a1d643 Fix djgpp gdb build
- A few missing casts required by C++, resulting in:

   ../../src/gdb/ser-go32.c:795:21: error: invalid conversion from 'const void*' to 'const char*' [-fpermissive]

   etc.

 - dos_noop has an incompatible prototype with struct serial_ops's
   setparity, resulting in:

    ../../src/gdb/ser-go32.c:874:1: error: invalid conversion from 'int (*)(serial*)' to 'int (*)(serial*, int)' [-fpermissive]

   (I thought of calling the ser-base.c default methods, but djgpp
   doesn't include ser-base.c in the build.)

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

	* go32-nat.c (go32_create_inferior): Add cast.
	* ser-go32.c (dos_noop): Delete.
	(dos_flush_output, dos_setparity, dos_drain_output): New
	functions.
	(dos_write): Add cast.
	(dos_ops): Use dos_flush_output, dos_setparity and
	dos_drain_output.
	* top.c (do_chdir_cleanup): Add cast.
2016-07-21 15:40:44 +01:00
Pedro Alves c25b7ccef4 Remove unused variable in windows-nat.c
Leave the call for side effects.

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

	* windows-nat.c (handle_exception): Remove "th".
2016-07-21 15:30:03 +01:00
Pedro Alves e3821cca15 Remove unused variable in gdb/varobj.c when built without Python support
gdb/ChangeLog:
2016-07-21  Pedro Alves  <palves@redhat.com>

	* varobj.c (varobj_value_get_print_value): Move "gdbarch" to block
	scope that uses it.
2016-07-21 15:29:58 +01:00
Yao Qi 2583da7cd6 Fix cast to 'gdb_breakpoint *'
c-mode buildbot catches a build problem,

gcc -g -O2    -I. -I../../../binutils-gdb/gdb/gdbserver -I../../../binutils-gdb/gdb/gdbserver/../common -I../../../binutils-gdb/gdb/gdbserver/../regformats -I../../../binutils-gdb/gdb/gdbserver/.. -I../../../binutils-gdb/gdb/gdbserver/../../include -I../../../binutils-gdb/gdb/gdbserver/../gnulib/import -Ibuild-gnulib-gdbserver/import  -Wall -Wpointer-arith -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -Wempty-body -Wpointer-sign -Wmissing-prototypes -Wdeclaration-after-statement -Wmissing-parameter-type -Wold-style-declaration -Wold-style-definition -Wformat-nonliteral -Wno-missing-prototypes -Werror -DGDBSERVER -c -o hostio.o -MT hostio.o -MMD -MP -MF .deps/hostio.Tpo ../../../binutils-gdb/gdb/gdbserver/hostio.c
../../../binutils-gdb/gdb/gdbserver/mem-break.c: In function find_gdb_breakpoint:
../../../binutils-gdb/gdb/gdbserver/mem-break.c:996:15: error: gdb_breakpoint undeclared (first use in this function)
       return (gdb_breakpoint *) bp;

we should use 'struct gdb_breakpoint' rather than 'gdb_breakpoint'.
Patch below fixes this.

gdb/gdbserver:

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

	* mem-break.c (find_gdb_breakpoint): Cast bp to
	'struct gdb_breakpoint *' rather than 'gdb_breakpoint *'.
2016-07-21 14:34:07 +01:00
Yao Qi 21536b367c Support vCont s and S actions with software single step
GDBserver with software single step should be able to claim supporting
vCont s and S actions, so that GDB knows the remote target can do
single step.  It doesn't matter to GDB that the single step in the
remote target is done via hardware or software.

gdb/gdbserver:

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

	* server.c (handle_v_requests): Support s and S actions
	if target_supports_software_single_step return true.
2016-07-21 12:12:18 +01:00
Yao Qi 8901d1936e Use reinsert_breakpoint for vCont;s
This patch is to teach GDBserver using software single step to handle
vCont;s.  Simply speaking, if the thread's resume request is resume_step,
install reinsert breakpoint at the next pcs when GDBserver is about to
resume threads.  These reinsert breakpoints of a thread are removed,
when GDBserver gets an event from that thread and reports it back to
GDB.

gdb/gdbserver:

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

	* linux-low.c (resume_stopped_resumed_lwps): If resume request
	is resume_step, call maybe_hw_step.
	(linux_wait_1): Stop all threads, remove reinsert breakpoints,
	and unstop them.
	(linux_resume_one_lwp_throw): Don't assert the thread has reinsert
	breakpoints or not.
	(proceed_one_lwp): If resume request is resume_step, install
	reinsert breakpoints and call maybe_hw_step.
2016-07-21 12:12:18 +01:00
Yao Qi 0e9a339ec8 Enqueue signal even when resuming threads
Nowadays, we only enqueue signal when we leave thread pending in
linux_resume_one_thread.  If lwp->resume->sig isn't zero (GDB wants
to resume with signal), we pass lwp->resume->sig to
linux_resume_one_lwp.

In order to reduce the difference between resuming thread with signal
and proceeding thread with signal, when we resume thread, we can
enqueue signal too, and proceed thread.  The signal will be consumed in
linux_resume_one_lwp_throw from lwp->pending_signals.

gdb/gdbserver:

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

	* linux-low.c (proceed_one_lwp): Declare.
	(linux_resume_one_thread): Remove local variable 'step'.
	Lift code enqueue signal.  Call proceed_one_lwp instead of
	linux_resume_one_lwp.
2016-07-21 12:12:18 +01:00
Yao Qi 4281b351bf Use enqueue_pending_signal in linux_resume_one_thread
gdb/gdbserver:

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

	* linux-low.c (linux_resume_one_thread): Call
	enqueue_pending_signal.
2016-07-21 12:12:18 +01:00
Yao Qi 984a2c042e Switch current_thread to lwp's thread in install_software_single_step_breakpoints
install_software_single_step_breakpoints has parameter lwp, but still
need to switch to current_thread.  In order to simplify its caller,
we do the current_thread save/restore inside install_software_single_step_breakpoints.

gdb/gdbserver:

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

	* gdbthread.h (make_cleanup_restore_current_thread): Declare.
	* inferiors.c (do_restore_current_thread_cleanup): New function.
	(make_cleanup_restore_current_thread): Likewise.
	* linux-low.c (install_software_single_step_breakpoints): Call
	make_cleanup_restore_current_thread.  Switch current_thread to
	thread.
2016-07-21 12:12:18 +01:00
Yao Qi bec903c96b Make reinsert_breakpoint thread specific
This patch makes reinsert_breakpoint thread specific, which means we
insert and remove reinsert_breakpoint breakpoints for a specific
thread.  This motivation of this change is that I'll use
reinsert_breakpoint for vCont;s on software single step target, so that
GDBserver may insert one reinsert_breakpoint for one thread doing
step-over, and insert one reinsert_breakpoint for another thread doing
vCont;s.  After the operation of one thread is finished, GDBserver must
remove reinsert_breakpoint for that thread only.

On the other hand, reinsert_breakpoint is used for step-over nowadays.
GDBserver inserts reinsert_breakpoint, and wait only from the thread
doing step-over.  After the step-over is done, GDBserver removes the
reinsert_breakpoint.  If there is still any threads need step-over, do
the same again until all threads are finished step-over.  In other words,
reinsert_breakpoint is globally thread specific, but in an implicit way.
It is natural to make it explicitly thread specific.

gdb/gdbserver:

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

	* mem-break.c (struct reinsert_breakpoint) <ptid>: New field.
	(set_reinsert_breakpoint): New parameter ptid.  Callers updated.
	(clone_one_breakpoint): Likewise.
	(delete_reinsert_breakpoints): Change parameter to thread.
	Callers updated.
	(has_reinsert_breakpoints): Likewise.
	(uninsert_reinsert_breakpoints): Likewise.
	(reinsert_reinsert_breakpoints): Likewise.
	* mem-break.h (set_reinsert_breakpoint): Update declaration.
	(delete_reinsert_breakpoints): Likewise.
	(reinsert_reinsert_breakpoints): Likewise.
	(uninsert_reinsert_breakpoints): Likewise.
	(has_reinsert_breakpoints): Likewise.
2016-07-21 12:12:18 +01:00
Yao Qi 63c40ec727 Refactor clone_all_breakpoints
This patch is to change the interface of clone_all_breakpoints, from
lists of breakpoints and raw_breakpoints to child thread and parent
thread.  I choose child thread to pass because we need the ptid of
the child thread in the following patch.

gdb/gdbserver:

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

	* inferiors.c (get_thread_process): Make parameter const.
	* inferiors.h (get_thread_process): Update declaration.
	* mem-break.c (clone_all_breakpoints): Remove all parameters.
	Add new parameters child_thread and parent_thread.  Callers
	updated.
	* mem-break.h (clone_all_breakpoints): Update declaration.
2016-07-21 12:12:18 +01:00
Yao Qi 9aa76cd0a7 Create sub classes of 'struct breakpoint'
Nowadays, there are three types of breakpoint in GDBserver,

 - gdb breakpoints,
 - reinsert breakpoints, used for software single step,
 - other breakpoints, used for tracepoint,

but we only have one 'struct breakpoint' for all of them.  Some fields
are only useful to one type of breakpoint.  For example, cond_list
and command_list are only used by gdb breakpoints, while handler is
only used by other breakpoints.

This patch changes 'struct breakpoint' to a base class, which has fields
needed by all breakpoint types, also add three sub-classes to
'struct breakpoint' to these three types of breakpoints.

gdb/gdbserver:

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

	* mem-break.c (struct breakpoint) <cond_list>: Remove.
	<command_list, handler>: Remove.
	(struct gdb_breakpoint): New.
	(struct other_breakpoint): New.
	(struct reinsert_breakpoint): New.
	(is_gdb_breakpoint): New function.
	(any_persistent_commands): Update command_list if
	is_gdb_breakpoint returns true.
	(set_breakpoint): Create breakpoints according to their types.
	(find_gdb_breakpoint): Return 'struct gdb_breakpoint *'.
	(set_gdb_breakpoint_1): Likewise.
	(set_gdb_breakpoint): Likewise.
	(clear_breakpoint_conditions): Change parameter type to
	'struct gdb_breakpoint *'.
	(clear_breakpoint_commands): Likewise.
	(clear_breakpoint_conditions_and_commands): Likewise.
	(add_condition_to_breakpoint): Likewise.
	(add_breakpoint_condition): Likewise.
	(add_commands_to_breakpoint): Likewise.
	(check_breakpoints): Check other_breakpoint.
	(clone_one_breakpoint): Clone breakpopint according to its type.
	* mem-break.h (struct gdb_breakpoint): Declare.
	(set_gdb_breakpoint): Update declaration.
	(clear_breakpoint_conditions_and_commands): Likewise.
	(add_breakpoint_condition): Likewise.
	(add_breakpoint_commands): Likewise.
	* server.c (process_point_options): Change parameter type to
	'struct gdb_breakpoint *'.
2016-07-21 12:12:17 +01:00
Yao Qi 811f8301f8 Pass breakpoint type in set_breakpoint_at
Nowadays, set_breakpoint_at creates breakpoint of type
other_breakpoint, but we also use set_breakpoint_at
in set_reinsert_breakpoint to create breakpoint, so that
we have to overwrite the breakpoint type like this,

  bp = set_breakpoint_at (stop_at, NULL);
  bp->type = reinsert_breakpoint;

which looks not very good.  This patch changes set_breakpoint_at
to receive breakpoint type.  Since set_breakpoint_at is
used in many places, I rename it to set_breakpoint_type_at, and wrap
it with set_breakpoint_at, and pass other_breakpoint.  In this way,
we can call set_breakpoint_type_at with reinsert_breakpoint in
set_reinsert_breakpoint too, and code looks cleaner.

gdb/gdbserver:

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

	* mem-break.c (set_breakpoint_at): Rename it to ...
	(set_breakpoint_type_at): ... it.
	(set_breakpoint_at): Call set_breakpoint_type_at.
	(set_reinsert_breakpoint): Call set_breakpoint_type_at.
	* mem-break.h (set_breakpoint_at): Update comments.
2016-07-21 12:12:17 +01:00
Yao Qi bae62ee208 Skip gdb.server/ tests if lack of XML support
I recently see some gdb.server/*.exp fails in my native gdb testing,
in which libexpat isn't available, so GDB isn't able to parse xml file.
It causes gdb.server/ tests fails because GDB can't get registers
correctly from GDBserver.

(gdb) PASS: gdb.server/connect-without-multi-process.exp: multiprocess=off: break main
target remote localhost:2352^M
Remote debugging using localhost:2352^M
warning: Can not parse XML target description; XML support was disabled at compile time^M
Reading /lib/ld-linux-armhf.so.3 from remote target...^M
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.^M
Reading /lib/ld-linux-armhf.so.3 from remote target...^M
Reading symbols from target:/lib/ld-linux-armhf.so.3...Reading /lib/ld-2.17.so.debug from remote target...^M
Reading /lib/.debug/ld-2.17.so.debug from remote target...^M
(no debugging symbols found)...done.^M
Remote 'g' packet reply is too long: 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000efffbe00000000808d0f4d100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000^
0x4d0f8d80 in _start () from target:/lib/ld-linux-armhf.so.3^M

Without XML support in GDB, it can't parse xml sent by GDBserver, and has
to fall back to the oldest arch.  However, GDBserver doesn't know this
(IMO, this is a defect in RSP), and still choose the right target
description to create regcache and 'g' packet.  If the port only has
one target description or coincidentally two sides choose the same
target description, there is no such issue.  Otherwise, GDB is broken
on read registers.

This patch is to skip gdbserver tests if XML is not support and the
target has multiple target descriptions.

gdb/testsuite:

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

	* lib/gdbserver-support.exp (skip_gdbserver_tests): Return 1
	if gdb_skip_xml_test is true on some targets.
2016-07-21 09:24:44 +01:00
Yao Qi b1b53fb3ef Fix fail in gdb.server/solib-list.exp
If I run single test solib-list.exp, it is OK.  If I run two, as below,
there are fails,

$ make check RUNTESTFLAGS="server-run.exp solib-list.exp"
FAIL: gdb.server/solib-list.exp: non-stop 0: continue (the program exited)
FAIL: gdb.server/solib-list.exp: non-stop 0: p libvar
FAIL: gdb.server/solib-list.exp: non-stop 1: continue (the program exited)
FAIL: gdb.server/solib-list.exp: non-stop 1: p libvar

in gdb.log,

/scratch/yao/gdb/build-git/x86_64/gdb/testsuite/../../gdb/gdbserver/gdbserver --once :2347 /scratch/yao/gdb/build-git/x86_64/gdb/testsuite/outputs/gdb.server/server-run/server-run /lib64/ld-linux-x86-64.so.2 /scratch/yao/gdb/build-git/x86_64/gdb/testsuite/outputs/gdb.server/solib-list/solib-list

server-run is spawned, which is wrong.  If I only run solib-list.exp, ld-linux
is spawned, which is right.

/scratch/yao/gdb/build-git/x86_64/gdb/testsuite/../../gdb/gdbserver/gdbserver --once :2346 /lib64/ld-linux-x86-64.so.2 /scratch/yao/gdb/build-git/x86_64/gdb/testsuite/outputs/gdb.server/solib-list/solib-list

in test, we spawn gdbserver this way,

    # Note we pass ${interp_system}, the program gdbserver spawns, as
    # argument here, instead of using gdb_load, because we don't want
    # to download the interpreter to the target (it's already there)
    # or to the test output directory.
    set res [gdbserver_spawn "${interp_system} ${remote_binfile}"]

in gdbserver_spawn -> gdbserver_download_current_prog, if
last_loaded_file is set (when you run multiple tests), it is
returned.

This patch is to unset last_loaded_file in solib-list.exp.

gdb/testsuite:

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

	* gdb.server/solib-list.exp: Unset last_loaded_file.
2016-07-21 09:15:21 +01:00