binutils-gdb.git
17 months agoFix memory leak in bfd_get_debug_link_info_1
Alan Modra [Wed, 29 Mar 2023 12:01:15 +0000 (22:31 +1030)]
Fix memory leak in bfd_get_debug_link_info_1

* opncls.c (bfd_get_alt_debug_link_info): Don't bother freeing
after bfd_malloc_and_get_section failure.
(get_build_id): Likewise.
(bfd_get_debug_link_info_1): Likewise.  Free section contents
when crc not present.
* section.c (bfd_malloc_and_get_section): Document that the
buffer is NULL on error return.

17 months agoTidy leaked objcopy memory
Alan Modra [Wed, 29 Mar 2023 11:35:59 +0000 (22:05 +1030)]
Tidy leaked objcopy memory

* objcopy.c (delete_symbol_htabs): Also free symbols.
(write_debugging_info): Free strings and syms once written.
* wrstabs.c (write_stabs_in_sections_debugging_info): memset
entire info struct.  Free hash tables before returning.  Free
syms on error return.

17 months agoTidy memory on addr2line failures
Alan Modra [Wed, 29 Mar 2023 11:33:35 +0000 (22:03 +1030)]
Tidy memory on addr2line failures

* addr2line.c (process_file): Close bfd on error paths.

17 months agoFix typo in ld manual --enable-non-contiguous-regions example
Roland McGrath [Thu, 30 Mar 2023 00:05:32 +0000 (17:05 -0700)]
Fix typo in ld manual --enable-non-contiguous-regions example

17 months agoAutomatic date update in version.in
GDB Administrator [Thu, 30 Mar 2023 00:00:13 +0000 (00:00 +0000)]
Automatic date update in version.in

17 months agoRISC-V: PR28789, Reject R_RISCV_PCREL relocations with ABS symbol in PIC/PIE.
Palmer Dabbelt [Sat, 25 Mar 2023 00:41:13 +0000 (08:41 +0800)]
RISC-V: PR28789, Reject R_RISCV_PCREL relocations with ABS symbol in PIC/PIE.

The non-preemptible SHN_ABS symbol with a pc-relative relocation should be
disallowed when generating shared object (pic and pie).  Generally, the
following cases, which refer to pr25749, will cause a symbol be
non-preemptible,

* -pie, or -shared with -symbolic
* STV_HIDDEN, STV_INTERNAL, STV_PROTECTED
* Have dynamic symbol table, but without the symbol
* VER_NDX_LOCAL

However, PCREL_HI20/LO12 relocs are always bind locally when generating
shared object, so not only the non-preemptible absolute symbol need to
be disallowed, all absolute symbol references need but except that they
are defined in linker script.  If we also disallow the absolute symbol
in linker script, then the glibc-linux toolchain build failed, so regard
them as pc-relative symbols, just like what x86 did.

Maybe we should add this check for all pc-relative relocations, rather
than just handle in R_RISCV_PCREL relocs.  Ideally, since the value of
SHN_ABS symbol is a constant, only S - A relocations should be allowed
in the shared object, so only BFD_RELOC_8/16/32/64 are allowed, which
means R_RISCV_32/R_RISCV_64.

bfd/
    PR 28789
    * elfnn-riscv.c (riscv_elf_check_relocs): The absolute symbol cannot be
    referneced with pc-relative relocation when generating shared object.
ld/
    PR 28789
    * ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
    * ld/testsuite/ld-riscv-elf/pcrel-reloc*: New testcases.

17 months agoRISC-V: Clarify link behaviors of R_RISCV_32/64 relocations with ABS symbol.
Nelson Chu [Sat, 25 Mar 2023 00:41:12 +0000 (08:41 +0800)]
RISC-V: Clarify link behaviors of R_RISCV_32/64 relocations with ABS symbol.

There are two improvements, which are all referenced to aarch64,

* R_RISCV_32 with non ABS symbol cannot be used under RV64 when making
  shard objects.

* Don't need dynamic relocation for R_RISCV_32/64 under RV32/RV64 when
  making shared objects, if the referenced symbol is local ABS symbol.

However, considering this link,
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/341

Seems like we should makes all R_RISCV_32/64 relocs with ABS symbol
that don't need any dynamic relocations when making the shared objects.
But anyway, I just sync the current behavior as aarch64 ld, in case
there are any unexpected behaviors happen.

Passed the gcc/binutils regressions in riscv-gnu-toolchain.

bfd/
    * elfnn-riscv.c (riscv_elf_check_relocs): Only allow R_RISCV_32 with ABS
    symbol under RV64.
    (riscv_elf_relocate_section): R_RISCV_32/64 with local ABS symbol under
    RV32/RV64 doesn't need any dynamic relocation when making shared objects.
    I just make the implementations similar to other targets, so that will be
    more easy to mainatain.
ld/
    * testsuite/ld-riscv-elf/data-reloc*: New testcases.
    * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Added new data-reloc* testcases,
    and need to make ifunc-seperate* testcases work for rv32.
    * testsuite/ld-riscv-elf/ifunc-seperate-caller-nonplt.s: Likewise.
    * testsuite/ld-riscv-elf/ifunc-seperate-caller-plt.s: Likewise.

17 months agoRISC-V: Extract the ld code which are too complicated, and may be reused.
Nelson Chu [Sat, 25 Mar 2023 00:41:11 +0000 (08:41 +0800)]
RISC-V: Extract the ld code which are too complicated, and may be reused.

These types of codes are different for each target, I am not sure what are the
best for RISC-V, so extract them out may be more easy to compare what's the
difference.

bfd/
    * elfnn-riscv.c (RISCV_NEED_DYNAMIC_RELOC): New defined.  Extracted
    from riscv_elf_check_relocs, to see if dynamic reloc is needed for the
    specific relocation.
    (RISCV_GENERATE_DYNAMIC_RELOC): New defined.  Extracted from
    riscv_elf_relocate_section, to see if R_RISCV_32/64 need to generate
    dynamic relocation.
    (RISCV_COPY_INPUT_RELOC): New defined.  Extracted from
    riscv_elf_relocate_section, to see if R_RISCV_32/64 need to copy itslef
    tp output file.
    (RISCV_RESOLVED_LOCALLY): New defined.  Extracted from
    riscv_elf_relocate_section, to see if R_RISCV_GOT_HI20 can be resolved
    locally.

17 months agoUse the correct frame when evaluating a dynamic property
Tom Tromey [Wed, 1 Mar 2023 17:33:27 +0000 (10:33 -0700)]
Use the correct frame when evaluating a dynamic property

The test case in this patch shows an unusual situation: an Ada array
has a dynamic bound, but the bound comes from a frame that's referred
to by the static link.  This frame is correctly found when evaluating
the array variable itself, but is lost when evaluating the array's
bounds.

This patch fixes the problem by passing this frame through to
value_at_lazy in the DWARF expression evaluator.

17 months agoPass a frame to value_at_lazy and value_from_contents_and_address
Tom Tromey [Wed, 1 Mar 2023 17:33:20 +0000 (10:33 -0700)]
Pass a frame to value_at_lazy and value_from_contents_and_address

This patch adds a 'frame' parameter to value_at_lazy and ensures that
it is passed down to the call to resolve_dynamic_type.  This required
also adding a frame parameter to value_from_contents_and_address.

Nothing passes this parameter to value_at_lazy yet, so this patch
should have no visible effect.

17 months agoAdd frame parameter to resolve_dynamic_type
Tom Tromey [Wed, 1 Mar 2023 16:54:04 +0000 (09:54 -0700)]
Add frame parameter to resolve_dynamic_type

This adds a frame parameter to resolve_dynamic_type and arranges for
it to be passed through the call tree and, in particular, to all calls
to dwarf2_evaluate_property.

Nothing passes this parameter yet, so this patch should have no
visible effect.

A 'const frame_info_ptr *' is used here to avoid including frame.h
from gdbtypes.h.

17 months agoRemove version_at_least
Tom Tromey [Tue, 14 Mar 2023 13:55:49 +0000 (07:55 -0600)]
Remove version_at_least

version_at_least is a less capable variant of version_compare, so this
patch removes it.

17 months agoRewrite version_compare and rust_at_least
Tom Tromey [Tue, 14 Mar 2023 13:51:45 +0000 (07:51 -0600)]
Rewrite version_compare and rust_at_least

This rewrites version_compare to allow the input lists to have
different lengths, then rewrites rust_at_least to use version_compare.

17 months agoIntroduce rust_at_least helper proc
Tom Tromey [Mon, 27 Feb 2023 20:23:35 +0000 (13:23 -0700)]
Introduce rust_at_least helper proc

This adds a 'rust_at_least' helper proc, for checking the version of
the Rust compiler in use.  It then changes various tests to use this
with 'require'.

17 months ago[gdb/testsuite] Require gnatmake 11 for gdb.ada/verylong.exp
Tom de Vries [Wed, 29 Mar 2023 14:09:44 +0000 (16:09 +0200)]
[gdb/testsuite] Require gnatmake 11 for gdb.ada/verylong.exp

With test-case gdb.ada/verylong.exp and gnatmake 7.5.0 I run into:
...
compilation failed: gcc ... $src/gdb/testsuite/gdb.ada/verylong/prog.adb
prog.adb:16:11: warning: file name does not match unit name, should be "main.adb"
prog.adb:17:08: "Long_Long_Long_Integer" is undefined (more references follow)
gnatmake: "prog.adb" compilation error

FAIL: gdb.ada/verylong.exp: compilation prog.adb
...

AFAICT, support for Long_Long_Long_Integer was added in gcc 11.

Fix this by requiring gnatmake version 11 or higher in the test-case.

Tested on x86_64-linux.

17 months agodoc: fix informations typo in gdb.texinfo
Nils-Christian Kempke [Tue, 16 Nov 2021 16:45:58 +0000 (16:45 +0000)]
doc: fix informations typo in gdb.texinfo

Co-Authored-By: Christina Schimpe <christina.schimpe@intel.com>
17 months agogdb, infcmd: remove redundant ERROR_NO_INFERIOR in continue_command
Nils-Christian Kempke [Wed, 6 Apr 2022 08:11:23 +0000 (10:11 +0200)]
gdb, infcmd: remove redundant ERROR_NO_INFERIOR in continue_command

The ERROR_NO_INFERIOR macro is already called at the beginning of the
function continue_command.  Since target/inferior are not switched in-between,
the second call to it is redundant.

Co-Authored-By: Christina Schimpe <christina.schimpe@intel.com>
17 months agogdb: move displaced_step_dump_bytes into gdbsupport (and rename)
Andrew Burgess [Wed, 22 Mar 2023 17:22:51 +0000 (17:22 +0000)]
gdb: move displaced_step_dump_bytes into gdbsupport (and rename)

It was pointed out during review of another patch that the function
displaced_step_dump_bytes really isn't specific to displaced stepping,
and should really get a more generic name and move into gdbsupport/.

This commit does just that.  The function is renamed to
bytes_to_string and is moved into gdbsupport/common-utils.{cc,h}.  The
function implementation doesn't really change. Much...

... I have updated the function to take an array view, which makes it
slightly easier to call in a couple of places where we already have a
gdb::bytes_vector.  I've then added an inline wrapper to convert a raw
pointer and length into an array view, which is used in places where
we don't easily have a gdb::bytes_vector (or similar).

Updated all users of displaced_step_dump_bytes.

There should be no user visible changes after this commit.

Finally, I ended up having to add an include of gdb_assert.h into
array-view.h.  When I include array-view.h into common-utils.h I ran
into build problems because array-view.h calls gdb_assert.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
17 months agogdb: more debug output for displaced stepping
Andrew Burgess [Tue, 21 Feb 2023 12:38:03 +0000 (12:38 +0000)]
gdb: more debug output for displaced stepping

While investigating a displaced stepping issue I wanted an easy way to
see what GDB thought the original instruction was, and what
instruction GDB replaced that with when performing the displaced step.

We do print out the address that is being stepped, so I can track down
the original instruction, I just need to go find the information
myself.

And we do print out the bytes of the new instruction, so I can figure
out what the replacement instruction was, but it's not really easy.

Also, the code that prints the bytes of the replacement instruction
only prints 4 bytes, which clearly isn't always going to be correct.

In this commit I remove the existing code that prints the bytes of the
replacement instruction, and add two new blocks of code to
displaced_step_prepare_throw.  This new code prints the original
instruction, and the replacement instruction.  In each case we print
both the bytes that make up the instruction and the completely
disassembled instruction.

Here's an example of what the output looks like on x86-64 (this is
with 'set debug displaced on').  The two interesting lines contain the
strings 'original insn' and 'replacement insn':

  (gdb) step
  [displaced] displaced_step_prepare_throw: displaced-stepping 2892655.2892655.0 now
  [displaced] displaced_step_prepare_throw: original insn 0x401030: ff 25 e2 2f 00 00 jmp    *0x2fe2(%rip)        # 0x404018 <puts@got.plt>
  [displaced] prepare: selected buffer at 0x401052
  [displaced] prepare: saved 0x401052: 1e fa 31 ed 49 89 d1 5e 48 89 e2 48 83 e4 f0 50
  [displaced] fixup_riprel: %rip-relative addressing used.
  [displaced] fixup_riprel: using temp reg 2, old value 0x7ffff7f8a578, new value 0x401036
  [displaced] amd64_displaced_step_copy_insn: copy 0x401030->0x401052: ff a1 e2 2f 00 00 68 00 00 00 00 e9 e0 ff ff ff
  [displaced] displaced_step_prepare_throw: prepared successfully thread=2892655.2892655.0, original_pc=0x401030, displaced_pc=0x401052
  [displaced] displaced_step_prepare_throw: replacement insn 0x401052: ff a1 e2 2f 00 00 jmp    *0x2fe2(%rcx)
  [displaced] finish: restored 2892655.2892655.0 0x401052
  [displaced] amd64_displaced_step_fixup: fixup (0x401030, 0x401052), insn = 0xff 0xa1 ...
  [displaced] amd64_displaced_step_fixup: restoring reg 2 to 0x7ffff7f8a578
  0x00007ffff7e402c0 in puts () from /lib64/libc.so.6
  (gdb)

One final note.  For many targets that support displaced stepping (in
fact all targets except ARM) the replacement instruction is always a
single instruction.  But on ARM the replacement could actually be a
series of instructions.

The debug code tries to handle this by disassembling the entire
displaced stepping buffer.  Obviously this might actually print more
than is necessary, but there's (currently) no easy way to know how
many instructions to disassemble; that knowledge is all locked in the
architecture specific code.  Still I don't think it really hurts, if
someone is looking at this debug then hopefully they known what to
expect.

Obviously we can imagine schemes where the architecture specific
displaced stepping code could communicate back how many bytes its
replacement sequence was, and then our debug print code could use this
to limit the disassembly.  But this seems like a lot of effort just to
save printing a few additional instructions in some debug output.

I'm not proposing to do anything about this issue for now.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
17 months ago[gdb/testsuite] Fix gdb.guile/scm-symbol.exp for remote host
Tom de Vries [Wed, 29 Mar 2023 06:01:42 +0000 (08:01 +0200)]
[gdb/testsuite] Fix gdb.guile/scm-symbol.exp for remote host

Fix test-case gdb.guile/scm-symbol.exp for remote host by making a regexp less
strict.

Likewise in gdb.guile/scm-symtab.exp.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix /gdb.guile/scm-parameter.exp for remote host
Tom de Vries [Wed, 29 Mar 2023 06:01:42 +0000 (08:01 +0200)]
[gdb/testsuite] Fix /gdb.guile/scm-parameter.exp for remote host

Fix test-case gdb.guile/scm-parameter.exp for remote host by taking into
account that gdb_reinitialize_dir has no effect for remote host.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix gdb.guile/scm-objfile-script.exp for remote host
Tom de Vries [Wed, 29 Mar 2023 06:01:42 +0000 (08:01 +0200)]
[gdb/testsuite] Fix gdb.guile/scm-objfile-script.exp for remote host

Fix test-case gdb.guile/scm-objfile-script.exp using gdb_remote_download.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix gdb.guile/scm-objfile-script.exp for remote host
Tom de Vries [Wed, 29 Mar 2023 06:01:42 +0000 (08:01 +0200)]
[gdb/testsuite] Fix gdb.guile/scm-objfile-script.exp for remote host

Fix test-case gdb.guile/scm-objfile-script.exp using host_standard_output_file.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix gdb.guile/scm-cmd.exp without readline
Tom de Vries [Wed, 29 Mar 2023 06:01:42 +0000 (08:01 +0200)]
[gdb/testsuite] Fix gdb.guile/scm-cmd.exp without readline

Fix test-case gdb.guile/scm-cmd.exp using readline_is_used.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix gdb.guile/guile.exp for remote host
Tom de Vries [Wed, 29 Mar 2023 06:01:42 +0000 (08:01 +0200)]
[gdb/testsuite] Fix gdb.guile/guile.exp for remote host

Fix test-case gdb.guile/guile.exp for remote host using gdb_remote_download.

Tested on x86_64-linux.

17 months agoSanity check section size in bfd_init_section_compress_status
Alan Modra [Wed, 29 Mar 2023 02:15:16 +0000 (12:45 +1030)]
Sanity check section size in bfd_init_section_compress_status

This function doesn't just initialise for compression, it actually
compresses.  This patch sanity checks section size before allocating
buffers for the uncompressed contents.

* compress.c (bfd_init_section_compress_status): Sanity check
section size.

17 months agoRe: Fix an aout memory leak
Alan Modra [Tue, 28 Mar 2023 22:43:17 +0000 (09:13 +1030)]
Re: Fix an aout memory leak

We have way too much duplicated code in bfd.  Apply dd3a3d0af9f6 and
920581c57e08 to pdp11.c.

* pdp11.c (bfd_free_cached_info): Free line_buf.  Return true
if tdata.aout_data is NULL.

17 months agold testsuite CFLAGS_FOR_TARGET
Alan Modra [Tue, 28 Mar 2023 10:32:36 +0000 (21:02 +1030)]
ld testsuite CFLAGS_FOR_TARGET

run_host_cmd adds $gcc_B_opt and $ld_L_opt to the command line if it
detects the program being run is a compiler.  Since the program being
run in lto.exp linking pr28138 is "sh", we need to add these by hand.
This isn't exactly as run_host_cmd does, as it lacks reordering of
any user -B option in $CC_FOR_TARGET, but it's better than ignoring
gcc_B_opt.  This fixes a mips64 testsuite fail.

ld_compile adds CFLAGS_FOR_TARGET and other flags as well, so there
is no need for the ld_compile command line to include
CFLAGS_FOR_TARGET.  Fixing this is just a tidy.

* testsuite/ld-plugin/lto.exp: Add gcc_B_opt, CFLAGS_FOR_TARGET
and $ld_L_opt to pr28138 link line.
* testsuite/lib/ld-lib.exp (run_ld_link_tests): Don't pass
unnecessary flags to ld_compile.
(run_ld_link_exec_tests, run_cc_link_tests): Likewise.

17 months agoAutomatic date update in version.in
GDB Administrator [Wed, 29 Mar 2023 00:00:11 +0000 (00:00 +0000)]
Automatic date update in version.in

17 months agoRename "raw" to "unrelocated"
Tom Tromey [Mon, 20 Mar 2023 22:03:05 +0000 (16:03 -0600)]
Rename "raw" to "unrelocated"

Per an earlier discussion, this patch renames the existing "raw" APIs
to use the word "unrelocated" instead.

17 months agoUse unrelocated_addr in minimal symbols
Tom Tromey [Sun, 19 Mar 2023 16:24:27 +0000 (10:24 -0600)]
Use unrelocated_addr in minimal symbols

This changes minimal symbols to use unrelocated_addr.  I believe this
detected a latent bug in add_pe_forwarded_sym.

17 months agoUse unrelocated_addr in psymbols
Tom Tromey [Sun, 19 Mar 2023 15:51:32 +0000 (09:51 -0600)]
Use unrelocated_addr in psymbols

This changes psymbols themselves to use unrelocated_addr.  This
transform is largely mechanical.  I don't think it finds any bugs.

17 months agoUse unrelocated_addr in partial symbol tables
Tom Tromey [Fri, 17 Mar 2023 22:37:15 +0000 (16:37 -0600)]
Use unrelocated_addr in partial symbol tables

This changes partial symbol tables to use unrelocated_addr for the
text_high and text_low members.  This revealed some latent bugs in
ctfread.c, which are fixed here.

17 months agoMove definition of unrelocated_addr earlier
Tom Tromey [Sun, 19 Mar 2023 15:57:48 +0000 (09:57 -0600)]
Move definition of unrelocated_addr earlier

This moves the definition of unrelocated_addr a bit earlier in
symtab.h, so that it can be used elsewhere in the file.

17 months agoUse function_view in gdb_bfd_lookup_symbol
Tom Tromey [Sun, 19 Mar 2023 22:12:58 +0000 (16:12 -0600)]
Use function_view in gdb_bfd_lookup_symbol

This changes gdb_bfd_lookup_symbol to use a function_view.  This
simplifies the code a little bit.

17 months ago[gdb/testsuite] Fix gdb.btrace/multi-inferior.exp for remote host
Tom de Vries [Tue, 28 Mar 2023 20:15:18 +0000 (22:15 +0200)]
[gdb/testsuite] Fix gdb.btrace/multi-inferior.exp for remote host

Fix test-case gdb.btrace/multi-inferior.exp for remote host using
gdb_remote_download.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix gdb.btrace/gcore.exp for remote host
Tom de Vries [Tue, 28 Mar 2023 20:15:18 +0000 (22:15 +0200)]
[gdb/testsuite] Fix gdb.btrace/gcore.exp for remote host

Fix test-case gdb.btrace/gcore.exp for remote host using
host_standard_output.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix gdb.btrace/reconnect.exp for remote target
Tom de Vries [Tue, 28 Mar 2023 20:15:18 +0000 (22:15 +0200)]
[gdb/testsuite] Fix gdb.btrace/reconnect.exp for remote target

Fix test-case gdb.btrace/reconnect.exp for target board
remote-gdbserver-on-localhost using gdb_remote_download.

Tested on x86_64-linux.

17 months agoPut pretty-printers to_string output in varobj result
Tom Tromey [Thu, 26 May 2022 14:33:05 +0000 (08:33 -0600)]
Put pretty-printers to_string output in varobj result

PR mi/11335 points out that an MI varobj will not display the result
of a pretty-printer's "to_string" method.  Instead, it always shows
"{...}".

This does not seem very useful, and there have been multiple
complaints about it over the years.  This patch changes varobj to emit
this string when possible, and updates the test suite.

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

17 months agogdb/testsuite: allow "require" callbacks to provide a reason
Simon Marchi [Tue, 28 Mar 2023 12:23:05 +0000 (08:23 -0400)]
gdb/testsuite: allow "require" callbacks to provide a reason

When an allow_* proc returns false, it can be a bit difficult what check
failed exactly, if the procedure does multiple checks.  To make
investigation easier, I propose to allow the "require" callbacks to be
able to return a list of two elements: the zero/non-zero value, and a
reason string.

Use the new feature in allow_hipcc_tests to demonstrate it (it's also
where I hit actually hit this inconvenience).  On my computer (where GDB
is built with amd-dbgapi support but where I don't have a suitable GPU
target), I get:

    UNSUPPORTED: gdb.rocm/simple.exp: require failed: allow_hipcc_tests (no suitable amdgpu targets found)

vs before:

    UNSUPPORTED: gdb.rocm/simple.exp: require failed: allow_hipcc_tests

Change-Id: Id1966535b87acfcbe9eac99f49dc1196398c6578
Approved-By: Tom de Vries <tdevries@suse.de>
17 months ago[gdb/testsuite] Fix gdb.server/server-kill-python.exp for remote host
Tom de Vries [Tue, 28 Mar 2023 15:48:35 +0000 (17:48 +0200)]
[gdb/testsuite] Fix gdb.server/server-kill-python.exp for remote host

Fix test-case gdb.server/server-kill-python.exp for remote host using
gdb_remote_download.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix gdb.server/sysroot.exp for remote host
Tom de Vries [Tue, 28 Mar 2023 15:48:35 +0000 (17:48 +0200)]
[gdb/testsuite] Fix gdb.server/sysroot.exp for remote host

Fix test-case gdb.server/sysroot.exp for remote host, by:
- using gdb_remote_download, and
- disabling the "local" scenario for remote host/target, unless
  remote host == remote target.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Require non-remote host for gdb.server/multi-ui-errors.exp
Tom de Vries [Tue, 28 Mar 2023 15:48:35 +0000 (17:48 +0200)]
[gdb/testsuite] Require non-remote host for gdb.server/multi-ui-errors.exp

Require non-remote host for test-case gdb.server/multi-ui-errors.exp, because
it uses "spawn -pty", which creates a pty on build, which gdb cannot use on
remote host.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix gdb.server/solib-list.exp for remote host
Tom de Vries [Tue, 28 Mar 2023 15:48:35 +0000 (17:48 +0200)]
[gdb/testsuite] Fix gdb.server/solib-list.exp for remote host

Fix test-case gdb.server/solib-list.exp for remote host using
gdb_remote_download.

Likewise in another test-case.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix gdb.server/file-transfer.exp for remote host
Tom de Vries [Tue, 28 Mar 2023 15:48:35 +0000 (17:48 +0200)]
[gdb/testsuite] Fix gdb.server/file-transfer.exp for remote host

Fix test-case gdb.server/file-transfer.exp for remote host using
gdb_remote_download and host_standard_output_file.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix local-remote-host-native.exp for gdb.server tests
Tom de Vries [Tue, 28 Mar 2023 15:48:34 +0000 (17:48 +0200)]
[gdb/testsuite] Fix local-remote-host-native.exp for gdb.server tests

When running test-case gdb.server/stop-reply-no-thread-multi.exp with
host+target board local-remote-host-native, I run into a time-out:
...
(gdb) PASS: gdb.server/stop-reply-no-thread-multi.exp: target-non-stop=off: \
  to_disable=: disconnect
builtin_spawn /usr/bin/ssh -t -l vries 127.0.0.1 gdbserver --once \
  localhost:2346 stop-reply-no-thread-multi^M
Process stop-reply-no-thread-multi created; pid = 32600^M
Listening on port 2346^M
set remote threads-packet off^M
FAIL: gdb.server/stop-reply-no-thread-multi.exp: target-non-stop=off: \
  to_disable=: set remote threads-packet off (timeout)
...

This is due to this line in ${board}_spawn:
...
    set board_info($board,fileid) $spawn_id
...

We have the following series of events:
- gdb is spawned, setting fileid
- a few gdb commands (set height etc) are send using fileid, arrive at gdb and
  are successful
- gdbserver is spawned, overwriting fileid
- the next gdb command is sent using fileid, so it's send
  to gdbserver instead of gdb, and we run into the timeout.

There is some notion of current gdb, tracked in both gdb_spawn_id and fileid
of the host board (see switch_gdb_spawn_id).  And because the host and target
board are the same, spawning something on the target overwrites the fileid on
host, and consequently the current gdb.

Fix this by only setting fileid when spawning gdb.

Tested on x86_64-linux.

Now gdb.server/*.exp passes for host+target board local-remote-host-native,
except for file-transfer.exp.

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

17 months agogdb: use dynamic year in update-freebsd.sh
Enze Li [Wed, 1 Feb 2023 13:26:11 +0000 (21:26 +0800)]
gdb: use dynamic year in update-freebsd.sh

When running update-freebsd.sh on FreeBSD, I see the following
modification in freebsd.xml,

-<!-- Copyright (C) 2009-2023 Free Software Foundation, Inc.
+<!-- Copyright (C) 2009-2020 Free Software Foundation, Inc.

It means that each time, when we running the update-freebsd.sh on
FreeBSD, we have to correct the year of copyright manually. So fix this
issue by using dynamic year.

Tested by regenerating freebsd.xml on FreeBSD/amd64.

Reviewed-By: John Baldwin <jhb@FreeBSD.org>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
17 months ago[gdb/testsuite] Fix gdb.server/non-existing-program.exp with remote-gdbserver-on...
Tom de Vries [Tue, 28 Mar 2023 12:18:44 +0000 (14:18 +0200)]
[gdb/testsuite] Fix gdb.server/non-existing-program.exp with remote-gdbserver-on-localhost

With test-case gdb.server/non-existing-program.exp and native, I have reliably:
...
(gdb) builtin_spawn gdbserver stdio non-existing-program^M
stdin/stdout redirected^M
/bin/bash: line 0: exec: non-existing-program: not found^M
During startup program exited with code 127.^M
Exiting^M
PASS: gdb.server/non-existing-program.exp: gdbserver exits cleanly
...

But with target board remote-gdbserver-on-localhost I sometimes have:
...
(gdb) builtin_spawn /usr/bin/ssh -t -l remote-target localhost gdbserver \
  stdio non-existing-program^M
stdin/stdout redirected^M
/bin/bash: line 0: exec: non-existing-program: not found^M
During startup program exited with code 127.^M
Exiting^M
Connection to localhost closed.^M^M
PASS: gdb.server/non-existing-program.exp: gdbserver exits cleanly
...
and sometimes the exact same output, but a FAIL instead.

Fix this by replacing "Exiting\r\n$" with "Exiting\r\n" in the regexps.

Tested on x86_64-linux.

17 months agoAvoid undefined behaviour in m68hc11 md_begin
Alan Modra [Tue, 28 Mar 2023 09:55:26 +0000 (20:25 +1030)]
Avoid undefined behaviour in m68hc11 md_begin

Given p = A where p is a pointer to some type and A is an array of
that type, then the expression p - 1 + 1 evokes undefined behaviour
according to the C standard.

gcc-13 -fsanitize=address,undefined complains about this, but not
where the undefined behaviour actually occurs at tc-m68hc11.c:646.
Instead you get an error: "tc-m68hc11.c:708:20: runtime error: store
to address 0x62600000016c with insufficient space for an object of
type 'int'".  Which is a lie.  There most definitely is space there.
Oh well, diagnostics are sometimes hard to get right.  The UB is easy
to avoid.

PR 30279
* config/tc-m68hc11.c (md_begin): Avoid undefined pointer
decrement.  Remove unnecessary cast.

17 months ago[gdb/testsuite] Allow gdb.rust/expr.exp without rust compiler
Tom de Vries [Tue, 28 Mar 2023 08:22:48 +0000 (10:22 +0200)]
[gdb/testsuite] Allow gdb.rust/expr.exp without rust compiler

Proc allow_rust_tests returns 0 when there's no rust compiler, but that gives
the wrong answer for gdb.rust/expr.exp, which doesn't require it.

Fix this by using can_compile rust in the test-cases that need it, and just
returning 1 in allow_rust_tests.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Add can_compile rust
Tom de Vries [Tue, 28 Mar 2023 08:22:48 +0000 (10:22 +0200)]
[gdb/testsuite] Add can_compile rust

If I deinstall the rust compiler, I get:
...
gdb compile failed, default_target_compile: Can't find rustc --color never.
UNTESTED: gdb.rust/watch.exp: failed to prepare
...

Fix this by adding can_compile rust, and using it in allow_rust_tests, such
that we have instead:
...
UNSUPPORTED: gdb.rust/watch.exp: require failed: allow_rust_tests
...

Since the rest of the code in allow_rust_tests is also about availability of
the rust compiler, move it to can_compile.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Unsupport gdb.rust for remote host
Tom de Vries [Tue, 28 Mar 2023 08:22:48 +0000 (10:22 +0200)]
[gdb/testsuite] Unsupport gdb.rust for remote host

With test-case gdb.rust/watch.exp and remote host I run into:
...
Executing on host: gcc   watch.rs  -g  -lm   -o watch    (timeout = 300)
  ...
ld:watch.rs: file format not recognized; treating as linker script
ld:watch.rs:1: syntax error
  ...
UNTESTED: gdb.rust/watch.exp: failed to prepare
...

The problem is that find_rustc returns "" for remote host, so we fall back to gcc, which fails.

Fix this by returning 0 in allow_rust_tests for remote host.

Tested on x86_64-linux.

17 months agoubsan: elfnn-aarch64.c:4595:19: runtime error: load of value 190
Alan Modra [Tue, 28 Mar 2023 01:30:02 +0000 (12:00 +1030)]
ubsan: elfnn-aarch64.c:4595:19: runtime error: load of value 190

which is not a valid value for type '_Bool'

* elfnn-aarch64.c (stub_hash_newfunc): Clear all fields past root.

17 months agoAutomatic date update in version.in
GDB Administrator [Tue, 28 Mar 2023 00:00:13 +0000 (00:00 +0000)]
Automatic date update in version.in

17 months ago[gdb/testsuite] Fix gnat_runtime_has_debug_info for remote host
Tom de Vries [Mon, 27 Mar 2023 21:11:41 +0000 (23:11 +0200)]
[gdb/testsuite] Fix gnat_runtime_has_debug_info for remote host

Fix gnat_runtime_has_debug_info for remote host by checking for
allow_ada_tests.

This fixes an error for test-case gdb.testsuite/gdb-caching-proc.exp and
remote host.

Tested on x86_64-linux.

17 months agofbsd-nat: Use correct constant for target_waitstatus::sig.
John Baldwin [Mon, 27 Mar 2023 19:51:02 +0000 (12:51 -0700)]
fbsd-nat: Use correct constant for target_waitstatus::sig.

Use GDB_SIGNAL_TRAP instead of SIGTRAP.  This is a no-op since the
value of SIGTRAP on FreeBSD matches the value of GDB_SIGNAL_TRAP, but
it is more correct.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
17 months agofbsd-nat: Avoid a direct write to target_waitstatus::kind.
John Baldwin [Mon, 27 Mar 2023 19:51:02 +0000 (12:51 -0700)]
fbsd-nat: Avoid a direct write to target_waitstatus::kind.

This is in #ifdef'd code for a workaround for FreeBSD versions older
than 11.1 which is why it wasn't caught earlier.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
17 months agofbsd-nat: Add missing spaces.
John Baldwin [Mon, 27 Mar 2023 19:51:02 +0000 (12:51 -0700)]
fbsd-nat: Add missing spaces.

No functional change, just style fixes.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
17 months agogprofng: 30089 [display text] Invalid number of threads
Vladimir Mezentsev [Thu, 23 Mar 2023 18:46:08 +0000 (11:46 -0700)]
gprofng: 30089 [display text] Invalid number of threads

The real problem is that libcollector doesn't interpose thread_create@GLIBC_2.34
We interpose a lot of libC functions (dlopen, fork, pthread_create, etc.).
Some of these functions have versions. For example, dlopen@GLIBC_2.34,
dlopen@GLIBC_2.17, dlopen@GLIBC_2.2.5, etc.
We have to interpose each of the functions because we don't know
which version of libC will be used during profiling.
Historically, we have used three versions of scripts (mapfile.aarch64-Linux,
mapfile.amd64-Linux, mapfile.intel-Linux).
Three are not needed. One is enough

The fixes below include:
 - merged all version symbols into one version script.
 - added new version symbols which are defined in latest versions of libC.
 - removed unused defines and duplicated code.
 - added the DCL_FUNC_VER macro to define the version symbols.

Tested on x86_64 and aarch64 (OL8/OL9). No regression.

gprofng/ChangeLog
2023-03-23  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

PR gprofng/30089
* libcollector/Makefile.am: Use libgprofng.ver instead of mapfile.*
* libcollector/configure.ac: Delete GPROFNG_VARIANT.
* src/collector_module.h: Move the SYMVER_ATTRIBUTE macro to collector.h
* libcollector/collector.h: Add macros (SYMVER_ATTRIBUTE, DCL_FUNC_VER).
Remove unused defines.
* libcollector/dispatcher.c: Interpose functions from libC.
Clean up the old code.
* libcollector/iotrace.c: Likewise.
* libcollector/libcol_util.c: Likewise.
* libcollector/linetrace.c: Likewise.
* libcollector/mmaptrace.c: Likewise.
* libcollector/synctrace.c: Likewise.
* libcollector/libgprofng.ver: New file.
* libcollector/Makefile.in: Rebuild.
* libcollector/configure: Rebuild.
* libcollector/mapfile.aarch64-Linux: Removed.
* libcollector/mapfile.amd64-Linux: Removed.
* libcollector/mapfile.intel-Linux: Removed.
* libcollector/mapfile.sparc-Linux: Removed.
* libcollector/mapfile.sparcv9-Linux: Removed.

17 months agolinux-nat: introduce pending_status_str
Pedro Alves [Fri, 12 Nov 2021 20:50:29 +0000 (20:50 +0000)]
linux-nat: introduce pending_status_str

I noticed that some debug log output printing an lwp's pending status
wasn't considering lp->waitstatus.  This fixes it, by introducing a
new pending_status_str function.

Also fix the comment in gdb/linux-nat.h describing
lwp_info::waitstatus and details the description of lwp_info::status
while at it.

Change-Id: I66e5c7a363d30a925b093b195d72925ce5b6b980
Approved-By: Andrew Burgess <aburgess@redhat.com>
17 months agodisplaced step: pass down target_waitstatus instead of gdb_signal
Pedro Alves [Tue, 22 Jun 2021 14:42:51 +0000 (15:42 +0100)]
displaced step: pass down target_waitstatus instead of gdb_signal

This commit tweaks displaced_step_finish & friends to pass down a
target_waitstatus instead of a gdb_signal.  This is needed because a
patch later in the step-over-{thread-exit,clone] series will want to
make displaced_step_buffers::finish handle
TARGET_WAITKIND_THREAD_EXITED.  It also helps with the
TARGET_WAITKIND_THREAD_CLONED patch later in that same series.

It's also a bit more logical this way, as we don't have to pass down
signals when the thread didn't actually stop for a signal.  So we can
also think of it as a clean up.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27338
Change-Id: I4c5d338647b028071bc498c4e47063795a2db4c0
Approved-By: Andrew Burgess <aburgess@redhat.com>
17 months ago[gdb/testsuite] Fix gdb.stabs/exclfwd.exp for remote host
Tom de Vries [Mon, 27 Mar 2023 16:06:19 +0000 (18:06 +0200)]
[gdb/testsuite] Fix gdb.stabs/exclfwd.exp for remote host

Fix test-case gdb.stabs/exclfwd.exp for remote host using include_file.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix gdb.stabs/weird.exp for remote host
Tom de Vries [Mon, 27 Mar 2023 16:06:19 +0000 (18:06 +0200)]
[gdb/testsuite] Fix gdb.stabs/weird.exp for remote host

Fix test-case gdb.stabs/weird.exp for remote host by not using an absolute
destfile argument to gdb_remote_download, which doesn't work well with remotedir.

17 months ago[gdb/testsuite] Fix gdb.gdb/unittest.exp for remote host
Tom de Vries [Mon, 27 Mar 2023 15:40:06 +0000 (17:40 +0200)]
[gdb/testsuite] Fix gdb.gdb/unittest.exp for remote host

Fix test-case gdb.gdb/unittest.exp for remote host, by:
- disabling the completion tests if readline is not used, and
- not using with_gdb_cwd $dir for remote host (because it does
  not support changing to ".").

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Skip do_self_tests on remote host
Tom de Vries [Mon, 27 Mar 2023 15:40:06 +0000 (17:40 +0200)]
[gdb/testsuite] Skip do_self_tests on remote host

In do_self_tests we try to find out the location of the gdb to debug, which
will then be copied and renamed to xgdb.

In principle, the host board specifies the location of GDB, on host.

With remote host, we could upload that gdb from host to build/target, but we
would miss the data directory (which is listed as the reason to skip
do_self_tests for remote target).

We could fix that by instead taking the gdb from build instead, but that
wouldn't work with installed testing.

It seems easier to just skip this on remote host.

It could be made to work for the "[is_remote host] && [is_remote target]
&& host == target" scenario (see board local-remote-host-native.exp), but
that doesn't seem worth the effort.

Tested on x86_64-linux.

17 months agoChange symbol::line to unsigned int
Tom Tromey [Wed, 22 Mar 2023 19:43:03 +0000 (13:43 -0600)]
Change symbol::line to unsigned int

A user here at AdaCore noticed that, when debugging a certain program,
a stack frame reported line 34358, where it should have been line
99894.

After debugging a bit, I discovered:

(top) p (99894 & ~65536)
$60 = 34358

That line, symbol::line is too narrow.

This patch widens the member and changes all the uses that currently
use the narrower type.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
17 months agoFix 128-bit integer bug in Ada
Tom Tromey [Wed, 1 Mar 2023 22:13:39 +0000 (15:13 -0700)]
Fix 128-bit integer bug in Ada

While working on 128-bit integer support, I found one spot in Ada that
needed a fix as well.

17 months agoUse gdb_gmp for scalar arithmetic
Tom Tromey [Wed, 1 Mar 2023 22:13:21 +0000 (15:13 -0700)]
Use gdb_gmp for scalar arithmetic

This changes gdb to use scalar arithmetic for expression evaluation.

I suspect this patch is not truly complete, as there may be code paths
that still don't correctly handle 128-bit integers.  However, many
things do work now.

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

17 months agoUse value_true in value_equal and value_less
Tom Tromey [Wed, 1 Mar 2023 19:23:43 +0000 (12:23 -0700)]
Use value_true in value_equal and value_less

Both value_equal and value_less use value_as_long to check a
presumably boolean result of calling value_binop.  However,
value_binop in this case actually returns an int as wide as its
arguments, and this approach can then fail for integers wider than
LONGEST.  Instead, rewrite this in a form that works for any size
integer.

17 months agoSimplify binop_promote
Tom Tromey [Tue, 28 Feb 2023 14:03:55 +0000 (07:03 -0700)]
Simplify binop_promote

binop_promote currently only handles integer sizes up to
builtin_long_long.  However, this may not handle 128-bit types.
Simplify this code, unify the C and non-C (but not OpenCL, as I don't
know how to test this) cases, and handle 128-bit integers as well.

This still doesn't exactly follow C or C++ rules.  This could be
implemented, but if so, I think it makes more sense as a C-specific
expression node.

17 months agoAdd value_as_mpz and value_from_mpz
Tom Tromey [Mon, 27 Feb 2023 18:57:24 +0000 (11:57 -0700)]
Add value_as_mpz and value_from_mpz

This adds the two new functions, value_as_mpz and value_from_mpz,
useful for manipulation values via gdb_mpz.

17 months agoAdd truncation mode to gdb_mpz
Tom Tromey [Wed, 1 Mar 2023 19:58:11 +0000 (12:58 -0700)]
Add truncation mode to gdb_mpz

This renames gdb_mpz::safe_export to export_bits, and adds a new flag
to export a truncated value.  This is needed by value arithmetic.

17 months agoAvoid a copy in gdb_mpz::safe_export
Tom Tromey [Wed, 1 Mar 2023 19:33:27 +0000 (12:33 -0700)]
Avoid a copy in gdb_mpz::safe_export

Currently, gdb_mpz::safe_export will always make a copy of *this.
However, this copy isn't always needed.  This patch makes this code
slightly more efficient, by avoiding the copy when possible.

17 months agoAdd many operators to gdb_mpz
Tom Tromey [Mon, 27 Feb 2023 18:43:09 +0000 (11:43 -0700)]
Add many operators to gdb_mpz

This adds many operator overloads and other useful methods to gdb_mpz.
This is preparation for using this class for scalar arithmetic in gdb
expression evaluation.

17 months agoPopulate seen_names hash in cooked_index_shard::do_finalize
Tom Tromey [Fri, 10 Feb 2023 14:18:15 +0000 (07:18 -0700)]
Populate seen_names hash in cooked_index_shard::do_finalize

Hannes pointed out that cooked_index_shard::do_finalize never
populates the seen_names hash table.  This patch adds the necessary
store.  This reduces memory use a little for "gdb gdb":

(before) Space used: 28909568 (+0 for this command)
(after)  Space used: 28884992 (+0 for this command)

What this means, btw, is that in gdb there are not many symbols that
are both mentioned in many CUs and that also require name
canonicalization.  It's possible this would differ in other programs.

17 months ago[gdb/testsuite] Fix gdb.asm/asm-source.exp for remote host
Tom de Vries [Mon, 27 Mar 2023 12:33:15 +0000 (14:33 +0200)]
[gdb/testsuite] Fix gdb.asm/asm-source.exp for remote host

Fix test-case gdb.asm/asm-source.exp for remote host using
host_standard_output_file and gdb_remote_download.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix gdb.dwarf2/imported-unit-bp-c.exp for remote host
Tom de Vries [Mon, 27 Mar 2023 11:58:10 +0000 (13:58 +0200)]
[gdb/testsuite] Fix gdb.dwarf2/imported-unit-bp-c.exp for remote host

Fix test-case gdb.dwarf2/imported-unit-bp-c.exp on remote by removing a
downloaded source file.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Unsupport gdb.dwarf2/gdb-add-index-symlink.exp for remote host
Tom de Vries [Mon, 27 Mar 2023 11:58:10 +0000 (13:58 +0200)]
[gdb/testsuite] Unsupport gdb.dwarf2/gdb-add-index-symlink.exp for remote host

Declare test-case gdb.dwarf2/gdb-add-index-symlink.exp unsupported for remote
host, because the current implementation of gdb_ensure_index doesn't support it.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix gdb.dwarf2/gdb-index-cxx.exp for remote host
Tom de Vries [Mon, 27 Mar 2023 11:58:10 +0000 (13:58 +0200)]
[gdb/testsuite] Fix gdb.dwarf2/gdb-index-cxx.exp for remote host

Fix test-case gdb.dwarf2/gdb-index-cxx.exp for remote host using
host_standard_output_file.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix gdb.dwarf2/enqueued-cu-base-addr.exp for remote host
Tom de Vries [Mon, 27 Mar 2023 11:58:10 +0000 (13:58 +0200)]
[gdb/testsuite] Fix gdb.dwarf2/enqueued-cu-base-addr.exp for remote host

Fix test-case gdb.dwarf2/enqueued-cu-base-addr.exp for remote host by using
$testfile instead $binfile.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix gdb.dwarf2/gdb-index.exp on remote host
Tom de Vries [Mon, 27 Mar 2023 11:58:10 +0000 (13:58 +0200)]
[gdb/testsuite] Fix gdb.dwarf2/gdb-index.exp on remote host

Fix test-case gdb.dwarf2/gdb-index.exp on remote host using
gdb_remote_download and host_standard_output_file.

Also declare the test-case unsupported with readnow.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix gdb.dwarf2/per-bfd-sharing.exp for remote host
Tom de Vries [Mon, 27 Mar 2023 11:58:10 +0000 (13:58 +0200)]
[gdb/testsuite] Fix gdb.dwarf2/per-bfd-sharing.exp for remote host

Fix test-case gdb.dwarf2/per-bfd-sharing.exp for remote host using
gdb_remote_download.

Likewise in a few other test-cases.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix quoting issue in gdb.base/index-cache.exp
Tom de Vries [Mon, 27 Mar 2023 11:58:09 +0000 (13:58 +0200)]
[gdb/testsuite] Fix quoting issue in gdb.base/index-cache.exp

For test-case gdb.base/index-cache.exp and remote host, this:
...
lassign [remote_exec host sh "-c \"rm $cache_dir/*.gdb-index\""] ret
...
gives us:
...
Executing on host: sh -c rm /tmp/tmp.m3L7m2AVkL/*.gdb-index    (timeout = 300)
builtin_spawn -ignore SIGHUP sh -c rm /tmp/tmp.m3L7m2AVkL/*.gdb-index^M
rm: missing operand^M
Try 'rm --help' for more information.^M
FAIL: gdb.dwarf2/per-bfd-sharing.exp: couldn't remove files in temporary cache dir
...

Fix this using quote_for_host.  Likewise in gdb.dwarf2/per-bfd-sharing.exp.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix quoting issues in gdb.dwarf2 for remote host
Tom de Vries [Mon, 27 Mar 2023 11:58:09 +0000 (13:58 +0200)]
[gdb/testsuite] Fix quoting issues in gdb.dwarf2 for remote host

A few test-cases in gdb.dwarf2 use something like:
...
  additional_flags=\"-DFOO=BAR + 10\"
...
which doesn't work on remote host.

Fix this by introducing a new proc quote_for_host that also works for remote
host, such that we have:
...
  additional_flags=[quote_for_host -DFOO=BAR + 10]
...

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix have_index for remote host
Tom de Vries [Mon, 27 Mar 2023 11:58:09 +0000 (13:58 +0200)]
[gdb/testsuite] Fix have_index for remote host

Proc have_index is mostly used with $binfile, which gives problems
for remote host.

Fix this by using "file tail" on the proc argument.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Add missing include_file in gdb.dwarf/*.exp
Tom de Vries [Mon, 27 Mar 2023 11:58:09 +0000 (13:58 +0200)]
[gdb/testsuite] Add missing include_file in gdb.dwarf/*.exp

17 months ago[gdb/testsuite] Add test-case gdb.dlang/dlang-start-2.exp
Tom de Vries [Mon, 27 Mar 2023 11:47:51 +0000 (13:47 +0200)]
[gdb/testsuite] Add test-case gdb.dlang/dlang-start-2.exp

For test-case gdb.dlang/dlang-start.exp, I run into:
...
UNSUPPORTED: gdb.dlang/dlang-start.exp: require failed: can_compile d
...

My distro has no support for gdc, but I'd like to have the test-case
running and passing, so let's rewrite the test-case using dwarf assembly
and add it alongside (rather than replacing it, because it's good to use
actual compiler output if we have it available).

My distro does have a package providing dmd, so let's mimic that debug info in
the dwarf assembly.  This gives us:
...
(gdb) start ^M
Temporary breakpoint 1 at 0x4004ab^M
Starting program: dlang-start-2 ^M
^M
Temporary breakpoint 1, 0x00000000004004ab in _Dmain ()^M
...

The "_Dmain ()" should probably be "D main", I've filed PR30276 about that.

Also add a "show language" to check that we automatically set the language
correctly to D.

Note that the dwarf assembly also describes main, otherwise the test-case
doesn't function as regression test for commit 47fe57c9281 ("Fix "start" for
D, Rust, etc").

Tested on x86_64-linux.

17 months agoTidy tc-ppc.c XCOFF auxent access
Alan Modra [Mon, 27 Mar 2023 06:32:15 +0000 (17:02 +1030)]
Tidy tc-ppc.c XCOFF auxent access

It's better not to drill down into u.auxent but instead use a pointer
to the combined_entry_type.  That way the fix_scnlen field is
available, and no one looking at the codes needs to wonder whether
coffsymbol (symbol_get_bfdsym (sym))->native[i + 1] is the same
auxent.

* config/tc-ppc.c (ppc_frob_symbol): Tidy XCOFF auxent access.
(ppc_adjust_symtab): Likewise.

17 months agoRemove coff_pointerize_aux table_end param
Alan Modra [Mon, 27 Mar 2023 06:15:57 +0000 (16:45 +1030)]
Remove coff_pointerize_aux table_end param

I'm fairly certain the table_end checks are redundant now.  This
patch reverts commit 334d4ced42d3.

* coffgen.c (coff_pointerize_aux): Remove table_end parameter.
(coff_get_normalized_symtab): Adjust to suit.

17 months agoUse stdint types in coff internal_auxent
Alan Modra [Sat, 25 Mar 2023 10:45:46 +0000 (21:15 +1030)]
Use stdint types in coff internal_auxent

long is a poor choice of type to store 32-bit values read from
objects files by H_GET_32.  H_GET_32 doesn't sign extend so tests like
that in gdb/coffread.c for "negative" values won't work if long is
larger than 32 bits.  If long is 32-bit then code needs to be careful
to not accidentally index negative array elements.  (I'd rather see a
segfault on an unmapped 4G array index than silently reading bogus
data.)  long is also a poor choice for x_sect.s_scnlen, which might
have 64-bit values.  It's better to use unsigned exact width types to
avoid surprises.

I decided to change the field names too, which makes most of this
patch simply renaming.  Besides that there are a few places where
casts are no longer needed, and where printf format strings or tests
need adjusting.

include/
* coff/internal.h (union internal_auxent): Use unsigned stdint
types.  Rename l fields to u32 and u64 as appropriate.
bfd/
* coff-bfd.c,
* coff-rs6000.c,
* coff64-rs6000.c,
* coffcode.h,
* coffgen.c,
* cofflink.c,
* coffswap.h,
* peXXigen.c,
* xcofflink.c: Adjust to suit internal_auxent changes.
binutils/
* rdcoff.c: Adjust to suit internal_auxent changes.
gas/
* config/obj-coff.h,
* config/tc-ppc.c: Adjust to suit internal_auxent changes.
gdb/
* coffread.c,
* xcoffread.c: Adjust to suit internal_auxent changes.
ld/
* pe-dll.c: Adjust to suit internal_auxent changes.

17 months agoSet proper union selector tag
Alan Modra [Mon, 27 Mar 2023 05:51:05 +0000 (16:21 +1030)]
Set proper union selector tag

* coff-bfd.c (bfd_coff_get_auxent): After converting sym pointer
to an index, reset the union tag.

17 months agocoffgrok access of u.auxent.x_sym.x_tagndx.p
Alan Modra [Sun, 26 Mar 2023 08:56:46 +0000 (19:26 +1030)]
coffgrok access of u.auxent.x_sym.x_tagndx.p

u.auxent.x_sym.x_tagndx is a union.  The p field is only valid when
fix_tag is set.  This patch fixes code in coffgrok.c that accessed the
field without first checking fix_tag, and removes a whole lot of code
validating bogus pointers to prevent segfaults (which no longer
happen, I checked the referenced PR 17512 testcases).  The patch also
documents this in the fix_tag comment, makes is_sym a bitfield, and
sorts the selecter fields a little.

bfd/
* coffcode.h (combined_entry_type): Make is_sym a bitfield.
Sort and comment on union selectors.
* libcoff.h: Regenerate.
binutils/
* coffgrok.c (do_type): Make aux a combined_entry_type.  Test
fix_tag before accessing u.auxent.x_sym.x_tagndx.p.  Remove
now unnecessary pointer bounds checking.

17 months agoDuplicate DW_AT_call_file leak
Alan Modra [Sun, 26 Mar 2023 08:19:13 +0000 (18:49 +1030)]
Duplicate DW_AT_call_file leak

When given two or more DW_AT_call_file for a given function we
currently leak the concat memory.

* dwarf2.c (scan_unit_for_symbols): Don't leak on duplicate
DW_AT_call_file.

17 months agoXCOFF sanity check
Alan Modra [Fri, 24 Mar 2023 23:13:40 +0000 (09:43 +1030)]
XCOFF sanity check

* coffcode.h (coff_pointerize_aux_hook): Sanity check
x_csect.x_scnlen against raw_syment_count.

17 months agoAdd an option to the gold linker to put its version string into the .comment section.
Nick Clifton [Mon, 27 Mar 2023 10:10:10 +0000 (11:10 +0100)]
Add an option to the gold linker to put its version string into the .comment section.

  PR 30187
  * options.h (class General_options): Add enable-linker-version.
  * layout.cc (Layout::create_gold_note): If linker-version is enabled put the version string into the .comment section.

17 months ago[gdb/testsuite] Handle missing gdc in gdb.dlang/dlang-start.exp
Tom de Vries [Mon, 27 Mar 2023 09:35:26 +0000 (11:35 +0200)]
[gdb/testsuite] Handle missing gdc in gdb.dlang/dlang-start.exp

On openSUSE Leap 15.4, I get:
...
Running gdb.dlang/dlang-start.exp ...
gdb compile failed, default_target_compile: Can't find gdc.
UNTESTED: gdb.dlang/dlang-start.exp: failed to prepare
...

Fix this by:
- introducing a new proc can_compile, and
- requiring "can_compile d" in the test-case,
such that I have instead:
...
Running gdb.dlang/dlang-start.exp ...
UNSUPPORTED: gdb.dlang/dlang-start.exp: require failed: can_compile d
...

Tested on x86_64-linux, on openSUSE Leap 15.4 and Fedora 37.

17 months ago[gdb/testsuite] Remove superfluous pid in temp files
Tom de Vries [Mon, 27 Mar 2023 09:35:26 +0000 (11:35 +0200)]
[gdb/testsuite] Remove superfluous pid in temp files

While trying to use gdb_can_simple_compile with a d program, I ran into:
...
/data/vries/gdb/f37/build/gdb/testsuite/temp/105856/can_compile_d-105856.d: \
  error: module 'can_compile_d-105856' has non-identifier characters in \
  filename, use module declaration instead
...

The d compiler has a problem with the filename can_compile_d-105856.d, which
contains the pid.  The pid is added by gdb_simple_compile:
...
    set obj [standard_temp_file $name-[pid].$postfix]
...
but it's unnecessary because standard_temp_file already uses the pid.

Fix this by removing "[pid]" in all calls to standard_temp_file.

Tested on x86_64-linux.

17 months agoAutomatic date update in version.in
GDB Administrator [Mon, 27 Mar 2023 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

17 months ago[gdb/testsuite] Introduce allow_dap_tests
Tom de Vries [Sun, 26 Mar 2023 11:44:58 +0000 (13:44 +0200)]
[gdb/testsuite] Introduce allow_dap_tests

Simon pointed out that with gdb.dap/*.exp and target board
native-gdbserver, we run into problems.

I see for each test-case:
...
+++ run
Traceback (most recent call last):
  File "startup.py", line 146, in exec_and_log
    output = gdb.execute(cmd, from_tty=True, to_string=True)
gdb.error: Don't know how to run.  Try "help target".
...

Likewise with target board native-extended-gdbserver.

Fix this by:
- adding a new proc allow_dap_tests,
- using it in all the gdb.dap tests, and
- bailing out if GDBFLAGS/INTERNAL_GDBFLAGS contains
  "set auto-connect-native-target off".

Tested on x86_64-linux.

Reported-By: Simon Marchi <simon.marchi@efficios.com>
Approved-By: Tom Tromey <tom@tromey.com>
17 months agoAutomatic date update in version.in
GDB Administrator [Sun, 26 Mar 2023 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in