binutils-gdb.git
3 years agoor1k: Support large plt_relocs when generating plt entries
Stafford Horne [Thu, 6 May 2021 11:51:25 +0000 (20:51 +0900)]
or1k: Support large plt_relocs when generating plt entries

The current PLT generation code will generate invalid code when the PLT
relocation offset exceeds 64k.  This fixes the issue by detecting large
plt_reloc offsets and generare code sequences to create larger plt
relocations.

The "large" plt code needs 2 extra instructions to create 32-bit offsets.

bfd/ChangeLog:

PR 27746
* elf32-or1k.c (PLT_ENTRY_SIZE_LARGE, PLT_MAX_INSN_COUNT,
OR1K_ADD, OR1K_ORI): New macros to help with plt creation.
(elf_or1k_link_hash_table): New field plt_count.
(elf_or1k_link_hash_entry): New field plt_index.
(elf_or1k_plt_entry_size): New function.
(or1k_write_plt_entry): Update to support variable size PLTs.
(or1k_elf_finish_dynamic_sections): Use new or1k_write_plt_entry
API.
(or1k_elf_finish_dynamic_symbol): Update to write large PLTs
when needed.
(allocate_dynrelocs): Use elf_or1k_plt_entry_size to account for
PLT size.

ld/ChangeLog:

PR 27746
testsuite/ld-or1k/or1k.exp (or1kplttests): Add tests for linking
along with gotha() relocations.
testsuite/ld-or1k/gotha1.dd: New file.
testsuite/ld-or1k/gotha1.s: New file.
testsuite/ld-or1k/gotha2.dd: New file.
testsuite/ld-or1k/gotha2.s: New file
testsuite/ld-or1k/pltlib.s (x): Define size to avoid link
failure.

3 years agoor1k: Avoid R_OR1K_GOT16 overflow failures in presence of R_OR1K_GOT_AHI16
Stafford Horne [Thu, 6 May 2021 11:51:25 +0000 (20:51 +0900)]
or1k: Avoid R_OR1K_GOT16 overflow failures in presence of R_OR1K_GOT_AHI16

Now that we support R_OR1K_GOT_AHI16 we can relax the R_OR1K_GOT16
overflow validation check if the section has R_OR1K_GOT_AHI16.

We cannot simple disable R_OR1K_GOT16 overflow validation as there will
still be binaries that will have only R_OR1K_GOT16.  The
R_OR1K_GOT_AHI16 relocation will only be added by GCC when building with
the option -mcmodel=large.

This assumes that R_OR1K_GOT_AHI16 will come before R_OR1K_GOT16, which
is the code pattern that will be emitted by GCC.

bfd/ChangeLog:

PR 21464
* elf32-or1k.c (or1k_elf_relocate_section): Relax R_OR1K_GOT16
overflow check if we have R_OR1K_GOT_AHI16 followed by
R_OR1K_GOT16.

3 years agoor1k: Implement relocation R_OR1K_GOT_AHI16 for gotha()
Stafford Horne [Thu, 6 May 2021 11:51:24 +0000 (20:51 +0900)]
or1k: Implement relocation R_OR1K_GOT_AHI16 for gotha()

The gotha() relocation mnemonic will be outputted by OpenRISC GCC when
using the -mcmodel=large option.  This relocation is used along with
got() to generate 32-bit GOT offsets.  This increases the previous GOT
offset limit from the previous 16-bit (64K) limit.

This is needed on large binaries where the GOT grows larger than 64k.

bfd/ChangeLog:

PR 21464
* bfd-in2.h: Add BFD_RELOC_OR1K_GOT_AHI16 relocation.
* elf32-or1k.c (or1k_elf_howto_table, or1k_reloc_map): Likewise.
(or1k_final_link_relocate, or1k_elf_relocate_section,
or1k_elf_check_relocs): Likewise.
* libbfd.h (bfd_reloc_code_real_names): Likewise.
* reloc.c: Likewise.

cpu/ChangeLog:

PR 21464
* or1k.opc (or1k_imm16_relocs, parse_reloc): Define parse logic
for gotha() relocation.

include/ChangeLog:

PR 21464
* elf/or1k.h (elf_or1k_reloc_type): Define R_OR1K_GOT_AHI16 number.

opcodes/ChangeLog:

PR 21464
* or1k-asm.c: Regenerate.

gas/ChangeLog:

PR 21464
* testsuite/gas/or1k/reloc-1.s: Add test for new relocation.
* testsuite/gas/or1k/reloc-1.d: Add test result for new
relocation.

Cc: Giulio Benetti <giulio.benetti@benettiengineering.com>
fixup reloc, add tests

3 years agoor1k: Fix issue with plt link failure for local calls
Stafford Horne [Thu, 6 May 2021 11:51:24 +0000 (20:51 +0900)]
or1k: Fix issue with plt link failure for local calls

When building protobuf we were seeing the assert failure:

    /home/giuliobenetti/git/upstream/or1k-binutils-2.36.1/host/lib/gcc/or1k-buildroot-linux-uclibc/9.3.0/../../../../or1k-buildroot-linux-uclibc/bin/ld:
    BFD (GNU Binutils) 2.36.1 assertion fail elf32-or1k.c:2377
    /home/giuliobenetti/git/upstream/or1k-binutils-2.36.1/host/lib/gcc/or1k-buildroot-linux-uclibc/9.3.0/../../../../or1k-buildroot-linux-uclibc/bin/ld:
    BFD (GNU Binutils) 2.36.1 assertion fail elf32-or1k.c:2377
    /home/giuliobenetti/git/upstream/or1k-binutils-2.36.1/host/lib/gcc/or1k-buildroot-linux-uclibc/9.3.0/../../../../or1k-buildroot-linux-uclibc/bin/ld:
    BFD (GNU Binutils) 2.36.1 assertion fail elf32-or1k.c:2377
    collect2: error: ld returned 1 exit status

This failure happens while writing out PLT entries, there is a check
"BFD_ASSERT (h->dynindx != -1)" to confirm all plt entries have dynamic
symbol attributes.  This was failing for symbols that were
"forced_local" in previous linking code.

The fix adds logic to or1k_elf_adjust_dynamic_symbol to identify
"forced_local" symbols and exclude them from the the PLT.

bfd/ChangeLog:

PR 27624
* elf32-or1k.c (or1k_elf_adjust_dynamic_symbol): Change
condition used to cleanup plt entries to cleanup forced local
entries.

Cc: Giulio Benetti <giulio.benetti@benettiengineering.com>
3 years agogdb/guile: don't try to print location for watchpoints
Andrew Burgess [Wed, 5 May 2021 15:52:29 +0000 (16:52 +0100)]
gdb/guile: don't try to print location for watchpoints

Currently, using the guile API, if a user tries to print a breakpoint
object that represents a watchpoint, then GDB will crash.  For
example:

  (gdb) guile (use-modules (gdb))
  (gdb) guile (define wp1 (make-breakpoint "some_variable" #:type BP_WATCHPOINT #:wp-class WP_WRITE))
  (gdb) guile (register-breakpoint! wp1)
  (gdb) guile (display wp1) (newline)
  Aborted (core dumped)

This turns out to be because GDB calls event_location_to_string on the
breakpoints location, and watchpoint breakpoints don't have a
location.

This commit resolves the crash by just skipping the printing of the
location if the breakpoint doesn't have one.

Potentially, we could improve on this by printing details about what
the watchpoint is watching, however, I'm considering this a possible
future enhancement, this commit focuses just on having GDB not crash.

gdb/ChangeLog:

* guile/scm-breakpoint.c (bpscm_print_breakpoint_smob): Only print
breakpoint locations when the breakpoint actually has a location.

gdb/testsuite/ChangeLog:

* gdb.guile/scm-breakpoint.exp (test_watchpoints): Print the
watchpoint object before and after registering it with GDB.

3 years agogdb/testsuite: use proc_with_prefix in gdb.guile/scm-breakpoint.exp
Andrew Burgess [Thu, 6 May 2021 09:37:04 +0000 (10:37 +0100)]
gdb/testsuite: use proc_with_prefix in gdb.guile/scm-breakpoint.exp

Convert gdb.guile/scm-breakpoint.exp to use proc_with_prefix instead
of using nested with_test_prefix calls.  Allows a level of indentation
to be removed from most of the test procs.

There were two procs that didn't use with_test_prefix, but I converted
them to be proc_with_prefix anyway, for consistency.

gdb/testsuite/ChangeLog:

* gdb.guile/scm-breakpoint.exp (test_bkpt_basic): Convert to
'proc_with_prefix', remove use of 'with_test_prefix', and
reindent.
(test_bkpt_deletion): Likewise.
(test_bkpt_cond_and_cmds): Likewise.
(test_bkpt_invisible): Likewise.
(test_watchpoints): Likewise.
(test_bkpt_internal): Likewise.
(test_bkpt_eval_funcs): Likewise.
(test_bkpt_registration): Likewise.
(test_bkpt_address): Convert to 'proc_with_prefix'.
(test_bkpt_probe): Likewise.

3 years agogdb/testsuite: resolve duplicate test names in gdb.guile/scm-breakpoint.exp
Andrew Burgess [Wed, 5 May 2021 17:57:47 +0000 (18:57 +0100)]
gdb/testsuite: resolve duplicate test names in gdb.guile/scm-breakpoint.exp

Extend some test names to avoid duplicates.

gdb/testsuite/ChangeLog:

* gdb.guile/scm-breakpoint.exp (test_bkpt_basic): Extend test
names to avoid duplicates.
(test_bkpt_cond_and_cmds): Likewise.
(test_bkpt_eval_funcs): Likewise.

3 years agogdb/mi: add a '--force' flag to the '-break-condition' command
Tankut Baris Aktemur [Thu, 6 May 2021 08:13:06 +0000 (10:13 +0200)]
gdb/mi: add a '--force' flag to the '-break-condition' command

Add a '--force' flag to the '-break-condition' command to be
able to force conditions.

gdb/ChangeLog:
2021-05-06  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* mi/mi-cmd-break.c (mi_cmd_break_condition): New function.
* mi/mi-cmds.c: Change the binding of "-break-condition" to
mi_cmd_break_condition.
* mi/mi-cmds.h (mi_cmd_break_condition): Declare.
* breakpoint.h (set_breakpoint_condition): Declare a new
overload.
* breakpoint.c (set_breakpoint_condition): New overloaded function
extracted out from ...
(condition_command): ... this.
* NEWS: Mention the change.

gdb/testsuite/ChangeLog:
2021-05-06  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* gdb.mi/mi-break.exp (test_forced_conditions): Add a test
for the -break-condition command's "--force" flag.

gdb/doc/ChangeLog:
2021-05-06  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* gdb.texinfo (GDB/MI Breakpoint Commands): Mention the
'--force' flag of the '-break-condition' command.

3 years agogdb/mi: add a '--force-condition' flag to the '-break-insert' cmd
Tankut Baris Aktemur [Thu, 6 May 2021 08:13:06 +0000 (10:13 +0200)]
gdb/mi: add a '--force-condition' flag to the '-break-insert' cmd

Add a '--force-condition' flag to the '-break-insert' command to be
able to force conditions.  Because the '-dprintf-insert' command uses
the same mechanism as the '-break-insert' command, it obtains the
'--force-condition' flag, too.

gdb/ChangeLog:
2021-05-06  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* mi/mi-cmd-break.c (mi_cmd_break_insert_1): Recognize the
'--force-condition' flag to force the condition in the
'-break-insert' and '-dprintf-insert' commands.
* NEWS: Mention the change.

gdb/testsuite/ChangeLog:
2021-05-06  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* gdb.mi/mi-break.exp (test_forced_conditions): New proc that
is called by the test.

gdb/doc/ChangeLog:
2021-05-06  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* gdb.texinfo (GDB/MI Breakpoint Commands): Mention the
'--force-condition' flag of the '-break-insert' and
'-dprintf-insert' commands.

3 years agolibctf, ld: fix test results for upstream GCC
Nick Alcock [Thu, 6 May 2021 08:30:58 +0000 (09:30 +0100)]
libctf, ld: fix test results for upstream GCC

The tests currently in binutils are aimed at the original GCC-based
implementation of CTF, which emitted CTF directly from GCC's internal
representation.  The approach now under review emits CTF from DWARF,
with an eye to eventually doing this for all non-DWARF debuginfo-like
formats GCC supports.  It also uses a different flag to enable
CTF emission (-gctf rather than -gt).

Adjust the testsuite accordingly.

Given that the ld testsuite results are dependent on type ordering,
which we do not guarantee at all, it's amazing how little changes. We
see a few type ordering differences, slices change because the old GCC
was buggy (slices were emitted "backwards", from the wrong end of the
machine word) and its expected results were wrong, and GCC now emits the
underlying integral type for enumerated types, though CTF has no way to
record this yet (coming in v4).

GCC also now emits even hidden symbols into the symtab (and thus
symtypetab), so one symtypetab test changes its expected results
slightly to compensate.

Also add tests for the CTF_K_UNKNOWN nonrepresentable type: this
couldn't be done before now since the only GCC that emits CTF_K_UNKNOWN
for nonrepresentable types is the new one.

ld/ChangeLog
2021-05-06  Nick Alcock  <nick.alcock@oracle.com>

* testsuite/ld-ctf/ctf.exp: Use -gctf, not -gt.
* testsuite/lib/ld-lib.exp: Likewise.
* testsuite/ld-ctf/nonrepresentable-1.c: New test for nonrepresentable types.
* testsuite/ld-ctf/nonrepresentable-2.c: Likewise.
* testsuite/ld-ctf/nonrepresentable.d: Likewise.
* testsuite/ld-ctf/array.d: Larger type section.
* testsuite/ld-ctf/data-func-conflicted.d: Likewise.
* testsuite/ld-ctf/enums.d: Likewise.
* testsuite/ld-ctf/conflicting-enums.d: Don't compare types.
* testsuite/ld-ctf/cross-tu-cyclic-conflicting.d: Changed type order.
* testsuite/ld-ctf/cross-tu-noncyclic.d: Likewise.
* testsuite/ld-ctf/slice.d: Adjust for improved slice emission.

libctf/ChangeLog
2021-05-06  Nick Alcock  <nick.alcock@oracle.com>

* testsuite/lib/ctf-lib.exp: Use -gctf, not -gt.
* testsuite/libctf-regression/nonstatic-var-section-ld-r.lk:
Hidden symbols now get into the symtypetab anyway.

3 years agolibctf, include: support an alternative encoding for nonrepresentable types
Nick Alcock [Thu, 6 May 2021 08:30:58 +0000 (09:30 +0100)]
libctf, include: support an alternative encoding for nonrepresentable types

Before now, types that could not be encoded in CTF were represented as
references to type ID 0, which does not itself appear in the
dictionary. This choice is annoying in several ways, principally that it
forces generators and consumers of CTF to grow special cases for types
that are referenced in valid dicts but don't appear.

Allow an alternative representation (which will become the only
representation in format v4) whereby nonrepresentable types are encoded
as actual types with kind CTF_K_UNKNOWN (an already-existing kind
theoretically but not in practice used for padding, with value 0).
This is backward-compatible, because CTF_K_UNKNOWN was not used anywhere
before now: it was used in old-format function symtypetabs, but these
were never emitted by any compiler and the code to handle them in libctf
likely never worked and was removed last year, in favour of new-format
symtypetabs that contain only type IDs, not type kinds.

In order to link this type, we need an API addition to let us add types
of unknown kind to the dict: we let them optionally have names so that
GCC can emit many different unknown types and those types with identical
names will be deduplicated together.  There are also small tweaks to the
deduplicator to actually dedup such types, to let opening of dicts with
unknown types with names work, to return the ECTF_NONREPRESENTABLE error
on resolution of such types (like ID 0), and to print their names as
something useful but not a valid C identifier, mostly for the sake of
the dumper.

Tests added in the next commit.

include/ChangeLog
2021-05-06  Nick Alcock  <nick.alcock@oracle.com>

* ctf.h (CTF_K_UNKNOWN): Document that it can be used for
nonrepresentable types, not just padding.
* ctf-api.h (ctf_add_unknown): New.

libctf/ChangeLog
2021-05-06  Nick Alcock  <nick.alcock@oracle.com>

* ctf-open.c (init_types): Unknown types may have names.
* ctf-types.c (ctf_type_resolve): CTF_K_UNKNOWN is as
non-representable as type ID 0.
(ctf_type_aname): Print unknown types.
* ctf-dedup.c (ctf_dedup_hash_type): Do not early-exit for
CTF_K_UNKNOWN types: they have real hash values now.
(ctf_dedup_rwalk_one_output_mapping): Treat CTF_K_UNKNOWN types
like other types with no referents: call the callback and do not
skip them.
(ctf_dedup_emit_type): Emit via...
* ctf-create.c (ctf_add_unknown): ... this new function.
* libctf.ver (LIBCTF_1.2): Add it.

3 years agosim: h8300 special case test
Yoshinori Sato [Tue, 4 May 2021 13:22:58 +0000 (22:22 +0900)]
sim: h8300 special case test

In "mov. [bwl] reg, @ -reg", added a special case test
using the same register.

3 years agosim: m32c/rl78/rx: fix command parsing
Mike Frysinger [Wed, 5 May 2021 18:54:33 +0000 (14:54 -0400)]
sim: m32c/rl78/rx: fix command parsing

Use buildargv to avoid writing to const memory and freeing invalid
pointers, and to avoid doing any string parsing ourselves.

3 years agoelf: Always append ".COUNT" to local symbols
H.J. Lu [Thu, 6 May 2021 03:28:39 +0000 (20:28 -0700)]
elf: Always append ".COUNT" to local symbols

Always append ".COUNT" to local symbols to avoid potential conflicts
with existing local symbol "XXX.COUNT".

bfd/

PR ld/27825
* elflink.c (elf_link_output_symstrtab): Always append ".COUNT"
to local symbols.

ld/

PR ld/27825
* testsuite/ld-elf/pr27825-1.d: New file.
* testsuite/ld-elf/pr27825-1a.s: Likewise.
* testsuite/ld-elf/pr27825-1b.s: Likewise.
* testsuite/ld-elf/pr27825-2.d: Likewise.
* testsuite/ld-elf/pr27825-2a.s: Likewise.
* testsuite/ld-elf/pr27825-2b.s: Likewise.

3 years agoAutomatic date update in version.in
GDB Administrator [Thu, 6 May 2021 00:00:37 +0000 (00:00 +0000)]
Automatic date update in version.in

3 years ago[gdb/testsuite] Fix timeout in gdb.threads/detach-step-over.exp with readnow
Tom de Vries [Wed, 5 May 2021 13:13:17 +0000 (15:13 +0200)]
[gdb/testsuite] Fix timeout in gdb.threads/detach-step-over.exp with readnow

When running test-case gdb.threads/detach-step-over.exp with target board
readnow, I run into:
...
Reading symbols from /lib64/libc.so.6...^M
Reading symbols from \
  /usr/lib/debug/lib64/libc-2.26.so-2.26-lp152.26.6.1.x86_64.debug...^M
Expanding full symbols from \
  /usr/lib/debug/lib64/libc-2.26.so-2.26-lp152.26.6.1.x86_64.debug...^M
FAIL: gdb.threads/detach-step-over.exp: \
  breakpoint-condition-evaluation=host: target-non-stop=on: non-stop=on: \
  displaced=off: iter 2: attach (timeout)
...

Fix this by doing exp_continue when encountering the "Reading symbols" or
"Expanding full symbols" lines.

This is still fragile and times out with a higher load, similated f.i. by
stress -c 5.  Fix that by using a timeout factor of 2.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2021-05-05  Tom de Vries  <tdevries@suse.de>

* gdb.threads/detach-step-over.exp: Do exp_continue when encountering
"Reading symbols" or "Expanding full symbols" lines.  Using timeout
factor of 2 for attach.

3 years ago[gdb/testsuite] Fix gdb.threads/fork-plus-threads.exp with readnow
Tom de Vries [Wed, 5 May 2021 07:07:27 +0000 (09:07 +0200)]
[gdb/testsuite] Fix gdb.threads/fork-plus-threads.exp with readnow

When running test-case gdb.threads/fork-plus-threads.exp with target board
readnow, I run into:
...
[LWP 9362 exited]^M
[New LWP 9365]^M
[New LWP 9363]^M
[New LWP 9364]^M
FAIL: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: \
  inferior 1 exited (timeout)
...

There is code in the test-case to prevent timeouts with readnow:
...
       -re "Thread \[^\r\n\]+ exited" {
           # Avoid timeout with check-read1
           exp_continue
       }
       -re "New Thread \[^\r\n\]+" {
           # Avoid timeout with check-read1
           exp_continue
       }
...
but this doesn't trigger because we get LWP rather than Thread.

Fix this by making these regexps accept LWP as well.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2021-05-05  Tom de Vries  <tdevries@suse.de>

* gdb.threads/fork-plus-threads.exp: Handle "New LWP <n>" and
"LWP <n> exited" messages.

3 years agoasan: stack-buffer-overflow vms-lib.c:367
Alan Modra [Wed, 5 May 2021 04:03:00 +0000 (13:33 +0930)]
asan: stack-buffer-overflow vms-lib.c:367

* vms-lib.c (vms_traverse_index): Account for vms_kbn size when
sanity checking keylen.

3 years agosim: rl78: clean up various warnings
Mike Frysinger [Wed, 5 May 2021 02:56:31 +0000 (22:56 -0400)]
sim: rl78: clean up various warnings

A random grab bag of minor fixes to enable -Werror for this port.

Fix local prototypes for a bunch of functions (e.g. adding static).
Add missing includes for missing prototypes.
Move local variable decls from the middle of functions to the top
of the scope.
Fix a logic error when processing commands where p was reassigned
to cmd and then has its leading whitespace scanned a 2nd time.
Handle short reads with fread().

3 years agogdb: update Type.fields doc based on actual GDB behavior
Simon Marchi [Wed, 5 May 2021 02:19:05 +0000 (22:19 -0400)]
gdb: update Type.fields doc based on actual GDB behavior

I noticed two errors in the Type.fields documentation:

1. It is possible to call `fields` on an array type, in which case it
   returns one field representing the array's range.  It is not
   mentioned.

2. When calling `fields` on a type that doesn't have fields (by nature,
   like an int), GDB raises a TypeError.  It does not return an empty
   sequence, as currently documented.

Fix these, and change the text into a bullet list.  I find it easier to
read than one big paragraph.

The first issue is already tested in gdb.python/py-type.exp, but the
second one doesn't seem tested.  Add a test in gdb.python/py-type.exp
for it.

gdb/doc/ChangeLog:

* python.texi (Types In Python): Re-organize Type.fields doc.
Mention handling of array types.  Correct doc for when calling
the method on another type.

gdb/testsuite/ChangeLog:

* gdb.python/py-type.exp (test_fields): Test calling fields on
an int type.

Change-Id: I11c688177504cb070b81a4446ac91dec50b56a22

3 years agosim: m68hc11: tweak types to fix warnings
Mike Frysinger [Sun, 2 May 2021 02:37:49 +0000 (22:37 -0400)]
sim: m68hc11: tweak types to fix warnings

The hw attach API wants unsigned addresses.
The write API wants signed chars.

3 years agosim: mips: include stdlib.h for memory prototypes
Mike Frysinger [Wed, 5 May 2021 02:03:37 +0000 (22:03 -0400)]
sim: mips: include stdlib.h for memory prototypes

This file uses free() and friends, so include it to fix missing
prototype warnings.

3 years agosim: mips: always enable device models
Mike Frysinger [Tue, 4 May 2021 12:39:17 +0000 (08:39 -0400)]
sim: mips: always enable device models

There's no need to restrict these to only specific targets as the user
can select them at runtime if they want them.  Always build them so we
can improve build coverage too.

3 years agosim: mips: delete unused constant variables
Mike Frysinger [Tue, 4 May 2021 12:38:29 +0000 (08:38 -0400)]
sim: mips: delete unused constant variables

Since these never change, inline and delete them.

3 years agosim: mcore: fix build time warnings
Mike Frysinger [Tue, 4 May 2021 12:35:40 +0000 (08:35 -0400)]
sim: mcore: fix build time warnings

Once we fix a minor const warning we can enable -Werror in here.

3 years agosim: remove sys/times.h in most places
Mike Frysinger [Tue, 4 May 2021 12:33:24 +0000 (08:33 -0400)]
sim: remove sys/times.h in most places

The v850 port used this, and then it got copied to other ports even
though it wasn't needed.  Clean it up to avoid portability issues on
platforms not providing this (e.g. mingw64 for Windows).

3 years agosim: mips: fix qh_acc table
Mike Frysinger [Sun, 2 May 2021 01:17:12 +0000 (21:17 -0400)]
sim: mips: fix qh_acc table

The AccAddLQH func was unused, and looking at this table, it looks
like it's due to a typo.

3 years agosim: hw: localize init callback
Mike Frysinger [Sun, 2 May 2021 03:37:35 +0000 (23:37 -0400)]
sim: hw: localize init callback

Now that we don't need to hardcode the module init list in a single
place, move the hw init logic out to the sim-hw file.

3 years agosim: microblaze: enable some basic trace points
Mike Frysinger [Tue, 27 Apr 2021 03:17:15 +0000 (23:17 -0400)]
sim: microblaze: enable some basic trace points

This isn't super complete, but it's useful enough as-is.

3 years agosim: microblaze: hook up libgloss syscalls
Mike Frysinger [Tue, 27 Apr 2021 03:14:11 +0000 (23:14 -0400)]
sim: microblaze: hook up libgloss syscalls

When in the virtual environment, have brki 8 trigger libgloss syscalls
like other ports.  This also matches the ABI that Linux uses for its
syscalls (ignoring the syscall table differences).

3 years agoPowerPC undefweak testcase
Alan Modra [Wed, 5 May 2021 01:05:31 +0000 (10:35 +0930)]
PowerPC undefweak testcase

Test for commit 4916030821bb and b293661219c3.

* testsuite/ld-powerpc/empty.s: New file.
* testsuite/ld-powerpc/undefweak.d,
* testsuite/ld-powerpc/undefweak.s: New testcase.
* testsuite/ld-powerpc/powerpc.exp: Run it.

3 years agoAutomatic date update in version.in
GDB Administrator [Wed, 5 May 2021 00:00:35 +0000 (00:00 +0000)]
Automatic date update in version.in

3 years agoAdd missing stdlib.h includes to sim
Tom Tromey [Tue, 4 May 2021 14:56:12 +0000 (08:56 -0600)]
Add missing stdlib.h includes to sim

This updates the various "mloop.in" files to emit an include of
stdlib.h, to avoid warnings about 'abort' being undeclared.

One such warning now remains, in mn10300.igen.  I don't know offhand
the best way to fix this one.

2021-05-04  Tom Tromey  <tromey@adacore.com>

* mloop.in: Include <stdlib.h>.

sim/iq2000/ChangeLog
2021-05-04  Tom Tromey  <tromey@adacore.com>

* mloop.in: Include <stdlib.h>.

sim/lm32/ChangeLog
2021-05-04  Tom Tromey  <tromey@adacore.com>

* mloop.in: Include <stdlib.h>.

sim/m32r/ChangeLog
2021-05-04  Tom Tromey  <tromey@adacore.com>

* mloop.in: Include <stdlib.h>.

sim/or1k/ChangeLog
2021-05-04  Tom Tromey  <tromey@adacore.com>

* mloop.in: Include <stdlib.h>.

3 years agoFix igen build
Tom Tromey [Tue, 4 May 2021 14:45:46 +0000 (08:45 -0600)]
Fix igen build

The igen build fails for me like:

gcc  -g -O2 -c ../../binutils-gdb/sim/igen/igen.c -o igen/igen.o
In file included from ../../binutils-gdb/sim/igen/igen.c:26:
../../binutils-gdb/sim/igen/lf.h:22:10: fatal error: ansidecl.h: No such file or directory

This patch fixes the problem by arranging for igen to find the
libiberty includes.

This seems slightly hacky to me, because libiberty is not a "build"
library, so it can't be linked against.  However, since igen currently
only includes the header, it seems relatively safe.

2021-05-04  Tom Tromey  <tromey@adacore.com>

* Makefile.in: Rebuild.
* Makefile.am (AM_CPPFLAGS): New variable.

3 years agoAdd config.h to generated_files for sim
Tom Tromey [Tue, 4 May 2021 14:37:13 +0000 (08:37 -0600)]
Add config.h to generated_files for sim

I noticed that config.h isn't in 'generated_files' in the sim
subdirectories.  This causes it to sometimes be rebuilt too late.

2021-05-04  Tom Tromey  <tromey@adacore.com>

* Make-common.in (generated_files): Add config.h.

3 years agognulib: import gendocs
Mike Frysinger [Sun, 2 May 2021 16:05:44 +0000 (12:05 -0400)]
gnulib: import gendocs

This will be used to generate more complete docs for the binutils site.

3 years agognulib: import getline
Mike Frysinger [Sat, 1 May 2021 22:00:27 +0000 (18:00 -0400)]
gnulib: import getline

We use getline in sim today which breaks on older systems that are
not compliant with the latest POSIX standard.  For example, mingw64
for Windows omits getline so we fail to build there.

3 years agogdb/testsuite: adjust gdb.python/flexible-array-member.exp expected pattern
Simon Marchi [Tue, 4 May 2021 15:20:09 +0000 (11:20 -0400)]
gdb/testsuite: adjust gdb.python/flexible-array-member.exp expected pattern

The `Type.range ()` tests in gdb.python/flexible-array-member.exp pass
when the test is compiled with gcc 9 or later, but not with gcc 8 or
earlier:

    $ make check TESTS="gdb.python/flexible-array-member.exp" RUNTESTFLAGS="CC_FOR_TARGET='gcc-8'"

    python print(zs['items'].type.range())^M
    (0, 0)^M
    (gdb) FAIL: gdb.python/flexible-array-member.exp: python print(zs['items'].type.range())
    python print(zso['items'].type.range())^M
    (0, 0)^M
    (gdb) FAIL: gdb.python/flexible-array-member.exp: python print(zso['items'].type.range())

The value that we get for the upper bound of a flexible array member
declared with a "0" size is 0 with gcc <= 8 and is -1 for gcc >= 9.
This is due to different debug info.  For this member, gcc 8 does:

    0x000000d5:   DW_TAG_array_type
                    DW_AT_type [DW_FORM_ref4]       (0x00000034 "int")
                    DW_AT_sibling [DW_FORM_ref4]    (0x000000e4)

    0x000000de:     DW_TAG_subrange_type
                      DW_AT_type [DW_FORM_ref4]     (0x0000002d "long unsigned int")

For the same type, gcc 9 does:

    0x000000d5:   DW_TAG_array_type
                    DW_AT_type [DW_FORM_ref4]       (0x00000034 "int")
                    DW_AT_sibling [DW_FORM_ref4]    (0x000000e5)

    0x000000de:     DW_TAG_subrange_type
                      DW_AT_type [DW_FORM_ref4]     (0x0000002d "long unsigned int")
                      DW_AT_count [DW_FORM_data1]   (0x00)

Ideally, GDB would present a consistent and documented value for an
array member declared with size 0, regardless of how the debug info
looks like.  But for now, just change the test to accept the two
values, to get rid of the failure and make the test in sync

I also realized (by looking at the py-type.exp test) that calling the
fields method on an array type yields one field representing the "index"
of the array.  The type of that field is of type range
(gdb.TYPE_CODE_RANGE).  When calling `.range()` on that range type, it
yields the same range tuple as when calling `.range()` on the array type
itself.  For completeness, add some tests to access the range tuple
through that range type as well.

gdb/testsuite/ChangeLog:

* gdb.python/flexible-array-member.exp: Adjust expected range
value for member declared with 0 size.  Test accessing range
tuple through range type.

Change-Id: Ie4e06d99fe9315527f04577888f48284d649ca4c

3 years agoDefine bfd_realloc(ptr,0) to return allocated memory, whilst bfd_realloc_or_free...
Nick Clifton [Tue, 4 May 2021 13:29:04 +0000 (14:29 +0100)]
Define bfd_realloc(ptr,0) to return allocated memory, whilst bfd_realloc_or_free(ptr,0) frees ptr.

* libbfd.c (bfd_malloc): Provide some documenation.  Treat a size
of 0 as 1.
(bfd_realloc): Likewise.
(bfd_zmalloc): Likewise.
(bfd_realloc_or_free): Provide some documentation.  Treat a size
of 0 as a request to free.
* libbfd-in.h (bfd_realloc): Remove prototype.
(bfd_realloc_or_free): Remove prototype.
(bfd_zmalloc): Remove prototype.
* libbfd.h: Regenerate.

3 years agoReplace AC_PROG_CC with AC_PROG_CC_C99 in top level configure file.
Nick Clifton [Tue, 4 May 2021 12:40:34 +0000 (13:40 +0100)]
Replace AC_PROG_CC with AC_PROG_CC_C99 in top level configure file.

2021-05-04  Nick Clifton  <nickc@redhat.com>

* configure.ac (AC_PROG_CC): Replace with AC_PROG_CC_C99.
* configure: Regenerate.

3 years agosim: add support for build-time ar & ranlib
Mike Frysinger [Sat, 1 May 2021 21:16:23 +0000 (17:16 -0400)]
sim: add support for build-time ar & ranlib

This is needed when building for a target whose ar & ranlib are
incompatible with the current build system.  For example, building
for Windows on a Linux system.

Then manually import the automake rule for libigen.a, but tweak the
tool variables to use the FOR_BUILD variants.

3 years agosim: clean up bfd_vma printing
Mike Frysinger [Tue, 4 May 2021 03:27:16 +0000 (23:27 -0400)]
sim: clean up bfd_vma printing

A lot of this code predates the bfd_vma format define, so we have a
random mix of casts to known types so we can printf the value.  Use
the BFD_VMA_FMT that now exists to simplify and reliability output
across different build configs.

3 years ago[gdb/guile] Don't allow libguile to change libgmp mem fns
Tom de Vries [Tue, 4 May 2021 08:26:16 +0000 (10:26 +0200)]
[gdb/guile] Don't allow libguile to change libgmp mem fns

Since gdb commit 880ae75a2b7 "gdb delay guile initialization until
gdbscm_finish_initialization" I'm running into:
...
(gdb) print My_Var > 10.0^M
free(): invalid pointer^M
ERROR: GDB process no longer exists
GDB process exited with wait status 5995 exp9 0 0 CHILDKILLED SIGABRT SIGABRT
UNRESOLVED: gdb.ada/fixed_cmp.exp: gnat_encodings=all: print My_Var > 10.0
...

The problem is that both gdb and libguile try to set the libgmp memory functions,
and since the gdb commit the ones from libguile are effective, which results
in gdb freeing some memory in a way that is not compatible with the way that
memory was actually allocated.

The fact that libguile tries to set the libgmp memory functions is a bug which
should be fixed starting version v3.0.6.

Meanwhile, work around this in gdb by not allowing libguile to set the libgomp
memory functions.

Tested on x86_64-linux.

gdb/ChangeLog:

2021-05-04  Tom de Vries  <tdevries@suse.de>

PR guile/27806
* guile/guile.c (gdbscm_initialize): Don't let guile change libgmp
memory functions.

3 years agoAutomatic date update in version.in
GDB Administrator [Tue, 4 May 2021 00:00:34 +0000 (00:00 +0000)]
Automatic date update in version.in

3 years agoRISC-V: PR27764, Add tests for A extension
Jim Wilson [Mon, 3 May 2021 23:19:17 +0000 (16:19 -0700)]
RISC-V: PR27764, Add tests for A extension

ChangeLog entry for last patch.

3 years agoRISC-V: PR27764, Add tests for A extension
Christoph Muellner [Wed, 21 Apr 2021 22:28:27 +0000 (00:28 +0200)]
RISC-V: PR27764, Add tests for A extension

gas/
    PR 27764
    * testsuite/gas/riscv/a-ext-64.d: New testcase.
    * testsuite/gas/riscv/a-ext-64.s: Likewise.
    * testsuite/gas/riscv/a-ext.d: Likewise.
    * testsuite/gas/riscv/a-ext.s: Likewise.

Signed-off-by: Christoph Muellner <cmuellner@gcc.gnu.org>
3 years agoFix x86_64 mingw build
Tom Tromey [Mon, 3 May 2021 14:57:46 +0000 (08:57 -0600)]
Fix x86_64 mingw build

PR build/27807 points out that my recent changes to the Windows port
missed a spot in win32-i386-low.cc -- a call to
win32_Wow64GetThreadContext remained, causing link errors in
gdbserver.  This happened because I tested an i686 build, but this
code is only used on an x86_64 build.

This patch fixes the bug.  I am checking it in.

gdbserver/ChangeLog
2021-05-03  Tom Tromey  <tromey@adacore.com>

PR build/27807:
* win32-i386-low.cc (i386_get_thread_context): Call
Wow64GetThreadContext, not win32_Wow64GetThreadContext.

3 years agosim: add ATTRIBUTE_PRINTF / ATTRIBUTE_NULL_PRINTF where necessary
Simon Marchi [Mon, 3 May 2021 14:54:08 +0000 (10:54 -0400)]
sim: add ATTRIBUTE_PRINTF / ATTRIBUTE_NULL_PRINTF where necessary

I finally got the all-targets sim building with Clang, these are all the
instances where an ATTRIBUTE_PRINTF or ATTRIBUTE_NULL_PRINTF attribute
needed to be added to avoid errors like:

    /home/simark/src/binutils-gdb/sim/aarch64/../common/sim-profile.c:464:19: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
        vfprintf (fp, fmt, ap);
                      ^~~
There are more fixes needed to get everything building, but adding these
attributes is trivial enough, so I send them all in a single patch.

Adding the format attributes introduces some format string errors when
building with GCC (because now format strings are checked), so
corresponding changes are needed to avoid breaking the build.  Other
than simple format string specified changes, there is this one:

    /home/simark/src/binutils-gdb/sim/aarch64/../common/hw-events.c: In function 'hw_event_queue_schedule':
    /home/simark/src/binutils-gdb/sim/aarch64/../common/hw-events.c:95:15: error: too many arguments for format [-Werror=format-extra-args]
       95 |         NULL, dummy);
          |               ^~~~~

We can fix it and avoid using a dummy variable by simply calling
hw_event_queue_schedule_tracef instead of
hw_event_queue_schedule_vtracef.

sim/arm/ChangeLog:

* armdefs.h (ARMul_ConsolePrint): Use format attribute.
* wrapper.c (op_printf): Likewise.

sim/bfin/ChangeLog:

* interp.c (sim_open): Adjust format string specifier.

sim/common/ChangeLog:

* hw-events.h (hw_event_queue_schedule_tracef): Use format attribute.
(hw_event_queue_schedule_vtracef): Likewise.
* hw-tree.h (hw_tree_vparse): Likewise.
* sim-profile.c (profile_vprintf): Likewise.
* sim-trace.c (dis_printf): Likewise.
* sim-trace.h (trace_printf): Likewise.
(trace_vprintf): Likewise.
* sim-utils.h (sim_do_commandf): Likewise.
* hw-events.c (hw_event_queue_schedule): Use
hw_event_queue_schedule_tracef.

sim/rx/ChangeLog:

* trace.c (op_printf): Likewise.

sim/v850/ChangeLog:

* interp.c (sim_open): Adjust format string specifier.

Change-Id: I1445115ce57db15bb8e35dca93014555e7555794

3 years agox86: allow @secrel32 also in data definitions
Jan Beulich [Mon, 3 May 2021 11:28:30 +0000 (13:28 +0200)]
x86: allow @secrel32 also in data definitions

Now that lex_got() is uniform for all targets using it, permit COFF
targets to also use @secrel32 with, in particular, .long. This is more
natural than the custom .secrel32 directive, and also allows more
flexibility (the "+six" form of the two added test lines doesn't work
with a .secrel32 equivalent, in that it silently produces an unintended
relocation type).

As an extra benefit this also makes sure that data definitions in Intel
syntax mode would get treated like they do for e.g. ELF targets.

3 years agox86: use UNIX EOL in secrel testcase
Jan Beulich [Mon, 3 May 2021 11:27:47 +0000 (13:27 +0200)]
x86: use UNIX EOL in secrel testcase

For some reason these were using Windows EOL.

3 years agox86: fold both instances of lex_got()
Jan Beulich [Mon, 3 May 2021 11:26:41 +0000 (13:26 +0200)]
x86: fold both instances of lex_got()

I see no reason at all for us to carry two copies of almost identical
code. The differences, apart from the table entries, are benign. And
the #ifdef-ary doesn't really get any worse.

3 years agox86: don't request useless overflow checking
Jan Beulich [Mon, 3 May 2021 11:25:12 +0000 (13:25 +0200)]
x86: don't request useless overflow checking

Relocations with a bitsize matching the architecture's address width
can't usefully use an overflow checking approach other than "dont" or
"signed": All others involve perhaps complex calculations in
_bfd_relocate_contents() (or, not as severe, in bfd_check_overflow())
without ever finding anything to complain about - because of the address
width masking applied. Avoid this unnecessary overhead and switch all
such reloc types to "dont".

Note that "signed" checking with rela relocations (i.e. x86-64 here) is
only going to be useful if the addend actually got passed to
_bfd_relocate_contents() (and maybe others) instead of bogusly adding in
prior section contents (which apparently is assumed to be zero, and
hence again no overflow would ever be detected). See
https://sourceware.org/pipermail/binutils/2021-April/116164.html.

3 years agogdb/testsuite: update expected results in gdb.python/py-startup-opt.exp
Andrew Burgess [Thu, 29 Apr 2021 09:11:35 +0000 (10:11 +0100)]
gdb/testsuite: update expected results in gdb.python/py-startup-opt.exp

The test gdb.python/py-startup-opt.exp checks the behaviour of GDB's:

  set python dont-write-bytecode on

This flag (when on) stops Python creating .pyc files.  The test first
checks that .pyc files will be created, then turns this option on and
checks .pyc files will not be created.

However, if the user has PYTHONDONTWRITEBYTECODE set in their
environment then this will prevent Python from creating .pyc files, as
such the first test, that .pyc files are being created, currently
fails.

We could unset PYTHONDONTWRITEBYTECODE, however, until Python 3.8
there is no way to control where Python writes the .pyc files.  As the
GDB developer clearly doesn't want .pyc files created in their
file-system it feels wrong to silently unset this environment
variable.

My proposal then, is that we just spot when this environment variable
is set and adjust the expected results.  My hope is that across all
GDB developers some will be running with PYTHONDONTWRITEBYTECODE
unset, so this feature will be fully tested at least some of the time.

gdb/testsuite/ChangeLog:

PR testsuite/27788
* gdb.python/py-startup-opt.exp (test_python_settings): Change the
expected results when environment variable PYTHONDONTWRITEBYTECODE
is set.

3 years agoPPC: undefweak dynamic relocs
Alan Modra [Mon, 3 May 2021 02:58:46 +0000 (12:28 +0930)]
PPC: undefweak dynamic relocs

This makes the default for ppc to keep dynamic relocs on undefweak
symbols when the code won't cause DT_TEXTREL (for instance when -fPIE
or -fPIC).  If ld is given -z dynamic-undefined-weak then dynamic
relocations will be created for non-PIC at the expense of possibly
causing DT_TEXTREL to be set on ppc32.  Note that DT_TEXTREL and GNU
indirect functions are incompatible.

* elf32-ppc.c (allocate_dynrelocs): Keep dyn_relocs for undefweak
symbols when -z dynamic-undefined-weak or when there are no
dynamic relocs in read-only sections and -z nodynamic-undefined-weak
is not given.
* elf64-ppc.c (allocate_dynrelocs): Likewise.

3 years agoPPC: ensure_undef_dynamic on weak undef only in plt
Alan Modra [Mon, 3 May 2021 00:33:06 +0000 (10:03 +0930)]
PPC: ensure_undef_dynamic on weak undef only in plt

It's slightly weird to have a call to a weak function not protected by
a test of that function being non-NULL, but the non-NULL test might be
covered by a test of another function.  For example:
  if (func1)
    {
      func1 ();
      func2 ();
    }
where func2 is known to exist if func1 exists.

* elf32-ppc.c (allocate_dynrelocs): Call ensure_undef_dynamic for
weak undefined symols that only appear on PLT relocs.
* elf64-ppc.c (allocate_dynrelocs): Likewise.

3 years agoPR27755, powerpc-ld infinite loop
Alan Modra [Mon, 3 May 2021 04:07:00 +0000 (13:37 +0930)]
PR27755, powerpc-ld infinite loop

PR 27755
* elf32-ppc.c (ppc_elf_inline_plt): Do increment rel in loop.

3 years agocsky: fix annobin test fails
Alan Modra [Sun, 2 May 2021 22:27:39 +0000 (07:57 +0930)]
csky: fix annobin test fails

* elf32-csky.c (is_mapping_symbol_name): New function.
(csky_elf_is_target_special_symbol): Likewise.
(csky_elf_maybe_function_sym): Likewise.
(bfd_elf32_bfd_is_target_special_symbol): Define.
(elf_backend_maybe_function_sym): Define.

3 years agotestsuite: Don't start directives in first column
Alan Modra [Sun, 2 May 2021 22:20:03 +0000 (07:50 +0930)]
testsuite: Don't start directives in first column

Fixes fails on hppa64-hp-hpux11.23

* testsuite/gas/elf/section25.s: Don't start directives in first
column.
* testsuite/gas/elf/section26.s: Likewise.

3 years agoRe: section symbols without a name
Alan Modra [Sun, 2 May 2021 22:14:23 +0000 (07:44 +0930)]
Re: section symbols without a name

commit 23356397449 changed this file but missed one place.

* testsuite/ld-s390/tlspic_64.rd: Adjust expected output for
named section symbols.

3 years agoAutomatic date update in version.in
GDB Administrator [Mon, 3 May 2021 00:00:35 +0000 (00:00 +0000)]
Automatic date update in version.in

3 years agosim: add default cases to two switches in sim-options.c
Simon Marchi [Sun, 2 May 2021 15:04:58 +0000 (11:04 -0400)]
sim: add default cases to two switches in sim-options.c

This is the next compilation error I hit when I build all targets with
Clang:

    /home/simark/src/binutils-gdb/sim/aarch64/../common/sim-options.c:234:12: error: no case matching constant switch condition '0' [-Werror]                                                                    switch (WITH_ENVIRONMENT)
                      ^~~~~~~~~~~~~~~~                                                                                                                                                                 ./config.h:215:26: note: expanded from macro 'WITH_ENVIRONMENT'
    #define WITH_ENVIRONMENT ALL_ENVIRONMENT                                                                                                                                                                                    ^~~~~~~~~~~~~~~
    /home/simark/src/binutils-gdb/sim/aarch64/../common/sim-options.c:276:15: error: no case matching constant switch condition '0' [-Werror]                                                                switch (WITH_ALIGNMENT)
                  ^~~~~~~~~~~~~~                                                                                                                                                                       /home/simark/src/binutils-gdb/sim/aarch64/../common/sim-config.h:220:24: note: expanded from macro 'WITH_ALIGNMENT'
    #define WITH_ALIGNMENT 0
                           ^

This is a little bit special because these are switches on compile-time
value.  But regardless, the idea is that we logically can't reach the
switches if WITH_ENVIRONMENT == 0 or WITH_ALIGNMENT == 0, so the code is
correct.

In addition to getting rid of the compiler warning, adding default cases
to these switches ensure that if we do get in an unexpected situation,
it is caught.  In GDB, I'd use gdb_assert_not_reached, I don't know if
there is something similar in sim so I went with abort.

sim/common/ChangeLog:

* sim-options.c (standard_option_handler): Add default cases to
switches.

Change-Id: Ie237d67a201caa6b72de0d17cc815193417156b6

3 years agosim: replace custom attributes with ansidecl.h
Mike Frysinger [Sun, 2 May 2021 04:07:21 +0000 (00:07 -0400)]
sim: replace custom attributes with ansidecl.h

A lot of this code predates the common attributes.  We had already
started migrating over piece by piece, so just do a pass across all
the attributes and replace most of them.

3 years agosim: bfin: move option inits to respective modules
Mike Frysinger [Sat, 2 Jan 2016 15:54:42 +0000 (10:54 -0500)]
sim: bfin: move option inits to respective modules

Now that modules can self declare their own init funcs, change the mmu
and mach logic to use it.  We don't need to export the option symbols
or specifically call this logic from the sim_open function anymore.

3 years agosim: options: fix --help output
Mike Frysinger [Sun, 2 May 2021 03:04:01 +0000 (23:04 -0400)]
sim: options: fix --help output

The hash table rewrite broke --help output due to subtle behavior:
calling dup_arg_p(NULL) will create & clear the table, not just
create it.  The --help output relies on this to clear the table
before it shows things.

3 years agosim: dv-sockser: localize init callback
Mike Frysinger [Sat, 2 Jan 2016 15:53:03 +0000 (10:53 -0500)]
sim: dv-sockser: localize init callback

Now that we don't need to hardcode the module init list in a single
place, move the dv-sockser logic to the place to the one file.

3 years agosim: mips: mark local func static
Mike Frysinger [Sun, 2 May 2021 01:16:17 +0000 (21:16 -0400)]
sim: mips: mark local func static

3 years agosim: add framework for declaring init callbacks locally
Mike Frysinger [Sat, 2 Jan 2016 15:50:46 +0000 (10:50 -0500)]
sim: add framework for declaring init callbacks locally

To facilitate decentralized module initialization/registration with an
eye towards multi-target support, add a framework to detect init calls
declared in the source and automatically call them.  This is akin to
gdb's _initialize_xxx framework for letting modules autodiscover.

3 years agoAutomatic date update in version.in
GDB Administrator [Sun, 2 May 2021 00:00:30 +0000 (00:00 +0000)]
Automatic date update in version.in

3 years agosim: nrun: add local strsignal prototype
Mike Frysinger [Sat, 1 May 2021 20:30:59 +0000 (16:30 -0400)]
sim: nrun: add local strsignal prototype

While libiberty provides a definition for this for systems that lack
the function (e.g. Windows), it doesn't provide a prototype.  So add
our own local copy in the one file that uses the func.

3 years agosim: rx: cast bfd_vma when printing
Mike Frysinger [Sat, 1 May 2021 20:03:10 +0000 (16:03 -0400)]
sim: rx: cast bfd_vma when printing

A bit of a hack, but it's what we've been doing so far when printing
bfd_vma's since bfd doesn't provide PRI helper types for us to use.

3 years agosim: riscv: fix building on 32-bit hosts w/out int128
Mike Frysinger [Sat, 1 May 2021 19:58:09 +0000 (15:58 -0400)]
sim: riscv: fix building on 32-bit hosts w/out int128

Check for __SIZEOF_INT128__ before trying to use the builtin type.
This fixes building on some 32-bit systems like x86.

3 years agosim: aarch64: use PRIx64 for formatting 64-bit types
Mike Frysinger [Sat, 1 May 2021 19:54:33 +0000 (15:54 -0400)]
sim: aarch64: use PRIx64 for formatting 64-bit types

We can't assume that %lx is big enough for 64-bit types as it isn't on
most 32-bit builds.  Use the standard format define for this instead.

3 years agosim: aarch64: fix 64-bit immediate shifts
Mike Frysinger [Sat, 1 May 2021 19:51:37 +0000 (15:51 -0400)]
sim: aarch64: fix 64-bit immediate shifts

Trying to shift immediates 63 bits fails on 32-bit systems since UL
is only 32-bits, not 64-bits.  Switch to ULL to guarantee at least
64-bits here.

3 years agosim: arm: move build logic to source files
Mike Frysinger [Sat, 24 Apr 2021 16:51:46 +0000 (12:51 -0400)]
sim: arm: move build logic to source files

This simplifies the build logic a bit by just having source file
inputs.  It also simplifies code that assumes there's a source
file for each object.

3 years agosim: callback: inline wrap helper
Mike Frysinger [Sat, 24 Apr 2021 18:28:17 +0000 (14:28 -0400)]
sim: callback: inline wrap helper

This is annoying as it requires inlining boiler plate, but we don't
have much choice: the wrap helper assumes the return value is always
an int, but that's already not the case with some of the callbacks
which use long.  GCC has extensions to define macros-as-functions,
but we can't assume GCC.

3 years agoopcodes: xtensa: support branch visualization
Max Filippov [Sat, 1 May 2021 09:22:19 +0000 (02:22 -0700)]
opcodes: xtensa: support branch visualization

2021-05-01  Max Filippov  <jcmvbkbc@gmail.com>
opcodes/
* xtensa-dis.c (print_insn_xtensa): Fill in info->insn_type and
info->insn_info_valid.

3 years agoAutomatic date update in version.in
GDB Administrator [Sat, 1 May 2021 00:00:31 +0000 (00:00 +0000)]
Automatic date update in version.in

3 years agoDo not separately read type units
Tom Tromey [Fri, 30 Apr 2021 20:07:58 +0000 (14:07 -0600)]
Do not separately read type units

Currently, the DWARF reader has a separate pass to read type units --
create_all_type_units.  While working on other patches, I discovered
that this caused DWARF 5 type units to be read twice, once by
create_all_comp_units and once by create_all_type_units.

There's no need any more (if there ever was) to treat type units
differently from CUs.  So, this patch removes create_all_type_units
and unifies the code paths.

Note that the DWO code still has a second pass.  I haven't looked into
this code yet; perhaps it can also be simplified.

Regression tested using the debug-types board file on x86-64 Fedora 32.

gdb/ChangeLog
2021-04-30  Tom Tromey  <tom@tromey.com>

* dwarf2/read.c (dwarf2_initialize_objfile): Update.
(add_signatured_type_cu_to_table): Remove.
(create_debug_type_hash_table): Assume dwo_file is non-null.
(create_debug_types_hash_table): Update comment.
(create_all_type_units): Remove.
(sort_tu_by_abbrev_offset): Update comment.
(build_type_psymtabs): Rename from build_type_psymtabs_1.
(build_type_psymtabs): Remove.
(process_skeletonless_type_unit, dwarf2_build_psymtabs_hard):
Update.
(read_comp_units_from_section): Add types_htab, section_kind
parameters.
(create_all_comp_units): Read type units.

3 years agoRemove dwarf2_per_bfd::all_type_units
Tom Tromey [Fri, 30 Apr 2021 20:07:58 +0000 (14:07 -0600)]
Remove dwarf2_per_bfd::all_type_units

I don't think there is any deep reason to separate CUs and TUs in
dwarf2_per_bfd.  This patch removes all_type_units and unifies these
two containers.  Some minor tweaks are needed to the index writers,
because both forms of index keep CUs and TUs separate;

Regression tested on x86-63 Fedora 32.

gdb/ChangeLog
2021-04-30  Tom Tromey  <tom@tromey.com>

* dwarf2/read.h (struct tu_stats) <nr_tus>: New member.
(struct dwarf2_per_bfd) <get_cutu, get_tu>: Remove
<get_cu>: Now inline.
<all_type_units>: Remove.
* dwarf2/read.c (dwarf2_per_bfd::~dwarf2_per_bfd): Update.
(dwarf2_per_bfd::get_cutu, dwarf2_per_bfd::get_cu)
(dwarf2_per_bfd::get_tu): Remove.
(dwarf2_per_bfd::allocate_signatured_type): Update nr_tus.
(create_signatured_type_table_from_index)
(create_signatured_type_table_from_debug_names)
(dw2_symtab_iter_next, dwarf2_base_index_functions::print_stats)
(dwarf2_base_index_functions::expand_all_symtabs)
(dw2_expand_marked_cus, dw_expand_symtabs_matching_file_matcher)
(dwarf2_base_index_functions::map_symbol_filenames)
(dw2_debug_names_iterator::next, dwarf2_initialize_objfile)
(add_signatured_type_cu_to_table, create_all_type_units)
(add_type_unit, build_type_psymtabs_1, print_tu_stats)
(create_all_comp_units): Update.
* dwarf2/index-write.c (check_dwarf64_offsets, write_gdbindex)
(write_debug_names): Update.

3 years agoAllocate dwarf2_per_cu_data with 'new'
Tom Tromey [Fri, 30 Apr 2021 20:07:58 +0000 (14:07 -0600)]
Allocate dwarf2_per_cu_data with 'new'

In a patch series I am working on, I'd like to have a non-POD member
in dwarf2_per_cu_data.  This currently can't be done because
dwarf2_per_cu_data is allocated on an obstack and initialized with
memset.

This patch changes the DWARF reader to allocate objects of this type
with 'new'.  The various "subclasses" of this type (signatured_type in
particular) are now changed to derive from dwarf2_per_cu_data, and
also use 'new' for allocation.

Regression tested on x86-64 Fedora 32.

gdb/ChangeLog
2021-04-30  Tom Tromey  <tom@tromey.com>

* dwarf2/read.h (struct dwarf2_per_bfd) <allocate_per_cu,
allocate_signatured_type>: Change return type.
<all_comp_units, all_type_units>: Hold unique pointers.
(struct dwarf2_per_cu_data): Add constructor and initializers.
(struct signatured_type): Derive from dwarf2_per_cu_data.
* dwarf2/read.c (type_unit_group): Derive from
dwarf2_per_cu_data.
(dwarf2_per_bfd::get_cutu, dwarf2_per_bfd::get_cu)
(dwarf2_per_bfd::get_tu)
(dwarf2_per_bfd::allocate_signatured_type)
(dwarf2_per_bfd::allocate_signatured_type)
(create_cu_from_index_list, create_cus_from_index_list)
(create_signatured_type_table_from_index)
(create_signatured_type_table_from_debug_names)
(create_addrmap_from_aranges)
(dwarf2_base_index_functions::find_last_source_symtab)
(dw_expand_symtabs_matching_file_matcher)
(dwarf2_gdb_index::expand_symtabs_matching)
(dwarf2_base_index_functions::map_symbol_filenames)
(create_cus_from_debug_names_list)
(dw2_debug_names_iterator::next)
(dwarf2_debug_names_index::expand_symtabs_matching)
(create_debug_type_hash_table, add_type_unit)
(fill_in_sig_entry_from_dwo_entry, lookup_dwo_signatured_type):
Update.
(allocate_type_unit_groups_table): Use delete.
(create_type_unit_group): Change return type.  Use new.
(get_type_unit_group, build_type_psymtabs_1)
(build_type_psymtab_dependencies)
(process_skeletonless_type_unit, set_partial_user)
(dwarf2_build_psymtabs_hard, read_comp_units_from_section)
(create_cus_hash_table, queue_and_load_dwo_tu, follow_die_sig_1)
(read_signatured_type): Update.
(dwarf2_find_containing_comp_unit): Change type of
'all_comp_units'.
(run_test): Update.
(dwarf2_per_bfd::allocate_per_cu)
(dwarf2_per_bfd::allocate_signatured_type): Change return type.
Use new.
(add_signatured_type_cu_to_table): Update.
* dwarf2/index-write.c (write_one_signatured_type)
(check_dwarf64_offsets, psyms_seen_size, write_gdbindex)
(write_debug_names): Update.

3 years agoMake get_image_name static
Tom Tromey [Fri, 30 Apr 2021 16:22:23 +0000 (10:22 -0600)]
Make get_image_name static

The only callers of get_image_name are nat/windows-nat.c, so make it
static.

gdb/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

* nat/windows-nat.h (get_image_name): Don't declare.
* nat/windows-nat.c (get_image_name): Now static.

3 years agoShare DLL code between gdb and gdbserver
Tom Tromey [Fri, 30 Apr 2021 16:22:23 +0000 (10:22 -0600)]
Share DLL code between gdb and gdbserver

This moves the new DLL-loading code into nat/windows-nat.c, and
changes both gdb and gdbserver to use the shared code.  One
client-provided callback, handle_load_dll, is changed to allow the
code to be shared.  This callback was actually never called from
nat/windows-nat.c; maybe I had planned to share more here and then
didn't finish... I'm not sure.

gdb/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

* windows-nat.c (windows_nat::handle_load_dll): Update.
(windows_nat_target::get_windows_debug_event): Call
dll_loaded_event.
(windows_add_all_dlls, windows_add_dll): Move to
nat/windows-nat.c.
* nat/windows-nat.h (handle_load_dll): Change parameters.
(dll_loaded_event, windows_add_all_dlls): Declare.
* nat/windows-nat.c (windows_add_dll, windows_add_all_dlls): Move
from windows-nat.c.
(dll_loaded_event): New function.

gdbserver/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

* win32-low.cc (do_initial_child_stuff): Update.
(windows_nat::handle_load_dll): Rename from win32_add_one_solib.
Change parameter type.
(win32_add_dll, win32_add_all_dlls)
(windows_nat::handle_load_dll): Remove.
(get_child_debug_event): Call dll_loaded_event.

3 years agoUse nat/windows-nat function indirection code
Tom Tromey [Fri, 30 Apr 2021 16:22:23 +0000 (10:22 -0600)]
Use nat/windows-nat function indirection code

This changes gdbserver to use the function indirection code that was
just moved into nat/windows-nat.[ch].  One additional function is used
by gdbserver that was not used by gdb.

gdb/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

* nat/windows-nat.h (GenerateConsoleCtrlEvent): New define.
(GenerateConsoleCtrlEvent_ftype, GenerateConsoleCtrlEvent):
Declare.
* nat/windows-nat.c (GenerateConsoleCtrlEvent): Define.
(initialize_loadable): Initialize GenerateConsoleCtrlEvent.

gdbserver/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

* win32-low.cc (GETPROCADDRESS): Remove.
(winapi_DebugActiveProcessStop, winapi_DebugSetProcessKillOnExit)
(winapi_DebugBreakProcess, winapi_GenerateConsoleCtrlEvent)
(winapi_Wow64SetThreadContext, win32_Wow64GetThreadContext)
(win32_Wow64SetThreadContext): Remove.
(win32_set_thread_context, do_initial_child_stuff)
(win32_process_target::attach, win32_process_target::detach):
Update.
(winapi_EnumProcessModules, winapi_EnumProcessModulesEx)
(winapi_GetModuleInformation, winapi_GetModuleInformationA):
Remove.
(win32_EnumProcessModules, win32_EnumProcessModulesEx)
(win32_GetModuleInformation, win32_GetModuleInformationA):
Remove.
(load_psapi): Remove.
(win32_add_dll, win32_process_target::request_interrupt): Update.
(initialize_low): Call initialize_loadable.

3 years agoMove function indirection code to nat/windows-nat
Tom Tromey [Fri, 30 Apr 2021 16:22:23 +0000 (10:22 -0600)]
Move function indirection code to nat/windows-nat

gdb and gdbserver both look for functions in some Windows DLLs at
runtime.  This patch moves this code out of gdb and into
nat/windows-nat, so it can be shared by both programs.

gdb/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

* windows-nat.c: Move code to nat/windows-nat.[ch].
(_initialize_windows_nat): Call initialize_loadable.
* nat/windows-nat.h (AdjustTokenPrivileges)
(DebugActiveProcessStop, DebugBreakProcess)
(DebugSetProcessKillOnExit, EnumProcessModules)
(EnumProcessModulesEx, GetModuleInformation)
(GetModuleFileNameExA, GetModuleFileNameExW)
(LookupPrivilegeValueA, OpenProcessToken, GetConsoleFontSize)
(GetCurrentConsoleFont, Wow64SuspendThread)
(Wow64GetThreadContext, Wow64SetThreadContext)
(Wow64GetThreadSelectorEntry): Move from windows-nat.c.
(AdjustTokenPrivileges_ftype)
(DebugActiveProcessStop_ftype, DebugBreakProcess_ftype)
(DebugSetProcessKillOnExit_ftype, EnumProcessModules_ftype)
(EnumProcessModulesEx_ftype, GetModuleInformation_ftype)
(GetModuleFileNameExA_ftype, GetModuleFileNameExW_ftype)
(LookupPrivilegeValueA_ftype, OpenProcessToken_ftype)
(GetConsoleFontSize_ftype)
(GetCurrentConsoleFont_ftype, Wow64SuspendThread_ftype)
(Wow64GetThreadContext_ftype, Wow64SetThreadContext_ftype)
(Wow64GetThreadSelectorEntry_ftype): Likewise.
(initialize_loadable): Declare.
* nat/windows-nat.c (AdjustTokenPrivileges)
(DebugActiveProcessStop, DebugBreakProcess)
(DebugSetProcessKillOnExit, EnumProcessModules)
(EnumProcessModulesEx, GetModuleInformation, GetModuleFileNameExA)
(GetModuleFileNameExW, LookupPrivilegeValueA, OpenProcessToken)
(GetCurrentConsoleFont, GetConsoleFontSize, Wow64SuspendThread)
(Wow64GetThreadContext, Wow64SetThreadContext)
(Wow64GetThreadSelectorEntry): Define.
(bad, bad_GetCurrentConsoleFont, bad_GetConsoleFontSize): Move
from windows-nat.c.
(initialize_loadable): Likewise, and rename.

3 years agoUse template functions in windows-nat.c
Tom Tromey [Fri, 30 Apr 2021 16:22:23 +0000 (10:22 -0600)]
Use template functions in windows-nat.c

windows-nat.c defines a number of replacement functions that simply
return zero.  This patch removes these in favor of a couple of
template functions.

gdb/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

* windows-nat.c (bad_GetModuleFileNameEx): Remove define.
(bad_DebugActiveProcessStop, bad_DebugBreakProcess)
(bad_DebugSetProcessKillOnExit, bad_EnumProcessModules)
(bad_GetModuleFileNameExW, bad_GetModuleFileNameExA)
(bad_GetModuleInformation, bad_OpenProcessToken): Remove.
(bad): New template functions.
(_initialize_loadable): Update.

3 years agoUse rvalue reference in thread_pool::post_task
Tom Tromey [Fri, 30 Apr 2021 16:04:56 +0000 (10:04 -0600)]
Use rvalue reference in thread_pool::post_task

Tankut's recent patches made me realize that thread_pool::post_task
should have used an rvalue reference for its parameter.  This patch
makes this change.

gdbsupport/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

* thread-pool.cc (thread_pool::post_task): Update.
* thread-pool.h (class thread_pool) <post_task>: Take rvalue
reference to function.

3 years agoFix crash with GNAT minimal encodings
Tom Tromey [Thu, 15 Apr 2021 14:54:06 +0000 (08:54 -0600)]
Fix crash with GNAT minimal encodings

Running the AdaCore internal test suite with -fgnat-encodings=minimal
found a gdb crash.  The bug is that GDB ends up with a typedef in
ada_index_type, resulting in a NULL dereference.

This crash can be reproduced using GCC 11 with the included test case.

Tested on x86-64 Fedora 32.  Because this is Ada-specific, and was
already reviewed by Joel, I am going to check it in.

2021-04-30  Tom Tromey  <tromey@adacore.com>

* ada-lang.c (ada_index_type): Use ada_check_typedef.

gdb/testsuite/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

* gdb.ada/enum_idx_packed/pck.ads (My_Enum, My_Array_Type)
(Confused_Array): New types.
* gdb.ada/enum_idx_packed/foo.adb (Confused_Array): New variable.
* gdb.ada/enum_idx_packed.exp: Add new tests.

3 years agoFix illegal memory access parsing a corrupt MACH-O format file.
Nick Clifton [Fri, 30 Apr 2021 13:31:03 +0000 (14:31 +0100)]
Fix illegal memory access parsing a corrupt MACH-O format file.

PR 27801
* mach-o.c (bfd_mach_o_core_fetch_environment): Use bfd_get_32 to
read 32-bit value.

3 years agoFix an illegal memory access when parsing a corrupt core note.
Nick Clifton [Fri, 30 Apr 2021 13:19:24 +0000 (14:19 +0100)]
Fix an illegal memory access when parsing a corrupt core note.

PR 27799
* elf32-xtensa.c (elf_xtensa_grok_prstatus): Check for core notes
that are too small.

3 years agoFix a double free when re-allocating a buffer to size 0.
Nick Clifton [Fri, 30 Apr 2021 13:04:08 +0000 (14:04 +0100)]
Fix a double free when re-allocating a buffer to size 0.

PR 27797
* libbfd.c (bfd_realloc_or_free): Do not free a pointer than has
been realloc'ed to size 0.

3 years agoFix attempt to free non-allocated pointer when parsing .debug_sup sections.
Nick Clifton [Fri, 30 Apr 2021 11:28:39 +0000 (12:28 +0100)]
Fix attempt to free non-allocated pointer when parsing .debug_sup sections.

PR 27796
* dwarf.c (load_debug_sup_file): Allocate memory for filename in
.debug_sup section.

3 years agoFix illegal memory access when parsing a corrupt PE format file.
Nick Clifton [Fri, 30 Apr 2021 11:11:35 +0000 (12:11 +0100)]
Fix illegal memory access when parsing a corrupt PE format file.

PR 27795
* coff-rs6000.c (_bfd_xcoff_read_ar_hdr): Check for invalid name
lengths.

3 years ago[gdb/testsuite] Make gdb.mi/mi-sym-info.exp more robust against timeouts
Tom de Vries [Fri, 30 Apr 2021 09:25:47 +0000 (11:25 +0200)]
[gdb/testsuite] Make gdb.mi/mi-sym-info.exp more robust against timeouts

Once in a while, I run into this timeout:
...
FAIL: gdb.mi/mi-sym-info.exp: List all variables from debug information \
  only (timeout)
...

I can make the timeout reproducible by setting timeout to 8s (instead of the
default 10s) for the duration of that test.

Make the test-case more stable by fixing all timeouts caused by setting
timeout to 5, either by adding with_timeout_factor, or increasing its factor.

Tested on x86_64-linux.  Also tested in parallel with stress -c 5, to simulate
a busy system in another way.

gdb/testsuite/ChangeLog:

2021-04-30  Tom de Vries  <tdevries@suse.de>

* gdb.mi/mi-sym-info.exp: Add with_timeout_factor, and increase
existing timeout factors.

3 years ago[gdb/testsuite] Fix duplicate test name in gdb.mi/mi-sym-info.exp
Tom de Vries [Fri, 30 Apr 2021 09:25:47 +0000 (11:25 +0200)]
[gdb/testsuite] Fix duplicate test name in gdb.mi/mi-sym-info.exp

Since commit 2d61316c32a "[gdb/testsuite] Fix buffer full errors in
gdb.mi/mi-sym-info.exp", we have a duplicate test name:
...
Running src/gdb/testsuite/gdb.mi/mi-sym-info.exp ...
DUPLICATE: gdb.mi/mi-sym-info.exp: List all variables
...

This is caused by a copy-paste accident: the idea was to copy the test, edit
it, and then remove the old test, but I forgot to remove the old one.
Remove it now.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2021-04-30  Tom de Vries  <tdevries@suse.de>

* gdb.mi/mi-sym-info.exp: Remove duplicate test.

3 years agoAutomatic date update in version.in
GDB Administrator [Fri, 30 Apr 2021 00:00:29 +0000 (00:00 +0000)]
Automatic date update in version.in

3 years ago[gdb/testsuite] Fix timeout in gdb.base/valgrind-infcall-2.exp
Tom de Vries [Thu, 29 Apr 2021 21:32:20 +0000 (23:32 +0200)]
[gdb/testsuite] Fix timeout in gdb.base/valgrind-infcall-2.exp

Since commit 6d5702a5eb3 "Fix test case gdb.base/valgrind-bt.exp" I run into:
...
FAIL: gdb.base/valgrind-infcall-2.exp: target remote for vgdb (timeout)
FAIL: gdb.base/valgrind-infcall-2.exp: monitor v.set gdb_output (timeout)
...

The commit adds this line in proc vgdb_start:
...
    set vgdbcmd "set remotetimeout 3"
...
which has no effect given that the value of var vgdbcmd is not used before
it's overwritten.  We can fix this by doing instead:
...
    set_remotetimeout 3
...

The FAIL I'm observing is fixed by increasing the remotetimeout value to 4.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2021-04-29  Tom de Vries  <tdevries@suse.de>

PR testsuite/27786
* lib/valgrind.exp (vgdb_start): Use set_remotetimeout.  Increase
remotetimeout to 4.

3 years agogdb: don't use C++17 namespace declaration style
Simon Marchi [Thu, 29 Apr 2021 20:24:19 +0000 (16:24 -0400)]
gdb: don't use C++17 namespace declaration style

In a review, I suggested to use "namespace gdb::observers" instead of
two separate namespace declarations.  I didn't realize that this was a
C++17 feature, which breaks compilers that default to an earlier version
of the language, like g++ 4.8.  Change it back to two separate
declarations.

gdb/ChangeLog:

* auto-load.h: Split namespace declaration.

Change-Id: I701537161967fbd9fcc298ff600bd072aab1251d

3 years agoFix an access through a null pointer when parsing a corrupt SOM format fle.
Nick Clifton [Thu, 29 Apr 2021 16:55:43 +0000 (17:55 +0100)]
Fix an access through a null pointer when parsing a corrupt SOM format fle.

PR 27793
* som.c (som_slurp_symbol_table): Assign symbols without any scope
to the undefined section.
(som_decode_symclass): Check for a missing symbol section.
* syms.c (bfd_decode_symclass): Likewise.

3 years agoFix illegal memory accesses when parsing a corrupt SOM format file.
Nick Clifton [Thu, 29 Apr 2021 16:41:43 +0000 (17:41 +0100)]
Fix illegal memory accesses when parsing a corrupt SOM format file.

PR 27792
* som.c (som_slurp_string_table): Place a terminating NUL byte at
the end of the table.
(som_slurp_symbol_table): Check for an over-large offset into the
string string table.

3 years agogdb: move some variables to an inner scope in save_waitstatus
Simon Marchi [Thu, 29 Apr 2021 14:16:28 +0000 (10:16 -0400)]
gdb: move some variables to an inner scope in save_waitstatus

These two variables:

      struct regcache *regcache = get_thread_regcache (tp);
      const address_space *aspace = regcache->aspace ();

are only needed inside the "if".  Getting a thread's regcache is a
somewhat expensive operation, so it's good to avoid it if not necessary.
Move the variable declarations and their initialization to the "if"
scope.

gdb/ChangeLog:

* infrun.c (save_waitstatus): Move variables to inner scope.

Change-Id: Ief1463728755b4dcc142c0a0a76896e9d594ae84