]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
14 months agoelf: Use mmap to map in read-only sections
H.J. Lu [Thu, 29 Feb 2024 19:17:01 +0000 (11:17 -0800)] 
elf: Use mmap to map in read-only sections

There are many linker input files in LLVM debug build with huge string
sections.  All these string sections can be treated as read-only.  But
linker copies all of them into memory which consumes huge amount of
memory and slows down linker significantly.

Add _bfd_mmap_readonly_persistent and _bfd_mmap_readonly_temporary to
mmap in reado-only sections with size >= 4 * page size.

NB: All string sections in valid ELF inputs must be null terminated.
There is no need to terminate it again and string sections are mmapped
as read-only.

* bfd.c (bfd_mmapped_entry): New.
(bfd_mmapped): Likewise.
(bfd): Add mmapped.
* bfdwin.c (bfd_get_file_window): Use _bfd_pagesize.
* cache.c (cache_bmmap): Remove pagesize_m1 and use pagesize_m1
instead.
* elf.c (bfd_elf_get_str_section): Call
_bfd_mmap_readonly_persistent instead of _bfd_alloc_and_read.
Don't terminate the string section again.
(get_hash_table_data): Call _bfd_mmap_readonly_temporary and
_bfd_munmap_readonly_temporary instead of _bfd_malloc_and_read
and free.
(_bfd_elf_get_dynamic_symbols): Call _bfd_mmap_readonly_persistent
instead of _bfd_alloc_and_read.  Don't terminate the string
section again.  Call _bfd_mmap_readonly_temporary and
_bfd_munmap_readonly_temporary instead of _bfd_malloc_and_read
and free.
(_bfd_elf_slurp_version_tables): Call _bfd_mmap_readonly_temporary
and _bfd_munmap_readonly_temporary instead of _bfd_malloc_and_read
and free.
* elflink.c (bfd_elf_link_record_dynamic_symbol): Use bfd_malloc
to get the unversioned symbol.
* libbfd-in.h (_bfd_pagesize): New.
(_bfd_pagesize_m1): Likewise.
(_bfd_minimum_mmap_size): Likewise.
(_bfd_mmap_readonly_persistent): Likewise.
(_bfd_mmap_readonly_temporary): Likewise.
(_bfd_munmap_readonly_temporary): Likewise.
* libbfd.c
(bfd_allocate_mmapped_page): New.
(_bfd_mmap_readonly_temporary): Likewise.
(_bfd_munmap_readonly_temporary): Likewise.
(_bfd_mmap_readonly_persistent): Likewise.
(_bfd_pagesize): Likewise.
(_bfd_pagesize_m1): Likewise.
(_bfd_minimum_mmap_size): Likewise.
(bfd_init_pagesize): Likewise.
* lynx-core.c (lynx_core_file_p): Use _bfd_pagesize.
* opncls.c (_bfd_delete_bfd): Munmap tracked mmapped memories.
* sysdep.h (MAP_ANONYMOUS): New. Define if undefined.
* bfd-in2.h: Regenerated.
* libbfd.h: Likewise.

14 months agoRevert "gdb/compile: Use std::filesystem::remove_all in cleanup"
Lancelot SIX [Wed, 3 Apr 2024 14:39:10 +0000 (15:39 +0100)] 
Revert "gdb/compile: Use std::filesystem::remove_all in cleanup"

This reverts commit 7bba0ad08576309763e3f41193eaa93025e10b8b.

Tom de Vries reported that 7bba0ad0857 (gdb/compile: Use
std::filesystem::remove_all in cleanup) broke builds with gcc-7.5.0
which mostly supports c++17, but not std::filesystem[1].  As this change
is not critical, revert it to maintain compatibility.

[1] https://inbox.sourceware.org/gdb-patches/a06e6483-aa2e-4b8a-854f-e369a1e961ea@suse.de/

Change-Id: I58150bd27600c95052bdf1bbbd6b44718a5a0bbf
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31420
Approved-By: Tom Tromey <tom@tromey.com>
14 months agodoc: add the missing 'handle' attribute in xml
Tankut Baris Aktemur [Wed, 3 Apr 2024 14:43:53 +0000 (16:43 +0200)] 
doc: add the missing 'handle' attribute in xml

The XML response to the "qXfer:threads:read" packet may include
a "handle" attribute.  The attribute is mentioned in the document
but not shown in the sample XML structure.  Add it.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
14 months agogdb/compile: Use std::filesystem::remove_all in cleanup
Lancelot SIX [Sun, 3 Mar 2024 16:47:56 +0000 (16:47 +0000)] 
gdb/compile: Use std::filesystem::remove_all in cleanup

In a previous review, I noticed that some code in gdb/compile/compile.c
could use c++17's `std::filesystem::remove_all` instead of using some
`system ("rm -rf ...");`.

This patch implements this.

Note that I use the noexcept overload of std::filesystem::remove_all and
explicitly check for an error code.  This means that this code called
during the cleanup procedure cannot throw, and does not risk preventing
other cleanup functions to be called.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31420
Change-Id: If5668bf3e15e66c020e5c3b4fa999f861690e4cf
Approved-By: Tom Tromey <tom@tromey.com>
14 months agogdb: ensure has dwarf info before reading DWZ file
Lancelot SIX [Sat, 30 Mar 2024 11:01:21 +0000 (11:01 +0000)] 
gdb: ensure has dwarf info before reading DWZ file

I recent change (e9b738dfbdc "Avoid race when reading dwz file") moved
the call to dwarf2_read_dwz_file from dwarf2_initialize_objfile to
dwarf2_has_info.

Before that patch, dwarf2_initialize_objfile was only called when
dwarf2_has_info returned true, and since that patch it is always called.

When reading a file that has no debug info (.debug_info/.debug_abbrev
sections), but has a .gnu_debugaltlink section, GDB’s behavior is
different.  I can observe this when loading
/lib/x86_64-linux-gnu/libtinfo.so on Ubuntu 22.04 (or while debugging
any program dynamically loading this library).

Before e9b738dfbdc, we had:

    $ ./gdb/gdb -data-directory ./gdb/data-directory -q  /lib/x86_64-linux-gnu/libtinfo.so
    Reading symbols from /lib/x86_64-linux-gnu/libtinfo.so...
    (No debugging symbols found in /lib/x86_64-linux-gnu/libtinfo.so)
    (gdb)

while after we have:

    $ ./gdb/gdb -data-directory ./gdb/data-directory -q  /lib/x86_64-linux-gnu/libtinfo.so
    Reading symbols from /lib/x86_64-linux-gnu/libtinfo.so...

    warning: could not find '.gnu_debugaltlink' file for /usr/lib/x86_64-linux-gnu/libtinfo.so.6.3
    (No debugging symbols found in /lib/x86_64-linux-gnu/libtinfo.so)
    (gdb)

This patch restores the previous behavior of only trying to load the
DWZ file for objfiles when the main part of the debuginfo is present
(i.e. when dwarf2_has_info returns true).  We still make sure that
dwarf2_read_dwz_file is called at most once per objfile.

A consequence of this change is that the per_bfd->dwz_file optional
object can now remain empty (instead of containing a nullptr), so also
this patch also adjusts dwarf2_get_dwz_file to account for this
possibility.  This effectively reverts the changes to
dwarf2_get_dwz_file done by e9b738dfbdc.

Regression tested on x86_64-linux-gnu Ubuntu 22.04.

Approved-By: Tom Tromey <tom@tromey.com>
14 months agoFix null pointer dereference in process_debug_info()
Nick Clifton [Wed, 3 Apr 2024 10:19:33 +0000 (11:19 +0100)] 
Fix null pointer dereference in process_debug_info()

14 months agoExtend objdump's --show-all-symbols option so that it also shows the extra symbols...
Nick Clifton [Wed, 3 Apr 2024 10:16:23 +0000 (11:16 +0100)] 
Extend objdump's --show-all-symbols option so that it also shows the extra symbols referenced by an instruction.

14 months agoArm64: check tied operand specifier in aarch64-gen
Jan Beulich [Wed, 3 Apr 2024 08:42:44 +0000 (10:42 +0200)] 
Arm64: check tied operand specifier in aarch64-gen

Make sure that field actually matches the specified operands. Don't
follow existing F_PSEUDO checking in using assertions, though. Print
meaningful error messages, thus - while not having a line number
available - at least providing some indication of where things are
wrong.

Fix SVE2.1's extq accordingly, but don't extend the testsuite there:
There are further issues with its operands (SVE_Zm_imm4 doesn't look to
be correct to use there, as that describes an indexed vector register,
while here a separate vector register and immediate operand are to be
specified).

14 months agox86: add missing No_qSuf to non-64-bit PTWRITE
Jan Beulich [Wed, 3 Apr 2024 08:41:30 +0000 (10:41 +0200)] 
x86: add missing No_qSuf to non-64-bit PTWRITE

While largely benign, it still should have been put there when the
original single template was split (commit a04973848dc5).

14 months agox86: drop stray Size64 from WRSSQ
Jan Beulich [Wed, 3 Apr 2024 08:40:57 +0000 (10:40 +0200)] 
x86: drop stray Size64 from WRSSQ

Like for WRUSSQ it's not needed here. The legacy insn had gained it in
the course of zapping Rex64, but that attribute wasn't needed here
either. The APX insn then simply gained it by copy-and-paste, I suppose.

14 months agox86/APX: Remove KEYLOCKER and SHA promotions from EVEX MAP4
Cui, Lili [Tue, 2 Apr 2024 06:40:18 +0000 (14:40 +0800)] 
x86/APX: Remove KEYLOCKER and SHA promotions from EVEX MAP4

APX spec removed KEYLOCKER and SHA promotions from EVEX MAP4.
https://www.intel.com/content/www/us/en/developer/articles/technical/advanced-performance-extensions-apx.html

gas/ChangeLog:

        * NEWS: Mention that remove KEYLOCKER and SHA promotions from EVEX
* MAP4.
        * config/tc-i386.c (process_operands): Removed special handling of
* KEYLOCKER and SHA.
        * testsuite/gas/i386/x86-64-apx-egpr-promote-inval.l: Removed KEYLOCKER
        * and SHA instructions.
        * testsuite/gas/i386/x86-64-apx-egpr-promote-inval.s: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted-bad.d: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted-bad.s: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted-intel.d: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted-wig.d: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted.d: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted.s: Ditto.

opcodes/ChangeLog:

        * i386-dis-evex-prefix.h: Removed KEYLOCKER and SHA instructions.
        * i386-dis-evex.h: Ditto.
        * i386-opc.tbl: Ditto.
        * i386-dis.c (print_vector_reg): Removed special handling of KEYLOCKER
*  and SHA.

14 months agoAutomatic date update in version.in
GDB Administrator [Wed, 3 Apr 2024 00:00:14 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agolibiberty: Invoke D demangler when --format=auto
Tom Tromey [Sat, 30 Mar 2024 19:48:30 +0000 (13:48 -0600)] 
libiberty: Invoke D demangler when --format=auto

Investigating GDB PR d/31580 showed that the libiberty demangler
doesn't automatically demangle D mangled names.  However, I think it
should -- like C++ and Rust (new-style), D mangled names are readily
distinguished by the leading "_D", and so the likelihood of confusion
is low.  The other non-"auto" cases in this code are Ada (where the
encoded form could more easily be confused by ordinary programs) and
Java (which is long gone, but which also shared the C++ mangling and
thus was just an output style preference).

This patch also fixed another GDB bug, though of course that part
won't apply to the GCC repository.

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

libiberty
* cplus-dem.c (cplus_demangle): Try the D demangler with
"auto" format.
* testsuite/d-demangle-expected: Add --format=auto test.

14 months agoPrint type name when printing Rust slice
Tom Tromey [Thu, 7 Mar 2024 19:57:07 +0000 (12:57 -0700)] 
Print type name when printing Rust slice

The recent change to how unsized Rust values are printed included a
small regression from past behavior.  Previously, a slice's type would
be printed, like:

    (gdb) print slice
    $80 = &[i32] [3]

The patch changed this to just

    (gdb) print slice
    $80 = [3]

This patch restores the previous behavior.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30330
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31517

14 months agoConstify ada-lex.l:attributes
Tom Tromey [Thu, 14 Mar 2024 18:25:42 +0000 (12:25 -0600)] 
Constify ada-lex.l:attributes

While examining the Ada parser globals with 'nm', I noticed that the
lexer's "attributes" array should be const.  This change moves it into
read-only storage.

14 months agoRemove "numbuf" global
Tom Tromey [Thu, 14 Mar 2024 18:28:26 +0000 (12:28 -0600)] 
Remove "numbuf" global

The lexer has a "numbuf" global that is only used for temporary
storage.  This patch removes the global and redeclares it at the
points of use.

14 months agoMove "returned_complete" into ada_parse_state
Tom Tromey [Thu, 14 Mar 2024 18:30:28 +0000 (12:30 -0600)] 
Move "returned_complete" into ada_parse_state

This moves the "returned_complete" global into ada_parse_state.

14 months agoMove "paren_depth" into ada_parse_state
Tom Tromey [Thu, 14 Mar 2024 18:29:40 +0000 (12:29 -0600)] 
Move "paren_depth" into ada_parse_state

This moves the "paren_depth" global into ada_parse_state.

14 months agoMove "temp_parse_space" into ada_parse_state
Tom Tromey [Thu, 14 Mar 2024 18:22:04 +0000 (12:22 -0600)] 
Move "temp_parse_space" into ada_parse_state

This patch moves the "temp_parse_space" global into ada_parse_state.
It is also renamed to remove the redundant "parse".  Finally, it is
changed to an auto_obstack to avoid the need for any manual
management.

14 months agoMove "iterated_associations" into ada_parse_state
Tom Tromey [Thu, 14 Mar 2024 18:19:22 +0000 (12:19 -0600)] 
Move "iterated_associations" into ada_parse_state

This patch moves the "iterated_associations" global into
ada_parse_state.

14 months agoMove "assignments" global into ada_parse_state
Tom Tromey [Thu, 14 Mar 2024 18:17:30 +0000 (12:17 -0600)] 
Move "assignments" global into ada_parse_state

This patch moves the "assignments" global into ada_parse_state.

14 months agoMove "components" and "associations" into ada_parse_state
Tom Tromey [Thu, 14 Mar 2024 18:16:43 +0000 (12:16 -0600)] 
Move "components" and "associations" into ada_parse_state

This patch moves the "components" and "associations" globals into
ada_parse_state.

14 months agoMove "int_storage" global into ada_parse_state
Tom Tromey [Thu, 14 Mar 2024 18:13:30 +0000 (12:13 -0600)] 
Move "int_storage" global into ada_parse_state

This patch moves the "int_storage" global into ada_parse_state.

14 months agoIntroduce ada_parse_state
Tom Tromey [Thu, 14 Mar 2024 18:09:55 +0000 (12:09 -0600)] 
Introduce ada_parse_state

This patch introduces the ada_parse_state class and the ada_parser
global.  It also changes find_completion_bounds to be a method of this
new type.

Note that find_completion_bounds never used its parameter; and because
it is generally fine to use the 'pstate' global throughout the parser,
this patch removes the parameter entirely.

14 months agoImplement Ada 2022 iterated assignment
Tom Tromey [Tue, 5 Mar 2024 14:59:55 +0000 (07:59 -0700)] 
Implement Ada 2022 iterated assignment

Ada 2022 includes iterated assignment for array initialization.  This
patch implements a subset of this for gdb.  In particular, only arrays
with integer index types really work -- currently there's no decent
way to get the index type in EVAL_AVOID_SIDE_EFFECTS mode during
parsing.  Fixing this probably requires the Ada parser to take a
somewhat more sophisticated approach to type resolution; and while
this would help fix another bug in this area, this patch is already
useful without it.

14 months agoIntroduce and use aggregate_assigner type
Tom Tromey [Tue, 5 Mar 2024 14:25:08 +0000 (07:25 -0700)] 
Introduce and use aggregate_assigner type

This patch is a refactoring to add a new aggregate_assigner type.
This type is passed to Ada aggregate assignment operations in place of
passing a number of separate arguments.  This new approach makes it
simpler to change some aspects of aggregate assignment behavior.

14 months agoRun isort
Tom Tromey [Wed, 20 Mar 2024 15:03:04 +0000 (09:03 -0600)] 
Run isort

This patch is the result of running 'isort .' in the gdb directory.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoPrepare gdb for isort
Tom Tromey [Wed, 20 Mar 2024 15:36:40 +0000 (09:36 -0600)] 
Prepare gdb for isort

This patch prepares gdb for isort: it adds a couple of isort marker
comments where needed, and it adds an isort clause to setup.cfg.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoDo not use bare "except"
Tom Tromey [Tue, 19 Mar 2024 17:11:05 +0000 (11:11 -0600)] 
Do not use bare "except"

flake8 warns about a bare "except".  The docs point out that this will
also catch KeyboardInterrupt and SystemExit exceptions, which is
normally undesirable.  Using "except Exception" catches everything
reasonable, so this patch makes this change.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoSuppress some "undefined" warnings from flake8
Tom Tromey [Tue, 19 Mar 2024 17:08:34 +0000 (11:08 -0600)] 
Suppress some "undefined" warnings from flake8

flake8 warns about some identifiers in __init__.py, because it does
not realize these come from the star-imported _gdb module.  This patch
suppresses these warnings.

14 months agoSpecify ImportError in styling.py
Tom Tromey [Tue, 19 Mar 2024 16:56:34 +0000 (10:56 -0600)] 
Specify ImportError in styling.py

styling.py has a long try/except surrounding most of the body.  flake8
warns about the final bare "except".  However, this except is really
only there to catch the situation where the host doesn't have Pygments
installed.  This patch changes this to only catch ImportError.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoSuppress star import errors
Tom Tromey [Tue, 19 Mar 2024 16:55:30 +0000 (10:55 -0600)] 
Suppress star import errors

flake8 warns about the "from _gdb.disassembler import *" line in
disassembler.py, and a similar line from __init__.py.  These line are
needed to re-export names from the corresponding C++ module, so this
patch applies the appropriate "noqa" flags.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoRemove bare "except" from disassembler.py
Tom Tromey [Tue, 19 Mar 2024 16:49:20 +0000 (10:49 -0600)] 
Remove bare "except" from disassembler.py

flake8 complains about a bare "except" in disassembler.py.  In this
case, the code purports to guard against some kind of user error
involving data structure corruption.  I think it's better here to just
let the error occur -- py-disasm.c will show a stack trace in this
case.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoRemove unused import from gdb/__init__.py
Tom Tromey [Tue, 19 Mar 2024 16:44:04 +0000 (10:44 -0600)] 
Remove unused import from gdb/__init__.py

flake8 points out that the import of _gdb in gdb/__init__.py is
unused.  Remove it.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoIgnore unsed import in dap/__init__.py
Tom Tromey [Tue, 19 Mar 2024 16:27:56 +0000 (10:27 -0600)] 
Ignore unsed import in dap/__init__.py

flake8 warns about dap/__init__.py because it has a number of unused
imports.  Most of these are intentional: the import is done to ensure
that the a DAP request is registered with the server object.

This patch applies a "noqa" comment to these imports, and also removes
one import that is truly unnecessary.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoFix flake8 errors in dap/server.py
Tom Tromey [Tue, 19 Mar 2024 16:24:41 +0000 (10:24 -0600)] 
Fix flake8 errors in dap/server.py

Commit 032d23a6 ("Fix stray KeyboardInterrupt after cancel")
introduced some errors into dap/server.py.  A function is called but
not imported, and the wrong variable name is used.  This patch
corrects both errors.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoRemove .flake8
Tom Tromey [Tue, 19 Mar 2024 16:21:01 +0000 (10:21 -0600)] 
Remove .flake8

I re-ran flake8 today and was puzzled to see W503 warnings.
Eventually I found out that the setup.cfg config overrides .flake8.
This patch merges the two and removes .flake8, to avoid future
confusion.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months ago[gdb/testsuite] Add missing include in gdb.base/ctf-ptype.c
Tom de Vries [Tue, 2 Apr 2024 14:22:46 +0000 (16:22 +0200)] 
[gdb/testsuite] Add missing include in gdb.base/ctf-ptype.c

On fedora rawhide, when running test-case gdb.base/ctf-ptype.exp, I get:
...
gdb compile failed, ctf-ptype.c: In function 'main':
ctf-ptype.c:242:29: error: implicit declaration of function 'malloc' \
  [-Wimplicit-function-declaration]
  242 |   v_char_pointer = (char *) malloc (1);
      |                             ^~~~~~
ctf-ptype.c:1:1: note: include '<stdlib.h>' or provide a declaration of 'malloc'
  +++ |+#include <stdlib.h>
    1 | /* This test program is part of GDB, the GNU debugger.
...

Fix this by adding the missing include.

Tested on aarch64-linux.

14 months ago[gdb/testsuite] Fix gdb.ada/verylong.exp on 32-bit target
Tom de Vries [Tue, 2 Apr 2024 14:14:39 +0000 (16:14 +0200)] 
[gdb/testsuite] Fix gdb.ada/verylong.exp on 32-bit target

In an aarch32-linux chroot on an aarch64-linux system, I run into:
...
(gdb) print x^M
$1 = 9223372036854775807^M
(gdb) FAIL: gdb.ada/verylong.exp: print x
...

A passing version on aarch64-linux looks like:
...
(gdb) print x^M
$1 = 170141183460469231731687303715884105727^M
(gdb) PASS: gdb.ada/verylong.exp: print x
...

The difference is caused by the size of the type Long_Long_Long_Integer, which
is:
- a 128-bit signed on 64-bit targets, and
- a 64-bit signed on 32-bit target.

Fix this by detecting the size of the Long_Long_Long_Integer type, and
handling it.

Tested on aarch64-linux and aarch32-linux.

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

[1] https://gcc.gnu.org/onlinedocs/gnat_rm/Implementation-Defined-Characteristics.html

14 months agoUpdate objcopy's --section-alignment option so that it sets the alignment flag on...
Nick Clifton [Tue, 2 Apr 2024 14:08:07 +0000 (15:08 +0100)] 
Update objcopy's --section-alignment option so that it sets the alignment flag on PE sections.   Add a check for aligned sections not matching their VMAs.

14 months ago[gdb/tui] Fix centering and highlighting of current line
Tom de Vries [Tue, 2 Apr 2024 14:09:10 +0000 (16:09 +0200)] 
[gdb/tui] Fix centering and highlighting of current line

After starting TUI like this with a hello world a.out:
...
$ gdb -q a.out -ex start -ex "tui enable"
...
we get:
...
┌─hello.c──────────────────────────────┐
│        5 {                           │
│        6   printf ("hello\n");       │
│        7                             │
│        8   return 0;                 │
│        9 }                           │
│                                      │
└──────────────────────────────────────┘
...

This is a regression since commit ee1e9bbb513 ("[gdb/tui] Fix displaying main
after resizing"), before which we had instead:
...
┌─hello.c──────────────────────────────┐
│        4 main (void)                 │
│        5 {                           │
│  >     6 \e[7m  printf ("hello\n");\e[0m       │
│        7                             │
│        8   return 0;                 │
│        9 }                           │
└──────────────────────────────────────┘
...

In other words, the problems are:
- the active line (source line 6) is no longer highlighted, and
- the active line is not vertically centered (screen line 2 out 6 instead of
  screen line 3 out of 6).

Fix these problems respectively by:
- in tui_enable, instead of "tui_show_frame_info (0)" using
  'tui_show_frame_info (deprecated_safe_get_selected_frame ())", and
- in tui_source_window_base::rerender, adding centering functionality.

Tested on aarch64-linux.

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

14 months agoPR31458, FAIL: MIPS eh-frame 3 with --no-keep-memory
H.J. Lu [Thu, 7 Mar 2024 16:28:29 +0000 (08:28 -0800)] 
PR31458, FAIL: MIPS eh-frame 3 with --no-keep-memory

PR 31458
bfd/
* elf-bfd.h (_bfd_elf_link_read_relocs),
(_bfd_elf_link_info_read_relocs): Constify section.
* elflink.c: Likewise.
* elfxx-mips.c (_bfd_mips_elf_eh_frame_address_size): Read
relocs again in case --no-keep-memory.
ld/
* testsuite/ld-mips-elf/mips-elf.exp: Run --no-keep-memory
version of eh-frame3 test.

14 months agoPR 30569, delete _bfd_mips_elf_early_size_sections
Alan Modra [Thu, 28 Mar 2024 10:03:32 +0000 (20:33 +1030)] 
PR 30569, delete _bfd_mips_elf_early_size_sections

PR30569 was triggered by a patch of mine 6540edd52cc0 moving the call
to always_size_sections in bfd_elf_size_dynamic_sections earlier, made
to support the x86 DT_RELR implementation.  This broke mips16 code
handling stubs when --export-dynamic is passed to the linker, because
numerous symbols then became dynamic after always_size_sections.  The
mips backend fiddles with symbols in its always_size_sections.  Maciej
in 902e9fc76a0e had moved the call to always_size_sections to after
the export-dynamic code.  Prior to that, Nathan in 04c3a75556c0 moved
it before the exec stack code, back to the start of
bfd_elf_size_dynamic_sections which was where Ian put it originally
in ff12f303355b.  So the call has moved around a little.  I'm leaving
it where it is, and instead calling mips_elf_check_symbols from
late_size_sections (the old size_dynamic_sections) which is now always
called.  In fact, the whole of _bfd_mips_elf_early_size_sections can
be merged into _bfd_mips_elf_late_size_sections.

14 months agoPR 30569, always call elf_backend_size_dynamic_sections
Alan Modra [Thu, 28 Mar 2024 08:55:42 +0000 (19:25 +1030)] 
PR 30569, always call elf_backend_size_dynamic_sections

This largely mechanical patch is preparation for a followup patch.

For quite some time I've thought that it would be useful to call
elf_backend_size_dynamic_sections even when no dynamic objects are
seen by the linker.  That's what this patch does, with some renaming.
There are no functional changes to the linker, just a move of the
dynobj test in bfd_elf_size_dynamic_sections to target backend
functions, replacing the asserts/aborts already there.  No doubt some
of the current always_size_sections functions could be moved to
size_dynamic_sections but I haven't made that change.

Because both hooks are now always called, I have renamed
always_size_sections to early_size_sections and size_dynamic_sections
to late_size_sections.  I condisdered calling late_size_sections plain
size_sections, since this is the usual target dynamic section sizing
hook, but decided that searching the sources for "size_sections" would
then hit early_size_sections and other functions.

14 months agoobjdump --disassemble=sym peculiarities
Alan Modra [Mon, 1 Apr 2024 20:48:19 +0000 (07:18 +1030)] 
objdump --disassemble=sym peculiarities

Given this testcase:
 .text
 mov $x1,%eax
f1:
 mov $f1,%eax
 .type f1,@function
 .size f1,.-f1

 mov $x2,%eax
f2:
 mov $f2,%eax
 .type f2,@function
 .size f2,.-f2+0x1000 #bad size

objdump --reloc --disassemble=f1 prints
00000000 <f1-0x5>:
   0: b8 00 00 00 00        mov    $0x0,%eax

and objdump --reloc --disassemble=f2 prints
0000000f <f2>:
   f: b8 0f 00 00 00        mov    $0xf,%eax
10: R_386_32 .text

It seems for f1 we get the insn before f1 and no reloc whereas, post
159daa36fa, f2 is disassembled correctly.  Some analysis says that
find_symbol_for_address may return a symbol past the current address,
and reloc skipping is broken.  Fix both of these problems.

* objdump.c (disassemble_jumps, disassemble_bytes): Replace
        relppp with relpp, ie. don't update caller's rel_pp.  Adjust
        calls.
(disassemble_section): Skip over relocs inside loop rather
        than before loop.  Revert 7e538762c2c1.  If given a symbol,
don't start disassembling until its address is reached.
Correct end of function calculation.

14 months agoAutomatic date update in version.in
GDB Administrator [Tue, 2 Apr 2024 00:00:09 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agohppa: Implement PA 2.0 symbolic relocations for long displacements
John David Anglin [Mon, 1 Apr 2024 23:00:52 +0000 (23:00 +0000)] 
hppa: Implement PA 2.0 symbolic relocations for long displacements

The PA 2.0 architecture introduced several new load and store
instructions with long displacements.  These include floating
point loads and stores for word mode, and integer and floating
point loads and stores for double words.  Currently, ld does
not correctly support symbolic relocations for these instructions.

If these are used, ld applies the standard R_PARISC_DPREL14R
relocation and corrupts the instruction.  This change uses
bfd_hppa_insn2fmt to determine the correct relocation format.

We need to check the computed displacement as the immediate
value used in these instruction must be a multiple of 4 or 8
depending on whether the access is for a word or double word.

A misaligned offset can potentially occur if the symbol is not
properly aligned or if $global$ (the global pointer) is not
double word aligned.  $global$ is provided as a .data section
start symbol.  The patch adjusts elf.sc and hppalinux.sh to
align .data to a 8-byte boundary in non-shared and non-pie
links.

2024-04-01  John David Anglin  <danglin@gcc.gnu.org>

PR ld/31503

bfd/ChangeLog:

* elf32-hppa.c (final_link_relocate): Output

ld/ChangeLog:

* emulparams/hppalinux.sh (DATA_SECTION_ALIGNMENT): Define.
* scripttempl/elf.sc: Align .data section to DATA_SECTION_ALIGNMENT
when relocating.

14 months agoasan: heap-buffer-overflow objdump.c:3299 in disassemble_bytes
Alan Modra [Mon, 1 Apr 2024 09:28:53 +0000 (19:58 +1030)] 
asan: heap-buffer-overflow objdump.c:3299 in disassemble_bytes

Fix yet another crash, this one with a fuzzed function symbol size.
The patch also corrects objdump behaviour when both --disassemble=sym
and --stop-address=value are given.  Previously --disassemble=sym
overrode --stop-address, now we take the lower of the stop-address
value and the end of function.

* objdump.c (disassemble_section): Sanity check ELF st_size.

14 months agoLoongArch: Fix the issue of excessive relocation generated by GD and IE
Lulu Cai [Thu, 21 Mar 2024 08:33:21 +0000 (16:33 +0800)] 
LoongArch: Fix the issue of excessive relocation generated by GD and IE

Currently, whether GD and IE generate dynamic relocation is
determined by SYMBOL_REFERENCES_LOCAL and bfd_link_executable.
This results in dynamic relocations still being generated in some
situations where dynamic relocations are not necessary (such as
the undefined weak symbol in static links).

We use RLARCH_TLS_GD_IE_NEED_DYN_RELOC macros to determine whether
GD/IE needs dynamic relocation. If GD/IE requires dynamic relocation,
set need_reloc to true and indx to be a dynamic index.

At the same time, some test cases were modified to use regular
expression matching instead of complete disassembly matching.

14 months agoLoongArch: gas: Ignore .align if it is at the start of a section
mengqinggang [Tue, 19 Mar 2024 13:09:12 +0000 (21:09 +0800)] 
LoongArch: gas: Ignore .align if it is at the start of a section

Ignore .align if it is at the start of a section and the alignment
can be divided by the section alignment, the section alignment
can ensure this .align has a correct alignment.

14 months agoAutomatic date update in version.in
GDB Administrator [Mon, 1 Apr 2024 00:00:09 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agogdb: build dprintf commands just once in code_breakpoint constructor
Andrew Burgess [Wed, 5 Apr 2023 15:12:05 +0000 (16:12 +0100)] 
gdb: build dprintf commands just once in code_breakpoint constructor

I noticed in code_breakpoint::code_breakpoint that we are calling
update_dprintf_command_list once for each breakpoint location, when we
really only need to call this once per breakpoint -- the data updated
by this function, the breakpoint command list -- is per breakpoint,
not per breakpoint location.  Calling update_dprintf_command_list
multiple times is just wasted effort, there's no per location error
checking, we don't even pass the current location to the function.

This commit moves the update_dprintf_command_list call outside of the
per-location loop.

There should be no user visible changes after this commit.

14 months agogdb: the extra_string in a dprintf breakpoint is never nullptr
Andrew Burgess [Wed, 13 Dec 2023 09:44:33 +0000 (09:44 +0000)] 
gdb: the extra_string in a dprintf breakpoint is never nullptr

Given the changes in the previous couple of commits, this commit
cleans up some of the asserts and 'if' checks related to the
extra_string within a dprintf breakpoint.

This commit:

  1. Adds some asserts to update_dprintf_command_list about the
  breakpoint type, and that the extra_string is not nullptr,

  2. Given that we know extra_string is not nullptr (this is enforced
  when the breakpoint is created), we can simplify
  code_breakpoint::code_breakpoint -- it no longer needs to check for
  the extra_string is nullptr case,

  3. In dprintf_breakpoint::re_set we can remove the assert (this will
  be checked within update_dprintf_command_list, we can also remove
  the redundant 'if' check.

There should be no user visible changes after this commit.

14 months agogdb: change 'if' to gdb_assert in update_dprintf_command_list
Andrew Burgess [Wed, 5 Apr 2023 14:37:00 +0000 (15:37 +0100)] 
gdb: change 'if' to gdb_assert in update_dprintf_command_list

I noticed in update_dprintf_command_list that we handle the case where
the bp_dprintf style breakpoint doesn't have a format and args string.

However, I don't believe such a situation is possible.  The obvious
approach certainly already catches this case:

  (gdb) dprintf main
  Format string required

If it is possible to create a dprintf breakpoint without a format and
args string then I think we should be catching this case and handling
it at creation time, rather than having GDB just ignore the situation
later on.

And so, I propose that we change the 'if' that ignores the case where
the format/args string is empty, and instead assert that we do always
have a format/args string.  The original code, that handled an empty
format/args string has existed since commit e7e0cddfb0d4, which is
when dprintf support was added to GDB.

If I'm correct and this situation can't ever happen then there should
be no user visible changes after this commit.

14 months agogdb: create_breakpoint: asserts relating to extra_string/parse_extra
Andrew Burgess [Thu, 16 Mar 2023 07:59:51 +0000 (07:59 +0000)] 
gdb: create_breakpoint: asserts relating to extra_string/parse_extra

The goal of this commit is to better define the API for
create_breakpoint especially around the use of extra_string and
parse_extra.  This will be useful in the next commit when I plan to
make some changes to create_breakpoint.

This commit makes one possibly breaking change: until this commit it
was possible to create thread-specific dprintf breakpoint like this:

  (gdb) dprintf call_me, thread 1 "%s", "hello"
  Dprintf 2 at 0x401152: file /tmp/hello.c, line 8.
  (gdb) info breakpoints
  Num     Type           Disp Enb Address            What
  2       dprintf        keep y   0x0000000000401152 in call_me at /tmp/hello.c:8 thread 1
          stop only in thread 1
          printf "%s", "hello"
  (gdb)

This feature of dprintf was not documented, was not tested, and is
slightly different in syntax to how we create thread specific
breakpoints and/or watchpoints -- the thread condition appears after
the first ','.

I believe that this worked at all was simply by luck.  We happen to
pass the parse_extra flag as true from dprintf_command to
create_breakpoint.

So in this commit I made the choice to change this.  We now pass
parse_extra as false from dprintf_command to create_breakpoint.  With
this done it is assumed that the only thing in the extra_string is the
dprintf format and arguments.

Beyond this change I've updated the comment on create_breakpoint in
breakpoint.h, and I've then added some asserts into
create_breakpoint as well as moving around some of the error
handling.

 - We now assert on the incoming argument values,

 - I've moved an error check to sit after the call to
   find_condition_and_thread_for_sals, this ensures the extra_string
   was parsed correctly,

In dprintf_command:

 - We now throw an error if there is no format string after the
   dprintf location.  This error was already being thrown, but was
   being caught later in the process.  With this change we catch the
   missing string earlier,

 - And, as mentioned earlier, we pass parse_extra as false when
   calling create_breakpoint,

In create_tracepoint_from_upload:

 - We now throw an error if the parsed location doesn't completely
   consume the addr_str variable.  This error has now effectively
   moved out of create_breakpoint.

14 months agogdb: create_breakpoint: add asserts and additional comments
Andrew Burgess [Wed, 15 Mar 2023 16:06:30 +0000 (16:06 +0000)] 
gdb: create_breakpoint: add asserts and additional comments

This commit extends the asserts on create_breakpoint (in the header
file), and adds some additional assertions into the definition.

The new assert confirms that when the thread and inferior information
is going to be parsed from the extra_string, then the thread and
inferior arguments should be -1.  That is, the caller of
create_breakpoint should not try to create a thread/inferior specific
breakpoint by *both* specifying thread/inferior *and* asking to parse
the extra_string, it's one or the other.

There should be no user visible changes after this commit.

14 months agoBFD: Fix the bug of R_LARCH_AGLIN caused by discard section
mengqinggang [Wed, 24 Jan 2024 06:34:26 +0000 (14:34 +0800)] 
BFD: Fix the bug of R_LARCH_AGLIN caused by discard section

To represent the first and third expression of .align, R_LARCH_ALIGN need to
associate with a symbol. We define a local symbol for R_LARCH_AGLIN.
But if the section of the local symbol is discarded, it may result in
a undefined symbol error.

Instead, we use the section name symbols, and this does not need to
add extra symbols.

During partial linking (ld -r), if the symbol associated with a relocation is
STT_SECTION type, the addend of relocation needs to add the section output
offset. We prevent it for R_LARCH_ALIGN.

The elf_backend_data.rela_normal only can set all relocations of a target to
rela_normal. Add a new function is_rela_normal to elf_backend_data, it can
set part of relocations to rela_normal.

14 months agoAutomatic date update in version.in
GDB Administrator [Sun, 31 Mar 2024 00:00:08 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agoLower variable definitions in tui_redisplay_readline
Tom Tromey [Sat, 30 Mar 2024 18:19:07 +0000 (12:19 -0600)] 
Lower variable definitions in tui_redisplay_readline

I noticed a redundant assignment to 'prev_col' in
tui_redisplay_readline, and then went ahead and lowered most of the
variable definitions in that function to their initialization point.

14 months agoAutomatic date update in version.in
GDB Administrator [Sat, 30 Mar 2024 00:00:08 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agogdb/testsuite: don't include port numbers in test names
Andrew Burgess [Fri, 29 Mar 2024 22:28:44 +0000 (22:28 +0000)] 
gdb/testsuite: don't include port numbers in test names

The gdb.python/py-cmd-prompt.exp script includes a test that has a
gdbserver port number within a test name.  As port numbers can change
from one test run to the next (depending on what else is running on
the machine at the time), this can make it hard to compare test
results between runs.

Give the test a specific name to avoid including the port number.

There is no change in what is tested after this commit.

14 months agogdb/testsuite: avoid $pc/$sp values in test names
Andrew Burgess [Fri, 29 Mar 2024 14:07:47 +0000 (14:07 +0000)] 
gdb/testsuite: avoid $pc/$sp values in test names

Provide an explicit name for a test in gdb.base/pc-not-saved.exp to
avoid printing $pc and $sp values in the test name -- these values
might change between different test runs, which makes it harder to
compare test results.

There is no change in what is actually being tested with this commit.

14 months ago[gdb/testsuite] Add missing includes in gdb.trace/collection.c
Tom de Vries [Fri, 29 Mar 2024 06:47:30 +0000 (07:47 +0100)] 
[gdb/testsuite] Add missing includes in gdb.trace/collection.c

On fedora rawhide, with test-case gdb.trace/collection.exp, I get:
...
gdb compile failed, collection.c: In function 'strings_test_func':
collection.c:227:13: error: implicit declaration of function 'malloc' \
  [-Wimplicit-function-declaration]
  227 |   longloc = malloc(500);
      |             ^~~~~~
collection.c:1:1: note: \
  include '<stdlib.h>' or provide a declaration of 'malloc'
  +++ |+#include <stdlib.h>
    1 | /* This testcase is part of GDB, the GNU debugger.

collection.c:228:3: error: implicit declaration of function 'strcpy' \
  [-Wimplicit-function-declaration]
  228 |   strcpy(longloc, ... );
      |   ^~~~~~
collection.c:1:1: note: include '<string.h>' or provide a declaration of \
  'strcpy'
  +++ |+#include <string.h>
    1 | /* This testcase is part of GDB, the GNU debugger.
collection.c:230:8: error: implicit declaration of function 'strlen' \
  [-Wimplicit-function-declaration]
  230 |   i += strlen (locstr);
      |        ^~~~~~
collection.c:230:8: note: include '<string.h>' or provide a declaration of \
  'strlen'
...

Fix this by adding the missing includes.

Tested on aarch64-linux.

Approved-By: John Baldwin <jhb@FreeBSD.org>
14 months ago[gdb/testsuite] Fix missing return type in gdb.linespec/break-asm-file.c
Tom de Vries [Fri, 29 Mar 2024 06:47:30 +0000 (07:47 +0100)] 
[gdb/testsuite] Fix missing return type in gdb.linespec/break-asm-file.c

On fedora rawhide, when running test-case gdb.linespec/break-asm-file.exp, I
get:
...
gdb compile failed, break-asm-file.c:21:8: error: \
  return type defaults to 'int' [-Wimplicit-int]
   21 | static func()
      |        ^~~~
...

Fix this by adding the missing return type.

Tested on aarch64-linux.

Approved-By: John Baldwin <jhb@FreeBSD.org>
14 months agoAutomatic date update in version.in
GDB Administrator [Fri, 29 Mar 2024 00:00:35 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agoMake pascal_language::print_type handle varstring==nullptr
Tom Tromey [Wed, 27 Mar 2024 16:34:46 +0000 (10:34 -0600)] 
Make pascal_language::print_type handle varstring==nullptr

PR gdb/31524 points out a crash when pascal_language::print_type is
called with varstring==nullptr.  This crash is a regression arising
from the printf/pager rewrite -- that indirectly removed a NULL check
from gdb's "puts".

This patch instead fixes the problem by adding a check to print_type.
Passing nullptr here seems to be expected in other places (e.g., there
is a call to type_print like this in expprint.c), and other
implementations of this method (or related helpers) explicitly check
for NULL.

I didn't write a test case for this because it seemed like overkill
for a Pascal bug that only occurs with -i=mi.  However, if you want
one, let me know and I will do it.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31524
Approved-By: John Baldwin <jhb@FreeBSD.org>
14 months agogas: gcfg: fix handling of non-local direct jmps in gcfg
Indu Bhagat [Thu, 28 Mar 2024 18:57:23 +0000 (11:57 -0700)] 
gas: gcfg: fix handling of non-local direct jmps in gcfg

The ginsn infrastructure in GAS includes the ability to create a GCFG
(ginsn CFG).  A GCFG is currently used for SCFI passes.

This patch fixes the following invalid assumptions / code blocks:
 - The function ginsn_direct_local_jump_p () was erroneously _not_
   checking whether the symbol is locally defined (i.e., within the
   scope of the code block for which GCFG is desired).  Fix the code
   to do so.
 - Similarly, the GCFG creation code, in gcfg_build () itself had an
   assumption that a GINSN_TYPE_JUMP to a non-local symbol will not be
   seen.  The latter can indeed be seen, and in fact, needs to be treated
   the same way as an exit from the function in terms of control-flow.

gas/
        * ginsn.c (ginsn_direct_local_jump_p): Check if the symbol
is local to the code block or function being assembled.
        (add_bb_at_ginsn): Remove buggy assumption.
        (frch_ginsn_data_append): Direct jmps do not disqualify a stream
of ginsns from GCFG creation.

gas/testsuite/
* gas/scfi/x86_64/scfi-cfg-3.d: New test.
* gas/scfi/x86_64/scfi-cfg-3.l: New test.
* gas/scfi/x86_64/scfi-cfg-3.s: New test.
* gas/scfi/x86_64/scfi-x86-64.exp: Add new test.

14 months agox86/SSE2AVX: move checking
Jan Beulich [Thu, 28 Mar 2024 10:55:53 +0000 (11:55 +0100)] 
x86/SSE2AVX: move checking

It has always been looking a little odd to me that this was done deep
in cpu_flags_match(). Move it to match_template() itself - there's no
need to do anything complex when encountering such a template while it
cannot possibly be used.

14 months agox86/SSE2AVX: respect prefixes
Jan Beulich [Thu, 28 Mar 2024 10:55:25 +0000 (11:55 +0100)] 
x86/SSE2AVX: respect prefixes

1) Without -msse2avx we unconditionally honor REX.W. Hence we ought to
   also do so with -msse2avx, converting to VEX.W.

2) {rex} doesn't prevent conversion to VEX encodings. Thus {rex2}
   shouldn't either.

14 months agogas: drop integer_constant()'s maxdig
Jan Beulich [Thu, 28 Mar 2024 10:54:48 +0000 (11:54 +0100)] 
gas: drop integer_constant()'s maxdig

Once properly set, it's only ever holding the same value as "radix".
Even if there was some plan with it, that plan hasn't made it anywhere
in over 20 years.

14 months agogas: drop dead check for double quote
Jan Beulich [Thu, 28 Mar 2024 10:54:25 +0000 (11:54 +0100)] 
gas: drop dead check for double quote

FB and dollar label definitions can't be enclosed in double quotes. In
fact at that point nul_char is the same as next_char, which we know is a
digit.

14 months agogas: sanitize FB- and dollar-label uses
Jan Beulich [Thu, 28 Mar 2024 10:53:59 +0000 (11:53 +0100)] 
gas: sanitize FB- and dollar-label uses

I don't view it as sensible to be more lax when it comes to references
to (uses of) such labels compared to their definition: The latter has
been limited to decimal numerics, while the former permitted any radix.
Beyond that leading zeroes on such labels aren't helpful either. Imo
labels and their use sites would better match literally, to avoid
confusion.

As it turns out, one z80 testcase actually had such an odd use of labels
where definition and use don't match in spelling. That testcase is being
adjusted accordingly.

While there also adjust a comment on a local variable in
integer_constant().

14 months agox86: templatize RAO-INT insns
Jan Beulich [Thu, 28 Mar 2024 10:50:27 +0000 (11:50 +0100)] 
x86: templatize RAO-INT insns

It's only four of them, but still better to reduce redundancy.

14 months agox86: templatize ADX insns
Jan Beulich [Thu, 28 Mar 2024 10:50:06 +0000 (11:50 +0100)] 
x86: templatize ADX insns

It's only two of them, but still better to reduce redundancy.

14 months agox86: templatize shift-double insns
Jan Beulich [Thu, 28 Mar 2024 10:49:48 +0000 (11:49 +0100)] 
x86: templatize shift-double insns

With the multitude of new APX templates, it finally becomes desirable to
further remove redundancy by also templatizing basic arithmetic insns.
Continue with the shift-double ones.

While there also drop the APX form with ShiftCount omitted. Other shift
and rotate insns were deliberately left without this form as well. Note
that there's also no testsuite adjustment needed for this, indicating
that the form wasn't tested either.

14 months agox86: templatize shift/rotate insns
Jan Beulich [Thu, 28 Mar 2024 10:49:24 +0000 (11:49 +0100)] 
x86: templatize shift/rotate insns

With the multitude of new APX templates, it finally becomes desirable to
further remove redundancy by also templatizing basic arithmetic insns.
Continue with the "ordinary" shift and rotate ones.

While there also drop the APX form of RCL/RCR with Imm1 omitted. Other
shift insns as well as ROR/ROL were deliberately left without this form
as well. Note that there's also no testsuite adjustment needed for this,
indicating that the form wasn't tested either.

Furthermore since RCL/RCR already had non-NDD APX forms, those end up
being added for the other 6 mnemonics, too.

14 months agox86: templatize binary ALU insns
Jan Beulich [Thu, 28 Mar 2024 10:49:01 +0000 (11:49 +0100)] 
x86: templatize binary ALU insns

With the multitude of new APX templates, it finally becomes desirable to
further remove redundancy by also templatizing basic arithmetic insns.
Continue with a the more complex binary (two source) cases.

Note how this adds a missing CheckOperandSize to one of the APX sub
forms.

Furthermore since SBB already had a non-NDD APX form, one ends up
being added for the other 6 mnemonics, too.

14 months agox86: templatize unary ALU insns
Jan Beulich [Thu, 28 Mar 2024 10:48:47 +0000 (11:48 +0100)] 
x86: templatize unary ALU insns

With the multitude of new APX templates, it finally becomes desirable to
further remove redundancy by also templatizing basic arithmetic insns.
Continue with a few simple unary (single source) cases.

14 months agox86: templatize INC/DEC
Jan Beulich [Thu, 28 Mar 2024 10:47:59 +0000 (11:47 +0100)] 
x86: templatize INC/DEC

With the multitude of new APX templates, it finally becomes desirable to
further remove redundancy by also templatizing basic arithmetic insns.
Start with the simplest case, accompanied by a necessary adjustment to
i386-gen (such that template uses can also be at the start of a line).

While there also drop a bogus (meaningless / unreachable) "break" as
well as a unused variable (which I'm surprised compilers didn't warn
about).

14 months ago[gdb/testsuite] Fix gdb.base/ending-run.exp on manjaro linux
Tom de Vries [Thu, 28 Mar 2024 07:26:31 +0000 (08:26 +0100)] 
[gdb/testsuite] Fix gdb.base/ending-run.exp on manjaro linux

On aarch64-linux, using the manjaro linux distro, I run into:
...
(gdb) next^M
32      }^M
(gdb) next^M
0x0000fffff7d67b80 in ?? () from /usr/lib/libc.so.6^M
(gdb) FAIL: gdb.base/ending-run.exp: step out of main
...

What happens here is described in detail in this clause:
...
    -re "0x.*\\?\\? \\(\\) from /lib/powerpc.*$gdb_prompt $" {
# This case occurs on Powerpc when gdb steps out of main and the
# needed debug info files are not loaded on the system, preventing
# GDB to determine which function it reached (__libc_start_call_main).
# Ideally, the target system would have the necessary debugging
# information, but in its absence, GDB's behavior is as expected.
...
    }
...
but the clause only matches for powerpc.

Fix this by:
- making the regexp generic enough to also match /usr/lib/libc.so.6, and
- updating the comment to not mention powerpc.

Tested on aarch64-linux.

PR testsuite/31450
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31450

14 months ago[gdb/testsuite] Fix test-case gdb.threads/attach-stopped.exp on manjaro linux
Tom de Vries [Thu, 28 Mar 2024 07:26:31 +0000 (08:26 +0100)] 
[gdb/testsuite] Fix test-case gdb.threads/attach-stopped.exp on manjaro linux

When running test-case gdb.threads/attach-stopped.exp on aarch64-linux, using
the manjaro linux distro, I get:
...
 (gdb) thread apply all bt^M
 ^M
 Thread 2 (Thread 0xffff8d8af120 (LWP 278116) "attach-stopped"):^M
 #0  0x0000ffff8d964864 in clock_nanosleep () from /usr/lib/libc.so.6^M
 #1  0x0000ffff8d969cac in nanosleep () from /usr/lib/libc.so.6^M
 #2  0x0000ffff8d969b68 in sleep () from /usr/lib/libc.so.6^M
 #3  0x0000aaaade370828 in func (arg=0x0) at attach-stopped.c:29^M
 #4  0x0000ffff8d930aec in ?? () from /usr/lib/libc.so.6^M
 #5  0x0000ffff8d99a5dc in ?? () from /usr/lib/libc.so.6^M
 ^M
 Thread 1 (Thread 0xffff8db62020 (LWP 278111) "attach-stopped"):^M
 #0  0x0000ffff8d92d2d8 in ?? () from /usr/lib/libc.so.6^M
 #1  0x0000ffff8d9324b8 in ?? () from /usr/lib/libc.so.6^M
 #2  0x0000aaaade37086c in main () at attach-stopped.c:45^M
 (gdb) FAIL: gdb.threads/attach-stopped.exp: threaded: attach2 to stopped bt
...

The problem is that the test-case expects to see start_thread:
...
gdb_test "thread apply all bt" ".*sleep.*start_thread.*" \
    "$threadtype: attach2 to stopped bt"
...
but lack of symbols makes that impossible.

Fix this by allowing " in ?? () from " as well.

Tested on aarch64-linux.

PR testsuite/31451
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31451

14 months ago[gdb/testsuite] Add missing include in gdb.base/rtld-step.exp
Tom de Vries [Thu, 28 Mar 2024 05:51:59 +0000 (06:51 +0100)] 
[gdb/testsuite] Add missing include in gdb.base/rtld-step.exp

On fedora rawhide, with test-case gdb.base/rtld-step.exp I get:
...
static-pie-static-libc.c: In function '_start':^M
static-pie-static-libc.c:1:22: error: \
  implicit declaration of function '_exit' [-Wimplicit-function-declaration]^M
    1 | void _start (void) { _exit (0); }^M
      |                      ^~~~~^M
compiler exited with status 1
  ...
UNTESTED: gdb.base/rtld-step.exp: failed to compile \
  (-static-pie not supported or static libc missing)
...

Fix this by adding the missing include.

Tested on aarch64-linux.

Approved-by: Kevin Buettner <kevinb@redhat.com>
14 months agoRISC-V: Removed privileged spec 1.9.1 support in assembler.
Nelson Chu [Fri, 22 Mar 2024 07:21:27 +0000 (15:21 +0800)] 
RISC-V: Removed privileged spec 1.9.1 support in assembler.

Removed since it's may have lots of conflicts with the newer extensions, but
still keep linker recognizes it in case of linking old objects.

gas/
* NEWS: Updated.
* config/tc-riscv.c (riscv_set_default_priv_spec): Regard 1.9.1 as
an unknown version.
(md_show_usage): Removed privileged spec 1.9.1 information.
* testsuite/gas/riscv/attribute-05.s: Updated since privileged spec
1.9.1 is unsupported.
* testsuite/gas/riscv/attribute-05.d: Likewise.
* testsuite/gas/riscv/attribute-12.d: Likewise.
* testsuite/gas/riscv/attribute-13.d: Likewise.
* testsuite/gas/riscv/csr-dw-regnums.d: Likewise.
* testsuite/gas/riscv/csr-dw-regnums.s: Likewise.
* testsuite/gas/riscv/csr.s: Likewise.
* testsuite/gas/riscv/csr-version-1p10.d: Likewise.
* testsuite/gas/riscv/csr-version-1p10.l: Likewise.
* testsuite/gas/riscv/csr-version-1p11.d: Likewise.
* testsuite/gas/riscv/csr-version-1p11.l: Likewise.
* testsuite/gas/riscv/csr-version-1p12.d: Likewise.
* testsuite/gas/riscv/csr-version-1p12.l: Likewise.
* testsuite/gas/riscv/csr-version-1p9p1.d: Removed.
* testsuite/gas/riscv/csr-version-1p9p1.l: Removed.
include/
* opcode/riscv-opc.h: Updated since privileged spec 1.9.1 is
unsupported.
ld/
* testsuite/ld-riscv-elf/attr-merge-priv-spec-01.d: Updated since
privileged spec 1.9.1 is unsupported.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-02.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-03.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-a.s: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-b.s: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-01.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-02.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-03.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-04.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-05.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-06.d: Likewise.

14 months agoAutomatic date update in version.in
GDB Administrator [Thu, 28 Mar 2024 00:00:57 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agoFix clang build
Tom Tromey [Wed, 27 Mar 2024 13:21:56 +0000 (07:21 -0600)] 
Fix clang build

Simon pointed out that commit 818ef5f4 ("Capture warnings when writing
to the index cache") broke the build with clang.  This patch fixes the
breakage.

15 months agogdb, gdbserver, gdbsupport: remove includes of early headers
Simon Marchi [Tue, 26 Mar 2024 19:06:46 +0000 (15:06 -0400)] 
gdb, gdbserver, gdbsupport: remove includes of early headers

Now that defs.h, server.h and common-defs.h are included via the
`-include` option, it is no longer necessary for source files to include
them.  Remove all the inclusions of these files I could find.  Update
the generation scripts where relevant.

Change-Id: Ia026cff269c1b7ae7386dd3619bc9bb6a5332837
Approved-By: Pedro Alves <pedro@palves.net>
15 months agogdb, gdbserver, gdbsupport: include early header files with `-include`
Simon Marchi [Tue, 26 Mar 2024 19:06:45 +0000 (15:06 -0400)] 
gdb, gdbserver, gdbsupport: include early header files with `-include`

The motivation for this change is for analysis tools and IDEs to be
better at analyzing header files on their own.

There are some definitions and includes we want to occur at the very
beginning of all translation units.  The way we currently do that is by
requiring all source files (.c and .cc files) to include one of defs.h
(for gdb), server.h (for gdbserver) of common-defs.h (for gdbsupport and
shared source files).  These special header files define and include
everything that needs to be included at the very beginning.  Other
header files are written in a way that assume that these special
"prologue" header files have already been included.

My problem with that is that my editor (clangd-based) provides a very
bad experience when editing header files.  Since clangd doesn't know
that one of defs.h/server.h/common-defs.h was included already, a lot of
things are flagged as errors.  For instance, CORE_ADDR is not known.
It's possible to edit the files in this state, but a lot of the power of
the editor is unavailable.

My proposal to help with this is to include those things we always want
to be there using the compilers' `-include` option.  Tom Tromey said
that the current approach might exist because not all compilers used to
have an option like this.  But I believe that it's safe to assume they
do today.

With this change, clangd picks up the -include option from the compile
command, and is able to analyze the header file correctly, as it sees
all that stuff included or defined by that -include option.  That works
because when editing a header file, clangd tries to get the compilation
flags from a source file that includes said header file.

This change is a bit self-serving, because it addresses one of my
frustrations when editing header files, but it might help others too.
I'd be curious to know if others encounter the same kinds of problems
when editing header files.  Also, even if the change is not necessary by
any means, I think the solution of using -include for stuff we always
want to be there is more elegant than the current solution.

Even with this -include flag, many header files currently don't include
what they use, but rather depend on files included before them.  This
will still cause errors when editing them, but it should be easily
fixable by adding the appropriate include.  There's no rush to do so, as
long as the code still compiles, it's just a convenience thing.

The changes are:

 - Add the appropriate `-include` option to the various Makefiles.

 - There is one particularity for gdbserver's Makefile: we do not want
   to include server.h when building `gdbreplay.o`, as `gdbreplay.cc`
   doesn't include it.  So we can't simply put the `-include` in
   `INTERNAL_CFLAGS`.  Add the `-include server.h` option to the
   `COMPILE` and `IPAGENT_COMPILE` variables, and added a special rule
   to compile `gdbreplay.o` with `-include gdbsupport/common-defs.h`.

 - Remove the `-include` option from the `check-headers` rule in
   gdb/Makefile.in, since it is already included in `INTERNAL_CFLAGS`.

Change-Id: If3e345d00a9fc42336322f1d8286687d22134340
Approved-By: Pedro Alves <pedro@palves.net>
15 months ago{gdb,gdbserver}/Makefile.in: remove unnecessary intermediary variables
Simon Marchi [Tue, 26 Mar 2024 19:06:44 +0000 (15:06 -0400)] 
{gdb,gdbserver}/Makefile.in: remove unnecessary intermediary variables

Remove `INTERNAL_CFLAGS_BASE` and `INTERNAL_WARN_CFLAGS`, inline their
contents in `INTERNAL_CFLAGS`.  Not functional changes expected.

Change-Id: I6a09794835ca2cfd4a88a3e9f2e627c8f5bd569f
Approved-By: Pedro Alves <pedro@palves.net>
15 months agogdb, gdbserver, gdbsupport: reformat some Makefile variables, one entry per line
Simon Marchi [Tue, 26 Mar 2024 19:06:43 +0000 (15:06 -0400)] 
gdb, gdbserver, gdbsupport: reformat some Makefile variables, one entry per line

Reformat some variables definitions.  I think it makes them easier to
read, and it also makes diffs clearer.

Change-Id: I82f63ba0e6d0fe268eb1f1ad5ab22c3cd016ab02
Approved-By: Pedro Alves <pedro@palves.net>
15 months agogdb: make gdbarch_types.py non-executable
Simon Marchi [Sat, 16 Mar 2024 17:21:03 +0000 (13:21 -0400)] 
gdb: make gdbarch_types.py non-executable

I noticed that gdbarch_types.py is executable.  It's not needed, since
it's only imported from gdbarch.py.

Change-Id: I481170714af66fc3fc3a48c55a7268e0789cf83e

15 months agoAutomatic date update in version.in
GDB Administrator [Wed, 27 Mar 2024 00:00:43 +0000 (00:00 +0000)] 
Automatic date update in version.in

15 months agoRevert "gdbserver: convert have_ptrace_getregset to a tribool"
Andrew Burgess [Tue, 26 Mar 2024 18:53:31 +0000 (18:53 +0000)] 
Revert "gdbserver: convert have_ptrace_getregset to a tribool"

This reverts commit 5920765d7513aaae9241a1850d62d73e0477f81c.

15 months agoRevert "gdb/x86: move reading of cs and ds state into gdb/nat directory"
Andrew Burgess [Tue, 26 Mar 2024 18:53:17 +0000 (18:53 +0000)] 
Revert "gdb/x86: move reading of cs and ds state into gdb/nat directory"

This reverts commit 01ed1674d4435aa4e194fd9373b7705e425ef354.

15 months agoRevert "gdbserver/x86: move no-xml code earlier in x86_linux_read_description"
Andrew Burgess [Tue, 26 Mar 2024 18:53:05 +0000 (18:53 +0000)] 
Revert "gdbserver/x86: move no-xml code earlier in x86_linux_read_description"

This reverts commit 0a7bb97ad2f2fe2d18a442dad265051e34eab13e.

15 months agoRevert "gdb/gdbserver: share I386_LINUX_XSAVE_XCR0_OFFSET definition"
Andrew Burgess [Tue, 26 Mar 2024 18:52:51 +0000 (18:52 +0000)] 
Revert "gdb/gdbserver: share I386_LINUX_XSAVE_XCR0_OFFSET definition"

This reverts commit 7816b81e9b36ea0f57662bfd7446b573bf0c9e54.

15 months agoRevert "gdb/gdbserver: share some code relating to target description creation"
Andrew Burgess [Tue, 26 Mar 2024 18:52:44 +0000 (18:52 +0000)] 
Revert "gdb/gdbserver: share some code relating to target description creation"

This reverts commit cd9b374ffe372dcaf7e4c15548cf53a301d8dcdd.

15 months agoRevert "gdb/arch: assert that X86_XSTATE_MPX is not set for x32"
Andrew Burgess [Tue, 26 Mar 2024 18:52:36 +0000 (18:52 +0000)] 
Revert "gdb/arch: assert that X86_XSTATE_MPX is not set for x32"

This reverts commit efba976d9713a92b4507ccfef2257e4589da2798.

15 months agoRevert "gdbserver: update target description creation for x86/linux"
Andrew Burgess [Tue, 26 Mar 2024 18:52:27 +0000 (18:52 +0000)] 
Revert "gdbserver: update target description creation for x86/linux"

This reverts commit 61bb321605fc74703adc994fd7a78e9d2495ca7a.

15 months agoRevert "gdb/gdbserver: share x86/linux tdesc caching"
Andrew Burgess [Tue, 26 Mar 2024 18:52:17 +0000 (18:52 +0000)] 
Revert "gdb/gdbserver: share x86/linux tdesc caching"

This reverts commit 198ff6ff819c240545f9fc68b39636fd376d4ba9.

15 months agoRevert "gdbserver/Makefile.in: add missing `-x c++`"
Andrew Burgess [Tue, 26 Mar 2024 18:52:01 +0000 (18:52 +0000)] 
Revert "gdbserver/Makefile.in: add missing `-x c++`"

This reverts commit c7c9820071f8b81a64221f5cfafb3cbfeafe7916.