]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
8 months agosegv in bfd_elf_get_str_section
Alan Modra [Mon, 30 Sep 2024 22:23:55 +0000 (07:53 +0930)] 
segv in bfd_elf_get_str_section

Attempting to write a termination NUL to PROT_READ mmap'd memory was
a silly idea.

PR 32109
* elf.c (bfd_elf_get_str_section): Don't write terminating NUL
if missing.
* libbfd.c (_bfd_munmap_readonly_temporary): Correct comment.

8 months agoAdd line-number styling
Tom Tromey [Sat, 14 Sep 2024 21:07:17 +0000 (15:07 -0600)] 
Add line-number styling

This patch adds separate styling for line numbers.  That is, whenever
gdb prints a source line number, it uses this style.

v2 includes a change to ensure that %ps works in query.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Reviewed-by: Keith Seitz <keiths@redhat.com>
8 months agoImprove the placement of orphan note sections.
Nick Clifton [Mon, 30 Sep 2024 13:41:11 +0000 (14:41 +0100)] 
Improve the placement of orphan note sections.

PR 32219

8 months agogdb: fix filename completion in the middle of a line
Andrew Burgess [Thu, 12 Sep 2024 09:56:54 +0000 (10:56 +0100)] 
gdb: fix filename completion in the middle of a line

I noticed that filename completion in the middle of a line doesn't
work as I would expect it too.  For example, assuming '/tmp/filename'
exists, and is the only file in '/tmp/' then when I do the following:

  (gdb) file "/tmp/filen<TAB>

GDB completes to:

  (gdb) file "/tmp/filename"

But, if I type this:

  (gdb) file "/tmp/filen "xxx"

Then move the cursor to the end of '/tmp/filen' and press <TAB>, GDB
will complete the line to:

  (gdb) file "/tmp/filename "xxx"

But GDB will not insert the trailing double quote character.

The reason for this is found in readline/readline/complete.c in the
function append_to_match.  This is the function that appends the
trailing closing quote character, however, the closing quote is only
inserted if the cursor (rl_point) is at the end (rl_end) of the line
being completed.

In this patch, what I do instead is add the closing quote in the
function gdb_completer_file_name_quote, which is called from readline
through the rl_filename_quoting_function hook.  The docs for
rl_filename_quoting_function say (see 'info readline'):

  "... The MATCH_TYPE is either 'SINGLE_MATCH', if there is only one
  completion match, or 'MULT_MATCH'.  Some functions use this to
  decide whether or not to insert a closing quote character. ..."

This is exactly what I'm doing in this patch, and clearly this is not
an unusual choice.  Now after completing a filename that is not at the
end of the line GDB will add the closing quote character if
appropriate.

I have managed to write some tests for this.  I send a line of text to
GDB which includes a partial filename followed by a trailing string, I
then send the escape sequence to move the cursor left, and finally I
send the tab character.

Obviously, expect doesn't actually see the complete output with the
extra text "in place", instead expect sees the original line followed
by some escape sequences to reflect the cursor movement, then an
escape sequence to indicate that text is being inserted in the middle
of a line, followed by the new characters ... it's a bit messy, but I
think it holds together.

Reviewed-By: Tom Tromey <tom@tromey.com>
8 months agogdb: fix for completing a second filename for a command
Andrew Burgess [Fri, 13 Sep 2024 10:16:51 +0000 (11:16 +0100)] 
gdb: fix for completing a second filename for a command

After the recent filename completion changes I noticed that the
following didn't work as expected:

  (gdb) file "/path/to/some/file" /path/to/so<TAB>

Now, I know that the 'file' command doesn't actually take multiple
filenames, but currently (and this was true before the recent filename
completion changes too) the completion function doesn't know that the
command only expects a single filename, and should complete any number
of filenames.  And indeed, this works:

  (gdb) file "/path/to/some/file" "/path/to/so<TAB>

In this case I quoted the second path, and now GDB is happy to offer
completions.

It turns out that the problem in the first case is an off-by-one bug
in gdb_completer_file_name_char_is_quoted.  This function tells GDB if
a character within the line being completed is escaped or not.  An
escaped character cannot be a word separator.

The algorithm in gdb_completer_file_name_char_is_quoted is to scan
forward through the line keeping track of whether we are inside double
or single quotes, or if a character follows a backslash.  When we find
an opening quote we skip forward to the closing quote and then check
to see if we skipped over the character we are looking for, if we did
then the character is within the quoted string.

The problem is that this "is character inside quoted string" check
used '>=' instead if '>'.  As a consequence a character immediately
after a quoted string would be thought of as inside the quoted string.

In our first example this means that the single white space character
after the quoted string was thought to be quoted, and was not
considered a word breaking character.  As such, GDB would not try to
complete the second path.  And indeed, if we tried this:

  (gdb) file "/path/to/some/file"    /path/to/so<TAB>

That is, place multiple spaces after the first path, then GDB would
consider the first space as quoted, but the second space is NOT
quoted, and would be a word break.  Now GDB does complete the second
path.

By changing '>=' to '>' in gdb_completer_file_name_char_is_quoted this
bug is resolved, now the original example works and GDB will correctly
complete the second path.

For testing I've factored out the core of one testing proc, and I now
run those tests multiple times, once with no initial path, once with
an initial path in double quotes, once with an initial path in
single quotes, and finally, with an unquoted initial path.

Reviewed-By: Tom Tromey <tom@tromey.com>
8 months agogdb/MAINTAINERS: add myself to maintainers
Gerlicher, Klaus [Mon, 30 Sep 2024 09:03:57 +0000 (09:03 +0000)] 
gdb/MAINTAINERS: add myself to maintainers

8 months agogdb: Remove myself as x86 maintainer and update my email
Felix Willgerodt [Wed, 25 Sep 2024 13:28:18 +0000 (15:28 +0200)] 
gdb: Remove myself as x86 maintainer and update my email

8 months agogdb, testsuite: clean duplicate header includes
Gerlicher, Klaus [Fri, 13 Sep 2024 07:55:33 +0000 (07:55 +0000)] 
gdb, testsuite: clean duplicate header includes

Some of the gdb and testsuite files double include some headers. While
all headers use include guards, it helps a bit keeping the code base
tidy.

No functional change.

Approved-by: Kevin Buettner <kevinb@redhat.com>
8 months agoAutomatic date update in version.in
GDB Administrator [Mon, 30 Sep 2024 00:00:08 +0000 (00:00 +0000)] 
Automatic date update in version.in

8 months agoAutomatic date update in version.in
GDB Administrator [Sun, 29 Sep 2024 00:00:08 +0000 (00:00 +0000)] 
Automatic date update in version.in

8 months ago[gdb/symtab] Dump m_all_parents_map for verbose debug dwarf-read
Tom de Vries [Sat, 28 Sep 2024 06:35:02 +0000 (08:35 +0200)] 
[gdb/symtab] Dump m_all_parents_map for verbose debug dwarf-read

[ This is based on "[gdb/symtab] Add parent_map::dump" [1]. ]

When building the cooked index, gdb builds up a parent map.

This map is currently only visible at user level through the effect of using
it, but it's useful to be able to inspect it as well.

Add dumping of this parent map for "set debug dwarf-read 2".

As example, take test-case gdb.dwarf2/enum-type-c++.exp with target board
debug-types.

The parent map looks like:
...
$ gdb -q -batch \
    -iex "maint set worker-threads 0" \
    -iex "set debug dwarf-read 2" \
    outputs/gdb.dwarf2/enum-type-c++/enum-type-c++
  ...
[dwarf-read] print_stats: Final m_all_parents_map:
map start:
  0x0000000000000000 0x0
  0x0000000000000037 0x20f27d30 (0x36: ec)
  0x0000000000000051 0x0
  0x000000000000008b 0x20f27dc0 (0x8a: A)
  0x00000000000000a6 0x0
...

There's no parent entry at address 0xd6, which is part of what causes this:
...
(gdb) FAIL: gdb.dwarf2/enum-type-c++.exp: val1 has a parent
...

With the series containing the proposed fix applied [2], we get instead:
...
[dwarf-read] print_stats: Final m_all_parents_map:
map start:
  0x0000000000000000 0x0
  0x0000000000000026 0x7e0bdc0 (0x25: ns)
  0x0000000000000036 0x0
  0x0000000000000037 0x7e0bdf0 (0x36: ns::ec)
  0x0000000000000051 0x0
  0x000000000000007f 0x7e0be80 (0x7e: ns)
  0x000000000000008a 0x0
  0x000000000000008b 0x7e0beb0 (0x8a: ns::A)
  0x00000000000000a6 0x0
  0x00000000000000cc 0x7e0bf10 (0xcb: ns)
  0x00000000000000d4 0x7e0bf40 (0xd3: ns::A)
  0x00000000000000dc 0x7e0bf10 (0xcb: ns)
  0x00000000000000dd 0x7e0bf40 (0xd3: ns::A)
  0x00000000000000f6 0x0
...
and find at 0xd6 parent ns::A.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
[1] https://sourceware.org/pipermail/gdb-patches/2023-October/202883.html
[2] https://sourceware.org/pipermail/gdb-patches/2024-September/211958.html

8 months agogas buffer overflow with --listing-rhs-width
Alan Modra [Fri, 27 Sep 2024 22:33:36 +0000 (08:03 +0930)] 
gas buffer overflow with --listing-rhs-width

With listings enabled, gas keeps a small cache of source lines.  They
are stored in buffers of size LISTING_RHS_WIDTH, ie. 100.  Given
listing-rhs-width larger than 100 it is of course possible to overflow
the buffer.  Fix that by allocating as needed.  We could allocate all
buffers on the first call to print_source using listing_rhs_width, but
I chose not to do that in case some future assembly directive allows
changes to listing_rhs_width similarly to the way paper_width can
change during assembly.

8 months agoMove uses_elf_em to ld-lib.exp
Alan Modra [Fri, 27 Sep 2024 00:22:07 +0000 (09:52 +0930)] 
Move uses_elf_em to ld-lib.exp

and add a missing entry from uses_genelf.

binutils/
* testsuite/lib/binutils-common.exp (uses_elf_em): Delete.
ld/
* testsuite/lib/ld-lib.exp (uses_genelf): Add moxie-*-moxiebox.
(uses_elf_em): New.

8 months agoAutomatic date update in version.in
GDB Administrator [Sat, 28 Sep 2024 00:00:10 +0000 (00:00 +0000)] 
Automatic date update in version.in

8 months agoRe-run 'isort' on gdb tests
Tom Tromey [Fri, 27 Sep 2024 19:45:11 +0000 (13:45 -0600)] 
Re-run 'isort' on gdb tests

Re-running 'isort' (via pre-commit) showed that the file
py-read-memory-leak.py (from the gdb test suite) needed a small patch.

8 months agogdb/symtab: pass program space to lookup_symtab and iterate_over_symtabs
Simon Marchi [Mon, 12 Aug 2024 17:46:06 +0000 (13:46 -0400)] 
gdb/symtab: pass program space to lookup_symtab and iterate_over_symtabs

Make the current program space references bubble up.

In collect_symtabs_from_filename, remove the calls to
set_current_program_space and just pass the relevant pspaces.
This appears safe to do, because nothing in the `collector` callback
cares about the current pspace.

Change-Id: I00a7ed484bfbe5264f01a6abf0d33b51de373cbb
Reviewed-by: Keith Seitz <keiths@redhat.com>
8 months agox86: fix Solaris gas testsuite run
Jan Beulich [Fri, 27 Sep 2024 09:41:27 +0000 (11:41 +0200)] 
x86: fix Solaris gas testsuite run

Commits 8015b1b0c1a1 ("x86-64: Never make R_X86_64_GOT64 section
relative"), d774bf9b3623 ("x86: Add tls check in gas"), and
1b714c14e40f ("x86: Turn PLT32 to PC32 only for PC-relative
relocations") all should have adjusted the Solaris counterpart of the
reloc64 test as well.

8 months agoRISC-V: odd data padding vs mapping symbols
Jan Beulich [Fri, 27 Sep 2024 09:41:00 +0000 (11:41 +0200)] 
RISC-V: odd data padding vs mapping symbols

Odd data padding has a $d label inserted at its beginning. When a $x...
label is removed instead, a replacement is inserted after the padding.
The same, however, needs to also happen when there's no $x to replace.

8 months agoRISC-V: correct alignment directive handling for text sections
Jan Beulich [Fri, 27 Sep 2024 09:40:22 +0000 (11:40 +0200)] 
RISC-V: correct alignment directive handling for text sections

.insn or data emitted inside text sections can lead to positions not
being at insn granularity. In such situations using alignment
directives should reliably enforce the requested alignment.
Specifically requests to align back to insn granularity may not be
ignored (where, as a subcase thereof, the ordering of ".option norvc"
and e.g. ".p2align 2" should not matter; so far the alignment directive
needs to come first to have any effect). Similarly ahead of emitting
NOPs alignment first needs to be forced back to insn granularity.

The new testcases actually point out a corner case issue in the
disassembler as well, which is being corrected at the same time: We
don't want to print "0x" without any subsequent digits.

8 months agox86: optimize {,V}INSERTPS with certain immediates
Jan Beulich [Fri, 27 Sep 2024 09:23:12 +0000 (11:23 +0200)] 
x86: optimize {,V}INSERTPS with certain immediates

They are equivalent to simple moves or xors, which are up to 3 bytes
shorter to encode (and maybe/likely also cheaper to execute).

8 months agox86: optimize {,V}EXTRACT{F,I}{128,32x{4,8},64x{2,4}} with immediate 0
Jan Beulich [Fri, 27 Sep 2024 09:22:34 +0000 (11:22 +0200)] 
x86: optimize {,V}EXTRACT{F,I}{128,32x{4,8},64x{2,4}} with immediate 0

They, too, are equivalent to simple moves, which are up to 3 bytes
shorter to encode (and maybe also cheaper to execute).

8 months agox86: optimize {,V}EXTRACTPS with immediate 0
Jan Beulich [Fri, 27 Sep 2024 09:21:51 +0000 (11:21 +0200)] 
x86: optimize {,V}EXTRACTPS with immediate 0

They are equivalent to simple moves, which are up to 2 bytes shorter to
encode (and maybe also cheaper to execute).

8 months agox86: correct {,V}PEXTR{D,Q} optimization
Jan Beulich [Fri, 27 Sep 2024 09:20:37 +0000 (11:20 +0200)] 
x86: correct {,V}PEXTR{D,Q} optimization

A possible relocation associated with a memory operand also needs
moving.

8 months agoEnable -z separate-code, -z common and -z text for more targets
Alan Modra [Fri, 27 Sep 2024 00:23:10 +0000 (09:53 +0930)] 
Enable -z separate-code, -z common and -z text for more targets

Fix a mis-placed "fi".

8 months agoAutomatic date update in version.in
GDB Administrator [Fri, 27 Sep 2024 00:00:10 +0000 (00:00 +0000)] 
Automatic date update in version.in

8 months agoAdd 'const' to symmisc.c
Tom Tromey [Thu, 26 Sep 2024 23:06:50 +0000 (17:06 -0600)] 
Add 'const' to symmisc.c

I noticed a few spots in symmisc.c that could use a 'const'.

8 months agoFix 32207 [gprofng collect app] Error in parsing the -O option
Vladimir Mezentsev [Wed, 25 Sep 2024 22:31:34 +0000 (15:31 -0700)] 
Fix 32207 [gprofng collect app] Error in parsing the -O option

gprofng/ChangeLog
2024-09-25  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

PR 32207
* src/collctrl.cc (preprocess_names): Fix the size in strndup.

8 months agoUpdated Brazilian Portuguese translation for the gprof directory.
Nick Clifton [Thu, 26 Sep 2024 15:11:28 +0000 (16:11 +0100)] 
Updated Brazilian Portuguese translation for the gprof directory.

8 months agoFix -Wstringop-overflow warning in ecoff_link_hash_newfunc
Andreas Schwab [Thu, 26 Sep 2024 11:06:25 +0000 (13:06 +0200)] 
Fix -Wstringop-overflow warning in ecoff_link_hash_newfunc

* ecoff.c (ecoff_link_hash_newfunc): Don't call memset if ret is
NULL.

8 months agold: Ignore .note.gnu.build-id when placing orphaned notes
H.J. Lu [Fri, 20 Sep 2024 03:32:26 +0000 (11:32 +0800)] 
ld: Ignore .note.gnu.build-id when placing orphaned notes

The commits:

e8e10743f7b Add --rosegment option to BFD linker to stop the '-z separate-code' from generating two read-only segments.
bf6d7087de0 ld: Move the .note.build-id section to near the start of the memory map

place .note.gnu.build-id before text sections when --rosegment is used.
Ignore .note.gnu.build-id when placing orphaned notes if --rosegment and
-z separate-code are used together to avoid putting any note sections
between .note.gnu.build-id and text sections in the same PT_LOAD segment.

PR ld/32191
* ldlang.c (lang_insert_orphan): Ignore .note.gnu.build-id when
placing orphaned notes.
* testsuite/ld-elf/pr23658-1a.d: Pass --no-rosegment to ld.
* testsuite/ld-elf/pr23658-1c.d: Likewise.
* testsuite/ld-elf/pr23658-1e.d: New file.
* testsuite/ld-elf/pr23658-1f.d: Likewise.
* testsuite/ld-i386/i386.exp: Run PR ld/32191 test.
* testsuite/ld-i386/pr32191.d: New file.
* testsuite/ld-x86-64/lam-u48.rd: Updated.
* testsuite/ld-x86-64/lam-u57.rd: Likewise.
* testsuite/ld-x86-64/pr32191-x32.d: New file.
* testsuite/ld-x86-64/pr32191.d: Likewise.
* testsuite/ld-x86-64/pr32191.s: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run PR ld/32191 tests.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
8 months agox86: templatize SIMD narrowing-move templates
Jan Beulich [Thu, 26 Sep 2024 10:27:14 +0000 (12:27 +0200)] 
x86: templatize SIMD narrowing-move templates

Once again to reduce redundancy.

8 months agox86: templatize SIMD sign-/zero-extension templates
Jan Beulich [Thu, 26 Sep 2024 10:27:01 +0000 (12:27 +0200)] 
x86: templatize SIMD sign-/zero-extension templates

Yet again to reduce redundancy.

8 months agox86: templatize SIMD FP binary-logic templates
Jan Beulich [Thu, 26 Sep 2024 10:26:34 +0000 (12:26 +0200)] 
x86: templatize SIMD FP binary-logic templates

Once more to reduce redundancy.

8 months agox86: further templatize FMA templates
Jan Beulich [Thu, 26 Sep 2024 10:26:15 +0000 (12:26 +0200)] 
x86: further templatize FMA templates

Further reduce redundancy, in preparation of the addition of
counterparts for AVX10.2.

8 months agox86: templatize SIMD FP arithmetic templates
Jan Beulich [Thu, 26 Sep 2024 10:25:45 +0000 (12:25 +0200)] 
x86: templatize SIMD FP arithmetic templates

Reduce redundancy, in preparation of the addition of further counterparts
for AVX10.2. Provide the "ne" parameter needed there right away, even if
unused for now.

8 months agogdb/testsuite: test for memory leaks in gdb.Inferior.read_memory()
Andrew Burgess [Wed, 25 Sep 2024 14:44:56 +0000 (15:44 +0100)] 
gdb/testsuite: test for memory leaks in gdb.Inferior.read_memory()

For a long time Fedora GDB has carried an out of tree patch which
checks for memory leaks in gdb.Inferior.read_memory().  At one point
in the distant past GDB did have a memory leak in this code, but this
was first fixed in commit:

  commit 655e820cf9a039ee55325d9e1f8423796d592b4b
  Date:   Wed Mar 28 17:38:07 2012 +0000

        * python/py-inferior.c (infpy_read_memory): Remove cleanups and
          explicitly free 'buffer' on exit paths.  Decref 'membuf_object'
          before returning.

And the code has changed a lot since then, but the leak is still
fixed.  Unfortunately, this commit didn't have any associated tests.

The original Fedora test wasn't really suitable for upstream, it was
reading /proc/PID/... to figure out if there was a leak or not.

However, we already have gdb.python/py-inferior-leak.exp in upstream
GDB, which makes use of the Python tracemalloc module to check for
memory leaks in a corner of the Python API, so I figured it wouldn't
hurt to rewrite the test in the same style.

And so here is a test for a bug which was closed 12 years ago.  This
detects if the gdb.Inferior.read_memory() call leaks any memory.

I've tested this by hacking gdbpy_buffer_to_membuf, replacing the last
line which currently looks like this:

  return PyMemoryView_FromObject ((PyObject *) membuf_obj.get ());

and instead doing:

  return PyMemoryView_FromObject ((PyObject *) membuf_obj.release ());

The use of "release" here will mean we no longer decrement the
reference count on membuf_obj before returning from the function.  As
a consequence the membuf_obj will not be garbage collected.  With this
hack in place the new test will fail.

The Python script in the new test is mostly a copy&paste from
py-inferior-leak.py with the core changed to do a memory read instead
of inferior creation.  I did consider rewriting both tests into a
single file, maybe, py-memory-leak.py, which would make it easier to
add additional similar tests in the future.  For now I've held off
doing that, but if this gets merged then I _might_ revisit this idea.

If folk feel that this new test should only be accepted if I do this
rewrite then let me know and I can get that done.

On copyright date ranges: The .exp and .py scripts are new enough for
this commit that I've dated them 2024.  The .c source script is lifted
directly from the old Fedora patch, so I've retained the original 2014
start date for that file only.

Approved-By: Tom Tromey <tom@tromey.com>
8 months agox86/testsuite: Refine AVX10.2 rounding testcases
Haochen Jiang [Wed, 25 Sep 2024 08:47:16 +0000 (16:47 +0800)] 
x86/testsuite: Refine AVX10.2 rounding testcases

Using hard byte code is not a good idea in dump file. Add a label
for intel syntax test check to avoid that.

gas/ChangeLog:

* testsuite/gas/i386/avx10_2-rounding-intel.d: Use label for
test split.
* testsuite/gas/i386/avx10_2-rounding.s: Add label to avoid
hard coding in dump file.

9 months agoAutomatic date update in version.in
GDB Administrator [Thu, 26 Sep 2024 00:00:14 +0000 (00:00 +0000)] 
Automatic date update in version.in

9 months agox86 TLS relocation checks
Alan Modra [Wed, 25 Sep 2024 12:02:03 +0000 (21:32 +0930)] 
x86 TLS relocation checks

Some configurations (eg. i386-bsd, i386-msdos) broke with the addition
of the TLS relocation checking.  The "x86_elf_abi undeclared" error
has been fixed, but "gotrel defined but not used" remains.  Fix that.
Also invert the preprocessor test around lex_got to make it positive
logic and remove the LEX_AT condition which is no longer necessary.
(The only x86 config files defining LEX_AT also define TE_PE.)

9 months agoltmain.sh: allow more flags at link-time
Sam James [Wed, 14 Aug 2024 03:09:39 +0000 (04:09 +0100)] 
ltmain.sh: allow more flags at link-time

libtool defaults to filtering flags passed at link-time.

This brings the filtering in GCC's 'fork' of libtool into sync with
upstream libtool commit 22a7e547e9857fc94fe5bc7c921d9a4b49c09f8e.

In particular, this now allows some harmless diagnostic flags (especially
useful for things like -Werror=odr), more optimization flags, and some
Clang-specific options.

GCC's -flto documentation mentions:
> To use the link-time optimizer, -flto and optimization options should be
> specified at compile time and during the final link. It is recommended
> that you compile all the files participating in the same link with the
> same options and also specify those options at link time.

This allows compliance with that.

* ltmain.sh (func_mode_link): Allow various flags through filter.

9 months ago[gdb/python] Make sure python sys.exit makes gdb exit
Tom de Vries [Wed, 25 Sep 2024 17:29:57 +0000 (19:29 +0200)] 
[gdb/python] Make sure python sys.exit makes gdb exit

With gdb 15.1, python sys.exit no longer makes gdb exit:
...
$ gdb -q -batch -ex "python sys.exit(2)" -ex "print 123"; echo $?
Python Exception <class 'SystemExit'>: 2
Error occurred in Python: 2
$1 = 123
0
...

This is a change in behaviour since commit a207f6b3a38 ("Rewrite "python"
command exception handling"), first available in gdb 15.1.

This patch reverts to the old behaviour by handling PyExc_SystemExit in
gdbpy_handle_exception, such what we have instead:
...
$ gdb -q -batch -ex "python sys.exit(2)" -ex "print 123"; echo $?
2
...

Tested on x86_64-linux, with python 3.6 and 3.13.

Tested-By: Guinevere Larsen <blarsen@redhat.com>
Approved-By: Tom Tromey <tom@tromey.com>
PR python/31946
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31946

9 months agogdb/testsuite: format some Python files
Simon Marchi [Wed, 25 Sep 2024 14:16:59 +0000 (10:16 -0400)] 
gdb/testsuite: format some Python files

Format with black.

Change-Id: I28e79e9da07ea29391ad1942047633960fa72ed2

9 months agogdb, gdbserver, python, testsuite: Remove MPX.
Schimpe, Christina [Wed, 6 Mar 2024 11:22:49 +0000 (11:22 +0000)] 
gdb, gdbserver, python, testsuite: Remove MPX.

GDB deprecated the commands "show/set mpx bound" in GDB 15.1, as Intel
listed Intel(R) Memory Protection Extensions (MPX) as removed in 2019.
MPX is also deprecated in gcc (since v9.1), the linux kernel (since v5.6)
and glibc (since v2.35).  Let's now remove MPX support in GDB completely.

This includes the removal of:
- MPX functionality including register support
- deprecated mpx commands
- i386 and amd64 implementation of the hooks report_signal_info and
  get_siginfo_type
- tests
- and pretty printer.

We keep MPX register numbers to not break compatibility with old gdbservers.

Approved-By: Felix Willgerodt <felix.willgerodt@intel.com>
9 months agogdb, testsuite, python: Add missing imports.
Schimpe, Christina [Mon, 19 Feb 2024 17:59:24 +0000 (17:59 +0000)] 
gdb, testsuite, python: Add missing imports.

Removing the pretty printer (bound_registers.py) in the next commit
leads to failures due to a missing import of 'gdb.printing':

"AttributeError: module 'gdb' has no attribute 'printing'".

Add this import to each file requiring it, as it's not imported by the
pretty-printer anymore.

Approved-By: Andrew Burgess <aburgess@redhat.com>
9 months agobinutils testsuite: canonicalize subtest names in libctf
Frank Ch. Eigler [Fri, 20 Sep 2024 20:23:48 +0000 (16:23 -0400)] 
binutils testsuite: canonicalize subtest names in libctf

Previous code included the full $srcdir pathnames in the individual
subtest PASS/FAIL names, which makes it difficult to compute
comparisons or regressions between test runs on different machines.
This version switches to the basename only, which are common.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
9 months agobinutils testsuite: canonicalize subtest names in debuginfod.exp
Frank Ch. Eigler [Fri, 20 Sep 2024 20:19:41 +0000 (16:19 -0400)] 
binutils testsuite: canonicalize subtest names in debuginfod.exp

Previous code included the full $srcdir pathnames in the individual
subtest PASS/FAIL names, which makes it difficult to compute
comparisons or regressions between test runs on different machines.
This version switches to the basename only, which are common.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
9 months agoRISC-V: Add Smrnmi extension csrs.
Jiawei [Tue, 24 Sep 2024 11:16:25 +0000 (19:16 +0800)] 
RISC-V: Add Smrnmi extension csrs.

This patch support Smrnmi extension[1],
The csrs address can be find in[2].

[1] https://github.com/riscv/riscv-isa-manual/commit/35eb3948bf0b87c83fab5a7238bd68b6211faf62
[2] https://github.com/riscv/riscv-isa-manual/blob/smrnmi-1.0/src/priv-csrs.adoc

bfd/ChangeLog:

* elfxx-riscv.c: New extension.

gas/ChangeLog:

* NEWS: Add Smrnmi extension support.
* config/tc-riscv.c (enum riscv_csr_class): New extension class.
(riscv_csr_address): Ditto.
* testsuite/gas/riscv/csr-version-1p10.d: New csrs.
* testsuite/gas/riscv/csr-version-1p10.l: Ditto.
* testsuite/gas/riscv/csr-version-1p11.d: Ditto.
* testsuite/gas/riscv/csr-version-1p11.l: Ditto.
* testsuite/gas/riscv/csr-version-1p12.d: Ditto.
* testsuite/gas/riscv/csr-version-1p12.l: Ditto.
* testsuite/gas/riscv/csr.s:  Ditto.
* testsuite/gas/riscv/march-help.l: New extension.

include/ChangeLog:

* opcode/riscv-opc.h (CSR_MNSCRATCH): New csr.
(CSR_MNEPC): Ditto.
(CSR_MNCAUSE): Ditto.
(CSR_MNSTATUS): Ditto.
(DECLARE_CSR): New csr declarations.

9 months agoAutomatic date update in version.in
GDB Administrator [Wed, 25 Sep 2024 00:00:11 +0000 (00:00 +0000)] 
Automatic date update in version.in

9 months agoFix typo in gdb.ada/complete.exp test
Tom Tromey [Tue, 24 Sep 2024 18:27:24 +0000 (12:27 -0600)] 
Fix typo in gdb.ada/complete.exp test

I noticed that two tests in gdb.ada/complete.exp are testing the same
thing: the completion of "p pck.inne".  The second such test has this
comment:

    # A fully qualified package name

I believe the intent here was to test "p pck.inner" (note the trailing
"r").  This patch makes this change.

9 months agogdb: testsuite: Test whether PC register is expedited in gdb.server/server-run.exp
Thiago Jung Bauermann [Thu, 5 Sep 2024 04:42:02 +0000 (01:42 -0300)] 
gdb: testsuite: Test whether PC register is expedited in gdb.server/server-run.exp

One thing GDB always does when the inferior stops is finding out where
it's stopped at, by way of querying the value of the program counter
register.

To save a packet round trip, the remote target can send the PC
value (often alongside other frequently consulted registers such as the
stack pointer) in the stop reply packet as an "expedited register".

Test that this is actually done for the targets where gdbserver is
supposed to.

Extend the "maintenance print remote-registers" command output with an
"Expedited" column which says "yes" if the register was seen by GDB in
the last stop reply packet it received, and is left blank otherwise.

Tested for regressions on aarch64-linux-gnu native-extended-remote.

The testcase was tested on aarch64-linux-gnu, i686-linux-gnu and
x86_64-linux-gnu native-remote and native-extended-remote targets.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
9 months agold: re-generate configure
Simon Marchi [Tue, 24 Sep 2024 16:31:44 +0000 (12:31 -0400)] 
ld: re-generate configure

Looks like configure has been generated with a non-upstream autoconf,
re-generate it.

ld/ChangeLog:

* configure: Re-generate.

Change-Id: I6774381ad411a190fb93ff260234dd79d8791680

9 months agogdb/elfread.c: remove unused includes
Simon Marchi [Tue, 24 Sep 2024 15:01:42 +0000 (11:01 -0400)] 
gdb/elfread.c: remove unused includes

Remove some includes reported as unused by clangd.

Change-Id: If7c4729975bd90b9cc2c22bcf84d333bd0002a52

9 months ago[gdb] Handle SIGTERM in run_events
Tom de Vries [Tue, 24 Sep 2024 14:45:27 +0000 (16:45 +0200)] 
[gdb] Handle SIGTERM in run_events

While reviewing "catch (...)" uses I came across:
...
  for (auto &item : local)
    {
      try
{
  item ();
}
      catch (...)
{
  /* Ignore exceptions in the callback.  */
}
    }
...

This means that when an item throws a gdb_exception_forced_quit,
the exception is ignored and following items are executed.

Fix this by handling gdb_exception_forced_quit explicity, and immediately
rethrowing it.

I wondered about ^C, and couldn't decide whether current behaviour is ok, so
I left this alone, but I made the issue explicit in the source code.

As for the "catch (...)", I think that it should let a non-gdb_exception
propagate, so I've narrowed it to "catch (const gdb_exception &)".

My rationale for this is as follows.

There seem to be a few ways that "catch (...)" is allowed in gdb:
- clean-up and rethrow (basically the SCOPE_EXIT pattern)
- catch and handle an exception from a call into an external c++ library

Since we're dealing with neither of those here, we remove the "catch (...)".

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
9 months agold: support --build-id=xx mode
Frank Ch. Eigler [Thu, 19 Sep 2024 21:06:48 +0000 (17:06 -0400)] 
ld: support --build-id=xx mode

The is patch adds a new ld build-id computation mode, "xx", using
xxhash in its 128-bit mode.  The patch prereqs the xxhash-devel
headers being installed, and uses the "all-inlined" model, so no
run-time or link-time library dependence exists.

The xxhash mode performs well, saving roughly 20% of total userspace
run time from an ld job over a 800MB shared library relative to sha1.
128 bits of good hash should be collision-resistant to a number of
distinct binaries that numbers in the 2**32 - 2**64 range, even if not
"crypto" level hash.  Confirmations of this are in progress.

         ld/configury: add --with-xxhash mode, different from gdb case
                       because only using it in inline mode

         ld/ldbuildid.c: add "xx" mode, #if WITH_XXHASH

         ld/NEWS, ld.texi: mention new option

         ld/lexsup.c: add enumeration of --build-id STYLES to --help

         ld/testsuite/ld-elf/build-id.exp: add test case for 0xHEX case
                                           and conditional for xx case;
                                           also, simply tcl list syntax

https://inbox.sourceware.org/binutils/20240917201509.GB26396@redhat.com/

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
9 months ago[gdb] Handle ^C in ~scoped_remote_fd
Tom de Vries [Tue, 24 Sep 2024 13:17:57 +0000 (15:17 +0200)] 
[gdb] Handle ^C in ~scoped_remote_fd

While reviewing "catch (...)" uses I came across:
...
try
  {
    fileio_error remote_errno;
    m_remote->remote_hostio_close (m_fd, &remote_errno);
  }
catch (...)
  {
    /* Swallow exception before it escapes the dtor.  If
       something goes wrong, likely the connection is gone,
       and there's nothing else that can be done.  */
  }
...

This also swallows gdb_exception_quit and gdb_exception_forced_quit.  I don't
know whether these can actually happen here, but if not it's better to
accommodate for the possibility anyway.

Fix this by handling gdb_exception_quit and gdb_exception_forced_quit
explicitly.

It could be that "catch (...)" should be replaced by
"catch (const gdb_exception &)" but that depends on what kind of exception
remote_hostio_close is expected to throw, and I don't know that, so I'm
leaving it as is.

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
9 months agobtrace: Add support for further events.
Felix Willgerodt [Tue, 27 Jun 2023 09:20:55 +0000 (11:20 +0200)] 
btrace: Add support for further events.

This is similar to the previous events that we added, and adds support for
SMI, RSM, SIPI, INIT, VMENTRY, VMEXIT, SHUTDOWN, UINTR and UIRET.
Though since these are mainly mechanical and not really possible to test,
they are bundled in one commit.

Approved-By: Markus Metzger <markus.t.metzger@intel.com>
9 months agobtrace: Add support for IRET events.
Felix Willgerodt [Tue, 27 Jun 2023 09:18:21 +0000 (11:18 +0200)] 
btrace: Add support for IRET events.

This is similar to the previous events that we added.

Approved-By: Markus Metzger <markus.t.metzger@intel.com>
9 months agobtrace: Add support for interrupt events.
Felix Willgerodt [Mon, 26 Jun 2023 14:54:25 +0000 (16:54 +0200)] 
btrace: Add support for interrupt events.

Newer Intel CPUs support recording asynchronous events in the PT trace.
Libipt also recently added support for decoding these.

This patch adds support for interrupt events, based on the existing aux
infrastructure.  GDB can now display such events during the record
instruction-history and function-call-history commands.

Subsequent patches will add the rest of the events currently supported.

Approved-By: Markus Metzger <markus.t.metzger@intel.com>
9 months agobtrace: Enable event tracing on Linux for Intel PT.
Felix Willgerodt [Wed, 28 Jun 2023 08:15:04 +0000 (10:15 +0200)] 
btrace: Enable event tracing on Linux for Intel PT.

Event tracing allows GDB to show information about interesting asynchronous
events when tracing with Intel PT.  Subsequent patches will add support for
displaying each type of event.

Enabling event-tracing unconditionally would result in rather noisy output, as
breakpoints themselves result in interrupt events.  Which is why this patch adds
a set/show command to allow the user to enable/disable event-tracing before
starting a recording. The event-tracing setting has no effect on an already
active recording.  The default setting is off.   As event tracing will use the
auxiliary infrastructure added by ptwrite, the user can still disable printing
events, even when event-tracing was enabled, by using the /a switch for the
record instruction-history/function-call-history commands.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Markus Metzger <markus.t.metzger@intel.com>
9 months agobtrace: Add printing support for cfe and evd packets.
Felix Willgerodt [Wed, 13 Sep 2023 08:42:57 +0000 (08:42 +0000)] 
btrace: Add printing support for cfe and evd packets.

Approved-By: Markus Metzger <markus.t.metzger@intel.com>
9 months agobtrace: Print "non-contiguous" for gaps.
Felix Willgerodt [Fri, 3 May 2024 12:04:12 +0000 (14:04 +0200)] 
btrace: Print "non-contiguous" for gaps.

So far we printed "disabled" for gaps, when we saw a ptev_enabled event that
doesn't have the resumed flag set.  This is wrong, as the actual disabling
happens with ptev_disabled.  So far this didn't matter, but once we have event
tracing, there can be events between a ptev_disabled and a ptev_enabled.
This patch is in preparation for that, and removes the disabled reason in
favour of a more accurate non-contiguous reason, and adjusts the string we
print accordingly.

Approved-By: Markus Metzger <markus.t.metzger@intel.com>
9 months ago[gdb] Eliminate catch(...) in pipe_command
Tom de Vries [Tue, 24 Sep 2024 11:57:55 +0000 (13:57 +0200)] 
[gdb] Eliminate catch(...) in pipe_command

Remove duplicate code in pipe_command using SCOPE_EXIT.

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
9 months ago[gdb] Eliminate catch(...) in target_wait
Tom de Vries [Tue, 24 Sep 2024 11:55:50 +0000 (13:55 +0200)] 
[gdb] Eliminate catch(...) in target_wait

Remove duplicate code in target_wait using SCOPE_EXIT.

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
9 months ago[gdb] Eliminate catch(...) in execute_fn_to_string
Tom de Vries [Tue, 24 Sep 2024 11:50:19 +0000 (13:50 +0200)] 
[gdb] Eliminate catch(...) in execute_fn_to_string

Remove duplicate code in execute_fn_to_string using SCOPE_EXIT.

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
9 months ago[gdb] Make scope_exit constructor throw
Tom de Vries [Tue, 24 Sep 2024 11:47:56 +0000 (13:47 +0200)] 
[gdb] Make scope_exit constructor throw

While reviewing "catch (...)" uses I came across:
...
  scope_exit (EFP &&f)
    try : m_exit_function ((!std::is_lvalue_reference<EFP>::value
    && std::is_nothrow_constructible<EF, EFP>::value)
   ? std::move (f)
   : f)
  {
  }
  catch (...)
    {
      /* "If the initialization of exit_function throws an exception,
 calls f()."  */
      f ();
    }

...
and while looking up the origin of the comment here [1] I saw right after:
...
throws: Nothing, unless the initialization of exit_function throws
...

I think that means that the exception should be rethrown, so fix this by doing
so.

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
[1] https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0052r5.pdf

9 months ago[gdb] Handle ^C in gnu_source_highlight_test
Tom de Vries [Tue, 24 Sep 2024 11:41:42 +0000 (13:41 +0200)] 
[gdb] Handle ^C in gnu_source_highlight_test

In gnu_source_highlight_test we have:
...
  try
    {
      res = try_source_highlight (styled_prog, language_c, fullname);
    }
  catch (...)
    {
      saw_exception = true;
    }
...

This also swallows gdb_exception_quit and gdb_exception_forced_quit.  I don't
know whether these can actually happen here, but if not it's better to
accommodate for the possibility anyway.

Fix this by handling gdb_exception explicitly, and rethrowing
gdb_exception_quit and gdb_exception_forced_quit.

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
9 months ago[gdb/cli] Show readline wrapping mode for maint info screen
Tom de Vries [Tue, 24 Sep 2024 11:26:15 +0000 (13:26 +0200)] 
[gdb/cli] Show readline wrapping mode for maint info screen

With the same trigger patch adding "set horizontal-scroll-mode on" to INPUTRC
as used in commit 250f1bbaf33 ("[gdb/testsuite] Fix gdb.tui/wrap-line.exp with
wrapping disabled"), we can easily reproduce a failure in
gdb.tui/wrap-line.exp mentioned in PR testsuite/31201:
...
(gdb) 78901234567890123456789012345678901234567890123456789012345678901234567^M<890123456789012345678901234567890123456789012345678                         ^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H9WFAIL: gdb.base/wrap-line.exp: term=ansi: width-hard-coded: wrap (timeout)
...

The test-case expects wrapping, but that's disabled by horizontal-scroll-mode.

Add a new line to "maint info screen", that describes the current readline
wrapping mode, and use it in the test-case to handle the different cases.

The reported values for the wrapping mode are as follows.

Unsupported because of running in batch mode:
...
$ gdb -q -batch -ex "maint info screen"
Readline wrapping mode: unsupported (gdb batch mode).
...

Unsupported because the terminal is not capable to move the cursor up:
...
$ TERM=dumb gdb -q -ex "maint info screen" -ex q
Readline wrapping mode: unsupported (terminal is not Cursor Up capable).
...

Disabled by horizontal-scroll-mode:
...
$ grep horizontal-scroll-mode ~/.inputrc
set horizontal-scroll-mode on
$ gdb -q -ex "maint info screen" -ex q
Readline wrapping mode: disabled (horizontal-scroll-mode).
...

Wrap done by readline because terminal is not auto wrap capable:
...
$ TERM=ansi gdb -q -ex "maint info screen" -ex q
Readline wrapping mode: readline (terminal is not auto wrap capable, last column reserved).
...

Wrap done by terminal autowrap:
...
$ TERM=xterm gdb -q -ex "maint info screen" -ex q
Readline wrapping mode: terminal (terminal is auto wrap capable).
...

Tested on x86_64-linux.

Co-Authored-By: Bernd Edlinger <bernd.edlinger@hotmail.de>
Approved-By: Tom Tromey <tom@tromey.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31201

9 months ago[gdb/python] Use gdbpy_handle_gdb_exception in valpy_assign_core
Tom de Vries [Tue, 24 Sep 2024 11:06:32 +0000 (13:06 +0200)] 
[gdb/python] Use gdbpy_handle_gdb_exception in valpy_assign_core

In valpy_assign_core we have:
...
  catch (const gdb_exception &except)
    {
      gdbpy_convert_exception (except);
      return false;
     }
...

Use instead:
...
  catch (const gdb_exception &except)
    {
      return gdbpy_handle_gdb_exception (false, except);
    }
...

No functional changes.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
9 months ago[gdb/python] Eliminate GDB_PY_SET_HANDLE_EXCEPTION
Tom de Vries [Tue, 24 Sep 2024 11:06:32 +0000 (13:06 +0200)] 
[gdb/python] Eliminate GDB_PY_SET_HANDLE_EXCEPTION

Result of:
...
$ search="GDB_PY_SET_HANDLE_EXCEPTION ("
$ replace="return gdbpy_handle_gdb_exception (-1, "
$ sed -i \
    "s/$search/$replace/" \
    gdb/python/*.c
...

Also remove the now unused GDB_PY_SET_HANDLE_EXCEPTION.

No functional changes.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
9 months ago[gdb/python] Eliminate GDB_PY_HANDLE_EXCEPTION
Tom de Vries [Tue, 24 Sep 2024 11:06:32 +0000 (13:06 +0200)] 
[gdb/python] Eliminate GDB_PY_HANDLE_EXCEPTION

Result of:
...
$ search="GDB_PY_HANDLE_EXCEPTION ("
$ replace="return gdbpy_handle_gdb_exception (nullptr, "
$ sed -i \
    "s/$search/$replace/" \
    gdb/python/*.c
...

Also remove the now unused GDB_PY_HANDLE_EXCEPTION.

No functional changes.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
9 months ago[gdb/python] Add gdbpy_handle_gdb_exception
Tom de Vries [Tue, 24 Sep 2024 11:06:32 +0000 (13:06 +0200)] 
[gdb/python] Add gdbpy_handle_gdb_exception

I've recently committed two patches:
- commit 2f8cd40c37a ("[gdb/python] Use GDB_PY_HANDLE_EXCEPTION more often")
- commit fbf8e4c35c2 ("[gdb/python] Use GDB_PY_SET_HANDLE_EXCEPTION more often")
which use the macros GDB_PY_HANDLE_EXCEPTION and GDB_PY_SET_HANDLE_EXCEPTION
more often, with the goal of making things more consistent.

Having done that, I wondered if a better approach could be possible.

Consider GDB_PY_HANDLE_EXCEPTION:
...
 /* Use this in a 'catch' block to convert the exception to a Python
    exception and return nullptr.  */
 #define GDB_PY_HANDLE_EXCEPTION(Exception) \
   do { \
     gdbpy_convert_exception (Exception); \
     return nullptr; \
   } while (0)
...

The macro nicely codifies how python handles exceptions:
- setting an error condition using some PyErr_Set* variant, and
- returning a value implying that something went wrong
presumably with the goal that using the macro will mean not accidentally:
- forgetting to return on error, or
- returning the wrong value on error.

The problems are that:
- the macro hides control flow, specifically the return statement, and
- the macro hides the return value.

For example, when reading somewhere:
...
  catch (const gdb_exception &except)
    {
      GDB_PY_HANDLE_EXCEPTION (except);
    }
...
in order to understand what this does, you have to know that the macro
returns, and that it returns nullptr.

Add a template gdbpy_handle_gdb_exception:
...
template<typename T>
[[nodiscard]] T
gdbpy_handle_gdb_exception (T val, const gdb_exception &e)
{
  gdbpy_convert_exception (e);
  return val;
}
...
which can be used instead:
...
  catch (const gdb_exception &except)
    {
      return gdbpy_handle_gdb_exception (nullptr, except);
    }
...

[ Initially I tried this:
...
template<auto val>
[[nodiscard]] auto
gdbpy_handle_gdb_exception (const gdb_exception &e)
{
  gdbpy_convert_exception (e);
  return val;
}
...
with which the usage is slightly better looking:
...
  catch (const gdb_exception &except)
    {
      return gdbpy_handle_gdb_exception<nullptr> (except);
    }
...
but I ran into trouble with older gcc compilers. ]

While still a single statement, we now have it clear:
- that the statement returns,
- what value the statement returns.

[ FWIW, this could also be handled by say:
...
-      GDB_PY_HANDLE_EXCEPTION (except);
+      GDB_PY_HANDLE_EXCEPTION_AND_RETURN_VAL (except, nullptr);
...
but I still didn't find the fact that it returns easy to spot.

Alternatively, this is the simplest form we could use:
...
      return gdbpy_convert_exception (e), nullptr;
...
but the pairing would not necessarily survive a copy/paste/edit cycle. ]

Also note how making the value explicit makes it easier to check for
consistency:
...
  catch (const gdb_exception &except)
    {
      return gdbpy_handle_gdb_exception (-1, except);
    }

  if (PyErr_Occurred ())
    return -1;
...
given that we do use the explicit constants almost everywhere else.

Compared to using GDB_PY_HANDLE_EXCEPTION, there is the burden now to specify
the return value, but I assume that this will be generally copy-pasted and
therefore present no problem.

Also, there's no longer a guarantee that there's an immediate return, but I
assume that nodiscard making sure that the return value is not silently
ignored is sufficient mitigation.

For now, re-implement GDB_PY_HANDLE_EXCEPTION and GDB_PY_SET_HANDLE_EXCEPTION
in terms of gdbpy_handle_gdb_exception.

Follow-up patches will eliminate the macros.

No functional changes.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
9 months ago[gdb/symtab] Fix segfault on invalid debug info
Tom de Vries [Tue, 24 Sep 2024 08:50:44 +0000 (10:50 +0200)] 
[gdb/symtab] Fix segfault on invalid debug info

While looking at PR symtab/31478 (a problem in the cooked indexer with invalid
dwarf) it occurred to me that I could trigger a similar problem using:
...
  Compilation Unit @ offset 0xb2:
   Length:        0x1f (32-bit)
   Version:       4
   Abbrev Offset: 0x6c
   Pointer Size:  8
 <0><bd>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <be>   DW_AT_language    : 2 (non-ANSI C)
 <1><bf>: Abbrev Number: 2 (DW_TAG_subprogram)
    <c0>   DW_AT_low_pc      : 0x4004a7
    <c8>   DW_AT_high_pc     : 0x4004b2
    <d0>   DW_AT_specification: <0xd5>
 <1><d4>: Abbrev Number: 0
  Compilation Unit @ offset 0xd5:
   Length:        0x7 (32-bit)
   Version:       4
   Abbrev Offset: 0x7f
   Pointer Size:  8
...
and indeed I get:
...
$ gdb -q -batch outputs/gdb.dwarf2/dw2-inter-cu-error-2/dw2-inter-cu-error-2

Fatal signal: Segmentation fault
...

The problem is that we're calling prepare_one_comp_unit with cu == nullptr and
comp_unit_die == nullptr here in cooked_indexer::ensure_cu_exists:
...
      cutu_reader new_reader (per_cu, per_objfile, nullptr, nullptr, false,
                              m_index_storage->get_abbrev_cache ());

      prepare_one_comp_unit (new_reader.cu, new_reader.comp_unit_die,
                             language_minimal);
...

Fix this by bailing out for various types of dummy CUs:
...
      if (new_reader.dummy_p || new_reader.comp_unit_die == nullptr
  || !new_reader.comp_unit_die->has_children)
return nullptr;
...

Also make sure in scan_attributes that this triggers a dwarf error:
...
$ gdb -q -batch dw2-inter-cu-error-2
DWARF Error: cannot follow reference to DIE at 0xd5 \
  [in module dw2-inter-cu-error-2]
...

With target board readnow, the test-case triggers an assertion failure in
follow_die_offset, so fix this by throwing the same dwarf error.

While we're at it, make the other check for dummy CUs in
cooked_indexer::ensure_cu_exists more robust by adding an intermediate test
for comp_unit_die:
...
-  if (result->dummy_p || !result->comp_unit_die->has_children)
+  if (result->dummy_p || result->comp_unit_die == nullptr
+      || !result->comp_unit_die->has_children)
     return nullptr;
...

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
9 months ago[gdb/symtab] Use expand_all_symtabs in maint expand-symtabs
Tom de Vries [Tue, 24 Sep 2024 08:32:41 +0000 (10:32 +0200)] 
[gdb/symtab] Use expand_all_symtabs in maint expand-symtabs

When issuing a command "maint expand-symtabs", maintenance_expand_symtabs is
called with regexp == nullptr, and calls expand_symtabs_matching like so:
...
      objfile->expand_symtabs_matching
       ([&] (const char *filename, bool basenames)
{
  /* KISS: Only apply the regexp to the complete file name.  */
  return (!basenames
  && (regexp == NULL || re_exec (filename)));
},
...

To expand all symtabs gdb usually uses expand_all_symtabs (used for -readnow),
but here we try to handle it in the filename_matcher argument.

Make this more similar to how gdb usually works by using expand_all_symtabs.

A previous version of the patch instead used a nullptr filename_matcher for
the regexp == nullptr case.  That approach regressed test-cases
gdb.dwarf2/dwz-unused-pu.exp and gdb.dwarf2/dw2-dummy.exp.

Tested on x86_64-linux.

9 months ago[gdb/testsuite] Add gdb.dwarf2/dwz-unused-pu.exp
Tom de Vries [Tue, 24 Sep 2024 08:32:41 +0000 (10:32 +0200)] 
[gdb/testsuite] Add gdb.dwarf2/dwz-unused-pu.exp

Add a new test-case gdb.dwarf2/dwz-unused-pu.exp that checks that a symbol
from an unused PU is not accessible.

Passes with the relevant target boards:
- unix (using the cooked index),
- readnow (using no index at all),
- cc-with-gdb-index (using .gdb_index), and
- cc-with-debug-names (using .debug_names).

Tested on x86_64-linux.

9 months ago[gdb/symtab] Don't expand non-Ada CUs for info exceptions
Tom de Vries [Tue, 24 Sep 2024 08:24:22 +0000 (10:24 +0200)] 
[gdb/symtab] Don't expand non-Ada CUs for info exceptions

I noticed when running test-case gdb.ada/info_exc.exp with glibc debug info
installed, that the "info exceptions" command that lists all Ada exceptions
also expands non-Ada CUs, which includes CUs in
/lib64/ld-linux-x86-64.so.2 and /lib64/libc.so.6.

Fix this by:
- adding a new lang_matcher parameter to the expand_symtabs_matching
  function, and
- using that new parameter in the expand_symtabs_matching call in
  ada_add_global_exceptions.

The new parameter is a hint, meaning implementations are free to ignore it and
expand CUs with any language.  This is the case for partial symtabs, I'm not
sure whether it makes sense to implement support for this there.

Conversely, when processing a CU with language C and name "<artificial>"
(as produced by GCC LTO), the CU may not really have a single language and we
should ignore the lang_matcher.  See also commit d2f67711730
("Fix 'catch exception' with -flto").

Now that we have lang_matcher available, also use it to limit name splitting
styles and symbol matchers to those applicable to the matched languages.

Without this patch we have (with a gdb build with -O0):
...
$ time gdb -q -batch -x outputs/gdb.ada/info_exc/gdb.in.1 > /dev/null
real 0m1.866s
user 0m2.089s
sys 0m0.120s
...
and with this patch we have:
...
$ time gdb -q -batch -x outputs/gdb.ada/info_exc/gdb.in.1 > /dev/null
real 0m0.469s
user 0m0.777s
sys 0m0.051s
...

Or, to put it in terms of number of CUs, we have 1853 CUs:
...
$ gdb -q -batch -readnow outputs/gdb.ada/info_exc/foo \
    -ex start \
    -ex "maint info symtabs" \
    | grep -c " name "
1853
...

Without this patch, we have:
...
$ gdb -q -batch outputs/gdb.ada/info_exc/foo \
    -ex start \
    -ex "info exceptions" \
    -ex "maint info symtabs" \
    | grep -c " name "
1393
...
so ~75% of the CUs is expanded, and with this patch we have:
...
$ gdb <same-as-above>
20
...
so ~1% of the CUs is expanded.

Tested on x86_64-linux.

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

9 months agotestsuite, threads: fix LD_LIBRARY_PATH in 'tls-sepdebug.exp'
Rohr, Stephan [Mon, 29 Jan 2024 15:05:40 +0000 (07:05 -0800)] 
testsuite, threads: fix LD_LIBRARY_PATH in 'tls-sepdebug.exp'

Some compilers (e.g. the Intel compiler) may dynamically link against
dependencies.  The test uses the 'set env' command to set the
LD_LIBRARY_PATH to a test specific value.  Update the 'set env' command
to also provide the users LD_LIBARY_PATH to gdb.

Approved-By: Tom Tromey <tom@tromey.com>
9 months agold/pdb: Handle DEBUG_S_INLINEELINES data
Mark Harmstone [Tue, 10 Sep 2024 00:21:21 +0000 (01:21 +0100)] 
ld/pdb: Handle DEBUG_S_INLINEELINES data

The DEBUG_S_INLINEELINES block in the .debug$S section records the line
numbers in a source file covered by inlined functions. It's similar to
the DEBUG_S_LINES block, but as it references LF_FUNC_ID types we also
need to parse it to remap the type numbers.

9 months agoAutomatic date update in version.in
GDB Administrator [Tue, 24 Sep 2024 00:00:35 +0000 (00:00 +0000)] 
Automatic date update in version.in

9 months agox86: Enable TLS relocation check only for ELF
H.J. Lu [Mon, 23 Sep 2024 21:02:22 +0000 (05:02 +0800)] 
x86: Enable TLS relocation check only for ELF

Since TLS relocation check is ELF specific, enable it only for ELF.

PR gas/32022
* config/tc-i386.c (x86_tls_error_type): Define only if
OBJ_MAYBE_ELF or OBJ_ELF is defined.
(x86_check_tls_relocation): Likewise.
(x86_report_tls_error): Likewise.
(i386_assemble): Check TLS relocations only if OBJ_MAYBE_ELF or
OBJ_ELF is defined.
(md_show_usage): Output -mtls-check= only if OBJ_MAYBE_ELF or
OBJ_ELF is defined.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
9 months ago[gdb/testsuite] Avoid large timeout in gdb.base/checkpoint.exp
Tom de Vries [Mon, 23 Sep 2024 20:03:56 +0000 (22:03 +0200)] 
[gdb/testsuite] Avoid large timeout in gdb.base/checkpoint.exp

I ran the testsuite in an environment simulating a stressed system, and the
only test-cases that timed out in gdb.base were gdb.base/checkpoint.exp and
gdb.base/checkpoint-ns.exp (which includes gdb.base/checkpoints.exp).

In test-case gdb.base/checkpoint.exp there's a part where the timeout is
increased with 120 seconds (in the default case that's from 10 to 130), to
accommodate for a single command creating 600+ checkpoints.

Instead, rewrite the test to present a gdb prompt each time a checkpoint is
created, for which the default timeout is sufficient.

Also ensure that the amount of checkpoints added is exactly 600 rather than
600+.

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
9 months agoAutomatically add types to Python modules
Tom Tromey [Wed, 11 Sep 2024 16:35:20 +0000 (10:35 -0600)] 
Automatically add types to Python modules

PR python/32163 points out that various types provided by gdb are not
added to the gdb module, so they aren't available for interactive
inspection.  I think this is just an oversight.

This patch fixes the problem by introducing a new helper function that
both readies the type and then adds it to the appropriate module.  The
patch also poisons PyType_Ready, the idea being to avoid this bug in
the future.

v2:
* Fixed a bug in original patch in gdb.Architecture registration
* Added regression test for the types mentioned in the bug

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32163
Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
9 months ago[gdb/testsuite] Fix timeout in gdb.fortran/info-types.exp
Tom de Vries [Mon, 23 Sep 2024 19:40:16 +0000 (21:40 +0200)] 
[gdb/testsuite] Fix timeout in gdb.fortran/info-types.exp

When running the testsuite in an enviroment that simulates a stressed system,
I ran into a timeout in test-case gdb.fortran/info-types.exp:
...
(gdb) info types^M
FAIL: gdb.fortran/info-types.exp: info types (timeout)
...

This is mainly due the presence of glibc debug info.

With it installed, I get:
...
$ time gdb -q -batch -x outputs/gdb.fortran/info-types/gdb.in.1 > /dev/null
real 0m35.969s
user 0m38.231s
sys 0m1.007s
...
and without:
...
$ time gdb -q -batch -x outputs/gdb.fortran/info-types/gdb.in.1 > /dev/null
real 0m4.782s
user 0m5.014s
sys 0m0.304s
...

Fix this by not running to main, which gets us:
...
$ time gdb -q -batch -x outputs/gdb.fortran/info-types/gdb.in.1 > /dev/null
real 0m0.808s
user 0m0.789s
sys 0m0.137s
...

Likewise in gdb.mi/mi-sym-info.exp and gdb.mi/mi-complete.exp.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
9 months agogdb: update comment in code_breakpoint::re_set_default
Andrew Burgess [Mon, 23 Sep 2024 13:30:44 +0000 (14:30 +0100)] 
gdb: update comment in code_breakpoint::re_set_default

Spotted a comment in code_breakpoint::re_set_default that was added in
commit:

  commit 6cce025114ccd0f53cc552fde12b6329596c6c65
  Date:   Fri Mar 3 19:03:15 2023 +0000

      gdb: only insert thread-specific breakpoints in the relevant inferior

that was incorrect.  The comment was not updated to take inferior
specific breakpoints into account.

This commit just updates the comment, there's no user visible changes
after this commit.

9 months agold/PE: enable secrel testcases also for 64-bit Cygwin
Jan Beulich [Mon, 23 Sep 2024 13:27:02 +0000 (15:27 +0200)] 
ld/PE: enable secrel testcases also for 64-bit Cygwin

Plus the others that are grouped there.

9 months agold/PE: no base relocs for section (relative) ones
Jan Beulich [Mon, 23 Sep 2024 13:26:29 +0000 (15:26 +0200)] 
ld/PE: no base relocs for section (relative) ones

Even more so than image relative (RVA) relocations, section relative
ones as well as section ones should not have base relocations created in
the final PE image. Reportedly section relative relocations will want
using for TLS support in the (Windows) compiler.

While there also correct the names for two of the "image base" relocs.

9 months agoLD: Document use of SOURCE_DATE_EPOCH in Environment section
Nick Clifton [Mon, 23 Sep 2024 13:22:57 +0000 (14:22 +0100)] 
LD: Document use of SOURCE_DATE_EPOCH in Environment section

9 months agoFix compile time error introduced by d774bf9b3623239a1cfa729afcf048a15da657d3 for...
Nick Clifton [Mon, 23 Sep 2024 11:27:29 +0000 (12:27 +0100)] 
Fix compile time error introduced by d774bf9b3623239a1cfa729afcf048a15da657d3 for non-ELF x86 targets

9 months ago[gdb/testsuite] Fix failure in gdb.threads/signal-sigtrap.exp
Tom de Vries [Mon, 23 Sep 2024 07:53:54 +0000 (09:53 +0200)] 
[gdb/testsuite] Fix failure in gdb.threads/signal-sigtrap.exp

The test-case gdb.threads/signal-sigtrap.exp:
- installs a signal handler called sigtrap_handler for SIGTRAP,
- sets a breakpoint on sigtrap_handler, and
- expects the breakpoint to trigger after issuing "signal SIGTRAP".

Usually, that happens indeed:
...
(gdb) signal SIGTRAP^M
Continuing with signal SIGTRAP.^M
^M
Thread 1 "signal-sigtrap" hit Breakpoint 2, sigtrap_handler (sig=5)^M
28      }^M
(gdb) PASS: $exp: sigtrap thread 1: signal SIGTRAP reaches handler
...

Occasionally, I run into this failure on openSUSE Tumbleweed:
...
(gdb) signal SIGTRAP^M
Continuing with signal SIGTRAP.^M
^M
Thread 1 "signal-sigtrap" received signal SIGTRAP, Trace/breakpoint trap.^M
__pthread_create_2_1 () at pthread_create.c:843^M
(gdb) FAIL: $exp: sigtrap thread 1: signal SIGTRAP reaches handler
...

AFAIU, the problem is in the situation that is setup before issuing that
command, by running to a breakpoint in thread_function:
...
void *thread_function (void *arg) {
  return NULL;
}
int main (void) {
  pthread_t child_thread;
  signal (SIGTRAP, sigtrap_handler);
  pthread_create (&child_thread, NULL, thread_function, NULL);
  pthread_join (child_thread, NULL);
  return 0;
}
...

In the passing case, thread 2 is stopped in thread_function, and thread 1 is
stopped somewhere in pthread_join:
...
(gdb) info threads^M
  Id   Target Id                                          Frame ^M
  1    Thread ... (LWP ...) "signal-sigtrap" __futex_abstimed_wait_common64 ()
* 2    Thread ... (LWP ...) "signal-sigtrap" thread_function ()
...

In the failing case, thread 2 is stopped in thread_function, but thread 1 is
stopped somewhere in pthread_create:
...
(gdb) info threads^M
  Id   Target Id                                          Frame ^M
  1    Thread ... (LWP ...) "signal-sigtrap" __GI___clone3 ()
* 2    Thread ... (LWP ...) "signal-sigtrap" thread_function ()
...

What I think happens is that pthread_create blocks SIGTRAP at some point, and
if the "signal SIGTRAP" command is issued while that is the case, the signal
becomes pending and consequently there's no longer a guarantee that the signal
will be delivered to the inferior.

Instead the signal will be handled by gdb like this:
...
(gdb) info signals SIGTRAP
Signal        Stop Print Pass to program Description
SIGTRAP       Yes Yes No Trace/breakpoint trap
...

Fix this by adding a barrier that ensures that pthread_create is done before
we issue the "signal SIGTRAP" command.

Likewise in test-case gdb.threads/signal-command-handle-nopass.exp.

Using the fixed test-case, I tested my theory by explicitly blocking SIGTRAP:
...
+  sigset_t old_ss, new_ss;
+  sigemptyset (&new_ss);
+  sigaddset (&new_ss, SIGTRAP);
+  sigprocmask (SIG_BLOCK, &new_ss, &old_ss);
+
   /* Make sure that pthread_create is done once the breakpoint on
      thread_function triggers.  */
   pthread_barrier_wait (&barrier);

   pthread_join (child_thread, NULL);
+  sigprocmask (SIG_SETMASK, &old_ss, NULL);
...
and managed to reproduce the same failure:
...
(gdb) signal SIGTRAP^M
Continuing with signal SIGTRAP.^M
[Thread 0x7ffff7c00700 (LWP 13254) exited]^M
^M
Thread 1 "signal-sigtrap" received signal SIGTRAP, Trace/breakpoint trap.^M
0x00007ffff7c80056 in __GI___sigprocmask () sigprocmask.c:39^M
(gdb) FAIL: $exp: sigtrap thread 1: signal SIGTRAP reaches handler
...

Tested on x86_64-linux.

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

9 months ago[gdb/testsuite] Fix gdb.base/return.exp on arm-linux
Tom de Vries [Mon, 23 Sep 2024 07:47:26 +0000 (09:47 +0200)] 
[gdb/testsuite] Fix gdb.base/return.exp on arm-linux

After doing pre-commit testing of some patch on arm-linux, the Linaro CI
reported:
...
FAIL: 1 regressions: 1 improvements

regressions.sum:
=== gdb tests ===

Running gdb:gdb.base/return.exp ...
ERROR: no fileid for ccd235fdc9bf

improvements.sum:
=== gdb tests ===

Running gdb:gdb.base/return.exp ...
ERROR: no fileid for 017e9b314c5a
...

The problem is the call to allow_float_test.  It calls gdb_exit (for arm-linux
only), and consequently kills the gdb instance setup by prepare_for_testing:
...
if { [prepare_for_testing "failed to prepare" "return"] } {
     return -1
}

set allow_float_test [allow_float_test]
...

Fix this by moving the call to allow_float_test to before prepare_for_testing.

Tested on arm-linux and x86_64-linux.

9 months ago[gdb/testsuite] Make parse_args error out on remaining args
Tom de Vries [Mon, 23 Sep 2024 07:34:48 +0000 (09:34 +0200)] 
[gdb/testsuite] Make parse_args error out on remaining args

I noticed that introducing a typo here in gdb.mi/mi-breakpoint-changed.exp:
...
     set bp_re [mi_make_breakpoint \
-    -number $bp_nr \
+    -nunber $bp_nr \
     -type dprintf \
     -func marker \
     -script [string_to_regexp {["printf \"arg\" \""]}]]
...
didn't make the test fail.

Proc mi_make_breakpoint uses parse_args, but does not check the remaining args
as parse_args suggests:
...
proc parse_args { argset } {
    parse_list 2 args $argset "-" false

    # The remaining args should be checked to see that they match the
    # number of items expected to be passed into the procedure
}
...

We could add the missing check in mi_make_breakpoint, but I think the problem
is likely to occur again because the name parse_args does not suggest that
further action is required.

Fix this instead by:
- copying proc parse_args to new proc parse_some_args,
- adding new proc check_no_args_left, and
- calling check_no_args_left in parse_args.

Also be more strict in a few places where we do lassign for remaining args:
...
    lassign $args a b
...

There may be more arguments left in $args, so check that that's not the case
using check_no_args_left:
...
    set args [lassign $args a b]
    check_no_args_left
...

Fix a few test-cases that trigger on the stricter checking.

Tested on x86_64-linux.

Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
PR testsuite/32129
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32129

9 months ago[gdb/testsuite] Fix gdb.base/empty-host-env-vars.exp
Tom de Vries [Mon, 23 Sep 2024 05:57:49 +0000 (07:57 +0200)] 
[gdb/testsuite] Fix gdb.base/empty-host-env-vars.exp

On aarch64-linux (debian testing) with test-case
gdb.base/empty-host-env-vars.exp I ran into:
...
(gdb) show index-cache directory^M
The directory of the index cache is "/home/linux/.cache/gdb".^M
(gdb) FAIL: $exp: env_var_name=HOME: show index-cache directory
...

Without changing any environment variables, the value of the index-cache dir
is:
...
$ gdb -q -batch -ex "show index-cache directory"
The directory of the index cache is "/home/linux/.cache/gdb".
...
and the expectation of the test-case is that setting HOME to empty will
produce an empty dir, but what it actually produces is:
...
$ HOME= gdb -q -batch -ex "show index-cache directory"
The directory of the index cache is "/home/linux/.cache/gdb".
...

There's nothing wrong with that behaviour, the dir is simply constructed using
XDG_CACHE_HOME which happens to be explictly set to its default value
$HOME/.cache [1]:
...
$ echo $XDG_CACHE_HOME
/home/linux/.cache
...
and indeed also setting that variable to empty gets us the expected empty dir:
...
$ XDG_CACHE_HOME= HOME= gdb -q -batch -ex "show index-cache directory"
gdb: warning: Couldn't determine a path for the index cache directory.
The directory of the index cache is "".
...

Furthermore, the test-case assumption that setting variables to empty either
produces the original dir or an empty dir is incorrect.

Say that XDG_CACHE_HOME has a non-default value:
...
$ echo $XDG_CACHE_HOME
/home/linux/my-xdg-cache-home
$ gdb -q -batch -ex "show index-cache directory"
The directory of the index cache is "/home/linux/my-xdg-cache-home/gdb".
...
then setting that variable to empty:
...
$ XDG_CACHE_HOME= gdb -q -batch -ex "show index-cache directory"
The directory of the index cache is "/home/linux/.cache/gdb".
...
does change the value of the dir.

Fix this by making the test-case less specific.

While we're at it, factor out regexps re_pre and re_post to make regexps more
readable, and use string_to_regexp to reduce quoting.

Tested on aarch64-linux.

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

[1] https://specifications.freedesktop.org/basedir-spec/latest/index.html#variables

9 months ago[gdb/testsuite] Fix gdb.base/attach-deleted-exec.exp with NFS
Tom de Vries [Mon, 23 Sep 2024 05:53:20 +0000 (07:53 +0200)] 
[gdb/testsuite] Fix gdb.base/attach-deleted-exec.exp with NFS

With test-case gdb.base/attach-deleted-exec.exp I ran into:
...
(gdb) attach 121552^M
Attaching to process 121552^M
Reading symbols .../attach-deleted-exec/.nfs00000000044ff2ef00000086...^M
Reading symbols from /lib64/libm.so.6...^M
(No debugging symbols found in /lib64/libm.so.6)^M
Reading symbols from /lib64/libc.so.6...^M
(No debugging symbols found in /lib64/libc.so.6)^M
Reading symbols from /lib64/ld64.so.2...^M
(No debugging symbols found in /lib64/ld64.so.2)^M
0x00007fff947cc838 in clock_nanosleep@@GLIBC_2.17 () from /lib64/libc.so.6^M
(gdb) FAIL: $exp: attach to process with deleted executable
....

The .nfs file indicates:
- that the file has been removed on the NFS server, and
- that the file is still open on the NFS client.

Fix this by detecting this situation, and declaring the test for filename
/proc/PID/exe unsupported.

Tested on:
- x86_64-linux (setup without NFS)
- ppc64le-linux (setup with NFS)

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

9 months ago[gdb/testsuite] Fix gdb.trace/entry-values.exp on riscv64-linux
Tom de Vries [Mon, 23 Sep 2024 05:50:16 +0000 (07:50 +0200)] 
[gdb/testsuite] Fix gdb.trace/entry-values.exp on riscv64-linux

On riscv64-linux, with test-case gdb.trace/entry-values.exp I run into:
...
(gdb) disassemble bar^M
Dump of assembler code for function bar:^M
   0x0000000000000646 <+0>:     addi    sp,sp,-48^M
   0x0000000000000648 <+2>:     sd      ra,40(sp)^M
   0x000000000000064a <+4>:     sd      s0,32(sp)^M
   0x000000000000064c <+6>:     addi    s0,sp,48^M
   0x000000000000064e <+8>:     mv      a5,a0^M
   0x0000000000000650 <+10>:    sw      a5,-36(s0)^M
   0x0000000000000654 <+14>:    li      a5,2^M
   0x0000000000000656 <+16>:    sw      a5,-20(s0)^M
   0x000000000000065a <+20>:    lw      a4,-20(s0)^M
   0x000000000000065e <+24>:    lw      a5,-36(s0)^M
   0x0000000000000662 <+28>:    mv      a1,a4^M
   0x0000000000000664 <+30>:    mv      a0,a5^M
   0x0000000000000666 <+32>:    jal     0x628 <foo>^M
   0x000000000000066a <+36>:    mv      a5,a0^M
   0x000000000000066c <+38>:    mv      a0,a5^M
   0x000000000000066e <+40>:    ld      ra,40(sp)^M
   0x0000000000000670 <+42>:    ld      s0,32(sp)^M
   0x0000000000000672 <+44>:    addi    sp,sp,48^M
   0x0000000000000674 <+46>:    ret^M
End of assembler dump.^M
(gdb) FAIL: gdb.trace/entry-values.exp: disassemble bar
FAIL: gdb.trace/entry-values.exp: find the call or branch instruction offset in bar
...

Fix this by setting call_insn to jal for riscv64.

Tested on riscv64-linux and x86_64-linux.

9 months ago[gdb/testsuite] Fix timeout in gdb.mi/mi-multi-commands.exp
Tom de Vries [Mon, 23 Sep 2024 05:45:54 +0000 (07:45 +0200)] 
[gdb/testsuite] Fix timeout in gdb.mi/mi-multi-commands.exp

On aarch64-linux, with test-case gdb.mi/mi-multi-commands.exp once in a while
I run into (edited for readability):
...
(gdb) ^M
<LOTS-OF-SPACES>-data-evaluate-expression $a^M
-data-evaluate-^done,value="\"FIRST COMMAND\""^M
expression $b(gdb) ^M
^M
^done,value="\"TEST COMPLETE\""^M
(gdb) ^M
PASS: $exp: args=: look for first command output, command length 236
FAIL: $exp: args=: look for second command output, command length 236 (timeout)
...

This is more likely to trigger when running the test-case using
taskset -c <cpu> (where in a big.little setup we pick a little cpu).

The setup here is that the test-case issues these two commands at once:
...
-data-evaluate-expression $a
-data-evaluate-expression $b
...
where the length of the first command is artificially increased by prefixing
it with spaces, show as <LOTS-OF-SPACES> above.

What happens is that gdb, after parsing the first command, executes it.
Then the output of the first command intermixes with the echoing of the second
command, which produces this line containing the first prompt:
...
expression $b(gdb) ^M
...
which doesn't match the \r\n prefix of the regexp supposed to consume the
first prompt:
...
           -re "\r\n$mi_gdb_prompt" {
...

Fix this by dropping the \r\n prefix.

Tested on aarch64-linux.

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

9 months agoAutomatic date update in version.in
GDB Administrator [Mon, 23 Sep 2024 00:00:12 +0000 (00:00 +0000)] 
Automatic date update in version.in

9 months agox86: Turn PLT32 to PC32 only for PC-relative relocations
H.J. Lu [Sun, 22 Sep 2024 09:06:45 +0000 (17:06 +0800)] 
x86: Turn PLT32 to PC32 only for PC-relative relocations

commit 292676c15a615b5a95bede9ee91004d3f7ee7dfd
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Feb 13 13:44:17 2020 -0800

    x86: Resolve PLT32 reloc aganst local symbol to section

resolved PLT32 relocation against local symbol to section and

commit 2585b7a5ce5830e60a089aa2316a329558902f0c
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sun Jul 19 06:51:19 2020 -0700

    x86: Change PLT32 reloc against section to PC32

turned PLT32 relocation against section into PC32 relocation.  But these
transformations are valid only for PC-relative relocations.  Add fx_pcrel
check for PC-relative relocations when performing these transformations
to keep PLT32 relocation in `movq $foo@PLT, %rax`.

gas/

PR gas/32196
* config/tc-i386.c (tc_i386_fix_adjustable): Return fixP->fx_pcrel
for PLT32 relocations.
(i386_validate_fix): Turn PLT32 relocation into PC32 relocation
only if fixp->fx_pcrel is set.
* testsuite/gas/i386/reloc32.d: Updated.
* testsuite/gas/i386/reloc64.d: Likewise.
* testsuite/gas/i386/reloc32.s: Add PR gas/32196 test.
* testsuite/gas/i386/reloc64.s: Likewise.

ld/

PR gas/32196
* testsuite/ld-x86-64/plt3.s: New file.
* testsuite/ld-x86-64/x86-64.exp: Run plt3.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
9 months agoAutomatic date update in version.in
GDB Administrator [Sun, 22 Sep 2024 00:00:09 +0000 (00:00 +0000)] 
Automatic date update in version.in

9 months ago[gdb/testsuite] Limit xfail in gdb.ada/call_pn.exp
Tom de Vries [Sat, 21 Sep 2024 04:12:40 +0000 (06:12 +0200)] 
[gdb/testsuite] Limit xfail in gdb.ada/call_pn.exp

Test-case gdb.ada/call_pn.exp contains an unconditional xfail, which is only
necessary for gcc 8 and 9.

Fix this by limiting the xfail to those releases.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
9 months ago[gdb/testsuite] Fix timeout in gdb.ada/call_pn.exp
Tom de Vries [Sat, 21 Sep 2024 04:12:40 +0000 (06:12 +0200)] 
[gdb/testsuite] Fix timeout in gdb.ada/call_pn.exp

With test-case gdb.ada/call_pn.exp and glibc debug info installed, I ran into
this timeout:
...
(gdb) maint expand-symtabs^M
FAIL: gdb.ada/call_pn.exp: maint expand-symtabs (timeout)
...

The timeout was related to running the cpu at base frequency of 400Mhz instead
of boost frequency of 3.5Ghz (efficiency core) or 4.7Ghz (performance core).

But when investigating the test-case I realized that the maint expand-symtabs
could be limited to the source files, so use that to speed up the test-case.

Tested on x86_64-linux.

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

9 months ago[gdb/testsuite] Drop -readnow in three gdb.dwarf2 test-cases
Tom de Vries [Sat, 21 Sep 2024 03:55:18 +0000 (05:55 +0200)] 
[gdb/testsuite] Drop -readnow in three gdb.dwarf2 test-cases

When running the testsuite in an enviroment simulating a stressed system, I
ran into timeouts in three test-cases in gdb.dwarf2:
- gdb.dwarf2/count.exp,
- gdb.dwarf2/implptrconst.exp, and
- gdb.dwarf2/implptrpiece.exp.

In all three cases, -readnow is used which results in symtabs being expanded for
the executable, /lib64/libc.so.6 and /lib64/ld-linux-x86-64.so.2.

We could address this by limiting the scope of -readnow to the executable, but
after reviewing the test-cases there doesn't seem to be a clear reason to use
-readnow.

Fix this by dropping the -readnow.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>