deliverable/binutils-gdb.git
4 years agoThe "b" flag for COFF sections only unsets the LOAD attribute. It should also clear...
J.W. Jagersma [Wed, 25 Mar 2020 11:52:07 +0000 (11:52 +0000)] 
The "b" flag for COFF sections only unsets the LOAD attribute.  It should also clear the CONTENTS attribute so that named bss sections don't take up space in an object file.  This can be achieved by setting the 'bss' flag in seg_info.

* config/obj-coff.c (obj_coff_section): Set the bss flag on
sections with the "b" attribute.

4 years ago[gdb] Print user/includes fields for maint commands
Tom de Vries [Wed, 25 Mar 2020 11:38:05 +0000 (12:38 +0100)] 
[gdb] Print user/includes fields for maint commands

The type struct compunit_symtab contains two fields (disregarding field next)
that express relations with other compunit_symtabs: user and includes.

These fields are currently not printed with "maint info symtabs" and
"maint print symbols".

Fix this such that for "maint info symtabs" we print:
...
   { ((struct compunit_symtab *) 0x23e8450)
     debugformat DWARF 2
     producer (null)
     dirname (null)
     blockvector ((struct blockvector *) 0x23e8590)
+    user ((struct compunit_symtab *) 0x2336280)
+    ( includes
+      ((struct compunit_symtab *) 0x23e85e0)
+      ((struct compunit_symtab *) 0x23e8960)
+    )
         { symtab <unknown> ((struct symtab *) 0x23e85b0)
           fullname (null)
           linetable ((struct linetable *) 0x0)
         }
   }
...

And for "maint print symbols" we print:
...
-Symtab for file <unknown>
+Symtab for file <unknown> at 0x23e85b0
 Read from object file /data/gdb_versions/devel/a.out (0x233ccf0)
 Language: c

 Blockvector:

 block #000, object at 0x23e8530, 0 syms/buckets in 0x0..0x0
   block #001, object at 0x23e84d0 under 0x23e8530, 0 syms/buckets in 0x0..0x0

+Compunit user: 0x2336300
+Compunit include: 0x23e8900
+Compunit include: 0x23dd970
...
Note: for user and includes we don't list the actual compunit_symtab address,
but instead the corresponding symtab address, which allows us to find that
symtab elsewhere in the output (given that we also now print the address of
symtabs).

gdb/ChangeLog:

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

* symtab.h (is_main_symtab_of_compunit_symtab): New function.
* symmisc.c (dump_symtab_1): Print user and includes fields.
(maintenance_info_symtabs): Same.

4 years agogdb/riscv: Apply NaN boxing when writing return values into registers
Andrew Burgess [Fri, 13 Mar 2020 15:50:28 +0000 (15:50 +0000)] 
gdb/riscv: Apply NaN boxing when writing return values into registers

When setting up function parameters we already perform NaN boxing, as
required by the RISC-V ABI, however, we don't do this when writing
values into registers as part of setting up a return value.

This commit moves the NaN boxing code into a small helper function,
and then makes use of this function when setting up function
parameters, and also when setting up return values.

This should resolve this failure:

  FAIL: gdb.base/return-nodebug.exp: float: full width of the returned result

gdb/ChangeLog:

PR gdb/25489
* riscv-tdep.c (riscv_arg_info::c_offset): Update comment.
(riscv_regcache_cooked_write): New function.
(riscv_push_dummy_call): Use new function.
(riscv_return_value): Likewise.

4 years agoarc: Use correct string when printing bfd DEBUG data
Shahab Vahedi [Tue, 24 Mar 2020 14:25:24 +0000 (15:25 +0100)] 
arc: Use correct string when printing bfd DEBUG data

PRINT_DEBUG_RELOC_INFO_BEFORE() macro prints bunch of parameters
for debugging purposes.  Due to a seemingly copy/paste mistake,
the "input_section->vma" is printed under the field name
"symbol_section->vma".  This commit fixes that.

This fix is a courtesy of xiangzhai.

* elf32-arc.c (PRINT_DEBUG_RELOC_INFO_BEFORE): Use the
correct field name in the output string.

4 years agoh8300-linux ld testsuite
Alan Modra [Wed, 25 Mar 2020 02:37:54 +0000 (13:07 +1030)] 
h8300-linux ld testsuite

This fixes lots of fails caused by h8300-linux not supporting -shared
and related options.  I've also fixed ld-h8300 tests to accept the
valid h8300-linux -m options .

pr22450.d is also fixed for avr, crx, ip2k, m68hc11 and xc16x, and the
new pr25708 test for hppa64.

* testsuite/ld-elf/compress1c.d: xfail h8300.
* testsuite/ld-elf/compressed1c.d: Likewise.
* testsuite/ld-elf/compressed1e.d: Likewise.
* testsuite/ld-elf/dynamic1.d: Likewise.
* testsuite/ld-elf/dynsym1.d: Likewise.
* testsuite/ld-elf/ehdr_start-shared.d: Likewise.
* testsuite/ld-elf/exclude3b.d: Likewise.
* testsuite/ld-elf/export-class.exp: Don't run without -shared support.
* testsuite/ld-elf/global1.d: xfail h8300.
* testsuite/ld-elf/hash.d: Likewise.
* testsuite/ld-elf/loadaddr1.d: Likewise.
* testsuite/ld-elf/loadaddr2.d: Likewise.
* testsuite/ld-elf/local1.d: Likewise.
* testsuite/ld-elf/mbind1b.d: Likewise.
* testsuite/ld-elf/mbind1c.d: Likewise.
* testsuite/ld-elf/now-1.d: Likewise.
* testsuite/ld-elf/now-2.d: Likewise.
* testsuite/ld-elf/now-3.d: Likewise.
* testsuite/ld-elf/now-4.d: Likewise.
* testsuite/ld-elf/pie.d: Likewise.
* testsuite/ld-elf/pr12975.d: Likewise.
* testsuite/ld-elf/pr13177.d: Likewise.
* testsuite/ld-elf/pr13195.d: Likewise.
* testsuite/ld-elf/pr16322.d: Likewise.
* testsuite/ld-elf/pr16498a.d: Likewise.
* testsuite/ld-elf/pr16498b.d: Likewise.
* testsuite/ld-elf/pr17615.d: Likewise.
* testsuite/ld-elf/pr19162.d: Likewise.
* testsuite/ld-elf/pr19539.d: Likewise.
* testsuite/ld-elf/pr19617a.d: Likewise.
* testsuite/ld-elf/pr19698.d: Likewise.
* testsuite/ld-elf/pr20513c.d: Likewise.
* testsuite/ld-elf/pr20513d.d: Likewise.
* testsuite/ld-elf/pr21389a.d: Likewise.
* testsuite/ld-elf/pr21389b.d: Likewise.
* testsuite/ld-elf/pr21389c.d: Likewise.
* testsuite/ld-elf/pr21562a.d: Likewise.
* testsuite/ld-elf/pr21562b.d: Likewise.
* testsuite/ld-elf/pr21562c.d: Likewise.
* testsuite/ld-elf/pr21562d.d: Likewise.
* testsuite/ld-elf/pr21562e.d: Likewise.
* testsuite/ld-elf/pr21562f.d: Likewise.
* testsuite/ld-elf/pr21562g.d: Likewise.
* testsuite/ld-elf/pr21562h.d: Likewise.
* testsuite/ld-elf/pr21562i.d: Likewise.
* testsuite/ld-elf/pr21562j.d: Likewise.
* testsuite/ld-elf/pr21562k.d: Likewise.
* testsuite/ld-elf/pr21562l.d: Likewise.
* testsuite/ld-elf/pr21562m.d: Likewise.
* testsuite/ld-elf/pr21562n.d: Likewise.
* testsuite/ld-elf/pr21903a.d: Likewise.
* testsuite/ld-elf/pr21903b.d: Likewise.
* testsuite/ld-elf/pr21903d.d: Likewise.
* testsuite/ld-elf/pr22269a.d: Likewise.
* testsuite/ld-elf/pr22269b.d: Likewise.
* testsuite/ld-elf/pr22393-1a.d: Likewise.
* testsuite/ld-elf/pr22393-1b.d: Likewise.
* testsuite/ld-elf/pr22393-1c.d: Likewise.
* testsuite/ld-elf/pr22393-1d.d: Likewise.
* testsuite/ld-elf/pr22393-1e.d: Likewise.
* testsuite/ld-elf/pr22393-1f.d: Likewise.
* testsuite/ld-elf/pr22423.d: Likewise.
* testsuite/ld-elf/pr22450.d: xfail avr, crx, h8300, ip2k, m68hc11,
and xc16x.
* testsuite/ld-elf/pr23658-1c.d: xfail h8300.
* testsuite/ld-elf/pr25708.d: xfail h8300 and hppa64.
* testsuite/ld-elf/rpath-1.d: xfail h8300.
* testsuite/ld-elf/rpath-2.d: Likewise.
* testsuite/ld-elf/runpath-1.d: Likewise.
* testsuite/ld-elf/runpath-2.d: Likewise.
* testsuite/ld-elf/sizeofb.d: Likewise.
* testsuite/ld-elf/startofb.d: Likewise.
* testsuite/ld-elf/strtab.d: Likewise.
* testsuite/ld-elf/textaddr1.d: Likewise.
* testsuite/ld-elf/textaddr2.d: Likewise.
* testsuite/ld-elf/textaddr4.d: Likewise.
* testsuite/ld-elf/textaddr5.d: Likewise.
* testsuite/ld-elf/textaddr6.d: Likewise.
* testsuite/ld-elf/unknown2.d: Likewise.
* testsuite/ld-undefined/entry-3.d: Likewise.
* testsuite/ld-undefined/entry-4.d: Likewise.
* testsuite/ld-h8300/h8300.exp: Pass appropriate ld -m option.
* testsuite/ld-h8300/gcsection.d: Remove ld -m option and relax
file format match.
* testsuite/ld-h8300/relax-2.d: Likewise.
* testsuite/ld-h8300/relax-3.d: Likewise.
* testsuite/ld-h8300/relax-4.d: Likewise.
* testsuite/ld-h8300/relax-5.d: Likewise.
* testsuite/ld-h8300/relax-6.d: Likewise.
* testsuite/ld-h8300/relax-7.d: Likewise.
* testsuite/ld-h8300/relax.d: Relax file format match.

4 years agoPR25662, invalid sh_offset for first section in segment with phdrs
Alan Modra [Tue, 24 Mar 2020 00:12:45 +0000 (10:42 +1030)] 
PR25662, invalid sh_offset for first section in segment with phdrs

PR 25662
* elf.c (assign_file_positions_for_load_sections): Adjust offset
for SHT_NOBITS section if first in segment.

4 years agoAutomatic date update in version.in
GDB Administrator [Wed, 25 Mar 2020 00:00:08 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 years agobfd: Add a bfd_boolean argument to bfd_get_symbol_version_string
H.J. Lu [Tue, 24 Mar 2020 22:37:14 +0000 (15:37 -0700)] 
bfd: Add a bfd_boolean argument to bfd_get_symbol_version_string

We can't call _bfd_elf_get_symbol_version_name from nm.c since it isn't
available for all target configurations.  This patch add a bfd_boolean
argument to bfd_get_symbol_version_string instead.

bfd/

PR binutils/25708
* elf-bfd.h (_bfd_elf_get_symbol_version_name): Renamed to ...
(_bfd_elf_get_symbol_version_string): This.
* elf.c (_bfd_elf_get_symbol_version_name): Renamed to ...
(_bfd_elf_get_symbol_version_string): This.
(bfd_elf_print_symbol): Pass TRUE to
_bfd_elf_get_symbol_version_string.
* libbfd-in.h (_bfd_nosymbols_get_symbol_version_string): Add a
bfd_boolean argument.
* syms.c (_bfd_nosymbols_get_symbol_version_string): Likewise.
* targets.c  (_bfd_get_symbol_version_string): Likewise.
(bfd_get_symbol_version_string): Likewise.
* bfd-in2.h: Regenerated.

binutils/

PR binutils/25708
* nm.c (print_symname): Replace _bfd_elf_get_symbol_version_name
with bfd_get_symbol_version_string.
(print_symbo): Pass TRUE to bfd_get_symbol_version_string.
* objdump.c (objdump_print_symname): Likewise.

4 years agoUninitialised memory read in z80-dis.c
Alan Modra [Tue, 24 Mar 2020 22:20:21 +0000 (08:50 +1030)] 
Uninitialised memory read in z80-dis.c

objdump -d -m ez80-adl testcase:
 .byte 0x40,0xfd

* z80-dis.c (suffix): Init mybuf.

4 years agogdb: bool-ify follow_fork
Simon Marchi [Tue, 24 Mar 2020 17:44:58 +0000 (13:44 -0400)] 
gdb: bool-ify follow_fork

Change parameters and return value of the various follow_fork
functions/methods from int to bool.

gdb/ChangeLog:

* fbsd-nat.c (fbsd_nat_target::follow_fork): Change bool to int.
* fbsd-nat.h (class fbsd_nat_target) <follow_fork>: Likewise.
* inf-ptrace.c (inf_ptrace_target::follow_fork): Likewise.
* inf-ptrace.h (struct inf_ptrace_target) <follow_fork>: Likewise.
* infrun.c (follow_fork): Likewise.
(follow_fork_inferior): Likewise.
* linux-nat.c (linux_nat_target::follow_fork): Likewise.
* linux-nat.h (class linux_nat_target): Likewise.
* remote.c (class remote_target) <follow_fork>: Likewise.
(remote_target::follow_fork): Likewise.
* target-delegates.c: Re-generate.
* target.c (default_follow_fork): Likewise.
(target_follow_fork): Likewise.
* target.h (struct target_ops) <follow_fork>: Likewise.
(target_follow_fork): Likewise.

4 years agoUpdate changelog.
Nick Clifton [Tue, 24 Mar 2020 15:25:36 +0000 (15:25 +0000)] 
Update changelog.

4 years agoAdd code to the BFD library to handle opening files with pathnames longer than MAX_PA...
Nick Clifton [Tue, 24 Mar 2020 15:24:02 +0000 (15:24 +0000)] 
Add code to the BFD library to handle opening files with pathnames longer than MAX_PATH on Win32 systems.

PR 25713
* bfdio.c (_bfd_real_fopen): Add code to handle long filenames on
Win32 systems.

4 years agoFix assertion failure in the BFD library when linking with --emit-relocs enabled.
Nick Clifton [Tue, 24 Mar 2020 13:35:53 +0000 (13:35 +0000)] 
Fix assertion failure in the BFD library when linking with --emit-relocs enabled.

PR 25681
* elf.c (_bfd_elf_map_sections_to_segments): When looking for a
segment to use for PT_GNU_RELRO, ignore empty sections in a
segment's current list.

4 years agobfd: Change num_group to unsigned int
H.J. Lu [Tue, 24 Mar 2020 11:52:39 +0000 (04:52 -0700)] 
bfd: Change num_group to unsigned int

elf.c failed with to with GCC 10 as of

commit 906b3eb9df6c577d3f6e9c3ea5c9d7e4d1e90536
Author: Martin Liska <mliska@suse.cz>
Date:   Tue Mar 24 11:40:10 2020 +0100

    Improve endianess detection.

            PR lto/94249
            * plugin-api.h: Add more robust endianess detection.

binutils-gdb/bfd/elf.c: In function ‘setup_group’:
binutils-gdb/bfd/elf.c:740:35: error: overflow in conversion from ‘unsigned int’ to ‘int’ changes value from ‘num_group = 4294967295’ to ‘-1’ [-Werror=overflow]
  740 |     elf_tdata (abfd)->num_group = num_group = -1;
      |                                   ^~~~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [Makefile:1608: elf.lo] Error 1

Change num_group in elf_obj_tdata to unsigned int to compile with GCC 10.

PR binutils/25717
* elf-bfd.h (elf_obj_tdata): Change num_group to unsigned int.

4 years agoinclude: Sync plugin-api.h with GCC
Martin Liska [Tue, 24 Mar 2020 10:40:10 +0000 (11:40 +0100)] 
include: Sync plugin-api.h with GCC

Improve endianess detection.

PR lto/94249
* plugin-api.h: Add more robust endianess detection.

4 years agobfd: Display symbol version for nm -D
H.J. Lu [Tue, 24 Mar 2020 11:23:11 +0000 (04:23 -0700)] 
bfd: Display symbol version for nm -D

Extend _bfd_elf_get_symbol_version_string for nm -D to display symbol
version.  _bfd_elf_get_symbol_version_name is added to avoid updating
all XXX_get_symbol_version_string functions.

bfd/

PR binutils/25708
* elf-bfd.h (_bfd_elf_get_symbol_version_name): New.
* elf.c (_bfd_elf_get_symbol_version_name): New function.  Based
on the previous _bfd_elf_get_symbol_version_string.
(_bfd_elf_get_symbol_version_string): Use it.

binutils/

PR binutils/25708
* nm.c (SYM_NAME): Removed.
(print_symname): Add a pointer to struct extended_symbol_info
argument.  Call _bfd_elf_get_symbol_version_name to get symbol
version.
(print_symdef_entry): Pass NULL to print_symname.
(print_symbol_info_bsd): Update call to print_symname.
(print_symbol_info_sysv): Likewise.
(print_symbol_info_posix): Likewise.

ld/

PR binutils/25708
* testsuite/ld-elf/pr25708.d: New file.

4 years ago[gdb] Print user for maint info psymtabs
Tom de Vries [Tue, 24 Mar 2020 09:00:51 +0000 (10:00 +0100)] 
[gdb] Print user for maint info psymtabs

The type struct partial_symtab contains two fields (disregarding field next)
that express relations with other symtabs: user and dependencies.

When using "maint print psymbols", we see both the dependencies and the user
fields:
...
Partial symtab for source file  (object 0x35ef270)
  ...
  Depends on 0 other partial symtabs.
  Shared partial symtab with user 0x35d5f40
...

But with "maint info psymtabs", we only see dependencies:
...
  { psymtab  ((struct partial_symtab *) 0x35ef270)
    ...
    dependencies (none)
  }
...

Add printing of the user field for "maint info psymtabs", such that we have:
...
   { psymtab  ((struct partial_symtab *) 0x35ef270)
     ...
+    user hello.c ((struct partial_symtab *) 0x35d5f40)
     dependencies (none)
   }
...

Tested on x86_64-linux.

gdb/ChangeLog:

2020-03-24  Tom de Vries  <tdevries@suse.de>

* psymtab.c (maintenance_info_psymtabs): Print user field.

4 years agoOverlarge allocation in _bfd_generic_read_ar_hdr_mag
Alan Modra [Tue, 24 Mar 2020 06:56:40 +0000 (17:26 +1030)] 
Overlarge allocation in _bfd_generic_read_ar_hdr_mag

* archive.c (_bfd_generic_read_ar_hdr_mag): Sanity check extended
name size.  Use bfd_malloc rather than bfd_zmalloc, clearing just
struct areltdata.

4 years agoreadelf memory leak in process_mips_specific
Alan Modra [Tue, 24 Mar 2020 01:42:24 +0000 (12:12 +1030)] 
readelf memory leak in process_mips_specific

* readelf.c (process_mips_specific): Free iconf on error path.

4 years agoAutomatic date update in version.in
GDB Administrator [Tue, 24 Mar 2020 00:00:08 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 years agoAvoid trigger an assertion failure in the STABS parser by replacing the abort with...
Nick Clifton [Mon, 23 Mar 2020 16:17:51 +0000 (16:17 +0000)] 
Avoid trigger an assertion failure in the STABS parser by replacing the abort with an error return.

PR 25714
* wrstabs.c (stab_pop_type): Replace assertion with error return.
* write_stabs_in_sections_debugging_info: Likewise.
* stab_enum_type: Likewise.
* stab_modify_type: Likewise.
* stab_struct_field: Likewise.
* stab_end_struct_type: Likewise.
* stab_start_class_type: Likewise.
* stab_class_static_member: Likewise.
* stab_class_baseclass: Likewise.
* stab_class_start_method: Likewise.
* stab_class_method_var: Likewise.
* stab_class_end_method: Likewise.
* stab_end_class_type: Likewise.
* stab_typedef_type: Likewise.
* stab_start_function: Likewise.
* stab_end_block: Likewise.
* stab_lineno: Likewise.

4 years agoMention .tdata in comment in _bfd_elf_tls_setup()
Sebastian Huber [Mon, 23 Mar 2020 13:01:05 +0000 (14:01 +0100)] 
Mention .tdata in comment in _bfd_elf_tls_setup()

This helps to find code areas which deal with the .tdata section.

bfd/

     * elflink.c (_bfd_elf_tls_setup): Mention .tdata in comment.

4 years agoECOFF archive uninitialised read
Alan Modra [Mon, 23 Mar 2020 12:53:31 +0000 (23:23 +1030)] 
ECOFF archive uninitialised read

* ecoff.c (_bfd_ecoff_slurp_armap): Sanity check parsed_size and
symbol count.  Allocate an extra byte to ensure name strings
are terminated.  Sanity check name offsets.  Release memory on
error return.

4 years agoi386msdos uninitialised read
Alan Modra [Mon, 23 Mar 2020 10:50:54 +0000 (21:20 +1030)] 
i386msdos uninitialised read

Also reinstate ld i386aout for i386-msdos target, which doesn't build
otherwise.

bfd/
* i386msdos.c (msdos_object_p): Don't access e_lfanew when that
field hasn't been read.  Remove unnecessary casts.
ld/
* Makefile.am (ALL_EMULATION_SOURCES): Reinstate ei386aout.c.
Include ei386aout dep file.
* Makefile.in: Regenerate.
* po/BLD-POTFILES.in: Regenerate.

4 years agogdb/testsuite: Remove hard coded addresses from expected results
Andrew Burgess [Mon, 23 Mar 2020 12:01:08 +0000 (12:01 +0000)] 
gdb/testsuite: Remove hard coded addresses from expected results

In commit:

  commit 6b8c53f2f1c0cf5bee46120d892d4c72571375eb
  Date:   Sat Feb 8 21:26:31 2020 +0000

      gdb/testsuite/fortran: Add mixed language stack test

The test incorrectly included two hard coded addresses in the expected
output, this commit replaces them with the $hex pattern.

gdb/testsuite/ChangeLog:

* gdb.fortran/mixed-lang-stack.exp: Replace two hard coded address
with $hex.

4 years agoAutomatic date update in version.in
GDB Administrator [Mon, 23 Mar 2020 00:00:08 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 years agoXCOFF64 uninitialised read
Alan Modra [Sun, 22 Mar 2020 09:59:16 +0000 (20:29 +1030)] 
XCOFF64 uninitialised read

Like git commit 67338173a4.

* coff64-rs6000.c (xcoff64_slurp_armap): Ensure size is large
enough to read number of symbols.

4 years agoH8300 use of uninitialised value
Alan Modra [Sun, 22 Mar 2020 09:56:31 +0000 (20:26 +1030)] 
H8300 use of uninitialised value

* h8300-dis.c (bfd_h8_disassemble): Limit data[] access to that
successflly read from section.

4 years agoARC: Use of uninitialised value
Alan Modra [Sun, 22 Mar 2020 09:32:55 +0000 (20:02 +1030)] 
ARC: Use of uninitialised value

* arc-dis.c (find_format): Use ISO C string concatenation rather
than line continuation within a string.  Don't access needs_limm
before testing opcode != NULL.

4 years agoNS32K arg_bufs uninitialised
Alan Modra [Sun, 22 Mar 2020 07:45:41 +0000 (18:15 +1030)] 
NS32K arg_bufs uninitialised

git commit d1e304bc27 was aimed at stopping uninitialised memory
access to the index_offset array.  Unfortunately that patch resulted
in a different array being uninitialised for all instructions with
more than two arguments.

* ns32k-dis.c (print_insn_arg): Update comment.
(print_insn_ns32k): Reduce size of index_offset array, and
initialize, passing -1 to print_insn_arg for args that are not
an index.  Don't exit arg loop early.  Abort on bad arg number.

4 years agos12z disassembler tidy
Alan Modra [Sun, 22 Mar 2020 04:32:27 +0000 (15:02 +1030)] 
s12z disassembler tidy

Don't ignore buffer memory read failure, or malloc failure.  Lots of
functions get a return status to pass these failures up the chain in
this patch.

opcodes/
* s12z-dis.c (abstract_read_memory): Don't print error on EOI.
* s12z-opc.c: Formatting.
(operands_f): Return an int.
(opr_n_bytes_p1): Return -1 on reaching buffer memory limit.
(opr_n_bytes2, bfextins_n_bytes, mul_n_bytes, bm_n_bytes),
(shift_n_bytes, mov_imm_opr_n_bytes, loop_prim_n_bytes),
(exg_sex_discrim): Likewise.
(create_immediate_operand, create_bitfield_operand),
(create_register_operand_with_size, create_register_all_operand),
(create_register_all16_operand, create_simple_memory_operand),
(create_memory_operand, create_memory_auto_operand): Don't
segfault on malloc failure.
(z_ext24_decode): Return an int status, negative on fail, zero
on success.
(x_imm1, imm1_decode, trap_decode, z_opr_decode, z_opr_decode2),
(imm1234, reg_s_imm, reg_s_opr, z_imm1234_8base, z_imm1234_0base),
(z_tfr, z_reg, reg_xy, lea_reg_xys_opr, lea_reg_xys, rel_15_7),
(decode_rel_15_7, cmp_xy, sub_d6_x_y, sub_d6_y_x),
(ld_18bit_decode, mul_decode, bm_decode, bm_rel_decode),
(mov_imm_opr, ld_18bit_decode, exg_sex_decode),
(loop_primitive_decode, shift_decode, psh_pul_decode),
(bit_field_decode): Similarly.
(z_decode_signed_value, decode_signed_value): Similarly.  Add arg
to return value, update callers.
(x_opr_decode_with_size): Check all reads, returning NULL on fail.
Don't segfault on NULL operand.
(decode_operation): Return OP_INVALID on first fail.
(decode_s12z): Check all reads, returning -1 on fail.
gas/
* testsuite/gas/s12z/truncated.d: Update expected output.

4 years agoAutomatic date update in version.in
GDB Administrator [Sun, 22 Mar 2020 00:00:09 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 years agoinclude: Sync lto-symtab.h and plugin-api.h with GCC
Martin Liska [Sat, 21 Mar 2020 07:09:02 +0000 (08:09 +0100)] 
include: Sync lto-symtab.h and plugin-api.h with GCC

Fix comma at end of enumerator list seen with -std=c++98.

* plugin-api.h (enum ld_plugin_symbol_type): Remove
comma after last value of an enum.
* lto-symtab.h (enum gcc_plugin_symbol_type): Likewise.

4 years agoAutomatic date update in version.in
GDB Administrator [Sat, 21 Mar 2020 00:00:10 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 years agoMake dwarf2_evaluate_property parameter const
Tom Tromey [Fri, 20 Mar 2020 19:04:56 +0000 (13:04 -0600)] 
Make dwarf2_evaluate_property parameter const

dwarf2_evaluate_property should not modify its "addr_stack"
parameter's contents.  This patch makes this part of the API, by
marking it const.

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

* dwarf2/loc.h (dwarf2_evaluate_property): Make "addr_stack"
const.
* dwarf2/loc.c (dwarf2_evaluate_property): Make "addr_stack"
const.

4 years ago[gdb/testsuite] Fix gdb.threads/omp-par-scope.exp XPASS
Tom de Vries [Fri, 20 Mar 2020 18:32:07 +0000 (19:32 +0100)] 
[gdb/testsuite] Fix gdb.threads/omp-par-scope.exp XPASS

When running test-case gdb.threads/omp-par-scope.exp, I get this XPASS:
...
XPASS: gdb.threads/omp-par-scope.exp: nested_parallel: outer_threads: \
  outer stop: get valueof "num"
...
for test:
...
           set thread_num [get_valueof "" "num" "unknown"]
...

The intention of the test is to get the value of local variable num, which
has been set to:
...
    int num = omp_get_thread_num ();
...
but the actually printed value is 'num':
...
(gdb) print num^M
$76 = num^M
...

This is due to the fact that num is missing in the locals, so instead we find
the enum member 'num' of enum expression_operator in glibc/intl/plural-exp.h.

Fix this by getting the value using a new proc get_local_valueof, which uses
the "info locals" commands to get the value.

Tested on x86_64-linux, with gcc 7.5.0 (where the test xfails) and gcc
10.0.1 (where the test passes).

4 years agogdb: remove HAVE_DECL_PTRACE
Simon Marchi [Fri, 20 Mar 2020 15:57:49 +0000 (11:57 -0400)] 
gdb: remove HAVE_DECL_PTRACE

I stumbled on this snippet in nat/gdb_ptrace.h:

    /* Some systems, in particular DEC OSF/1, Digital Unix, Compaq Tru64
       or whatever it's called these days, don't provide a prototype for
       ptrace.  Provide one to silence compiler warnings.  */

    #ifndef HAVE_DECL_PTRACE
    extern PTRACE_TYPE_RET ptrace();
    #endif

I believe this is unnecessary today and should be removed.  First, the
comment only mentions OSes we don't support (and to be honest, I had
never even heard of).

But most importantly, in C++, a declaration with empty parenthesis
declares a function that accepts no arguments, unlike in C.  So if this
declaration was really used, GDB wouldn't build, since all ptrace call
sites pass some arguments.  Since we haven't heard anything about this
causing some build failures since we have transitioned to C++, I
conclude that it's not used.

This patch removes it as well as the corresponding configure check.

gdb/ChangeLog:

* ptrace.m4: Don't check for ptrace declaration.
* config.in: Re-generate.
* configure: Re-generate.
* nat/gdb_ptrace.h: Don't declare ptrace if HAVE_DECL_PTRACE is
not defined.

gdbserver/ChangeLog:

* config.in: Re-generate.
* configure: Re-generate.

gdbsupport/ChangeLog:

* config.in: Re-generate.
* configure: Re-generate.

4 years agoUpdate the return type of gdb_ptrace to be more flexible
Kamil Rytarowski [Fri, 20 Mar 2020 14:37:18 +0000 (15:37 +0100)] 
Update the return type of gdb_ptrace to be more flexible

Linux returns long from ptrace(2) and BSDs int.

gdb/ChangeLog:

       * amd64-bsd-nat.c (gdb_ptrace): Change return type from `int' to
       `PTRACE_TYPE_RET'.
       * i386-bsd-nat.c (gdb_ptrace): Likewise.
       * sparc-nat.c (gdb_ptrace): Likewise.
       * x86-bsd-nat.c (gdb_ptrace): Likewise.

4 years agoFix assert in c-exp.y
Tom Tromey [Fri, 20 Mar 2020 14:10:59 +0000 (08:10 -0600)] 
Fix assert in c-exp.y

The "restrict" patch added some asserts to c-exp.y, but one spot was
copy-pasted and referred to the wrong table.  This was pointed out by
-fsanitize=address.  This patch fixes the bug.

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

* c-exp.y (lex_one_token): Fix assert.

4 years agoAvoid stringop-truncation errors
Tom Tromey [Fri, 20 Mar 2020 13:30:13 +0000 (07:30 -0600)] 
Avoid stringop-truncation errors

I configured with -fsanitize=address and built gdb.  linux-tdep.c and
ada-tasks.c failed to build due to some stringop-truncation errors,
e.g.:

In function ‘char* strncpy(char*, const char*, size_t)’,
    inlined from ‘int linux_fill_prpsinfo(elf_internal_linux_prpsinfo*)’ at ../../binutils-gdb/gdb/linux-tdep.c:1742:11,
    inlined from ‘char* linux_make_corefile_notes(gdbarch*, bfd*, int*)’ at ../../binutils-gdb/gdb/linux-tdep.c:1878:27:
/usr/include/bits/string_fortified.h:106:34: error: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ specified bound 81 equals destination size [-Werror=stringop-truncation]

This patch fixes the problem by using "sizeof - 1" in the call to
strndup, as recommended in the GCC manual.  This doesn't make a
difference here because the next line, in all cases, sets the final
element to '\0' anyway.

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

* ada-tasks.c (read_atcb): Use smaller length in strncpy call.
* linux-tdep.c (linux_fill_prpsinfo): Use smaller length in
strncpy call.

4 years agoFix column alignment in "maint info line-table"
Tom Tromey [Fri, 20 Mar 2020 13:15:08 +0000 (07:15 -0600)] 
Fix column alignment in "maint info line-table"

Andrew Burgess pointed out on irc that "maint info line-table" doesn't
properly align the table headers.  This patch fixes the problem by
switching the table to use ui-out.

This required a small tweak to one test case, as ui-out will pad a
field using spaces, even at the end of a line.

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

* symmisc.c (maintenance_print_one_line_table): Use ui_out.

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

* gdb.dwarf2/dw2-ranges-base.exp: Update regular expressions.

4 years agoFix Ada val_print removal regression
Tom Tromey [Fri, 20 Mar 2020 14:24:16 +0000 (08:24 -0600)] 
Fix Ada val_print removal regression

The removal of val_print caused a regression in the Ada code.  In one
scenario, a variant type would not be properly printed, because the
address of a component was lost.  This patch fixes the bug by changing
this API to be value-based.  This is cleaner and fixes the bug as a
side effect.

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

* ada-valprint.c (print_variant_part): Remove parameters; switch
to value-based API.
(print_field_values): Likewise.
(ada_val_print_struct_union): Likewise.
(ada_value_print_1): Update.

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

* gdb.ada/sub_variant/subv.adb: New file.
* gdb.ada/sub_variant.exp: New file.

4 years agoInherit ppc_nbsd_nat_target from nbsd_nat_target
Kamil Rytarowski [Thu, 19 Mar 2020 13:52:57 +0000 (14:52 +0100)] 
Inherit ppc_nbsd_nat_target from nbsd_nat_target

gdb/ChangeLog:

* ppc-nbsd-nat.c (ppc_nbsd_nat_target): Inherit from
nbsd_nat_target instead of inf_ptrace_target.
* ppc-nbsd-nat.c: Include "nbsd-nat.h", as we are now using
nbsd_nat_target.

4 years agoAdd support for NetBSD threads in hppa-nbsd-nat.c
Kamil Rytarowski [Thu, 19 Mar 2020 14:39:56 +0000 (15:39 +0100)] 
Add support for NetBSD threads in hppa-nbsd-nat.c

NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.

gdb/ChangeLog:

* hppa-nbsd-nat.c (fetch_registers): New variable lwp and pass
it to the ptrace call.
* (store_registers): Likewise.

4 years ago[gdb/testsuite] Fix timeouts in gdb.threads/step-over-*.exp
Tom de Vries [Fri, 20 Mar 2020 13:59:01 +0000 (14:59 +0100)] 
[gdb/testsuite] Fix timeouts in gdb.threads/step-over-*.exp

When running test-cases gdb.threads/step-over-lands-on-breakpoint.exp and
gdb.threads/step-over-trips-on-watchpoint.exp with target board
unix/-flto/-O0/-flto-partition=none/-ffat-lto-objects, we run into timeouts
due not being able to set a breakpoint and then trying to continue to that
breakpoint.

In total, we run into 186 timeouts, which roughly corresponds to half an hour:
...
$ grep "FAIL.*(timeout)" gdb.sum \
  | awk '{print $2}' \
  | sort \
  | uniq -c
     66 gdb.threads/step-over-lands-on-breakpoint.exp:
    120 gdb.threads/step-over-trips-on-watchpoint.exp:
...

Fix this by bailing out if the first break fails.

Tested on x86_64-linux, both with native and with target board mentioned above.

gdb/testsuite/ChangeLog:

2020-03-20  Tom de Vries  <tdevries@suse.de>

* gdb.threads/step-over-lands-on-breakpoint.exp (do_test): Bail out if
first break fails.
* gdb.threads/step-over-trips-on-watchpoint.exp: (do_test): Same.

4 years agoAdd support for the xdef and xref pseudo-ops to the Z80 assembler.
Sergey Belyashov [Fri, 20 Mar 2020 13:53:02 +0000 (13:53 +0000)] 
Add support for the xdef and xref pseudo-ops to the Z80 assembler.

PR 25690
* config/tc-z80.c (md_pseudo_table): Add xdef anf xref pseudo ops.
* doc/c-z80.texi: Update documentation.

4 years agoAdd support for NetBSD threads in ppc-nbsd-nat.c
Kamil Rytarowski [Thu, 19 Mar 2020 14:01:27 +0000 (15:01 +0100)] 
Add support for NetBSD threads in ppc-nbsd-nat.c

NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.

gdb/ChangeLog:

* ppc-nbsd-nat.c (fetch_registers): New variable lwp and pass
        it to the ptrace call.
        * (store_registers): Likewise.

4 years agoFix compile time warnings about the possibility of using uninitialised fields in...
Nick Clifton [Fri, 20 Mar 2020 11:33:07 +0000 (11:33 +0000)] 
Fix compile time warnings about the possibility of using uninitialised fields in the Elf_Internal_Chdr structure when building readelf.

* readelf.c (get_compression_header): Add ATTRIBUTE_WARN_UNUSED_RESULT.
(process_section_headers): Check the return value from
get_compression_header.
(dump_section_as_strings): Likewise.
(dump_section_as_bytes): Likewise.
(load_specific_debug_section): Likewise.

4 years agoplugin: Don't invoke LTO-wrapper
H.J. Lu [Fri, 20 Mar 2020 10:55:17 +0000 (03:55 -0700)] 
plugin: Don't invoke LTO-wrapper

Don't invoke LTO-wrapper since the LTO wrapper approach is not only
slow but also unreliable.  For GCC 10 or newer, LDPT_ADD_SYMBOLS_V2
will be used.

bfd/

* configure.ac (HAVE_EXECUTABLE_SUFFIX): Removed.
(EXECUTABLE_SUFFIX): Likewise.
* config.in: Regenerated.
* configure: Likewise.
* plugin.c (bfd_plugin_close_and_cleanup): Defined as
_bfd_generic_close_and_cleanup.
(plugin_list_entry): Remove resolution_file, resolution_option,
real_bfd, real_nsyms, real_syms, lto_nsyms, lto_syms, gcc,
lto_wrapper, gcc_env and initialized,
(need_lto_wrapper_p): Removed.
(get_lto_wrapper): Likewise.
(setup_lto_wrapper_env): Likewise.
(register_all_symbols_read): Likewise.
(egister_cleanup): Likewise.
(get_symbols): Likewise.
(add_input_file): Likewise.
(bfd_plugin_set_program_name): Remove need_lto_wrapper.
(add_symbols): Updated.
(try_claim): Likewise.
(try_load_plugin): Likewise.
(bfd_plugin_canonicalize_symtab): Likewise.
* plugin.h (bfd_plugin_set_program_name): Remove int argument.
(plugin_data_struct): Remove real_bfd, real_nsyms and real_syms.

binutils/

* ar.c (main): Update bfd_plugin_set_program_name call.
* nm.c (main): Likewise.

ld/

* testsuite/ld-plugin/lto.exp (lto_link_tests): Run PR ld/25355
test only for GCC 10 or newer.

4 years agoplugin: Use LDPT_ADD_SYMBOLS_V2 to get symbol type
H.J. Lu [Fri, 20 Mar 2020 04:00:19 +0000 (21:00 -0700)] 
plugin: Use LDPT_ADD_SYMBOLS_V2 to get symbol type

Since LTO plugin may generate more than one ltrans.o file from one input
IR object as LTO wrapper ignores -flto-partition=none:

lto-wrapper.c:608:

   604          /* Drop arguments that we want to take from the link line.  */
   605          case OPT_flto_:
   606          case OPT_flto:
   607          case OPT_flto_partition_:
   608            continue;

the LTO wrapper approach is not only slow but also unreliable.  Since
the LTO plugin API has been extended to add LDPT_ADD_SYMBOLS_V2 with
symbol type and section kind, we can use LDPT_ADD_SYMBOLS_V2 to get
symbol type, instead of invoking the LTO wrapper.

PR binutils/25640
* plugin.c (plugin_list_entry): Add has_symbol_type.
(add_symbols_v2): New function.
(bfd_plugin_open_input): Don't invoke LTO wrapper if LTO plugin
provides symbol type.
(try_load_plugin): Add LDPT_ADD_SYMBOLS_V2.
(bfd_plugin_canonicalize_symtab): Use LTO plugin symbol type if
available.

4 years agoSilence warnings due to plugin API change
Alan Modra [Fri, 20 Mar 2020 02:27:42 +0000 (12:57 +1030)] 
Silence warnings due to plugin API change

* testplug.c (parse_symdefstr): Use %hhi to read sym->def, and
clear new fields.
* testplug2.c (parse_symdefstr): Likewise.
* testplug3.c (parse_symdefstr): Likewise.
* testplug4.c (parse_symdefstr): Likewise.

4 years agoXCOFF uninitialized read
Alan Modra [Fri, 20 Mar 2020 00:27:38 +0000 (10:57 +1030)] 
XCOFF uninitialized read

* coff-rs6000.c (_bfd_xcoff_slurp_armap): Ensure size is large
enough to read number of symbols.

4 years agometag uninitialized memory read
Alan Modra [Fri, 20 Mar 2020 00:25:58 +0000 (10:55 +1030)] 
metag uninitialized memory read

* metag-dis.c (print_insn_metag): Don't ignore status from
read_memory_func.

4 years agoNDS32 disassembly of odd sized sections
Alan Modra [Fri, 20 Mar 2020 00:21:14 +0000 (10:51 +1030)] 
NDS32 disassembly of odd sized sections

* nds32-dis.c (print_insn_nds32): Remove unnecessary casts.
Initialize parts of buffer not written when handling a possible
2-byte insn at end of section.  Don't attempt decoding of such
an insn by the 4-byte machinery.

4 years agoPowerPC disassembly of odd sized sections
Alan Modra [Thu, 19 Mar 2020 23:46:28 +0000 (10:16 +1030)] 
PowerPC disassembly of odd sized sections

We shouldn't really decode a 2-byte left-over at the end of a section
as if the section contains two more bytes of zeros.  Not that it
matters very much, but this patch tidies the corner case.

* ppc-dis.c (print_insn_powerpc): Only clear needed bytes of
partially filled buffer.  Prevent lookup of 4-byte insns when
only VLE 2-byte insns are possible due to section size.  Print
".word" rather than ".long" for 2-byte leftovers.

4 years agotidy elf_backend calls
Alan Modra [Tue, 17 Mar 2020 21:01:47 +0000 (07:31 +1030)] 
tidy elf_backend calls

Function pointers in elfNN_bed that are initialized by elfxx-target.h
to non-zero values generally don't need a non-NULL test before calling
them.  Targets don't set a non-NULL function to NULL.  The one
exception being elfnn-ia64.c and that exception is removed here.

* elf.c (_bfd_elf_setup_sections): Don't test known non-NULL
backend functions for NULL before calling.
(copy_special_section_fields, _bfd_elf_copy_private_bfd_data),
(bfd_section_from_shdr, assign_section_numbers): Likewise.
* elfcode.h (elf_write_relocs, elf_slurp_reloc_table): Likewise.
* elfnn-ia64.c (ignore_errors): New function.
(elf_backend_link_order_error_handler): Redefine as ignore_errors.

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

4 years agoAdd support for --no-rosegment option.
Fangrui Song [Thu, 19 Mar 2020 22:54:20 +0000 (15:54 -0700)] 
Add support for --no-rosegment option.

gold/
    * options.h (General_options): Add --no-rosegment option.

4 years agoDisable get_ptrace_pid for NetBSD
Kamil Rytarowski [Tue, 17 Mar 2020 16:57:14 +0000 (17:57 +0100)] 
Disable get_ptrace_pid for NetBSD

Unlike most other Operating Systems, NetBSD tracks both pid and lwp.
The process id on NetBSD is stored always in the pid field of ptid.

gdb/ChangeLog:

* inf-ptrace.h: Disable get_ptrace_pid on NetBSD.
* inf-ptrace.c: Likewise.
* (gdb_ptrace): Add.
* (inf_ptrace_target::resume): Update.
* (inf_ptrace_target::xfer_partial): Likewise.
* (inf_ptrace_peek_poke): Change argument `pid' to `ptid'.
* (inf_ptrace_peek_poke): Update.

4 years agoFix discrepancies in nm's --line-number output by adding support for the DW_AT_specif...
Nick Clifton [Thu, 19 Mar 2020 16:55:13 +0000 (16:55 +0000)] 
Fix discrepancies in nm's --line-number output by adding support for the DW_AT_specification DWARF Attttribute.

PR 25676
bfd * dwarf2.c (struct varinfo): Add unit_offset field to record the
location of the varinfo in the unit's debug info data.  Change the
type of the stack field to a boolean.
(lookup_var_by_offset): New function.  Returns the varinfo
structure for the variable described at the given offset in the
unit's debug info.
(scan_unit_for_symbols): Add support for variables which have the
DW_AT_specification attribute.

binutils* testsuite/binutils-all/dw4.s: New test source file.
* testsuite/binutils-all/nm.exp: Run the new test.

4 years agoInclude: Sync lto-symtab.h and plugin-api.h with GCC
Martin Liska [Thu, 19 Mar 2020 15:55:59 +0000 (16:55 +0100)] 
Include: Sync lto-symtab.h and plugin-api.h with GCC

2020-03-19  Martin Liska  <mliska@suse.cz>

* lto-symtab.h (enum gcc_plugin_symbol_type): New.
(enum gcc_plugin_symbol_section_kind): Likewise.

2020-03-19  Martin Liska  <mliska@suse.cz>

* plugin-api.h (struct ld_plugin_symbol): Split
int def into 4 char fields.
(enum ld_plugin_symbol_type): New.
(enum ld_plugin_symbol_section_kind): New.
(enum ld_plugin_tag): Add LDPT_ADD_SYMBOLS_V2.

4 years ago[AArch64] When unavailable, fetch VG from ptrace.
Luis Machado [Mon, 16 Mar 2020 17:09:25 +0000 (14:09 -0300)] 
[AArch64] When unavailable, fetch VG from ptrace.

I was doing some SVE tests on system QEMU and noticed quite a few failures
related to inferior function calls. Any attempt to do an inferior function
call would result in the following:

Unable to set VG register.: Success.

This happens because, after an inferior function call, GDB attempts to restore
the regcache state and updates the SVE register in order. Since the Z registers
show up before the VG register, VG is still INVALID by the time the first Z
register is being updated. So when executing the following code in
aarch64_sve_set_vq:

if (reg_buf->get_register_status (AARCH64_SVE_VG_REGNUM) != REG_VALID)
  return false;

By returning false, we signal something is wrong, then we get to this:

  /* First store vector length to the thread.  This is done first to ensure the
     ptrace buffers read from the kernel are the correct size.  */
  if (!aarch64_sve_set_vq (tid, regcache))
    perror_with_name (_("Unable to set VG register."));

Ideally we'd always have a valid VG before attempting to set the Z registers,
but in this case the ordering of registers doesn't make that possible.

I considered reordering the registers to put VG before the Z registers, like
the DWARF numbering, but that would break backwards compatibility with
existing implementations. Also, the Z register numbering is pinned to the V
registers, and adding VG before Z would create a gap for non-SVE targets,
since we wouldn't be able to undefine VG for non-SVE targets.

As a compromise, it seems we can safely fetch the VG register value from
ptrace. The value in the kernel is likely the updated value anyway.

This patch fixed all the failures i saw in the testsuite and caused no further
regressions.

gdb/ChangeLog:

2020-03-19  Luis Machado  <luis.machado@linaro.org>

* nat/aarch64-sve-linux-ptrace.c (aarch64_sve_set_vq): If vg is not
valid, fetch vg value from ptrace.

4 years agoFix assertion failure in the BFD library when called to parse a file containing corru...
Nick Clifton [Thu, 19 Mar 2020 14:40:00 +0000 (14:40 +0000)] 
Fix assertion failure in the BFD library when called to parse a file containing corrupt ELF group information.

PR 25699
* elf.c (bfd_elf_set_group_contents): Replace assertion with an
error return.

4 years agoAvoid get_ptrace_pid() usage on NetBSD in x86-bsd-nat.c
Kamil Rytarowski [Thu, 19 Mar 2020 13:01:36 +0000 (14:01 +0100)] 
Avoid get_ptrace_pid() usage on NetBSD in x86-bsd-nat.c

Add gdb_ptrace() that wraps the ptrace(2) API and correctly passes
the pid,lwp pair to the calls on NetBSD; and the result of
get_ptrace_pid() on other BSD Operating Systems.

gdb/ChangeLog:

* x86-bsd-nat.c (gdb_ptrace): New.
* (x86bsd_dr_set): Add new argument `ptid'.
* (x86bsd_dr_get, x86bsd_dr_set, x86bsd_dr_set_control,
x86bsd_dr_set_addr): Update.

4 years agoreadelf.c: Use unsigned long to iterate over num_syms
H.J. Lu [Thu, 19 Mar 2020 12:22:18 +0000 (05:22 -0700)] 
readelf.c: Use unsigned long to iterate over num_syms

process_symbol_table () has

  unsigned long num_syms;
  ...
  for (si = 0, psym = symtab; si < num_syms; si++, psym++)

We should use unsigned long to iterate over num_syms.

* readelf.c (process_symbol_table): Use unsigned long for si.

4 years agogdb: Handle W and X remote packets without giving a warning
Andrew Burgess [Wed, 11 Mar 2020 12:30:13 +0000 (12:30 +0000)] 
gdb: Handle W and X remote packets without giving a warning

In this commit:

  commit 24ed6739b699f329c2c45aedee5f8c7d2f54e493
  Date:   Thu Jan 30 14:35:40 2020 +0000

      gdb/remote: Restore support for 'S' stop reply packet

A regression was introduced such that the W and X packets would give a
warning in some cases.  The warning was:

  warning: multi-threaded target stopped without sending a thread-id, using first non-exited thread

This problem would arise when:

  1. The multi-process extensions to the remote protocol were not
  being used, and

  2. The inferior has multiple threads.

In this case when the W (or X) packet arrives the ptid of the
stop_reply is set to null_ptid, then when we arrive in
process_stop_reply GDB spots that we have multiple non-exited theads,
but the stop event didn't specify a thread-id.

The problem with this is that the W (and X) packets are actually
process wide events, they apply to all threads.  So not specifying a
thread-id is not a problem, in fact, the best these packets allow is
for the remote to specify a process-id, not a thread-id.

If we look at how the W (and X) packets deal with a specified
process-id, then what happens is GDB sets to stop_reply ptid to a
value which indicates all threads in the process, this is done by
creating a value `ptid_t (pid)`, which sets the pid field of the
ptid_t, but leaves the tid field as 0, indicating all threads.

So, this commit does the same thing for the case where there is not
process-id specified.  In process_stop_reply we not distinguish
between stop events that apply to all threads, and those that apply to
only one.  If the stop event applies to only one thread then we treat
it as before.  If, however, the stop event applies to all threads,
then we find the first non-exited thread, and use the pid from this
thread to create a `ptid_t (pid)` value.

If the target has multiple inferiors, and receives a process wide
event without specifying a process-id GDB now gives this warning:

  warning: multi-inferior target stopped without sending a process-id, using first non-exited inferior

gdb/ChangeLog:

* remote.c (remote_target::process_stop_reply): Handle events for
all threads differently.

gdb/testsuite/ChangeLog:

* gdb.server/exit-multiple-threads.c: New file.
* gdb.server/exit-multiple-threads.exp: New file.

4 years agogdb/testsuite/fortran: Add mixed language stack test
Andrew Burgess [Sat, 8 Feb 2020 21:26:31 +0000 (21:26 +0000)] 
gdb/testsuite/fortran: Add mixed language stack test

This commit adds a test that builds a mixed language stack, the stack
contains frames of Fortran, C, and C++.  The test prints the backtrace
and explores the stack printing arguments of different types in frames
of different languages.

The core of the test is repeated with GDB's language set to auto,
fortran, c, and c++ in turn to ensure that GDB is happy to print
frames and frame arguments when the language is set to a value that
doesn't match the frame language.

This test currently passes, and there are no known bugs in this area.
The aim of this commit is simply to increase test coverage, as I don't
believe this functionality is currently tested.

gdb/testsuite/ChangeLog:

* gdb.fortran/mixed-lang-stack.c: New file.
* gdb.fortran/mixed-lang-stack.cpp: New file.
* gdb.fortran/mixed-lang-stack.exp: New file.
* gdb.fortran/mixed-lang-stack.f90: New file.

4 years agogdb: Remove C++ symbol aliases from completion list
Andrew Burgess [Fri, 27 Dec 2019 18:31:09 +0000 (18:31 +0000)] 
gdb: Remove C++ symbol aliases from completion list

Consider debugging the following C++ program:

  struct object
  { int a; };

  typedef object *object_p;

  static int
  get_value (object_p obj)
  {
    return obj->a;
  }

  int
  main ()
  {
    object obj;
    obj.a = 0;

    return get_value (&obj);
  }

Now in a GDB session:

  (gdb) complete break get_value
  break get_value(object*)
  break get_value(object_p)

Or:

  (gdb) break get_va<TAB>
  (gdb) break get_value(object<RETURN>
  Function "get_value(object" not defined.
  Make breakpoint pending on future shared library load? (y or [n]) n

The reason this happens is that we add completions based on the
msymbol names and on the symbol names.  For C++ both of these names
include the parameter list, however, the msymbol names have some
differences from the symbol names, for example:

  + typedefs are resolved,
  + whitespace rules are different around pointers,
  + the 'const' keyword is placed differently.

What this means is that the msymbol names and symbol names appear to
be completely different to GDB's completion tracker, and therefore to
readline when it offers the completions.

This commit builds on the previous commit which reworked the
completion_tracker class.  It is now trivial to add a
remove_completion member function, this is then used along with
cp_canonicalize_string_no_typedefs to remove the msymbol aliases from
the completion tracker as we add the symbol names.

Now, for the above program GDB only presents a single completion for
'get_value', which is 'get_value(object_p)'.

It is still possible to reference the symbol using the msymbol name,
so a user can manually type out 'break get_value (object *)' if they
wish and will get the expected behaviour.

I did consider adding an option to make this alias exclusion optional,
in the end I didn't bother as I didn't think it would be very useful,
but I can easily add such an option if people think it would be
useful.

gdb/ChangeLog:

* completer.c (completion_tracker::remove_completion): Define new
function.
* completer.h (completion_tracker::remove_completion): Declare new
function.
* symtab.c (completion_list_add_symbol): Remove aliasing msymbols
when adding a C++ function symbol.

gdb/testsuite/ChangeLog:

* gdb.linespec/cp-completion-aliases.cc: New file.
* gdb.linespec/cp-completion-aliases.exp: New file.

Change-Id: Ie5c7c9fc8ecf973072cfb4a9650867104bf7f50c

4 years agogdb: Restructure the completion_tracker class
Andrew Burgess [Mon, 27 Jan 2020 17:37:20 +0000 (17:37 +0000)] 
gdb: Restructure the completion_tracker class

In this commit I rewrite how the completion tracker tracks the
completions, and builds its lowest common denominator (LCD) string.
The LCD string is now built lazily when required, and we only track
the completions in one place, the hash table, rather than maintaining
a separate vector of completions.

The motivation for these changes is that the next commit will add the
ability to remove completions from the list, removing a completion
will invalidate the LCD string, so we need to keep hold of enough
information to recompute the LCD string as needed.

Additionally, keeping the completions in a vector makes removing a
completion expensive, so better to only keep the completions in the
hash table.

This commit doesn't add any new functionality itself, and there should
be no user visible changes after this commit.

For testing, I ran the testsuite as usual, but I also ran some manual
completion tests under valgrind, and didn't get any reports about
leaked memory.

gdb/ChangeLog:

* completer.c (completion_tracker::completion_hash_entry): Define
new class.
(advance_to_filename_complete_word_point): Call
recompute_lowest_common_denominator.
(completion_tracker::completion_tracker): Call discard_completions
to setup the hash table.
(completion_tracker::discard_completions): Allow for being called
from the constructor, pass new equal function, and element deleter
when constructing the hash table.  Initialise new class member
variables.
(completion_tracker::maybe_add_completion): Remove use of
m_entries_vec, and store more information into m_entries_hash.
(completion_tracker::recompute_lcd_visitor): New function, most
content taken from...
(completion_tracker::recompute_lowest_common_denominator):
...here, this now just visits each item in the hash calling the
above visitor.
(completion_tracker::build_completion_result): Remove use of
m_entries_vec, call recompute_lowest_common_denominator.
* completer.h (completion_tracker::have_completions): Remove use
of m_entries_vec.
(completion_tracker::completion_hash_entry): Declare new class.
(completion_tracker::recompute_lowest_common_denominator): Change
function signature.
(completion_tracker::recompute_lcd_visitor): Declare new function.
(completion_tracker::m_entries_vec): Delete.
(completion_tracker::m_entries_hash): Initialize to NULL.
(completion_tracker::m_lowest_common_denominator_valid): New
member variable.
(completion_tracker::m_lowest_common_denominator_max_length): New
member variable.

Change-Id: I9d1db52c489ca0041b8959ca0d53b7d3af8aea72

4 years ago[gdb/testsuite] Fix gdb.opt/inline-locals.exp KFAILs
Tom de Vries [Thu, 19 Mar 2020 07:44:04 +0000 (08:44 +0100)] 
[gdb/testsuite] Fix gdb.opt/inline-locals.exp KFAILs

When running test-case gdb.opt/inline-locals.exp, I get:
...
Running src/gdb/testsuite/gdb.opt/inline-locals.exp ...
KPASS: gdb.opt/inline-locals.exp: info locals above bar 2 (PRMS gdb/xyz)
KPASS: gdb.opt/inline-locals.exp: info locals above bar 3 (PRMS gdb/xyz)
...

I've opened PR25695 - 'abstract and concrete variable listed both with "info
locals"' to refer to in the PRMS field, and this patch adds that reference.

Furthermore, I noticed that while I see KPASSes, given the problem description
the tests should actually be KFAILs.  This patch also fixes that.

Tested on x86_64-linux.  With gcc 7.5.0, I get 2 KFAILs.  With clang 5.0.2,
the tests pass.

gdb/testsuite/ChangeLog:

2020-03-19  Tom de Vries  <tdevries@suse.de>

* gdb.opt/inline-locals.exp: Add kfail PR number.  Make kfail matching
more precise.

4 years agoAdditional c99 elfxx-riscv.c fix
Sebastian Huber [Wed, 18 Mar 2020 06:06:28 +0000 (07:06 +0100)] 
Additional c99 elfxx-riscv.c fix

Similar to 2d0e121701a95e0f37af02bc622393b1ccd88c76.

bfd/

     * elfxx-riscv.c (riscv_parse_subset): Don't use C99.

4 years agoDon't use bfd.h in binutils/elfcomm.c
Alan Modra [Thu, 19 Mar 2020 05:03:03 +0000 (15:33 +1030)] 
Don't use bfd.h in binutils/elfcomm.c

Better than warning about bfd types, just don't include bfd.h and
warn against including the header again.

* elfcomm.c: Don't include bfd.h or bucomm.h.
(program_name): Declare.
(process_archive_index_and_symbols): Replace bfd_boolean with int,
and substitute FALSE and TRUE.
(setup_archive, setup_nested_archive): Likewise.
* elfcomm.h: Likewise.

4 years agoreadelf leak in process_archive
Alan Modra [Wed, 18 Mar 2020 23:40:32 +0000 (10:10 +1030)] 
readelf leak in process_archive

* readelf.c (process_archive): Always return via path freeing
memory.  Formatting.

4 years agoInvalid read in process_netbsd_elf_note
Alan Modra [Thu, 19 Mar 2020 01:49:50 +0000 (12:19 +1030)] 
Invalid read in process_netbsd_elf_note

* readelf.c (process_netbsd_elf_note): Validate descsz before
accessing descdata.  Formatting.

4 years agosetup_archive parameter mismatch
Alan Modra [Thu, 19 Mar 2020 01:17:45 +0000 (11:47 +1030)] 
setup_archive parameter mismatch

* elfcomm.c (setup_archive): Make file_size an off_t.  Comment.
* elfcomm.h (setup_archive): Update prototype.

4 years agoAutomatic date update in version.in
GDB Administrator [Thu, 19 Mar 2020 00:00:06 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 years ago[gdb/testsuite] Add test-case gdb.dwarf2/break-inline-psymtab.exp
Tom de Vries [Wed, 18 Mar 2020 13:40:49 +0000 (14:40 +0100)] 
[gdb/testsuite] Add test-case gdb.dwarf2/break-inline-psymtab.exp

Add a test-case that tests whether we can set a breakpoint on an inlined
inline function in CU for which the partial symtab has not yet been expanded.

Tested on x86_64-linux, with gcc 4.8.5, gcc-7.5.0, gcc-10.0.1, and clang
5.0.2.

gdb/testsuite/ChangeLog:

2020-03-18  Tom de Vries  <tdevries@suse.de>

* gdb.dwarf2/break-inline-psymtab-2.c: New test.
* gdb.dwarf2/break-inline-psymtab.c: New test.
* gdb.dwarf2/break-inline-psymtab.exp: New file.

4 years agoNon-contiguous memory regions support: Fix testcases after previous commit
Christophe Lyon [Wed, 18 Mar 2020 12:36:53 +0000 (12:36 +0000)] 
Non-contiguous memory regions support: Fix testcases after previous commit

2020-03-18  Christophe Lyon  <christophe.lyon@linaro.org>

* testsuite/ld-arm/non-contiguous-arm4.d: Fix expected output.
* testsuite/ld-powerpc/non-contiguous-powerpc.d: Likewise.

Change-Id: I8870800177e1ff79cdd05af13613ec53ef95681f

4 years agoFix seg-fault in strip when copying a file containing corrupt secondary relocs.
Nick Clifton [Wed, 18 Mar 2020 12:12:07 +0000 (12:12 +0000)] 
Fix seg-fault in strip when copying a file containing corrupt secondary relocs.

PR 25673
* elf.c (_bfd_elf_write_secondary_reloc_section): Fix illegal
memory access when processing a corrupt secondary reloc section.

4 years agoNon-contiguous memory regions support: Avoid calls to abort
Christophe Lyon [Tue, 17 Mar 2020 15:59:01 +0000 (15:59 +0000)] 
Non-contiguous memory regions support: Avoid calls to abort

Use '%F' format when printing error messages to exit cleanly rather
than by calling abort().

2020-03-18  Christophe Lyon  <christophe.lyon@linaro.org>

bfd/
* elf32-arm.c (arm_build_one_stub): Emit a fatal error message
instead of calling abort.
* elf32-csky.c (csky_build_one_stub): Likewise.
* elf32-hppa.c (hppa_build_one_stub): Likewise.
* elf32-m68hc11.c (m68hc11_elf_build_one_stub): Likewise.
* elf32-m68hc12.c (m68hc12_elf_build_one_stub): Likewise.
* elf32-metag.c (metag_build_one_stub): Likewise.
* elf32-nios2.c (nios2_build_one_stub): Likewise.
* elf64-ppc.c (ppc_build_one_stub): Likewise.
(ppc_size_one_stub): Likewise.
* elfnn-aarch64.c (aarch64_build_one_stub): Likewise.

ld/
* emultempl/xtensaelf.em: Emit a fatal error message
instead of calling abort.
* ldlang.c: Likewise.

Change-Id: I60deaeeee59d4e7cab06b8a40a3e51837c43a8ab

4 years agoNamespace the reg class to avoid clashes with OS headers
Kamil Rytarowski [Tue, 17 Mar 2020 13:38:23 +0000 (14:38 +0100)] 
Namespace the reg class to avoid clashes with OS headers

Fix build issues on NetBSD where the reg symbol exists in public headers.

regformats/regdef.h:22:8: error: redefinition struct
 struct reg
        ^~~
/usr/include/amd64/reg.h:51:8: note: previous definition struct
 struct reg {
        ^~~

gdb/ChangeLog:

* regformats/regdef.h: Put reg in gdb namespace.

gdbserver/ChangeLog:

* regcache.cc (find_register_by_number): Update.
* tdesc.cc (init_target_desc): Likewise.
* tdesc.h (target_desc::reg_defs): Likewise.

4 years agoAdd support for NetBSD threads in i386-bsd-nat.c
Kamil Rytarowski [Sat, 14 Mar 2020 16:41:11 +0000 (17:41 +0100)] 
Add support for NetBSD threads in i386-bsd-nat.c

NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.

Define gdb_ptrace() a wrapper function for ptrace(2) that properly passes
the pid,lwp pair on NetBSD and the result of get_ptrace_pid() for others.

gdb/ChangeLog:

* i386-bsd-nat.c (gdb_ptrace): New.
* (i386bsd_fetch_inferior_registers,
i386bsd_store_inferior_registers) Switch from pid_t to ptid_t.
* (i386bsd_fetch_inferior_registers,
i386bsd_store_inferior_registers) Use gdb_ptrace.

4 years agoAdd support for NetBSD threads in amd64-bsd-nat.c
Kamil Rytarowski [Sat, 14 Mar 2020 16:41:11 +0000 (17:41 +0100)] 
Add support for NetBSD threads in amd64-bsd-nat.c

NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.

Define gdb_ptrace() a wrapper function for ptrace(2) that properly passes
the pid,lwp pair on NetBSD and the result of get_ptrace_pid() for others.

gdb/ChangeLog:

* amd64-bsd-nat.c (gdb_ptrace): New.
* (amd64bsd_fetch_inferior_registers,
amd64bsd_store_inferior_registers) Switch from pid_t to ptid_t.
* (amd64bsd_fetch_inferior_registers,
amd64bsd_store_inferior_registers) Use gdb_ptrace.

4 years agoInclude <alloca.h> conditionally
Kamil Rytarowski [Tue, 17 Mar 2020 14:01:55 +0000 (15:01 +0100)] 
Include <alloca.h> conditionally

Fixes build on NetBSD, where alloca() is defined in <stdlib.h>.

gdbsupport:

* common-defs.h: Include alloca.h if HAVE_ALLOCA_H is defined.

4 years agoRename the read symbol to xread
Kamil Rytarowski [Tue, 17 Mar 2020 12:41:46 +0000 (13:41 +0100)] 
Rename the read symbol to xread

This avoids clashes with macro read in the NetBSD headers.

gdb/ChangeLog:

* user-regs.c (user_reg::read): Rename to...
(user_reg::xread): ...this.
* (append_user_reg): Rename argument `read' to `xread'.
* (user_reg_add_builtin): Likewise.
* (user_reg_add): Likewise.
* (value_of_user_reg): Likewise.

4 years agoAutomatic date update in version.in
GDB Administrator [Wed, 18 Mar 2020 00:00:05 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 years agoAdd support for NetBSD threads in sparc-nat.c
Kamil Rytarowski [Sat, 14 Mar 2020 16:41:11 +0000 (17:41 +0100)] 
Add support for NetBSD threads in sparc-nat.c

NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.

Define gdb_ptrace() a wrapper function for ptrace(2) that properly passes
the pid,lwp pair on NetBSD and the result of get_ptrace_pid() for others.

gdb/ChangeLog:

* sparc-nat.c (gdb_ptrace): New.
* sparc-nat.c (sparc_fetch_inferior_registers)
(sparc_store_inferior_registers) Remove obsolete comment.
* sparc-nat.c (sparc_fetch_inferior_registers)
(sparc_store_inferior_registers) Switch from pid_t to ptid_t.
* sparc-nat.c (sparc_fetch_inferior_registers)
(sparc_store_inferior_registers) Use gdb_ptrace.

4 years agoFix PR number in previous delta
Nick Clifton [Tue, 17 Mar 2020 17:03:53 +0000 (17:03 +0000)] 
Fix PR number in previous delta

4 years agoReplace a couple of assertions in the BFD library that can be triggered by attempts...
Nick Clifton [Tue, 17 Mar 2020 17:02:15 +0000 (17:02 +0000)] 
Replace a couple of assertions in the BFD library that can be triggered by attempts to parse corrupt input files.

PR 25633
* elf.c (_bfd_elf_copy_special_section_fields): Replace assertions
with error messages.

4 years agoFix a small set of Z80 problems.
Sergey Belyashov [Tue, 17 Mar 2020 16:55:32 +0000 (16:55 +0000)] 
Fix a small set of Z80 problems.

PR 25641
PR 25668
PR 25633
gas Fix disassembling ED+A4/AC/B4/BC opcodes.
Fix assembling lines containing colonless label and instruction
with first operand inside parentheses.
Fix registration of unsupported by target CPU registers.
* config/tc-z80.c: See above.
* config/tc-z80.h: See above.
* testsuite/gas/z80/colonless.d: Update test.
* testsuite/gas/z80/colonless.s: Likewise.
* testsuite/gas/z80/ez80_adl_all.d: Likewise.
* testsuite/gas/z80/ez80_unsup_regs.d: Likewise.
* testsuite/gas/z80/ez80_z80_all.d: Likewise.
* testsuite/gas/z80/gbz80_unsup_regs.d: Likewise.
* testsuite/gas/z80/r800_unsup_regs.d: Likewise.
* testsuite/gas/z80/unsup_regs.s: Likewise.
* testsuite/gas/z80/z180_unsup_regs.d: Likewise.
* testsuite/gas/z80/z80.exp: Likewise.
* testsuite/gas/z80/z80_strict_unsup_regs.d: Likewise.
* testsuite/gas/z80/z80_unsup_regs.d: Likewise.
* testsuite/gas/z80/z80n_unsup_regs.d: Likewise.

opcodes * z80-dis.c: Fix disassembling ED+A4/AC/B4/BC opcodes.

4 years agoRemove a double free in the BFD library triggered when parsing a corrupt file.
Nick Clifton [Tue, 17 Mar 2020 16:45:07 +0000 (16:45 +0000)] 
Remove a double free in the BFD library triggered when parsing a corrupt file.

PR 25687
* elf.c (_bfd_elf_slurp_secondary_reloc_section): Remove redundant
free.  Add free on another failure path.

4 years agoAdd support for NetBSD threads in sh-nbsd-nat.c
Kamil Rytarowski [Tue, 17 Mar 2020 15:31:49 +0000 (16:31 +0100)] 
Add support for NetBSD threads in sh-nbsd-nat.c

NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.

gdb/ChangeLog:

* sh-nbsd-nat.c (fetch_registers): New variable lwp and pass
it to the ptrace call.
* sh-nbsd-nat.c (store_registers): Likewise.

4 years agoInherit sh_nbsd_nat_target from nbsd_nat_target
Kamil Rytarowski [Tue, 17 Mar 2020 14:07:39 +0000 (15:07 +0100)] 
Inherit sh_nbsd_nat_target from nbsd_nat_target

gdb/ChangeLog:

* sh-nbsd-nat.c (sh_nbsd_nat_target): Inherit from
nbsd_nat_target instead of inf_ptrace_target.
* sh-nbsd-nat.c: Include "nbsd-nat.h", as we are now using
nbsd_nat_target.

4 years agoAutomatic date update in version.in
GDB Administrator [Tue, 17 Mar 2020 13:14:43 +0000 (13:14 +0000)] 
Automatic date update in version.in

4 years agoInclude missing header to get missing declarations
Kamil Rytarowski [Mon, 16 Mar 2020 17:26:29 +0000 (18:26 +0100)] 
Include missing header to get missing declarations

  CXX    amd64-bsd-nat.o
amd64-bsd-nat.c:42:1: error: no previous declaration void amd64bsd_fetch_inferior_registers(regcache*,  [-Werror=missing-declarations]
 amd64bsd_fetch_inferior_registers (struct regcache *regcache, int regnum)
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
amd64-bsd-nat.c:118:1: error: no previous declaration void amd64bsd_store_inferior_registers(regcache*,  [-Werror=missing-declarations]
 amd64bsd_store_inferior_registers (struct regcache *regcache, int regnum)
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Detected on NetBSD/amd64 9.99.49.

gdb/ChangeLog:

* amd64-bsd-nat.c: Include amd64-bsd-nat.h".

4 years agoRewrite nbsd_nat_target::pid_to_exec_file to sysctl(3)
Kamil Rytarowski [Sat, 14 Mar 2020 23:12:53 +0000 (00:12 +0100)] 
Rewrite nbsd_nat_target::pid_to_exec_file to sysctl(3)

procfs on NetBSD is optional and not recommended.

* nbsd-nat.c: Include <sys/types.h>, <sys/ptrace.h> and
<sys/sysctl.h>.
* nbsd-nat.c (nbsd_nat_target::pid_to_exec_file): Rewrite.

4 years ago[gdb] Skip imports of c++ CUs
Tom de Vries [Tue, 17 Mar 2020 07:56:36 +0000 (08:56 +0100)] 
[gdb] Skip imports of c++ CUs

The DWARF standard appendix E.1 describes techniques that can be used for
compression and deduplication: DIEs can be factored out into a new compilation
unit, and referenced using DW_FORM_ref_addr.

Such a new compilation unit can either use a DW_TAG_compile_unit or
DW_TAG_partial_unit.  If a DW_TAG_compile_unit is used, its contents is
evaluated by consumers as though it were an ordinary compilation unit.  If a
DW_TAG_partial_unit is used, it's only considered by consumers in the context
of a DW_TAG_imported_unit.

An example of when DW_TAG_partial_unit is required is when the factored out
DIEs are not top-level, f.i. because they were children of a namespace.  In
such a case the corresponding DW_TAG_imported_unit will occur as child of the
namespace.

In the case of factoring out DIEs from c++ compilation units, we can factor
out into a new DW_TAG_compile_unit, and no DW_TAG_imported_unit is required.

This begs the question how to interpret a top-level DW_TAG_imported_unit of a
c++ DW_TAG_compile_unit compilation unit.  The semantics of
DW_TAG_imported_unit describe that the imported unit logically appears at the
point of the DW_TAG_imported_unit entry.  But it's not clear what the effect
should be in this case, since all the imported DIEs are already globally
visible anyway, due to the use of DW_TAG_compile_unit.

So, skip top-level imports of c++ DW_TAG_compile_unit compilation units in
process_imported_unit_die.

Using the cc1 binary from PR23710 comment 1 and setting a breakpoint on do_rpo_vn:
...
$ gdb \
    -batch \
    -iex "maint set dwarf max-cache-age 316" \
    -iex "set language c++" \
    -ex "b do_rpo_vn" \
    cc1
...
we get a 8.1% reduction in execution time, due to reducing the number of
partial symtabs expanded into full symtabs from 212 to 175.

Build and reg-tested on x86_64-linux.

gdb/ChangeLog:

2020-03-17  Tom de Vries  <tdevries@suse.de>

PR gdb/23710
* dwarf2/read.h (struct dwarf2_per_cu_data): Add unit_type and lang
fields.
* dwarf2/read.c (process_psymtab_comp_unit): Initialize unit_type and lang
fields.
(process_imported_unit_die): Skip import of c++ CUs.

4 years ago[gdb/testsuite] Give up after consecutive timeouts in completion-support.exp
Tom de Vries [Tue, 17 Mar 2020 07:56:35 +0000 (08:56 +0100)] 
[gdb/testsuite] Give up after consecutive timeouts in completion-support.exp

When running test-case gdb.linespec/cpcompletion.exp with target board
unix/-flto/-O0/-flto-partition=none/-ffat-lto-objects, we run into lots of
timeouts, in particular with this pattern:
...
FAIL: gdb.linespec/cpcompletion.exp: template-ret-type: \
  cmd complete "b template2_"
FAIL: gdb.linespec/cpcompletion.exp: template-ret-type: \
  tab complete "b template2_st" (timeout)
FAIL: gdb.linespec/cpcompletion.exp: template-ret-type: \
  cmd complete "b template2_st"
FAIL: gdb.linespec/cpcompletion.exp: template-ret-type: \
  tab complete "b template2_str" (timeout)
FAIL: gdb.linespec/cpcompletion.exp: template-ret-type: \
  cmd complete "b template2_str"
FAIL: gdb.linespec/cpcompletion.exp: template-ret-type: \
  tab complete "b template2_stru" (timeout)
...

Fix this by detecting timeouts in test_complete_prefix_range_re and giving up
after 3 consecutive timeouts.

This reduces testing time from ~39m to ~9m.

Tested on x86_64-linux.

4 years agoInitialize base_value in pascal_object_print_value
Tom Tromey [Tue, 17 Mar 2020 00:32:44 +0000 (18:32 -0600)] 
Initialize base_value in pascal_object_print_value

The val_print removal series introduced a new possibly-uninitialized
warning in p-valprint.c.  Examination of the code shows that the
warning does not indicate a real bug, so this patch silences the
warning by setting the variable in the catch clause of a try/catch.
(The obvious initialization did not work due to a "goto" in this
function.)

gdb/ChangeLog
2020-03-16  Tom Tromey  <tom@tromey.com>

* p-valprint.c (pascal_object_print_value): Initialize
base_value.

4 years agoarc: Migrate to new target features
Anton Kolesov [Wed, 25 Oct 2017 18:51:54 +0000 (21:51 +0300)] 
arc: Migrate to new target features

This patch replaces usage of target descriptions in ARC, where the whole
description is fixed in XML, with new target descriptions where XML describes
individual features, and GDB assembles those features into actual target
description.

v2:
Removed arc.c from ALLDEPFILES in gdb/Makefile.in.
Removed vim modeline from arc-tdep.c to have it in a separate patch.
Removed braces from one line "if/else".
Undid the type change for "jb_pc" (kept it as "int").
Joined the unnecessary line breaks into one line.
No more moving around arm targets in gdb/features/Makefile.
Changed pattern checking for ARC features from "arc/{aux,core}" to "arc/".

v3:
Added include gaurds to arc.h.
Added arc_read_description to _create_ target descriptions less.

v4:
Got rid of ARC_SYS_TYPE_NONE.
Renamed ARC_SYS_TYPE_INVALID to ARC_SYS_TYPE_NUM.
Fixed a few indentations/curly braces.
Converted arc_sys_type_to_str from a macro to an inline function.

gdb/ChangeLog:
2020-03-16  Anton Kolesov  <anton.kolesov@synopsys.com>
    Shahab Vahedi  <shahab@synopsys.com>

* Makefile.in: Add arch/arc.o
* configure.tgt: Likewise.
* arc-tdep.c (arc_tdesc_init): Use arc_read_description.
(_initialize_arc_tdep): Don't initialize old target descriptions.
        (arc_read_description): New function to cache target descriptions.
* arc-tdep.h (arc_read_description): Add proto type.
* arch/arc.c: New file.
* arch/arc.h: Likewise.
* features/Makefile: Replace old target descriptions with new.
* features/arc-arcompact.c: Remove.
* features/arc-arcompact.xml: Likewise.
* features/arc-v2.c: Likewise
* features/arc-v2.xml: Likewise
* features/arc/aux-arcompact.xml: New file.
* features/arc/aux-v2.xml: Likewise.
* features/arc/core-arcompact.xml: Likewise.
* features/arc/core-v2.xml: Likewise.
* features/arc/aux-arcompact.c: Generate.
* features/arc/aux-v2.c: Likewise.
* features/arc/core-arcompact.c: Likewise.
* features/arc/core-v2.c: Likewise.
* target-descriptions (maint_print_c_tdesc_cmd): Support ARC features.

This page took 0.04975 seconds and 4 git commands to generate.