binutils-gdb.git
4 years ago[PATCH] gas: Fix comment on definition of frag_grow()
Nick Clifton [Thu, 28 May 2020 13:30:34 +0000 (14:30 +0100)]
[PATCH] gas: Fix comment on definition of frag_grow()

* frags.c (frag_grow): Fix comment.

4 years agoFix "'operator new' should not return NULL" errors in testsuite
Gary Benson [Thu, 28 May 2020 13:18:36 +0000 (14:18 +0100)]
Fix "'operator new' should not return NULL" errors in testsuite

When running the testsuite with clang, gdb.linespec/cpls-ops.cc
fails to compile with the following errors:
  warning: 'operator new' should not return a null pointer unless
    it is declared 'throw()' or 'noexcept' [-Wnew-returns-null]
  warning: 'operator new[]' should not return a null pointer unless
    it is declared 'throw()' or 'noexcept' [-Wnew-returns-null]

This prevents the gdb.linespec/cpls-ops.exp testcase from executing.
This commit fixes.

gdb/testsuite/ChangeLog:

* gdb.linespec/cpls-ops.cc (dummy): New static global.
(test_op_new::operator new): Add return statement.
(test_op_new_array::operator new[]): Likewise.

4 years agoubsan: nios2: undefined shift
Alan Modra [Thu, 28 May 2020 12:37:11 +0000 (22:07 +0930)]
ubsan: nios2: undefined shift

* nios2-dis.c (nios2_print_insn_arg): Avoid shift left of negative
values.

4 years agoPR26044, Some targets can't be compiled with GCC 10 (tilepro)
Alan Modra [Thu, 28 May 2020 09:16:17 +0000 (18:46 +0930)]
PR26044, Some targets can't be compiled with GCC 10 (tilepro)

Since this value is used in fields of type tilepro_pipeline (as
NO_PIPELINE, see tc-tilepro.c) it is appropriate to put it in
the tilepro_pipelen enum.  This avoids a warning about converting from
one enum type to another.

PR 26044
* opcode/tilepro.h (TILEPRO_NUM_PIPELINE_ENCODINGS): Move to
tilepro_pipeline enum.

4 years agoasan: ns32k: use of uninitialized value
Alan Modra [Thu, 28 May 2020 08:06:31 +0000 (17:36 +0930)]
asan: ns32k: use of uninitialized value

* ns32k-dis.c (print_insn_arg): Handle d value of 'f' for
immediates.
(print_insn_ns32k): Revert last change.

4 years agold: Mention --enable-textrel-check=yes is default for Linux/x86 targets
H.J. Lu [Thu, 28 May 2020 11:36:33 +0000 (04:36 -0700)]
ld: Mention --enable-textrel-check=yes is default for Linux/x86 targets

* NEWS: Mention --enable-textrel-check=yes is default for
Linux/x86 targets.

4 years agold: Enable --warn-textrel by default for Linux/x86 targets
H.J. Lu [Thu, 28 May 2020 11:27:08 +0000 (04:27 -0700)]
ld: Enable --warn-textrel by default for Linux/x86 targets

* configure.tgt (ac_default_ld_textrel_check): Set to if unset
for Linux/x86 targets.

4 years agold: Add --enable-textrel-check=[no|yes|warning|error]
H.J. Lu [Thu, 28 May 2020 11:21:04 +0000 (04:21 -0700)]
ld: Add --enable-textrel-check=[no|yes|warning|error]

Add a configure option, --enable-textrel-check=[no|yes|warning|error],
to decide what ELF linker should do by default with DT_TEXTREL in an
executable or shared library.

PR ld/20824
* NEWS: Mention --enable-textrel-check=[no|yes|warning|error].
* configure.ac: Add --enable-textrel-check=[no|yes|warning|error].
(DEFAULT_LD_TEXTREL_CHECK): New AC_DEFINE_UNQUOTED.
(DEFAULT_LD_TEXTREL_CHECK_WARNING): Likewise.
* ldmain.c (main): Initialize link_info.textrel_check to
DEFAULT_LD_TEXTREL_CHECK.
* lexsup.c (ld_options): Check DEFAULT_LD_TEXTREL_CHECK_WARNING.
* config.in: Regenerated.
* configure: Likewise.

4 years agoFix a potential use of an uninitialised value in the ns32k disassembler.
Nick Clifton [Thu, 28 May 2020 10:04:27 +0000 (11:04 +0100)]
Fix a potential use of an uninitialised value in the ns32k disassembler.

* ns32k-dis.c (print_insn_ns32k): Change the arg_bufs array to
static.

4 years agoLinker: Remove support for -Map= with an empty argument.
Nick Clifton [Thu, 28 May 2020 09:51:29 +0000 (10:51 +0100)]
Linker: Remove support for -Map= with an empty argument.

* lexsup.c (parse_args): Generate an error if a name is not
provided to the -Map option.
(ld_options): Mention that the -Map option supports a directory
name as an argument.
* NEWS: Remove mention of support for an empty string as an
argument to -Map.
* ld.texi: Likewise.

4 years agoFix PR gas/26001 (pdp11-*-*)
Stephen Casner [Thu, 28 May 2020 01:40:38 +0000 (18:40 -0700)]
Fix PR gas/26001 (pdp11-*-*)

PR gas/26001
* gas/config/tc-pdp11.c (parse_reg): Distinguish register names from
symbols that begin with a register name.
* gas/testsuite/gas/pdp11/pdp11.exp: Add test of such symbols.
* gas/testsuite/gas/pdp11/pr26001.s: Likewise.
* gas/testsuite/gas/pdp11/pr26001.d: Likewise.

4 years agoAutomatic date update in version.in
GDB Administrator [Thu, 28 May 2020 00:00:16 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agoRISC-V: Fix missing initialization of riscv_csr_extra structs
Simon Cook [Wed, 27 May 2020 16:34:58 +0000 (17:34 +0100)]
RISC-V: Fix missing initialization of riscv_csr_extra structs

The next pointer of struct riscv_csr_extra was not always initilized
to NULL or a valid pointer, causing the assembler to attempt to read
through an uninitialized pointer on startup.

gas/ChangeLog:

        * config/tc-riscv.c (riscv_init_csr_hash): NULL initilize next
        pointer when creating struct riscv_csr_extra.

4 years agoPR ld/22909 amendment; don't xfail ld-elf/pr19539.d for cris*-*-*.
Hans-Peter Nilsson [Wed, 27 May 2020 21:14:45 +0000 (23:14 +0200)]
PR ld/22909 amendment; don't xfail ld-elf/pr19539.d for cris*-*-*.

Noticed by my autotester covering cris-axis-linux-gnu:
...
Running <x>/src/ld/testsuite/ld-elf/elf.exp ...
XPASS: ld-elf/pr19539
...

This was apparently as intended, so I'm just adjusting the xfail.

PR ld/22909
* testsuite/ld-elf/pr19539.d: Don't xfail for cris*-*-*.

4 years agocp-completion-aliases.exp: Use test_gdb_complete_{unique,multiple}
Pedro Alves [Wed, 27 May 2020 18:59:19 +0000 (19:59 +0100)]
cp-completion-aliases.exp: Use test_gdb_complete_{unique,multiple}

gdb.linespec/cp-completion-aliases.exp is calling
test_gdb_complete_{tab,cmd}_unique and
test_gdb_complete_{tab,cmd}_multiple separately for each use case.
I.e., testing once for TAB completion and once for the "complete"
command.  There's no need to do that explicitly and separately, we
have wrapper procedures to do that for us.

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

* gdb.linespec/cp-completion-aliases.exp: Remove readline_is_used
check.  Use test_gdb_complete_unique instead of
test_gdb_complete_tab_unique + test_gdb_complete_cmd_unique.  Use
test_gdb_complete_multiple instead of
test_gdb_complete_tab_multiple + test_gdb_complete_cmd_multiple.

4 years agoUse add_partial_symbol in load_partial_dies
Tom Tromey [Wed, 27 May 2020 17:48:18 +0000 (11:48 -0600)]
Use add_partial_symbol in load_partial_dies

An earlier patch added the add_partial_symbol helper function to
dwarf2/read.c.  However, a couple of calls to add_psymbol_to_list were
left in place.  It turns out that these calls slow down partial symbol
reading, because they still go via the path that tries to needlessly
demangle already-demangled names.

This patch improves the performance of partial symbol reading by
changing this code to use add_partial_symbol instead.

The run previous to this had times of (see the first patch in the
series for an explanation):

gdb    1.64
libxul 1.99
Ada    2.47

This patch improves the times to:

gdb    1.47
libxul 1.89
Ada    2.39

gdb/ChangeLog
2020-05-27  Tom Tromey  <tromey@adacore.com>

* dwarf2/read.c (load_partial_dies): Use add_partial_symbol.

4 years agoInline abbrev lookup
Tom Tromey [Wed, 27 May 2020 17:48:18 +0000 (11:48 -0600)]
Inline abbrev lookup

Profiling showed that calls to abbrev_table::lookup_abbrev were "too
visible".  As these are just forwarding calls to the hash table, this
patch inlines the lookup.  Also, htab_find_with_hash is used, avoiding
another call.

The run previous to this had times of (see the first patch in the
series for an explanation):

gdb    1.69
libxul 2.02
Ada    2.52

This patch improves the times to:

gdb    1.64
libxul 1.99
Ada    2.47

gdb/ChangeLog
2020-05-27  Tom Tromey  <tromey@adacore.com>

* dwarf2/abbrev.h (struct abbrev_table) <lookup_abbrev>: Inline.
Use htab_find_with_hash.
<add_abbrev>: Remove "abbrev_number" parameter.
* dwarf2/abbrev.c (abbrev_table::add_abbrev): Remove
"abbrev_number" parameter.  Use htab_find_slot_with_hash.
(hash_abbrev): Add comment.
(abbrev_table::lookup_abbrev): Move to header file.
(abbrev_table::read): Update.

4 years agoLazily compute partial DIE name
Tom Tromey [Wed, 27 May 2020 17:48:18 +0000 (11:48 -0600)]
Lazily compute partial DIE name

Currently the name of a partial DIE is computed eagerly.  However, the
name is not always needed.  This patch changes partial DIEs to compute
their name lazily, improving performance by avoiding unnecessary name
computations.

The run previous to this had times of (see the first patch in the
series for an explanation):

gdb    1.88
libxul 2.11
Ada    2.60

This patch improves the times to:

gdb    1.69
libxul 2.02
Ada    2.52

gdb/ChangeLog
2020-05-27  Tom Tromey  <tromey@adacore.com>

* dwarf2/read.c (struct partial_die_info) <name>: Declare new
method.
<canonical_name>: New member.
<raw_name>: Rename from "name".
(partial_die_info): Initialize canonical_name.
(scan_partial_symbols): Check raw_name.
(partial_die_parent_scope, partial_die_full_name)
(add_partial_symbol, add_partial_subprogram)
(add_partial_enumeration, load_partial_dies): Use "name" method.
(partial_die_info::name): New method.
(partial_die_info::read, guess_partial_die_structure_name)
(partial_die_info::fixup): Update.

4 years agoAttribute method inlining
Tom Tromey [Wed, 27 May 2020 17:48:18 +0000 (11:48 -0600)]
Attribute method inlining

This inlines a couple of methods on struct attribute, improving the
performance of DWARF partial symbol reading.  These methods were
discovered as hot spots using callgrind.

For this patch, and for all the patches in this series, I tested gdb's
performance on three programs:

1. gdb itself -- I built gdb and copied it to /tmp, ensuring that the
   same version was used in all tests.

2. The system libxul.so, the main library of Firefox.  I installed the
   separate debuginfo and ensured that gdb read it.

3. A large-ish Ada program that I happen to have.

I ran gdb 10 times like:

  /bin/time -f %e \
    ./gdb/gdb --data-directory ./gdb/data-directory -nx \
    -iex 'set debug-file-directory /usr/lib/debug' \
    -batch $X

... where $X was the test executable.  Then I computed the mean time.
This was all done with a standard (-g -O2) build of gdb.

The baseline times were

gdb    1.90
libxul 2.12
Ada    2.61

This patch brings the numbers down to

gdb    1.88
libxul 2.11
Ada    2.60

Not a huge change, but still visible in the results.

gdb/ChangeLog
2020-05-27  Tom Tromey  <tromey@adacore.com>

* dwarf2/attribute.h (struct attribute) <form_is_ref>: Inline.
<get_ref_die_offset>: Inline.
<get_ref_die_offset_complaint>: New method.
* dwarf2/attribute.c (attribute::form_is_ref): Move to header.
(attribute::get_ref_die_offset_complaint): Rename from
get_ref_die_offset.  Just issue complaint.

4 years agoMove exit_status_set_internal_vars out of GLOBAL_CURDIR
Hannes Domani [Sat, 23 May 2020 17:45:44 +0000 (19:45 +0200)]
Move exit_status_set_internal_vars out of GLOBAL_CURDIR

Fixes these testsuite fails on Windows:
FAIL: gdb.base/shell.exp: shell success exitcode
FAIL: gdb.base/shell.exp: shell fail exitcode

The convenience variables $_shell_exitcode and $_shell_exitsignal don't
depend on the GLOBAL_CURDIR define.

gdb/ChangeLog:

2020-05-27  Hannes Domani  <ssbssa@yahoo.de>

* cli/cli-cmds.c (shell_escape): Move exit_status_set_internal_vars.

4 years agoUse errno value of first openp failure
Hannes Domani [Wed, 13 May 2020 10:41:51 +0000 (12:41 +0200)]
Use errno value of first openp failure

Fixes this testsuite fail on Windows:
FAIL: gdb.base/bad-file.exp: directory

If both tries to open the file fail (without and with ".exe"), use the
errno value of the first try.

gdb/ChangeLog:

2020-05-27  Hannes Domani  <ssbssa@yahoo.de>

* exec.c (exec_file_attach): Use errno value of first openp failure.

4 years agoDon't close process handle provided by WaitForDebugEvent
Hannes Domani [Sun, 24 May 2020 22:18:25 +0000 (00:18 +0200)]
Don't close process handle provided by WaitForDebugEvent

Only the process handle returned by OpenProcess or CreateProcess needs to
be closed, the one provided by WaitForDebugEvent is closed automatically.

gdbserver/ChangeLog:

2020-05-27  Hannes Domani  <ssbssa@yahoo.de>

* win32-low.cc (do_initial_child_stuff): Set open_process_used.
(win32_clear_inferiors): Use open_process_used.
(get_child_debug_event): Likewise.

4 years agoDon't close thread handles provided by WaitForDebugEvent
Hannes Domani [Sun, 24 May 2020 20:59:33 +0000 (22:59 +0200)]
Don't close thread handles provided by WaitForDebugEvent

I sometimes encountered a weird breakpoint failure when using start:

(gdb) start
Temporary breakpoint 2 at 0x40162d: file gdb-25911.c, line 4.
Starting program: C:\src\tests\gdb-25911.exe
Warning:
Cannot insert breakpoint 2.
Cannot access memory at address 0x401628

After trying a lot of combinations, I found a way to reproduce it:

(gdb) file gdb-25987.exe
Reading symbols from gdb-25987.exe...
(gdb) start
Temporary breakpoint 1 at 0x401638: file gdb-25987.cpp, line 13.
Starting program: C:\src\tests\gdb-25987.exe

Temporary breakpoint 1, main () at gdb-25987.cpp:13
13      int main() {
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
MyClass::call (this=0x3d20d0) at gdb-25987.cpp:8
8           *(char*)(nullptr) = 1;
(gdb) kill
Kill the program being debugged? (y or n) y
[Inferior 1 (process 1140) killed]
(gdb) file gdb-25911.exe
Load new symbol table from "gdb-25911.exe"? (y or n) y
Reading symbols from gdb-25911.exe...
(gdb) start
Temporary breakpoint 2 at 0x40162d: file gdb-25911.c, line 4.
Starting program: C:\src\tests\gdb-25911.exe
Warning:
Cannot insert breakpoint 2.
Cannot access memory at address 0x401628

Command aborted.

The actual failure was that ReadProcessMemory used a process handle that
was no longer valid.
And the underlying reason was that the windows_thread_info destructor
closes a thread handle that was provided earlier by WaitForDebugEvent.

But since this is not allowed (and it was actually already closed at this
point, and the handle value reused), this closed another still-needed handle.

gdb/ChangeLog:

2020-05-27  Hannes Domani  <ssbssa@yahoo.de>

* nat/windows-nat.c (windows_thread_info::~windows_thread_info):
Don't close thread handle.

4 years ago [PATCH] allow empty string as argument to -Map
Nick Clifton [Wed, 27 May 2020 16:49:17 +0000 (17:49 +0100)]
 [PATCH] allow empty string as argument to -Map

* lexsup.c (parse_args): If the map filename is defined but empty
create a name based upon the output file name.  If the name is
defined but refers to a directory create a file inside the
directory based on the output file name.
* ld.texi: Document the new feature.
* testsuite/ld-script/map-address.exp: Add test of new feature.
* NEWS: Mention the new feature.

4 years agoShare DWARF partial symtabs
Tom Tromey [Wed, 27 May 2020 15:20:14 +0000 (11:20 -0400)]
Share DWARF partial symtabs

This changes the DWARF reader to share partial symtabs (or indices if
they are available) across objfiles.  This has a few parts.

* If multiple objfiles backed by the same BFD can share partial symtabs
  (see below), a single dwarf2_per_bfd is created.  It is stored in the
  per-bfd `dwarf2_per_bfd_bfd_data_key` registry.  Multiple
  dwarf2_per_objfile objects will point to the same instance.  The
  lifetime of these dwarf2_per_bfd objects is naturally handled.  When
  all the objfiles using the BFD are destroyed, the BFD's refount drops
  to 0, which triggers the removal of the corresponding dwarf2_per_bfd
  object from the registry and its destruction.

* If multiple objfiles backed by the same BFD can't share partial
  symtabs (see below), one dwarf2_per_bfd object is created for each
  objfile.  Each dwarf2_per_objfile will point to their own instance of
  dwarf2_per_bfd.  These instances of dwarf2_per_bfd are kept in a
  per-objfile registry, meaning that when the objfile gets destroyed,
  the dwarf2_per_bfd instance gets destroyed as well.

* objfile::partial_symtabs is changed to be a shared_ptr again.  This
  lets us stash a second reference in dwarf2_per_bfd; if the DWARF
  data is being shared, we can simply copy this value to the new
  objfile.

* Two dwarf2_per_objfile objects backed by the same BFD may share a
  dwarf2_per_bfd instance if:

  * No other symbol reader has found symbols, and
  * No BFD section rqeuires relocation

gdb/ChangeLog:

YYYY-MM-DD  Tom Tromey  <tom@tromey.com>
YYYY-MM-DD  Simon Marchi  <simon.marchi@efficios.com>

* objfiles.h (struct objfile) <partial_symtabs>: Now a
shared_ptr.
* dwarf2/read.h (struct dwarf2_per_objfile) <partial_symtabs>: New
member.
* dwarf2/read.c (dwarf2_per_bfd_bfd_data_key,
dwarf2_per_bfd_objfile_data_key>: New globals.
(dwarf2_has_info): Use shared dwarf2_per_bfd if possible.
(dwarf2_get_section_info): Use get_dwarf2_per_objfile.
(dwarf2_initialize_objfile): Consider cases where per_bfd can be
shared.
(dwarf2_build_psymtabs): Set objfile::partial_symtabs and
short-circuit when sharing.
(dwarf2_build_psymtabs): Set dwarf2_per_objfile::partial_symtabs.
(dwarf2_psymtab::expand_psymtab): Use free_cached_comp_units.

Change-Id: I868c64448589102ab8cbb8f06c31a8de50a14004

4 years agoMove line_header_hash to dwarf2_per_objfile
Simon Marchi [Wed, 27 May 2020 15:14:12 +0000 (11:14 -0400)]
Move line_header_hash to dwarf2_per_objfile

The `line_header_hash` field of `struct dwarf2_per_bfd` contains some
`struct line_header` objects.  A `struct line_header` objects contains
some `file_entry` objects.  A `file_entry` object contains a pointer to
the `symtab` object created from it.  The `line_header_hash` is
therefore ultimately objfile-dependent and can't be shared as-is between
objfiles.

Move it from `dwarf2_per_bfd` to `dwarf2_per_objfile`.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_bfd) <line_header_hash>: Move
to...
(struct dwarf2_per_objfile) <line_header_hash>: ... here.
* dwarf2/read.c (handle_DW_AT_stmt_list): Update.

Change-Id: I8d2ee04df4f4847c2db99061fc976c35af98ac71

4 years agoMake mapped_debug_names independent of objfile
Simon Marchi [Wed, 27 May 2020 15:14:11 +0000 (11:14 -0400)]
Make mapped_debug_names independent of objfile

mapped_debug_names currently has a dwarf2_per_objfile field.  Since we
want it to become objfile-independent, this field must be removed.

This patch removes it, and then arranges for all methods that needed it
to accept a dwarf2_per_objfile parameter.  This trickles down at various
places, like the dw2_debug_names_iterator type.

Ultimately, the objfile only seems to be needed because we might need to
read a string from the string section.  For that, we might need to read
in the section, and if it's a relocatable section, the objfile is needed
in order to do the relocation.  This pattern happens often (that we to
pass an objfile only because a section might be read).  I think it's a
bit ugly, but I don't have a good alternative right now.

gdb/ChangeLog:

* dwarf2/read.c (struct mapped_index_base) <symbol_name_at,
build_name_components, find_name_components_bounds>:
Add per_objfile parameter.
(struct mapped_index) <symbol_name_at>: Likewise.
(struct mapped_debug_names): Remove constructor.
<dwarf2_per_objfile>: Remove field.
<namei_to_name, symbol_name_at>: Add per_objfile parameter.
(mapped_index_base::find_name_components_bounds,
mapped_index_base::build_name_components,
dw2_expand_symtabs_matching_symbol): Likewise.
(class mock_mapped_index) <symbol_name_at>: Likewise.
(check_match): Likewise.
(check_find_bounds_finds): Likewise.
(test_mapped_index_find_name_component_bounds): Update.
(CHECK_MATCH): Update.
(dw2_expand_symtabs_matching): Update.
(class dw2_debug_names_iterator) <dw2_debug_names_iterator>: Add
per_objfile parameter.
<find_vec_in_debug_names>: Likewise.
<m_per_objfile>: New field.
(mapped_debug_names::namei_to_name): Add dwarf2_per_objfile
parameter.
(dw2_debug_names_iterator::find_vec_in_debug_names): Likewise.
(dw2_debug_names_iterator::next): Update.
(dw2_debug_names_lookup_symbol): Update.
(dw2_debug_names_expand_symtabs_for_function): Update.
(dw2_debug_names_map_matching_symbols): Update.
(dw2_debug_names_expand_symtabs_matching): Update.
(dwarf2_read_debug_names): Update.

Change-Id: I00ee0d939390d353442675c7d400a261307c57a1

4 years agoReplace dwarf2_per_cu_data::cu backlink with per-objfile map
Simon Marchi [Wed, 27 May 2020 15:14:11 +0000 (11:14 -0400)]
Replace dwarf2_per_cu_data::cu backlink with per-objfile map

The dwarf2_per_cu_data type is going to become objfile-independent,
while the dwarf2_cu type will stay object-dependent.  This patch removes
the backlink from dwarf2_per_cu_data to dwarf2_cu, in favor of the
dwarf2_per_objfile::m_dwarf2_cus map.  It maps dwarf2_per_cu_data
objects to the corresponding dwarf2_cu objects for this objfile.  If a
CU has been read in in the context of this objfile, then an entry will
be present in the map.

The dwarf2_cu objects that are read in are currently kept in a linked
list rooted in the dwarf2_per_bfd.  Except that the dwarf2_cu objects
are not simply linked together, they are interleaved with their
corresponding dwarf2_per_cu_data objects.  So if we have CUs A and B
read in, the dwarf2_per_bfd::read_in_chain will point to a chain like
this (DPCD == dwarf2_per_cu_data, DC == dwarf2_cu):

 DPCD A -> DC A -> DPCD B -> DC B

Obviously, this can't stay as is, since a same CU can be read in for an
objfile but not read in for another objfile sharing the same BFD, and
the dwarf2_per_cu_data::cu link is removed.   This is all replaced by
the dwarf2_per_objfile::m_dwarf2_cus map.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_cu): Forward-declare.
(struct dwarf2_per_bfd) <free_cached_comp_units>: Remove,
move to dwarf2_per_objfile.
<read_in_chain>: Remove.
(struct dwarf2_per_objfile) <get_cu, set_cu, remove_cu,
remove_all_cus, age_comp_units>: New methods.
<m_dwarf2_cus>: New member.
(struct dwarf2_per_cu_data) <cu>: Remove.
* dwarf2/read.c (struct dwarf2_cu) <read_in_chain>: Remove.
(age_cached_comp_units, free_one_cached_comp_unit): Remove,
moved to methods of dwarf2_per_objfile.
(dwarf2_clear_marks): Remove.
(dwarf2_queue_item::~dwarf2_queue_item): Update.
(dwarf2_per_bfd::~dwarf2_per_bfd): Don't free dwarf2_cus.
(dwarf2_per_bfd::free_cached_comp_units): Remove.
(dwarf2_per_objfile::remove_all_cus): New.
(class free_cached_comp_units) <~free_cached_comp_units>:
Update.
(load_cu): Update.
(dw2_do_instantiate_symtab): Adjust.
(fill_in_sig_entry_from_dwo_entry): Adjust.
(cutu_reader::init_tu_and_read_dwo_dies): Update.
(cutu_reader::cutu_reader): Likewise.
(cutu_reader::keep): Use dwarf2_per_objfile::set_cu.
(cutu_reader::cutu_reader): Use dwarf2_per_objfile::get_cu.
(process_psymtab_comp_unit): Use dwarf2_per_objfile::remove_cu
and dwarf2_per_objfile::age_comp_units.
(load_partial_comp_unit): Update.
(maybe_queue_comp_unit): Use dwarf2_per_objfile::get_cu.
(process_queue): Likewise.
(find_partial_die): Use dwarf2_per_objfile::get_cu instead of cu
backlink.
(dwarf2_read_addr_index): Likewise.
(follow_die_offset): Likewise.
(dwarf2_fetch_die_loc_sect_off): Likewise.
(dwarf2_fetch_constant_bytes): Likewise.
(dwarf2_fetch_die_type_sect_off): Likewise.
(follow_die_sig_1): Likewise.
(load_full_type_unit): Likewise.
(read_signatured_type): Likewise.
(dwarf2_cu::dwarf2_cu): Don't set cu field.
(dwarf2_cu::~dwarf2_cu): Remove.
(dwarf2_per_objfile::get_cu): New.
(dwarf2_per_objfile::set_cu): New.
(age_cached_comp_units): Rename to...
(dwarf2_per_objfile::age_comp_units): ... this.  Adjust
to std::unordered_map.
(free_one_cached_comp_unit): Rename to...
(dwarf2_per_objfile::remove_cu): ... this.  Adjust
to std::unordered_map.
(dwarf2_per_objfile::~dwarf2_per_objfile): New.
(dwarf2_mark_helper): Use dwarf2_per_objfile::get_cu, expect
a dwarf2_per_objfile in data.
(dwarf2_mark): Pass dwarf2_per_objfile in data to htab_traverse.
(dwarf2_clear_marks): Remove.

Change-Id: Ia33ac71c79b2de4710569008e22a6563a1505cde

4 years agoPass existing_cu object to cutu_reader
Simon Marchi [Wed, 27 May 2020 15:14:10 +0000 (11:14 -0400)]
Pass existing_cu object to cutu_reader

It is possible, seemingly for a special case described in
find_partial_die, for cutu_reader to re-use an existing dwarf2_cu
instead of creating a new one.  This happens when running this test, for
example:

    make check TESTS="gdb.dwarf2/fission-reread.exp"

Right now the, `use_existing_cu` flag tells cutu_reader to use the
dwarf2_cu object at dwarf2_per_cu_data::cu.  However, we'll remove that
field, so we need to find another solution.

This situation arises when some caller up the stack has already created
the dwarf2_cu to read a dwarf2_per_cu_data, but needs to re-read it with
some other parameters.  Therefore, it's possible to just have that
caller pass down the dwarf2_cu object to use as a `existing_cu`
parameter.  If `existing_cu` is NULL, it tells cutu_reader that it needs
to instantiate a new one.

gdb/ChangeLog:

* dwarf2/read.c (class cutu_reader) <cutu_reader>: Replace
`int use_existing_cu` parameter with `dwarf2_cu *existing_cu`.
(init_tu_and_read_dwo_dies): Likewise.
(cutu_reader::init_tu_and_read_dwo_dies): Likewise.
(cutu_reader::cutu_reader): Likewise.
(load_partial_comp_unit): Likewise.
(process_psymtab_comp_unit): Update.
(build_type_psymtabs_1): Update.
(process_skeletonless_type_unit): Update.
(load_full_comp_unit): Update.
(find_partial_die): Update.
(dwarf2_read_addr_index): Update.
(read_signatured_type): Update.

Change-Id: Id03e3bc3de3cf99d9e4b4080ad83b029c93bf434

4 years agoAdd comp_unit_head to dwarf2_per_cu_data
Simon Marchi [Wed, 27 May 2020 15:14:10 +0000 (11:14 -0400)]
Add comp_unit_head to dwarf2_per_cu_data

The per_cu_header_read_in function allows obtaining a filled
comp_unit_head object for a given dwarf2_per_cu_data object.  If a
dwarf2_cu object exists for this dwarf2_per_cu_data, then it just
returns a pointer to the comp_unit_head from that dwarf2_cu.  Otherwise,
it reads the header into a temporary buffer provided by the caller, and
returns a pointer to that.

Since the dwarf2_per_cu_data::cu link is going to be removed
(dwarf2_per_cu_data will become objfile-independent while dwarf2_cu
stays objfile-dependent), we cannot rely anymore on returning the header
from the dwarf2_cu object.

The not too complex solution implemented by this patch is to keep a copy
of the header in the dwarf2_per_cu_data object, independent from the
copy in dwarf2_cu.  The new copy is only used in the addr_size,
offset_size and ref_addr_size methods of dwarf2_per_cu_data.

There's nothing intrinsic to the comp_unit_head object that prevents it
to be shared between two dwarf2_cu objects (belonging to different
objfiles) representing the same CU.  In other words, I think we could
eventually get rid of the copy in dwarf2_cu to only keep the one in
dwarf2_per_cu_data.  It is not trivial, however, so I have decided not
to do it for the moment.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_cu_data) <m_header,
m_header_read_in>: New fields.
<get_header>: New method.
* dwarf2/read.c (per_cu_header_read_in): Remove.
(dwarf2_per_cu_data::get_header): New.
(dwarf2_per_cu_data::addr_size): Update.
(dwarf2_per_cu_data::offset_size): Update.
(dwarf2_per_cu_data::ref_addr_size): Update.

Change-Id: Id7541fca7562843eba110ece21c4df38d45fca23

4 years agoMake load_cu return the loaded dwarf2_cu
Simon Marchi [Wed, 27 May 2020 15:14:09 +0000 (11:14 -0400)]
Make load_cu return the loaded dwarf2_cu

In a subsequent patch, the dwarf2_per_cu_data::cu link will be removed.
dwarf2_cu objects will instead need to be looked up from a per-objfile
map, using the dwarf2_per_cu_data object as the key.

To make it easier for some callers, this patch makes load_cu return the
dwarf2_cu it creates.  If the caller needs to use the created dwarf2_cu,
it will have it available right away, rather than having to do a map
lookup.

At the same time, this allows changing queue_and_load_all_dwo_tus to
take a dwarf2_cu instead of a dwarf2_per_cu_data.

gdb/ChangeLog:

* dwarf2/read.c (load_cu): Return dwarf2_cu.
(dw2_do_instantiate_symtab): Update.
(queue_and_load_all_dwo_tus): Change parameter from
dwarf2_per_cu_data to dwarf2_cu.
(dwarf2_fetch_die_loc_sect_off): Update.
(dwarf2_fetch_constant_bytes): Update.
(dwarf2_fetch_die_type_sect_off): Update.

Change-Id: I8a04c5d1b8cc661b8203f97999258ba8e04e1765

4 years agoPass dwarf2_cu to process_full_{comp,type}_unit
Simon Marchi [Wed, 27 May 2020 15:14:09 +0000 (11:14 -0400)]
Pass dwarf2_cu to process_full_{comp,type}_unit

These two functions work on a dwarf2_cu.  It is currently obtained from
the per_cu->cu link, which we want to remove.  Make them accept the
dwarf2_cu directly as a parameter.  This moves the per_cu->cu references
one level up, but that one will be removed too in a subsequent patch.

gdb/ChangeLog:

* dwarf2/read.c (process_full_comp_unit,
process_full_type_unit): Remove per_cu, per_objfile paramters.
Add dwarf2_cu parameter.
(process_queue): Update.

Change-Id: I1027d36986073ac991e198e06f9d51341dc19c6e

4 years agoPass dwarf2_per_bfd instead of dwarf2_per_objfile to some index-related functions
Simon Marchi [Wed, 27 May 2020 15:14:08 +0000 (11:14 -0400)]
Pass dwarf2_per_bfd instead of dwarf2_per_objfile to some index-related functions

All these functions actually only need to receive a dwarf2_per_bfd, pass
that instead of dwarf2_per_objfile.

gdb/ChangeLog:

* dwarf2/read.c (create_cu_from_index_list): Replace
dwarf2_per_objfile parameter with dwarf2_per_bfd.
(create_cus_from_index_list): Likewise.
(create_cus_from_index): Likewise.
(create_signatured_type_table_from_index): Likewise.
(create_cus_from_debug_names_list): Likewise.
(create_cus_from_debug_names): Likewise.
(dwarf2_read_gdb_index): Update.
(dwarf2_read_debug_names): Update.

Change-Id: I8cd7dc04bf815723a48745e7e9b283663dccc1ac

4 years agoMove signatured_type::type to unshareable object
Tom Tromey [Wed, 27 May 2020 15:19:35 +0000 (11:19 -0400)]
Move signatured_type::type to unshareable object

signatured_type has a link to the "struct type".  However, types are
inherently objfile-specific, so once sharing is implemented, this will
be incorrect.

This patch moves the type to a new map in the DWARF unshareable
object.

gdb/ChangeLog:

YYYY-MM-DD  Tom Tromey  <tom@tromey.com>
YYYY-MM-DD  Simon Marchi  <simon.marchi@efficios.com>

* dwarf2/read.h (struct dwarf2_per_objfile)
<get_type_for_signatured_type, set_type_for_signatured_type>:
New methods.
<m_type_map>: New member.
(struct signatured_type) <type>: Remove.
* dwarf2/read.c
(dwarf2_per_objfile::get_type_for_signatured_type,
dwarf2_per_objfile::set_type_for_signatured_type): New.
(get_signatured_type): Use new methods.

Change-Id: I765ae3c43fae1064f51ced352167a57638609f02

4 years agoSplit type_unit_group
Tom Tromey [Wed, 27 May 2020 15:19:09 +0000 (11:19 -0400)]
Split type_unit_group

type_unit_group has links to the compunit_symtab and other symtabs.
However, once this object is shared across objfiles, this will no
longer be ok.

This patch introduces a new type_unit_group_unshareable and arranges to
store a map from type unit groups to type_unit_group_unshareable objects
in dwarf2_per_objfile.

gdb/ChangeLog:

YYYY-MM-DD  Tom Tromey  <tom@tromey.com>
YYYY-MM-DD  Simon Marchi  <simon.marchi@efficios.com>

* dwarf2/read.h (struct type_unit_group_unshareable): New.
(struct dwarf2_per_objfile) <type_units>: New member.
<get_type_unit_group_unshareable>: New method.
* dwarf2/read.c (struct type_unit_group) <compunit_symtab,
num_symtabs, symtabs>: Remove; move to
type_unit_group_unshareable.
(dwarf2_per_objfile::get_type_unit_group_unshareable): New.
(process_full_type_unit, dwarf2_cu::setup_type_unit_groups)
(dwarf2_cu::setup_type_unit_groups): Use type_unit_group_unshareable.

Change-Id: I1fec2fab59e0ec40fee3614fc821172a469c0e41

4 years agoRemove dwarf2_per_cu_data::dwarf2_per_objfile
Simon Marchi [Wed, 27 May 2020 15:14:06 +0000 (11:14 -0400)]
Remove dwarf2_per_cu_data::dwarf2_per_objfile

Nothing references this field anymore, remove it.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_cu_data):
<dwarf2_per_objfile>: Remove.
* dwarf2/read.c (create_cu_from_index_list): Don't assign
dwarf2_per_objfile.
(create_signatured_type_table_from_index): Likewise.
(create_signatured_type_table_from_debug_names): Likewise.
(create_debug_type_hash_table): Likewise.
(fill_in_sig_entry_from_dwo_entry): Likewise.
(create_type_unit_group): Likewise.
(read_comp_units_from_section): Likewise.
(create_cus_hash_table): Likewise.

Change-Id: Icf0b657a6beec953fe17cbe0fb2ae2c6e744d3ed

4 years agoRemove leftover references to dwarf2_per_cu_data::dwarf2_per_objfile
Simon Marchi [Wed, 27 May 2020 15:14:06 +0000 (11:14 -0400)]
Remove leftover references to dwarf2_per_cu_data::dwarf2_per_objfile

This patch removes the remaining references to that field in obvious
ways (the same object is already available some other way in these
contexts).

gdb/ChangeLog:

* dwarf2/read.c (process_psymtab_comp_unit): Remove reference to
dwarf2_per_cu_data::dwarf2_per_objfile.
(compute_compunit_symtab_includes): Likewise.
(dwarf2_cu::start_symtab): Likewise.

Change-Id: I965700fa793d8457711a2d6ae448aaefd779eb96

4 years agoAdd dwarf2_per_objfile parameter to get_die_type_at_offset
Simon Marchi [Wed, 27 May 2020 15:14:05 +0000 (11:14 -0400)]
Add dwarf2_per_objfile parameter to get_die_type_at_offset

This allows removing some dwarf2_per_cu_data::dwarf2_per_objfile
references.

gdb/ChangeLog:

* dwarf2/read.h (dwarf2_get_die_type): Add dwarf2_per_objfile
parameter.
* dwarf2/read.c (get_die_type_at_offset): Likewise.
(read_namespace_alias): Update.
(lookup_die_type): Update.
(dwarf2_get_die_type): Add dwarf2_per_objfile parameter.
* dwarf2/loc.c (class dwarf_evaluate_loc_desc) <get_base_type>:
Update.
(disassemble_dwarf_expression): Update.

Change-Id: Ibaf5b684cb0a8eb8f0b23e62bd0283c295410aa5

4 years agoAdd dwarf2_per_objfile parameter to free_one_cached_comp_unit
Simon Marchi [Wed, 27 May 2020 15:14:04 +0000 (11:14 -0400)]
Add dwarf2_per_objfile parameter to free_one_cached_comp_unit

This allows removing some references to
dwarf2_per_cu_data::dwarf2_per_objfile.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_queue_item): Add
dwarf2_per_objfile parameter, assign new parameter.
<per_objfile>: New field.
* dwarf2/read.c (free_one_cached_comp_unit): Add
dwarf2_per_objfile parameter.
(queue_comp_unit): Likewise.
(dw2_do_instantiate_symtab): Update.
(process_psymtab_comp_unit): Update.
(maybe_queue_comp_unit): Add dwarf2_per_objfile parameter.
(process_imported_unit_die): Update.
(queue_and_load_dwo_tu): Update.
(follow_die_offset): Update.
(follow_die_sig_1): Update.

Change-Id: Ibb4a4ea28eeac5ebcbf73c0d2a13f9391e15c235

4 years agoRemove dwarf2_per_cu_data::objfile ()
Simon Marchi [Wed, 27 May 2020 15:14:04 +0000 (11:14 -0400)]
Remove dwarf2_per_cu_data::objfile ()

Since dwarf2_per_cu_data objects are going to become
objfile-independent, the backlink from dwarf2_per_cu_data to one
particular objfile must be removed.  Instead, users of
dwarf2_per_cu_data that need an objfile must know from somewhere else in
the context of which objfile they are using this CU.

This also helps remove a dwarf2_per_cu_data::dwarf2_per_objfile
reference (from where the objfile was obtained).

Note that the dwarf2_per_cu_data::objfile method has a special case to
make sure to return the main objfile, if the objfile associated to the
dwarf2_per_cu_data is a separate debug objfile.  I don't really know if
this is necessary: I ignored that, and didn't see any regression when
testing with the various Dejagnu boards with separate debug info, so I
presume it wasn't needed.  If it turns out this was needed, then we can
have a helper method on the objfile type for that.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_cu_data) <objfile>: Remove.
* dwarf2/read.c (dwarf2_compute_name): Pass per_objfile down.
(read_call_site_scope): Assign per_objfile.
(dwarf2_per_cu_data::objfile): Remove.
* gdbtypes.h (struct call_site) <per_objfile>: New member.
* dwarf2/loc.h (dwarf2_evaluate_loc_desc): Add
dwarf2_per_objfile parameter.
* dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Add
dwarf2_per_objfile parameter.
(dwarf_expr_reg_to_entry_parameter): Add output
dwarf2_per_objfile parameter.
(locexpr_get_frame_base): Update.
(class dwarf_evaluate_loc_desc) <get_tls_address>: Update.
<push_dwarf_reg_entry_value>: Update.
<call_site_to_target_addr>: Update.
(dwarf_entry_parameter_to_value): Add dwarf2_per_objfile
parameter.
(value_of_dwarf_reg_entry): Update.
(rw_pieced_value): Update.
(indirect_synthetic_pointer): Update.
(dwarf2_evaluate_property): Update.
(dwarf2_loc_desc_get_symbol_read_needs): Add dwarf2_per_objfile
parameter.
(locexpr_read_variable): Update.
(locexpr_get_symbol_read_needs): Update.
(loclist_read_variable): Update.

Change-Id: Idb40d1a94995af305054d463967bb6ce11a08f25

4 years agoAdd dwarf2_per_objfile parameters to dwarf2_fetch_* functions
Simon Marchi [Wed, 27 May 2020 15:14:03 +0000 (11:14 -0400)]
Add dwarf2_per_objfile parameters to dwarf2_fetch_* functions

This allows removing dwarf2_per_cu_data references.

gdb/ChangeLog:

* dwarf2/read.h (dwarf2_fetch_die_loc_sect_off,
dwarf2_fetch_die_loc_cu_off, dwarf2_fetch_constant_bytes,
dwarf2_fetch_die_type_sect_off): Add dwarf2_per_objfile
parameter.
* dwarf2/read.c (dwarf2_fetch_die_loc_sect_off,
dwarf2_fetch_die_loc_cu_off, dwarf2_fetch_constant_bytes,
dwarf2_fetch_die_type_sect_off): Add dwarf2_per_objfile
parameter.
* dwarf2/loc.c (indirect_synthetic_pointer, per_cu_dwarf_call,
sect_variable_value): Add dwarf2_per_objfile parameter.
(class dwarf_evaluate_loc_desc) <dwarf_call,
dwarf_variable_value>: Update.
(fetch_const_value_from_synthetic_pointer): Add
dwarf2_per_objfile parameter.
(fetch_const_value_from_synthetic_pointer): Update.
(coerced_pieced_ref): Update.
(class symbol_needs_eval_context) <dwarf_call,
dwarf_variable_value>: Update.
(dwarf2_compile_expr_to_ax): Update.

Change-Id: I07cf1806380633d0572304cea049a1fa5e9ea67f

4 years agoAdd dwarf2_per_objfile parameter to allocate_piece_closure
Simon Marchi [Wed, 27 May 2020 15:14:03 +0000 (11:14 -0400)]
Add dwarf2_per_objfile parameter to allocate_piece_closure

This allows removing a dwarf2_per_cu_data::dwarf2_per_objfile reference.

gdb/ChangeLog:

* dwarf2/loc.c (allocate_piece_closure): Add dwarf2_per_objfile
parameter.
(dwarf2_evaluate_loc_desc_full): Update.

Change-Id: Ic4a694a3fc763360a131ee4e3aaf5a5b4735c813

4 years agoAdd dwarf2_per_objfile parameter to dwarf2_read_addr_index
Simon Marchi [Wed, 27 May 2020 15:14:02 +0000 (11:14 -0400)]
Add dwarf2_per_objfile parameter to dwarf2_read_addr_index

Pass it all the way from the symbol batons.  This allows removing a
dwarf2_per_cu_data::dwarf2_per_objfile reference.

gdb/ChangeLog:

* dwarf2/read.h (dwarf2_read_addr_index): Add dwarf2_per_objfile
parameter.
* dwarf2/read.c (dwarf2_read_addr_index): Likewise.
* dwarf2/loc.c (decode_debug_loclists_addresses): Add
dwarf2_per_objfile parameter.
(decode_debug_loc_dwo_addresses): Likewise.
(dwarf2_find_location_expression): Update.
(class dwarf_evaluate_loc_desc) <get_addr_index>: Update.
(locexpr_describe_location_piece): Add dwarf2_per_objfile
parameter.
(disassemble_dwarf_expression): Add dwarf2_per_objfile
parameter.
(locexpr_describe_location_1): Likewise.
(locexpr_describe_location): Update.

Change-Id: I8414755e41a87c92f96e408524cc7aaccf086cda

4 years agoRemove dwarf2_per_cu_data::text_offset
Simon Marchi [Wed, 27 May 2020 15:14:01 +0000 (11:14 -0400)]
Remove dwarf2_per_cu_data::text_offset

This method simply returns the text offset of the objfile associated to
the dwarf2_per_cu_data object.  Since dwarf2_per_cu_data objects are
going to become objfile-independent, we can't keep this method.  This
patch removes it.

Existing callers need to figure out the in the context of which objfile
this is being used, and call text_offset on it.  Typically, this comes
from a symbol baton, where we store the corresponding
dwarf2_per_objfile.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_cu_data) <text_offset>:
Remove.
* dwarf2/read.c (dwarf2_per_cu_data::text_offset): Remove.
* dwarf2/loc.c (dwarf2_find_location_expression): Update.
(dwarf2_compile_property_to_c): Update.
(dwarf2_compile_expr_to_ax): Add dwarf2_per_objfile parameter,
use text offset from objfile.
(locexpr_tracepoint_var_ref): Update.
(locexpr_generate_c_location): Update.
(loclist_describe_location): Update.
(loclist_tracepoint_var_ref): Update.
* dwarf2/compile.h (compile_dwarf_bounds_to_c): Add
dwarf2_per_objfile parameter.
* dwarf2/loc2c.c (do_compile_dwarf_expr_to_c): Likewise,
use text offset from objfile.
(compile_dwarf_expr_to_c): Add dwarf2_per_objfile parameter.

Change-Id: I56b01ba294733362a3562426a96d48ae051a776f

4 years agoAdd dwarf2_per_objfile to dwarf_expr_context and dwarf2_frame_cache
Simon Marchi [Wed, 27 May 2020 15:14:01 +0000 (11:14 -0400)]
Add dwarf2_per_objfile to dwarf_expr_context and dwarf2_frame_cache

Evaluating DWARF expressions (such as location expressions) requires
knowing about the current objfile.  For example, it may call functions
like dwarf2_fetch_die_loc_sect_off, which currently obtain the
dwarf2_per_objfile object it needs from the dwarf2_per_cu_data object.
However, since we are going to remove this
dwarf2_per_cu_data::dwarf2_per_objfile link, these functions will need
to obtain the current dwarf2_per_objfile by parmeter.

If we go up the stack, we see that the DWARF expression contexts
(dwarf_expr_context and the classes that derive from it) need to store
the dwarf2_per_objfile, to be able to pass it to those functions that
will need it.

This patch adds a constructor to all these dwarf_expr_context variants,
accepting a dwarf2_per_objfile parameter.  This dwarf2_per_objfile
generally comes from a symbol baton created earlier.

For frame-related expressions, the dwarf2_per_objfile object must be
passed through the dwarf2_frame_cache object.  This lead to the
dwarf2_frame_find_fde function returning (by parameter) a
dwarf2_per_objfile object.  I then realized that this made the existing
"out_offset" parameter redundant.  This offset is
`objfile->text_section_offset ()`, so it can be recomputed from the
dwarf2_per_objfile object at any time.  I therefore opted to remove this
output parameter, as well as the offset field of dwarf2_frame_cache.

*Note*, there's one spot I'm particularly unsure about.  In
dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value, we would save and
overwrite the offset value in the context, along with a bunch of other
state.  This is because we might be about to evaluate something in a
different CU that the current one.  If the two CUs are in the same
objfile, then the text_offset is the same, as it's a property of the
objfile.  However, if the two CUs are possibly in different objfiles,
then it means the text_offsets are different.  It would also mean we
would need to save and restore the dwarf2_per_objfile in the context.
Is that even possible?

gdb/ChangeLog:

* dwarf2/expr.h (struct dwarf_expr_context)
<dwarf_expr_context>: Add dwarf2_per_objfile parameter.
<offset>: Remove.
<per_objfile>: New member.
* dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add
dwarf2_per_objfile parameter.  Don't set offset, set
per_objfile.
(dwarf_expr_context::execute_stack_op): Use offset from objfile.
* dwarf2/frame.c (dwarf2_frame_find_fde): Return (by parameter)
a dwarf2_per_objfile object instead of an offset.
(class dwarf_expr_executor) <dwarf_expr_executor>: Add
constructor.
(execute_stack_op): Add dwarf2_per_objfile parameter, pass it
to dwarf2_expr_executor constructor.  Don't set offset.
(dwarf2_fetch_cfa_info): Update.
(struct dwarf2_frame_cache) <text_offset>: Remove.
<per_objfile>: New field.
(dwarf2_frame_cache): Update.
(dwarf2_frame_prev_register): Update.
* dwarf2/loc.c (class dwarf_evaluate_loc_desc)
<dwarf_evaluate_loc_desc>: Add constructor.
(dwarf2_evaluate_loc_desc_full): Update.
(dwarf2_locexpr_baton_eval): Update.
(class symbol_needs_eval_context) <symbol_needs_eval_context>:
Add constructor.
(dwarf2_loc_desc_get_symbol_read_needs): Update.

Change-Id: I14df060669cc36ad04759f1708c6d7b1fda77727

4 years agoMove int type methods out of dwarf2_per_cu_data
Simon Marchi [Wed, 27 May 2020 15:14:00 +0000 (11:14 -0400)]
Move int type methods out of dwarf2_per_cu_data

These methods rely on the current objfile to create types based on it.
Since dwarf2_per_cu_data is to become objfile-independent, these methods
need to mvoe.

int_type can be in dwarf2_per_objfile, as it only requires knowing about
the objfile.

addr_sized_int_type and addr_type also need to know about the DWARF
address type size, which is CU-specific.  The dwarf2_cu objects seems
like a good place for it, as it knows both about the current objfile and
the current CU.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_cu_data) <addr_type,
addr_sized_int_type>: Move to dwarf2_cu.
<int_type>: Move to dwarf2_per_objfile.
(struct dwarf2_per_objfile) <int_type>: Move here.
* dwarf2/read.c (struct dwarf2_cu) <addr_type,
addr_sized_int_type>: Move here.
(read_func_scope): Update.
(read_array_type): Update.
(read_tag_string_type): Update.
(attr_to_dynamic_prop): Update.
(dwarf2_per_cu_data::int_type): Rename to...
(dwarf2_per_objfile::int_type): ... this.
(dwarf2_per_cu_data::addr_sized_int_type): Rename to...
(dwarf2_cu::addr_sized_int_type): ... this.
(read_subrange_type): Update.
(dwarf2_per_cu_data::addr_type): Rename to...
(dwarf2_cu::addr_type): ... this.
(set_die_type): Update.

Change-Id: Ic4708ef99d43a8d99325ff91dee59b2eb706cb8f

4 years agoRemove reference to dwarf2_per_cu_data::dwarf2_per_objfile in queue_and_load_all_dwo_tus
Simon Marchi [Wed, 27 May 2020 15:13:59 +0000 (11:13 -0400)]
Remove reference to dwarf2_per_cu_data::dwarf2_per_objfile in queue_and_load_all_dwo_tus

In this context, we know that per_cu->cu will be set, as there is this
assertion:

    gdb_assert (per_cu->cu != NULL)

So in order to remove the dwarf2_per_cu_data::dwarf2_per_objfile
reference in queue_and_load_all_dwo_tus, we can go through per_cu->cu.
This adds a reference to dwarf2_per_cu_data::cu, but it will get removed
eventually, in a subsequent patch.

gdb/ChangeLog:

* dwarf2/read.c (queue_and_load_all_dwo_tus): Access per_objfile
data through per_cu->cu.

Change-Id: Id4662828ac3c5bc93fe221df3c9bd9a36a8427ad

4 years agoPass dwarf2_cu objects to dwo-related functions, instead of dwarf2_per_cu_data
Simon Marchi [Wed, 27 May 2020 15:13:59 +0000 (11:13 -0400)]
Pass dwarf2_cu objects to dwo-related functions, instead of dwarf2_per_cu_data

This allows removing references to the
dwarf2_per_cu_data::dwarf2_per_objfile field.

I am not too sure of the code flow here, but ultimately
open_and_init_dwo_file calls create_cus_hash_table, and passes it
per_cu->cu.  create_cus_hash_table requires a dwarf2_cu to pass to
cutu_reader, as the "parent_cu".

The dwarf2_per_cu_data::cu link is only set when in a certain context.
It's not easy to convince myself in which situations it's safe to use
it.  Instead, if a function is going to use a dwarf2_cu, I think it's
simpler if it takes that object directly.  If it needs access to the
corresponding dwarf2_per_cu_data object, then it can used the
dwarf2_cu::per_cu field, which we know is always set.

This patch adds some references to dwarf2_per_cu_data::cu in the
cutu_reader context.  In this context, we know this field will be set,
as it's cutu_reader that is responsible for instantiating the dwarf2_cu
and assigning the field.

gdb/ChangeLog:

* dwarf2/read.c (lookup_dwo_comp_unit): Change
dwarf2_per_cu_data parameter fo dwarf2_cu.
(lookup_dwo_type_unit): Likewise.
(read_cutu_die_from_dwo): Likewise.
(lookup_dwo_unit): Likewise.
(open_and_init_dwo_file): Likewise.
(lookup_dwo_cutu): Likewise.
(lookup_dwo_comp_unit): Likewise.
(lookup_dwo_type_unit): Likewise.
(cutu_reader::init_tu_and_read_dwo_dies): Update.
(cutu_reader::cutu_reader): Update.

Change-Id: I0406a715b0797963bde2bd86237f159cbece5839

4 years agoAdd dwarf2_per_objfile parameter to process_full_{comp,type}_unit
Simon Marchi [Wed, 27 May 2020 15:13:58 +0000 (11:13 -0400)]
Add dwarf2_per_objfile parameter to process_full_{comp,type}_unit

This allows removing the dwarf2_per_cu_data::dwarf2_per_objfile
references in them.

gdb/ChangeLog:

* dwarf2/read.c (process_full_comp_unit): Add dwarf2_per_objfile
parameter.
(process_full_type_unit): Likewise.
(process_queue): Update.

Change-Id: Ie68baa8cc4bf1f81cc67d4ad13a59881b4c3feb6

4 years agoAdd dwarf2_per_objfile parameter to recursively_compute_inclusions
Simon Marchi [Wed, 27 May 2020 15:13:58 +0000 (11:13 -0400)]
Add dwarf2_per_objfile parameter to recursively_compute_inclusions

This allows removing dwarf2_per_cu_data::dwarf2_per_objfile references
in recursively_compute_inclusions and compute_compunit_symtab_includes.

gdb/ChangeLog:

* dwarf2/read.c (recursively_compute_inclusions): Add
dwarf2_per_objfile parameter.
(compute_compunit_symtab_includes): Likewise.
(process_cu_includes): Update.

Change-Id: I1ee7f8dfc07b39763985e6764e8ce04dcc943ec5

4 years agoAdd dwarf2_per_objfile parameter to create_partial_symtab
Simon Marchi [Wed, 27 May 2020 15:13:57 +0000 (11:13 -0400)]
Add dwarf2_per_objfile parameter to create_partial_symtab

This allows removing a dwarf2_per_cu_data::dwarf2_per_objfile reference.

gdb/ChangeLog:

* dwarf2/read.c (create_partial_symtab): Add dwarf2_per_objfile
parameter.
(create_type_unit_group): Update.
(process_psymtab_comp_unit_reader): Update.
(build_type_psymtabs_reader): Update.

Change-Id: I72e3a8fce8022943ce6992fb623e05636cd0e3a5

4 years agoRemove dwarf2_per_cu_data::dwarf2_per_objfile reference in cutu_reader::keep
Simon Marchi [Wed, 27 May 2020 15:13:56 +0000 (11:13 -0400)]
Remove dwarf2_per_cu_data::dwarf2_per_objfile reference in cutu_reader::keep

Here, it should be safe to use dwarf2_per_cu_data->cu->per_objfile, as
we know that dwarf2_per_cu_data->cu will be set at this point.

Note that this adds a reference to dwarf2_per_cu_data::cu, which we'll
want to remove later, but the current focus is to remove references to
dwarf2_per_cu_data::dwarf2_per_objfile.  We'll deal with that in a
subsequent patch.

gdb/ChangeLog:

* dwarf2/read.c (cutu_reader::keep): Access dwarf2_per_objfile
object through m_this_cu->cu.

Change-Id: I8dc26d4db021e0b9e9306eb033965b2704bba87c

4 years agoMake queue_and_load_dwo_tu receive a dwarf2_cu
Simon Marchi [Wed, 27 May 2020 15:13:56 +0000 (11:13 -0400)]
Make queue_and_load_dwo_tu receive a dwarf2_cu

queue_and_load_dwo_tu, used as a callback for htab_traverse_noresize,
currently receives a dwarf2_per_cu_data as its `info` user data.  It
accesses the current dwarf2_cu object through the dwarf2_per_cu_data::cu field.
This field will be removed, because the dwarf2_per_cu_data will become
objfile-independent, while dwarf_cu will remain objfile-dependent.

To remove references to this field, change queue_and_load_dwo_tu so
that it expects to receive a pointer to the dwarf2_cu as its info
parameter.

A reference to dwarf2_per_cu_data::cu needs to be added, but it will get
removed in a subsequent patch, when this function gets re-worked.

I kept this as a separate patch, because since there's no strong typing
here, it's easy to miss something.

gdb/ChangeLog:

* dwarf2/read.c (queue_and_load_dwo_tu): Expect a dwarf2_cu as
the info parameter.
(queue_and_load_all_dwo_tus): Pass per_cu->cu.

Change-Id: I3db2a780f0e2157d52ce6939f478558ffe20abcf

4 years agoAdd dwarf2_per_objfile parameter to cutu_reader's constructors
Simon Marchi [Wed, 27 May 2020 15:13:55 +0000 (11:13 -0400)]
Add dwarf2_per_objfile parameter to cutu_reader's constructors

The cutu_reader type is used for reading the CU represented by the
passed dwarf2_per_cu_data object.  This reading is done in the context
of a given obfile, which is currently the one associated to the passed
dwarf2_per_cu_data object.  Since the dwarf2_per_cu_data type will
become objfile-independent, we will need to pass the objfile separately.

This patch therefore adds a dwarf2_per_objfile parameter to the
cutu_reader constructors, as well as to their callers, up until the
point where we can get the dwarf2_per_objfile object from somewhere
else.  In the end, this allows removing the reference to
dwarf2_per_cu_data::dwarf2_per_objfile in cutu_reader::cutu_reader.

A few dwarf2_per_cu_data::dwarf2_per_objfile references are added (e.g.
in dwarf2_fetch_die_type_sect_off).  This is temporary, this will be
removed once these functions will get re-worked in subsequent patches.

gdb/ChangeLog:

* dwarf2/read.c (class cutu_reader) <cutu_reader>: Add
per_objfile parameter.
(load_full_type_unit): Add per_objfile parameter.
(read_signatured_type): Likewise.
(load_full_comp_unit): Likewise.
(load_cu): Likewise.
(dw2_do_instantiate_symtab): Likewise.
(dw2_get_file_names): Likewise.
(dw2_map_symtabs_matching_filename): Update.
(dw_expand_symtabs_matching_file_matcher): Update.
(dw2_map_symbol_filenames): Update.
(process_psymtab_comp_unit): Add per_objfile parameter.
(build_type_psymtabs_1): Update.
(process_skeletonless_type_unit): Update.
(dwarf2_build_psymtabs_hard): Update.
(load_partial_comp_unit): Add per_objfile parameter.
(scan_partial_symbols): Update.
(load_full_comp_unit): Add per_objfile parameter.
(process_imported_unit_die): Update.
(create_cus_hash_table): Update.
(find_partial_die): Update.
(dwarf2_read_addr_index): Update.
(follow_die_offset): Update.
(dwarf2_fetch_die_loc_sect_off): Update.
(dwarf2_fetch_constant_bytes): Update.
(dwarf2_fetch_die_type_sect_off): Update.
(follow_die_sig_1): Update.
(load_full_type_unit): Add per_objfile parameter.
(read_signatured_type): Likewise.

Change-Id: Ibd7bbc443df8b9b8b6f96ff18e93a60ee721b85f

4 years agoUse bfd_get_filename instead of objfile_name in lookup_dwo_unit
Simon Marchi [Wed, 27 May 2020 15:13:55 +0000 (11:13 -0400)]
Use bfd_get_filename instead of objfile_name in lookup_dwo_unit

There should be no functional difference, as objfile_name defers to
bfd_get_filename if objfile::obfd is non-NULL, which should be the case
here.  This allows to remove a reference to
dwarf2_per_cu_data::dwarf2_per_objfile.

gdb/ChangeLog:

* dwarf2/read.c (lookup_dwo_unit): Use bfd_get_filename instead
of objfile_name.

Change-Id: I1e1c1870820aec23701edc9c3994612da5781c23

4 years agoMake dwarf2_get_dwz_file take a dwarf2_per_bfd
Simon Marchi [Wed, 27 May 2020 15:13:54 +0000 (11:13 -0400)]
Make dwarf2_get_dwz_file take a dwarf2_per_bfd

This allows removing a per_bfd->dwarf2_per_objfile reference in
get_abbrev_section_for_cu.

This requires saving the bfd in dwarf2_per_bfd.  The constructor of
dwarf2_per_bfd already accepts the bfd, so it's just a matter of saving
it in a field.

I replaced uses of objfile_name with bfd_get_filename, which should be
equivalent in this case.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_bfd) <obfd>: New member.
(dwarf2_get_dwz_file): Replace parameter with dwarf2_per_bfd.
* dwarf2/read.c (dwarf2_per_bfd::dwarf2_per_bfd): Assign obfd
field.
(dwarf2_get_dwz_file): Replace parameter with dwarf2_per_bfd.
(create_cus_from_index): Update.
(dwarf2_read_gdb_index): Update.
(create_cus_from_debug_names): Update.
(dwarf2_read_debug_names): Update.
(get_abbrev_section_for_cu): Update.
(create_all_comp_units): Update.
(read_attribute_value): Update.
(get_debug_line_section): Update.
* dwarf2/index-cache.c (index_cache::store): Update.
* dwarf2/index-write.c (save_gdb_index_command): Update.
* dwarf2/macro.c (dwarf_decode_macro_bytes): Update.

Change-Id: Ifb23f55dda93c499aae57b6a9aff9c6ff9d2f45f

4 years agoAdd dwarf2_per_bfd field to dwarf2_per_cu_data
Simon Marchi [Wed, 27 May 2020 15:13:54 +0000 (11:13 -0400)]
Add dwarf2_per_bfd field to dwarf2_per_cu_data

Some code using dwarf2_per_cu_data objects accesses the corresponding
dwarf2_per_bfd using the following pattern:

    per_cu->dwarf2_per_objfile->per_bfd

Since dwarf2_per_cu_data objects are going to become
objfile-independent, the dwarf2_per_objfile link must go.  To replace
it, add a dwarf2_per_cu_data->per_bfd link.  It makes sense to have it
there because the dwarf2_per_cu_data objects belong to the
dwarf2_per_bfd, so this is essentially just a backlink to their owner.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_cu_data) <per_bfd>: New
member.
* dwarf2/read.c (dwarf2_per_bfd::allocate_per_cu): Initialize
dwarf2_per_cu_data::per_bfd.
(dwarf2_per_bfd::allocate_signatured_type): Likewise.
(create_type_unit_group): Likewise.
(queue_comp_unit): Remove reference to
per_cu->dwarf2_per_objfile.
(maybe_queue_comp_unit): Likewise.
(fill_in_sig_entry_from_dwo_entry): Assign new field.
(create_cus_hash_table): Assign new field.

Change-Id: I4ba0a393e64a14489ef061261a3dede1509d055b

4 years agoRemove dwarf2_cu->per_cu->dwarf2_per_objfile references
Simon Marchi [Wed, 27 May 2020 15:13:53 +0000 (11:13 -0400)]
Remove dwarf2_cu->per_cu->dwarf2_per_objfile references

Change spots that access the dwarf2_per_objfile object through this
pattern:

  dwarf2_cu->per_cu->dwarf2_per_objfile

to

  dwarf2_cu->per_objfile

This allows removing many references to
dwarf2_per_cu_data::dwarf2_per_objfile.

Again, I hope the following ChangeLog entry will be fine.  I'd rather not
list all the affected functions, as it would be time-consuming and a bit
pointless.

gdb/ChangeLog:

* dwarf2/read.c: Replace
dwarf2_cu->per_cu->dwarf2_per_objfile references with
dwarf2_cu->per_objfile throughout.

Change-Id: I00f44e88295f70ae805a4b18e8144ca92154612e

4 years agoRemove reference to dwarf2_per_cu_data::dwarf2_per_objfile in dw2_do_instantiate_symtab
Simon Marchi [Wed, 27 May 2020 15:13:52 +0000 (11:13 -0400)]
Remove reference to dwarf2_per_cu_data::dwarf2_per_objfile in dw2_do_instantiate_symtab

This patch begins by removing the per_cu->dwarf2_per_objfile reference
in dw2_do_instantiate_symtab, instead accepting a dwarf2_per_objfile
object as a parameter.  It then fixes the fallouts.  In this context,
the dwarf2_per_objfile is generally derived from an objfile passed to a
quick_symbol_functions callback.

gdb/ChangeLog:

* dwarf2/read.c (dw2_do_instantiate_symtab): Add per_objfile
parameter, don't use per_cu->dwarf2_per_objfile.
(dw2_instantiate_symtab): Likewise.
(dw2_find_last_source_symtab): Update.
(dw2_map_expand_apply): Update.
(dw2_lookup_symbol): Update.
(dw2_expand_symtabs_for_function): Update.
(dw2_expand_all_symtabs): Update.
(dw2_expand_symtabs_with_fullname): Update.
(dw2_expand_symtabs_matching_one): Add per_objfile parameter,
don't use per_cu->dwarf2_per_objfile.
(dw2_expand_marked_cus): Update.
(dw2_find_pc_sect_compunit_symtab): Update.
(dw2_debug_names_lookup_symbol): Update.
(dw2_debug_names_expand_symtabs_for_function): Update.
(dw2_debug_names_map_matching_symbols): Update.
(dwarf2_psymtab::expand_psymtab): Update.

Change-Id: I248300822a09bae8470b65a7122d04fb9cb2b5bc

4 years agoAdd dwarf2_per_objfile field to dwarf2_cu
Simon Marchi [Wed, 27 May 2020 15:13:52 +0000 (11:13 -0400)]
Add dwarf2_per_objfile field to dwarf2_cu

Subsequent patches will make dwarf2_per_cu_data objfile-independent.
This means that the dwarf2_per_cu_data::dwarf2_per_objfile field must
go.

The code using a dwarf2_cu structure currently accesses the current
dwarf2_per_objfile object through dwarf2_cu->per_cu->dwarf2_per_objfile.
Since it's ok for the dwarf2_cu to know about the current objfile (a
dwarf2_cu is always used in the context of a particular objfile), add a
dwarf2_per_objfile field to dwarf2_cu.  Upcoming patches will gradually
remove uses of dwarf2_per_cu_data::dwarf2_per_objfile in favor of
dwarf2_cu::dwarf2_per_objfile, until the former can be removed.

gdb/ChangeLog:

* dwarf2/read.c (struct dwarf2_cu) <dwarf2_cu>: Add parameter.
<per_objfile>: New member.
(class cutu_reader) <init_tu_and_read_dwo_dies>: Add parameter.
(cutu_reader::init_tu_and_read_dwo_dies): Add parameter, update
call to dwarf2_cu.
(cutu_reader::cutu_reader): Update.
(dwarf2_cu::dwarf2_cu): Add parameter, initialize per_objfile.

Change-Id: I8fd0da7371f65baea1ea7787aad08e10453bc565

4 years agoMove die_type_hash to dwarf2_per_objfile
Simon Marchi [Wed, 27 May 2020 15:13:51 +0000 (11:13 -0400)]
Move die_type_hash to dwarf2_per_objfile

The die_type_hash field can't be shared between multiple obfiles, as it
holds `struct type` objects, which are objfile-specific.  Move it from
dwarf2_per_bfd to dwarf2_per_objfile and update all references.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_bfd) <die_type_hash>: Move to
struct dwarf2_per_objfile.
(struct dwarf2_per_objfile) <die_type_hash>: Move from struct
dwarf2_per_bfd.
* dwarf2/read.c (set_die_type): Update.
(get_die_type_at_offset): Update.

Change-Id: I3589777ed3579bcabafd2ba859d27babe4502bfb

4 years agoRemove symtab links from dwarf2_psymtab and dwarf2_per_cu_quick_data
Simon Marchi [Wed, 27 May 2020 15:15:47 +0000 (11:15 -0400)]
Remove symtab links from dwarf2_psymtab and dwarf2_per_cu_quick_data

The dwarf2_psymtab and dwarf2_per_cu_quick_data types contain a pointer
to a compunit_symtab, which is a pointer to the corresponding full
symtab.  The dwarf2_psymtab and dwarf2_per_cu_quick_data objects are
going to become objfile-independent, and possibly shared by multiple
objfiles, whereas compunit_symtab will stay objfile-dependent.  This
backlink to the compunit_symtab must therefore be removed.

This patch replaces them with a vector in the dwarf2_per_objfile type,
that serves as a mapping from dwarf2_per_cu_data objects to
compunit_symtab objects, for this particular objfile.  The vector is
indexed using the index assigned to the dwarf2_per_cu_data at its
creation.

I removed the get_compunit_symtab, as it appears to bring not much value
over calling dwarf2_per_objfile::get_symtab directly.

gdb/ChangeLog:

YYYY-MM-DD  Tom Tromey  <tom@tromey.com>
YYYY-MM-DD  Simon Marchi  <simon.marchi@efficios.com>

* dwarf2/read.h (struct dwarf2_per_bfd) <num_psymtabs>: New
method.
(struct dwarf2_per_objfile) <resize_symtabs, symtab_set_p,
get_symtab, set_symtab>: New methods.
<m_symtabs>: New field.
(struct dwarf2_psymtab): Derive from partial_symtab.
<readin_p, get_compunit_symtab>: Declare methods.
* dwarf2/read.c (dwarf2_per_objfile::symtab_set_p,
dwarf2_per_objfile::get_symtab, dwarf2_per_objfile::set_symtab):
New methods.
(struct dwarf2_per_cu_quick_data) <compunit_symtab>: Remove.
(dw2_do_instantiate_symtab, dw2_instantiate_symtab)
(dw2_map_expand_apply, dw2_map_symtabs_matching_filename)
(dw2_symtab_iter_next, dw2_print_stats)
(dw2_expand_symtabs_with_fullname)
(dw2_expand_symtabs_matching_one)
(dw_expand_symtabs_matching_file_matcher)
(dw2_find_pc_sect_compunit_symtab, dw2_map_symbol_filenames)
(dw2_debug_names_iterator::next)
(dw2_debug_names_map_matching_symbols)
(fill_in_sig_entry_from_dwo_entry, dwarf2_psymtab::read_symtab)
(process_queue, dwarf2_psymtab::expand_psymtab): Update.
(dwarf2_psymtab::readin_p, dwarf2_psymtab::get_compunit_symtab):
New methods.
(get_compunit_symtab, process_full_comp_unit)
(process_full_type_unit): Update.
(dwarf2_build_psymtabs, dwarf2_initialize_objfile, add_type_unit): Call

Change-Id: Iec53d96e0b70a57d8b68408febdac3c6c3d4854b

4 years agoSplit dwarf2_per_objfile into dwarf2_per_objfile and dwarf2_per_bfd
Simon Marchi [Wed, 27 May 2020 15:13:50 +0000 (11:13 -0400)]
Split dwarf2_per_objfile into dwarf2_per_objfile and dwarf2_per_bfd

This is the first step of splitting dwarf2_per_objfile in two, one
structure for objfile-independent data (dwarf2_per_bfd) and one for
objfile-dependent data (dwarf2_per_objfile).

The existing dwarf2_per_objfile is renamed dwarf2_per_bfd, and a new
dwarf2_per_objfile type is introduced, which sits "in between" the
objfile and dwarf2_per_bfd.

So where we had this before:

  objfile -> dwarf2_per_objfile (*)

we now have this:

  objfile -> dwarf2_per_objfile -> dwarf2_per_bfd (*)

(*) Note that the dwarf2_per_objfile in the former corresponds to
the dwarf2_per_bfd in the latter.

I've done the minimal amount of changes in this patch: following patches
will incrementally move things that are not actually shareable between
objfiles from dwarf2_per_bfd to dwarf2_per_objfile.

Most references to dwarf2_per_objfile objects are changed to
dwarf2_per_objfile->per_bfd.  To avoid many of these replacements, which
would have to be reverted later anyway, I've moved right away the
objfile backlink to the new dwarf2_per_objfile structure in this patch.
I've also moved the read_line_string method, since it references the
objfile backlink, and it's actually not difficult to move.

Once the moves are completed, multiple dwarf2_per_objfile sharing the
same BFD will point to the same single instance of dwarf2_per_bfd (as
long as they don't require relocation).

dwarf2_has_info, where we create these objects, is updated to the new
architecture.

I've had to change the get_gdb_index_contents_ftype typedef and related
functions.  The parameter type was changed from dwarf2_per_objfile to
dwarf2_per_bfd, otherwise the template wouldn't work.

Please excuse the terse ChangeLog entry, I have not listed all the
functions where dwarf2_per_objfile has been changed to
dwarf2_per_objfile->per_bfd.  It would take a considerable amount of
time and would not really be useful in the end.

gdb/ChangeLog:

* dwarf2/read.h (dwarf2_per_objfile): Rename to dwarf2_per_bfd,
then introduce a new dwarf2_per_objfile type.
<read_line_string>: Move to the new dwarf2_per_objfile type.
<objfile>: Likewise.
(dwarf2_per_bfd): Rename dwarf2_per_objfile to this.
* dwarf2/read.c: Replace references to dwarf2_per_objfile with
dwarf2_per_objfile->per_bfd.
(dwarf2_per_objfile::dwarf2_per_objfile): Rename to...
(dwarf2_per_bfd::dwarf2_per_bfd): ... this.
(dwarf2_per_objfile::free_cached_comp_units): Rename to...
(dwarf2_per_bfd::free_cached_comp_units): ... this.
(dwarf2_has_info): Allocate dwarf2_per_bfd.
(dwarf2_per_objfile::locate_sections): Rename to...
(dwarf2_per_bfd::locate_sections): ... this.
(dwarf2_per_objfile::get_cutu): Rename to...
(dwarf2_per_bfd::get_cutu): ... this.
(dwarf2_per_objfile::get_cu): Rename to...
(dwarf2_per_bfd::get_cu): ... this.
(dwarf2_per_objfile::get_tu): Rename to...
(dwarf2_per_bfd::get_tu): ... this.
(dwarf2_per_objfile::allocate_per_cu): Rename to...
(dwarf2_per_bfd::allocate_per_cu): ... this.
(dwarf2_per_objfile::allocate_signatured_type): Rename to...
(dwarf2_per_bfd::allocate_signatured_type): ... this.
(get_gdb_index_contents_ftype): Change parameter from
dwarf2_per_objfile to dwarf2_per_bfd.
* dwarf2/macro.c, dwarf2/index-write.c: Replace references to
dwarf2_per_objfile with dwarf2_per_objfile->per_bfd.

Change-Id: I7de7b5d1ce7494aa73bfcf15f719d3c5c46e138c

4 years agoAdd dwarf2_per_objfile member to DWARF batons
Tom Tromey [Wed, 27 May 2020 15:13:50 +0000 (11:13 -0400)]
Add dwarf2_per_objfile member to DWARF batons

Various DWARF callbacks expect to be able to fetch the objfile and / or
dwarf2_per_objfile from the DWARF CU object.  However, this won't be
possible once sharing is implemented.

Because these objects are related to full symbols (e.g., they are used
to implement location expressions), they can simply store the
dwarf2_per_objfile they need.

This patch adds a per_objfile member to the various "baton" structures
and arranges to set this value when constructing the baton.

gdb/ChangeLog:

YYYY-MM-DD  Tom Tromey  <tom@tromey.com>
YYYY-MM-DD  Simon Marchi  <simon.marchi@efficios.com>

* dwarf2/loc.c (struct piece_closure) <per_objfile>: New member.
(allocate_piece_closure): Set "per_objfile" member.
(dwarf2_find_location_expression, dwarf2_locexpr_baton_eval)
(locexpr_describe_location, loclist_describe_location): Use new
member.
* dwarf2/read.c (read_call_site_scope)
(mark_common_block_symbol_computed, attr_to_dynamic_prop)
(dwarf2_const_value_attr, dwarf2_fetch_die_loc_sect_off)
(fill_in_loclist_baton, dwarf2_symbol_mark_computed,
handle_data_member_location): Set per_objfile member.
* dwarf2/loc.h (struct dwarf2_locexpr_baton) <per_objfile>: New
member.
(struct dwarf2_loclist_baton) <per_objfile>: New member.

Change-Id: If3aaa6a0f544be86710157c3adb68fde24d80037

4 years agoAdd dwarf2_per_cu_data::index
Tom Tromey [Wed, 27 May 2020 15:13:49 +0000 (11:13 -0400)]
Add dwarf2_per_cu_data::index

Currently, a dwarf2_per_cu_data can hold a link to the corresponding
expanded compunit_symtab.  However, the dwarf2_per_cu_data objects are
shared across objfiles, a simple pointer won't work: each objfile
sharing the dwarf2_per_cu_data instance will have a corresponding
compunit_symtab.

Instead, this link will be stored in the dwarf2_per_objfile object
(which will contain the objfile-specific data).  To enable this, we add
an index to each dwarf2_per_cu_data and signatured_type.  The data
structure in the dwarf2_per_objfile will use this new index to map a
dwarf2_per_cu_data to its corresponding compunit_symtab, for this
objfile.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_objfile) <allocate_per_cu,
allocate_signatured_type>: Declare new methods.
<m_num_psymtabs>: New member.
(struct dwarf2_per_cu_data) <index>: New member.
* dwarf2/read.c (dwarf2_per_objfile::allocate_per_cu)
(dwarf2_per_objfile::allocate_signatured_type): New methods.
(create_cu_from_index_list): Use allocate_per_cu.
(create_signatured_type_table_from_index)
(create_signatured_type_table_from_debug_names)
(create_debug_type_hash_table, add_type_unit)
(read_comp_units_from_section): Use allocate_signatured_type.

Change-Id: I7733479a38ce82a5015cb184c8acce5f8bbf2e69

4 years agoAdd "objfile" parameter to two partial_symtab methods
Tom Tromey [Wed, 27 May 2020 15:13:48 +0000 (11:13 -0400)]
Add "objfile" parameter to two partial_symtab methods

This series will cause partial symtabs to be shared across objfiles.
However, full symtabs and symbols will still be objfile-dependent, so
will be expanded separately for each objfile.  So, a debug info reader
will need to know which objfile to consult when expanding a partial
symtab.

This patch adds an objfile parameter to the two relevant methods of
partial_symtab.  Current implementations simply ignore them.

gdb/ChangeLog:

* psymtab.c (partial_map_expand_apply)
(psym_find_pc_sect_compunit_symtab, psym_lookup_symbol)
(psym_lookup_global_symbol_language)
(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): Update.
* psympriv.h (struct partial_symtab) <readin_p,
get_compunit_symtab>: Add objfile parameter.
(struct standard_psymtab) <readin_p, get_compunit_symtab>:
Likewise.
* dwarf2/read.c (struct dwarf2_include_psymtab) <readin_p,
get_compunit_symtab>: Likewise.
(dwarf2_psymtab::expand_psymtab): Pass objfile argument.

Change-Id: I3f0b26787c3e78f7fb78b9fc011d91fb8690f3a0

4 years agoIntroduce dwarf2_per_objfile::obstack
Tom Tromey [Wed, 27 May 2020 15:13:48 +0000 (11:13 -0400)]
Introduce dwarf2_per_objfile::obstack

Currently much of the DWARF-related data is stored on the objfile
obstack.  This prevents sharing this data across objfiles, so this patch
adds a new obstack to dwarf2_per_objfile.  Note that the
dwarf2_per_objfile type is going to become "dwarf2_per_bfd" in a
subsequent patch, which is indeed going to be shared between objfiles.

One way to check whether this is correct is to look at the remaining
uses of objfile_obstack in the DWARF code and note that they all
appear in the "full CU" code paths.

The converse -- storing per-objfile data on the shared obstack -- is
not good, but it is just a memory leak, not a potential
use-after-free.  Double-checking this would also be useful, though.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_objfile) <obstack>: New
member.
* dwarf2/read.c (delete_file_name_entry): Fix comment.
(create_cu_from_index_list)
(create_signatured_type_table_from_index)
(create_signatured_type_table_from_debug_names)
(dw2_get_file_names_reader, dwarf2_initialize_objfile)
(dwarf2_create_include_psymtab)
(create_debug_type_hash_table, add_type_unit)
(create_type_unit_group, read_comp_units_from_section)
(dwarf2_compute_name, create_cus_hash_table)
(create_dwp_hash_table, create_dwo_unit_in_dwp_v1)
(create_dwo_unit_in_dwp_v2, open_and_init_dwp_file): Use new
obstack.
(dw2_get_real_path): Likewise.  Change argument to
dwarf2_per_objfile.

Change-Id: Icdec7be7c4d9f33d1dce4f807284f3077f7d3f03

4 years agoFix PR 26000, logical bitwise error / prologue analyzer
Luis Machado [Sat, 16 May 2020 02:06:52 +0000 (23:06 -0300)]
Fix PR 26000, logical bitwise error / prologue analyzer

This fixes an instruction mask typo. We should be matching only
ldrd (immediate) and not any other of its variants. As is, it never matches
anything.

With the patch, the instruction mask also allows matching of ldrd (literal),
but the check for SP discards this particular instruction pattern, as it has
a hardcoded PC register.

gdb/ChangeLog:

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

PR tdep/26000
* arm-tdep.c (thumb_analyze_prologue): Fix instruction matching
for ldrd (immediate).

4 years agoFix some duplicate test names
Luis Machado [Mon, 25 May 2020 16:25:50 +0000 (13:25 -0300)]
Fix some duplicate test names

While doing a testsuite run on aarch64-linux, I noticed a bunch of duplicated
test name results. It annoyed me a little, so I decided to go ahead and fix the
worst offenders.

The following patch brings the duplicate test names down from 461 to 137.

The remaining ones are mostly scattered across the testsuite, with 1 to 3
duplicates per testcase. We can fix those as we go.

gdb/testsuite/ChangeLog:

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

* gdb.arch/aarch64-sighandler-regs.exp: Fix duplicated test names.
* gdb.arch/aarch64-tagged-pointer.exp: Likewise.
* gdb.arch/arm-disassembler-options.exp: Likewise.
* gdb.arch/arm-disp-step.exp: Likewise.
* gdb.arch/thumb-prologue.exp: Likewise.
* gdb.base/async.exp: Likewise.
* gdb.base/auxv.exp: Likewise.
* gdb.base/complex-parts.exp: Likewise.
* gdb.base/ena-dis-br.exp: Likewise.
* gdb.base/foll-exec.exp: Likewise.
* gdb.base/permissions.exp: Likewise.
* gdb.base/relocate.exp: Likewise.
* gdb.base/return2.exp: Likewise.
* gdb.base/sigbpt.exp: Likewise.
* gdb.base/siginfo-obj.exp: Likewise.
* gdb.cp/converts.exp: Likewise.
* gdb.cp/exceptprint.exp: Likewise.
* gdb.cp/inherit.exp: Likewise.
* gdb.cp/nsnoimports.exp: Likewise.
* gdb.cp/virtbase2.exp: Likewise.
* gdb.mi/mi-var-cmd.exp: Likewise.
* gdb.mi/var-cmd.c: Likewise.

4 years agold: Add --warn-textrel and obsolete --warn-shared-textrel
H.J. Lu [Wed, 27 May 2020 11:53:54 +0000 (04:53 -0700)]
ld: Add --warn-textrel and obsolete --warn-shared-textrel

--warn-shared-textrel and -z text apply to both shared object and PIE.
Add --warn-textrel and obsolete --warn-shared-textrel.  Consolidate
--warn-textrel and -z text/notext/textoff implementation.

bfd/

PR ld/22909
* elflink.c (bfd_elf_final_link): Use bfd_link_textrel_check.
Check bfd_link_dll when issue a DT_TEXTREL warning.
* elfxx-x86.c (maybe_set_textrel): Likewise.
(_bfd_x86_elf_size_dynamic_sections): Likewise.

include/

PR ld/22909
* bfdlink.h (textrel_check_method): New enum.
(bfd_link_textrel_check): New.
(bfd_link_info): Replace warn_shared_textrel and error_textrel
with textrel_check.

ld/

PR ld/22909
* NEWS: Mention --warn-textrel.
* ld.texi: Update -z text/notext/textoff.  Add --warn-textrel.
Remove --warn-shared-textrel.
* ldlex.h (option_values): Rename OPTION_WARN_SHARED_TEXTREL to
OPTION_WARN_TEXTREL.
* lexsup.c (ld_options): Add --warn-textrel.  Obsolete
--warn-shared-textrel.
(parse_args): Updated.
(elf_shlib_list_options): Check link_info.textrel_check.
* emultempl/elf.em: Updated.
* testsuite/ld-elf/pr19539.d: Replace -z notext with
--warn-textrel.  Expect a warning.
* testsuite/ld-i386/warn1.d: Update expected warning.

4 years agoFix extraction of signed constants in nios2 disassembler (again).
Sandra Loosemore [Wed, 27 May 2020 06:23:03 +0000 (23:23 -0700)]
Fix extraction of signed constants in nios2 disassembler (again).

In commit 6031ac352c05c5c9f44e24fa1c5a8222a7a7d02d I added some casts
to explicitly do conversions from unsigned to signed as 32-bit
quantities to address some bugs with different sizes of long and
bfd_signed_vma.  Those casts were removed in the rewrite of the
sign-extension logic in commit 1d61b032265e69317f42e8019e072506f11890c5,
reintroducing the same bugs.  This patch restores the casts.

2020-05-26  Sandra Loosemore  <sandra@codesourcery.com>

opcodes/
* nios2-dis.c (nios2_print_insn_arg): Add explicit casts to
extractions of signed fields.

4 years agoAutomatic date update in version.in
GDB Administrator [Wed, 27 May 2020 00:00:17 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agold: Skip some x86 ifunc tests for lynxos and nto
H.J. Lu [Tue, 26 May 2020 21:25:19 +0000 (14:25 -0700)]
ld: Skip some x86 ifunc tests for lynxos and nto

On lynxos and nto:

regexp_diff match failure
regexp "^Relocation section '.rel(a|).plt' at offset 0x[0-9a-f]+ contains 1 entry:$"
line   "Relocation section '.rel.dyn' at offset 0x74 contains 1 entry:"
FAIL: ld-ifunc/ifunc-23a-x86

* testsuite/ld-ifunc/ifunc-23a-x86.d: Skip *-*-lynxos *-*-nto*.
* testsuite/ld-ifunc/ifunc-24a-x86.d: Likewise.
* testsuite/ld-ifunc/ifunc-25a-x86.d: Likewise.

4 years agogas: Adjust x86 tests for PECOFF
H.J. Lu [Tue, 26 May 2020 21:17:09 +0000 (14:17 -0700)]
gas: Adjust x86 tests for PECOFF

* testsuite/gas/i386/align-branch-9.d: Updated for PECOFF.
* testsuite/gas/i386/inval-avx512f.s: Add .p2align for PECOFF.
* testsuite/gas/i386/inval-avx512f.l: Updated.

4 years agoEnsure class_tui is listed in the output of "help" giving the list of classes.
Philippe Waroquiers [Sat, 23 May 2020 13:11:52 +0000 (15:11 +0200)]
Ensure class_tui is listed in the output of "help" giving the list of classes.

Before this change, "help" was not showing the TUI class.
With this change:
  (gdb) help
  ...
  support -- Support facilities.
  text-user-interface -- TUI is the GDB text based interface.
  tracepoints -- Tracing of program execution without stopping the program.
  ...
  (gdb) help text-user-interface
  TUI is the GDB text based interface.
  In TUI mode, GDB can display several text windows showing
  the source file, the processor registers, the program disassembly, ...

  List of commands:

  + -- Scroll window forward.
  ...

Note that we cannot use "tui" for the fake class command name, as "tui"
is a command.

gdb/ChangeLog

2020-05-26  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

* command.h: Add comment giving the name of class_tui.
* cli/cli-cmds.c (_initialize_cli_cmds): If TUI defined,
create the fake command for the help for class_tui.

4 years agoHandle indexing Ada arrays with enum indices
Tom Tromey [Tue, 26 May 2020 20:11:08 +0000 (14:11 -0600)]
Handle indexing Ada arrays with enum indices

In Ada, like C, an enum can assign values to the constants.  However,
unlike C (or any other language supported by gdb), the enum type can
also be used as the range of an array.

In this case, the user's code references the enum constants, but the
compiler translates these to the position of the constant in the enum.
So for example one might write:

   type Enum_With_Gaps is
     (
      LIT0,
      LIT1,
      LIT2,
      LIT3,
      LIT4
     );

   for Enum_With_Gaps use
     (
      LIT0 => 3,
      LIT1 => 5,
      LIT2 => 8,
      LIT3 => 13,
      LIT4 => 21
     );

Then index an array like "array(LIT3)" -- but this will be the 4th
element in an array of 5 elements, not the 13th element in an array of
19 (assuming I did the math right) elements.

gdb supports this to some degree, with the only missing piece being
indexing into such an array.  This patch implements this missing
feature, and also fixes an existing bug, which is that in some
situations I believe gdb would mis-compute the resulting array's
length.

The approach taken here is to try to integrate this feature into the
core of gdb.  My view is that much of the Ada support should be better
integrated with gdb, rather than being "on the side".  This, I think,
would help avoid code duplication at least.  So, I try to take steps
toward this goal when possible.

Because other languages generally don't allow the user to specify the
index type of an array, I simply made the core of gdb unconditionally
apply discrete_position when computing the range of such an array.
This is a no-op for ordinary types, but applies the enum
value-to-position transformation for TYPE_CODE_ENUM.

gdb/ChangeLog
2020-05-26  Tom Tromey  <tromey@adacore.com>

* ada-lang.c (ada_print_array_index): Change type.  Call val_atr.
(ada_value_ptr_subscript): Don't call pos_atr on the lower bound.
(val_atr): New function.
(value_val_atr): Use it.
* ada-valprint.c (print_optional_low_bound): Change low bound
handling for enums.
(val_print_packed_array_elements): Don't call discrete_position.
* gdbtypes.c (get_discrete_bounds) <TYPE_CODE_RANGE>: Call
discrete_position for enum types.
* language.c (default_print_array_index): Change type.
* language.h (struct language_defn) <la_print_array_index>: Add
index_type parameter, change type of index_value.
(LA_PRINT_ARRAY_INDEX): Add index_type parameter.
(default_print_array_index): Update.
* valprint.c (maybe_print_array_index): Don't call
value_from_longest.  Update.
(value_print_array_elements): Don't call discrete_position.

gdb/testsuite/ChangeLog
2020-05-26  Tom Tromey  <tromey@adacore.com>

* gdb.ada/arr_acc_idx_w_gap.exp: Add tests.

4 years agoFix bugs in 'val and 'pos with range types
Tom Tromey [Tue, 26 May 2020 20:11:08 +0000 (14:11 -0600)]
Fix bugs in 'val and 'pos with range types

In Ada, the 'val and 'pos attributes can be used to map from an
enumeration constant to its position in the enum and vice versa.
These operators did not work properly when the type in question was a
subrange of an enum type with "holes".

gdb/ChangeLog
2020-05-26  Tom Tromey  <tromey@adacore.com>

* ada-lang.c (value_val_atr): Handle TYPE_CODE_RANGE.
* gdbtypes.c (discrete_position): Handle TYPE_CODE_RANGE.

gdb/testsuite/ChangeLog
2020-05-26  Tom Tromey  <tromey@adacore.com>

* gdb.ada/arr_acc_idx_w_gap.exp: Add enum subrange tests.
* gdb.ada/arr_acc_idx_w_gap/enum_with_gap.ads (Enum_Subrange): New
type.
* gdb.ada/arr_acc_idx_w_gap/enum_with_gap_main.adb (V): New
variable.

4 years agoUse = instead of == for better portability
Christian Biesinger via Gdb-patches [Tue, 26 May 2020 16:58:04 +0000 (11:58 -0500)]
Use = instead of == for better portability

Reported by sobukus on IRC.

gdb/testsuite/ChangeLog:

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

        * Makefile.in: Use = instead of == for the test command
        for portability.

Change-Id: I431ccfa5e5ba15f9af082ffd6aa8cd7046456cd2

4 years agoChangeLog entries for f687f5f563
Stefan Schulze Frielinghaus [Tue, 26 May 2020 16:34:39 +0000 (18:34 +0200)]
ChangeLog entries for f687f5f563

4 years agotc-xgate.c: Replace R_XGATE_PCREL_X with BFD_RELOC_XGATE_PCREL_X
H.J. Lu [Tue, 26 May 2020 16:33:48 +0000 (09:33 -0700)]
tc-xgate.c: Replace R_XGATE_PCREL_X with BFD_RELOC_XGATE_PCREL_X

Replace R_XGATE_PCREL_X with BFD_RELOC_XGATE_PCREL_X to silence GCC 10
warning:

gas/config/tc-xgate.c:1339:5: error: implicit conversion from ‘enum elf_xgate_reloc_type’ to ‘bfd_reloc_code_real_type’ {aka ‘enum bfd_reloc_code_real’} [-Werror=enum-conversion]
 1339 |     R_XGATE_PCREL_9);
      |     ^~~~~~~~~~~~~~~

PR gas/26044
* config/tc-xgate.c (md_apply_fix): Check BFD_RELOC_XGATE_PCREL_X
instead of R_XGATE_PCREL_X.
(xgate_parse_operand): Replace R_XGATE_PCREL_X with
BFD_RELOC_XGATE_PCREL_X.

4 years agoS/390: z13: Accept vector alignment hints
Stefan Schulze Frielinghaus [Mon, 18 May 2020 15:22:57 +0000 (17:22 +0200)]
S/390: z13: Accept vector alignment hints

Accept vector alignment hints on z13 although they are ignored there.
The advantage is that any binary compiled for architecture level z13 may
run on z14 or later and benefit from vector alignment hints.

gas/ChangeLog:

2020-05-18  Stefan Schulze Frielinghaus  <stefansf@linux.ibm.com>

* testsuite/gas/s390/zarch-z13.d: Add regexp checks for vector
load/store instruction variants with alignment hints.
* testsuite/gas/s390/zarch-z13.s: Emit new vector load/store
instruction variants with alignment hints.

opcodes/ChangeLog:

2020-05-18  Stefan Schulze Frielinghaus  <stefansf@linux.ibm.com>

* s390-opc.txt: Relocate vector load/store instructions with
additional alignment parameter and change architecture level
constraint from z14 to z13.

4 years agogas: Silence GCC 10 warning on tc-visium.c
H.J. Lu [Tue, 26 May 2020 14:54:05 +0000 (07:54 -0700)]
gas: Silence GCC 10 warning on tc-visium.c

PR gas/26044
* config/tc-visium.c (md_convert_frag): Replace fragP->fr_literal
with &fragP->fr_literal[0].

4 years agogas: Silence GCC 10 warning tc-vax.c
H.J. Lu [Tue, 26 May 2020 14:41:07 +0000 (07:41 -0700)]
gas: Silence GCC 10 warning tc-vax.c

PR gas/26044
* config/tc-vax.c (md_estimate_size_before_relax): Replace
fragP->fr_literal with &fragP->fr_literal[0].
(md_convert_frag): Likewise.

4 years agogas: Silence GCC 10 warning on tc-v850.c
H.J. Lu [Tue, 26 May 2020 13:56:18 +0000 (06:56 -0700)]
gas: Silence GCC 10 warning on tc-v850.c

PR gas/26044
* config/tc-v850.c (md_convert_frag): Replace fragP->fr_literal
with &fragP->fr_literal[0].

4 years agogas: Silence GCC 10 warning on tc-crx.c
H.J. Lu [Tue, 26 May 2020 13:46:26 +0000 (06:46 -0700)]
gas: Silence GCC 10 warning on tc-crx.c

opcode/crx.h has

typedef enum
  {
    ...
    MAX_REG
  }
reg;

typedef enum
  {
    c0 = MAX_REG,
  }
copreg;

tc-crx.c has

static int
getreg_image (reg r)
{
  ...
 /* Check whether the register is in registers table.  */
  if (r < MAX_REG)
    rreg = &crx_regtab[r];
  /* Check whether the register is in coprocessor registers table.  */
  else if (r < (int) MAX_COPREG)
    rreg = &crx_copregtab[r-MAX_REG];
}

Change getreg_image's argument type to int and replace fragP->fr_literal
with &fragP->fr_literal[0] to silence GCC 10 warning.

PR gas/26044
* config/tc-crx.c (getreg_image): Change argument type to int.
(md_convert_frag): Replace fragP->fr_literal with
&fragP->fr_literal[0].

4 years agoExtend the error message displayed when a plugin fails to load.
Nick Clifton [Tue, 26 May 2020 13:49:42 +0000 (14:49 +0100)]
Extend the error message displayed when a plugin fails to load.

* plugin.c (try_load_plugin): Extend error message when a plugin
fails to open.

4 years agotc-score.c: Replace overlapping sprintf with memmove
H.J. Lu [Tue, 26 May 2020 13:09:54 +0000 (06:09 -0700)]
tc-score.c: Replace overlapping sprintf with memmove

Fix GCC 10 warning:

gas/config/tc-score.c:4575:6: error: ‘sprintf’ argument 3 may overlap destination object ‘keep_data’ [-Werror=restrict]
 4575 |      sprintf (append_str, "bne %s", keep_data);
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

PR gas/26044
* onfig/tc-score.c (s3_do_macro_bcmp): Replace overlapping
sprintf with memmove.

4 years ago[gdb/testsuite] Add test-case gold-gdb-index.exp
Tom de Vries [Tue, 26 May 2020 09:35:32 +0000 (11:35 +0200)]
[gdb/testsuite] Add test-case gold-gdb-index.exp

There's a PR binutils/15646 - "gold-generated .gdb_index has duplicated
symbols that gdb-generated index doesn't", and gdb contains a workaround,
added in commit 8943b87476 "Work around gold/15646".

Add a test-case testing this workaround.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-05-26  Tom de Vries  <tdevries@suse.de>

* gdb.base/gold-gdb-index-2.c: New test.
* gdb.base/gold-gdb-index.c: New test.
* gdb.base/gold-gdb-index.exp: New file.
* gdb.base/gold-gdb-index.h: New test.

4 years agogas: Silence GCC 10 warning on tc-mcore.c
H.J. Lu [Tue, 26 May 2020 02:37:54 +0000 (19:37 -0700)]
gas: Silence GCC 10 warning on tc-mcore.c

* config/tc-mcore.c (md_convert_frag): Replace fragP->fr_literal
with &fragP->fr_literal[0].

4 years agotc-cr16.c: Use memmove to concatenate 2 overlapping strings
H.J. Lu [Tue, 26 May 2020 02:29:22 +0000 (19:29 -0700)]
tc-cr16.c: Use memmove to concatenate 2 overlapping strings

PR gas/26041
* config/tc-cr16.c (md_assemble): Use memmove to concatenate
2 overlapping strings.

4 years agoAutomatic date update in version.in
GDB Administrator [Tue, 26 May 2020 00:00:13 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agogas: Silence GCC 10 warning on tc-cr16.c
H.J. Lu [Mon, 25 May 2020 23:17:50 +0000 (16:17 -0700)]
gas: Silence GCC 10 warning on tc-cr16.c

* config/tc-cr16.c (md_convert_frag): Replace fragP->fr_literal
with &fragP->fr_literal[0].

4 years agoELF: Updated comments for ET_EXEC and ET_DYN
H.J. Lu [Mon, 25 May 2020 18:26:48 +0000 (11:26 -0700)]
ELF: Updated comments for ET_EXEC and ET_DYN

include/elf/common.h has

 #define ET_EXEC         2       /* Executable file */
 #define ET_DYN          3       /* Shared object file */

These predate PIE:

https://groups.google.com/forum/#!topic/generic-abi/mBKlSNldFW4

Updated comments to

 #define ET_EXEC         2       /* Position-dependent executable file */
 #define ET_DYN          3       /* Position-independent executable or
                                    shared object file */

* elf/common.h: Update comments for ET_EXEC and ET_DYN.

4 years ago[gdb/testsuite] Add target board gold-gdb-index
Tom de Vries [Mon, 25 May 2020 17:36:05 +0000 (19:36 +0200)]
[gdb/testsuite] Add target board gold-gdb-index

Add new target board that uses gold to add a .gdb_index section, enabled by
-ggnu-pubnames.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-05-25  Tom de Vries  <tdevries@suse.de>

* boards/gold-gdb-index.exp: New file.

4 years agogdb: make avr_integer_to_address generate code or data address based on type
Cristiano De Alti [Mon, 25 May 2020 15:55:56 +0000 (11:55 -0400)]
gdb: make avr_integer_to_address generate code or data address based on type

The AVR architecture is a Harvard one, meaning it has different memory
spaces for code and data.  In GDB, this is dealt with by having the data
(SRAM) addresses start at 0x00800000.  When interpreting an integer as
an address (converting to a CORE_ADDR), we currently always generate a
data address.  This doesn't work for some cases described below, where
the integer is meant to represent a code address.

This patch changes avr_integer_to_address so that it generates the
correct type of address (code or data) based on the passed type.

Using the simavr.exp board, I didn't see any regressions when running
the gdb.base/*.exp tests.  A few tests go from fail to pass, but none
from pass to fail.  There are a few new fails and unresolved, but it's
just because some tests manage to make more progress before failing in a
different way.

In practice, it fixes disassembling by address, as described in the PR:

    - (gdb) disassemble 0x12a,0x12b
    - Dump of assembler code from 0x12a to 0x12b:
    -    0x0000012a <main+0>: push    r28
    - End of assembler dump.

    + (gdb) disassemble 0x12a,0x12b
    + Dump of assembler code from 0x80012a to 0x80012b:
    +    0x0080012a:  nop
    + End of assembler dump.

And also, setting a breakpoint by address:

    - (gdb) p &main
    - $1 = (int (*)(void)) 0x12a <main>
    - (gdb) b *0x12a
    - Breakpoint 1 at 0x80012a

    + (gdb) p &main
    + $1 = (int (*)(void)) 0x12a <main>
    + (gdb) b *0x12a
    + Breakpoint 1 at 0x12a: file test-avr.c, line 3.
    + Note: automatically using hardware breakpoints for read-only addresses.

gdb/ChangeLog:

PR gdb/13519
* avr-tdep.c (avr_integer_to_address): Return data or code
address accordingly to the second 'type' argument of the
function.

Change-Id: Iaea1587d053e86f4ab8aebdcabec8d31a6d262cd

4 years agogdb/testsuite: add simavr.exp board
Simon Marchi [Mon, 25 May 2020 15:55:21 +0000 (11:55 -0400)]
gdb/testsuite: add simavr.exp board

This patch adds a board file for against a simavr target (so, for the
AVR architecture).

simavr, when started with option -g, runs a GDB stub on port 1234.  In
the current latest release (1.6), the port is hardcoded to 1234.  But in
master, there is the option to choose another port.  So while the board
file hardcodes the port today, in the future it should be possible to
let the user choose a port, or automatically select a free port.

It is easy enough to run, make sure you have avr-gcc/avr-g++ and simavr
installed, and as usual just run:

    make check RUNTESTFLAGS="--target_board=simavr"

The following environment variables influence the behavior of the board
file:

  - SIMAVR_MCU: type of chip to simulate
  - SIMAVR_PATH: path to simavr binary (useful if you build your own
    simavr or for some reason it is not simply called `simavr`.

As expected, there are a lot of failures.  Many tests use some features
not supported by such a target, and I suppose there are real GDB bugs
too.  But a lot also passes (including tests that actually run stuff),
so this board file should still help to validate changes to the AVR
architecture support.

These are the results I got of running tests gdb.base/*.exp:

    # of expected passes            20926
    # of unexpected failures        2257
    # of expected failures          14
    # of unknown successes          1
    # of known failures             13
    # of unresolved testcases       592
    # of untested testcases         156
    # of unsupported tests          30
    # of paths in test names        3
    # of duplicate test names       56

gdb/testsuite/ChangeLog:

* boards/simavr.exp: New file.

Change-Id: Ib7fa8c4e2e90b08b104bb9b552df37779de3bc21

4 years agogdb/testsuite: add inferior arguments test
Simon Marchi [Mon, 25 May 2020 15:15:01 +0000 (11:15 -0400)]
gdb/testsuite: add inferior arguments test

Add a test for verifying different methods of passing arguments to the
inferior: the start, starti and run commands, as well as `set args`.

All these methods work naturally when using the unix or
native-extended-gdbserver target boards.  Since those are non-stub
boards, GDB runs new inferiors and therefore pass arguments to them.
With target boards where GDB connects to a stub, for example with
native-gdbserver, they don't really make sense.  The inferior process is
already started when GDB connects.

However, the "run" method is still tested with stub targets, because the
gdb_run_cmd procedure is adapted for stub targets.  Instead of issuing
the `run` command, it spawns whatever program is supposed to bring up
the stub (gdbserver, for example) using gdb_reload and makes GDB connect
to it.  So this allows us to exercise argument passing through the
gdbserver command line, when testing with the native-gdbserver board.

Note that there is already a gdb.base/args.exp, but this tests
specifically the --args switch of GDB.  Perhaps it could be integrated
in this new test, as a new "method".

gdb/testsuite/ChangeLog:

* lib/gdb.exp (gdb_run_cmd): Return success or failure.
* gdb.base/inferior-args.exp: New file.
* gdb.base/inferior-args.c: New file.

Change-Id: Ib61ea6220a47f9f67aed2960dcacd240cb57af70

4 years agogdb/testsuite: support passing inferior arguments with native-gdbserver board
Simon Marchi [Mon, 25 May 2020 15:15:01 +0000 (11:15 -0400)]
gdb/testsuite: support passing inferior arguments with native-gdbserver board

This patch makes it possible to run tests requiring passing arguments to
the inferior with the native-gdbserver board.  The end goal is to write
a test that verifies passing arguments to the inferior works, and to
have that test exercise inferior arguments passed on the gdbserver
command line, when using the native-gdbserver target board (in addition
to the other boards).  This is done in the next patch.

With the native-gdbserver target board, gdbserver is started in
gdb_reload (implemented in config/gdbserver.exp), called in gdb_run_cmd.
gdb_run_cmd already supposedly accepts inferior arguments (although that
feature does not seem to be used anywhere), which it passes to the `run`
command, for non-stub target boards.  I've changed gdb_run_cmd so that
it forwards these arguments to gdb_reload as well.  gdb_reload passes
them to gdbserver_run, and they eventually make their way to the
gdbserver command line.

gdb_run_cmd currently accepts `args` (the varargs of tcl), which means
it receives inferior arguments as a list.  This won't work with
arguments with spaces, because they will end up being formatted with
curly braces like this:

    % set args [list hello "with spaces" world]
    hello {with spaces} world
    % puts "run $args"
    run hello {with spaces} world

I've changed it to accept a single string that is passed to `run` and
gdb_reload.  I've done the same change in gdb_start_cmd and
gdb_starti_cmd, although these two are not used with native-gdbserver.

I've changed all gdb_reload implementations in the tree to accept a new
inferior_args argument, although most of them don't do anything with it
(and don't need to).  People maintaining target boards out of tree will
need to do the same.

I found two tests to adjust to avoid adding new failures or errors.
These tests needed new [use_gdb_stub] checks, because they rely on
having GDB run new processes.  These are guarded by a [target_info
exists noargs], which made them get skipped on native-gdbserver.  But
now that the native-gdbserver board supports args, this is no longer
enough.

Note that with this change, noargs and use_gdb_stub are orthogonal.  It
took me a moment to grasp this, so I thought I would spell out the
different possible situations:

- !noargs and !use_gdb_stub: inferior process started by gdb, can pass
  args
- noargs and !use_gdb_stub: inferior process started by gdb (perhaps
  through extended-remote protocol, the simulator, some other target),
  but that target doesn't support inferior arguments
- noargs and use_gdb_stub: inferior process started by some other
  program to which GDB connects using the remote protocol, that program
  does not support passing args to the inferior process
- !noargs and use_gdb_stub: inferior process started by some other
  program to which GDB connects u sing the remote protocol, that program
  supports passing args to the inferior process

gdb/testsuite/ChangeLog:

* lib/gdb.exp (gdb_run_cmd): Change argument from args to
inferior_args.  Pass it to gdb_reload.
(gdb_start_cmd, gdb_starti_cmd): Change argument from args to
inferior_args.
(gdb_reload): Add inferior_args argument.
* config/gdbserver.exp (gdb_reload): Add inferior_args argument,
pass it to gdbserver_run.
* boards/native-gdbserver.exp: Do not set noargs.
* boards/native-extended-gdbserver.exp (gdb_reload): Add
inferior_args argument.
* boards/stdio-gdbserver-base.exp (gdb_reload): Likewise.
* gdb.base/a2-run.exp: Check for use_gdb_stub.
* gdb.base/args.exp: Likewise.

Change-Id: Ibda027c71867157852f34700342ab31edf39e4d8

4 years agogdbsupport: Drop now unused function 'stringify_argv'
Michael Weghorn [Mon, 25 May 2020 15:40:07 +0000 (11:40 -0400)]
gdbsupport: Drop now unused function 'stringify_argv'

The function did not properly escape special characters
and all uses have been replaced in previous commits, so
drop the now unused function.

gdbsupport/ChangeLog:

* common-utils.cc, common-utils.h (stringify_argv): Drop
now unused function stringify_argv

Change-Id: Id5f861f44eae1f0fbde3476a5eac23a842ed04fc

4 years agoUse construct_inferior_arguments which handles special chars
Michael Weghorn [Mon, 25 May 2020 15:39:43 +0000 (11:39 -0400)]
Use construct_inferior_arguments which handles special chars

Use the construct_inferior_arguments function instead of
stringify_argv to construct a string from the program
arguments in those places where that one is then passed
to fork_inferior (linux-low, lyn-low), since
construct_inferior_arguments properly takes care of
special characters, while stringify_argv does not.
Using construct_inferior_arguments seems "natural", since its
documentation also mentions that it "does the
same shell processing as fork_inferior".

Since construct_inferior_args has been extended to do
proper quoting for Windows shells in commit
5d60742e2dd3c9b475dce54b56043a358751bbb8
("Fix quoting of special characters for the MinGW build.",
2012-06-12), use it for the Windows case as well.
(I could not test that case myself, though.)

Adapt handling of empty args in function 'handle_v_run'
in gdbserver/server.cc to just insert an empty string
for an empty arg, since that one is now properly handled
in 'construct_inferior_arguments' already (and inserting
a "''" string in 'handle_v_run' would otherwise
cause that one to be treated as a string literally
containing two quote characters, which
'construct_inferior_args' would preserve by adding
extra escaping).

This makes gdbserver properly handle program args containing special
characters (like spaces), e.g. (example from PR25893)

  $ gdbserver localhost:50505 myprogram "hello world"

now properly handles "hello world" as a single arg, not two separate
ones ("hello", "world").

gdbserver/ChangeLog:

PR gdbserver/25893
* linux-low.cc (linux_process_target::create_inferior),
lynx-low.cc (lynx_process_target::create_inferior),
win32-low.cc (win32_process_target::create_inferior): Use
construct_inferior_arguments instead of stringify_argv
to get string representation which properly escapes
special characters.
* server.cc (handle_v_run): Just pass empty program arg
as such, since any further processing is now handled via
construct_inferior_arguments.

Change-Id: Ibf963fcd51415c948840fb463289516b3479b0c3