Commit Graph

44196 Commits

Author SHA1 Message Date
Tom Tromey f92ff6b552 Don't allow copying of auto_obstack
Add DISABLE_COPY_AND_ASSIGN to struct auto_obstack, to prevent copying
it.  Copying an auto_obstack would be a bug.

2020-02-11  Tom Tromey  <tom@tromey.com>

	* gdb_obstack.h (struct auto_obstack): Use
	DISABLE_COPY_AND_ASSIGN.

Change-Id: Ic9e5ab20acfcfa61c241fed4d99bbb1caefba3cd
2020-02-11 17:57:46 -07:00
Tom Tromey 3fd6912bb1 Don't forward-declare struct objfile in dwarf2/frame.h
dwarf2/frame.h forward-declares struct objfile, but there's no need
for this.

gdb/ChangeLog
2020-02-11  Tom Tromey  <tom@tromey.com>

	* dwarf2/frame.h (struct objfile): Don't forward declare.

Change-Id: I4d54d46ac9422eeb64dc5f0b934792e77a875aa5
2020-02-11 17:57:46 -07:00
Christian Biesinger 69ed9b74b6 Remove use of deprecated_add_core_fns in cris_tdep.c
The non-deprecated equivalent is implementing the gdbarch function
iterate_over_regset_sections, this patch does that.

Tested by generating a core file on cris under qemu and comparing
the output of "info registers".

This also fixes this warning when loading cris core files:
  warning: Unexpected size of section `.reg/164' in core file.

gdb/ChangeLog:

2020-02-11  Christian Biesinger  <cbiesinger@google.com>

	* cris-tdep.c (cris_supply_gregset): Change signature to match
	what struct regset expects.
	(cris_regset): New struct.
	(fetch_core_registers): Remove.
	(cris_iterate_over_regset_sections): New function.
	(_initialize_cris_tdep): Don't call deprecated_add_core_fns.
	(cris_gdbarch_init): Call set_gdbarch_iterate_over_regset_sections.

Change-Id: Ieef895b5a2fdc797d1a913cd1c0c07563edfe8e7
2020-02-11 10:40:05 -06:00
Sergio Durigan Junior f6be87130b New testcase for PR tui/25126 (staled source cache)
I'm dealing with a Fedora GDB bug that is related to PR tui/25126, and
I thought I'd write a specific testcase for it because I couldn't find
one.

The idea is to get the simple reproducer from the bug and tweak the
testcase around it.  This one was a bit hard because, since we need to
modify the source file and recompile it, it involved a bit of TCL-foo
to do things.  Also for this reason, I'm only enabling the test for
native boards.

I tested this with an upstream GDB and made sure everything is
passing.  I also tested with a faulty GDB and made sure the test
failed.

gdb/testsuite/ChangeLog:
2020-02-11  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR tui/25126
	https://bugzilla.redhat.com/show_bug.cgi?id=1784210
	* gdb.base/cached-source-file.c: New file.
	* gdb.base/cached-source-file.exp: New file.

Change-Id: Ib1b074342ebe8613c6d1dfde631691ebdf6d81c6
2020-02-11 11:36:17 -05:00
Christian Biesinger bda874f6d1 Add a comment for the ARM_F{0..7}_REGNUM registers
These are for the obsolete FPA architecture.

gdb/ChangeLog:

2020-02-11  Christian Biesinger  <cbiesinger@google.com>

	* arch/arm.h (enum gdb_regnum): Add comment for the FP0..7
	registers.

Change-Id: I6920616318ee637493d4ca12b91fa2ebcd103d76
2020-02-11 10:24:04 -06:00
Christian Biesinger 754e156431 Add missing \n in fprintf
gdb/ChangeLog:

2020-02-11  Christian Biesinger  <cbiesinger@google.com>

	* arm-tdep.c (arm_dump_tdep): Add \n in fprintf.

Change-Id: I0175572436cc7dec29e852c96371f85ea763ba2a
2020-02-11 10:22:33 -06:00
Simon Marchi 898e7f6078 Re-generate gdb/gdbserver/gdbsupport configure scripts
In my previous commit, I did a last minute modification of warning.m4,
but forgot to re-generate the configure scripts, this commit fixes that.

gdb/ChangeLog:

	* configure: Re-generate.

gdbserver/ChangeLog:

	* configure: Re-generate.

gdbsupport/ChangeLog:

	* configure: Re-generate.
2020-02-11 10:56:09 -05:00
Simon Marchi 8ddd8e0ed8 Add -Wstrict-null-sentinel to gdbsupport/warning.m4
Commit 85f0dd3ce ("[gdb] Fix -Wstrict-null-sentinel warnings") fixed
some violations of -Wstrict-null-sentinel.  If we want to enforce this
warning, I think we should enable it in our warning.m4 file.

gdbsupport/ChangeLog:

	* warning.m4: Add -Wstrict-null-sentinel.
	* configure: Re-generate.

gdbserver/ChangeLog:

	* configure: Re-generate.

gdb/ChangeLog:

	* configure: Re-generate.
2020-02-11 10:51:49 -05:00
Simon Marchi 58df732b21 Move gdb/warning.m4 to gdbsupport
This file is used by gdbsupport, gdbserver and gdb, so I think it
belongs in gdbsupport.  Move it there and update the references the
various acinclude.m4 files.

gdbsupport/ChangeLog:

	* warning.m4: Move here, from gdb/warning.m4.
	* acinclude.m4: Update warning.m4 path.
	* Makefile.in: Re-generate.

gdbserver/ChangeLog:

	* acinclude.m4: Update warning.m4 path.

gdb/ChangeLog:

	* acinclude: Update warning.m4 path.
	* warning.m4: Move to gdbsupport.
2020-02-11 10:51:43 -05:00
Tom Tromey da5bd37ebc Remove some ui_file_* functions
This removes ui_file_isatty, ui_file_read, ui_file_write,
ui_file_write_async_safe, ui_file_flush, and ui_file_puts, replacing
them with calls to the appropriate method instead.

gdb/ChangeLog
2020-02-11  Tom Tromey  <tromey@adacore.com>

	* remote.c (remote_console_output): Update.
	* printcmd.c (printf_command): Update.
	* event-loop.c (gdb_wait_for_event): Update.
	* linux-nat.c (sigchld_handler): Update.
	* remote-sim.c (gdb_os_write_stdout): Update.
	(gdb_os_flush_stdout): Update.
	(gdb_os_flush_stderr): Update.
	(gdb_os_write_stderr): Update.
	* exceptions.c (print_exception): Update.
	* remote-fileio.c (remote_fileio_func_read): Update.
	(remote_fileio_func_write): Update.
	* tui/tui.c (tui_enable): Update.
	* tui/tui-interp.c (tui_interp::init): Update.
	* utils.c (init_page_info): Update.
	(putchar_unfiltered, fputc_unfiltered): Update.
	(gdb_flush): Update.
	(emit_style_escape): Update.
	(flush_wrap_buffer, fputs_maybe_filtered): Update.
	* ui-file.c (ui_file_isatty, ui_file_read, ui_file_write)
	(ui_file_write_async_safe, ui_file_flush, ui_file_puts): Remove.
	(stderr_file::write): Update.
	(stderr_file::puts): Update.
	* ui-file.h (ui_file_isatty, ui_file_write)
	(ui_file_write_async_safe, ui_file_read, ui_file_flush)
	(ui_file_puts): Don't declare.

Change-Id: I3ca9b36e9107f6adbc41e014f5078b41d6bcec4d
2020-02-11 07:05:28 -07:00
Tom de Vries b2770d5e77 [gdb/testsuite] Fix UNRESOLVED in gdb.server/server-kill-python.exp
The test-case gdb.server/server-kill-python.exp runs fine by itself:
...
Running src/gdb/testsuite/gdb.server/server-kill-python.exp ...

                === gdb Summary ===

nr of expected passes            3
...

But if we run f.i. gdb.server/file-transfer.exp before it, we get instead:
...
Running src/gdb/testsuite/gdb.server/server-kill-python.exp ...
ERROR: GDB process no longer exists

                === gdb Summary ===

nr of expected passes            13
nr of unresolved testcases       1
...

We can see the origin of the problem here:
...
spawn gdbserver --once localhost:2347 \
  build/gdb/testsuite/outputs/gdb.server/file-transfer/file-transfer \
  build/gdb/testsuite/outputs/gdb.server/server-kill-python/server-kill-python^M
Process build/gdb/testsuite/outputs/gdb.server/file-transfer/file-transfer
  \ created; pid = 9464^M
Listening on port 2347^M
...

The spawn of the gdbserver for the server-kill-python test-case gets as
executable argument the file-transfer binary.

This is caused by proc gdbserver_spawn attempting to load the exec file in
$file_last_loaded.  This is something that is meant to load the same exec in
the gdbserver that was earlier loaded into gdb.

In this test-case however, nothing has been loaded into gdb by the test-case,
and consequently we load the file that was loaded into gdb in the previous
test-case.

Fix this by unsetting $file_last_loaded in gdb_init.

Build and reg-tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-02-11  Tom de Vries  <tdevries@suse.de>

	PR testsuite/25488
	* lib/gdb.exp (gdb_init): Unset $file_last_loaded.

Change-Id: Ic385e08cbd34cbf85518720cf5695b4ff6619f4b
2020-02-11 07:08:33 +01:00
Tom de Vries 85f0dd3ce8 [gdb] Fix -Wstrict-null-sentinel warnings
When passed in CXXFLAGS, -Wstrict-null-sentinel triggers twice in a
gdb/gdbserver build.

Fix the two occurrences.

Build and reg-tested on x86_64-linux.

gdb/ChangeLog:

2020-02-10  Tom de Vries  <tdevries@suse.de>

	* dwarf2/read.c (process_psymtab_comp_unit_reader): Cast concat NULL
	sentinel to char *.

gdbsupport/ChangeLog:

2020-02-10  Tom de Vries  <tdevries@suse.de>

	* environ.c (gdb_environ::set): Cast concat NULL sentinel to char *.
2020-02-10 15:13:42 +01:00
Tom de Vries 44f6938ead [gdb/testsuite] Skip multi-target.exp without gdbserver
Pre-commit 919adfe840 "Move gdbserver to top level", if we build gdb with
--disable-gdbserver, and run test-case gdb.multi/multi-target.exp, we run
into:
...
(gdb) PASS: gdb.multi/multi-target.exp: continue: non-stop=off: set remote-exec file in inferior 2
spawn of  --once --multi localhost:2346 failed
ERROR: tcl error sourcing /data/gdb_versions/devel/src/gdb/testsuite/gdb.multi/multi-target.exp.
ERROR: Timeout waiting for gdbserver response.
...

Fix this by using skip_gdbserver_tests in multi-target.exp.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-02-10  Tom de Vries  <tdevries@suse.de>

	* gdb.multi/multi-target.exp: Skip if skip_gdbserver_tests.
2020-02-10 13:22:09 +01:00
Maciej W. Rozycki 5f0e2eb79e GDB/testsuite: Fix a catastrophic step-over-no-symbols.exp failure
Fix a catastrophic failure in gdb.base/step-over-no-symbols.exp where
remote target communication issues cause the value of the PC retrieved
to be empty:

(gdb) FAIL: gdb.base/step-over-no-symbols.exp: displaced=off: stepi
p /x $pc
Remote 'g' packet reply is too long (expected 264 bytes, got 532 bytes): 00000000000000002a6f61551500000080faffff3f0000000028010000000000b03857551500000060ad5f5515000000906e615515000000802401000000000090faffff3f00000000000000000000000100000000000000e8fbffff3f000000f8fbffff3f0000000000000000000000b8faffff3f0000008a05010000000000589c6f551500000056424d40435c2f7c1809575515000000f0e0baaa2a0000000000000000000000f0ffbaaa2a000000f0e0baaa2a0000006804baaa2a000000000000000000000000000000000000007053baaa2a0000008252b2aa2a00000090fe01000000000048e056551500000004000000000000004000000000000000920501000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000xxxxxxxxxxxxxxxx00000000
(gdb) FAIL: gdb.base/step-over-no-symbols.exp: displaced=off: get after PC
ERROR: tcl error sourcing .../gdb/testsuite/gdb.base/step-over-no-symbols.exp.
ERROR: missing operand at _@_
in expression " _@_!= "
    (parsing expression " != ")
    invoked from within
"expr $before_addr != $after_addr"
    ("uplevel" body line 1)
    invoked from within
"uplevel 1 expr $condition"
    (procedure "gdb_assert" line 6)
    invoked from within
"gdb_assert {$before_addr != $after_addr} "advanced""
    (procedure "test_step_over" line 36)
    invoked from within
"test_step_over $displaced"
    ("uplevel" body line 2)
    invoked from within
"uplevel 1 $body"
    invoked from within
"with_test_prefix "displaced=$displaced" {
	test_step_over $displaced
    }"
    ("foreach" body line 6)
    invoked from within
"foreach displaced { "off" "on" "auto" } {
    if { $displaced != "off" && ![support_displaced_stepping] } {
	continue
    }

    with_test_prefix "dis..."
    (file ".../gdb/testsuite/gdb.base/step-over-no-symbols.exp" line 84)
    invoked from within
"source .../gdb/testsuite/gdb.base/step-over-no-symbols.exp"
    ("uplevel" body line 1)
    invoked from within
"uplevel #0 source .../gdb/testsuite/gdb.base/step-over-no-symbols.exp"
    invoked from within
"catch "uplevel #0 source $test_file_name""
Remote debugging from host xxx.xxx.xxx.xxx, port 47130
monitor exit
Killing process(es): 1092
Remote communication error.  Target disconnected.: Connection reset by peer.
(gdb)

To do so verify first, before making an arithmetic comparison, that the
values to compare are actually integers (using a string comparison would
result in a false PASS if both operands were empty, as in this case),
making the test script proceed normally:

(gdb) FAIL: gdb.base/step-over-no-symbols.exp: displaced=off: stepi
p /x $pc
Remote 'g' packet reply is too long (expected 264 bytes, got 532 bytes): 00000000000000002a6f61551500000080faffff3f0000000028010000000000b03857551500000060ad5f5515000000906e615515000000802401000000000090faffff3f00000000000000000000000100000000000000e8fbffff3f000000f8fbffff3f0000000000000000000000b8faffff3f0000008a05010000000000589c6f5515000000424d40435c2f7c7c1809575515000000f0e0baaa2a0000000000000000000000f0ffbaaa2a000000f0e0baaa2a0000006804baaa2a000000000000000000000000000000000000007053baaa2a0000008252b2aa2a00000090fe01000000000048e056551500000004000000000000004000000000000000920501000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000xxxxxxxxxxxxxxxx00000000
(gdb) FAIL: gdb.base/step-over-no-symbols.exp: displaced=off: get after PC
FAIL: gdb.base/step-over-no-symbols.exp: displaced=off: advanced
Remote debugging from host xxx.xxx.xxx.xxx, port 48404
monitor exit
Killing process(es): 1795
Remote communication error.  Target disconnected.: Connection reset by peer.
(gdb)

Note the double curly braces, to take advantage of `&&' operator's lazy
evaluation.

	gdb/testsuite/
	* gdb.base/step-over-no-symbols.exp: Verify that $before_addr
	and $after_addr are both integers before making a comparison.
2020-02-10 08:59:04 +00:00
Tom de Vries 2e9276136b [gdb] Mention CU offset for <artifical> if verbose
Say we're debugging a test-case with CUs with name "<artificial>", meaning
not originating from a single file compilation, and use the verbose setting:
...
$ gdb -iex "set verbose on" -batch cc1
Reading symbols from cc1...
Reading in symbols for <artificial>... \
  and /tmp/trunk/gcc/attribs.c... \
  ...
  and /tmp/trunk/gcc/tree-ssa-reassoc.c... \
  done.
...

From the "/tmp/trunk/gcc/attribs.c" message, it's clear which CU is loaded.  But
that's not the case for the "<artificial>" message.

The message uses the filename field of struct partial_symtab, which is
documented like this:
...
  /* Name of the source file which this partial_symtab defines,
     or if the psymtab is anonymous then a descriptive name for
     debugging purposes, or "".  It must not be NULL.  */
...

So, fix this by setting the filename field to a more descriptive name than
"<artificial>", by appending the CU offset.

This way, we print instead:
...
$ gdb -iex "set verbose on" -batch cc1
Reading symbols from cc1...
Reading in symbols for <artificial>@0x41146d9 \
  and /tmp/trunk/gcc/attribs.c... \
  ... \
  and /tmp/trunk/gcc/tree-ssa-reassoc.c... \
  done.
...

Build and reg-tested on x86_64-linux.

gdb/ChangeLog:

2020-02-09  Tom de Vries  <tdevries@suse.de>

	* dwarf2read.c (process_psymtab_comp_unit_reader): Append CU offset to
	filename if it matches "<artificial>".
2020-02-09 13:32:26 +01:00
Tom de Vries 46ce2b6f4c [gdb/testsuite] Capture many-headers.exp progress and output in gdb.log
When running test-case gdb.base/many-headers.exp, we have test output on
stdout/stderr:
...
Running src/gdb/testsuite/gdb.base/many-headers.exp ...
[New LWP 759]
Core was generated by `outputs/gdb.base/many-headers/many'.
Program terminated with signal SIGSEGV, Segmentation fault.
\#0  0x0000000000400688 in ?? ()

                === gdb Summary ===

nr of expected passes            1
...

Furthermore, the only trace in gdb.log that we have of the gdb command issued
is:
...
PASS: gdb.base/many-headers.exp: read core file
...

Fix this by echoing the gdb command in gdb.log, and capturing the
command output and pasting it into gdb.log:
...
( ulimit -s 4096; \
  gdb -nw -nx -data-directory data-directory -batch -core=many-headers.core )
[New LWP 1542]
Core was generated by `many'.
Program terminated with signal SIGSEGV, Segmentation fault.
\#0  0x0000000000400688 in ?? ()
PASS: gdb.base/many-headers.exp: read core file
...

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-02-09  Tom de Vries  <tdevries@suse.de>

	* gdb.base/many-headers.exp: Echo gdb command to gdb.log.  Capture gdb
	command output and paste it into gdb.log.  If any, paste catch message
	to gdb.log.
2020-02-09 13:30:03 +01:00
Hannes Domani 6bafc8451e Use enums for human-readable exception information.
Changes to $_siginfo type to this:

(gdb) pt $_siginfo
type = struct EXCEPTION_RECORD {
    enum ExceptionCode ExceptionCode;
    DWORD ExceptionFlags;
    struct EXCEPTION_RECORD *ExceptionRecord;
    PVOID ExceptionAddress;
    DWORD NumberParameters;
    union {
        ULONG_PTR ExceptionInformation[15];
        struct {...} AccessViolationInformation;
    };
}
(gdb) pt $_siginfo.ExceptionCode
type = enum ExceptionCode {FATAL_APP_EXIT = 1073741845,
    DBG_CONTROL_C = 1073807365, DBG_CONTROL_BREAK = 1073807368,
    DATATYPE_MISALIGNMENT = 2147483650, BREAKPOINT, SINGLE_STEP,
    ACCESS_VIOLATION = 3221225477, IN_PAGE_ERROR,
    ILLEGAL_INSTRUCTION = 3221225501, NONCONTINUABLE_EXCEPTION = 3221225509,
    INVALID_DISPOSITION, ARRAY_BOUNDS_EXCEEDED = 3221225612,
    FLOAT_DENORMAL_OPERAND, FLOAT_DIVIDE_BY_ZERO, FLOAT_INEXACT_RESULT,
    FLOAT_INVALID_OPERATION, FLOAT_OVERFLOW, FLOAT_STACK_CHECK,
    FLOAT_UNDERFLOW, INTEGER_DIVIDE_BY_ZERO, INTEGER_OVERFLOW,
    PRIV_INSTRUCTION, STACK_OVERFLOW = 3221225725, FAST_FAIL = 3221226505}
(gdb) pt $_siginfo.AccessViolationInformation
type = struct {
    enum ViolationType Type;
    PVOID Address;
}
(gdb) pt $_siginfo.AccessViolationInformation.Type
type = enum ViolationType {READ_ACCESS_VIOLATION, WRITE_ACCESS_VIOLATION,
    DATA_EXECUTION_PREVENTION_VIOLATION = 8}

Which makes it easier to understand the reason of the exception:

(gdb) p $_siginfo
$1 = {
  ExceptionCode = ACCESS_VIOLATION,
  ExceptionFlags = 0,
  ExceptionRecord = 0x0,
  ExceptionAddress = 0x401632 <main+18>,
  NumberParameters = 2,
  {
    ExceptionInformation = {1, 291, 0 <repeats 13 times>},
    AccessViolationInformation = {
      Type = WRITE_ACCESS_VIOLATION,
      Address = 0x123
    }
  }
}

gdb/ChangeLog:

2020-02-09  Hannes Domani  <ssbssa@yahoo.de>

	* windows-tdep.c (struct enum_value_name): New struct.
	(create_enum): New function.
	(windows_get_siginfo_type): Create and use enum types.
2020-02-09 12:15:50 +01:00
Hannes Domani 7928d571c5 Display ExceptionRecord for $_siginfo
Uses the $_siginfo convenience variable to show the last exception.

The type looks like this:

(gdb) pt $_siginfo
type = struct EXCEPTION_RECORD {
    DWORD ExceptionCode;
    DWORD ExceptionFlags;
    struct EXCEPTION_RECORD *ExceptionRecord;
    PVOID ExceptionAddress;
    DWORD NumberParameters;
    ULONG_PTR ExceptionInformation[15];
}

EXCEPTION_RECORD is documented at [1].

Example:

Program received signal SIGSEGV, Segmentation fault.
main () at crasher.c:4
4         *(int*)0x123 = 0;
(gdb) p $_siginfo
$1 = {
  ExceptionCode = 3221225477,
  ExceptionFlags = 0,
  ExceptionRecord = 0x0,
  ExceptionAddress = 0x401632 <main+18>,
  NumberParameters = 2,
  ExceptionInformation = {1, 291, 0 <repeats 13 times>}
}
(gdb) p/x $_siginfo.ExceptionCode
$2 = 0xc0000005
(gdb) p/x $_siginfo.ExceptionInformation[1]
$3 = 0x123

And 0xc0000005 is the value of EXCEPTION_ACCESS_VIOLATION.

[1] https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-exception_record

gdb/ChangeLog:

2020-02-09  Hannes Domani  <ssbssa@yahoo.de>

	* NEWS: Mention $_siginfo support for Windows.
	* windows-nat.c (handle_exception): Set siginfo_er.
	(windows_nat_target::mourn_inferior): Reset siginfo_er.
	(windows_xfer_siginfo): New function.
	(windows_nat_target::xfer_partial): Call windows_xfer_siginfo.
	* windows-tdep.c (struct windows_gdbarch_data): New struct.
	(init_windows_gdbarch_data): New function.
	(get_windows_gdbarch_data): New function.
	(windows_get_siginfo_type): New function.
	(windows_init_abi): Register windows_get_siginfo_type.
	(_initialize_windows_tdep): Register init_windows_gdbarch_data.

gdbserver/ChangeLog:

2020-02-09  Hannes Domani  <ssbssa@yahoo.de>

	* win32-low.c (win32_clear_inferiors): Reset siginfo_er.
	(handle_exception): Set siginfo_er.
	(win32_xfer_siginfo): New function.
2020-02-09 12:14:51 +01:00
Tom Tromey 6751ebaea0 Remove "keep" parameter from cutu_reader constructor
cutu_reader has a "keep" parameter, which is used to decide what to do
with a new CU when the reader is destroyed.  Most code does not try to
preserve the CU, so this patch removes this parameter and instead adds
a new method that users can call to preserve the CU on the chain.

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (class cutu_reader) <cutu_reader,
	init_tu_and_read_dwo_dies>: Remove "keep" parameter.
	<keep>: Declare method.
	<m_keep>: Remove member.
	<~cutu_reader>: Remove.
	(cutu_reader::init_tu_and_read_dwo_dies): Update.
	(cutu_reader::cutu_reader): Update.
	(cutu_reader::keep): Rename from ~cutu_reader.
	(process_psymtab_comp_unit, build_type_psymtabs_1)
	(process_skeletonless_type_unit, load_partial_comp_unit)
	(load_full_comp_unit, dwarf2_read_addr_index)
	(read_signatured_type): Update.

Change-Id: I859b1c64313569d76d46317c14e9b077ebc3a27b
2020-02-08 13:43:55 -07:00
Tom Tromey 135f543748 Simplify "want_partial_unit" handling
This changes the "want_partial_unit" parameters to have type bool, and
also removes the parameter from process_psymtab_comp_unit_reader.
This latter change seemed like an improvement, because it avoids a
pointless function call in the case where we are not planning to read
a partial unit.

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

	* dwarf2/read.c (process_psymtab_comp_unit_reader): Remove
	"want_partial_unit" parameter.
	(process_psymtab_comp_unit): Change want_partial_unit to bool.
	Inline check for DW_TAG_partial_unit.
	(dwarf2_build_psymtabs_hard, scan_partial_symbols): Update.

Change-Id: I99e647f0c4faa3346e90a6e7bacc82af57eccff1
2020-02-08 13:43:24 -07:00
Tom Tromey 9f66ff1c8c Move two more functions to dwarf2/leb.h
This moves read_n_bytes and read_direct_string to be with the the
low-level value-reading code.

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

	* dwarf2/read.c (read_n_bytes, read_direct_string): Move to
	read.c.
	* dwarf2/leb.h (read_n_bytes, read_direct_string): Move from
	read.c.

Change-Id: Id07bfa13d93c0ac1f47a385749a8f01f4755b818
2020-02-08 13:43:24 -07:00
Tom Tromey c8a7a66fb7 Convert read_address to a method on comp_unit_head
This changes read_address to be a method on comp_unit_head.

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

	* dwarf2/read.c (read_address): Move to comp-unit.c.
	(dwarf2_rnglists_process, dwarf2_ranges_process)
	(read_attribute_value, dwarf_decode_lines_1)
	(var_decode_location, decode_locdesc): Update.
	* dwarf2/comp-unit.c (comp_unit_head::read_address): Move from
	read.c.  Remove "cu" parameter.
	* dwarf2/comp-unit.h (struct comp_unit_head) <read_address>: New
	method.

Change-Id: Ibd6c7235f2e4d5fd88c272cfd2c3d3328618cc56
2020-02-08 13:43:24 -07:00
Tom Tromey 8266302dc3 Convert read_offset to method on comp_unit_head
This changes one of the read_offset overloads to be a method on
comp_unit_head.

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

	* dwarf2/read.c (read_attribute_value, read_indirect_string)
	(read_indirect_line_string): Update.
	* dwarf2/comp-unit.c (read_offset): Remove.
	(read_comp_unit_head): Update.
	* dwarf2/comp-unit.h (struct comp_unit_head) <read_offset>: New
	method.
	(read_offset): Don't declare.

Change-Id: Ia595702a5748337b7c031352bc437956baab9990
2020-02-08 13:43:24 -07:00
Tom Tromey 4057dfde49 Create dwarf2/comp-unit.[ch]
This creates the new files dwarf2/comp-unit.[ch], moving
comp_unit_head and helpers to those files.  A couple of functions are
turned into methods, because it was convenient to do so now.

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

	* Makefile.in (COMMON_SFILES): Add dwarf2/comp-unit.c.
	* dwarf2/read.c (struct comp_unit_head): Move to
	dwarf2/comp-unit.h.
	(enum class rcuh_kind): Move to comp-unit.h.
	(get_cu_length, offset_in_cu_p): Now methods on comp_unit_head.
	(read_comp_unit_head, error_check_comp_unit_head)
	(read_and_check_comp_unit_head): Move to comp-unit.c.
	(read_offset, dwarf_unit_type_name): Likewise.
	(create_debug_type_hash_table, read_cutu_die_from_dwo)
	(cutu_reader::cutu_reader, read_call_site_scope)
	(find_partial_die, follow_die_offset): Update.
	* dwarf2/comp-unit.h: New file, from dwarf2read.c.

Change-Id: Id961b9674c0081ed061083c8152c38b27b27388a
2020-02-08 13:43:24 -07:00
Tom Tromey 24aa364d60 Move read_offset_1 to leb.c
This moves read_offset_1 to leb.c, as it is a low-level data-reading
function.  It is also renamed to remove the "_1", because gdb can use
overloading now, and this is clearer.

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

	* dwarf2/read.c (read_offset_1): Move to leb.c.
	(read_abbrev_offset, read_offset, dwarf_decode_line_header)
	(dwarf_decode_macro_bytes): Update.
	* dwarf2/leb.c (read_offset): Rename; move from read.c.
	* dwarf2/leb.h (read_offset): Declare.

Change-Id: I048140598acfa76eade2cc529ab7933d4b9ca0b3
2020-02-08 13:43:24 -07:00
Tom Tromey 2c7d5afccf Convert dwarf2_section_size to a method
This changes dwarf2_section_size to be a method on
dwarf2_section_info.

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

	* dwarf2/read.c (dwarf2_section_size): Remove.
	(error_check_comp_unit_head, dwarf2_symbol_mark_computed):
	Update.
	* dwarf2/section.h (struct dwarf2_section_info) <get_size>: New method.

Change-Id: I12928fee5c84350ce98883e329357b86888d639b
2020-02-08 13:43:24 -07:00
Tom Tromey 4075cb2668 Unify read_initial_length implementations
There are two implementations of read_initial_length in gdb.  This
merges them and moves the resulting function to leb.c.

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

	* dwarf2/read.c (read_initial_length): Move to leb.c.
	* dwarf2/leb.h (read_initial_length): Declare.
	* dwarf2/leb.c (read_initial_length): Move from read.c.  Add
	handle_nonstd parameter.
	* dwarf2/frame.c (read_initial_length): Remove.
	(decode_frame_entry_1): Update.

Change-Id: I34d37bad0f8a584bfa781432cba25e05e1bd5750
2020-02-08 13:43:24 -07:00
Tom Tromey 09ba997f32 Add some methods to dwarf2_per_cu_data
This changes a few helper functions to be methods on
dwarf2_per_cu_data.

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

	* dwarf2/loc.c (dwarf2_find_location_expression)
	(dwarf_evaluate_loc_desc::get_tls_address)
	(dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value)
	(rw_pieced_value, dwarf2_evaluate_loc_desc_full)
	(dwarf2_locexpr_baton_eval, dwarf2_evaluate_property)
	(dwarf2_compile_property_to_c)
	(dwarf2_loc_desc_get_symbol_read_needs)
	(dwarf2_compile_expr_to_ax, locexpr_describe_location)
	(locexpr_tracepoint_var_ref, locexpr_generate_c_location)
	(loclist_describe_location, loclist_tracepoint_var_ref)
	(loclist_generate_c_location): Update.
	* compile/compile-loc2c.c (do_compile_dwarf_expr_to_c): Update.
	* dwarf2/loc.h (dwarf2_per_cu_objfile, dwarf2_per_cu_addr_size)
	(dwarf2_per_cu_ref_addr_size, dwarf2_per_cu_offset_size)
	(dwarf2_per_cu_text_offset, dwarf2_version): Don't declare.
	* dwarf2/read.c (dwarf2_per_cu_data::objfile)
	(dwarf2_per_cu_data::addr_size)
	(dwarf2_per_cu_data::ref_addr_size)
	(dwarf2_per_cu_data::text_offset)
	(dwarf2_per_cu_data::addr_type): Now methods.
	(per_cu_header_read_in): Make per_cu "const".
	(dwarf2_version): Remove.
	(dwarf2_per_cu_data::int_type): Now a method.
	(dwarf2_per_cu_data::_addr_sized_int_type): Likewise.
	(set_die_type, read_array_type, read_subrange_index_type)
	(read_tag_string_type, read_subrange_type): Update.
	* dwarf2/read.h (struct dwarf2_per_cu_data) <addr_size,
	offset_size, ref_addr_size, text_offset, addr_type, version,
	objfile, int_type, addr_sized_int_type>: Declare methods.

Change-Id: I07a42fa26e00795352389fa7a0cc1c12997d26f7
2020-02-08 13:43:24 -07:00
Tom Tromey 96c738c02f Move dwarf2_per_cu_data::imported_symtabs earlier
This moves dwarf2_per_cu_data::imported_symtabs earlier, near where
the other data members are located.

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

	* dwarf2/read.h (struct dwarf2_per_cu_data) <imported_symtabs>:
	Move earlier.

Change-Id: I314ddaa6f67c53a848e513b3f6d42913bd957833
2020-02-08 13:43:24 -07:00
Tom Tromey 8fdd972c30 Move DWARF line_header to new file
This moves the line_header class to a pair of new files, making
dwarf2/read.c somewhat smaller.

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

	* dwarf2/read.h (dwarf_line_debug): Declare.
	* Makefile.in (COMMON_SFILES): Add dwarf2/line-header.c.
	* dwarf2/read.c: Move line_header code to new files.
	(dwarf_line_debug): No longer static.
	* dwarf2/line-header.c: New file.
	* dwarf2/line-header.h: New file.

Change-Id: I8d9d8a2398b4e888e20cc5dd68d041c28b5a06e3
2020-02-08 13:43:24 -07:00
Tom Tromey 0307581275 Change line_table methods to return unique_xmalloc_ptr
This changes the two new line_table methods to return
unique_xmalloc_ptr.  This removes a bit of manual memory management.

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

	* dwarf2/read.c (struct line_header) <file_full_name,
	file_file_name>: Return unique_xmalloc_ptr.
	(line_header::file_file_name): Update.
	(line_header::file_full_name): Update.
	(dw2_get_file_names_reader): Update.
	(macro_start_file): Update.

Change-Id: I9442dba43882fb26097d0770a291eea2b03913a4
2020-02-08 13:43:24 -07:00
Tom Tromey bb82240439 Change file_full_name and file_file_name methods
This changes file_full_name and file_file_name methods to be methods
on line_header.  This seems more clear to me.

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

	* dwarf2/read.c (struct line_header) <file_full_name,
	file_file_name>: Declare methods.
	(dw2_get_file_names_reader): Update.
	(file_file_name): Now a method.
	(file_full_name): Likewise.
	(macro_start_file): Update.

Change-Id: I50d3e91665a9637c732e1e8d8e4263764c766d9c
2020-02-08 13:43:24 -07:00
Tom Tromey 009b64fc98 Move dwarf_always_disassemble to dwarf2/loc.c
dwarf_always_disassemble is only used in dwarf2/loc.c, so move the
definition and the command infrastructure to that file.

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

	* dwarf2/read.c (dwarf_always_disassemble)
	(show_dwarf_always_disassemble): Move to loc.c.
	(_initialize_dwarf2_read): Move "always-disassemble" registration
	to loc.c.
	* dwarf2/read.h (dwarf_always_disassemble): Don't declare.
	* dwarf2/loc.c (dwarf_always_disassemble): Move from read.c.  Now
	static.
	(show_dwarf_always_disassemble): Move from read.c.
	(_initialize_dwarf2loc): Move always-disassemble from read.c.

Change-Id: I33fb88112e98e583c3f4919d20e4d100f2ea0124
2020-02-08 13:43:24 -07:00
Tom Tromey 5895093f4a Change dwarf2_per_objfile::quick_file_names_table to htab_up
This changes dwarf2_per_objfile::quick_file_names_table to be an
htab_up.  This just removes a bit of manual management.

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

	* dwarf2/read.c (~dwarf2_per_objfile): Update.
	(create_quick_file_names_table): Return htab_up.
	(dw2_get_file_names_reader, dw2_forget_cached_source_info):
	Update.
	* dwarf2/read.h (struct dwarf2_per_objfile)
	<quick_file_names_table>: Now htab_up.

Change-Id: I4ff2fce8b8af27f4bfe01a11b97a889edfd23151
2020-02-08 13:43:24 -07:00
Tom Tromey b3b3227982 Minor simplification in abbrev_table::read
abbrev_table::read increments cur_abbrev->num_attrs in the inner loop,
but there's no need to do this, as the information is already stored
in the temporary vector.

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

	* dwarf2/abbrev.c (abbrev_table::read): Simplify.

Change-Id: I765f12850ffa1c6066e884bb22c94468d1abdba4
2020-02-08 13:43:24 -07:00
Tom Tromey 1d33d811c7 Use htab_up in abbrev_table
This changes abbrev_table to use an htab_up rather than an ad hoc,
bucket-based hash table.

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

	* dwarf2/abbrev.c (abbrev_table): Move constructor from header.
	Rewrite.
	(abbrev_table::add_abbrev, abbrev_table::lookup_abbrev): Rewrite.
	* dwarf2/abbrev.h (struct abbrev_info) <next>: Remove.
	(abbrev_table::abbrev_table): No longer inline.
	(ABBREV_HASH_SIZE): Remove.
	(abbrev_table::m_abbrevs): Now an htab_up.

Change-Id: Icbaa8e49501f9c43218d6a81a7e8c4d3a77d65dc
2020-02-08 13:43:24 -07:00
Tom Tromey 86de1d91ac Minor cleanups in abbrev_table
This cleans up the DWARF abbrev_table API a bit, primarily by making
various methods and members private.

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

	* dwarf2/read.c (read_cutu_die_from_dwo): Update.
	(cutu_reader): Update.
	(build_type_psymtabs_1): Update.
	* dwarf2/abbrev.c (abbrev_table::read): Rename.
	(abbrev_table::alloc_abbrev): Update.
	* dwarf2/abbrev.h (abbrev_table_up): Move earlier.
	(abbrev_table::read): New static method, renamed from
	abbrev_table_read_table.
	(abbrev_table::alloc_abbrev)
	(abbrev_table::add_abbrev): Now private.
	(abbrev_table::abbrev_table): Now private.
	(abbrev_table::m_abbrev_obstack): Now private.  Rename.

Change-Id: I320dca83b799f672909ae66f73b7aca266adbaf9
2020-02-08 13:43:24 -07:00
Tom Tromey 0335378b4c Change dwarf2_per_objfile::die_type_hash to htab_up
This changes dwarf2_per_objfile::die_type_hash to be an htab_up,
moving its contents off the objfile obstack.

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

	* dwarf2/read.c (set_die_type, get_die_type_at_offset): Update.
	* dwarf2/read.h (struct dwarf2_per_objfile) <die_type_hash>: Now
	htab_up.

Change-Id: Ic651f99ebf71bf7ad2dc2880192adacf7b60964a
2020-02-08 13:43:24 -07:00
Tom Tromey 48b490f28a Change dwp_file to use htab_up
This changes dwp_file to use htab_up for the loaded_cus and loaded_tus
members.  This lets us avoid allocating the contents of these hash
tables on the objfile obstack.

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

	* dwarf2/read.c (struct dwp_file) <loaded_cus, loaded_tus>: Now
	htab_up.
	(lookup_dwo_unit_in_dwp): Update.
	(allocate_dwp_loaded_cutus_table): Return htab_up.  Don't allocate
	on obstack.

Change-Id: Id61209bf5c6c6faa0c067195af31fbcf26813a3a
2020-02-08 13:43:24 -07:00
Tom Tromey bc68fb1930 Don't allocate DWO file hash on obstack
This changes allocate_dwo_file_hash_table so that it does not use the
objfile obstack to store the contents of the hash table.

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

	* dwarf2/read.c (allocate_dwo_file_hash_table): Don't allocate on
	obstack.

Change-Id: Ic20a618acc7277e56aa18580c68f75c793bef97b
2020-02-08 13:43:24 -07:00
Tom Tromey d15acc4252 Change dwarf2_per_objfile::line_header_hash to htab_up
This changes dwarf2_per_objfile::line_header_hash to be an htab_up,
and changes it to use heap allocation.

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

	* dwarf2/read.c (~dwarf2_per_objfile): Don't delete
	line_header_hash.
	(handle_DW_AT_stmt_list): Update.  Don't allocate on obstack.
	* dwarf2/read.h (struct dwarf2_per_objfile) <line_header_hash>:
	Change type to htab_up.

Change-Id: Icb148a270838c0f96f38fc4a28b5b77d067927b6
2020-02-08 13:43:24 -07:00
Tom Tromey eaa5fa8b29 Change dwarf2_per_objfile::type_unit_groups to htab_up
This changes dwarf2_per_objfile::type_unit_groups to be an htab_up,
again allowing us to move the memory used by the hash table from the
objfile obstack to the heap.

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

	* dwarf2/read.c (allocate_type_unit_groups_table): Return
	htab_up.  Don't allocate on obstack.
	(get_type_unit_group, dwarf2_build_psymtabs_hard): Update.
	* dwarf2/read.h (struct dwarf2_per_objfile) <type_unit_groups>:
	Change type to htab_up.

Change-Id: Ia045df0ff3ec30aac813da5a9a2314a607ef7ec8
2020-02-08 13:43:24 -07:00
Tom Tromey b0b6a9878a Change dwarf2_per_objfile::signatured_types to be htab_up
This changes dwarf2_per_objfile::signatured_types to be an htab_up.
This in turn lets us change it not to use the objfile obstack for
allocation; obstack allocation for hash tables is a bad practice
because it leads to excess memory use if the table is ever resized.

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.h (struct dwarf2_per_objfile) <signatured_types>:
	Change type to htab_up.
	* dwarf2/read.c (create_signatured_type_table_from_index)
	(create_signatured_type_table_from_debug_names)
	(create_all_type_units, add_type_unit)
	(lookup_dwo_signatured_type, lookup_signatured_type)
	(process_skeletonless_type_unit): Update.
	(create_debug_type_hash_table, create_debug_types_hash_table):
	Change type of types_htab.
	(allocate_signatured_type_table, allocate_dwo_unit_table): Return
	htab_up.  Don't allocate on obstack.
	(create_cus_hash_table): Change type of cus_htab parameter.
	(struct dwo_file) <cus, tus>: Now htab_up.
	(lookup_dwo_signatured_type, lookup_dwo_cutu)
	(process_dwo_file_for_skeletonless_type_units, lookup_dwo_cutu)
	(queue_and_load_all_dwo_tus): Update.
	* dwarf2/index-write.c (write_gdbindex): Update.
	(write_debug_names): Update.

Change-Id: I290a209b96945fb5f415c82723b62830e9c4b467
2020-02-08 13:43:03 -07:00
Tom Tromey 39856def4f Remove DWARF queue-related globals
This removes some queue-related globals from the DWARF reader, in
favor of a new member on dwarf2_per_objfile.  Globals must be avoided
in this code, because they prevent multi-threading the reader.

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.h (struct dwarf2_queue_item): Move from
	dwarf2/read.c.  Remove "next" member.  Add constructor ntad
	destructor.
	(struct dwarf2_per_objfile) <queue>: New member.
	* dwarf2/read.c (struct dwarf2_queue_item): Move to
	dwarf2/read.h.
	(dwarf2_queue, dwarf2_queue_tail): Remove.
	(class dwarf2_queue_guard): Add parameter to constructor.  Use
	DISABLE_COPY_AND_ASSIGN.
	<m_per_objfile>: New member.
	<~dwarf2_queue_guard>: Rewrite.
	(dw2_do_instantiate_symtab, queue_comp_unit, process_queue):
	Update.
	(~dwarf2_queue_item): New.

Change-Id: Ied1f6ff3691352a66c4709b0b2cba0588f49f79a
2020-02-08 13:41:00 -07:00
Tom Tromey 3e22507450 Introduce die_info::has_children
Many functions take a "has_children" parameter (either as an in- or
out-parameter).  However, it seems to me that it makes more sense to
have "has_children" be an attribute of a DIE.  Making this change
allows this parameter to be eliminated in many places.

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (struct die_info) <has_children>: New member.
	(dw2_get_file_names_reader): Remove has_children.
	(dw2_get_file_names): Update.
	(read_cutu_die_from_dwo): Remove has_children.
	(cutu_reader::init_tu_and_read_dwo_dies)
	(cutu_reader::cutu_reader): Update.
	(process_psymtab_comp_unit_reader, build_type_psymtabs_reader):
	Remove has_children.
	(build_type_psymtabs_1, process_skeletonless_type_unit)
	(load_partial_comp_unit, load_full_comp_unit): Update.
	(create_dwo_cu_reader): Remove has_children.
	(create_cus_hash_table, read_die_and_children): Update.
	(read_full_die_1,read_full_die): Remove has_children.
	(read_signatured_type): Update.
	(class cutu_reader) <has_children>: Remove.

Change-Id: I0d3d51ae9379554a66032648d51124bba07f87b4
2020-02-08 13:40:59 -07:00
Tom Tromey 82ca895718 Move DWARF code to dwarf2/ subdirectory
This moves all the remaining DWARF code to the new dwarf2
subdirectory.  This is just a simple renaming, with updates to
includes as needed.

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2/expr.c: Rename from dwarf2expr.c.
	* dwarf2/expr.h: Rename from dwarf2expr.h.
	* dwarf2/frame-tailcall.c: Rename from dwarf2-frame-tailcall.c.
	* dwarf2/frame-tailcall.h: Rename from dwarf2-frame-tailcall.h.
	* dwarf2/frame.c: Rename from dwarf2-frame.c.
	* dwarf2/frame.h: Rename from dwarf2-frame.h.
	* dwarf2/index-cache.c: Rename from dwarf-index-cache.c.
	* dwarf2/index-cache.h: Rename from dwarf-index-cache.h.
	* dwarf2/index-common.c: Rename from dwarf-index-common.c.
	* dwarf2/index-common.h: Rename from dwarf-index-common.h.
	* dwarf2/index-write.c: Rename from dwarf-index-write.c.
	* dwarf2/index-write.h: Rename from dwarf-index-write.h.
	* dwarf2/loc.c: Rename from dwarf2loc.c.
	* dwarf2/loc.h: Rename from dwarf2loc.h.
	* dwarf2/read.c: Rename from dwarf2read.c.
	* dwarf2/read.h: Rename from dwarf2read.h.
	* dwarf2/abbrev.c, aarch64-tdep.c, alpha-tdep.c,
	amd64-darwin-tdep.c, arc-tdep.c, arm-tdep.c, bfin-tdep.c,
	compile/compile-c-symbols.c, compile/compile-cplus-symbols.c,
	compile/compile-loc2c.c, cris-tdep.c, csky-tdep.c, findvar.c,
	gdbtypes.c, guile/scm-type.c, h8300-tdep.c, hppa-bsd-tdep.c,
	hppa-linux-tdep.c, i386-darwin-tdep.c, i386-linux-tdep.c,
	i386-tdep.c, iq2000-tdep.c, m32c-tdep.c, m68hc11-tdep.c,
	m68k-tdep.c, microblaze-tdep.c, mips-tdep.c, mn10300-tdep.c,
	msp430-tdep.c, nds32-tdep.c, nios2-tdep.c, or1k-tdep.c,
	riscv-tdep.c, rl78-tdep.c, rs6000-tdep.c, rx-tdep.c, s12z-tdep.c,
	s390-tdep.c, score-tdep.c, sh-tdep.c, sparc-linux-tdep.c,
	sparc-tdep.c, sparc64-linux-tdep.c, sparc64-tdep.c, tic6x-tdep.c,
	tilegx-tdep.c, v850-tdep.c, xstormy16-tdep.c, xtensa-tdep.c:
	Update.
	* Makefile.in (COMMON_SFILES): Update.
	(HFILES_NO_SRCDIR): Update.

Change-Id: Ied9ce1436cd27ac4a4cffef10ec92e396f181928
2020-02-08 13:40:59 -07:00
Tom Tromey 9e35d49961 Remove die_reader_specs::comp_dir
die_reader_specs::comp_dir is assigned but never read; this patch
removes it.

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (struct die_reader_specs) <comp_dir>: Remove.
	(init_cu_die_reader, read_cutu_die_from_dwo): Update.

Change-Id: I9818a2593197a6972cddec23cd2f3dd0ce28f580
2020-02-08 13:40:58 -07:00
Tom Tromey 1eba2311e1 Don't declare die_info in dwarf2read.h
There's no need to forward-declare struct die_info in dwarf2read.h.

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2read.h (struct die_info): Don't declare.

Change-Id: I0b8dbf99558b9547d418cfd8ef387a21f7dfa660
2020-02-08 13:40:58 -07:00
Tom Tromey e41c2da2dd Remove die_info_ptr typedef
die_info_ptr is not used and so can be removed.

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2read.h (die_info_ptr): Remove typedef.

Change-Id: Ibd0a5ad55876dc96a35b658adc36348f01e48884
2020-02-08 13:40:57 -07:00
Tom Tromey 4fc6c0d534 Change attr_form_is_block to be a method
This changes attr_form_is_block to be a method.  This is done
separately because, unlike the other attribute functions,
attr_form_is_block had special handling for the case where the
argument was NULL.  This required auditing each call site; in most
cases, NULL was already ruled out, but in a few spots, an additional
check was needed.

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (read_call_site_scope)
	(handle_data_member_location, dwarf2_add_member_fn)
	(mark_common_block_symbol_computed, read_common_block)
	(attr_to_dynamic_prop, partial_die_info::read)
	(var_decode_location, dwarf2_fetch_die_loc_sect_off)
	(dwarf2_symbol_mark_computed, set_die_type): Update.
	* dwarf2/attribute.h (struct attribute) <form_is_block>: Declare
	method.
	(attr_form_is_block): Don't declare.
	* dwarf2/attribute.c (attribute::form_is_block): Now a method.

Change-Id: Idfb290c61d738301ab991666f43e0b9cf577b2ae
2020-02-08 13:40:57 -07:00
Tom Tromey cd6c91b4f8 Change some attribute functions to be methods
This changes most of the attribute-related functions to be methods.
(attr_form_is_block changed in a subsequent patch.)

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (dwarf2_find_base_address, )
	(read_call_site_scope, rust_containing_type)
	(dwarf2_get_pc_bounds, dwarf2_record_block_ranges)
	(handle_data_member_location, dwarf2_add_member_fn)
	(get_alignment, read_structure_type, process_structure_scope)
	(mark_common_block_symbol_computed, read_common_block)
	(read_tag_string_type, attr_to_dynamic_prop, read_subrange_type)
	(partial_die_info::read, read_attribute_value, new_symbol)
	(lookup_die_type, dwarf2_get_ref_die_offset)
	(dwarf2_get_attr_constant_value, follow_die_ref_or_sig)
	(dwarf2_fetch_die_loc_sect_off, get_DW_AT_signature_type)
	(dwarf2_symbol_mark_computed): Update.
	* dwarf2/attribute.h (struct attribute) <value_as_address,
	form_is_section_offset, form_is_constant, form_is_ref>: Declare
	methods.
	(value_as_address, attr_form_is_section_offset)
	(attr_form_is_constant, attr_form_is_ref): Don't declare.
	* dwarf2/attribute.c (attribute::value_as_address)
	(attribute::form_is_section_offset, attribute::form_is_constant)
	(attribute::form_is_ref): Now methods.

Change-Id: I320dad13002c59b848dc86c39d5d7111c8a15bdc
2020-02-08 13:40:56 -07:00
Tom Tromey 162dce5526 Create dwarf2/attribute.[ch]
This moves the attribute-related code out of dwarf2read.c and into the
new files dwarf2/attribute.[ch].

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (struct attribute, DW_STRING)
	(DW_STRING_IS_CANONICAL, DW_UNSND, DW_BLOCK, DW_SND, DW_ADDR)
	(DW_SIGNATURE, struct dwarf_block, attr_value_as_address)
	(attr_form_is_block, attr_form_is_section_offset)
	(attr_form_is_constant, attr_form_is_ref): Move.
	* dwarf2/attribute.h: New file.
	* dwarf2/attribute.c: New file, from dwarf2read.c.
	* Makefile.in (COMMON_SFILES): Add dwarf2/attribute.c.

Change-Id: I1ea4c146256a1b9e38b66f1c605d782a14eeded7
2020-02-08 13:40:56 -07:00
Tom Tromey 3054dd5470 Create dwarf2/abbrev.[ch]
This moves the abbrev table code out of dwarf2read.c and into new
files dwarf2/abbrev.[ch].

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (abbrev_table_up, struct abbrev_info)
	(struct attr_abbrev, ABBREV_HASH_SIZE, struct abbrev_table):
	Move.
	(read_cutu_die_from_dwo, build_type_psymtabs_1): Update.
	(abbrev_table::alloc_abbrev, abbrev_table::add_abbrev)
	(abbrev_table::lookup_abbrev, abbrev_table_read_table): Move to
	abbrev.c.
	* dwarf2/abbrev.h: New file.
	* dwarf2/abbrev.c: New file, from dwarf2read.c.
	* Makefile.in (COMMON_SFILES): Add dwarf2/abbrev.c.

Change-Id: I87911bc5297de4407587ca849fef8e8d19136c30
2020-02-08 13:40:55 -07:00
Tom Tromey 96b792931f Change section functions to be methods of dwarf2_section_info
This changes various section-related functions to be methods on
dwarf2_section_info.  I think this clarifies the role of these
functions.  This also changes one such function to return bool.

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (dwarf2_section_buffer_overflow_complaint)
	(dwarf2_section_size, dwarf2_get_section_info)
	(create_signatured_type_table_from_debug_names)
	(create_addrmap_from_aranges, read_debug_names_from_section)
	(get_gdb_index_contents_from_section, read_comp_unit_head)
	(error_check_comp_unit_head, read_abbrev_offset)
	(create_debug_type_hash_table, init_cu_die_reader)
	(read_cutu_die_from_dwo, dwarf2_build_psymtabs_hard)
	(read_comp_units_from_section, create_cus_hash_table)
	(create_dwp_hash_table, create_dwo_unit_in_dwp_v1)
	(create_dwp_v2_section, dwarf2_rnglists_process)
	(dwarf2_ranges_process, read_die_and_siblings, read_full_die)
	(abbrev_table_read_table, read_indirect_string_at_offset_from)
	(read_indirect_string_from_dwz, read_addr_index_1)
	(read_str_index, dwarf_decode_line_header, skip_form_bytes)
	(dwarf_decode_macro_bytes, dwarf_decode_macros)
	(fill_in_loclist_baton): Update.
	* dwarf2/section.h (struct dwarf2_section_info) <get_name,
	get_containing_section, get_bfd_owner, get_bfd_section,
	get_file_name, get_id, get_flags, empty, read>: Declare methods.
	(dwarf2_read_section, get_section_name, get_section_file_name)
	(get_containing_section, get_section_bfd_owner)
	(get_section_bfd_section, get_section_name, get_section_file_name)
	(get_section_id, get_section_flags, dwarf2_section_empty_p): Don't
	declare.
	* dwarf2/section.c (dwarf2_section_info::get_containing_section)
	(dwarf2_section_info::get_bfd_owner)
	(dwarf2_section_info::get_bfd_section)
	(dwarf2_section_info::get_name)
	(dwarf2_section_info::get_file_name, dwarf2_section_info::get_id)
	(dwarf2_section_info::get_flags, dwarf2_section_info::empty)
	(dwarf2_section_info::read): Now methods.
	* dwarf-index-write.c (class debug_names): Update.

Change-Id: Ic849f182f57a18bad6b1c7c3b9368005d307758a
2020-02-08 13:40:55 -07:00
Tom Tromey 2c86cff96f Create dwarf2/section.[ch]
This moves some section-handling code from dwarf2read.c into new
files, dwarf2/section.[ch].

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2read.h (struct dwarf2_section_info, dwarf2_read_section):
	Move to dwarf2/section.h.
	* dwarf2read.c (get_containing_section, get_section_bfd_owner)
	(get_section_bfd_section, get_section_name)
	(get_section_file_name, get_section_id, get_section_flags)
	(dwarf2_section_empty_p, dwarf2_read_section): Moe to
	dwarf2/section.c.
	* dwarf2/section.h: New file.
	* dwarf2/section.c: New file, from dwarf2read.c.
	* Makefile.in (COMMON_SFILES): Add dwarf2/section.c.

Change-Id: I9f8498094cf99d9521e9481622ce8adbd453daf4
2020-02-08 13:40:54 -07:00
Tom Tromey f4382c45a4 Create dwarf2/leb.[ch]
This moves some scalar-unpacking code into a couple of new files,
dwarf2/leb.h and dwarf2/leb.c.

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2read.h (read_unsigned_leb128): Don't declare.
	* dwarf2read.c (read_1_byte, read_1_signed_byte, read_2_bytes)
	(read_2_signed_bytes, read_3_bytes, read_4_bytes)
	(read_4_signed_bytes, read_8_bytes): Move to dwarf2/leb.h.
	(read_unsigned_leb128, read_signed_leb128): Move to dwarf2/leb.c.
	* dwarf2/leb.h: New file, from dwarf2read.c.
	* dwarf2/leb.c: New file, from dwarf2read.c.
	* dwarf2-frame.c (read_1_byte, read_4_bytes, read_8_bytes):
	Remove.
	* Makefile.in (CONFIG_SRC_SUBDIR): Add dwarf2.
	(COMMON_SFILES): Add dwarf2/leb.c.

Change-Id: Idd19647686c8f959d226a95fdfca4db47c6e96d0
2020-02-08 13:40:54 -07:00
Joel Brobecker 01840b7a09 Document the GDB 9.1 release in gdb/ChangeLog
gdb/ChangeLog:

	GDB 9.1 released.
2020-02-08 17:02:16 +04:00
Iain Buclaw dfcb27e41d Make fputs_unfiltered use fputs_maybe_filtered
This patch redefines fputs_unfiltered in utils.c, with new behavior to
forward parameters to fputs_maybe_filtered.  This makes
fputs_unfiltered identical to fputs_filtered, except filtering is
disabled.

Some callers of fputs_unfiltered have been updated to use ui_file_puts
where they were using other ui_file_* functions anyway for IO.

This fixes the problem I saw with \032\032post-prompt annotation being
flushed to stdout in the wrong order.

2020-02-05  Iain Buclaw  <ibuclaw@gdcproject.org>

	PR gdb/25190:
        * gdb/remote-sim.c (gdb_os_write_stderr): Update.
        * gdb/remote.c (remote_console_output): Update.
        * gdb/ui-file.c (fputs_unfiltered): Rename to...
        (ui_file_puts): ...this.
        * gdb/ui-file.h (ui_file_puts): Add declaration.
        * gdb/utils.c (emit_style_escape): Update.
        (flush_wrap_buffer): Update.
        (fputs_maybe_filtered): Update.
        (fputs_unfiltered): Add function.

Change-Id: I17ed5078f71208344f2f8ab634a6518b1af6e213
2020-02-07 14:06:03 -07:00
Iain Buclaw faa17681cc Make gdb_flush also flush the wrap buffer
This changes gdb_flush to also flush the internal wrap buffer.  A few
places needed to continue using the previous approach, so this also
introduces ui_file_flush for those.

2020-02-05  Iain Buclaw  <ibuclaw@gdcproject.org>

        * gdb/event-loop.c (gdb_wait_for_event): Update.
        * gdb/printcmd.c (printf_command): Update.
        * gdb/remote-fileio.c (remote_fileio_func_write): Update.
        * gdb/remote-sim.c (gdb_os_flush_stdout): Update.
        (gdb_os_flush_stderr): Update.
        * gdb/remote.c (remote_console_output): Update.
        * gdb/ui-file.c (gdb_flush): Rename to...
        (ui_file_flush): ...this.
        (stderr_file::write): Update.
        (stderr_file::puts): Update.
        * gdb/ui-file.h (gdb_flush): Rename to...
        (ui_file_flush): ...this.
        * gdb/utils.c (gdb_flush): Add function.
        * gdb/utils.h (gdb_flush): Add declaration.

Change-Id: I7ca143d30f03dc39f218f6e880eb9bca9e15af39
2020-02-07 14:06:02 -07:00
Tom Tromey 5abbbe1d13 Revert basenames_may_differ patch
Commit a0c1ffedc regressed certain cases coming from Eclipse.
See PR breakpoints/24915.

gdb/ChangeLog
2020-02-07  Tom Tromey  <tromey@adacore.com>

	PR breakpoints/24915:
	* source.c (find_and_open_source): Do not check basenames_may_differ.

gdb/testsuite/ChangeLog
2020-02-07  Tom Tromey  <tromey@adacore.com>

	PR breakpoints/24915:
	* gdb.base/annotate-symlink.exp: Use setup_xfail.

Change-Id: Iadbf42f35eb40c95ad32b2108ae25d8f199998bd
2020-02-07 14:05:56 -07:00
Tom Tromey 919adfe840 Move gdbserver to top level
This patch moves gdbserver to the top level.

This patch is as close to a pure move as possible -- gdbserver still
builds its own variant of gnulib and gdbsupport.  Changing this will
be done in a separate patch.

[v2] Note that, per Simon's review comment, this patch changes the
tree so that gdbserver is not built for or1k or score.  This makes
sense, because there is apparently not actually a gdbserver port here.

[v3] This version of the patch also splits out some configury into a
new file, gdbserver/configure.host, so that the top-level configure
script can simply rely on it in order to decide whether gdbserver
should be built.

[v4] This version adds documentation and removes some unnecessary
top-level dependencies.

[v5] Update docs to mention "make all-gdbserver" and change how
top-level configure decides whether to build gdbserver, switching to a
single, shared script.

Tested by the buildbot.

ChangeLog
2020-02-07  Tom Tromey  <tom@tromey.com>
	    Pedro Alves  <palves@redhat.com>

	* src-release.sh (GDB_SUPPORT_DIRS): Add gdbserver.
	* gdbserver: New directory, moved from gdb/gdbserver.
	* configure.ac (host_tools): Add gdbserver.
	Only build gdbserver on certain systems.
	* Makefile.in, configure: Rebuild.
	* Makefile.def (host_modules, dependencies): Add gdbserver.
	* MAINTAINERS: Add gdbserver.

gdb/ChangeLog
2020-02-07  Tom Tromey  <tom@tromey.com>

	* README: Update gdbserver documentation.
	* gdbserver: Move to top level.
	* configure.tgt (build_gdbserver): Remove.
	* configure.ac: Remove --enable-gdbserver.
	* configure: Rebuild.
	* Makefile.in (distclean): Don't mention gdbserver.

Change-Id: I826b7565b54604711dc7a11edea0499cd51ff39e
2020-02-07 08:42:25 -07:00
Shahab Vahedi 1d5d29e73f gdb: Catch exceptions if the source file is not found
The source_cache::ensure method may throw an exception through
the invocation of source_cache::get_plain_source_lines. This
happens when the source file is not found. The expected behaviour
of "ensure" is only returning "true" or "false" according to the
documentation in the header file.

So far, if gdb is in source layout and a file is missing, you see
some outputs like below:

 ,---------------------------------------------.
 | test.c file is loaded in the source window. |
 |                                             |
 | int main()                                  |
 | ...                                         |
 |---------------------------------------------|
 | Remote debugging using :1234                |
 | __start () at /path/to/crt0.S:141           |
 | /path/to/crt0.S: No such file or directory. |
 | (gdb) p/x $pc                               |
 | $1 = 0x124                                  |
 | (gdb) n                                     |
 | /path/to/crt0.S: No such file or directory. |
 | (gdb) p/x $pc                               |
 | $2 = 0x128                                  |
 | (gdb) [pressing arrow-down key]             |
 | (gdb) terminate called after throwing an    |
 |       instance of 'gdb_exception_error'     |
 `---------------------------------------------'
Other issues have been encountered as well [1].

The patch from Pedro [2] which is about preventing exceptions
from crossing the "readline" mitigates the situation by not
causing gdb crash, but still there are lots of errors printed:

 ,---------------------------------------------.
 | test.c file is loaded in the source window. |
 |                                             |
 | int main()                                  |
 | ...                                         |
 |---------------------------------------------|
 | Remote debugging using :1234                |
 | __start () at /path/to/crt0.S:141           |
 | /path/to/crt0.S: No such file or directory. |
 | (gdb) [pressing arrow-down key]             |
 | /path/to/crt0.S: No such file or directory. |
 | (gdb) [pressing arrow-down key]             |
 | /path/to/crt0.S: No such file or directory. |
 | (gdb) [pressing arrow-up key]               |
 | /path/to/crt0.S: No such file or directory. |
 `---------------------------------------------'

With the changes of this patch, the behavior is like:
 ,---------------------------------------------.
 | initially, source window is empty because   |
 | crt0.S is not found and according to the    |
 | program counter that is the piece of code   |
 | being executed.                             |
 |                                             |
 | later, when we break at main (see commands  |
 | below), this window will be filled with the |
 | the contents of test.c file.                |
 |---------------------------------------------|
 | Remote debugging using :1234                |
 | __start () at /path/to/crt0.S:141           |
 | (gdb) p/x $pc                               |
 | $1 = 0x124                                  |
 | (gdb) n                                     |
 | (gdb) p/x $pc                               |
 | $2 = 0x128                                  |
 | (gdb) b main                                |
 | Breakpoint 1 at 0x334: file test.c, line 8. |
 | (gdb) cont                                  |
 | Continuing.                                 |
 | Breakpoint 1, main () at hello.c:8          |
 | (gdb) n                                     |
 | (gdb)                                       |
 `---------------------------------------------'

There is no crash and the error message is completely
gone. Maybe it is good practice that the error is
shown inside the source window.

I tested this change against gdb.base/list-missing-source.exp
and there was no regression.

[1]
It has also been observed in the past that the register
values are not transferred from qemu's gdb stub, see:
https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/issues/226

[2]
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=2f267673f0fdee9287e6d404ecd4f2d29da0d2f2

gdb/ChangeLog:

	* source-cache.c (source_cache::ensure): Surround
	get_plain_source_lines with a try/catch.
	(source_cache::get_line_charpos): Get rid of try/catch
	and only check for the return value of "ensure".
	* tui/tui-source.c (tui_source_window::set_contents):
	Simplify "nlines" calculation.

gdb/testsuite/ChangeLog:

	* gdb.tui/tui-missing-src.exp: Add the "missing source
	file" test for the TUI.
2020-02-06 17:54:59 +01:00
Andrew Burgess b0999b9b45 gdb/testsuite: Avoid leaking a port number into results summary
Give a test a real name in order to avoid including a port number in
the results summary file - which makes comparing test results between
runs hard.

gdb/testsuiteChangeLog:

	* gdb.server/multi-ui-errors.exp: Give a test a real name to avoid
	including a port number in the output.

Change-Id: I19334e176ac15aee2a9732a6060c58153d9fb793
2020-02-06 16:39:20 +00:00
Shahab Vahedi 6eb1129ce0 gdb: Add myself as one of GDB maintainer
May this be the beginning of a great flow of patches.

2020-02-06  Shahab Vahedi  <shahab@synopsys.com>

	* MAINTAINERS (Write After Approval): Add myself.
2020-02-06 16:56:40 +01:00
Ali Tamur 095252be0b Disambiguate info_print_options
struct info_print_options is defined in both symtab.c and stack.c, which is
an ODR violation. So, I am renaming info_print_options and related
structs/functions in symtab.c:

info_print_options                ==> info_vars_funcs_options
info_print_options_defs           ==> info_vars_funcs_options_defs
make_info_print_options_def_group ==> make_info_vars_funcs_options_def_group
info_print_command_completer      ==> info_vars_funcs_command_completer

gdb/ChangeLog:

	* symtab.c (info_print_options): Rename to
	info_vars_funcs_options.
	(info_print_options_defs): Rename to
	info_vars_funcs_options_defs.
	(make_info_print_options_def_group): Rename to
	make_info_vars_funcs_options_def_group.
	(info_print_command_completer): Rename to
	info_vars_funcs_command_completer.
	(info_variables_command): Apply name changes.
	(info_functions_command): Likewise.
	(_initialize_symtab): Likewise.
2020-02-05 17:35:18 -08:00
Christian Biesinger c6a42d11ac Fix base class function call
This was a typo introduced in f6ac5f3d63.

Found by looking through NetBSD's GDB patches:
https://github.com/NetBSD/pkgsrc-wip/blob/master/gdb-netbsd/patches/patch-gdb_sparc-nat.h

This patch can't be tested on Linux because Linux does not use the
sparc_target template.

gdb/ChangeLog:

2020-02-05  Christian Biesinger  <cbiesinger@google.com>

	* sparc-nat.h (struct sparc_target) <xfer_partial>: Fix base class
	function call.

Change-Id: I4fa88cbdc365efe89b84cc0619b60db38718d9ce
2020-02-05 11:51:58 -06:00
Christian Biesinger c8ecdda6b6 Fix header guard name in #endif comment
Makes the comment match the macro name in the #define/#ifdef.

gdb/ChangeLog:

2020-02-05  Christian Biesinger  <cbiesinger@google.com>

	* ppc-nbsd-tdep.h: Fix macro name in #endif comment.

Change-Id: If7b2e49e65495b8eb9ed7b6c9a11277579a93a05
2020-02-05 11:35:33 -06:00
Maciej W. Rozycki f6480e7000 RISC-V/Linux/native: Factor out target description determination
In preparation for RISC-V/Linux `gdbserver' support factor out parts of
native target description determination code that can be shared between
the programs.

	gdb/
	* nat/riscv-linux-tdesc.h: New file.
	* nat/riscv-linux-tdesc.c: New file, taking code from...
	* riscv-linux-nat.c (riscv_linux_nat_target::read_description):
	... here.
	* configure.nat <linux> <riscv*>: Add nat/riscv-linux-tdesc.o to
	NATDEPFILES.
2020-02-05 17:21:12 +00:00
Alok Kumar Sharma c3b149eb76 gdb/fortran: Allow for using Flang in Fortran testing
In lib/fortran.exp, in the helper function fortran_int4, there is
currently no support for the LLVM Fortran compiler, Flang.  As a
result we return the default pattern 'unknown' to match against all
4-byte integer types, which causes many tests to fail.

The same is true for all of the other helper functions related to
finding a suitable type pattern.

This commit adds support for Flang.  There should be no change when
testing with gfortran.

gdb/testsuite/ChangeLog:

	* lib/fortran.exp (fortran_int4): Handle clang.
	(fortran_int8): Likewise.
	(fortran_real4): Likewise.
	(fortran_real8): Likewise.
	(fortran_complex4): Likewise.
	(fortran_logical4): Likewise.
	(fortran_character1): Likewise.

Change-Id: Ife0d9828f78361fbd992bf21af746042b017dafc
2020-02-04 17:17:20 +00:00
Andrew Burgess dcc9fbc6da gdb/sim: Assert that the simulator ptid is not null_ptid
We assign the simulator inferior a fake ptid.  If this ptid is ever
set to null_ptid then we are going to run into problems - the
simulator ptid is what we return from gdbsim_target::wait, and this in
turn is used to look up the inferior data with a call to
find_inferior_pid, which asserts the pid is not 0 (which it is in
null_pid).

This commit adds an assert that the simulator's fake pid is not
null_ptid.  There should be no user visible changes after this commit.

gdb/ChangeLog:

	* remote-sim.c (sim_inferior_data::sim_inferior_data): Assert that
	we don't set the fake simulator ptid to the null_ptid.

Change-Id: I6e08effe70e70855aea13c9caf4fd6913d5af56d
2020-02-04 16:46:10 +00:00
Tom de Vries f8dcc90b60 [gdb/testsuite] Add note to 'Race detection' entry in README
Add note to 'Race detection' entry in README about the possibility that
check-read1 makes failing tests pass.

gdb/testsuite/ChangeLog:

2020-02-04  Tom de Vries  <tdevries@suse.de>

	* README (Race detection): Add note.

Change-Id: I12ef2f0ec35abc5a0221585bf30e5f4f0616aa7c
2020-02-04 17:36:17 +01:00
Tom de Vries f90ac7c2bb [gdb/testsuite] Make inferior_exited_re match a single line
The current inferior_exited_re regexp contains a '.*':
...
set inferior_exited_re "(?:\\\[Inferior \[0-9\]+ \\(.*\\) exited)"
...

This means that while matching a single line:
...
$ tclsh
% set re "(?:\\\[Inferior \[0-9\]+ \\(.*\\) exited)"
(?:\[Inferior [0-9]+ \(.*\) exited)
% set line "\[Inferior 1 (process 33) exited\]\n"
[Inferior 1 (process 33) exited]

% regexp $re $line
1
...
it also matches more than one line:
...
$ tclsh
% set re "(?:\\\[Inferior \[0-9\]+ \\(.*\\) exited)"
(?:\[Inferior [0-9]+ \(.*\) exited)
% set line "\[Inferior 1 (process 33) exited\]\n\[Inferior 2 (process 44) exited\]\n"
[Inferior 1 (process 33) exited]
[Inferior 2 (process 44) exited]

% regexp $re $line
1
...

Fix this by using "\[^\n\r\]*" instead of ".*".

Build and reg-tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-02-04  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (inferior_exited_re): Use "\[^\n\r\]*" instead of ".*".

Change-Id: Id7b1dcecd8c7fda3d1ab34b4fa1364d301748333
2020-02-04 17:30:05 +01:00
Tom de Vries 780636aec0 [gdb/testsuite] Use non-capturing parentheses for inferior_exited_re
The inferior_exited_re regexp uses capturing parentheses by default:
...
set inferior_exited_re "(\\\[Inferior \[0-9\]+ \\(.*\\) exited)"
...

The parentheses are there to be able to use the expression as an atom, f.i.,
to have '+' apply to the whole regexp in "${inferior_exited_re}+".

But the capturing is not necessary, and it can be confusing because it's not
obvious in a regexp using "$inferior_exited_re (bla|bli)" that the first
captured expression is in $inferior_exited_re.

Replace by non-capturing parentheses.  If we still want to capture the
expression, we can simply (and more clearly) use "($inferior_exited_re)".

Build and reg-tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-02-04  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (inferior_exited_re): Use non-capturing parentheses.

Change-Id: I7640c6129b1ada617424d6a63730d4b119c58ef3
2020-02-04 09:53:50 +01:00
Simon Marchi 719546c44f Change ints to bools around thread_info executing/resumed
Switch thread_info::resumed to bool (thread_info::executing already is a bool),
and try to change everything more or less related to that to consistently use
true/false instead of 1/0.

gdb/ChangeLog:

	* fork-child.c (gdb_startup_inferior): Use bool instead of int.
	* gdbthread.h (class thread_info) <resumed>: Likewise.
	* infrun.c (resume_1): Likewise.
	(proceed): Likewise.
	(infrun_thread_stop_requested): Likewise.
	(stop_all_threads): Likewise.
	(handle_inferior_event): Likewise.
	(restart_threads): Likewise.
	(finish_step_over): Likewise.
	(keep_going_stepped_thread): Likewise.
	* linux-nat.c (attach_proc_task_lwp_callback): Likewise.
	(linux_handle_extended_wait): Likewise.
	* record-btrace.c (get_thread_current_frame_id): Likewise.
	* record-full.c (record_full_wait_1): Likewise.
	* remote.c (remote_target::process_initial_stop_replies): Likewise.
	* target.c (target_resume): Likewise.
	* thread.c (set_running_thread): Likewise.
2020-02-03 23:06:55 -05:00
Rogerio Alves 5d2e119328 gdb: fix powerpc disassembly tests
This patch fixes test failures power8 and power9 caused by changes on
opcodes:

The dissasembler does not emit whitespace for instructions
anymore (c2b1c27545)

The dissasembler generates extended mnemonics for some instructions
instead (aae9718e4d)

The ldmx instruction was removed. This instruction was never
implemented (6fbc939cfd)

gdb/testsuite/ChangeLog:
2020-02-03  Rogerio A. Cardoso  <rcardoso@linux.ibm.com>

	* gdb.arch/powerpc-power8.exp: Delete trailing whitespace of
	tbegin., tend. instructions. Replace bctar-, bctar+, bctarl-,
	bctarl+ extended mnemonics when avaliable by bgttar, bnstarl,
	blttar, bnetarl.
	* gdb.arch/powerpc-power8.s: Fix comments. Fix instructions
	binary for blttar, bnetarl.
	* gdb.arch/powerpc-power9.exp: Delete trailing whitespace of
	wait instruction. Delete ldmx test.
	* gdb.arch/powerpc-power9.s: Delete ldmx instruction.
2020-02-03 22:35:49 -05:00
Alok Kumar Sharma e409c542cc Fixed gdb to print arrays with very high indexes
In the function f77_print_array_1, the variable 'i' which holds the
index is of datatype 'int', while bounds are of datatype LONGEST. Due to
size of int being smaller than LONGEST, the variable 'i' stores
incorrect values for high indexes (higher than max limit of int).  Due
to this issue in sources, two abnormal behaviors are seen while printing
arrays with high indexes (please check array-bounds-high.f90) For high
indexes with negative sign, gdb prints empty array even if the array has
elements.

    (gdb) p arr
    $1 = ()

For high indexes with positive sign, gdb crashes.  We have now changed
the datatype of 'i' to LONGEST which is same as datatype of bounds.

gdb/ChangeLog:

	* f-valprint.c (f77_print_array_1): Changed datatype of index
	variable to LONGEST from int to enable it to contain bound
	values correctly.

gdb/testsuite/ChangeLog:

	* gdb.fortran/array-bounds-high.exp: New file.
	* gdb.fortran/array-bounds-high.f90: New file.

Change-Id: Ie2dce9380a249e634e2684b9c90f225e104369b7
2020-02-03 20:24:34 -05:00
Maciej W. Rozycki ee98c0daf9 RISC-V/Linux/native: Determine FLEN dynamically
Fix RISC-V native Linux support to handle a 64-bit FPU (FLEN == 64) with
both RV32 and RV64 systems, which is a part of the current Linux ABI for
hard-float systems, rather than assuming that (FLEN == XLEN) in target
description determination and that (FLEN == 64) in register access.

We can do better however and not rely on any particular value of FLEN
and probe for it dynamically, by observing that the PTRACE_GETREGSET
ptrace(2) call will only accept an exact regset size, and that will
reflect FLEN.  Therefore iterate over the call in target description
determination with a geometrically increasing regset size until a match
is marked by a successful ptrace(2) call completion or we run beyond the
maximum size we can support.

Update register accessors accordingly, using FLEN determined to size the
buffer used for NT_PRSTATUS requests and then to exchange data with the
regcache.

Also handle a glibc bug where ELF_NFPREG is defined in terms of NFPREG,
however NFPREG is nowhere defined.

	gdb/
	* riscv-linux-nat.c [!NFPREG] (NFPREG): New macro.
	(supply_fpregset_regnum, fill_fpregset): Handle regset buffer
	offsets according to FLEN determined.
	(riscv_linux_nat_target::read_description): Determine FLEN
	dynamically.
	(riscv_linux_nat_target::fetch_registers): Size regset buffer
	according to FLEN determined.
	(riscv_linux_nat_target::store_registers): Likewise.
2020-02-03 12:07:02 +00:00
Lukas Durfina b0029748ca Fix compilation error with musl in gdb/testsuite/gdb.base/fileio.c
Musl is giving warnings about these includes in this way:
warning: #warning redirecting incorrect #include <sys/errno.h> to <errno.h>
warning: #warning redirecting incorrect #include <sys/fcntl.h> to <fcntl.h>

gdb/testsuite/Changelog:

	* gdb.base/fileio.c: Remove #include of <sys/errno.h>.
	Replace #include of <sys/fcntl.h> by <fcntl.h>.
2020-02-03 14:36:17 +04:00
Shahab Vahedi aa66aac47b gdb: Do not print empty-group regs when printing general ones
When the command "info registers" (same as "info registers general"),
is issued, _all_ the registers from a tdesc XML are printed. This
includes the registers with empty register groups (set as "") which
are supposed to be only printed by "info registers all" (or "info
all-registers").

This bug got introduced after all the overhauls that the
tdesc_register_in_reggroup_p() went through. You can see that the
logic of tdesc_register_in_reggroup_p() did NOT remain the same after
all those changes:

  git difftool c9c895b9666..HEAD -- gdb/target-descriptions.c

With the current implementation, when the reg->group is an empty
string, this function returns -1, while in the working revision
(c9c895b966), it returned 0. This patch makes sure that the 0 is
returned again.

The old implementation of tdesc_register_in_reggroup_p() returned
-1 when "reggroup" was set to "all_reggroups" at line 4 below:

1  tdesc_register_reggroup_p (...)
2  {
3   ...
4   ret = tdesc_register_in_reggroup_p (gdbarch, regno, reggroup);
5   if (ret != -1)
6     return ret;
7
8   return default_register_reggroup_p (gdbarch, regno, reggroup);
9  }

As a result, the execution continued at line 8 and the
default_register_reggroup_p(..., reggroup=all_reggroups) would
return 1. However, with the current implementation of
tdesc_register_in_reggroup_p() that allows checking against any
arbitrary group name, it returns 0 when comparing the "reg->group"
against the string "all" which is the group name for "all_reggroups".
I have added a special check to cover this case and
"info all-registers" works as expected.

gdb/ChangeLog:

	* target-descriptions.c (tdesc_register_in_reggroup_p): Return 0
	when reg->group is empty and reggroup is not.

Change-Id: I9eaf9d7fb36410ed5684ae652fe4756b1b2e61a3
2020-02-01 00:25:40 +00:00
Tom de Vries 195a8287c1 [gdb/testsuite] Fix typo in gdb.server/server-kill-python.exp
Fix typo '$gdb_tst_name' -> '$gdb_test_name'.

gdb/testsuite/ChangeLog:

2020-02-01  Tom de Vries  <tdevries@suse.de>

	* gdb.server/server-kill-python.exp: Fix $gdb_tst_name typo.

Change-Id: Iad050dab0e8aad2f2692e54e398021558250f1ac
2020-02-01 00:05:42 +01:00
Tom Tromey fd9faca826 Fix ravenscar-thread.c for multi-target
ravenscar-thread.c needed a change to adapt to multi-target:
ravenscar_thread_target::mourn_inferior called the mourn_inferior
method on the target beneat -- but when the target beneath was the
remote target, this resulted in the ravenscar target being deleted.

Switching the order of the calls to unpush_target and the beneath's
mourn_inferior fixes this problem.

gdb/ChangeLog
2020-01-31  Tom Tromey  <tromey@adacore.com>

	* ravenscar-thread.c (ravenscar_thread_target::mourn_inferior):
	Call beneath target's mourn_inferior after unpushing.

Change-Id: Ia80380515c403adc40505a6b3420c9cb35754370
2020-01-31 11:38:37 +01:00
Andrew Burgess 42330a681a gdb/tui: Disassembler scrolling of very small programs
In TUI mode, if the disassembly output for the program is less than
one screen long, then currently if the user scrolls down until on the
last assembly instruction is displayed and then tries to scroll up
using Page-Up, the display doesn't update - they are stuck viewing the
last line.

If the user tries to scroll up using the Up-Arrow, then the display
scrolls normally.

What is happening is on the Page-Up we ask GDB to scroll backward the
same number of lines as the height of the TUI ASM window.  The back
scanner, which looks for a good place to start disassembling, fails to
find a starting address which will provide the requested number of new
lines before we get back to the original starting address (which is
not surprising, our whole program contains less than a screen height
of instructions), as a result the back scanner gives up and returns
the original starting address.

When we scroll with Up-Arrow we only ask the back scanner to find 1
new instruction, which it manages to do, so this scroll works.

The solution here is, when we fail to find enough instructions, to
return the lowest address we did manage to find.  This will ensure we
jump to the lowest possible address in the disassembly output.

gdb/ChangeLog:

	PR tui/9765
	* tui/tui-disasm.c (tui_find_disassembly_address): If we don't
	have enough lines to fill the screen, still return the lowest
	address we found.

gdb/testsuite/ChangeLog:

	PR tui/9765
	* gdb.tui/tui-layout-asm-short-prog.S: New file.
	* gdb.tui/tui-layout-asm-short-prog.exp: New file.

Change-Id: I6a6a7972c68a0559e9717fd8d82870b669a40af3
2020-01-31 00:41:06 +00:00
Andrew Burgess 7a27a45bc6 gdb/tui: Update help text for scroll commands
GDB has some commands ('+', '-', '<', and '>') for scrolling the SRC
and ASM TUI windows from the CMD window, however the help text for
these commands lists the arguments in the wrong order.

This commit updates the help text to match how GDB actually works, and
also extends the text to describe what the arguments mean, and what
the defaults are.

There should be no change in GDBs functionality after this commit.

gdb/ChangeLog:

	* tui/tui-win.c (_initialize_tui_win): Update help text for '+',
	'-', '<', and '>' commands.

Change-Id: Ib2624891de1f4ba983838822206304e4c3ed982e
2020-01-31 00:41:05 +00:00
Pedro Alves c47f70e2ce Fix -Werror-stringop error on infcmd.c:construct_inferior_arguments
While testing a GCC 10 build of our git HEAD, Sergio noticed an error
triggered by -Werror-stringop on
infcmd.c:construct_inferior_arguments.  One of the things the function
does is calculate the length of the string that will hold the
inferior's arguments.  GCC warns us that 'length' can be 0, which can
lead to undesired behaviour:

../../gdb/infcmd.c: In function 'char* construct_inferior_arguments(int, char**)':
../../gdb/infcmd.c:369:17: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
  369 |       result[0] = '\0';
      |       ~~~~~~~~~~^~~~~~
../../gdb/infcmd.c:368:33: note: at offset 0 to an object with size 0 allocated by 'xmalloc' here
  368 |       result = (char *) xmalloc (length);
      |                         ~~~~~~~~^~~~~~~~

The solution here is to assert that 'argc' is greater than 0 on entry,
which makes GCC understand that the loops always run at least once,
and thus 'length' is always > 0.

Tested by rebuilding.

gdb/ChangeLog:
2020-01-29  Pedro Alves  <palves@redhat.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>

	* infcmd.c (construct_inferior_arguments): Assert that
	'argc' is greater than 0.

Change-Id: Ide8407cbedcb4921de1843a6a15bbcb7676c7d26
2020-01-29 15:23:37 -05:00
Maciej W. Rozycki 287c844a33 gdbserver: Fix whitespace configure.srv damage for `i[34567]86-*-mingw*'
Fix fallout from commit 42cd72aa02 ("gdbserver: Make `make TAGS'
actually work") add a missing newline to configure.srv for
`i[34567]86-*-mingw*'.

	gdb/gdbserver/
	* configure.srv <i[34567]86-*-mingw*>: Fix whitespace damage.
2020-01-29 18:26:15 +00:00
Pedro Franco de Carvalho 548a204f7d Fix configure.srv error for Linux on PowerPC
An error in commit 42cd72aa02 caused
srv_tgtobj to be overwritten and linux-ppc-low.o to be missed when
linking gdbserver for Linux on PowerPC.  This patch fixes the error.

gdb/gdbserver/ChangeLog:
2020-01-29  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* configure.srv (powerpc*-*-linux*): Use srv_tgtobj in second
	assignment instead of srv_linux_obj.
2020-01-29 14:42:40 -03:00
Luis Machado b62a802857 Test handling of additional brk instruction patterns
New in v5:

- Use gdb_test_name for gdb_test_multiple.
- Use gdb_assert.
- Verify count matches the expected sigtraps exactly.

New in v4:

- Fix formatting nit in gdb/testsuite/gdb.arch/aarch64-brk-patterns.c.

New in v3:

- Minor formatting and code cleanups.
- Added count check to validate number of brk SIGTRAP's.
- Moved count to SIGTRAP check conditional block.

This test exercises the previous patch's code and makes sure GDB can
properly get a SIGTRAP from various brk instruction patterns.

GDB needs to be able to see the program exiting normally. If GDB doesn't
support the additional brk instructions, we will see timeouts.

We bail out with the first timeout since we won't be able to step through
the program breakpoint anyway, so it is no use carrying on.

gdb/testsuite/ChangeLog:

2020-01-29  Luis Machado  <luis.machado@linaro.org>

	* gdb.arch/aarch64-brk-patterns.c: New source file.
	* gdb.arch/aarch64-brk-patterns.exp: New test.
2020-01-29 11:26:07 -03:00
Luis Machado 5133a31537 Recognize more program breakpoint patterns
New in v3:

- Code cleanups based on reviews.

New in v2:

- Fixed misc problems based on reviews.
- Switched to using gdbarch_program_breakpoint_here_p as opposed to
gdbarch_insn_is_breakpoint.
- Fixed matching of brk instructions. Previously the mask was incorrect, which
was showing up as a few failures in the testsuite. Now it is clean.
- New testcase (separate patch).
- Moved program_breakpoint_here () to arch-utils.c and made it the default
implementation of gdbarch_program_breakpoint_here_p.

--

It was reported to me that program breakpoints (permanent ones inserted into
the code itself) other than the one GDB uses for AArch64 (0xd4200000) do not
generate visible stops when continuing, and GDB will continue spinning
infinitely.

This happens because GDB, upon hitting one of those program breakpoints, thinks
the SIGTRAP came from a delayed breakpoint hit...

(gdb) x/i $pc
=> 0x4005c0 <problem_function>: brk     #0x90f
(gdb) c
Continuing.
infrun: clear_proceed_status_thread (process 14198)
infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT)
infrun: proceed: resuming process 14198
infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 14198] at 0x4005c0
infrun: infrun_async(1)
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   14198.14198.0 [process 14198],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: handle_inferior_event status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: stop_pc = 0x4005c0
infrun: delayed software breakpoint trap, ignoring
infrun: no stepping, continue
infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 14198] at 0x4005c0
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   14198.14198.0 [process 14198],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: handle_inferior_event status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: stop_pc = 0x4005c0
infrun: delayed software breakpoint trap, ignoring
infrun: no stepping, continue
infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 14198] at 0x4005c0
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   14198.14198.0 [process 14198],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: handle_inferior_event status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: stop_pc = 0x4005c0
infrun: delayed software breakpoint trap, ignoring
infrun: no stepping, continue
infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 14198] at 0x4005c0
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   14198.14198.0 [process 14198],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: handle_inferior_event status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: stop_pc = 0x4005c0
infrun: delayed software breakpoint trap, ignoring
infrun: no stepping, continue
infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 14198] at 0x4005c0
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   14198.14198.0 [process 14198],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
...

... which is not the case.

If the program breakpoint is one GDB recognizes, then it will stop when it
hits it.

(gdb) x/i $pc
=> 0x4005c0 <problem_function>: brk     #0x0
(gdb) c
Continuing.
infrun: clear_proceed_status_thread (process 14193)
infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT)
infrun: proceed: resuming process 14193
infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 14193] at 0x4005c0
infrun: infrun_async(1)
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   14193.14193.0 [process 14193],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: handle_inferior_event status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: stop_pc = 0x4005c0
infrun: random signal (GDB_SIGNAL_TRAP)
infrun: stop_waiting
infrun: stop_all_threads
infrun: stop_all_threads, pass=0, iterations=0
infrun:   process 14193 not executing
infrun: stop_all_threads, pass=1, iterations=1
infrun:   process 14193 not executing
infrun: stop_all_threads done

Program received signal SIGTRAP, Trace/breakpoint trap.
problem_function () at brk_0.c:7
7        asm("brk %0\n\t" ::"n"(0x0));
infrun: infrun_async(0)

Otherwise GDB will keep trying to resume the inferior and will keep
seeing the SIGTRAP's, without stopping.

To the user it appears GDB has gone into an infinite loop, interruptible only
by Ctrl-C.

Also, windbg seems to use a different variation of AArch64 breakpoint compared
to GDB. This causes problems when debugging Windows on ARM binaries, when
program breakpoints are being used.

The proposed patch creates a new gdbarch method (gdbarch_program_breakpoint_here_p)
that tells GDB whether the underlying instruction is a breakpoint instruction
or not.

This is more general than only checking for the instruction GDB uses as
breakpoint.

The existing logic is still preserved for targets that do not implement this
new gdbarch method.

The end result is like so:

(gdb) x/i $pc
=> 0x4005c0 <problem_function>: brk     #0x90f
(gdb) c
Continuing.
infrun: clear_proceed_status_thread (process 16417)
infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT)
infrun: proceed: resuming process 16417
infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 16417] at 0x4005c0
infrun: infrun_async(1)
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   16417.16417.0 [process 16417],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: handle_inferior_event status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: stop_pc = 0x4005c0
infrun: random signal (GDB_SIGNAL_TRAP)
infrun: stop_waiting
infrun: stop_all_threads
infrun: stop_all_threads, pass=0, iterations=0
infrun:   process 16417 not executing
infrun: stop_all_threads, pass=1, iterations=1
infrun:   process 16417 not executing
infrun: stop_all_threads done

Program received signal SIGTRAP, Trace/breakpoint trap.
problem_function () at brk.c:7
7        asm("brk %0\n\t" ::"n"(0x900 + 0xf));
infrun: infrun_async(0)

gdb/ChangeLog:

2020-01-29  Luis Machado  <luis.machado@linaro.org>

	* aarch64-tdep.c (BRK_INSN_MASK): Define to 0xffe0001f.
	(BRK_INSN_MASK): Define to 0xd4200000.
	(aarch64_program_breakpoint_here_p): New function.
	(aarch64_gdbarch_init): Set gdbarch_program_breakpoint_here_p hook.
	* arch-utils.c (default_program_breakpoint_here_p): Moved from
	breakpoint.c.
	* arch-utils.h (default_program_breakpoint_here_p): Moved from
	breakpoint.h
	* breakpoint.c (bp_loc_is_permanent): Changed return type to bool and
	call gdbarch_program_breakpoint_here_p.
	(program_breakpoint_here): Moved to arch-utils.c, renamed to
	default_program_breakpoint_here_p, changed return type to bool and
	simplified.
	* breakpoint.h (program_breakpoint_here): Moved prototype to
	arch-utils.h, renamed to default_program_breakpoint_here_p and changed
	return type to bool.
	* gdbarch.c: Regenerate.
	* gdbarch.h: Regenerate.
	* gdbarch.sh (program_breakpoint_here_p): New method.
	* infrun.c (handle_signal_stop): Call
	gdbarch_program_breakpoint_here_p.
2020-01-29 11:25:10 -03:00
Tankut Baris Aktemur 5f440116e8 testsuite, cp: add expected failures to pass-by-ref tests for certain compilers
There exist expected failures in the pass-by-ref.exp and
pass-by-ref-2.exp tests based on the GCC and Clang version.

* GCC version <= 6 and Clang do not emit DW_AT_deleted and
  DW_AT_defaulted.

* Clang version >= 7 emits DW_AT_calling_convention, which helps the
  debugger make the right calling convention decision in some cases
  despite lacking the 'defaulted' and 'deleted' attributes.

Mark the related tests as XFAIL based on the compiler version.

Tested on X86_64 using GCC 5.5.0, 6.5.0, 7.4.0, 8.3.0, 9.2.1;
and Clang 5.0.1, 6.0.0, 7.0.0, 8.0.0, 9.0.1, 10.0.0.

gdb/testsuite/ChangeLog:
2020-01-29  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* gdb.cp/pass-by-ref-2.exp: Mark some tests as XFAIL based on the
	GCC/Clang version.
	* gdb.cp/pass-by-ref.exp: Ditto.

Change-Id: I1d8440aa438049f7c4da7f4f76f201c48550f1e4
2020-01-29 09:10:56 +01:00
Tom de Vries ee2a6fc604 [gdb/testsuite] Fix gdb.threads/watchpoint-fork.exp race
I ran into:
...
Thread 3.1 "watchpoint-fork" hit Breakpoint 3, marker () at \
  watchpoint-fork-mt.c:42^M
42      }^M
(gdb) parent2: 1945^M

FAIL: gdb.threads/watchpoint-fork.exp: child: multithreaded: breakpoint (A) \
  after the second fork (timeout)
...
The problem is that the FAILing gdb_test expects '(gdb) ' to be the last thing
printed, but the inferior prints something after that.

A similar FAIL is described in the sources in watchpoint-fork-parent.c:
...
      printf ("child%d: %d\n", nr, (int) getpid ());
      /* Delay to get both the "child%d" and "parent%d" message printed
      	 without a race breaking expect by its endless wait on `$gdb_prompt$':
         Breakpoint 3, marker () at watchpoint-fork.c:33
         33      }
         (gdb) parent2: 14223  */
      i = sleep (1);
...

I noticed that while the executables print output, the output is not verified in
the test-case, so it's merely debug output.

Fix this by:
- guarding the prints in the executables (as well as related
  sleep and setbuf calls) with #if DEBUG, and
- compiling by default with DEBUG=0.

gdb/testsuite/ChangeLog:

2020-01-29  Tom de Vries  <tdevries@suse.de>

	* gdb.threads/watchpoint-fork-child.c: Guard prints with #if DEBUG.
	* gdb.threads/watchpoint-fork-mt.c: Same.
	* gdb.threads/watchpoint-fork-parent.c: Same.
	* gdb.threads/watchpoint-fork-st.c: Same.
	* gdb.threads/watchpoint-fork.exp: Compile with DEBUG=0.

Change-Id: I63efd4c7771f96b5f5cd87ef2ab36795484ae2be
2020-01-29 08:48:53 +01:00
Hannes Domani a2236a0844 Fix library segment-address for 64bit values
The address was written as a long value, but long is always a 32bit value
on Windows, which lead to truncated addresses.
The solution was to use paddress instead.

gdb/gdbserver/ChangeLog:

2020-01-28  Hannes Domani  <ssbssa@yahoo.de>

	* server.c (handle_qxfer_libraries): Write segment-address with
	paddress.
2020-01-28 20:01:02 +01:00
Luis Machado 16b10d6e61 Harden gdb.base/step-over-syscall.exp
New in v3:
- Verify if the syscall number matches what is expected for the target.
- Used gdb_assert for one more check.

New in v2:

- Set initial values to -1 instead of 0.
- Rewrote RE to prevent unexpected matching when parsing one character at a
  time.
- Used gdb_assert for an additional check.
- Validated with check-read1

There are a couple problems with this test.

First
--

gdb.base/step-over-syscall.exp records the address of a syscall instruction
within fork/vfork/clone functions and also the address of the instruction
after that syscall instruction.

It uses these couples addresses to make sure we stepped over a syscall
instruction (fork/vfork/clone events) correctly.

The way the test fetches the addresses of the instructions is by stepi-ing
its way through the fork/vfork/clone functions until it finds a match for
a syscall. Then it stepi's once again to get the address of the next
instruction.

This assumes that stepi-ing over a syscall is working correctly and landing
in the right PC. This is not the case for AArch64/Linux, where we're
landing a couple instructions after the syscall in some cases.

The following patch lets the test execute as before, but adds a new instruction
address check using the x command as opposed to stepi.

I didn't want to change how the test works since we may also be
interested in checking if stepi-ing over the syscall under different
conditions (displaced stepping on/off) yields the same results. I don't
feel strongly about this, so i'm OK with changing how we compare PC's for
the entire test if folks decide it is reasonable.

Second
--

FAIL: gdb.base/step-over-syscall.exp: vfork: displaced=off: continue to vfork (3rd time) (the program exited)
FAIL: gdb.base/step-over-syscall.exp: vfork: displaced=off: continue to syscall insn vfork (the program is no longer running)
FAIL: gdb.base/step-over-syscall.exp: vfork: displaced=off: single step over vfork (the program is no longer running)

Depending on the glibc version we may have different code generated for the
fork/vfork/clone functions.

I ran into the situation where vfork for newer glibc's on AArch64/Linux is
very short, so "break vfork" will put a breakpoint right at the syscall
instruction, which is something the testcase isn't expecting (a off-by-1
of sorts).

The patch adds extra code to handle this case. If the test detects we're
already sitting at a syscall instruction, it records the address and moves
on to record the address after that particular instruction.

Another measure is to "break *$syscall" instead of "break $syscall". That
guarantees we're stopping at the first instruction of the syscall function,
if it ever happens that the syscall instruction is the first instruction of
those functions.

With these changes i can fix some failures for aarch64-linux-gnu and also
expose the problems i've reported here:

https://sourceware.org/ml/gdb-patches/2019-12/msg01071.html

These tests now fail for aarch64-linux-gnu (patch for this is going through
reviews):

FAIL: gdb.base/step-over-syscall.exp: vfork: displaced=off: pc after stepi matches insn addr after syscall
FAIL: gdb.base/step-over-syscall.exp: vfork: displaced=on: pc after stepi matches insn addr after syscall

gdb/testsuite/ChangeLog:

2020-01-27  Luis Machado  <luis.machado@linaro.org>

	* gdb.base/step-over-syscall.exp (setup): Check if we're already
	sitting at a syscall instruction when we hit the syscall function's
	breakpoint.
	Check PC against one obtained with the x command.
	Validate syscall number.
	(step_over_syscall): Don't continue to the syscall instruction if
	we're already there.
2020-01-27 17:28:06 -03:00
Tom Tromey 168f8c6ba0 Two minor changes in ctfread.c
I noticed a couple of minor issues in ctfread.c, both fixed by this
patch:

* ctf_fp_info was not indented properly; and
* _initialize_ctfread is no longer needed

gdb/ChangeLog
2020-01-26  Tom Tromey  <tom@tromey.com>

	* ctfread.c (struct ctf_fp_info): Reindent.
	(_initialize_ctfread): Remove.

Change-Id: I72707b74bc59e6e426b3a7bc8843d96c0d786f1e
2020-01-26 18:44:41 -07:00
Tom Tromey 128a391fe4 Virtualize "readin" and "compunit_symtab"
This patch removes the "readin" and "compunit_symtab" members from
partial_symtab, replacing them with methods.  Then it introduces a new
"standard_psymtab" class, which restores these members; and changes
the symbol readers to use this intermediate class as the base class of
their partial symtab subclasses.

The reason for this is to make it possible for a symbol reader to
implement an alternate mapping between partial and full symbol tables.
This is important in order to be able to share psymtabs across
objfiles -- whether a psymtab has been "readin" is objfile-dependent,
as are the pointers to the full symbol tables.

gdb/ChangeLog
2020-01-26  Tom Tromey  <tom@tromey.com>

	* psymtab.c (partial_map_expand_apply)
	(psym_find_pc_sect_compunit_symtab, psym_lookup_symbol)
	(psymtab_to_symtab, psym_find_last_source_symtab, dump_psymtab)
	(psym_print_stats, psym_expand_symtabs_for_function)
	(psym_map_symbol_filenames, psym_map_matching_symbols)
	(psym_expand_symtabs_matching)
	(partial_symtab::read_dependencies, maintenance_info_psymtabs)
	(maintenance_check_psymtabs): Use new methods.
	* psympriv.h (struct partial_symtab) <readin_p,
	get_compunit_symtab>: New methods.
	<readin, compunit_symtab>: Remove members.
	(struct standard_psymtab): New.
	(struct legacy_psymtab): Derive from standard_psymtab.
	* dwarf2read.h (struct dwarf2_psymtab): Derive from
	standard_psymtab.
	* ctfread.c (struct ctf_psymtab): Derive from standard_psymtab.

Change-Id: Idb923f196d7e03bf7cb9cfc8134ed06dd3f211ce
2020-01-26 16:40:21 -07:00
Tom Tromey 0494dbecdf Consolidate partial symtab dependency reading
Most of the symbol readers have code to iterate over a partial symtabs
dependencies, expanding each one and optionally printing a message.
Now that the "second-stage" psymtab expansion is available as a
method, these implementations can all be merged.

This patch also changes a couple more warnings into assertions.

gdb/ChangeLog
2020-01-26  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (xcoff_psymtab_to_symtab_1): Call
	read_dependencies.  Add assert.
	* psymtab.c (partial_symtab::read_dependencies): New method.
	* psympriv.h (struct partial_symtab) <read_dependencies>: New
	method.
	* mdebugread.c (psymtab_to_symtab_1): Call read_dependencies.
	* dwarf2read.c (dwarf2_psymtab::expand_psymtab): Call
	read_dependencies.
	* dbxread.c (dbx_psymtab_to_symtab_1): Call read_dependencies.
	Add assert.

Change-Id: I8151e05677794e90223edc1a4cb70f7f69137d46
2020-01-26 16:40:21 -07:00
Tom Tromey 8566b89b73 Introduce partial_symtab::expand_psymtab method
The symbol readers generally used two functions to expand a partial
symtab: an outer function (now the "read_symtab" method), and an inner
function, typically named something like "psymtab_to_symtab".

This patch changes this second step to be a method on partial_symtab,
and updates all the callers.  For legacy_psymtab, a new function
pointer member is introduced.

This patch enables a subsequent cleanup.

gdb/ChangeLog
2020-01-26  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (xcoff_psymtab_to_symtab_1): Change argument order.
	Call expand_psymtab.
	(xcoff_read_symtab): Call expand_psymtab.
	(xcoff_start_psymtab, xcoff_end_psymtab): Set
	legacy_expand_psymtab.
	* psympriv.h (struct partial_symtab) <expand_psymtab>: New
	method.
	(struct legacy_psymtab) <expand_psymtab>: Implement.
	<legacy_expand_psymtab>: New member.
	* mdebugread.c (mdebug_read_symtab): Call expand_psymtab.
	(parse_partial_symbols): Set legacy_expand_psymtab.
	(psymtab_to_symtab_1): Change argument order.  Call
	expand_psymtab.
	(new_psymtab): Set legacy_expand_psymtab.
	* dwarf2read.h (struct dwarf2_psymtab) <expand_psymtab>: Declare.
	* dwarf2read.c (dwarf2_psymtab::read_symtab): Call
	expand_psymtab.
	(dwarf2_psymtab::expand_psymtab): Rename from
	psymtab_to_symtab_1.  Call expand_psymtab.
	* dbxread.c (start_psymtab): Set legacy_expand_psymtab.
	(dbx_end_psymtab): Likewise.
	(dbx_psymtab_to_symtab_1): Change argument order. Call
	expand_psymtab.
	(dbx_read_symtab): Call expand_psymtab.
	* ctfread.c (struct ctf_psymtab) <expand_psymtab>: Declare.
	(ctf_psymtab::expand_psymtab): Rename from psymtab_to_symtab.
	(ctf_psymtab::read_symtab): Call expand_psymtab.

Change-Id: Ic39a2d7aa7b424088d910b59dbd21271fa1c3430
2020-01-26 16:40:21 -07:00
Tom Tromey 077cbab270 Consolidate psymtab "Reading" messages
Each symbol reader implemented its own "Reading..." messages, and most
of them double-checked that a previously-expanded psymtab could not be
re-read.

This patch consolidates the message-printing, and changes these checks
into asserts.

gdb/ChangeLog
2020-01-26  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (xcoff_read_symtab): Remove prints.  Add assert.
	* psymtab.c (psymtab_to_symtab): Print verbose "Reading"
	messages.
	* mdebugread.c (mdebug_read_symtab): Remove prints.
	* dwarf2read.c (dwarf2_psymtab::read_symtab): Remove prints.  Add
	assert.
	* dbxread.c (dbx_read_symtab): Remove prints.  Add assert.

Change-Id: I795be9710d42708299bb7b44972cffd27aec9413
2020-01-26 16:40:21 -07:00
Tom Tromey 891813beaa Introduce partial_symtab::read_symtab method
This introduces a new partial_symtab::read_symtab method, and updates
the symbol readers to subclass partial_symtab and implement this
method.  The old read_symtab and read_symtab_private members are
removed.

In practice, only DWARF and CTF are truly updated to take advantage of
the new setup.  The other symbol readers are less actively maintained,
and so this patch also introduces a "legacy_psymtab", which
essentially works the same way as the old partial_symtab.

(Note that, without more knowledge of the interaction between these
symbol readers, fixing this to remove the new (small) overhead is not
trivial, because these readers copy the read_symtab pointer between
partial symtabs.)

gdb/ChangeLog
2020-01-26  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (this_symtab_psymtab, read_xcoff_symtab)
	(xcoff_psymtab_to_symtab_1, xcoff_read_symtab)
	(xcoff_start_psymtab, xcoff_end_psymtab, scan_xcoff_symtab): Use
	legacy_symtab.
	* stabsread.h (dbx_end_psymtab): Use legacy_symtab.
	* psymtab.c (psymtab_to_symtab): Call method.
	(dump_psymtab): Update.
	* psympriv.h (struct partial_symtab): Add virtual destructor.
	<read_symtab>: New method.
	(struct legacy_symtab): New.
	* mdebugread.c (mdebug_read_symtab): Use legacy_psymtab.
	(struct pst_map) <pst>: Now a legacy_psymtab.
	(parse_procedure, parse_partial_symbols, psymtab_to_symtab_1)
	(new_psymtab): Use legacy_psymtab.
	* dwarf2read.h (struct dwarf2_psymtab): New.
	(struct dwarf2_per_cu_data) <psymtab>: Use it.
	* dwarf2read.c (dwarf2_create_include_psymtab)
	(dwarf2_build_include_psymtabs, create_type_unit_group)
	(create_partial_symtab, process_psymtab_comp_unit_reader)
	(build_type_psymtabs_reader, build_type_psymtab_dependencies)
	(set_partial_user): Use dwarf2_psymtab.
	(dwarf2_psymtab::read_symtab): Rename from dwarf2_read_symtab.
	(psymtab_to_symtab_1, process_full_comp_unit)
	(process_full_type_unit, dwarf2_ranges_read)
	(dwarf2_get_pc_bounds, psymtab_include_file_name)
	(dwarf_decode_lines): Use dwarf2_psymtab.
	* dwarf-index-write.c (psym_index_map): Use dwarf2_psymtab.
	(add_address_entry_worker, write_one_signatured_type)
	(recursively_count_psymbols, recursively_write_psymbols)
	(write_one_signatured_type, psyms_seen_size, write_gdbindex)
	(write_debug_names): Likewise.
	* dbxread.c (struct header_file_location): Take a legacy_psymtab.
	<pst>: Now a legacy_psymtab.
	(find_corresponding_bincl_psymtab): Return a legacy_psymtab.
	(read_dbx_symtab, start_psymtab, dbx_end_psymtab)
	(dbx_psymtab_to_symtab_1, read_ofile_symtab): Use legacy_psymtab.
	* ctfread.c (struct ctf_psymtab): New.
	(ctf_start_symtab, ctf_end_symtab, psymtab_to_symtab): Take a
	ctf_psymtab.
	(ctf_psymtab::read_symtab): Rename from ctf_read_symtab.
	(create_partial_symtab): Return a ctf_psymtab.
	(scan_partial_symbols): Update.

Change-Id: Ia57a828786867d6ad03200af8f996f48ed15285e
2020-01-26 16:40:21 -07:00
Tom Tromey c3693a1d94 Turn start_psymtab_common into a constructor
This turns start_psymtab_common into a constructor, and then changes
the callers to use "new" directly.  This completes the psymtab
allocation transition -- now it is possible for symbol readers to
subclass struct partial_symtab.

gdb/ChangeLog
2020-01-26  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (xcoff_start_psymtab): Use new.
	* psymtab.c (partial_symtab::partial_symtab): New constructor,
	renamed from start_psymtab_common.
	* psympriv.h (struct partial_symtab): Add new constructor.
	(start_psymtab_common): Don't declare.
	* mdebugread.c (parse_partial_symbols): Use new.
	* dwarf2read.c (create_partial_symtab): Use new.
	* dbxread.c (start_psymtab): Use new.
	* ctfread.c (create_partial_symtab): Use new.

Change-Id: I5a0217bcb52bcfa442559771954bb66bd9ccbf02
2020-01-26 16:40:21 -07:00
Tom Tromey 32caafd02b Change allocate_psymtab to be a constructor
This is the next step in getting the symbol readers to allocate
psymtabs themselves: change allocate_psymtab to be an ordinary
constructor, and then use "new" at the previous call sites.  Note that
this doesn't get us all the way -- start_psymtab_common is still
allocating a partial symtab.

gdb/ChangeLog
2020-01-26  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (xcoff_end_psymtab): Use new.
	* psymtab.c (start_psymtab_common): Use new.
	(partial_symtab::partial_symtab): Rename from allocate_psymtab.
	Update.
	* psympriv.h (struct partial_symtab): Add parameters to
	constructor.  Don't inline.
	(allocate_psymtab): Don't declare.
	* mdebugread.c (new_psymtab): Use new.
	* dwarf2read.c (dwarf2_create_include_psymtab): Use new.
	* dbxread.c (dbx_end_psymtab): Use new.

Change-Id: Iffeae64c925050b90b9916cbc36e15b26ff42226
2020-01-26 16:40:21 -07:00