]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
16 months agogas: use "stack trace" instead of "unwind" for SFrame
Indu Bhagat [Thu, 2 Feb 2023 08:48:59 +0000 (00:48 -0800)] 
gas: use "stack trace" instead of "unwind" for SFrame

SFrame format is meant for generating stack traces only.

gas/
* as.c: Replace the use of "unwind" with "stack trace".
* config/tc-aarch64.c: Likewise.
* config/tc-aarch64.h: Likewise.
* config/tc-i386.c: Likewise.
* config/tc-i386.h: Likewise.
* gen-sframe.c: Likewise.
* gen-sframe.h: Likewise.
* testsuite/gas/cfi-sframe/cfi-sframe-aarch64-2.s: Likewise.
* testsuite/gas/cfi-sframe/cfi-sframe-common-8.s: Likewise.
* testsuite/gas/cfi-sframe/common-empty-2.s: Likewise.
* testsuite/gas/cfi-sframe/common-empty-3.s: Likewise.

16 months agosframe: use "stack trace" instead of "unwind" for SFrame
Indu Bhagat [Thu, 2 Feb 2023 08:47:38 +0000 (00:47 -0800)] 
sframe: use "stack trace" instead of "unwind" for SFrame

SFrame format is meant for generating stack traces only.

include/
* sframe.h: Fix comments in the header file.

16 months agolibsframe/doc: use "stack trace" instead of "unwind" for SFrame
Indu Bhagat [Thu, 2 Feb 2023 08:47:22 +0000 (00:47 -0800)] 
libsframe/doc: use "stack trace" instead of "unwind" for SFrame

SFrame format is meant for generating stack traces only.

libsframe/
* doc/sframe-spec.texi: Use "stack trace" instead of "unwind".

16 months agold-elf/merge test update
Alan Modra [Wed, 1 Feb 2023 23:19:00 +0000 (09:49 +1030)] 
ld-elf/merge test update

The merge test fais on numerous targets because they don't support the
necessary pc-relative relocs.  This patch removes that part of the
merge test, and makes references to the merged strings from .data
rather than .text to better support targets that relax text by
default.

16 months agoAutomatic date update in version.in
GDB Administrator [Thu, 2 Feb 2023 00:00:12 +0000 (00:00 +0000)] 
Automatic date update in version.in

16 months agoobj-elf.h BYTES_IN_WORD
Alan Modra [Wed, 1 Feb 2023 13:04:16 +0000 (23:34 +1030)] 
obj-elf.h BYTES_IN_WORD

Don't define this.  It is defined just before elf-bfd.h is included,
but doesn't have any relevance there.  Instead is for aout64.h where
the default is 4 anyway.

16 months agogas obj_end
Alan Modra [Wed, 1 Feb 2023 12:41:30 +0000 (23:11 +1030)] 
gas obj_end

Provide a way for config/obj-* to clean up at end of assembly, and do
so for ELF.

* obj.h (struct format_ops): Add "end".
* config/obj-aout.c (aout_format_ops): Init new field.
* config/obj-coff.c (coff_format_ops): Likewise.
* config/obj-ecoff.c (ecoff_format_ops): Likewise.
* config/obj-elf.c (elf_format_ops): Likewise.
(elf_begin): Move later in file.  Clear some more variables.
(comment_section): Make file scope.
(free_section_idx): Rewrite.
(elf_adjust_symtab): Expand str_htab_create call and use
free_section_idx as delete function.
(elf_frob_file_after_relocs): Don't clean up groups.indexes here.
(elf_end): New function.
* config/obj-elf.h (obj_end): Define.
* config/obj-multi.h (obj_end): Define.
* output-file.c (output_file_close): Call obj_end.

16 months agogdbserver: Add PID parameter to linux_get_auxv and linux_get_hwcap
Thiago Jung Bauermann [Thu, 18 Aug 2022 18:21:18 +0000 (18:21 +0000)] 
gdbserver: Add PID parameter to linux_get_auxv and linux_get_hwcap

This patch doesn't change gdbserver behaviour, but after later changes are
made it avoids a null pointer dereference when HWCAP needs to be obtained
for a specific process while current_thread is nullptr.

Fixing linux_read_auxv, linux_get_hwcap and linux_get_hwcap2 to take a PID
parameter seems more correct than setting current_thread in one particular
code path.

Changes are propagated to allow passing the new parameter through the call
chain.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
16 months agogdbserver: Add assert in find_register_by_number
Thiago Jung Bauermann [Tue, 16 Aug 2022 17:18:47 +0000 (17:18 +0000)] 
gdbserver: Add assert in find_register_by_number

It helped me during development, catching bugs closer to when they actually
happened.

Also remove the equivalent gdb_assert in regcache_raw_read_unsigned, since
it's checking the same condition a few frames above.

Suggested-By: Simon Marchi <simon.marchi@efficios.com>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
16 months agogdb/testsuite: fix fetch_src_and_symbols.exp with native-gdbserver board
Andrew Burgess [Wed, 1 Feb 2023 17:09:47 +0000 (17:09 +0000)] 
gdb/testsuite: fix fetch_src_and_symbols.exp with native-gdbserver board

I noticed that the gdb.debuginfod/fetch_src_and_symbols.exp script
doesn't work with the native-gdbserver board, I see this error:

  ERROR: tcl error sourcing /tmp/build/gdb/testsuite/../../../src/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp.
  ERROR: gdbserver does not support run without extended-remote
      while executing
  "error "gdbserver does not support $command without extended-remote""
      (procedure "gdb_test_multiple" line 51)
      invoked from within

This was introduced with this commit:

  commit 7dd38e31d67c2548b52bea313ab18e40824c05da
  Date:   Fri Jan 6 18:45:27 2023 -0500

      gdb/linespec.c: Fix missing source file during breakpoint re-set

The problem is that the above commit introduces a direct use of the
"run" command, which doesn't work with 'target remote' targets, as
exercised by the native-gdbserver board.

To avoid this, in this commit I switch to using runto_main.  However,
calling runto_main will, by default, delete all the currently set
breakpoints.  As the point of the above commit was to check that a
breakpoint set before stating an inferior would be correctly re-set,
we need to avoid this breakpoint deleting behaviour.

To do this I make use of with_override, and override the
delete_breakpoints proc with a dummy proc which does nothing.

By reverting the GDB changes in commit 7dd38e31d67c I have confirmed
that even after my changes in this commit, the test still fails.  But
with the fixes in commit 7dd38e31d67c, this test now passed using the
unix, native-gdbserver, and native-extended-gdbserver boards.

16 months agogdb: defer warnings when loading separate debug files
Alexandra Hájková [Tue, 24 Jan 2023 17:13:38 +0000 (18:13 +0100)] 
gdb: defer warnings when loading separate debug files

Currently, when GDB loads debug information from a separate debug
file, there are a couple of warnings that could be produced if things
go wrong.

In find_separate_debug_file_by_buildid (build-id.c) GDB can give a
warning if the separate debug file doesn't include any actual debug
information, and in separate_debug_file_exists (symfile.c) we can warn
if the CRC checksum in the separate debug file doesn't match the
checksum in the original executable.

The problem here is that, when looking up debug information, GDB will
try several different approaches, lookup by build-id, lookup by
debug-link, and then a lookup from debuginfod.  GDB can potentially
give a warning from an earlier attempt, and then succeed with a later
attempt.  In the cases I have run into this is primarily a warning
about some out of date debug information on my machine, but then GDB
finds the correct information using debuginfod.  This can be confusing
to a user, they will see warnings from GDB when really everything is
working just fine.

For example:

  warning: the debug information found in "/usr/lib/debug//lib64/ld-2.32.so.debug" \
      does not match "/lib64/ld-linux-x86-64.so.2" (CRC mismatch).

This diagnostic was printed on Fedora 33 even when the correct
debuginfo was downloaded.

In this patch I propose that we defer any warnings related to looking
up debug information from a separate debug file.  If any of the
approaches are successful then GDB will not print any of the warnings.
As far as the user is concerned, everything "just worked".  Only if
GDB completely fails to find any suitable debug information will the
warnings be printed.

The crc_mismatch test compiles two executables: crc_mismatch and
crc_mismatch-2 and then strips them of debuginfo creating separate
debug files. The test then replaces crc_mismatch-2.debug with
crc_mismatch.debug to trigger "CRC mismatch" warning. A local
debuginfod server is setup to supply the correct debug file, now when
GDB looks up the debug info no warning is given.

The build-id-no-debug-warning.exp is similar to the previous test. It
triggers the "separate debug info file has no debug info" warning by
replacing the build-id based .debug file with the stripped binary and
then loading it to GDB.  It then also sets up local debuginfod server
with the correct debug file to download to make sure no warnings are
emitted.

16 months agoFix compilation of the assembler with sanitization enabled.
Nick Clifton [Wed, 1 Feb 2023 09:49:07 +0000 (09:49 +0000)] 
Fix compilation of the assembler with sanitization enabled.

  * dwarf2dbg.c (emit_inc_line_addr): Use unsigned constants when checking addr_delta.

16 months agoRecursion in as_info_where
Alan Modra [Wed, 1 Feb 2023 06:23:27 +0000 (16:53 +1030)] 
Recursion in as_info_where

This function has a gas_assert, ie. possible call to as_abort, which
calls as_report_context, which calls as_info_where.

* messages.c (as_info_where): Don't gas_assert.

16 months agogdb/dwarf: rename cooked_index_vector to cooked_index
Simon Marchi [Tue, 31 Jan 2023 18:27:21 +0000 (13:27 -0500)] 
gdb/dwarf: rename cooked_index_vector to cooked_index

See previous patch's commit message for rationale.

Change-Id: I6b8cdc045dffccc1c01ed690ff258af09f6ff076
Approved-By: Tom Tromey <tom@tromey.com>
16 months agogdb/dwarf: rename cooked_index to cooked_index_shard
Simon Marchi [Tue, 31 Jan 2023 18:27:20 +0000 (13:27 -0500)] 
gdb/dwarf: rename cooked_index to cooked_index_shard

I propose to rename cooked_index_vector and cooked_index such that the
"main" object, that is the entry point to the index, is called
cooked_index.  The fact that the cooked index is implemented as a vector
of smaller indexes is an implementation detail.

This patch renames cooked_index to cooked_index_shard.  The following
patch renames cooked_index_vector to cooked_index.

Change-Id: Id650f97dcb23c48f8409fa0974cd093ca0b75177
Approved-By: Tom Tromey <tom@tromey.com>
16 months ago[gas] Emit v2 .debug_line for -gdwarf-2
Tom de Vries [Wed, 1 Feb 2023 00:13:37 +0000 (01:13 +0100)] 
[gas] Emit v2 .debug_line for -gdwarf-2

Currently, when using -gdwarf-2, gas emits a v3 .debug_line contribution.

Fix this by emitting a v2 .debug_line contribution instead.

gas/ChangeLog:

2023-01-31  Tom de Vries  <tdevries@suse.de>

PR 23941
* dwarf2dbg.c (DWARF2_LINE_VERSION): Set to 2 for -gdwarf-2.
(DWARF2_LINE_OPCODE_BASE): Handle DWARF2_LINE_VERSION == 2.
(dwarf2_directive_loc): Bump dwarf_level when encountering
v3 .loc options.
(out_debug_line): Don't output v3 standard opcodes for v2.
* testsuite/gas/i386/debug1.d: Update.
* testsuite/gas/i386/dwarf2-line-1.d: Update.
* testsuite/gas/i386/dwarf2-line-4.d: Update.

16 months agoAutomatic date update in version.in
GDB Administrator [Wed, 1 Feb 2023 00:00:29 +0000 (00:00 +0000)] 
Automatic date update in version.in

16 months agogdb: add nullptr check to cooked_index_functions::dump
Simon Marchi [Tue, 31 Jan 2023 15:57:21 +0000 (10:57 -0500)] 
gdb: add nullptr check to cooked_index_functions::dump

Since commit 7d82b08e9e0a ("gdb/dwarf: dump cooked index contents in
cooked_index_functions::dump"), we see:

    maint print objfiles /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.dwarf2/dw2-error/dw2-error^M
    ^M
    Object file /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.dwarf2/dw2-error/dw2-error:  Objfile at 0x614000005040, bfd at 0x6120000e08c0, 15 minsyms^M
    ^M
    Cooked index in use:^M
    ^M
    /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/gdb-checked-static-cast.h:58: internal-error: checked_static_cast: Assertion `result != nullptr' failed.^M
    A problem internal to GDB has been detected,^M
    further debugging may prove unreliable.^M
    ----- Backtrace -----^M
    FAIL: gdb.dwarf2/dw2-error.exp: maint print objfiles /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.dwarf2/dw2-error/dw2-error (GDB internal error)

The problem is that when cooked_index_functions fails to build an index,
per_objfile->index_table is nullptr.  Therefore, add a nullptr check,
like other methods of cooked_index_functions already do.

Print the "Cooked index in use" message after the nullptr check, such
that if the cooked index failed to build, that message is not printed.

Change-Id: Id67aef592e76c41b1e3bde9838a4e36cef873253

16 months agogdbsupport: allow passing nullptr to checked_static_cast
Simon Marchi [Tue, 31 Jan 2023 15:57:20 +0000 (10:57 -0500)] 
gdbsupport: allow passing nullptr to checked_static_cast

Both static_cast and dynamic_cast handle nullptr (they return nullptr),
so I think checked_static_cast should too.  This will allow doing a null
check after a checked_static_cast:

  cooked_index_vector *table
    = (gdb::checked_static_cast<cooked_index_vector *>
       (per_bfd->index_table.get ()));
  if (table != nullptr)
    return;

Change-Id: If5c3134e63696f8e417c87b5f3901240c9f7ea97

16 months agogdb/testsuite: adjust ensure_gdb_index to cooked_index_functions::dump changes
Simon Marchi [Tue, 31 Jan 2023 16:41:41 +0000 (11:41 -0500)] 
gdb/testsuite: adjust ensure_gdb_index to cooked_index_functions::dump changes

Following 7d82b08e9e0a ("gdb/dwarf: dump cooked index contents in
cooked_index_functions::dump"), I see some failures like:

    (gdb) mt print objfiles with-mf^M
    ^M
    Object file /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.base/with-mf/with-mf:  Objfile at 0x614000005040, bfd at 0x6120000e08c0, 18 minsyms    ^M
    ^M
    Cooked index in use:^M
    ^M
    ...
    (gdb) FAIL: gdb.base/with-mf.exp: check if index present

This is because the format of the "Cooked index in use" line changed
slightly.  Adjust ensure_gdb_index to expect the trailing colon.

Change-Id: If0a87575c02d8a0bc0d4b8ead540c234c62760f8

16 months agogdb/testsuite: fix xfail in gdb.ada/ptype_tagged_param.exp
Simon Marchi [Tue, 31 Jan 2023 16:34:38 +0000 (11:34 -0500)] 
gdb/testsuite: fix xfail in gdb.ada/ptype_tagged_param.exp

I see:

    ERROR: wrong # args: should be "xfail message"
        while executing
    "xfail "no debug info" $gdb_test_name"
        ("uplevel" body line 3)
        invoked from within
    "uplevel {
            if {!$has_runtime_debug_info} {
                xfail "no debug info" $gdb_test_name
            } else {
                fail $gdb_test_name
            }
        }"

This is because the xfail takes only one argument, fix that.

Change-Id: I2e304d4fd3aa61067c04b5dac2be2ed34dab3190

16 months agoUpdated Swedish translation for the binutils sub-directory
Nick Clifton [Tue, 31 Jan 2023 13:02:20 +0000 (13:02 +0000)] 
Updated Swedish translation for the binutils sub-directory

16 months agoRe: Another fix for EFI generation with LTO enabled
Alan Modra [Tue, 31 Jan 2023 11:18:58 +0000 (21:48 +1030)] 
Re: Another fix for EFI generation with LTO enabled

Revert 1c66b8a03989 and instead fix the broken list pointer.

PR 29998
* pe-dll.c (build_filler_bfd): Revert last change.
* ldlang.c (lang_process): When rescanning archives for lto,
fix file_chain.tail pointer if the insert point happens to be
at the end of the list.

16 months agogas/ppc: Additional tests for DFP instructions
Andrew Burgess [Mon, 30 Jan 2023 11:47:31 +0000 (11:47 +0000)] 
gas/ppc: Additional tests for DFP instructions

I noticed that some of the Power6 DFP instructions were not covered by
the assembler tests.  I've added a new test file which I believe
covers all the DFP Power6 instructions.

The existing gas/testsuite/gas/ppc/power6.d test is called:

  POWER6 tests (includes DFP and Altivec)

And does cover some of the DFP instructions.  But, given the number of
additional instructions I'm adding I opted to add a whole new test
file.  I've left the original power6.d unchanged, so there is now some
overlap, but I don't think that should hurt much.

16 months agoRISC-V: make C-extension JAL available again for (32-bit) assembly
Jan Beulich [Tue, 31 Jan 2023 08:47:22 +0000 (09:47 +0100)] 
RISC-V: make C-extension JAL available again for (32-bit) assembly

Along with the normal JAL alias, the C-extension one should have been
moved as well by 839189bc932e ("RISC-V: re-arrange opcode table for
consistent alias handling"), for the assembler to actually be able to
use it where/when possible.

Since neither this nor any other compressed branch insn was being tested
so far, take the opportunity and introduce a new testcase covering those.

16 months agoSilence ubsan warning about 1<<31
Alan Modra [Tue, 31 Jan 2023 04:46:02 +0000 (15:16 +1030)] 
Silence ubsan warning about 1<<31

* merge.c (hash_blob): Write 1u << 31.

16 months agoPR 30060, ASAN error in bfd_cache_close
Alan Modra [Tue, 31 Jan 2023 02:09:29 +0000 (12:39 +1030)] 
PR 30060, ASAN error in bfd_cache_close

After bfd_close nothing should access bfd memory.  Now that bfd_close
always tidies up even after an error, attempting to tidy the cached
bfd list by calling bfd_cache_close is wrong and not needed.

PR 30060
* ar.c (remove_output): Don't call bfd_cache_close.
(output_bfd): Delete.
* arsup.c (ar_end): Call bfd_close_all_done, not bfd_cache_close.

16 months agotestsuite XPASSes
Alan Modra [Mon, 30 Jan 2023 00:59:34 +0000 (11:29 +1030)] 
testsuite XPASSes

This adjusts the testsuite to get rid of a number of XPASSes that have
appeared.  Someone might like to look into a better patch for the s390
change.

aarch64-pe  XPASS: weak symbols
arm-nacl  XPASS: rgn-over8
mcore-pe  XPASS: ld-scripts/provide-8
mips64-linux-gnuabi64  XPASS: vers4
mips64-linux-gnuabi64  XPASS: vers4b
mips-linux-gnu  XPASS: vers4
mips-linux-gnu  XPASS: vers4b
s390-linux-gnu  XPASS: undefined line
sh4-linux-gnu  XPASS: --gc-sections with __start_SECTIONNAME
sh-coff  XPASS: objcopy object (simple copy)
sh-coff  XPASS: objcopy executable (pr25662)

binutils/
* testsuite/binutils-all/objcopy.exp: Don't xfail "simple
copy" and "pr25662" on sh-*-coff.  Remove all non-ELF xfails
on "ELF unknown section type" test.
ld/
* testsuite/ld-elfvers/vers.exp (vers4, vers4b): Don't xfail
all mips, just xfail mips irix.
* testsuite/ld-gc/pr19161.d: Don't xfail sh.
* testsuite/ld-scripts/rgn-over8-ok.d: Don't xfail nacl.
* testsuite/ld-scripts/weak.exp: Don't xfail aarch64-pe.
* testsuite/ld-undefined/undefined.exp: Conditionally xfail
"undefined line" depending on gcc version for s390.

16 months agoAutomatic date update in version.in
GDB Administrator [Tue, 31 Jan 2023 00:00:13 +0000 (00:00 +0000)] 
Automatic date update in version.in

16 months agoRemove value_next declaration
Tom Tromey [Mon, 30 Jan 2023 23:23:11 +0000 (16:23 -0700)] 
Remove value_next declaration

value_next is declared but not defined.  It's long obsolete.  This
patch removes the stray declaration.

16 months agogdb: fix dwarf2/cooked-index.c compilation on 32-bit systems
Simon Marchi [Mon, 30 Jan 2023 20:46:15 +0000 (15:46 -0500)] 
gdb: fix dwarf2/cooked-index.c compilation on 32-bit systems

The i386 builder shows:

    ../../binutils-gdb/gdb/dwarf2/cooked-index.c: In member function ‘void cooked_index_vector::dump(gdbarch*) const’:
    ../../binutils-gdb/gdb/dwarf2/cooked-index.c:492:40: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘std::__underlying_type_impl<sect_offset, true>::type’ {aka ‘long long unsigned int’} [-Werror=format=]
      492 |       gdb_printf ("    DIE offset: 0x%lx\n",
          |                                      ~~^
          |                                        |
          |                                        long unsigned int
          |                                      %llx
      493 |     to_underlying (entry->die_offset));
          |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          |                   |
          |                   std::__underlying_type_impl<sect_offset, true>::type {aka long long unsigned int}

The die_offset's underlying type is uint64, so use PRIx64 in the format
string.

Change-Id: Ibdde4c624ed1bb50eced9a514a4e37aec70a1323

16 months agogdb: Replace memcpy with std::copy to avoid some g++ warnings on sparc
Mark Wielaard [Sun, 15 Jan 2023 00:06:16 +0000 (01:06 +0100)] 
gdb: Replace memcpy with std::copy to avoid some g++ warnings on sparc

For some reason g++ 12.2.1 on sparc produces spurious warnings for
stringop-overread and restrict in fbsd-tdep.c for a memcpy call.
Use std::copy to avoid the warnings:

In function ‘void* memcpy(void*, const void*, size_t)’,
    inlined from ‘gdb::optional<std::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > > fbsd_make_note_desc(target_object, uint32_t)’ at ../../binutils-gdb/gdb/fbsd-tdep.c:666:10:
/usr/include/bits/string_fortified.h:29:33: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ specified bound 18446744073709551612 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]

In function ‘void* memcpy(void*, const void*, size_t)’,
    inlined from ‘gdb::optional<std::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > > fbsd_make_note_desc(target_object, uint32_t)’ at ../../binutils-gdb/gdb/fbsd-tdep.c:673:10:
/usr/include/bits/string_fortified.h:29:33: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 18446744073709551612 bytes at offsets 0 and 0 overlaps 9223372036854775801 bytes at offset -9223372036854775805 [-Werror=restrict]

gdb/ChangeLog:

* fbsd-tdep.c (fbsd_make_note_desc): Use std::copy instead
of memcpy.

16 months agogdb/dwarf: dump cooked index contents in cooked_index_functions::dump
Simon Marchi [Mon, 30 Jan 2023 16:03:37 +0000 (11:03 -0500)] 
gdb/dwarf: dump cooked index contents in cooked_index_functions::dump

As I am investigating a crash I see with the cooked index, I thought it
would be useful to have a way to dump the index contents.  For those not
too familiar with it (that includes me), it can help get a feel of what
it contains and how it is structured.

The cooked_index_functions::dump function is called as part of the
"maintenance print objfiles" command.  I tried to make the output
well structured and indented to help readability, as this prints a lot
of text.

The dump function first dumps all cooked index entries, like this:

    [25] ((cooked_index_entry *) 0x621000121220)
    name:       __ioinit
    canonical:  __ioinit
    DWARF tag:  DW_TAG_variable
    flags:      0x2 [IS_STATIC]
    DIE offset: 0x21a4
    parent:     ((cooked_index_entry *) 0x6210000f9610) [std]

Then the information about the main symbol:

    main: ((cooked_index_entry *) 0x621000123b40) [main]

And finally the address map contents:

    [1] ((addrmap *) 0x6210000f7910)

      [0x0] ((dwarf2_per_cu_data *) 0)
      [0x118a] ((dwarf2_per_cu_data *) 0x60c000007f00)
      [0x1cc7] ((dwarf2_per_cu_data *) 0)
      [0x1cc8] ((dwarf2_per_cu_data *) 0x60c000007f00)
      [0x1cdf] ((dwarf2_per_cu_data *) 0)
      [0x1ce0] ((dwarf2_per_cu_data *) 0x60c000007f00)

The display of address maps above could probably be improved, to show it
more as ranges, but I think this is a reasonable start.

Note that this patch depends on Pedro Alves' patch "enum_flags
to_string" [1].  If my patch is to be merged before Pedro's series, I
will cherry-pick this patch from his series and merge it before mine.

[1] https://inbox.sourceware.org/gdb-patches/20221212203101.1034916-8-pedro@palves.net/

Change-Id: Ida13e479fd4c8d21102ddd732241778bc3b6904a

16 months agoenum_flags to_string
Pedro Alves [Tue, 25 Oct 2022 14:39:37 +0000 (15:39 +0100)] 
enum_flags to_string

This commit introduces shared infrastructure that can be used to
implement enum_flags -> to_string functions.  With this, if we want to
support converting a given enum_flags specialization to string, we
just need to implement a function that provides the enumerator->string
mapping, like so:

 enum some_flag
   {
     SOME_FLAG1 = 1 << 0,
     SOME_FLAG2 = 1 << 1,
     SOME_FLAG3 = 1 << 2,
   };

 DEF_ENUM_FLAGS_TYPE (some_flag, some_flags);

 static std::string
 to_string (some_flags flags)
 {
   static constexpr some_flags::string_mapping mapping[] = {
     MAP_ENUM_FLAG (SOME_FLAG1),
     MAP_ENUM_FLAG (SOME_FLAG2),
     MAP_ENUM_FLAG (SOME_FLAG3),
   };
   return flags.to_string (mapping);
 }

.. and then to_string(SOME_FLAG2 | SOME_FLAG3) produces a string like
"0x6 [SOME_FLAG2 SOME_FLAG3]".

If we happen to forget to update the mapping array when we introduce a
new enumerator, then the string representation will pretty-print the
flags it knows about, and then the leftover flags in hex (one single
number).  For example, if we had missed mapping SOME_FLAG2 above, we'd
end up with:

  to_string(SOME_FLAG2 | SOME_FLAG3)  => "0x6 [SOME_FLAG2 0x4]");

Other than in the unit tests included, no actual usage of the
functionality is added in this commit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I835de43c33d13bc0c95132f42c3f97318b875779

16 months agoFix comparator bug in cooked index
Tom Tromey [Fri, 27 Jan 2023 18:19:16 +0000 (11:19 -0700)] 
Fix comparator bug in cooked index

Simon pointed out that the cooked index template-matching patch
introduced a failure in libstdc++ debug mode.  In particular, the new
code violates the assumption of std::lower_bound and std::upper_bound
that the range is sorted with respect to the comparison.

When I first debugged this, I thought the problem was unfixable as-is
and that a second layer of filtering would have to be done.  However,
on irc, Simon pointed out that it could perhaps be solved if the
comparison function were assured that one operand always came from the
index, with the other always being the search string.

This patch implements this idea.

First, a new mode is introduced: a sorting mode for
cooked_index_entry::compare.  In this mode, strings are compared
case-insensitively, but we're careful to always sort '<' before any
other printable character.  This way, two names like "func" and
"func<param>" will be sorted next to each other -- i.e., "func1" will
not be seen between them.  This is important when searching.

Second, the compare function is changed to work in a strcmp-like way.
This makes it easier to test and (IMO) understand.

Third, the compare function is modified so that in non-sorting modes,
the index entry is always the first argument.  This allows consistency
in compares.

I regression tested this in libstdc++ debug mode on x86-64 Fedora 36.
It fixes the crash that Simon saw.

This is v2.  I believe it addresses the review comments, except for
the 'enum class' change, as I mentioned in email on the list.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
16 months agoClean up lnp_state_machine constructor
Tom Tromey [Sat, 28 Jan 2023 15:30:57 +0000 (08:30 -0700)] 
Clean up lnp_state_machine constructor

This changes the lnp_state_machine constructor to initialize members
directly; and changes lnp_state_machine itself to initialize members
inline when possible.

Reviewed-By: Lancelot Six <lancelot.six@amd.com>
16 months agoMake addrmap const-correct in cooked index
Tom Tromey [Mon, 30 Jan 2023 15:29:36 +0000 (10:29 -0500)] 
Make addrmap const-correct in cooked index

After the cooked index is created, the addrmaps should be const.

Change-Id: I8234520ab346ced40a8dd6e478ba21fc438c2ba2

16 months agogdb: provide const-correct versions of addrmap::find and addrmap::foreach
Simon Marchi [Fri, 27 Jan 2023 19:46:50 +0000 (14:46 -0500)] 
gdb: provide const-correct versions of addrmap::find and addrmap::foreach

Users of addrmap::find and addrmap::foreach that have a const addrmap
should ideally receive const pointers to objects, to indicate they
should not be modified.  However, users that have a non-const addrmap
should still receive a non-const pointer.

To achieve this, without adding more virtual methods, make the existing
find and foreach virtual methods private and prefix them with "do_".
Add small non-const and const wrappers for find and foreach.

Obviously, the const can be cast away, but if using static_cast
instead of C-style casts, then the compiler won't let you cast
the const away.  I changed all the callers of addrmap::find and
addrmap::foreach I could find to make them use static_cast.

Change-Id: Ia8e69d022564f80d961413658fe6068edc71a094

16 months agoUse xfail in ptype_tagged_param.exp
Tom Tromey [Mon, 30 Jan 2023 15:03:33 +0000 (08:03 -0700)] 
Use xfail in ptype_tagged_param.exp

Pedro pointed out that ptype_tagged_param.exp used a kfail, but an
xfail would be more appropriate as the problem appears to be in gcc,
not gdb.

16 months agogdb: Remove workaround for the vCont packet
Christina Schimpe [Thu, 9 Dec 2021 13:18:36 +0000 (14:18 +0100)] 
gdb: Remove workaround for the vCont packet

The workaround for the vCont packet is no longer required due to the
former commit "gdb: Make global feature array a per-remote target array".
The vCont packet is now checked once when the connection is started and
the supported vCont actions are set to the target's remote state
attribute.

16 months agogdb: Add per-remote target variables for memory read and write config
Christina Schimpe [Fri, 26 Nov 2021 18:23:48 +0000 (18:23 +0000)] 
gdb: Add per-remote target variables for memory read and write config

This patch adds per-remote target variables for the configuration of
memory read- and write packet size.  It is a further change to commit
"gdb: Make global feature array a per-remote target array" to apply the
fixme notes described in commit 5b6d1e4 "Multi-target support".

The former global variables for that configuration are still available
to allow the command line configuration for all future remote
connections.  Similar to the command line configuration of the per-
remote target feature array, the commands

- set remotewritesize (deprecated)
- set remote memory-read-packet-size
- set remote memory-write-packet-size

will configure the current target (if available).  If no target is
available, the default configuration for future remote connections is
adapted.  The show command will display the current remote target's
packet size configuration.  If no remote target is selected, the default
configuration for future connections will be shown.

It is required to adapt the test gdb.base/remote.exp which is failing
for --target_board=native-extended-gdbserver.  With that board GDB
connects to gdbserver at gdb start time.  Due to this patch two loggings
"The target may not be able to.." are shown if the command 'set remote
memory-write-packet-size fixed' is executed while a target is connected
for the current inferior.  To fix this, the clean_restart command is
moved to a later time point of the test.  It is sufficient to be
connected to the server when "runto_main" is executed.  Now the
connection time is similar to a testrun with
--target_board=native-gdbserver.

To allow the user to distinguish between the packet-size configuration
for future remote connections and for the currently selected target, the
commands' loggings are adapted.

16 months agogdb: Make global feature array a per-remote target array
Christina Schimpe [Thu, 18 Nov 2021 16:13:16 +0000 (16:13 +0000)] 
gdb: Make global feature array a per-remote target array

This patch applies the appropriate FIXME notes described in commit 5b6d1e4
"Multi-target support".

"You'll notice that remote.c includes some FIXME notes.  These refer to
the fact that the global arrays that hold data for the remote packets
supported are still globals.  For example, if we connect to two
different servers/stubs, then each might support different remote
protocol features.  They might even be different architectures, like
e.g., one ARM baremetal stub, and a x86 gdbserver, to debug a
host/controller scenario as a single program.  That isn't going to
work correctly today, because of said globals.  I'm leaving fixing
that for another pass, since it does not appear to be trivial, and I'd
rather land the base work first.  It's already useful to be able to
debug multiple instances of the same server (e.g., a distributed
cluster, where you have full control over the servers installed), so I
think as is it's already reasonable incremental progress."

Using this patch it is possible to configure per-remote targets'
feature packets.

Given the following setup for two gdbservers:

~~~~
gdbserver --multi :1234
gdbserver --disable-packet=vCont --multi :2345
~~~~

Before this patch configuring of range-stepping was not possible for one
of two connected remote targets with different support for the vCont
packet.  As one of the targets supports vCont, it should be possible to
configure "set range-stepping".  However, the output of GDB looks like:

(gdb) target extended-remote :1234
Remote debugging using :1234
(gdb) add-inferior -no-connection
[New inferior 2]
Added inferior 2
(gdb) inferior 2
[Switching to inferior 2 [<null>] (<noexec>)]
(gdb) target extended-remote :2345
Remote debugging using :2345
(gdb) set range-stepping on
warning: Range stepping is not supported by the current target
(gdb) inferior 1
[Switching to inferior 1 [<null>] (<noexec>)]
(gdb) set range-stepping on
warning: Range stepping is not supported by the current target
~~~~

Two warnings are shown.  The warning for inferior 1 should not appear
as it is connected to a target supporting the vCont package.

~~~~
(gdb) target extended-remote :1234
Remote debugging using :1234
(gdb) add-inferior -no-connection
[New inferior 2]
Added inferior 2
(gdb) inferior 2
[Switching to inferior 2 [<null>] (<noexec>)]
(gdb) target extended-remote :2345
Remote debugging using :2345
(gdb) set range-stepping on
warning: Range stepping is not supported by the current target
(gdb) inferior 1
[Switching to inferior 1 [<null>] (<noexec>)]
(gdb) set range-stepping on
(gdb)
~~~~

Now only one warning is shown for inferior 2, which is connected to
a target not supporting vCont.

The per-remote target feature array is realized by a new class
remote_features, which stores the per-remote target array and
provides functions to determine supported features of the target.
A remote_target object now has a new member of that class.

Each time a new remote_target object is initialized, a new per-remote
target array is constructed based on the global remote_protocol_packets
array.  The global array is initialized in the function _initialize_remote
and can be configured using the command line.  Before this patch the
command line configuration affected current targets and future remote
targets (due to the global feature array used by all remote
targets).  This behavior is different and the configuration applies as
follows:

 - If a target is connected, the command line configuration affects the
   current connection.  All other existing remote targets are not
   affected.

 - If not connected, the command line configuration affects future
   connections.

The show command displays the current remote target's configuration.  If no
remote target is selected the default configuration for future
connections is shown.

If we have for instance the following setup with inferior 2 being
selected:
~~~~
(gdb) info inferiors
  Num  Description       Connection                Executable
  1    <null>             1 (extended-remote :1234)
* 2    <null>             2 (extended-remote :2345)
~~~~

Before this patch, if we run 'set remote multiprocess-feature-packet', the
following configuration was set:
The feature array of all remote targets (in this setup the two connected
targets) and all future remote connections are affected.

After this patch, it will be configured as follows:
The feature array of target with port :2345 which is currently selected
will be configured.  All other existing remote targets are not affected.
The show command 'show remote multiprocess-feature-packet' will display
the configuration of target with port :2345.

Due to this configuration change, it is required to adapt the test
"gdb/testsuite/gdb.multi/multi-target-info-inferiors.exp" to configure the
multiprocess-feature-packet before the connections are created.

To inform the gdb user about the new behaviour of the 'show remote
PACKET-NAME' commands and the new configuration impact for remote
targets using the 'set remote PACKET-NAME' commands the commands'
outputs are adapted.  Due to this change it is required to adapt each
test using the set/show remote 'PACKET-NAME' commands.

16 months agoAutomatic date update in version.in
GDB Administrator [Mon, 30 Jan 2023 00:00:07 +0000 (00:00 +0000)] 
Automatic date update in version.in

16 months agoAutomatic date update in version.in
GDB Administrator [Sun, 29 Jan 2023 00:00:38 +0000 (00:00 +0000)] 
Automatic date update in version.in

16 months agoAutomatic date update in version.in
GDB Administrator [Sat, 28 Jan 2023 00:00:08 +0000 (00:00 +0000)] 
Automatic date update in version.in

16 months agoMore const-correctness in cooked indexer
Tom Tromey [Fri, 27 Jan 2023 16:20:43 +0000 (09:20 -0700)] 
More const-correctness in cooked indexer

I noticed that iterating over the index yields non-const
cooked_index_entry objects.  However, after finalization, they should
not be modified.  This patch enforces this by adding const where
needed.

v2 makes the find, all_entries, and wait methods const as well.

16 months ago[gdb/testsuite] Simplify gdb.base/unwind-on-each-insn.exp.tcl
Tom de Vries [Fri, 27 Jan 2023 21:01:16 +0000 (22:01 +0100)] 
[gdb/testsuite] Simplify gdb.base/unwind-on-each-insn.exp.tcl

Recent commit 1d98e564c97 ("[gdb/testsuite] Add
gdb.base/unwind-on-each-insn-{amd64,i386}.exp") broke commit eb015bf86b6
("[gdb/testsuite] Avoid using .eh_frame in gdb.base/unwind-on-each-insn.exp"),
in the sense that gdb.base/unwind-on-each-insn.exp no longer uses
-fno-asynchronous-unwind-tables, due to trying to concatenate two lists using:
...
    lappend srcfile2_flags $nodebug_flags
...
which should instead be:
...
    lappend srcfile2_flags {*}$nodebug_flags
...

Fix this by simplifying gdb.base/unwind-on-each-insn.exp.tcl, completely
leaving the responsibility to set srcfile_flags and srcfile2_flags to each
includer.

Tested on x86_64-linux.

16 months agoInvert test in gdb.ada/ptype_tagged_param.exp
Tom Tromey [Fri, 27 Jan 2023 17:22:17 +0000 (10:22 -0700)] 
Invert test in gdb.ada/ptype_tagged_param.exp

Simon pointed out that the kfail check in
gdb.ada/ptype_tagged_param.exp is inverted.  See:

https://sourceware.org/pipermail/gdb-patches/2023-January/196296.html

This patch fixes the problem.

16 months agogdb/tui: more debug output
Andrew Burgess [Thu, 5 Jan 2023 14:42:34 +0000 (14:42 +0000)] 
gdb/tui: more debug output

Add some additional debug output that I've found really useful while
working on the previous set of patches.

Unless tui debug is turned on, then there should be no user visible
changes with this commit.

16 months agogdb/tui: avoid extra refresh_window on vertical scroll
Andrew Burgess [Thu, 5 Jan 2023 12:26:09 +0000 (12:26 +0000)] 
gdb/tui: avoid extra refresh_window on vertical scroll

While working on the previous couple of patches I noticed that when I
scroll the src and asm windows vertically, I get two refresh_window
calls.

The two calls can be traced back to
tui_source_window_base::update_source_window_as_is, in here we call
show_source_content, which calls refresh_window, and then
update_exec_info, which also calls refresh_window.

In this commit I propose making the refresh_window call in
update_exec_info optional.  In update_source_window_as_is I'll then
call update_exec_info before calling show_source_content, and pass a
flag to update_exec_info to defer the refresh.

There are places where update_exec_info is used without any subsequent
refresh_window call (e.g. when a breakpoint is updated), so
update_exec_info does not to call refresh_window in some cases, which
is why I'm using a flag to control the refresh.

With this changes I'm now only seeing a single refresh_window call for
each vertical scroll.

There should be no user visible changes after this commit.

16 months agogdb/tui: avoid extra refresh_window on horizontal scroll
Andrew Burgess [Thu, 5 Jan 2023 12:18:05 +0000 (12:18 +0000)] 
gdb/tui: avoid extra refresh_window on horizontal scroll

While working on the previous patches I noticed that in some cases I
was seeing two calls to tui_source_window_base::refresh_window when
scrolling the window horizontally.

The two calls would trigger in for the tui-disasm-long-lines.exp test
when the pad needed to be refilled.  The two called both come from
tui_source_window_base::show_source_content.  The first call is nested
within check_and_display_highlight_if_needed, while the second call is
done directly at the end of show_source_content.

The check_and_display_highlight_if_needed is being used to draw the
window box to the window, this is needed here because
show_source_content is what gets called when the window needs
updating, e.g. after a resize.  We could potentially do the boxing in
refresh_window, but then we'd be doing it each time we scroll, even
though the box doesn't need changing in this case.

However, we can move the check_and_display_highlight_if_needed to be
the last thing done in show_source_content, this means that we can
rely on the refresh_window call within it to be our single refresh
call.

There should be no user visible changes after this commit.

16 months agogdb/tui: rewrite of tui_source_window_base to handle very long lines
Andrew Burgess [Sat, 24 Dec 2022 20:45:51 +0000 (20:45 +0000)] 
gdb/tui: rewrite of tui_source_window_base to handle very long lines

This commit addresses an issue that is exposed by the test script
gdb.tui/tui-disasm-long-lines.exp, that is, tui_source_window_base
does not handle very long lines.

The problem can be traced back to the newpad call in
tui_source_window_base::show_source_content, this is where we allocate
a backing pad to hold the window content.

Unfortunately, there appears to be a limit to the size of pad that can
be allocated, and the gdb.tui/tui-disasm-long-lines.exp test goes
beyond this limit.  As a consequence the newpad call fails and returns
nullptr.

It just so happens that the reset of the tui_source_window_base code
can handle the pad being nullptr (this happens anyway when the window
is first created, so we already depend on nullptr handling), so all
that happens is the source window displays no content.

... well, sort of ... something weird does happen in the command
window, we seem to see a whole bunch of blank lines.  I've not
bothered to track down exactly what's happening there, but it's some
consequence of GDB attempting to write content to a WINDOW* that is
nullptr.

Before explaining my solution, I'll outline how things currently work:

Consider we have the following window content to display:

  aaaaaaaaaa
  bbbbbbbbbbbbbbbbbbbb
  ccccccccccccccc

the longest line here is 20 characters.  If our display window is 10
characters wide, then we will create a pad that is 20 characters wide,
and then copy the lines of content into the pad:

  .--------------------.
  |aaaaaaaaaa          |
  |bbbbbbbbbbbbbbbbbbbb|
  |ccccccccccccccc     |
  .--------------------.

Now we will copy a 10 character wide view into this pad to the
display, our display will then see:

  .----------.
  |aaaaaaaaaa|
  |bbbbbbbbbb|
  |cccccccccc|
  .----------.

As the user scrolls left and right we adjust m_horizontal_offset and
use this to select which part of the pad is copied onto the display.

The benefit of this is that we only need to copy the content to the
pad once, which includes processing the ansi escape sequences, and
then the user can scroll left and right as much as they want
relatively cheaply.

The problem then, is that if the longest content line is very long,
then we try to allocate a very large pad, which can fail.

What I propose is that we allow both the pad and the display view to
scroll.  Once we allow this, then it becomes possible to allocate a
pad that is smaller than the longest display line.  We then copy part
of the content into the pad.  As the user scrolls the view left and
right GDB will continue to copy content from the pad just as it does
right now.  But, when the user scrolls to the edge of the pad, GDB
will copy a new block of content into the pad, and then update the
view as normal.  This all works fine so long as the maximum pad size
is larger than the current window size - which seems a reasonable
restriction, if ncurses can't support a pad of a given size it seems
likely it will not support a display window of that size either.

If we return to our example above, but this time we assume that the
maximum pad size is 15 characters, then initially the pad would be
loaded like this:

  .---------------.
  |aaaaaaaaaa     |
  |bbbbbbbbbbbbbbb|
  |ccccccccccccccc|
  .---------------.

Notice that the last 5 characters from the 'b' line are no longer
included in the pad.  There is still enough content though to fill the
10 character wide display, just as we did before.

The pad contents remain unchanged until the user scrolls the display
right to this point:

  .----------.
  |aaaaa     |
  |bbbbbbbbbb|
  |cccccccccc|
  .----------.

Now, when the user scrolls right once more GDB spots that the user has
reached the end of the pad, and the pad contents are reloaded, like
this:

  .---------------.
  |aaaaa          |
  |bbbbbbbbbbbbbbb|
  |cccccccccc     |
  .---------------.

The display can now be updated from the pad again just like normal.

With this change in place the gdb.tui/tui-disasm-long-lines.exp test
now correctly loads the assembler code, and we can scroll around as
expected.

Most of the changes are pretty mundane, just updating to match the
above.  One interesting change though is the new member function
tui_source_window_base::puts_to_pad_with_skip.  This replaces direct
calls to tui_puts when copying content to the pad.

The content strings contain ansi escape sequences.  When these strings
are written to the pad these escape sequences are translated into
ncurses attribute setting calls.

Now however, we sometimes only write a partial string to the pad,
skipping some of the leading content.  Imagine then that we have a
content line like this:

  "\033[31mABCDEFGHIJKLM\033[0m"

Now the escape sequences in this content mean that the actual
content (the 'ABCDEFGHIJKLM') will have a red foreground color.

If we want to copy this to the pad, but skip the first 3 characters,
then what we expect is to have the pad contain 'DEFGHIJKLM', but this
text should still have a red foreground color.

It is this problem that puts_to_pad_with_skip solves.  This function
skips some number of printable characters, but processes all the
escape sequences.  This means that when we do start printing the
actual content the content will have the expected attributes.
/

16 months agogdb/tui: make m_horizontal_offset private
Andrew Burgess [Wed, 4 Jan 2023 17:07:47 +0000 (17:07 +0000)] 
gdb/tui: make m_horizontal_offset private

I noticed that tui_source_window_base::m_horizontal_offset was
protected, but could be made private, so lets do that.

This makes more sense in the context of a later commit where I plan to
add another member variable that is similar to m_horizontal_offset.
The new member variable could also be private.

So I had to choose, place the new member variable next to
m_horizontal_offset making it protected, but grouping similar
variables together, or make m_horizontal_offset private, and then add
the new variable as private too.

I chose to make m_horizontal_offset private, which is this commit.

There should be no user visible changes after this commit.

16 months agogdb/tui: disable tui mode when an assert triggers
Andrew Burgess [Wed, 4 Jan 2023 09:48:31 +0000 (09:48 +0000)] 
gdb/tui: disable tui mode when an assert triggers

When an assert triggers in tui mode the output is not great, the
internal backtrace that is generated is printed directly to the file
descriptor for gdb_stderr, and, as a result, does not currently format
itself correctly - the output uses only '\n' at the end of each line,
and so, when the terminal is in raw mode, the cursor does not return
to the start of each line after the '\n'.

This is mostly fixable, we could update bt-utils.c to use '\r\n'
instead of just '\n', and this would fix most of the problems.  The
one we can't easily fix is if/when GDB is built to use execinfo
instead of libbacktrace, in this case we use backtrace_symbols_fd to
print the symbols, and this function only uses '\n' as the line
terminator.  Fixing this would require switching to backtrace_symbols,
but that API uses malloc, which is something we're trying to
avoid (this code is called when GDB hits an error, so ideally we don't
want to rely on malloc).

However, the execinfo code is only used when libbacktrace is not
available (or the user specifically disables libbacktrace) so maybe we
can ignore that problem...

... but there is another problem.  When the backtrace is printed in
raw mode, it is possible that the backtrace fills the screen.  With
the terminal in raw mode we don't have the ability to scroll back,
which means we loose some of the backtrace, which isn't ideal.

In this commit I propose that we should disable tui mode whenever we
handle a fatal signal, or when we hit the internal error code
path (e.g. when an assert triggers).  With this done then we don't
need to update the bt-utils.c code, and the execinfo version of the
code (using backtrace_symbols_fd) works just fine.  We also get the
ability to scroll back to view the error message and all of the
backtrace, assuming the users terminal supports scrolling back.

The only downside I see with this change is if the tui_disable call
itself causes an error for some reason, or, if we handle a single at a
time when it is not safe to call tui_disable, in these cases the extra
tui_disable call might cause GDB to loose the original error.

However, I think (just from personal experience) that the above two
issues are pretty rare and the benefits from this change far out
weighs the possible drawbacks.

16 months agogdb/tui: improve errors from tui focus command
Andrew Burgess [Thu, 22 Dec 2022 16:26:37 +0000 (16:26 +0000)] 
gdb/tui: improve errors from tui focus command

This commit improves (I think) the errors from the tui focus command.
There are a number of errors that can be triggered by the focus
command, they include:

  (1) Window name "NAME" is ambiguous

  (2) Unrecognized window name "NAME"

  (3) Window "NAME" cannot be focused

Error (1) is triggered when the user gives a partial window name, and
the name matches multiple windows in the current layout.

It is worth noting that the ambiguity must be within the current
layout; if the partial name matches one window in the current layout,
and one or more windows not in the current layout, then this is not
ambiguous, and focus will shift to the matching window in the current
layout.

This error was not previous being tested, but in this commit I make
use of the Python API to trigger and test this error.

Error (3) is simple enough, and was already being tested.  This is
triggered by something like 'focus status'.  The named window needs to
be present in the current layout, and non-focusable in order to
trigger the error.

Error (2) is what I'd like to improve in this commit.  This error
triggers if the name the user gives doesn't match any window in the
current layout.  Even if GDB does know about the window, but the
window isn't in the current layout, then GDB will say it doesn't
recognize the window name.

In this commit I propose to to split this error into three different
errors.  These will be:

  (a) Unrecognized window name "NAME"

  (b) No windows matching "NAME" in the current layout

  (c) Window "NAME" is not in the current layout

Error (a) is the same as before, but will now only trigger if GDB
doesn't know about window NAME at all.  If the window is known, but
not in the current layout then one of the other errors will trigger.

Error (b) will trigger if NAME is ambiguous for multiple windows that
are not in the current layout.  If NAME identifies a single window in
the current layout then that window will continue to be selected, just
as it currently is.  Only in the case where NAME doesn't identify a
window in the current layout do we then check all the other known
windows, if NAME matches multiple of these, then (b) is triggered.

Finally, error (c) is used when NAME uniquely identifies a single
window that is not in the current layout.

The hope with these new errors is that the user will have a better
understanding of what went wrong.  Instead of GDB claiming to not know
about a window, the mention of the current layout will hint to the
user that they should first switch layouts.

There are tests included for all the new errors.

16 months agogdb/testsuite: fix line feed scrolling in tuiterm.exp
Andrew Burgess [Thu, 22 Dec 2022 16:26:50 +0000 (16:26 +0000)] 
gdb/testsuite: fix line feed scrolling in tuiterm.exp

In a following commit I managed to trigger the line feed scrolling
case in tuiterm.exp.  This case is currently unhandled, and this
commit fills in this missing functionality.

The implementation is pretty simple, just scroll all the content up
one line at a time until the cursor is back on the screen (a single
line of scroll is all that should be needed).

This change is untested in this commit, but is required by the next
commit.

16 months agoAnother fix for EFI generation with LTO enabled.
Nick Clifton [Fri, 27 Jan 2023 11:59:53 +0000 (11:59 +0000)] 
Another fix for EFI generation with LTO enabled.

PR 29998 * pe-dll.c (build_filler_bfd): Initialise the next field of the filler input statement, so that it does not break the file chain.

16 months agox86: move reg_operands adjustment
Jan Beulich [Fri, 27 Jan 2023 08:23:38 +0000 (09:23 +0100)] 
x86: move reg_operands adjustment

Ideally we'd do away with this somewhat questionable adjustment (leaving
i.types[] untouched). That's non-trivial though as it looks, so only
- move the logic into process_operands(), putting it closer to related
  logic and eliminating a conditional for operand-less insns,
- make it consistent (i.e. also affect %xmm0), eliminating an ugly
  special case later in the function.

16 months agox86: drop dead SSE2AVX-related code
Jan Beulich [Fri, 27 Jan 2023 08:23:12 +0000 (09:23 +0100)] 
x86: drop dead SSE2AVX-related code

All (there are just two) SSE2AVX templates with %xmm0 as first operand
also specify VEX3SOURCES. Hence there's no need for an "else" to the
respective if(), and the if() itself can become an assertion.

16 months agox86: use ModR/M for FPU insns with operands
Jan Beulich [Fri, 27 Jan 2023 08:22:49 +0000 (09:22 +0100)] 
x86: use ModR/M for FPU insns with operands

This is the correct way of expressing things; encoding the ModR/M byte
directly in base_opcode has always been bogus.

16 months agox86/Intel: improve special casing of certain insns
Jan Beulich [Fri, 27 Jan 2023 08:21:24 +0000 (09:21 +0100)] 
x86/Intel: improve special casing of certain insns

Now that we have identifiers for the mnemonic strings we can avoid
opcode based comparisons, for (in many cases) being more expensive and
(in a few cases) being a little fragile and not self-documenting.

16 months agoopcodes: suppress internationalization on build helper tools
Jan Beulich [Fri, 27 Jan 2023 08:20:58 +0000 (09:20 +0100)] 
opcodes: suppress internationalization on build helper tools

While one of the two actually having been instrumented (i386-gen.c) now
has that instrumentation dropped, there's still no point in honoring
such instrumentation in general (i.e. now for ia64-gen.c only), as that
only leads to a waste of resources.

With CFILES then being merely an alias of LIBOPCODES_CFILES, drop the
former variable altogether.

16 months agox86: remove internationalization from i386-gen.c
Jan Beulich [Fri, 27 Jan 2023 08:20:26 +0000 (09:20 +0100)] 
x86: remove internationalization from i386-gen.c

This is a build time helper utility, which doesn't require translation.

16 months agoCall bfd_close_all_done in ld_cleanup
Alan Modra [Fri, 27 Jan 2023 05:02:06 +0000 (15:32 +1030)] 
Call bfd_close_all_done in ld_cleanup

This is similar to "Call bfd_close_all_done in output_file_close",
but with some code tidying in the pe/pep write_build_id functions.
write_build_id is passed the output bfd as its parameter, so there is
no need to go looking for the output bfd via link_info (and doing so
will no longer work since I clear link_info.output_bfd before calling
bfd_close).

* emultempl/pe.em (write_build_id): Rename t to td.  Formatting.
Don't access pe_data(link_info.output_bfd), use td instead.
(setup_build_id): Rename t to td.  Formatting.
* emultempl/pep.em: As for pe.em.
* ldmain.c (ld_cleanup): Call bfd_close_all_done on linker bfds.
(main): Clear link_info.output_bfd when closing.

16 months agoPerform cleanup in bfd_close after errors
Alan Modra [Fri, 27 Jan 2023 04:46:03 +0000 (15:16 +1030)] 
Perform cleanup in bfd_close after errors

It seems reasonable to continue after errors in bfd_close_all_done,
particularly since bfd_close_all_done is typically called on an output
file after we've hit some sort of error elsewhere.  The iovec test is
necessary if bfd_close_all_done is to work on odd bfd's opened by
bfd_create.

* opncls.c (bfd_close): Call bfd_close_all_done after errors
from _bfd_write_contents.
(bfd_close_all_done): Call _bfd_delete_bfd after errors.
Don't call iovec->bclose when iovec is NULL.

16 months agoCall bfd_close_all_done in output_file_close
Alan Modra [Fri, 27 Jan 2023 02:01:27 +0000 (12:31 +1030)] 
Call bfd_close_all_done in output_file_close

bfd_cache_close_all is good for closing file descriptors, but doesn't
do the cleanup of bfd memory as in bfd_close_all_done.

PR 13056
* output-file.c (output_file_close): Call bfd_close_all_done,
not bfd_cache_close_all.

16 months agogas macro memory leaks
Alan Modra [Fri, 27 Jan 2023 00:01:56 +0000 (10:31 +1030)] 
gas macro memory leaks

This tidies memory allocated for entries in macro_hash.  Freeing the
macro name requires a little restructuring of the define_macro
interface due to the name being used in the error message, and exposed
the fact that the name and other fields were not initialised by the
iq2000 backend.

There is also a fix for
 .macro .macro
 .endm
 .macro .macro
 .endm
which prior to this patch reported
mac.s:1: Warning: attempt to redefine pseudo-op `.macro' ignored
mac.s:3: Error: Macro `.macro' was already defined
rather than reporting the attempt to redefine twice.

* macro.c (macro_del_f): New function.
(macro_init): Use it when creating macro_hash.
(free_macro): Free macro name too.
(define_macro): Return the macro_entry, remove idx, file, line and
namep params.  Call as_where.  Report errors here.  Delete macro
from macro_hash on attempt to redefined pseudo-op.
(delete_macro): Don't call free_macro.
* macro.h (define_macro): Update prototype.
* read.c (s_macro): Adjust to suit.
* config/tc-iq2000.c (iq2000_add_macro): Init all fields of
macro_entry.

16 months agogas/testsuite: Add -gcodeview test for aarch64-w64-mingw32
Mark Harmstone [Thu, 26 Jan 2023 00:33:29 +0000 (00:33 +0000)] 
gas/testsuite: Add -gcodeview test for aarch64-w64-mingw32

This is a copy of the x86 gas -gcodeview test, with changes made for the
differing instruction lengths between x86 and aarch64.

16 months agogas: Add CodeView constant for aarch64
Mark Harmstone [Wed, 25 Jan 2023 23:54:37 +0000 (23:54 +0000)] 
gas: Add CodeView constant for aarch64

Adds the correct constant to the S_COMPILE3 CodeView record when
assembling aarch64-w64-mingw32 with the -gcodeview flag.

16 months agoUse clean_restart in gdb.base
Tom Tromey [Wed, 25 Jan 2023 21:55:12 +0000 (14:55 -0700)] 
Use clean_restart in gdb.base

Change gdb.base to use clean_restart more consistently.

16 months agoUse clean_restart in gdb.python
Tom Tromey [Wed, 25 Jan 2023 21:48:55 +0000 (14:48 -0700)] 
Use clean_restart in gdb.python

Change gdb.python to use clean_restart more consistently.

16 months agoUse clean_restart in gdb.cp
Tom Tromey [Wed, 25 Jan 2023 21:43:51 +0000 (14:43 -0700)] 
Use clean_restart in gdb.cp

Change gdb.cp to use clean_restart more consistently.

16 months agoUse clean_restart in gdb.disasm
Tom Tromey [Wed, 25 Jan 2023 21:42:39 +0000 (14:42 -0700)] 
Use clean_restart in gdb.disasm

Change gdb.disasm to use clean_restart more consistently.

16 months agoUse clean_restart in gdb.perf
Tom Tromey [Wed, 25 Jan 2023 21:41:57 +0000 (14:41 -0700)] 
Use clean_restart in gdb.perf

Change gdb.perf to use clean_restart more consistently.

16 months agoUse clean_restart in gdb.go
Tom Tromey [Wed, 25 Jan 2023 21:41:39 +0000 (14:41 -0700)] 
Use clean_restart in gdb.go

Change gdb.go to use clean_restart more consistently.

16 months agoUse clean_restart in gdb.stabs
Tom Tromey [Wed, 25 Jan 2023 21:41:23 +0000 (14:41 -0700)] 
Use clean_restart in gdb.stabs

Change gdb.stabs to use clean_restart more consistently.

16 months agoUse clean_restart in gdb.fortran
Tom Tromey [Wed, 25 Jan 2023 17:48:44 +0000 (10:48 -0700)] 
Use clean_restart in gdb.fortran

Change gdb.fortran to use clean_restart more consistently.

16 months agoUse clean_restart in gdb.ada
Tom Tromey [Wed, 25 Jan 2023 17:48:27 +0000 (10:48 -0700)] 
Use clean_restart in gdb.ada

Change gdb.ada to use clean_restart more consistently.

16 months agoUse clean_restart in gdb.dwarf2
Tom Tromey [Wed, 25 Jan 2023 17:46:52 +0000 (10:46 -0700)] 
Use clean_restart in gdb.dwarf2

Change gdb.dwarf2 to use clean_restart more consistently.

16 months agoUse clean_restart in gdb.reverse
Tom Tromey [Wed, 25 Jan 2023 17:45:30 +0000 (10:45 -0700)] 
Use clean_restart in gdb.reverse

Change gdb.reverse to use clean_restart more consistently.

16 months agoUse clean_restart in gdb.arch
Tom Tromey [Wed, 25 Jan 2023 17:44:25 +0000 (10:44 -0700)] 
Use clean_restart in gdb.arch

Change gdb.arch to use clean_restart more consistently.

16 months agoUse clean_restart in gdb.guile
Tom Tromey [Wed, 25 Jan 2023 17:39:53 +0000 (10:39 -0700)] 
Use clean_restart in gdb.guile

Change gdb.guile to use clean_restart more consistently.

16 months agoUse clean_restart in gdb.threads
Tom Tromey [Wed, 25 Jan 2023 17:36:09 +0000 (10:36 -0700)] 
Use clean_restart in gdb.threads

Change gdb.threads to use clean_restart more consistently.

16 months agoUse clean_restart in gdb.objc
Tom Tromey [Wed, 25 Jan 2023 17:31:34 +0000 (10:31 -0700)] 
Use clean_restart in gdb.objc

Change gdb.objc to use clean_restart more consistently.

16 months agoUse clean_restart in gdb.trace
Tom Tromey [Wed, 25 Jan 2023 17:18:01 +0000 (10:18 -0700)] 
Use clean_restart in gdb.trace

Change gdb.trace to use clean_restart more consistently.

16 months agoUse clean_restart in gdb.opencl
Tom Tromey [Wed, 25 Jan 2023 17:14:50 +0000 (10:14 -0700)] 
Use clean_restart in gdb.opencl

Change gdb.opencl to use clean_restart more consistently.

16 months agoUse clean_restart in gdb.linespec
Tom Tromey [Wed, 25 Jan 2023 17:13:40 +0000 (10:13 -0700)] 
Use clean_restart in gdb.linespec

Change gdb.linespec to use clean_restart more consistently.

16 months agoUse clean_restart in gdb.pascal
Tom Tromey [Wed, 25 Jan 2023 17:06:20 +0000 (10:06 -0700)] 
Use clean_restart in gdb.pascal

Change gdb.pascal to use clean_restart more consistently.

16 months agoUse mi_clean_restart more
Tom Tromey [Wed, 25 Jan 2023 17:01:57 +0000 (10:01 -0700)] 
Use mi_clean_restart more

This changes a number of MI tests to use mi_clean_restart rather than
separate calls.  This reduces the number of lines, which is nice, and
also provides a nicer model to copy for future tests.

16 months agoStart gdb after building executable in mi-basics.exp
Tom Tromey [Wed, 25 Jan 2023 17:00:58 +0000 (10:00 -0700)] 
Start gdb after building executable in mi-basics.exp

A lot of the MI tests start gdb and only then build the executable.
This just seemed weird to me, so I've fixed this up.  In this patch,
no other cleanups are done, the startup is just moved to a more
logical (to me) spot.

16 months agoRemove unnecessary call to standard_testfile
Tom Tromey [Wed, 25 Jan 2023 16:56:46 +0000 (09:56 -0700)] 
Remove unnecessary call to standard_testfile

This test does not build a program and does not need to call
standard_testfile.

16 months agoMinor "require" fixups
Tom Tromey [Wed, 25 Jan 2023 16:43:03 +0000 (09:43 -0700)] 
Minor "require" fixups

I found a couple of spots that could use "require", and one spot where
hoisting the "require" closer to the top of the file made it more
clear.

16 months agoRemove some dead code in gdb.fortran/info-types.exp
Tom Tromey [Wed, 25 Jan 2023 16:37:25 +0000 (09:37 -0700)] 
Remove some dead code in gdb.fortran/info-types.exp

An early "return" in this test case prevents a test from running.
This seems to have been intentional and has been in place since:

commit d57cbee932f86df06251498daa93154046dc77c0
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date:   Tue Dec 3 13:18:43 2019 +0000

    gdb/testsuite/fortran: Fix info-modules/info-types for gfortran 8+

This patch removes the dead code.

16 months agoEliminate spurious returns from the test suite
Tom Tromey [Wed, 25 Jan 2023 16:36:25 +0000 (09:36 -0700)] 
Eliminate spurious returns from the test suite

A number of tests end with "return".  However, this is unnecessary.
This patch removes all of these.

16 months agoUse clean_restart in gdb.dlang
Tom Tromey [Wed, 25 Jan 2023 16:26:53 +0000 (09:26 -0700)] 
Use clean_restart in gdb.dlang

Change gdb.dlang to use clean_restart more consistently.

16 months agoUse ordinary calling convention for clean_restart
Tom Tromey [Wed, 25 Jan 2023 16:25:36 +0000 (09:25 -0700)] 
Use ordinary calling convention for clean_restart

clean_restart accepts a single optional argument.  Rather than using
{args} and handling the argument by hand, change it to use Tcl's own
argument-checking.

16 months agoAutomatic date update in version.in
GDB Administrator [Fri, 27 Jan 2023 00:00:10 +0000 (00:00 +0000)] 
Automatic date update in version.in

16 months agoFree gas/dwarf2dbg.c dirs
Alan Modra [Thu, 26 Jan 2023 08:42:09 +0000 (19:12 +1030)] 
Free gas/dwarf2dbg.c dirs

Entries are allocated with xmemdup0.

* dwarf2dbg.c (dwarf2_cleanup): Free dirs entries.

16 months agoSanity check dwarf5 form of .file
Alan Modra [Thu, 26 Jan 2023 08:29:07 +0000 (18:59 +1030)] 
Sanity check dwarf5 form of .file

There's a comment a few lines earlier saying that demand_copy_C_string
has already reported an error if it returns NULL.  Given the proximity
I decided not to duplicate the comment.

* dwarf2dbg.c (dwarf2_directive_filename): Check return of
demand_copy_C_string for file.

16 months agoresolve gas shift expressions with large exponents to zero
Alan Modra [Thu, 26 Jan 2023 08:14:51 +0000 (18:44 +1030)] 
resolve gas shift expressions with large exponents to zero

* expr.c (resolve_expression <O_left_shift, O_right_shift>): Resolve
shifts exceeding bits in a valueT to zero.