binutils-gdb.git
9 months agoMove rust_language::lookup_symbol_nonlocal
Tom Tromey [Fri, 4 Aug 2023 20:00:33 +0000 (14:00 -0600)]
Move rust_language::lookup_symbol_nonlocal

This moves rust_language::lookup_symbol_nonlocal to rust-lang.c.
There's no need to have it in rust-lang.h and moving it lets us avoid
adding new includes in a later patch.

9 months agogdb/riscv: Fix oob memory access when printing info registers
Ciaran Woodward [Fri, 1 Sep 2023 11:13:55 +0000 (12:13 +0100)]
gdb/riscv: Fix oob memory access when printing info registers

If the length of a register name was greater than 15,
print_spaces was called with a negative number, which
prints random data from the heap instead of the requested
number of spaces.

This could happen if a target-description file was used
to specify additional long-named registers.

Fix is simple - don't ask for fewer than 1 space (since
we still want column separation).

Approved-by: Kevin Buettner <kevinb@redhat.com>
9 months agoRead Ada main name from executable, not inferior
Tom Tromey [Mon, 21 Aug 2023 15:55:14 +0000 (09:55 -0600)]
Read Ada main name from executable, not inferior

An upstream bug report points out this bug: if the user switches from
one Ada executable to another without "kill"ing the inferior, then the
"start" command will fail.

What happens here is that the Ada "main" name is found in a constant
string in the executable.  But, if the inferior is running, then the
process_stratum target reads from the inferior memory.

This patch fixes the problem by changing the main name code to set
trust-readonly-sections, causing the target stack to read from the
executable instead.

I looked briefly at changing GNAT to emit DW_AT_main_subprogram
instead, but this looks to be pretty involved.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25811

9 months agoAvoid crash with Ada and -fdata-sections
Tom Tromey [Thu, 17 Aug 2023 14:08:42 +0000 (08:08 -0600)]
Avoid crash with Ada and -fdata-sections

A user noticed that gdb would crash when showing a backtrace.
Investigation showed this to be a crash in the DWARF reader when
handling a "pragma export" symbol.  The bug here is that earlier code
decides to eliminate the symbol, but the export code tries to add it
anyway -- but to a NULL list.

9 months agoreadelf: Add option to display the names of sections referenced by symbols.
Nick Clifton [Tue, 5 Sep 2023 10:08:23 +0000 (11:08 +0100)]
readelf: Add option to display the names of sections referenced by symbols.

  PR 30684
  * readelf.c (extra_sym_info): New variable. (section_name_valid): Also check for filedata being NULL. (section_name_print): Delete. (section_index_real): New function.  Returns true if the given section index references a real section. (print_symbol): Rename to print_sumbol_name. (printable_section_name): Use a rotating array of static buffers for the return string. (printable_section_name_from_index): Merge code from dump_relocations and get_symbol_index_type into here. (long_option_values): Add OPTION_NO_EXTRA_SYM_INFO. (options): Add "extra-sym-info" and "no-extra-sym-info". (usage): Mention new options. (parse_args): Parse new options. (get_symbol_index_type): Delete. (print_dynamic_symbol_size): Rename to print_symbol_size. (print_dynamic_symbol): Rename to print_symbol. (print_symbol_table_heading): New function. (process_symbol_table): Use new function.
  * doc/binutils.texi: Document the new option.
  * NEWS: Mention the new feature.

9 months agoRISC-V: fold duplicate code in vector_macro()
Jan Beulich [Tue, 5 Sep 2023 08:03:35 +0000 (10:03 +0200)]
RISC-V: fold duplicate code in vector_macro()

There's no need to have almost identical code twice. Do away with
M_VMSGEU and instead simply use an unused (for these macros) field to
tell apart both variants.

9 months agoRISC-V: Add stub support for the 'Svadu' extension
Tsukasa OI [Mon, 24 Oct 2022 15:05:58 +0000 (15:05 +0000)]
RISC-V: Add stub support for the 'Svadu' extension

This commit implements support for 'Svadu' extension.  Because it does not
add any instructions or CSRs (but adds bits to existing CSRs), this commit
only adds extension name support and implication to the 'Zicsr' extension.

This is based on the "Hardware Updating of PTE A/D Bits (Svadu)"
specification, version 1.0-rc1 (Frozen):
<https://github.com/riscv/riscv-svadu/releases/tag/v1.0-rc1>

bfd/ChangeLog:

* elfxx-riscv.c (riscv_implicit_subsets): Add implication from
'Svadu' to 'Zicsr'.  (riscv_supported_std_s_ext) Add 'Svadu'.

9 months agoRISC-V: Fix typo in the testsuite
Tsukasa OI [Tue, 5 Sep 2023 03:59:02 +0000 (03:59 +0000)]
RISC-V: Fix typo in the testsuite

gas/ChangeLog:

* testsuite/gas/riscv/csr.s: Fix typo. mhcounteren is superseded
by minstretcfg, not mcyclecfg.

9 months agoRISC-V: Add 'Smcntrpmf' extension and its CSRs
Tsukasa OI [Sun, 3 Sep 2023 02:13:14 +0000 (02:13 +0000)]
RISC-V: Add 'Smcntrpmf' extension and its CSRs

This commit adds now stable and approved 'Smcntrpmf' extension defined by
the RISC-V Cycle and Instret Privilege Mode Filtering specification.

Note that, because mcyclecfg and minstretcfg CSRs conflict with the
privileged specification version 1.9.1, CSRs for this extension are only
enabled on the privileged specification version 1.10 or later.

By checking the base privileged specification, we no longer need to change
the design of base CSR handling.

This is based on the specification version v1.0_rc1 (Frozen):
<https://github.com/riscv/riscv-smcntrpmf/commit/32b752c40d59c1b5e95de83399c1f54be6669163>

bfd/ChangeLog:

* elfxx-riscv.c (riscv_implicit_subsets): Add implication rule from
the new 'Smcntrpmf' extension.  (riscv_supported_std_s_ext): Add
'Smcntrpmf' to the supported S extension list.

gas/ChangeLog:

* config/tc-riscv.c (enum riscv_csr_class): Add new CSR classes
CSR_CLASS_SMCNTRPMF and CSR_CLASS_SMCNTRPMF_32.
(riscv_csr_address): Add handling for new CSR classes.
* testsuite/gas/riscv/csr-dw-regnums.s: Add new CSRs.  Move
"mscounteren" and "mhcounteren" CSRs and note that they are now
aliases.
* testsuite/gas/riscv/csr-dw-regnums.d: Reflect the change.
* testsuite/gas/riscv/csr.s: Add new CSRs.  Move "mscounteren"
and "mhcounteren" CSRs and note that they are now reused for
the 'Smcntrpmf' extension.
* testsuite/gas/riscv/csr-version-1p9p1.d: Reflect the changes of
csr.s.
* testsuite/gas/riscv/csr-version-1p9p1.l: Likewise.
* testsuite/gas/riscv/csr-version-1p10.d: Likewise.
* testsuite/gas/riscv/csr-version-1p10.l: Likewise.
* testsuite/gas/riscv/csr-version-1p11.d: Likewise.
* testsuite/gas/riscv/csr-version-1p11.l: Likewise.
* testsuite/gas/riscv/csr-version-1p12.d: Likewise.
* testsuite/gas/riscv/csr-version-1p12.l: Likewise.

include/ChangeLog:

* opcode/riscv-opc.h: Add new CSRs noting that this extension is
incompatible with the privileged specification version 1.9.1.
Move "mscounteren" and "mhcounteren" CSRs, make them aliases and
reuse the CSR numbers from the 'Smcntrpmf' extension.
(CSR_MSCOUNTEREN, CSR_MHCOUNTEREN) Remove as "mscounteren" and
"mhcounteren" are now aliases and new CSR macros are used instead.
(CSR_MCYCLECFG, CSR_MINSTRETCFG, CSR_MCYCLECFGH, CSR_MINSTRETCFGH):
New CSR macros.

9 months agoRISC-V: Prohibit combination of 'E' and 'H'
Tsukasa OI [Tue, 8 Aug 2023 04:06:32 +0000 (04:06 +0000)]
RISC-V: Prohibit combination of 'E' and 'H'

According to the ratified privileged specification (version 20211203),
it says:

> The hypervisor extension depends on an "I" base integer ISA with 32 x
> registers (RV32I or RV64I), not RV32E, which has only 16 x registers.

Also in the latest draft, it also prohibits RV64E with the 'H' extension.
This commit prohibits the combination of 'E' and 'H' extensions.

bfd/ChangeLog:

* elfxx-riscv.c (riscv_parse_check_conflicts): Prohibit 'E' and
'H' combinations.

gas/ChangeLog:

* testsuite/gas/riscv/march-fail-rv32eh.d: New failure test to
make sure that RV32E + 'H' is prohibited.
* testsuite/gas/riscv/march-fail-rv32eh.l: Likewise.

9 months agoAutomatic date update in version.in
GDB Administrator [Tue, 5 Sep 2023 00:00:39 +0000 (00:00 +0000)]
Automatic date update in version.in

9 months agoarm: Make 'conflicting CPU architectures' error message more user-friendly
Christophe Lyon [Fri, 1 Sep 2023 13:52:49 +0000 (13:52 +0000)]
arm: Make 'conflicting CPU architectures' error message more user-friendly

Error messages such as "conflicting CPU architectures 10/16" are not
very to understand, so this patch replaces the numbers with the
description they actually mean:
"conflicting CPU architectures ARM v7E-M vs Pre v4"

2023-09-01  Christophe Lyon  <christophe.lyon@linaro.org>

bfd/
* elf32-arm.c (tag_cpu_arch_combine): Add name_table parameter and
use it.
(elf32_arm_merge_eabi_attributes): Update call to
tag_cpu_arch_combine.

ld/
* testsuite/ld-arm/attr-merge-9.out: Update expected error
message.
* testsuite/ld-arm/attr-merge-arch-2.d: Likewise.

9 months ago[gdb/testsuite] Fix race in gdb.base/add-symbol-file-attach.exp
Tom de Vries [Mon, 4 Sep 2023 11:54:36 +0000 (13:54 +0200)]
[gdb/testsuite] Fix race in gdb.base/add-symbol-file-attach.exp

When running test-case gdb.base/add-symbol-file-attach.exp with target board
unix/-m32, we run into:
...
(gdb) attach 3955^M
Attaching to process 3955^M
Load new symbol table from "add-symbol-file-attach"? (y or n) y^M
Reading symbols from add-symbol-file-attach/add-symbol-file-attach...^M
Reading symbols from /lib/libm.so.6...^M
Reading symbols from /usr/lib/debug/lib/libm-2.31.so-i386.debug...^M
Reading symbols from /lib/libc.so.6...^M
Reading symbols from /usr/lib/debug/lib/libc-2.31.so-i386.debug...^M
Reading symbols from /lib/ld-linux.so.2...^M
Reading symbols from /usr/lib/debug/lib/ld-2.31.so-i386.debug...^M
0xf7f53549 in __kernel_vsyscall ()^M
(gdb) FAIL: gdb.base/add-symbol-file-attach.exp: attach
...

The test fails because this regexp is used:
...
    -re ".*in \[_A-Za-z0-9\]*pause.*$gdb_prompt $" {
...

The regexp attempts to detect that the exec is somewhere in pause ():
...
int
main (int argc, char **argv)
{
  pause ();
  return 0;
}
...
but when the exec is blocked in pause, the backtrace is:
...
 (gdb) bt
 #0  0xf7fd2549 in __kernel_vsyscall ()
 #1  0xf7d84966 in __libc_pause () at ../sysdeps/unix/sysv/linux/pause.c:29
 #2  0x0804844c in main (argc=1, argv=0xffffce84)
     at /data/vries/gdb/src/gdb/testsuite/gdb.base/add-symbol-file-attach.c:26
...

We could simply extend the regexp to also match __kernel_vsyscall, but the
more fundamental problem is that the test is racy.

The attach can happen before the exec is blocked in pause (), somewhere in the
dynamic linker resolving the call to pause, in main or even earlier.

Note that for the test-case to be effective, the exec is not required to be in
pause ().  I added a "while (1);" loop at the start of main, reverted the
patch fixing the corresponding PR and reproduced the problem it's supposed to
detect.

Fix this by simply matching the "Reading symbols from" line, similar to what
an earlier test is doing.

While we're at it, rewrite the earlier test to also use the -wrap idiom.

Tested on x86_64-linux.

9 months agoAutomatic date update in version.in
GDB Administrator [Mon, 4 Sep 2023 00:00:24 +0000 (00:00 +0000)]
Automatic date update in version.in

9 months agoAutomatic date update in version.in
GDB Administrator [Sun, 3 Sep 2023 00:00:22 +0000 (00:00 +0000)]
Automatic date update in version.in

9 months agogdbserver: i387_cache_to_xsave: fix copy dest of zmm registers
Simon Marchi [Fri, 1 Sep 2023 18:12:07 +0000 (14:12 -0400)]
gdbserver: i387_cache_to_xsave: fix copy dest of zmm registers

On a machine with AVX512 support (AMD EPYC 9634), I see these failures:

    $ make check TESTS="gdb.arch/i386-avx512.exp" RUNTESTFLAGS="--target_board=native-gdbserver"
    ...
    FAIL: gdb.arch/i386-avx512.exp: check contents of zmm_data[16] after writing ZMM regs
    FAIL: gdb.arch/i386-avx512.exp: check contents of zmm_data[17] after writing ZMM regs
    FAIL: gdb.arch/i386-avx512.exp: check contents of zmm_data[18] after writing ZMM regs
    ...

The problem can be reduced to:

    (gdb) print $zmm16.v8_int64
    $1 = {0, 0, 0, 0, 0, 0, 0, 0}
    (gdb) print $zmm16.v8_int64 = {11,22,33,44,55,66,77,88}
    $2 = {11, 22, 33, 44, 55, 66, 77, 88}
    (gdb) print $zmm16.v8_int64
    $3 = {11, 22, 33, 44, 55, 66, 77, 88}
    (gdb) step
    5               ++x;
    (gdb) print $zmm16.v8_int64
    $4 = {11, 22, 77, 88, 0, 0, 0, 0}

Writing to the local regcache in GDB works fine, but the writeback to
gdbserver (which happens when resuming / stepping) doesn't work (the
code being stepped doesn't touch AVX registers, so we don't expect the
value of zmm16 to change when stepping).

The problem is on the gdbserver side, the zmmh and ymmh portions of the
zmm register are not memcpied at the right place in the xsave buffer.  Fix
that.  Note now how the two modified memcpy calls match the memcmp calls
just above them.

With this patch, gdb.arch/i386-avx512.exp passes completely for me.

Change-Id: I22c417e0f5e88d4bc635a0f08f8817a031c76433
Reviewed-by: John Baldwin <jhb@FreeBSD.org>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30818

9 months agoAutomatic date update in version.in
GDB Administrator [Sat, 2 Sep 2023 00:00:38 +0000 (00:00 +0000)]
Automatic date update in version.in

9 months agoconfig: Fix host -rdynamic detection for build != host != target
Joseph Myers [Fri, 1 Sep 2023 15:20:47 +0000 (15:20 +0000)]
config: Fix host -rdynamic detection for build != host != target

[Merge from GCC commit 4d9bc81a5d8d884dee7a7781fa4c1577a6c9681a.]

The GCC_ENABLE_PLUGINS configure logic for detecting whether -rdynamic
is necessary and supported uses an appropriate objdump for $host
binaries (running on $build) in cases where $host is $build or
$target.

However, it is missing such logic in the case where $host is neither
$build nor $target, resulting in the compilers not being linked with
-rdynamic and plugins not being usable with such a compiler.  In fact
$ac_cv_prog_OBJDUMP, as used when $build = $host, is always an objdump
for $host binaries that runs on $build; that is, it's appropriate to
use in this case as well.

Tested in such a configuration that it does result in cc1 being linked
with -rdynamic as expected.  Also bootstrapped with no regressions for
x86_64-pc-linux-gnu.

config/
* gcc-plugin.m4 (GCC_ENABLE_PLUGINS): Use
export_sym_check="$ac_cv_prog_OBJDUMP -T" also when host is not
build or target.

9 months agoFix "usage" errors for some MI varobj commands
Tom Tromey [Thu, 31 Aug 2023 17:59:06 +0000 (11:59 -0600)]
Fix "usage" errors for some MI varobj commands

I noticed that the "usage" error for -var-set-frozen mentioned the
wrong command name.  Then I looked through the whole file and found a
couple other spots that didn't mention the command name at all.  This
patch fixes all of these.

Reviewed-by: Kevin Buettner <kevinb@redhat.com>
9 months agox86: unindent most of set_cpu_arch()
Jan Beulich [Fri, 1 Sep 2023 10:29:44 +0000 (12:29 +0200)]
x86: unindent most of set_cpu_arch()

Inverting the initial if()'s condition allows to move out the bulk of
the function by a level, improving readability at least a bit. While
doing that also pull the push/pop handling up first, such that "else if"
after "return" isn't needed anymore; the order in which special cases
are checked doesn't really matter.

9 months agox86: rename CpuPCLMUL
Jan Beulich [Fri, 1 Sep 2023 10:29:24 +0000 (12:29 +0200)]
x86: rename CpuPCLMUL

The name we use internally isn't in line with the SDM, and also isn't in
line with CpuVPCLMULQDQ. Add the missing suffix, but of course leave
alone user facing names.

9 months agox86: correct source used for two non-AVX512 VEXWIG tests
Jan Beulich [Fri, 1 Sep 2023 10:28:57 +0000 (12:28 +0200)]
x86: correct source used for two non-AVX512 VEXWIG tests

These shouldn't wrongly include the AVX512VL sources. Obviously the
expectations therefore also need to change.

9 months agox86: drop Size64 from VMOVQ
Jan Beulich [Fri, 1 Sep 2023 10:27:20 +0000 (12:27 +0200)]
x86: drop Size64 from VMOVQ

Commit 916fae91358d ("Add Size64 to movq/vmovq with Reg64 operand" was
right in adding the attribute to MOVQ, but there was no need to add it
to VMOVQ. (See also the AVX512F form, which doesn't have the attribute
either.)

9 months agoRISC-V: move various alias entries
Jan Beulich [Fri, 1 Sep 2023 10:26:46 +0000 (12:26 +0200)]
RISC-V: move various alias entries

For disassembly to only use spec-mandated aliases, respective non-alias
entries need to come ahead of their alias ones. Since identical
mnemonics need to stay together, whole groups are moved up where
necessary.

This partly reverts 839189bc932e ("RISC-V: re-arrange opcode table for
consistent alias handling"), but then also goes beyond a plain revert.

Reviewed-by: Tsukasa OI <research_trasio@irq.a4lg.com>
Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
9 months agoFix ld Makefile variable naming: ELF_CLFAGS -> ELF_CFLAGS
Jerry Zhang Jian [Fri, 1 Sep 2023 03:36:25 +0000 (11:36 +0800)]
Fix ld Makefile variable naming: ELF_CLFAGS -> ELF_CFLAGS

Signed-off-by: Jerry Zhang Jian <jerry.zhangjian@sifive.com>
9 months agoRISC-V: Fixed the wrong expansion for pseudo vmsge[u].vx instructions.
Nelson Chu [Fri, 1 Sep 2023 07:21:35 +0000 (15:21 +0800)]
RISC-V: Fixed the wrong expansion for pseudo vmsge[u].vx instructions.

The original report was from Kiva Oyama <libkernelpanic@gmail.com>,
https://sourceware.org/pipermail/binutils/2023-August/129255.html

The vmsge[u].vx pseudo should be expanded to masked vmslt[u].vx only when
vd != v0.  Otherwise, it should be expanded to unmasked one.

gas/
* config/tc-riscv.c (vector_macro): Fixed the wrong expansion for
pseudo vmsge[u].vx instructions.
* testsuite/gas/riscv/vector-insns-vmsgtvx.d: Updated.

9 months agogdb: remove uses of alloca in gdbtypes.c
Simon Marchi [Thu, 31 Aug 2023 19:56:10 +0000 (15:56 -0400)]
gdb: remove uses of alloca in gdbtypes.c

Replace two uses of alloca with std::string.

Change-Id: I970ae3f450da407494d95668a57bba8796d6292b
Approved-by: Kevin Buettner <kevinb@redhat.com>
9 months agoAutomatic date update in version.in
GDB Administrator [Fri, 1 Sep 2023 00:00:45 +0000 (00:00 +0000)]
Automatic date update in version.in

9 months agoPR30806, CPPFLAGS are missing for bfd/chew, syslex_wrap and sysinfo
Nicolas Boulenguez [Thu, 31 Aug 2023 16:09:09 +0000 (18:09 +0200)]
PR30806, CPPFLAGS are missing for bfd/chew, syslex_wrap and sysinfo

PR 30806
bfd/
* doc/local.mk (doc/chew.stamp): Add CPPFLAGS_FOR_BUILD.
* Makefile.in: Regenerate.
binutils/
* Makefile.am (syslex_wrap.@OBJEXT@): Add CPPFLAGS_FOR_BUILD.
(sysinfo.@OBJEXT@): Likewise.
* Makefile.in: Regenerate.

9 months agoelf: Adjust PR ld/30791 tests
H.J. Lu [Thu, 31 Aug 2023 15:38:10 +0000 (08:38 -0700)]
elf: Adjust PR ld/30791 tests

Adjust PR ld/30791 tests:

1. Generic linker targets don't comply with all orhpan section merging
rules.
2. z80 fails since a, b, c, d are registers for z80.
3. hppa fails since .text sections aren't merged for relocatable link.

PR ld/30791
* testsuite/ld-elf/pr30791a.d: Xfail for generic and z80
targets.
* testsuite/ld-elf/pr30791b.d: Xfail for hppa and z80 targets.

9 months agoAdd symbol::matches method
Tom Tromey [Tue, 14 Mar 2023 22:56:38 +0000 (16:56 -0600)]
Add symbol::matches method

This adds symbol::matches, a wrapper for symbol_matches_domain.  Most
places calling symbol_matches_domain can call this method instead,
which is a bit less wordy and also (IMO) clearer.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
9 months agogdb: remove TYPE_FIELD_PACKED
Simon Marchi [Thu, 31 Aug 2023 15:46:28 +0000 (11:46 -0400)]
gdb: remove TYPE_FIELD_PACKED

Replace with a new equivalent "is_packed" method on struct field.

Change-Id: I78647be3d408b40b63becb6b6f0fca211bede51c
Approved-By: Tom Tromey <tom@tromey.com>
9 months agogdb: remove TYPE_FIELD_BITSIZE
Simon Marchi [Thu, 31 Aug 2023 15:46:27 +0000 (11:46 -0400)]
gdb: remove TYPE_FIELD_BITSIZE

Replace with type::field + field::bitsize.

Change-Id: I2a24755a33683e4a2775a6d2a7b7a9ae7362e43a
Approved-By: Tom Tromey <tom@tromey.com>
9 months agogdb: remove FIELD_BITSIZE
Simon Marchi [Thu, 31 Aug 2023 15:46:26 +0000 (11:46 -0400)]
gdb: remove FIELD_BITSIZE

Replace with field::bitsize.

Change-Id: I400be235d6a1f446d0a4aafac01df5e850185d3a
Approved-By: Tom Tromey <tom@tromey.com>
9 months agogdb: introduce field::bitsize / field::set_bitsize
Simon Marchi [Thu, 31 Aug 2023 15:46:25 +0000 (11:46 -0400)]
gdb: introduce field::bitsize / field::set_bitsize

Add these two methods, rename the field to m_bitsize to make it pseudo
private.

Change-Id: Ief95e5cf106e72f2c22ae47b033d0fa47202b413
Approved-By: Tom Tromey <tom@tromey.com>
9 months agogdb: remove TYPE_FIELD_ARTIFICIAL
Simon Marchi [Thu, 31 Aug 2023 15:46:24 +0000 (11:46 -0400)]
gdb: remove TYPE_FIELD_ARTIFICIAL

Replace with type::field + field::is_artificial.

Change-Id: Ie3bacae49d9bd02e83e504c1ce01470aba56a081
Approved-By: Tom Tromey <tom@tromey.com>
9 months agogdb: remove FIELD_ARTIFICIAL
Simon Marchi [Thu, 31 Aug 2023 15:46:23 +0000 (11:46 -0400)]
gdb: remove FIELD_ARTIFICIAL

Replace uses with field::is_artificial.

Change-Id: I599616fdd9f4b6d044de492e8151aa6130725cd1
Approved-By: Tom Tromey <tom@tromey.com>
9 months agogdb: introduce field::is_artificial / field::set_is_artificial
Simon Marchi [Thu, 31 Aug 2023 15:46:22 +0000 (11:46 -0400)]
gdb: introduce field::is_artificial / field::set_is_artificial

Add these two methods, rename the field to m_artificial to make it
pseudo private.

Change-Id: If3a3825473d1d79bb586a8a074b87bba9b43fb1a
Approved-By: Tom Tromey <tom@tromey.com>
9 months agoRemove eval_op_ternop
Tom Tromey [Tue, 29 Aug 2023 16:51:33 +0000 (10:51 -0600)]
Remove eval_op_ternop

eval_op_ternop is only used by the implementation of
ternop_slice_operation.  While working on another series, it was
convenient for me to merge this function into its only caller.

Reviewed-by: Kevin Buettner <kevinb@redhat.com>
9 months ago[symtab/27831] New test case: gdb.base/add-symbol-file-attach.exp
Kevin Buettner [Thu, 31 Aug 2023 14:44:13 +0000 (07:44 -0700)]
[symtab/27831] New test case: gdb.base/add-symbol-file-attach.exp

This commit adds a new test case for bug 27831.  See the contents
of the .exp file for a description of what it's about.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27831
Approved-By: Tom Tromey <tom@tromey.com>
9 months ago[symtab/27831] Fix OBJF_MAINLINE assert
Kevin Buettner [Thu, 31 Aug 2023 14:43:20 +0000 (07:43 -0700)]
[symtab/27831] Fix OBJF_MAINLINE assert

This commit fixes a bug mentioned by Florian Weimer during the
libpthread/ld.so load order discussion from 2021.  Florian provided
instructions for reproducing the bug here:

https://sourceware.org/pipermail/gdb-patches/2021-April/177923.html

That particular test does some interesting things involving forks,
threads, and thread local storage.  Fortunately, none of that is
needed to reproduce the problem.

I've made a new test case (which is now found in a separate commit)
contained in the files gdb.base/add-symbol-file-attach.{c,exp}.  The
.c file is fairly simple as is the recipe for reproducing the problem.

After separately starting the test case and noting the process id,
start gdb (w/ no arguments), and do the following to reproduce the
assertion failure - for this run, the process id of the separately
started add-symbol-file-attach process is 4103218:

(gdb) add-symbol-file add-symbol-file-attach
add symbol table from file "add-symbol-file-attach"
(y or n) y
Reading symbols from add-symbol-file-attach...
(gdb) attach 4103218
Attaching to process 4103218
Load new symbol table from "/tmp/add-symbol-file-attach"? (y or n) y
Reading symbols from /tmp/add-symbol-file-attach...
Reading symbols from /lib64/libc.so.6...
(No debugging symbols found in /lib64/libc.so.6)
Reading symbols from /lib64/ld-linux-x86-64.so.2...
(No debugging symbols found in /lib64/ld-linux-x86-64.so.2)
0x00007f502130bf27 in pause () from /lib64/libc.so.6
(gdb) p foo
symtab.c:6417: internal-error: CORE_ADDR get_msymbol_address(objfile*,
  const minimal_symbol*): Assertion `(objf->flags & OBJF_MAINLINE) == 0'
  failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.

The add-symbol-file command causes the symbols to be loaded without
the SYMFILE_MAINLINE (and hence the OBJFILE_MAINLINE) flags being
set.  This, in turn, causes the "maybe_copied" flag to be set for
the global symbol (named "foo" in the provided test case).

The attach command will cause another objfile to be created, but
it will reuse the symtabs from the objfile created by add-symbol-file,
leading to a situation in which the OBJFILE_MAINLINE flag will be set
for the new (attach-created) objfile, however the "maybe_copied"
flag will still be set for the global symbol.  Had it been loaded
anew, this flag would not be set due to OBJFILE_MAINLINE being set
for the objfile.

At present, minimal_symbol::value_address looks like this:

CORE_ADDR
minimal_symbol::value_address (objfile *objfile) const
{
  if (this->maybe_copied (objfile))
    return get_msymbol_address (objfile, this);
  else
    return (CORE_ADDR (this->unrelocated_address ())
    + objfile->section_offsets[this->section_index ()]);
}

So, we can now see the problem: When the "maybe_copied" flag is set,
get_msymbol_address() will be called.  However, get_msymbol_address()
assumes that it won't be called with the OBF_MAINLINE flag set for
the objfile in question.  It, in fact, contains an assert() which
makes sure that this is the case:

  gdb_assert ((objf->flags & OBJF_MAINLINE) == 0);

(If this assert is removed, then get_msymbol_address() recurses
infinitely for the case under consideration.)

So, the problem here is that the maybe_copied flag is set for the
symbol AND the OBJF_MAINLINE flag is set for the objfile.  As noted
earlier, this happens due to add-symbol-file being used; this causes
the maybe_copied flag to be set.  Later, when the attach is performed,
OBJF_MAINLINE will be set for that objfile, leading to this
unfortunate situation.

My first cut at a solution involved adjusting the
MSYMBOL_VALUE_ADDRESS macro (which has since been changed to be the
method noted above) to include a test of the OBJFILE_MAINLINE flag.
However, Simon Marchi, in his review of my patch, suggested a better
solution.  Simon observed that the 'maybe_copied' flag is (was, after
this commit) being set/initialized in record_minimal_symbol() using
using the objfile in the context in which the symbol was created.

Simon further observed:

  Today, a single copy is created, as symtabs are shared between
  objfiles.  This means that everything that we store into a symbol
  must be independent of any objfile.  However, the value of the
  maybe_copied field is dependent on the objfile in the context of
  which the symbol was created.  Meaning that when the symbol is
  re-used in the context of another objfile, the maybe_copied value is
  not right in the context of that objfile.

  So I think it means there isn't a single "is this symbol maybe
  copied" value, but instead "is this symbol maybe copied, in the
  context of this given objfile".  And the answer is yes or no,
  depending on whether the objfile is mainline.  So maybe_copied
  should become a method that takes an objfile and returns an answer
  based on that.

Simon's full review can be found here:

  https://sourceware.org/pipermail/gdb-patches/2021-May/178855.html

Simon also provided a patch which implements this suggestion.  The
current patch is mostly his work, though I did make some adjustments
during a rebase in addition to making some changes to account for a
concern from Tom Tromey.

During his review of the v3 series, Tom noted, "The old approach was
specific to ELF, while the new approach will be used by any object
format." Tom further observed, "...it seems like it could result in an
incorrect evaluation in some scenario."  This seemed plausible to me,
so I introduced the flag 'object_format_has_copy_relocs' to struct
objfile.  It is set at the end of elf_symfile_read() in elfread.c.
The minimal_symbol::maybe_copied method tests this new flag, forcing
this method to return false when the flag is not set.  If we find that
other object file formats use the same copy reloc mechanism as ELF,
then 'object_format_has_copy_relocs' should be set for objfiles using
those formats.

Lastly, I'll note that this is a strange use case.  It's far more
common to either let gdb figure out which file to load by itself when
attaching, i.e.

(gdb) attach 4104360
Attaching to process 4104360
Reading symbols from /tmp/add-symbol-file-attach...
Reading symbols from /lib64/libc.so.6...
(No debugging symbols found in /lib64/libc.so.6)
Reading symbols from /lib64/ld-linux-x86-64.so.2...
(No debugging symbols found in /lib64/ld-linux-x86-64.so.2)
0x00007fdb1fc33f27 in pause () from /lib64/libc.so.6
(gdb) p foo
$1 = 42

...or to use the "file" command prior to the attach, like this:

(gdb) file add-symbol-file-attach
Reading symbols from add-symbol-file-attach...
(gdb) attach 4104360
Attaching to program: /tmp/add-symbol-file-attach, process 4104360
Reading symbols from /lib64/libc.so.6...
(No debugging symbols found in /lib64/libc.so.6)
Reading symbols from /lib64/ld-linux-x86-64.so.2...
(No debugging symbols found in /lib64/ld-linux-x86-64.so.2)
0x00007fdb1fc33f27 in pause () from /lib64/libc.so.6

Both of these more common scenarios work perfectly fine; using
"add-symbol-file" to load the program to which you will attach
isn't recommended as a normal use case.  That said, it's bad for
gdb to assert, hence this fix.

Reviewed-by: Simon Marchi <simon.marchi@polymtl.ca>
Co-Authored-by: Simon Marchi <simon.marchi@polymtl.ca>
Approved-by: Tom Tromey <tom@tromey.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27831

9 months agoUnify DW_TAG_typedef case in new_symbol
Tom Tromey [Wed, 30 Aug 2023 00:38:25 +0000 (18:38 -0600)]
Unify DW_TAG_typedef case in new_symbol

This patch merges the DW_TAG_typedef case in new_symbol with some
other type-related cases.  These all have identical code.

Reviewed-By: Guinevere Larsen <blarsen@redhat.com>
9 months agoRevert "Simplify @node use in BFD documentation"
Tom Tromey [Wed, 30 Aug 2023 15:22:53 +0000 (09:22 -0600)]
Revert "Simplify @node use in BFD documentation"

This reverts commit 8bb23cdbb498ff645bb0937bc8c0cb89e9e5ebd8.

My earlier patch to simplifify the @node uses in the BFD manual didn't
take into account (1) that BFD doesn't use the ordinary texinfo
sectioning commands, and (2) that some users are stuck on very ancient
versions of makeinfo.

This patch reverts the change.

I went through the entire manual using the spacebar, trying to find
the original problem I reported in the change, but couldn't.  I don't
know why.  Anyway, all this means is that, with this reversion,
editing the node structure will be slightly less convenient.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30703

2023-08-30  Tom Tromey  <tom@tromey.com>

PR binutils/30703
* doc/webassembly.texi, doc/bfd.texi: Revert 8bb23cdb, adding
parameters back to @node.

9 months ago[gdb/contrib] Require minimal dwz version in cc-with-tweaks.sh
Tom de Vries [Thu, 31 Aug 2023 13:25:31 +0000 (15:25 +0200)]
[gdb/contrib] Require minimal dwz version in cc-with-tweaks.sh

I usually run target boards cc-with-dwz and cc-with-dwz-m using a dwz build
from current trunk, but the pathname to the build dir changed and I forgot to
update my test scripts, so the test scripts reverted to using system dwz,
version 0.12.

Consequently, I ran into:
...
(gdb) p ZERO^M
No symbol "ZERO" in current context.^M
(gdb) FAIL: gdb.base/enumval.exp: p ZERO
...
which is due to PR dwz/24468, which was fixed in version 0.13.

Fix this by minimally requiring dwz version 0.13 in cc-with-tweaks.sh, such
that this situation is detected and we get instead:
...
gdb compile failed, cc-with-tweaks.sh: dwz version 0.12 detected, version \
  0.13 or higher required
...

Tested on x86_64-linux, verified with shellcheck.

Approved-By: Tom Tromey <tom@tromey.com>
9 months agovms-alpha: Free memory on failure path
Alan Modra [Thu, 31 Aug 2023 09:10:40 +0000 (18:40 +0930)]
vms-alpha: Free memory on failure path

* vms-alpha.c (evax_bfd_print_eobj): Free rec on failure.

9 months agogas init_stab_section and get_stab_string_offset
Alan Modra [Thu, 31 Aug 2023 08:35:35 +0000 (18:05 +0930)]
gas init_stab_section and get_stab_string_offset

get_stab_string_offset currently creates the stabstr section if not
already present, in the process keeping a reference to the malloc'd
section name string.  Really, the name belongs in bfd_alloc'd memory
or some obstack so that it doesn't show as a memory leak on exit.
s_stab_generic at least does allocate the name for the stab section on
an obstack, but doesn't tidy that as well as it could.  Return paths
after issuing a warning don't release the memory, nor the memory for
the "string" copy.

This patch fixes these problems.  s_stab_generic is rearranged so that
creation of the sections occurs earlier, before any potential uses of
the note obstack during expression parsing.  That makes it possible to
always free the section name strings unless used to create new
sections.  I've also avoided get_absolute_expression_and_terminator
as I see that function might skip over end-of-line, and lack of a
--input_line_pointer might have caused the following source line to be
ignored.  (Other uses of this function in gas are OK.)

* config/obj-coff.c (obj_coff_init_stab_section): Add stabstr
param.  Pass to get_stab_string_offset rather than name of
section.
* config/obj-som.c (obj_som_init_stab_section): Likewise.
* config/obj-elf.c (obj_elf_init_stab_section): Likewise.
(elf_init_stab_section): Adjust.
* config/obj-coff.h (INIT_STAB_SECTION): Update.
(obj_coff_init_stab_section): Update prototype.
* config/obj-som.h: Similarly.
* config/obj-elf.h: Similarly.
* config/obj-multi.h (INIT_STAB_SECTION): Update.
* obj.h (struct format_ops <init_stab_section>): Update.
* read.h (get_stab_string_offset): Update prototype.
* stabs.c (cached_sec): Delete.
(stabs_begin): Adjust to suit.
(get_stab_string_offset): Add stabstr param, delete stabstr_name
and free_stabstr_secname params.  Don't make stabstr section
here.
(eat_comma): New function.
(s_stab_generic): Replace stab_secname_obstack_end param with
bool freenames.  Move creation of stab and stabstr sections
earlier, so the names can be freed earlier before possible use
of notes obstack during expression parsing.  Tidy error paths
ensuring "string" is freed.  Use get_absolute_expression in
place of get_absolute_expression_and_terminator.
(s_stab): Adjust.
(s_xstab): Use notes_concat to make stabstr section name.

9 months agogas OBJ_PROCESS_STAB
Alan Modra [Thu, 31 Aug 2023 06:01:56 +0000 (15:31 +0930)]
gas OBJ_PROCESS_STAB

This macro and the supporting functions have an unused "seg" first
argument.  Tidy that.

* config/obj-aout.c (obj_aout_process_stab): Delete first param.
* config/obj-ecoff.h (OBJ_PROCESS_STAB): Likewise.
* config/obj-elf.c (elf_process_stab): Likewise.
* config/obj-elf.h (OBJ_PROCESS_STAB): Likewise.
* config/obj-macho.h (OBJ_PROCESS_STAB): Likewise.
* config/obj-multi.h (OBJ_PROCESS_STAB): Likewise.
* ecoff.c (ecoff_stab): Likewise.
* ecoff.h (ecoff_stab): Likewise.
* obj.h (struct format_ops <process_stab>): Likewise.
* stabs.c (OBJ_PROCESS_STAB): Likewise.

9 months ago[gdb/symtab] Replace TYPE_ALLOC with TYPE_ZALLOC where required
Tom de Vries [Thu, 31 Aug 2023 07:37:44 +0000 (09:37 +0200)]
[gdb/symtab] Replace TYPE_ALLOC with TYPE_ZALLOC where required

Handle the remaining uses of TYPE_ALLOC, either by:
- replacing with TYPE_ZALLOC, or
- adding a comment explaining why zero-initialization is not necessary.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
9 months ago[gdb/symtab] Replace TYPE_ALLOC + B_CLRALL with TYPE_ZALLOC
Tom de Vries [Thu, 31 Aug 2023 07:37:44 +0000 (09:37 +0200)]
[gdb/symtab] Replace TYPE_ALLOC + B_CLRALL with TYPE_ZALLOC

I noticed some cases of TYPE_ALLOC followed by B_CLRALL.

Replace these with TYPE_ZALLOC.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
9 months ago[gdb/symtab] Replace TYPE_ALLOC + memset with TYPE_ZALLOC
Tom de Vries [Thu, 31 Aug 2023 07:37:44 +0000 (09:37 +0200)]
[gdb/symtab] Replace TYPE_ALLOC + memset with TYPE_ZALLOC

I noticed a case of TYPE_ALLOC followed by memset.

Replace this with TYPE_ZALLOC.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
9 months ago[gdb/symtab] Do more zero-initialization of type::fields
Tom de Vries [Thu, 31 Aug 2023 07:37:44 +0000 (09:37 +0200)]
[gdb/symtab] Do more zero-initialization of type::fields

Now that we've introduced type::{alloc_fields,copy_fields}, the places where
no zero-initialization of allocated fields is done are easy to spot:
...
$ find gdb* -type f | grep -v ChangeLog | xargs grep alloc_fields | grep false
gdb/coffread.c:  type->alloc_fields (nfields, false);
gdb/coffread.c:  type->alloc_fields (nsyms, false);
gdb/stabsread.c:   ftype->alloc_fields (nsemi, false);
gdb/gdbtypes.c:  resolved_type->alloc_fields (nfields, false);
gdb/gdbtypes.c:  alloc_fields (nfields, false);
gdb/gdbtypes.c:  alloc_fields (nfields, false);
gdb/mdebugread.c: t->alloc_fields (nfields, false);
gdb/mdebugread.c:   ftype->alloc_fields (nparams, false);
...

All hits in gdbtypes.c are ok.  There are two hits in the two variants of
copy_fields, and there's already a comment for the third.

AFAICT, the other ones are not ok, so fix those by dropping the "false"
argument.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
9 months ago[gdb/symtab] Factor out type::{alloc_fields,copy_fields}
Tom de Vries [Thu, 31 Aug 2023 07:37:44 +0000 (09:37 +0200)]
[gdb/symtab] Factor out type::{alloc_fields,copy_fields}

After finding this code in buildsym_compunit::finish_block_internal:
...
              ftype->set_fields
                ((struct field *)
                 TYPE_ALLOC (ftype, nparams * sizeof (struct field)));
...
and fixing PR30810 by using TYPE_ZALLOC, I wondered if there were more
locations that needed fixing.

I decided to make things easier to spot by factoring out a new function
alloc_fields:
...
 /* Allocate the fields array of this type, with NFIELDS elements.  If INIT,
     zero-initialize the allocated memory.  */
  void
  type::alloc_fields (unsigned int nfields, bool init = true);
...
where:
- a regular use would be "alloc_fields (nfields)", and
- an exceptional use that needed no initialization would be
  "alloc_fields (nfields, false)".

Pretty soon I discovered that most of the latter cases are due to
initialization by memcpy, so I added two variants of copy_fields as well.

After this rewrite there are 8 uses of set_fields left:
...
gdb/coffread.c:   type->set_fields (nullptr);
gdb/coffread.c:   type->set_fields (nullptr);
gdb/coffread.c:   type->set_fields (nullptr);
gdb/eval.c:  type->set_fields
gdb/gdbtypes.c:  type->set_fields (args);
gdb/gdbtypes.c:  t->set_fields (XRESIZEVEC (struct field, t->fields (),
gdb/dwarf2/read.c:      type->set_fields (new_fields);
gdb/dwarf2/read.c:       sub_type->set_fields (sub_type->fields () + 1);
...

These fall into the following categories:
- set to nullptr (coffread.c),
- type not owned by objfile or gdbarch (eval.c), and
- modifying an existing fields array, like adding an element at the end or
  dropping an element at the start (the rest).

Tested on x86_64-linux.

9 months ago[gdb/symtab] Fix uninitialized memory in buildsym_compunit::finish_block_internal
Tom de Vries [Thu, 31 Aug 2023 07:37:44 +0000 (09:37 +0200)]
[gdb/symtab] Fix uninitialized memory in buildsym_compunit::finish_block_internal

When running test-case gdb.dwarf2/per-bfd-sharing.exp with target board stabs,
gdb either segfaults or asserts due to reading uninitialized memory, allocated
here in buildsym_compunit::finish_block_internal:
...
      ftype->set_fields
((struct field *)
 TYPE_ALLOC (ftype, nparams * sizeof (struct field)));
...

Fix this by using TYPE_ZALLOC instead.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
PR symtab/30810
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30810

9 months agoarc: Update elfarcv2 script template
Claudiu Zissulescu [Tue, 29 Aug 2023 08:52:06 +0000 (11:52 +0300)]
arc: Update elfarcv2 script template

Update ARC's elfarcv2 script template with:

- The .ivt section (Interrupt Vector Table) is mapped at the begining
  of STARTUP_MEMORY when ivtbase_addr is not defined. Previously, it
  was pointing to 0x00.

- MEMORY_FILE is a new emulation paramter and sets the name for the
  linker script file which holds the MEMORY commands required by
  arcv2elfx emulation.

- Four new linker variables are introduced available when arcv2elf emulation is used:
  * __TEXT_REGION_ORIGIN__ Once defined it is setting the text region origin. By default it points to zero.
  * __TEXT_REGION_LENGTH__ Once defined it is setting the text region length. By default it is set to 2M.
  * __DATA_REGION_ORIGIN__ Once defined it is setting the data region origin. By default it is set to 0x80000000.
  * __DATA_REGION_LENGTH__ Once defined it is setting the data region length. By default it is set to 2M.

ld/ChangeLog:

* scripttempl/elfarcv2.sc: Update script template.

Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
9 months agoelf: Don't merge sections with different SHF_LINK_ORDER
H.J. Lu [Wed, 30 Aug 2023 17:24:56 +0000 (10:24 -0700)]
elf: Don't merge sections with different SHF_LINK_ORDER

For relocatable link, don't merge 2 SHF_LINK_ORDER sections if output
sections of their linked to sections are different.

* ldelf.c (elf_orphan_compatible): Don't merge sections with
different SHF_LINK_ORDER.
* testsuite/ld-elf/pr30791a.d: New file.
* testsuite/ld-elf/pr30791a.s: Likewise.
* testsuite/ld-elf/pr30791b.d: Likewise.
* testsuite/ld-elf/pr30791b.s: Likewise.
* testsuite/ld-elf/pr30791c.s: Likewise.
* testsuite/ld-elf/pr30791d.s: Likewise.

9 months agoelf: Check DT_SYMTAB only on non-IR object
H.J. Lu [Wed, 30 Aug 2023 15:49:15 +0000 (08:49 -0700)]
elf: Check DT_SYMTAB only on non-IR object

Check DT_SYMTAB only on non-IR object of archive member to avoid crash
on LLVM IR object with NULL elf_tdata.

PR ld/30811
* elflink.c (elf_link_is_defined_archive_symbol): Check
DT_SYMTAB only on non-IR object.

9 months agoAutomatic date update in version.in
GDB Administrator [Thu, 31 Aug 2023 00:00:44 +0000 (00:00 +0000)]
Automatic date update in version.in

9 months agolibbfd.texi zero size
Alan Modra [Wed, 30 Aug 2023 23:27:31 +0000 (08:57 +0930)]
libbfd.texi zero size

Pattern rules in doc/local.mk exist that specify how to make
libbfd.texi from libfd.h or libbfd.c.  Since both files exist and the
libbfd.h rule is first, libbfd.h is used.  libbfd.h doesn't contain
the documentation..

* doc/local.mk (doc/%stamp): Put rule making this from %.c
before %.h rule.
* Makefile.in: Regenerate.
* libbfd.c (Byte swapping routines): Don't omit description.

9 months agoDEFAULT_BUFFERSIZE
Alan Modra [Wed, 30 Aug 2023 13:12:53 +0000 (22:42 +0930)]
DEFAULT_BUFFERSIZE

There isn't any reason to think that a particular buffer size is
ideal in bfd, so let's just not define it.

* libbfd-in.h (DEFAULT_BUFFERSIZE): Don't define.
* libbfd.h: Regenerate.
* archive.c (AR_WRITE_BUFFERSIZE): Substitute value.
* vms-lib.c (_bfd_vms_lib_write_archive_contents): Likewise.
* coff-rs6000.c (do_copy): Likewise, and use sizeof.

9 months ago[gdb/testsuite] Fix gdb.dwarf2/nullptr_t.exp with cc-with-dwz-m
Tom de Vries [Wed, 30 Aug 2023 21:33:31 +0000 (23:33 +0200)]
[gdb/testsuite] Fix gdb.dwarf2/nullptr_t.exp with cc-with-dwz-m

When running test-case gdb.dwarf2/nullptr_t.exp with target board
cc-with-dwz-m, I run into:
...
FAIL: gdb.dwarf2/nullptr_t.exp: decltype(nullptr) symbol
...

The problem is that were looking for "typedef void decltype\\(nullptr\\)"
using "maint print symbols -source $srcfile", but dwz has moved the typedef to
a PU, so it's shown by "maint print symbols -source <unknown>" instead.

Fix this by dropping the "-source $srcfile" bit.

Tested on x86_64-linux, with make-check-all.sh.

9 months agogdb: simplify vector construction in eval_op_rust_array
Simon Marchi [Wed, 30 Aug 2023 15:21:20 +0000 (11:21 -0400)]
gdb: simplify vector construction in eval_op_rust_array

Replace the manual fill of the vector with the appropriate std::vector
constructor that makes N copies of the provided value.

Change-Id: I579570748c48f53d35024105269d83c716294746
Approved-By: Tom Tromey <tom@tromey.com>
9 months agoRevert "Gold: Add targ_extra_little_endian to configure.ac"
Maciej W. Rozycki [Tue, 29 Aug 2023 15:13:54 +0000 (16:13 +0100)]
Revert "Gold: Add targ_extra_little_endian to configure.ac"

This reverts commit cf8565fb2ea42579c50722cbaeafdf71c3d58c66.  It was
applied unapproved.

9 months agoRevert "Gold/MIPS: Use EM_MIPS instead of EM_MIPS_RS3_LE for little endian"
Maciej W. Rozycki [Tue, 29 Aug 2023 15:13:22 +0000 (16:13 +0100)]
Revert "Gold/MIPS: Use EM_MIPS instead of EM_MIPS_RS3_LE for little endian"

This reverts commit 39834263784567c306fbccb8230ddd1badca53fe.  It was
applied unapproved.

9 months agoRevert "Gold/MIPS: Drop mips*le/mips*el* triple pattern"
Maciej W. Rozycki [Tue, 29 Aug 2023 15:13:15 +0000 (16:13 +0100)]
Revert "Gold/MIPS: Drop mips*le/mips*el* triple pattern"

This reverts commit adb3ae2eba78b4b84d7b94342f6774b250190a98.  It was
applied unapproved.

9 months agoRevert "Gold/MIPS: Add targ_extra_size=64 for mips32 triples"
Maciej W. Rozycki [Tue, 29 Aug 2023 15:13:10 +0000 (16:13 +0100)]
Revert "Gold/MIPS: Add targ_extra_size=64 for mips32 triples"

This reverts commit d6cdc0af2b880bb48dd16055f4cb3509c7a2da70.  It was
applied unapproved.

9 months agoRevert "Gold/MIPS: Add mips64*/mips64*el triple support"
Maciej W. Rozycki [Tue, 29 Aug 2023 15:12:58 +0000 (16:12 +0100)]
Revert "Gold/MIPS: Add mips64*/mips64*el triple support"

This reverts commit 5c4cdba100b66e2924a25dad9b12d8e5b84d527f.  It was
applied unapproved.

9 months agoRevert "MIPS: Use 64-bit a ABI by default for `mipsisa64*-*-linux*' targets"
Maciej W. Rozycki [Tue, 29 Aug 2023 15:12:12 +0000 (16:12 +0100)]
Revert "MIPS: Use 64-bit a ABI by default for `mipsisa64*-*-linux*' targets"

This reverts commit 025e84f93566c8ced594ef48ddee1dec7e5b4cdd.  It was
applied unapproved.

9 months agogdbserver, linux-low: add a couple of nullptr assertions.
Willgerodt, Felix [Tue, 29 Aug 2023 13:28:04 +0000 (13:28 +0000)]
gdbserver, linux-low: add a couple of nullptr assertions.

This safeguards a couple of places that may theoretically return NULL but
must not in this specific context.  These were found by a static analysis tool.

Approved-By: Tom Tromey <tom@tromey.com>
9 months agoRISC-V: Make XVentanaCondOps RV64 only
Tsukasa OI [Wed, 30 Aug 2023 01:04:42 +0000 (01:04 +0000)]
RISC-V: Make XVentanaCondOps RV64 only

Although XVentanaCondOps instructions are XLEN-agonistic, Ventana's manual
only defines them only for RV64 (because all Ventana's processors implement
RV64).

This commit limits XVentanaCondOps instructions RV64-only to match the
behavior of the manual and LLVM.

Note that this commit alone will not make XVentanaCondOps extension with
RV32 invalid (it just makes XVentanaCondOps on RV32 empty).

opcodes/ChangeLog:

* riscv-opc.c (riscv_opcodes): Restrict "vt.maskc" and "vt.maskcn"
to XLEN=64.

gas/ChangeLog:

* testsuite/gas/riscv/x-ventana-condops-32.d: New failure test.
* testsuite/gas/riscv/x-ventana-condops-32.l: Likewise.

9 months agoobjdump: Free sorted_syms on error path
Alan Modra [Wed, 30 Aug 2023 01:48:01 +0000 (11:18 +0930)]
objdump: Free sorted_syms on error path

* objdump.c (disassemble_data): Free sorted_syms before returning.

9 months agobinutils/dwarf.c abbrev list leak
Alan Modra [Wed, 30 Aug 2023 01:40:58 +0000 (11:10 +0930)]
binutils/dwarf.c abbrev list leak

* dwarf.c (process_debug_info): Call free_abrev_list on
return paths.

9 months agoRe: readelf/objdump: Handle DWARF info with mixed types of range section
Alan Modra [Wed, 30 Aug 2023 01:15:03 +0000 (10:45 +0930)]
Re: readelf/objdump: Handle DWARF info with mixed types of range section

PR 30791
* dwarf.c (free_debug_information): Free range_versions.

9 months agoAutomatic date update in version.in
GDB Administrator [Wed, 30 Aug 2023 00:00:41 +0000 (00:00 +0000)]
Automatic date update in version.in

9 months ago[gdb/build] Fix C inclusion of nat/x86-cpuid.h
Tom de Vries [Tue, 29 Aug 2023 20:40:36 +0000 (22:40 +0200)]
[gdb/build] Fix C inclusion of nat/x86-cpuid.h

When running test-case gdb.arch/i386-avx512.exp, I run into:
...
 gdb compile failed, In file included from gdb.arch/i386-avx512.c:20:0:
 src/gdb/nat/x86-cpuid.h: In function 'x86_cpuid_count':
 src/gdb/nat/x86-cpuid.h:63:16: error: \
   'nullptr' undeclared (first use in this function)
    if (__eax == nullptr)
                 ^~~~~~~
 src/gdb/nat/x86-cpuid.h:63:16: note: each \
   undeclared identifier is reported only once for each function it appears in

                  === gdb Summary ===

 # of untested testcases         1
...

This is due to commit e85aad4ae76 ("nat/x86-cpuid.h: Add x86_cpuid_count
wrapper around __get_cpuid_count"), which introduced the nullptr check.

The header file gdb/nat/x86-cpuid.h is a file that is included in the build
and compiled as a C++ file, but also in the testsuite and compiled as a C
file.

Fix this by replacing nullptr with (void *)0.

Tested on x86_64-linux.

Co-Authored-By: Kevin Buettner <kevinb@redhat.com>
Approved-by: Kevin Buettner <kevinb@redhat.com>
9 months agoMore renames in array_operation::evaluate
Tom Tromey [Tue, 29 Aug 2023 15:18:42 +0000 (09:18 -0600)]
More renames in array_operation::evaluate

array_operation::evaluate has variables named "tem2" and "tem3".  This
patch replaces one with a better name, and entirely removes the other.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
9 months agoRemove "highbound" parameter from value_array
Tom Tromey [Tue, 29 Aug 2023 15:14:01 +0000 (09:14 -0600)]
Remove "highbound" parameter from value_array

value_array requires the passed-in bounds to match the length of the
array_view it is given.  This patch removes the redundant "highbound"
parameter.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
9 months agoRemove another redundant variable from array_operation::evaluate
Tom Tromey [Mon, 28 Aug 2023 18:52:54 +0000 (12:52 -0600)]
Remove another redundant variable from array_operation::evaluate

This removes yet another redundant variable from
array_operation::evaluate -- only one index is needed.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
9 months agoRemove redundant variable from array_operation::evaluate
Tom Tromey [Mon, 28 Aug 2023 18:43:35 +0000 (12:43 -0600)]
Remove redundant variable from array_operation::evaluate

In array_operation::evaluate, 'idx' and 'tem' are redundant in one
branch.  This patch merges them, using the clearer name.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
9 months agoHoist array bounds check in array_operation::evaluate
Tom Tromey [Mon, 28 Aug 2023 19:39:33 +0000 (13:39 -0600)]
Hoist array bounds check in array_operation::evaluate

This hoists the array bounds check in array_operation::evaluate to
before the loop.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
9 months agoDeclare 'tem' in loop header in array_operation::evaluate
Tom Tromey [Mon, 28 Aug 2023 18:42:51 +0000 (12:42 -0600)]
Declare 'tem' in loop header in array_operation::evaluate

This changes array_operation::evaluate to declare the 'tem' variable
in the loop header, rather than at the top of the function.  This is
cleaner and easier to reason about.  I also changed 'nargs' to be
'const'.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
9 months agoUse gdb::array_view for value_array
Tom Tromey [Mon, 28 Aug 2023 18:40:35 +0000 (12:40 -0600)]
Use gdb::array_view for value_array

This changes value_array to accept an array view.  I also replaced an
alloca with a std::vector in array_operation::evaluate.  This function
can work on any size of array, so it seems bad to use alloca.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
9 months agogdb/testsuite: recognize one more unsupported instruction in gdb.reverse/step-precsav...
Simon Marchi [Tue, 29 Aug 2023 16:19:02 +0000 (12:19 -0400)]
gdb/testsuite: recognize one more unsupported instruction in gdb.reverse/step-precsave.exp

When running this test on a processor that supports AVX512 (AMD EPYC
9634) on Debian 12 bookwork (system compiler is gcc 12.2.0), I see:

    continue^M
    Continuing.^M
    Process record does not support instruction bound.^M
    Process record does not support instruction 0x62 at address 0x7ffff7f49b40.^M
    Process record: failed to record execution log.^M
    ^M
    Program stopped.^M
    0x00007ffff7f49b40 in ?? () from /lib/x86_64-linux-gnu/libc.so.6^M
    (gdb) FAIL: gdb.reverse/step-precsave.exp: run to end of main

The instruction at this address is:

   0x00007ffff7f49b40: 62 e2 7d 48 7a c6   vpbroadcastb %esi,%zmm16

This seems like an AVX512 instruction (given the use of zmm16).  Match
this byte value in order to produce a KFAIL.

Change-Id: I1d20357fa538ba60b9c537160acf511a37d751ee
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30807
Approved-By: Tom Tromey <tom@tromey.com>
9 months ago[gdb/testsuite] Require have_compile_flag -mavx512f in gdb.arch/i386-avx512.exp
Tom de Vries [Tue, 29 Aug 2023 15:27:19 +0000 (17:27 +0200)]
[gdb/testsuite] Require have_compile_flag -mavx512f in gdb.arch/i386-avx512.exp

When running test-case gdb.arch/i386-avx512.exp with gcc 4.8.4, I run into:
...
Running gdb.arch/i386-avx512.exp ...
gdb compile failed, gcc: error: unrecognized command line option '-mavx512f'
...

Fix this by requiring have_compile_flag -mavx512f.

Tested on x86_64-linux.

9 months ago[gdb/testsuite] Require gcc >= 5 in gdb.linespec/cpls-abi-tag.exp
Tom de Vries [Tue, 29 Aug 2023 15:27:19 +0000 (17:27 +0200)]
[gdb/testsuite] Require gcc >= 5 in gdb.linespec/cpls-abi-tag.exp

When running test-case gdb.linespec/cpls-abi-tag.exp with gcc 4.8.4, we run
into:
...
cpls-abi-tag.cc:71:26: error: ‘abi_tag’ attribute applied to non-function ‘s’
 ABI3 test_abi_tag_struct s;
                          ^
...

The test-case is supported starting gcc 5.

Fix this by requiring gcc >= 5, if a gcc compiler is used.

Tested on x86_64-linux.

9 months ago[gdb/testsuite] Handle some test-cases with older compiler
Tom de Vries [Tue, 29 Aug 2023 15:27:19 +0000 (17:27 +0200)]
[gdb/testsuite] Handle some test-cases with older compiler

When running test-case gdb.mi/print-simple-values.exp with gcc 4.8.4, I run
into a compilation failure due to the test-case requiring c++11 and the
compiler defaulting to less than that.

Fix this by compiling with -std=c++11.

Likewise in a few other test-cases.

Tested on x86_64-linux.

9 months ago[gdb/testsuite] Fix false negative in have_host_locale
Tom de Vries [Tue, 29 Aug 2023 15:27:19 +0000 (17:27 +0200)]
[gdb/testsuite] Fix false negative in have_host_locale

In test-case gdb.tui/pr30056.exp we check for:
...
require {have_host_locale C.UTF-8}
...

The "C.UTF-8" is normalized by have_host_locale to "c.utf8", before trying to
find it in the list returned by host_locales.

On my development platform, "locale -a" lists C.utf8, which is normalized to
"c.utf8" by host_locales, so there's a match and have_host_locale returns true.

On another platform however, "locale -a" lists C.UTF-8, which is normalized to
"c.utf-8" by host_locales, so there's no match and have_host_locale returns false.

Fix this by also dropping the dash in host_locales.

Tested on x86_64-linux.

9 months agoreadelf: typos in user messages
Nicolas Boulenguez [Tue, 29 Aug 2023 15:04:47 +0000 (16:04 +0100)]
readelf: typos in user messages

9 months agoDefault getpkt 'forever' parameter to 'false'
Tom Tromey [Mon, 28 Aug 2023 20:03:31 +0000 (14:03 -0600)]
Default getpkt 'forever' parameter to 'false'

This patch changes remote.c so that the getpkt 'forever' parameter now
defaults to 'false' and fixes up all the callers.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
9 months agoUnify getpkt and getpkt_or_notif_sane
Tom Tromey [Mon, 28 Aug 2023 16:25:57 +0000 (10:25 -0600)]
Unify getpkt and getpkt_or_notif_sane

getpkt and getpkt_or_notif_sane are just wrappers for
getpkt_or_notif_sane_1.  This patch adds the is_notif parameter to
getpkt, with a suitable default, and removes the wrappers.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
9 months agoUse bool in getpkt
Tom Tromey [Mon, 28 Aug 2023 16:24:32 +0000 (10:24 -0600)]
Use bool in getpkt

This changes getpkt and related functions to use bool rather than int.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
9 months agoRemove expecting_notif parameter from getpkt_or_notif_sane_1
Tom Tromey [Mon, 28 Aug 2023 16:17:32 +0000 (10:17 -0600)]
Remove expecting_notif parameter from getpkt_or_notif_sane_1

For getpkt_or_notif_sane_1, expecting_notif is redundant, because it
always reflects whether the is_notif parameter is non-NULL.  This
patch removes the redundant parameter.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
9 months agoRemove getpkt_sane
Tom Tromey [Mon, 28 Aug 2023 16:14:54 +0000 (10:14 -0600)]
Remove getpkt_sane

I noticed that getpkt is just a wrapper around getpk_sane, so this
patch unifies the two of them.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
10 months ago[gdb/testsuite] Check for sys/random.h in gdb.reverse/getrandom.exp
Tom de Vries [Tue, 29 Aug 2023 09:02:08 +0000 (11:02 +0200)]
[gdb/testsuite] Check for sys/random.h in gdb.reverse/getrandom.exp

When running test-case gdb.reverse/getrandom.exp on a system with eglibc 2.19,
we run into:
...
 gdb compile failed, gdb.reverse/getrandom.c:18:24: fatal error: \
   sys/random.h: No such file or directory
  #include <sys/random.h>
                         ^
 compilation terminated.

                 === gdb Summary ===

 # of untested testcases        1
...
and:
...
UNTESTED: gdb.reverse/getrandom.exp: failed to prepare
...

Fix this by testing for the presence of the header, such that we have instead:
...
UNSUPPORTED: gdb.reverse/getrandom.exp: require failed: \
  have_system_header sys/random.h
...

Tested on x86_64-linux and i686-linux.

10 months agoAutomatic date update in version.in
GDB Administrator [Tue, 29 Aug 2023 00:00:37 +0000 (00:00 +0000)]
Automatic date update in version.in

10 months ago[gdb/testsuite] Improve xfail in gdb.cp/nsusing.exp
Tom de Vries [Mon, 28 Aug 2023 21:42:11 +0000 (23:42 +0200)]
[gdb/testsuite] Improve xfail in gdb.cp/nsusing.exp

In test-case gdb.cp/nsusing.exp I came across these xfails without PRMS
mentioned:
...
XFAIL: gdb.cp/nsusing.exp: print x, before using statement
XFAIL: gdb.cp/nsusing.exp: print x, only using M
...

Add the missing PRMS, such that we have:
...
XFAIL: gdb.cp/nsusing.exp: print x, before using statement (PRMS gcc/108716)
XFAIL: gdb.cp/nsusing.exp: print x, only using M (PRMS gcc/108716)
...
and limit the xfail to unfixed versions.

The PR is fixed starting gcc 13, but it has been backported to release
branches stretching back to gcc 10.  For simplicity we just stick to testing
for the major version and ignore the backported fixes.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
10 months agogdbserver: Fix style of struct declarations in i387-fp.cc
John Baldwin [Mon, 28 Aug 2023 21:18:19 +0000 (14:18 -0700)]
gdbserver: Fix style of struct declarations in i387-fp.cc

10 months agogdbserver: Simplify handling of ZMM registers.
John Baldwin [Mon, 28 Aug 2023 21:18:19 +0000 (14:18 -0700)]
gdbserver: Simplify handling of ZMM registers.

- Reuse num_xmm_registers directly for the count of ZMM0-15 registers
  as is already done for the YMM registers for AVX rather than using
  a new variable that is always the same.

- Replace 3 identical variables for the count of upper ZMM16-31
  registers with a single variable.  Make use of this to merge
  various loops working on the ZMM XSAVE region so that all of the
  handling for the various sub-registers in this region are always
  handled in a single loop.

- While here, fix some bugs in i387_cache_to_xsave where if
  X86_XSTATE_ZMM was set on i386 (e.g. a 32-bit process on a 64-bit
  kernel), the -1 register nums would wrap around and store the value
  of GPRs in the XSAVE area.  This should be harmless, but is
  definitely odd.  Instead, check num_zmm_high_registers directly when
  checking X86_XSTATE_ZMM and skip the ZMM region handling entirely if
  the register count is 0.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
10 months agox86: Remove X86_XSTATE_SIZE and related constants.
John Baldwin [Mon, 28 Aug 2023 21:18:19 +0000 (14:18 -0700)]
x86: Remove X86_XSTATE_SIZE and related constants.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
10 months agogdbserver: Use x86_xstate_layout to parse the XSAVE extended state area.
Aleksandar Paunovic [Mon, 28 Aug 2023 21:18:19 +0000 (14:18 -0700)]
gdbserver: Use x86_xstate_layout to parse the XSAVE extended state area.

Replace the extended state area fields of i387_xsave with methods which
return an offset into the XSAVE buffer.

The two changed functions are called within all tests which runs
gdbserver.

Signed-off-by: Aleksandar Paunovic <aleksandar.paunovic@intel.com>
Co-authored-by: John Baldwin <jhb@FreeBSD.org>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
10 months agogdbserver: Refactor the legacy region within the xsave struct
Aleksandar Paunovic [Mon, 28 Aug 2023 21:18:19 +0000 (14:18 -0700)]
gdbserver: Refactor the legacy region within the xsave struct

Legacy fields of the XSAVE area are already defined within fx_save
struct.  Use class inheritance to remove code duplication.

The two changed functions are called within all tests which run
gdbserver.

Signed-off-by: Aleksandar Paunovic <aleksandar.paunovic@intel.com>
Co-authored-by: John Baldwin <jhb@FreeBSD.org>
Approved-By: Simon Marchi <simon.marchi@efficios.com>