Commit Graph

39580 Commits

Author SHA1 Message Date
Yao Qi afe37d6be5 Class-fy dwarf2_frame_state
This patch adds ctor and dtor to dwarf2_frame_state, so that we can
remove one cleanup "old_chain".

gdb:

2017-08-11  Yao Qi  <yao.qi@linaro.org>

	* dwarf2-frame.c (dwarf2_frame_state_free): Remove.
	(dwarf2_frame_state::dwarf2_frame_state): New.
	(dwarf2_frame_state::~dwarf2_frame_state): New.
	(dwarf2_fetch_cfa_info): Update.
	(dwarf2_frame_cache): Remove old_chain.  Change 'fs' to an object
	rather than a pointer.  Update code.
	* dwarf2-frame.h (struct dwarf2_frame_state): Declare ctor and
	dtor.
	<data_align, code_align, retaddr_column>: Change them to const.
	<armcc_cfa_offsets_sf, armcc_cfa_offsets_reversed>: Change them
	to bool.
2017-08-11 09:30:02 +01:00
Yao Qi b348037fd8 Move dwarf2_frame_state_reg.exp_len to union .loc
dwarf2_frame_state_reg.exp_len is only used together with .loc.exp, so
it makes more sense to exp_len to the union as well.

gdb:

2017-08-11  Yao Qi  <yao.qi@linaro.org>

	* dwarf2-frame.h (struct dwarf2_frame_state_reg) <exp_len>: Remove.
	<loc.exp>: New field.
	* dwarf2-frame.c (execute_cfa_program): Update.
	(dwarf2_frame_prev_register): Update.
2017-08-11 09:30:02 +01:00
Pedro Alves e7c9de2678 Allow gdb::unique_xmalloc_ptr<T[]>
Currently, if you try to use the array version of
gdb::unique_xmalloc_ptr (i.e., std::unique_ptr) in order to have
access to operator[], like:

  gdb::unique_xmalloc_ptr<char[]> buf ((char *) xmalloc (10));
  return buf[0];

then the build fails, like:

  /usr/include/c++/5.3.1/bits/unique_ptr.h: In instantiation of ‘std::unique_ptr<_Tp [], _Dp>::~unique_ptr() [with _Tp = char; _Dp = gdb::xfree_deleter<char []>]’:
  main.c:30:61:   required from here
  /usr/include/c++/5.3.1/bits/unique_ptr.h:484:17: error: no match for call to ‘(std::unique_ptr<char [], gdb::xfree_deleter<char []> >::deleter_type {aka gdb::xfree_deleter<char []>}) (char*&)’
      get_deleter()(__ptr);
		   ^
  In file included from src/gdb/common/common-defs.h:92:0,
		   from src/gdb/defs.h:28,
		   from src/gdb/main.c:20:
  src/gdb/common/gdb_unique_ptr.h:34:8: note: candidate: void gdb::xfree_deleter<T>::operator()(T*) const [with T = char []]
     void operator() (T *ptr) const { xfree (ptr); }
	  ^
  src/gdb/common/gdb_unique_ptr.h:34:8: note:   no known conversion for argument 1 from ‘char*’ to ‘char (*)[]’
  Makefile:1911: recipe for target 'main.o' failed
  make: *** [main.o] Error 1

The problem is that we're missing an xfree_deleter specialization for
arrays.

gdb/ChangeLog:
2017-08-10  Pedro Alves  <palves@redhat.com>

	* common/gdb_unique_ptr.h (xfree_deleter<T[]>): Define.
2017-08-10 14:18:02 +01:00
John Baldwin e8c6b620f7 Replace home-grown linked-lists in FreeBSD's native target with STL lists.
FreeBSD's native target uses linked-lists to keep track of pending fork
events and fake vfork done events.  Replace the first list with std::list
and the second with std::forward_list.

gdb/ChangeLog:

	* fbsd-nat.c (struct fbsd_fork_info): Remove.
	(fbsd_pending_children): Use std::list.
	(fbsd_remember_child): Likewise.
	(fbsd_is_child_pending): Likewise.
	(fbsd_pending_vfork_done): Use std::forward_list.
	(fbsd_add_vfork_done): Likewise.
	(fbsd_is_vfork_done_pending): Likewise.
	(fbsd_next_vfork_done): Likewise.
2017-08-09 15:24:46 -07:00
John Baldwin e4a26669b9 Replace remaining cleanups in fbsd-nat.c.
- Use a custom deleter with std::unique_ptr to free() memory returned
  by kinfo_getvmmap().
- Use std::string with string_printf() to generate the pathname of the
  procfs 'map' file.
- Use gdb::byte_vector to manage the dynamic buffer for
  TARGET_OBJECT_AUXV and the dynamically allocated array of LWP IDs.

gdb/ChangeLog:

	* fbsd-nat.c [HAVE_KINFO_GETVMMAP] (struct free_deleter): New.
	(fbsd_find_memory_regions): Use free_deleter with std::unique_ptr.
	[!HAVE_KINFO_GETVMMAP] (fbsd_find_memory_regions): Use std::string
	for `mapfilename'.
	(fbsd_xfer_partial): Use gdb::byte_vector.
	(fbsd_add_threads): Likewise.
2017-08-09 15:24:46 -07:00
John Baldwin 142311d325 Fix compile in the !HAVE_KINFO_GETVMMAP case.
gdb/ChangeLog:

	* fbsd-nat.c: [!HAVE_KINFO_GETVMMAP]: Include <sys/user.h> and
	"filestuff.h".
	(fbsd_find_memory_regions): Fix `mapfile' initialization.
2017-08-09 15:24:46 -07:00
Simon Marchi 0968fbae6b doc: Fix copy-pasto in Z0 packet documentation
The documentation for the cmd_list field of the Z0 packet refers to its
content as a conditional expression, which seems like a copy-paste error
from the cond_list field.

gdb/doc/ChangeLog:

	* gdb.texinfo (Packets): Fix Z0 cmd_list doc referring to
	conditional expression.
2017-08-09 22:16:14 +02:00
Tom Tromey 42fa2e0e1b C++-ify skip.c
I happened to notice that skiplist_entry, in skip.c, contains a
gdb::optional<compiled_regex> -- but that this object's destructor is
never run.  This can result in a memory leak.

This patch fixes the bug by applying a bit more C++: changing this
code to use new and delete, and std::unique_ptr; and removing cleanups
in the process.

Built and regression tested on x86-64 Fedora 25.

ChangeLog
2017-08-09  Tom Tromey  <tom@tromey.com>

	* skip.c (skiplist_entry): New constructor.
	(skiplist_entry::enabled, skiplist_entry::function_is_regexp)
	(skiplist_entry::file_is_glob): Now bool.
	(skiplist_entry::file, skiplist_entry::function): Now
	std::string.
	(make_skip_entry): Return a unique_ptr.  Use new.
	(free_skiplist_entry, free_skiplist_entry_cleanup)
	(make_free_skiplist_entry_cleanup): Remove.
	(skip_command, skip_disable_command, add_skiplist_entry)
	(skip_form_bytes, compile_skip_regexp, skip_command, skip_info)
	(skip_file_p, skip_gfile_p, skip_function_p, skip_rfunction_p)
	(function_name_is_marked_for_skip): Update.
	(skip_delete_command): Update.  Use delete.
2017-08-09 12:32:06 -06:00
Jiong Wang cd3af38d7b [AArch64] Implement gdbarch_core_read_description
Recommit with missing header files added.

gdb/
	* aarch64-linux-tdep.c: Include "auxv.h" and "elf/common.h".
	(aarch64_linux_core_read_description): New function.
	(aarch64_linux_init_abi): Register gdbarch_core_read_description.
2017-08-09 17:46:06 +01:00
Jiong Wang 0f76ffafce Revert "[AArch64] Implement gdbarch_core_read_description"
This reverts commit b1a6c1cea3.
2017-08-09 15:51:56 +01:00
Jiong Wang b1a6c1cea3 [AArch64] Implement gdbarch_core_read_description
Currently, AArch64 only have one target description which is tdesc_aarch64.  So,
we haven't implemented any target description detection mechanism for core file.

This patch is an initial implementation of core_read_description method.  Future
features can use this to return selected description.

gdb/
	* aarch64-linux-tdep.c (aarch64_linux_core_read_description): New
	function.
	(aarch64_linux_init_abi): Register gdbarch_core_read_description.
2017-08-09 15:37:20 +01:00
Pedro Alves 29592bde87 Make cp_comp_to_string return a gdb::unique_xmalloc_ptr<char>
To help avoid issues like the one fixed by e88e8651cf ("Fix memory
leak in cp-support.c").

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

	* cp-name-parser.y (cp_comp_to_string): Return a
	gdb::unique_xmalloc_ptr<char>.
	* cp-support.c (replace_typedefs_qualified_name)
	(replace_typedefs): Adjust to use gdb::unique_xmalloc_ptr<char>.
	(cp_canonicalize_string_full): Use op= instead of explicit
	convertion.
	(cp_class_name_from_physname, method_name_from_physname)
	(cp_func_name, cp_remove_params): Adjust to use
	gdb::unique_xmalloc_ptr<char>.
	* cp-support.h (cp_comp_to_string): Return a
	gdb::unique_xmalloc_ptr<char>.
	* python/py-type.c (typy_lookup_type): Adjust to use
	gdb::unique_xmalloc_ptr<char>.
2017-08-09 15:04:32 +01:00
H.J. Lu b33404388e gdb: Fix build failure with GCC 7
Fix:

/export/gnu/import/git/sources/binutils-gdb/gdb/dwarf2read.c: In function ‘const char* dwarf2_string_attr(die_info*, unsigned int, dwarf2_cu*)’:
/export/gnu/import/git/sources/binutils-gdb/gdb/dwarf2read.c:17626:39: error: enum constant in boolean context [-Werror=int-in-bool-context]
    || attr->form == DW_FORM_string || DW_FORM_GNU_str_index

	* dwarf2read.c (dwarf2_string_attr): Fix a typo.
2017-08-09 05:01:55 -07:00
Yao Qi e88e8651cf Fix memory leak in cp-support.c
The return value of cp_comp_to_string was never freed, creating a
sizable memory leak detectable with valgrind.

==21225== 8 bytes in 1 blocks are definitely lost in loss record 4,599 of 10,949^M
==21225==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M
==21225==    by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M
==21225==    by 0x76CB31: d_growable_string_resize (cp-demangle.c:3963)^M
==21225==    by 0x76CB31: d_growable_string_init (cp-demangle.c:3942)^M
==21225==    by 0x76CB31: cplus_demangle_print (cp-demangle.c:4308)^M
==21225==    by 0x4C9535: cp_comp_to_string(demangle_component*, int) (cp-name-parser.y:1972)^M
==21225==    by 0x53E1D4: cp_canonicalize_string_full[abi:cxx11](char const*, char const* (*)(type*, void*), void*) (cp-support.c:530)^M
==21225==    by 0x53E360: cp_canonicalize_string_no_typedefs[abi:cxx11](char const*) (cp-support.c:548)^M
==21225==    by 0x5D51D2: find_linespec_symbols(linespec_state*, VEC_symtab_ptr*, char const*, VEC_symbolp**, VEC_bound_minimal_symbol_d**) (linespec.c:4030)^M
==21225==    by 0x5D6CF6: linespec_parse_basic (linespec.c:1907)

==21279== 32 bytes in 1 blocks are definitely lost in loss record 6,066 of 10,947^M
==21279==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M
==21279==    by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M
==21279==    by 0x76CB31: d_growable_string_resize (cp-demangle.c:3963)^M
==21279==    by 0x76CB31: d_growable_string_init (cp-demangle.c:3942)^M
==21279==    by 0x76CB31: cplus_demangle_print (cp-demangle.c:4308)^M
==21279==    by 0x4C9535: cp_comp_to_string(demangle_component*, int) (cp-name-parser.y:1972)^M
==21279==    by 0x53EF14: cp_canonicalize_string[abi:cxx11](char const*) (cp-support.c:569)^M
==21279==    by 0x561B75: dwarf2_canonicalize_name(char const*, dwarf2_cu*, obstack*) [clone .isra.210] (dwarf2read.c:20159)

This patch fixes the leak.  It is a regression by 2f408ecb.

gdb:

2017-08-09  Alex Lindsay  <alexlindsay239@gmail.com>
	    Yao Qi  <yao.qi@linaro.org>

	* cp-support.c (cp_canonicalize_string_full): Use
	gdb::unique_xmalloc_ptr<char>.
	(cp_canonicalize_string): Likewise.
2017-08-09 12:39:16 +01:00
Yao Qi f5a29eb0a6 Clean up x86 non-linux GDBserver target descriptions
In GDBserver, only tdesc_i386 and tdesc_amd64 are used.  There is no point
of generating these *.dat files (which are used to generate *.c files during
GDBserver build.).

gdb:

2017-08-09  Yao Qi  <yao.qi@linaro.org>

	* features/Makefile (WHICH): Remove i386/ non-linux stuff.
	* regformats/i386/amd64-avx-avx512.dat: Remove.
	* regformats/i386/amd64-avx-mpx-avx512-pku.dat: Remove.
	* regformats/i386/amd64-avx-mpx.dat:Remove.
	* regformats/i386/amd64-avx.dat: Remove.
	* regformats/i386/amd64-mpx.dat: Remove.
	* regformats/i386/i386-avx-avx512.dat: Remove.
	* regformats/i386/i386-avx-mpx-avx512-pku.dat: Remove.
	* regformats/i386/i386-avx-mpx.dat: Remove.
	* regformats/i386/i386-mmx.dat: Remove.
	* regformats/i386/i386-mpx.dat: Remove.

gdb/gdbserver:

2017-08-09  Yao Qi  <yao.qi@linaro.org>

	* configure.srv (srv_i386_regobj): Remove i386-avx.o,
	i386-avx-avx512.o, i386-avx-mpx-avx512-pku.o, i386-mpx.o,
	i386-avx-mpx.o and i386-mmx.o.
	(srv_amd64_regobj): Remove amd64-avx.o, amd64-avx-avx512.o,
	amd64-avx-mpx-avx512-pku.o, amd64-mpx.o and amd64-avx-mpx.o.
	(srv_i386_xmlfiles): Remove i386/i386-avx.xml,
	i386/i386-avx-avx512.xml, i386/i386-avx-mpx-avx512-pku.xml,
	i386/i386-mpx.xml, i386/i386-avx-mpx.xml and i386/i386-mmx.xml.
	(srv_amd64_xmlfile):i386/amd64-avx.xml, i386/amd64-avx-avx512.xml,
	i386/amd64-avx-mpx-avx512-pku.xml, i386/amd64-mpx.xml,
	i386/amd64-avx-mpx.xml.
2017-08-09 12:29:21 +01:00
Yao Qi 57757c2f09 Remove x32 non-linux target descriptions
x32 non-linux target descriptions are not used in GDB or GDBserver.  This
patch removes them.

gdb:

2017-08-09  Yao Qi  <yao.qi@linaro.org>

	* amd64-tdep.h (tdesc_x32): Remove the declaration.
	* amd64-tdep.c: Don't include features/i386/x32*.c.
	(_initialize_amd64_tdep): Don't call initialize_tdesc_x32*
	functions.
	* features/Makefile (WHICH): Remove i386/x32, i386/x32-avx,
	and i386/x32-avx-avx512.
	(XMLTOC): Remove i386/x32-avx.xml, i386/x32-avx-avx512.xml,
	and i386/x32.xml.
	* features/i386/x32-avx-avx512.c: Removed.
	* features/i386/x32-avx-avx512.xml: Removed.
	* features/i386/x32-avx.c: Removed.
	* features/i386/x32-avx.xml: Removed.
	* features/i386/x32.c: Removed.
	* features/i386/x32.xml: Removed.
	* regformats/i386/x32-avx-avx512.dat: Removed.
	* regformats/i386/x32-avx.dat: Removed.
	* regformats/i386/x32.dat: Removed.

gdb/gdbserver:

2017-08-09  Yao Qi  <yao.qi@linaro.org>

	* configure.srv (srv_amd64_regobj): Remove x32.o, x32-avx.o
	and x32-avx-avx512.o.
	(srv_amd64_xmlfiles): Remove i386/x32.xml, i386/x32-avx.xml
	i386/x32-avx-avx512.xml.
2017-08-09 12:28:59 +01:00
Simon Marchi 7b005726f9 Add missing PR mention in ChangeLog
I noticed that the patch pushed previously had an open bug about it, so
add a reference to it.
2017-08-07 18:27:29 +02:00
Maciej W. Rozycki ba7b109b29 PR breakpoints/21886: mem-break: Fix breakpoint insertion location
Fix a commit cd6c3b4ffc ("New gdbarch methods breakpoint_kind_from_pc
and sw_breakpoint_from_kind") regression and restore the use of
`->placed_address' rather than `->reqstd_address' as the location for a
memory breakpoint to be inserted at.  Previously
`gdbarch_breakpoint_from_pc' was used that made that adjustment in
`default_memory_insert_breakpoint' from the preinitialized value,
however with the said commit that call is gone, so the passed
`->placed_address' has to be used for the initialization.

The regression manifests itself as the inability to debug any MIPS/Linux
compressed ISA dynamic executable as GDB corrupts the dynamic loader
with one of its implicit breakpoints, causing the program to crash, as
seen for example with the `mips-linux-gnu' target, o32 ABI, MIPS16 code,
and the gdb.base/advance.exp test case:

(gdb) continue
Continuing.

Program received signal SIGBUS, Bus error.
_dl_debug_initialize (ldbase=0, ns=0) at dl-debug.c:51
51	    r = &_r_debug;
(gdb) FAIL: gdb.base/advance.exp: Can't run to main

	gdb/
	PR breakpoints/21886
	* mem-break.c (default_memory_insert_breakpoint): Use
	`->placed_address' rather than `->reqstd_address' for the
	breakpoint location.
2017-08-07 17:02:04 +01:00
Maciej W. Rozycki e347efc38b GDB/opcodes: Remove arch/mach/endian disassembler assertions
Fix `set architecture' and `set endian' command disassembly regressions
from commit 39503f8242 ("Delegate opcodes to select disassembler in
GDB"), and commit 003ca0fd22 ("Refactor disassembler selection"), as
well as a MIPS compressed ISA disassembly target regression from commit
6394c60699 ("Don't use print_insn_XXX in GDB"), which caused assertion
failures to trigger.

For example with the `mips-linux-gnu' target we get:

$ cat main.c
int
main (void)
{
  return 0;
}
$ gcc -mips32r2 -O2 main.c -o main
$ gcc -mips16 -mips32r2 -O2 main.c -o main16
$ gdb
GNU gdb (GDB) 8.0.50.20170731-git
[...]
(gdb) file main
Reading symbols from main...done.
(gdb) show architecture
The target architecture is set automatically (currently mips:isa32r2)
(gdb) show endian
The target endianness is set automatically (currently big endian)
(gdb) disassemble main
Dump of assembler code for function main:
   0x00400500 <+0>:	jr	ra
   0x00400504 <+4>:	move	v0,zero
End of assembler dump.
(gdb) set architecture mips:isa64r2
The target architecture is assumed to be mips:isa64r2
(gdb) disassemble main
Dump of assembler code for function main:
   0x00400500 <+0>:
.../gdb/arch-utils.c:979: internal-error: int default_print_insn(bfd_vma, disassemble_info*): Assertion `info->mach == bfd_get_mach (exec_bfd)' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) n
[...]
Command aborted.
(gdb) set architecture auto
The target architecture is set automatically (currently mips:isa32r2)
(gdb) set endian little
The target is assumed to be little endian
(gdb) disassemble main
Dump of assembler code for function main:
   0x00400500 <+0>:
.../gdb/arch-utils.c:978: internal-error: int default_print_insn(bfd_vma, disassemble_info*): Assertion `info->endian == (bfd_big_endian (exec_bfd) ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE)' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) n
[...]
Command aborted.
(gdb) set endian auto
The target endianness is set automatically (currently big endian)
(gdb) set architecture i386
The target architecture is assumed to be i386
(gdb) disassemble main
Dump of assembler code for function main:
   0x00400500 <+0>:
.../gdb/arch-utils.c:976: internal-error: int default_print_insn(bfd_vma, disassemble_info*): Assertion `info->arch == bfd_get_arch (exec_bfd)' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) n
[...]
Command aborted.
(gdb) set architecture auto
The target architecture is set automatically (currently mips:isa32r2)
(gdb) file main16
Load new symbol table from "main16"? (y or n) y
Reading symbols from main16...done.
(gdb) disassemble main
Dump of assembler code for function main:
   0x00400501 <+0>:
.../gdb/arch-utils.c:979: internal-error: int default_print_insn(bfd_vma, disassemble_info*): Assertion `info->mach == bfd_get_mach (exec_bfd)' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) n
Command aborted.
(gdb)

Remove the assertions then, restoring previous semantics:

(gdb) file main
Reading symbols from main...done.
(gdb) set architecture mips:isa64r2
The target architecture is assumed to be mips:isa64r2
(gdb) disassemble main
Dump of assembler code for function main:
   0x00400500 <+0>:	jr	ra
   0x00400504 <+4>:	move	v0,zero
End of assembler dump.
(gdb) set endian little
The target is assumed to be little endian
(gdb) disassemble main
Dump of assembler code for function main:
   0x00400500 <+0>:	j	0x3800c
   0x00400504 <+4>:	addiu	s0,t0,0
End of assembler dump.
(gdb) set architecture i386
The target architecture is assumed to be i386
(gdb) disassemble main
Dump of assembler code for function main:
   0x00400500 <+0>:	add    %eax,%esp
   0x00400502 <+2>:	add    %cl,(%eax)
   0x00400504 <+4>:	add    %al,(%eax)
   0x00400506 <+6>:	adc    %ah,0x0
End of assembler dump.
(gdb) set architecture auto
The target architecture is set automatically (currently mips:isa32r2)
(gdb) set endian auto
The target endianness is set automatically (currently big endian)
(gdb) file main16
Load new symbol table from "main16"? (y or n) y
Reading symbols from main16...done.
(gdb) disassemble main
Dump of assembler code for function main:
   0x00400501 <+0>:	jr	ra
   0x00400503 <+2>:	li	v0,0
End of assembler dump.
(gdb)

	gdb/
	* arch-utils.c (default_print_insn): Remove arch/mach/endian
	assertions.

	opcodes/
	* disassemble.c (disassembler): Remove arch/mach/endian
	assertions.
2017-08-07 15:53:54 +01:00
Maciej W. Rozycki 0dba2a6c09 gdbarch: Use an anonymous union for target data in `gdbarch_info'
As an update to commit ede5f15146 ("gdbarch.h: Change
gdbarch_info::tdep_info's type to void *") replace the definition of the
`tdep_info' member in `struct gdbarch_info' with an anonymous union,
comprising the original member, with its type reverted to `struct
gdbarch_tdep_info *', a `tdesc_data' member of a `struct tdesc_arch_data
*' type and an `id' member of an `int *' type.  Remove now unnecessary
casts throughout use places then, making code easier to read an less
prone to errors, which may happen with casting.

	gdb/
	* gdbarch.sh (gdbarch_info): Replace the `tdep_info' member with
	a union of `tdep_info', `tdesc_data' and `id'.
	* aarch64-tdep.c (aarch64_gdbarch_init): Use `info.tdesc_data'
	rather than `info.tdep_info'.
	* amd64-linux-tdep.c (amd64_linux_init_abi): Likewise.
	* i386-linux-tdep.c (i386_linux_init_abi): Likewise.
	* i386-tdep.c (i386_gdbarch_init): Likewise.
	* mips-linux-tdep.c (mips_linux_init_abi): Likewise.
	* mips-tdep.c (mips_gdbarch_init): Likewise.
	* nds32-tdep.c (nds32_gdbarch_init): Likewise.
	* rs6000-tdep.c (rs6000_gdbarch_init): Likewise.
	* ppc-linux-tdep.c (ppu2spu_sniffer): Use `info.id' rather than
	`info.tdep_info'.
	(ppc_linux_init_abi): Use `info.tdesc_data' rather than
	`info.tdep_info'.
	* sparc-tdep.c (sparc32_gdbarch_init): Likewise.
	* spu-multiarch.c (spu_gdbarch): Use `info.id' rather than
	`info.tdep_info'.
	* spu-tdep.c (spu_gdbarch_init): Likewise.
	* gdbarch.h: Regenerate.
2017-08-07 15:53:54 +01:00
Leszek Swirski 16eb6b2db4 Fix dwarf2_string_attr for -gsplit-dwarf
The dwarf2_string_attr did not allow DW_FORM_GNU_str_index as a form for
string types. This manifested as null strings in the namespace_name
lookup (replaced with "(anonymous namespace)") when debugging
Fission-compiled code.

gdb/ChangeLog:

	* dwarf2read.c (dwarf2_string_attr): Allow DW_FORM_GNU_strp_alt.
2017-08-07 16:40:46 +02:00
Simon Marchi 74cbb09e74 remote-sim.c: Fix arg variables conflicts
The recent change introducing gdb_argv introduced some build failures in
remote-sim.c.

  /home/emaisin/src/binutils-gdb/gdb/remote-sim.c: In function 'void gdbsim_load(target_ops*, const char*, int)':
  /home/emaisin/src/binutils-gdb/gdb/remote-sim.c:573:22: error: conflicting declaration 'gdb_argv argv'
     gdb_argv argv (args);
                        ^
  /home/emaisin/src/binutils-gdb/gdb/remote-sim.c:565:10: note: previous declaration as 'char** argv'
     char **argv;
            ^~~~
  /home/emaisin/src/binutils-gdb/gdb/remote-sim.c: In function 'void gdbsim_open(const char*, int)':
  /home/emaisin/src/binutils-gdb/gdb/remote-sim.c:730:25: error: declaration of 'gdb_argv args' shadows a parameter
     gdb_argv args (arg_buf);

In gdbsim_load, the new gdb_argv object conflicts with old char **argv
variable.  I think the old variable should be removed.

In gdbsim_open, the new gdb_argv object conflicts with the args
parameter.  This patch renames it to argv.

Built-tested for a mips host.

gdb/ChangeLog:

	* remote-sim.c (gdbsim_load): Remove char **argv local variable.
	(gdbsim_open): Rename gdb_argv args object to argv.
2017-08-07 12:13:00 +02:00
Tom Tromey ee0c32930c Use gdb::unique_xmalloc_ptr when calling tilde_expand
This patch changes most sites calling tilde_expand to use
gdb::unique_xmalloc_ptr, rather than a cleanup.  It also changes
scan_expression_with_cleanup to return a unique pointer, because the
patch was already touching code in that area.

Regression tested on the buildbot.

ChangeLog
2017-08-05  Tom Tromey  <tom@tromey.com>

	* compile/compile-object-load.c (compile_object_load): Use
	gdb::unique_xmalloc_ptr.
	* cli/cli-dump.c (scan_filename): Rename from
	scan_filename_with_cleanup.  Change return type.
	(scan_expression): Rename from scan_expression_with_cleanup.
	Change return type.
	(dump_memory_to_file, dump_value_to_file, restore_command):
	Use gdb::unique_xmalloc_ptr.  Update.
	* cli/cli-cmds.c (find_and_open_script): Use
	gdb::unique_xmalloc_ptr.
	* tracefile-tfile.c (tfile_open): Use gdb::unique_xmalloc_ptr.
	* symmisc.c (maintenance_print_symbols)
	(maintenance_print_msymbols): Use gdb::unique_xmalloc_ptr.
	* symfile.c (symfile_bfd_open, generic_load)
	(add_symbol_file_command, remove_symbol_file_command): Use
	gdb::unique_xmalloc_ptr.
	* source.c (openp): Use gdb::unique_xmalloc_ptr.
	* psymtab.c (maintenance_print_psymbols): Use
	gdb::unique_xmalloc_ptr.
	* corelow.c (core_open): Use gdb::unique_xmalloc_ptr.
	* breakpoint.c (save_breakpoints): Use gdb::unique_xmalloc_ptr.
	* solib.c (solib_map_sections): Use gdb::unique_xmalloc_ptr.
	(reload_shared_libraries_1): Likewise.
2017-08-05 15:52:49 -06:00
Tom Tromey fdffd6f411 Fix Rust test suite for 1.20 beta
I ran the gdb.rust tests against Rust 1.20 (beta) and saw a few
failures.  The failures all came because a particular item moved to a
different module.  Since the particular choice of module name isn't
important here, I simply widened the allowable results.

Tested locally against rustc 1.19, 1.20, and 1.21.

testsuite/ChangeLog
2017-08-05  Tom Tromey  <tom@tromey.com>

	* gdb.rust/simple.exp: Allow String to appear in a different
	namespace.
2017-08-05 15:38:32 -06:00
Tom Tromey 3232fabd2d Remove cleanups from Rust parser
This removes the few remaining cleanups in the Rust language code.
The main difficulty here was that the earlier code allocated VEC heads
on an obstack.  The new code instead introduces an object that
allocates and maintains the storage for whatever vectors are needed
during the parse.

Regression tested on the buildbot.

ChangeLog
2017-08-05  Tom Tromey  <tom@tromey.com>

	* rust-exp.y (rust_op_ptr, set_field): Remove typedefs.
	(rust_op_vector, rust_set_vector): New typedefs.
	(current_parser): New global.
	(work_obstack): Change to pointer type.  Update all users.
	(rust_ast, pstate): Remove globals.
	(struct rust_parser): New.
	(%union) <params, field_inits>: Change type.
	(start, tuple_expr, unit_expr, struct_expr_list, literal)
	(field_expr, expr_list, maybe_expr_list, type_list): Update.
	(ast_call_ish, ast_path, ast_function_type, ast_tuple_type)
	(convert_params_to_types, convert_params_to_expression): Change
	type of "params".
	(ast_string): Change type of "fields".
	(rust_parse): Make a rust_parser.  Remove cleanups.
	(rust_lex_tests): Make and install an auto_obstack.
2017-08-05 11:14:06 -06:00
Yao Qi f02fd7745d Unbreak GDBserver build for x32
When I verify my target description changes, I build GDB and GDBserver for
x32, but it failed.

/../../binutils-gdb/gdb/gdbserver/linux-amd64-ipa.c
../../../binutils-gdb/gdb/gdbserver/linux-amd64-ipa.c: In function ‘const target_desc* get_ipa_tdesc(int)’:
../../../binutils-gdb/gdb/gdbserver/linux-amd64-ipa.c:184:10: error: ‘X86_TDESC_AVX512’ was not declared in this scope
     case X86_TDESC_AVX512:
          ^
../../../binutils-gdb/gdb/gdbserver/linux-amd64-ipa.c:185:14: error: ‘tdesc_x32_avx512_linux’ was not declared in this scope
       return tdesc_x32_avx512_linux;
              ^
../../../binutils-gdb/gdb/gdbserver/linux-amd64-ipa.c: In function ‘void initialize_low_tracepoint()’:
../../../binutils-gdb/gdb/gdbserver/linux-amd64-ipa.c:282:36: error: ‘init_registers_x32_avx512_linux’ was not declared in this scope
   init_registers_x32_avx512_linux ();
                                    ^

ipa_x32_linux_regobj use to be there, but removed by
22049425ce by mistake.

gdb/gdbserver:

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

	* configure.srv (ipa_x32_linux_regobj): New.
	* linux-amd64-ipa.c (get_ipa_tdesc): Use X86_TDESC_AVX_AVX512
	instead of X86_TDESC_AVX512.
	(initialize_low_tracepoint): Call
	init_registers_x32_avx_avx512_linux.
2017-08-04 16:06:01 +01:00
Yao Qi 91975afd35 Add namespace std to nullptr_t
This patch fixes the build failure for target i686-w64-mingw32,

In file included from ../../binutils-gdb/gdb/defs.h:786:0,
                 from ../../binutils-gdb/gdb/gdb.c:19:
../../binutils-gdb/gdb/utils.h:188:20: error: ‘nullptr_t’ has not been declared
   bool operator!= (nullptr_t)
                    ^
../../binutils-gdb/gdb/utils.h:193:20: error: ‘nullptr_t’ has not been declared
   bool operator== (nullptr_t)
                    ^

gdb:

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

	* utils.h (gdb_argv): Add namespace std for nullptr_t.
2017-08-04 14:27:58 +01:00
Ruslan Kabatsayev 2331fa3af5 Add myself as a write-after-approval GDB maintainer. 2017-08-03 22:23:22 +03:00
Tom Tromey 744e4fe1db Remove make_cleanup_freeargv and gdb_buildargv
After the previous patches in this series, make_cleanup_freeargv and
gdb_buildargv are now unused and can be removed.

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

	* utils.c (make_cleanup_freeargv, do_freeargv, gdb_buildargv):
	Remove.
	* utils.h (make_cleanup_freeargv, gdb_buildargv): Remove.
2017-08-03 07:59:10 -06:00
Tom Tromey 1c034b67a0 Use gdb_argv in Python
This changes one spot in the Python code to use gdb_argv.  This
removes the last cleanup from the Python layer.

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

	* python/py-param.c (compute_enum_values): Use gdb_argv.
2017-08-03 07:59:09 -06:00
Tom Tromey 773a1edcd1 Introduce gdb_argv, a class wrapper for buildargv
This introduces gdb_argv, a class wrapping an "argv" pointer; that is,
a pointer to a NULL-terminated array of char*, where both the array
and each non-NULL element in the array are xmalloc'd.

This patch then changes most users of gdb_buildargv to use gdb_argv
instead.

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

	* utils.h (struct gdb_argv_deleter): New.
	(gdb_argv): New class.
	* utils.c (gdb_argv::reset): New method.
	* tracepoint.c (delete_trace_variable_command): Use gdb_argv.
	* tracefile.c (tsave_command): Use gdb_argv.
	* top.c (new_ui_command): Use gdb_argv.
	* symmisc.c (maintenance_print_symbols)
	(maintenance_print_msymbols, maintenance_expand_symtabs): Use gdb_argv.
	* symfile.c (symbol_file_command, generic_load)
	(remove_symbol_file_command): Use gdb_argv.
	* stack.c (backtrace_command): Use gdb_argv.
	* source.c (add_path, show_substitute_path_command)
	(unset_substitute_path_command, set_substitute_path_command):
	Use gdb_argv.
	* skip.c (skip_command): Use gdb_argv.  Use gdb_buildargv.
	* ser-mingw.c (pipe_windows_open): Use gdb_argv.
	* remote.c (extended_remote_run, remote_put_command)
	(remote_get_command, remote_delete_command): Use gdb_argv.
	* remote-sim.c (gdbsim_load, gdbsim_create_inferior)
	(gdbsim_open): Use gdb_argv.
	* python/py-cmd.c (gdbpy_string_to_argv): Use gdb_argv.
	* psymtab.c (maintenance_print_psymbols): Use gdb_argv.
	* procfs.c (procfs_info_proc): Use gdb_argv.
	* interps.c (interpreter_exec_cmd): Use gdb_argv.
	* infrun.c (handle_command): Use gdb_argv.
	* inferior.c (add_inferior_command, clone_inferior_command):
	Use gdb_argv.
	* guile/scm-string.c (gdbscm_string_to_argv): Use gdb_argv.
	* exec.c (exec_file_command): Use gdb_argv.
	* cli/cli-cmds.c (alias_command): Use gdb_argv.
	* compile/compile.c (build_argc_argv): Use gdb_argv.
2017-08-03 07:59:08 -06:00
Tom Tromey 0d50bde32b Remove a cleanup in Python
This removes cleanups from gdbpy_decode_line, in favor of a use of
unique_xmalloc_ptr.

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

	* python/python.c (gdbpy_decode_line): Use unique_xmalloc_ptr.
2017-08-03 07:59:07 -06:00
Tom Tromey 7f968c899f Avoid some manual memory management in Python
This changes a few places in the Python code to avoid manual memory
management, in favor of letting std::string do the work.

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

	* python/python.c (compute_python_string): Return std::string.
	(gdbpy_eval_from_control_command): Update.
	(do_start_initialization): Use std::string.
	* python/py-varobj.c (py_varobj_iter_next): Use string_printf, not
	xstrprintf.
	* python/py-breakpoint.c (local_setattro): Use string_printf, not
	xstrprintf.
2017-08-03 07:59:07 -06:00
Tom Tromey 3c9ebddd93 Replace do_restore_instream_cleanup with scoped_restore
This changes the users of do_restore_instream_cleanup to use a
scoped_restore instead.  This patch is broken out because it warrants
some additional attention: in particular it's unclear to me whether
current_ui can change in the body of these functions -- but if it can,
then the cleanup would have modified a different UI's instream member.

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

	* top.h (do_restore_instream_cleanup): Remove.
	* top.c (do_restore_instream_cleanup): Remove.
	(read_command_file): Use scoped_restore.
	* cli/cli-script.c (execute_user_command): Use scoped_restore.
2017-08-03 07:59:06 -06:00
Tom Tromey b51b225eb9 Use a scoped_restore for command_nest_depth
This changes a couple of places to use a scoped_restore when
manipulating command_nest_depth.

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

	* cli/cli-script.c (execute_user_command)
	(execute_control_command): Use scoped_restore.
2017-08-03 07:59:05 -06:00
Tom Tromey ac991630ca Remove user_call_depth
This changes execute_user_command to remove user_call_depth, using the
size of user_args_stack instead.  This avoids a cleanup.

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

	* cli/cli-script.c (do_restore_user_call_depth): Remove.
	(execute_user_command): Remove user_call_depth; use
	user_args_stack's size instead.
2017-08-03 07:59:04 -06:00
Tom Tromey 898e0c8e87 Remove in_user_command
While working on the next patch in this series, I found that the
global in_user_command is not used.  This patch removes it.  (I didn't
think to check Insight until submitting this series; and it's not very
convenient to do so, so if someone has it checked out and could look
at it, that would be nice.)

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

	* top.h (in_user_command): Remove.
	* top.c (in_user_command): Remove.
	* cli/cli-script.c (do_restore_user_call_depth)
	(execute_user_command): Update.
2017-08-03 07:59:03 -06:00
Tom Tromey 26fcd5d757 Use containers to avoid cleanups
This patch introduces the use of various containers -- std::vector,
std::string, or gdb::byte_vector -- in several spots in gdb that were
using xmalloc and a cleanup.

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

	* valops.c (search_struct_method): Use gdb::byte_vector.
	* valarith.c (value_concat): Use std::vector.
	* target.c (memory_xfer_partial): Use gdb::byte_vector.
	(simple_search_memory): Likewise.
	* printcmd.c (find_string_backward): Use gdb::byte_vector.
	* mi/mi-main.c (mi_cmd_data_write_memory): Use gdb::byte_vector.
	* gcore.c (gcore_copy_callback): Use gdb::byte_vector.
	* elfread.c (elf_rel_plt_read): Use std::string.
	* cp-valprint.c (cp_print_value): Use gdb::byte_vector.
	* cli/cli-dump.c (restore_section_callback): Use
	gdb::byte_vector.
2017-08-03 07:59:02 -06:00
Tom Tromey 7c218e6c9c Use unique_xmalloc_ptr in jit.c
This removes some cleanups from jit.c by using unique_xmalloc_ptr
instead.

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

	* jit.c (jit_reader_load_command): Use unique_xmalloc_ptr.
2017-08-03 07:59:01 -06:00
Tom Tromey 31b68d4ad7 Replace tui_restore_gdbout with scoped_restore
This patch replaces tui_restore_gdbout (a cleaup function) with a use
of scoped_restore.  This one is broken out into its own patch because
it might slightly change the behavior of gdb: it saves and restores
pagination_enabled, whereas the tui_restore_gdbout unconditionally set
pagination_enabled to 1; and I think this warrants closer review.

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

	* tui/tui-regs.c (tui_restore_gdbout): Remove.
	(tui_register_format): Use scoped_restore.
2017-08-03 07:59:01 -06:00
Tom Tromey 2ec845e758 More uses of scoped_restore
There were a few more places in gdb that could easily use
scoped_restore, replacing some cleanups.

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

	* reverse.c (exec_direction_default): Remove.
	(exec_reverse_once): Use scoped_restore.
	* remote.c (restore_remote_timeout): Remove.
	(remote_flash_erase, remote_flash_write, remote_flash_done)
	(readchar, remote_serial_write): Use scoped_restore.
	* cli/cli-script.c (struct source_cleanup_lines_args)
	(source_cleanup_lines): Remove.
	(script_from_file): Use scoped_restore.
	* cli/cli-cmds.c (source_verbose_cleanup): Remove.
	(source_command): Use scoped_restore.
2017-08-03 07:59:00 -06:00
Tom Tromey b3bc84537b Remove make_cleanup_free_so
make_cleanup_free_so is used in a single spot.  This patch introduces
a unique pointer wrapper for struct so_list, and changes this spot to
use it.

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

	* utils.h (make_cleanup_free_so): Remove.
	* utils.c (do_free_so, make_cleanup_free_so): Remove.
	* solist.h (struct so_deleter): New.
	(so_list_up): New typedef.
	* solib-svr4.c (svr4_read_so_list): Use so_list_up.
2017-08-03 07:58:59 -06:00
Tom Tromey e3ad2841b1 Remove make_cleanup_restore_current_language
This patch replaces make_cleanup_restore_current_language with an RAII
class that saves the current language, and restores it when the object
is destroyed.

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

	* utils.h (make_cleanup_restore_current_language): Remove.
	* utils.c (do_restore_current_language)
	(make_cleanup_restore_current_language): Remove.
	* parse.c (parse_exp_in_context_1)
	(parse_expression_with_language): Use
	scoped_restore_current_language.
	* mi/mi-main.c (mi_cmd_execute): Use
	scoped_restore_current_language.
	* language.h (scoped_restore_current_language): New class.
2017-08-03 07:58:58 -06:00
Tom Tromey b80cf83844 Remove an unlink cleanup
compile/compile.c had its own cleanup to unlink a file.  This patch
replaces this cleanup with gdb::unlinker.

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

	* compile/compile.c (cleanup_unlink_file): Remove.
	(compile_to_object): Use gdb::unlinker.
	(eval_compile_command): Likewise.
2017-08-03 07:58:57 -06:00
Tom Tromey fad0444a57 Remove make_cleanup_fclose
After the preceding patches, make_cleanup_fclose is no longer used, so
remove it.

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

	* utils.h (make_cleanup_fclose): Remove.
	* utils.c (do_fclose_cleanup, make_cleanup_fclose): Remove.
2017-08-03 07:58:56 -06:00
Tom Tromey 6e7bc05c53 Change open_terminal_stream to return a gdb_file_up
This changes open_terminal_stream to return a gdb_file_up, eliminating
another use of make_cleanup_fclose.  Arguably perhaps new_ui should
take ownership of the files using a move, but there is at least one
spot where this isn't appropriate (or at least not currently done), so
I elected to use a more minimal approach.

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

	* top.c (open_terminal_stream): Return gdb_file_up.
	(new_ui_command): Update.
2017-08-03 07:58:55 -06:00
Tom Tromey 4a45905b82 Use gdb_file_up in source.c
This changes some functions in source.c to use gdb_file_up.

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

	* source.c (print_source_lines_base, forward_search_command)
	(reverse_search_command): Use gdb_file_up.
2017-08-03 07:58:54 -06:00
Tom Tromey 7cd06d6e89 Use gdb_file_up in fbsd-nat.c
This updates fbsd-nat.c to use gdb_file_up.  This removes a use of a
cleanup, and helps remove make_cleanup_fclose in a later patch.

I have no way to test this patch.

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

	* fbsd-nat.c (fbsd_find_memory_regions): Update.
2017-08-03 07:58:54 -06:00
Tom Tromey ed1669453b Change return type of find_and_open_script
This changes find_and_open_script to return a
gdb::optional<open_script>, where open_script is a new type
encapsulating the two return values.  The new type helps avoid
cleanups in the callers.

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

	* cli/cli-cmds.c (find_and_open_script): Change return type.
	Remove "streamp" and "full_path" parameters.
	(source_script_with_search): Update.
	* auto-load.c (source_script_file): Update.
	* cli/cli-cmds.h (find_and_open_script): Change type.
	(open_script): New struct.
2017-08-03 07:58:53 -06:00
Tom Tromey d419f42dd3 Introduce and use gdb_file_up
This introduces gdb_file_up, a unique pointer holding a FILE*, and
then changes some code in gdb to use it.  In particular
gdb_fopen_cloexec now returns a gdb_file_up.  This allow removing some
cleanups.

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

	* xml-support.c (xml_fetch_content_from_file): Update.
	* ui-file.c (stdio_file::open): Update.
	* tracefile-tfile.c (tfile_start): Update.
	* remote.c (remote_file_put, remote_file_get): Update.
	* nat/linux-procfs.c (linux_proc_get_int)
	(linux_proc_pid_get_state, linux_proc_tid_get_name): Update.
	* nat/linux-osdata.c (linux_common_core_of_thread): Update.
	(command_from_pid, commandline_from_pid, linux_xfer_osdata_cpus)
	(print_sockets, linux_xfer_osdata_shm, linux_xfer_osdata_sem)
	(linux_xfer_osdata_msg, linux_xfer_osdata_modules): Update.
	* nat/linux-btrace.c (linux_determine_kernel_start): Update.
	* linux-nat.c (linux_proc_pending_signals): Update.
	* dwarf2read.c (write_psymtabs_to_index): Use gdb_file_up.
	(file_closer): Remove.
	* compile/compile.c (compile_to_object): Update.
	* common/filestuff.h (struct gdb_file_deleter): New.
	(gdb_file_up): New typedef.
	(gdb_fopen_cloexec): Change return type.
	* common/filestuff.c (gdb_fopen_cloexec): Return gdb_file_up.
	* cli/cli-dump.c (fopen_with_cleanup): Remove.
	(dump_binary_file, restore_binary_file): Update.
	* auto-load.c (auto_load_objfile_script_1): Update.
2017-08-03 07:58:52 -06:00
Tom Tromey 4a2b031d54 Introduce and use ui_out_emit_table
This introduces ui_out_emit_table, similar to the other existing
ui_out RAII classes, and then uses it in a number of places.  This
replaces some cleanups.

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

	* tracepoint.c (tvariables_info_1): Use ui_out_emit_table.
	(info_static_tracepoint_markers_command): Likewise.
	* solib.c (info_sharedlibrary_command): Use ui_out_emit_table.
	* skip.c (skip_info): Use ui_out_emit_table.
	* progspace.c (print_program_space): Use ui_out_emit_table.
	* osdata.c (info_osdata): Use ui_out_emit_table.
	* mi/mi-cmd-info.c (mi_cmd_info_ada_exceptions): Use
	ui_out_emit_table.
	* linux-thread-db.c (info_auto_load_libthread_db): Use
	ui_out_emit_table.
	* inferior.c (print_inferior): Use ui_out_emit_table.
	* gdb_bfd.c (maintenance_info_bfds): Use ui_out_emit_table.
	* breakpoint.c (breakpoint_1): Use ui_out_emit_table.
	* auto-load.c (auto_load_info_scripts): Use ui_out_emit_table.
	* ada-tasks.c (print_ada_task_info): Use ui_out_emit_table.
	* ui-out.h (class ui_out_emit_table): New.
2017-08-03 07:58:51 -06:00
Maciej W. Rozycki a4f320fd1b MIPS: Factor out FPU type naming in `gdbarch' debug
Replace chains of conditional expressions used in target-dependent MIPS
`gdbarch' debug output to get a textual name of the FPU type with calls
to a helper decoder function, improving code readability.  No functional
change.

	gdb/
	* mips-tdep.c (mips_fpu_type_str): New function.
	(mips_dump_tdep): Call it.
2017-08-02 16:40:16 +01:00
Maciej W. Rozycki a2f1f30853 MIPS: Consistently use MIPS_FPU_TYPE for `gdbarch' member
Complement commit 74ed0bb414 ("Replace current_gdbarch in *mips*"),
<https://sourceware.org/ml/gdb-patches/2008-06/msg00490.html>, and
consistently use the MIPS_FPU_TYPE macro to access the `->mips_fpu_type'
target-dependent `gdbarch' member.  No functional change.

	gdb/
	* mips-tdep.c (mips_gdbarch_init): Use MIPS_FPU_TYPE to access
	`->mips_fpu_type'.
2017-08-01 19:32:25 +01:00
Xavier Roirand 7e5ed83b22 Update ChangeLog (missed that in my previous commit)
gdb/
        * ChangeLog: Add previous commit entry

Change-Id: Ic4f07cca66126e73340f032f19a2d5029bf0d40a
2017-07-31 14:37:33 +02:00
Simon Marchi 791fb3d7a5 Fix documentation about rot agent expression bytecode
The rot agent expression bytecode rotates the three items on the top of
the stack.  It is not clear which way the rotation is.  However, the
documentation currently shows this as the effect of the instructions:

   a b c => c b a

which doesn't make sense, since the value b doesn't move.  The two
valid possibilities I see are

  a b c => b c a
  a b c => c a b

depending on which way you rotate.

When looking at the gdbserver code, the top of the stack becomes the
third item, and the next-to-top item becomes the top.  So the second
form would be the right one, since in this notation the top of the stack
is the rightmost element:

  a b c => c a b

I adjusted the symbolic description and added a bit of text to make it
more obvious.

gdb/doc/ChangeLog:

	* agentexpr.texi (rot): Fix symbolic description, improve
	textual description.
2017-07-31 11:26:50 +02:00
Xavier Roirand 4bbd4ef219 darwin: handle recent version of dyld
gdb/
        * solib-darwin.c (DYLD_VERSION_MAX): Increase value.

Change-Id: I45da25f46b3e452d44993b122a994c818d00020b
2017-07-31 11:10:14 +02:00
Xavier Roirand 4c9dc81149 Add myself as a write-after-approval GDB maintainer.
gdb/Changelog:

2017-07-27  Xavier Roirand  <roirand@adacore.com>

        * MAINTAINERS (Write After Approval): Add Xavier Roirand.

Change-Id: Iee1dae7597da8f2c8c3098c14649ff400a81a388
2017-07-27 16:06:55 +02:00
Yao Qi 27d41eac62 Add "maint check xml-descriptions" to test builtin xml target descriptions
Now, GDB is able to dynamically create i386-linux target descriptions
from features, instead of using pre-generated target descriptions.  These
pre-generated target descriptions are no longer used by GDB (note that
they are still used by GDBserver).

This patch add a new maint command "maint check xml-descriptions" to test
dynamically generated tdesc are identical to these generated from xml files.

gdb:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* cli/cli-cmds.c (maintenancechecklist): New variable.
	* gdbcmd.h (maintenancechecklist): Declare it.
	* i386-linux-tdep.c (_initialize_i386_linux_tdep) [GDB_SELF_TEST]:
	Call i386_linux_read_description with different masks.
	* maint.c (maintenance_check_command): New function.
	(_initialize_maint_cmds): Call add_prefix_cmd.
	* target-descriptions.c (tdesc_reg): override operator != and ==.
	(tdesc_type): Likewise.
	(tdesc_feature): Likewise.
	(target_desc): Likewise.
	[GDB_SELF_TEST] (selftests::record_xml_tdesc): New function.
	(maintenance_check_xml_descriptions): New function.
	(_initialize_target_descriptions) Add command "xml-descriptions".
	* target-descriptions.h (selftests::record_xml_tdesc): Declare.

gdb/testsuite:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* gdb.gdb/unittest.exp: Invoke command
	"maintenance check xml-descriptions".

gdb/doc:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* gdb.texinfo (Maintenance Commands): Document command
	"maint check xml-descriptions".
2017-07-26 14:55:31 +01:00
Yao Qi ea03d0d3c3 Lazily and dynamically create i386-linux target descriptions
Instead of using pre-generated target descriptions, this patch
changes GDB to lazily and dynamically create target descriptions
according to the target hardware capability (xcr0 in i386).
This support any combination of target features.

Some reg in target description has "regnum" attribute, so its register
number is got from the attribute value instead from sequential allocation.

  <reg name="xmm0" bitsize="128" type="vec128" regnum="32"/>

when target description is created, it should match the regnum, so this
patch adds a new field m_next_regnum to track it, if attribute number is
greater than the m_next_regnum, print the code to set register number
explicitly.

gdb:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* i386-linux-tdep.c: Don't include features/i386/i386-*linux.c.
	Include features/i386/32bit-*.c.
	(i386_linux_read_description): Generate target description if it
	doesn't exist.
	(_initialize_i386_linux_tdep): Don't call _initialize_tdesc_i386
	functions.
	* features/i386/32bit-linux.c: Re-generated.
	* features/i386/32bit-sse.c: Likewise.
	* target-descriptions.c (print_c_feature::visit): Print code to
	set register number if needed.
	(print_c_feature) <m_next_regnum>: New field.
2017-07-26 14:39:54 +01:00
Yao Qi 25aa13e522 Generate c for feature instead of tdesc
This patch changes Makefile and command "maint print c-files" so
that GDB can print c files for features instead target description.
Previously, we feed GDB a target description xml file, which generate
c files including multiple features.

With this patch, in Makefile, we wrap each feature xml file, and
create a temp target description which include only one feature.
Then, adjust the target description printer for them, and print
a c function for each given feature, so that we can use these
c functions later to create target description in a flexible way.

gdb:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* features/Makefile (CFILES): Rename with TDESC_CFILES.
	(FEATURE_XMLFILES): New.
	(FEATURE_CFILES): New.
	New rules.
	(clean-cfiles): Remove generated c files.
	* features/i386/32bit-avx.c: Generated.
 	* features/i386/32bit-avx512.c: Generated.
 	* features/i386/32bit-core.c: Generated.
 	* features/i386/32bit-linux.c: Generated.
 	* features/i386/32bit-mpx.c: Generated.
 	* features/i386/32bit-pkeys.c: Generated.
 	* features/i386/32bit-sse.c: Generated.
 	* target-descriptions.c: Include algorithm.
	(tdesc_element_visitor): Add method visit_end.
	(print_c_tdesc): Implement visit_end.
	(print_c_tdesc:: m_filename_after_features): Move it to
	protected.
	(print_c_feature): New class.
	(maint_print_c_tdesc_cmd): Use print_c_feature if XML file
	name starts with "i386/32bit-".
2017-07-26 14:24:08 +01:00
Yao Qi 6eb1e6a8c1 Use visitor pattern for "maint print c-tdesc"
Target description can be modeled as a tree, the target description
is the root node, features are children nodes, registers and types are
grand-children nodes.  So command "maint print c-tdesc" in effect
traverse/visit each node, and print them in c.  This can be
implemented by visitor pattern, this is the first reason.  Secondly,
I want to this command prints c files in a different way for some
specific xml files, but still print c files the same way for the rest
of xml files.  Third, I even want to print xml files from target
descriptions, so that GDBserver can use it to reply GDB's query
qXfer:features:read:target.xml.

gdb:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* target-descriptions.c (tdesc_element_visitor): New class.
	(tdesc_element): New class.
	(tdesc_reg): Inherit from tdesc_element.
	(tdesc_reg::accept): New function.
	(tdesc_type): Inherit from tdesc_element.
	(tdesc_type::accept): New function.
	(tdesc_feature): Inherit from tdesc_element.
	(tdesc_feature::accept): New function.
	(target_desc): Inherit from tdesc_element.
	(target_desc::target_desc): New.
	(target_desc::~target_desc): New.
	(target_desc::accept): New.
	(allocate_target_description): Use new.
	(free_target_description): Use delete.
	(print_c_tdesc): New class.
	(maint_print_c_tdesc_cmd): Adjust.

	* features/aarch64.c: Re-generated.
	* features/arc-arcompact.c: Re-generated.
	* features/arc-v2.c: Re-generated.
	* features/arm/arm-with-iwmmxt.c: Re-generated.
	* features/arm/arm-with-m.c: Re-generated.
	* features/arm/arm-with-m-fpa-layout.c: Re-generated.
	* features/arm/arm-with-m-vfp-d16.c: Re-generated.
	* features/arm/arm-with-neon.c: Re-generated.
	* features/arm/arm-with-vfpv2.c: Re-generated.
	* features/arm/arm-with-vfpv3.c: Re-generated.
	* features/i386/amd64-avx-avx512.c: Re-generated.
	* features/i386/amd64-avx-avx512-linux.c: Re-generated.
	* features/i386/amd64-avx.c: Re-generated.
	* features/i386/amd64-avx-linux.c: Re-generated.
	* features/i386/amd64-avx-mpx-avx512-pku.c: Re-generated.
	* features/i386/amd64-avx-mpx-avx512-pku-linux.c: Re-generated.
	* features/i386/amd64-avx-mpx.c: Re-generated.
	* features/i386/amd64-avx-mpx-linux.c: Re-generated.
	* features/i386/amd64.c: Re-generated.
	* features/i386/amd64-linux.c: Re-generated.
	* features/i386/amd64-mpx.c: Re-generated.
	* features/i386/amd64-mpx-linux.c: Re-generated.
	* features/i386/i386-avx-avx512.c: Re-generated.
	* features/i386/i386-avx-avx512-linux.c: Re-generated.
	* features/i386/i386-avx.c: Re-generated.
	* features/i386/i386-avx-linux.c: Re-generated.
	* features/i386/i386-avx-mpx-avx512-pku.c: Re-generated.
	* features/i386/i386-avx-mpx-avx512-pku-linux.c: Re-generated.
	* features/i386/i386-avx-mpx.c: Re-generated.
	* features/i386/i386-avx-mpx-linux.c: Re-generated.
	* features/i386/i386.c: Re-generated.
	* features/i386/i386-linux.c: Re-generated.
	* features/i386/i386-mmx.c: Re-generated.
	* features/i386/i386-mmx-linux.c: Re-generated.
	* features/i386/i386-mpx.c: Re-generated.
	* features/i386/i386-mpx-linux.c: Re-generated.
	* features/i386/x32-avx-avx512.c: Re-generated.
	* features/i386/x32-avx-avx512-linux.c: Re-generated.
	* features/i386/x32-avx.c: Re-generated.
	* features/i386/x32-avx-linux.c: Re-generated.
	* features/i386/x32.c: Re-generated.
	* features/i386/x32-linux.c: Re-generated.
	* features/microblaze.c: Re-generated.
	* features/microblaze-with-stack-protect.c: Re-generated.
	* features/mips64-dsp-linux.c: Re-generated.
	* features/mips64-linux.c: Re-generated.
	* features/mips-dsp-linux.c: Re-generated.
	* features/mips-linux.c: Re-generated.
	* features/nds32.c: Re-generated.
	* features/nios2.c: Re-generated.
	* features/nios2-linux.c: Re-generated.
	* features/rs6000/powerpc-32.c: Re-generated.
	* features/rs6000/powerpc-32l.c: Re-generated.
	* features/rs6000/powerpc-403.c: Re-generated.
	* features/rs6000/powerpc-403gc.c : Re-generated.
	* features/rs6000/powerpc-405.c: Re-generated.
	* features/rs6000/powerpc-505.c: Re-generated.
	* features/rs6000/powerpc-601.c: Re-generated.
	* features/rs6000/powerpc-602.c: Re-generated.
	* features/rs6000/powerpc-603.c: Re-generated.
	* features/rs6000/powerpc-604.c: Re-generated.
	* features/rs6000/powerpc-64.c: Re-generated.
	* features/rs6000/powerpc-64l.c: Re-generated.
	* features/rs6000/powerpc-7400.c: Re-generated.
	* features/rs6000/powerpc-750.c: Re-generated.
	* features/rs6000/powerpc-860.c: Re-generated.
	* features/rs6000/powerpc-altivec32.c: Re-generated.
	* features/rs6000/powerpc-altivec32l.c: Re-generated.
	* features/rs6000/powerpc-altivec64.c: Re-generated.
	* features/rs6000/powerpc-altivec64l.c: Re-generated.
	* features/rs6000/powerpc-cell32l.c: Re-generated.
	* features/rs6000/powerpc-cell64l.c: Re-generated.
	* features/rs6000/powerpc-e500.c: Re-generated.
	* features/rs6000/powerpc-e500l.c: Re-generated.
	* features/rs6000/powerpc-isa205-32l.c: Re-generated.
	* features/rs6000/powerpc-isa205-64l.c: Re-generated.
	* features/rs6000/powerpc-isa205-altivec32l.c: Re-generated.
	* features/rs6000/powerpc-isa205-altivec64l.c: Re-generated.
	* features/rs6000/powerpc-isa205-vsx32l.c: Re-generated.
	* features/rs6000/powerpc-isa205-vsx64l.c: Re-generated.
	* features/rs6000/powerpc-vsx32.c: Re-generated.
	* features/rs6000/powerpc-vsx32l.c: Re-generated.
	* features/rs6000/powerpc-vsx64.c: Re-generated.
	* features/rs6000/powerpc-vsx64l.c: Re-generated.
	* features/rs6000/rs6000.c: Re-generated.
	* features/s390-linux32.c: Re-generated.
	* features/s390-linux32v1.c: Re-generated.
	* features/s390-linux32v2.c: Re-generated.
	* features/s390-linux64.c: Re-generated.
	* features/s390-linux64v1.c: Re-generated.
	* features/s390-linux64v2.c: Re-generated.
	* features/s390-te-linux64.c: Re-generated.
	* features/s390-tevx-linux64.c: Re-generated.
	* features/s390-vx-linux64.c: Re-generated.
	* features/s390x-linux64.c: Re-generated.
	* features/s390x-linux64v1.c: Re-generated.
	* features/s390x-linux64v2.c: Re-generated.
	* features/s390x-te-linux64.c: Re-generated.
	* features/s390x-tevx-linux64.c: Re-generated.
	* features/s390x-vx-linux64.c: Re-generated.
	* features/sparc/sparc32-solaris.c: Re-generated.
	* features/sparc/sparc64-solaris.c: Re-generated.
	* features/tic6x-c62x.c: Re-generated.
	* features/tic6x-c62x-linux.c: Re-generated.
	* features/tic6x-c64x.c: Re-generated.
	* features/tic6x-c64x-linux.c: Re-generated.
	* features/tic6x-c64xp.c: Re-generated.
	* features/tic6x-c64xp-linux.c: Re-generated.
2017-07-26 12:56:54 +01:00
Yao Qi 35b4818d03 Centralize i386 linux target descriptions
This patch moves all the tdesc_i386*_linux target descriptions to a
function i386_linux_read_description, which returns the right target
description according to xcr0.  This also remove the duplication in
getting target descriptions in corefile and native target.

gdb:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* i386-linux-tdep.c (i386_linux_read_description): New function.
	(i386_linux_core_read_description): Call
	i386_linux_read_description.
	* i386-linux-tdep.h (i386_linux_read_description): Declare.
	(tdesc_i386_linux, tdesc_i386_mmx_linux): Remove declarations.
	(tdesc_i386_avx_linux, tdesc_i386_mpx_linux): Likewise
	(tdesc_i386_avx_mpx_linux, tdesc_i386_avx_avx512_linux): Likewise.
	(tdesc_i386_avx_mpx_avx512_pku_linux): Likewise.
	* x86-linux-nat.c (x86_linux_read_description): Call
	i386_linux_read_description.
2017-07-26 12:36:42 +01:00
Yao Qi 8e2141c6fb Add optional argument to command "maint prints c-tdesc"
Nowadays, we need two steps to print c files for xml target description,
that is, 1) read xml target description in, update the current tdesc,
2) visit the current tdesc, print the c file.  It is unnecessary to
involve in current tdesc, and some validations in each gdbarch are
performed unnecessarily, which will reject some target descriptions if
they are missing some mandatory feature.

This patch adds an optional argument to "maint print c-tdesc", which
is an XML file target description, so that we can combine the two
steps above into one step, and don't have to involve in global current
tdesc.

gdb:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* NEWS: Mention it.
	* features/Makefile (%.c: %.xml): Pass the xml file name to
	command "maint print c-tdesc".
	* target-descriptions.c (maint_print_c_tdesc_cmd): Get file
	name from 'arg'.

gdb/doc:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* gdb.texinfo (Maintenance Commands): Document optional
	argument of "maint print c-tdesc".
2017-07-26 12:03:47 +01:00
Yao Qi b468ff4cbf Class-fy target_desc
This patch adds ctor and dtor in target_desc.

gdb:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* target-descriptions.c (target_desc): Add ctor and dtor.  Do
	in-class initialization.
	(tdesc_create_feature): Call new instead of XCNEW.
	(free_target_description): Ue delete.
2017-07-26 10:37:17 +01:00
Simon Marchi 229d26fc9e Add enum for result of fast_tracepoint_collecting
I got confused by the result value of fast_tracepoint_collecting, while
it sounds like it would return true/false (whether the thread is
collecting or not), it actually returns:

  0: not collecting
  1: in the jump pad, before the relocated instruction
  2: in the jump pad, at or after the relocated instruction

To avoid confusion, I think it would be nice to make it return an enum.
If you can help find a shorter but still relavant name, it would be
awesome.  Otherwise, we'll go with that, fast_tpoint_collect_result,
which is at least consistent with the existing
fast_tpoint_collect_status.

gdb/gdbserver/ChangeLog:

	* tracepoint.h (enum class fast_tpoint_collect_result): New
	enumeration.
	(fast_tracepoint_collecting): Change return type to
	fast_tpoint_collect_result.
	* tracepoint.c (fast_tracepoint_collecting): Likewise.
	* linux-low.h: Include tracepoint.h.
	(struct lwp_info) <collecting_fast_tracepoint>: Change type to
	fast_tpoint_collect_result.
	* linux-low.c (handle_tracepoints): Adjust.
	(linux_fast_tracepoint_collecting): Change return type to
	fast_tpoint_collect_result.
	(maybe_move_out_of_jump_pad, linux_wait_for_event_filtered,
	linux_wait_1, stuck_in_jump_pad_callback,
	lwp_signal_can_be_delivered, linux_resume_one_lwp_throw,
	proceed_one_lwp): Adjust to type change.
2017-07-26 10:57:07 +02:00
John Baldwin b9c0e1b40e Fix two NetBSD-specific typos in the configure.nat conversion.
- Add the '-lkvm' library requirement for NetBSD/sparc64.
- Fix spelling of 'nbsdelf' host.

gdb/Changelog:

	* configure.nat: Add "-lkvm" for NetBSD/sparc64 and fix typo.
2017-07-25 09:40:44 -07:00
Yao Qi a04b53379a Make amd64_x32_init_abi and amd64_init_abi argument constant
gdb:

2017-07-25  Yao Qi  <yao.qi@linaro.org>

	* amd64-tdep.c (amd64_init_abi): Make argument default_tdesc
	constant.
	(amd64_x32_init_abi): Likewise.
	* amd64-tdep.h (amd64_init_abi): Update declaration.
	(amd64_x32_init_abi): Likewise.
2017-07-25 15:25:38 +01:00
Yao Qi 46a62268b8 Catch exceptions thrown from gdbarch_skip_prologue
PR 21555 is caused by the exception during the prologue analysis when re-set
a breakpoint.

(gdb) bt
 #0  memory_error_message (err=TARGET_XFER_E_IO, gdbarch=0x153db50, memaddr=93824992233232) at ../../binutils-gdb/gdb/corefile.c:192
 #1  0x00000000005718ed in memory_error (err=TARGET_XFER_E_IO, memaddr=memaddr@entry=93824992233232) at ../../binutils-gdb/gdb/corefile.c:220
 #2  0x00000000005719d6 in read_memory_object (object=object@entry=TARGET_OBJECT_CODE_MEMORY, memaddr=93824992233232, memaddr@entry=1, myaddr=myaddr@entry=0x7fffffffd0a0 "P\333S\001", len=len@entry=1) at ../../binutils-gdb/gdb/corefile.c:259
 #3  0x0000000000571c6e in read_code (len=1, myaddr=0x7fffffffd0a0 "P\333S\001", memaddr=<optimized out>) at ../../binutils-gdb/gdb/corefile.c:287
 #4  read_code_unsigned_integer (memaddr=memaddr@entry=93824992233232, len=len@entry=1, byte_order=byte_order@entry=BFD_ENDIAN_LITTLE)                          at ../../binutils-gdb/gdb/corefile.c:362
 #5  0x000000000041d4a0 in amd64_analyze_prologue (gdbarch=gdbarch@entry=0x153db50, pc=pc@entry=93824992233232, current_pc=current_pc@entry=18446744073709551615, cache=cache@entry=0x7fffffffd1e0) at ../../binutils-gdb/gdb/amd64-tdep.c:2310
 #6  0x000000000041e404 in amd64_skip_prologue (gdbarch=0x153db50, start_pc=93824992233232) at ../../binutils-gdb/gdb/amd64-tdep.c:2459
 #7  0x000000000067bfb0 in skip_prologue_sal (sal=sal@entry=0x7fffffffd4e0) at ../../binutils-gdb/gdb/symtab.c:3628
 #8  0x000000000067c4d8 in find_function_start_sal (sym=sym@entry=0x1549960, funfirstline=1) at ../../binutils-gdb/gdb/symtab.c:3501
 #9  0x000000000060999d in symbol_to_sal (result=result@entry=0x7fffffffd5f0, funfirstline=<optimized out>, sym=sym@entry=0x1549960) at ../../binutils-gdb/gdb/linespec.c:3860
....
 #16 0x000000000054b733 in location_to_sals (b=b@entry=0x15792d0, location=0x157c230, search_pspace=search_pspace@entry=0x1148120, found=found@entry=0x7fffffffdc64) at ../../binutils-gdb/gdb/breakpoint.c:14211
 #17 0x000000000054c1f5 in breakpoint_re_set_default (b=0x15792d0) at ../../binutils-gdb/gdb/breakpoint.c:14301
 #18 0x00000000005412a9 in breakpoint_re_set_one (bint=bint@entry=0x15792d0) at ../../binutils-gdb/gdb/breakpoint.c:14412

This problem can be fixed by

 - either each prologue analyzer doesn't throw exception,
 - or catch the exception thrown from gdbarch_skip_prologue,

I choose the latter because the former needs to fix *every* prologue
analyzer to not throw exception.

This error can be reproduced by changing reread.exp.  The test reread.exp
has already test that breakpoint can be reset correctly after the
executable is re-read.  This patch extends this test by compiling test c
file with and without -fPIE.

(gdb) run ^M
The program being debugged has been started already.^M
Start it from the beginning? (y or n) y^M
x86_64/gdb/testsuite/outputs/gdb.base/reread/reread' has changed; re-reading symbols.
Error in re-setting breakpoint 1: Cannot access memory at address 0x555555554790^M
Error in re-setting breakpoint 2: Cannot access memory at address 0x555555554790^M
Starting program: /scratch/yao/gdb/build-git/x86_64/gdb/testsuite/outputs/gdb.base/reread/reread ^M
This is foo^M
[Inferior 1 (process 27720) exited normally]^M
(gdb) FAIL: gdb.base/reread.exp: opts= "-fPIE" "ldflags=-pie" : run to foo() second time (the program exited)

This patch doesn't re-indent the code, to keep the patch simple.

gdb:

2017-07-25  Yao Qi  <yao.qi@linaro.org>

	PR gdb/21555
	* arch-utils.c (gdbarch_skip_prologue_noexcept): New function.
	* arch-utils.h (gdbarch_skip_prologue_noexcept): Declare.
	* infrun.c: Include arch-utils.h
	(handle_step_into_function): Call gdbarch_skip_prologue_noexcept.
	(handle_step_into_function_backward): Likewise.
	* symtab.c (skip_prologue_sal): Likewise.

gdb/testsuite:

2017-07-25  Yao Qi  <yao.qi@linaro.org>

	PR gdb/21555
	* gdb.base/reread.exp: Wrap the whole test with two kinds of
	compilation flags, with -fPIE and without -fPIE.
2017-07-25 11:38:50 +01:00
Yao Qi 02ad7fc29f [ARM] Access FPSCR on vfpv2
GDB can fetch or store FPSCR on vfpv3, which has 32 VFP registers, but
fail to do so on vfpv2, which has 16 VFP registers.  GDB code is incorrect
for vfpv2,

       else if (tdep->vfp_register_count > 0
 	       && regno >= ARM_D0_REGNUM
	       && regno <= ARM_D0_REGNUM + tdep->vfp_register_count)

while FPSCR register number is defined as ARM_D0_REGNUM + 32.

  ARM_D0_REGNUM,		/* VFP double-precision registers.  */
  ARM_D31_REGNUM = ARM_D0_REGNUM + 31,
  ARM_FPSCR_REGNUM,

The code above uses "<=" rather than "<", in order to put FPSCR in the
range, but it is only correct when tdep->vfp_register_count is 32.  On
vpfv2, it is 16, and FPSCR is out of the range, so fetch_vfp_regs or
store_vfp_regs are not called.

gdb:

2017-07-25  Yao Qi  <yao.qi@linaro.org>

	PR tdep/21717
	* arm-linux-nat.c (arm_linux_fetch_inferior_registers): Update
	condition for FPSCR.
	(arm_linux_store_inferior_registers): Likewise.
2017-07-25 10:05:58 +01:00
Andreas Arnez 031ed05dd2 s390-vregs.exp: Fix Tcl error after non-zero-pad patch
s390-vregs.exp yields a Tcl error:

  ERROR: can't read "i": no such variable
      while executing
  "expr $a_high * ($i + 1) * $a_high "
      (procedure "hex128" line 2)
      invoked from within
  "hex128 $a_high $a_low $b_high $b_low"
  ...

This is a regression, caused by commit 30a254669b -- "Don't always
zero pad in print_*_chars".  That patch introduced a new procedure
"hex128" for formatting a 128-bit value as hex, but it accidentally moved
the calculation of the 128-bit value into that new procedure as well
instead of leaving it in the original context.  This is fixed.

gdb/testsuite/ChangeLog:

	* gdb.arch/s390-vregs.exp: Calculate parameters to hex128 in the
	calling context.
	(hex128): Drop erroneous calculation of parameters.
2017-07-24 18:35:30 +02:00
Tom Tromey b6f48cb022 Use std::vector in struct catch_syscall_inferior_data
This changes struct catch_syscall_inferior_data to use a std::vector
rather than a VEC.  It also changes it to be allocated with new and
destroyed with delete.

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

	* break-catch-syscall.c (struct catch_syscall_inferior_data)
	<syscalls_counts>: Now a std::vector.
	(get_catch_syscall_inferior_data): Use "new".
	(catch_syscall_inferior_data_cleanup): Use "delete".
	(insert_catch_syscall, remove_catch_syscall)
	(clear_syscall_counts): Update.
2017-07-22 16:10:42 -06:00
Tom Tromey e12c9b7a0c Use std::vector in syscall_catchpoint
This changes syscall_catchpoint to use a std::vector rather than a VEC
for "syscalls_to_be_caught".  This simplifies the code a bit.

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

	* break-catch-syscall.c (syscall_catchpoint)
	<syscalls_to_be_caught>: Now a std::vector<int>
	(~syscall_catchpoint): Remove.
	(insert_catch_syscall, remove_catch_syscall)
	(breakpoint_hit_catch_syscall, print_one_catch_syscall)
	(print_mention_catch_syscall, print_recreate_catch_syscall):
	Update.
	(create_syscall_event_catchpoint): Change type of "filter"
	parameter.
	(catch_syscall_split_args): Return a std::vector.
	(catch_syscall_command_1, catching_syscall_number_1): Update.
2017-07-22 16:10:42 -06:00
Tom Tromey 4fa8aeac19 C++-ify break-catch-throw
This changes exception_catchpoint's "exception_rx' member to be a
std::string, and updating the users.

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

	* break-catch-throw.c (struct exception_catchpoint)
	<exception_rx>: Now a std::string.
	(~exception_catchpoint): Remove.
	(print_one_detail_exception_catchpoint): Update.
	(handle_gnu_v3_exceptions): Change type of except_rx.
	(extract_exception_regexp): Return a std::string.
	(catch_exception_command_1): Update.
2017-07-22 16:10:41 -06:00
Tom Tromey f746a15444 C++-ify break-catch-sig
This changes signal_catchpoint to be more of a C++ class, using
std::vector and updating the users.

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

	* break-catch-sig.c (gdb_signal_type): Remove typedef.
	(struct signal_catchpoint) <signals_to_be_caught>: Now a
	std::vector.
	<catch_all>: Now a bool.
	(~signal_catchpoint): Remove.
	(signal_catchpoint_insert_location)
	(signal_catchpoint_remove_location)
	(signal_catchpoint_breakpoint_hit, signal_catchpoint_print_one)
	(signal_catchpoint_print_mention)
	(signal_catchpoint_print_recreate)
	(signal_catchpoint_explains_signal): Update.
	(create_signal_catchpoint): Change type of "filter" and
	"catch_all".
	(catch_signal_split_args): Return a std::vector.  Change type of
	"catch_all".
	(catch_signal_command): Update.
2017-07-22 16:10:41 -06:00
Simon Marchi dcd27ddf87 gdb.python/py-unwind: Disable stack protection
[I made some typo fixes but forgot to amend my commit before sending the patch,
 hence this v2.]

I see the following failure on Ubuntu 16.04's gcc 5.4.0:

Running /home/emaisin/src/binutils-gdb/gdb/testsuite/gdb.python/py-unwind.exp ...
FAIL: gdb.python/py-unwind.exp: continue to breakpoint: break backtrace-broken
FAIL: gdb.python/py-unwind.exp: Backtrace restored by unwinder (pattern 1)

The problem is that the test expects a very particular stack layout.
When stack protection is enabled, it adds a canary value which looks
like an additional local variable.  This makes the test complain about
a bad stack layout and fail.

The simple solution is to disable stack protection for that test using
-fno-stack-protector.  I checked older compilers (gcc 4.4, clang 3.5)
and they support that flag, so I don't think it's necessary to probe for
whether the compiler supports it.

Maybe a better solution would be to change the test to make it cope with
different stack layouts (perhaps it could save addresses of stuff in
some global variables which GDB/the unwinder would read).  I'll go with
the simple solution for now though.

gdb/testsuite/ChangeLog:

	* gdb.python/py-unwind.exp: Disable stack protection when
	building test file.
2017-07-22 00:01:03 +02:00
Pedro Alves 47e77640be Make language_def O(1)
Profiling GDB with the rest of series applied, I saw calls to
language_def showing up high in some runs.  The problem is that
language_def is O(N) currently, since walk the languages vector each
time to find the matching language_defn.

IMO, the add_language mechanism is pointless, because "enum language"
implies the core of GDB needs to know about all languages anyway.  So
simply make the languages vector array be an array where each
element's index is the corresponding enum language enumerator.  Note
that "local_language_defn" is gone along the way.  It's just a copy of
"auto", so the new code simply maps one to the other.  One fewer place
to update when we need to change the language vector...

Also, a while ago the output of "set language" was made out of order
as side effect of some other change.  While I was at it, I made them
sorted again.

gdb/ChangeLog:
2017-07-20  Pedro Alves  <palves@redhat.com>

	* ada-lang.c (ada_language_defn): Make extern.
	(_initialize_ada_language): Remove add_language call.
	* c-lang.c (c_language_defn, cplus_language_defn)
	(asm_language_defn, minimal_language_defn): Make extern.
	(_initialize_c_language): Delete.
	* completer.c (compare_cstrings): Delete, moved to utils.h.
	* d-lang.c (d_language_defn): Make extern.
	(_initialize_d_language): Remove add_language calls.
	* defs.h (enum language): Add comment.
	* f-lang.c (f_language_defn): Make extern.
	(_initialize_f_language): Remove add_language call.
	* go-lang.c (go_language_defn): Make extern.
	(_initialize_go_language): Remove add_language call.
	* language.c: Include <algorithm>.
	(languages): Redefine as const array.
	(languages_size, languages_allocsize, DEFAULT_ALLOCSIZE): Delete.
	(set_language_command): Handle "local".  Use for-range loop.
	(set_language): Remove loop.
	(language_enum): Rewrite.
	(language_def, language_str): Remove loops.
	(add_language): Delete.
	(add_set_language_command): New, based on add_languages.
	(skip_language_trampoline): Adjust.
	(local_language_defn): Delete.
	(language_gdbarch_post_init): Adjust.
	(_initialize_language): Remove add_language calls.  Call
	add_set_language_command.
	* language.h (add_language): Delete.
	(auto_language_defn)
	(unknown_language_defn, minimal_language_defn, ada_language_defn)
	(asm_language_defn, c_language_defn, cplus_language_defn)
	(d_language_defn, f_language_defn, go_language_defn)
	(m2_language_defn, objc_language_defn, opencl_language_defn)
	(pascal_language_defn, rust_language_defn): Declare.
	* m2-lang.c (m2_language_defn): Make extern.
	(_initialize_m2_language): Remove add_language call.
	* objc-lang.c (objc_language_defn): Make extern.
	(_initialize_objc_language): Remove add_language call.
	* opencl-lang.c (opencl_language_defn): Make extern.
	(_initialize_opencl_language): Remove add_language call.
	* p-lang.c (pascal_language_defn): Make extern.
	(_initialize_pascal_language): Delete.
	* rust-lang.c (rust_language_defn): Make extern.
	(_initialize_rust_language): Delete.
	* utils.h (compare_cstrings): New static inline function.

gdb/testsuite/ChangeLog:
2017-07-20  Pedro Alves  <palves@redhat.com>

	* gdb.base/default.exp (set language): Adjust expected output.
2017-07-20 18:28:01 +01:00
Pedro Alves edb0c9cb22 get_int_var_value
I noticed that get_int_var_value's parameters could use some
constification.  And then realized that client code would become
simpler by changing the interface to return the success/failure
indication as actual return value, as it allows getting rid of the
local "boolean" variable.

gdb/ChangeLog:
2017-07-20  Pedro Alves  <palves@redhat.com>

	* ada-lang.c (ada_to_fixed_type_1): Adjust.
	(get_var_value): Constify parameters.
	(get_int_var_value): Change prototype.
	(to_fixed_range_type): Adjust.
	* ada-lang.h (get_int_var_value): Change prototype.
2017-07-20 18:12:19 +01:00
Pedro Alves a778f165ad Use SYMBOL_MATCHES_SEARCH_NAME some more
gdb/ChangeLog:
2017-07-20  Pedro Alves  <palves@redhat.com>

	* dwarf2read.c (dw2_lookup_symbol): Use
	SYMBOL_MATCHES_SEARCH_NAME.
	* psymtab.c (psym_lookup_symbol): Use SYMBOL_MATCHES_SEARCH_NAME.
2017-07-20 18:06:13 +01:00
Pedro Alves 42edd901a2 Eliminate block_iter_name_*
This patch gets rid of block_iter_name_* as being unnecessary.  It's
the same as calling block_iter_match_*, and passing strcmp_iw as
comparison routine.

(A later patch will get rid of those new explicit strcmp_iw calls.)

gdb/ChangeLog:
2017-07-20  Pedro Alves  <palves@redhat.com>

	* block.c (block_iter_name_step, block_iter_name_first)
	(block_iter_name_next): Delete.
	(block_lookup_symbol_primary): Adjust to use
	dict_iter_match_first/dict_iter_match_next.
	* block.h (block_iter_name_first, block_iter_name_next): Delete
	declarations.
	(ALL_BLOCK_SYMBOLS_WITH_NAME): Adjust to use
	dict_iter_match_first/dict_iter_match_next.
2017-07-20 18:04:46 +01:00
Pedro Alves cf32529923 Fix cp_find_first_component_aux bug
Valgrind catches an out-of-bounds read here:

 $ gdb ./testsuite/outputs/gdb.cp/method2/method2
 (gdb) start
 [...]
 Temporary breakpoint 1, main (argc=1, argv=0x7fffffffd958) at src/gdb/testsuite/gdb.cp/method2.cc:26
 26        return 0;
 (gdb) b A::operator
 ==26907== Invalid read of size 1
 ==26907==    at 0x75C0AE: cp_find_first_component_aux(char const*, int) (cp-support.c:951)
 ==26907==    by 0x75C084: cp_find_first_component(char const*) (cp-support.c:925)
 ==26907==    by 0x75C3DA: cp_entire_prefix_len(char const*) (cp-support.c:1089)
 ==26907==    by 0x758B16: cp_lookup_symbol_in_namespace(char const*, char const*, block const*, domain_enum_tag, int) (cp-namespace.c:314)
 ==26907==    by 0x75972A: lookup_namespace_scope(language_defn const*, char const*, block const*, domain_enum_tag, char const*, int) (cp-namespace.c:739)
 ==26907==    by 0x7597CB: cp_lookup_symbol_nonlocal(language_defn const*, char const*, block const*, domain_enum_tag) (cp-namespace.c:768)
 ==26907==    by 0x8C1137: lookup_symbol_aux(char const*, block const*, domain_enum_tag, language, field_of_this_result*) (symtab.c:2016)
 ==26907==    by 0x8C098A: lookup_symbol_in_language(char const*, block const*, domain_enum_tag, language, field_of_this_result*) (symtab.c:1824)
 ==26907==    by 0x8C0A04: lookup_symbol(char const*, block const*, domain_enum_tag, field_of_this_result*) (symtab.c:1836)
 ==26907==    by 0x82CBE1: find_label_symbols(linespec_state*, VEC_symbolp*, VEC_symbolp**, char const*) (linespec.c:3390)
 ==26907==    by 0x828FB5: linespec_parse_basic(ls_parser*) (linespec.c:1620)
 ==26907==    by 0x82A78F: parse_linespec(ls_parser*, char const*) (linespec.c:2307)
 ==26907==  Address 0x910f97c is 0 bytes after a block of size 12 alloc'd
 ==26907==    at 0x4C28BF6: malloc (vg_replace_malloc.c:299)
 ==26907==    by 0x74E737: xmalloc (common-utils.c:43)
 ==26907==    by 0x74EAF4: savestring(char const*, unsigned long) (common-utils.c:179)
 ==26907==    by 0x826CEF: copy_token_string(ls_token) (linespec.c:488)
 ==26907==    by 0x828EF6: linespec_parse_basic(ls_parser*) (linespec.c:1599)
 ==26907==    by 0x82A78F: parse_linespec(ls_parser*, char const*) (linespec.c:2307)
 ==26907==    by 0x82AE27: event_location_to_sals(ls_parser*, event_location const*) (linespec.c:2469)
 ==26907==    by 0x82B1CE: decode_line_full(event_location const*, int, program_space*, symtab*, int, linespec_result*, char const*, char const*) (linespec.c:2557)
 ==26907==    by 0x720C8A: parse_breakpoint_sals(event_location const*, linespec_result*) (breakpoint.c:9550)
 ==26907==    by 0x72A2F7: create_sals_from_location_default(event_location const*, linespec_result*, bptype) (breakpoint.c:14484)
 ==26907==    by 0x727F86: bkpt_create_sals_from_location(event_location const*, linespec_result*, bptype) (breakpoint.c:13219)
 ==26907==    by 0x72146D: create_breakpoint(gdbarch*, event_location const*, char*, int, char*, int, int, bptype, int, auto_boolean, breakpoint_ops const*, int, int, int, unsigned int) (breakpoint.c:9759)

Tests exercising this will be added further down the series.

gdb/ChangeLog:
2017-07-20  Pedro Alves  <palves@redhat.com>

	* cp-support.c (cp_find_first_component_aux): Add missing case for
	end of string.
2017-07-20 17:58:17 +01:00
Pedro Alves 62d2a18a2e Make gdb.base/dmsym.exp independent of "set language ada"
This test is using "set language ada" expecting that to cause GDB to
do Ada symbol name matching.  That won't work when GDB uses the
symbol's language to decide which symbol matching algorithm to use,
because the test's symbols are C symbols.

So generalize the test a bit to not rely on Ada name matching rules.

Confirmed that by undoing the original fix the test was written for,
the test still fails.

gdb/testsuite/ChangeLog:
2017-07-20  Pedro Alves  <palves@redhat.com>

	* gdb.base/dmsym.c (pck__foo__bar__minsym): Rename to ...
	(test_minsym): ... this, and make static.
	(get_pck__foo__bar__minsym): Rename to ...
	(get_test_minsym): ... this.
	* gdb.base/dmsym.exp (): Remove "set language ada" call.  Adjust
	symbol names and comments.
	* gdb.base/dmsym_main.c (get_pck__foo__bar__minsym): Rename to ...
	(get_test_minsym): ... this.
	(pck__foo__bar__minsym__2): Rename to ...
	(test_minsym): ... this.
	(main): Adjust.
2017-07-20 17:52:03 +01:00
David Blaikie c5ed057625 Fix Fission (broken by my previous patch)
Turns out somewhere along the refactoring of the multiple-CU support
for Fission I broke the patch before submitting it (& seems to have
broken Fission support generally).

Syncing back to the point at which the patch was committed, the
previous test results on my machine are:

 expected passes: 36137
 unexpected failures: 416

with the previous (broken) patch committed:

 expected passes: 36131
 unexpected failures: 429

With this one line patch applied on top of the broken commit:

 expected passes: 36144
 unexpected failures: 416

(& all other result counts remained the same in all 3 cases)

gdb/ChangeLog:
2017-07-18  David Blaikie  <dblaikie@gmail.com>

	* dwarf2read.c (create_cus_hash_table): Re-add lost initialization
	of dwo_cu's dwo_file.
2017-07-18 16:06:17 +01:00
Yao Qi 27841e762c Remove one line comment
This patch is going to remove a line comment, which was added in this
commit,

commit 55fea07
Author: Jim Kingdon <jkingdon@engr.sgi.com>
Date:   Tue Sep 14 01:08:22 1993 +0000

        * remote.c: Define remote_debug to 0 and #if 0 baud_rate.  Temporary
        hack so this file compiles again.

        * remote-utils.c (gr_multi_scan): Cast return value from alloca.
        (gr_multi_scan): #if 0 never-reached return(-1).

and at that moment, remote_prepare_to_store does updates some global
state,

static void
remote_prepare_to_store ()
{
  /* Make sure the entire registers array is valid.  */
  read_register_bytes (0, (char *)NULL, REGISTER_BYTES);
}

However, now, remote_prepare_to_store doesn't do that at all, and
rsa->sizeof_g_packet is updated in init_remote_state, so the line of
comment is out of date, and this patch removes it.

gdb:

2017-07-18  Yao Qi  <yao.qi@linaro.org>

	* remote.c (store_registers_using_G): Remove one line comment.
2017-07-18 12:57:19 +01:00
Yao Qi cfb7e58b48 Simplify regcache_cpy and remove regcache::cpy_no_passthrough
Nowadays, regcache_cpy is used where src is read-only and dst is not
read-only, so the regcache_cpy can be simplified to handle this case only.
As a result, regcache::cpy_no_passthrough, which is about two read-only
regcache copy, is no longer used, remove it as well.

gdb:

2017-07-18  Yao Qi  <yao.qi@linaro.org>

	* regcache.c (regcache_cpy): Simplify it.
	(regcache::cpy_no_passthrough): Remove it.
	* regcache.h (cpy_no_passthrough): Remove it.
	(regcache_dup, regcache_cpy): Update comments.
2017-07-18 12:46:14 +01:00
Yao Qi c646b4e87f Improve doc about "maint print c-tdesc"
In my patch extending command "maint print c-tdesc"
(https://sourceware.org/ml/gdb-patches/2017-06/msg00286.html), Eli
raised some questions on the existing doc to this command.  It is not
very clear, so this patch improves it.  Eli approved it.

gdb/doc:

2017-07-18  Yao Qi  <yao.qi@linaro.org>

	* gdb.texinfo (Maintenance Commands): Improve the doc to
	command "maint print c-tdesc".
2017-07-18 12:39:22 +01:00
Pedro Alves 386535dd91 Fix GDB builds that include the simulator
The completer rewrite series missed adjusting target sim to the new
completion_tracker interface.

src/gdb/remote-sim.c: In function ‘void _initialize_remote_sim()’:
src/gdb/remote-sim.c:1350:46: error: invalid conversion from ‘VEC_char_ptr* (*)(cmd_list_element*, const char*, const char*)’ to ‘void (*)(cmd_list_element*, completion_tracker&, const char*, const char*)’ [-fpermissive]
   set_cmd_completer (c, sim_command_completer);
                                              ^

This commit fixes it, and also takes care to be exception safe (the
previous code would leak if growing the VEC throws).

Tested manually with a --target=arm-none-eabi build.

gdb/ChangeLog:
2017-07-18  Pedro Alves  <palves@redhat.com>

	* remote-sim.c (sim_command_completer): Adjust to work with a
	completion_tracker instead of a VEC.
2017-07-18 11:38:17 +01:00
Pedro Alves c45ec17c07 A smarter linespec completer
Continuing the theme of the explicit locations patch, this patch gets
rid of the need for quoting function names in linespec TAB completion.
To recap, when you have overloads in your program, and you want to set
a breakpoint in one of them:

 void function(int);  // set breakpoint here.
 void function(long);

 (gdb) b function(i[TAB]
 <all the symbols in the program that start with "i" are uselessly shown...>

This patch gets rid of the need for quoting by switching the linespec
completer to use the custom completion word point mechanism added in
the previous explicit location patch (extending it as needed), to
correctly determine the right completion word point.  In the case
above, we want the completer to figure out that it's completing a
function name that starts with "function(i", and it now does.

We also want the completer to know when it's potentially completing a
source file name, for:

(gdb) break source.[TAB] -> source.c:
(gdb) break source.c:  # Type line number or function name now

And we want it to know to complete label names, which it doesn't today:

(gdb) break function:lab[TAB]

etc., etc.

So what we want is for completion to grok the input string as closely
to how the linespec parser groks it.

With that in mind, the solution suggests itself - make the linespec
completer use the same parsing code as normal linespec parsing.

That's what the patch does.  The old completer is replaced by one that
reuses the actual linespec parser as much as possible.  This (ideally)
eliminate differences between what completion understands and actually
setting breakpoints understands by design.

The completer now offers sensible completion candidates depending on
which component of the linespec is being completed, source filename,
function, line number, expression, and (a new addition), labels.  For
example, when completing the function part, we now show the full name
of the method as completion candidates, instead of showing whatever
comes after what readline considered the word break character:

 (gdb) break klass::method[TAB]
 klass:method1(int)
 klass:method2()

If input is past the function, then we now offer keyword condidates:

  (gdb) b function(int) [TAB]
  if      task    thread

If input is past a keyword, we offer expression completion, which is
different from linespec completion:

  (gdb) b main if 1 + glo[TAB]
  global

(e.g., completes on types, struct data fields, etc.)

As mentioned, this teaches the linespec completer about completing
label symbols too:

  (gdb) b source.c:function:lab[TAB]

A nice convenience is that when completion uniquely matches a source
name, gdb adds the ":" automatically for you:

  (gdb) b filenam[TAB]
  (gdb) b filename.c:  # ':' auto-added, cursor right after it.

It's the little details.  :-)

I worked on this patch in parallel with writing the (big) testcase
added closer to the end of the series, which exercises many many
tricky cases around quoting and whitespace insertion placement.  In
general, I think it now all Just Works.

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* completer.c (complete_source_filenames): New function.
	(complete_address_and_linespec_locations): New function.
	(location_completer): Use complete_address_and_linespec_locations.
	(completion_tracker::build_completion_result): Honor the tracker's
	request to suppress append.
	* completer.h (completion_tracker::suppress_append_ws)
	(completion_tracker::set_suppress_append_ws): New methods.
	(completion_tracker::m_suppress_append_ws): New field.
	(complete_source_filenames): New declaration.
	* linespec.c (linespec_complete_what): New.
	(struct ls_parser) <complete_what, completion_word,
	completion_quote_char, completion_quote_end, completion_tracker>:
	New fields.
	(string_find_incomplete_keyword_at_end): New.
	(linespec_lexer_lex_string): Record quote char.  If in completion
	mode, don't throw.
	(linespec_lexer_consume_token): Advance the completion word point.
	(linespec_lexer_peek_token): Save/restore completion info.
	(save_stream_and_consume_token): New.
	(set_completion_after_number): New.
	(linespec_parse_basic): Set what to complete next depending on
	token.  Handle function and label completions specially.
	(parse_linespec): Disable objc shortcut in completion mode.  Set
	what to complete next depending on token type.  Skip keyword if in
	completion mode.
	(complete_linespec_component, linespec_complete): New.
	* linespec.h (linespec_complete): Declare.

gdb/testsuite/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* gdb.base/completion.exp: Adjust expected output.
	* gdb.linespec/ls-errs.exp: Don't send tab characters, now that
	the completer works.
2017-07-17 20:29:37 +01:00
Pedro Alves be966d4207 Linespec lexing and C++ operators
There's some lexing code in linespec that isn't handling C++ operators
correctly.  It's the usual confusion with operator< / operator<<, in
code that wants to skip past template parameters.

The linespec_lexer_lex_string change is necessary otherwise we get
this (with current master):

 (gdb) break 'operator<'
 unmatched quote

The need for the find_toplevel_char change was exposed by the use of
that function in the explicit location completer.  Without the fix,
that completer is not able to "see" past operator< symbols, without
quoting, like:

 (gdb) b -function operator<(int, int) -labe[TAB]    # nothing happens

gdb incorrectly thinks "-labe" is part of the "unclosed" template
parameter list started with "<".

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* linespec.c (linespec_lexer_lex_string, find_toplevel_char):
	Handle 'operator<' / 'operator<<'.
2017-07-17 20:28:12 +01:00
Pedro Alves a245927022 Explicit locations -label completer
We're missing a completer for

  (gdb) break -function func -label [TAB]

This patch adds one.  Tests will be added later in the series.

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* completer.c (collect_explicit_location_matches): Handle
	MATCH_LABEL.
	(convert_explicit_location_to_linespec): New, factored out from
	...
	(convert_explicit_location_to_sals): ... this.
	(complete_label): New.
	(linespec_complete_label, find_label_symbols_in_block): New.
	(find_label_symbols): Add completion_mode parameter and adjust to
	call find_label_symbols_in_block.
	* linespec.h (linespec_complete_label): Declare.
2017-07-17 20:24:41 +01:00
Pedro Alves c6756f62e0 Rewrite/enhance explicit locations completer, parse left->right
One of the most annoying (to me) things about GDB's completion is when
you have overloads in your program, and you want to set a breakpoint
in one of them:

 void function(int);  // set breakpoint here.
 void function(long);

 (gdb) b -f func[TAB]
 (gdb) b -f function(       # ok, gdb completed as much as possible.
 (gdb) b -f function([TAB]  # show me the overloads, please.
 <_all_ symbols in the program are shown...>

E.g., when debugging GDB, that'd be:

 (gdb) b -f function([TAB]
 (anonymous namespace)::get_global()::global  pt_insn_get_offset@plt                       scm_new_port_table_entry
 asprintf                                     pt_pkt_alloc_decoder                         scm_new_port_table_entry@plt
 asprintf@plt                                 pt_pkt_alloc_decoder@plt                     scm_out_of_range
 bt_ctf_get_char_array                        pt_pkt_sync_forward                          scm_out_of_range@plt
 bt_ctf_get_char_array@plt                    pt_pkt_sync_forward@plt                      scm_putc
 bt_ctf_get_uint64                            pwrite                                       scm_putc@plt
 bt_ctf_get_uint64@plt                        pwrite@plt                                   scm_reverse_x
 bt_ctf_iter_read_event                       PyErr_Restore                                scm_reverse_x@plt
 bt_ctf_iter_read_event@plt                   PyErr_Restore@plt                            scm_set_port_filename_x
 <snip...>

Now that's a load of completely useless completions.

The reason GDB offers those is that the completer relies on readline
figuring out the completion word point in the input line based on the
language's word break characters, which include "(".  So readline
tells the completer to complete on "", the string that is after '('.
Likewise, if you type "function(i[TAB]" to try to complete to "int",
you're out of luck.  GDB shows you all the symbols in the program that
start with "i"...  This makes sense for the expression completer, as
what you'd want to type is e.g., a global variable, say:

(gdb) print function(i[TAB]

but, it makes no sense when specifying a function name for a
breakpoint location.

To get around that limitation, users need to quote the function name,
like:

 (gdb) b -f 'function([TAB]
 function(int)      function(long)
 (gdb) b 'function(i[TAB]
 (gdb) b 'function(int)' # now completes correctly!

Note that the quoting is only necessary for completion.  Creating the
breakpoint does not require the quoting:

 (gdb) b -f function(int) [RET]
 Breakpoint 1 at ....

This patch removes this limitation.

(
Actually, it's a necessary patch, though not sufficient.  That'll
start working correctly by the end of the series.  With this patch, if try it,
you'll see:

 (gdb) b -f function(i[TAB]
 (gdb) b -f function

i.e., gdb strips everything after the "(".  That's caused by some code
in symtab.c that'll be eliminated further down the series.  These
patches are all unfortunately interrelated, which is also the reason
new tests only appear much later in the series.
But let's ignore that reality for the remainder of the description.
)

So... this patch gets rid of the need for quoting.

It does that by adding a way for a completer to control the exact
completion word point that readline should start the completion
request for, instead of letting readline try to figure it out using
the current language's word break chars array, and often failing.

In the case above, we want the completer to figure out that it's
completing a function name that starts with "function(i".  It now
does.

It took me a while to figure out a way to ask readline to "use this
exact word point", and for a while I feared that it'd be impossible
with current readline (and having to rely on master readline for core
functionality is something I'd like to avoid very much).  Eventually,
after several different attempts, I came up with what is described in
the comment above gdb_custom_word_point_brkchars in the patch.

With this patch, the handle_brkchars phase of the explicit location
completer advances the expected word point as it parses the input line
left to right, until it figures out exactly what we're completing,
instead of expecting readline to break the string using the word break
characters, and then having the completer heuristically fix up a bad
decision by parsing the input string backwards.  This allows correctly
knowning that we're completing a symbol name after -function, complete
functions without quoting, etc.

Later, we'll make use of this same mechanims to implement a proper
linespec completer that avoids need for quoting too.

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* ada-lang.c (ada_collect_symbol_completion_matches): Add
	complete_symbol_mode parameter.
	* cli/cli-cmds.c (complete_command): Get the completion result out
	of the handle_brkchars tracker if used a custom word point.
	* completer.c: Include "linespec.h".
	(enum explicit_location_match_type) <MATCH_LINE>: New enumerator.
	(advance_to_expression_complete_word_point): New.
	(completion_tracker::completes_to_completion_word): New.
	(complete_files_symbols): Pass down
	complete_symbol_mode::EXPRESSION.
	(explicit_options, probe_options): New.
	(collect_explicit_location_matches): Complete on the
	explictit_loc->foo instead of word.  Use
	linespec_complete_function.  Handle MATCH_LINE.  Handle offering
	keyword and options completions.
	(backup_text_ptr): Delete.
	(skip_keyword): New.
	(complete_explicit_location): Remove 'word' parameter.  Add
	language, quoted_arg_start and quoted_arg_end parameters.
	Rewrite, parsing left to right.
	(location_completer): Rewrite.
	(location_completer_handle_brkchars): New function.
	(symbol_completer): Pass down complete_symbol_mode::EXPRESSION.
	(enum complete_line_internal_reason): Adjust comments.
	(completion_tracker::discard_completions): New.
	(completer_handle_brkchars_func_for_completer): Handle
	location_completer.
	(gdb_custom_word_point_brkchars)
	(gdb_org_rl_basic_quote_characters): New.
	(gdb_completion_word_break_characters_throw)
	(completion_find_completion_word): Handle trackers that use a
	custom word point.
	(completion_tracker::advance_custom_word_point_by): New.
	(completion_tracker::build_completion_result): Don't rely on
	readline appending the quote char.
	(gdb_rl_attempted_completion_function_throw): Handle trackers that
	use a custom word point.
	(gdb_rl_attempted_completion_function): Restore
	rl_basic_quote_characters.
	* completer.h (class completion_tracker): Extend intro comment.
	(completion_tracker::set_quote_char)
	(completion_tracker::quote_char)
	(completion_tracker::set_use_custom_word_point)
	(completion_tracker::use_custom_word_point)
	(completion_tracker::custom_word_point)
	(completion_tracker::set_custom_word_point)
	(completion_tracker::advance_custom_word_point_by)
	(completion_tracker::completes_to_completion_word)
	(completion_tracker::discard_completions): New methods.
	(completion_tracker::m_quote_char)
	(completion_tracker::m_use_custom_word_point)
	(completion_tracker::m_custom_word_point): New fields.
	(advance_to_expression_complete_word_point): Declare.
	* f-lang.c (f_collect_symbol_completion_matches): Add
	complete_symbol_mode parameter.
	* language.h (struct language_defn)
	<la_collect_symbol_completion_matches>: Add complete_symbol_mode
	parameter.
	* linespec.c (linespec_keywords): Add NULL terminator.  Make extern.
	(linespec_complete_function): New function.
	(linespec_lexer_lex_keyword): Adjust.
	* linespec.h (linespec_keywords, linespec_complete_function): New
	declarations.
	* location.c (find_end_quote): New function.
	(explicit_location_lex_one): Add explicit_completion_info
	parameter.  Save quoting info.  Don't throw if being called for
	completion.  Don't handle Ada operators here.
	(is_cp_operator, skip_op_false_positives, first_of)
	(explicit_location_lex_one_function): New function.
	(string_to_explicit_location): Replace 'dont_throw' parameter with
	an explicit_completion_info pointer parameter.  Handle it.  Don't
	use explicit_location_lex_one to lex function names.  Use
	explicit_location_lex_one_function instead.
	* location.h (struct explicit_completion_info): New.
	(string_to_explicit_location): Replace 'dont_throw' parameter with
	an explicit_completion_info pointer parameter.
	* symtab.c (default_collect_symbol_completion_matches_break_on):
	Add complete_symbol_mode parameter.  Handle LINESPEC mode.
	(default_collect_symbol_completion_matches)
	(collect_symbol_completion_matches): Add complete_symbol_mode
	parameter.
	(collect_symbol_completion_matches_type): Pass down
	complete_symbol_mode::EXPRESSION.
	(collect_file_symbol_completion_matches): Add complete_symbol_mode
	parameter.  Handle LINESPEC mode.
	* symtab.h (complete_symbol_mode): New.
	(default_collect_symbol_completion_matches_break_on)
	(default_collect_symbol_completion_matches)
	(collect_symbol_completion_matches)
	(collect_file_symbol_completion_matches): Add complete_symbol_mode
	parameter.

gdb/testsuite/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* gdb.linespec/ls-errs.exp (do_test): Adjust expected output.
2017-07-17 20:21:33 +01:00
Pedro Alves 1d550c828c Introduce strncmp_iw
The explicit locations completer patch will need a strncmp_iw
function, that to strcmp_iw like strncmp is to strcmp.  This patch
implements it.

(Unit tests added a bit further down in this series will exercise
this.)

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* utils.c (enum class strncmp_iw_mode): New.
	(strcmp_iw): Rename to ...
	(strncmp_iw_with_mode): ... this.  Add string2_len and mode
	parameters.  Handle them.
	(strncmp_iw): New.
	(strcmp_iw): Reimplement as wrapper around strncmp_iw_with_mode.
	* utils.h (strncmp_iw): Declare.
	(strcmp_iw): Move describing comments here.
2017-07-17 20:08:48 +01:00
Pedro Alves 8090b426b5 Introduce CP_OPERATOR_STR/CP_OPERATOR_LEN and use throughout
Move LENGTH_OF_OPERATOR from cp-support.c to cp-support.h so we can
use it elsewhere.  Since there's already
CP_ANONYMOUS_NAMESPACE_STR/CP_ANONYMOUS_NAMESPACE_LEN there, follow
the same naming pattern for the new symbols.

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* c-exp.y (operator_stoken): Use CP_OPERATOR_LEN and
	CP_OPERATOR_STR.
	* c-typeprint.c (is_type_conversion_operator): Use
	CP_OPERATOR_STR.
	* cp-support.c (LENGTH_OF_OPERATOR): Delete.
	(cp_find_first_component_aux): Use CP_OPERATOR_STR and
	CP_OPERATOR_LEN.
	* cp-support.h (CP_OPERATOR_STR, CP_OPERATOR_LEN): New.
	* gnu-v2-abi.c (gnuv2_is_operator_name): Use CP_OPERATOR_STR.
	* gnu-v3-abi.c (gnuv3_is_operator_name): Use CP_OPERATOR_STR.
	* linespec.c (linespec_lexer_lex_string): Use CP_OPERATOR_LEN and
	CP_OPERATOR_STR.
	* location.c: Include "cp-support.h".
	(explicit_location_lex_one): Use CP_OPERATOR_LEN and
	CP_OPERATOR_STR.
	* symtab.c (operator_chars): Use CP_OPERATOR_STR and
	CP_OPERATOR_LEN.
2017-07-17 15:51:55 +01:00
Pedro Alves 6a2c1b8790 "complete" command and completion word break characters
The linespec/locations/completer testcase added later in the series
tests every completion with both TAB completion and the "complete"
command.  This exposed problems in the "complete" command, around
determining the completion word point.

First, the complete command has a too-simple approximation of what
readline's TAB-completion code does to find the completion word point.
Unfortunately, readline doesn't expose the functionality it uses
internally, so to fix this this patch copies over the relevant code,
and adjusts it a bit to better fit the use cases we need it for.
(Specifically, our version avoids relying on the
rl_word_break_characters, etc. globals, and instead takes those as
arguments.)

A following patch will want to use this function for TAB-completion
too, but the "complete" command was a good excuse to split this to a
separate patch.

Then, notice how the complete_command does not call into the completer
for the command being completed to determine the right set of word
break characters.  It always uses the default set.  That is fixed by
having the "complete" command call into complete_line_internal for a
full handle_brkchars phase, just TAB-completion.

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* cli/cli-cmds.c (complete_command): Use a completion tracker
	along with completion_find_completion_word for handle_brkchars
	phase.
	* completer.c (RL_QF_SINGLE_QUOTE, RL_QF_DOUBLE_QUOTE)
	(RL_QF_BACKSLASH, RL_QF_OTHER_QUOTE): New.
	(struct gdb_rl_completion_word_info): New.
	(gdb_rl_find_completion_word): New.
	(completion_find_completion_word): New.
	* completer.h (completion_find_completion_word): Declare.
2017-07-17 15:30:59 +01:00
Pedro Alves eb3ff9a551 Introduce class completion_tracker & rewrite completion<->readline interaction
This patch reworks the whole completion machinery, and prepares it
for later enhancements.

Adds a new "completion_tracker" class that is meant to hold everything
about the state of the current completion operation.

This class now has the responsibility of tracking the list of
completion matches, and checking whether the max completions limit has
been reached.  You can look at this as this patch starting out by
C++fying the existing "completion_tracker" in symtab.c (it's just an
htab_t typedef currently), moving it to completer.h/c, and then making
it a class/generalizing/enhancing it.

Unlike with the current tracking, completion_tracker now checks
whether the limit has been reached on each completion match list
insertion.  This both simplifies the max-completions handling code
(maybe_add_completion_enum is gone, for example), and is a
prerequisite for follow up patches.

The current completion_tracker is only used for symbol completions,
and the symbol code gets at the current instance via globals.  This
patch cleans that up by adding a completion_tracker reference to the
signature of the completion functions, and passing the tracker around
everywhere necessary.

Then, the patch changes how the completion match list is handed over
to readline.  Currently, we're using the rl_completion_entry_function
readline entry point, and the patch switches to
rl_attempted_completion_function.  A following patch will want to let
GDB itself decide the common completion prefix between all matches
(what readline calls the "lowest common denominator"), instead of
having readline compute it, and that's not possible with the
rl_completion_entry_function entry point.  Also,
rl_attempted_completion_function lets GDB hand over the match list to
readline as an array in one go instead of passing down matches one by
one, so from that angle it's a nicer entry point anyway.

Lastly, the patch catches exceptions around the readline entry points,
because we can't let C++ exceptions cross readline.  We handle that in
the readline input entry point, but the completion entry point isn't
guarded, so GDB can abort if completion throws.  E.g., in current
master:

 (gdb) b -function "fun<tab>
 terminate called after throwing an instance of 'gdb_exception_RETURN_MASK_ERROR'
 Aborted (core dumped)

This patch fixes that.  This will be exercised in the new tests added
later on in the series.

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* ada-lang.c (symbol_completion_match): Adjust comments.
	(symbol_completion_add): Replace vector parameter with
	completion_tracker parameter.  Use it.
	(ada_make_symbol_completion_list): Rename to...
	(ada_collect_symbol_completion_matches): ... this.  Add
	completion_tracker parameter and use it.
	(ada_language_defn): Adjust.
	* break-catch-syscall.c (catch_syscall_completer): Adjust
	prototype and work with completion_tracker instead of VEC.
	* breakpoint.c (condition_completer): Adjust prototype and work
	with completion_tracker instead of VEC.
	* c-lang.c (c_language_defn, cplus_language_defn)
	(asm_language_defn, minimal_language_defn): Adjust to renames.
	* cli/cli-cmds.c (complete_command): Rework using
	completion_tracker.  Catch exceptions when completing.
	* cli/cli-decode.c (integer_unlimited_completer)
	(complete_on_cmdlist, complete_on_enum): Adjust prototype and work
	with completion_tracker instead of VEC.
	* command.h (struct completion_tracker): Forward declare.
	(completer_ftype, completer_handle_brkchars_ftype): Change
	types.
	(complete_on_cmdlist, complete_on_enum): Adjust.
	* completer.c: Include <algorithm>.
	(struct gdb_completer_state): New.
	(current_completion): New global.
	(readline_line_completion_function): Delete.
	(noop_completer, filename_completer)
	(filename_completer_handle_brkchars, complete_files_symbols)
	(linespec_location_completer): Adjust to work with a
	completion_tracker instead of a VEC.
	(string_or_empty): New.
	(collect_explicit_location_matches): Adjust to work with a
	completion_tracker instead of a VEC.
	(explicit_location_completer): Rename to ...
	(complete_explicit_location): ... this and adjust to work with a
	completion_tracker instead of a VEC.
	(location_completer): Adjust to work with a completion_tracker
	instead of a VEC.
	(add_struct_fields): Adjust to work with a completion_list instead
	of VEC.
	(expression_completer): Rename to ...
	(complete_expression): ... this and adjust to work with a
	completion_tracker instead of a VEC.  Use complete_files_symbols.
	(expression_completer): Reimplement on top of complete_expression.
	(symbol_completer): Adjust to work with a completion_tracker
	instead of a VEC.
	(enum complete_line_internal_reason): Add describing comments.
	(complete_line_internal_normal_command): Adjust to work with a
	completion_tracker instead of a VEC.
	(complete_line_internal): Rename to ...
	(complete_line_internal_1): ... this and adjust to work with a
	completion_tracker instead of a VEC.  Assert TEXT is NULL in the
	handle_brkchars phase.
	(new_completion_tracker): Delete.
	(complete_line_internal): Reimplement as TRY/CATCH wrapper around
	complete_line_internal_1.
	(free_completion_tracker): Delete.
	(INITIAL_COMPLETION_HTAB_SIZE): New.
	(completion_tracker::completion_tracker)
	(completion_tracker::~completion_tracker): New.
	(maybe_add_completion): Delete.
	(completion_tracker::maybe_add_completion)
	(completion_tracker::add_completion)
	(completion_tracker::add_completions): New.
	(throw_max_completions_reached_error): Delete.
	(complete_line): Adjust to work with a completion_tracker instead
	of a VEC.  Don't create a completion_tracker_t or check for max
	completions here.
	(command_completer, command_completer_handle_brkchars)
	(signal_completer, reg_or_group_completer_1)
	(reg_or_group_completer, default_completer_handle_brkchars):
	Adjust to work with a completion_tracker.
	(gdb_completion_word_break_characters_throw): New.
	(gdb_completion_word_break_characters): Reimplement.
	(line_completion_function): Delete.
	(completion_tracker::recompute_lowest_common_denominator)
	(expand_preserving_ws)
	(completion_tracker::build_completion_result)
	(completion_result::completion_result)
	(completion_result::completion_result)
	(completion_result::~completion_result)
	(completion_result::completion_result)
	(completion_result::release_match_list, compare_cstrings)
	(completion_result::sort_match_list)
	(completion_result::reset_match_list)
	(gdb_rl_attempted_completion_function_throw)
	(gdb_rl_attempted_completion_function): New.
	* completer.h (completion_list, struct completion_result)
	(class completion_tracker): New.
	(complete_line): Add completion_tracker parameter.
	(readline_line_completion_function): Delete.
	(gdb_rl_attempted_completion_function): New.
	(noop_completer, filename_completer, expression_completer)
	(location_completer, symbol_completer, command_completer)
	(signal_completer, reg_or_group_completer): Update prototypes.
	(completion_tracker_t, new_completion_tracker)
	(make_cleanup_free_completion_tracker): Delete.
	(enum maybe_add_completion_enum): Delete.
	(maybe_add_completion): Delete.
	(throw_max_completions_reached_error): Delete.
	* corefile.c (complete_set_gnutarget): Adjust to work with a
	completion_tracker instead of a VEC.
	* cp-abi.c (cp_abi_completer): Adjust to work with a
	completion_tracker instead of a VEC.
	* d-lang.c (d_language_defn): Adjust.
	* disasm.c (disassembler_options_completer): Adjust to work with a
	completion_tracker instead of a VEC.
	* f-lang.c (f_make_symbol_completion_list): Rename to ...
	(f_collect_symbol_completion_matches): ... this.  Adjust to work
	with a completion_tracker instead of a VEC.
	(f_language_defn): Adjust.
	* go-lang.c (go_language_defn): Adjust.
	* guile/scm-cmd.c (cmdscm_add_completion, cmdscm_completer):
	Adjust to work with a completion_tracker instead of a VEC.
	* infrun.c (handle_completer): Likewise.
	* interps.c (interpreter_completer): Likewise.
	* interps.h (interpreter_completer): Likewise.
	* language.c (unknown_language_defn, auto_language_defn)
	(local_language_defn): Adjust.
	* language.h (language_defn::la_make_symbol_completion_list):
	Rename to ...
	(language_defn::la_collect_symbol_completion_matches): ... this
	and adjust to work with a completion_tracker instead of a VEC.
	* m2-lang.c (m2_language_defn): Adjust.
	* objc-lang.c (objc_language_defn): Adjust.
	* opencl-lang.c (opencl_language_defn): Adjust.
	* p-lang.c (pascal_language_defn): Adjust.
	* python/py-cmd.c (cmdpy_completer_helper): Handle NULL word.
	(cmdpy_completer_handle_brkchars, cmdpy_completer): Adjust to work
	with a completion_tracker.
	* rust-lang.c (rust_language_defn): Adjust.
	* symtab.c (free_completion_list, do_free_completion_list)
	(return_val, completion_tracker): Delete.
	(completion_list_add_name, completion_list_add_symbol)
	(completion_list_add_msymbol, completion_list_objc_symbol)
	(completion_list_add_fields, add_symtab_completions): Add
	completion_tracker parameter and use it.
	(default_make_symbol_completion_list_break_on_1): Rename to...
	(default_collect_symbol_completion_matches_break_on): ... this.
	Add completion_tracker parameter and use it instead of allocating
	a completion tracker here.
	(default_make_symbol_completion_list_break_on): Delete old
	implementation.
	(default_make_symbol_completion_list): Delete.
	(default_collect_symbol_completion_matches): New.
	(make_symbol_completion_list): Delete.
	(collect_symbol_completion_matches): New.
	(make_symbol_completion_type): Rename to ...
	(collect_symbol_completion_matches_type): ... this.  Add
	completion_tracker parameter and use it instead of VEC.
	(make_file_symbol_completion_list_1): Rename to...
	(collect_file_symbol_completion_matches): ... this.  Add
	completion_tracker parameter and use it instead of VEC.
	(make_file_symbol_completion_list): Delete.
	(add_filename_to_list): Use completion_list instead of a VEC.
	(add_partial_filename_data::list): Now a completion_list.
	(make_source_files_completion_list): Work with a completion_list
	instead of a VEC.
	* symtab.h: Include "completer.h".
	(default_make_symbol_completion_list_break_on)
	(default_make_symbol_completion_list, make_symbol_completion_list)
	(make_symbol_completion_type, make_file_symbol_completion_list)
	(make_source_files_completion_list): Delete.
	(default_collect_symbol_completion_matches_break_on)
	(default_collect_symbol_completion_matches)
	(collect_symbol_completion_matches)
	(collect_symbol_completion_matches_type)
	(collect_file_symbol_completion_matches)
	(make_source_files_completion_list): New.
	* top.c (init_main): Don't install a rl_completion_entry_function
	hook.  Install a rl_attempted_completion_function hook instead.
	* tui/tui-layout.c (layout_completer): Adjust to work with a
	completion_tracker.
	* tui/tui-regs.c (tui_reggroup_completer):
	* tui/tui-win.c (window_name_completer, focus_completer)
	(winheight_completer): Adjust to work with a completion_tracker.
	* value.c: Include "completer.h".
	(complete_internalvar): Adjust to work with a completion_tracker.
	* value.h (complete_internalvar): Likewise.
2017-07-17 14:45:59 +01:00
Pedro Alves 6e1dbf8cda Clean up "completer_handle_brkchars" callback handling
This patch cleans up "completer_handle_brkchars" callback handling:

- Renames the function typedef to better match its intent:
  completer_ftype_void ->  completer_handle_brkchars_ftype

- Factors out common code in complete_line_internal handling the
  "handle_brkchars" callback to a separate function.

- Centralizes all the "completer method" to "handle_brkchars method"
  mapping in a single function.

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* cli/cli-decode.c (set_cmd_completer_handle_brkchars): Adjust to
	renames.
	* cli/cli-decode.h (struct cmd_list_element) <completer>: Move
	comments to completer_ftype's declaration.
	<completer_handle_brkchars>: Change type to
	completer_handle_brkchars_ftype.
	* command.h (completer_ftype): Add describing comment and give
	names to parameters.
	(completer_ftype_void): Rename to ...
	(completer_handle_brkchars_ftype) ... this.  Add describing comment.
	(set_cmd_completer_handle_brkchars): Adjust.
	* completer.c (filename_completer_handle_brkchars): New function.
	(complete_line_internal_normal_command): New function, factored
	out from ...
	(complete_line_internal): ... here.
	(command_completer_handle_brkchars)
	(default_completer_handle_brkchars)
	(completer_handle_brkchars_func_for_completer): New functions.
	* completer.h (set_gdb_completion_word_break_characters): Delete
	declaration.
	(completer_handle_brkchars_func_for_completer): New declaration.
	* python/py-cmd.c (cmdpy_completer_handle_brkchars): Adjust to use
	completer_handle_brkchars_func_for_completer.
2017-07-17 12:05:03 +01:00
Pedro Alves 78b13106ed Rename make_symbol_completion_list_fn -> symbol_completer
"make_symbol_completion_list_fn" is odly named when you look at a list
of "standard" completers, like the Python/Guile completer lists
adjusted by this patch.  Rename / move it to completers.h/c, for
consistency.

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* completer.c (symbol_completer): New function, based on
	make_symbol_completion_list_fn.
	* completer.h (symbol_completer): New declaration.
	* guile/scm-cmd.c (cmdscm_completers): Adjust.
	* python/py-cmd.c (completers): Adjust.
	* symtab.c (make_symbol_completion_list_fn): Delete.
	* symtab.h (make_symbol_completion_list_fn): Delete.
	* cli/cli-decode.c (add_cmd): Adjust.
2017-07-17 11:55:42 +01:00
Pedro Alves bbf2f4dfae Fix TAB-completion + .gdb_index slowness (generalize filename_seen_cache)
Tab completion when debugging a program binary that uses GDB index is
surprisingly much slower than when GDB uses psymtabs instead.  Around
1.5x/3x slower.  That's surprising, because the whole point of GDB
index is to speed things up...

For example, with:

 set pagination off
 set $count = 0
 while $count < 400
   complete b string_prin         # matches gdb's string_printf
   printf "count = %d\n", $count
   set $count = $count + 1
 end

 $ time ./gdb --batch -q  ./gdb-with-index -ex "source script.cmd"
 real    0m11.042s
 user    0m10.920s
 sys     0m0.042s

 $ time ./gdb --batch -q  ./gdb-without-index -ex "source script.cmd"
 real    0m4.635s
 user    0m4.590s
 sys     0m0.037s

Same but with:
 -   complete b string_prin
 +   complete b zzzzzz
to exercise the no-matches worst case, master currently gets you
something like:

 with index           without index
 real    0m11.971s    0m8.413s
 user    0m11.912s    0m8.355s
 sys     0m0.035s     0m0.035s

Running gdb under perf shows 80% spent inside
maybe_add_partial_symtab_filename, and 20% spent in the lbasename
inside that.

The problem that tab completion walks over all compunit symtabs, and
for each, walks the contained file symtabs.  And there a huge number
of file symtabs (each included system header, etc.) that appear in
each compunit symtab's file symtab list.  As in, when debugging GDB, I
have 367381 symtabs iterated, when of those only 5371 filenames are
unique...

This was a regression from the earlier (nice) split of symtabs in
compunit symtabs + file symtabs.

The fix here is to add a cache of unique filenames per objfile so that
the walk / uniquing is only done once.  There's already a abstraction
for this in symtab.c; this patch moves that code out to a separate
file and C++ifies it bit.

This makes the worst-case scenario above consistently drop to ~2.5s
(1.5s for the "string_prin" hit case), making it over 3.3x times
faster than psymtabs in this use case (7x in the "string_prin" hit
case).

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* Makefile.in (COMMON_OBS): Add filename-seen-cache.o.
	* dwarf2read.c: Include "filename-seen-cache.h".
	* dwarf2read.c (dwarf2_per_objfile) <filenames_cache>: New field.
	(dw2_map_symbol_filenames): Build and use a filenames_seen_cache.
	* filename-seen-cache.c: New file.
	* filename-seen-cache.h: New file.
	* symtab.c: Include "filename-seen-cache.h".
	(struct filename_seen_cache, INITIAL_FILENAME_SEEN_CACHE_SIZE)
	(create_filename_seen_cache, clear_filename_seen_cache)
	(delete_filename_seen_cache, filename_seen): Delete, parts moved
	to filename-seen-cache.h/filename-seen-cache.c.
	(output_source_filename, sources_info)
	(maybe_add_partial_symtab_filename)
	(make_source_files_completion_list): Adjust to use
	filename_seen_cache.
2017-07-17 11:38:11 +01:00
Pedro Alves 330cdd9891 C++ify dwarf2_per_objfile
This makes dwarf2_per_objfile a class with cdtors.

A following patch will add a non-trivial field to struct
dwarf2_per_objfile, making dwarf2_per_objfile itself non-trivial.
Since dwarf2_per_objfile is allocated in an obstack, we need to run
its cdtors manually.

Tested on x86-64 GNU/Linux.

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* dwarf2read.c (dwarf2_per_objfile): In-class initialize all
	fields.
	(dwarf2_per_objfile::dwarf2_per_objfile(objfile*, const
	dwarf2_debug_sections*)): New.
	(dwarf2_per_objfile::dwarf2_per_objfile(const
	dwarf2_per_objfile&)): Declare as deleted.
	(dwarf2_per_objfile::operator=): Declare as deleted.
	(dwarf2_per_objfile::dwarf2_per_objfile)
	(dwarf2_per_objfile::~dwarf2_per_objfile)
	(dwarf2_per_objfile::free_cached_comp_units): New.
	(dwarf2_has_info): dwarf2_per_objfile initialization code moved to
	ctor.  Call dwarf2_per_objfile's ctor manually.
	(dwarf2_locate_sections): Deleted/refactored as ...
	(dwarf2_per_objfile::locate_sections): ... this new method.
	(free_cached_comp_units): Defer to
	dwarf2_per_objfile::free_cached_comp_units.
	(dwarf2_free_objfile): Call dwarf2_per_objfile's dtor manually.
2017-07-17 11:31:20 +01:00
Andrew Burgess 5bd6848722 gdb: Make some test names unique
Make sure all of the tests have unique names in
gdb.mi/mi-vla-fortran.exp.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-vla-fortran.exp: Make test names unique.
2017-07-15 01:04:44 +01:00
Tom Tromey 8880f2a9cb Handle sizeof(type) in Rust
PR rust/21764 notes that "sizeof" does not work correctly for all types
in Rust.  The bug turns out to be an error in the conversion of the AST
to gdb expressions.  This patch fixes the bug and also avoids generating
incorrect expressions in another case.

Tested on the buildbot.  I'm checking this in.

2017-07-14  Tom Tromey  <tom@tromey.com>

	PR rust/21764:
	* rust-exp.y (convert_ast_to_expression): Add "want_type"
	parameter.
	<UNOP_SIZEOF>: Split into separate case.
	<UNOP_VAR_VALUE>: Handle want_type.  Add error case.

2017-07-14  Tom Tromey  <tom@tromey.com>

	PR rust/21764:
	* gdb.rust/simple.exp: Add tests.
2017-07-14 12:30:56 -06:00
Tom Tromey 65547233e0 Make gdb.lookup_typename work for Rust types
PR rust/21763 points out that gdb.lookup_typename does not work properly
for (some) Rust types.  I tracked this down to a missing case in
symbol_matches_domain.

Tested by the buildbot.

2017-07-14  Tom Tromey  <tom@tromey.com>

	PR rust/21763:
	* symtab.c (symbol_matches_domain): Add language_rust to special
	case.
	* rust-exp.y (convert_ast_to_expression) <OP_VAR_VALUE>: Don't
	treat LOC_TYPEDEF symbols as variables.

2017-07-14  Tom Tromey  <tom@tromey.com>

	* gdb.rust/simple.exp: Add regression test for PR rust/21763.
2017-07-14 10:16:39 -06:00
Pedro Alves 8f14146e13 Fix gdb.base/completion.exp with --target_board=dwarf4-gdb-index
This is the same patch as posted at
<https://sourceware.org/ml/gdb-patches/2017-02/msg00644.html>, with
the test at
<https://sourceware.org/ml/gdb-patches/2017-02/msg00687.html> squashed
in.

This patch fixes:

 -FAIL: gdb.base/completion.exp: tab complete break break.c:ma (timeout)
 -FAIL: gdb.base/completion.exp: complete break break.c:ma
 +PASS: gdb.base/completion.exp: tab complete break break.c:ma
 +PASS: gdb.base/completion.exp: delete breakpoint for tab complete break break.c:ma
 +PASS: gdb.base/completion.exp: complete break break.c:ma

When run with --target_board=dwarf4-gdb-index.

The issue here is that make_file_symbol_completion_list_1, used when
completing a symbol restricted to a given source file, uses
lookup_symtab to look up the symtab with the given name, and search
for matching symbols inside.  This assumes that there's only one
symtab for the given source file.  This is an incorrect assumption
with (for example) -fdebug-types-section, where we'll have an extra
extra symtab containing the types.  lookup_symtab finds that symtab,
and inside that symtab there are no functions...

gdb/ChangeLog:
2017-07-14  Pedro Alves  <palves@redhat.com>

	* symtab.c (make_file_symbol_completion_list_1): Iterate over
	symtabs matching all symtabs with SRCFILE as file name instead of
	only considering the first hit, with lookup_symtab.

gdb/testsuite/ChangeLog:
2017-07-14  Pedro Alves  <palves@redhat.com>

	* gdb.linespec/base/one/thefile.cc (z1): New function.
	* gdb.linespec/base/two/thefile.cc (z2): New function.
	* gdb.linespec/linespec.exp: Add tests.
2017-07-14 16:50:35 +01:00
Simon Marchi 2347965cd9 ax-gdb: Remove more unused arguments
gdb/ChangeLog:

	* ax-gdb.c (gen_aggregate_elt_ref): Remove operand_name and
	operator_name parameters.
	(gen_expr): Update function call.
2017-07-14 12:47:40 +02:00
Simon Marchi 40f4af2873 ax-gdb: Remove unnecessary gdbarch parameters
In multiple places, we pass the gdbarch as an argument to some
functions, even though it's available in the agent_expr structure also
passed to the same functions.  Remove these arguments and replace their
usage with accesses to agent_expr::gdbarch.

gdb/ChangeLog:

	* dwarf2loc.h (dwarf2_compile_expr_to_ax): Remove gdbarch
	parameter.
	* symtab.h (struct symbol_computed_ops::tracepoint_var_ref):
	Likewise.
	* dwarf2loc.c (dwarf2_compile_expr_to_ax): Remove gdbarch
	parameter, use agent_expr::gdbarch instead, update function
	calls.
	(locexpr_tracepoint_var_ref): Likewise.
	(loclist_tracepoint_var_ref): Likewise.
	* ax-gdb.c (gen_trace_static_fields): Likewise.
	(gen_traced_pop): Likewise.
	(gen_frame_args_address): Likewise.
	(gen_frame_locals_address): Likewise.
	(gen_var_ref): Likewise.
	(gen_struct_ref_recursive): Likewise.
	(gen_static_field): Likewise.
	(gen_maybe_namespace_elt): Likewise.
	(gen_expr): Likewise.
	(gen_trace_for_var): Likewise.
	(gen_trace_for_expr): Likewise.
	(gen_trace_for_return_address): Likewise.
2017-07-14 12:47:40 +02:00
Simon Marchi 053f805718 ax-gdb: Remove two unused agent_expr *ax parameters
gdb/ChangeLog:

	* ax-gdb.c (gen_deref, gen_address_of): Remove unused ax
	parameter.
	(gen_struct_ref, gen_expr, gen_expr_binop_rest): Update call.
2017-07-14 12:47:39 +02:00
Simon Marchi 6661ad4873 ax-gdb: Use ax->gdbarch instead of exp->gdbarch, remove unused parameters
In many ax generation functions, the "expression *exp" parameter is only
used to access the gdbarch.  The same value can be found in the
"agent_expr *ax" parameter, which needs to be passed in any case.  By
using ax->gdbarch instead of exp->gdbarch, we can avoid passing exp in
many of these functions.

gdb/ChangeLog:

	* ax-gdb.c (gen_usual_unary): Remove exp parameter, get gdbarch
	from ax, update calls.
	(gen_usual_arithmetic): Likewise.
	(gen_integral_promotions): Likewise.
	(gen_bitfield_ref): Likewise.
	(gen_primitive_field): Likewise.
	(gen_struct_ref_recursive): Likewise.
	(gen_struct_ref): Likewise.
	(gen_maybe_namespace_elt): Likewise.
	(gen_struct_elt_for_reference): Likewise.
	(gen_namespace_elt): Likewise.
	(gen_aggregate_elt_ref): Likewise.
	(gen_expr): Get gdbarch from ax, update calls.
	(gen_expr_binop_rest): Likewise.
2017-07-14 12:47:39 +02:00
Andrew Burgess b4365d025e gdb: Fix more parameter passing to mi_create_breakpoint
In the test gdb.mi/mi-vla-fortran.exp the parameters passed to
mi_create_breakpoint are passed in the wrong order.  By good luck the
tests still passes, however the wrong test name is used.  All fixed in
this commit.

A previous commit fixed most of these, but I missed this last one.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-vla-fortran.exp: Correct even more parameter passing
	to mi_create_breakpoint.
2017-07-13 21:05:42 +01:00
Pedro Alves c55a47e723 Fix x86-64 GNU/Linux crashes
Ref: https://sourceware.org/ml/gdb-patches/2017-07/msg00162.html

Debugging x86-64 GNU/Linux programs currently crashes GDB in
tdesc_use_registers during gdbarch initialization:

  Program received signal SIGSEGV, Segmentation fault.
  0x0000000001093eaf in htab_remove_elt_with_hash (htab=0x2ef9fa0, element=0x26af960, hash=557151073) at src/libiberty/hashtab.c:728
  728       if (*slot == HTAB_EMPTY_ENTRY)
  (top-gdb) p slot
  $1 = (void **) 0x0
  (top-gdb) bt
  #0  0x0000000001093eaf in htab_remove_elt_with_hash (htab=0x2ef9fa0, element=0x26af960, hash=557151073) at src/libiberty/hashtab.c:728
  #1  0x0000000001093e79 in htab_remove_elt (htab=0x2ef9fa0, element=0x26af960) at src/libiberty/hashtab.c:714
  #2  0x00000000009121b0 in tdesc_use_registers (gdbarch=0x3001240, target_desc=0x2659cb0, early_data=0x2881cb0)
      at src/gdb/target-descriptions.c:1328
  #3  0x000000000047c93e in i386_gdbarch_init (info=..., arches=0x0) at src/gdb/i386-tdep.c:8634
  #4  0x0000000000818d5f in gdbarch_find_by_info (info=...) at src/gdb/gdbarch.c:5394
  #5  0x00000000007198a8 in set_gdbarch_from_file (abfd=0x2f48250) at src/gdb/arch-utils.c:618
  #6  0x00000000007f21cb in exec_file_attach (filename=0x7fffffffddb0 "/home/pedro/gdb/tests/threads", from_tty=1) at src/gdb/exec.c:380
  #7  0x0000000000865c18 in catch_command_errors_const (command=0x7f1d83 <exec_file_attach(char const*, int)>, arg=0x7fffffffddb0 "/home/pedro/gdb/tests/threads",
      from_tty=1) at src/gdb/main.c:403
  #8  0x00000000008669cf in captured_main_1 (context=0x7fffffffd860) at src/gdb/main.c:1035
  #9  0x0000000000866de2 in captured_main (data=0x7fffffffd860) at src/gdb/main.c:1142
  #10 0x0000000000866e24 in gdb_main (args=0x7fffffffd860) at src/gdb/main.c:1160
  #11 0x000000000041312d in main (argc=3, argv=0x7fffffffd968) at src/gdb/gdb.c:32

The direct cause of the crash is that we tried to remove an element
from the hash which supposedly exists, but does not.  (htab_remove_elt
shouldn't really crash in this case, but that's secondary.)

The real problem is that early_data passed to tdesc_use_registers
includes regs from a target description that is not the target_desc,
which violates its assumptions.  The registers in question are the
fs_base/gs_base registers, added by amd64_init_abi:

      tdesc_numbered_register (feature, tdesc_data_segments,
		       AMD64_FSBASE_REGNUM, "fs_base");
      tdesc_numbered_register (feature, tdesc_data_segments,
		       AMD64_GSBASE_REGNUM, "gs_base");

and that happens because amd64_linux_init_abi uses amd64_init_abi as
helper, but they don't coordinate on which fallback tdesc to use.

amd64_init_abi does:

  if (! tdesc_has_registers (tdesc))
    tdesc = tdesc_amd64;

and then adds the fs_base/gs_base registers of the "tdesc_amd64" tdesc
to the tdesc_arch_data.

After amd64_init_abi returns, amd64_linux_init_abi does:

  if (! tdesc_has_registers (tdesc))
    tdesc = tdesc_amd64_linux;
  tdep->tdesc = tdesc;

and we end up tdesc_amd64_linux installed in tdep->tdesc.

The fix is to make sure that amd64_linux_init_abi and amd64_init_abi
agree on default tdesc, by adding a "default tdesc" parameter to
amd64_init_abi, instead of having amd64_init_abi hardcode a default.
With this, amd64_init_abi creates the fs_base/gs_base registers using
the tdesc_amd64_linux tdesc.

Tested on x86-64 GNU/Linux, -m64.  I don't have an x32 setup handy.

Thanks to John Baldwin, Yao Qi and Simon Marchi for the investigation.

gdb/ChangeLog:
2017-07-13  Pedro Alves  <palves@redhat.com>

	* amd64-darwin-tdep.c (x86_darwin_init_abi_64): Pass tdesc_amd64
	as default tdesc.
	* amd64-dicos-tdep.c (amd64_dicos_init_abi):
	* amd64-fbsd-tdep.c (amd64fbsd_init_abi):
	* amd64-linux-tdep.c (amd64_linux_init_abi): Pass
	tdesc_amd64_linux as default tdesc.  Get final tdesc from the
	tdep.
	(amd64_x32_linux_init_abi): Pass tdesc_x32_linux as default tdesc.
	Get final tdesc from the tdep.
	* amd64-nbsd-tdep.c (amd64nbsd_init_abi): Pass tdesc_amd64 as
	default tdesc.
	* amd64-obsd-tdep.c (amd64obsd_init_abi): Likewise.
	* amd64-sol2-tdep.c (amd64_sol2_init_abi): Likewise.
	* amd64-tdep.c (amd64_init_abi): Add 'default_tdesc' parameter.
	Use it as default tdesc.
	(amd64_x32_init_abi): Add 'default_tdesc' parameter, and pass it
	down to amd_init_abi.  No longer handle fallback tdesc here.
	* amd64-tdep.h (tdesc_x32): Declare.
	(amd64_init_abi, amd64_x32_init_abi): Add 'default_tdesc'
	parameter.
	* amd64-windows-tdep.c (amd64_windows_init_abi): Pass tdesc_amd64
	as default tdesc.
2017-07-13 20:56:42 +01:00
Andrew Burgess 5d2cbaa526 gdb: Fix parameter passing to mi_create_breakpoint
In the test gdb.mi/mi-vla-fortran.exp the parameters passed to
mi_create_breakpoint are passed in the wrong order.  By good luck the
tests still passes, however the wrong test name is used.  All fixed in
this commit.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-vla-fortran.exp: Correct parameter passing to
	mi_create_breakpoint.
2017-07-13 20:44:57 +01:00
Andreas Arnez 55efceabc6 S390: Add record/replay support for arch12 instructions
Support record/replay of the z/Architecture instructions that were
introduced with arch12.

gdb/ChangeLog:

	* s390-linux-tdep.c (s390_process_record): Add support for
	instructions new in arch12.
2017-07-13 20:17:03 +02:00
John Baldwin 0aa37b654c Support the fs_base and gs_base registers on FreeBSD/amd64 native processes.
Use ptrace operations to fetch and store the fs_base and gs_base registers
for FreeBSD/amd64 processes.  Note that FreeBSD does not currently store the
value of these registers in core dumps, so these registers are only
available when inspecting a running process.

gdb/ChangeLog:

	* amd64-bsd-nat.c (amd64bsd_fetch_inferior_registers): Use
	PT_GETFSBASE and PT_GETGSBASE.
	(amd64bsd_store_inferior_registers): Use PT_SETFSBASE and
	PT_SETGSBASE.
2017-07-11 09:47:14 -07:00
John Baldwin 48aeef91c2 Include the fs_base and gs_base registers in amd64 target descriptions.
This permits these registers to be used with non-Linux targets.

gdb/ChangeLog:

	* features/Makefile (amd64.dat, amd64-avx.dat, amd64-mpx.dat)
	(amd64-avx-mpx.dat, amd64-avx-avx512.dat)
	(amd64-avx-mpx-avx512-pku.dat): Add i386/64bit-segments.xml in
	those rules.
	* features/i386/amd64-avx-avx512.xml: Add 64bit-segments.xml.
        * features/i386/amd64-avx-mpx-avx512-pku.xml: Add 64bit-segments.xml.
	* features/i386/amd64-avx-mpx.xml: Add 64bit-segments.xml.
	* features/i386/amd64-avx.xml: Add 64bit-segments.xml.
	* features/i386/amd64-mpx.xml: Add 64bit-segments.xml.
	* features/i386/amd64.xml: Add 64bit-segments.xml.
	* features/i386/amd64-avx-avx512.c: Regenerated.
	* features/i386/amd64-avx-mpx-avx512-pku.c: Regenerated.
	* features/i386/amd64-avx-mpx.c: Regenerated.
	* features/i386/amd64-avx.c: Regenerated.
	* features/i386/amd64-mpx.c: Regenerated.
	* features/i386/amd64.c: Regenerated.
	* regformats/i386/amd64-avx-avx512.dat: Regenerated.
	* regformats/i386/amd64-avx-mpx-avx512-pku.dat: Regenerated.
	* regformats/i386/amd64-avx-mpx.dat: Regenerated.
	* regformats/i386/amd64-avx.dat: Regenerated.
	* regformats/i386/amd64-mpx.dat: Regenerated.
	* regformats/i386/amd64.dat: Regenerated.
2017-07-11 09:46:29 -07:00
Iain Buclaw 11cb57160f Sync dlang demangling tests from upstream libiberty testsuite.
Rationale behind the change instead of adding a `.init$' postfix being
that "initializer for symbol" is much more informative when inspecting D
runtime type information in gdb, which is the only place where you would
encounter references to this compiler-generated symbol.

gdb/testsuite/ChangeLog:

	* gdb.dlang/demangle.exp: Update for demangling changes.
2017-07-11 09:51:03 +02:00
Anton Kolesov 6dc8d7579d Add missing ChangeLog etries
This adds the missing ChangeLog entries for my previous patch

3d99e81 Import setenv and unsetenv from gnulib
2017-07-10 20:49:28 +03:00
Yao Qi 77c501bcea Re-generate i386/amd64-avx-avx512-linux.c and i386/amd64-avx-mpx-avx512-pku-linux.c
gdb:

2017-07-10  Yao Qi  <yao.qi@linaro.org>

	* features/i386/amd64-avx-avx512-linux.c: Re-generated.
	* features/i386/amd64-avx-mpx-avx512-pku-linux.c: Re-generated.
2017-07-10 12:00:35 +01:00
Yao Qi 2e1e43e140 Re-indent the code
gdb/gdbserver:

2017-07-10  Yao Qi  <yao.qi@linaro.org>

	* linux-x86-low.c (x86_linux_read_description): Re-indent the code.
2017-07-10 11:53:44 +01:00
Anton Kolesov 3d99e817a9 Import setenv and unsetenv from gnulib
This patch supersedes
https://sourceware.org/ml/gdb-patches/2017-07/msg00009.html

---

Patch [1] broke a build on MinGW hosts, because MinGW doesn't provide POSIX
functions setenv () and unsetenv ().  This can be fixed by using
implementations from gnulib.

[1] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=9a6c7d9c0

gdb/ChangeLog
yyyy-mm-dd  Anton Kolesov  <Anton.Kolesov@synopsys.com>

	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add setenv and
	unsetenv.
	* gnulib/aclocal.m4: Regenerate.
	* gnulib/config.in: Regenerate.
	* gnulib/configure: Regenerate.
	* gnulib/import/Makefile.am: Regenerate.
	* gnulib/import/Makefile.in: Regenerate.
	* gnulib/import/m4/gnulib-cache.m4: Regenerate.
	* gnulib/import/m4/gnulib-comp.m4: Regenerate.
	* gnulib/import/m4/environ.m4: New file.
	* gnulib/import/m4/setenv.m4: New file.
	* gnulib/import/setenv.c: New file.
	* gnulib/import/unsetenv.c: New file.
2017-07-10 13:23:12 +03:00
Simon Marchi 266934d1ad compile-loc2c: Fix uninitialized variable error
Compiling with clang gives this warning/error:

  /home/emaisin/src/binutils-gdb/gdb/compile/compile-loc2c.c:731:6: error: variable 'uoffset' is uninitialized when used here [-Werror,-Wuninitialized]
              uoffset += dwarf2_per_cu_text_offset (per_cu);
              ^~~~~~~
  /home/emaisin/src/binutils-gdb/gdb/compile/compile-loc2c.c:669:23: note: initialize the variable 'uoffset' to silence this warning
        uint64_t uoffset, reg;
                        ^
                         = 0

I am really not sure if what this patch does is good, but it is my best
guess.  DW_OP_addr means that there's an constant address provided by
the DWARF bytecode that should be pushed on the stack.  That address is
considered skipped by the "op_ptr += addr_size", but it is never read.
uoffset is indeed read just after, without having been assigned first.

So I think the intent is to read the address, it was just omitted.

gdb/ChangeLog:

	* compile/compile-loc2c.c (do_compile_dwarf_expr_to_c): Read
	address when op is DW_OP_addr.
2017-07-09 20:25:46 +02:00
Tom Tromey 0327869232 Fix size check in dwarf2_evaluate_loc_desc_full
This Rust bug report:

https://github.com/rust-lang/rust/issues/41970

noted an error from gdb.  What is happening here (for me, the original
report had a different error) is that a pieced DWARF expression is not
writing to every byte in the resulting value.  GDB errors in this
case.  However, it seems to me that it is always valid to write fewer
bytes; the issue comes from writing too many -- that is, the test is
reversed.  The test was also checking the sub-object, but this also
seems incorrect, as it's expected for the expression to write the
entirety of the enclosing object.  So, this patch reverses the test
and applies it to the outer type, not the subobject type.

Regtested on the buildbot.

gdb/ChangeLog
2017-07-09  Tom Tromey  <tom@tromey.com>

	* dwarf2loc.c (dwarf2_evaluate_loc_desc_full): Reverse size
	check and apply to outer type.

gdb/testsuite/ChangeLog
2017-07-09  Tom Tromey  <tom@tromey.com>

	* gdb.dwarf2/shortpiece.exp: New file.
2017-07-09 10:46:49 -06:00
John Baldwin 4b654465bf Read signal information from FreeBSD core dumps.
FreeBSD recently added a new ELF core note which dumps the entire LWP
info structure (the same structure returned by the ptrace PT_LWPINFO
operation) for each thread.  The plan is for this note to eventually
supplant the older "thrmisc" ELF core note as it contains more
information and it permits new information to be exported via both
ptrace() and core dumps using the same structure.

For signal information, the implementation is similar to the native
implementation for FreeBSD processes.  The PL_FLAG_SI flag must be
checked to determine if the embedded siginfo_t structure is valid, and
if so it is transferred into the caller's buffer.

gdb/ChangeLog:

	* fbsd-tdep.c (LWPINFO_OFFSET, LWPINFO_PL_FLAGS)
	(LWPINFO64_PL_SIGINFO, LWPINFO32_PL_SIGINFO, PL_FLAG_SI)
	(SIZE64_SIGINFO_T, SIZE32_SIGINFO_T, fbsd_core_xfer_siginfo): New.
	(fbsd_init_abi): Install gdbarch "core_xfer_siginfo" method.
2017-07-07 16:12:42 -07:00
John Baldwin 2af9fc4432 Use the thread_section_name helper class in fbsd_core_thread_name.
gdb/ChangeLog:

	* fbsd-tdep.c (fbsd_core_thread_name): Use thread_section_name.
2017-07-07 16:09:13 -07:00
John Baldwin 382b69bbb7 Add a new gdbarch method to fetch signal information from core files.
Previously the core_xfer_partial method used core_get_siginfo to handle
TARGET_OBJECT_SIGNAL_INFO requests.  However, core_get_siginfo looked for
Linux-specific sections in the core file.  To support fetching siginfo
from cores on other systems, add a new gdbarch method (`core_xfer_siginfo`)
and move the body of the existing core_get_siginfo into a
linux_core_xfer_siginfo implementation of this method in linux-tdep.c.

gdb/ChangeLog:

	* corelow.c (get_core_siginfo): Remove.
	(core_xfer_partial): Use the gdbarch "core_xfer_siginfo" method
	instead of get_core_siginfo.
	* gdbarch.sh (core_xfer_siginfo): New gdbarch callback.
	* gdbarch.h: Re-generate.
	* gdbarch.c: Re-generate.
	* linux-tdep.c (linux_core_xfer_siginfo): New.
	(linux_init_abi): Install gdbarch "core_xfer_siginfo" method.
2017-07-07 16:08:33 -07:00
John Baldwin 6e5eab33ab Move the thread_section_name class to gdbcore.h.
This allows it to be used outside of corelow.c.
2017-07-07 16:06:45 -07:00
John Baldwin 929edea98d Fetch signal information for native FreeBSD processes.
Use the `pl_siginfo' field in the `struct ptrace_lwpinfo' object returned
by the PT_LWPINFO ptrace() request to supply the current contents of
$_siginfo for each thread.  Note that FreeBSD does not supply a way to
modify the signal information for a thread, so $_siginfo is read-only for
FreeBSD.

To handle 32-bit processes on a 64-bit host, define types for 32-bit
compatible siginfo_t and convert the 64-bit siginfo_t to the 32-bit
equivalent when supplying information for a 32-bit process.

gdb/ChangeLog:

	* fbsd-nat.c [PT_LWPINFO && __LP64__] (union sigval32)
	(struct siginfo32): New.
	[PT_LWPINFO] (fbsd_siginfo_size, fbsd_convert_siginfo): New.
	(fbsd_xfer_partial) [PT_LWPINFO]: Handle TARGET_OBJECT_SIGNAL_INFO
	via ptrace(PT_LWPINFO).
2017-07-07 16:05:47 -07:00
John Baldwin 762c974a09 Implement the "get_siginfo_type" gdbarch method for FreeBSD architectures.
As with Linux architectures, cache the created type in the gdbarch when it
is first created.  Currently FreeBSD uses an identical siginfo type on
all architectures, so there is no support for architecture-specific fields.

gdb/ChangeLog:

	* fbsd-tdep.c (fbsd_gdbarch_data_handle, struct fbsd_gdbarch_data)
	(init_fbsd_gdbarch_data, get_fbsd_gdbarch_data)
	(fbsd_get_siginfo_type): New.
	(fbsd_init_abi): Install gdbarch "get_siginfo_type" method.
	(_initialize_fbsd_tdep): New.
2017-07-07 16:04:18 -07:00
David Blaikie 33c5cd7587 Fission support for multiple CUs per DWO file
In some cases a compiler may produce a single object file (& thus single
DWO file) representing multiple source files. The most common example of
this is in whole program optimization (such as LLVM's LTO). Fission may
still be a beneficial feature to use here - to avoid the need to
read/link the debug info with system libraries and the like.

This change adds basic support for multiple CUs in a single DWO file to
support LLVM's output in this situation.

There is still outstanding work to design and implement a solution for
cross-CU references (usually using DW_FORM_ref_addr) in this scenario.
For now LLVM works around this by duplicating DIEs rather than making
cross-CU references in DWO files. This degrades debugger
behavior/quality especially for file-local entities.

2017-07-06  David Blaikie  <dblaikie@gmail.com>

	* dwarf2read.c (struct dwo_file): Use a htab of dwo_unit* (rather than
	a singular dwo_unit*) to support multiple CUs in the same way that
	multiple TUs are supported.
	(create_cus_hash_table): Replace create_dwo_cu with a function for
	parsing multiple CUs from a DWO file.
	(open_and_init_dwo_file): Use create_cus_hash_table rather than
	create_dwo_cu.
	(lookup_dwo_cutu): Lookup CU in the hash table in the dwo_file with
	htab_find, rather than comparing the signature to a singleton CU in
	the dwo_file.

2017-07-06  David Blaikie  <dblaikie@gmail.com>

	* gdb.dwarf2/fission-multi-cu.S: Test containing multiple CUs in a DWO,
	built from fissiont-multi-cu{1,2}.c.
	* gdb.dwarf2/fission-multi-cu.exp: Test similar to fission-base.exp,
	except putting 'main' and 'func' in separate CUs in the same DWO file.
	* gdb.dwarf2/fission-multi-cu1.c: First CU for the multi-CU-single-DWO
	test.
	* gdb.dwarf2/fission-multi-cu2.c: Second CU in the multi-CU-single-DWO
	test.
2017-07-06 11:59:39 -07:00
Pedro Alves 8455d26243 Fix Python unwinder frames regression
The gdb.python/py-unwind.exp test is crashing GDB / leaving core dumps
in the test dir, even though it all passes cleanly.  The crash is not
visible in gdb.sum/gdb.log because it happens as side effect of the
"quit" command, while flushing the frame cache.

The problem is simply a typo in a 'for' loop's condition, introduced
by a recent change [4fa847d78e ("Remove MAX_REGISTER_SIZE from
py-unwind.c")], resulting in infinite loop / double-free.

The new test exposes the crash, like:

 Running src/gdb/testsuite/gdb.python/py-unwind.exp ...
 ERROR: Process no longer exists

gdb/ChangeLog:
2017-07-06  Pedro Alves  <palves@redhat.com>

	* python/py-unwind.c (pyuw_dealloc_cache): Fix for loop condition.

gdb/testsuite/ChangeLog:
2017-07-06  Pedro Alves  <palves@redhat.com>

	* gdb.python/py-unwind.exp: Test flushregs.
2017-07-06 00:19:24 +01:00
Pedro Alves 4da3eb35ef Garbage collect TYPE_STATIC and several TYPE_FN_FIELD_x
Nothing uses these.  Most of the TYPE_FN_FIELD_ ones were probably
used by the gcj support.

gdb/ChangeLog:
2017-07-04  Pedro Alves  <palves@redhat.com>

	* gdbtypes.c (recursive_dump_type): Don't reference TYPE_STATIC.
	* gdbtypes.h (TYPE_STATIC): Delete.
	(struct fn_field) <is_public, is_abstract, is_static, is_final,
	is_synchronized, is_native>: Delete.
	<dummy>: Bump.
	(TYPE_FN_FIELD_PUBLIC, TYPE_FN_FIELD_STATIC, TYPE_FN_FIELD_FINAL)
	(TYPE_FN_FIELD_SYNCHRONIZED, TYPE_FN_FIELD_NATIVE)
	(TYPE_FN_FIELD_ABSTRACT): Delete.
2017-07-04 18:40:26 +01:00
Simon Marchi 5bfd255c41 buffer.h: Fix spelling mistakes
gdb/ChangeLog:

	* buffer.h (buffer_finish): Fix spelling mistakes.
2017-07-03 13:59:00 +02:00
Eli Zaretskii 25c5412713 Setup .dir-locals.el to use C-style comments by default
gdb/ChangeLog:
2017-07-01  Eli Zaretskii  <eliz@gnu.org>

	* .dir-locals.el: Automatically switch to C-style comments in
	versions of Emacs that support the feature.
2017-07-01 18:45:57 +03:00
Sergio Durigan Junior dc4bde35d1 PR cli/21688: Detect aliases when issuing python/compile/guile commands (and fix last commit)
My last commit fixed a regression that happened when using
inline/multi-line commands for Python/Compile/Guile, but introduced
another regression: it is now not possible to use aliases for the
commands mentioned above.  The fix is to almost revert the change I've
made and go back to using the 'struct cmd_list_element *', but at the
same time make sure that we advance the 'cmd_name' variable past all
the whitespace characters after the command name.  If, after skipping
the whitespace, we encounter a '\0', it means that the command is not
inline.  Otherwise, it is.

This patch also expands the testcase in order to check for aliases and
for trailing whitespace after the command name.

gdb/ChangeLog:
2017-06-30  Sergio Durigan Junior  <sergiodj@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	PR cli/21688
	* cli/cli-script.c (command_name_equals_not_inline): Remove function.
	(process_next_line): New variable 'inline_cmd'.
	Adjust 'if' clauses for "python", "compile" and "guile" to use
	'command_name_equals' and check for '!inline_cmd'.

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

	PR cli/21688
	* gdb.python/py-cmd.exp (test_python_inline_or_multiline): Add new
	tests for alias commands and trailing whitespace.
2017-06-30 09:31:21 -04:00
Sergio Durigan Junior 51ed89aa0d PR cli/21688: Fix multi-line/inline command differentiation
This bug is a regression caused by the following commit:

  604c4576fd is the first bad commit
  commit 604c4576fd
  Author: Jerome Guitton <guitton@adacore.com>
  Date:   Tue Jan 10 15:15:53 2017 +0100

The problem happens because, on cli/cli-script.c:process_next_line,
GDB is not using the command line string to identify which command to
run, but it instead using the 'struct cmd_list_element *' that is
obtained by using the mentioned string.  The problem with that is that
the 'struct cmd_list_element *' doesn't have any information on
whether the command issued by the user is a multi-line or inline one.

A multi-line command is a command that will necessarily be composed of
more than 1 line.  For example:

  (gdb) if 1
  >python
   >print ('hello')
   >end
  >end

As can be seen in the example above, the 'python' command actually
"opens" a new command line (represented by the change in the
indentation) that will then be used to enter Python code.  OTOH, an
inline command is a command that is "self-contained" in a single line,
for example:

  (gdb) if 1
  >python print ('hello')
  >end

This Python command is a one-liner, and therefore there is no other
Python code that can be entered for this same block.  There is also no
change in the indentation.

So, the fix is somewhat simple: we have to revert the change and use
the full command line string passed to process_next_line in order to
identify whether we're dealing with a multi-line or an inline command.
This commit does just that.  As can be seen, this regression also
affects other languages, like guile or the compile framework.  To make
things clearer, I decided to create a new helper function responsible
for identifying a non-inline command.

Testcase is attached.

gdb/ChangeLog:
2017-06-30  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR cli/21688
	* cli/cli-script.c (command_name_equals_not_inline): New function.
	(process_next_line): Adjust 'if' clauses for "python", "compile"
	and "guile" to use command_name_equals_not_inline.

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

	PR cli/21688
	* gdb.python/py-cmd.exp (test_python_inline_or_multiline): New
	procedure.  Call it.
2017-06-30 07:14:29 -04:00
Pedro Alves eb17d4137d Expression completer should not match explicit location options
This commit fixes a mismatch between what "print" command completer
thinks the command understands, and what the command actually
understands.

The explicit location options are understood by commands that take
(linespecs and) explicit locations as argument.  I.e, breakpoint
commands, and "list".  For example:

 (gdb) b -source file.c -function my_func

So for those commands, it makes sense that the completer
completes:

 "b -sour[TAB]" -> "b -source "
 "b -functi[TAB]" -> "b -function "

etc.

However, completion for commands that take expressions (not
linespecs/locations) as arguments, such as the "print" command, also
completes the explicit location options, even though those switches
aren't really understood by these commands.  Instead, "-foo" is
understood as an expression applying unary minus on a symbol named
"foo" (think "print -1"):

 (gdb) p -func[TAB]
 (gdb) p -function [RET]
 No symbol "function" in current context.

The patch fixes this by having the expression_completer function
bypass the function that completes explicit locations.

New regression tests included.

gdb/ChangeLog:
2017-06-29  Pedro Alves  <palves@redhat.com>

	* completer.c (expression_completer): Call
	linespec_location_completer instead of location_completer.

gdb/testsuite/ChangeLog:
2017-06-29  Pedro Alves  <palves@redhat.com>

	* gdb.base/printcmds.exp: Add tests.
2017-06-29 15:53:48 +01:00
Pedro Alves 195bcdd518 Remove old stale expression_completer hack
The code in question was introduced by:

 https://sourceware.com/ml/gdb-patches/2008-06/msg00143.html

"The fix is to make sure that the entire expression is passed to
expression_completer, then duplicate some logic there in the case
where location_completer is called."

The logic that was duplicated was much later on removed by the
original explicit locations patch:

 commit 87f0e72047
 Author:     Keith Seitz <keiths@redhat.com>
 AuthorDate: Tue Aug 11 17:09:36 2015 -0700
 Commit:     Keith Seitz <keiths@redhat.com>
 CommitDate: Tue Aug 11 17:09:36 2015 -0700

     Explicit locations: add UI features for CLI

 @@ -688,16 +880,6 @@ complete_line_internal (const char *text,
		       rl_completer_word_break_characters =
			 gdb_completer_file_name_break_characters;
		     }
 -                 else if (c->completer == location_completer)
 -                   {
 -                     /* Commands which complete on locations want to
 -                        see the entire argument.  */
 -                     for (p = word;
 -                          p > tmp_command
 -                            && p[-1] != ' ' && p[-1] != '\t';
 -                          p--)
 -                       ;
 -                   }

However this case in expression_completer was left behind.

I couldn't come up with a test where this currently makes any
difference.

gdb/ChangeLog:
2017-06-29  Pedro Alves  <palves@redhat.com>

	* completer.c (expression_completer): Remove code that recomputes
	'text' from 'word'.
2017-06-29 15:52:37 +01:00
Yao Qi adc764e7d2 Use target_desc fields expedite_regs and xmltarget ifndef IN_PROCESS_AGENT
struct target_desc is used by both GDBserver and IPA, but fields
expedite_regs and xmltarget are only used in GDBserver, so this patch wraps
these two fields by ifndef IN_PROCESS_AGENT.  This patch also changes
regformats/regdat.sh to generate .c files in this way too.

gdb/gdbserver:

2017-06-29  Yao Qi  <yao.qi@linaro.org>

	* tdesc.h (struct target_desc) [IN_PROCESS_AGENT] <expedite_regs>:
	Remove.
	[IN_PROCESS_AGENT] <xmltarget>: Likewise.

gdb:

2017-06-29  Yao Qi  <yao.qi@linaro.org>

	* regformats/regdat.sh: Generate code with
	"ifndef IN_PROCESS_AGENT".
2017-06-29 12:41:50 +01:00
Pedro Alves 6e75794e9d gdb/command.h: Include common/scoped_restore.h
command.h depends on scoped_restore:

  extern scoped_restore_tmpl<int> prevent_dont_repeat (void);

But doesn't include the corresponding header
("common/scoped_restore.h").  We haven't noticed a problem because
utils.h includes scoped_restore.h, and defs.h includes utils.h.

However, a patch that makes "symtab.h" include "completer.h", exposed
the issue:
 https://sourceware.org/ml/gdb-patches/2017-06/msg00023.html.

Without this fix that would break building all .o files like this:

 In file included from src/gdb/completer.h:21:0,
                  from src/gdb/symtab.h:28,
                  from src/gdb/language.h:26,
                  from src/gdb/frame.h:72,
                  from src/gdb/gdbarch.h:39,
                  from src/gdb/defs.h:636,
                  from src/gdb/top.c:20:
 src/gdb/command.h:434:8: error: ‘scoped_restore_tmpl’ does not name a type
  extern scoped_restore_tmpl<int> prevent_dont_repeat (void);
         ^
 Makefile:1911: recipe for target 'top.o' failed

because defs.h includes gdbarch.h before it includes utils.h.

gdb/ChangeLog:
2017-06-28  Pedro Alves  <palves@redhat.com>

	* command.h: Include "common/scoped_restore.h".
2017-06-28 15:19:02 +01:00
Yao Qi bc491f2e76 Use obstack_grow_str
We already have macro obstack_grow_str, which is helpful to shorten the
code.

gdb:

2017-06-28  Yao Qi  <yao.qi@linaro.org>

	* mi/mi-cmd-break.c (mi_argv_to_format): Use obstack_grow_str
	instead of obstack_grow.
2017-06-28 15:00:27 +01:00
Doug Gilmore 41664b45ab Fix PR 21337: segfault when re-reading symbols.
Fix issue exposed by commit 3e29f34.

The basic issue is that section data referenced through an objfile
pointer can also be referenced via the program-space data pointer,
although via a separate mapping mechanism, which is set up by
update_section_map.  Thus once section data attached to an objfile
pointer is released, the section map associated with the program-space
data pointer must be marked dirty to ensure that update_section_map is
called to prevent stale data being referenced.  For the matter at hand
this marking is being done via a call to objfiles_changed.

Before commit 3e29f34 objfiles_changed could be called after all of
the objfile pointers were processed in reread_symbols since section
data references via the program-space data pointer would not occur in
the calls of read_symbols performed by reread_symbols.

With commit 3e29f34 MIPS target specific calls to find_pc_section were
added to the code for DWARF information processing, which is called
via read_symbols.  Thus in reread_symbols the call to objfiles_changed
needs to be called before calling read_symbols, otherwise stale
section data can be referenced.

Thanks to Luis Machado for providing text for the main comment
associated with the change.

gdb/
2017-06-28  Doug Gilmore  <Doug.Gilmore@imgtec.com>
    PR gdb/21337
    * symfile.c (reread_symbols): Call objfiles_changed just before
    read_symbols.

gdb/testsuite/
2017-06-28  Doug Gilmore  <Doug.Gilmore@imgtec.com>
    PR gdb/21337
    * gdb.base/reread-readsym.exp: New file.
    * gdb.base/reread-readsym.c: New file.
2017-06-28 02:54:22 +01:00
Pedro Alves 6da67eb10d completion_list_add_name wrapper functions
Replace macros with functions.

gdb/ChangeLog:
2017-06-27  Pedro Alves  <palves@redhat.com>

	* symtab.c (COMPLETION_LIST_ADD_SYMBOL)
	(MCOMPLETION_LIST_ADD_SYMBOL): Delete macros, replace with ...
	(completion_list_add_symbol, completion_list_add_msymbol):
	... these new functions.
	(add_symtab_completions)
	(default_make_symbol_completion_list_break_on_1): Adjust.
2017-06-27 16:32:57 +01:00
Pedro Alves 23732b1e32 objfile_per_bfd_storage non-POD
A following patch will want to add a std::vector to
objfile_per_bfd_storage.  That makes it non-trivially
constructible/destructible.  Since objfile_per_bfd_storage objects are
allocated on an obstack, we need to call their ctors/dtors manually.
This is what this patch does.  And then since we can now rely on
ctors/dtors being run, make objfile_per_bfd_storage::storage_obstack
be an auto_obstack.

gdb/ChangeLog:
2017-06-27  Pedro Alves  <palves@redhat.com>

	* objfiles.c (get_objfile_bfd_data): Call bfd_alloc instead of
	bfd_zalloc.  Call objfile_per_bfd_storage's ctor.
	(free_objfile_per_bfd_storage): Call objfile_per_bfd_storage's
	dtor.
	* objfiles.h (objfile_per_bfd_storage): Add ctor.  Make
	'storage_obstack' field an auto_obstack.  In-class initialize all
	non-bitfield fields.  Make minsyms_read bool.
	* symfile.c (read_symbols): Adjust.
2017-06-27 16:22:08 +01:00
Alan Hayward a4d1e79aaa Remove MAX_REGISTER_SIZE from remote-sim.c
gdb/
	* remote-sim.c (gdbsim_fetch_register): Use byte_vector.
	(gdbsim_store_register): Likewise.
2017-06-27 13:10:16 +01:00
Pedro Alves 8268c77870 Eliminate make_cleanup_obstack_free, introduce auto_obstack
This commit eliminates make_cleanup_obstack_free, replacing it with a
new auto_obstack type that inherits obstack to add cdtors.

These changes in the parsers may not be obvious:

 -  obstack_init (&name_obstack);
 -  make_cleanup_obstack_free (&name_obstack);
 +  name_obstack.clear ();

Here, the 'name_obstack' variable is a global.  The change means that
the obstack's contents from a previous parse will stay around until
the next parsing starts.  I.e., memory won't be reclaimed until then.
I don't think that's a problem, these objects don't really grow much
at all.

The other option I tried was to add a separate type that is like
auto_obstack but manages an external obstack, just for those cases.  I
like the current approach better as that other approach adds more
boilerplate and yet another type to learn.

gdb/ChangeLog:
2017-06-27  Pedro Alves  <palves@redhat.com>

	* c-exp.y (name_obstack): Now an auto_obstack.
	(yylex): Use auto_obstack::clear.
	(c_parse): Use auto_obstack::clear instead of reinitializing and
	freeing the obstack.
	* c-lang.c (evaluate_subexp_c): Use auto_obstack.
	* d-exp.y (name_obstack): Now an auto_obstack.
	(yylex): Use auto_obstack::clear.
	(d_parse): Use auto_obstack::clear instead of reinitializing and
	freeing the obstack.
	* dwarf2loc.c (fetch_const_value_from_synthetic_pointer): Use
	auto_obstack.
	* dwarf2read.c (create_addrmap_from_index)
	(dwarf2_build_psymtabs_hard)
	(update_enumeration_type_from_children): Likewise.
	* gdb_obstack.h (auto_obstack): New type.
	* go-exp.y (name_obstack): Now an auto_obstack.
	(build_packaged_name): Use auto_obstack::clear.
	(go_parse): Use auto_obstack::clear instead of reinitializing and
	freeing the obstack.
	* linux-tdep.c (linux_make_mappings_corefile_notes): Use
	auto_obstack.
	* printcmd.c (printf_wide_c_string, ui_printf): Use auto_obstack.
	* rust-exp.y (work_obstack): Now an auto_obstack.
	(rust_parse, rust_lex_tests): Use auto_obstack::clear instead of
	reinitializing and freeing the obstack.
	* utils.c (do_obstack_free, make_cleanup_obstack_free): Delete.
	(host_char_to_target): Use auto_obstack.
	* utils.h (make_cleanup_obstack_free): Delete declaration.
	* valprint.c (generic_emit_char, generic_printstr): Use
	auto_obstack.
2017-06-27 11:07:14 +01:00
Simon Marchi db665f427c darwin: Do not add a dummy thread
Starting a process on macOS/Darwin currently leads to this error:

/Users/simark/src/binutils-gdb/gdb/darwin-nat.c:383: internal-error: void darwin_check_new_threads(struct inferior *): Assertion `tp' failed.

with the corresponding partial backtrace (sorry, taken with lldb,
because well, gdb is broken :)):

    frame #9: 0x000000010004605a gdb`darwin_check_new_threads(inf=0x0000000100edf670) at darwin-nat.c:383
    frame #10: 0x0000000100045848 gdb`darwin_init_thread_list(inf=0x0000000100edf670) at darwin-nat.c:1710
    frame #11: 0x00000001000452f8 gdb`darwin_ptrace_him(pid=8375) at darwin-nat.c:1792
    frame #12: 0x0000000100041d95 gdb`fork_inferior(...) at fork-inferior.c:440
    frame #13: 0x0000000100043f82 gdb`darwin_create_inferior(...) at darwin-nat.c:1841
    frame #14: 0x000000010034ac32 gdb`run_command_1(args=0x0000000000000000, from_tty=1, tbreak_at_main=1) at infcmd.c:611

The issue was introduced by commit

  "Share fork_inferior et al with gdbserver"

because it changed the place where the dummy thread (pid, 0, 0) is added,
relative to the call to the init_trace_fun callback.  In this callback, darwin
checks for new threads in the program (there should be exactly one) in order to
update this dummy thread with the right tid.  Previously, things happened in
this order:

 - fork_inferior calls fork()
 - fork_inferior adds dummy thread
 - fork_inferior calls init_trace_fun callback, which updates the dummy
   thread info

Following the commit mentioned above, the new thread is added in the
darwin-nat code, after having called fork_inferior (in
darwin_create_inferior).  So gdb tries to do things in this order:

 - fork_inferior calls fork()
 - fork_inferior calls init_trace_fun callback, which tries to update
   the dummy thread info
 - darwin_create_inferior adds the dummy thread

The error happens while trying to update the dummy thread that has not
been added yet.

I don't think this dummy thread is necessary for darwin.  Previously, it
was fork_inferior that was adding this thread, for all targets, so
darwin had to deal with it.  Now that it's done by targets themselves,
we can just skip that on darwin.  darwin_check_new_threads called
indirectly by init_trace_fun/darwin_ptrace_him will simply notice the
new thread and add it with the right information.

My level of testing was: try to start a process and try to attach to a
process, and it seems to work somewhat like it did before.  I tried to
run the testsuite, but it leaves a huge amount of zombie processes that
launchd doesn't seem to reap, leading to exhaustion of system resources
(number of processes).

gdb/ChangeLog:

	* darwin-nat.c (darwin_check_new_threads): Don't handle dummy
	thread.
	(darwin_init_thread_list): Don't update dummy thread.
	(darwin_create_inferior, darwin_attach): Don't add a dummy thread.
2017-06-27 10:56:53 +02:00
Simon Marchi 873c08142c record-full: Remove unused function netorder16
clang shows this warning:

  /home/emaisin/src/binutils-gdb/gdb/record-full.c:2344:1: error: unused function 'netorder16' [-Werror,-Wunused-function]
  netorder16 (uint16_t input)
  ^

Remove this function, which, AFAIK, has never been used.  Note that GCC
doesn't warn about this, because the function is marked as inline.
According to gcc's man page, it should ideed not warn:

  -Wunused-function
    Warn whenever a static function is declared but not defined or a non-inline static function is unused.  This warning is enabled by -Wall.

So it's probably not a GCC bug that it doesn't find this unused function, but a
different definition of "unused".

gdb/ChangeLog:

	* record-full.c (netorder16): Remove.
2017-06-26 16:51:17 +02:00
Simon Marchi 8b5a7a6e8c vec: Silence -Wunused-function warnings on clang
clang has a too aggressive (or broken, depends on how you want to see
it) -Wunused-function warning, which is triggered by the functions
defined by DEF_VEC_* but not used in the current source file.  Normally,
it won't warn about unused static inline functions defined in header
files, because it's expected that a source file won't use all functions
defined in a header file it includes.  However, if the DEF_VEC_* macro
is used in a source file, it considers those functions as defined in the
source file, which leads it to think that we should remove those
functions.  It is therefore missing a check to see whether those
functions are resulting from macro expansion.  A bug already exists for
that:

  https://bugs.llvm.org//show_bug.cgi?id=22712

It's quite easy to silence this warning in a localized way, that is in
the DEF_VEC_* macros.

gdb/ChangeLog:

	* common/diagnostics.h: Define macros for GCC.
	(DIAGNOSTIC_IGNORE_UNUSED_FUNCTION): New macro.
	* common/vec.h: Include diagnostics.h.
	(DIAGNOSTIC_IGNORE_UNUSED_VEC_FUNCTION): New macro.
	(DEF_VEC_I, DEF_VEC_P, DEF_VEC_O): Ignore -Wunused-function
	warning.
2017-06-26 16:51:17 +02:00
Simon Marchi d1435379df ada-lex: Ignore warnings about register keyword
Some older versions of flex (such as the one shipped with macOS) generate
code that use the register keyword, which clang warns about.  This patch
makes the compiler ignore those warnings for the portion of the code
generated by flex.

gdb/ChangeLog:

	* common/diagnostics.h (DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER):
	New macro.
	* ada-lex.l: Ignore deprecated register warnings.
2017-06-26 16:51:17 +02:00
Simon Marchi cc75e0fdae main: Don't add int to string
clang shows this warning:

  /home/emaisin/src/binutils-gdb/gdb/main.c:227:56: error: adding 'int' to a string does not append to the string [-Werror,-Wstring-plus-int]
                char *tmp_sys_gdbinit = xstrdup (SYSTEM_GDBINIT + datadir_len);
                                                 ~~~~~~~~~~~~~~~^~~~~~~~~~~~~
  /home/emaisin/src/binutils-gdb/gdb/main.c:227:56: note: use array indexing to silence this warning
                char *tmp_sys_gdbinit = xstrdup (SYSTEM_GDBINIT + datadir_len);
                                                                ^
                                                 &              [            ]

It's quite easy to get rid of it by using &foo[len] instead of foo + len.
I think this warning is relevant to keep enabled, because it can be an
easy mistake to do.

This warning is already discussed here in GCC bugzilla:

  https://gcc.gnu.org/ml/gcc-patches/2017-06/msg00729.html

and a patch series for it was submitted very recently.

gdb/ChangeLog:

	* main.c (get_init_files): Replace "SYSTEM_GDBINIT +
	datadir_len" with "&SYSTEM_GDBINIT[datadir_len]".
2017-06-25 12:57:13 +02:00
Simon Marchi 07809eafc9 dtrace-probe: Put semicolon after while on its own line
clang shows this warning.

  /home/emaisin/src/binutils-gdb/gdb/dtrace-probe.c:424:52: error: while loop has empty body [-Werror,-Wempty-body]
            while (*p++ != '\0' && p - strtab < strtab_size);
                                                            ^
  /home/emaisin/src/binutils-gdb/gdb/dtrace-probe.c:424:52: note: put the semicolon on a separate line to silence this warning

Putting the semicolon on its own line is not a big sacrifice to get rid of this
warning.  I think it's also useful to keep this, because it can catch errors
like this:

  while (something);
    {
      ...
    }

although gcc would warn about it in a different way (misleading indentation).

This warning is already discussed here in the GCC bugzilla:

  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62184

gdb/ChangeLog:

	* dtrace-probe.c (dtrace_process_dof_probe): Put semi-colon on
	its own line.
2017-06-25 12:49:19 +02:00
Simon Marchi f076f0349c x86-dregs: Print debug registers one per line
This get around this warning given by clang...

  /home/emaisin/src/binutils-gdb/gdb/nat/x86-dregs.c:209:7: error: variable 'i' is incremented both in the loop header and in the loop body [-Werror,-Wfor-loop-analysis]
        i++;
        ^
  /home/emaisin/src/binutils-gdb/gdb/nat/x86-dregs.c:199:32: note: incremented here
    ALL_DEBUG_ADDRESS_REGISTERS (i)
                               ^

... I decided in the end to simply print the debug registers one per
line.  I don't think it particularly helps readability to have them two
per line anyway.

gdb/ChangeLog:

	* nat/x86-dregs.c (x86_show_dr): Print registers one per line.
2017-06-25 12:40:10 +02:00
Alan Hayward 0dd5cbc563 Add XTENSA_MAX_REGISTER_SIZE
gdb/
	* xtensa-tdep.c (XTENSA_MAX_REGISTER_SIZE): Add.
	(xtensa_register_write_masked): Use XTENSA_MAX_REGISTER_SIZE.
	(xtensa_register_read_masked): Likewise.
2017-06-23 10:21:39 +01:00
Sergio Durigan Junior d4c6ce5b01 Update comment on gdb_environ::unset
gdb_environ::unset iterates using '.end () - 1' now, instead of '.cend
() - 1'.  This obvious patch updates the comment.

gdb/ChangeLog:
2017-06-22  Sergio Durigan Junior  <sergiodj@redhat.com>

	* common/environ.c (gdb_environ::unset): Update comment.
2017-06-22 14:50:24 -04:00
Alan Hayward 16892a0323 Fix cached_frame allocation in py-unwind
gdb/
	* python/py-unwind.c (pyuw_sniffer): Allocate space for
	registers.
2017-06-22 16:30:15 +01:00
Alan Hayward d7dcbefc72 Remove an instance of MAX_REGISTER_SIZE from record-full.c
gdb/
	* record-full.c (record_full_exec_insn): Use byte_vector.
2017-06-22 15:33:18 +01:00
Yao Qi b30ff123fb Regenerate two regformats/i386/.dat files
The self tests which compare pre-generated target descriptions and
dynamically created target descriptions fail, and it turns out that two
pre-generated target descriptions are wrong, so regenerate them.

gdb:

2017-06-22  Yao Qi  <yao.qi@linaro.org>

	* regformats/i386/amd64-avx-mpx-avx512-pku-linux.dat: Regenerated.
	* regformats/i386/amd64-avx-mpx-avx512-pku.dat: Regenerated.
2017-06-22 14:13:57 +01:00
Alan Hayward 4fa847d78e Remove MAX_REGISTER_SIZE from py-unwind.c
gdb/
	* remote.c (cached_reg): Move from here...
	* regcache.h (cached_reg): ...to here.
	* python/py-unwind.c (struct reg_info): Remove.
	(cached_frame_info): Use cached_reg_t.
	(pyuw_prev_register): Likewise.
	(pyuw_sniffer): Use cached_reg_t and allocate registers.
	(pyuw_dealloc_cache): Free all registers.
2017-06-22 14:10:34 +01:00
Pedro Alves f4906a9a74 environ-selftests: Ignore -Wself-move warning
clang gives this warning:

 ..../gdb/unittests/environ-selftests.c:139:7: error: explicitly moving variable of type 'gdb_environ' to itself [-Werror,-Wself-move]
   env = std::move (env);
   ~~~ ^            ~~~

Ignoring the warning locally is the right thing to do, since it warns
about behavior we want to unit test, while an explicit self-move in
real code would likely be a mistake that we'd want to catch.

To avoid cluttering the code with preprocessor conditionals, this
commit adds the file common/diagnostics.h, in which we can put macros
used to control compiler diagnostics.

GCC enhancement request here:
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81159

gdb/ChangeLog:
2017-06-22  Pedro Alves  <palves@redhat.com>
	    Simon Marchi  <simon.marchi@ericsson.com>

	* unittests/environ-selftests.c (run_tests): Ignore -Wself-move
	warning.
	* common/diagnostics.h: New file.
2017-06-22 11:18:49 +01:00
Pedro Alves d269dfc64f Add STRINGIFY to gdb/common/preprocessor.h
We have several copies of this common idiom under gdb/ currently.
This commit moves them / factors them out to gdb/common/preprocessor.h.

gdb/ChangeLog:
2017-06-22  Pedro Alves  <palves@redhat.com>

	* common/agent.h: Include "common/preprocessor.h".
	(STRINGIZE_1, STRINGIZE): Delete.
	(IPA_SYM): Use STRINGIFY instead.
	* common/preprocessor.h (STRINGIFY_1, STRINGIFY): New.
	* compile/compile-c-support.c: Include "common/preprocessor.h".
	(STR, STRINGIFY): Delete.
	* ia64-libunwind-tdep.c: Include "common/preprocessor.h".
	(STRINGIFY2, STRINGIFY): Delete.
2017-06-22 10:59:42 +01:00
Pedro Alves b45a120833 common/agent.h: Add missing include guards
gdb/ChangeLog:
2017-06-22  Pedro Alves  <palves@redhat.com>

	* common/agent.h: Add include guards.
2017-06-22 10:57:13 +01:00
Kevin Buettner 75312ae3ab Use noncapturing subpattern/parens in gdb_test implementation
This is the portion of gdb_test which performs the match against
the RE (regular expression) passed to it:

    return [gdb_test_multiple $command $message {
        -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
            if ![string match "" $message] then {
                pass "$message"
            }
        }

In a test that I've been working on recently, I wanted to use
a backreference - that's the \1 in the the RE below:

gdb_test "info threads"  \
	{.*[\r\n]+\* +([0-9]+) +Thread[^\r\n]* do_something \(n=\1\) at.*}

Put into English, I wanted to make sure that the value of n passed to
do_something() is the same as the thread number shown in the "info
threads" Id column.  (I've structured the test case so that this
*should* be the case.)

It didn't work though.  It turned out that ($pattern) in the RE
noted above is capturing the attempted backreference.  So, in this
case, the backreference does not refer to ([0-9]+) as intended, but
instead refers to ($pattern).  This is wrong because it's not what I
intended, but is also wrong because, if allowed, it could only match a
string of infinite length.

This problem can be fixed by using parens for a "noncapturing
subpattern".  The way that this is done, syntactically, is to use
(?:$pattern) instead of ($pattern).

My research shows that this feature has been present since tcl8.1 which
was released in 1999.

The current tcl version is 8.6 - at least that's what I have on my
machine.  It appears to me that mingw uses some subversion of tcl8.4
which will also have this feature (since 8.4 > 8.1).

So it seems to me that any platform upon which we might wish to test
GDB will have a version of tcl which has this feature.  That being the
case, my hope is that there won't be any objections to its use.

When I looked at the implementation of gdb_test, I wondered whether
the parens were needed at all.  I've concluded that they are.  In the
event that $pattern is an RE which uses alternation at the top level,
e.g. a|b, we need to make $pattern a subpattern (via parens) to limit
the extend of the alternation.  I.e, we don't want the alternation to
extend to the other portions of the RE which gdb_test uses to match
potential blank lines at the beginning of the pattern or the gdb
prompt at the end.

gdb/testsuite/ChangeLog:

	* gdb.exp (gdb_test): Using noncapturing parens for the $pattern
	subpattern.
2017-06-21 14:44:04 -07:00
Simon Marchi e4da2c6166 Change to_xfer_partial doc to use addressable memory units
The commit

  d309493  target: consider addressable unit size when reading/writing memory

introduced the possibility of reading memory of targets with
non-8-bit-bytes (e.g. memories that store 16 bits at each address).
The documentation of target_read and target_write was updated
accordingly, but to_xfer_partial, which is very related, wasn't updated.
This commit fixes that.

gdb/ChangeLog:

	* target.h (struct target_ops) <to_xfer_partial>: Update doc to
	talk about addressable units instead of bytes.
2017-06-21 13:16:47 +02:00
Sergio Durigan Junior eb83230b4d Fix PR gdb/21606: SYMBOL_FUNCTIONS_DOMAIN misspelled in documentation
Both Python and Guile documentations misspelled
SYMBOL_FUNCTIONS_DOMAIN, writing SYMBOL_FUNCTION_DOMAIN instead.  This
obvious commit fixes it.

gdb/doc/ChangeLog:
2017-06-20  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR gdb/21606
	* python.texi (Python representation of Symbols.): Replace
	SYMBOL_FUNCTION_DOMAIN by SYMBOL_FUNCTIONS_DOMAIN, fixing typo.
	* guile.texi (Guile representation of Symbols.): Likewise.
2017-06-20 21:31:59 -04:00
Simon Marchi a206891ad1 gdbserver/Makefile.in: Sort IPA_OBJS
gdb/gdbserver/ChangeLog:

	* Makefile.in (IPA_OBJS): Sort and format one item per line.
2017-06-20 16:59:03 +02:00
Sergio Durigan Junior 96160d6051 Use '::iterator' instead of '::const_iterator' on environ.c (and fix breakage on early versions of libstdc++)
Even though C++11 supports modifying containers using a const_iterator
(e.g., calling the 'erase' method of a std::vector), early versions of
libstdc++ did not implement that.  Some of our buildslaves are using
these versions (e.g., the AArch64 buildslave uses gcc 4.8.8), and my
previous commit causes a breakage on them.  The solution is simple:
just use a normal iterator, without const.

gdb/ChangeLog:
2017-06-20  Sergio Durigan Junior  <sergiodj@redhat.com>

	* common/environ.c (gdb_environ::unset): Use '::iterator' instead
	of '::const_iterator'.
2017-06-20 09:33:53 -04:00
Sergio Durigan Junior 9a6c7d9c02 C++ify gdb/common/environ.c
As part of the preparation necessary for my upcoming task, I'd like to
propose that we turn gdb_environ into a class.  The approach taken
here is simple: the class gdb_environ contains everything that is
needed to manipulate the environment variables.  These variables are
stored in an std::vector<char *>, which can be converted to a 'char
**' and passed as argument to functions that need it.

The usage has not changed much.  As per Pedro's suggestion, this class
uses a static factory method initialization.  This means that when an
instance is created, it is initially empty.  When needed, it has to be
initialized using the static method 'from_host_environ'.

As mentioned before, this is a preparation for an upcoming work that I
will be posting in the next few weeks or so.  For that work, I'll
probably create another data structure that will contain all the
environment variables that were set by the user using the 'set
environment' command, because I'll need access to them.  This will be
much easier with the class-ification of gdb_environ.

As noted, this has been regression-tested with the new version of
environ.exp and no regressions were found.

gdb/ChangeLog:
2017-06-20  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
	'unittests/environ-selftests.c'.
	(SUBDIR_UNITTESTS_OBS): Add 'environ-selftests.o'.
	* charset.c (find_charset_names): Declare object 'iconv_env'.
	Update code to use 'iconv_env' object.  Remove call to
	'free_environ'.
	* common/environ.c: Include <utility>.
	(make_environ): Delete function.
	(free_environ): Delete function.
	(gdb_environ::clear): New function.
	(gdb_environ::operator=): New function.
	(gdb_environ::get): Likewise.
	(environ_vector): Delete function.
	(set_in_environ): Delete function.
	(gdb_environ::set): New function.
	(unset_in_environ): Delete function.
	(gdb_environ::unset): New function.
	(gdb_environ::envp): Likewise.
	* common/environ.h: Include <vector>.
	(struct gdb_environ): Delete; transform into...
	(class gdb_environ): ... this class.
	(free_environ): Delete prototype.
	(init_environ, get_in_environ, set_in_environ, unset_in_environ,
	environ_vector): Likewise.
	* infcmd.c (run_command_1): Update code to call
	'envp' from 'gdb_environ' class.
	(environment_info): Update code to call methods from 'gdb_environ'
	class.
	(unset_environment_command): Likewise.
	(path_info): Likewise.
	(path_command): Likewise.
	* inferior.c (inferior::~inferior): Delete call to 'free_environ'.
	(inferior::inferior): Initialize 'environment' using the host's
	information.
	* inferior.h: Remove forward declaration of 'struct gdb_environ'.
	Include "environ.h".
	(class inferior) <environment>: Change type from 'struct
	gdb_environ' to 'gdb_environ'.
	* mi/mi-cmd-env.c (mi_cmd_env_path): Update code to call
	methods from 'gdb_environ' class.
	* solib.c (solib_find_1): Likewise
	* unittests/environ-selftests.c: New file.

gdb/gdbserver/ChangeLog:
2017-06-20  Sergio Durigan Junior  <sergiodj@redhat.com>

	* linux-low.c (linux_create_inferior): Adjust code to access the
	environment information via 'gdb_environ' class.
	* lynx-low.c (lynx_create_inferior): Likewise.
	* server.c (our_environ): Make it an instance of 'gdb_environ'.
	(get_environ): Return a pointer to 'our_environ'.
	(captured_main): Initialize 'our_environ'.
	* server.h (get_environ): Adjust prototype.
	* spu-low.c (spu_create_inferior): Adjust code to access the
	environment information via 'gdb_environ' class.
2017-06-20 08:59:27 -04:00
Yao Qi 75c554cf9c Adjust the order of 32bit-linux.xml and 32bit-sse.xml in i386/i386-linux.xml
Exchange the order of 32bit-linux.xml and 32bit-sse.xml in
i386/i386-linux.xml, to align with other i386 linux .xml files.

gdb:

2017-06-20  Yao Qi  <yao.qi@linaro.org>

	* features/i386/i386-linux.xml: Exchange the order of including
	32bit-linux.xml and 32bit-sse.xml.
	* features/i386/i386-linux.c: Regenerated.
2017-06-20 12:08:33 +01:00
Yao Qi 72ddacb77e Class-fy tdesc_reg tdesc_type and tdesc_feature
This patch class-fies them, adding ctor, dtor, and deleting
copy ctor and assignment operator.

gdb:

2017-06-20  Yao Qi  <yao.qi@linaro.org>

	* target-descriptions.c (tdesc_reg): Add ctor, dtor.
	Delete copy ctor and assignment operator.
	(tdesc_type): Likewise.
	(tdesc_feature): Likewise.
	(tdesc_free_reg): Remove.
	(tdesc_create_reg): Use new.
	(tdesc_free_type): Remove.
	(tdesc_create_vector): Use new.
	(tdesc_create_union): Likewise.
	(tdesc_create_flags): Likewise.
	(tdesc_create_enum): Likewise.
	(tdesc_free_feature): Delete.
	(free_target_description): Use delete.
2017-06-20 11:29:17 +01:00
John Baldwin 325c9fd4aa Don't throw an error in 'info registers' for unavailable MIPS registers.
'info registers' for MIPS throws an error and when it first encounters
an unavailable register.  This does not match other architectures
which annotate unavailable registers and continue to print out the
values of subsequent registers.  Replace the error by displaying an
aligned "<unavailable>".  This string is truncated to "<unavl>" when
displaying a 32-bit register.

gdb/ChangeLog:

	* mips-tdep.c (print_gp_register_row): Don't error for unavailable
	registers.
2017-06-19 14:40:22 -07:00
Peter Bergner 66953522c9 Update GDB test case for new lnia extended mnemonic.
When I added the new lnia extended mnemonic for addpcis, I updated the
assembler/disassembler test cases, but overlooked the GDB test cases.
This patch fixes that oversight and associated test case failure.

	* gdb.arch/powerpc-power9.exp: Update test case for new lnia
	extended mnemonic.
	* gdb.arch/powerpc-power9.s: Likewise.
2017-06-19 13:04:13 -05:00
Pedro Alves 16b7a71998 .gdb_index writer: close the file before unlinking it
We should close the file before unlinking because on MS-Windows one
cannot delete a file that is still open.

I considered making 'gdb::unlinker::unlinker(const char *)'
'noexcept(true)' and then adding
  static_assert (noexcept (gdb::unlinker (filename.c_str ())), "");

but that doesn't really work because gdb::unlinker has a gdb_assert,
which can throw a QUIT if/when the assertion fails.  'noexcept(true)'
would cause GDB to abruptly terminate if/when the assertion fails.

gdb/ChangeLog:
2017-06-19  Pedro Alves  <palves@redhat.com>

	* dwarf2read.c (write_psymtabs_to_index): Construct file_closer
	after gdb::unlinker.
2017-06-19 12:46:47 +01:00
Sergio Durigan Junior 1c8e01c960 Use getenv instead of gdb_environ on mi-cmd-env.c
This is a spinoff of
<https://sourceware.org/ml/gdb-patches/2017-06/msg00437.html>.
mi-cmd-env.c is using the whole gdb_environ machinery in order to
access just one variable, which can be easily replaced by a simple
call to getenv.  This patch does that, and doesn't cause regressions.

gdb/ChangeLog:
2017-06-18  Sergio Durigan Junior  <sergiodj@redhat.com>

	* mi/mi-cm-env.c (_initialize_mi_cmd_env): Use getenv instead of
	gdb_environ to access an environment variable.
2017-06-19 00:14:00 -04:00
Thomas Petazzoni ffce45d224 nat/linux-ptrace.c: add missing gdb_byte* cast
On noMMU platforms, the following code gets compiled:

  child_stack = xmalloc (STACK_SIZE * 4);

Where child_stack is a gdb_byte*, and xmalloc() returns a void*. While
the lack of cast is valid in C, it is not in C++, causing the
following build failure:

../nat/linux-ptrace.c: In function 'int linux_fork_to_function(gdb_byte*, int (*)(void*))':
../nat/linux-ptrace.c:273:29: error: invalid conversion from 'void*' to 'gdb_byte* {aka unsigned char*}' [-fpermissive]
       child_stack = xmalloc (STACK_SIZE * 4);

Therefore, this commit adds the appropriate cast.

gdb/ChangeLog:

	* nat/linux-ptrace.c (linux_fork_to_function): Add cast to
	gdb_byte*.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2017-06-18 23:29:03 +02:00
Simon Marchi 1d4fbac99e Add ATTRIBUTE_PRINTF to trace_start_error
clang complains that the fmt passed to vwarning in trace_start_error is
not a literal.  This looks like a fair warning, which can be removed by
adding ATTRIBUTE_PRINTF to the declaration of trace_start_error.

gdb/ChangeLog:

	* nat/fork-inferior.h (trace_start_error): Add ATTRIBUTE_PRINTF.
2017-06-17 23:19:25 +02:00
Simon Marchi ae3e2ccfe7 linux-low: Remove usage of "register" keyword
AFAIK, the register keyword is not relevant today, and clang complains
about it:

/home/emaisin/src/binutils-gdb/gdb/gdbserver/linux-low.c:5873:3: error: 'register' storage class specifier is deprecated and incompatible with C++1z
      [-Werror,-Wdeprecated-register]
  register PTRACE_XFER_TYPE *buffer;
  ^~~~~~~~~

I think we can safely remove it.

gdb/gdbserver/ChangeLog:

	* linux-low.c (linux_read_memory, linux_write_memory): Remove
	usage of "register" keyword.
2017-06-17 23:19:09 +02:00
Simon Marchi 8465943af6 gdb: Add -Wno-mismatched-tags
clang complains that for some types, we use both the class and struct
keywords in different places.  It's not really a problem, so I think we
can safely turn this warning off.

gdb/ChangeLog:

	* configure: Re-generate.
	* warning.m4 (build_warnings): Add -Wno-mismatched-tags.

gdb/gdbserver/ChangeLog:

	* configure: Re-generate.
2017-06-17 23:18:49 +02:00
Simon Marchi 3e019bdc20 gdb: Use -Werror when checking for (un)supported warning flags
In warning.m4, we pass all the warning flags one by one to the compiler
to test if they are supported by this particular compiler.  If the
compiler exits with an error, we conclude that this warning flag is not
supported and exclude it.  This allows us to use warning flags without
having to worry about which versions of which compilers support each
flag.

clang, by default, only emits a warning if an unknown flag is passed:

  warning: unknown warning option '-Wfoo' [-Wunknown-warning-option]

The result is that we think that all the warning flags we use are
supported by clang (they are not), and the compilation fails later when
building with -Werror, since the aforementioned warning becomes an
error.  The fix is to also pass -Werror when probing for supported
flags, then we'll correctly get an error when using an unknown warning,
and we'll exclude it:

  error: unknown warning option '-Wfoo' [-Werror,-Wunknown-warning-option]

I am not sure why there is a change in a random comment in
gdbserver/configure, but I suppose it's a leftfover from a previous
patch, so I included it.

gdb/ChangeLog:

	* configure: Re-generate.
	* warning.m4: Pass -Werror to compiler when checking for
	supported warning flags.

gdb/gdbserver/ChangeLog:

	* configure: Re-generate.
2017-06-17 23:18:20 +02:00
Simon Marchi cf0dd6f02c gdb: Pass -x c++ to the compiler
Because we are compiling .c files containing C++ code, clang++ complains
with:

  clang: error: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated

If renaming all the source files to .cpp is out of the question, an
alternative is to pass "-x c++" to convince the compiler that we are
really compiling C++.  It works fine with GCC too.

gdb/ChangeLog:

	* Makefile.in (COMPILE.pre): Add "-x c++".

gdb/gdbserver/ChangeLog:

	* Makefile.in (COMPILE.pre): Add "-x c++".
2017-06-17 23:17:00 +02:00
Yao Qi 6f98355cda extract/store integer function template
This patch converts functions extract_{unsigned,signed}_integer
to a function template extract_integer, which has two instantiations.  It
also does the similar changes to store__{unsigned,signed}_integer,
regcache::raw_read_{unsigned,signed}, regcache::raw_write_{unsigned,signed},
regcache::cooked_read_{unsigned,signed},
regcache::cooked_write_{unsigned,signed}.

This patch was posted here
https://sourceware.org/ml/gdb-patches/2017-05/msg00492.html but the
problem was fixed in a different way.  However, I think the patch is still
useful to shorten the code.

gdb:

2017-06-16  Alan Hayward  <alan.hayward@arm.com>
	    Pedro Alves  <palves@redhat.com>
	    Yao Qi  <yao.qi@linaro.org>

	* defs.h (RequireLongest): New.
	(extract_integer): Declare function template.
	(extract_signed_integer): Remove the declaration, but define it
	static inline.
	(extract_unsigned_integer): Likewise.
	(store_integer): Declare function template.
	(store_signed_integer): Remove the declaration, but define it
	static inline.
	(store_unsigned_integer): Likewise.
	* findvar.c (extract_integer): New function template.
	(extract_signed_integer): Remove.
	(extract_unsigned_integer): Remove.
	(extract_integer<LONGEST>, extract_integer<ULONGEST>): Explicit
	instantiations.
	(store_integer): New function template.
	(store_signed_integer): Remove.
	(store_unsigned_integer): Remove.
	(store_integer): Explicit instantiations.
	* regcache.c (regcache_raw_read_signed): Update.
	(regcache::raw_read): New function.
	(regcache::raw_read_signed): Remove.
	(regcache::raw_read_unsigned): Remove.
	(regcache_raw_read_unsigned): Update.
	(regcache_raw_write_unsigned): Update.
	(regcache::raw_write_signed): Remove.
	(regcache::raw_write): New function.
	(regcache_cooked_read_signed): Update.
	(regcache::raw_write_unsigned): Remove.
	(regcache::cooked_read_signed): Remove.
	(regcache_cooked_read_unsigned): Update.
	(regcache::cooked_read_unsigned): Remove.
	(regcache_cooked_write_signed): Update.
	(regcache_cooked_write_unsigned): Update.
	* regcache.h (regcache) <raw_read_signed>: Remove.
	<raw_write_signed, raw_read_unsigned, raw_write_unsigned>: Remove.
	<raw_read, raw_write>: New.
	<cooked_read_signed, cooked_write_signed>: Remove.
	<cooked_write_unsigned, cooked_read_unsigned>: Remove.
	<cooked_read, cooked_write>: New.
	* sh64-tdep.c (sh64_pseudo_register_read): Update.
	(sh64_pseudo_register_write): Update.
2017-06-16 15:38:42 +01:00
Anton Kolesov a87dc45adc arc: Select CPU model properly before disassembling
Enforce CPU model for disassembler via its options, if it was specified in XML
target description, otherwise use default method of determining CPU implemented
in disassembler - scanning ELF private header.  The latter requires
disassemble_info->section to be properly initialized.  To make sure that
info->section is set in all cases this patch partially reverts [1] for ARC: it
reinstates arc_delayed_print_insn as a "print_insn" function for ARC, but
now this function only sets disassemble_info->section and then calls
default_print_insn to do the rest of the job.

Support for CPU in disassembler options for ARC has been added in [2].

[1] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=39503f82427e22ed8e04d986ccdc8562091ec62e
[2] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=10045478d984f9924cb945423388ba25b7dd3ffe

gdb/ChangeLog:

yyyy-mm-dd  Anton Kolesov  <anton.kolesov@synopsys.com>

	* arc-tdep.c (arc_disassembler_options): New variable.
	(arc_gdbarch_init): Set and use it. Use arc_delayed_print_insn instead
	of default_print_insn.
	(arc_delayed_print_insn): Set info->section when needed,
	use default_print_insn to retrieve a disassembler.
2017-06-16 14:54:17 +03:00
Sergio Durigan Junior 45159d6ad3 PR gdb/21574: Mention $SHELL and startup-with-shell on "help run"
This simple patch updates the documentation of "help run" in order to
mention that the shell used to start the inferior comes from the
$SHELL environment variable.  It also mentions that this behaviour can
be disabled by using the "set startup-with-shell off" command.

gdb/ChangeLog:
2017-06-14  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR gdb/21574
	* infcmd.c (_initialize_infcmd): Expand "help run" documentation
	to mention $SHELL and startup-with-shell.
2017-06-14 22:44:01 -04:00
Max Filippov b46c4cf090 Maxim Grigoriev stepping down as Xtensa maintainer
gdb/
2017-06-14  Max Filippov  <jcmvbkbc@gmail.com>

	* MAINTAINERS: Move Maxim Grigoriev to the Past Maintainers.
2017-06-14 10:45:03 -07:00
Yao Qi 6394c60699 Don't use print_insn_XXX in GDB
This is a follow-up to

  [PATCH 0/6] Unify the disassembler selection in gdb and objdump
  https://sourceware.org/ml/binutils/2017-05/msg00192.html

that is, opcodes is able to select the right disassembler, so gdb
doesn't have to select them.  Instead, gdb can just use
default_print_insn.  As a result, these print_insn_XXX are not used
out of opcodes, so this patch also moves their declarations from
include/dis-asm.h to opcodes/disassemble.h.  With this change,
GDB doesn't use any print_insn_XXX directly any more.

gdb:

2017-06-14  Yao Qi  <yao.qi@linaro.org>

	* aarch64-tdep.c (aarch64_gdb_print_insn): Call
	default_print_insn instead of print_insn_aarch64.
	* arm-tdep.c (gdb_print_insn_arm): Call
	default_print_insn instead of print_insn_big_arm
	and print_insn_little_arm.
	* i386-tdep.c (i386_print_insn): Call default_print_insn
	instead of print_insn_i386.
	* ia64-tdep.c (ia64_print_insn): Call
	default_print_insn instead of print_insn_ia64.
	* mips-tdep.c (gdb_print_insn_mips): Call
	default_print_insn instead of print_insn_big_mips
	and print_insn_little_mips.
	* spu-tdep.c (gdb_print_insn_spu): Call default_print_insn
	instead of print_insn_spu.

include:

2017-06-14  Yao Qi  <yao.qi@linaro.org>

	* dis-asm.h (print_insn_aarch64): Move it to opcodes/disassemble.h.
	(print_insn_big_arm, print_insn_big_mips): Likewise.
	(print_insn_i386, print_insn_ia64): Likewise.
	(print_insn_little_arm, print_insn_little_mips): Likewise.
	(print_insn_spu): Likewise.

opcodes:

2017-06-14  Yao Qi  <yao.qi@linaro.org>

	* aarch64-dis.c: Include disassemble.h instead of dis-asm.h.
	* arm-dis.c: Likewise.
	* ia64-dis.c: Likewise.
	* mips-dis.c: Likewise.
	* spu-dis.c: Likewise.
	* disassemble.h (print_insn_aarch64): New declaration, moved from
	include/dis-asm.h.
	(print_insn_big_arm, print_insn_big_mips): Likewise.
	(print_insn_i386, print_insn_ia64): Likewise.
	(print_insn_little_arm, print_insn_little_mips): Likewise.
2017-06-14 16:29:01 +01:00
Andreas Arnez 5524b5250e Fix register selection in var-access.exp
The new test var-access.exp causes FAILs on i686.  This is because the
test chooses the wrong name for DWARF register number 1: It uses
"edx" (which corresponds to DWARF register number 2), but should have used
"ecx" instead.

Also, the current logic in var-access.exp does not correctly distinguish
between a 64-bit and a 32-bit program on an x86-64 target.  It uses the
64-bit register names for both.

These problems are fixed.  In order to address the latter, the convenience
macros is_*_target are exploited where appropriate.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/var-access.exp: Use register name ecx instead of edx
	on 32-bit x86 targets.  Exploit is_*_target macros where
	appropriate.
2017-06-14 14:24:31 +02:00
Pedro Alves d5722aa2fe Introduce gdb::byte_vector, add allocator that default-initializes
In some cases we've been replacing heap-allocated gdb_byte buffers
managed with xmalloc/make_cleanup(xfree) with gdb::vector<gdb_byte>.
That usually pessimizes the code a little bit because std::vector
value-initializes elements (which for gdb_byte means
zero-initialization), while if you're creating a temporary buffer,
you're most certaintly going to fill it in with some data.  An
alternative is to use

  unique_ptr<gdb_byte[]> buf (new gdb_byte[size]);

but it looks like that's not very popular.

Recently, a use of obstacks in dwarf2read.c was replaced with
std::vector<gdb_byte> and that as well introduced a pessimization for
always memsetting the buffer when it's garanteed that the zeros will
be overwritten immediately.  (see dwarf2read.c change in this patch to
find it.)

So here's a different take at addressing this issue "by design":

#1 - Introduce default_init_allocator<T>

I.e., a custom allocator that does default construction using default
initialization, meaning, no more zero initialization.  That's the
default_init_allocation<T> class added in this patch.

See "Notes" at
<http://en.cppreference.com/w/cpp/container/vector/resize>.

#2 - Introduce def_vector<T>

I.e., a convenience typedef, because typing the allocator is annoying:

  using def_vector<T> = std::vector<T, gdb::default_init_allocator<T>>;

#3 - Introduce byte_vector

Because gdb_byte vectors will be the common thing, add a convenience
"byte_vector" typedef:

  using byte_vector = def_vector<gdb_byte>;

which is really the same as:

  std::vector<gdb_byte, gdb::default_init_allocator<gdb_byte>>;

The intent then is to make "gdb::byte_vector" be the go-to for dynamic
byte buffers.  So the less friction, the better.

#4 - Adjust current code to use it.

To set the example going forward.  Replace std::vector uses and also
unique_ptr<byte[]> uses.

One nice thing is that with this allocator, for changes like these:

  -std::unique_ptr<byte[]> buf (new gdb_byte[some_size]);
  +gdb::byte_vector buf (some_size);
   fill_with_data (buf.data (), buf.size ());

the generated code is the same as before.  I.e., the compiler
de-structures the vector and gets rid of the unused "reserved vs size"
related fields.

The other nice thing is that it's easier to write
  gdb::byte_vector buf (size);
than
  std::unique_ptr<gdb_byte[]> buf (new gdb_byte[size]);
or even (C++14):
  auto buf = std::make_unique<gdb_byte[]> (size); // zero-initializes...

#5 - Suggest s/std::vector<gdb_byte>/gdb::byte_vector/ going forward.

Note that this commit actually fixes a couple of bugs where the current
code is incorrectly using "std::vector::reserve(new_size)" and then
accessing the vector's internal buffer beyond the vector's size: see
dwarf2loc.c and charset.c.  That's undefined behavior and may trigger
debug mode assertion failures.  With default_init_allocator,
"resize()" behaves like "reserve()" performance wise, in that it
leaves new elements with unspecified values, but, it does that safely
without triggering undefined behavior when you access those values.

gdb/ChangeLog:
2017-06-14  Pedro Alves  <palves@redhat.com>

	* ada-lang.c: Include "common/byte-vector.h".
	(ada_value_primitive_packed_val): Use gdb::byte_vector.
	* charset.c (wchar_iterator::iterate): Resize the vector instead
	of reserving it.
	* common/byte-vector.h: Include "common/def-vector.h".
	(wchar_iterator::m_out): Now a gdb::def_vector<gdb_wchar_t>.
	* cli/cli-dump.c: Include "common/byte-vector.h".
	(dump_memory_to_file, restore_binary_file): Use gdb::byte_vector.
	* common/byte-vector.h: New file.
	* common/def-vector.h: New file.
	* common/default-init-alloc.h: New file.
	* dwarf2loc.c: Include "common/byte-vector.h".
	(rw_pieced_value): Use gdb::byte_vector, and resize the vector
	instead of reserving it.
	* dwarf2read.c: Include "common/byte-vector.h".
	(data_buf::m_vec): Now a gdb::byte_vector.
	* gdb_regex.c: Include "common/def-vector.h".
	(compiled_regex::compiled_regex): Use gdb::def_vector<char>.
	* mi/mi-main.c: Include "common/byte-vector.h".
	(mi_cmd_data_read_memory): Use gdb::byte_vector.
	* printcmd.c: Include "common/byte-vector.h".
	(print_scalar_formatted): Use gdb::byte_vector.
	* valprint.c: Include "common/byte-vector.h".
	(maybe_negate_by_bytes, print_decimal_chars): Use
	gdb::byte_vector.
2017-06-14 11:08:52 +01:00
Simon Marchi 01ec7a2722 darwin-nat: Add missing include
I forgot this one, which is kind of related.

The function trace_start_error_with_name has moved in commit "Share
fork_inferior et al with gdbserver", so this additional include is
needed.

Fixes:

darwin-nat.c:1735:5: error: use of undeclared identifier 'trace_start_error_with_name'
    trace_start_error_with_name ("close");

gdb/ChangeLog:

	* darwin-nat.c: Include "nat/fork-inferior.h".
2017-06-13 21:14:50 +02:00
Simon Marchi 848d907446 darwin: Add fork-inferior.o to NATDEPFILES
I happened to be build-testing on macOS and found this:

  Undefined symbols for architecture x86_64:

    "fork_inferior(char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char**, void (*)(), void (*)(int), void (*)(), char const*, void (*)(char const*, char* const*, char* const*))", referenced from:

        darwin_create_inferior(target_ops*, char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char**, int) in darwin-nat.o

    "startup_inferior(int, int, target_waitstatus*, ptid_t*)", referenced from:

        gdb_startup_inferior(int, int) in fork-child.o

    "trace_start_error(char const*, ...)", referenced from:

        darwin_ptrace_me() in darwin-nat.o

    "trace_start_error_with_name(char const*)", referenced from:

        darwin_ptrace_me() in darwin-nat.o

  ld: symbol(s) not found for architecture x86_64

  clang: error: linker command failed with exit code 1 (use -v to see invocation)

Adding fork-inferior.o fixes it.  I factored out the Darwin bits that
are no architecture-specific in the section meant for that at the top.

I only built-tested this using Travis-CI, since I don't have access to
this platform.

gdb/ChangeLog:

	* configure.nat: Factor out Darwin bits that are not
	architecture-specific.  Add fork-inferior.o.
2017-06-13 21:14:35 +02:00
Simon Marchi 3b912944f4 aix: Add fork-inferior.o to NATDEPFILES
Trying to build on AIX gives:

ld: 0711-317 ERROR: Undefined symbol: .trace_start_error_with_name(char const*)
ld: 0711-317 ERROR: Undefined symbol: .fork_inferior(char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char**, void (*)(), void (*)(int), void (*)(), char const*, void (*)(char const*, char* const*, char* const*))
ld: 0711-317 ERROR: Undefined symbol: .startup_inferior(int, int, target_waitstatus*, ptid_t*)

Including fork-inferior.o in the build should help.  I also factored out
the AIX bits that are not architecture-specific to be consistent with the other
OSes.

gdb/ChangeLog:

	* configure.nat: Factor out AIX bits that are not
	architecture-specific.  Add fork-inferior.o.
2017-06-13 21:14:25 +02:00
Andreas Arnez 55acdf2242 read/write_pieced_value: Merge into one function
Since read_pieced_value and write_pieced_value share significant logic,
this patch merges them into a single function rw_pieced_value.

gdb/ChangeLog:

	* dwarf2loc.c (rw_pieced_value): New.  Merge logic from...
	(read_pieced_value, write_pieced_value): ...here.  Reduce to
	wrappers that just call rw_pieced_value.
2017-06-13 15:20:32 +02:00
Andreas Arnez f65e204425 write_pieced_value: Notify memory_changed observers
So far write_pieced_value uses write_memory when writing memory pieces to
the target.  However, this is a case where GDB potentially overwrites a
watchpoint value.  In such a case write_memory_with_notification should be
used instead, so that memory_changed observers get notified.

gdb/ChangeLog:

	* dwarf2loc.c (write_pieced_value): When writing the data for a
	memory piece, use write_memory_with_notification instead of
	write_memory.
2017-06-13 15:20:32 +02:00
Andreas Arnez 23f945bf8c Fix bit-/byte-offset mismatch in parameter to read_value_memory
The function read_value_memory accepts a parameter embedded_offset and
expects it to represent the byte offset into the given value.  However,
the only invocation with a possibly non-zero embedded_offset happens in
read_pieced_value, where a bit offset is passed instead.

Adjust the implementation of read_value_memory to meet the caller's
expectation.  This implicitly fixes the invocation in read_pieced_value.

gdb/ChangeLog:

	* valops.c (read_value_memory): Change embedded_offset to
	represent a bit offset instead of a byte offset.
	* value.h (read_value_memory): Adjust comment.
2017-06-13 15:20:31 +02:00
Andreas Arnez f236533e3c read/write_pieced_value: Remove unnecessary variable copies
In read_pieced_value's main loop, the variables `dest_offset_bits' and
`source_offset_bits' are basically just copies of `offset' and
`bits_to_skip', respectively.  In write_pieced_value the copies are
reversed.  This is not very helpful when trying to keep the logic between
these functions in sync.  Since the copies are unnecessary, this patch
just removes them.

gdb/ChangeLog:

	* dwarf2loc.c (read_pieced_value): Remove unnecessary variables
	dest_offset_bits and source_offset_bits.
	(write_pieced_value): Likewise.
2017-06-13 15:20:31 +02:00
Andreas Arnez 65d84b7616 Respect piece offset for DW_OP_bit_piece
So far GDB ignores the piece offset of all kinds of DWARF bit
pieces (DW_OP_bit_piece) and treats such pieces as if the offset was zero.

This is fixed, and an appropriate test is added.

gdb/ChangeLog:

	* dwarf2loc.c (read_pieced_value): Respect the piece offset, as
	given by DW_OP_bit_piece.
	(write_pieced_value): Likewise.

  Andreas Arnez  <arnez@linux.vnet.ibm.com>

	* gdb.dwarf2/var-access.exp: Add test for composite location with
	nonzero piece offsets.
2017-06-13 15:20:31 +02:00
Andreas Arnez 242d31ab7c read/write_pieced_value: Improve logic for buffer allocation
So far the main loop in read_pieced_value and write_pieced_value is
structured like this:

(1) Prepare a buffer and some variables we may need;

(2) depending on the DWARF piece type to be handled, use the buffer and
    the prepared variables, ignore them, or even recalculate them.

This approach reduces readability and may also lead to unnecessary copying
of data.  This patch moves the preparations to the places where sufficient
information is available and removes some of the variables involved.

gdb/ChangeLog:

	* dwarf2loc.c (read_pieced_value): Move the buffer allocation and
	some other preparations to the places where sufficient information
	is available.
	(write_pieced_value): Likewise.
2017-06-13 15:20:30 +02:00
Andreas Arnez 03c8af18d1 Fix handling of DWARF register pieces on big-endian targets
For big-endian targets the logic in read/write_pieced_value tries to take
a register piece from the LSB end.  This requires offsets and sizes to be
adjusted accordingly, and that's where the current implementation has some
issues:

* The formulas for recalculating the bit- and byte-offsets into the
  register are wrong.  They just happen to yield correct results if
  everything is byte-aligned and the piece's last byte belongs to the
  given value.

* After recalculating the bit offset into the register, the number of
  bytes to be copied from the register is not recalculated.  Of course
  this does not matter if everything (particularly the piece size) is
  byte-aligned.

These issues are fixed.  The size calculation is performed with a new
helper function bits_to_bytes().

gdb/ChangeLog:

	* dwarf2loc.c (bits_to_bytes): New function.
	(read_pieced_value): Fix offset calculations for register pieces
	on big-endian targets.
	(write_pieced_value): Likewise.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/var-access.exp: Add test for non-byte-aligned
	register pieces.
2017-06-13 15:20:30 +02:00
Andreas Arnez 840989c113 read/write_pieced_value: Drop 'buffer_size' variable
When the variable 'buffer_size' in read_pieced_value and
write_pieced_value was introduced, it was needed for tracking the buffer's
allocated size.  Now that the buffer's data type has been changed to a
std::vector, the variable is no longer necessary; so remove it.

gdb/ChangeLog:

	* dwarf2loc.c (read_pieced_value): Remove buffer_size variable.
	(write_pieced_value): Likewise.
2017-06-13 15:20:30 +02:00
Andreas Arnez 3bf3101107 Add DWARF piece test cases for bit-field access
This verifies some of the previous fixes to the logic in
write_pieced_value when accessing bit-fields.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/var-access.exp: Add tests for accessing bit-fields
	located in one or more DWARF pieces.
2017-06-13 15:20:29 +02:00
Andreas Arnez 359b19bb24 write_pieced_value: Transfer least significant bits into bit-field
On big-endian targets, when targeting a bit-field, write_pieced_value
currently transfers the source value's *most* significant bits to the
target value, instead of its least significant bits.  This is fixed.

In particular the fix adjusts the initial value of 'offset', which can now
potentially be nonzero.  Thus the variable 'type_len' is renamed to
'max_offset', to avoid confusion.  And for consistency, the affected logic
that was mirrored in read_pieced_value is changed there in the same way.

gdb/ChangeLog:

	* dwarf2loc.c (write_pieced_value): When writing to a bit-field,
	transfer the source value's least significant bits, instead of its
	lowest-addressed ones.  Rename type_len to max_offset.
	(read_pieced_value): Mirror above changes to write_pieced_value as
	applicable.
2017-06-13 15:20:28 +02:00
Andreas Arnez 07c9ca3bd8 write_pieced_value: Fix buffer offset for memory pieces
In write_pieced_value, when transferring the data to target memory via a
buffer, the bit offset within the target value is not reduced to its
sub-byte fraction before using it as a bit offset into the buffer.  This
is fixed.

gdb/ChangeLog:

	* dwarf2loc.c (write_pieced_value): In DWARF_VALUE_MEMORY,
	truncate full bytes from dest_offset_bits before using it as an
	offset into the buffer.
2017-06-13 15:20:28 +02:00
Andreas Arnez f1cc987420 write_pieced_value: Include transfer size in byte-wise check
In write_pieced_value, when checking whether the data can be transferred
byte-wise, the current logic verifies the source- and destination offsets
to be byte-aligned, but not the transfer size.  This is fixed.

gdb/ChangeLog:

	* dwarf2loc.c (write_pieced_value): Include transfer size in
	byte-wise check.
2017-06-13 15:20:27 +02:00
Andreas Arnez cdaac320fd write_pieced_value: Fix copy/paste error in size calculation
In write_pieced_value, the number of bytes containing a portion of the
bit-field in a given piece is calculated with the wrong starting offset;
thus the result may be off by one.  This bug was probably introduced when
copying this logic from read_pieced_value.  Fix it.

gdb/ChangeLog:

	* dwarf2loc.c (write_pieced_value): Fix copy/paste error in the
	calculation of this_size.
2017-06-13 15:20:27 +02:00
Andreas Arnez af547a9614 read/write_pieced_value: Respect value parent's offset
In the case of targeting a bit-field, read_pieced_value and
write_pieced_value calculate the number of bits preceding the bit-field
without considering the relative offset of the value's parent.  This is
relevant for a structure variable like this:

  struct s {
      uint64_t foo;
      struct {
	  uint32_t bar;
	  uint32_t bf : 10;  /* <-- target bit-field */
      } baz;
  } s;

In this scenario, if 'val' is a GDB value representing s.baz.bf,
val->parent represents the whole s.baz structure, and the following holds:

  - value_offset (val) == sizeof s.baz.bar == 4
  - value_offset (val->parent) == sizeof s.foo == 8

The current logic would only use value_offset(val), resulting in the wrong
offset into the target value.  This is fixed.

gdb/ChangeLog:

	* dwarf2loc.c (read_pieced_value): Respect parent value's offset
	when targeting a bit-field.
	(write_pieced_value): Likewise.
2017-06-13 15:20:27 +02:00