Commit Graph

6805 Commits

Author SHA1 Message Date
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
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
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
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 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 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 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 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
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 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 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
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
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
Tom Tromey e6cf65f283 Print Rust unsized array types a bit more nicely
It's a bit difficult to create an unsized array type in Rust, but if
you do, right now ptype will show something like "[u8; ]".  It really
should print "[u8]", though, which is what this patch implements.

This is part of PR 21466.

Built and regtested on x86-64 Fedora 25.  I'm checking this in.

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

	PR rust/21466:
	* rust-lang.c (rust_print_type) <TYPE_CODE_ARRAY>: Print unsized
	arrays as "[T]", not "[T; ]".

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

	PR rust/21466:
	* gdb.rust/unsized.exp: New file.
	* gdb.rust/unsized.rs: New file.
2017-05-21 17:02:16 -06:00
Tom Tromey 43cc5389bc Use watchpoint's language when re-parsing expression
PR rust/21484 notes that watch -location does not work with Rust:

    (gdb) watch -location a
    syntax error in expression, near `) 0x00007fffffffe0f4'.

update_watchpoint tries to tell gdb that the new expression it creates
has C syntax:

      /* The above expression is in C.  */
      b->language = language_c;

However, update_watchpoint doesn't actually use this language when
re-parsing the expression.

Originally I was going to fix this by saving and restoring the
language in update_watchpoint, but this regressed
gdb.dlang/watch-loc.exp, because the constructed expression actually
has D syntax (specifically the name is not parseable by C).

Next I looked at directly constructing an expression, and not relying
on the parser at all; but it seemed to me that upon a re-set, we'd
want to reparse the type, and there is no existing API to do this
correctly.

So, in the end I made a hook to let each language choose what
expression to use.  I made all the languages other than Rust use the C
expression, because that is the status quo ante.  However, this is
probably not truly correct.  After this patch, at least, it is easy to
correct by someone who knows the language(s) in question.

Regtested by the buildbot.

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

	PR rust/21484:
	* rust-lang.c (exp_descriptor_rust): New function.
	(rust_language_defn): Use it.
	* p-lang.c (pascal_language_defn): Update.
	* opencl-lang.c (opencl_language_defn): Update.
	* objc-lang.c (objc_language_defn): Update.
	* m2-lang.c (m2_language_defn): Update.
	* language.h (struct language_defn)
	<la_watch_location_expression>: New member.
	* language.c (unknown_language_defn, auto_language_defn)
	(local_language_defn): Update.
	* go-lang.c (go_language_defn): Update.
	* f-lang.c (f_language_defn): Update.
	* d-lang.c (d_language_defn): Update.
	* c-lang.h (c_watch_location_expression): Declare.
	* c-lang.c (c_watch_location_expression): New function.
	(c_language_defn, cplus_language_defn, asm_language_defn)
	(minimal_language_defn): Use it.
	* breakpoint.c (watch_command_1): Call
	la_watch_location_expression.
	* ada-lang.c (ada_language_defn): Update.

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

	PR rust/21484:
	* gdb.rust/watch.exp: New file.
	* gdb.rust/watch.rs: New file.
2017-05-19 21:23:16 -06:00
Tom Tromey ec8df23454 Fix test failure with Rust 1.18 and 1.19
With Rust 1.18 and 1.19, I saw some test suite failures.  They were
all of the same form -- Box seems to be qualified in the output now,
like:

  print box_some
  $64 = core::option::Option<alloc::boxed::Box<u8>>::Some(0x7ffff6c21018 "\001\000")

... where the test was expecting Option<Box<u8>>.

This patch fixes the problem in a way that should work with earlier
versions of Rust.

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

	* gdb.rust/simple.exp: Allow Box to be qualified.
2017-05-18 17:40:29 -06:00
Thomas Preud'homme 3e3e7faebe Expect prompt after no FPU warning
2017-05-18  Thomas Preud'homme  <thomas.preudhomme@arm.com>

gdb/testsuite/
	* gdb.base/float.exp: Expect GDB prompt for targets without FPU.
2017-05-18 16:31:40 +01:00
Pedro Alves 59cc050d89 gdb.base/fileio.c: Fix several -Wmaybe-uninitialized warnings
src/gdb/testsuite/gdb.base/fileio.c: In function ‘test_write’:
 src/gdb/testsuite/gdb.base/fileio.c:158:5: warning: ‘ret’ may be used uninitialized in this function [-Wmaybe-uninitialized]
      printf ("write 1: ret = %d, errno = %d\n", ret, errno);
      ^

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

	* gdb.base/fileio.c (test_write, test_read, test_close)
	(test_fstat): Don't print 'ret' in the fail path.
2017-05-18 12:56:38 +01:00
Pedro Alves c8f6abd10d gdb.base/fileio.c: Fix several -Wreturn-type warnings
All the "test_" functions warn like:

  src/gdb/testsuite/gdb.base/fileio.c: In function ‘test_close’:
  src/gdb/testsuite/gdb.base/fileio.c:280:1: warning: control reaches end of non-void function [-Wreturn-type]
   }
   ^

Nothing looks at the return of these functions, so just make them
return void.  While at it, "()" is not the same as "(void)" in C - fix
that too.

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

	* gdb.base/fileio.c (stop, test_open, test_write, test_read)
	(test_lseek, test_close, test_stat, test_fstat, test_isatty)
	(test_system, test_rename, test_unlink, test_time): Change
	prototypes.
	* gdb.base/fileio.exp (stop_msg): Adjust.
2017-05-18 12:56:16 +01:00
Pedro Alves d2a03b7745 gdb.base/fileio.exp: Remove nowarnings
... and quiet -Wnonnull in a different way.

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

	* gdb.base/fileio.c (null_str): New global.
	(test_stat): Use it.
	* gdb.base/fileio.exp: Remove nowarnings.
2017-05-18 11:47:05 +01:00
Yao Qi 0d5c69990c Add nowarnings in gdb.base/fileio.exp
I see the following warning in gdb.base/fileio.c,

testsuite/gdb.base/fileio.c:297:3: warning: null argument where non-null required (argument 1) [-Wnonnull]
   ret = stat (NULL, &st);
   ^

This patch adds "nowarnings" to the list passed to gdb_compile.

gdb/testsuite:

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

	* gdb.base/fileio.exp: Pass nowarnings to gdb_compile.
2017-05-17 14:46:17 +01:00
Yao Qi 21873064e8 Add alias command to cmd_list_element
When we add alias command, we call add_alias_cmd and pass the alias name
and command name.  This implicitly requires the command and its prefix
commands are already added to cmdlist.  This may not be true, for example,

  add_com_alias ("tty", "set inferior-tty", class_alias, 0);

"inferior-tty" command is added to setlist, but setlist may not be added
to cmdlist (It depends on the order of related _initialize_XXX functions
called) so that we can't find "set inferior-tty" from cmdlist.

This patch fixes this problem by passing cmd_list_element of "inferior-tty"
to add_alias_cmd, so that cmd_list_element of "inferior-tty" doesn't have
to be reachable from cmdlist at that moment.

gdb:

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

	* cli/cli-decode.c (add_alias_cmd): New function.
	* command.h (add_alias_cmd): Declare.
	* infcmd.c (_initialize_infcmd): Don't call add_com_alias,
	instead call add_alias_cmd.

gdb/testsuite:

2017-05-17  Simon Marchi  <simon.marchi@ericsson.com>

	* gdb.base/set-inferior-tty.exp (test_set_inferior_tty): Add
	argument command.
	(top-level): Invoke test_set_inferior_tty.
2017-05-17 14:22:35 +01:00
Pedro Alves d512d31c39 Fix gdb.python/py-record-btrace-threads.exp with Python 3
Fix several instances of:

 ...
 python print not f1calls
   File "<string>", line 1
     print not f1calls
		     ^
 SyntaxError: Missing parentheses in call to 'print'
 Error while executing Python code.
 (gdb) FAIL: gdb.python/py-record-btrace-threads.exp: thread=1: checking thread 1: python print not f1calls
 ...

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

	* gdb.python/py-record-btrace-threads.exp (check_insn_for_thread):
	Add parens to print call for Python 3.
2017-05-04 16:02:36 +01:00
Keith Seitz 90cef2edd2 Make sure malloc is linked into gdb.cp/oranking.cc.
On some platforms, e.g., arm-eabi-none, we need to make certain that
malloc is linked into the program because the test suite uses function
calls requiring malloc:

(gdb) p foo101("abc")
evaluation of this expression requires the program to have a function "malloc".

gdb/testsuite/ChangeLog

	* gdb.cp/oranking.cc (dummy): New function to grab malloc.
	(main): Call it.
2017-05-03 12:41:09 -07:00
Tim Wiederhake 14f819c8c5 Python: Move and rename gdb.BtraceFunction
Remove gdb.BtraceFunctionCall and replace by gdb.FunctionSegment.  Additionally,
rename prev_segment and next_segment to prev and next.
2017-05-02 11:35:54 +02:00
Tim Wiederhake 913aeadd9d Python: Introduce gdb.RecordGap class
As discussed here: https://sourceware.org/ml/gdb-patches/2017-04/msg00157.html

A gap is not an instruction and it should not pretend to be one.
gdb.Record.instruction_history is now a list of gdb.RecordInstruction and
gdb.RecordGap objects.  This allows the user to deal with Gaps in the record
in a more sane way.
2017-05-02 11:35:54 +02:00
Tim Wiederhake a3be24ad59 Python: Remove ptid from gdb.Record interface
As discussed here: https://sourceware.org/ml/gdb-patches/2017-04/msg00166.html
2017-05-02 11:35:54 +02:00
Tim Wiederhake ae20e79ae8 Python: Use correct ptid in btrace recording
The user would always get the instruction_history and function_call_history
objects of the current thread, not the thread for which the gdb.Record object
was created.

The attached testcase fails without this patch and passes with the patch.
2017-05-02 11:35:54 +02:00
Sergio Durigan Junior 45ce1b47e4 Make environ.exp run on all platforms (and create info-program.exp)
This has been on my TODO list for a while.  There's a really old bug
about this (PR testsuite/8595), and there was no reason for
environ.exp to be specific for hppa* targets.  So this patch removes
this constraint, modernizes the testcase, and cleans up some things.
Most of the tests remained, and some were rewritten (especially the
one that checks if "show environment" works, which is something kind
of hard to do).

As a bonus, I'm adding a separated info-program.exp file containing
all the tests related to "info program" that were present on
environ.exp.

Tested locally, everything still passes.

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

	PR testsuite/8595
	* gdb.base/environ.exp: Make test available in all architectures.
	Move bits related to "info program" testing to
	gdb.base/info-program.exp.  Rewrite tests to use the two new
	procedures mentione below.
	(test_set_show_env_var) New procedure.
	(test_set_show_env_var_equal): Likewise.
	* gdb.base/info-program.exp: New file.
2017-04-28 20:29:20 -04:00
Keith Seitz e15c3eb45b Fix overload resolution involving rvalue references and cv qualifiers.
The following patch fixes several outstanding overload resolution problems
with rvalue references and cv qualifiers in the test suite. The tests for
these problems typically passed with one compiler version and failed with
another. This behavior occurs because of the ordering of the overloaded
functions in the debug info. So the first best match "won out" over the
a subsequent better match.

One of the bugs addressed by this patch is the failure of rank_one_type to
account for type equality of two overloads based on CV qualifiers.  This was
leading directly to problems evaluating rvalue reference overload quality,
but it is also highlighted in gdb.cp/oranking.exp, where two test KFAIL as
a result of this shortcoming.

I found the overload resolution code committed with the rvalue reference
patch (f9aeb8d49) needlessly over-complicated, and I have greatly simplified
it. This fixes some KFAILing tests in gdb.exp/rvalue-ref-overload.exp.

gdb/ChangeLog

	* gdbtypes.c (LVALUE_REFERENCE_TO_RVALUE_BINDING_BADNESS)
	DIFFERENT_REFERENCE_TYPE_BADNESS): Remove.
	(CV_CONVERSION_BADNESS): Define.
	(rank_one_type): Remove overly restrictive rvalue reference
	rank checks.
	Add cv-qualifier checks and subranks for type equality.
	* gdbtypes.h (REFERENCE_CONVERSION_RVALUE,
	REFERENCE_CONVERSION_CONST_LVALUE, CV_CONVERSION_BADNESS,
	CV_CONVERSION_CONST, CV_CONVERSION_VOLATILE): Declare.

gdb/testsuite/ChangeLog

	* gdb.cp/oranking.cc (test15): New function.
	(main): Call test15 and declare additional variables for testing.
	* gdb.cp/oranking.exp: Remove kfail status for "p foo4(&a)" and
	"p foo101('abc')" tests.
	* gdb.cp/rvalue-ref-overloads.exp: Remove kfail status for
	"lvalue reference overload" test.
	* gdb.cp/rvalue-ref-params.exp: Remove kfail status for
	"print value of f1 on Child&& in f2" test.
2017-04-27 15:58:54 -07:00
Pedro Alves 3a3fd0fd2c Fix removing inferiors from within "thread apply" commands
This patch fixes an internal error exposed by a test that does
something like:

  define kill-and-remove
    kill inferiors 2
    remove-inferiors 2
  end

  # Start one inferior.
  start

  # Start another inferior.
  add-inferior 2
  inferior 2
  start

  # Kill and remove inferior 1 while inferior 2 is selected.
  thread apply 1.1 kill-and-remove

The internal error looks like this:

 Thread 1.1 (Thread 0x7ffff7fc2700 (LWP 20677)):
 [Switching to inferior 1 [process 20677] (gdb/testsuite/outputs/gdb.threads/threadapply/threadapply)]
 [Switching to thread 1.1 (Thread 0x7ffff7fc2700 (LWP 20677))]
 #0  main () at src/gdb/testsuite/gdb.threads/threadapply.c:38
 38          for (i = 0; i < NUM; i++)
 src/gdb/inferior.c:66: internal-error: void set_current_inferior(inferior*): Assertion `inf != NULL' failed.
 A problem internal to GDB has been detected,
 further debugging may prove unreliable.
 Quit this debugging session? (y or n) FAIL: gdb.threads/threadapply.exp: kill_and_remove_inferior: try kill-and-remove: thread apply 1.1 kill-and-remove (GDB internal error)

There are several problems around this area of the code.  One is that
in do_restore_current_thread_cleanup, we do a look up of inferior by
ptid, which can find the wrong inferior if the previously selected
inferior exited and some other inferior was started with a reused pid
(rare, but still...).

The other problem is that the "remove-inferiors" command rejects
attempts to remove the current inferior, but when we get to
"remove-inferiors" in a "thread apply THR remove-inferiors 2" command,
the current inferior is the inferior of thread THR, not the previously
selected inferior, so if the previously selected inferior was inferior
2, that command still manages to wipe it, and then gdb restores the
old selected inferior, which is now a dangling pointer...

So the fix here is:

- Make make_cleanup_restore_current_thread store a pointer to the
  previously selected inferior directly, and use it directly instead
  of doing ptid look ups.

- Add a refcount to inferiors, very similar to thread_info's refcount,
  that is incremented/decremented by
  make_cleanup_restore_current_thread, and checked before deleting an
  inferior.  To avoid duplication, a new refcounted_object type is
  added, that both thread_info and inferior inherit from.

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

	* common/refcounted-object.h: New file.
	* gdbthread.h: Include "common/refcounted-object.h".
	(thread_info): Inherit from refcounted_object and add comments.
	(thread_info::incref, thread_info::decref)
	(thread_info::m_refcount): Delete.
	(thread_info::deletable): Use the refcounted_object::refcount()
	method.
	* inferior.c (current_inferior_): Add comment.
	(set_current_inferior): Increment/decrement refcounts.
	(prune_inferiors, remove_inferior_command): Skip inferiors marked
	not-deletable instead of comparing with the current inferior.
	(initialize_inferiors): Increment the initial inferior's refcount.
	* inferior.h (struct inferior): Forward declare.
	Include "common/refcounted-object.h".
	(current_inferior, set_current_inferior): Move declaration to
	before struct inferior's definition, and fix comment.
	(inferior): Inherit from refcounted_object.  Add comments.
	* thread.c (switch_to_thread_no_regs): Reference the thread's
	inferior pointer directly instead of doing a ptid lookup.
	(switch_to_no_thread): New function.
	(switch_to_thread(thread_info *)): New function, factored out
	from ...
	(switch_to_thread(ptid_t)): ... this.
	(restore_current_thread): Delete.
	(current_thread_cleanup): Remove 'inf_id' and 'was_removable'
	fields, and add 'inf' field.
	(do_restore_current_thread_cleanup): Check whether old->inf is
	alive instead of looking up an inferior by ptid.  Use
	switch_to_thread and switch_to_no_thread.
	(restore_current_thread_cleanup_dtor): Use old->inf directly
	instead of lookup up an inferior by id.  Decref the inferior.
	Don't restore 'removable'.
	(make_cleanup_restore_current_thread): Same the inferior pointer
	in old, instead of the inferior number.  Incref the inferior.
	Don't save/clear 'removable'.

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

	* gdb.threads/threadapply.exp (kill_and_remove_inferior): New
	procedure.
	(top level): Call it.
	* lib/gdb.exp (gdb_define_cmd): New procedure.
2017-04-19 13:12:23 +01:00
Pedro Alves 5fd69d0ab2 Improve coverage of the PR threads/13217 regression test
- Make sure we end up with no thread selected after the detach.

- Test both "thread apply all" and "thread apply $some_threads", for
  completeness.

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

	PR threads/13217
	* gdb.threads/threadapply.exp (thr_apply_detach): New procedure.
	(top level): Call it twice, with different thread sets.
2017-04-13 16:18:16 +01:00
Iain Buclaw b1b45502bd Add ChangeLog entries
ChangeLog entries were left unstaged in my previous commit on March 30th.
2017-04-13 10:39:13 +02:00
Pedro Alves 53375380e9 Teach GDB that wchar_t is a built-in type in C++ mode
GDB is currently not aware that wchar_t is a built-in type in C++
mode.  This is usually not a problem because the debug info describes
the type, so when you have a program loaded, you don't notice this.
However, if you try expressions involving wchar_t before a program is
loaded, gdb errors out:

 (gdb) p (wchar_t)-1
 No symbol table is loaded.  Use the "file" command.
 (gdb) p L"hello"
 No type named wchar_t.
 (gdb) ptype L"hello"
 No type named wchar_t.

This commit teaches gdb about the type.  After:

 (gdb) p (wchar_t)-1
 $1 = -1 L'\xffffffff'
 (gdb) p L"hello"
 $2 = L"hello"
 (gdb) ptype L"hello"
 type = wchar_t [6]

Unlike char16_t/char32_t, unfortunately, the underlying type of
wchar_t is implementation dependent, both size and signness.  So this
requires adding a couple new gdbarch hooks.

I grepped the GCC code base for WCHAR_TYPE and WCHAR_TYPE_SIZE, and it
seems to me that the majority of the ABIs have a 4-byte signed
wchar_t, so that's what I made the default for GDB too.  And then I
looked for which ports have a 16-bit and/or unsigned wchar_t, and made
GDB follow suit.

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

	PR gdb/21323
	* c-lang.c (cplus_primitive_types) <cplus_primitive_type_wchar_t>:
	New enum value.
	(cplus_language_arch_info): Register cplus_primitive_type_wchar_t.
	* gdbtypes.h (struct builtin_type) <builtin_wchar>: New field.
	* gdbtypes.c (gdbtypes_post_init): Create the "wchar_t" type.
	* gdbarch.sh (wchar_bit, wchar_signed): New per-arch values.
	* gdbarch.h, gdbarch.c: Regenerate.
	* aarch64-tdep.c (aarch64_gdbarch_init): Override
	gdbarch_wchar_bit and gdbarch_wchar_signed.
	* alpha-tdep.c (alpha_gdbarch_init): Likewise.
	* arm-tdep.c (arm_gdbarch_init): Likewise.
	* avr-tdep.c (avr_gdbarch_init): Likewise.
	* h8300-tdep.c (h8300_gdbarch_init): Likewise.
	* i386-nto-tdep.c (i386nto_init_abi): Likewise.
	* i386-tdep.c (i386_go32_init_abi): Likewise.
	* m32r-tdep.c (m32r_gdbarch_init): Likewise.
	* moxie-tdep.c (moxie_gdbarch_init): Likewise.
	* nds32-tdep.c (nds32_gdbarch_init): Likewise.
	* rs6000-aix-tdep.c (rs6000_aix_init_osabi): Likewise.
	* sh-tdep.c (sh_gdbarch_init): Likewise.
	* sparc-tdep.c (sparc32_gdbarch_init): Likewise.
	* sparc64-tdep.c (sparc64_init_abi): Likewise.
	* windows-tdep.c (windows_init_abi): Likewise.
	* xstormy16-tdep.c (xstormy16_gdbarch_init): Likewise.

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

	PR gdb/21323
	* gdb.cp/wide_char_types.c: Include <wchar.h>.
	(wchar): New global.
	* gdb.cp/wide_char_types.exp (wide_char_types_program)
	(do_test_wide_char, wide_char_types_no_program, top level): Add
	wchar_t testing.
2017-04-12 14:06:40 +01:00
Pedro Alves 53e710acd2 Fix PR c++/21323: GDB thinks char16_t and char32_t are signed in C++
While the C++ standard says that char16_t and char32_t are unsigned types:

 Types char16_t and char32_t denote distinct types with the same size,
 signedness, and alignment as uint_least16_t and uint_least32_t,
 respectively, in <cstdint>, called the underlying types.

... gdb treats them as signed currently:

 (gdb) p (char16_t)-1
 $1 = -1 u'\xffff'

There are actually two places in gdb that hardcode these types:

- gdbtypes.c:gdbtypes_post_init, when creating the built-in types,
  seemingly used by the "x /s" command (judging from commit 9a22f0d0).

- dwarf2read.c, when reading base types with DW_ATE_UTF encoding
  (which is what is used for these types, when compiling for C++11 and
  up).  Despite the comment, the type created does end up used.

Both places need fixing.  But since I couldn't tell why dwarf2read.c
needs to create a new type, I've made it use the per-arch built-in
types instead, so that the types are only created once per arch
instead of once per objfile.  That seems to work fine.

While writting the test, I noticed that the C++ language parser isn't
actually aware of these built-in types, so if you try to use them
without a program that uses them, you get:

 (gdb) set language c++
 (gdb) ptype char16_t
 No symbol table is loaded.  Use the "file" command.
 (gdb) ptype u"hello"
 No type named char16_t.
 (gdb) p u"hello"
 No type named char16_t.

That's fixed by simply adding a couple entries to C++'s built-in types
array in c-lang.c.  With that, we get the expected:

 (gdb) ptype char16_t
 type = char16_t
 (gdb) ptype u"hello"
 type = char16_t [6]
 (gdb) p u"hello"
 $1 = u"hello"

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

	PR c++/21323
	* c-lang.c (cplus_primitive_types) <cplus_primitive_type_char16_t,
	cplus_primitive_type_char32_t>: New enum values.
	(cplus_language_arch_info): Register cplus_primitive_type_char16_t
	and cplus_primitive_type_char32_t.
	* dwarf2read.c (read_base_type) <DW_ATE_UTF>: If bit size is 16 or
	32, use the archtecture's built-in type for char16_t and char32_t,
	respectively.  Otherwise, fallback to init_integer_type as before,
	but make the type unsigned, and issue a complaint.
	* gdbtypes.c (gdbtypes_post_init): Make char16_t and char32_t unsigned.

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

	PR c++/21323
	* gdb.cp/wide_char_types.c: New file.
	* gdb.cp/wide_char_types.exp: New file.
2017-04-12 14:00:49 +01:00
Sergio Durigan Junior 0ad9d8c734 PR 21352: Add testsuite for "tsave -r" command
This commit adds a test for the fix of PR 21352.

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

	PR gdb/21352
	* gdb.trace/tsv.exp: Add test for "tsave -r".
2017-04-05 12:43:52 -04:00
Yao Qi 55a9897675 Fix racy test in gdb.threads/thread-specific-bp.exp
I see the following test fail from time to time, due to the racy test
in gdb.threads/thread-specific-bp.exp.

continue -a^M
Continuing.^M
^M
Thread 1 "thread-specific" hit Breakpoint 4, end () at binutils-gdb/gdb/testsuite/gdb.threads/thread-specific-bp.c:29^M
29      }^M
(gdb) [Thread 0x40322460 (LWP 12950) exited]^M
Thread-specific breakpoint 3 deleted - thread 2 no longer in the thread list.^M
FAIL: gdb.threads/thread-specific-bp.exp: non-stop: continue to end (timeout)

This patch changes gdb_test to gdb_test_multiple to match prompt only
instead of both prompt and anchor.

gdb/testsuite:

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

	* gdb.threads/thread-specific-bp.exp (check_thread_specific_breakpoint):
	Use gdb_test_multiple, and don't match anchor.
2017-04-05 14:46:13 +01:00
Iain Buclaw 662659a1a5 Fix classification of `module.type' in D lexer.
The two-tier lexer in gdb/d-exp.y, which resolves fully qualified names
missed a case where `module.type' was not being classified as one token.
And so when the grammar takes over, it matched the remaining tokens
against the rule `TypeExp . IdentifierExp', where we were expecting to
instead match cast expression `( TypeExp ) UnaryExpression'.

Adding a case for TYPE_CODE_MODULE in type_aggregate_p means that
classify_inner_name will get a chance to lookup the symbol.

This was noticed when using `watch -l', and got the rather confusing
response:

    A syntax error in expression, near `) 0x0add4e55'.

So it's been included in the testsuite, along with another test that
does effectively the same expression, but explicitly.

gdb/ChangeLog:

	* d-exp.y (type_aggregate_p): Treat TYPE_CODE_MODULE as being
	aggregate-like.

gdb/testsuite/ChangeLog:

	* gdb.dlang/watch-loc.c: New file.
	* gdb.dlang/watch-loc.exp: New file.
2017-03-30 10:54:54 +02:00
Jan Kratochvil ec13808ef0 Fix warning: Invalid entry in .debug_gdb_scripts section
$ gdb rustc
Reading symbols from rustc...Reading symbols from /usr/lib/debug/usr/bin/rustc.debug...done.
done.
warning: Invalid entry in .debug_gdb_scripts section

/usr/bin/rustc
Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [15] .debug_gdb_scripts PROGBITS        00000000000008ed 0008ed 000022 00 AMS  0   0  1

/usr/lib/debug/usr/bin/rustc.debug
Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [15] .debug_gdb_scripts NOBITS          00000000000008ed 000280 000022 00 AMS  0   0  1

There remains questionable whether bfd_get_section_by_name() should not return
an error for !SEC_LOAD but I haven't investigated that.

gdb/ChangeLog
2017-03-29  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* auto-load.c (auto_load_section_scripts): Check SEC_HAS_CONTENTS.

gdb/testsuite/ChangeLog
2017-03-29  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.python/py-section-script.exp (sepdebug): New testcases.
2017-03-29 21:53:43 +02:00
Anton Kolesov fe5f7374be arc: Add prologue analysis
Add a prologue analysis that recognizes all instructions that may happen in
compiler-generated prologue, including various stores, core register moves,
subtraction and ENTER_S instruction that does a lot of prologue actions through
microcode.

Testcases cover various prologue scenarios, including instructions that are
spread across multiple 16-bit encodings (for example there are 7 encodings of
store instruction).

gdb/ChangeLog:

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

	* arc-tdep.c (arc_frame_cache): Add support for prologue analysis.
	(arc_skip_prologue): Likewise.
	(arc_make_frame_cache): Likewise.
	(arc_pv_get_operand): New function.
	(arc_is_in_prologue): Likewise.
	(arc_analyze_prologue): Likewise.
	(arc_print_frame_cache): Likewise.
	(MAX_PROLOGUE_LENGTH): New constant.

gdb/doc/ChangeLog:

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

	* gdb.texinfo (Synopsys ARC): Document "set debug arc 2".

gdb/testsuite/ChangeLog:

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

	* gdb.arch/arc-analyze-prologue.S: New file.
	* gdb.arch/arc-analyze-prologue.exp: Likewise.
2017-03-28 21:38:32 +03:00
Anton Kolesov eea787570f arc: Add disassembler helper
Add disassembler helper for GDB, that uses opcodes structure arc_instruction
and adds convenience functions to handle instruction operands.  This interface
solves at least those problems with arc_instruction:

  * Some instructions, like "push_s", have implicit operands which are not
    directly present in arc_instruction.
  * Operands of particular meaning, like branch/jump targets, have various
    locations and meaning depending on type of branch/target.
  * Access to operand value is abstracted into a separate function, so callee
    code shouldn't bother if operand value is an immediate value or in a
    register.

Testcases included in this commit are fairly limited - they test exclusively
branch instructions, something that will be used in software single stepping.
Most of the other parts of this disassembler helper are tested during prologue
analysis testing.

gdb/ChangeLog:

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

	* configure.tgt: Add arc-insn.o.
	* arc-tdep.c (arc_delayed_print_insn): Make non-static.
	(dump_arc_instruction_command): New function.
	(arc_fprintf_disasm): Likewise.
	(arc_disassemble_info): Likewise.
	(arc_insn_get_operand_value): Likewise.
	(arc_insn_get_operand_value_signed): Likewise.
	(arc_insn_get_memory_base_reg): Likewise.
	(arc_insn_get_memory_offset): Likewise.
	(arc_insn_get_branch_target): Likewise.
	(arc_insn_dump): Likewise.
	(arc_insn_get_linear_next_pc): Likewise.
	* arc-tdep.h (arc_delayed_print_insn): Add function declaration.
	(arc_disassemble_info): Likewise.
	(arc_insn_get_branch_target): Likewise.
	(arc_insn_get_linear_next_pc): Likewise.
	* NEWS: Mention new "maint print arc arc-instruction".

gdb/doc/ChangeLog:

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

	* gdb.texinfo (Synopsys ARC): Add "maint print arc arc-instruction".

gdb/testsuite/ChangeLog:

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

	* gdb.arch/arc-decode-insn.S: New file.
	* gdb.arch/arc-decode-insn.exp: Likewise.
2017-03-28 21:36:35 +03:00
Ivo Raisr 5badf10a18 Decode properly flags of %ccr register on sparc64.
While at it, decode also properly one-bit flags for %fsr (accrued and
current exception flags were mixed up).

ChangeLog entry:
2017-03-21  Ivo Raisr  <ivo.raisr@oracle.com>

    	PR tdep/20928
    	* gdb/sparc-tdep.h (gdbarch_tdep) <sparc64_ccr_type>: New field.
    	* gdb/sparc64-tdep.c (sparc64_ccr_type): New function.
    	(sparc64_fsr_type): Fix %fsr decoding.

ChangeLog entry for testsuite:
2017-03-21  Ivo Raisr  <ivo.raisr@oracle.com>

    	PR tdep/20928
    	* gdb.arch/sparc64-regs.exp: New file.
    	* gdb.arch/sparc64-regs.S: Likewise.
2017-03-21 04:39:33 -07:00
Tim Wiederhake cee59b3fea Fix break on Python 2
This changes the return type of "gdb.BtraceInstruction.data ()" from
"memoryview" to "buffer" on Python 2.7 and below, similar to what
"gdb.Inferior.read_memory ()" does.
2017-03-21 08:19:59 +01:00
Artemiy Volkov c0f55cc689 Add rvalue reference tests and docs
This patch adds tests for the initial rvalue reference support patchset.  All
of the new tests are practically mirrored regular references tests and, except
for the demangler ones, are introduced in new files, which are set to be
compiled with -std=gnu++11.  Tested are printing of rvalue reference types and
values, rvalue reference parameters in function overloading, demangling of
function names containing rvalue reference parameters, casts to rvalue
reference types, application of the sizeof operator to rvalue reference types
and values, and support for rvalue references within the gdb python module.

gdb/ChnageLog

	PR gdb/14441
	* NEWS: Mention support for rvalue references in GDB and python.
	* doc/gdb.texinfo (C Plus Plus Expressions): Mention that GDB
	supports both lvalue and rvalue references.

gdb/testsuite/ChangeLog

	PR gdb/14441
	* gdb.cp/demangle.exp: Add rvalue reference tests.
	* gdb.cp/rvalue-ref-casts.cc: New file.
	* gdb.cp/rvalue-ref-casts.exp: New file.
	* gdb.cp/rvalue-ref-overload.cc: New file.
	* gdb.cp/rvalue-ref-overload.exp: New file.
	* gdb.cp/rvalue-ref-params.cc: New file.
	* gdb.cp/rvalue-ref-params.exp: New file.
	* gdb.cp/rvalue-ref-sizeof.cc: New file.
	* gdb.cp/rvalue-ref-sizeof.exp: New file.
	* gdb.cp/rvalue-ref-types.cc: New file.
	* gdb.cp/rvalue-ref-types.exp: New file.
	* gdb.python/py-rvalue-ref-value-cc.cc: New file.
	* gdb.python/py-rvalue-ref-value-cc.exp: New file.
2017-03-20 13:47:59 -07:00
Marc-Andre Laperle 51457a0578 Add -file-list-shared-libraries MI command
This change adds the MI equivalent for the "info sharedlibrary"
command. The command was already partially documented but ignored as
it was not implemented. The new MI command works similarly to the CLI
command, taking an optional regular expression as an argument and
outputting the library information.

I included a test for the new command in mi-solib.exp.

gdb/doc/ChangeLog:

	* gdb.texinfo (gdb/mi Symbol Query Commands): Document new MI
	command file-list-shared-libraries
	(GDB/MI Async Records): Update documentation of library-loaded with new
	field.

gdb/ChangeLog:

	* NEWS: Add an entry about new '-file-list-shared-libraries' command.
	* mi/mi-cmd-file.c (mi_cmd_file_list_shared_libraries):
	New function definition.
	* mi/mi-cmds.c (mi_cmds): Add -file-list-shared-libraries command.
	* mi/mi-cmds.h (mi_cmd_file_list_shared_libraries):
	New function declaration.
	* mi/mi-interp.c (mi_output_solib_attribs): New Function.
	* mi/mi-interp.h: New file.
	* solib.c (info_sharedlibrary_command): Replace for loop with
	ALL_SO_LIBS macro
	* solib.h (update_solib_list): New function declaration.
	(so_list_head): Move macro.
	* solist.h (ALL_SO_LIBS): New macro.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-solib.exp (test_file_list_shared_libraries):
	New procedure.

Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
2017-03-20 14:57:51 -04:00
Marc-Andre Laperle 5b291c0496 Add a better diagnostic message in mi_gdb_test
When using mi_gdb_test, if it fails because of the presence of
unexpected output, the error message is only the message passed as
the argument with no indication that there was an unexpected output.
This change adds an additional text to the failure message to
indicate that there was an unexpected output.

gdb/testsuite/ChangeLog:

	* lib/mi-support.exp (mi_gdb_test): Add additional message
	for unexpected output.

Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
2017-03-20 14:57:45 -04:00
Andreas Arnez 59a561480d Fix spurious FAILs with examine-backward.exp
The test case examine-backward.exp issues the command "x/-s" after the end
of the first string in TestStrings, but without making sure that this
string is preceded by a string terminator.  Thus GDB may spuriously print
some random characters from before that string, and then the test fails.

This patch assures that TestStrings is preceded by a string terminator.

gdb/testsuite/ChangeLog:

	* gdb.base/examine-backward.c (Barrier): New character array
	constant, to ensure that TestStrings is preceded by a string
	terminator.
2017-03-20 18:55:39 +01:00