Commit Graph

39310 Commits

Author SHA1 Message Date
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
Andreas Arnez 805acca042 gdb/testsuite: Add "get_endianness" convenience proc
The test suite contains multiple instances of determining the target's
endianness with GDB's "show endian" command.  This patch replaces these by
an invocation of a new convenience proc 'get_endianness'.

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (get_endianness): New proc.
	* gdb.arch/aarch64-fp.exp: Use it.
	* gdb.arch/altivec-regs.exp: Likewise.
	* gdb.arch/e500-regs.exp: Likewise.
	* gdb.arch/vsx-regs.exp: Likewise.
	* gdb.base/dump.exp: Likewise.
	* gdb.base/funcargs.exp: Likewise.
	* gdb.base/gnu_vector.exp: Likewise.
	* gdb.dwarf2/formdata16.exp: Likewise.
	* gdb.dwarf2/implptrpiece.exp: Likewise.
	* gdb.dwarf2/nonvar-access.exp: Likewise.
	* gdb.python/py-inferior.exp: Likewise.
	* gdb.trace/unavailable-dwarf-piece.exp: Likewise.
2017-06-13 15:20:26 +02:00
Andreas Arnez ddd7882a58 Remove addr_size field from struct piece_closure
The addr_size field in the piece_closure data structure is a relic from
before introducing the typed DWARF stack.  It is obsolete now.  This patch
removes it.

gdb/ChangeLog:

	* dwarf2loc.c (struct piece_closure) <addr_size>: Remove field.
	(allocate_piece_closure): Drop addr_size parameter.
	(dwarf2_evaluate_loc_desc_full): Adjust call to
	allocate_piece_closure.
2017-06-13 15:20:26 +02:00
Andreas Arnez e93523245b PR gdb/21226: Take DWARF stack value pieces from LSB end
When taking a DW_OP_piece or DW_OP_bit_piece from a DW_OP_stack_value, the
existing logic always takes the piece from the lowest-addressed end, which
is wrong on big-endian targets.  The DWARF standard states that the
"DW_OP_bit_piece operation describes a sequence of bits using the least
significant bits of that value", and this also matches the current logic
in GCC.  For instance, the GCC guality test case pr54970.c fails on s390x
because of this.

This fix adjusts the piece accordingly on big-endian targets.  It is
assumed that:

* DW_OP_piece shall take the piece from the LSB end as well;

* pieces reaching outside the stack value bits are considered undefined,
  and a zero value can be used instead.

gdb/ChangeLog:

	PR gdb/21226
	* dwarf2loc.c (read_pieced_value): Anchor stack value pieces at
	the LSB end, independent of endianness.

gdb/testsuite/ChangeLog:

	PR gdb/21226
	* gdb.dwarf2/nonvar-access.exp: Add checks for verifying that
	stack value pieces are taken from the LSB end.
2017-06-13 15:20:26 +02:00
Andreas Arnez d5d1163eff write_pieced_value: Fix size capping logic
A field f in a structure composed of DWARF pieces may be located in
multiple pieces, where the first and last of those may contain bits from
other fields as well.  So when writing to f, the beginning of the first
and the end of the last of those pieces may have to be skipped.  But the
logic in write_pieced_value for handling one of those pieces is flawed
when the first and last piece are the same, i.e., f is contained in a
single piece:

  < - - - - - - - - - piece_size - - - - - - - - - ->
  +-------------------------------------------------+
  | skipped_bits |   f_bits   | / / / / / / / / / / |
  +-------------------------------------------------+

The current logic determines the size of the sub-piece to operate on by
limiting the piece size to the bit size of f and then subtracting the
skipped bits:

  min (piece_size, f_bits) - skipped_bits

Instead of:

  min (piece_size - skipped_bits, f_bits)

So the resulting sub-piece size is corrupted, leading to wrong handling of
this piece in write_pieced_value.

Note that the same bug was already found in read_pieced_value and fixed
there (but not in write_pieced_value), see PR 15391.

This patch swaps the calculations, bringing them into the same (correct)
order as in read_pieced_value.

gdb/ChangeLog:

	* dwarf2loc.c (write_pieced_value): Fix order of calculations for
	size capping.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/var-pieces.exp: Add test case for modifying a
	variable at nonzero offset.
2017-06-13 15:20:26 +02:00
Andreas Arnez 0567c9861e Add test for modifiable DWARF locations
This adds a test for read/write access to variables with various types of
DWARF locations.  It uses register- and memory locations and composite
locations with register- and memory pieces.

Since the new test calls gdb_test_no_output with commands that contain
braces, it is necessary for string_to_regexp to quote braces as well.
This was not done before.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/var-access.c: New file.
	* gdb.dwarf2/var-access.exp: New test.
	* lib/gdb-utils.exp (string_to_regexp): Quote braces as well.
2017-06-13 15:20:25 +02:00
Yao Qi 032bb6eae8 Move initialize_tdesc_mips* calls from mips-linux-nat.c to mips-linux-tdep.c
All target descriptions except mips initialization are called in -tdep.c,
instead of -nat.c, so this patch moves mips target descriptions
initialization to -tdep.c.  Secondly, I want to change the target
descriptions from pre-generated to dynamical creation, so I want to test
that these pre-generated target descriptions equal to these dynamically
created ones.  Move target descriptions initialization to -tdep.c files so
we can test them in any hosts (if they are still -nat.c, we can only test
them on mips-linux host.).

gdb:

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

	* mips-linux-nat.c: Move include features/mips*-linux.c to
	mips-linux-tdep.c.
	(_initialize_mips_linux_nat): Move initialize_tdesc_mips* calls
	to mips-linux-tdep.c.
	* mips-linux-tdep.c: Include features/mips*-linux.c
	(_initialize_mips_linux_tdep): Call initialize_tdesc_mips*
	functions.
	* mips-linux-tdep.h (tdesc_mips_linux): Declare.
	(tdesc_mips_dsp_linux, tdesc_mips64_linux): Declare.
	(tdesc_mips64_dsp_linux): Declare.
2017-06-13 09:05:04 +01:00
Tom Tromey 973e9aab63 Add some 128-bit integer tests
This adds some tests for printing 128-bit integers.

2017-06-12  Tom Tromey  <tom@tromey.com>

	* gdb.dwarf2/formdata16.exp: Add tests.
2017-06-12 15:04:58 -06:00
Tom Tromey f12f6bad7d Remove val_print_type_code_int
Now that print_scalar_formatted is more capable, there's no need for
val_print_type_code_int.  This patch removes it in favor of
val_print_scalar_formatted.

2017-06-12  Tom Tromey  <tom@tromey.com>

	* valprint.h (val_print_type_code_int): Remove.
	* valprint.c (generic_val_print_int): Always call
	val_print_scalar_formatted.
	(val_print_type_code_int): Remove.
	* printcmd.c (print_scalar_formatted): Handle options->format==0.
	* f-valprint.c (f_val_print): Use val_print_scalar_formatted.
	* c-valprint.c (c_val_print_int): Use val_print_scalar_formatted.
	* ada-valprint.c (ada_val_print_num): Use
	val_print_scalar_formatted.
2017-06-12 15:04:58 -06:00
Tom Tromey d9109c8080 Simplify print_scalar_formatted
This unifies the two switches in print_scalar_formatted, removing some
now-redundant code.  Now scalar types are never converted to LONGEST,
instead printing is done using print_*_chars, operating on the byte
representation.

ChangeLog
2017-06-12  Tom Tromey  <tom@tromey.com>

	* printcmd.c (print_scalar_formatted): Unify the two switches.
	Don't convert scalars to LONGEST.

2017-06-12  Tom Tromey  <tom@tromey.com>

	* gdb.arch/altivec-regs.exp: Expect decimal results for uint128.
2017-06-12 15:04:57 -06:00
Tom Tromey 4ac0cb1cf0 Let print_decimal_chars handle signed values
This changes print_decimal_chars to handle signed values.

gdb/ChangeLog
2017-06-12  Tom Tromey  <tom@tromey.com>

	PR exp/16225:
	* valprint.h (print_decimal_chars): Update.
	* valprint.c (maybe_negate_by_bytes): New function.
	(print_decimal_chars): Add "is_signed" argument.
	* printcmd.c (print_scalar_formatted): Update.
2017-06-12 15:04:57 -06:00
Tom Tromey 30a254669b Don't always zero pad in print_*_chars
This changes print_octal_chars and print_decimal_chars to never zero
pad, and changes print_binary_chars and print_hex_chars to only
optionally zero-pad, based on a flag.

ChangeLog
2017-06-12  Tom Tromey  <tom@tromey.com>

	PR exp/16225:
	* valprint.h (print_binary_chars, print_hex_chars): Update.
	* valprint.c (val_print_type_code_int): Update.
	(print_binary_chars): Add "zero_pad" argument.
	(emit_octal_digit): New function.
	(print_octal_chars): Don't zero-pad.
	(print_decimal_chars): Likewise.
	(print_hex_chars): Add "zero_pad" argument.
	* sh64-tdep.c (sh64_do_fp_register): Update.
	* regcache.c (regcache::dump): Update.
	* printcmd.c (print_scalar_formatted): Update.
	* infcmd.c (default_print_one_register_info): Update.

2017-06-12  Tom Tromey  <tom@tromey.com>

	PR exp/16225:
	* gdb.reverse/i386-sse-reverse.exp: Update tests.
	* gdb.arch/vsx-regs.exp: Update tests.
	* gdb.arch/s390-vregs.exp (hex128): New proc.
	Update test.
	* gdb.arch/altivec-regs.exp: Update tests.
2017-06-12 15:04:56 -06:00
Pedro Alves b3464d0316 mips-tdep.c: Remove MAX_REGISTER_SIZE usage
mips_eabi_push_dummy_call is storing the address of a struct in a
buffer that must have the same of the confisued/set ABI register size.
Add a define for the maximum ABI size and use it to size the local
buffer.  Also rename the 'regsize' local to 'abi_regsize' for clarity.

Tested that --enable-targets=all still builds.

gdb/ChangeLog:
2017-06-12  Pedro Alves  <palves@redhat.com>
	    Alan Hayward  <alan.hayward@arm.com>

	* mips-tdep.c (MAX_MIPS_ABI_REGSIZE): New.
	(mips_eabi_push_dummy_call): Rename local 'regsize' to
	'abi_regsize'.  Rename local array 'valbuf' to 'ref_valbuf', and
	use MAX_MIPS_ABI_REGSIZE instead of MAX_REGISTER_SIZE to size it.
	Assert that abi_regsize bytes fit in 'ref_valbuf'.
2017-06-12 19:04:52 +01:00
Pedro Alves 4b76cda993 .gdb_index prod perf regression: mapped_symtab now vector of values
... instead of vector of pointers

There's no real reason for having mapped_symtab::data be a vector of
heap-allocated symtab_index_entries.  symtab_index_entries is not that
large, it's movable, and it's cheap to move.  Making the vector hold
values instead improves cache locality and eliminates many roundtrips
to the heap.

Using the same test as in the previous patch, against the same gdb
inferior, timing improves ~13% further:

  ~6.0s => ~5.2s (average of 5 runs).

Note that before the .gdb_index C++ifycation patch, we were at ~5.7s.
We're now consistenly better than before.

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

	* dwarf2read.c (mapped_symtab::data): Now a vector of
	symtab_index_entry instead of vector of
	std::unique_ptr<symtab_index_entry>.  All users adjusted to check
	whether an element's name is NULL instead of checking whether the
	element itself is NULL.
	(find_slot): Change return type.  Adjust.
	(hash_expand, , add_index_entry, uniquify_cu_indices)
	(write_hash_table): Adjust.
2017-06-12 17:06:26 +01:00
Pedro Alves e8f8bcb35f .gdb_index prod perf regression: Estimate size of psyms_seen
Using the same test as the previous patch, perf shows GDB spending
over 7% in "free".  A substantial number of those calls comes from
insertions in the psyms_seen unordered_set causing lots of rehashing
and recreating buckets.  Fix this by computing an estimate of the size
of the set upfront.

Using the same test as in the previous patch, against the same gdb
inferior, timing improves ~8% further:

  ~6.5s => ~6.0s (average of 5 runs).

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

	* dwarf2read.c (recursively_count_psymbols): New function.
	(write_psymtabs_to_index): Call it to compute number of psyms and
	pass estimate size of psyms_seen to unordered_set's ctor.
2017-06-12 17:06:25 +01:00
Pedro Alves 70a1152bee .gdb_index prod perf regression: find before insert in unordered_map
"perf" shows the unordered_map::emplace call in write_hash_table a bit
high up on profiles.  Fix this using the find + insert idiom instead
of going straight to insert.

I tried doing the same to the other unordered_maps::emplace calls in
the file, but saw no performance improvement, so left them be.

With a '-g3 -O2' build of gdb, and:

  $ cat save-index.cmd
  set $i = 0
  while $i < 100
    save gdb-index .
    set $i = $i + 1
  end
  $ time ./gdb -data-directory=data-directory -nx --batch -q -x save-index.cmd  ./gdb.pristine

I get an improvement of ~7%:

  ~7.0s => ~6.5s (average of 5 runs).

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

	* dwarf2read.c (write_hash_table): Check if key already exists
	before emplacing.
2017-06-12 17:06:25 +01:00
Pedro Alves c2f134ac41 Code cleanup: dwarf2read.c: Add data_buf::append_uint
This avoids having to specify the integer size twice in the same line.

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

	* dwarf2read.c (data_buf::append_space): Rename to...
	(data_buf::grow): ... this, and make private.  Adjust all callers.
	(data_buf::append_uint): New method.
	(add_address_entry, write_one_signatured_type)
	(write_psymtabs_to_index): Use it.
2017-06-12 17:06:25 +01:00
Pedro Alves a81e6d4d26 Code cleanup: dwarf2read.c: Eliminate ::file_write
There's no real need for all this indirection.

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

	* dwarf2read.c (file_write(FILE *, const void *, size_t)): Delete.
	(file_write (FILE *, const std::vector<Elem>&)): Delete.
	(data_buf::file_write): Call ::fwrite directly.
2017-06-12 17:06:25 +01:00
Pedro Alves 6fd931f2d6 Code cleanup: dwarf2read.c:uniquify_cu_indices: Use std::unique
gdb/ChangeLog:
2017-06-12  Pedro Alves  <palves@redhat.com>

	* dwarf2read.c (uniquify_cu_indices): Use std::unique and
	std::vector::erase.
2017-06-12 17:06:25 +01:00
Jan Kratochvil bc8f2430e0 Code cleanup: C++ify .gdb_index producer
gdb/ChangeLog
2017-06-12  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Code cleanup: C++ify .gdb_index producer.
	* dwarf2read.c: Include <unordered_set> and <unordered_map>.
	(MAYBE_SWAP) [WORDS_BIGENDIAN]: Cast to offset_type.
	(struct strtab_entry, hash_strtab_entry, eq_strtab_entry)
	(create_strtab, add_string): Remove.
	(file_write, data_buf): New.
	(struct symtab_index_entry): Use std::vector for cu_indices.
	(struct mapped_symtab): Use std::vector for data.
	(hash_symtab_entry, eq_symtab_entry, delete_symtab_entry)
	(create_symbol_hash_table, create_mapped_symtab, cleanup_mapped_symtab):
	Remove.
	(find_slot): Change return type.  Update it to the new data structures.
	(hash_expand, add_index_entry): Update it to the new data structures.
	(offset_type_compare): Remove.
	(uniquify_cu_indices): Update it to the new data structures.
	(c_str_view, c_str_view_hasher, vector_hasher): New.
	(add_indices_to_cpool): Remove.
	(write_hash_table): Update it to the new data structures.
	(struct psymtab_cu_index_map, hash_psymtab_cu_index)
	(eq_psymtab_cu_index): Remove.
	(psym_index_map): New typedef.
	(struct addrmap_index_data): Change addr_obstack pointer to data_buf
	reference and std::unordered_map for cu_index_htab.
	(add_address_entry, add_address_entry_worker, write_address_map)
	(write_psymbols): Update it to the new data structures.
	(write_obstack): Remove.
	(struct signatured_type_index_data): Change types_list to a data_buf
	reference and psyms_seen to a std::unordered_set reference.
	(write_one_signatured_type, recursively_write_psymbols)
	(write_psymtabs_to_index): Update it to the new data structures.
2017-06-12 16:29:53 +01:00
Simon Marchi c4dcb155c4 Introduce "set debug separate-debug-file"
I helped someone figure out why their separate debug info (debug
link-based) was not found by gdb.  It turns out that the debug file was
not named properly.  It made me realize that it is quite difficult to
diagnose this kind of problems.  This patch adds some debug output to
show where GDB looks for those files, so that it should be (more)
obvious to find what's wrong.

Here's an example of the result, first with an example of unsuccessful lookup,
and then a successful one.

  (gdb) set debug separate-debug-file on
  (gdb) file /usr/bin/gnome-calculator
  Reading symbols from /usr/bin/gnome-calculator...
  Looking for separate debug info (build-id) for /usr/bin/gnome-calculator
    Trying /usr/local/lib/debug/.build-id/0d/5c5e8c86dbe4f4f95f7a13de04f91d377f3c6a.debug

  Looking for separate debug info (debug link) for /usr/bin/gnome-calculator
    Trying /usr/bin/5c5e8c86dbe4f4f95f7a13de04f91d377f3c6a.debug
    Trying /usr/bin/.debug/5c5e8c86dbe4f4f95f7a13de04f91d377f3c6a.debug
    Trying /usr/local/lib/debug//usr/bin/5c5e8c86dbe4f4f95f7a13de04f91d377f3c6a.debug
  (no debugging symbols found)...done.
  (gdb) set debug-file-directory /usr/lib/debug
  (gdb) file /usr/bin/gnome-calculator
  Reading symbols from /usr/bin/gnome-calculator...
  Looking for separate debug info by build-id for /usr/bin/gnome-calculator
    Trying /usr/lib/debug/.build-id/0d/5c5e8c86dbe4f4f95f7a13de04f91d377f3c6a.debug
  Reading symbols from /usr/lib/debug/.build-id/0d/5c5e8c86dbe4f4f95f7a13de04f91d377f3c6a.debug...done.
  done.

Note: here, the debug link happens to be named like the build-id, but it
doesn't have to be this way.  It puzzled me for a minute.

gdb/ChangeLog:

	* NEWS (Changes since GDB 8.0): Announce {set,show} debug
	separate-debug-file commands.
	* symfile.h (separate_debug_file_debug): New global.
	* symfile.c (separate_debug_file_debug): New global.
	(separate_debug_file_exists, find_separate_debug_file): Add
	debug output.
	(_initialize_symfile): Add "set debug separate-debug-file"
	command.
	* build-id.c (build_id_to_debug_bfd,
	find_separate_debug_file_by_buildid): Add debug output.

gdb/doc/ChangeLog:

	* gdb.texinfo (Optional Messages about Internal Happenings):
	Document {set,show} debug separate-debug-file commands.
2017-06-11 23:16:28 +02:00
Simon Marchi 6d45d4b42b gdbarch: Remove displaced_step_free_closure
The displaced_step_free_closure gdbarch hook allows architectures to
free data they might have allocated to complete a displaced step.
However, all architectures using that hook use the
simple_displaced_step_free_closure provided in arch-utils.{c,h}, which
does a simple xfree.  We can remove it and do an xfree directly instead
of calling the hook.

gdb/ChangeLog:

	* gdbarch.sh (displaced_step_free_closure): Remove.
	* gdbarch.h, gdbarch.c: Re-generate.
	* aarch64-linux-tdep.c (aarch64_linux_init_abi): Don't set
	displaced_step_free_closure.
	* amd64-linux-tdep.c (amd64_linux_init_abi_common): Likewise.
	* arm-linux-tdep.c (arm_linux_init_abi): Likewise.
	* i386-linux-tdep.c (i386_linux_init_abi): Likewise.
	* rs6000-aix-tdep.c (rs6000_aix_init_osabi): Likewise.
	* rs6000-tdep.c (rs6000_gdbarch_init): Likewise.
	* s390-linux-tdep.c (s390_gdbarch_init): Likewise.
	* arch-utils.h (simple_displaced_step_free_closure): Remove.
	* arch-utils.c (simple_displaced_step_free_closure): Remove.
	* infrun.c (displaced_step_clear): Call xfree instead of
	gdbarch_displaced_step_free_closure.
2017-06-10 00:24:50 +02:00
Sergio Durigan Junior 9845682bda Include <signal.h> on gdbserver/fork-child.c (and fix regressions)
Hi,

This is another obvious patch that fixes a thinko from my previous
startup-with-shell series.  We should conditionally include <signal.h>
on gdb/gdbserver/fork-child.c because gdbserver will be putting the
inferior's terminal on the correct mode after the call to
fork_inferior, and for that it needs to ignore SIGTTOU.

This patch fixes a bunch of regressions happening on AArch64 that were
reported by Yao.

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

	* fork-child.c: Conditionally include <signal.h>.
2017-06-09 18:16:19 -04:00
Sergio Durigan Junior 2f91880f3a Fix possible bug when no args have been provided to the executable
Hi,

This bug is related to:

  <https://sourceware.org/ml/gdb-patches/2017-06/msg00216.html>

On stringify_argv, we have to check if args[0] is not NULL before
stringifying anything, otherwise we might do the wrong thing when
trimming the "ret" string in the end.  args[0] will be NULL when no
arguments are passed to the inferior that will be started.

Checked in as obvious.

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

	* common/common-utils.c (stringify_argv): Check for "arg[0] !=
	NULL".
2017-06-08 16:58:25 -04:00
Alan Hayward b8b6e72f3d Add MN10300_MAX_REGISTER_SIZE
gdb/
	* mn10300-tdep.c (MN10300_MAX_REGISTER_SIZE): Add.
	(mn10300_extract_return_value): Use MN10300_MAX_REGISTER_SIZE.
	(mn10300_push_dummy_call): Likewise.
2017-06-08 16:05:24 +01:00
Alan Hayward 5369082e7b Update ff4ca5ac6a to the correct version.
gdb/
	* mi/mi-main.c (register_changed_p): Use value_contents_eq.
2017-06-08 16:00:23 +01:00
Alan Hayward ff4ca5ac6a Remove MAX_REGISTER_SIZE from mi/mi-main.c
gdb/
	* mi/mi-main.c (register_changed_p): Use cooked_read_value.
2017-06-08 14:02:59 +01:00
Sergio Durigan Junior aefd8b33d9 Implement proper "startup-with-shell" support on gdbserver
This patch implements the proper support for the "startup-with-shell"
feature on gdbserver.  A new packet is added, QStartupWithShell, and
it is sent on initialization.  If the host sends a
"QStartupWithShell:1", it means the inferior shall be started using a
shell.  If the host sends a "QStartupWithShell:0", it means the
inferior shall be started without using a shell.  Any other value is
considered an error.

There is no way to remotely set the shell that will be used by the
target to start the inferior.  In order to do that, the user must
start gdbserver while providing a shell via the $SHELL environment
variable.  The same is true for the host side.

The "set startup-with-shell" setting from the host side is used to
decide whether to start the remote inferior using a shell.  This same
setting is also used to decide whether to use a shell to start the
host inferior; this means that it is not really possible to start the
inferior using different mechanisms on target and host.

A documentation patch is included, along with a new testcase for the
feature.

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

	* NEWS (Changes since GDB 8.0): Announce that GDBserver is now
	able to start inferiors	using a shell.
	(New remote packets): Announce new packet "QStartupWithShell".
	* remote.c: Add PACKET_QStartupWithShell.
	(extended_remote_create_inferior): Handle new
	PACKET_QStartupWithShell.
	(remote_protocol_features) <QStartupWithShell>: New entry for
	PACKET_QStartupWithShell.
	(_initialize_remote): Call "add_packet_config_cmd" for
	QStartupShell.

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

	* server.c (handle_general_set): Handle new packet
	"QStartupWithShell".
	(handle_query): Add "QStartupWithShell" to the list of supported
	packets.
	(gdbserver_usage): Add help text explaining the
	new "--startup-with-shell" and "--no-startup-with-shell" CLI
	options.
	(captured_main): Recognize and act upon the presence of the new
	CLI options.

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

	* gdb.base/startup-with-shell.c: New file.
	* gdb.base/startup-with-shell.exp: Likewise.

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

	* gdb.texinfo (Starting) <startup-with-shell>: Add @anchor.
	(Connecting) <Remote Packet>: Add "startup-with-shell"
	and "QStartupWithShell" to the table.
	(Remote Protocol) <QStartupWithShell>: New item, explaining the
	packet.
2017-06-07 19:56:09 -04:00
Sergio Durigan Junior 2090129c36 Share fork_inferior et al with gdbserver
This is the most important (and the biggest, sorry) patch of the
series.  It moves fork_inferior from gdb/fork-child.c to
nat/fork-inferior.c and makes all the necessary adjustments to both
GDB and gdbserver to make sure everything works OK.

There is no "most important change" with this patch; all changes are
made in a progressive way, making sure that gdbserver had the
necessary features while not breaking GDB at the same time.

I decided to go ahead and implement a partial support for starting the
inferior with a shell on gdbserver, although the full feature comes in
the next patch.  The user won't have the option to disable the
startup-with-shell, and also won't be able to change which shell
gdbserver will use (other than setting the $SHELL environment
variable, that is).

Everything is working as expected, and no regressions were present
during the tests.

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

	* Makefile.in (HFILES_NO_SRCDIR): Add "common/common-inferior.h"
	and "nat/fork-inferior.h".
	* common/common-inferior.h: New file, with contents from
	"gdb/inferior.h".
	* commom/common-utils.c: Include "common-utils.h".
	(stringify_argv): New function.
	* common/common-utils.h (stringify_argv): New prototype.
	* configure.nat: Add "fork-inferior.o" as a dependency for
	"*linux*", "fbsd*" and "nbsd*" hosts.
	* corefile.c (get_exec_file): Update comment.
	* darwin-nat.c (darwin_ptrace_him): Call "gdb_startup_inferior"
	instead of "startup_inferior".
	(darwin_create_inferior): Call "add_thread_silent" after
	"fork_inferior".
	* fork-child.c: Cleanup unnecessary includes.
	(SHELL_FILE): Move to "common/common-fork-child.c".
	(environ): Likewise.
	(exec_wrapper): Initialize.
	(get_exec_wrapper): New function.
	(breakup_args): Move to "common/common-fork-child.c"; rename to
	"breakup_args_for_exec".
	(escape_bang_in_quoted_argument): Move to
	"common/common-fork-child.c".
	(saved_ui): New variable.
	(prefork_hook): New function.
	(postfork_hook): Likewise.
	(postfork_child_hook): Likewise.
	(gdb_startup_inferior): Likewise.
	(fork_inferior): Move to "common/common-fork-child.c".  Update
	function to support gdbserver.
	(startup_inferior): Likewise.
	* gdbcore.h (get_exec_file): Remove declaration.
	* gnu-nat.c (gnu_create_inferior): Call "gdb_startup_inferior"
	instead of "startup_inferior".  Call "add_thread_silent" after
	"fork_inferior".
	* inf-ptrace.c: Include "nat/fork-inferior.h" and "utils.h".
	(inf_ptrace_create_inferior): Call "gdb_startup_inferior"
	instead of "startup_inferior".  Call "add_thread_silent" after
	"fork_inferior".
	* inferior.h: Include "common-inferior.h".
	(trace_start_error): Move to "common/common-utils.h".
	(trace_start_error_with_name): Likewise.
	(fork_inferior): Move prototype to "nat/fork-inferior.h".
	(startup_inferior): Likewise.
	(gdb_startup_inferior): New prototype.
	* nat/fork-inferior.c: New file, with contents from "fork-child.c".
	* nat/fork-inferior.h: New file.
	* procfs.c (procfs_init_inferior): Call "gdb_startup_inferior"
	instead of "startup_inferior".  Call "add_thread_silent" after
	"fork_inferior".
	* target.h (target_terminal_init): Move prototype to
	"target/target.h".
	(target_terminal_inferior): Likewise.
	(target_terminal_ours): Likewise.
	* target/target.h (target_terminal_init): New prototype, moved
	from "target.h".
	(target_terminal_inferior): Likewise.
	(target_terminal_ours): Likewise.
	* utils.c (gdb_flush_out_err): New function.

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

	* Makefile.in (SFILES): Add "nat/fork-inferior.o".
	* configure: Regenerate.
	* configure.srv (srv_linux_obj): Add "fork-child.o" and
	"fork-inferior.o".
	(i[34567]86-*-lynxos*): Likewise.
	(spu*-*-*): Likewise.
	* fork-child.c: New file.
	* linux-low.c: Include "common-inferior.h", "nat/fork-inferior.h"
	and "environ.h".
	(linux_ptrace_fun): New function.
	(linux_create_inferior): Adjust function prototype to reflect
	change on "target.h".  Adjust function code to use
	"fork_inferior".
	(linux_request_interrupt): Delete "signal_pid".
	* lynx-low.c: Include "common-inferior.h" and "nat/fork-inferior.h".
	(lynx_ptrace_fun): New function.
	(lynx_create_inferior): Adjust function prototype to reflect
	change on "target.h".  Adjust function code to use
	"fork_inferior".
	* nto-low.c (nto_create_inferior): Adjust function prototype and
	code to reflect change on "target.h".  Update comments.
	* server.c: Include "common-inferior.h", "nat/fork-inferior.h",
	"common-terminal.h" and "environ.h".
	(terminal_fd): Moved to fork-child.c.
	(old_foreground_pgrp): Likewise.
	(restore_old_foreground_pgrp): Likewise.
	(last_status): Make it global.
	(last_ptid): Likewise.
	(our_environ): New variable.
	(startup_with_shell): Likewise.
	(program_name): Likewise.
	(program_argv): Rename to...
	(program_args): ...this.
	(wrapper_argv): New variable.
	(start_inferior): Delete function.
	(get_exec_wrapper): New function.
	(get_exec_file): Likewise.
	(get_environ): Likewise.
	(prefork_hook): Likewise.
	(post_fork_inferior): Likewise.
	(postfork_hook): Likewise.
	(postfork_child_hook): Likewise.
	(handle_v_run): Update code to deal with arguments coming from the
	remote host.  Update calls from "start_inferior" to
	"create_inferior".
	(captured_main): Likewise.  Initialize environment variable.  Call
	"have_job_control".
	* server.h (post_fork_inferior): New prototype.
	(get_environ): Likewise.
	(last_status): Declare.
	(last_ptid): Likewise.
	(signal_pid): Likewise.
	* spu-low.c: Include "common-inferior.h" and "nat/fork-inferior.h".
	(spu_ptrace_fun): New function.
	(spu_create_inferior): Adjust function prototype to reflect change
	on "target.h".  Adjust function code to use "fork_inferior".
	* target.c (target_terminal_init): New function.
	(target_terminal_inferior): Likewise.
	(target_terminal_ours): Likewise.
	* target.h: Include <vector>.
	(struct target_ops) <create_inferior>: Update prototype.
	(create_inferior): Update macro.
	* utils.c (gdb_flush_out_err): New function.
	* win32-low.c (win32_create_inferior): Adjust function prototype
	and code to reflect change on "target.h".

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

	* gdb.server/non-existing-program.exp: Update regex in order to
	reflect the fact that gdbserver is now using fork_inferior (with a
	shell) to startup the inferior.
2017-06-07 19:56:09 -04:00
Sergio Durigan Junior 043a49349c Share parts of gdb/gdbthread.h with gdbserver
GDB and gdbserver now share 'switch_to_thread' because of
fork_inferior.  To make things clear, I created a new file name
common/common-gdbthread.h, and left the implementation specific to
each part.

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

	* Makefile.in (HFILES_NO_SRCDIR): Add "common/common-gdbthread.h".
	* common/common-gdbthread.h: New file, with parts from
	"gdb/gdbthread.h".
	* gdbthread.h: Include "common-gdbthread.h".
	(switch_to_thread): Moved to "common/common-gdbthread.h".

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

	* inferiors.c (switch_to_thread): New function.
2017-06-07 19:56:01 -04:00
Sergio Durigan Junior 156525114c Move parts of inferior job control to common/
This commit moves a few bits responsible for dealing with inferior job
control from GDB to common/, which makes them available to gdbserver.
This is necessary for the upcoming patches that will share
fork_inferior et al between GDB and gdbserver.

We move some parts of gdb/terminal.h to gdb/common/common-terminal.h,
especifically the code that checks terminal features and that are used
to set job_control accordingly.

After sharing parts of gdb/terminal.h, we also to share the two
functions on gdb/inflow.c that are going to be needed by the
fork_inferior rework.  They are 'gdb_setpgid' and the new
'have_job_control'.  I've also taken the opportunity to give a more
meaningful name to "inflow.c" on common/.  Now it is called
"job-control.c" (thanks Pedro for the suggestion).

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

	* Makefile.in (SFILES): Add "common/job-control.c".
	(HFILES_NO_SRCDIR): Add "common/job-control.h".
	(COMMON_OBS): Add "job-control.o".
	* common/job-control.c: New file, with contents from
	"gdb/inflow.c".
	* common/job-control.h: New file, with contents from "terminal.h".
	* fork-child.c: Include "job-control.h".
	* inflow.c: Include "job-control.h".
	(gdb_setpgid): Move to "common/common-inflow.c".
	(_initialize_inflow): Move setting of "job_control" to
	"handle_job_control".
	* terminal.h (job_control): Moved to "common/common-terminal.h".
	(gdb_setpgid): Likewise.
	* top.c: Include "job_control.h".
	* utils.c: Likewise.
	(job_control): Moved to "job-control.c".

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

	* Makefile.in (SFILE): Add "common/job-control.c".
	(OBS): Add "job-control.o".
2017-06-07 19:52:56 -04:00
Pedro Alves 2d7cc5c797 Introduce compiled_regex, eliminate make_regfree_cleanup
This patch replaces compile_rx_or_error and make_regfree_cleanup with
a class that wraps a regex_t.

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

	* Makefile.in (SFILES): Add gdb_regex.c.
	(COMMON_OBS): Add gdb_regex.o.
	* ada-lang.c (ada_add_standard_exceptions)
	(ada_add_exceptions_from_frame, name_matches_regex)
	(ada_add_global_exceptions, ada_exceptions_list_1): Change regex
	parameter type to compiled_regex.  Adjust.
	(ada_exceptions_list): Use compiled_regex.
	* break-catch-throw.c (exception_catchpoint::pattern): Now a
	std::unique_ptr<compiled_regex>.
	(exception_catchpoint::~exception_catchpoint): Remove regfree
	call.
	(check_status_exception_catchpoint): Adjust to use compiled_regex.
	(handle_gnu_v3_exceptions): Adjust to use compiled_regex.
	* breakpoint.c (solib_catchpoint::compiled): Now a
	std::unique_ptr<compiled_regex>.
	(solib_catchpoint::~solib_catchpoint): Remove regfree call.
	(check_status_catch_solib): Adjust to use compiled_regex.
	(add_solib_catchpoint): Adjust to use compiled_regex.
	* cli/cli-cmds.c (apropos_command): Use compiled_regex.
	* cli/cli-decode.c (apropos_cmd): Change regex parameter to
	compiled_regex reference.  Adjust to use it.
	* cli/cli-decode.h: Remove struct re_pattern_buffer forward
	declaration.  Include "gdb_regex.h".
	(apropos_cmd): Change regex parameter to compiled_regex reference.
	* gdb_regex.c: New file.
	* gdb_regex.h (make_regfree_cleanup, get_regcomp_error): Delete
	declarations.
	(class compiled_regex): New.
	* linux-tdep.c: Include "common/gdb_optional.h".
	(struct mapping_regexes): New, factored out from
	mapping_is_anonymous_p, and adjusted to use compiled_regex.
	(mapping_is_anonymous_p): Use mapping_regexes wrapped in a
	gdb::optional and remove cleanups.  Adjust to compiled_regex.
	* probe.c: Include "common/gdb_optional.h".
	(collect_probes): Use compiled_regex and gdb::optional and remove
	cleanups.
	* skip.c: Include "common/gdb_optional.h".
	(skiplist_entry::compiled_function_regexp): Now a
	gdb::optional<compiled_regex>.
	(skiplist_entry::compiled_function_regexp_is_valid): Delete field.
	(free_skiplist_entry): Remove regfree call.
	(compile_skip_regexp, skip_rfunction_p): Adjust to use
	compiled_regex and gdb::optional.
	* symtab.c: Include "common/gdb_optional.h".
	(search_symbols): Use compiled_regex and gdb::optional.
	* utils.c (do_regfree_cleanup, make_regfree_cleanup)
	(get_regcomp_error, compile_rx_or_error): Delete.  Some bits moved
	to gdb_regex.c.
2017-06-07 14:21:40 +01:00
Alan Hayward 50d6adef3b Remove MAX_REGISTER_SIZE from regcache.c
gdb/
	* regcache.c (regcache::save): Avoid buffer use.
	(regcache::dump): Likewise.
2017-06-07 10:16:46 +01:00
Alan Hayward 4a8a33c843 Remove MAX_REGISTER_SIZE from sh(64)-tdep.c
gdb/
	* sh-tdep.c (sh_pseudo_register_read): Remove
	MAX_REGISTER_SIZE.
	(sh_pseudo_register_write): Likewise.
	* sh64-tdep.c (sh64_pseudo_register_read): Likewise.
	(sh64_pseudo_register_write): Likewise.
2017-06-07 10:11:24 +01:00
Alan Hayward d1be909e7f Remove MAX_REGISTER_SIZE from aarch64-tdep.c
gdb/
	* aarch64-tdep.c (aarch64_store_return_value): Use
	V_REGISTER_SIZE.
	(aarch64_pseudo_read_value): Likewise.
	(aarch64_pseudo_write): Likewise.
2017-06-07 09:57:55 +01:00
Yao Qi f4a6504277 Remove declaration of set_register_cache from regdef.h
Function set_register_cache was removed by 3aee891821
([GDBserver] Multi-process + multi-arch), so this patch removes the
declaration too.

gdb:

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

	* regformats/regdef.h (set_register_cache): Remove the
	declaration.
2017-06-06 16:42:45 +01:00
Alan Hayward 9f7fb0aa2b Remove a MAX_REGISTER_SIZE from frame.c
gdb/
	* frame.c (frame_unwind_register_signed): Use
	frame_unwind_register_value.
2017-06-06 16:34:20 +01:00
Pedro Alves e1e01040aa Fix double free when running gdb.linespec/ls-errs.exp (PR breakpoints/21553)
The problem is that b->extra_string is free'ed twice: Once in the
breakpoint's dtor, and another time via make_cleanup (xfree).

This patch gets rid of the cleanups, fixing the problem.

Tested on x86_64 GNU/Linux.

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

	PR breakpoints/21553
	* breakpoint.c (create_breakpoints_sal_default)
	(init_breakpoint_sal, create_breakpoint_sal): Use
	gdb::unique_xmalloc_ptr for string parameters.
	(create_breakpoint): Constify 'extra_string' and 'cond_string'
	parameters.  Replace cleanups with gdb::unique_xmalloc_ptr.
	(base_breakpoint_create_breakpoints_sal)
	(bkpt_create_breakpoints_sal, tracepoint_create_breakpoints_sal)
	(strace_marker_create_breakpoints_sal)
	(create_breakpoints_sal_default): Use gdb::unique_xmalloc_ptr for
	string parameters.
	* breakpoint.h (breakpoint_ops::create_breakpoints_sal): Use
	gdb::unique_xmalloc_ptr for string parameters.
	(create_breakpoint): Constify 'extra_string' and 'cond_string'
	parameters.
2017-06-06 15:53:59 +01:00
Alan Hayward fbe654c8bc Remove uses of MAX_REGISTER_SIZE from alpha-tdep.c
gdb/
	* alpha-tdep.c (alpha_register_to_value): Use
	get_frame_register_value.
	(alpha_value_to_register): Use ALPHA_REGISTER_SIZE.
2017-06-06 15:45:08 +01:00
Alan Hayward ae0d01d663 Add IA64_MAX_FP_REGISTER_SIZE
gdb/
	* ia64-tdep.c (IA64_MAX_FP_REGISTER_SIZE) Add.
	(ia64_register_to_value): Use IA64_MAX_FP_REGISTER_SIZE.
	(ia64_value_to_register): Likewise.
	(ia64_extract_return_value): Likewise.
	(ia64_store_return_value): Likewise.
	(ia64_push_dummy_call): Likewise.
2017-06-06 13:50:07 +01:00
Joel Brobecker 49cf576c22 Document the GDB 8.0 release in gdb/ChangeLog
gdb/ChangeLog:

	GDB 8.0 released.
2017-06-04 09:04:09 -07:00
Simon Marchi 26b6a6aba5 x86-linux-nat: Remove unused arch_lwp_info structure
The structure arch_lwp_info for x86 is not used, remove it.

gdb/ChangeLog:

	* x86-linux-nat.c (struct arch_lwp_info): Remove.
2017-06-03 22:06:55 +02:00
Simon Marchi 22827c5133 linux-nat: Remove unused parameter
The parameter "first" of linux_nat_post_attach_wait is unused, remove
it.

gdb/ChangeLog:

	* linux-nat.c (linux_nat_post_attach_wait): Remove FIRST
	parameter.
	(linux_nat_attach): Adjust call to linux_nat_post_attach_wait.
2017-06-03 21:24:00 +02:00
Simon Marchi 0e05cf3a61 Use delete instead of xfree for gdb_timer
gdb_timer objects are new'ed in create_timer, but xfree'd in
poll_timers.  Use delete instead.

gdb/ChangeLog:

	* event-loop.c (poll_timers): Unallocate timer using delete
	instead of xfree.
2017-06-02 23:24:21 +02:00
Simon Marchi c1fc265720 C++ify breakpoint class hierarchy (destructors only)
Breakpoints are currently in a limbo state between C and C++.  There is
a pseudo class hierarchy implemented using struct fields.  Taking
watchpoint as an example:

  struct watchpoint
  {
    /* The base class.  */
    struct breakpoint base;

    ...
  }

and it is instantianted with "new watchpoint ()".  When destroyed, a
destructor is first invoked through the breakpoint_ops, and then the
memory is freed by calling delete through a pointer to breakpoint.
Address sanitizer complains about this, for example, because we new and
delete the same memory using different types.

This patch takes the logical step of making breakpoint subclasses extend
the breakpoint class for real, and converts their destructors to actual
C++ destructors.

Regtested on the buildbot.

gdb/ChangeLog:

	* breakpoint.h (struct breakpoint_ops) <dtor>: Remove.
	(struct breakpoint) <~breakpoint>: New.
	(struct watchpoint): Inherit from breakpoint.
	<~watchpoint>: New.
	<base>: Remove.
	(struct tracepoint): Inherit from breakpoint.
	<base>: Remove.
	* breakpoint.c (longjmp_breakpoint_ops): Remove.
	(struct longjmp_breakpoint): Inherit from breakpoint.
	<~longjmp_breakpoint>: New.
	<base>: Remove.
	(new_breakpoint_from_type): Remove casts.
	(watchpoint_in_thread_scope): Remove reference to base field.
	(watchpoint_del_at_next_stop): Likewise.
	(update_watchpoint): Likewise.
	(watchpoint_check): Likewise.
	(bpstat_check_watchpoint): Likewise.
	(set_longjmp_breakpoint): Likewise.
	(struct fork_catchpoint): Inherit from breakpoint.
	<base>: Remove.
	(struct solib_catchpoint): Inherit from breakpoint.
	<~solib_catchpoint>: New.
	<base>: Remove.
	(dtor_catch_solib): Change to ...
	(solib_catchpoint::~solib_catchpoint): ... this.
	(breakpoint_hit_catch_solib): Remove reference to base field.
	(add_solib_catchpoint): Likewise.
	(create_fork_vfork_event_catchpoint): Likewise.
	(struct exec_catchpoint): Inherit from breakpoint.
	<~exec_catchpoint>: New.
	<base>: Remove.
	(dtor_catch_exec): Change to ...
	(exec_catchpoint::~exec_catchpoint): ... this.
	(dtor_watchpoint): Change to ...
	(watchpoint::~watchpoint): ... this.
	(watch_command_1): Remove reference to base field.
	(catch_exec_command_1): Likewise.
	(base_breakpoint_dtor): Change to ...
	(breakpoint::~breakpoint): ... this.
	(base_breakpoint_ops): Remove dtor field value.
	(longjmp_bkpt_dtor): Change to ...
	(longjmp_breakpoint::~longjmp_breakpoint): ... this.
	(strace_marker_create_breakpoints_sal): Remove reference to base
	field.
	(delete_breakpoint): Don't manually call breakpoint destructor.
	(create_tracepoint_from_upload): Remove reference to base field.
	(trace_pass_set_count): Likewise.
	(initialize_breakpoint_ops): Don't initialize
	momentary_breakpoint_ops, don't set dtors.
	* ada-lang.c (struct ada_catchpoint): Inherit from breakpoint.
	<~ada_catchpoint>: New.
	<base>: Remove.
	(create_excep_cond_exprs): Remove reference to base field.
	(dtor_exception): Change to ...
	(ada_catchpoint::~ada_catchpoint): ... this.
	(dtor_catch_exception): Remove.
	(dtor_catch_exception_unhandled): Remove.
	(dtor_catch_assert): Remove.
	(create_ada_exception_catchpoint): Remove reference to base
	field.
	(initialize_ada_catchpoint_ops): Don't set dtors.
	* break-catch-sig.c (struct signal_catchpoint): Inherit from
	breakpoint.
	<~signal_catchpoint>: New.
	<base>: Remove.
	(signal_catchpoint_dtor): Change to ...
	(signal_catchpoint::~signal_catchpoint): ... this.
	(create_signal_catchpoint): Remove reference to base field.
	(initialize_signal_catchpoint_ops): Don't set dtor.
	* break-catch-syscall.c (struct syscall_catchpoint): Inherit
	from breakpoint.
	<~syscall_catchpoint>: New.
	<base>: Remove.
	(dtor_catch_syscall): Change to ...
	(syscall_catchpoint::~syscall_catchpoint): ... this.
	(create_syscall_event_catchpoint): Remove reference to base
	field.
	(initialize_syscall_catchpoint_ops): Don't set dtor.
	* break-catch-throw.c (struct exception_catchpoint): Inherit
	from breakpoint.
	<~exception_catchpoint>: New.
	<base>: Remove.
	(dtor_exception_catchpoint): Change to ...
	(exception_catchpoint::~exception_catchpoint): ... this.
	(handle_gnu_v3_exceptions): Remove reference to base field.
	(initialize_throw_catchpoint_ops): Don't set dtor.
	* ctf.c (ctf_get_traceframe_address): Remove reference to base
	field.
	* remote.c (remote_get_tracepoint_status): Likewise.
	* tracefile-tfile.c (tfile_get_traceframe_address): Likewise.
	* tracefile.c (tracefile_fetch_registers): Likewise.
	* tracepoint.c (actions_command): Likewise.
	(validate_actionline): Likewise.
	(tfind_1): Likewise.
	(get_traceframe_location): Likewise.
	(find_matching_tracepoint_location): Likewise.
	(parse_tracepoint_status): Likewise.
	* mi/mi-cmd-break.c (mi_cmd_break_passcount): Likewise.
2017-06-02 23:16:21 +02:00
Simon Marchi 3b0871f44a Create struct type for longjmp breakpoint
The longjmp kind of breakpoint has a destructor, but doesn't have an
associated structure.  The next patch converts breakpoint destructors from
breakpoint_ops::dtor to actual destructors, but to do that it is needed
for longjmp_breakpoint to have a structure that will contain such
destructor.  This patch adds it.

According to initialize_breakpoint_ops, a longjmp breakpoint derives
from "momentary breakpoints", so eventually a momentary_breakpoint
struct/class should probably be created.  It's not necessary for the
destructor though, so a structure type for this abstract kind of
breakpoint can be added when we fully convert breakpoint ops into
methods of the breakpoint type hierarchy.

It is now necessary to instantiate different kinds of breakpoint objects
in set_raw_breakpoint_without_location based on bptype (sometimes a
breakpoint, sometimes a longjmp_breakpoint), so it now uses
new_breakpoint_from_type to do that.  I also changed set_raw_breakpoint
to use it, even though I don't think that it can ever receive a bptype
that actually requires it.  However, I think it's good if all breakpoint
object instantion is done in a single place.

gdb/ChangeLog:

	* breakpoint.c (struct longjmp_breakpoint): New struct.
	(is_tracepoint_type): Change return type to bool.
	(is_longjmp_type): New function.
	(new_breakpoint_from_type): Handle longjmp kinds of breakpoints.
	(set_raw_breakpoint_without_location): Use
	new_breakpoint_from_type.
	(set_raw_breakpoint): Likewise.
2017-06-02 23:16:20 +02:00
Simon Marchi a5e364af4a Introduce and use new_breakpoint_from_type
This is a small preparatory patch to factor out a snippet that appears
twice.  More kinds of breakpoints will need to be created based on
bptype, so I think it's a good idea to centralize the instantiation of
breakpoint objects.

gdb/ChangeLog:

	* breakpoint.c (new_breakpoint_from_type): New function.
	(create_breakpoint_sal): Use new_breakpoint_from_type and
	unique_ptr.
	(create_breakpoint): Likewise.
2017-06-02 23:16:19 +02:00
Simon Marchi ae3b3f34ed Rename "mem" related commmands
Rename "mem" related commands, so that their naming is consistent with
the <command-name>_command pattern of naming functions that implement
commands.

gdb/ChangeLog:

	* memattr.c (mem_info_command): Rename to ...
	(info_mem_command): ... this.
	(mem_enable_command): Rename to ...
	(enable_mem_command): ... this.
	(mem_disable_command): Rename to ...
	(disable_mem_command): ... this.
	(mem_delete_command): Rename to ...
	(delete_mem_command): ... this.
	(_initialize_mem): Adjust function names.
2017-05-31 17:09:07 +02:00
Markus Metzger 13ace07792 btrace: support decoder events
Newer versions of libipt support instruction flow decoder events instead of
indicating those events with flags in struct pt_insn.  Add support for them in
GDB.

gdb/
	* btrace.c (handle_pt_insn_events): New.
	(ftrace_add_pt): Call handle_pt_insn_events.  Rename ERRCODE into
	STATUS.  Split into this and ...
	(handle_pt_insn_event_flags): ... this.
2017-05-31 10:47:39 +02:00
Markus Metzger c56ccc05b2 config, btrace: check for pt_insn_event in libipt
Version 2 of libipt adds an event system to instruction flow decoders and
deprecates indicating events via flags in struct pt_insn.  Add configuration
checks to determine which version we have.

gdb/
	* configure.ac: Check for pt_insn_event, struct pt_insn.enabled,
	and struct pt_insn.resynced.
	* configure: Regenerated.
	* config.in: Regenerated.
2017-05-31 10:44:32 +02:00
Tim Wiederhake 08c3f6d234 btrace: Store function segments as objects. 2017-05-30 12:49:25 +02:00
Tim Wiederhake 8ffd39f2e4 btrace: Remove bfun_s vector. 2017-05-30 12:49:25 +02:00
Tim Wiederhake 4aeb0dfcc4 btrace: Replace struct btrace_function::segment.
This used to hold a pair of pointers to the previous and next function segment
that belong to this function call.  Replace with a pair of indices into the
vector of function segments.
2017-05-30 12:49:25 +02:00
Tim Wiederhake eb8f2b9c44 btrace: Remove struct btrace_function::flow.
This used to hold a pair of pointers to the previous and next function segment
in execution flow order.  It is no longer necessary as the previous and next
function segments now are simply the previous and next elements in the vector
of function segments.
2017-05-30 12:49:25 +02:00
Tim Wiederhake 42bfe59e3a btrace: Replace struct btrace_function::up.
This used to hold a function segment pointer.  Change it to hold an index into
the vector of function segments instead.
2017-05-30 12:49:25 +02:00
Tim Wiederhake b54b03bd87 btrace: Remove struct btrace_thread_info::{begin,end}.
These are no longer needed and might hold invalid addresses once we change the
vector of function segment pointers into a vector of function segment objects
where a reallocation of the vector changes the address of its elements.
2017-05-30 12:49:25 +02:00
Tim Wiederhake 8286623c11 btrace: Remove constant arguments. 2017-05-30 12:49:25 +02:00
Tim Wiederhake a0f1b96332 btrace: Use function segment index in insn iterator.
Remove FUNCTION pointer in struct btrace_insn_iterator and use an index into
the list of function segments instead.
2017-05-30 12:49:25 +02:00
Tim Wiederhake f158f20875 btrace: Use function segment index in call iterator.
Remove FUNCTION pointer in struct btrace_call_iterator and use an index into
the list of function segments instead.
2017-05-30 12:49:25 +02:00
Tim Wiederhake 521103fd00 btrace: Add btinfo to instruction interator.
This will serve as the access path to the vector of function segments once
the FUNCTION pointer in struct btrace_insn_iterator is removed.
2017-05-30 12:49:25 +02:00
Tim Wiederhake 17b89b34b8 btrace: Transfer ownership of pointers.
Directly insert new btrace_function pointers into the vector and have the
vector own these pointers.  This allows us to later retrieve these objects by
their number directly after creation whereas at the moment we have to wait
until the vector is fully populated.

This requires to pull btrace_thread_info through different functions but
cleans up the code for freeing the trace.
2017-05-30 12:49:25 +02:00
Tim Wiederhake 2b51eddc55 btrace: Use std::vector in struct btrace_thread_information. 2017-05-30 12:49:25 +02:00
Simon Marchi db6be0d5e3 Fix NEWS formatting in GDB 8.0 section
Change the GDB 8.0 section of the NEWS file to try to follow this order:

  * Functional changes
  * Added and removed configurations and targets
  * New commands
  * New options
  * MI changes

In particular, there were two "New commands" sections.

gdb/ChangeLog:

	* NEWS (Changes in GDB 8.0): Remove extra empty line.  Move
	"Removed targets and native configurations" up.  Merge duplicate
	"New commands" sub-sections.  Add "New options" sub-sections.
2017-05-30 11:29:57 +02:00
Simon Marchi 8e86a419d7 gdb.base/watch-cond-infcall.exp: Don't run if target doesn't support infcalls
This test requires calling a function in the inferior, and therefore it
doesn't make sense to run it if the target doesn't support calling
functions from GDB.

gdb/testsuite/ChangeLog:

	* gdb.base/watch-cond-infcall.exp: Don't run if target doesn't
	support function calls from GDB.
2017-05-30 11:24:52 +02:00
Alan Hayward b057297ab6 Add regcache raw_supply_integer and raw_collect_integer.
Use these to replace instances of MAX_REGISTER_SIZE.

	* defs.h (copy_integer_to_size): New declaration.
	* findvar.c (copy_integer_to_size): New function.
	(do_cint_test): New selftest function.
	(copy_integer_to_size_test): Likewise.
	(_initialize_findvar): Likewise.
	* mips-fbsd-tdep.c (mips_fbsd_supply_reg): Use raw_supply_integer.
	(mips_fbsd_collect_reg): Use raw_collect_integer.
	* mips-linux-tdep.c (supply_32bit_reg): Use raw_supply_integer.
	(mips64_fill_gregset): Use raw_collect_integer
	(mips64_fill_fpregset): Use raw_supply_integer.
	* regcache.c (regcache::raw_supply_integer): New function.
	(regcache::raw_collect_integer): Likewise.
	* regcache.h: (regcache::raw_supply_integer): New declaration.
	(regcache::raw_collect_integer): Likewise.
2017-05-26 17:07:52 +01:00
Yao Qi b77b02a5ca Add unit test to gdbarch methods register_to_value and value_to_register
This patch adds one unit test for gdbarch methods register_to_value and
value_to_register.  The test pass different combinations of {regnu, type}
to gdbarch_register_to_value and gdbarch_value_to_register.  In order
to do the test, add a new function create_new_frame to create a fake
frame.  It can be improved after we converted frame_info to class.

In order to isolate regcache (from target_ops operations on writing
registers, like target_store_registers), the sub-class of regcache in the
test override raw_write.  Also, in order to get the right regcache from
get_thread_arch_aspace_regcache, the sub-class of regcache inserts itself
to current_regcache.

Suppose I incorrectly modified the size of buffer as below,

@@ -1228,7 +1228,7 @@ ia64_register_to_value (struct frame_info *frame, int regnum,
                        int *optimizedp, int *unavailablep)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  gdb_byte in[MAX_REGISTER_SIZE];
+  gdb_byte in[1];

   /* Convert to TYPE.  */
   if (!get_frame_register_bytes (frame, regnum, 0,

build GDB with "-fsanitize=address" and run unittest.exp, asan can detect
such error

==2302==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fff98193870 at pc 0xbd55ea bp 0x7fff981935a0 sp 0x7fff98193598
WRITE of size 16 at 0x7fff98193870 thread T0
    #0 0xbd55e9 in frame_register_unwind(frame_info*, int, int*, int*, lval_type*, unsigned long*, int*, unsigned char*) /home/yao/SourceCode/gnu/gdb/git/gdb/frame.c:1119
    #1 0xbd58c8 in frame_register(frame_info*, int, int*, int*, lval_type*, unsigned long*, int*, unsigned char*) /home/yao/SourceCode/gnu/gdb/git/gdb/frame.c:1147
    #2 0xbd6e25 in get_frame_register_bytes(frame_info*, int, unsigned long, int, unsigned char*, int*, int*) /home/yao/SourceCode/gnu/gdb/git/gdb/frame.c:1427
    #3 0x70080a in ia64_register_to_value /home/yao/SourceCode/gnu/gdb/git/gdb/ia64-tdep.c:1236
    #4 0xbf570e in gdbarch_register_to_value(gdbarch*, frame_info*, int, type*, unsigned char*, int*, int*) /home/yao/SourceCode/gnu/gdb/git/gdb/gdbarch.c:2619
    #5 0xc05975 in register_to_value_test /home/yao/SourceCode/gnu/gdb/git/gdb/gdbarch-selftests.c:131

Or, even if GDB is not built with asan, GDB just crashes.

*** stack smashing detected ***: ./gdb terminated
Aborted (core dumped)

gdb:

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

	* Makefile.in (SFILES): Add gdbarch-selftests.c.
	(COMMON_OBS): Add gdbarch-selftests.o.
	* frame.c [GDB_SELF_TESTS] (create_new_frame): New function.
	* frame.h [GDB_SELF_TESTS] (create_new_frame): Declare.
	* gdbarch-selftests.c: New file.
	* regcache.h (regcache) <~regcache>: Mark it virtual if
	GDB_SELF_TEST.
	<raw_write>: Likewise.
2017-05-24 22:15:23 +01:00
Yao Qi e521e87e85 Move current_regcache to regcache::current_regcache
This patches moves global variable current_regcache to a class regcache
static variable (protected) so that the unit test I add in the following
patch can access it (by means of extending class regcache in unit test).

gdb:

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

	* regcache.c (current_regcache): Change it to
	regcache::current_regcache.
	(regcache_observer_target_changed): Update.
	(regcache_thread_ptid_changed): Make it a regcache static
	method.
	(regcache_thread_ptid_changed): Update.
	(class regcache_access): New.
	(current_regcache_test): Update.
	(_initialize_regcache): Update.
	* regcache.h: Include forward_list.
	(regcache): Declare regcache_thread_ptid_changed and declare
	registers_changed_ptid as friend.
2017-05-24 22:15:23 +01:00
Yao Qi d8e07dda92 Get register contents by register_size instead of TYPE_LENGTH
We should use register_size to get register contents instead of
TYPE_LENGTH.

gdb:

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

	* i387-tdep.c (i387_register_to_value): Use register_size
	instead of TYPE_LENGTH.
	* m68k-tdep.c (m68k_register_to_value): Likewise.
2017-05-24 22:15:23 +01:00
Yao Qi 8c8f9122ce Restrict i387_convert_register_p
gdb:

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

	* i387-tdep.c (i387_convert_register_p): Return false if type
	code isn't TYPE_CODE_FLT.
2017-05-24 22:15:23 +01:00
Yao Qi 68fce50f04 Restrict alpha_convert_register_p
This patch restricts alpha_convert_register_p from
"TYPE_LENGTH (type) != 8" to "TYPE_LENGTH (type) == 4", because,

 - we have check "TYPE_LENGTH (valtype) == 4" in alpha_register_to_value
   and alpha_value_to_register,
 - alpha lds and sts instruction access 4 bytes,
 - comments "It might need to convert the [float] register into the
   corresponding [integer] type (see Alpha)" and integer is 4-byte on
   alpha,

I think it is the right restrict condition to "TYPE_LENGTH (valtype) == 4".

gdb:

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

	* alpha-tdep.c (alpha_convert_register_p): Return true if type
	length is 4.
	(alpha_register_to_value): Remove type length check.
	(alpha_value_to_register): Likewise.
2017-05-24 22:15:23 +01:00
Yao Qi 88954b49e4 Restrict ia64_convert_register_p
gdb:

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

	* ia64-tdep.c (ia64_convert_register_p): Check type's code is
	TYPE_CODE_FLT.
2017-05-24 22:15:23 +01:00