]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
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>
9 months agoAutomatic date update in version.in
GDB Administrator [Sat, 21 Sep 2024 00:00:11 +0000 (00:00 +0000)] 
Automatic date update in version.in

9 months agox86: Add tls check in gas
Cui, Lili [Thu, 19 Sep 2024 06:38:16 +0000 (14:38 +0800)] 
x86: Add tls check in gas

Assembler shouldn't accept invalid TLS instructions, TLS relocations
can only be used with specific instructions as specified in TLS psABI
and linker issues an error when TLS relocations are used with wrong
instructions or format. Since it is inconvenient for gcc to rely on
linker to report errors, adding TLS check in the assembler stage so
that gcc can know TLS errors earlier.

gas/ChangeLog:

        PR gas/32022
        * config.in: Regenerate.
        * config/tc-i386.c
        *(enum x86_tls_error_type): New.
        *(struct _i386_insn): Added has_gotrel to indicate whether TLS
relocations need to be checked.
        (x86_check_tls_relocation): Added a new function to check TLS
relocation.
        (x86_report_tls_error): Created a new function to report TLS error.
        (i386_assemble): Handle x86_check_tls_relocation.
        (lex_got): Set i.has_gotrel.
        (OPTION_MTLS_CHECK): Added a new option to contrl TLS check.
        (struct option): Ditto.
        (md_parse_option): Ditto.
        (md_show_usage): Ditto.
        * configure.ac: Added a new option to check TLS relocation by
default.
        * configure: Regenerated.
        * doc/c-i386.texi: Document -mtls-check=.
        * testsuite/gas/i386/i386.exp: Added new tests.
        * testsuite/gas/i386/ilp32/ilp32.exp: Ditto.
        * testsuite/gas/i386/ilp32/reloc64.d: Disable TLS check for it.
        * testsuite/gas/i386/ilp32/x32-tls.d: Ditto.
        * testsuite/gas/i386/inval-tls.l: Added more test cases.
        * testsuite/gas/i386/inval-tls.s: Ditto.
        * testsuite/gas/i386/reloc32.d: Disable TLS check for it.
        * testsuite/gas/i386/reloc64.d: Ditto.
        * testsuite/gas/i386/x86-64-inval-tls.l: Added more test cases.
        * testsuite/gas/i386/x86-64-inval-tls.s: Ditto.
        * testsuite/gas/i386/x86-64.exp: Added new tests.
        * testsuite/gas/i386/ilp32/x32-inval-tls.l: New test.
        * testsuite/gas/i386/ilp32/x32-inval-tls.s: Ditto.
        * testsuite/gas/i386/ilp32/x86-64-tls.d: Ditto.
        * testsuite/gas/i386/tls.d: Ditto.
        * testsuite/gas/i386/tls.s: Ditto.
        * testsuite/gas/i386/x86-64-tls.d: Ditto.
        * testsuite/gas/i386/x86-64-tls.s: Ditto.

ld/ChangeLog:

        PR gas/32022
        * testsuite/ld-i386/tlsgdesc1.d: Disable TLS check for it.
        * testsuite/ld-i386/tlsgdesc2.d: Ditto.
        * testsuite/ld-i386/tlsie2.d: Ditto.
        * testsuite/ld-i386/tlsie3.d: Ditto.
        * testsuite/ld-i386/tlsie4.d: Ditto.
        * testsuite/ld-i386/tlsie5.d: Ditto.
        * testsuite/ld-i386/tlsgdesc3.d: Ditto.
        * testsuite/ld-x86-64/tlsdesc3.d: Ditto.
        * testsuite/ld-x86-64/tlsdesc4.d: Ditto.
        * testsuite/ld-x86-64/tlsie2.d: Ditto.
        * testsuite/ld-x86-64/tlsie3.d: Ditto.
        * testsuite/ld-x86-64/tlsie5.d: Ditto.
        * testsuite/ld-x86-64/tlsdesc5.d: Ditto.

9 months agold: Use --no-rosegment to ld for PR ld/22393 tests
H.J. Lu [Fri, 20 Sep 2024 19:44:22 +0000 (03:44 +0800)] 
ld: Use --no-rosegment to ld for PR ld/22393 tests

The commit

bf6d7087de0 ld: Move the .note.build-id section to near the start of the memory map

moves the .note.build-id section before text sections.  When --rosegment
and -z separate-code are used together, the .note.gnu.property section
is placed between the .note.build-id section and text sections in the
same PT_LOAD segment by orphan placement.  Pass --no-rosegment to ld for
PR ld/22393 tests to avoid linker test failures.

PR ld/32190
* testsuite/ld-elf/pr22393-2a.rd: Pass --no-rosegment to ld.
* testsuite/ld-elf/pr22393-2b.rd: Likewise.
* testsuite/ld-elf/shared.exp: Pass --no-rosegment to ld when
building pr22393-2 tests.
* testsuite/ld-x86-64/pr22393-3a.rd: Pass --no-rosegment to ld.
* testsuite/ld-x86-64/pr22393-3b.rd: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Pass --no-rosegment to ld when
building pr22393-3 tests.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
9 months agogdb: fully separate coff and elf reading from dbx
Guinevere Larsen [Tue, 10 Sep 2024 17:42:30 +0000 (14:42 -0300)] 
gdb: fully separate coff and elf reading from dbx

With the previous commits, the only thing entangling elf and coff file
reading with dbx file reading is the functions
{elf|coff}stab_build_psymtabs, defined in dbxread.c. These functions
depend on dbx_symfile_read.

To solve this, I renamed read_stabs_symtab to read_stabs_symtab_1, and
created a function with the original name that does what
dbx_symfile_read used to do.

This way, dbx_symfile_read can just call read_stabs_symtab, and the elf
and coff psymtab builders can also call it directly, fully disentangling
the readers, which would allow us to selectively not compile dbxread in
the future.

Approved-By: Tom Tromey <tom@tromey.com>
9 months agogdb: Move read_dbx_symtab to stabsread, and rename to read_stabs_symtab
Guinevere Larsen [Tue, 17 Sep 2024 13:16:30 +0000 (10:16 -0300)] 
gdb: Move read_dbx_symtab to stabsread, and rename to read_stabs_symtab

Despite the name, read_dbx_symtab is not only used for the dbx file
format (also called the aout format). It is used by elf and coff
implicitly as well. So I think it makes more sense to have this function
in the generic stabsread file, so that reading elf files or coff files
depends less on GDB's ability to read dbx files.

There were 11 static functions in dbxread that were onlyl helper
functions, they were moved and kept as static in stabsread.c. Notably,
dbx_read_symtab - which is installed as a callback on legacy_psymtab
for aout, elf and coff at least - has been moved to stabsread.c and
renamed as well; the function that is specific to aout is
dbx_symfile_read, and that hasn't been moved.

Some macros had to be moved as well, but since they are still used
in dbxread, they were moved to the .h file that the struct symloc
is declared, so anyone can properly use the struct.

Approved-By: Tom Tromey <tom@tromey.com>
9 months agogdb: Move dbx_end_psymtab to stabsread, and rename to stabs_end_psymtab
Guinevere Larsen [Mon, 9 Sep 2024 18:06:29 +0000 (15:06 -0300)] 
gdb: Move dbx_end_psymtab to stabsread, and rename to stabs_end_psymtab

This function is used by multiple stabs readers (even if not all), and
the comment in stabsread.h even acknowledges it. I believe that the
comment is incorrect in saying that the function should be in dbxread
because not everyone uses it. If any one reader other than dbx uses
it, the function should be in stabsread, in my opinion.

This commit makes also renames the function to stabs_end_psymtab since,
again, this is not specific to dbx/aout format.

struct symloc had to be moved because stabs_end_psymtab dereferences
symloc objects, so stabsread.c must be aware of the full struct.

Approved-By: Tom Tromey <tom@tromey.com>
9 months agogdb: Move process_one_symbol to stabsread.c
Guinevere Larsen [Mon, 9 Sep 2024 15:56:42 +0000 (12:56 -0300)] 
gdb: Move process_one_symbol to stabsread.c

The function process_one_symbol was defined in the file dbxread.c, but
this function is used by all file formats that handle stabs debug
information. It makes much more sense for it to be in the stabsread.c
file instead.

To move that function, many other static functions had to be moved from
dbxread. A few were only used by process_one_symbol, so they're still
static, but most were used by other functions still in dbxread, so they
are being exported by stabsread.h

Finally, the registry entry has been moved as well, seeing as it was
already exported by gdb-stabs.h, and stabsread.c will need it to
properly use the newly added function.

With this change, reading mdebug files is totally independent of reading
dbx.

Approved-By: Tom Tromey <tom@tromey.com>
9 months agogdb: Make dbxread rely less on global variables
Guinevere Larsen [Fri, 6 Sep 2024 17:47:44 +0000 (14:47 -0300)] 
gdb: Make dbxread rely less on global variables

The file dbxread.c, which is responsible for reading stabs information
for multiple file formats, relies heavily on setting and using global
variables over the course of reading symbols.

Future patches aim to make stabs reading more file format independent,
and this patch starts that change by introducing a stabs_context struct,
that will hold all the relevant variables. This context struct is saved
on the registry key inside the objfile being read. Some of those global
variables have been deemed irrelevant:
* dbxread_objfile - Since we're saving in an objfile, this is redundant
* symfile_bfd - It is trivial to get the bfd pointer from the objfile,
  so also unnecessary
* string_table_offset - was never initialized, just used to set a value.
  That usage was substituted by a hardcoded 0
* next_file_string_table_offset - was only used by read_dbx_symtab, so
  it was turned into a local variable there.

As I was moving variables, I also couldn't think of a good reason for
the bincl_list to be a pointer, so it was changed to just be an
std::vector.

Approved-By: Tom Tromey <tom@tromey.com>
9 months agogdb/testsuite: rework bp-cond-failure to not depend on inlining
Guinevere Larsen [Fri, 2 Aug 2024 11:46:28 +0000 (08:46 -0300)] 
gdb/testsuite: rework bp-cond-failure to not depend on inlining

The test gdb.base/bp-cond-failure is implicitly expecting that the
function foo will be inlined twice and gdb will be able to find 2
locations to place a breakpoint. When clang is used, gdb only finds
one location which causes the test to fail. Since the test is not
worried about handling breakpoints on inlined functions, but rather on
the format of the message on a breakpoint condition fail, this seems
like a false fail report.

This commit reworks the test to be in c++, and uses function overloading
to ensure that 2 locations will always be found. Empirical testing
showed that, for clang, we will land on location 2 with the currest exp
commands, no matter the order of the functions declared, whereas for gcc
it depends on the order that functions were declared, so they are
ordered to always land on the second location, this way we are able to
hardcode it and check for it.

Reviewed-by: Keith Seitz <keiths@redhat.com>
Approved-By: Tom Tromey <tom@tromey.com>
9 months agold: Change -z one-rosegment to --rosegment in comments
H.J. Lu [Fri, 20 Sep 2024 03:00:59 +0000 (11:00 +0800)] 
ld: Change -z one-rosegment to --rosegment in comments

There is no such linker command-line option, -z one-rosegment.  Replace
it with --rosegment in comments.

* genscripts.sh: Change -z one-rosegment to --rosegment in
comments.

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

9 months agox86-64: Disable PIE on PR gas/32189 test
H.J. Lu [Thu, 19 Sep 2024 23:15:02 +0000 (07:15 +0800)] 
x86-64: Disable PIE on PR gas/32189 test

Disable PIE on PR gas/32189 test, which contains the non-PIE assembly
source, to support GCC defaulted to PIE.

PR gas/32189
* testsuite/ld-x86-64/x86-64.exp: Pass $NOPIE_LDFLAGS to linker
on PR gas/32189 test.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
9 months agox86-64: Never make R_X86_64_GOT64 section relative
H.J. Lu [Thu, 19 Sep 2024 21:37:04 +0000 (05:37 +0800)] 
x86-64: Never make R_X86_64_GOT64 section relative

R_X86_64_GOT64 relocation should never be made section relative.  Change
tc_i386_fix_adjustable to return 0 for BFD_RELOC_X86_64_GOT64.

gas/

PR gas/32189
* config/tc-i386.c (tc_i386_fix_adjustable): Return 0 for
BFD_RELOC_X86_64_GOT64.
* testsuite/gas/i386/reloc64.d: Updated.
* testsuite/gas/i386/reloc64.s: Add more tests for R_X86_64_GOT64
and R_X86_64_GOTOFF64.

ld/

PR gas/32189
* testsuite/ld-x86-64/x86-64.exp: Run PR gas/32189 test.
* testsuite/ld-x86-64/pr32189.s: New file.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
9 months agogdb/MAINTAINERS: update my email address
Guinevere Larsen [Thu, 19 Sep 2024 15:10:34 +0000 (12:10 -0300)] 
gdb/MAINTAINERS: update my email address

Sync the maintainers file with my new email address

9 months agold: Move the .note.build-id section to near the start of the memory map.
Nick Clifton [Thu, 19 Sep 2024 15:45:30 +0000 (16:45 +0100)] 
ld: Move the .note.build-id section to near the start of the memory map.

This helps GDB to locate the debug information associated with a core dump.
Core dumps include the first page of an executable's image, and if this
page include the .note.build-id section then GDB can find it and then track
down a debug info file for that build-id.

9 months agoFix 32096 UBSAN issues in gprofng
Vladimir Mezentsev [Wed, 18 Sep 2024 04:36:29 +0000 (21:36 -0700)] 
Fix 32096 UBSAN issues in gprofng

Fixed UBSAN runtime errors such as:
 - member call on address which does not point to an object of type 'Vector'
 - load of misaligned address 0x623e5a670173 for type 'int', which requires 4 byte alignment

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

PR gprofng/32096
* libcollector/unwind.c: Fix UBSAN runtime errors.
* src/CallStack.cc (add_stack_java, add_stack_java_epilogue):
Change argument type to Vector<Histable*>*.
* src/Experiment.cc (update_ts_in_maps): Change variable type.
* src/Experiment.h: Change field type to Vector<Histable*>*.

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

9 months agoLoongArch: Add elfNN_loongarch_mkobject to initialize LoongArch tdata
Xin Wang [Fri, 6 Sep 2024 01:00:12 +0000 (09:00 +0800)] 
LoongArch: Add elfNN_loongarch_mkobject to initialize LoongArch tdata

LoongArch: Add elfNN_loongarch_mkobject to initialize LoongArch tdata.

9 months agox86/APX: Don't promote AVX/AVX2 instructions out of APX spec
H.J. Lu [Sun, 15 Sep 2024 23:11:39 +0000 (07:11 +0800)] 
x86/APX: Don't promote AVX/AVX2 instructions out of APX spec

V{BROADCAST,EXTRACT,INSERT}{F,I}128 and VROUND{P,S}{S,D} aren't promoted
to support EGPR in APX spec.  Don't promote them out of APX spec.  This
commit effectively reverted:

ec3babb8c10 x86/APX: V{BROADCAST,EXTRACT,INSERT}{F,I}128 can also be expressed
5a635f1f59a x86/APX: VROUND{P,S}{S,D} encodings require AVX512{F,VL}
eea4357967b x86/APX: VROUND{P,S}{S,D} can generally be encoded

gas/

PR gas/32171
* testsuite/gas/i386/x86-64-apx-egpr-promote-inval.s: Add
V{BROADCAST,EXTRACT,INSERT}{F,I}128 tests with EGPR.
* testsuite/gas/i386/x86-64-apx-evex-promoted.s: Remove
V{BROADCAST,EXTRACT,INSERT}{F,I}128 and VROUND{P,S}{S,D} tests
with EGPR.
* testsuite/gas/i386/x86-64-apx-egpr-inval.l: Updated.
* testsuite/gas/i386/x86-64-apx-egpr-promote-inval.l: Likewise.
* testsuite/gas/i386/x86-64-apx-evex-promoted-intel.d: Likewise.
* testsuite/gas/i386/x86-64-apx-evex-promoted-wig.d: Likewise.
* testsuite/gas/i386/x86-64-apx-evex-promoted.d: Likewise.

opcodes/

PR gas/32171
* i386-opc.tbl: Remove V{BROADCAST,EXTRACT,INSERT}{F,I}128 and
VROUND{P,S}{S,D} entries with EGPR.
* i386-tbl.h: Regenerated.

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

9 months agogdb/testsuite: skip gdb.mi/dw2-ref-missing-frame.exp with clang
Guinevere Larsen [Tue, 23 Jul 2024 19:37:48 +0000 (16:37 -0300)] 
gdb/testsuite: skip gdb.mi/dw2-ref-missing-frame.exp with clang

The test gdb.mi/dw2-ref-missing-frame.exp uses the old-school way to set
debug information by hand, using a .S file and assembly labels to get
addresses. Unfortunately, clang will always re-arrange the global labels
to be side by side, making high and low PC for CUs and functions be the
same, and thus they will all be empty ranges. This makes the test fail,
since we never technically enter the functions that we want to check.

This commit skips that test when using clang. If we ever port this test
to use the dwarf assembler, we can reenable it with clang.

Approved-By: Tom Tromey <tom@tromey.com>
9 months agogdb/testsuite: fix gdb.mi/mi-var-cp.exp with clang
Guinevere Larsen [Tue, 23 Jul 2024 17:36:20 +0000 (14:36 -0300)] 
gdb/testsuite: fix gdb.mi/mi-var-cp.exp with clang

The inline tests in gdb.mi/mi-var-cp.cc were failing when using clang to
run the test. This happened because inline tests want to step past the C
statements and then run the TCL tests, but in mi-var-cp.cc the statement
to be stepped past is "return s2.i;". Since clang links the epilogue
information to the return statement, not the closing brace,
single-stepping past return had us exiting the function - which made the
expressions invalid.

This commit fixes this by making the function have 2 C statements, and
the return one be after all inline tests, so we know GDB won't leave the
function before running the create_varobj tests.

Approved-By: Tom Tromey <tom@tromey.com>
9 months agogdb/testsuite: fix gdb.mi/mi-catch-cpp-exceptions.exp with clang
Guinevere Larsen [Tue, 23 Jul 2024 16:56:17 +0000 (13:56 -0300)] 
gdb/testsuite: fix gdb.mi/mi-catch-cpp-exceptions.exp with clang

Clang adds line table information for a try/catch block differently to
gcc. Instead of linking the instructions related to __cxa_begin_catch to
the line containing the "catch" statement in the source code, it links
to the closing brace of the try block.

This was causing gdb.mi/mi-catch-cpp-exceptions.exp to fail when tested
with clang. The test was updated to have the catch in the same line as
the closing brace so it passes with no additional modifications with
clang.

Approved-By: Tom Tromey <tom@tromey.com>
9 months agoAutomatic date update in version.in
GDB Administrator [Tue, 17 Sep 2024 00:00:12 +0000 (00:00 +0000)] 
Automatic date update in version.in

9 months agoFix typo in py-arch.exp
Tom Tromey [Mon, 16 Sep 2024 14:11:54 +0000 (08:11 -0600)] 
Fix typo in py-arch.exp

I found a typo in a test name in py-arch.exp.

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

9 months agoMIPS/GAS: Discard redundant instruction from DDIV/DREM macros
Maciej W. Rozycki [Sun, 15 Sep 2024 14:28:18 +0000 (15:28 +0100)] 
MIPS/GAS: Discard redundant instruction from DDIV/DREM macros

A sequence such as:

li at,-1
bne xx,at,0f
 li at,1
dsll32 at,at,0x1f

is produced in the expansion of the DDIV and DREM assembly macros, where
a redundant `li at,1' instruction is used to load an intermediate value
of 1 into $at, which is then left-shifted by 63 with `dsll32 at,at,0x1f'
yielding 0x8000000000000000.  However this value likewise results from
left-shifting the value of -1, already present in $at at this point.

Remove the extraneous instruction then, shortening the sequence emitted.
Adjust dumps in the testsuite accordingly.

9 months agoMIPS/GAS/testsuite: Print instructions in hex in division tests
Maciej W. Rozycki [Sun, 15 Sep 2024 14:28:18 +0000 (15:28 +0100)] 
MIPS/GAS/testsuite: Print instructions in hex in division tests

Add `--show-raw-insn' to division tests so as to verify branch offsets
without the need to know actual offsets into the text section individual
instructions have been assembled at.  Add `-z' where applicable to make
interlock NOP instructions appear in output so as to verify them without
the need to know the offsets too.  Replace individual offsets to match
against with generic patterns so that a change in the expansion of an
assembly macro does not affect code that follows.

9 months agoMIPS/opcodes: Rework documentation for instruction args
Maciej W. Rozycki [Sun, 15 Sep 2024 12:27:33 +0000 (13:27 +0100)] 
MIPS/opcodes: Rework documentation for instruction args

Rewrite the inline documentation for the characters used in the `args'
member of `struct mips_opcode' to make it consistent in terms of style
and formatting.  Discard references to inexistent macros.

9 months agogdb: fix amd_dbgapi_target_breakpoint::re_set's signature
Simon Marchi [Sun, 15 Sep 2024 09:28:50 +0000 (09:28 +0000)] 
gdb: fix amd_dbgapi_target_breakpoint::re_set's signature

Following

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

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

... when building amd-dbgapi-target.c:

      CXX    amd-dbgapi-target.o
    /home/smarchi/src/binutils-gdb/gdb/amd-dbgapi-target.c:486:8: error: ‘void amd_dbgapi_target_breakpoint::re_set()’ marked ‘override’, but does not override
      486 |   void re_set () override;
          |        ^~~~~~

Update the signature to match the base.

Change-Id: Ie8bd71a63284917180f3e67eead58bea74bb0692

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

9 months ago[gdb/symtab] Revert "Change handling of DW_TAG_enumeration_type in DWARF scanner"
Tom de Vries [Sat, 14 Sep 2024 12:09:35 +0000 (14:09 +0200)] 
[gdb/symtab] Revert "Change handling of DW_TAG_enumeration_type in DWARF scanner"

After adding dwarf assembly to test-case gdb.dwarf2/enum-type.exp that adds
this debug info:
...
 <1><11f>: Abbrev Number: 3 (DW_TAG_enumeration_type)
    <120>   DW_AT_specification: <0x130>
 <2><124>: Abbrev Number: 4 (DW_TAG_enumerator)
    <125>   DW_AT_name        : val1
    <12a>   DW_AT_const_value : 1
 <2><12b>: Abbrev Number: 0
 <1><12c>: Abbrev Number: 5 (DW_TAG_namespace)
    <12d>   DW_AT_name        : ns
 <2><130>: Abbrev Number: 6 (DW_TAG_enumeration_type)
    <131>   DW_AT_name        : e
    <133>   DW_AT_type        : <0x118>
    <137>   DW_AT_declaration : 1
...
I run into an assertion failure:
...
(gdb) file enum-type^M
Reading symbols from enum-type...^M
cooked-index.h:214: internal-error: get_parent: \
  Assertion `(flags & IS_PARENT_DEFERRED) == 0' failed.^M
...

This was reported in PR32160 comment 1.

This is a regression since commit 4e417d7bb1c ("Change handling of
DW_TAG_enumeration_type in DWARF scanner").

Fix this by reverting the commit.

[ Also drop the kfails for PR31900 and PR32158, which are regressions by that
same commit. ]

That allows us to look at the output of "maint print objfiles", and for val1
we get an entry without parent:
...
    [27] ((cooked_index_entry *) 0x7fbbb4002ef0)
    name:       val1
    canonical:  val1
    qualified:  val1
    DWARF tag:  DW_TAG_enumerator
    flags:      0x0 []
    DIE offset: 0x124
    parent:     ((cooked_index_entry *) 0)
...
which is incorrect, as noted in that same comment, but an improvement over the
assertion failure, and I don't think that ever worked.  This is to be
addressed in a follow-up patch.

Reverting the commit begs the question: what was it trying to fix in the first
place, and do we need a different fix?  I've investigated this and filed
PR32160 to track this.

My guess is that the commit was based on a misunderstand of what we track
in cooked_indexer::m_die_range_map.

Each DIE has two types of parent DIEs:
- a DIE that is the parent as indicated by the tree structure in which DIEs
  occur, and
- a DIE that represent the parent scope.

In most cases, these two are the same, but some times they're not.

The debug info above demonstrates such a case.  The DIE at 0x11f:
- has a tree-parent: the DIE representing the CU, and
- has a scope-parent: DIE 0x12c representing namespace ns.

In cooked_indexer::m_die_range_map, we track scope-parents, and the commit
tried to add a tree-parent instead.

So, I don't think we need a different fix, and propose we backport the reversal
for gdb 15.2.

Tested on x86_64-linux.

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

9 months ago[gdb/testsuite] Add regression test for PR32158
Tom de Vries [Sat, 14 Sep 2024 12:09:35 +0000 (14:09 +0200)] 
[gdb/testsuite] Add regression test for PR32158

Consider test-case:
...
namespace ns {
  enum class ec {
    val2 = 2
  };
}

int main () {
  return (int)ns::ec::val2;
}
...
compiled with debug info:
...
$ g++ test.c -g
...

When looking at the cooked index entry for val2 using "maint print objfiles",
we get:
...
    [7] ((cooked_index_entry *) 0x7f8ecc002ef0)
    name:       val2
    canonical:  val2
    qualified:  ns::val2
    DWARF tag:  DW_TAG_enumerator
    flags:      0x0 []
    DIE offset: 0xe9
    parent:     ((cooked_index_entry *) 0x7f8ecc002e90) [ns]
...
which is wrong, there is no source level entity ns::val2.

This is PR symtab/32158.

This is a regression since commit 4e417d7bb1c ("Change handling of
DW_TAG_enumeration_type in DWARF scanner").

Reverting the commit on current trunk fixes the problem, and gets us instead:
...
    [7] ((cooked_index_entry *) 0x7fba70002ef0)
    name:       val2
    canonical:  val2
    qualified:  ns::ec::val2
    DWARF tag:  DW_TAG_enumerator
    flags:      0x0 []
    DIE offset: 0xe9
    parent:     ((cooked_index_entry *) 0x7fba70002ec0) [ec]
...

Add a regression test for this PR in test-case gdb.dwarf2/enum-type-c++.exp.

Tested on x86_64-linux.

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

9 months ago[gdb/testsuite] Add gdb.dwarf2/enum-type-c++.exp, regression test for PR31900.
Tom de Vries [Sat, 14 Sep 2024 12:09:35 +0000 (14:09 +0200)] 
[gdb/testsuite] Add gdb.dwarf2/enum-type-c++.exp, regression test for PR31900.

Consider the following test-case:
...
$ cat a.h
namespace ns {

class A {
public:
  enum {
    val1 = 1
  };
};

}
$ cat main.c

ns::A a;

int
main (void)
{
  return 0;
}
$ cat val1.c

int u1 = ns::A::val1;
...
compiled with debug info:
...
$ g++ main.c val1.c -g
...

When trying to print ns::A::val with current trunk and gdb 15.1 we get:
...
$ gdb -q -batch a.out -ex "print ns::A::val1"
There is no field named val1
...

This PR c++/31900.

With gdb 14.2 we get the expected:
...
$ gdb -q -batch a.out -ex "print ns::A::val1"
$1 = ns::A::val1
...

This is a regression since commit 4e417d7bb1c ("Change handling of
DW_TAG_enumeration_type in DWARF scanner").

Reverting the commit on current trunk fixes the problem.

So how does this problem happen?

First, let's consider the current trunk, with the commit reverted.

Gdb looks for the entry ns::A::val1, and find this entry:
...
    [29] ((cooked_index_entry *) 0x7f7830002ef0)
    name:       val1
    canonical:  val1
    qualified:  ns::A::val1
    DWARF tag:  DW_TAG_enumerator
    flags:      0x0 []
    DIE offset: 0x15a
    parent:     ((cooked_index_entry *) 0x7f7830002ec0) [A]
...
and expands the corresponding CU val1.c containing this debug info:
...
 <2><14a>: Abbrev Number: 3 (DW_TAG_class_type)
    <14b>   DW_AT_name        : A
    <14d>   DW_AT_byte_size   : 1
 <3><150>: Abbrev Number: 4 (DW_TAG_enumeration_type)
    <151>   DW_AT_encoding    : 7       (unsigned)
    <152>   DW_AT_byte_size   : 4
    <153>   DW_AT_type        : <0x163>
    <159>   DW_AT_accessibility: 1      (public)
 <4><15a>: Abbrev Number: 5 (DW_TAG_enumerator)
    <15b>   DW_AT_name        : val1
    <15f>   DW_AT_const_value : 1
 <4><160>: Abbrev Number: 0
 <3><161>: Abbrev Number: 0
 <2><162>: Abbrev Number: 0
...
after which it finds ns::A::val1 in the expanded symtabs.

Now let's consider the current trunk as is (so, with the commit present).

Gdb looks for the entry ns::A::val1, but doesn't find it because the val1
entry is missing its parent:
...
   [29] ((cooked_index_entry *) 0x7f5240002ef0)
    name:       val1
    canonical:  val1
    qualified:  val1
    DWARF tag:  DW_TAG_enumerator
    flags:      0x0 []
    DIE offset: 0x15a
    parent:     ((cooked_index_entry *) 0)
...

Then gdb looks for the entry ns::A, and finds this entry:
...
   [3] ((cooked_index_entry *) 0x7f5248002ec0)
    name:       A
    canonical:  A
    qualified:  ns::A
    DWARF tag:  DW_TAG_class_type
    flags:      0x0 []
    DIE offset: 0xdd
    parent:     ((cooked_index_entry *) 0x7f5248002e90) [ns]
...
which corresponds to this debug info, which doesn't contain val1
due to -fno-eliminate-unused-debug-types:
...
 <2><dd>: Abbrev Number: 3 (DW_TAG_class_type)
    <de>   DW_AT_name        : A
    <e0>   DW_AT_byte_size   : 1
 <2><e3>: Abbrev Number: 0
...

Gdb expands the corresponding CU main.c, after which it doesn't find
ns::A::val1 in the expanded symtabs.

The root cause of the problem is the missing parent on the val1
cooked_index_entry, but this only becomes user-visible through the
elaborate scenario above.

Add a test-case gdb.dwarf2/enum-type-c++.exp that contains a regression test
for this problem that doesn't rely on expansion state or
-feliminate-unused-debug-types, but simply tests for the root cause by
grepping for ns::A::val1 in the output of "maint print objfile".

Tested on x86_64-linux.

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

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

9 months agogdb dap: introduce stopOnEntry option
oltolm [Mon, 2 Sep 2024 10:13:22 +0000 (12:13 +0200)] 
gdb dap: introduce stopOnEntry option

Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
9 months agoUpdate more types for section index change
Tom Tromey [Thu, 12 Sep 2024 23:22:24 +0000 (17:22 -0600)] 
Update more types for section index change

Commit f89276a2f3e ("change type of `general_symbol_info::m_section`
to int") did what it says in the title -- changed the type of the
section index from short to int.  However, it seems incomplete, in
that there are uses of the section index that use the type 'short'.

This patch fixes the ones I found, first by searching for
"short.*sect" and then by looking at all the callers of section_index
(and then functions called with the resulting value) just to try to be
more sure.

Approved-by: Kevin Buettner <kevinb@redhat.com>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
9 months agoFix quoting in gdb-add-index.sh
Tom Tromey [Tue, 10 Sep 2024 17:05:04 +0000 (11:05 -0600)] 
Fix quoting in gdb-add-index.sh

When the filename quoting change was merged into the AdaCore tree, we
saw a regression in a test setup that uses the DWARF 5 index (that is
running gdb-add-index), and a filename with a space in it.

Initially I thought this was a change in the 'file' command -- but
looking again, I found out that 'file' has worked this way for a
while, and our immediate error was caused by the (documented) change
to "save gdb-index".

While I'm not sure why this test was working previously, it seems to
me that gdb-add-index.sh requires a change to quote the arguments to
"file" and "save gdb-index".

While working on this, though, it seemed to me that multiple other
spots needed quoting for the script to work correctly.  And, I was
unable to get quoting working correctly in the objcopy calls, so I
split it into multiple different invocations.

Approved-by: Kevin Buettner <kevinb@redhat.com>
9 months agoAdd quoting to 'file' invocations in DAP
Tom Tromey [Wed, 11 Sep 2024 15:25:45 +0000 (09:25 -0600)] 
Add quoting to 'file' invocations in DAP

Oleg Tolmatcev noticed that DAP launch and attach requests don't
properly handle Windows filenames, because "file" doesn't handle the
backslash characters correctly.  This patch adds quoting to the
command in an attempt to fix this.

9 months agogdb/solib: use owning_intrusive_list for solib list
Simon Marchi [Mon, 12 Aug 2024 17:09:05 +0000 (13:09 -0400)] 
gdb/solib: use owning_intrusive_list for solib list

Functions implementing `solib_ops::current_sos` return a list of solib
object, transferring the ownership to their callers.  However, the
return type, `intrusive_list<solib>`, does not reflect that.

Also, some of these functions build these lists incrementally, reading
this from the target for each solib.  If a target read were to throw,
for instance, the already created solibs would just be leaked.

Change `solib_ops::current_sos` to return an owning_intrusive_list to
address that.  Change `program_space::so_list` to be an
owning_intrusive_list as well.  This also saves us doing a few manual
deletes.

Change-Id: I6e4071d49744874491625075136c59cce8e608d4
Reviewed-by: Keith Seitz <keiths@redhat.com>
9 months agogdbsupport/intrusive-list: add owning_intrusive_list
Simon Marchi [Mon, 12 Aug 2024 17:09:04 +0000 (13:09 -0400)] 
gdbsupport/intrusive-list: add owning_intrusive_list

It occured to me that `intrusive_list<solib>`, as returned by
`solib_ops::current_sos`, for instance, is not very safe.  The
current_sos method returns the ownership of the solib objects
(heap-allocated) to its caller, but the `intrusive_list<solib>` type
does not convey it.  If a function is building an
`intrusive_list<solib>` and something throws, the solibs won't
automatically be deleted.  Introduce owning_intrusive_list to fill this
gap.

Interface
---------

The interface of owning_intrusive_list is mostly equivalent to
intrusive_list, with the following differences:

 - When destroyed, owning_intrusive_list deletes all element objects.
   The clear method does so as well.

 - The erase method destroys the removed object.

 - The push_front, push_back and insert methods accept a `unique_ptr<T>`
   (compared to `T &` for intrusive_list), taking ownership of the
   object.

 - owning_intrusive_list has emplace_front, emplace_back and emplace
   methods, allowing to allocate and construct an object directly in the
   list.  This is really just a shorthand over std::make_unique and
   insert (or push_back / push_front if you don't care about the return
   value), but I think it is nicer to read:

     list.emplace (pos, "hello", 2);

   rather than

     list.insert (pos, std::make_unique<Foo> ("hello", 2));

   These methods are not `noexcept`, since the allocation or the
   constructor could throw.

 - owning_intrusive_list has a release method, allowing to remove an
   element without destroying it.  The release method returns a
   pair-like struct with an iterator to the next element in the list
   (like the erase method) and a unique pointer transferring the
   ownership of the released element to the caller.

 - owning_intrusive_list does not have a clear_and_dispose method, since
   that is typically used to manually free items.

Implementation
--------------

owning_intrusive_list privately inherits from intrusive_list, in order
to re-use the linked list machinery.  It adds ownership semantics around
it.

Testing
-------

Because of the subtle differences in the behavior in behavior and what
we want to test for each type of intrusive list, I didn't see how to
share the tests for the two implementations.  I chose to copy the
intrusive_list tests and adjust them for owning_intrusive_list.

The verify_items function was made common though, and it tries to
dereference the items in the list, to make sure they have not been
deleted by mistake (which would be caught by Valgrind / ASan).

Change-Id: Idbde09c1417b79992a0a9534d6907433e706f760
Co-Authored-By: Pedro Alves <pedro@palves.net>
Reviewed-by: Keith Seitz <keiths@redhat.com>
9 months agogdbsupport/intrusive-list: make insert return an iterator
Simon Marchi [Mon, 12 Aug 2024 17:09:03 +0000 (13:09 -0400)] 
gdbsupport/intrusive-list: make insert return an iterator

Make the insert method return an iterator to the inserted element.  This
mimics what boost does [1] and what the standard library insert methods
generally do [2].

[1] https://www.boost.org/doc/libs/1_79_0/doc/html/boost/intrusive/list.html#idm33771-bb
[2] https://en.cppreference.com/w/cpp/container/vector/insert

Change-Id: I59082883492c60ee95e8bb29a18c9376283dd660
Reviewed-by: Keith Seitz <keiths@redhat.com>
9 months agogdbsupport/intrusive-list: sprinkle noexcept
Simon Marchi [Mon, 12 Aug 2024 17:09:02 +0000 (13:09 -0400)] 
gdbsupport/intrusive-list: sprinkle noexcept

Some methods of intrusive_list are marked noexcept.  But really,
everything in that file could be noexcept.  Add it everywhere.

The only one I had a doubt about is clear_and_dispose: what if the
disposer throws?  The boost equivalent [1] is noexcept and requires the
disposer not to throw.  The rationale is probably the same as for
destructors.  What if the disposer throws for an element in the middle
of the list?  Do you skip the remaining elements?  Do you swallow the
exception and keep calling the disposer for the remaining elements?
It's simpler to say no exceptions allowed.

[1] https://www.boost.org/doc/libs/1_79_0/doc/html/boost/intrusive/list.html#idm33710-bb

Change-Id: I402646cb12c6b7906f4bdc2ad85203d8c8cdf2cc
Reviewed-by: Keith Seitz <keiths@redhat.com>
9 months agotestsuite, trace: add guards if In-Process Agent library is not found
Stephan Rohr [Wed, 21 Feb 2024 09:55:37 +0000 (01:55 -0800)] 
testsuite, trace: add guards if In-Process Agent library is not found

Several tests in gdb.trace trigger TCL errors if the In-Process Agent
library is not found, e.g.:

  Running gdb/testsuite/gdb.trace/change-loc.exp ...
  ERROR: tcl error sourcing gdb/testsuite/gdb.trace/change-loc.exp.
  ERROR: error copying "gdb/gdb/testsuite/../../gdbserver/libinproctrace.so":
 no such file or directory
      while executing
  "file copy -force $fromfile $tofile"
      (procedure "gdb_remote_download" line 29)
      invoked from within
  "gdb_remote_download target $target_file"
      (procedure "gdb_download_shlib" line 6)
      invoked from within
  "gdb_download_shlib $file"
      (procedure "gdb_load_shlib" line 2)
      invoked from within
  "gdb_load_shlib $libipa"
      (file "gdb/testsuite/gdb.trace/change-loc.exp" line 354)
      invoked from within
  "source gdb/testsuite/gdb.trace/change-loc.exp"
      ("uplevel" body line 1)
      invoked from within
  "uplevel #0 source gdb/testsuite/gdb.trace/change-loc.exp"
      invoked from within
  "catch "uplevel #0 source $test_file_name""

Protect against this error by checking if the library is available.

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

9 months agogprofng: avoid use of non-portable which [PR32166]
Sam James [Wed, 11 Sep 2024 21:01:49 +0000 (22:01 +0100)] 
gprofng: avoid use of non-portable which [PR32166]

Distributions like Debian [0] and Gentoo are phasing out the use of
the non-portable `which` utility. Use POSIX's `command -v` instead.

[0] https://lwn.net/Articles/874049/

gprofng/ChangeLog
PR gprofng/32166
* testsuite/lib/Makefile.skel (JAVABIN): Replace use of which.

9 months agogdb: change type of `general_symbol_info::m_section` to int
Simon Marchi [Thu, 12 Sep 2024 12:27:08 +0000 (08:27 -0400)] 
gdb: change type of `general_symbol_info::m_section` to int

The binary provided with bug 32165 [1] has 36139 ELF sections.  GDB
crashes on it with (note that my GDB is build with -D_GLIBCXX_DEBUG=1:

    $ ./gdb  -nx -q --data-directory=data-directory ./vmlinux
    Reading symbols from ./vmlinux...
    (No debugging symbols found in ./vmlinux)
    (gdb) info func
    /usr/include/c++/14.2.1/debug/vector:508:
    In function:
        std::debug::vector<_Tp, _Allocator>::reference std::debug::vector<_Tp,
        _Allocator>::operator[](size_type) [with _Tp = long unsigned int;
        _Allocator = std::allocator<long unsigned int>; reference = long
        unsigned int&; size_type = long unsigned int]

    Error: attempt to subscript container with out-of-bounds index -29445, but
    container only holds 36110 elements.

    Objects involved in the operation:
        sequence "this" @ 0x514000007340 {
          type = std::debug::vector<unsigned long, std::allocator<unsigned long> >;
        }

The crash occurs here:

    #3  0x00007ffff5e334c3 in __GI_abort () at abort.c:79
    #4  0x00007ffff689afc4 in __gnu_debug::_Error_formatter::_M_error (this=<optimized out>) at /usr/src/debug/gcc/gcc/libstdc++-v3/src/c++11/debug.cc:1320
    #5  0x0000555561119a16 in std::__debug::vector<unsigned long, std::allocator<unsigned long> >::operator[] (this=0x514000007340, __n=18446744073709522171)
        at /usr/include/c++/14.2.1/debug/vector:508
    #6  0x0000555562e288e8 in minimal_symbol::value_address (this=0x5190000bb698, objfile=0x514000007240) at /home/smarchi/src/binutils-gdb/gdb/symtab.c:517
    #7  0x0000555562e5a131 in global_symbol_searcher::expand_symtabs (this=0x7ffff0f5c340, objfile=0x514000007240, preg=std::optional [no contained value])
        at /home/smarchi/src/binutils-gdb/gdb/symtab.c:4983
    #8  0x0000555562e5d2ed in global_symbol_searcher::search (this=0x7ffff0f5c340) at /home/smarchi/src/binutils-gdb/gdb/symtab.c:5189
    #9  0x0000555562e5ffa4 in symtab_symbol_info (quiet=false, exclude_minsyms=false, regexp=0x0, kind=FUNCTION_DOMAIN, t_regexp=0x0, from_tty=1)
        at /home/smarchi/src/binutils-gdb/gdb/symtab.c:5361
    #10 0x0000555562e6131b in info_functions_command (args=0x0, from_tty=1) at /home/smarchi/src/binutils-gdb/gdb/symtab.c:5525

That is, at this line of `minimal_symbol::value_address`, where
`objfile->section_offsets` is an `std::vector`:

    return (CORE_ADDR (this->unrelocated_address ())
    + objfile->section_offsets[this->section_index ()]);

A section index of -29445 is suspicious.  The minimal_symbol at play
here is:

    (top-gdb) p m_name
    $1 = 0x521001de10af "_sinittext"

So I restarted debugging, breaking on:

   (top-gdb) b general_symbol_info::set_section_index if $_streq("_sinittext", m_name)

And I see that weird -29445 value:

    (top-gdb) frame
    #0  general_symbol_info::set_section_index (this=0x525000082390, idx=-29445) at /home/smarchi/src/binutils-gdb/gdb/symtab.h:611
    611       { m_section = idx; }

But going up one frame, the section index is 36091:

    (top-gdb) frame
    #1  0x0000555562426526 in minimal_symbol_reader::record_full (this=0x7ffff0ead560, name="_sinittext", copy_name=false,
        address=-2111475712, ms_type=mst_text, section=36091) at /home/smarchi/src/binutils-gdb/gdb/minsyms.c:1228
    1228      msymbol->set_section_index (section);

It seems like the problem is just that the type used for the section
index (short) is not big enough.  Change from short to int.  If somebody
insists, we could even go long long / int64_t, but I doubt it's
necessary.

With that fixed, I get:

    (gdb) info func
    All defined functions:

    Non-debugging symbols:
    0xffffffff81000000  _stext
    0xffffffff82257000  _sinittext
    0xffffffff822b4ebb  _einittext

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=32165

Change-Id: Icb1c3de9474ff5adef7e0bbbf5e0b67b279dee04
Reviewed-By: Tom de Vries <tdevries@suse.de>
Reviewed-by: Keith Seitz <keiths@redhat.com>
9 months agos390: Relax risbg[n]z, risb{h|l}gz, {rns|ros|rxs}bgt operand constraints
Jens Remus [Thu, 12 Sep 2024 13:06:06 +0000 (15:06 +0200)] 
s390: Relax risbg[n]z, risb{h|l}gz, {rns|ros|rxs}bgt operand constraints

This leverages commit ("s390: Simplify (dis)assembly of insn operands
with const bits") to relax the operand constraints of the immediate
operand that contains the constant Z- or T-bit of the following extended
mnemonics:
risbgz, risbgnz, risbhgz, risblgz, rnsbgt, rosbgt, rxsbgt

Previously those instructions were the only ones where the assembler
on s390 restricted the specification of the subject I3/I4 operand values
exactly according to their specification to an unsigned 6- or 5-bit
unsigned integer. For any other instructions the assembler allows to
specify any operand value allowed by the instruction format, regardless
of whether the instruction specification is more restrictive.

Allow to specify the subject I3/I4 operand as unsigned 8-bit integer
with the constant operand bits being ORed during assembly.
Relax the instructions subject significant operand bit masks to only
consider the Z/T-bit as significant, so that the instructions get
disassembled as their *z or *t flavor regardless of whether any reserved
bits are set in addition to the Z/T-bit.
Adapt the rnsbg, rosbg, and rxsbg test cases not to inadvertently set
the T-bit in operand I3, as they otherwise get disassembled as their
rnsbgt, rosbgt, and rxsbgt counterpart.

This aligns GNU Assembler to LLVM Assembler.

opcodes/
* s390-opc.c (U6_18, U5_27, U6_26): Remove.
(INSTR_RIE_RRUUU2, INSTR_RIE_RRUUU3, INSTR_RIE_RRUUU4): Define
as INSTR_RIE_RRUUU while retaining insn fmt mask.
(MASK_RIE_RRUUU2, MASK_RIE_RRUUU3, MASK_RIE_RRUUU4): Treat only
Z/T-bit of I3/I4 operand as significant.

gas/testsuite/
* gas/s390/zarch-z10.s (rnsbg, rosbg, rxsbg): Do not set T-bit.

Reported-by: Dominik Steenken <dost@de.ibm.com>
Suggested-by: Ulrich Weigand <ulrich.weigand@de.ibm.com>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
9 months agos390: Simplify (dis)assembly of insn operands with const bits
Jens Remus [Thu, 12 Sep 2024 13:06:06 +0000 (15:06 +0200)] 
s390: Simplify (dis)assembly of insn operands with const bits

Simplify assembly and disassembly of extended mnemonics with operands
with constant ORed bits:
Their instruction template already contains the respective constant
operand bits, as they are significant to distinguish the extended from
their base mnemonic. Operands are ORed into the instruction template.
Therefore it is not necessary to OR the constant bits into the operand
value during assembly in s390_insert_operand.
Additionally the constant operand bits from the instruction template
can be used to mask them from the operand value during disassembly in
s390_print_insn_with_opcode. For now do so for non-length unsigned
integer operands only.

The separate instruction formats need to be retained, as their masks
differ, which is relevant during disassembly to distinguish the base
and extended mnemonics from each other.

This affects the following extended mnemonics:
- vfaebs, vfaehs, vfaefs
- vfaezb, vfaezh, vfaezf
- vfaezbs, vfaezhs, vfaezfs
- vstrcbs, vstrchs, vstrcfs
- vstrczb, vstrczh, vstrczf
- vstrczbs, vstrczhs, vstrczfs
- wcefb, wcdgb
- wcelfb, wcdlgb
- wcfeb, wcgdb
- wclfeb, wclgdb
- wfisb, wfidb, wfixb
- wledb, wflrd, wflrx

include/
* opcode/s390.h (S390_OPERAND_OR1, S390_OPERAND_OR2,
S390_OPERAND_OR8): Remove.

opcodes/
* s390-opc.c (U4_OR1_24, U4_OR2_24, U4_OR8_28): Remove.
(INSTR_VRR_VVV0U1, INSTR_VRR_VVV0U2, INSTR_VRR_VVV0U3): Define
as INSTR_VRR_VVV0U0 while retaining respective insn fmt mask.
(INSTR_VRR_VV0UU8): Define as INSTR_VRR_VV0UU while retaining
respective insn fmt mask.
(INSTR_VRR_VVVU0VB1, INSTR_VRR_VVVU0VB2, INSTR_VRR_VVVU0VB3):
Define as INSTR_VRR_VVVU0VB while retaining respective insn fmt
mask.
* s390-dis.c (s390_print_insn_with_opcode): Mask constant
operand bits set in insn template of non-length unsigned
integer operands.

gas/
* config/tc-s390.c (s390_insert_operand): Do not OR constant
operand value bits.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
9 months agoAutomatic date update in version.in
GDB Administrator [Thu, 12 Sep 2024 00:00:10 +0000 (00:00 +0000)] 
Automatic date update in version.in

9 months agoFix 32096 UBSAN issues in gprofng
Vladimir Mezentsev [Wed, 11 Sep 2024 04:05:19 +0000 (21:05 -0700)] 
Fix 32096 UBSAN issues in gprofng

Fixed UBSAN runtime errors such as:
 - load of value 4294967295, which is not a valid value for type 'Cmsg_warn'
 - null pointer passed as argument 2, which is declared to never be null
 - load of value 4294967295, which is not a valid value for type 'ProfData_type'
 - reference binding to misaligned address 0x00000357583c for type 'long unsigned int', which requires 8 byte alignment

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

PR gprofng/32096
* src/BaseMetric.cc: Fix UBSAN runtime errors.
* src/BaseMetric.h: Likewise.
* src/Emsg.h: Likewise.
* src/Experiment.cc: Likewise.
* src/Table.h: Likewise.

9 months ago[gdb/testsuite] Simplify gdb.dwarf2/forward-spec.exp
Tom de Vries [Wed, 11 Sep 2024 15:56:34 +0000 (17:56 +0200)] 
[gdb/testsuite] Simplify gdb.dwarf2/forward-spec.exp

Test-case gdb.dwarf2/forward-spec.exp contains a non-trivial gdb_test_multiple
to parse this cooked_index_entry:
...
    [5] ((cooked_index_entry *) 0x7f01f0004040)^M
    name:       v^M
    canonical:  v^M
    qualified:  ns::v^M
    DWARF tag:  DW_TAG_variable^M
    flags:      0x2 [IS_STATIC]^M
    DIE offset: 0xcb^M
    parent:     ((cooked_index_entry *) 0x7f01f00040a0) [ns]^M
...
which allows us to verify that the entry has a parent.

After commit 8f258a6c979 ("[gdb/symtab] Dump qualified name of
cooked_index_entry") that's no longer necessary.

Simplify this by checking for ns::v instead.

While we're at it, also fix the test-case for target boards readnow,
cc-with-gdb-index and cc-with-debug-names.

Tested on x86_64-linux.

9 months agoarm: Handle undefweak with ST_BRANCH_UNKNOWN
Christophe Lyon [Fri, 6 Sep 2024 17:10:02 +0000 (17:10 +0000)] 
arm: Handle undefweak with ST_BRANCH_UNKNOWN

A previous patch made ld fail early on Thumb-only where branch_type is
ST_BRANCH_UNKNOWN.

However, this fails erroneously when the target is undefweak: in that
case the branch should be replaced by a branch to the next instruction
(or nop.w on thumb2).  This patch accepts this case and restores the
previous behaviour in such cases.

This was reported by failures in the GCC testsuite, where we fail to
link executables because __deregister_frame_info is undefweak:

(__deregister_frame_info): Unknown destination type (ARM/Thumb) in ...crtbegin.o
crtbegin.o: in function `__do_global_dtors_aux':
crtstuff.c:(.text+0x52): dangerous relocation: unsupported relocation

9 months agogdb: Support DW_OP_constx (the standardized version of DW_OP_GNU_const_index).
Kyle Huey [Sat, 7 Sep 2024 15:20:05 +0000 (08:20 -0700)] 
gdb: Support DW_OP_constx (the standardized version of DW_OP_GNU_const_index).

Approved-By: Tom Tromey <tom@tromey.com>
9 months agoFix typo in Python TUI window text
Tom Tromey [Wed, 11 Sep 2024 14:18:06 +0000 (08:18 -0600)] 
Fix typo in Python TUI window text

I noticed a typo in the Python TUI window documentation.

9 months agogas: avoid (scrubber) diagnostics for stuff past .end
Jan Beulich [Wed, 11 Sep 2024 11:56:36 +0000 (13:56 +0200)] 
gas: avoid (scrubber) diagnostics for stuff past .end

What's past an active .end directive (when that has its default purpose)
is supposed to be entirely ignored. That should be true not just for
regular processing, but also for "pre-processing" (aka scrubbing). A
complication is that such a directive may of course occur inside a
(false) conditional or a macro definition. To deal with that make sure
we can continue as usual if called another time.

Note however that .end inside a macro will still have the full macro
body expanded; dealing with that would require further (perhaps
intrusive) adjustments in sb_scrub_and_add_sb() and/or callers thereof.
However, at least some of the warnings issued by do_scrub_chars() are
unlikely to occur when expanding a macro. (If we needed to go that far,
presumably .exitm would also want recognizing.)

9 months agogas: restrict scrubber mri_{state,last_ch} vars
Jan Beulich [Wed, 11 Sep 2024 11:55:49 +0000 (13:55 +0200)] 
gas: restrict scrubber mri_{state,last_ch} vars

They're needed with TC_M68K only. Group them accordingly, just like is
the case for Arm's symver vars.

9 months agoarm: don't engage symver scrubber hack in CCS mode
Jan Beulich [Wed, 11 Sep 2024 11:55:01 +0000 (13:55 +0200)] 
arm: don't engage symver scrubber hack in CCS mode

In that mode the comment char is ; while @ has no special meaning.
Engaging the special logic in that case results in comments not being
respected on .symver lines.

9 months agox86/APX: correct disassembly for EVEX.B4
Jan Beulich [Wed, 11 Sep 2024 11:52:42 +0000 (13:52 +0200)] 
x86/APX: correct disassembly for EVEX.B4

EVEX.B4 is used only for GPR (or addressing of memory) operands. SIMD
registers encoded via ModR/M.rm (when ModR/M.mod == 3) have their top
bit in EVEX.X3. Supposedly (doc version 004) EVEX.B4 is ignored when
unused, hence also don't flag such encodings as invalid.

9 months agox86: error handling in set_cpu_arch()
Jan Beulich [Wed, 11 Sep 2024 11:52:18 +0000 (13:52 +0200)] 
x86: error handling in set_cpu_arch()

Error messages there would better not be followed by further "junk at
end of line" diagnostics. Arrange for this to be the case uniformly.

While there also replace a somewhat unhelpful open-coding of
restore_line_pointer().

9 months agold/testsuite: exclude relocs from section contributions PDB test
Mark Harmstone [Mon, 9 Sep 2024 21:01:00 +0000 (22:01 +0100)] 
ld/testsuite: exclude relocs from section contributions PDB test

A bug in ld meant that we were erroneously generating image relocations
for .secrel32 ops, which we then reflected in our PDB section
contributions because the linker was adding a .reloc section.

This was incidental to what we were testing for, so pass
--disable-reloc-section to ld in order to ensure a consistent output.

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

9 months agogdb/testsuite: fix argument order in example code within a comment
Andrew Burgess [Sun, 11 Aug 2024 14:40:54 +0000 (15:40 +0100)] 
gdb/testsuite: fix argument order in example code within a comment

Small typo in some example code inside a comment; the arguments were
in the wrong order.

There's no functional change after this commit.

9 months agogdb/testsuite: add return after a call to 'untested'
Andrew Burgess [Sat, 10 Aug 2024 11:26:49 +0000 (12:26 +0100)] 
gdb/testsuite: add return after a call to 'untested'

In gdb.base/corefile-buildid.exp, in the function
do_corefile_buildid_tests, if we fail to find the build-id for the
test binary then we call 'untested', but then push on with the test,
which inevitably fails as the rest of the test depends on having found
the build-id.

I think we're missing a 'return' after the call to 'untested' which
I've now added.

Also I noticed that we call build_id_debug_filename_get and then
manually remove '.debug' from the end.  This is no longer necessary,
we can just ask build_id_debug_filename_get to not add the suffix.

9 months agoRevert "[gdb/testsuite] Handle missing curses in gdb.python/py-missing-debug.exp"
Andrew Burgess [Tue, 10 Sep 2024 13:05:55 +0000 (14:05 +0100)] 
Revert "[gdb/testsuite] Handle missing curses in gdb.python/py-missing-debug.exp"

This reverts commit 29c70787112e01cd52b53bf14bdcacb0a11e0725.

After the previous commit 29c70787112e01cd52 should no longer be
needed as the curses dependency has been removed.

9 months agogdb/python: avoid depending on the curses library
Andrew Burgess [Mon, 9 Sep 2024 16:33:54 +0000 (17:33 +0100)] 
gdb/python: avoid depending on the curses library

The commit:

  commit 29c70787112e01cd52b53bf14bdcacb0a11e0725
  Date:   Sun Sep 8 07:46:09 2024 +0200

      [gdb/testsuite] Handle missing curses in gdb.python/py-missing-debug.exp

Highlighted that in some cases we might be running on a system with an
older version of Python (earlier than 3.7), and on a system for which
the curses library has not been installed.

In these circumstances the gdb.missing_debug module will not load as
it uses curses to provide isalnum() and isascii() functions.

To avoid this problem I propose that we copy the isalnum() and
isascii() from the Python curses library.  These functions are
basically trivial and removing the curses dependency means GDB will
work in more cases without increasing its dependencies.

I did consider keeping the uses of curses and only having the function
definitions be a fallback for when the curses library failed to load,
but this felt like overkill.  The function definitions are both tiny
and I think "obvious" given their specifications, so I figure we might
as well just use our own definitions if they are not available as
builtin methods on the str class.

For testing I changed this line:

  if sys.version_info >= (3, 7):

to

  if sys.version_info >= (3, 7) and False:

then reran gdb.python/py-missing-debug.exp, there were no failures.

Approved-By: Tom de Vries <tdevries@suse.de>
9 months ago[gdb/testsuite] Fix gdb.xml/tdesc-regs.exp on riscv64
Tom de Vries [Tue, 10 Sep 2024 08:25:07 +0000 (10:25 +0200)] 
[gdb/testsuite] Fix gdb.xml/tdesc-regs.exp on riscv64

When running test-case gdb.xml/tdesc-regs.exp on riscv64-linux, I get:
...
(gdb) set tdesc file single-reg.xml^M
warning: Architecture rejected target-supplied description^M
(gdb) FAIL: gdb.xml/tdesc-regs.exp: set tdesc file single-reg.xml
UNSUPPORTED: gdb.xml/tdesc-regs.exp: register tests
...

The FAIL and UNSUPPORTED are produced here:
...
 # If no core registers were specified, assume this target does not
 # support target-defined registers.  Verify that we get a warning if
 # we try to use them.  This not only tests the warning, but also
 # reminds maintainers to add test support when they add the feature.

if {[string equal ${core-regs} ""]} {
    gdb_test "set tdesc file $single_reg_xml" \
"warning: Target-supplied registers are not supported.*" \
"set tdesc file single-reg.xml"
    unsupported "register tests"
    return 0
}
...

The test-case contains target-specific setting of the core-regs variable, and
adding this for riscv64 bypasses this code and makes the test-case pass.

However, without that change, the test-case shouldn't produce a FAIL since
gdb isn't doing anything wrong.

Fix this by producing instead:
...
PASS: $exp: set tdesc file single-reg.xml
UNSUPPORTED: $exp: register tests (missing architecture-specific core-regs setting)
...

Tested on riscv64-linux.

9 months ago[gdb/build] Fix unused var in corelow.c
Tom de Vries [Tue, 10 Sep 2024 08:08:29 +0000 (10:08 +0200)] 
[gdb/build] Fix unused var in corelow.c

On x86_64-linux, with gcc 7.5.0 and CFLAGS/CXXFLAGS="-O0 -g -Wall" I ran into
a build breaker:
...
gdb/corelow.c: In member function ‘void mapped_file_info::add(const char*, const char*, const char*, std::vector<mem_range>&&, const bfd_build_id*)’:
gdb/corelow.c:1822:27: error: unused variable ‘it’ [-Werror=unused-variable]
   const auto [it, inserted]
                           ^
...

Fix this by dropping the variable it.

Tested on x86_64-linux.

Reviewed-By: Lancelot Six<lancelot.six@amd.com>
9 months agobfd: Pass true to ld_plugin_object_p
H.J. Lu [Mon, 9 Sep 2024 00:27:00 +0000 (17:27 -0700)] 
bfd: Pass true to ld_plugin_object_p

Since linker calls bfd_plugin_object_p, which calls ld_plugin_object_p,
only for command-line input objects, pass true to ld_plugin_object_p so
that the same input IR file won't be included twice if the new LTO hook,
LDPT_REGISTER_CLAIM_FILE_HOOK_V2 isn't used.

PR ld/32153
* plugin.c (bfd_plugin_object_p): Pass true to ld_plugin_object_p.

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

9 months agoMove enum size check into ada_identical_enum_types_p
Tom Tromey [Mon, 26 Aug 2024 17:30:01 +0000 (11:30 -0600)] 
Move enum size check into ada_identical_enum_types_p

Currently, the callers of ada_identical_enum_types_p must check that
both enum types have the same number of members.  In another series
I'm working on, it was convenient to move this check into the callee
instead; and I broke this patch out to make that series a little
simpler.

Approved-By: Tom de Vries <tdevries@suse.de>
9 months agoMinor cleanup to ada_identical_enum_types_p
Tom Tromey [Mon, 26 Aug 2024 17:29:01 +0000 (11:29 -0600)] 
Minor cleanup to ada_identical_enum_types_p

This moves the declaration of 'i' into the 'for' loops in
ada_identical_enum_types_p.  This is just a trivial cleanup.

Approved-By: Tom de Vries <tdevries@suse.de>
9 months agoBoolify ada_identical_enum_types_p
Tom Tromey [Mon, 26 Aug 2024 17:25:01 +0000 (11:25 -0600)] 
Boolify ada_identical_enum_types_p

This changes ada_identical_enum_types_p to return bool rather than
int.

Approved-By: Tom de Vries <tdevries@suse.de>
9 months agoFix some comments in dwarf2/cooked-index.h
Tom Tromey [Fri, 6 Sep 2024 17:50:27 +0000 (11:50 -0600)] 
Fix some comments in dwarf2/cooked-index.h

This fixes a couple of comments in dwarf2/cooked-index.h.

The comment by cooked_index_entry::canonical mentions C++, but this
field can also be different from 'name' in other situations.  Rather
than enumerate the cases here (which doesn't seem important), make the
text a little less specific.

Also, cooked_index_entry::write_scope doesn't document its "for_main"
parameter -- and it is misnamed in the prototype as well.

Reviewed-By: Tom de Vries <tdevries@suse.de>
9 months agoRefactor cooked_index_shard::handle_gnat_encoded_entry
Tom Tromey [Tue, 3 Sep 2024 18:04:18 +0000 (12:04 -0600)] 
Refactor cooked_index_shard::handle_gnat_encoded_entry

This changes cooked_index_shard::handle_gnat_encoded_entry to modify
the incoming entry itself, and to return void rather than a new name.
this simplifies the caller a little, which is convenient for a
different series I am working on.

Approved-By: Tom de Vries <tdevries@suse.de>
9 months agoIgnore DW_TAG_padding in tag_is_type
Tom Tromey [Fri, 6 Sep 2024 16:52:54 +0000 (10:52 -0600)] 
Ignore DW_TAG_padding in tag_is_type

DW_TAG_padding isn't a real tag -- it doesn't appear in the DWARF
standard, only in include/dwarf2.def as a placeholder.  So, remove it
from dwarf2/tag.h:tag_is_type.

Reviewed-By: Tom de Vries <tdevries@suse.de>
9 months agos390: Align opcodes to lower-case
Jens Remus [Mon, 9 Sep 2024 15:05:28 +0000 (17:05 +0200)] 
s390: Align opcodes to lower-case

opcodes/
* s390-opc.txt (rdp): Change opcode to lower-case.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
9 months agos390: Document syntax to omit base register operand
Jens Remus [Mon, 9 Sep 2024 15:05:27 +0000 (17:05 +0200)] 
s390: Document syntax to omit base register operand

Document the s390-specific assembler syntax introduced by commit
aacf780bca29 ("s390: Allow to explicitly omit base register operand in
assembly") to omit the base register operand B in D(X,B) and D(L,B) by
coding D(X,) and D(L,).

While at it document the alternative syntax to omit the index register
operand X in D(X,B) by coding D(,B) instead of D(B).

gas/
* doc/c-s390.texi (s390 Operands): Document syntax to omit base
register operand.

Fixes: aacf780bca29 ("s390: Allow to explicitly omit base register operand in assembly")
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
9 months agogdb/NEWS: group general news items together
Andrew Burgess [Mon, 9 Sep 2024 10:27:30 +0000 (11:27 +0100)] 
gdb/NEWS: group general news items together

I noticed that the list of general NEWS items seemed to have gotten
mixed up a bit in the NEWS file.  This commit just moves things around
so that the general items all appear at the start of the 'Changes
since GDB 15' section.  I've not changed any of the actual content.

9 months agoLoongArch: Fixed precedence of expression operators in instructions
Lulu Cai [Mon, 2 Sep 2024 04:05:54 +0000 (12:05 +0800)] 
LoongArch: Fixed precedence of expression operators in instructions

The precedence of the operators "+" and "-" in the current loongarch
instruction expression is higher than "<<" and ">>", which is different
from the explanation in the user guide.

We modified the precedence of "<<" and ">>" to be higher than "+" and "-".

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

9 months agogdb: fix use of out of scope temporary variable in break-cond-parse.c
Andrew Burgess [Sun, 8 Sep 2024 20:17:55 +0000 (21:17 +0100)] 
gdb: fix use of out of scope temporary variable in break-cond-parse.c

The commit:

  commit c6b486755e020095710c7494d029577ca967a13a
  Date:   Thu Mar 30 19:21:22 2023 +0100

      gdb: parse pending breakpoint thread/task immediately

Introduce a use bug where the value of a temporary variable was being
used after it had gone out of scope.  This was picked up by the
address sanitizer and would result in this error:

  (gdb) maintenance selftest create_breakpoint_parse_arg_string
  Running selftest create_breakpoint_parse_arg_string.
  =================================================================
  ==2265825==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7fbb08046511 at pc 0x000001632230 bp 0x7fff7c2fb770 sp 0x7fff7c2fb768
  READ of size 1 at 0x7fbb08046511 thread T0
      #0 0x163222f in create_breakpoint_parse_arg_string(char const*, std::unique_ptr<char, gdb::xfree_deleter<char> >*, int*, int*, int*, std::unique_ptr<char, gdb::xfree_deleter<char> >*, bool*) ../../src/gdb/break-cond-parse.c:496
      #1 0x1633026 in test ../../src/gdb/break-cond-parse.c:582
      #2 0x163391b in create_breakpoint_parse_arg_string_tests ../../src/gdb/break-cond-parse.c:649
      #3 0x12cfebc in void std::__invoke_impl<void, void (*&)()>(std::__invoke_other, void (*&)()) /usr/include/c++/13/bits/invoke.h:61
      #4 0x12cc8ee in std::enable_if<is_invocable_r_v<void, void (*&)()>, void>::type std::__invoke_r<void, void (*&)()>(void (*&)()) /usr/include/c++/13/bits/invoke.h:111
      #5 0x12c81e5 in std::_Function_handler<void (), void (*)()>::_M_invoke(std::_Any_data const&) /usr/include/c++/13/bits/std_function.h:290
      #6 0x18bb51d in std::function<void ()>::operator()() const /usr/include/c++/13/bits/std_function.h:591
      #7 0x4193ef9 in selftests::run_tests(gdb::array_view<char const* const>, bool) ../../src/gdbsupport/selftest.cc:100
      #8 0x21c2206 in maintenance_selftest ../../src/gdb/maint.c:1172
      ... etc ...

The problem was caused by three lines like this one:

  thread_info *thr
    = parse_thread_id (std::string (t.get_value ()).c_str (), &tmptok);

After parsing the thread-id TMPTOK would be left pointing into the
temporary string which had been created on this line.  When on the
next line we did this:

  gdb_assert (*tmptok == '\0');

The value of *TMPTOK is undefined.

Fix this by creating the std::string earlier in the scope.  Now the
contents of the string will remain valid when we check *TMPTOK.  The
address sanitizer issue is now resolved.

9 months ago[gdb/testsuite] Handle missing curses in gdb.python/py-missing-debug.exp
Tom de Vries [Sun, 8 Sep 2024 05:46:09 +0000 (07:46 +0200)] 
[gdb/testsuite] Handle missing curses in gdb.python/py-missing-debug.exp

On a system with python 3.6, module gdb.missing_debug imports module curses,
so when running test-case gdb.python/py-missing-debug.exp on a system without
that module installed, we run into:
...
(gdb) source py-missing-debug.py^M
Python Exception <class 'ImportError'>: Module 'curses' is not installed.^M
Use:^M
  sudo zypper install python36-curses^M
to install it.^M
Error occurred in Python: Module 'curses' is not installed.^M
Use:^M
  sudo zypper install python36-curses^M
to install it.^M
(gdb) FAIL: gdb.python/py-missing-debug.exp: source python script
...

Fix this by issuing UNSUPPORTED instead, and bailing out.

Tested on x86_64-linux.

Approved-by: Kevin Buettner <kevinb@redhat.com>
PR testsuite/31576
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31576

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