]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
10 months agoAutomatic date update in version.in
GDB Administrator [Fri, 9 Aug 2024 00:00:28 +0000 (00:00 +0000)] 
Automatic date update in version.in

10 months agogas: sparc: Fix faligndatai assembly and disassembly
Richard Henderson [Thu, 8 Aug 2024 22:32:54 +0000 (08:32 +1000)] 
gas: sparc: Fix faligndatai assembly and disassembly

The first operand is a general register, not an fp register;
the third operand is encoded into RS2, not RS3;
the second operand must match the destination operand.

10 months ago[gdb/python] Fix handling of ^C during disassembly
Tom de Vries [Thu, 8 Aug 2024 21:52:00 +0000 (23:52 +0200)] 
[gdb/python] Fix handling of ^C during disassembly

Inspired by the trigger patch I used here [1], I tried this in
gdbpy_print_insn:
...
   /* Call into the registered disassembler to (possibly) perform the
      disassembly.  */
+  set_quit_flag ();
   PyObject *insn_disas_obj = (PyObject *) disasm_info;
   gdbpy_ref<> result (PyObject_CallFunctionObjArgs (hook.get (),
                                                    insn_disas_obj,
...
and with test-case gdb.python/py-disasm-exec.exp ran into:
...
(gdb) disassemble test^M
Dump of assembler code for function test:^M
   0x00000000004101ac <+0>:     Python Exception <class 'KeyboardInterrupt'>: ^M
^M
unknown disassembler error (error = -1)^M
(gdb)
...

This is incorrect, the KeyboardInterrupt should propagate and interrupt the
command.

Fix this by using gdbpy_print_stack_or_quit instead of gdbpy_print_stack in
gdbpy_print_insn, giving us instead:
...
(gdb) disassemble test^M
Dump of assembler code for function test:^M
   0x00000000004101ac <+0>:     ^M
Quit^M
(gdb)
...

Tested on aarch64-linux.

Approved-By: Andrew Burgess <aburgess@redhat.com>
[1] https://sourceware.org/pipermail/gdb-patches/2024-July/210798.html

10 months ago[gdb] Handle ^C during disassembly
Tom de Vries [Thu, 8 Aug 2024 21:52:00 +0000 (23:52 +0200)] 
[gdb] Handle ^C during disassembly

In PR gdb/32025, a fatal error was reported when sending a SIGINT to gdb while
disassembling.

I managed to reproduce this on aarch64-linux in a Leap 15.5 container using
this trigger patch:
...
 gdb_disassembler_memory_reader::dis_asm_read_memory
   (bfd_vma memaddr, gdb_byte *myaddr, unsigned int len,
    struct disassemble_info *info) noexcept
 {
+  set_quit_flag ();
   return target_read_code (memaddr, myaddr, len);
 }
...
and a simple gdb command line calling the disassemble command:
...
$ gdb -q -batch a.out -ex "disassemble main"
...

The following scenario leads to the fatal error:
- the disassemble command is executed,
- set_quit_flag is called in
  gdb_disassembler_memory_reader::dis_asm_read_memory, pretending that a
  user pressed ^C,
- target_read_code calls QUIT, which throws a
  gdb_exception_quit,
- the exception propagation mechanism reaches c code in libopcodes and a fatal
  error triggers because the c code is not compiled with -fexception.

Fix this by:
- wrapping the body of gdb_disassembler_memory_reader::dis_asm_read_memory in
  catch_exceptions (which consequently needs moving to a header file), and
- reraising the caught exception in default_print_insn using QUIT.

Tested on aarch64-linux.

Approved-By: Andrew Burgess <aburgess@redhat.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32025

10 months agoAutomatic date update in version.in
GDB Administrator [Thu, 8 Aug 2024 00:00:35 +0000 (00:00 +0000)] 
Automatic date update in version.in

10 months agoscore: drop TC_ALPHA code
Jan Beulich [Wed, 7 Aug 2024 14:32:43 +0000 (16:32 +0200)] 
score: drop TC_ALPHA code

I can't see how that could ever have come into play.

10 months agogas: drop dead VMS code from command line handling
Jan Beulich [Wed, 7 Aug 2024 14:32:15 +0000 (16:32 +0200)] 
gas: drop dead VMS code from command line handling

The only time 'v' was overridden, allowing for an optional value, was
when OBJ_VMS support still existed (until a little less than 20 years
ago). Drop the respective leftovers.

With that OPTION_VERBOSE also becomes redundant and hence is being
dropped.

10 months agoVAX: drop OBJ_VMS leftovers
Jan Beulich [Wed, 7 Aug 2024 14:31:54 +0000 (16:31 +0200)] 
VAX: drop OBJ_VMS leftovers

OBJ_VMS support was dropped almost 20 years ago (e330299ed5ee). Drop
respective code from tc-vax.c as well.

While there, make adjustments for OBJ_ELF as well: -K was dropped over
20 years ago (530556a951f5), yet left in md_shortopts. OPTION_PIC isn't
really necessary either; 'k' can be used instead. And then the ELF
options available weren't displayed by md_show_usage().

10 months agogas: improve unrecognized command line option diagnostic
Jan Beulich [Wed, 7 Aug 2024 14:31:00 +0000 (16:31 +0200)] 
gas: improve unrecognized command line option diagnostic

Printing optc with %c makes sense only when optc is actually a
character. Add logic to also deal with unrecognized long options,
rejected by md_parse_option() rather than get_opt_long_only(). Also
quote the reproduced strings, such that possible included whitespace
can be recognized.

10 months agogas/NEWS: Moved RISC-V Zimop/Zcmop changes into 2.43 section due to backport.
Nelson Chu [Wed, 7 Aug 2024 08:17:05 +0000 (16:17 +0800)] 
gas/NEWS: Moved RISC-V Zimop/Zcmop changes into 2.43 section due to backport.

10 months agoloongarch ld testsuite xpasses
Alan Modra [Tue, 6 Aug 2024 22:26:33 +0000 (07:56 +0930)] 
loongarch ld testsuite xpasses

Some tests started passing with commit 3a83f0342e54.  However,
supporting a changed ld output format is not so simple, and the change
to the loongarch_elf_hash_table macro needs further changes to the
rest of the code.  It is true that some uses of
loongarch_elf_hash_table do not need to check the type of the hash
table, but others like loongarch_elf_relax_section do need to check.
bfd_relax_section is called in lang_size_sections using the input bfd,
not the output bfd.  If the input bfd may be of different type to the
output, then the hash table type must be checked before accessing
elements of the hash table.  This patch corrects
loongarch_elf_relax_section.  I haven't checked all the uses of the
hash table throughout the loongarch backend.

bfd/
* elfnn-loongarch.c (loongarch_elf_relax_section): Don't relax
unless the hash table is loongarch_elf_link_hash_table.
Move variable declarations.  Formatting.
ld/
* testsuite/ld-elf/pr21884.d: Don't xfail loongarach.
* testsuite/ld-unique/pr21529.d: Likewise.

10 months agoAutomatic date update in version.in
GDB Administrator [Wed, 7 Aug 2024 00:00:28 +0000 (00:00 +0000)] 
Automatic date update in version.in

10 months agoMark unavailable bytes of limited-length arrays when allocating contents
Hannes Domani [Tue, 6 Aug 2024 17:34:18 +0000 (19:34 +0200)] 
Mark unavailable bytes of limited-length arrays when allocating contents

Using 'output' to print arrays larger than max-value-size, with only
repeating elements, can cause gdb to crash:
```
$ cat a.c:
char a[1000000];

int main()
{
  return a[0];
}
$ gdb -q a
(gdb) print a
$1 = {0 '\000' <repeats 65536 times>, <unavailable> <repeats 934464 times>}
(gdb) output a

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
```

Using 'print' works, because value::record_latest sets the unavailable
bytes of the value when it's added to the value history.
But 'outout' doesn't do that, so the printing tries to access more bytes
than are available.

The original problem in PR32015 was about using 'print' of a dynamic
array in a D program.
Here the crash happens because for 'print' the value was a struct with
length/ptr fields, which is converted in d-valprint.c into an array.
So value::record_latest didn't have a chance to mark the unavailable
bytes in this case.

To make sure the unavailable bytes always match the contents, this fixes
it by marking the unavailable bytes immediately after the contents are
allocated.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32015
Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
10 months agogas: scfi: replace verbose expressions with local vars
Indu Bhagat [Tue, 6 Aug 2024 16:46:06 +0000 (09:46 -0700)] 
gas: scfi: replace verbose expressions with local vars

Replace the scattered and repeated uses of verbose expressions with
variables.  E.g.,
  ginsn_get_src_reg (src1)  -> src1_reg
  ginsn_get_src_type (src1) -> src1_type
etc.

This hopefully makes the logic bit more maintainable.  While at it,
include minor adjustments to make few checks in gen_scfi_ops () more
precise:
  - When getting imm value from src operand, ensure the src type is
    GINSN_SRC_IMM,
  - When getting reg from src operand, ensure the src type is checked
    too (GINSN_SRC_REG or GINSN_SRC_INDIRECT as appropriate).

On the other hand, the changes in verify_heuristic_traceable_reg_fp ()
and verify_heuristic_traceable_stack_manipulation () are purely
mechanical.

gas/
        * scfi.c (verify_heuristic_traceable_reg_fp): Add new local
vars and reuse them.
        (verify_heuristic_traceable_stack_manipulation): Likewise.
        (gen_scfi_ops): Likewise.  Additionally, make some conditionals
more precise.

10 months agoRISC-V: map zext.h to pack/packw if Zbkb is enabled
Hau Hsu [Tue, 6 Aug 2024 03:56:18 +0000 (11:56 +0800)] 
RISC-V: map zext.h to pack/packw if Zbkb is enabled

The `zext.h` is zero-extend halfword instruction that belongs to Zbb.
Currently `zext.h` falls back to 2 shifts if Zbb is not enabled.  However, the
encoding and operation is a special case of `pack/packw rd, rs1, rs2`, which
belongs to Zbkb.  The instructions pack the low halves of rs1 and rs2 into rd.
When rs2 is zero (x0), they behave like zero-extend instruction, and the
encoding are exactly the same as zext.h.

Thus we can map `zext.h` to `pack` or `packw` (rv64) if Zbkb is enabled,
instead of 2 shifts. This reduces one instruction.

This patch does this by making `zext.h` also available for Zbkb.

opcodes/
* riscv-opc.c (riscv_opcodes): Update `zext.h` entries to use
`ZBB_OR_ZBKB` instruction class.

gas/
* testsuite/gas/riscv/zext-to-pack.s: Add test for mapping zext to
pack/packw encoding.
* testsuite/gas/riscv/zext-to-pack-encoding.d: Likewise.
* testsuite/gas/riscv/zext-to-packw-encoding.d: Likewise.

10 months agoRISC-V: Add support for XCvBitmanip extension in CV32E40P
Mary Bennett [Sun, 4 Aug 2024 17:12:26 +0000 (18:12 +0100)] 
RISC-V: Add support for XCvBitmanip extension in CV32E40P

Spec: https://docs.openhwgroup.org/projects/cv32e40p-user-manual/en/latest/instruction_set_extensions.html

Contributors:
  Mary Bennett <mary.bennett682@gmail.com>
  Nandni Jamnadas <nandni.jamnadas@embecosm.com>
  Pietra Ferreira <pietra.ferreira@embecosm.com>
  Charlie Keaney
  Jessica Mills
  Craig Blackmore <craig.blackmore@embecosm.com>
  Simon Cook <simon.cook@embecosm.com>
  Jeremy Bennett <jeremy.bennett@embecosm.com>
  Helene Chelin <helene.chelin@embecosm.com>

bfd/ChangeLog:
* elfxx-riscv.c (riscv_multi_subset_supports): Add `xcvbitmanip`
instruction class.
(riscv_multi_subset_supports_ext): Likewise.

gas/ChangeLog:
* config/tc-riscv.c (validate_riscv_insn): Add custom operands `Xc6` and `Xc7`.
(riscv_ip): Likewise.
* doc/c-riscv.texi: Note XCVbitmanip as an additional ISA extension
for CORE-V.
* testsuite/gas/riscv/march-help.l: Add xcvbitmanip.
* testsuite/gas/riscv/x-cv-bitmanip-fail.d: New Test.
* testsuite/gas/riscv/x-cv-bitmanip-fail.l: New Test.
* testsuite/gas/riscv/x-cv-bitmanip-fail.s: New Test.
* testsuite/gas/riscv/x-cv-bitmanip.d: New Test.
* testsuite/gas/riscv/x-cv-bitmanip.s: New Test.

include/opcode/ChangeLog:
* riscv-opc.h: Add corresponding MATCH and MASK macros for
XCVbitmanip.
* riscv.h: Add corresponding EXTRACT and ENCODE macros for
XCVbitmanip.
(enum riscv_insn_class): Add the XCVbitmanip instruction class.

opcodes/ChangeLog:
* riscv-dis.c (print_insn_args): Add custom operands `Xc6` and `Xc7`.
* riscv-opc.c: Add XCvBitmanip instructions.

10 months agoRISC-V: Add support for Zcmop extension
Xiao Zeng [Wed, 12 Jun 2024 01:28:18 +0000 (09:28 +0800)] 
RISC-V: Add support for Zcmop extension

This implements the Zcmop (Compressed Zimop) extension, as of version 1.0.

View detailed information in:
<https://github.com/riscv/riscv-isa-manual/blob/main/src/zimop.adoc>

The Zcmop extension requires the Zca extension.

bfd/ChangeLog:

* elfxx-riscv.c (riscv_multi_subset_supports): Handle Zcmop.
(riscv_multi_subset_supports_ext): Ditto.

gas/ChangeLog:

* NEWS: Updated.
* testsuite/gas/riscv/march-help.l: Ditto.
* testsuite/gas/riscv/zcmop.d: New test.
* testsuite/gas/riscv/zcmop.s: New test.

include/ChangeLog:

* opcode/riscv-opc.h (DECLARE_INSN): New declarations for Zcmop.
(MATCH_C_MOP_1, MATCH_C_MOP_3, MATCH_C_MOP_5, MATCH_C_MOP_7,
MATCH_C_MOP_9, MATCH_C_MOP_11, MATCH_C_MOP_13, MATCH_C_MOP_15): Define.
(MASK_C_MOP_1, MASK_C_MOP_3, MASK_C_MOP_5, MASK_C_MOP_7,
MASK_C_MOP_9, MASK_C_MOP_11, MASK_C_MOP_13, MASK_C_MOP_15): Ditto.
* opcode/riscv.h (enum riscv_insn_class): Add INSN_CLASS_ZCMOP.

opcodes/ChangeLog:

* riscv-opc.c: Add Zcmop instructions.

10 months agoRISC-V: Add support for Zimop extension
Xiao Zeng [Wed, 12 Jun 2024 01:28:17 +0000 (09:28 +0800)] 
RISC-V: Add support for Zimop extension

This implements the Zimop (May-Be-Operations) extension, as of version 1.0.

View detailed information in:
<https://github.com/riscv/riscv-isa-manual/blob/main/src/zimop.adoc>

bfd/ChangeLog:

* elfxx-riscv.c (riscv_multi_subset_supports): Handle Zimop
(riscv_multi_subset_supports_ext): Ditto.

gas/ChangeLog:

* NEWS: Updated.
* testsuite/gas/riscv/march-help.l: Ditto.
* testsuite/gas/riscv/zimop.d: New test.
* testsuite/gas/riscv/zimop.s: New test.

include/ChangeLog:

* opcode/riscv-opc.h (DECLARE_INSN): New declarations for Zimop.
(MATCH_MOP_R_0, MATCH_MOP_R_1, MATCH_MOP_R_2, MATCH_MOP_R_3,
MATCH_MOP_R_4, MATCH_MOP_R_5, MATCH_MOP_R_6, MATCH_MOP_R_7,
MATCH_MOP_R_8, MATCH_MOP_R_9, MATCH_MOP_R_10, MATCH_MOP_R_11,
MATCH_MOP_R_12, MATCH_MOP_R_13, MATCH_MOP_R_14, MATCH_MOP_R_15,
MATCH_MOP_R_16, MATCH_MOP_R_17, MATCH_MOP_R_18, MATCH_MOP_R_19,
MATCH_MOP_R_20, MATCH_MOP_R_21, MATCH_MOP_R_22, MATCH_MOP_R_23,
MATCH_MOP_R_24, MATCH_MOP_R_25, MATCH_MOP_R_26, MATCH_MOP_R_27,
MATCH_MOP_R_28, MATCH_MOP_R_29, MATCH_MOP_R_30, MATCH_MOP_R_31,
MATCH_MOP_RR_0, MATCH_MOP_RR_1, MATCH_MOP_RR_2, MATCH_MOP_RR_3,
MATCH_MOP_RR_4, MATCH_MOP_RR_5, MATCH_MOP_RR_6, MATCH_MOP_RR_7): Define.
(MASK_MOP_R_0, MASK_MOP_R_1, MASK_MOP_R_2, MASK_MOP_R_3, MASK_MOP_R_4,
MASK_MOP_R_5, MASK_MOP_R_6, MASK_MOP_R_7, MASK_MOP_R_8, MASK_MOP_R_9,
MASK_MOP_R_10, MASK_MOP_R_11, MASK_MOP_R_12, MASK_MOP_R_13,
MASK_MOP_R_14, MASK_MOP_R_15, MASK_MOP_R_16, MASK_MOP_R_17,
MASK_MOP_R_18, MASK_MOP_R_19, MASK_MOP_R_20, MASK_MOP_R_21,
MASK_MOP_R_22, MASK_MOP_R_23, MASK_MOP_R_24, MASK_MOP_R_25,
MASK_MOP_R_26, MASK_MOP_R_27, MASK_MOP_R_28, MASK_MOP_R_29,
MASK_MOP_R_30, MASK_MOP_R_31, MASK_MOP_RR_0, MASK_MOP_RR_1,
MASK_MOP_RR_2, MASK_MOP_RR_3, MASK_MOP_RR_4, MASK_MOP_RR_5,
MASK_MOP_RR_6, MASK_MOP_RR_7): Ditto.
* opcode/riscv.h (enum riscv_insn_class): Add INSN_CLASS_ZIMOP.

opcodes/ChangeLog:

* riscv-opc.c: Add Zimop instructions.

10 months agoAutomatic date update in version.in
GDB Administrator [Tue, 6 Aug 2024 00:00:29 +0000 (00:00 +0000)] 
Automatic date update in version.in

10 months agogdb: rename gdbarch.c to gdbarch-gen.c
Simon Marchi [Wed, 31 Jul 2024 18:34:53 +0000 (14:34 -0400)] 
gdb: rename gdbarch.c to gdbarch-gen.c

For clarity and symmetry with `gdbarch-gen.h`.  I wouldn't mind
if all generated files had the `-gen` suffix.

Change-Id: Icb70194fb0e3e2fa9d1c6f0d9331be09b805b428
Approved-By: John Baldwin <jhb@FreeBSD.org>
10 months agogas: maintain line numbers correctly after #APP / #NO_APP
Jan Beulich [Mon, 5 Aug 2024 14:29:54 +0000 (16:29 +0200)] 
gas: maintain line numbers correctly after #APP / #NO_APP

Maintaining line numbers correctly both inside the region and past it
requires special care. The SB produced there is somewhat different from
that produced for e.g. macro expansions, and hence also needs treating
differently: In particular we aren't doing anything resembling macro
expansion here.

The new testcase may be a little misplaced in macros/, but that's where
all the other #APP / #NO_APP ones are.

10 months agogas: generalize / tighten #APP / #NO_APP recognition
Jan Beulich [Mon, 5 Aug 2024 14:29:28 +0000 (16:29 +0200)] 
gas: generalize / tighten #APP / #NO_APP recognition

For one '#' may not be in line_comment_chars[] in the first place. Look
for just it when it is (these "directives" are akin to C preprocessor
directives after all), but accept any other line comment character
otherwise (in read.c further requiring a match on the counterpart
"directive").

Then, when in the middle of a file, the constructs should be all on
their own on a line.  There needs to be a newline ahead of them and
after them.

Finally '\n' may not be the only end-of-line character. Accept any (but
not end-of-statement ones) in read.c, while making sure in input-file.c
there is one in the first place - merely any kind of whitespace isn't
good enough.

10 months agogas: recognize #APP at start-of-physical-line only
Jan Beulich [Mon, 5 Aug 2024 14:28:43 +0000 (16:28 +0200)] 
gas: recognize #APP at start-of-physical-line only

It's not valid to recognize it after mere line separators (often
semicolon) or after labels, let alone after tc_unrecognized_line()
perhaps having parsed off parts of a line. It shouldn't even be
preceded by whitespace, aiui.

However, keep ignoring line comments as before, for backwards
compatibility.

10 months ago[gdb] Notice when stepping into different file
Tom de Vries [Mon, 5 Aug 2024 12:00:42 +0000 (14:00 +0200)] 
[gdb] Notice when stepping into different file

Consider the following test-case:
...
$ cat -n test.c
     1 int var;
     2
     3 int
     4 foo (void)
     5 {
     6   var = 1;
     7 #include "test.h"
     8 }
     9
    10 int
    11 main ()
    12 {
    13   return foo ();
    14 }
$ cat -n test.h
     1   return 1;
$ gcc test.c -g
...

When stepping through the test-case, gdb doesn't make it explicit that line 1
is not in test.c:
...
Temporary breakpoint 1, main () at test.c:13
13   return foo ();
(gdb) step
foo () at test.c:6
6   var = 1;
(gdb) n
1   return 1;
(gdb)
8 }
(gdb)
...
which makes it easy to misinterpret the output.

This is with the default "print frame-info" == auto, with documented
behaviour [1]:
...
stepi will switch between source-line and source-and-location depending on the
program counter.
...

What is actually implemented is that source-line is used unless stepping into
or out of a function.

The problem can be worked around by using
"set print frame-info source-and-location", but that's a bit verbose.

Instead, change the behaviour of "print frame-info" == auto to also use
source-and-location when stepping into another file, which gets us:
...
(gdb) n
foo () at test.h:1
1   return 1;
...

Tested on x86_64-linux.

Reviewed-By: Kevin Buettner <kevinb@redhat.com>
Reviewed-By: Kévin Le Gouguec <legouguec@adacore.com>
PR gdb/32011
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32011

[1] https://sourceware.org/gdb/current/onlinedocs/gdb.html/Print-Settings.html#index-set-print-frame_002dinfo

10 months agoLoongArch: Add support for OUTPUT_FORMAT("binary")
mengqinggang [Fri, 28 Jun 2024 06:24:19 +0000 (14:24 +0800)] 
LoongArch: Add support for OUTPUT_FORMAT("binary")

In binary output format, loongarch_elf_hash_table return NULL and result
in segment fault.

When ld output binary file, it seems that elf related functions should
not be called. But loongarch_elf_relax_section be called and
loongarch_elf_hash_table cause segment fault.

Just redefined loongarch_elf_hash_table and always return
link_info->hash.

The tests of binutils, glibc and gcc is ok.

0  loongarch_elf_relax_section ()
1  0x000055555557ab28 in lang_size_sections_1 ()
2  0x000055555557a16c in lang_size_sections_1 ()
3  0x000055555557b0a8 in one_lang_size_sections_pass ()
4  0x000055555557b478 in lang_size_sections ()
5  0x000055555557e65c in lang_relax_sections ()
6  0x000055555559f9c8 in ldelf_map_segments ()
7  0x000055555559783c in gldelf64loongarch_after_allocation ()
8  0x000055555558dac0 in ldemul_after_allocation ()
9  0x000055555557f6c0 in lang_process ()
10 0x0000555555585314 in main ()

10 months agoAutomatic date update in version.in
GDB Administrator [Mon, 5 Aug 2024 00:00:29 +0000 (00:00 +0000)] 
Automatic date update in version.in

10 months agoUpdate release-README after completing the 2.43 release.
Nick Clifton [Sun, 4 Aug 2024 16:47:49 +0000 (17:47 +0100)] 
Update release-README after completing the 2.43 release.

10 months agoAutomatic date update in version.in
GDB Administrator [Sun, 4 Aug 2024 00:00:28 +0000 (00:00 +0000)] 
Automatic date update in version.in

10 months agoLTO: Restore the wrapper symbol check for standard function
H.J. Lu [Sat, 3 Aug 2024 02:52:00 +0000 (19:52 -0700)] 
LTO: Restore the wrapper symbol check for standard function

Call unwrap_hash_lookup to restore the wrapper symbol check for standard
function since reference to standard function may not show up in LTO
symbol table:

[hjl@gnu-tgl-3 pr31956-3]$ nm foo.o
00000000 T main
         U __real_malloc
00000000 T __wrap_malloc
[hjl@gnu-tgl-3 pr31956-3]$  lto-dump -list foo.o
Type   Visibility  Size  Name
function  default     0  malloc
function  default     0  __real_malloc
function  default     3  main
function  default     5  __wrap_malloc
[hjl@gnu-tgl-3 pr31956-3]$ make
gcc -O2 -flto -Wall   -c -o foo.o foo.c
gcc -Wl,--wrap=malloc -O2 -flto -Wall -o x foo.o
/usr/local/bin/ld: /tmp/ccsPW0a9.ltrans0.ltrans.o: in function `main':
<artificial>:(.text.startup+0xa): undefined reference to `__wrap_malloc'
collect2: error: ld returned 1 exit status
make: *** [Makefile:22: x] Error 1
[hjl@gnu-tgl-3 pr31956-3]$

Also add a test to verify that the unused wrapper is removed.

PR ld/31956
* plugin.c (get_symbols): Restore the wrapper symbol check for
standard function.
* testsuite/ld-plugin/lto.exp: Run the malloc test and the
unused test.
* testsuite/ld-plugin/pr31956c.c: New file.
* testsuite/ld-plugin/pr31956d.c: New file.
* testsuite/ld-plugin/pr31956d.d: New file.

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

10 months agogdb, gdbserver, gdbsupport: remove -Wno-vla-cxx-extension
Simon Marchi [Wed, 31 Jul 2024 18:06:13 +0000 (14:06 -0400)] 
gdb, gdbserver, gdbsupport: remove -Wno-vla-cxx-extension

Now that all known uses of VLAs within GDB are removed, remove the
`-Wno-vla-cxx-extension` (which was used to silence clang warnings) and
add `-Wvla`, such that any use of a VLA will trigger a warning.

Change-Id: I69a8d7f93f973743165b0ba46f9c2ea8adb89025
Reviewed-By: Keith Seitz <keiths@redhat.com>
10 months agogdb: remove uses of VLA
Simon Marchi [Wed, 31 Jul 2024 18:06:12 +0000 (14:06 -0400)] 
gdb: remove uses of VLA

Remove uses of VLAs, replace with gdb::byte_vector.  There might be more
in files that I can't compile, but it's difficult to tell without
actually compiling on all platforms.

Many thanks to the Linaro pre-commit CI for helping find some problems
with an earlier iteration of this patch.

Change-Id: I3e5e34fcac51f3e6b732bb801c77944e010b162e
Reviewed-by: Keith Seitz <keiths@redhat.com>
10 months agogdb,testsuite: fix gdb.base/list-dot-nodebug and make it more robust
Guinevere Larsen [Fri, 31 May 2024 13:48:54 +0000 (10:48 -0300)] 
gdb,testsuite: fix gdb.base/list-dot-nodebug and make it more robust

Thiago Jung Bauermann noticed that gdb.base/list-dot-nodebug was not
actually compiling the test with some debuginfo in the relevant part,
and while fixing I noticed that the base assumption of the "some" case
was wrong, GDB would select some symtab as a default location and the
test would always fail. This fix makes printing the default location
only be tested when there is no debuginfo.

When testing with no debuginfo, if a system had static libc debuginfo,
the test would also fail. To add an extra layer of robustness to the
test, this rewrite also strips any stray debuginfo from the executable.
The test would only fail now if it runs in a system that can't handle
stripped debuginfo and has static debuginfo pre-installed.

Reported-By: Tom de Vries <tdevries@suse.de>
Reported-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31721
Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Approved-By: Andrew Burgess <aburgess@redhat.com>
10 months agogdb: remove inline_frame::skipped_frames
Simon Marchi [Tue, 30 Jul 2024 14:47:58 +0000 (10:47 -0400)] 
gdb: remove inline_frame::skipped_frames

While reviewing [1], it occurred to me that having both the
skipped_frames counter and the skipped_syms vector is redundant.  When
stepping into an inline frame, we can just pop the last element.

[1] https://inbox.sourceware.org/gdb-patches/96cfee31-6a50-4a78-a25b-67e5d061c2a3@simark.ca/T/#m7e0e4b5b6cfc91be3d8ab6d5025a97c2e647103a

Change-Id: I8c10e7fcd05e41c2c838431d06c9e793d18a2198
Approved-By: Andrew Burgess <aburgess@redhat.com>
10 months agoUpdated Bulgarian translation for the binutils/ directory
Nick Clifton [Fri, 2 Aug 2024 14:40:14 +0000 (15:40 +0100)] 
Updated Bulgarian translation for the binutils/ directory

10 months agoFix typo in --help output of the strings program.
Aapo Rantalainen [Fri, 2 Aug 2024 14:13:44 +0000 (15:13 +0100)] 
Fix typo in --help output of the strings program.

  PR 31940

10 months agogdb/testsuite: fix gdb.python/py-framefilter-invalidarg.exp with clang
Guinevere Larsen [Wed, 31 Jul 2024 14:13:25 +0000 (11:13 -0300)] 
gdb/testsuite: fix gdb.python/py-framefilter-invalidarg.exp with clang

The final test of gdb.python/py-framefilter-invalidarg.exp expected that
the the backtrace only printed the source file name. However, when using
clang, gdb will always print the full path to the file, which would
cause the test to fail. This commit introduces a regexp that optionally
matches paths, preprended to the file name, which fixes the clang
failure without introducing gcc failures.

Approved-By: Andrew Burgess <aburgess@redhat.com>
10 months agogdb/testsuite: extend XFAIL to gdb.fortran/entry-point.exp to clang too
Guinevere Larsen [Tue, 30 Jul 2024 17:36:45 +0000 (14:36 -0300)] 
gdb/testsuite: extend XFAIL to gdb.fortran/entry-point.exp to clang too

The test gdb.fortran/entry-point.exp already has an XFAIL when trying to
set a breakpoint in mod::mod_foo because gcc puts that subprogram in the
wrong scope in the debug information. Clang's debug information looks
the same as gcc's, so the test to setup the xfail has been extended to
also include clang.

Approved-By: Andrew Burgess <aburgess@redhat.com>
10 months agogdb/testsuite: add build-id compile flag to tests that expect it
Guinevere Larsen [Wed, 31 Jul 2024 14:23:51 +0000 (11:23 -0300)] 
gdb/testsuite: add build-id compile flag to tests that expect it

Clang doesn't add build-id information by default, unlike gcc. This
means that tests that rely on build-id being available and don't
explicitly add it to the compilation options will fail with clang.
This commit fixes the fails in gdb.python/py-missing-debug.exp,
gdb.server/remote-read-msgs.exp, gdb.base/coredump-filter-build-id.exp
and gdb.server/solib-list.exp

Approved-By: Andrew Burgess <aburgess@redhat.com>
10 months agogas: drop unnecessary use of tc_comment_chars
Jan Beulich [Fri, 2 Aug 2024 07:44:53 +0000 (09:44 +0200)] 
gas: drop unnecessary use of tc_comment_chars

The override is necessary only when a target needs other than an array
of const char.

For cris drop redundant sibling declarations at the same time.

10 months agogas: correctly deal with line comments when not preprocessing
Jan Beulich [Fri, 2 Aug 2024 07:43:58 +0000 (09:43 +0200)] 
gas: correctly deal with line comments when not preprocessing

Internal naming of functions / data as well as commentary mixes lines
and statements. It is presumably this confusion which has led to the
wrong use of ignore_rest_of_line() when dealing with line comments in
read_a_source_file(). We shall not (silently) produce different output
depending on whether -f is passed (for suitable input).

Introduce two new helper macros, intended to be used in favor of open-
coded accesses to is_end_of_line[]. To emphasize the difference, convert
ignore_rest_of_line() right away, including adjustments to its comments.

Since most targets have # in line_comment_chars[], add a target-
independent test for that, plus an x86-only one also checking for non-#
to work as intended.

10 months agoAutomatic date update in version.in
GDB Administrator [Fri, 2 Aug 2024 00:00:31 +0000 (00:00 +0000)] 
Automatic date update in version.in

10 months agogas: ginsn: minor improvements in ginsn_dst_print and ginsn_src_print
Indu Bhagat [Thu, 1 Aug 2024 18:50:10 +0000 (11:50 -0700)] 
gas: ginsn: minor improvements in ginsn_dst_print and ginsn_src_print

Keep the two symmetrical looking.  Makes sense to perform the sanity
checks similarly too.

gas/
        * ginsn.c (ginsn_src_print): Buffer up result of snprintf and
add sanity checks on the value.
        (ginsn_dst_print): Use switch case instead.

10 months agogas: ginsn: do not emit an unnecessary trailing comma in textual dump
Indu Bhagat [Thu, 1 Aug 2024 18:34:08 +0000 (11:34 -0700)] 
gas: ginsn: do not emit an unnecessary trailing comma in textual dump

For ginsns with less than 2 source operands or no destination operands,
the current textual dump contains a superfluous comma, like the relevant
testcases show.

Adjust the code a bit to not emit the lone trailing comma.  Also, adjust
the aarch64 and x86_64 testcases.

gas/
        * ginsn.c (ginsn_src_print): Do not use a trailing comma when
printing the src of ginsn.
        (ginsn_print): Check the strlen and prefix a comma before the
src string.

gas/testsuite/
* gas/scfi/aarch64/ginsn-cofi-1.l: Adjust the expected textual
dump of the ginsn.
* gas/scfi/x86_64/ginsn-cofi-1.l: Likewise.

10 months agogas: x86: ginsn: handle previously missed indirect call and jmp ops
Indu Bhagat [Thu, 1 Aug 2024 17:07:07 +0000 (10:07 -0700)] 
gas: x86: ginsn: handle previously missed indirect call and jmp ops

Some flavors of indirect call and jmp instructions were not being
handled earlier, leading to a GAS error (#1):
  (#1) "Error: SCFI: unhandled op 0xff may cause incorrect CFI"

Not handling jmp/call (direct or indirect) ops is an error (as shown
above) because SCFI needs an accurate CFG to synthesize CFI correctly.
Recall that the presence of indirect jmp/call, however, does make the
CFG ineligible for SCFI. In other words, generating the ginsns for them
now, will eventually cause SCFI to bail out later with an error (#2)
anyway:
  (#2) "Error: untraceable control flow for func 'XXX'"

The first error (#1) gives the impression of missing functionality in
GAS.  So, it seems cleaner to synthesize a GINSN_TYPE_JUMP /
GINSN_TYPE_CALL now in the backend, and let SCFI machinery complain with
the error as expected.

The handling for these indirect jmp/call instructions is similar, so
reuse the code by carving out a function for the same.

Adjust the testcase to include the now handled jmp/call instructions as
well.

gas/
* config/tc-i386-ginsn.c (x86_ginsn_indirect_branch): New
function.
(x86_ginsn_new): Refactor out functionality to above.

gas/testsuite/
* gas/scfi/x86_64/ginsn-cofi-1.l: Adjust the output.
* gas/scfi/x86_64/ginsn-cofi-1.s: Add further varieties of
jmp/call opcodes.

10 months agogdb: LoongArch: Add show-debug-regs maintenance command
Hui Li [Tue, 30 Jul 2024 11:41:05 +0000 (19:41 +0800)] 
gdb: LoongArch: Add show-debug-regs maintenance command

This patch register the command "maint set show-debug-regs on/off"
and make it settable by the user. If show-debug-regs is enabled,
the debug register values are shown when GDB inserts or removes a
hardware breakpoint or watchpoint. This is helpful for the use and
development of hardware watchpoints.

With this patch, the effect of this maintenance command as follows:

lihui@bogon:~$ cat test.c
int a = 0;
int main()
{
a = 1;
return 0;
}
lihui@bogon:~$ gcc -g test.c -o test
lihui@bogon:~$ gdb test
...
(gdb) watch a
Hardware watchpoint 1: a
(gdb) maint set show-debug-regs on
(gdb) r
Starting program: /home/lihui/test
...
...

prepare_to_resume thread 41525
...
insert_watchpoint (addr=0x12000803c, len=4, type=hw-write-watchpoint):
BREAKPOINTs:
BP0: addr=0x0, ctrl=0x00000000, ref.count=0
BP1: addr=0x0, ctrl=0x00000000, ref.count=0
BP2: addr=0x0, ctrl=0x00000000, ref.count=0
BP3: addr=0x0, ctrl=0x00000000, ref.count=0
BP4: addr=0x0, ctrl=0x00000000, ref.count=0
BP5: addr=0x0, ctrl=0x00000000, ref.count=0
BP6: addr=0x0, ctrl=0x00000000, ref.count=0
BP7: addr=0x0, ctrl=0x00000000, ref.count=0
WATCHPOINTs:
WP0: addr=0x0, ctrl=0x00000000, ref.count=0
WP1: addr=0x0, ctrl=0x00000000, ref.count=0
WP2: addr=0x0, ctrl=0x00000000, ref.count=0
WP3: addr=0x0, ctrl=0x00000000, ref.count=0
WP4: addr=0x0, ctrl=0x00000000, ref.count=0
WP5: addr=0x0, ctrl=0x00000000, ref.count=0
WP6: addr=0x0, ctrl=0x00000000, ref.count=0
WP7: addr=0x12000803c, ctrl=0x00000610, ref.count=1
...
remove_watchpoint (addr=0x12000803c, len=4, type=hw-write-watchpoint):
BREAKPOINTs:
BP0: addr=0x0, ctrl=0x00000000, ref.count=0
BP1: addr=0x0, ctrl=0x00000000, ref.count=0
BP2: addr=0x0, ctrl=0x00000000, ref.count=0
BP3: addr=0x0, ctrl=0x00000000, ref.count=0
BP4: addr=0x0, ctrl=0x00000000, ref.count=0
BP5: addr=0x0, ctrl=0x00000000, ref.count=0
BP6: addr=0x0, ctrl=0x00000000, ref.count=0
BP7: addr=0x0, ctrl=0x00000000, ref.count=0
WATCHPOINTs:
WP0: addr=0x0, ctrl=0x00000000, ref.count=0
WP1: addr=0x0, ctrl=0x00000000, ref.count=0
WP2: addr=0x0, ctrl=0x00000000, ref.count=0
WP3: addr=0x0, ctrl=0x00000000, ref.count=0
WP4: addr=0x0, ctrl=0x00000000, ref.count=0
WP5: addr=0x0, ctrl=0x00000000, ref.count=0
WP6: addr=0x0, ctrl=0x00000000, ref.count=0
WP7: addr=0x0, ctrl=0x00000000, ref.count=0

Hardware watchpoint 1: a

Old value = 0
New value = 1
main () at test.c:5
5 return 0;
(gdb)

Signed-off-by: Hui Li <lihui@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
10 months agoskip_attr_bytes assertion (data) <= (end) fail
Alan Modra [Thu, 1 Aug 2024 11:06:42 +0000 (20:36 +0930)] 
skip_attr_bytes assertion (data) <= (end) fail

get_type_abbrev_from_form is lax in not limiting data for a uleb to
the current CU, because DW_FORM_ref_addr allows access to other CU's
data.  This can lead to an assertion fail when skipping or reading
attributes in get_type_signedness.

* dwarf.c (get_type_abbrev_from_form): Limit uleb data to map end
for ref_addr, cu_end otherwise.

10 months agogdb: AArch64: Support MTE on baremetal
Gustavo Romero [Tue, 30 Jul 2024 14:39:36 +0000 (14:39 +0000)] 
gdb: AArch64: Support MTE on baremetal

This commit moves aarch64_linux_memtag_matches_p,
aarch64_linux_set_memtags, aarch64_linux_get_memtag, and
aarch64_linux_memtag_to_string hooks (plus the aarch64_mte_get_atag
function used by them), along with the setting of the memtag granule
size, from aarch64-linux-tdep.c to aarch64-tdep.c, making MTE available
on baremetal targets. Since the aarch64-linux-tdep.c layer inherits
these hooks from aarch64-tdep.c, there is no effective change for
aarch64-linux targets.

Helpers used both by aarch64-tdep.c and by aarch64-linux-tdep.c were
moved from arch/aarch64-mte-linux.{c,h} to new arch/aarch64-mte.{c,h}
files.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
Tested-By: Luis Machado <luis.machado@arm.com>
Approved-By: Luis Machado <luis.machado@arm.com>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
10 months ago[gdb/testsuite] Fix gdb.python/py-format-string.exp with python 3.13
Tom de Vries [Thu, 1 Aug 2024 07:23:24 +0000 (09:23 +0200)] 
[gdb/testsuite] Fix gdb.python/py-format-string.exp with python 3.13

On fedora rawhide, with python 3.13, I run into:
...
(gdb) python print (gdb.parse_and_eval ('a_point_t').format_string (invalid=True))^M
Python Exception <class 'TypeError'>: \
  this function got an unexpected keyword argument 'invalid'^M
Error occurred in Python: \
  this function got an unexpected keyword argument 'invalid'^M
(gdb) FAIL: $exp: format_string: lang_c: test_all_common: test_invalid_args: \
  a_point_t with option invalid=True
...

A passing version with an older python version looks like:
...
(gdb) python print (gdb.parse_and_eval ('a_point_t').format_string (invalid=True))^M
Python Exception <class 'TypeError'>: \
  'invalid' is an invalid keyword argument for this function^M
Error occurred in Python: \
  'invalid' is an invalid keyword argument for this function^M
(gdb) PASS: $exp: format_string: lang_c: test_all_common: test_invalid_args: \
  a_point_t with option invalid=True
...

Fix this by accepting the updated error message.

Tested on aarch64-linux.

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

10 months agoLoongArch: Fix ld FAIL test cases
Lulu Cai [Wed, 17 Jul 2024 02:54:46 +0000 (10:54 +0800)] 
LoongArch: Fix ld FAIL test cases

To avoid differences in C library paths on different systems
use gcc instead of ld to perform the test.

Problems caused by adding options to different distributions
will not be fixed.

10 months agold/PDB: handle empty LF_FIELDLIST types
Mark Harmstone [Mon, 29 Jul 2024 21:19:36 +0000 (22:19 +0100)] 
ld/PDB: handle empty LF_FIELDLIST types

Empty structs in C++ lead to empty LF_FIELDLIST types in the .debug$T
section, but we were mistakenly rejecting these as invalid. Allow
CodeView types of two bytes, and add a test for this.

10 months agoAutomatic date update in version.in
GDB Administrator [Thu, 1 Aug 2024 00:00:43 +0000 (00:00 +0000)] 
Automatic date update in version.in

10 months agolibctf: fix ctf_archive_count return value on big-endian
Nick Alcock [Tue, 30 Jul 2024 11:28:04 +0000 (12:28 +0100)] 
libctf: fix ctf_archive_count return value on big-endian

This failed to properly byteswap its return value.

The ctf_archive format predates the idea of "just write natively and
flip on open", and byteswaps all over the place.  It's too easy to
forget one.  The next revision of the archive format (not versioned,
so we just tweak the magic number instead) should be native-endianned
like the dicts inside it are.

libctf/
* ctf-archive.c (ctf_archive_count): Byteswap return value.

10 months agolibctf: dump: fix small leak
Nick Alcock [Mon, 29 Jul 2024 17:02:03 +0000 (18:02 +0100)] 
libctf: dump: fix small leak

If you asprintf something and then use it only as input to another asprintf,
it helps to free it afterwards.

libctf/
* ctf-dump.c (ctf_dump_header): Free the flagstr after use.
(ctf_dump): Make a NULL return slightly clearer.

10 months agolibctf: fix ref leak of names of newly-inserted non-root-visible types
Nick Alcock [Mon, 29 Jul 2024 11:45:09 +0000 (12:45 +0100)] 
libctf: fix ref leak of names of newly-inserted non-root-visible types

A bug in ctf_dtd_delete led to refs in the string table to the
names of non-root-visible types not being removed when the DTD
was.  This seems harmless, but actually it would lead to a write
down a pointer into freed memory if such a type was ctf_rollback()ed
over and then the dict was serialized (updating all the refs as the
strtab was serialized in turn).

Bug introduced in commit fe4c2d55634c700ba527ac4183e05c66e9f93c62
("libctf: create: non-root-visible types should not appear in name tables")
which is included in binutils 2.35.

libctf/
* ctf-create.c (ctf_dtd_delete): Remove refs for all types
with names, not just root-visible ones.

10 months agolibctf: clean up hashtab error handling mess
Nick Alcock [Fri, 26 Jul 2024 20:58:03 +0000 (21:58 +0100)] 
libctf: clean up hashtab error handling mess

The dict and archive opening code in libctf is somewhat unusual, because
unlike everything else, it cannot report errors by setting an error on the
dict, because in case of error there isn't one.  They get passed an error
integer pointer that is set on error instead.

Inside ctf_bufopen this is implemented by calling ctf_set_open_errno and
passing it a positive error value.  In turn this means that most things it
calls (including init_static_types) return zero on success and a *positive*
ECTF_* or errno value on error.

This trickles down to ctf_dynhash_insert_type, which is used by
init_static_types to add newly-detected types to the name tables.  This was
returning the error value it received from a variety of functions without
alteration.  ctf_dynhash_insert conformed to this contract by returning a
positive value on error (usually OOM), which is unfortunate for multiple
reasons:

- ctf_dynset_insert returns a *negative* value
- ctf_dynhash_insert and ctf_dynset_insert don't take an fp, so the value
  they return is turned into the errno, so it had better be right, callers
  don't just check for != 0 here
- more or less every single caller of ctf_dyn*_insert in libctf other than
  ctf_dynhash_insert_type (and there are a *lot*, mostly in the
  deduplicator) assumes that ctf_dynhash_insert returns a negative value
  on error, even though it doesn't.  In practice the only possible error is
  OOM, but if OOM does happen we end up with a nonsense error value.

The simplest fix for this seems to be to make ctf_dynhash_insert and
ctf_dynset_insert conform to the usual interface contract: negative
values are errors.  This in turn means that ctf_dynhash_insert_type
needs to change: let's make it consistent too, returning a negative
value on error, putting the error on the fp in non-negated form.

init_static_types_internal adapts to this by negating the error return from
ctf_dynhash_insert_type, so the value handed back to ctf_bufopen is still
positive: the new call site in ctf_track_enumerator does not need to change.

(The existing tests for this reliably detect when I get it wrong.
I know, because they did.)

libctf/
* ctf-hash.c (ctf_dynhash_insert): Negate return value.
(ctf_dynhash_insert_type): Set de-negated error on the dict:
        return negated error.
* ctf-open.c (init_static_types_internal): Adapt to this change.

10 months agolibctf, include: add ctf_dict_set_flag: less enum dup checking by default
Nick Alcock [Fri, 26 Jul 2024 20:38:24 +0000 (21:38 +0100)] 
libctf, include: add ctf_dict_set_flag: less enum dup checking by default

The recent change to detect duplicate enum values and return ECTF_DUPLICATE
when found turns out to perturb a great many callers.  In particular, the
pahole-created kernel BTF has the same problem we historically did, and
gleefully emits duplicated enum constants in profusion.  Handling the
resulting duplicate errors from BTF -> CTF converters reasonably is
unreasonably difficult (it amounts to forcing them to skip some types or
reimplement the deduplicator).

So let's step back a bit.  What we care about mostly is that the
deduplicator treat enums with conflicting enumeration constants as
conflicting types: programs that want to look up enumeration constant ->
value mappings using the new APIs to do so might well want the same checks
to apply to any ctf_add_* operations they carry out (and since they're
*using* the new APIs, added at the same time as this restriction was
imposed, there is likely to be no negative consequence of this).

So we want some way to allow processes that know about duplicate detection
to opt into it, while allowing everyone else to stay clear of it: but we
want ctf_link to get this behaviour even if its caller has opted out.

So add a new concept to the API: dict-wide CTF flags, set via
ctf_dict_set_flag, obtained via ctf_dict_get_flag.  They are not bitflags
but simple arbitrary integers and an on/off value, stored in an unspecified
manner (the one current flag, we translate into an LCTF_* flag value in the
internal ctf_dict ctf_flags word). If you pass in an invalid flag or value
you get a new ECTF_BADFLAG error, so the caller can easily tell whether
flags added in future are valid with a particular libctf or not.

We check this flag in ctf_add_enumerator, and set it around the link
(including on child per-CU dicts).  The newish enumerator-iteration test is
souped up to check the semantics of the flag as well.

The fact that the flag can be set and unset at any time has curious
consequences. You can unset the flag, insert a pile of duplicates, then set
it and expect the new duplicates to be detected, not only by
ctf_add_enumerator but also by ctf_lookup_enumerator.  This means we now
have to maintain the ctf_names and conflicting_enums enum-duplication
tracking as new enums are added, not purely as the dict is opened.
Move that code out of init_static_types_internal and into a new
ctf_track_enumerator function that addition can also call.

(None of this affects the file format or serialization machinery, which has
to be able to handle duplicate enumeration constants no matter what.)

include/
* ctf-api.h (CTF_ERRORS) [ECTF_BADFLAG]: New.
(ECTF_NERR): Update.
(CTF_STRICT_NO_DUP_ENUMERATORS): New flag.
(ctf_dict_set_flag): New function.
(ctf_dict_get_flag): Likewise.

libctf/
* ctf-impl.h (LCTF_STRICT_NO_DUP_ENUMERATORS): New flag.
(ctf_track_enumerator): Declare.
* ctf-dedup.c (ctf_dedup_emit_type): Set it.
* ctf-link.c (ctf_create_per_cu): Likewise.
(ctf_link_deduplicating_per_cu): Likewise.
(ctf_link): Likewise.
(ctf_link_write): Likewise.
* ctf-subr.c (ctf_dict_set_flag): New function.
(ctf_dict_get_flag): New function.
* ctf-open.c (init_static_types_internal): Move enum tracking to...
* ctf-create.c (ctf_track_enumerator): ... this new function.
(ctf_add_enumerator): Call it.
* libctf.ver: Add the new functions.
* testsuite/libctf-lookup/enumerator-iteration.c: Test them.

10 months agoinclude, libctf: improve ECTF_DUPLICATE error message
Nick Alcock [Fri, 26 Jul 2024 20:20:50 +0000 (21:20 +0100)] 
include, libctf: improve ECTF_DUPLICATE error message

It applies to enums now, so it should mention them.

include/
* ctf-api.h (_CTF_ERRORS) ECTF_DUPLICATE]: Mention enums.

10 months agolibctf: link: remember to turn off the LCTF_LINKING flag after ctf_link_write
Nick Alcock [Mon, 15 Jul 2024 22:25:25 +0000 (23:25 +0100)] 
libctf: link: remember to turn off the LCTF_LINKING flag after ctf_link_write

We set this flag at the top of ctf_link_write (to tell ctf_serialize, way
down under the archive file writing functions, to do the various link- time
serialization things like symbol filtering and the like), but we never
remember to clear it except on error.  This is probably bad if you want to
serialize the dict yourself directly in the future after linking it (which
is...  definitely a *possible* use of the API, if rather strange).

libctf/
* ctf-link.c (ctf_link_write): Clear LCTF_LINKING before exit.

10 months agolibctf: link: fix error handling
Nick Alcock [Mon, 15 Jul 2024 21:05:57 +0000 (22:05 +0100)] 
libctf: link: fix error handling

We were calling the wrong error function if opening failed, causing leaks.

libctf/
* ctf-link.c (ctf_link_deduplicating_per_cu): Fix error handling.

10 months agolibctf, open: Fix enum error handling path
Nick Alcock [Mon, 15 Jul 2024 20:05:43 +0000 (21:05 +0100)] 
libctf, open: Fix enum error handling path

This new error-handling path was not properly initializing the
fp's errno.

libctf/
* ctf-open.c (init_static_types_internal): Set errno properly.

10 months agolibctf, subr: don't mix up errors and warnings
Nick Alcock [Mon, 15 Jul 2024 20:04:24 +0000 (21:04 +0100)] 
libctf, subr: don't mix up errors and warnings

ctf_err_warn() was debug-logging warnings as if they were errors and vice
versa.

libctf/
* ctf-subr.c (ctf_err_warn): Fix debugging thinko.

10 months agolibctf: fix dynset insertion
Nick Alcock [Mon, 15 Jul 2024 19:50:25 +0000 (20:50 +0100)] 
libctf: fix dynset insertion

libctf's dynsets are a straight wrapper around libiberty hashtab, storing
the key directly in the hashtab slot.  However, we'd often like to be able
to store 0 and 1 (HTAB_EMPTY_ENTRY and HTAB_DELETED_ENTRY) in there, so we
move them out of the way and replace them with huge unlikely values
instead.  Unfortunately we failed to do this replacement in one place, so
insertion of 0 or 1 ended up misinforming the hashtab machinery that an
entry was empty or deleted when it wasn't.

libctf/
* ctf-hash.c (ctf_dynset_insert): Call key_to_internal properly.

10 months agolibctf: dedup: tiny tweaks
Nick Alcock [Mon, 15 Jul 2024 19:00:59 +0000 (20:00 +0100)] 
libctf: dedup: tiny tweaks

Drop an unnecessary variable, and fix a buggy comment.

No effect on generated code.

libctf/
* ctf-dedup.c (ctf_dedup_detect_name_ambiguity): Drop unnecessary
        variable.
(ctf_dedup_rwalk_output_mapping): Fix comment.

10 months agolibctf: improve ECTF_NOPARENT error message
Nick Alcock [Mon, 15 Jul 2024 18:59:13 +0000 (19:59 +0100)] 
libctf: improve ECTF_NOPARENT error message

This erorr doesn't just indicate that there is no parent dictionary
(that's routine, and true of all dicts that are parents themselves)
but that a parent is *needed* but wasn't found.

include/
* ctf-api.h (_CTF_ERRORS) [ECTF_NOPARENT]: Improve error message.

ld/
* testsuite/ld-ctf/diag-parname.d: Adjust.

10 months agolibctf: fix CTF dict compression
Nick Alcock [Mon, 15 Jul 2024 18:55:40 +0000 (19:55 +0100)] 
libctf: fix CTF dict compression

Commit 483546ce4f3 ("libctf: make ctf_serialize() actually serialize")
accidentally broke dict compression.  There were two bugs:

 - ctf_arc_write_one_ctf was still making its own decision about
   whether to compress the dict via direct ctf_size comparison, which is
   unfortunate because now that it no longer calls ctf_serialize itself,
   ctf_size is always zero when it does this: it should let the writing
   functions decide on the threshold, which they contain code to do which is
   simply not used for lack of one trivial wrapper to write to an fd and
   also provide a compression threshold

 - ctf_write_mem, the function underlying all writing as of the commit
   above, was calling zlib's compressBound and avoiding compression if this
   returned a value larger than the input.  Unfortunately compressBound does
   not do a trial compression and determine whether the result is
   compressible: it just adds zlib header sizes to the value passed in, so
   our test would *always* have concluded that the value was incompressible!
   Avoid by simply always compressing if the raw size is larger than the
   threshold: zlib is quite clever enough to avoid actually compressing
   if the data is incompressible.

Add a testcase for this.

libctf/
* ctf-impl.h (ctf_write_thresholded): New...
* ctf-serialize.c (ctf_write_thresholded): ... defined here,
        a wrapper around...
        (ctf_write_mem): ... this.  Don't check compressibility.
(ctf_compress_write): Reimplement as a ctf_write_thresholded
        wrapper.
(ctf_write): Likewise.
* ctf-archive.c (arc_write_one_ctf): Just call
        ctf_write_thresholded rather than trying to work out whether
        to compress.
* testsuite/libctf-writable/ctf-compressed.*: New test.

10 months agolibctf: fix linking of non-root-visible types
Nick Alcock [Mon, 15 Jul 2024 18:42:10 +0000 (19:42 +0100)] 
libctf: fix linking of non-root-visible types

If you deduplicate non-root-visible types, the resulting type should still
be non-root-visible! We were promoting all such types to root-visible, and
re-demoting them only if their names collided (which might happen on
cu-mapped links if multiple compilation units with conflicting types are
fused into one child dict).

This "worked" before now, in that linking at least didn't fail (if you don't
mind having your non-root flag value destroyed if you're adding
non-root-visible types), but now that conflicting enumerators cause their
containing enums to become conflicted (enums which might have *different
names*), this caused the linker to crash when it hit two enumerators with
conflicting values.

Not testable in ld because cu-mapped links are not exposed to ld, but can be
tested via direct creation of libraries and calls to ctf_link directly.
(This also tests the ctf_dump non-root type printout, which before now
was untested.)

libctf/
* ctf-dedup.c (ctf_dedup_emit_type): Non-root-visible input types
should be emitted as non-root-visible output types.
* testsuite/libctf-writable/ctf-nonroot-linking.c: New test.
* testsuite/libctf-writable/ctf-nonroot-linking.lk: New test.

10 months agolibctf, dump: correctly dump non-root-visible types
Nick Alcock [Mon, 15 Jul 2024 18:39:48 +0000 (19:39 +0100)] 
libctf, dump: correctly dump non-root-visible types

The flag test when dumping non-root-visible tyeps was doubly wrong: the
flags word is a *bitfield* containing CTF_ADD_ROOT as one possible
value, so needs | and & testing, not just ==, and CTF_ADD_NONROOT is 0,
so cannot be tested for this way: one must check for the non-presence of
CTF_ADD_ROOT.

libctf/
* ctf-dump.c (ctf_dump_format_type): Fix non-root flag test.

10 months agolibctf, string: split the movable refs out of the ref list
Nick Alcock [Fri, 12 Jul 2024 11:44:02 +0000 (12:44 +0100)] 
libctf, string: split the movable refs out of the ref list

In commit 149ce5c263616e65 we introduced the concept of "movable" refs,
which are refs that can be moved in batches, to let us maintain valid ref
lists even when adding refs to blocks of memory that can be realloced (which
is any type containing a vlen which can expand, like names contained within
enum or struct members).  Movable refs need a backpointer to the movable
refs dynhash for this dict; since non-movable refs are very common, we tried
to save memory by having a slightly bigger struct for moveable refs with a
backpointer in it, and casting appropriately, indicating which sort of ref
we were dealing with via a flag on the atom.

Unfortunately this doesn't work reliably, because you can perfectly well
have a string ("foo", say) which has both non-movable refs (say, an external
symbol and a variable name) and movable refs (say, a structure member name)
to the same atom.  Indicate which struct we're dealing with with an atom
flag and suddenly you're casting a ctf_str_atom_ref to a
ctf_str_atom_ref_movable (which is bigger) and dereferencing random memory
off the end of it and interpreting it as a backpointer to the movable refs
dynhash.  This is unlikely to work well.

So bite the bullet and split refs into two separate lists, one for movable
refs, one for immovable refs. It means some annoying code duplication, but
there's not very much of it, and it means we can keep the movable refs
hashtab (which in turn means we don't have to do linear searches to find all
relevant refs when moving refs, which in turn means that
structure/union/enum member additions remain amortized O(n) time, not
O(n^2).

Callers can now purge movable and non-movable refs independently of each
other.  We don't use this yet, but a use is coming.

libctf/
* ctf-impl.h (CTF_STR_ATOM_MOVABLE): Delete.
        (struct ctf_str_atom) [csa_movable_refs]: New.
(struct ctf_dict): Adjust comment.
(ctf_str_purge_refs): Add MOVABLE arg.
* ctf-string.c (ctf_str_purge_movable_atom_refs): Split out of...
        (ctf_str_purge_atom_refs): ... this.
(ctf_str_free_atom): Call it.
(ctf_str_purge_one_atom_refs): Likewise.
(aref_create): Adjust accordingly.
(ctf_str_move_refs): Likewise.
(ctf_str_remove_ref): Remove movable refs too, including
deleting the ref from ctf_str_movable_refs.
(ctf_str_purge_refs): Add MOVABLE arg.
(ctf_str_update_refs): Update movable refs.
(ctf_str_write_strtab): Check, and purge, movable refs.

10 months agolibctf, dedup: drop unnecessary arg from ctf_dedup()
Nick Alcock [Tue, 9 Jul 2024 14:30:39 +0000 (15:30 +0100)] 
libctf, dedup: drop unnecessary arg from ctf_dedup()

The PARENTS arg is carefully passed down through all the layers of hash
functions and then never used for anything.  (In the distant past it was
used for cycle detection, but the algorithm eventually committed doesn't
need to do cycle detection...)

The PARENTS arg is still used by ctf_dedup_emit(), but even there we can
loosen the requirements and state that you can just leave entries
corresponding to dicts with no parents at zero (which will be useful
in an upcoming commit).

libctf/
* ctf-dedup.c (ctf_dedup_hash_type): Drop PARENTS arg.
(ctf_dedup_rhash_type): Likewise.
(ctf_dedup): Likewise.
(ctf_dedup_emit_struct_members): Mention what you can do to
        PARENTS entries for parent dicts.
* ctf-impl.h (ctf_dedup): Adjust accordingly.
* ctf-link.c (ctf_link_deduplicating_per_cu): Likewise.
(ctf_link_deduplicating): Likewise.

10 months agolibctf: we do in fact support foreign-endian old versions
Nick Alcock [Fri, 5 Jul 2024 14:53:14 +0000 (15:53 +0100)] 
libctf: we do in fact support foreign-endian old versions

The worry that caused this to not be supported was because we don't
bother endian-flipping version-related fields before checking them.
But they're all unsigned chars anyway, and don't need any flipping at
all.

This should be supported and should already work.  Enable it.

libctf/
* ctf-open.c (ctf_bufopen): Don't prohibit foreign-endian
        upgrades.

10 months ago[gdb/testsuite] Fix trailing-text-in-parentheses duplicates
Tom de Vries [Wed, 31 Jul 2024 13:04:25 +0000 (15:04 +0200)] 
[gdb/testsuite] Fix trailing-text-in-parentheses duplicates

Fix all trailing-text-in-parentheses duplicates exposed by previous patch.

Tested on x86_64-linux and aarch64-linux.

10 months ago[gdb/testsuite] Detect trailing-text-in-parentheses duplicates
Tom de Vries [Wed, 31 Jul 2024 13:04:25 +0000 (15:04 +0200)] 
[gdb/testsuite] Detect trailing-text-in-parentheses duplicates

When using a duplicate test name:
...
fail foo
fail foo
...
we get:
...
FAIL: $exp: foo
FAIL: $exp: foo
DUPLICATE: $exp: foo
...

But when we do:
...
fail foo
fail "foo (timeout)"
...
we get only:
...
FAIL: $exp: foo
FAIL: $exp: foo (timeout)
...

Trailing text between parentheses prefixed with a space is interpreted as
extra information, and not as part of the test name [1].

Consequently, "foo" and "foo (timeout)" do count as duplicate test names,
which should have been detected.  This is PR testsuite/29772.

Fix this in CheckTestNames::_check_duplicates, such that we get:
...
FAIL: $exp: foo
FAIL: $exp: foo (timeout)
DUPLICATE: $exp: foo (timeout)
...

[ One note on the implementation: I used the regexp { \([^()]*\)$}. I don't
know whether that covers all required cases, due to the fact that those are
not unambiguousely specified.  It might be possible to reverse-engineer that
information by reading or running the "regression analysis tools" mentioned on
the wiki page [1], but I haven't been able to.  Regardless, the current regexp
covers a large amount of cases, which IMO should be sufficient to be
acceptable. ]

Doing so shows many new duplicates in the testsuite.

A significant number of those is due to using a message which is a copy of the
command:
...
gdb_test "print (1)"
...

Fix this by handling those cases using test names "gdb-command<print (1)>" and
"gdb-command<print (2)>.

Fix the remaining duplicates manually (split off as follow-up patch for
readability of this patch).

Tested on x86_64-linux and aarch64-linux.

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

[1] https://sourceware.org/gdb/wiki/GDBTestcaseCookbook#Do_not_use_.22tail_parentheses.22_on_test_messages

10 months ago[gdb/testsuite] Add gdb.python/py-disasm-{exec,obj}.exp
Tom de Vries [Wed, 31 Jul 2024 11:24:20 +0000 (13:24 +0200)] 
[gdb/testsuite] Add gdb.python/py-disasm-{exec,obj}.exp

I tried to reproduce a problem in test-case gdb.python/py-disasm.exp on a
s390x machine, but when running with target board unix/-m31 I saw that the
required libraries were missing, so I couldn't generate an executable.

However, I realized that I did have an object file, and the test-case should
mostly also work with an object file.

I've renamed gdb.python/py-disasm.exp to gdb.python/py-disasm.exp.tcl and
included it from two new minimal test-case wrappers:
- gdb.python/py-disasm-exec.exp, and
- gdb.python/py-disasm-obj.exp
where the former uses an executable as before, and the latter uses an object
file.

Using an object file required changing the info.read_memory calls in
gdb.python/py-disasm.py:
...
-            info.read_memory(1, -info.address + 2)
+            info.read_memory(1, -info.address - 1)
...
because reading from address 2 succeeds.  Using address -1 instead does
generate the expected gdb.MemoryError.

Tested on x86_64-linux.

10 months ago[gdb/exp] Fix gdb.fortran/intrinsics.exp fail on arm
Tom de Vries [Wed, 31 Jul 2024 11:11:48 +0000 (13:11 +0200)] 
[gdb/exp] Fix gdb.fortran/intrinsics.exp fail on arm

When running test-case gdb.fortran/intrinsics.exp on arm-linux, I get:
...
(gdb) p cmplx (4,4,16)^M
/home/linux/gdb/src/gdb/f-lang.c:1002: internal-error: eval_op_f_cmplx: \
  Assertion `kind_arg->code () == TYPE_CODE_COMPLEX' failed.^M
A problem internal to GDB has been detected,^M
further debugging may prove unreliable.^M
----- Backtrace -----^M
FAIL: gdb.fortran/intrinsics.exp: p cmplx (4,4,16) (GDB internal error)
...

The problem is that 16-byte floats are unsupported:
...
$ gfortran test.f90
test.f90:2:17:

    2 |     REAL(kind=16) :: foo = 1
      |                 1
Error: Kind 16 not supported for type REAL at (1)
...
and consequently we end up with a builtin_real_s16 and builtin_complex_s16 with
code TYPE_CODE_ERROR.

Fix this by bailing out asap when encountering such a type.

Without this patch we're able to do the rather useless:
...
(gdb) ptype real*16
type = real*16
(gdb) ptype real_16
type = real*16
...
but with this patch we get:
...
(gdb) ptype real*16
unsupported kind 16 for type real*4
(gdb) ptype real_16
unsupported type real*16
...

Tested on arm-linux.

PR fortran/30537
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30537

10 months agox86: move ginsn stuff
Jan Beulich [Wed, 31 Jul 2024 10:04:03 +0000 (12:04 +0200)] 
x86: move ginsn stuff

This had been badly inserted between md_assemble() and its helpers
anyway. Follow what was done for Arm64 and move the code to its own
file, #include-d as appropriate.

10 months agogas/doc: adjust an @xref
Jan Beulich [Wed, 31 Jul 2024 10:03:23 +0000 (12:03 +0200)] 
gas/doc: adjust an @xref

Old doc tools warn about there not being a . or , following; satisfy
those tools by shortening the line and adding a full stop.

10 months agofix the framework error
Alan Modra [Tue, 30 Jul 2024 22:32:24 +0000 (08:02 +0930)] 
fix the framework error

Running the testsuite for an x86_64-w64-mingw32 target using the
Ubuntu package gcc-mingw-w64-x86-64 version 13.2.0-6ubuntu1+26.1
results in a number of messages:
ERROR: can't decipher gcc version number, fix the framework!

Someone in their wisdom decided this compiler should advertise itself
with a version of 13-win32, breaking the ld testsuite version checks.
(It is also configured using --with-as=/usr/bin/x86_64-w64-mingw32-as
--with-ld=/usr/bin/x86_64-w64-mingw32-ld which renders the -B flag
inoperative for testing the newly built gas and ld.  You'd need to
install binutils over the top of the Ubuntu versions before testing, a
rather unsatisfactory process.)

* testsuite/lib/ld-lib.exp (at_least_gcc_version): Use
preprocessor test of __GNUC__ and __GNUC_MINOR__ rather than
output of gcc --version.  Correct removal of -Wl options.

10 months agoAutomatic date update in version.in
GDB Administrator [Wed, 31 Jul 2024 00:00:28 +0000 (00:00 +0000)] 
Automatic date update in version.in

10 months ago[gdb/testsuite] Fix regexp in gdb.ada/mi_var_access.exp some more
Tom de Vries [Tue, 30 Jul 2024 19:50:17 +0000 (21:50 +0200)] 
[gdb/testsuite] Fix regexp in gdb.ada/mi_var_access.exp some more

When running test-case gdb.ada/mi_var_access.exp on arm-linux (debian trixie),
I run into:
...
Expecting: ^(-var-create A_String_Access \* A_String_Access[
]+)?((\^done,name="A_String_Access",numchild="[0-9]+",.*|\^error,msg="Value out of range.".*)[
]+[(]gdb[)]
[ ]*)
-var-create A_String_Access * A_String_Access
^error,msg="Cannot access memory at address 0x4"
(gdb)
FAIL: gdb.ada/mi_var_access.exp: Create varobj (unexpected output)
...

This is similar to the problem fixed by commit c5a72a8d1c3 ("[gdb/testsuite]
Fix regexp in gdb.ada/mi_var_access.exp").

The problem in both cases is that we're printing an uninitialized variable,
and consequently we can run into various error messages during printing.

Fix this as in the other commit, by accepting the error message.

Tested on arm-linux.

10 months agogdb: don't call macro_bcache with nullptr
Simon Marchi [Tue, 30 Jul 2024 19:24:58 +0000 (19:24 +0000)] 
gdb: don't call macro_bcache with nullptr

Since commit b1da98a74656 ("gdb: remove use of alloca in
new_macro_definition"), if cached_argv is empty, we call macro_bcache
with a nullptr data.  This ends up caught by UBSan deep down in the
bcache code:

    $ ./gdb -nx -q --data-directory=data-directory  /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.base/macscp/macscp -readnow
    Reading symbols from /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.base/macscp/macscp...
    Expanding full symbols from /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.base/macscp/macscp...
    /home/smarchi/src/binutils-gdb/gdb/bcache.c:195:12: runtime error: null pointer passed as argument 2, which is declared to never be null

The backtrace:

    #1  0x00007ffff619a05d in __ubsan::__ubsan_handle_nonnull_arg_abort (Data=<optimized out>) at ../../../../src/libsanitizer/ubsan/ubsan_handlers.cpp:750
    #2  0x000055556337fba2 in gdb::bcache::insert (this=0x62d0000c8458, addr=0x0, length=0, added=0x0) at /home/smarchi/src/binutils-gdb/gdb/bcache.c:195
    #3  0x0000555564b49222 in gdb::bcache::insert<char const*, void> (this=0x62d0000c8458, addr=0x0, length=0, added=0x0) at /home/smarchi/src/binutils-gdb/gdb/bcache.h:158
    #4  0x0000555564b481fa in macro_bcache<char const*> (t=0x62100007ae70, addr=0x0, len=0) at /home/smarchi/src/binutils-gdb/gdb/macrotab.c:117
    #5  0x0000555564b42b4a in new_macro_definition (t=0x62100007ae70, kind=macro_function_like, special_kind=macro_ordinary, argv=std::__debug::vector of length 0, capacity 0, replacement=0x62a00003af3a "__builtin_va_arg_pack ()") at /home/smarchi/src/binutils-gdb/gdb/macrotab.c:573
    #6  0x0000555564b44674 in macro_define_internal (source=0x6210000ab9e0, line=469, name=0x7fffffffa710 "__va_arg_pack", kind=macro_function_like, special_kind=macro_ordinary, argv=std::__debug::vector of length 0, capacity 0, replacement=0x62a00003af3a "__builtin_va_arg_pack ()") at /home/smarchi/src/binutils-gdb/gdb/macrotab.c:777
    #7  0x0000555564b44ae2 in macro_define_function (source=0x6210000ab9e0, line=469, name=0x7fffffffa710 "__va_arg_pack", argv=std::__debug::vector of length 0, capacity 0, replacement=0x62a00003af3a "__builtin_va_arg_pack ()") at /home/smarchi/src/binutils-gdb/gdb/macrotab.c:816
    #8  0x0000555563f62fc8 in parse_macro_definition (file=0x6210000ab9e0, line=469, body=0x62a00003af2a "__va_arg_pack() __builtin_va_arg_pack ()") at /home/smarchi/src/binutils-gdb/gdb/dwarf2/macro.c:203

This can be reproduced by running gdb.base/macscp.exp.  Avoid calling
macro_bcache if the macro doesn't have any arguments.

Change-Id: I33b5a7c3b3a93d5adba98983fcaae9c8522c383d

10 months agogprofng: 32018 Compilation of binutils 2.43 failed on CentOS 6
Vladimir Mezentsev [Mon, 29 Jul 2024 21:15:01 +0000 (14:15 -0700)] 
gprofng: 32018 Compilation of binutils 2.43 failed on CentOS 6

strchr is redefined as a macro in /usr/include/bits/string.h on CentOS 6/7.
In this case, we may not use our CALL_UTIL macro for strchr.
Use __collector_strchr instead of "CALL_UTIL (strchr)".

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

PR 32018
* libcollector/hwprofile.c (open_experiment): Use __collector_strchr.

10 months ago[gdb/symtab] Emit malformed macro definition complaint once
Tom de Vries [Tue, 30 Jul 2024 14:56:31 +0000 (16:56 +0200)] 
[gdb/symtab] Emit malformed macro definition complaint once

Add a test-case gdb.dwarf2/macro-complaints.exp, that checks complaints for the
.debug_macro section.

For one malformed macro definition, I get two identical complaints:
...
During symbol reading: macro debug info contains a malformed macro definition:^M
`M1_11_MALFORMED(ARG'^M
During symbol reading: macro debug info contains a malformed macro definition:^M
`M1_11_MALFORMED(ARG'^M
...

Fix this by bailing out after the first one.

Tested on aarch64-linux.

Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
10 months agogdb: remove use of alloca in new_macro_definition
Simon Marchi [Wed, 24 Jul 2024 19:07:15 +0000 (15:07 -0400)] 
gdb: remove use of alloca in new_macro_definition

Replace alloca with std::vector.

Change-Id: Ie8756da09126f6808e5b52c43388ad9324e8ad2c
Approved-By: Tom de Vries <tdevries@suse.de>
10 months agogdb: use std::string vector for macro definition
Simon Marchi [Wed, 24 Jul 2024 19:07:14 +0000 (15:07 -0400)] 
gdb: use std::string vector for macro definition

Use std::vector<std::string> when defining macros, to avoid the manual
memory management.

With the use of std::vector, the separate `int argc` parameter is no
longer needed, we can use the size of the vector instead.  However, for
some functions, this parameter had a dual function.  For object-like
macros, it was interpreted as a `macro_special_kind` enum.  For these
functions, remove `argc`, but add a new `special_kind` parameter.

Change-Id: Ice76a6863dfe598335e3b8d5d077513e50975cc5
Approved-By: Tom de Vries <tdevries@suse.de>
10 months agogdb/doc: move @anchor off @item line
Andrew Burgess [Tue, 30 Jul 2024 10:19:14 +0000 (11:19 +0100)] 
gdb/doc: move @anchor off @item line

When building the GDB info manual I see this warning:

  gdb.texinfo:41447: warning: @anchor should not appear on @item line

And indeed line 41447 looks like this:

  @item @anchor{maint info breakpoints}maint info breakpoints

I propose moving the @anchor{...} part to the previous line which
silences the warning.

Approved-By: Eli Zaretskii <eliz@gnu.org>
10 months agogas/NEWS, ld/NEWS: Announce LoongArch changes in 2.43
Lulu Cai [Fri, 26 Jul 2024 08:34:38 +0000 (16:34 +0800)] 
gas/NEWS, ld/NEWS: Announce LoongArch changes in 2.43

10 months agoAutomatic date update in version.in
GDB Administrator [Tue, 30 Jul 2024 00:00:17 +0000 (00:00 +0000)] 
Automatic date update in version.in

10 months agoAdd a test for the gcore script
Alexandra Hájková [Fri, 2 Feb 2024 10:13:47 +0000 (11:13 +0100)] 
Add a test for the gcore script

It also tests the gcore script being run without its accessible
terminal.

This test was written by Jan Kratochvil a long time ago. I modernized
the test making it use various procs from lib/gdb.exp, reorganizing it
and added some comments.

Modify the gcore script to make it possible to pass the --data-directory to
it. This prevents a lot of these warnings:

Python Exception <class 'AttributeError'>: module 'gdb' has no attribute
'_handle_missing_debuginfo'

Tested by using make check-all-boards.

Co-Authored-By: Jan Kratochvil <jan.kratochvil@redhat.com>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
10 months ago[gdb/testsuite] Fix gdb.gdb/index-file.exp with -g0
Tom de Vries [Mon, 29 Jul 2024 13:42:28 +0000 (15:42 +0200)] 
[gdb/testsuite] Fix gdb.gdb/index-file.exp with -g0

When building gdb with -g0 and running test-case gdb.gdb/index-file.exp, we
run into:
...
(gdb) save gdb-index index_1^M
Error while writing index for `xgdb': No debugging symbols^M
(gdb) FAIL: gdb.gdb/index-file.exp: create gdb-index file
...

Fix this by instead emitting an unsupported, and bailing out.

Tested on aarch64-linux.

10 months ago[gdb/testsuite] Remove PR31554 kfail in gdb.threads/leader-exit-attach.exp
Tom de Vries [Mon, 29 Jul 2024 12:05:52 +0000 (14:05 +0200)] 
[gdb/testsuite] Remove PR31554 kfail in gdb.threads/leader-exit-attach.exp

When running test-case gdb.threads/leader-exit-attach.exp with target board
native-extended-gdbserver I run into:
...
(gdb) KFAIL: $exp: attach (PRMS: gdb/31555)
print $_inferior_thread_count^M
$1 = 0^M
(gdb) KPASS: $exp: get valueof "$_inferior_thread_count" (PRMS server/31554)
...

The PR mentioned in the KPASS, PR31554 was fixed by commit f1fc8dc2dcc
("Fix "attach" failure handling with GDBserver"), and consequently the PR is
closed.

Fix this by removing the corresponding kfail.

Tested on x86_64-linux.

10 months ago[gdb/testsuite] Fix gdb.threads/leader-exit-attach.exp with check-read1
Tom de Vries [Mon, 29 Jul 2024 12:05:52 +0000 (14:05 +0200)] 
[gdb/testsuite] Fix gdb.threads/leader-exit-attach.exp with check-read1

With test-case gdb.threads/leader-exit-attach.exp and check-read1, I run into:
...
(gdb) attach 18591^M
Attaching to program: leader-exit-attach, process 18591^M
warning: process 18591 is a zombie - the process has already terminatedKFAIL: $exp: attach (PRMS: gdb/31555)
^M
ptrace: Operation not permitted.^M
(gdb) FAIL: $exp: get valueof "$_inferior_thread_count"
...

The problem is that the gdb_test_multiple in the test-case doesn't consume the
prompt in all clauses:
...
gdb_test_multiple "attach $testpid" "attach" {
    -re "Attaching to process $testpid failed.*" {
# GNU/Linux gdbserver.  Linux ptrace does not let you attach
# to zombie threads.
setup_kfail "gdb/31555" *-*-linux*
fail $gdb_test_name
    }
    -re "warning: process $testpid is a zombie - the process has already terminated.*" {
# Native GNU/Linux.  Linux ptrace does not let you attach to
# zombie threads.
setup_kfail "gdb/31555" *-*-linux*
fail $gdb_test_name
    }
    -re "Attaching to program: $escapedbinfile, process $testpid.*$gdb_prompt $" {
pass $gdb_test_name
set attached 1
    }
}
...

Fix this by using -wrap in the first two clauses.

While we're at it, also use -wrap in the third clause.

Tested on x86_64-linux.

10 months agoUpdated translations for the bfd, binutils, gas, ld and opcodes directories
Nick Clifton [Mon, 29 Jul 2024 10:57:25 +0000 (11:57 +0100)] 
Updated translations for the bfd, binutils, gas, ld and opcodes directories

10 months agoFixes to "PR 31728 testcases"
Alan Modra [Fri, 26 Jul 2024 23:43:27 +0000 (09:13 +0930)] 
Fixes to "PR 31728 testcases"

This brings us down to just these fails for the set of targets I
usually test when making testsuite changes.
aarch64-pe  +FAIL: ld-pe/symbols-ordinals-hints-imports-ld
arm-pe  +FAIL: ld-pe/symbols-ordinals-hints-exports-dlltool
arm-pe  +FAIL: ld-pe/symbols-ordinals-hints-imports-dlltool

The aarch64 one is likely due to the target missing support somewhere.
It is fairly new, I haven't investigated.  The arm-pe fails are due to
arm-pe being a target that adds underscores to symbol names (see
config.bfd) whereas dlltool thinks it does not (see
dlltool.c:asm_prefix).  arm-wince-pe on the other hand doesn't add
underscores.  I would guess the right fix for dlltool is to get this
symbol info from bfd using bfd_get_target_info.

Note I'm not very happy about the creative use of ld_after_inputfile
in symbols-ordinals-hints-imports-ld.d, which is likely to break with
some future run_dump_test change.

10 months agoPR 31728 testcases
Pali Rohár [Fri, 26 Jul 2024 05:40:18 +0000 (15:10 +0930)] 
PR 31728 testcases

10 months agoPR32032 dwp segfaults on hello world binary
Alan Modra [Mon, 29 Jul 2024 04:55:07 +0000 (14:25 +0930)] 
PR32032 dwp segfaults on hello world binary

Fixing the segfault is easy with this bandaid, but further work is
needed to teach dwp about DW_AT_dwo_name and dwo id in the cu header.
At the moment dwp only handles DW_AT_GNU_dwo_name and DW_AT_GNU_dwo_id.

PR 32032
* dwp.cc (Dwp_output_file::finalize): Return immediately on
no output file.

10 months agoAutomatic date update in version.in
GDB Administrator [Mon, 29 Jul 2024 00:00:23 +0000 (00:00 +0000)] 
Automatic date update in version.in

10 months agogdb/testsuite: track if a caching proc calls gdb_exit or not
Andrew Burgess [Mon, 3 Jun 2024 12:56:54 +0000 (13:56 +0100)] 
gdb/testsuite: track if a caching proc calls gdb_exit or not

After a recent patch review I asked myself why can_spawn_for_attach
exists.  This proc currently does some checks, and then calls
can_spawn_for_attach_1 which is an actual caching proc.

The answer is that can_spawn_for_attach exists in order to call
gdb_exit the first time can_spawn_for_attach is called within any test
script.

The reason this is useful is that can_spawn_for_attach_1 calls
gdb_exit.  If the user calls can_spawn_for_attach_1 directly then a
problem might exist.  Imagine a test written like this:

  gdb_start

  if { [can_spawn_for_attach_1] } {
    ... do stuff that assumes GDB is running ...
  }

If this test is NOT the first test run, and if an earlier test calls
can_spawn_for_attach_1, then when the above test is run the
can_spawn_for_attach_1 call will return the cached value and gdb_exit
will not be called.

But, if the above test IS the first test run then
can_spawn_for_attach_1 will not return the cached value, but will
instead compute the cached value, a process that ends up calling
gdb_exit.  When can_spawn_for_attach_1 returns GDB will have exited
and the test might fail if it is written assuming that GDB is
running.

So can_spawn_for_attach was added which ensures that we _always_ call
gdb_exit the first time can_spawn_for_attach is called within a single
test script, this ensures that in the above case, even if the above is
not the first test script run, gdb_exit will still be called.  This
ensures consistent behaviour and avoids some hidden bugs in the
testsuite.

The split between can_spawn_for_attach and can_spawn_for_attach_1 was
introduced in this commit:

  commit 147fe7f9fb9a89b217d11d73053f53e8edacf90f
  Date:   Mon May 6 14:27:09 2024 +0200

      [gdb/testsuite] Handle ptrace operation not permitted in can_spawn_for_attach

However, I observe that can_spawn_for_attach is not the only caching
proc that calls gdb_exit.  Why does can_spawn_for_attach get special
treatment when surely the same issue exists for any other caching proc
that calls gdb_exit?

I think a better solution is to move the logic from
can_spawn_for_attach into cache.exp and generalise it so that it
applies to all caching procs.

This commit does this by:

 1. When the underlying caching proc is executed we track calls to
    gdb_exit.  If a caching proc calls gdb_exit then this information
    is stored in gdb_data_cache (using a ',exit' suffix), and also
    written to the cache file if appropriate.

 2. When a cached value is returned from gdb_do_cache, if the
    underlying proc would have called gdb_exit, and if this is the
    first use of the caching proc in this test script, then we call
    gdb_exit.

When storing the ',exit' value into the on-disk cache file, the flag
value is stored on a second line.  Currently every cached value only
occupies a single line, and a check is added to ensure this remains
true in the future.

To track calls to gdb_exit I eventually settled on using TCL's trace
mechanism.  We already make use of this in lib/gdb.exp so I figure
this is OK to use.  This should be fine, so long as non of the caching
procs use 'with_override' to replace gdb_exit, or do any other proc
replacement to change gdb_exit, however, I think that is pretty
unlikely.

One issue did come up in testing, a FAIL in gdb.base/break-interp.exp,
prior to this commit can_spawn_for_attach would call gdb_exit before
calling the underlying caching proc.  After this call we call gdb_exit
after calling the caching proc.

The underlying caching proc relies on gdb_exit having been called.  To
resolve this issue I just added a call to gdb_exit into
can_spawn_for_attach.

With this done can_spawn_for_attach_1 can be renamed to
can_spawn_for_attach, and the existing can_spawn_for_attach can be
deleted.

10 months agogdb/testsuite: restructure gdb_data_cache (lib/cache.exp)
Andrew Burgess [Mon, 3 Jun 2024 08:23:18 +0000 (09:23 +0100)] 
gdb/testsuite: restructure gdb_data_cache (lib/cache.exp)

In the next commit I want to add more information to
gdb_data_cache (see lib/cache.exp).  Specifically I want to track if
the underlying function of a caching proc calls gdb_exit or not.

Currently gdb_data_cache is an associative array, the keys of which
are the name of the caching proc.

In this commit I add a ',value' suffix to the gdb_data_cache keys.  In
the next commit I'll add additional entries with a different suffix.

There should be no noticable changes after this commit, this is just a
restructuring.

11 months agoAutomatic date update in version.in
GDB Administrator [Sun, 28 Jul 2024 00:00:20 +0000 (00:00 +0000)] 
Automatic date update in version.in