Commit Graph

42431 Commits

Author SHA1 Message Date
Andrew Burgess 3714a195e0 gdb/testsuite: Make test names unique in gdb.python/py-prettyprint.exp
This makes the test names unique in gdb.python/py-prettyprint.exp, it
also switches to use gdb_breakpoint and gdb_continue_to_breakpoint
more so that we avoid test names with the source line number in - this
is bad if the test source ever changes as the test names will then
change.

One final change is to switch from using gdb_py_test_silent_cmd to use
gdb_test_no_output, the former should be used for running python
commands and can catch any thrown exception.  However, in this case
the command being run is not a python command, its just a normal GDB
CLI command that produces no output, so lets use the appropriate
wrapper function.

gdb/testsuite/ChangeLog:

	* gdb.python/py-prettyprint.exp: Use gdb_breakpoint and
	gdb_continue_to_breakpoint more throughout this test.
	(run_lang_tests) Supply unique test names, and use
	gdb_test_no_output.
2019-03-26 18:23:50 +00:00
Andrew Burgess 18c77628b1 gdb: Avoid trailing whitespace when pretty printing
While writing a new test for 'set print pretty on' I spotted that GDB
will sometimes add a trailing whitespace character when pretty
printing.  This commit removes the trailing whitespace and updates the
expected results in one tests where this was an issue.

I've added an extra test for 'set print pretty on' as it doesn't seem
to have much testing.

gdb/ChangeLog:

	* cp-valprint.c (cp_print_value_fields): Don't print trailing
	whitespace when pretty printing is on.

gdb/testsuite/ChangeLog:

	* gdb.base/finish-pretty.exp: Update expected results.
	* gdb.base/pretty-print.c: New file.
	* gdb.base/pretty-print.exp: New file.
2019-03-26 18:23:49 +00:00
Alan Hayward 53c973f200 Fix Powerpc build
gdb/ChangeLog:

        * ppc-linux-nat.c: Add include.
2019-03-26 17:18:27 +00:00
Alan Hayward d851aa7170 Add AArch64 Pointer Authentication to the NEWS file
gdb/ChangeLog:

        * NEWS: Mention AArch64 Pointer Authentication.
2019-03-26 17:09:00 +00:00
Alan Hayward 974c89e088 gdbserver: Add linux_get_hwcap
In gdbserver, Tidy up calls to read HWCAP (and HWCAP2) by adding common
functions, removing the Arm, AArch64, PPC and S390 specific versions.

No functionality differences.

gdb/gdbserver/ChangeLog:

	* linux-aarch64-low.c (aarch64_get_hwcap): Remove function.
	(aarch64_arch_setup): Call linux_get_hwcap.
	* linux-arm-low.c (arm_get_hwcap): Remove function.
	(arm_read_description): Call linux_get_hwcap.
	* linux-low.c (linux_get_auxv): New function.
	(linux_get_hwcap): Likewise.
	(linux_get_hwcap2): Likewise.
	* linux-low.h (linux_get_hwcap): New declaration.
	(linux_get_hwcap2): Likewise.
	* linux-ppc-low.c (ppc_get_auxv): Remove function.
	(ppc_arch_setup): Call linux_get_hwcap.
	* linux-s390-low.c (s390_get_hwcap): Remove function.
	(s390_arch_setup): Call linux_get_hwcap.
2019-03-26 16:27:43 +00:00
Alan Hayward 2fe7bab775 Fix Arm build
Add missing include.

2019-03-26  Alan Hayward  <alan.hayward@arm.com>

        * arm-linux-nat.c: Add include.
2019-03-26 11:43:40 +00:00
Simon Marchi 068ef30e9e Fix use-after-free in source_cache::get_source_lines
Commit ab42892fb7 ("Fix vertical scrolling of TUI source window")
introduced a use-after-free in source_cache::get_source_lines.

At the beginning of the method, we get the fullname of the symtab:

    const char *fullname = symtab_to_fullname (s);

fullname points to the string owned by the symtab (s.fullname).  When we
later do

    scoped_fd desc = open_source_file (s);

s.fullname gets reallocated (even though the string contents may not
change).  The fullname local variable now points to freed memory.

To avoid it, refresh the value of fullname after calling
open_source_file.

Here is the ASan report:

$ ./gdb -nx --data-directory=data-directory ./a.out
(gdb) start
Temporary breakpoint 1 at 0x1130: file test.cpp, line 12.
Starting program: /home/simark/build/binutils-gdb/gdb/a.out

Temporary breakpoint 1, main () at test.cpp:12
=================================================================
==26068==ERROR: AddressSanitizer: heap-use-after-free on address 0x6210003d4100 at pc 0x7fed89a34681 bp 0x7ffd8d185d80 sp 0x7ffd8d185528
READ of size 2 at 0x6210003d4100 thread T0
    #0 0x7fed89a34680 in __interceptor_strlen /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:301
    #1 0x55b6edf6c2f7 in std::char_traits<char>::length(char const*) /usr/include/c++/8.2.1/bits/char_traits.h:320
    #2 0x55b6edf6c9b2 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) /usr/include/c++/8.2.1/bits/basic_string.h:516
    #3 0x55b6ef09121b in source_cache::get_source_lines(symtab*, int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) /home/simark/src/binutils-gdb/gdb/source-cache.c:214
    #4 0x55b6ef0a15cb in print_source_lines_base /home/simark/src/binutils-gdb/gdb/source.c:1340
    #5 0x55b6ef0a2045 in print_source_lines(symtab*, int, int, enum_flags<print_source_lines_flag>) /home/simark/src/binutils-gdb/gdb/source.c:1415
    #6 0x55b6ef112c87 in print_frame_info(frame_info*, int, print_what, int, int) /home/simark/src/binutils-gdb/gdb/stack.c:914
    #7 0x55b6ef10e90d in print_stack_frame(frame_info*, int, print_what, int) /home/simark/src/binutils-gdb/gdb/stack.c:180
    #8 0x55b6ee9592f8 in print_stop_location /home/simark/src/binutils-gdb/gdb/infrun.c:7853
    #9 0x55b6ee95948f in print_stop_event(ui_out*) /home/simark/src/binutils-gdb/gdb/infrun.c:7870
    #10 0x55b6ef34b962 in tui_on_normal_stop /home/simark/src/binutils-gdb/gdb/tui/tui-interp.c:98
    #11 0x55b6ee01a14d in std::_Function_handler<void (bpstats*, int), void (*)(bpstats*, int)>::_M_invoke(std::_Any_data const&, bpstats*&&, int&&) /usr/include/c++/8.2.1/bits/std_function.h:297
    #12 0x55b6ee965415 in std::function<void (bpstats*, int)>::operator()(bpstats*, int) const /usr/include/c++/8.2.1/bits/std_function.h:687
    #13 0x55b6ee962f1b in gdb::observers::observable<bpstats*, int>::notify(bpstats*, int) const /home/simark/src/binutils-gdb/gdb/common/observable.h:106
    #14 0x55b6ee95a6e7 in normal_stop() /home/simark/src/binutils-gdb/gdb/infrun.c:8142
    #15 0x55b6ee93f236 in fetch_inferior_event(void*) /home/simark/src/binutils-gdb/gdb/infrun.c:3782
    #16 0x55b6ee8f2641 in inferior_event_handler(inferior_event_type, void*) /home/simark/src/binutils-gdb/gdb/inf-loop.c:43
    #17 0x55b6eea2a1f0 in handle_target_event /home/simark/src/binutils-gdb/gdb/linux-nat.c:4358
    #18 0x55b6ee7045f1 in handle_file_event /home/simark/src/binutils-gdb/gdb/event-loop.c:733
    #19 0x55b6ee704e89 in gdb_wait_for_event /home/simark/src/binutils-gdb/gdb/event-loop.c:859
    #20 0x55b6ee7027b5 in gdb_do_one_event() /home/simark/src/binutils-gdb/gdb/event-loop.c:322
    #21 0x55b6ee702907 in start_event_loop() /home/simark/src/binutils-gdb/gdb/event-loop.c:371
    #22 0x55b6eeadfc16 in captured_command_loop /home/simark/src/binutils-gdb/gdb/main.c:331
    #23 0x55b6eeae2ef9 in captured_main /home/simark/src/binutils-gdb/gdb/main.c:1174
    #24 0x55b6eeae30c2 in gdb_main(captured_main_args*) /home/simark/src/binutils-gdb/gdb/main.c:1190
    #25 0x55b6edf4fa89 in main /home/simark/src/binutils-gdb/gdb/gdb.c:32
    #26 0x7fed88ad8222 in __libc_start_main (/usr/lib/libc.so.6+0x24222)
    #27 0x55b6edf4f86d in _start (/home/simark/build/binutils-gdb/gdb/gdb+0x197186d)

0x6210003d4100 is located 0 bytes inside of 4096-byte region [0x6210003d4100,0x6210003d5100)
freed by thread T0 here:
    #0 0x7fed89a8ac19 in __interceptor_free /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:66
    #1 0x55b6edfe12df in xfree<char> /home/simark/src/binutils-gdb/gdb/common/common-utils.h:60
    #2 0x55b6edfea675 in gdb::xfree_deleter<char>::operator()(char*) const /home/simark/src/binutils-gdb/gdb/common/gdb_unique_ptr.h:34
    #3 0x55b6edfe532c in std::unique_ptr<char, gdb::xfree_deleter<char> >::reset(char*) /usr/include/c++/8.2.1/bits/unique_ptr.h:382
    #4 0x55b6edfe7329 in std::unique_ptr<char, gdb::xfree_deleter<char> >::operator=(std::unique_ptr<char, gdb::xfree_deleter<char> >&&) /usr/include/c++/8.2.1/bits/unique_ptr.h:289
    #5 0x55b6ef09ec2b in find_and_open_source(char const*, char const*, std::unique_ptr<char, gdb::xfree_deleter<char> >*) /home/simark/src/binutils-gdb/gdb/source.c:990
    #6 0x55b6ef09f56a in open_source_file(symtab*) /home/simark/src/binutils-gdb/gdb/source.c:1069
    #7 0x55b6ef090f78 in source_cache::get_source_lines(symtab*, int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) /home/simark/src/binutils-gdb/gdb/source-cache.c:205
    #8 0x55b6ef0a15cb in print_source_lines_base /home/simark/src/binutils-gdb/gdb/source.c:1340
    #9 0x55b6ef0a2045 in print_source_lines(symtab*, int, int, enum_flags<print_source_lines_flag>) /home/simark/src/binutils-gdb/gdb/source.c:1415
    #10 0x55b6ef112c87 in print_frame_info(frame_info*, int, print_what, int, int) /home/simark/src/binutils-gdb/gdb/stack.c:914
    #11 0x55b6ef10e90d in print_stack_frame(frame_info*, int, print_what, int) /home/simark/src/binutils-gdb/gdb/stack.c:180
    #12 0x55b6ee9592f8 in print_stop_location /home/simark/src/binutils-gdb/gdb/infrun.c:7853
    #13 0x55b6ee95948f in print_stop_event(ui_out*) /home/simark/src/binutils-gdb/gdb/infrun.c:7870
    #14 0x55b6ef34b962 in tui_on_normal_stop /home/simark/src/binutils-gdb/gdb/tui/tui-interp.c:98
    #15 0x55b6ee01a14d in std::_Function_handler<void (bpstats*, int), void (*)(bpstats*, int)>::_M_invoke(std::_Any_data const&, bpstats*&&, int&&) /usr/include/c++/8.2.1/bits/std_function.h:297
    #16 0x55b6ee965415 in std::function<void (bpstats*, int)>::operator()(bpstats*, int) const /usr/include/c++/8.2.1/bits/std_function.h:687
    #17 0x55b6ee962f1b in gdb::observers::observable<bpstats*, int>::notify(bpstats*, int) const /home/simark/src/binutils-gdb/gdb/common/observable.h:106
    #18 0x55b6ee95a6e7 in normal_stop() /home/simark/src/binutils-gdb/gdb/infrun.c:8142
    #19 0x55b6ee93f236 in fetch_inferior_event(void*) /home/simark/src/binutils-gdb/gdb/infrun.c:3782
    #20 0x55b6ee8f2641 in inferior_event_handler(inferior_event_type, void*) /home/simark/src/binutils-gdb/gdb/inf-loop.c:43
    #21 0x55b6eea2a1f0 in handle_target_event /home/simark/src/binutils-gdb/gdb/linux-nat.c:4358
    #22 0x55b6ee7045f1 in handle_file_event /home/simark/src/binutils-gdb/gdb/event-loop.c:733
    #23 0x55b6ee704e89 in gdb_wait_for_event /home/simark/src/binutils-gdb/gdb/event-loop.c:859
    #24 0x55b6ee7027b5 in gdb_do_one_event() /home/simark/src/binutils-gdb/gdb/event-loop.c:322
    #25 0x55b6ee702907 in start_event_loop() /home/simark/src/binutils-gdb/gdb/event-loop.c:371
    #26 0x55b6eeadfc16 in captured_command_loop /home/simark/src/binutils-gdb/gdb/main.c:331
    #27 0x55b6eeae2ef9 in captured_main /home/simark/src/binutils-gdb/gdb/main.c:1174
    #28 0x55b6eeae30c2 in gdb_main(captured_main_args*) /home/simark/src/binutils-gdb/gdb/main.c:1190
    #29 0x55b6edf4fa89 in main /home/simark/src/binutils-gdb/gdb/gdb.c:32

previously allocated by thread T0 here:
    #0 0x7fed89a8b019 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:86
    #1 0x7fed88af983f in realpath@@GLIBC_2.3 (/usr/lib/libc.so.6+0x4583f)
    #2 0x7fed899dbbbc in __interceptor_canonicalize_file_name /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:3297
    #3 0x55b6ee376a03 in gdb_realpath(char const*) /home/simark/src/binutils-gdb/gdb/common/pathstuff.c:72
    #4 0x55b6ef09ec12 in find_and_open_source(char const*, char const*, std::unique_ptr<char, gdb::xfree_deleter<char> >*) /home/simark/src/binutils-gdb/gdb/source.c:990
    #5 0x55b6ef09f56a in open_source_file(symtab*) /home/simark/src/binutils-gdb/gdb/source.c:1069
    #6 0x55b6ef0a0f12 in print_source_lines_base /home/simark/src/binutils-gdb/gdb/source.c:1270
    #7 0x55b6ef0a2045 in print_source_lines(symtab*, int, int, enum_flags<print_source_lines_flag>) /home/simark/src/binutils-gdb/gdb/source.c:1415
    #8 0x55b6ef112c87 in print_frame_info(frame_info*, int, print_what, int, int) /home/simark/src/binutils-gdb/gdb/stack.c:914
    #9 0x55b6ef10e90d in print_stack_frame(frame_info*, int, print_what, int) /home/simark/src/binutils-gdb/gdb/stack.c:180
    #10 0x55b6ee9592f8 in print_stop_location /home/simark/src/binutils-gdb/gdb/infrun.c:7853
    #11 0x55b6ee95948f in print_stop_event(ui_out*) /home/simark/src/binutils-gdb/gdb/infrun.c:7870
    #12 0x55b6ef34b962 in tui_on_normal_stop /home/simark/src/binutils-gdb/gdb/tui/tui-interp.c:98
    #13 0x55b6ee01a14d in std::_Function_handler<void (bpstats*, int), void (*)(bpstats*, int)>::_M_invoke(std::_Any_data const&, bpstats*&&, int&&) /usr/include/c++/8.2.1/bits/std_function.h:297
    #14 0x55b6ee965415 in std::function<void (bpstats*, int)>::operator()(bpstats*, int) const /usr/include/c++/8.2.1/bits/std_function.h:687
    #15 0x55b6ee962f1b in gdb::observers::observable<bpstats*, int>::notify(bpstats*, int) const /home/simark/src/binutils-gdb/gdb/common/observable.h:106
    #16 0x55b6ee95a6e7 in normal_stop() /home/simark/src/binutils-gdb/gdb/infrun.c:8142
    #17 0x55b6ee93f236 in fetch_inferior_event(void*) /home/simark/src/binutils-gdb/gdb/infrun.c:3782
    #18 0x55b6ee8f2641 in inferior_event_handler(inferior_event_type, void*) /home/simark/src/binutils-gdb/gdb/inf-loop.c:43
    #19 0x55b6eea2a1f0 in handle_target_event /home/simark/src/binutils-gdb/gdb/linux-nat.c:4358
    #20 0x55b6ee7045f1 in handle_file_event /home/simark/src/binutils-gdb/gdb/event-loop.c:733
    #21 0x55b6ee704e89 in gdb_wait_for_event /home/simark/src/binutils-gdb/gdb/event-loop.c:859
    #22 0x55b6ee7027b5 in gdb_do_one_event() /home/simark/src/binutils-gdb/gdb/event-loop.c:322
    #23 0x55b6ee702907 in start_event_loop() /home/simark/src/binutils-gdb/gdb/event-loop.c:371
    #24 0x55b6eeadfc16 in captured_command_loop /home/simark/src/binutils-gdb/gdb/main.c:331
    #25 0x55b6eeae2ef9 in captured_main /home/simark/src/binutils-gdb/gdb/main.c:1174
    #26 0x55b6eeae30c2 in gdb_main(captured_main_args*) /home/simark/src/binutils-gdb/gdb/main.c:1190
    #27 0x55b6edf4fa89 in main /home/simark/src/binutils-gdb/gdb/gdb.c:32
    #28 0x7fed88ad8222 in __libc_start_main (/usr/lib/libc.so.6+0x24222)

gdb/ChangeLog:

	* source-cache.c (source_cache::get_source_lines): Re-read
	fullname after calling open_source_file.
2019-03-25 20:32:41 -04:00
John Baldwin 81a24d04df Note support for TLS variables on FreeBSD.
gdb/ChangeLog:

	* NEWS: Mention TLS support for FreeBSD.
2019-03-25 13:23:42 -07:00
Tom Tromey 79e7ae11c7 Clean up some comments in minsyms.c
Philippe pointed out that some comments in minsyms.c still referred to
obstack allocation.  This patch fixes these up.

In most cases here, my view is that the comments were more misleading
than helpful.  So, I've generally removed text.

gdb/ChangeLog
2019-03-25  Tom Tromey  <tromey@adacore.com>

	* minsyms.c (BUNCH_SIZE): Update comment.
	(~minimal_symbol_reader): Remove old comment.
	(compact_minimal_symbols): Update comment.
	(minimal_symbol_reader::install): Remove old comment.  Update
	other comments.
2019-03-25 13:45:57 -06:00
Alan Hayward d45963c2b2 Fix s390 build
Add missing include.

2019-03-25  Alan Hayward  <alan.hayward@arm.com>

        * s390-linux-nat.c: Add include.
2019-03-25 17:08:14 +00:00
Alan Hayward 0f83012ea0 Add linux_get_hwcap
Tidy up calls to read HWCAP (and HWCAP2) by adding common functions,
removing the PPC and AArch64 specific versions.

The only function difference is in aarch64_linux_core_read_description - if
the hwcap read fails it now return a valid description instead of nullptr.

gdb/ChangeLog:

2019-03-25  Alan Hayward  <alan.hayward@arm.com>

	* aarch64-linux-nat.c (aarch64_linux_nat_target::read_description):
	Call linux_get_hwcap.
	* aarch64-linux-tdep.c (aarch64_linux_core_read_description):
	Likewise.
	(aarch64_linux_get_hwcap): Remove function.
	* aarch64-linux-tdep.h (aarch64_linux_get_hwcap): Remove
	declaration.
	* arm-linux-nat.c (arm_linux_nat_target::read_description):Call
	linux_get_hwcap.
	* arm-linux-tdep.c (arm_linux_core_read_description): Likewise.
	* linux-tdep.c (linux_get_hwcap): Add function.
	(linux_get_hwcap2): Likewise.
	* linux-tdep.h (linux_get_hwcap): Add declaration.
	(linux_get_hwcap2): Likewise.
	* ppc-linux-nat.c (ppc_linux_get_hwcap): Remove function.
	(ppc_linux_get_hwcap2): Likewise.
	(ppc_linux_nat_target::region_ok_for_hw_watchpoint): Call
	linux_get_hwcap.
	(ppc_linux_nat_target::insert_watchpoint): Likewise.
	(ppc_linux_nat_target::watchpoint_addr_within_range): Likewise.
	(ppc_linux_nat_target::read_description): Likewise.
	* ppc-linux-tdep.c (ppc_linux_core_read_description): Likewise.
	* s390-linux-nat.c: Likewise.
	* s390-linux-tdep.c (s390_core_read_description): Likewise.
2019-03-25 16:50:38 +00:00
Pedro Alves 9a93502fa8 Fix testsuite hangs when gdb_test_multiple body errors out
This commit fixes a regression in the testsuite itself, triggered by
errors being raised from within gdb_test_multiple, originally reported
by Pedro Franco de Carvalho's at
<https://sourceware.org/ml/gdb-patches/2019-03/msg00160.html>.  Parts
of the commit message are based on his report.

This started happening due to a commit that was introduced recently,
and it can cause the testsuite to hang.

The commit that triggers this is:

 fe1a5cad30
 [gdb/testsuite] Log wait status on process no longer exists error

That commit introduces a new "eof" block in gdb_test_multiple.  That
is not incorrect itself, but dejagnu's remote_expect is picking that
block as the "default" action when an error is raised from within the
commands inside a call to gdb_test_multiple:

  # remote_expect works basically the same as standard expect, but it
  # also takes care of getting the file descriptor from the specified
  # host and also calling the timeout/eof/default section if there is an
  # error on the expect call.
  #
  proc remote_expect { board timeout args } {

I find that "feature" surprising, and I don't really know why it
exists, but this means that the eof section that remote_expect picks
as the error block can be executed even when there was no actual eof
and the GDB process is still running, so the wait introduced in the
commit that tries to get the exit status of GDB hangs forever, while
GDB itself waits for input.

This only happens when there are internal testsuite errors (not
testcase failures).  This can be reproduced easily with a testcase
such as:

  gdb_start
  gdb_test_multiple "show version" "show version" {
    -re ".*" {
       error "forced error"
    }
  }

I think that working around this in GDB is useful so that the
testsuite doesn't hang in these cases.

Adding an empty "default" block at the end of the expect body in
gdb_test_multiple doesn't work, because dejagnu gives preference to
"eof" blocks:

	    if { $x eq "eof" } {
		set save_next 1
	    } elseif { $x eq "default" || $x eq "timeout" } {
		if { $error_sect eq "" } {
		    set save_next 1
		}
	    }

And we do have "eof" blocks.  So we need to make sure that the last
"eof" block is safe to use as the default error block.  It's also
pedantically incorrect to print

 "ERROR: Process no longer exists"

which is what we'd get if the last eof block we have was selected
(more below on this).

So this commit solves this by appending an "eof" with an empty
spawn_id list, so that it won't ever match.

Now, why is the first "eof" block selected today as the error block,
instead of the last one?

The reason is that remote_expect, while parsing the body to select the
default block to execute after an error, is affected by the comments
in the body (since they are also parsed).

If this comment in gdb_test_multiple

 # patterns below apply to any spawn id specified.

is changed to

 # The patterns below apply to any spawn id specified.

then the second eof block is selected and there is no hang.

Any comment at that same place with an even number of tokens also
works.

This is IMO a coincidence caused by how comments work in TCL.
Comments should only appear in places where a command can appear.  And
here, remote_expect is parsing a list of options, not commands, so
it's not unreasonable to not parse comments, similarly to how this:

  set a_list {
     an_element
     # another_element
  }

results in a list with three elements, not one element.

The fact that comments with an even number of tokens work is just a
coincidence of how remote_expect's little state machine is
implemented.

I thought we could solve this by stripping out comment lines in
gdb_expect, but I didn't find an easy way to do that.  Particularly, a
couple naive approaches I tried run into complications.  For example,
we have gdb_test calls with regular expressions that include sequences
like "\r\n#", and by the time we get to gdb_expect, the \r\n have
already been expanded to a real newline, so just splitting the whole
body at newline boundaries, looking for lines that start with #
results in incorrectly stripping out half of the gdb_text regexp.  I
think it's better (at least in this commit), to move the comments out
of the list, because it's much simpler and risk free.

gdb/testsuite/ChangeLog:
2019-03-25  Pedro Alves  <palves@redhat.com>

	* lib/gdb.exp (gdb_test_multiple): Split appends to $code and
	move comments outside list.  Append '-i "" eof' section.
2019-03-25 13:26:23 +00:00
Tom Tromey 6640a367bf Remove null_block_symbol
This removes null_block_symbol.  It seemed simpler to me to change
initializations and returns to use value initialization rather than
null_block_symbol.  This also fixes up a few spots where
initialization was done piecemeal.

gdb/ChangeLog
2019-03-24  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (standard_lookup): Simplify initialization.
	(ada_lookup_symbol_nonlocal): Simplify return.
	* solib-spu.c (spu_lookup_lib_symbol): Simplify return.
	* solib-darwin.c (darwin_lookup_lib_symbol): Simplify return.
	* solib-svr4.c (elf_lookup_lib_symbol): Simplify return.
	* rust-lang.c (rust_lookup_symbol_nonlocal): Simplify
	initialization.
	* solib.c (solib_global_lookup): Simplify.
	* symtab.c (null_block_symbol): Remove.
	(symbol_cache_lookup): Simplify returns.
	(lookup_language_this): Simplify returns.
	(lookup_symbol_aux): Simplify return.
	(lookup_local_symbol): Simplify returns.
	(lookup_global_symbol_from_objfile): Simplify return.
	(lookup_symbol_in_objfile_symtabs)
	(lookup_symbol_in_objfile_from_linkage_name): Simplify return.
	(lookup_symbol_via_quick_fns, lookup_symbol_in_static_block)
	(lookup_static_symbol, lookup_global_symbol): Simplify return.
	* cp-namespace.c (cp_lookup_bare_symbol)
	(cp_search_static_and_baseclasses, cp_lookup_symbol_via_imports)
	(cp_lookup_symbol_via_all_imports, cp_lookup_nested_symbol_1)
	(cp_lookup_nested_symbol): Don't use null_block_symbol.
	(cp_lookup_symbol_via_imports): Simplify initialization.
	(find_symbol_in_baseclass): Likewise.
	* symtab.h (null_block_symbol): Remove.
	* d-namespace.c (d_lookup_symbol): Don't use null_block_symbol.
	(d_lookup_nested_symbol, d_lookup_symbol_imports)
	(d_lookup_symbol_module): Likewise.
	(find_symbol_in_baseclass): Simplify initialization.
2019-03-24 23:32:09 -06:00
Tom Tromey a930ebcdf9 Don't include symtab.h from expression.h
expression.h includes symtab.h, but apparently only for the
declaration of struct block.  This patch changes it to foward-declare
the structure, and remove the include.

gdb/ChangeLog
2019-03-24  Tom Tromey  <tom@tromey.com>

	* expression.h: Don't include symtab.h.
	(struct block): Forward declare.
2019-03-24 23:32:09 -06:00
Tom Tromey 582942f456 More block constification
I noticed that there are still many places referring to non-const
blocks.  This constifies all the remaining ones that I found that
could be constified.

In a few spots, this search found unused variables or fields.  I
removed these.  I've also removed some unnecessary casts to
"struct block *".

gdb/ChangeLog
2019-03-24  Tom Tromey  <tom@tromey.com>

	* c-exp.y (typebase): Remove casts.
	* gdbtypes.c (lookup_unsigned_typename, )
	(lookup_signed_typename): Remove cast.
	* eval.c (parse_to_comma_and_eval): Remove cast.
	* parse.c (write_dollar_variable): Remove cast.
	* block.h (struct block) <superblock>: Now const.
	* symfile-debug.c (debug_qf_map_matching_symbols): Update.
	* psymtab.c (psym_map_matching_symbols): Make "block" const.
	(map_block): Make "block" const.
	* symfile.h (struct quick_symbol_functions)
	<map_matching_symbols>: Constify block argument to "callback".
	* symtab.c (basic_lookup_transparent_type_quick): Make "block"
	const.
	(find_pc_sect_compunit_symtab): Make "b" const.
	(find_symbol_at_address): Likewise.
	(search_symbols): Likewise.
	* dwarf2read.c (dw2_lookup_symbol): Make "block" const.
	(dw2_debug_names_lookup_symbol): Likewise.
	(dw2_map_matching_symbols): Update.
	* p-valprint.c (pascal_val_print): Remove "block".
	* ada-lang.c (ada_add_global_exceptions): Make "b" const.
	(aux_add_nonlocal_symbols): Make "block" const.
	(resolve_subexp): Remove cast.
	* linespec.c (iterate_over_all_matching_symtabs): Make "block"
	const.
	(iterate_over_file_blocks): Likewise.
	* f-exp.y (%union) <bval>: Remove.
	* coffread.c (patch_opaque_types): Make "b" const.
	* spu-tdep.c (spu_catch_start): Make "block" const.
	* c-valprint.c (print_unpacked_pointer): Remove "block".
	* symmisc.c (dump_symtab_1): Make "b" const.
	(block_depth): Make "block" const.
	* d-exp.y (%union) <bval>: Remove.
	* cp-support.h (cp_lookup_rtti_type): Update.
	* cp-support.c (cp_lookup_rtti_type): Make "block" const.
	* psymtab.c (psym_lookup_symbol): Make "block" const.
	(maintenance_check_psymtabs): Make "b" const.
	* python/py-framefilter.c (extract_sym): Make "sym_block" const.
	(enumerate_locals, enumerate_args): Update.
	* python/py-symtab.c (stpy_global_block): Make "block" const.
	(stpy_static_block): Likewise.
	* inline-frame.c (block_starting_point_at): Make "new_block"
	const.
	* block.c (find_block_in_blockvector): Make return type const.
	(blockvector_for_pc_sect): Make "b" const.
	(find_block_in_blockvector): Make "b" const.
2019-03-24 23:32:08 -06:00
Philippe Waroquiers 5783e150b2 (re-)fix the regcache leaks when detaching from an executable.
Commit 799efbe8e0 was supposed to fix
the below leak.  However, for this fix to work, it is critical to
save the ptid before detach.

This commit (pushed as OBVIOUS, as the change was already reviewed/approved)
saves the ptid before the detach, as in the original reviewed patch
(see https://sourceware.org/ml/gdb-patches/2019-02/msg00263.html).

Re-tested on debian/amd64, natively and under valgrind.

==7426== 1,123 (72 direct, 1,051 indirect) bytes in 1 blocks are definitely lost in loss record 2,872 of 3,020
==7426==    at 0x4C2C4CC: operator new(unsigned long) (vg_replace_malloc.c:344)
==7426==    by 0x5BD1E1: get_thread_arch_aspace_regcache(ptid_t, gdbarch*, address_space*) (regcache.c:330)
==7426==    by 0x5BD39A: get_thread_regcache (regcache.c:366)
==7426==    by 0x5BD39A: get_current_regcache() (regcache.c:372)
==7426==    by 0x4B1EB4: get_current_frame() (frame.c:1588)
...
2019-03-24 13:56:46 +01:00
Tom Tromey 7ad417dd21 Have parser reset the innermost block tracker
I ran across a comment in symfile.c today:

  /* Clear globals which might have pointed into a removed objfile.
     FIXME: It's not clear which of these are supposed to persist
     between expressions and which ought to be reset each time.  */

It seems to me that this can be clarified: the parser entry points
ought to reset the innermost block tracker (and the expression context
block), and these should not be considered valid for code to use at
arbitrary times -- only immediately after an expression has been
parsed.

This patch implements this idea.  This could be further improved by
removing the parser globals and changing the parser functions to
return this information, but I have not done this.

Tested by the buildbot.

gdb/ChangeLog
2019-03-23  Tom Tromey  <tom@tromey.com>

	* varobj.c (varobj_create): Update.
	* symfile.c (clear_symtab_users): Don't reset innermost_block.
	* printcmd.c (display_command, do_one_display): Don't reset
	innermost_block.
	* parser-defs.h (enum innermost_block_tracker_type): Move to
	expression.h.
	(innermost_block): Update comment.
	* parse.c (parse_exp_1): Add tracker_types parameter.
	(parse_exp_in_context): Rename from parse_exp_in_context_1.  Add
	tracker_types parameter.  Reset innermost_block.
	(parse_exp_in_context): Remove.
	(parse_expression_for_completion): Update.
	* objfiles.c (~objfile): Don't reset expression_context_block or
	innermost_block.
	* expression.h (enum innermost_block_tracker_type): Move from
	parser-defs.h.
	(parse_exp_1): Add tracker_types parameter.
	* breakpoint.c (set_breakpoint_condition, watch_command_1): Don't
	reset innermost_block.
2019-03-23 10:59:10 -06:00
Tom Tromey b366c208ee Include bcache.h from objfiles.h
objfiles.h needs "struct bcache" to be complete, so it should include
bcache.h.  This patch implements this.

Tested by rebuilding.

gdb/ChangeLog
2019-03-23  Tom Tromey  <tom@tromey.com>

	* objfiles.h: Include bcache.h.
2019-03-23 10:50:27 -06:00
Tom Tromey 9bb9b2f9d6 Use scoped_restore_current_language in two places
I found a couple of spots that manually saved and restored the current
language.  This patch changes them to use
scoped_restore_current_language.

Tested by the buildbot.

gdb/ChangeLog
2019-03-23  Tom Tromey  <tom@tromey.com>

	* linespec.c (get_current_search_block): Use
	scoped_restore_current_language.
	* symmisc.c (dump_symtab): Use scoped_restore_current_language.
2019-03-23 10:18:15 -06:00
Alan Hayward 59c283728f AArch64: Read pauth section from core files
gdb/ChangeLog:

	* aarch64-linux-tdep.c
	(aarch64_linux_iterate_over_regset_sections): Check for pauth
	section.
	* aarch64-linux-tdep.h (AARCH64_LINUX_SIZEOF_PAUTH): New define.
2019-03-22 10:43:17 +00:00
Alan Hayward 17e116a7d1 AArch64: Prologue scan unwinder support for signed return addresses
Pauth address signing is enabled at binary compile time.  When enabled the
return addresses for functions may be mangled.  This patch adds functionality
to restore the original address for use in the prologue scan unwinder.

In the prologue analyzer, check for PACIASP/PACIBSP (enable address mangling)
and AUTIASP/AUTIBSP (disable address mangling).

When unwinding the PC from the prologue, unmask the register if required.

Add a test case to the prologue tests.

gdb/ChangeLog:

	* aarch64-tdep.c (aarch64_analyze_prologue): Check for pauth
	instructions.
	(aarch64_analyze_prologue_test): Add PACIASP test.
	(aarch64_prologue_prev_register): Unmask PC value.
2019-03-22 10:41:15 +00:00
Alan Hayward 11e1b75f06 AArch64: DWARF unwinder support for signed return addresses
Pauth address signing is enabled at binary compile time.  When enabled the
return addresses for functions may be mangled.  This patch adds functionality
to restore the original address for use in the DWARF unwinder.

DW_CFA_AARCH64_negate_ra_state in a binary indicates the toggling of address
signing between enabled and disabled.  Ensure the state is stored in the DWARF
register ra_state.

Ensure the pauth DWARF registers are initialised.

gdb/ChangeLog:

	* aarch64-tdep.c (aarch64_frame_unmask_address): New function.
	(aarch64_dwarf2_prev_register): Unmask PC value.
	(aarch64_dwarf2_frame_init_reg): Init pauth registers.
	(aarch64_execute_dwarf_cfa_vendor_op): Check for
	DW_CFA_AARCH64_negate_ra_state.
	(aarch64_gdbarch_init): Add aarch64_execute_dwarf_cfa_vendor_op.
2019-03-22 10:39:11 +00:00
Alan Hayward 34dcc7cf95 AArch64: Add pauth DWARF registers
Map the pauth registers to DWARF.

Add a new pseudo register ra_state and also map this to DWARF.  This register
is hidden from the user - prevent it from being read or written to.  It will
be used for the unmangling of addresses.

gdb/ChangeLog:

	* aarch64-tdep.c (aarch64_dwarf_reg_to_regnum): Check for pauth
	registers.
	(aarch64_pseudo_register_name): Likewise.
	(aarch64_pseudo_register_type): Likewise.
	(aarch64_pseudo_register_reggroup_p): Likewise.
	(aarch64_gdbarch_init): Add pauth registers.
	* aarch64-tdep.h (AARCH64_DWARF_PAUTH_RA_STATE): New define.
	(AARCH64_DWARF_PAUTH_DMASK): Likewise.
	(AARCH64_DWARF_PAUTH_CMASK): Likewise.
	(struct gdbarch_tdep): Add regnum for ra_state.
2019-03-22 10:37:46 +00:00
Alan Hayward 1ef53e6b83 AArch64: gdbserver: read pauth registers
Add the pauth registers to the regset lists.

Add a new regset type OPTIONAL_REGS which allows for the regset read to fail.
Once the read fails, it will not be checked again.  This allows targets with
optional features to keep a single static regset_info structure.

gdb/ChangeLog:

	* arch/aarch64.h (AARCH64_PAUTH_REGS_SIZE): New define.

gdb/gdbserver/ChangeLog:

	* linux-aarch64-low.c (aarch64_store_pauthregset): New function.
	* linux-low.c (regsets_store_inferior_registers): Allow optional reads
	to fail.
	* linux-low.h (enum regset_type): Add OPTIONAL_REGS.
2019-03-22 10:34:09 +00:00
Alan Hayward 76bed0fd94 AArch64: Read pauth registers
Initialise the pauth registers when creating a target description, and store
the regnum of the first pauth register.

Use ptrace to read the registers in the pauth feature.

Do not allow the registers to be written.

gdb/ChangeLog:

	* aarch64-linux-nat.c (fetch_pauth_masks_from_thread): New
	function.
	(aarch64_linux_nat_target::fetch_registers): Read pauth registers.
	* aarch64-tdep.c (aarch64_cannot_store_register): New function.
	(aarch64_gdbarch_init): Add puth registers.
	* aarch64-tdep.h (struct gdbarch_tdep): Add pauth features.
	* arch/aarch64.h (AARCH64_PAUTH_DMASK_REGNUM): New define.
	(AARCH64_PAUTH_CMASK_REGNUM): Likewise.
2019-03-22 10:31:02 +00:00
Alan Hayward ee4fbcfa26 AArch64: Use HWCAP to detect pauth feature
Add aarch64_get_hwcap functions for reading the HWCAP.
From this extract the PACA value and use this to enable pauth.

gdb/ChangeLog:

	* aarch64-linux-nat.c
	(aarch64_linux_nat_target::read_description): Read PACA hwcap.
	* aarch64-linux-tdep.c
	(aarch64_linux_core_read_description): Likewise.
	(aarch64_linux_get_hwcap): New function.
	* aarch64-linux-tdep.h (AARCH64_HWCAP_PACA): New define.
	(aarch64_linux_get_hwcap): New declaration.

gdb/gdbserver/ChangeLog:

	* linux-aarch64-low.c (AARCH64_HWCAP_PACA): New define.
	(aarch64_get_hwcap): New function.
	(aarch64_arch_setup): Read APIA hwcap.
2019-03-22 10:10:22 +00:00
Alan Hayward 6dc0ebde59 AArch64: Add pointer authentication feature
Pointer Authentication is a new feature in AArch64 v8.3-a. When enabled in
the compiler, function return addresses will be mangled by the kernel.

Add register description xml and wire up to aarch64_linux_read_description.
This description includes the two pauth user registers.

Nothing yet uses the feature - that is added in later patches.

gdb/ChangeLog:

	* aarch64-linux-nat.c
	(aarch64_linux_nat_target::read_description): Add pauth param.
	* aarch64-linux-tdep.c
	(aarch64_linux_core_read_description): Likewise.
	* aarch64-tdep.c (struct target_desc): Add in pauth.
	(aarch64_read_description): Add pauth param.
	(aarch64_gdbarch_init): Likewise.
	* aarch64-tdep.h (aarch64_read_description): Likewise.
	* arch/aarch64.c (aarch64_create_target_description): Likewise.
	* arch/aarch64.h (aarch64_create_target_description): Likewise.
	* features/Makefile: Add new files.
	* features/aarch64-pauth.c: New file.
	* features/aarch64-pauth.xml: New file.

gdb/doc/ChangeLog:

	* gdb.texinfo: Describe pauth feature.

gdb/gdbserver/ChangeLog:

	* linux-aarch64-ipa.c (get_ipa_tdesc): Add pauth param.
	(initialize_low_tracepoint): Likewise.
	* linux-aarch64-low.c (aarch64_arch_setup): Likewise.
	* linux-aarch64-tdesc-selftest.c (aarch64_tdesc_test): Likewise.
	* linux-aarch64-tdesc.c (struct target_desc): Likewise.
	(aarch64_linux_read_description): Likewise.
	* linux-aarch64-tdesc.h (aarch64_linux_read_description): Likewise.
2019-03-22 09:58:42 +00:00
Alan Hayward 968aa7ae38 Testsuite: Ensure pie is disabled on some tests
Recent versions of Ubuntu and Debian default GCC to enable pie.

In dump.exp, pie will causes addresses to be out of range for IHEX.

In break-interp.exp, pie is explicitly set for some tests and assumed
to be disabled for the remainder.

Ensure pie is disabled for these tests when required.

In addition, add a pie option to gdb_compile to match the nopie option
and simplify use.

gdb/testsuite/ChangeLog:

	* README: Add pie options.
	* gdb.base/break-interp.exp: Ensure pie is disabled.
	* gdb.base/dump.exp: Likewise.
	* lib/gdb.exp (gdb_compile): Add pie option.
2019-03-22 09:43:35 +00:00
Tom Tromey 48869a5f9c Use @defvar to document gdb.pretty_printers
While referencing the manual, I noticed that gdb.pretty_printers
wasn't documented using @defvar.  This made it more difficult to find
in the info pages.  This patch adds the @defvar and also an
introductory paragraph in that node.

gdb/doc/ChangeLog
2019-03-20  Tom Tromey  <tromey@adacore.com>

	* python.texi (Selecting Pretty-Printers): Use @defvar for
	gdb.pretty_printers.
2019-03-20 11:28:44 -06:00
Tom Tromey 595915c1c1 Merge handle_inferior_event and handle_inferior_event_1
I noticed that handle_inferior_event is just a small wrapper that
frees the value chain.  This patch replaces it with a
scoped_value_mark, reducing the number of lines of code here.

Regression tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-03-20  Tom Tromey  <tromey@adacore.com>

	* infrun.c (handle_inferior_event): Rename from
	handle_inferior_event_1.  Create a scoped_value_mark.
	(handle_inferior_event): Remove.
2019-03-20 11:09:10 -06:00
Tom Tromey 4c7d57e72e Don't show "display"s twice in MI
If you run "gdb -i=mi2" and set a "display", then when "next"ing the
displays will be shown twice:

    ~"1: x = 23\n"
    ~"7\t  printf(\"%d\\n\", x);\n"
    ~"1: x = 23\n"
    *stopped,reason="end-stepping-range",frame={addr="0x0000000000400565",func="main",args=[],file="q.c",fullname="/tmp/q.c",line="7"},thread-id="1",stopped-threads="all",core="1"

The immediate cause of this is this code in mi_on_normal_stop_1:

      print_stop_event (mi_uiout);

      console_interp = interp_lookup (current_ui, INTERP_CONSOLE);
      if (should_print_stop_to_console (console_interp, tp))
	print_stop_event (mi->cli_uiout);

... which obviously prints the stop twice.

However, I think the first call to print_stop_event is intended just
to emit the MI *stopped notification, which explains why the source
line does not show up two times.

This patch fixes the bug by changing print_stop_event to only call
do_displays for non-MI-like ui-outs.

Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-03-19  Tom Tromey  <tromey@adacore.com>

	* mi/mi-interp.c (mi_on_normal_stop_1): Only show displays once.
	* infrun.h (print_stop_event): Add "displays" parameter.
	* infrun.c (print_stop_event): Add "displays" parameter.

gdb/testsuite/ChangeLog
2019-03-19  Tom Tromey  <tromey@adacore.com>

	* gdb.mi/mi2-cli-display.c: New file.
	* gdb.mi/mi2-cli-display.exp: New file.
2019-03-19 12:16:48 -06:00
Pedro Alves cb24623460 Add comments describing tui_ui_out and its fields, cleanup a bit
This commit add comments describing tui_ui_out and its fields, and
cleans up the code a little bit.

Also switch to using in-class initialization so that the initial
values can be seen alongside the comments.

I see no reason for initializing m_line as -1 instead of 0, since all
the checks in the .c file are of the form "> 0".  AFAICS there's no
practical difference between -1 and 0.  So it seems simpler to
initialize it as 0.

There's a bit of redundancy in tui_ui_out::do_field_string, which is
fixed by this commit.

gdb/ChangeLog:
2019-03-19  Pedro Alves  <palves@redhat.com>

	* tui/tui-out.c (tui_ui_out::do_field_string): Simplify.
	(tui_ui_out::do_text): Add comments.  Reset M_LINE to 0 instead of
	to -1.  Fix TABs vs spaces.
	(tui_ui_out::tui_ui_out): Don't initialize fields here.
	* tui/tui-out.h (tui_ui_out) Add intro comments.
	<m_line, m_start_of_line>: In-class initialize, and add describing
	comment.
2019-03-19 18:08:27 +00:00
Alan Hayward 3a0e45b2f1 Fix Arm build error
The following commit broke the build for Arm:
d3a70e03cf
Change iterate_over_lwps to take a gdb::function_view

Correct the changes made to arm_linux_insert_hw_breakpoint1 and make
similar changes to arm_linux_remove_hw_breakpoint1.

2019-03-18  Alan Hayward  <alan.hayward@arm.com>

	* arm-linux-nat.c (arm_linux_insert_hw_breakpoint1): Fix
	variable names.
	(arm_linux_remove_hw_breakpoint1): Use a gdb::function_view.
2019-03-19 09:59:55 +00:00
Pedro Alves 5371b8502a Fix first time you type UP or DOWN in TUI's command window
The first time you type UP or DOWN arrow in the command window, GDB
should scroll the source window, but instead it displays the line
number and the file name in the command window(?).

What happens there is that the first time we call
tui_ui_out::do_field_int, it doesn't initialize m_line, because
m_start_of_line is -1, as set by the constructor; and then the
following call to tui_ui_out::do_field_string falls back to
cli_ui_out::do_field_string because m_line is zero.

The problem is caused by a typo in the C++ification of tui_ui_out,
commit 112e8700a6, where m_line and m_start_of_line's initial values
were swapped from what they used to be:

 -struct ui_out *
 -tui_out_new (struct ui_file *stream)
 +tui_ui_out::tui_ui_out (ui_file *stream)
 +: cli_ui_out (stream, 0),
 +  m_line (0),
 +  m_start_of_line (-1)
  {
 -
 -  /* Initialize our fields.  */
 -  data->line = -1;
 -  data->start_of_line = 0;

This commit fixes it.

gdb/ChangeLog:
2019-03-18  Pedro Alves  <palves@redhat.com>
	    Eli Zaretskii <eliz@gnu.org>

	* tui/tui-out.c (tui_ui_out::tui_ui_out): Fix initialization of
	m_line and m_start_of_line.
2019-03-18 18:32:42 +00:00
Eli Zaretskii b17c4cd078 Fix gdb/TUI behavior in response to [Enter] keypress
gdb/ChangeLog:
2019-03-18  Eli Zaretskii  <eliz@gnu.org>

	* tui/tui-io.c (gdb_wgetch): Don't echo CR.
	(tui_getc): When gdb_wgetch returns a CR, behave the same as when
	it returns a newline.  This fixes a regression in TUI mode, whereby
	the next line is output on the same screen line as the user input.
2019-03-18 20:04:40 +02:00
Tom Tromey 4bd56d18cc Fix regression caused by minimal symbol changes
The earlier patch to change minimal symbol allocations to use xmalloc
erroneously left a call to obstack_blank in
minimal_symbol_reader::install.  Because obstack_blank does not finish
the object allocation on an obstack, this in turn could cause invalid
memory reads in some situations.

This patch fixes the problem by removing the call.  Tested on x86-64
Fedora 29; also verified with valgrind.

gdb/ChangeLog
2019-03-18  Tom Tromey  <tromey@adacore.com>

	* minsyms.c (minimal_symbol_reader::install): Remove call to
	obstack_blank.
2019-03-18 09:56:27 -06:00
Pedro Alves 55c10aca2e Improve/fix the TUI's current source line highlight
With styling enabled, I think the way we display the TUI's
highlighted/current line is very ugly and distracting.  The problem in
my view is that we reverse foreground/background in colored text as
well, leading to rainbow of background colors.

This patch changes that to something that I find much more sensible --
only reverse the default foreground/background colors, leave styled
text colors alone.  If the foreground color is not the default
(because the text was styled), leave the foreground color as is.  If
e.g., the terminal is fg=BLACK, and bg=WHITE, and the style wants to
print text in RED, reverse the background color (print in BLACK), but
still print the text in RED.

Note: The new ui_file_style::set_fg method isn't called set_foreground
instead, because set_foreground is a macro in /usr/lib/term.h (ncurses).

gdb/ChangeLog:
2019-03-18  Pedro Alves  <palves@redhat.com>

	* tui/tui-io.c (reverse_mode_p, reverse_save_bg, reverse_save_fg):
	New globals.
	(apply_style): New, factored out from ...
	(apply_ansi_escape): ... this.  Handle reverse video mode.
	(tui_set_reverse_mode): New function.
	* tui/tui-io.h (tui_set_reverse_mode): New declaration.
	* tui/tui-winsource.c (tui_show_source_line): Use
	tui_set_reverse_mode instead of setting A_STANDOUT.
	* ui-style.h (struct ui_file_style) <set_reverse, set_fg, set_bg>:
	New setter methods.
2019-03-18 14:26:00 +00:00
Hannes Domani 647bb750c2 Fix scrolling right in the TUI
This commit fixes two issues in scrolling right in the TUI:

#1 - Scrolling right with the arrow keys, the first keypress doesn't
do anything.  The problem is that copy_source_line() checks if
(column < first_col), and because of the ++column directly before, it
basically starts with 1 instead of 0.

#2 - Scrolling right handles TABS and escaped characters as single
characters, which just looks weird.  The problem is that there's a
spot that misses handling TABS.

gdb/ChangeLog:
2019-03-18  Hannes Domani  <ssbssa@yahoo.de>

	* tui/tui-source.c (copy_source_line): Fix handling of 'column'.
	Handle tabs.
2019-03-18 14:25:59 +00:00
Tom Tromey bff8c71fd8 Fix Ada "ptype" bug with array types
Using ptype on an array type in Ada can sometimes show an incorrect
high bound.  This happens because ada_evaluate_subexp will create an
array with an incorrect upper bound in the EVAL_AVOID_SIDE_EFFECTS
case.

This patch fixes the problem by arranging to always create such an
array with valid bounds.

Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-03-18  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (empty_array): Add "high" parameter.
	(ada_evaluate_subexp): Update.

gdb/testsuite/ChangeLog
2019-03-18  Joel Brobecker  <brobecker@adacore.com>
	    Tom Tromey  <tromey@adacore.com>

	* gdb.ada/ptype_array/pck.adb: New file.
	* gdb.ada/ptype_array/pck.ads: New file.
	* gdb.ada/ptype_array/foo.adb: New file.
	* gdb.ada/ptype_array.exp: New file.
2019-03-18 06:45:16 -06:00
Sergei Trofimovich 58785d9888 gdb: unconditionally define _initialize_string_view_selftests
The build failure was noticed by Helmut Jarausch in
https://bugs.gentoo.org/680232:
    $ ./configure CXXFLAGS='-std=c++17 -Os'
    ...
      CXXLD  gdb
    ld: init.o: in function `initialize_all_files()':
    init.c:(.text+0x113): undefined reference to `_initialize_string_view_selftests()'

It happens because '_initialize_string_view_selftests()' is
conditionally defined based on C++ default.

The change defines '_initialize_string_view_selftests()'
unconditionally and leaves implementation a no-op on c++17
compilers.

gdb/ChangeLog:
2019-03-17  Sergei Trofimovich <siarheit@google.com>

	* unittests/string_view-selftests.c: Define
	_initialize_string_view_selftests unconditionally.
2019-03-18 00:01:13 -04:00
Владимир Мартьянов d4cbef22ba Remove unused variable from windows_make_so
There is unused variable text_vma in function windows_make_so. This
leads to build error on Windows using Cygwin.

gdb/ChangeLog:
2019-03-17  Vladimir Martyanov  <vilgeforce@gmail.com>

    PR gdb/24350
    * windows-nat.c (windows_make_so): Remove unused text_vma variable.
2019-03-17 14:48:59 -04:00
Владимир Мартьянов fce4c07161 Fix wrong format specification in display_selector()
There are a wrong format strings in function display_selector() in
file windows-nat.c. This leads to build error using Cygwin on Windows.
LDT_ENTRY.HighWord is a DWORD, which is unsigned long int, so the
format specification should be for long int, not simply int.

gdb/ChangeLog:
2019-03-17  Vladimir Martyanov  <vilgeforce@gmail.com>

    PR gdb/24351
    * windows-nat.c (display_selector): Format specifications fixed
2019-03-17 14:41:12 -04:00
Eli Zaretskii f7f0a12390 Fix redisplay of the current line in GDB TUI mode
Without this change, when the current line is longer than the source
window width, redisplaying that line overwrites the window frame and
also portions of the next line.

gdb/ChangeLog:
2019-03-17  Eli Zaretskii  <eliz@gnu.org>

	* tui/tui-winsource.c (tui_set_is_exec_point_at): Call
	tui_refill_source_window instead of tui_refresh_win, to update the
	current execution line.  This fixes redisplay of the current line
	when stepping through very long lines with "next" or "step".
2019-03-17 18:00:34 +02:00
Eli Zaretskii ab42892fb7 Fix vertical scrolling of TUI source window
gdb/ChangeLog:
2019-03-16  Eli Zaretskii  <eliz@gnu.org>

	* source-cache.c (source_cache::get_source_lines): Call
	find_source_lines to initialize s->nlines.  This fixes vertical
	scrolling of TUI source window when the DOWN arrow is pressed.
2019-03-16 19:53:46 +02:00
Philippe Waroquiers 8d8c087f34 OBVIOUS: fix several occurrences of 'This options has' to 'This option has' 2019-03-16 16:57:25 +01:00
Eli Zaretskii 798e1c302a Revert "Use wclrtoeol in tui_show_source_line"
gdb/ChangeLog:
2019-03-16  Eli Zaretskii  <eliz@gnu.org>

	* tui/tui-winsource.c (tui_show_source_line): Revert "Use
	wclrtoeol in tui_show_source_line".  This reverts changes made in
	commit 4a3045920b.
2019-03-16 14:13:43 +02:00
Tom Tromey eefba3da27 Change minimal_symbol inheritance
This changes struct minimal_symbol to inherit from general_symbol_info
and updates various macros to cope.

Because MSYMBOL_SET_LANGUAGE and MSYMBOL_SET_NAMES were only used from
a single spot, this patch removes them in favor of simply inlining
their definitions.  I consider this to be somewhat cleaner, not least
because the "phony polymorphism" provided by such macros is not useful
in practice.

gdb/ChangeLog
2019-03-15  Tom Tromey  <tom@tromey.com>

	* symtab.h (struct minimal_symbol): Derive from
	general_symbol_info.
	(MSYMBOL_VALUE, MSYMBOL_VALUE_RAW_ADDRESS)
	(MSYMBOL_VALUE_ADDRESS, MSYMBOL_VALUE_BYTES)
	(MSYMBOL_BLOCK_VALUE, MSYMBOL_VALUE_CHAIN, MSYMBOL_LANGUAGE)
	(MSYMBOL_SECTION, MSYMBOL_OBJ_SECTION, MSYMBOL_NATURAL_NAME)
	(MSYMBOL_LINKAGE_NAME, MSYMBOL_DEMANGLED_NAME)
	(MSYMBOL_SEARCH_NAME): Update.
	(MSYMBOL_SET_LANGUAGE, MSYMBOL_SET_NAMES): Remove.
	* solib.c (gdb_bfd_lookup_symbol_from_symtab): Don't use memset.
	* minsyms.c (minimal_symbol_reader::record_full): Update.
2019-03-15 16:02:10 -06:00
Tom Tromey 0de2420c4b Use memcpy in minimal_symbol_reader::install
minimal_symbol_reader::install copies minsyms from the msym_bunch
objects into the allocated memory.  It seemed better to me to do this
via memcpy, as that is frequently optimized in libc.

gdb/ChangeLog
2019-03-15  Tom Tromey  <tom@tromey.com>

	* minsyms.c (minimal_symbol_reader::install): Use memcpy.
2019-03-15 16:02:10 -06:00
Tom Tromey 042d75e42c Allocate minimal symbols with malloc
Currently, minimal symbols are allocated on the per-BFD obstack.
However, it is also possible for multiple symbol readers to create
minimal symbols for a given objfile.  In this case, the minimal
symbols will be reallocated on the obstack, leading to some waste of
storage.

This is a memory leak, but I think it won't be caught by tools like
valgrind, because valgrind doesn't know about obstacks.

This patch fixes the problem by using malloc to allocate the storage
for minimal symbols.

gdb/ChangeLog
2019-03-15  Tom Tromey  <tom@tromey.com>

	* objfiles.h (struct objfile_per_bfd_storage) <msymbols>: Now a
	unique_xmalloc_ptr.
	(objfile::msymbols_range::begin, objfile::msymbols_range::end):
	Update.
	* minsyms.c (lookup_minimal_symbol_by_pc_section)
	(build_minimal_symbol_hash_tables)
	(minimal_symbol_reader::install): Update.
2019-03-15 16:02:10 -06:00
Tom Tromey db92718b54 Use htab_up for demangled hash
This changes objfile_per_bfd_storage::demangled_names_hash to be an
htab_up.  This lets us remove some manual management code from the
objfile_per_bfd_storage destructor.

gdb/ChangeLog
2019-03-15  Tom Tromey  <tom@tromey.com>

	* symtab.c (create_demangled_names_hash): Update.
	(symbol_set_names): Update.
	* objfiles.h (struct objfile_per_bfd_storage)
	<demangled_names_hash>: Now an htab_up.
	* objfiles.c (objfile_per_bfd_storage): Simplify.
2019-03-15 16:02:09 -06:00