binutils-gdb.git
4 years agogdb: Represent all languages as sub-classes of language_defn
Andrew Burgess [Fri, 1 May 2020 11:16:58 +0000 (12:16 +0100)]
gdb: Represent all languages as sub-classes of language_defn

This commit converts all languages to sub-classes of a language_defn
base class.

The motivation for this change is to make it easier to add new methods
onto languages without having to update all of the individual language
structures.  In the future it might be possible to move more things,
like expression parsing, into the language class(es) for better
encapsulation, however I have no plans to tackle this in the short
term.

This commit sets up a strategy for transitioning from the current
language system, where each language is an instance of the
language_defn structure, to the class hierarchy system.

The plan is to rename the existing language_defn into language_data,
and make this a base class for the new language_defn class, something
like this:

  struct language_data
  {
    ... old language_defn fields here ...
  };

  struct language_defn : public language_data
  {
    language_defn (const language_data d)
      : language_data (d)
    { .... }
  };

Then each existing language, for example ada_language_defn can be
converted into an instance of language_data, and passed into the
constructor of a new language class, something like this:

  language_data ada_language_data =
  {
    ... old ada_language_defn values here ...
  };

  struct ada_language : public language_defn
  {
    ada_language (ada_language_data)
    { .... }
  };

What this means is that immediately after the conversion nothing much
changes.  Every language is now its own class, but all the old
language fields still exist and can be accessed in the same way.

In later commits I will convert function pointers from the old
language_defn structure into real class methods on language_defn, with
overrides on sub-classes where needed.

At this point I imagine that those fields of the old language_defn
structure that contained only data will probably remain as data fields
within the new language_data base structure, it is only the methods
that I plan to change initially.

I tweaked how we manage the list of languages a bit, each language is
now registered as it is created, and this resulted in a small number
of changes in language.c.

Most of the changes in the *-lang.c files are identical.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* gdb/ada-lang.c (ada_language_defn): Convert to...
(ada_language_data): ...this.
(class ada_language): New class.
(ada_language_defn): New static global.
* gdb/c-lang.c (c_language_defn): Convert to...
(c_language_data): ...this.
(class c_language): New class.
(c_language_defn): New static global.
(cplus_language_defn): Convert to...
(cplus_language_data): ...this.
(class cplus_language): New class.
(cplus_language_defn): New static global.
(asm_language_defn): Convert to...
(asm_language_data): ...this.
(class asm_language): New class.
(asm_language_defn): New static global.
(minimal_language_defn): Convert to...
(minimal_language_data): ...this.
(class minimal_language): New class.
(minimal_language_defn): New static global.
* gdb/d-lang.c (d_language_defn): Convert to...
(d_language_data): ...this.
(class d_language): New class.
(d_language_defn): New static global.
* gdb/f-lang.c (f_language_defn): Convert to...
(f_language_data): ...this.
(class f_language): New class.
(f_language_defn): New static global.
* gdb/go-lang.c (go_language_defn): Convert to...
(go_language_data): ...this.
(class go_language): New class.
(go_language_defn): New static global.
* gdb/language.c (unknown_language_defn): Remove declaration.
(current_language): Initialize to nullptr, real initialization is
moved to _initialize_language.
(languages): Delete global.
(language_defn::languages): Define.
(set_language_command): Use language_defn::languages.
(set_language): Likewise.
(range_error): Likewise.
(language_enum): Likewise.
(language_def): Likewise.
(add_set_language_command): Use language_def::languages for the
language list, and language_def to lookup language pointers.
(skip_language_trampoline): Use language_defn::languages.
(unknown_language_defn): Convert to...
(unknown_language_data): ...this.
(class unknown_language): New class.
(unknown_language_defn): New static global.
(auto_language_defn): Convert to...
(auto_language_data): ...this.
(class auto_language): New class.
(auto_language_defn): New static global.
(language_gdbarch_post_init): Use language_defn::languages.
(_initialize_language): Initialize current_language.
* gdb/language.h (struct language_defn): Rename to...
(struct language_data): ...this.
(struct language_defn): New.
(auto_language_defn): Delete.
(unknown_language_defn): Delete.
(minimal_language_defn): Delete.
(ada_language_defn): Delete.
(asm_language_defn): Delete.
(c_language_defn): Delete.
(cplus_language_defn): Delete.
(d_language_defn): Delete.
(f_language_defn): Delete.
(go_language_defn): Delete.
(m2_language_defn): Delete.
(objc_language_defn): Delete.
(opencl_language_defn): Delete.
(pascal_language_defn): Delete.
(rust_language_defn): Delete.
* gdb/m2-lang.c (m2_language_defn): Convert to...
(m2_language_data): ...this.
(class m2_language): New class.
(m2_language_defn): New static global.
* gdb/objc-lang.c (objc_language_defn): Convert to...
(objc_language_data): ...this.
(class objc_language): New class.
(objc_language_defn): New static global.
* gdb/opencl-lang.c (opencl_language_defn): Convert to...
(opencl_language_data): ...this.
(class opencl_language): New class.
(opencl_language_defn): New static global.
* gdb/p-lang.c (pascal_language_defn): Convert to...
(pascal_language_data): ...this.
(class pascal_language): New class.
(pascal_language_defn): New static global.
* gdb/rust-exp.y (rust_lex_tests): Use language_def to find
language pointer, update comment format.
* gdb/rust-lang.c (rust_language_defn): Convert to...
(rust_language_data): ...this.
(class rust_language): New class.
(rust_language_defn): New static global.

4 years ago[gdb/testsuite] Fix scrolling in gdb.dwarf2/multidictionary.exp
Tom de Vries [Tue, 2 Jun 2020 12:20:25 +0000 (14:20 +0200)]
[gdb/testsuite] Fix scrolling in gdb.dwarf2/multidictionary.exp

Consider a gdb_load patch to call the gdb_file_cmd twice:
...
 proc gdb_load { arg } {
     if { $arg != "" } {
+       set res [gdb_file_cmd $arg]
+       if { $res != 0 } {
+           return $res
+       }
        return [gdb_file_cmd $arg]
     }
     return 0
 }
...

With this patch, I run into:
...
(gdb) kill^M
The program is not being run.^M
(gdb) ^M</outputs/gdb.dwarf2/multidictionary/multidictionary^M
<.dwarf2/multidictionary/multidictionary"? (y or n)
ERROR: Couldn't load outputs/gdb.dwarf2/multidictionary/multidictionary \
  into gdb (timeout).
p 1^M
Please answer y or n.^M
<.dwarf2/multidictionary/multidictionary"? (y or n) n^M
Not confirmed.^M
(gdb) UNRESOLVED: gdb.dwarf2/multidictionary.exp: GDB is alive \
  (got interactive prompt)
...

The problem is that the second file command results in a prompt, which is
normally handled by gdb_file_cmd, but not recognized because the initial part
of the prompt is scrolled out.

This in turn is caused by using gdb_spawn_with_cmdline_opts without a
subsequent "set width 0".

Fix this by avoiding gdb_spawn_with_cmdline_opts, and forcing -readline by
temporarily modifying GDBFLAGS instead.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

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

* gdb.dwarf2/multidictionary.exp: Don't use
gdb_spawn_with_cmdline_opts.

4 years agobinutils archive tests
Alan Modra [Tue, 2 Jun 2020 05:30:14 +0000 (15:00 +0930)]
binutils archive tests

There are a number of targets that don't support thin archives (*),
and vms doesn't even support file name extensions other than .obj for
archives containing object files.  This patch adjusts the testsuite
to cater for the vms restriction, and reenables testing for non-ELF
alpha targets.  That adds a few alpha-dec-vms fails and one
alpha-linuxecoff fail but testsuite fails on those targets are nothing
new.

(*) It might seem like they do if binutils is built with
--enable-plugins but the plugin archive support is broken, causing the
wrong type of archives to be created by ar for those targets.

* testsuite/binutils-all/ar.exp (obj): Set up object file name
extension.  Use throughout.  Don't completely exclude non-ELF
alpha targets.  Run long_filenames test for tic30.  Exclude thin
archive tests for aix, ecoff and vms.
* estsuite/binutils-all/objdump.exp (obj): Set up object file name
extension.  Use throughout.  Don't exclude non-ELF alpha targets
from "bintest.a".

4 years agoELF: Move dyn_relocs to struct elf_link_hash_entry
H.J. Lu [Tue, 2 Jun 2020 01:18:43 +0000 (18:18 -0700)]
ELF: Move dyn_relocs to struct elf_link_hash_entry

All ELF backends with shared library support have

  /* Track dynamic relocs copied for this symbol.  */
  struct elf_dyn_relocs *dyn_relocs;

in symbol hash entry.  Move dyn_relocs to struct elf_link_hash_entry
to reduce code duplication.

PR ld/26067
* elf-bfd.h (elf_link_hash_entry): Add dyn_relocs after size.
* elf-s390-common.c (s390_elf_allocate_ifunc_dyn_relocs):
Updated.
* elf32-arc.c (elf_arc_link_hash_entry): Remove dyn_relocs.
(elf_arc_link_hash_newfunc): Updated.
* elf32-arm.c (elf32_arm_link_hash_entry): Remove dyn_relocs.
(elf32_arm_link_hash_newfunc): Updated.
(elf32_arm_copy_indirect_symbol): Likewise.
(elf32_arm_check_relocs): Likewise.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs_for_symbol): Likewise.
* elf32-csky.c (csky_elf_link_hash_entry): Remove dyn_relocs.
(csky_elf_link_hash_newfunc): Updated.
(csky_allocate_dynrelocs): Likewise.
(readonly_dynrelocs): Likewise.
(csky_elf_copy_indirect_symbol): Likewise.
* elf32-hppa.c (elf32_hppa_link_hash_entry): Remove dyn_relocs.
(hppa_link_hash_newfunc): Updated.
(elf32_hppa_copy_indirect_symbol): Likewise.
(elf32_hppa_hide_symbol): Likewise.
(elf32_hppa_adjust_dynamic_symbol): Likewise.
(allocate_dynrelocs): Likewise.
(elf32_hppa_relocate_section): Likewise.
* elf32-i386.c (elf_i386_check_relocs): Likewise.
* elf32-lm32.c (elf_lm32_link_hash_entry): Removed.
(lm32_elf_link_hash_newfunc): Likewise.
(lm32_elf_link_hash_table_create): Updated.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
(lm32_elf_copy_indirect_symbol): Likewise.
* elf32-m32r.c (elf_m32r_link_hash_entry): Removed.
(m32r_elf_link_hash_newfunc): Likewise.
(m32r_elf_link_hash_table_create): Updated.
(m32r_elf_copy_indirect_symbol): Likewise.
(allocate_dynrelocs): Likewise.
* elf32-metag.c (elf_metag_link_hash_entry): Remove dyn_relocs.
(metag_link_hash_newfunc): Updated.
(elf_metag_copy_indirect_symbol): Likewise.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
* elf32-microblaze.c (elf32_mb_link_hash_entry): Remove
dyn_relocs.
(link_hash_newfunc): Updated.
(microblaze_elf_check_relocs): Likewise.
(microblaze_elf_copy_indirect_symbol): Likewise.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
* elf32-nds32.c (elf_nds32_link_hash_entry): Remove dyn_relocs.
(nds32_elf_link_hash_newfunc): Updated.
(nds32_elf_copy_indirect_symbol): Likewise.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
(nds32_elf_check_relocs): Likewise.
* elf32-nios2.c (elf32_nios2_link_hash_entry): Remove dyn_relocs.
(link_hash_newfunc): Updated.
(nios2_elf32_copy_indirect_symbol): Likewise.
(nios2_elf32_check_relocs): Likewise.
(allocate_dynrelocs): Likewise.
* elf32-or1k.c (elf_or1k_link_hash_entry): Remove dyn_relocs.
(or1k_elf_link_hash_newfunc): Updated.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
(or1k_elf_copy_indirect_symbol): Likewise.
* elf32-ppc.c (ppc_elf_link_hash_entry): Remove dyn_relocs.
(ppc_elf_link_hash_newfunc): Updated.
(ppc_elf_copy_indirect_symbol): Likewise.
(ppc_elf_check_relocs): Likewise.
(readonly_dynrelocs): Likewise.
(ppc_elf_adjust_dynamic_symbol): Likewise.
(allocate_dynrelocs): Likewise.
(ppc_elf_relocate_section): Likewise.
* elf32-s390.c (elf_s390_link_hash_entry): Remove dyn_relocs.
(link_hash_newfunc): Updated.
(elf_s390_copy_indirect_symbol): Likewise.
(readonly_dynrelocs): Likewise.
(elf_s390_adjust_dynamic_symbol): Likewise.
(allocate_dynrelocs): Likewise.
* elf32-sh.c (elf_sh_link_hash_entry): Remove dyn_relocs.
(sh_elf_link_hash_newfunc): Updated.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
(sh_elf_copy_indirect_symbol): Likewise.
(sh_elf_check_relocs): Likewise.
* elf32-tic6x.c (elf32_tic6x_link_hash_entry): Removed.
(elf32_tic6x_link_hash_newfunc): Likewise.
(elf32_tic6x_link_hash_table_create): Updated.
(readonly_dynrelocs): Likewise.
(elf32_tic6x_check_relocs): Likewise.
(elf32_tic6x_allocate_dynrelocs): Likewise.
* elf32-tilepro.c (tilepro_elf_link_hash_entry): Remove
dyn_relocs.
(link_hash_newfunc): Updated.
(tilepro_elf_copy_indirect_symbol): Likewise.
(tilepro_elf_check_relocs): Likewise.
(allocate_dynrelocs): Likewise.
* elf64-ppc.c (ppc_link_hash_entry): Remove dyn_relocs.
(ppc64_elf_copy_indirect_symbol): Updated.
(ppc64_elf_check_relocs): Likewise.
(readonly_dynrelocs): Likewise.
(ppc64_elf_adjust_dynamic_symbol): Likewise.
(dec_dynrel_count): Likewise.
(allocate_dynrelocs): Likewise.
(ppc64_elf_relocate_section): Likewise.
* elf64-s390.c (elf_s390_link_hash_entry): Remove dyn_relocs.
(link_hash_newfunc): Updated.
(elf_s390_copy_indirect_symbol): Likewise.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
* elfnn-aarch64.c (elf_aarch64_link_hash_entry): Remove
dyn_relocs.
(elfNN_aarch64_link_hash_newfunc): Updated.
(elfNN_aarch64_copy_indirect_symbol): Likewise.
(readonly_dynrelocs): Likewise.
(need_copy_relocation_p): Likewise.
(elfNN_aarch64_allocate_dynrelocs): Likewise.
(elfNN_aarch64_allocate_ifunc_dynrelocs): Likewise.
* elfnn-riscv.c (riscv_elf_link_hash_entry): Remove dyn_relocs.
(link_hash_newfunc): Updated.
(riscv_elf_copy_indirect_symbol): Likewise.
(riscv_elf_check_relocs): Likewise.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
* elfxx-sparc.c (_bfd_sparc_elf_link_hash_entry): Remove
dyn_relocs.
(link_hash_newfunc): Updated.
(_bfd_sparc_elf_copy_indirect_symbol): Likewise.
(_bfd_sparc_elf_check_relocs): Likewise.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
* elfxx-tilegx.c (tilegx_elf_link_hash_entry): Remove dyn_relocs.
(link_hash_newfunc): Updated.
(tilegx_elf_copy_indirect_symbol): Likewise.
(tilegx_elf_check_relocs): Likewise.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
* elfxx-x86.c (elf_x86_allocate_dynrelocs): Likewise.
(readonly_dynrelocs): Likewise.
(_bfd_x86_elf_copy_indirect_symbol): Likewise.
* elfxx-x86.h (elf_x86_link_hash_entry): Remove dyn_relocs.

4 years agoAutomatic date update in version.in
GDB Administrator [Tue, 2 Jun 2020 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agogas: Fix checking for backwards .org with negative offset
Alex Coplan [Fri, 29 May 2020 15:04:50 +0000 (16:04 +0100)]
gas: Fix checking for backwards .org with negative offset

This patch fixes internal errors in (at least) arm and aarch64 GAS
when assembling code that attempts a negative .org.  The bug appears
to be a regression introduced in binutils-2.29 by commit 9875b36538d.

* write.c (relax_segment): Fix handling of negative offset when
relaxing an rs_org frag.
* testsuite/gas/aarch64/org-neg.d: New test.
* testsuite/gas/aarch64/org-neg.l: Error output for test.
* testsuite/gas/aarch64/org-neg.s: Input for test.
* testsuite/gas/arm/org-neg.d: New test.
* testsuite/gas/arm/org-neg.l: Error output for test.
* testsuite/gas/arm/org-neg.s: Input for test.

4 years agoalpha-vms: ETIR checks
Alan Modra [Mon, 1 Jun 2020 04:51:50 +0000 (14:21 +0930)]
alpha-vms: ETIR checks

Better validity checks, and remove a fuzzer vulnerability of sorts that
targeted the store-immediate-repeat command with a zero length but
very large repeat counts to chew cpu.

* vms-alpha.c (_bfd_vms_slurp_etir): Check bound for the current
command against cmd_length, not the end of record.  For
ETIR__C_STO_IMMR check size against cmd_length, mask repeat count
to 32-bits and break out on zero size.  Add ETIR__C_STC_LP_PSB
cmd_length test.

4 years agoRegen opcodes/bpf-desc.c
Alan Modra [Sat, 30 May 2020 02:46:43 +0000 (12:16 +0930)]
Regen opcodes/bpf-desc.c

The last regen used an old version of cgen.

* bpf-desc.c: Regenerate.

4 years agogdb: Preserve is-stmt lines when switch between files
Andrew Burgess [Fri, 3 Apr 2020 19:32:38 +0000 (20:32 +0100)]
gdb: Preserve is-stmt lines when switch between files

After the is-stmt support commit:

  commit 8c95582da858ac981f689a6f599acacb8c5c490f
  Date:   Mon Dec 30 21:04:51 2019 +0000

      gdb: Add support for tracking the DWARF line table is-stmt field

A regression was observed where a breakpoint could no longer be placed
in some cases.

Consider a line table like this:

  File 1: test.c
  File 2: test.h

  | Addr | File | Line | Stmt |
  |------|------|------|------|
  | 1    | 1    | 16   | Y    |
  | 2    | 1    | 17   | Y    |
  | 3    | 2    | 21   | Y    |
  | 4    | 2    | 22   | Y    |
  | 4    | 1    | 18   | N    |
  | 5    | 2    | 23   | N    |
  | 6    | 1    | 24   | Y    |
  | 7    | 1    | END  | Y    |
  |------|------|------|------|

Before the is-stmt patch GDB would ignore any non-stmt lines, so GDB
built two line table structures:

  File 1                 File 2
  ------                 ------

  | Addr | Line |        | Addr | Line |
  |------|------|        |------|------|
  | 1    | 16   |        | 3    | 21   |
  | 2    | 17   |        | 4    | 22   |
  | 3    | END  |        | 6    | END  |
  | 6    | 24   |        |------|------|
  | 7    | END  |
  |------|------|

After the is-stmt patch GDB now records non-stmt lines, so the
generated line table structures look like this:

  File 1                   File 2
  ------                   ------

  | Addr | Line | Stmt |  | Addr | Line | Stmt |
  |------|------|------|  |------|------|------|
  | 1    | 16   | Y    |  | 3    | 21   | Y    |
  | 2    | 17   | Y    |  | 4    | 22   | Y    |
  | 3    | END  | Y    |  | 4    | END  | Y    |
  | 4    | 18   | N    |  | 5    | 23   | N    |
  | 5    | END  | Y    |  | 6    | END  | Y    |
  | 6    | 24   | Y    |  |------|------|------|
  | 7    | END  | Y    |
  |------|------|------|

The problem is that in 'File 2', end END marker at address 4 causes
the previous line table entry to be discarded, so we actually end up
with this:

  File 2
  ------

  | Addr | Line | Stmt |
  |------|------|------|
  | 3    | 21   | Y    |
  | 4    | END  | Y    |
  | 5    | 23   | N    |
  | 6    | END  | Y    |
  |------|------|------|

When a user tries to place a breakpoint in file 2 at line 22, this is
no longer possible.

The solution I propose here is that we ignore line table entries that
would trigger a change of file if:

  1. The new line being added is at the same address as the previous
  line, and

  2. We have previously seen an is-stmt line at the current address.

The result of this is that GDB switches file, and knows that some line
entry (or entries) are going to be discarded, prefer to keep is-stmt
lines and discard non-stmt lines.

After this commit the lines tables are now:

  File 1                   File 2
  ------                   ------

  | Addr | Line | Stmt |  | Addr | Line | Stmt |
  |------|------|------|  |------|------|------|
  | 1    | 16   | Y    |  | 3    | 21   | Y    |
  | 2    | 17   | Y    |  | 4    | 22   | Y    |
  | 3    | END  | Y    |  | 5    | 23   | N    |
  | 5    | END  | Y    |  | 6    | END  | Y    |
  | 6    | 24   | Y    |  |------|------|------|
  | 7    | END  | Y    |
  |------|------|------|

We've lost the non-stmt entry for file 1, line 18, but retained the
is-stmt entry for file 2, line 22.  The user can now place a
breakpoint at that location.

One problem that came from this commit was the test
gdb.cp/step-and-next-inline.exp, which broke in several places.  After
looking at this test again I think that in some cases this test was
only ever passing by pure luck.  The debug GCC is producing for this
test is pretty broken.  I raised this GCC bug:

  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94474

for this and disabled one entire half of the test.  There are still
some cases in here that do pass, and if/when GCC is fixed it would be
great to enable this test again.

gdb/ChangeLog:

* dwarf2/read.c (class lnp_state_machine) <m_last_address>: New
member variable.
<m_stmt_at_address>: New member variable.
(lnp_state_machine::record_line): Don't record some lines, update
tracking of is_stmt at the same address.
(lnp_state_machine::lnp_state_machine): Initialise new member
variables.

gdb/testsuite/ChangeLog:

* gdb.cp/step-and-next-inline.exp (do_test): Skip all tests in the
use_header case.
* gdb.dwarf2/dw2-inline-header-1.exp: New file.
* gdb.dwarf2/dw2-inline-header-2.exp: New file.
* gdb.dwarf2/dw2-inline-header-3.exp: New file.
* gdb.dwarf2/dw2-inline-header-lbls.c: New file.
* gdb.dwarf2/dw2-inline-header.c: New file.
* gdb.dwarf2/dw2-inline-header.h: New file.

4 years agohurd: Add shared mig declarations
Samuel Thibault [Mon, 1 Jun 2020 07:50:14 +0000 (07:50 +0000)]
hurd: Add shared mig declarations

We are using -Werror=missing-declarations, and the _S.h files generated
by mig do not currently include a declaration for the server routine.
gnu-nat.c used to have its own external declarations, but better just
share them between gnu-nat.c and the _S.c files.

Fixes

exc_request_S.c:177:24: error: no previous declaration for ‘exc_server’ [-Werror=missing-declarations]
  177 | mig_external boolean_t exc_server

gdb/ChangeLog:

* config/i386/i386gnu.mn [%_S.o %_U.o] (COMPILE.post): Add
"-include gnu-nat-mig.h".
* gnu-nat-mig.h: New file.
* gnu-nat.c: Include "gnu-nat-mig.h".
(exc_server, msg_reply_server, notify_server,
process_reply_server): Remove declarations.

4 years agoAutomatic date update in version.in
GDB Administrator [Mon, 1 Jun 2020 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agognu-nat: Move local functions inside gnu_nat_target class
Samuel Thibault [Sun, 31 May 2020 07:42:10 +0000 (07:42 +0000)]
gnu-nat: Move local functions inside gnu_nat_target class

This allows to have the process_stratum_target object at hand for future use in
the gdb API, and only use gnu_target from external calls.

gdb/Changelog:

* gnu-nat.h (inf_validate_procs, inf_suspend, inf_set_traced,
steal_exc_port, proc_get_state, inf_clear_wait, inf_cleanup,
inf_startup, inf_update_suspends, inf_set_pid, inf_steal_exc_ports,
inf_validate_procinfo, inf_validate_task_sc, inf_restore_exc_ports,
inf_set_threads_resume_sc, inf_set_threads_resume_sc_for_signal_thread,
inf_resume, inf_set_step_thread, inf_detach, inf_attach, inf_signal,
inf_continue, make_proc, proc_abort, _proc_free, proc_update_sc,
proc_get_exception_port, proc_set_exception_port, _proc_get_exc_port,
proc_steal_exc_port, proc_restore_exc_port, proc_trace): Move functions
to gnu_nat_target class.
* gnu-nat.c: Likewise.
(inf_update_procs, S_proc_wait_reply, set_task_pause_cmd,
set_task_exc_port_cmd, set_signals_cmd, set_thread_pause_cmd,
set_thread_exc_port_cmd): Call inf_validate_procs through gnu_target
object.
(gnu_nat_target::create_inferior, gnu_nat_target::detach): Pass `this'
instead of `gnu_target'.

4 years agoAutomatic date update in version.in
GDB Administrator [Sun, 31 May 2020 00:00:20 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agohurd: unwinding support over signal trampolines
Samuel Thibault [Sat, 30 May 2020 18:45:30 +0000 (18:45 +0000)]
hurd: unwinding support over signal trampolines

This allows to get full backtrace from signal handlers, otherwise the
backtrace stops at the trampoline that calls the handler.

This needs special knowledge how the trampoline records register context
for the sigreturn call after signal handling.

gdb/ChangeLog:

* i386-gnu-tdep.c: Include "gdbcore.h"
(gnu_sigtramp_code, i386_gnu_sc_reg_offset): New arrays.
        (GNU_SIGTRAMP_LEN, GNU_SIGTRAMP_TAIL,
        I386_GNU_SIGCONTEXT_THREAD_STATE_OFFSET): New macros
        (i386_gnu_sigtramp_start, i386_gnu_sigtramp_p,
        i386_gnu_sigcontext_addr): New functions
        (i386gnu_init_abi): Register i386_gnu_sigtramp_p,
        i386_gnu_sigcontext_addr, and i386_gnu_sc_reg_offset in the gdbarch
        tdep.

4 years agohurd: fix pushing target on inferior creation
Samuel Thibault [Sat, 30 May 2020 18:44:17 +0000 (18:44 +0000)]
hurd: fix pushing target on inferior creation

This fixes creating inferiors, which was broken since 5b6d1e4fa
('Multi-target support')

gdb/ChangeLog:

* gnu-nat.c (gnu_nat_target::create_inferior): Move push_target call
before fork_inferior call. Avoid calling it if target_is_pushed returns
true.

4 years agohurd: add gnu_target pointer to fix thread API calls
Samuel Thibault [Sat, 30 May 2020 18:43:25 +0000 (18:43 +0000)]
hurd: add gnu_target pointer to fix thread API calls

Fixes

../../gdb/gnu-nat.c:1110:28: error: cannot convert ‘ptid_t’ to ‘process_stratum_target*’
 1110 |        thread_change_ptid (inferior_ptid, ptid);

and others related to 5b6d1e4fa ("Multi-target support")

gdb/ChangeLog:

* gnu-nat.h (gnu_target): New variable declaration.
* i386-gnu-nat.c (_initialize_i386gnu_nat): Initialize
gnu_target.
* gnu-nat.c (gnu_target): New variable.
(inf_validate_procs): Pass gnu_target to thread_change_ptid,
add_thread_silent, and add_thread calls.
(gnu_nat_target::create_inferior): Pass gnu_target to
add_thread_silent, thread_change_ptid call.
(gnu_nat_target::detach): Pass gnu_target to detach_inferior
call.

4 years agohurd: remove unused variables
Samuel Thibault [Sat, 30 May 2020 18:42:17 +0000 (18:42 +0000)]
hurd: remove unused variables

Fixes

../../gdb/gnu-nat.c:2554:7: error: unused variable ‘res’ [-Werror=unused-variable]
 2554 |   int res;
../../gdb/gnu-nat.c:2644:20: error: unused variable ‘old_address’ [-Werror=unused-variable]
 2644 |       vm_address_t old_address = region_address;

gdb/ChangeLog:

* gnu-nat.c (gnu_xfer_auxv): Remove unused `res' variable.
(gnu_nat_target::find_memory_regions): Remove unused
`old_address' variable.

4 years agohurd: add missing include
Samuel Thibault [Sat, 30 May 2020 18:41:30 +0000 (18:41 +0000)]
hurd: add missing include

Fixes

../../gdb/gnu-nat.c:2522:14: error: ‘target_gdbarch’ was not declared in this scope; did you mean ‘target_detach’?
 2522 |    paddress (target_gdbarch (), memaddr), pulongest (len),

gdb/Changelog:

* gnu-nat.c: Include "gdbarch.h".

4 years agohurd: make function cast stronger
Samuel Thibault [Sat, 30 May 2020 18:38:46 +0000 (18:38 +0000)]
hurd: make function cast stronger

Fixes

process_reply_S.c:104:23: error: function called through a non-compatible type [-Werror]
  104 |      OutP->RetCode = (*(kern_return_t (*)(mach_port_t, kern_return_t)) S_proc_setmsgport_reply) (In0P->Head.msgh_request_port, In0P-

As the existing comment says, it is in general not safe to drop some
parameters like this, but this is the error handling case, where the
called function does not actually read them, and mig is currently planned
to be used on i386 and x86_64 only, where this is not a problem. As the
existing comment says, fixing it properly would be far from trivial:
we can't just pass 0 for them, as they might not be scalar.

gdb/ChangeLog:

* reply_mig_hack.awk (Error return): Cast function through
void *, to bypass compiler function call check.

4 years agohurd: add missing awk script dependency
Samuel Thibault [Sat, 30 May 2020 18:37:54 +0000 (18:37 +0000)]
hurd: add missing awk script dependency

To make sure the *_reply_S.[ch] files get regenerated whenever we change
the awk script.

gdb/ChangeLog:

* config/i386/i386gnu.mn (%_reply_S.c): Add dependency on
$(srcdir)/reply_mig_hack.awk.

4 years agohurd: fix gnu_debug_flag type
Samuel Thibault [Sat, 30 May 2020 18:35:59 +0000 (18:35 +0000)]
hurd: fix gnu_debug_flag type

Fixes

../../gdb/gnu-nat.c:96:6: error: conflicting declaration ‘bool gnu_debug_flag’
   96 | bool gnu_debug_flag = false;
../../gdb/gnu-nat.c: In function ‘void _initialize_gnu_nat()’:
../../gdb/gnu-nat.c:3511:7: error: cannot

gdb/ChangeLog:

* gnu-nat.h (gnu_debug_flag): Set type to bool.

4 years agogdb: change bug URL to https
Jonny Grant [Sat, 30 May 2020 15:17:28 +0000 (11:17 -0400)]
gdb: change bug URL to https

gdb/ChangeLog:

* configure.ac (ACX_BUGURL): change bug URL to https.

Signed-off-by: Jonny Grant <jg@jguk.org>
Change-Id: If8d939e50c830e3e452c3e8f7a7aee06d9c96645

4 years agoreplace_typedefs: handle templates in namespaces
Pedro Alves [Sat, 30 May 2020 13:20:10 +0000 (14:20 +0100)]
replace_typedefs: handle templates in namespaces

GDB currently crashes with infinite recursion, if you set a breakpoint
on a function inside a namespace that includes a template on its fully
qualified name, and, the template's name is also used as typedef in
the global scope that expands to a name that includes the template
name in its qualified name.  For example, from the testcase added by
this commit:

 namespace NS1 { namespace NS2 {

 template<typename T> struct Templ1
 {
   T x;

   Templ1 (object_p) {}
 }} // namespace NS1::NS2

 using Templ1 = NS1::NS2::Templ1<unsigned>;

Setting a breakpoint like so:

(gdb) break NS1::NS2::Templ1<int>::Templ1(NS1::NS2::object*)

Results in infinite recursion, with this cycle (started by
cp_canonicalize_string_full) repeating until the stack is exhausted:

 ...
 #1709 0x000000000055533c in inspect_type (info=0x38ff720, ret_comp=0xd83be10, finder=0x0, data=0x0) at /home/pedro/gdb/mygit/src/gdb/cp-support.c:267
 #1710 0x0000000000555a6f in replace_typedefs (info=0x38ff720, ret_comp=0xd83be10, finder=0x0, data=0x0) at /home/pedro/gdb/mygit/src/gdb/cp-support.c:475
 #1711 0x0000000000555a36 in replace_typedefs (info=0x38ff720, ret_comp=0xd83be70, finder=0x0, data=0x0) at /home/pedro/gdb/mygit/src/gdb/cp-support.c:470
 #1712 0x0000000000555800 in replace_typedefs_qualified_name (info=0x38ff720, ret_comp=0xd839470, finder=0x0, data=0x0) at /home/pedro/gdb/mygit/src/gdb/cp-support.c:389
 #1713 0x0000000000555a8c in replace_typedefs (info=0x38ff720, ret_comp=0xd839470, finder=0x0, data=0x0) at /home/pedro/gdb/mygit/src/gdb/cp-support.c:479
 ...

The demangle component tree for that symbol name looks like this:

d_dump tree for NS1::NS2::Templ1<int>::Templ1(NS1::NS2::object*):
typed name
  qualified name
    name 'NS1'
    qualified name
      name 'NS2'
      qualified name
        template                  <<<<<<<<<<
          name 'Templ1'
          template argument list
            builtin type int
        name 'Templ1'
  function type
    argument list
      pointer
        qualified name
          name 'NS1'
          qualified name
            name 'NS2'
            name 'object'

The recursion starts at replace_typedefs_qualified_name, which doesn't
handle the "template" node, and thus doesn't realize that the template
name actually has the fully qualified name NS1::NS2::Templ1.
replace_typedefs_qualified_name calls into replace_typedefs on the
template node, and that ends up in inspect_type looking up for a
symbol named "Templ1", which finds the global namespace typedef, which
itself expands to NS1::NS2::Templ1.  GDB then tries replacing typedefs
in that newly expanded name, which ends up again in
replace_typedefs_qualified_name, trying to expand a fully qualified
name with "NS::NS2::Templ1<unsigned>" in its name, which results in
recursion whenever the template node is reached.

Fix this by teaching replace_typedefs_qualified_name how to handle
template nodes.  It needs handling in two places: the first spot
handles the symbol above; the second spot handles a symbol like this,
from the new test:

(gdb) b NS1::NS2::grab_it(NS1::NS2::Templ1<int>*)
d_dump tree for NS1::NS2::grab_it(NS1::NS2::Templ1<int>*):
typed name
  qualified name
    name 'NS1'
    qualified name
      name 'NS2'
      name 'grab_it'
  function type
    argument list
      pointer
        qualified name
          name 'NS1'
          qualified name
            name 'NS2'
            template             <<<<<<<<
              name 'Templ1'
              template argument list
                builtin type int

What's different in this case is that the template node appears on the
right child node of a qualified name, instead of on the left child.

The testcase includes a test that checks whether template aliases are
correctly replaced by GDB too.  That fails with GCC due to GCC PR
95437, which makes GDB not know about a typedef for
"NS1::NS2::AliasTempl<int>".  GCC emits a typedef named
"NS1::NS2::AliasTempl" instead, with no template parameter info.  The
test passes with Clang (5.0.2 at least).  See more details here:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95437

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

* cp-support.c (replace_typedefs_template): New.
(replace_typedefs_qualified_name): Handle
DEMANGLE_COMPONENT_TEMPLATE.

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

* gdb.linespec/cp-replace-typedefs-ns-template.cc: New.
* gdb.linespec/cp-replace-typedefs-ns-template.exp: New.

4 years agoAutomatic date update in version.in
GDB Administrator [Sat, 30 May 2020 00:00:19 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agogdb: rename dwarf2_per_objfile variables/fields to per_objfile
Simon Marchi [Fri, 29 May 2020 19:15:10 +0000 (15:15 -0400)]
gdb: rename dwarf2_per_objfile variables/fields to per_objfile

While doing the psymtab-sharing patchset, I avoided renaming variables
unnecessarily to avoid adding noise to patches, but I'd like to do it
now.  Basically, we have these dwarf2 per-something structures:

  - dwarf2_per_objfile
  - dwarf2_per_bfd
  - dwarf2_per_cu_data

I named the instances of dwarf2_per_bfd `per_bfd` and most of instances
of dwarf2_per_cu_data are called `per_cu`.  Most pre-existing instances
of dwarf2_per_objfile are named `dwarf2_per_objfile`.  For consistency
with the other type, I'd like to rename them to just `per_objfile`.  The
`dwarf2_` prefix is superfluous, since it's already clear we are in
dwarf2 code.  It also helps reducing the line wrapping by saving 7
precious columns.

gdb/ChangeLog:

* dwarf2/comp-unit.c, dwarf2/comp-unit.h, dwarf2/index-cache.c,
dwarf2/index-cache.h, dwarf2/index-write.c,
dwarf2/index-write.h, dwarf2/line-header.c,
dwarf2/line-header.h, dwarf2/macro.c, dwarf2/macro.h,
dwarf2/read.c, dwarf2/read.h: Rename struct dwarf2_per_objfile
variables and fields from `dwarf2_per_objfile` to just
`per_objfile` throughout.

Change-Id: I3c45cdcc561265e90df82cbd36b4b4ef2fa73aef

4 years agoFix build errors in with clang in gdb.compile/compile-cplus.c
Gary Benson [Fri, 29 May 2020 16:43:17 +0000 (17:43 +0100)]
Fix build errors in with clang in gdb.compile/compile-cplus.c

Clang fails to compile the file, with the following error:
  fatal error: 'iostream' file not found

This prevents the following testcase from executing:
  gdb.compile/compile-cplus.exp

The testcase sets additional_flags when building with GCC, which
this commit causes to also be set when building with clang.  This
makes the testcase fail to build with a different error:
  warning: treating 'c' input as 'c++' when in C++ mode, this behavior
  is deprecated [-Wdeprecated]
so this commit adds -Wno-deprecated in two places to sidestep this.
Note that, while allowing the testcase to build, this commit reveals
failures when the testsuite is built using clang.

gdb/testsuite/ChangeLog:

* gdb.compile/compile-cplus.exp (additional_flags): Also
set when building with clang.
(additional_flags, srcfilesoptions): Pass -Wno-deprecated
when building with clang.

4 years agoFix file-not-found error with clang in gdb.arch/i386-{avx,sse}.c
Gary Benson [Fri, 29 May 2020 16:15:13 +0000 (17:15 +0100)]
Fix file-not-found error with clang in gdb.arch/i386-{avx,sse}.c

Clang fails to compile two testcases with the following error:
  fatal error: 'nat/x86-cpuid.h' file not found

This prevents the following testcases from executing:
  gdb.arch/i386-avx.exp
  gdb.arch/i386-sse.exp

Both testcases set additional_flags when building with GCC.
This commit causes the additional_flags to also be used when
building with clang.  Note that, while fixing the build, this
commit reveals several new failures when using clang to build
the testsuite.

gdb/testsuite/ChangeLog:

* gdb.arch/i386-avx.exp (additional_flags): Also set when
building with clang.
* gdb.arch/i386-sse.exp (additional_flags): Likewise.

4 years agoBuild two gdb.cp testcases with -Wno-unused-comparison
Gary Benson [Fri, 29 May 2020 13:03:01 +0000 (14:03 +0100)]
Build two gdb.cp testcases with -Wno-unused-comparison

Clang fails to compile two testcases with the following error:
  warning: equality comparison result unused [-Wunused-comparison]

This prevents the following testcases from executing:
  gdb.cp/koenig.exp
  gdb.cp/operator.exp

This commit builds those testcases with -Wno-unused-comparison, to
avoid the failure.  Note that this commit reveals a new failure,
"FAIL: gdb.cp/koenig.exp: p foo (p_union)" when the testsuite is
compiled using clang.

gdb/testsuite/ChangeLog:

* gdb.cp/koenig.exp (prepare_for_testing): Add
additional_flags=-Wno-unused-comparison.
* gdb.cp/operator.exp (prepare_for_testing): Likewise.

4 years agobinutils: Add myself as Xtensa maintainer
Max Filippov [Fri, 29 May 2020 04:05:46 +0000 (21:05 -0700)]
binutils: Add myself as Xtensa maintainer

2020-05-28  Max Filippov  <jcmvbkbc@gmail.com>
binutils/
* MAINTAINERS (Xtensa): Add myself as maintainer.

4 years agoAutomatic date update in version.in
GDB Administrator [Fri, 29 May 2020 00:00:14 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agobfd: fix handling of R_BPF_INSN_{32,64} relocations.
David Faust [Thu, 28 May 2020 18:53:29 +0000 (20:53 +0200)]
bfd: fix handling of R_BPF_INSN_{32,64} relocations.

2020-05-28  David Faust  <david.faust@oracle.com>

* elf64-bpf.c (bpf_elf_relocate_section): Fix handling of
R_BPF_INSN_{32,64} relocations.

4 years agocpu,opcodes: add instruction semantics to bpf.cpu and minor fixes
Jose E. Marchesi [Thu, 28 May 2020 14:53:54 +0000 (16:53 +0200)]
cpu,opcodes: add instruction semantics to bpf.cpu and minor fixes

This patch adds semantic RTL descriptions to the eBPF instructions
defined in cpu/bpf.cpu.  It also contains a couple of minor
improvements.

Tested in bpf-unknown-none targets.
No regressions.

cpu/ChangeLog:

2020-05-28  Jose E. Marchesi  <jose.marchesi@oracle.com>
    David Faust <david.faust@oracle.com>

* bpf.cpu (define-alu-insn-un): Add definitions of semantics.
(define-alu-insn-mov): Likewise.
(daib): Likewise.
(define-alu-instructions): Likewise.
(define-endian-insn): Likewise.
(define-lddw): Likewise.
(dlabs): Likewise.
(dlind): Likewise.
(dxli): Likewise.
(dxsi): Likewise.
(dsti): Likewise.
(define-ldstx-insns): Likewise.
(define-st-insns): Likewise.
(define-cond-jump-insn): Likewise.
(dcji): Likewise.
(define-condjump-insns): Likewise.
(define-call-insn): Likewise.
(ja): Likewise.
("exit"): Likewise.
(define-atomic-insns): Likewise.
(sem-exchange-and-add): New macro.
* bpf.cpu ("brkpt"): New instruction.
(bpfbf): Set word-bitsize to 32 and insn-endian big.
(h-gpr): Prefer r0 to `a' and r6 to `ctx'.
(h-pc): Expand definition.
* bpf.opc (bpf_print_insn): Set endian_code to BIG.

opcodes/ChangeLog:

2020-05-28  Jose E. Marchesi  <jose.marchesi@oracle.com>
    David Faust <david.faust@oracle.com>

* bpf-desc.c: Regenerate.
* bpf-opc.h: Likewise.
* bpf-opc.c: Likewise.
* bpf-dis.c: Likewise.

4 years agogdb: add comment in dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value
Simon Marchi [Thu, 28 May 2020 19:47:53 +0000 (15:47 -0400)]
gdb: add comment in dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value

Add a comment to clarify why we temporarily override some of the
context's fields, and especially the per_objfile field.  A longer
explanation can be found in this previous commit

    44486dcf19b ("gdb: use caller objfile in dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value")

gdb/ChangeLog:

* dwarf2/loc.c (class dwarf_evaluate_loc_desc)
<push_dwarf_reg_entry_value>: Add comment.

Change-Id: I60c6e1062799f729b30a9db78bcb6448783324b4

4 years agoFix Python3.9 related runtime problems
Kevin Buettner [Thu, 28 May 2020 03:05:40 +0000 (20:05 -0700)]
Fix Python3.9 related runtime problems

Python3.9b1 is now available on Rawhide.  GDB w/ Python 3.9 support
can be built using the configure switch -with-python=/usr/bin/python3.9.

Attempting to run gdb/Python3.9 segfaults on startup:

    #0  0x00007ffff7b0582c in PyEval_ReleaseLock () from /lib64/libpython3.9.so.1.0
    #1  0x000000000069ccbf in do_start_initialization ()
at worktree-test1/gdb/python/python.c:1789
    #2  _initialize_python ()
at worktree-test1/gdb/python/python.c:1877
    #3  0x00000000007afb0a in initialize_all_files () at init.c:237
    ...

Consulting the the documentation...

https://docs.python.org/3/c-api/init.html

...we find that PyEval_ReleaseLock() has been deprecated since version
3.2.  It recommends using PyEval_SaveThread or PyEval_ReleaseThread()
instead.  In do_start_initialization, in gdb/python/python.c, we
can replace the calls to PyThreadState_Swap() and PyEval_ReleaseLock()
with a single call to PyEval_SaveThread.   (Thanks to Keith Seitz
for working this out.)

With that in place, GDB gets a little bit further.  It still dies
on startup, but the backtrace is different:

    #0  0x00007ffff7b04306 in PyOS_InterruptOccurred ()
       from /lib64/libpython3.9.so.1.0
    #1  0x0000000000576e86 in check_quit_flag ()
at worktree-test1/gdb/extension.c:776
    #2  0x0000000000576f8a in set_active_ext_lang (now_active=now_active@entry=0x983c00 <extension_language_python>)
at worktree-test1/gdb/extension.c:705
    #3  0x000000000069d399 in gdbpy_enter::gdbpy_enter (this=0x7fffffffd2d0,
gdbarch=0x0, language=0x0)
at worktree-test1/gdb/python/python.c:211
    #4  0x0000000000686e00 in python_new_inferior (inf=0xddeb10)
at worktree-test1/gdb/python/py-inferior.c:251
    #5  0x00000000005d9fb9 in std::function<void (inferior*)>::operator()(inferior*) const (__args#0=<optimized out>, this=0xccad20)
at /usr/include/c++/10/bits/std_function.h:617
    #6  gdb::observers::observable<inferior*>::notify (args#0=0xddeb10,
this=<optimized out>)
at worktree-test1/gdb/../gdbsupport/observable.h:106
    #7  add_inferior_silent (pid=0)
at worktree-test1/gdb/inferior.c:113
    #8  0x00000000005dbcb8 in initialize_inferiors ()
at worktree-test1/gdb/inferior.c:947
    ...

We checked with some Python Developers and were told that we should
acquire the GIL prior to calling any Python C API function.  We
definitely don't have the GIL for calls of PyOS_InterruptOccurred().

I moved class_gdbpy_gil earlier in the file and use it in
gdbpy_check_quit_flag() to acquire (and automatically release) the
GIL.

With those changes in place, I was able to run to a GDB prompt.  But,
when trying to quit, it segfaulted again due to due to some other
problems with gdbpy_check_quit_flag():

    Thread 1 "gdb" received signal SIGSEGV, Segmentation fault.
    0x00007ffff7bbab0c in new_threadstate () from /lib64/libpython3.9.so.1.0
    (top-gdb) bt 8
    #0  0x00007ffff7bbab0c in new_threadstate () from /lib64/libpython3.9.so.1.0
    #1  0x00007ffff7afa5ea in PyGILState_Ensure.cold ()
       from /lib64/libpython3.9.so.1.0
    #2  0x000000000069b58c in gdbpy_gil::gdbpy_gil (this=<synthetic pointer>)
at worktree-test1/gdb/python/python.c:278
    #3  gdbpy_check_quit_flag (extlang=<optimized out>)
at worktree-test1/gdb/python/python.c:278
    #4  0x0000000000576e96 in check_quit_flag ()
at worktree-test1/gdb/extension.c:776
    #5  0x000000000057700c in restore_active_ext_lang (previous=0xe9c050)
at worktree-test1/gdb/extension.c:729
    #6  0x000000000088913a in do_my_cleanups (
pmy_chain=0xc31870 <final_cleanup_chain>,
old_chain=0xae5720 <sentinel_cleanup>)
at worktree-test1/gdbsupport/cleanups.cc:131
    #7  do_final_cleanups ()
at worktree-test1/gdbsupport/cleanups.cc:143

In this case, we're trying to call a Python C API function after
Py_Finalize() has been called from finalize_python().  I made
finalize_python set gdb_python_initialized to false and then cause
check_quit_flag() to return early when it's false.

With these changes in place, GDB seems to be working again with
Python3.9b1.  I think it likely that there are other problems lurking.
I wouldn't be surprised to find that there are other calls into Python
where we don't first make sure that we have the GIL.  Further changes
may well be needed.

I see no regressions testing on Rawhide using a GDB built with the
default Python version (3.8.3) versus one built using Python 3.9b1.

I've also tested on Fedora 28, 29, 30, 31, and 32 (all x86_64) using
the default (though updated) system installed versions of Python on
those OSes.  This means that I've tested against Python versions
2.7.15, 2.7.17, 2.7.18, 3.7.7, 3.8.2, and 3.8.3.  In each case GDB
still builds without problem and shows no regressions after applying
this patch.

gdb/ChangeLog:

2020-MM-DD  Kevin Buettner  <kevinb@redhat.com>
    Keith Seitz  <keiths@redhat.com>

* python/python.c (do_start_initialization): For Python 3.9 and
later, call PyEval_SaveThread instead of PyEval_ReleaseLock.
(class gdbpy_gil): Move to earlier in file.
(finalize_python): Set gdb_python_initialized.
(gdbpy_check_quit_flag): Acquire GIL via gdbpy_gil.  Return early
when not initialized.

4 years agoFix all unexpected failures in gas testsuite for pdp11-aout.
Stephen Casner [Thu, 28 May 2020 17:11:59 +0000 (10:11 -0700)]
Fix all unexpected failures in gas testsuite for pdp11-aout.

These failures were caused by the PDP11's mix of little-endian octets
in shorts but shorts in big endian order for long or quad so regexps
did not match.  Also tests used addresses as values in .long which
required BRD_RELOC_32 that was not implemented.

* gas/config/tc-pdp11.c (md_number_to_chars): Implement .quad
* gas/testsuite/gas/all/gas.exp: Select alternate test scripts for
pdp11, skip octa test completely.
* gas/testsuite/gas/all/eqv-dot-pdp11.s: Identical to eqv-dot.s
* gas/testsuite/gas/all/eqv-dot-pdp11.d: Match different octet order.
* gas/testsuite/gas/all/cond-pdp11.l: Match different octet order.

* bfd/pdp11.c: Implement BRD_RELOC_32 to relocate the low 16 bits of
addreses in .long (used in testsuites) and .stab values.

4 years agoFix "enumeration values not handled in switch" error in testsuite
Gary Benson [Thu, 28 May 2020 17:02:55 +0000 (18:02 +0100)]
Fix "enumeration values not handled in switch" error in testsuite

When running the testsuite with clang, gdb.base/sigaltstack.c
fails to compile with the following error:
  warning: enumeration values 'LEAF' and 'NR_LEVELS' not handled
    in switch [-Wswitch]

This prevents the gdb.base/sigaltstack.exp from executing.
This commit fixes.

gdb/testsuite/ChangeLog:

* gdb.base/sigaltstack.c (catcher): Add default case to switch
statement.

4 years agoHave the linker fail if any attempt to link in an executable is made.
Nick Clifton [Thu, 28 May 2020 16:43:21 +0000 (17:43 +0100)]
Have the linker fail if any attempt to link in an executable is made.

PR 26047
* ldelf.c (ldelf_after_open): Fail if attempting to link one
executable into another.  Ensure that the test is made for all
forms of linking.

4 years agoStop the linker from accepting executable ELF files as inputs to other links.
Nick Clifton [Thu, 28 May 2020 15:43:01 +0000 (16:43 +0100)]
Stop the linker from accepting executable ELF files as inputs to other links.

PR 26047
* ldelf.c (ldelf_after_open): Fail if attempting to link one
executable into another.

4 years agogdb: use caller objfile in dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value
Simon Marchi [Thu, 28 May 2020 15:30:11 +0000 (11:30 -0400)]
gdb: use caller objfile in dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value

In commit

    89b07335fe ("Add dwarf2_per_objfile to dwarf_expr_context and dwarf2_frame_cache")

I replaced the offset property of dwarf_expr_context by a per_objfile
property (since we can get the text offset from the objfile).  The
previous code in dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value
(dwarf_evaluate_loc_desc derives from dwarf_expr_context) did
temporarily override the offset property while evaluating a DWARF
sub-expression.  I speculated that this sub-expression always came from
the same objfile as the outer expression, so I didn't see the need to
temporarily override the per_objfile property in the new code.  A later
commit:

    9f47c70716 ("Remove dwarf2_per_cu_data::objfile ()")

added the following assertion to verify this:

    gdb_assert (this->per_objfile == caller_per_objfile);

It turns out that this is not true.  Call sites can refer to function in
another objfile, and therefore the caller's objfile can be different
from the callee's objfile.  This can happen when the call site DIE in the
DWARF represents a function call done through a function pointer.  The
DIE can't describe statically which function is being called, since it's
variable and not known at compile time.  Instead, it provides an
expression that evaluates to the address of the function being called.
In this case, the called function can very well be in a separate
objfile.

Fix this by overriding the per_objfile property while evaluating the
sub-expression.

This was exposed by the gdb.base/catch-load.exp test failing on openSUSE
Tumbleweed with the glibc debug info installed.  It was also reported to
fail on Fedora.

When I investigated the problem, the particular call site on which we
did hit the assert was coming from this DIE, in
/usr/lib/debug/lib64/libc-2.31.so-2.31-5.1.x86_64.debug on openSUSE
Tumbleweed:

    0x0091aa10:     DW_TAG_GNU_call_site
                      DW_AT_low_pc [DW_FORM_addr]   (0x00000000001398e0)
                      DW_AT_GNU_call_site_target [DW_FORM_exprloc]  (DW_OP_fbreg -272, DW_OP_deref)
                      DW_AT_sibling [DW_FORM_ref4]  (0x0091aa2b)

And for you curious out there, this call site is found in this function:

    0x0091a91d:   DW_TAG_subprogram
                    DW_AT_external [DW_FORM_flag_present]   (true)
                    DW_AT_name [DW_FORM_strp]       ("_dl_catch_exception")
                    DW_AT_decl_file [DW_FORM_data1] ("/usr/src/debug/glibc-2.31-5.1.x86_64/elf/dl-error-skeleton.c")
                    ...

Which is a function that indeed uses a function pointer.

gdb/ChangeLog:

* dwarf2/loc.c (class dwarf_evaluate_loc_desc)
<push_dwarf_reg_entry_value>: Remove assert.  Override
per_objfile with caller_per_objfile.

Change-Id: Ib227d767ce525c10607ab6621a373aaae982c67a

4 years agoPass -Wno-deprecated-register for gdb.cp that use "register"
Gary Benson [Thu, 28 May 2020 15:29:48 +0000 (16:29 +0100)]
Pass -Wno-deprecated-register for gdb.cp that use "register"

Clang fails to compile three testcases with the following error:
  warning: 'register' storage class specifier is deprecated and
    incompatible with C++17 [-Wdeprecated-register]

This prevents the following testcases from executing:
  gdb.cp/classes.exp
  gdb.cp/inherit.exp
  gdb.cp/misc.exp

This commit builds those testcases with -Wno-deprecated-register, to
avoid the failure.  Note that this commit reveals five "wrong access
specifier for typedef" failures in gdb.cp/classes.exp when compiling
the testsuite with clang.

gdb/testsuite/ChangeLog:

* gdb.cp/classes.exp (prepare_for_testing): Add
additional_flags=-Wno-deprecated-register.
* gdb.cp/inherit.exp (prepare_for_testing): Likewise.
* gdb.cp/misc.exp: Likewise.

4 years ago[gdb/symtab] Make gold index workaround more precise
Tom de Vries [Thu, 28 May 2020 15:26:22 +0000 (17:26 +0200)]
[gdb/symtab] Make gold index workaround more precise

There's a PR gold/15646 - "gold-generated .gdb_index has duplicated
symbols that gdb-generated index doesn't", that causes gold to generate
duplicate symbols in the index.

F.i., a namespace N1 declared in a header file can be listed for two CUs that
include the header file:
...
[759] N1:
        2 [global type]
        3 [global type]
...

This causes a gdb performance problem: f.i. when attempting to set a
breakpoint on a non-existing function N1::misspelled, the symtab for both CUs
will be expanded.

Gdb contains a workaround for this, added in commit 8943b87476 "Work around
gold/15646", that skips duplicate global symbols in the index.

However, the workaround does not check for the symbol kind ("type" in the
example above).

Make the workaround more precise by limiting it to symbol kind "type".

Tested on x86_64-linux, with target boards cc-with-gdb-index and
gold-gdb-index.

gdb/ChangeLog:

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

* dwarf2/read.c (dw2_symtab_iter_next, dw2_expand_marked_cus): Limit
PR gold/15646 workaround to symbol kind "type".

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