binutils-gdb.git
13 months agoSupport NEXT_SECTION in ALIGNOF and SIZEOF
Alan Modra [Fri, 14 Jul 2023 23:16:35 +0000 (08:46 +0930)]
Support NEXT_SECTION in ALIGNOF and SIZEOF

This patch is aimed at making __bss_start properly aligned with the
first of any bss-style sections following.  Most of the work here
involves keeping track of the last output section seen when processing
the linker script.

You can almost align __bss_start properly by using
${RELOCATING+. = ALIGN(${DATA_SDATA-${NO_SMALL_DATA-ALIGNOF(.${SBSS_NAME}) != 0 ? ALIGNOF(.${SBSS_NAME}) : }}${BSS_PLT+ALIGNOF(.plt) != 0 ? ALIGNOF(.plt) : }ALIGNOF(.${BSS_NAME}));}
and changing every place that defines NO_SMALL_DATA to use " ", but
having two .plt sections (marked SPECIAL) on some backends foils that
idea.  The problem is that you only want to pick up the following
.plt, not the one preceeding __bss_start in the data segment if the
backend decides that is the proper .plt section.

Perhaps that could be fixed too, but I decided instead to extend the
linker script a little.  THIS_SECTION and PREV_SECTION could easily be
added too.

* ld.texi (ALIGNOF, SIZEOF): Update and mention NEXT_SECTION.
* ldexp.c (output_section_find): New function.
(fold_name <ALIGNOF, SIZEOF>): Use output_section_find.
(exp_fold_tree): Add os parameter.  Adjust all calls.
(exp_fold_tree_no_dot, exp_get_vma, exp_get_power): Likewise.
* ldexp.h (struct ldexp_control): Add last_os.
(exp_fold_tree, exp_fold_tree_no_dot): Update prototypes.
(exp_get_vma, exp_get_power): Likewise.
* ldlang.c: Pass last output section to expression folder
calls throughout file.
(open_input_bfds): Add os parameter to track last os seen.
(lang_size_sections_1): Rename output_section_statement param
to current_os.  Track last os.
(lang_do_assignments_1): Track last os.
* scripttempl/arclinux.sc: Align to ALIGNOF NEXT_SECTION
before defining __bss_start.
* scripttempl/elf.sc: Likewise.
* scripttempl/elf64bpf.sc: Likewise.
* scripttempl/elf64hppa.sc: Likewise.
* scripttempl/elf_chaos.sc: Likewise.
* scripttempl/elfarc.sc: Likewise.
* scripttempl/elfd10v.sc: Likewise.
* scripttempl/elfxtensa.sc: Likewise.
* scripttempl/epiphany_4x4.sc: Likewise.
* scripttempl/iq2000.sc: Likewise.
* scripttempl/mep.sc: Likewise.
* scripttempl/nds32elf.sc: Likewise.
* scripttempl/xstormy16.sc: Likewise.
* testsuite/ld-x86-64/pe-x86-64-5.od: Update expected __bss_start.
* testsuite/ld-x86-64/pe-x86-64-5.rd: Likewise.

13 months ago[gdb/testsuite] Handle has_native_target in gdb.testsuite/gdb-caching-proc-consistenc...
Tom de Vries [Sun, 16 Jul 2023 14:18:41 +0000 (16:18 +0200)]
[gdb/testsuite] Handle has_native_target in gdb.testsuite/gdb-caching-proc-consistency.exp

With test-case gdb.testsuite/gdb-caching-proc-consistency.exp we run into:
...
ERROR: no fileid for xerxes
Couldn't send help target native to GDB.
UNRESOLVED: <exp>: have_native_target: initial: help target native
...

Fix this by handling have_native_target in
gdb.testsuite/gdb-caching-proc-consistency.exp.

Tested on x86_64-linux.

13 months agoAutomatic date update in version.in
GDB Administrator [Sun, 16 Jul 2023 00:00:09 +0000 (00:00 +0000)]
Automatic date update in version.in

13 months agogdb/tui: make tui_win_info::title private
Andrew Burgess [Mon, 10 Jul 2023 14:56:47 +0000 (15:56 +0100)]
gdb/tui: make tui_win_info::title private

This commit builds on this earlier work:

  commit 9fe01a376b2fb096e4836e985ba316ce9dc02399
  Date:   Thu Jun 29 11:26:55 2023 -0600

      Update TUI window title when changed

and makes tui_win_info::title private, renaming to m_title at the same
time.  There's a new tui_win_info::title() member function to provide
read-only access to the title.

There should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
13 months agogdb: style filenames in separate debug file warnings
Andrew Burgess [Fri, 5 May 2023 13:22:38 +0000 (14:22 +0100)]
gdb: style filenames in separate debug file warnings

After the commit:

  commit 6647f05df023b63bbe056e9167e9e234172fa2ca
  Date:   Tue Jan 24 18:13:38 2023 +0100

      gdb: defer warnings when loading separate debug files

It was pointed out[1] that the warnings being deferred and then later
emitted lacked styling.  The warnings lacked styling before the above
commit, but it was suggested that the filenames in these warnings
should be styled, and this commit does this.

There were a couple of previous attempts[2][3][4] to solve this
problem, but these all tried to extend the mechanism introduced in the
above commit, the deferred warnings were placed directly into a
std::vector, but now we tried to, when appropriate, style these
warnings.  The review feedback that this approach looked too complex.

So instead, this revision adds a new helper class 'deferred_warnings'
which can be used to collect a set of deferred warnings, and then emit
these deferred warnings later, if needed.  This helper class hides the
complexity, so at the point the deferred warning is created no extra
logic is required.

The deferred_warnings class will style the deferred warnings only if
gdb_stderr supports styling.  GDB's warnings are sent to gdb_stderr,
so this should ensure we only style when expected.

There was also review feedback[5] that all of the warnings should be
bundled into a single string_file, this has not been done.  I feel
pretty strongly that separate warnings should be emitted using
separate "warning" calls.  If we do end up with multiple warnings in
this case they aren't really related, one will be about looking up
debug via .gnu_debuglink, while the other will be about build-id based
lookup.  So I'd really rather keep the warnings separate.

[1] https://inbox.sourceware.org/gdb-patches/87edr9pcku.fsf@tromey.com/
[2] https://inbox.sourceware.org/gdb-patches/20230216195604.2685177-1-ahajkova@redhat.com/
[3] https://inbox.sourceware.org/gdb-patches/20230217123547.2737612-1-ahajkova@redhat.com/
[4] https://inbox.sourceware.org/gdb-patches/20230320145638.1202335-1-ahajkova@redhat.com/
[5] https://inbox.sourceware.org/gdb-patches/87o7nh1g8h.fsf@tromey.com/

Co-Authored-By: Alexandra Hájková <ahajkova@redhat.com>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
13 months ago[gdb/testsuite] Fix gdb.dwarf2/forward-spec.exp with read1
Tom de Vries [Sat, 15 Jul 2023 08:09:40 +0000 (10:09 +0200)]
[gdb/testsuite] Fix gdb.dwarf2/forward-spec.exp with read1

When running test-case gdb.dwarf2/forward-spec.exp with check-read1 we run
into:
...
    parent:     ((cooked_index_entry *) 0xFAIL: <exp>: v has a parent
7fdc1c002ed0) [ns]^M
...

The problem is using regexps containing '.' to avoid escaping, which makes
them too generic.

Fix this by eliminating the '.' from the regexps.

Tested on x86_64-linux.

13 months agoAutomatic date update in version.in
GDB Administrator [Sat, 15 Jul 2023 00:00:12 +0000 (00:00 +0000)]
Automatic date update in version.in

13 months agoUse correct inferior in Inferior.read_memory et al
Tom Tromey [Thu, 6 Jul 2023 17:33:47 +0000 (11:33 -0600)]
Use correct inferior in Inferior.read_memory et al

A user noticed that Inferior.read_memory and a few other Python APIs
will always use the currently selected inferior, not the one passed to
the call.

This patch fixes the bug by arranging to switch to the inferior.  I
found this same issue in several APIs, so this fixes them all.

I also added a few missing calls to INFPY_REQUIRE_VALID to these
methods.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30615
Approved-By: Pedro Alves <pedro@palves.net>
13 months agoIntroduce scoped_restore_current_inferior_for_memory
Tom Tromey [Tue, 11 Jul 2023 15:54:01 +0000 (09:54 -0600)]
Introduce scoped_restore_current_inferior_for_memory

This introduces a new class,
scoped_restore_current_inferior_for_memory, and arranges to use it in
a few places.  This class is intended to handle setting up and
restoring the various globals that are needed to read or write memory
-- but without invalidating the frame cache.

I wasn't able to test the change to aix-thread.c.

Approved-By: Pedro Alves <pedro@palves.net>
13 months agoRemove obsolete comment from gdbthread.h
Tom Tromey [Fri, 7 Jul 2023 14:16:02 +0000 (08:16 -0600)]
Remove obsolete comment from gdbthread.h

A comment in gdbthread.h refers to a global that no longer exists.

Approved-By: Pedro Alves <pedro@palves.net>
13 months agoRename Python variable in py-inferior.exp
Tom Tromey [Thu, 6 Jul 2023 17:57:26 +0000 (11:57 -0600)]
Rename Python variable in py-inferior.exp

py-inferior.exp creates a Python variable named 'str'.  This clashes
with the built-in type of the same name and can be confusing when
trying to evaluate Python code when debugging the test case.  This
patch renames it.

Approved-By: Pedro Alves <pedro@palves.net>
13 months agoRefactor py-inferior.exp
Tom Tromey [Thu, 6 Jul 2023 17:55:47 +0000 (11:55 -0600)]
Refactor py-inferior.exp

This changes py-inferior.exp to make it a bit more robust when adding
new inferiors during the course of the test.

Approved-By: Pedro Alves <pedro@palves.net>
13 months agoMinor cleanups in py-inferior.exp
Tom Tromey [Thu, 6 Jul 2023 17:44:09 +0000 (11:44 -0600)]
Minor cleanups in py-inferior.exp

While working on this series, I noticed a some oddities in
py-inferior.exp.  One is an obviously incorrect comment, and the
others are confusing test names.  This patch fixes these.

Approved-By: Pedro Alves <pedro@palves.net>
13 months agoRevert "Simplify auto_load_expand_dir_vars and remove substitute_path_component"
Tom Tromey [Fri, 14 Jul 2023 15:35:03 +0000 (09:35 -0600)]
Revert "Simplify auto_load_expand_dir_vars and remove substitute_path_component"

This reverts commit 02601231fdd91a7bd4837ce202906ea2ce661489.

This commit was a refactoring to remove an xrealloc and simplify
utils.[ch].  However, it has a flaw -- it mishandles a substitution
like "$datadir/subdir".

I am backing out the patch in the interests of fixing the regression
before GDB 14.  It can be reinstated (with modifications) later if we
like.

Regression tested on x86-64 Fedora 36.

13 months agoTest that native targets can read a tdesc without a process attached.
John Baldwin [Fri, 14 Jul 2023 15:39:24 +0000 (08:39 -0700)]
Test that native targets can read a tdesc without a process attached.

This ensures that 'unset tdesc filename' does not generate any output
on a "bare" native target inferior without an attached process.

13 months agoAdd a have_native_target helper function for use with require.
John Baldwin [Fri, 14 Jul 2023 15:39:24 +0000 (08:39 -0700)]
Add a have_native_target helper function for use with require.

Move logic from auto-connect-native-target.exp into this helper.

13 months ago*-linux-nat: Handle null inferior in read_description.
John Baldwin [Fri, 14 Jul 2023 15:39:24 +0000 (08:39 -0700)]
*-linux-nat: Handle null inferior in read_description.

Don't invoke ptrace in the target read_description method if there is
not an active inferior to query via ptrace.  Instead, use the default
register set for the architecture.

Previously the native target could report an error from a failed
ptrace operation when fetching a tdesc without an attached process.
For example on Linux x86-64:

(gdb) target native
Done.  Use the "run" command to start a process.
(gdb) unset tdesc filename
Couldn't get CS register: No such process.

13 months ago*-fbsd-nat: Handle null inferior in read_description.
John Baldwin [Fri, 14 Jul 2023 15:39:24 +0000 (08:39 -0700)]
*-fbsd-nat: Handle null inferior in read_description.

Don't invoke ptrace in the target read_description method if there is
not an active inferior to query via ptrace.  Instead, use the default
register set for the architecture.

Previously the native target could report an error from a failed
ptrace operation when fetching a tdesc without an attached process.
For example on FreeBSD/amd64:

(gdb) target native
Done.  Use the "run" command to start a process.
(gdb) unset tdesc filename
Couldn't get registers: Operation not permitted.

13 months agoRe: Let '^' through the lexer
Tobias Burnus [Fri, 14 Jul 2023 14:32:43 +0000 (00:02 +0930)]
Re: Let '^' through the lexer

Fix "make pdf".

13 months agogdb/doc: document '+' argument for 'list' command
Bruno Larsen [Tue, 20 Jun 2023 14:57:38 +0000 (16:57 +0200)]
gdb/doc: document '+' argument for 'list' command

The command 'list' has accepted the argument '+' for many years already,
but this option wasn't documented either in the texinfo docs or in the
help text for the command.  This commit documents it.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
13 months agogdb/cli: Improve UX when using list with no args
Bruno Larsen [Thu, 15 Jun 2023 09:17:07 +0000 (11:17 +0200)]
gdb/cli: Improve UX when using list with no args

When using "list" with no arguments, GDB will first print the lines
around where the inferior is stopped, then print the next N lines until
reaching the end of file, at which point it warns the user "Line X out
of range, file Y only has X-1 lines.".  This is usually desirable, but
if the user can no longer see the original line, they may have forgotten
the current line or that a list command was used at all, making GDB's
error message look cryptic. It was reported in bugzilla as PR cli/30497.

This commit improves the user experience by changing the behavior of
"list" slightly when a user passes no arguments.  It now prints that the
end of the file has been reached and recommends that the user use the
command "list ." instead.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30497
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
13 months agogdb/cli: add '.' as an argument for 'list' command
Bruno Larsen [Thu, 15 Jun 2023 10:14:22 +0000 (12:14 +0200)]
gdb/cli: add '.' as an argument for 'list' command

Currently, after the user has used the list command once, there is no
self-contained way to ask GDB to print the location where the inferior is
stopped.  The current best options require either using a separate
command to scope out where the inferior is stopped, or using "list *$pc"
requiring knowledge of GDB standard registers.  This commit adds a way
to do that using '.' as a new argument for the 'list' command.  If the
inferior isn't running, the command prints around the main function.

Because this necessitated having the inferior running and the test was
(seemingly unnecessarily) using printf in a non-essential way and it
would make the resulting log harder to read for no benefit, it was
replaced by a different statement.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
13 months agogdb/cli: Factor out code to list lines around a given line
Bruno Larsen [Thu, 15 Jun 2023 09:02:11 +0000 (11:02 +0200)]
gdb/cli: Factor out code to list lines around a given line

A future patch will add more situations that calculates "lines around a
certain point" to be printed using print_source_lines, and the logic
could be re-used. As a preparation for those commits, this one factors
out that part of the logic of the list command into its own function.
No functional changes are expected

Approved-By: Tom Tromey <tom@tromey.com>
13 months agogprofng: 30602 [2.41] gprofng test hangs on i686-linux-gnu
Vladimir Mezentsev [Wed, 12 Jul 2023 22:03:28 +0000 (15:03 -0700)]
gprofng: 30602 [2.41] gprofng test hangs on i686-linux-gnu

There were several problems in the gprofng testing:
 - we did not catch a timeout for each test.
 - we used exit() to stop a failed test. But this stops all other tests.
 - we used a time_t (long) type in smalltest.c instead of a long long type.

PR gprofng/30602
* configure.ac: Launch only native testing.
* configure: Rebuild.
* testsuite/config/default.exp: Set TEST_TIMEOUT.
* testsuite/gprofng.display/setpath_map.exp: Use return instead of exit.
* testsuite/gprofng.display/gp-archive.exp: Likewise.
* testsuite/gprofng.display/gp-collect-app_F.exp: Likewise.
* testsuite/gprofng.display/display.exp: Delete an unnecessary test
for native testing.
* testsuite/lib/display-lib.exp (run_native_host_cmd): Add timeout.
* testsuite/lib/smalltest.c: Use a long long type instead of time_t.

13 months agoMake the default gas symbol hash table larger
Alan Modra [Fri, 14 Jul 2023 01:18:27 +0000 (10:48 +0930)]
Make the default gas symbol hash table larger

We may as well start with the symbol table a little larger, saving
time resizing.  Even a simple C hello world compiled with -O2 -g will
exceed 16 symbols (by well over 3 times with gcc-11).

* symbols.c (symbol_begin): Create sy_hash with more entries.

13 months agoFix loongarch build with gcc-4.5
Alan Modra [Fri, 14 Jul 2023 01:18:05 +0000 (10:48 +0930)]
Fix loongarch build with gcc-4.5

* loongarch-opc.c (loongarch_alias_opcodes): Don't trigger
gcc-4.5 bug in handling of struct initialisation.

13 months agoMore tidies to objcopy archive handling
Alan Modra [Fri, 14 Jul 2023 01:17:30 +0000 (10:47 +0930)]
More tidies to objcopy archive handling

This makes sure copy_archive exits with ibfd and obfd closed.  Error
paths didn't do that, leading to memory leaks.  None of this matters
very much.

* objcopy.c (copy_archive): bfd_close ibfd and obfd on error
return paths.  Remove braces around "list" free.
(copy_file): Don't close invalid file descriptor.

13 months agoAIX_WEAK_SUPPORT
Alan Modra [Fri, 14 Jul 2023 01:16:50 +0000 (10:46 +0930)]
AIX_WEAK_SUPPORT

Making target code depend on a host define like _AIX52 is never
correct, so out it goes.  Also, sort some config.bfd entries a little
to make it more obvious there is a config difference between aix5.1
and aix5.2.  These two changes should make no difference to anything
in binutils.  The gas define of AIX_WEAK_SUPPORT on the other hand was
wrong, so fix that.  Finally, fix some testsuite fails on aix < 5.2 by
simply not running the tests.

include/
* coff/internal.h (C_WEAKEXT): Don't depend on _AIX52.
bfd/
* coffcode.h (coff_slurp_symbol_table): Don't depend on _AIX52.
(coff_classify_symbol): Likewise.
* config.bfd: Sort some entries.
gas/
* configure.ac (AIX_WEAK_SUPPORT): Don't set for aix5.[01].
* configure: Regenerate.
* testsuite/gas/ppc/aix.exp (xcoff-visibility-1*) Don't run
for aix < 5.2.

13 months agoAutomatic date update in version.in
GDB Administrator [Fri, 14 Jul 2023 00:00:19 +0000 (00:00 +0000)]
Automatic date update in version.in

13 months agoImplement 'Enum_Val and 'Enum_Rep
Tom Tromey [Fri, 23 Jun 2023 15:59:38 +0000 (09:59 -0600)]
Implement 'Enum_Val and 'Enum_Rep

This patch implements the Ada 2022 attributes 'Enum_Val and 'Enum_Rep.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
13 months agoRemove ada_attribute_name
Tom Tromey [Fri, 23 Jun 2023 15:39:57 +0000 (09:39 -0600)]
Remove ada_attribute_name

ada_attribute_name uses an array that must be kept in sync with an
enum -- but the comment here refers to an enum that no longer exists.
Looking at the sole caller, I see this can only be called for two
opcodes.  So, remove this entirely and inline it.

13 months agoLet '^' through the lexer
Michael Matz [Wed, 12 Jul 2023 13:10:10 +0000 (15:10 +0200)]
Let '^' through the lexer

so that the (existing) code in parser and expression evaluator
actually get to see it and handle it as XOR.  Also adjust docu
to match what's there.

13 months agoelf_object_p load of dynamic symbols
Alan Modra [Thu, 13 Jul 2023 04:02:42 +0000 (13:32 +0930)]
elf_object_p load of dynamic symbols

This fixes an uninitialised memory access on a fuzzed file:
0 0xf22e9b in offset_from_vma /src/binutils-gdb/bfd/elf.c:1899:2
1 0xf1e90f in _bfd_elf_get_dynamic_symbols /src/binutils-gdb/bfd/elf.c:2099:13
2 0x10e6a54 in bfd_elf32_object_p /src/binutils-gdb/bfd/elfcode.h:851:9

Hopefully it will also stop any attempt to load dynamic symbols from
eu-strip debug files.

* elfcode.h (elf_object_p): Do not attempt to load dynamic
symbols for a file with no section headers until all the
program headers are swapped in.  Do not fail on eu-strip debug
files.

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

13 months ago[gdb/tui] Assume HAVE_WBORDER
Tom de Vries [Wed, 12 Jul 2023 14:27:40 +0000 (16:27 +0200)]
[gdb/tui] Assume HAVE_WBORDER

The tui border-kind setting allows values acs, ascii and space.

The values ascii and space however don't work well with !HAVE_WBORDER.

Fix this by removing the !HAVE_WBORDER case, which was introduced for Ultrix
support, which is now obsolete.

Tested on x86_64-linux.

PR tui/30580
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30580

Approved-By: Tom Tromey <tom@tromey.com>
13 months ago[gdb/tui] Make translate return entry->value instead of entry
Tom de Vries [Wed, 12 Jul 2023 10:07:40 +0000 (12:07 +0200)]
[gdb/tui] Make translate return entry->value instead of entry

The only use of "entry = translate (...)" is entry->value.

Simplify using the function by returning entry->value instead.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
13 months ago[gdb/tui] Merge tui border-kind corner translation tables
Tom de Vries [Wed, 12 Jul 2023 10:07:40 +0000 (12:07 +0200)]
[gdb/tui] Merge tui border-kind corner translation tables

The tables:
- tui_border_kind_translate_ulcorner
- tui_border_kind_translate_urcorner
- tui_border_kind_translate_llcorner
- tui_border_kind_translate_lrcorner
are identical.

Merge and rename to tui_border_kind_translate_corner.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
13 months ago[gdb/tui] Introduce translate_acs
Tom de Vries [Wed, 12 Jul 2023 10:07:40 +0000 (12:07 +0200)]
[gdb/tui] Introduce translate_acs

In function tui_update_variables we have the somewhat inconvenient:
...
  entry = translate (tui_border_kind, tui_border_kind_translate_lrcorner);
  int val = (entry->value < 0) ? ACS_LRCORNER : entry->value;
...

Add a new function translate_acs, that allows us to do the more straighforward:
...
  int val = translate_acs (tui_border_kind, tui_border_kind_translate_lrcorner,
   ACS_LRCORNER);
...

By special-casing "acs" in translate_acs, we can now remove the acs entries
from the translation tables.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
13 months ago[gdb/tui] Remove default entries in TUI translation tables
Tom de Vries [Wed, 12 Jul 2023 10:07:40 +0000 (12:07 +0200)]
[gdb/tui] Remove default entries in TUI translation tables

The TUI translation tables contain default entries at the end:
...
static struct tui_translate tui_border_kind_translate_hline[] = {
  { "space",    ' ' },
  { "ascii",    '-' },
  { "acs",      -1 },
  { 0, 0 },
  { "ascii",    '-' }
};
...

A simpler way of implementing this would be to to declare the first (or last)
entry the default, but in fact these default entries are not used.

Make this explicit by removing the default entries, and asserting in translate
that an entry will always be found.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
13 months ago.noinit and .persistent for msp430
Alan Modra [Fri, 7 Jul 2023 08:10:00 +0000 (17:40 +0930)]
.noinit and .persistent for msp430

Similar to the previous patch, but also tidy a few more sections.

* scripttempl/elf32msp430.sc (.text, .rodata, .data, .bss, .noinit),
(.persistent): Align the section rather than aligning inside.

13 months ago.noinit and .persistent alignment
Alan Modra [Fri, 7 Jul 2023 05:02:00 +0000 (14:32 +0930)]
.noinit and .persistent alignment

It's more elegant to make the section match up with its "_start"
symbol.  We could align by setting the address of the section (by
using ALIGN before the colon), but this way we also set sh_addralign
to at least $ALIGNMENT.

* scripttempl/elf.sc (.noinit, .persistent): Align the output
section rather than using ". = ALIGN();" at the beginning.
Set address to zero when not a final link.

13 months agoRe: Align linkerscript symbols according to ABI
Alan Modra [Fri, 7 Jul 2023 04:03:56 +0000 (13:33 +0930)]
Re: Align linkerscript symbols according to ABI

Align dot before symbols defined outside of output sections.  Before _end
is already aligned.

* scripttempl/elf.sc (def_symbol): Tidy excess space.
(_edata): Align before emitting symbol when SYMBOL_ABI_ALIGNMENT.

13 months agoRe: Keeping track of rs6000-coff archive element pointers
Alan Modra [Mon, 10 Jul 2023 22:49:20 +0000 (08:19 +0930)]
Re: Keeping track of rs6000-coff archive element pointers

bfd/
* coff-rs6000.c (add_range): Revise comment, noting possible fail.
(_bfd_xcoff_openr_next_archived_file): Start with clean ranges.
binutils/
* bfdtest1.c: Enhance to catch errors on second scan.

13 months agoAutomatic date update in version.in
GDB Administrator [Wed, 12 Jul 2023 00:00:26 +0000 (00:00 +0000)]
Automatic date update in version.in

13 months agoRemove some TODOs from gdb.cp tests
Tom Tromey [Mon, 10 Jul 2023 16:22:33 +0000 (10:22 -0600)]
Remove some TODOs from gdb.cp tests

This patch removes many TODOs from the gdb.cp tests.
Going through the patch:

* bs15503.exp - these have been commented out forever and rely on
  libstdc++ debuginfo.  It's better to just remove these.

* classes.exp - the test is wrong, I think, according to the C++ ABI
  that gdb understands; and the test can be fixed and comments removed
  with a simple change to the code.

* ctti.exp - there's no need to bail out any more, as the test works.

* exception.exp - the code relying on the line numbers can't work,
  because gdb never prints that message anyway.

Reviewed-By: Bruno Larsen <blarsen@redhat.com>
13 months agox86: simplify table-referencing macros
Jan Beulich [Tue, 11 Jul 2023 06:22:17 +0000 (08:22 +0200)]
x86: simplify table-referencing macros

First of all it is entirely unclear why THREE_BYTE_TABLE_PREFIX() was
introduced by bf890a93a7c4. Nothing uses the .prefix_requirement values
from the two relevant entries.

And then having VEX_Cn_TABLE() and friends take arguments is misleading.
These aren't used (or pointlessly used in the case of VEX_C5_TABLE); the
respective table index is decoded from the insn (or implied in the case
of VEX_C5_TABLE).

13 months agox86: convert 0FXOP to just XOP in enumerator names
Jan Beulich [Tue, 11 Jul 2023 06:21:51 +0000 (08:21 +0200)]
x86: convert 0FXOP to just XOP in enumerator names

There's nothing 0f-ish in XOP encodings.

13 months agox86: misc further register-only insns don't need to go through mod_table[]
Jan Beulich [Tue, 11 Jul 2023 06:21:28 +0000 (08:21 +0200)]
x86: misc further register-only insns don't need to go through mod_table[]

Several already use OP_R(), which rejects the memory forms of insns, and
a few others can easily be converted to do so as well. Note that for it
to be able to use BadOp() without forward declaration, OP_Skip_MODRM() is
moved down.

While there add the previously missing PREFIX_OPCODE to legacy opcode
0FD7.

13 months agox86: various operations on mask registers can avoid going through mod_table[]
Jan Beulich [Tue, 11 Jul 2023 06:21:03 +0000 (08:21 +0200)]
x86: various operations on mask registers can avoid going through mod_table[]

Now that we have OP_R(), use it here as well, while wiring memory-only
operands to OP_M() at the same time. To keep the number of consumed
opcode bytes similar to before, make BadOp() also account for VEX/XOP/
EVEX prefix bytes. To keep that change simple, convert need_vex to an
actual count of prefix bytes (keeping intact all prior boolean uses of
the field).

Note how this improves disassembly of such bad encodings, by at least
leaving a hint towards what a "nearby" instruction is. (For KSHIFT*
change the immediates test testcases use, such that disassembly remains
sufficiently in sync.)

While there also use Ux for VPMOV{B,W,D,Q}2M, where decoding through
mod_table[] was missing in the earlier scheme.

13 months agox86: slightly rework handling of some register-only insns
Jan Beulich [Tue, 11 Jul 2023 06:20:17 +0000 (08:20 +0200)]
x86: slightly rework handling of some register-only insns

Fold OP_MS() and OP_XS() into OP_R(), paralleling OP_M(). Use operand
names (largely) matching those in the SDM. For 128-bit-only forms use
Uxmm though, marking 256-bit forms as bad. This then allows no longer
going through vex_len_table[] for two of the insns.

Specifically _do not_ continue to mis-use v_mode.

13 months agox86: SIMD shift-by-immediate don't need to go through mod_table[]
Jan Beulich [Tue, 11 Jul 2023 06:19:53 +0000 (08:19 +0200)]
x86: SIMD shift-by-immediate don't need to go through mod_table[]

OP_MS() and OP_XS() reject memory forms of insns quite fine. This then
also eliminates mis-named enumerators (we use M_1 for register forms).

13 months agox86: misc further memory-only insns don't need to go through mod_table[]
Jan Beulich [Tue, 11 Jul 2023 06:19:22 +0000 (08:19 +0200)]
x86: misc further memory-only insns don't need to go through mod_table[]

Several already use OP_M(), which rejects the register forms of insns,
and a few others can easily be converted to do so as well. (Note that
FXSAVE_Fixup() wires through to OP_M(). Note further that OP_IndirE(),
which wasn't placed very well anyway, is moved down to avoid the need to
forward-declare BadOp().)

Also adjust formatting of and drop PREFIX_OPCODE from a few adjacent
entries.

13 months agox86: {,V}MOVNT* don't need to go through mod_table[]
Jan Beulich [Tue, 11 Jul 2023 06:17:22 +0000 (08:17 +0200)]
x86: {,V}MOVNT* don't need to go through mod_table[]

Most of them use Mx already for the memory operand, which rejects the
register form of the insn. Use that operand type also for the two EVEX
forms which so far have used EXEvexXNoBcst (and thus failed to reject
the register forms), compensating by flagging broadcast as bad for all
Mx. This way several other insns which don't permit embedded broadcast
either are also covered at the same time.

13 months agox86: fold legacy/VEX {,V}MOV{H,L}* entries
Jan Beulich [Tue, 11 Jul 2023 06:16:00 +0000 (08:16 +0200)]
x86: fold legacy/VEX {,V}MOV{H,L}* entries

By changing decode order to do ModR/M.mod last (rather than VEX.L), the
VEX entries (which are already reused by EVEX decoding) can be folded
with their legacy counterparts as well. Note how this change of decode
order also allows removing two auxiliary #define-s, which were
introduced during earlier folding (because of that unhelpful order of
steps).

13 months agox86: fold certain legacy/VEX table entries
Jan Beulich [Tue, 11 Jul 2023 06:15:39 +0000 (08:15 +0200)]
x86: fold certain legacy/VEX table entries

Introduce macro V to expand to 'v' in the VEX/EVEX case, and replace a
couple of abort()s where legacy code can now legitimately make it. While
there for {,V}LDDQU drop hoing through mod_table[] - OP_M() rejects
register operands quite fine.

13 months agold/PDB: fix off-by-1 in add_globals_ref()
Jan Beulich [Tue, 11 Jul 2023 06:14:57 +0000 (08:14 +0200)]
ld/PDB: fix off-by-1 in add_globals_ref()

Copying one too many bytes can corrupt memory, detected/reported by
glibc on a 32-bit distro.

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

13 months agoRemove target_close
Tom Tromey [Mon, 10 Jul 2023 00:46:53 +0000 (18:46 -0600)]
Remove target_close

I noticed that target_close is only called in two places:
solib-svr4.c, and target_ops_ref_policy::decref.

This patch fixes the former by changing target_bfd_reopen to return a
target_ops_up and then fixing the sole caller.  Then it removes
target_close by inlining its body into the decref method.

The advantage of this approach is that targets are now automatically
managed.

Regression tested on x86-64 Fedora 38.

Approved-By: Andrew Burgess <aburgess@redhat.com>
13 months agoUpdate TUI window title when changed
Tom Tromey [Thu, 29 Jun 2023 17:26:55 +0000 (11:26 -0600)]
Update TUI window title when changed

I wrote a TUI window in Python, and I noticed that setting its title
did not result in a refresh, so the new title did not appear.  This
patch corrects this problem.

13 months agoAdd Ada scope test for DAP
Tom Tromey [Thu, 22 Jun 2023 15:17:26 +0000 (09:17 -0600)]
Add Ada scope test for DAP

This adds a DAP test for fetching scopes and variables with an Ada
program.  This test is the reason that the FrameVars code does not
check is_constant on the symbols it returns.

Note that this test also shows that string-printing is incorrect in
Ada.  This is a known bug but I'm still considering how to fix it.

13 months agoHandle typedefs in no-op pretty printers
Tom Tromey [Thu, 22 Jun 2023 15:00:13 +0000 (09:00 -0600)]
Handle typedefs in no-op pretty printers

The no-ops pretty-printers that were introduced for DAP have a classic
gdb bug: they neglect to call check_typedef.  This will cause some
strange behavior; for example not showing the children of a variable
whose type is a typedef of a structure type.  This patch fixes the
oversight.

13 months agoReimplement DAP stack traces using frame filters
Tom Tromey [Wed, 14 Jun 2023 12:09:23 +0000 (06:09 -0600)]
Reimplement DAP stack traces using frame filters

This reimplements DAP stack traces using frame filters.  This slightly
simplifies the code, because frame filters and DAP were already doing
some similar work.  This also renames RegisterReference and
ScopeReference to make it clear that these are private (and so changes
don't have to worry about other files).

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

13 months agoSimplify FrameVars
Tom Tromey [Wed, 14 Jun 2023 14:32:08 +0000 (08:32 -0600)]
Simplify FrameVars

FrameVars implements its own variant of Symbol.is_variable.  This
patch replaces this code.

13 months agoFix oversights in frame decorator code
Tom Tromey [Wed, 14 Jun 2023 14:31:21 +0000 (08:31 -0600)]
Fix oversights in frame decorator code

The frame decorator "FrameVars" code misses a couple of cases,
discovered when working on related DAP changes.

First, fetch_frame_locals does not stop when reaching a function
boundary.  This means it would return locals from any enclosing
functions.

Second, fetch_frame_args assumes that all arguments are at the
outermost scope, but this doesn't seem to be required by gdb.

13 months agoAdd new interface to frame filter iteration
Tom Tromey [Wed, 14 Jun 2023 12:54:13 +0000 (06:54 -0600)]
Add new interface to frame filter iteration

This patch adds a new function, frame_iterator, that wraps the
existing code to find and execute the frame filters.  However, unlike
execute_frame_filters, it will always return an iterator -- whereas
execute_frame_filters will return None if no frame filters apply.

Nothing uses this new function yet, but it will used by a subsequent
DAP patch.

13 months agoFix execute_frame_filters doc string
Tom Tromey [Wed, 14 Jun 2023 12:27:49 +0000 (06:27 -0600)]
Fix execute_frame_filters doc string

When reading the doc string for execute_frame_filters, I wasn't sure
if the ranges were inclusive or exclusive.  This patch updates the doc
string to reflect my findings, and also fixes an existing typo.

13 months agoChange 'handle_id' to be a local variable
Tom Tromey [Sun, 26 Jun 2022 20:17:05 +0000 (14:17 -0600)]
Change 'handle_id' to be a local variable

The global variable 'handle_id' in tracectf.c is only used in a single
function, so change it to be a local variable.

Reviewed-by: Keith Seitz <keiths@redhat.com>
13 months agoMove definition of ctf_target type
Tom Tromey [Sun, 26 Jun 2022 15:19:46 +0000 (09:19 -0600)]
Move definition of ctf_target type

This moves the definition of the ctf_target type into the
HAVE_LIBBABELTRACE block.  This type is only used in this block, so it
makes sense to only define it there.

Reviewed-by: Keith Seitz <keiths@redhat.com>
13 months agoConstify tfile_interp_line
Tom Tromey [Sun, 9 Jul 2023 15:00:42 +0000 (09:00 -0600)]
Constify tfile_interp_line

This adds 'const' to tfile_interp_line.

Reviewed-by: Keith Seitz <keiths@redhat.com>
13 months agoUse function_view in traceframe_walk_blocks
Tom Tromey [Thu, 23 Jun 2022 17:23:43 +0000 (11:23 -0600)]
Use function_view in traceframe_walk_blocks

This change traceframe_walk_blocks to take a function_view.  This
simplifies the code somewhat and lets us entirely remove one helper
function.

Reviewed-by: Keith Seitz <keiths@redhat.com>
13 months agoUse unique_ptr for trace_dirname
Tom Tromey [Sun, 9 Jul 2023 15:05:21 +0000 (09:05 -0600)]
Use unique_ptr for trace_dirname

This changes trace_dirname to use unique_ptr, removing some manual
memory management.

Reviewed-by: Keith Seitz <keiths@redhat.com>
13 months agoUse unique_ptr for trace_filename
Tom Tromey [Thu, 23 Jun 2022 00:09:32 +0000 (18:09 -0600)]
Use unique_ptr for trace_filename

This changes trace_filename to use unique_ptr, removing some manual
memory management.

Reviewed-by: Keith Seitz <keiths@redhat.com>
13 months agoReplace use of xfree with byte_vector
Tom Tromey [Wed, 22 Jun 2022 23:36:05 +0000 (17:36 -0600)]
Replace use of xfree with byte_vector

This replaces a use of xfree with a byte_vector.

Reviewed-by: Keith Seitz <keiths@redhat.com>
13 months agoRemove a use of xfree
Tom Tromey [Wed, 22 Jun 2022 23:31:17 +0000 (17:31 -0600)]
Remove a use of xfree

This removes a use of xfree from tracefile-tfile.c, replacing it with
a unique_xmalloc_ptr.

Reviewed-by: Keith Seitz <keiths@redhat.com>
13 months agoAvoid crash with absolute symbol
Tom Tromey [Tue, 20 Jun 2023 21:18:23 +0000 (15:18 -0600)]
Avoid crash with absolute symbol

A user supplied an executable and a remote logfile that could be used
to crash gdb.  The problem is that the BFD section for a particular
symbol was null, because the section was not marked "allocated".
Digging deeper, the problem was that elfread.c dropped the section for
absolute symbols.  This patch fixes the crash.

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

13 months agogdbserver: handle all eval_result_type values in tracepoint.cc
Andrew Burgess [Fri, 7 Jul 2023 16:18:46 +0000 (17:18 +0100)]
gdbserver: handle all eval_result_type values in tracepoint.cc

It was pointed out[1] that after this commit:

  commit 3812b38d8de5804ad3eadd6c7a5d532402ddabab
  Date:   Thu Oct 20 11:14:33 2022 +0100

      gdbserver: allow agent expressions to fail with invalid memory access

Now that agent expressions might fail with the error
expr_eval_invalid_memory_access, we might overflow the
eval_result_names array in tracepoint.cc.  This is because the
eval_result_names array does not include a string for either
expr_eval_invalid_goto or expr_eval_invalid_memory_access.

I don't know if having expr_eval_invalid_goto missing is also a
problem, but it feels like eval_result_names should just include a
string for every possible error.

I could just add two more strings into the array, but I figure that a
more robust solution will be to move all of the error types, and their
associated strings, into a new ax-result-types.def file, and to then
include this file in both ax.h and tracepoint.cc in order to build
the enum eval_result_type and the eval_result_names string array.
Doing this means it is impossible to have a missing error string in
the future.

[1] https://inbox.sourceware.org/gdb-patches/01059f8a-0e59-55b5-f530-190c26df5ba3@palves.net/

Approved-By: Pedro Alves <pedro@palves.net>
13 months agogdb/testsuite: avoid stack addresses in test names
Andrew Burgess [Mon, 10 Jul 2023 11:16:30 +0000 (12:16 +0100)]
gdb/testsuite: avoid stack addresses in test names

When comparing the test results for two different runs of GDB I
noticed a difference in the results for gdb.base/frame-view.exp.

The difference was caused by one of the tests including a stack
address in the test name:

  PASS: gdb.base/frame-view.exp: with_pretty_printer=false: select-frame view 0x7ffff7c5cea8 0x40115b

and

  PASS: gdb.base/frame-view.exp: with_pretty_printer=true: select-frame view 0x7ffff7c5cea8 0x40115b

If for whatever reason the stack address changes between test runs
then it becomes harder to compare results.

Fix this by giving the test a descriptive name that doesn't include a
stack address:

  PASS: gdb.base/frame-view.exp: with_pretty_printer=false: select thread 2 frame from thread 1

and

  PASS: gdb.base/frame-view.exp: with_pretty_printer=true: select thread 2 frame from thread 1

There's no change to what is actually tested after this commit.

13 months agogdb/testsuite: return after reporting a test unsupported
Andrew Burgess [Mon, 10 Jul 2023 11:05:21 +0000 (12:05 +0100)]
gdb/testsuite: return after reporting a test unsupported

In this commit:

  commit 8bcead69665af3a9f9867cd34c3a1daf22120027
  Date:   Tue May 23 11:25:01 2023 +0100

      gdb/testsuite: add test for core file with a 0 pid

a new test gdb.arch/core-file-pid0.exp was added.  This test includes
a pre-generated core file for x86-64 and for other architectures the
test reports 'unsupported'.

However, after reporting 'unsupported' the test failed to perform an
early return, so the test would then carry on and try to actually
perform the test, which resulted in some TCL errors.

Fix this by returning after reporting the test unsupported.

13 months agogdb: include location number in breakpoint error message
Andrew Burgess [Fri, 7 Jul 2023 15:36:26 +0000 (16:36 +0100)]
gdb: include location number in breakpoint error message

This commit improves the output of this previous commit:

  commit 2dc3457a454a35d0617dc1f9cc1db77468471f95
  Date:   Fri Oct 14 13:22:55 2022 +0100

      gdb: include breakpoint number in testing condition error message

The earlier commit extended the error message:

  Error in testing breakpoint condition:

to include the breakpoint number, e.g.:

  Error in testing breakpoint condition 3:

This commit extends takes this further, and includes the location
number if the breakpoint has multiple locations, so we might now see:

  Error in testing breakpoint condition 3.2:

Just as with how GDB reports a normal breakpoint stop, if a breakpoint
only has a single location then the location number is not included,
this keeps things nice and consistent.

I've extended one of the tests to cover the new functionality.

Approved-By: Pedro Alves <pedro@palves.net>
13 months agogdb/testsuite: Testing with the nvfortran compiler
Richard Bunt [Mon, 10 Jul 2023 07:43:59 +0000 (08:43 +0100)]
gdb/testsuite: Testing with the nvfortran compiler

Currently, the Fortran test suite does not run with NVIDIA's Fortran
compiler (nvfortran).

The goal here is to get the tests running and preventing further
regressions during future work. This change does not do anything to fix
existing failures.

Teach the compiler detection about nvfortran. There is no underlying
information about whether this compiler is related to flang classic or
flang, so we cannot reuse the main and type definitions. Therefore, we
explicitly record the main method and type information observed when
using nvfortran.

The main name was extracted by trying to set breakpoints on both MAIN_
and MAIN__.

The following mapping of test to type names was used to extract how
nvfortran reports types.

info-types.exp: fortran_int4, fortran_int8, fortran_real4,
fortran_logical4

common-block.exp: fortran_real8

complex.exp: fortran_complex4 fortran_complex8

logical.exp: fortran_character1. Ran ptype on "c".

Types defined as fortran_complex16 do not compile with nvfortran, so it
was left unset.

gdb.fortran regression tests run with GNU, Intel, Intel LLVM and ACfL.
No regressions detected.

The gdb.fortran test results with nvfortran 23.3 are as follows.

Before:

    # of expected passes        523
    # of unexpected failures    107
    # of known failures         2
    # of unresolved testcases   1
    # of untested testcases     7
    # of duplicate test names   2

After:

    # of expected passes        5696
    # of unexpected failures    271
    # of known failures         12
    # of untested testcases     9
    # of unsupported tests      5

As can be seen from the above, there are now considerably more passing
assertions.

Approved-By: Tom Tromey <tom@tromey.com>
13 months agoAutomatic date update in version.in
GDB Administrator [Mon, 10 Jul 2023 00:00:12 +0000 (00:00 +0000)]
Automatic date update in version.in

13 months agoPR30592 objcopy: allow --set-section-flags to add or remove SHF_X86_64_LARGE
Fangrui Song [Sun, 9 Jul 2023 17:57:19 +0000 (10:57 -0700)]
PR30592 objcopy: allow --set-section-flags to add or remove SHF_X86_64_LARGE

For example, objcopy --set-section-flags .data=alloc,large will add
SHF_X86_64_LARGE to the .data section.  Omitting "large" will drop the
SHF_X86_64_LARGE flag.

The bfd_section flag is named generically, SEC_ELF_LARGE, in case other
processors want to follow SHF_X86_64_LARGE.  SEC_ELF_LARGE has the same
value as SEC_TIC54X_BLOCK used by coff.

bfd/
    * section.c: Define SEC_ELF_LARGE.
    * bfd-in2.h: Regenerate.
    * elf64-x86-64.c (elf_x86_64_section_flags, elf_x86_64_fake_sections,
    elf_x86_64_copy_private_section_data): New.

binutils/
    * NEWS: Mention the new feature for objcopy.
    * doc/binutils.texi: Mention "large".
    * objcopy.c (parse_flags): Parse "large".
    (check_new_section_flags): Error if "large" is used with a
    non-x86-64 ELF target.
    * testsuite/binutils-all/x86-64/large-sections.d: New.
    * testsuite/binutils-all/x86-64/large-sections.s: New.
    * testsuite/binutils-all/x86-64/large-sections-i386.d: New.
    * testsuite/binutils-all/x86-64/large-sections-2.d: New.
    * testsuite/binutils-all/x86-64/large-sections-2-x32.d: New.

13 months agoAutomatic date update in version.in
GDB Administrator [Sun, 9 Jul 2023 00:00:09 +0000 (00:00 +0000)]
Automatic date update in version.in

13 months agogdb/cp-namespace.c: Fix assert failure caused by malformed user input
Aaron Merey [Tue, 4 Jul 2023 22:38:16 +0000 (18:38 -0400)]
gdb/cp-namespace.c: Fix assert failure caused by malformed user input

When debugging C++ programs, it is possible to trigger a spurious assert
failure when attempting to set a breakpoint on a malformed symbol name.
Names of the form 'A>::B' and 'A)::B' trigger this assert failure in
cp_lookup_bare_symbol:

    $ gdb gdb
    [...]
    (gdb) br test>::assert
    Function "test>::assert" not defined.
    Make breakpoint pending on future shared library load? (y or [n]) y
    Breakpoint 1 (test>::assert) pending.
    (gdb) start
    [...]
    cp-namespace.c:181: internal-error: cp_lookup_bare_symbol: Assertion `strstr (name, "::") == NULL' failed.
    A problem internal to GDB has been detected,
    further debugging may prove unreliable.
    ----- Backtrace -----
    0x5217e2 gdb_internal_backtrace_1
            /home/amerey/binutils-gdb/gdb/bt-utils.c:122
    0x521885 _Z22gdb_internal_backtracev
            /home/amerey/binutils-gdb/gdb/bt-utils.c:168
    0xaf8303 internal_vproblem
            /home/amerey/binutils-gdb/gdb/utils.c:396
    0xaf86be _Z15internal_verrorPKciS0_P13__va_list_tag
            /home/amerey/binutils-gdb/gdb/utils.c:476
    0xccdb3f _Z18internal_error_locPKciS0_z
            /home/amerey/binutils-gdb/gdbsupport/errors.cc:58
    0x5dded9 cp_lookup_bare_symbol
            /home/amerey/binutils-gdb/gdb/cp-namespace.c:181
    0x5de39d cp_lookup_symbol_in_namespace
            /home/amerey/binutils-gdb/gdb/cp-namespace.c:328
    [...]

Currently this assert is skipped if the symbol name contains '<' or '('.
Fix this spurious failure by also skipping the assert when the symbol
name contains '>' or ')'.

Regression tested on F38 x86_64.

Approved-By: Tom Tromey <tom@tromey.com>
13 months agoAutomatic date update in version.in
GDB Administrator [Sat, 8 Jul 2023 00:00:11 +0000 (00:00 +0000)]
Automatic date update in version.in

13 months agoFix result of DAP setExpression
Tom Tromey [Wed, 21 Jun 2023 12:23:20 +0000 (06:23 -0600)]
Fix result of DAP setExpression

A co-worker, Andry, noticed that the DAP setExpression implementation
returned the wrong fields -- it used "result" rather than "value", and
included "memoryReference", which isn't in the spec (an odd oversight,
IMO).

This patch fixes the problems.

13 months agoRemove unchecked casts to mi_interp
Tom Tromey [Thu, 8 Jun 2023 20:06:45 +0000 (14:06 -0600)]
Remove unchecked casts to mi_interp

Simon noticed a crash that could be caused via new Python
gdb.execute_mi function.  Looking into this, I found a few unchecked
casts to mi_interp, like:

-  struct mi_interp *mi = (struct mi_interp *) command_interp ();

This patch replaces all such casts with safer variants.

For -gdb-exit and mi_load_progress, I chose to have the functions
simply not generate any output.  It didn't seem useful to do so.

Some casts I eliminated by adding a parameter to a function.  Then, in
mi_execute_command, I changed the code to use
gdb::checked_static_cast.  This is appropriate because this particular
overload can only be called by the MI interpreter.

There does not seem to be a very good way to test -gdb-exit.

Regression tested on x86-64 Fedora 36.

13 months agogdb: check max-value-size when reading strings for printf
Andrew Burgess [Wed, 31 May 2023 20:41:48 +0000 (21:41 +0100)]
gdb: check max-value-size when reading strings for printf

I noticed that the printf code for strings, printf_c_string and
printf_wide_c_string, don't take max-value-size into account, but do
load a complete string from the inferior into a GDB buffer.

As such it would be possible for an badly behaved inferior to cause
GDB to try and allocate an excessively large buffer, potentially
crashing GDB, or at least causing GDB to swap lots, which isn't
great.

We already have a setting to protect against this sort of thing, the
'max-value-size'.  So this commit updates the two function mentioned
above to check the max-value-size and give an error if the
max-value-size is exceeded.

If the max-value-size is exceeded, I chose to continue reading
inferior memory to figure out how long the string actually is, we just
don't store the results.  The benefit of this is that when we give the
user an error we can tell the user how big the string actually is,
which would allow them to correctly adjust max-value-size, if that's
what they choose to do.

The default for max-value-size is 64k so there should be no user
visible changes after this commit, unless the user was previously
printing very large strings.  If that is the case then the user will
now need to increase max-value-size.

13 months agogdb: remove last alloca call from printcmd.c
Andrew Burgess [Wed, 31 May 2023 19:57:01 +0000 (20:57 +0100)]
gdb: remove last alloca call from printcmd.c

This commit removes the last alloca call from printcmd.c.  This is
similar to the patches I originally posted here:

  https://inbox.sourceware.org/gdb-patches/cover.1677533215.git.aburgess@redhat.com/

However, this change was not included in that original series.

The original series received push back because it was thought that
replacing alloca with a C++ container type would introduce unnecessary
malloc/free overhead.

However, in this case we are building a string, and (at least for
GCC), the std::string type has a small string optimisation, where
small strings are stored on the stack.

And in this case we are building what will usually be a very small
string, we're just constructing a printf format specifier for a hex
value, so it'll be something like '%#x' -- though it could also have a
width in there too -- but still, it should normally fit within GCCs
small string buffer.

So, in this commit, I propose replacing the use of alloca with a
std::string.  This shouldn't result (normally) in any additional
malloc or free calls, so should be similar in performance to the
original approach.

There should be no user visible differences after this commit.

13 months agogdb: remove two uses of alloca from printcmd.c
Andrew Burgess [Mon, 27 Feb 2023 13:47:10 +0000 (13:47 +0000)]
gdb: remove two uses of alloca from printcmd.c

Remove a couple of uses of alloca from printcmd.c, and replace them
with gdb::byte_vector.

An earlier variant of this patch was proposed in this thread:

  https://inbox.sourceware.org/gdb-patches/cover.1677533215.git.aburgess@redhat.com/

however, there was push back on that thread due to it adding extra
dynamic allocation, i.e. moving the memory buffers off the stack on to
the heap.

However, of all the patches originally proposed, I think in these two
cases moving off the stack is the correct thing to do.  Unlike all the
other patches in the original series, where the data being read
was (mostly) small in size, a register, or a couple of registers, in
this case we are reading an arbitrary string from the inferior.  This
could be any size, and so should not be placed on the stack.

So in this commit I replace the use of alloca with std::byte_vector
and simplify the logic a little (I think) to take advantage of the
ability of std::byte_vector to dynamically grow in size.

Of course, really, we should probably be checking the max-value-size
setting as we load the string to stop GDB crashing if a corrupted
inferior causes GDB to try read a stupidly large amount of
memory... but I'm leaving that for a follow on patch.

There should be no user visible changes after this commit.

13 months agogdb: fix printf of wchar_t early in a gdb session
Andrew Burgess [Wed, 31 May 2023 15:14:47 +0000 (16:14 +0100)]
gdb: fix printf of wchar_t early in a gdb session

Given this test program:

  #include <wchar.h>

  const wchar_t wide_str[] = L"wide string";

  int
  main (void)
  {
    return 0;
  }

I observed this GDB behaviour:

  $ gdb -q /tmp/printf-wchar_t
  Reading symbols from /tmp/printf-wchar_t...
  (gdb) start
  Temporary breakpoint 1 at 0x40110a: file /tmp/printf-wchar_t.c, line 8.
  Starting program: /tmp/printf-wchar_t

  Temporary breakpoint 1, main () at /tmp/printf-wchar_t.c:8
  25   return 0;
  (gdb) printf "%ls\n", wide_str

  (gdb)

Notice that the printf results in a blank line rather than the
expected 'wide string' output.

I tracked the problem down to printf_wide_c_string (in printcmd.c), in
this function we do this:

  struct type *wctype = lookup_typename (current_language,
 "wchar_t", NULL, 0);
  int wcwidth = wctype->length ();

the problem here is that 'wchar_t' is a typedef.  If we look at the
comment on type::length() we see this:

  /* Note that if thistype is a TYPEDEF type, you have to call check_typedef.
     But check_typedef does set the TYPE_LENGTH of the TYPEDEF type,
     so you only have to call check_typedef once.  Since value::allocate
     calls check_typedef, X->type ()->length () is safe.  */

What this means is that after calling lookup_typename we should call
check_typedef in order to ensure that the length of the typedef has
been setup correctly.  We are not doing this in printf_wide_c_string,
and so wcwidth is incorrectly calculated as 0.  This is what leads GDB
to print an empty string.

We can see in c_string_operation::evaluate (in c-lang.c) an example of
calling check_typedef specifically to fix this exact issue.

Initially I did fix this problem by adding a check_typedef call into
printf_wide_c_string, but then I figured why not move the
check_typedef call up into lookup_typename itself, that feels like it
should be harmless when looking up a non-typedef type, but will avoid
bugs like this when looking up a typedef.  So that's what I did.

I can then remove the extra check_typedef call from c-lang.c, I don't
see any other places where we had extra check_typedef calls.  This
doesn't mean we definitely had bugs -- so long as we never checked the
length, or, if we knew that check_typedef had already been called,
then we would be fine.

I don't see any test regressions after this change, and my new test
case is now passing.

Reviewed-By: Tom Tromey <tom@tromey.com>
13 months agold: fix build with old glibc / gcc
Jan Beulich [Fri, 7 Jul 2023 12:10:21 +0000 (14:10 +0200)]
ld: fix build with old glibc / gcc

"rename" conflicts with a function of that name, which gcc from that
same timeframe then complains about. Use a name matching that of
struct input_remap's respective field.

13 months agoarc: Update/Add ARCv3 support.
Claudiu Zissulescu [Fri, 7 Jul 2023 09:58:34 +0000 (12:58 +0300)]
arc: Update/Add ARCv3 support.

The ARC HS5x and ARC HS6x processors are based on the new ARCv3 ISA
that implements a full range of 32-bit and 64-bit instructions.  These
processors feature a high-speed 10-stage, dual-issue pipeline that
offers increased utilization of functional units with a limited
increase in power and area.  The HS5x processors feature a 32-bit
pipeline that can execute all ARCv3 32-bit instructions, while the
HS6x processors feature a full 64-bit pipeline and register file that
can execute both 32-bit and 64-bit instructions.  In addition, the ARC
HS6x supports 64-bit virtual and 52-bit physical address spaces to
enable direct addressing of current and future large memories, as well
as 128-bit loads and stores for efficient data movement.

This readelf patch updates/adds Synopsys ARCv3 machine name fileds and
supported relocations.

Signed-off-by: Claudiu Zissulescu <claziss@synopsys.com>
13 months agogdb/testsuite: fix license on recently added file
Andrew Burgess [Fri, 7 Jul 2023 09:51:53 +0000 (10:51 +0100)]
gdb/testsuite: fix license on recently added file

The license header on a file I recently contributed was incorrect.
The file was added in commit:

  commit 087969169836f802a09b1cd0502d2f22d7a8f7dc
  Date:   Tue May 23 11:25:21 2023 +0100

      gdb: handle core files with .reg/0 section names

The problems were:

  - GPLv2 instead of GPLv3,
  - Use the FSF postal address rather than their URL.

Nobody else has touched the file since I merged it, so I don't believe
there are any problems with me changing the license, this commit does
just that.

13 months agoUdated Freach and Romainian translations for various sub-directories
Nick Clifton [Fri, 7 Jul 2023 08:40:20 +0000 (09:40 +0100)]
Udated Freach and Romainian translations for various sub-directories

13 months agoMinor updates to release readme
Nick Clifton [Fri, 7 Jul 2023 08:39:16 +0000 (09:39 +0100)]
Minor updates to release readme

13 months agoAutomatic date update in version.in
GDB Administrator [Fri, 7 Jul 2023 00:00:09 +0000 (00:00 +0000)]
Automatic date update in version.in

13 months agoLinux: Avoid pread64/pwrite64 for high memory addresses (PR gdb/30525)
Pedro Alves [Wed, 7 Jun 2023 09:38:14 +0000 (10:38 +0100)]
Linux: Avoid pread64/pwrite64 for high memory addresses (PR gdb/30525)

Since commit 05c06f318fd9 ("Linux: Access memory even if threads are
running"), GDB prefers pread64/pwrite64 to access inferior memory
instead of ptrace.  That change broke reading shared libraries on
SPARC64 Linux, as reported by PR gdb/30525 ("gdb cannot read shared
libraries on SPARC64").

On SPARC64 Linux, surprisingly (to me), userspace shared libraries are
mapped at high 64-bit addresses:

   (gdb) info sharedlibrary
   Cannot access memory at address 0xfff80001002011e0
   Cannot access memory at address 0xfff80001002011d8
   Cannot access memory at address 0xfff80001002011d8
   From                To                  Syms Read   Shared Object Library
   0xfff80001000010a0  0xfff8000100021f80  Yes (*)     /lib64/ld-linux.so.2
   (*): Shared library is missing debugging information.

Those addresses are 64-bit addresses with the high bits set.  When
interpreted as signed, they're negative.

The Linux kernel rejects pread64/pwrite64 if the offset argument of
type off_t (a signed type) is negative, which happens if the memory
address we're accessing has its high bit set.  See
linux/fs/read_write.c sys_pread64 and sys_pwrite64 in Linux.

Thankfully, lseek does not fail in that situation.  So the fix is to
use the 'lseek + read|write' path if the offset would be negative.

Fix this in both native GDB and GDBserver.

Tested on a SPARC64 GNU/Linux and x86-64 GNU/Linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30525
Change-Id: I79c724f918037ea67b7396fadb521bc9d1b10dc5

13 months agoriscv: Ensure LE instruction fetching
Branislav Brzak [Tue, 20 Jun 2023 14:19:55 +0000 (16:19 +0200)]
riscv: Ensure LE instruction fetching

Currently riscv gdb code looks at arch byte order
when fetching instructions. This works when the
target is LE, but on BE arch it will byte swap the
instruction, while the riscv spec defines all
instructions are LE encoded regardless of
system memory endianess.

13 months agoFix Solaris regression (PR tdep/30252)
Pedro Alves [Thu, 6 Jul 2023 14:05:11 +0000 (15:05 +0100)]
Fix Solaris regression (PR tdep/30252)

PR tdep/30252 reports that using GDB on Solaris fails an assertion in
target_resume:

 target.c:2648: internal-error: target_resume: Assertion `inferior_ptid != null_ptid' failed.
 A problem internal to GDB has been detected,
 further debugging may prove unreliable.
 Quit this debugging session? (y or n)

The backtrace, after running it through c++filt, looks like:

 ----- Backtrace -----
 0xa18914 gdb_internal_backtrace_1
 /root/binutils-gdb/gdb/bt-utils.c:122
 0xa18914 gdb_internal_backtrace()
 /root/binutils-gdb/gdb/bt-utils.c:168
 0xdec834 internal_vproblem
 /root/binutils-gdb/gdb/utils.c:401
 0xdecad8 internal_verror(char const*, int, char const*, __va_list_tag*)
 /root/binutils-gdb/gdb/utils.c:481
 0xf3638c internal_error_loc(char const*, int, char const*, ...)
 /root/binutils-gdb/gdbsupport/errors.cc:58
 0xd70580 target_resume(ptid_t, int, gdb_signal)
 /root/binutils-gdb/gdb/target.c:2648
 0xc59e85 procfs_target::wait(ptid_t, target_waitstatus*, enum_flags<target_wait_flag>)
 /root/binutils-gdb/gdb/procfs.c:2187
 0xcf6da7 sol_thread_target::wait(ptid_t, target_waitstatus*, enum_flags<target_wait_flag>)
 /root/binutils-gdb/gdb/sol-thread.c:442
 0xd73711 target_wait(ptid_t, target_waitstatus*, enum_flags<target_wait_flag>)
 /root/binutils-gdb/gdb/target.c:2586
 ...

The problem is that the procfs backend, while inside target_wait,
called target_resume without switching to the leader thread of that
resumption.

The target_resume interface is:

 /* Resume execution (or prepare for execution) of the current thread
    (INFERIOR_PTID), while optionally letting other threads of the
    current process or all processes run free.
    ...

Thus calling target_resume with inferior_ptid == null_ptid is bogus.

target_wait (which leads to procfs_target::wait on Solaris) is called
with inferior_ptid == null_ptid on entry exactly to help catch such
bogus uses.

From the backtrace, it seems that the relevant line in question is
procfs.c:2187:

2186  /* How to keep going without returning to wfi: */
2187  target_continue_no_signal (ptid);
2188  goto wait_again;

target_continue_no_signal is a small wrapper around target_resume,
which would make sense.

The fix is to not call target_resume or go via the target stack at
all.  Instead, factor out a new proc_resume function out of
procfs_target::resume, and call that.  The new function does not rely
on inferior_ptid.

I've not been able to test it myself, but Petr confirmed it fixes the
assertion failure with his test case, and Marcel Telka also confirmed
it solves the problem.

Tested-By: Petr Šumbera <petr.sumbera@oracle.com>
Tested-By: Marcel Telka <marcel@telka.sk>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30252
Change-Id: I6213c59b081d400a22e799ee621c2eff6dcafbf3