]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
14 months agos390: Initial support for s390x users/jremus/sframe-stacktracer-testsuite-s390x
Jens Remus [Thu, 16 May 2024 11:55:44 +0000 (13:55 +0200)] 
s390: Initial support for s390x

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
14 months agos390: Update SFrame test cases for FP without RA
Jens Remus [Fri, 19 Apr 2024 14:50:41 +0000 (16:50 +0200)] 
s390: Update SFrame test cases for FP without RA

SFrame FP and RA tracking can represent FP without RA being saved
since commit "sframe: Represent FP without RA on stack". As a result
the s390-specific error test cases for FP without RA saved on stack or
in register now do no longer trigger a warning. Rename and update them
accordingly.

gas/testsuite/
* gas/cfi-sframe/cfi-sframe.exp: Rename s390-specific test
cases.
* gas/cfi-sframe/cfi-sframe-s390-fpra-offset-err-1.s: Rename
to ...
* cfi-sframe/cfi-sframe-s390-fpra-offset-err-1.d: Likewise.
* gas/cfi-sframe/cfi-sframe-s390-fpra-offset-2.s: This.
* gas/cfi-sframe/cfi-sframe-s390-fpra-offset-2.d: Likewise.
Update test verification pattern accordingly.
* cfi-sframe/cfi-sframe-s390-fpra-register-err-1.s: Rename
to ...
* cfi-sframe/cfi-sframe-s390-fpra-register-err-1.d: Likewise.
* gas/cfi-sframe/cfi-sframe-s390-fpra-register-2.s: This.
* gas/cfi-sframe/cfi-sframe-s390-fpra-register-2.d: Likewise.
Update test verification pattern accordingly.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
14 months agosframe: Represent FP without RA on stack
Jens Remus [Wed, 13 Mar 2024 17:03:52 +0000 (18:03 +0100)] 
sframe: Represent FP without RA on stack

If an architecture uses both SFrame RA and FP tracking SFrame assumes
that the RA offset is the 2nd offset and the FP offset is the 3rd offset
following the SFrame FRE. An architecture does not need to store both on
the stack. SFrame cannot represent a FP without RA on stack, since it
cannot distinguish whether the 2nd offset is the RA or FP offset.

Use an invalid SFrame FRE RA offset value of zero as dummy padding to
represent the FP being saved on the stack when the RA is not saved on
the stack.

include/
* sframe.h (SFRAME_FRE_RA_OFFSET_INVALID): New macro defining
the invalid RA offset value used to represent a dummy padding
offset.

gas/
* gen-sframe.c (get_fre_num_offsets): Accommodate for dummy
padding RA offset if FP without RA on stack.
(sframe_get_fre_offset_size): Likewise.
(output_sframe_row_entry): Write a dummy padding RA offset
if FP without RA needs to be represented.

libsframe/
* sframe-dump.c (dump_sframe_func_with_fres): Treat invalid RA
offsets as if they were undefined. Display them as "u*" to
distinguish them.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
14 months agos390: SFrame track FP/RA saved in register
Jens Remus [Tue, 9 Apr 2024 13:59:12 +0000 (15:59 +0200)] 
s390: SFrame track FP/RA saved in register

GCC on s390x, when in a leaf function, can be observed to save the
frame pointer (FP) and/or return address (RA) register in a floating-
point registers (FPR) instead of on the stack. This is declared using
the following CFI directive:

  .cfi_register <fp/ra-regno>, <fpr-regno>

SFrame cannot represent the FP and/or RA being saved in another
register. It does only track the CFA base register (SP/FP), CFA offset
from CFA base register, and FP and RA save area offsets from CFA.

On s390x the FP and/or RA are only saved in another FPR when in a leaf
function. That is a function that does not call any other functions.
Therefore it can ever only be the topmost function in a call chain.
During function return, if the RA would be restored into a non-default
RA register, the function would also only ever be the topmost function
on the call stack.
An unwinder by default has access to all registers of the function that
if the topmost on the call stack. Therefore no further information would
be required for those registers.

Represent the FP/RA in another register on s390, by encoding the
register number shifted by one to the left with the least-significant
bit set in the offset as follows:

  offset = (regno << 1) | 1

Add s390-specific SFrame (error) test cases for FP/RA being saved in
FPRs in leaf-function.

gas/
* gen-sframe.c (s390_sframe_xlate_do_register): New s390-
specific function to represent FP/RA in another register on
s390.
(sframe_xlate_do_register): Invoke s390_sframe_xlate_do_register
on s390.

libsframe/
* sframe-dump.c (is_sframe_abi_arch_s390): New helper to test
whether ABI/arch is s390.
(dump_sframe_func_with_fres): Dump FP/RA in another register on
s390.

gas/testsuite/
* gas/cfi-sframe/cfi-sframe.exp: Update s390-specific SFrame
(error) test cases.
* gas/cfi-sframe/cfi-sframe-s390-fpra-register-err-2.s: Rename
to ...
* gas/cfi-sframe/cfi-sframe-s390-fpra-register-err-2.d:
Likewise.
* gas/cfi-sframe/cfi-sframe-s390-fpra-register-1.s: This. Test
case no longer triggers a warning, as SFrame can represent FP
and RA saved in registers.
* gas/cfi-sframe/cfi-sframe-s390-fpra-register-1.d: Likewise.
* gas/cfi-sframe/cfi-sframe-s390-fpra-register-err-1.d: Test
case now triggers a different warning, as SFrame can represent
FP and RA saved in registers, but not FP without RA saved in
register.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
14 months agos390: Initial support to generate .sframe from CFI directives in assembler
Jens Remus [Fri, 19 Apr 2024 13:34:09 +0000 (15:34 +0200)] 
s390: Initial support to generate .sframe from CFI directives in assembler

This introduces initial support to generate .sframe from CFI directives
in assembler on s390x. Due to the following SFrame limitations it is
incomplete and does not work for most real-world applications (i.e.
generation of SFrame FDE is skipped):

- SFrame FP/RA tracking assumes the register contents to be saved on
  the stack (i.e. .cfi_offset). It does not support FP/RA register
  contents being saved in other registers (i.e. .cfi_register). GCC
  on s390x can be observed to save the FP/RA register contents in
  floating-point registers, but only in leaf functions.

- SFrame assumes a static FP register number. The s390x ELF ABI [1]
  does not specify any FP register number. GCC and clang on s390x
  usually use register 11 as frame pointer.
  GCC on s390x can also be observed to use register 14 (e.g. binutils
  and glibc builds) in the stack clash protector in the funcion
  prologue.
  glibc on s390x contains hand-written assembler code that uses
  register 12 for the frame pointer.

This s390x support is largely based on the AArch64 support from commit
b52c4ee46657 ("gas: generate .sframe from CFI directives").

SFrame ABI/arch identifier SFRAME_ABI_S390_ENDIAN_BIG is introduced
for s390 and added to the SFrame specification.

According to the s390x ELF ABI [1] the following calling conventions
are used on s390x architecture:
- Register 15 is used as stack pointer (SP). The CFA is initially
  located at offset +160 from the SP.
- Register 14 is used as return address (RA).
- There is no dedicated frame pointer. GCC and LLVM currently use
  register 11 as frame pointer.

The s390x ELF ABI [1] standard stack frame layout has the following
conventions:
- The return address (RA, r15) may be saved at offset -40 from the
  CFA. Unlike x86 AMD64 architecture it is not necessarily saved on
  the stack. Also compilers may use a non-standard stack frame layout,
  such as but not limited to GCC with option -mpacked-stack.
  Therefore SFrame RA tracking is used.
- The potential frame pointer (FP, r11) may be saved at offset -72
  from the CFA. It is not necessarily saved on the stack and compilers
  may use a non-standard stack frame layout (see above).
  Therefore SFrame FP tracking is used.

Support for SFrame is only enabled for z/Architecture (s390x) with
64-bit architecture mode. It is disabled for 32-bit architecture mode
and ESA/390 (s390).

Add s390-specific SFrame test cases. As for the error test cases add
ones that use a non-default frame pointer (FP) register number and ones
that save the return address (RA) in a non-default RA register number.

[1] ELF ABI s390x Supplement:
    https://github.com/IBM/s390x-abi/releases
[2] ELF ABI s390 Supplement:
    https://refspecs.linuxfoundation.org/ELF/zSeries/lzsabi0_s390.html
    https://refspecs.linuxfoundation.org/ELF/zSeries/lzsabi0_s390.pdf

include/
* sframe.h (SFRAME_ABI_S390_ENDIAN_BIG): Define SFrame ABI/arch
identifier for s390x. Reference s390x architecture in comments.

libsframe/
* doc/sframe-spec.texi: Document SFrame ABI/arch identifier for
s390x and reference s390x architecture.

gas/
* config/tc-s390.h: s390x support to generate .sframe from CFI
directives in assembler.
* config/tc-s390.c: Likewise.
* gen-sframe.c: Reference s390x architecture in comments.
* NEWS: Update news.

gas/testsuite/
* gas/cfi-sframe/cfi-sframe.exp: Enable common SFrame test cases
for s390x. Add s390-specific SFrame (error) test cases.
* gas/cfi-sframe/cfi-sframe-s390-1.s: New s390-specific SFrame
test case.
* gas/cfi-sframe/cfi-sframe-s390-1.d: Likewise.
* gas/cfi-sframe/cfi-sframe-s390-2.s: Likewise.
* gas/cfi-sframe/cfi-sframe-s390-2.d: Likewise.
* gas/cfi-sframe/cfi-sframe-s390-err-1.s: New s390-specific
SFrame error test case that uses a non-default frame-pointer
register as CFA base address.
* gas/cfi-sframe/cfi-sframe-s390-err-1.d: Likewise.
* gas/cfi-sframe/cfi-sframe-s390-err-2.s: Likewise.
* gas/cfi-sframe/cfi-sframe-s390-err-2.d: Likewise.
* gas/cfi-sframe/cfi-sframe-s390-err-3.s: New s390-specific
SFrame error test case that uses a non-default return-address
register.
* gas/cfi-sframe/cfi-sframe-s390-err-3.d: Likewise.
* gas/cfi-sframe/cfi-sframe-s390-fpra-offset-1.s: New s390-
specific SFrame test case that saves RA and FP individually
on the stack.
* gas/cfi-sframe/cfi-sframe-s390-fpra-offset-1.d: Likewise.
* gas/cfi-sframe/cfi-sframe-s390-fpra-offset-err-1.s: New s390-
specific SFRame error test case that saves FP and RA
individually, to trigger FP without RA.
* gas/cfi-sframe/cfi-sframe-s390-fpra-offset-err-1.d: Likewise.
* gas/cfi-sframe/cfi-sframe-s390-fpra-register-err-1.s: New
s390-specific SFrame error test case that saves FP and RA
individually in registers.
* gas/cfi-sframe/cfi-sframe-s390-fpra-register-err-1.d:
Likewise.
* gas/cfi-sframe/cfi-sframe-s390-fpra-register-err-2.s: New
s390-specific SFrame error test case that saves RA and FP
individually in registers.
* gas/cfi-sframe/cfi-sframe-s390-fpra-register-err-2.d:
Likewise.

Reviewed-by: Andreas Krebbel <krebbel@linux.ibm.com>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
14 months agogas: Validate SFrame RA tracking and fixed RA offset
Jens Remus [Thu, 7 Mar 2024 16:01:46 +0000 (17:01 +0100)] 
gas: Validate SFrame RA tracking and fixed RA offset

If an architecture uses SFrame return-address (RA) tracking it must
specify the fixed RA offset as invalid. Otherwise, if an architecture
does not use RA tracking, it must specify a valid fixed RA offset.

gas/
* gen-sframe.c: Validate SFrame RA tracking and fixed
RA offset.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
14 months agogas: Test predicate whether SFrame RA tracking is used
Jens Remus [Thu, 7 Mar 2024 12:02:29 +0000 (13:02 +0100)] 
gas: Test predicate whether SFrame RA tracking is used

The existence of the macro SFRAME_FRE_RA_TRACKING only ensures the
existence of the macro SFRAME_CFA_RA_REG and the predicate function
sframe_ra_tracking_p. It does not indicate whether SFrame RA tracking
is actually used.

Test the return value of the SFrame RA tracking predicate function
sframe_ra_tracking_p to determine whether RA tracking is used.

This aligns the logic in functions get_fre_num_offsets and
output_sframe_row_entry to the one used in all other places.

gas/
* gen-sframe.c (get_fre_num_offsets, output_sframe_row_entry):
Test predicate to determine whether SFrame RA tracking is used.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
14 months agogas: Don't skip SFrame FDE if .cfi_register specifies SP register
Jens Remus [Thu, 14 Mar 2024 13:48:52 +0000 (14:48 +0100)] 
gas: Don't skip SFrame FDE if .cfi_register specifies SP register

The stack-pointer (SP) register contents on entry can be reconstructed
from the CFA base register tracking information from the current SFrame
FRE and initial FRE from the FDE:

1. Compute CFA from the current CFA base register (SP or FP) and CFA
   offset from the SFrame CFA base register tracking information from
   the SFrame FRE for the current instruction address:

     CFA = <current_base_reg> + <current_cfa_offset>

2. Compute SP from the current CFA and the CFA offset from the SFrame
   CFA tracking information from the initial SFrame FRE of the FDE:

     SP = CFA - <initial_cfa_offset>

While at it add a comment to the processing of .cfi_val_offset that the
SP can be reconstructed from the CFA base register tracking information.

gas/
* gen-sframe.c (sframe_xlate_do_register): Do not skip SFrame
FDE if .cfi_register specifies SP register.
(sframe_xlate_do_val_offset): Add comment that this is likewise.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
14 months agogas: Don't skip SFrame FDE if .cfi_register specifies RA w/o tracking
Jens Remus [Thu, 7 Mar 2024 11:23:25 +0000 (12:23 +0100)] 
gas: Don't skip SFrame FDE if .cfi_register specifies RA w/o tracking

Do not skip SFrame FDE if .cfi_register specifies RA register without
RA tracking being actually used. Without RA tracking the register
contents can always be restored from the stack using the fixed
RA offset from CFA.

gas/
* gen-sframe.c (sframe_xlate_do_register): Do not skip SFrame
FDE if .cfi_register specifies RA register without RA tracking
being used.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
14 months agogas: Skip SFrame FDE if .cfi_window_save
Jens Remus [Thu, 28 Mar 2024 09:31:00 +0000 (10:31 +0100)] 
gas: Skip SFrame FDE if .cfi_window_save

CFI opcode DW_CFA_AARCH64_negate_ra_state is multiplexed with
DW_CFA_GNU_window_save. Process DW_CFA_AARCH64_negate_ra_state on
AArch64. Skip generation of SFrame FDE otherwise.

gas/
* gen-sframe.c: Skip SFrame FDE if .cfi_window_save.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
14 months agogas: Skip SFrame FDE if FP without RA on stack
Jens Remus [Thu, 7 Mar 2024 13:34:21 +0000 (14:34 +0100)] 
gas: Skip SFrame FDE if FP without RA on stack

The SFrame format cannot represent the frame pointer (FP) being saved
on the stack without the return address (RA) also being saved on the
stack, if RA tracking is used.

A SFrame FDE is followed by 1-3 offsets with the following information:

Without RA tracking:
1. Offset from base pointer (SP or FP) to locate the CFA
2. Optional: Offset to CFA to restore the frame pointer (FP)

With RA tracking:
1. Offset from base pointer (SP or FP) to locate the CFA
2. Optional: Offset to CFA to restore the return address (RA)
3. Optional: Offset to CFA to restore the frame pointer (FP)

When RA tracking is used and a FDE is followed by two offsets the
SFrame format does not provide any information to distinguish whether
the second offset is the RA or FP offset. SFrame assumes the offset to
be the RA offset, which may be wrong.

Therefore skip generation of SFrame FDE information and print the
following warning, if RA tracking is used and the FP is saved on the
stack without the RA being saved as well:

  skipping SFrame FDE due to FP without RA on stack

gas/
* gen-sframe.c (sframe_do_fde): Skip SFrame FDE if FP without RA
on stack, as the SFrame format cannot represent this case.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
14 months agogas: User readable warnings if SFrame FDE is not generated
Jens Remus [Wed, 14 Feb 2024 10:59:10 +0000 (11:59 +0100)] 
gas: User readable warnings if SFrame FDE is not generated

The following generic warning message, which is printed whenever the
assembler skips generation of SFrame FDE, is not very helpful for the
user:

  skipping SFrame FDE due to DWARF CFI op <name> (0x<hexval>)

Whenever possible print meaningful warning messages, when the assembler
skips generation of SFrame FDE:

- skipping SFrame FDE due to .cfi_def_cfa defining non-SP/FP register
  <regno> as CFA base register
- skipping SFrame FDE due to .cfi_def_cfa_register defining non-SP/FP
  register <regno> as CFA base register
- skipping SFrame FDE due to .cfi_def_cfa_offset without CFA base
  register in effect
- skipping SFrame FDE due to .cfi_def_cfa_offset with non-SP/FP register
  <regno> as CFA base register in effect
- skipping SFrame FDE due to .cfi_val_offset specifying {FP|RA} register
- skipping SFrame FDE due to .cfi_remember_state without SFrame FRE
  state
- skipping SFrame FDE due to .cfi_register specifying {SP|FP|RA}
  register
- skipping SFrame FDE due to non-default return-address register <regno>

gas/
* gen-sframe.h (SFRAME_FRE_BASE_REG_INVAL): New macro for
invalid SFrame FRE CFA base register value of -1.
* gen-sframe.c: User readable warnings if SFrame FDE is not
generated.

gas/testsuite/
* gas/cfi-sframe/common-empty-1.d: Update generic SFrame test
case to updated warning message texts.
* gas/cfi-sframe/common-empty-2.d: Likewise.
* gas/cfi-sframe/common-empty-3.d: Likewise.

Reviewed-by: Andreas Krebbel <krebbel@linux.ibm.com>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
14 months agogas: Refactor SFrame CFI opcode DW_CFA_register processing
Jens Remus [Thu, 7 Mar 2024 16:20:50 +0000 (17:20 +0100)] 
gas: Refactor SFrame CFI opcode DW_CFA_register processing

Refactor SFrame processing of CFI opcode DW_CFA_register into a separate
function. This harmonizes the CFI opcode processing.

While at it reword the comment on CFI opcodes that are not processed.

This is a purely mechanical change.

gas/
* gen-sframe.c (sframe_do_cfi_insn, sframe_xlate_do_register):
Refactor SFrame CFI opcode DW_CFA_register processing.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
14 months agogas: Warn if SFrame FDE is skipped due to non-default return column
Jens Remus [Tue, 13 Feb 2024 12:21:34 +0000 (13:21 +0100)] 
gas: Warn if SFrame FDE is skipped due to non-default return column

Print a warning message if SFrame FDE is skipped due to a non-default
DWARF return column (i.e. return address (RA) register number). This
may be caused by the use of CFI directive .cfi_return_column with a
non-default return address (RA) register number in the processed
assembler source code.

  Warning: skipping SFrame FDE due to non-default DWARF return column

gas/
* gen-sframe.c: Warn if SFrame FDE is skipped due to non-default
DWARF return column.

gas/testsuite/
* gas/cfi-sframe/common-empty-3.d: Update test case to expect
for new warning message when SFrame FDE is skipped due to
a non-default DWARF return column.

Reviewed-by: Andreas Krebbel <krebbel@linux.ibm.com>
Reviewed-by: Indu Bhagat <indu.bhagat@oracle.com>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
14 months agogas: Skip SFrame FDE if CFI specifies non-FP/SP base register
Jens Remus [Mon, 12 Feb 2024 16:29:50 +0000 (17:29 +0100)] 
gas: Skip SFrame FDE if CFI specifies non-FP/SP base register

Do not generate SFrame FDE if DWARF CFI directives .cfi_def_cfa or
.cfi_def_cfa_register specify a CFA base register number other than
the architecture-specific stack-pointer (SP) or frame-pointer (FP)
register numbers.

This also causes the assembler to print a warning message, so that
skipping of the SFrame FDE does not occur silently.

Update the generic ld SFrame test case to be architecture independent.
Do not use CFI directive .cfi_def_cfa, as the specified CFA base
register number is not a valid SP/FP register number on all
architectures. An invalid SP/FP register number will now cause the
assembler to print a warning message and skip SFrame FDE generation.
Remove the offending CFI directive, that cannot be coded architecture-
independent, as the test case requires SFrame information to be
generated. This was reported by the Linaro-TCWG-CI for AArch64.

gas/
* gen-sframe.c: Skip SFrame generation if CFI specifies
non-FP/SP base register.

ld/testsuite/
* ld-sframe/discard.s: Update generic SFrame test case to be
architecture independent.

Reviewed-by: Andreas Krebbel <krebbel@linux.ibm.com>
Reviewed-by: Indu Bhagat <indu.bhagat@oracle.com>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
14 months agogas: Print DWARF call frame insn name in SFrame warning message
Jens Remus [Mon, 12 Feb 2024 15:50:25 +0000 (16:50 +0100)] 
gas: Print DWARF call frame insn name in SFrame warning message

SFrame generation prints the DWARF call frame instruction opcode in
hexadecimal. Leverage get_DW_CFA_name to additionally print the
DWARF call frame instruction name in human readable form, while also
respecting fake CFI types. Use "(unknown)", if the DWARF call frame
instruction name is not known.

This changes the following assembler SFrame generation warning message
as follows:

Old:
Warning: skipping SFrame FDE due to DWARF CFI op 0x<hexnum>

New:
Warning: skipping SFrame FDE due to DWARF CFI op <name> (0x<hexnum>)

gas/
* gen-sframe.c (sframe_get_cfi_name): New function to get the
DWARF call frame instruction name for a DWARF call frame
instruction opcode.
(sframe_do_cfi_insn): Use sframe_get_cfi_name to print the
DWARF call frame instruction name for the DWARF call frame
instruction opcode in the warning message.

gas/testsuite/
* gas/cfi-sframe/common-empty-1.d: Update expected SFrame
warning message text for DWARF call frame insn name.
* gas/cfi-sframe/common-empty-2.d: Likewise.

Reviewed-by: Andreas Krebbel <krebbel@linux.ibm.com>
Reviewed-by: Indu Bhagat <indu.bhagat@oracle.com>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
14 months agoreadelf/objdump: Display SFrame fixed RA offset as 'f' in dump
Jens Remus [Thu, 7 Mar 2024 15:13:57 +0000 (16:13 +0100)] 
readelf/objdump: Display SFrame fixed RA offset as 'f' in dump

For the SFrame FRE frame-pointer (FP) offset from CFA a 'u' is displayed
if it is unavailable.

For the SFrame FRE return-address (RA) offset from CFA a 'u' was
displayed if the ABI uses a fixed RA offset from CFA. By chance a
'u' was also displayed if the RA offset is unavailable, as the string
buffer was not initialized after formatting the FP offset. Note that it
could not occur that the FP offset was erroneously displayed as RA
offset, as the SFrame format cannot have a FRE with FP offset without
RA offset.

For the FRE RA offset display 'f' if the ABI uses a fixed RA offset
from CFA. Display a 'u' if it is unavailable.

libsframe/
* sframe-dump.c: Display SFrame fixed RA offset as 'f' in dump.

gas/testsuite/
* gas/cfi-sframe/cfi-sframe-common-4.d: Test for RA displayed
either as 'u' (if RA tracking) or as 'f' (fixed RA offset if no
RA tracking).
* gas/cfi-sframe/cfi-sframe-common-5.d: Likewise.
* gas/cfi-sframe/cfi-sframe-common-6.d: Likewise.
* gas/cfi-sframe/cfi-sframe-common-7.d: Likewise.
* gas/cfi-sframe/cfi-sframe-common-8.d: Likewise.
* gas/cfi-sframe/cfi-sframe-x86_64-1.d: Test for RA displayed
as 'f' (fixed RA offset), as x86-64 does not use RA tracking.
* gas/scfi/x86_64/scfi-cfi-sections-1.d: Likewise.
* gas/scfi/x86_64/scfi-dyn-stack-1.d: Likewise.

ld/testsuite/
* ld-x86-64/sframe-plt-1.d: Test for RA displayed as 'f' (fixed
RA offset), as x86-64 does not use RA tracking.
* ld-x86-64/sframe-simple-1.d: Likewise.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
14 months agoreadelf/objdump: Dump SFrame CFA fixed FP and RA offsets
Jens Remus [Thu, 8 Feb 2024 12:34:29 +0000 (13:34 +0100)] 
readelf/objdump: Dump SFrame CFA fixed FP and RA offsets

The SFrame format allows architectures to specify fixed offsets from the
CFA, if any, from which the frame pointer (FP) and/or return address
(RA) may be recovered. These offsets are stored in the SFrame header.

For instance the SFrame generation in the assembler for x86 AMD64
specifies a fixed offset from the CFA, from which the return address
(RA) may be recovered.

When dumping the SFrame header, for instance in readelf/objdump with
option --sframe, do also dump the specified fixed offsets from the CFA,
if any, from which the frame pointer (FP) and return address (RA) may
be recovered.

Update the common SFrame test case verification patterns to allow for
the optional dumping of the CFA fixed FP/RA offsets. Update the x86-
specific SFrame and SCFI test case verification patterns to require a
CFA fixed RA offset of -8.

libsframe/
* sframe-dump.c: Dump CFA fixed FP and RA offsets.

gas/testsuite/
* gas/cfi-sframe/cfi-sframe-common-1.d: Test for optional fixed
FP and RA offsets.
* gas/cfi-sframe/cfi-sframe-common-2.d: Likewise.
* gas/cfi-sframe/cfi-sframe-common-3.d: Likewise.
* gas/cfi-sframe/cfi-sframe-common-4.d: Likewise.
* gas/cfi-sframe/cfi-sframe-common-5.d: Likewise.
* gas/cfi-sframe/cfi-sframe-common-6.d: Likewise.
* gas/cfi-sframe/cfi-sframe-common-7.d: Likewise.
* gas/cfi-sframe/cfi-sframe-common-8.d: Likewise.
* gas/cfi-sframe/cfi-sframe-x86_64-1.d: Test for fixed
RA offset.
* gas/cfi-sframe/common-empty-1.d: Test for optional fixed
FP and RA offsets.
* gas/cfi-sframe/common-empty-2.d: Likewise.
* gas/cfi-sframe/common-empty-3.d: Likewise.
* gas/scfi/x86_64/scfi-cfi-sections-1.d: Test for SFrame fixed
RA offset.
* gas/scfi/x86_64/scfi-dyn-stack-1.d: Likewise.

ld/testsuite/
* ld-x86-64/sframe-plt-1.d: Test for SFrame fixed RA offset.
* ld-x86-64/sframe-simple-1.d: Likewise.

Reviewed-by: Andreas Krebbel <krebbel@linux.ibm.com>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
14 months agogas: Enhance arch-specific SFrame configuration descriptions
Jens Remus [Mon, 26 Feb 2024 15:28:13 +0000 (16:28 +0100)] 
gas: Enhance arch-specific SFrame configuration descriptions

Explicitly mention "SFrame" in the descriptions for the architecture-
specific SFrame configuration macros, variables, and functions.

Use the term "frame pointer" (FP) instead of "base pointer". This aligns
with the terminology used in the SFrame specification. Additionally it
helps not to confuse "base-pointer register" with the term "BASE_REG"
used in the specification to denote either the SP or FP register.

Specify what the SFRAME_CFA_*_REG register numbers are used for:
- SP (stack pointer): CFA tracking
- FP (frame pointer): CFA and FP tracking
- RA (return address): RA tracking

Align the descriptions for definitions in the source files to the
declarations in the header files.

gas/
* config/tc-aarch64.h: Enhance architecture-specific SFrame
configuration descriptions.
* config/tc-aarch64.c: Likewise.
* config/tc-i386.h: Likewise.
* config/tc-i386.c: Likewise.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
14 months agox86: Remove unused SFrame CFI RA register variable
Jens Remus [Thu, 1 Feb 2024 16:35:28 +0000 (17:35 +0100)] 
x86: Remove unused SFrame CFI RA register variable

gas/
* config/tc-i386.c: Remove unused SFrame CFI RA register
variable.

Reviewed-by: Andreas Krebbel <krebbel@linux.ibm.com>
Reviewed-by: Indu Bhagat <indu.bhagat@oracle.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
15 months agotestsuite: libsframest: more renames
Indu Bhagat [Mon, 29 Apr 2024 22:57:21 +0000 (15:57 -0700)] 
testsuite: libsframest: more renames

and fixing some formatting issues.

ChangeLog:
* include/sframe-stacktrace-api.h
* sframe-stacktrace.c
* sframe-state.c
* sframe-state.h

15 months agotestsuite: libsframest: create new sframest_sfinfo_init
Indu Bhagat [Mon, 29 Apr 2024 20:55:36 +0000 (13:55 -0700)] 
testsuite: libsframest: create new sframest_sfinfo_init

ChangeLog:
* sframe-state.c
* sframe-state.h

15 months agotestsuite: libsframest: define a new function sframest_sfinfo_addr_range_p
Indu Bhagat [Mon, 29 Apr 2024 19:02:25 +0000 (12:02 -0700)] 
testsuite: libsframest: define a new function sframest_sfinfo_addr_range_p

Use this function consistently and remove unnecessary API
sframest_update_sfinfo.

ChangeLog:
* sframe-stacktrace.c
* sframe-state.c
* sframe-state.h

15 months agomore renames for readability
Indu Bhagat [Sat, 27 Apr 2024 15:01:38 +0000 (08:01 -0700)] 
more renames for readability

ChangeLog:
* sframe-stacktrace.c
* sframe-state.c
* sframe-state.h

15 months agotestsuite: libsframest: rename for readability
Indu Bhagat [Fri, 26 Apr 2024 23:15:57 +0000 (16:15 -0700)] 
testsuite: libsframest: rename for readability

Some struct names and member names were long and unintuitive.  Reduce
the technical debt and make the code hopefully easier to maintain.

libsframe/testsuite/
* libsframe.stacktrace/libsframest/sframe-stacktrace.c
* libsframe.stacktrace/libsframest/sframe-state.c
* libsframe.stacktrace/libsframest/sframe-state.h

15 months agotestsuite: libsframest: use shorter version in conditionals
Indu Bhagat [Fri, 26 Apr 2024 18:58:41 +0000 (11:58 -0700)] 
testsuite: libsframest: use shorter version in conditionals

libsframe/testsuite/

* libsframe.stacktrace/libsframest/sframe-stacktrace.c
* libsframe.stacktrace/libsframest/sframe-state.c

15 months agolibsframest: use access API instead of direct access using FRE info
Indu Bhagat [Fri, 26 Apr 2024 18:28:38 +0000 (11:28 -0700)] 
libsframest: use access API instead of direct access using FRE info

libsframe/testsuite/

            * libsframe.stacktrace/libsframest/sframe-backtrace.c

15 months agolisbframest: remove unnecessary arch-specific code
Indu Bhagat [Thu, 25 Apr 2024 20:25:33 +0000 (13:25 -0700)] 
lisbframest: remove unnecessary arch-specific code

ChangeLog:
* libsframe/testsuite/libsframe.stacktrace/libsframest
/sframe-stacktrace.c (sframe_unwind): Remove unnecessary guards
and arch-specific handling.

15 months agotestsuite: minor housekeeping
Indu Bhagat [Thu, 25 Apr 2024 16:37:28 +0000 (09:37 -0700)] 
testsuite: minor housekeeping

Fix some code formatting nits.

libsframe/testsuite/

        * libsframe.stacktrace/libsframest/sframe-stacktrace-err.c:
        * libsframe.stacktrace/libsframest/sframe-stacktrace.c:
        * libsframe.stacktrace/libsframest/sframe-state.c:
        * libsframe.stacktrace/libsframest/sframe-state.h:
        * libsframe.stacktrace/stacktrace-inline-2.c:

15 months agotestsuite: libsframest: use as, ld, collect-ld from build dir
Indu Bhagat [Tue, 23 Apr 2024 23:00:49 +0000 (16:00 -0700)] 
testsuite: libsframest: use as, ld, collect-ld from build dir

instead of host's as and ld.  Also disable libsframest build if cross
compiling.  The testsuite will consequently also be skipped.

Override the check-am make target and first execute setup.sh to bring in
the as-new / ld-new and use -B<path> to ensure these are picked up for
building:
  - libsframest
  - libsframe.stacktrace testsuite

Remove the configure time variable HAVE_SFRAME_AS as it is now
unnecessary.

TBD:
  - Get review on whether the whole setup.sh way of doing this is OK.
    But it seems there is no other way ?
  - Check the portability of the setup.sh script.

ChangeLog:
* libsframe/Makefile.am: Override check-am to first run setup.sh
before invoking make.  This ensures libsframest is built with
the newly setup tmpdir/libsframe.
* libsframe/Makefile.in: Regenerate.
* libsframe/acinclude.m4: Delete.
* libsframe/aclocal.m4: Remove include for acinclude.m4.
* libsframe/configure: Regenerate.
* libsframe/configure.ac: Remove HAVE_SFRAME_AS.  Add a new
AM_CONDITIONAL for CROSS_COMPILE.
* libsframe/setup.sh: New file.
* libsframe/testsuite/config/default.exp: Remove the creation
and setup of tmpdir/lisframe.
* libsframe/testsuite/lib/sframe-lib.exp: Use -B<path> to use
the as/ld from build tree.
* libsframe/testsuite/libsframe.stacktrace/libsframest/local.mk:
Use -B<path> and use the as/ld from build tree.
* libsframe/testsuite/libsframe.stacktrace/stacktrace.exp: Skip
testing if cross build.

15 months agolibsframest: use as a test tool instead
Indu Bhagat [Thu, 16 Feb 2023 21:57:58 +0000 (13:57 -0800)] 
libsframest: use as a test tool instead

Add a configure time check for dl_iterate_phdr and run
libsframe.stacktrace testsuite using libsframest.  libsframest is the
library for stack tracing using the SFrame stack trace format.

libsframest is not installed anymore but used in the testsuite only.

TBD:
  - More renamings are in order.
  - Cleanup the .exp files.
  - Disable (libsframest based) stack tracer tests in a cross build

15 months agotestsuite: sframebt: Add backtrace-1 which uses -O2 always
Indu Bhagat [Tue, 8 Nov 2022 05:59:06 +0000 (21:59 -0800)] 
testsuite: sframebt: Add backtrace-1 which uses -O2 always

Keep a testcase with an explicit -O2 for testing purposes.

15 months agotestsuite: sframebt: Use -fno-optimize-sibling-calls
Weimin Pan [Sat, 11 Feb 2023 00:00:50 +0000 (16:00 -0800)] 
testsuite: sframebt: Use -fno-optimize-sibling-calls

With -O2 and above, the compiler performs a sibling call optimization as
main () and it's callee have compatible stack usage.  As for generating
stack traces though, there is nothing that any stack trace or unwind
format can do here.  Use -fno-optimize-sibling-calls to at least ensure
the testcase checkes for the complete stack trace.

ChangeLog:

* libsframe/testsuite/libsframe.unwind/backtrace-fp-attr-1.lk:
Use -fno-optimize-sibling-calls.
* libsframe/testsuite/libsframe.unwind/backtrace-fp-attr-2.lk:
Likewise.

15 months agosframebt: Factor register access code into a header file
Weimin Pan [Fri, 10 Feb 2023 23:43:53 +0000 (15:43 -0800)] 
sframebt: Factor register access code into a header file

ChangeLog:

* libsframe/sframe-backtrace-regs.h: New file.
* libsframe/sframe-backtrace.c: Use the new abstractions.

15 months agounwinder: Add SFrame unwinder tests
Weimin Pan [Tue, 27 Sep 2022 22:24:47 +0000 (15:24 -0700)] 
unwinder: Add SFrame unwinder tests

[Changes in V4]
  - Addressed Mike's review comments.
    - Be careful with the use of # and dnl in configure.ac
    - Add AC_CANONICAL_TARGET as we check for target.
    - Remove the LC_ALL=C bits.
  - Minor code fixups in the testcases
    - Removed unnecessary unistd.h.
    - use ATTRIBUTE_NOCLONE consistently.
    - Other minor cleanups.
[End of changes in V4]

[Changes in V3]
  - Added two new tests with attributes -f(no-)omit-frame-pointer.
  - Minor adjustments due to buildsystem changes in libsframe.
[End of changes in V3]

[Changes in V2]
  - minor changes in filenames in the testsuite.
[End of changes in V2]

Add tests for backtracing using SFrame section.

ChangeLog:

* libsframe/Makefile.in: Regenerated.
* libsframe/configure: Regenerated.
* libsframe/configure.ac: Check for cross compilation.
* libsframe/testsuite/Makefile.in: Regenerated.
* libsframe/testsuite/config/default.exp: Load
  sframe-lib.exp.
* libsframe/testsuite/libsframe.decode/Makefile.in:
  Regenerated.
* libsframe/testsuite/libsframe.encode/Makefile.in:
  Regenerated.
* libsframe/testsuite/lib/sframe-lib.exp: New file.  Add
  procedures for handling unwinder tests.
* libsframe/testsuite/libsframe.unwind/backtrace.c: New test.
* libsframe/testsuite/libsframe.unwind/backtrace.lk: New test.
* libsframe/testsuite/libsframe.unwind/inline-cmds.c: New test.
* libsframe/testsuite/libsframe.unwind/inline-cmds.lk: New test.
* libsframe/testsuite/libsframe.unwind/inline.c: New test.
* libsframe/testsuite/libsframe.unwind/inline.lk: New test.
* libsframe/testsuite/libsframe.unwind/solib-lib1.c: New test.
* libsframe/testsuite/libsframe.unwind/solib-lib2.c: New test.
* libsframe/testsuite/libsframe.unwind/solib-main.c: New test.
* libsframe/testsuite/libsframe.unwind/solib-main.d: New test.
* libsframe/testsuite/libsframe.unwind/solib.exp: New file.
* libsframe/testsuite/libsframe.unwind/solib-lib1.h: New test.
* libsframe/testsuite/libsframe.unwind/solib-lib2.h: New test.
* libsframe/testsuite/libsframe.unwind/tailcall.c: New test.
* libsframe/testsuite/libsframe.unwind/tailcall.lk: New test.
* libsframe/testsuite/libsframe.unwind/ttest.c: New test.
* libsframe/testsuite/libsframe.unwind/ttest.lk: New test.
* libsframe/testsuite/libsframe.unwind/unwind.exp: New file.
* libsframe/testsuite/libsframe.unwind/backtrace-fp-attr-1.c:
  Likewise.
* libsframe/testsuite/libsframe.unwind/backtrace-fp-attr-1.lk:
  Likewise.
* libsframe/testsuite/libsframe.unwind/backtrace-fp-attr-2.c:
  Likewise.
* libsframe/testsuite/libsframe.unwind/backtrace-fp-attr-2.lk:
  Likewise.

15 months agounwinder: generate backtrace using SFrame format
Weimin Pan [Tue, 27 Sep 2022 21:58:04 +0000 (14:58 -0700)] 
unwinder: generate backtrace using SFrame format

[Changes in V4]
  - Renamed ESFRAME_* enum error code names to SFRAME_ERR_*.
  - Addressed review comments by Mike.
    - Use AC_CACHE_CHECK macro in sframe.m4
    - Delete config/sframe.m4. Add into libsframe/acinclude.m4.
    - Code fixups.
[End of changes in V4]

[Changes in V3]
  - Use the updated APIs from libsframe.
  - Use sframe_decoder_get_fixed_ra_offset on AMD64 instead of magic
    number -8.
[End of changes in V3]

[Changes in V2]
  - Minor formatting fixes.
[End of changes in V2]

A simple unwinder based on SFrame format.

The unwinder is made available via libsframebt library.

Buildsystem changes have been made to build libsframebt only when
--gsframe support is available in the assembler. These buildsystem
changes are necessary because the SFrame based unwinder the SFrame
unwind info for itself to work.

include/ChangeLog:

* sframe-backtrace-api.h: New file.

ChangeLog:

* libsframe/acinclude.m4: New file.
* libsframe/Makefile.am: Build backtrace functionality in its
own library.  Install libsframebt conditionally.
* libsframe/Makefile.in: Regenerate.
* libsframe/aclocal.m4: Regenerate.
* libsframe/configure: Regenerate.
* libsframe/configure.ac: Check if gas supports --gsframe
command line option.
* libsframe/sframe-backtrace-err.c: New file.
* libsframe/sframe-backtrace.c: New file.

15 months agobpf: fix calculation when deciding to relax branch
David Faust [Thu, 25 Apr 2024 18:40:31 +0000 (11:40 -0700)] 
bpf: fix calculation when deciding to relax branch

In certain cases we were calculating the jump displacement incorrectly
when deciding whether to relax a branch.  This meant for some branches,
such as a very long backwards conditional branch, relaxation was not
done when it should have been.  The result was to error later, because
the actual jump displacement was too large to fit in the original
instruction.

This patch fixes up the displacement calculation so that those branches
are correctly relaxed and no longer result in an error.  In addition, it
changes md_convert_frag to install fixups for the JAL instructions in
the resulting relaxations rather than encoding the displacement value
directly.

gas/
* config/tc-bpf.c (relaxed_branch_length): Correct displacement
calculation when relaxing.
(md_convert_frag): Likewise.  Install fixups for JAL
instructions resulting from relaxation.
* testsuite/gas/bpf/jump-relax-ja-be.d: Correct and expand test.
* testsuite/gas/bpf/jump-relax-ja.d: Likewise.
* testsuite/gas/bpf/jump-relax-ja.s: Likewise.
* testsuite/gas/bpf/jump-relax-jump-be.d: Likewise.
* testsuite/gas/bpf/jump-relax-jump.d: Likewise.
* testsuite/gas/bpf/jump-relax-jump.s: Likewise.

15 months agogdb: add type annotations to ada-unicode.py
Simon Marchi [Thu, 25 Apr 2024 17:26:11 +0000 (13:26 -0400)] 
gdb: add type annotations to ada-unicode.py

Add type annotations to ada-unicode.py, just enough to make pyright
happy:

    $ pyright --version
    pyright 1.1.359
    $ pyright ada-unicode.py
    0 errors, 0 warnings, 0 informations

Introduce a `Range` class instead of using separate variables and
tuples, to make the code and type annotations a bit cleaner.

When running ada-unicode.py, I get a diff for ada-casefold.h, but I get
the same diff before and after this patch, so that is a separate issue.

Change-Id: I0d8975a57f9fb115703178ae197dc6b6b8b4eb7a
Approved-By: Tom Tromey <tom@tromey.com>
15 months agogdb: remove gdbcmd.h
Simon Marchi [Tue, 23 Apr 2024 19:22:44 +0000 (15:22 -0400)] 
gdb: remove gdbcmd.h

Most files including gdbcmd.h currently rely on it to access things
actually declared in cli/cli-cmds.h (setlist, showlist, etc).  To make
things easy, replace all includes of gdbcmd.h with includes of
cli/cli-cmds.h.  This might lead to some unused includes of
cli/cli-cmds.h, but it's harmless, and much faster than going through
the 170 or so files by hand.

Change-Id: I11f884d4d616c12c05f395c98bbc2892950fb00f
Approved-By: Tom Tromey <tom@tromey.com>
15 months agogdb: move style_set_list/style_show_list declarations to cli/cli-style.h
Simon Marchi [Tue, 23 Apr 2024 19:22:43 +0000 (15:22 -0400)] 
gdb: move style_set_list/style_show_list declarations to cli/cli-style.h

They are defined in cli/cli-style.c.

Change-Id: Ic478a3985ff0fd773bd7ba85bb144c6e914d0be6
Approved-By: Tom Tromey <tom@tromey.com>
15 months agogdb: remove unused print_command_line and print_command_lines declarations
Simon Marchi [Tue, 23 Apr 2024 19:22:42 +0000 (15:22 -0400)] 
gdb: remove unused print_command_line and print_command_lines declarations

There is no corresponding definition for print_command_line.

There is already a declaration for print_command_lines in
cli/cli-script.h (the implementation is in cli/cli-script.c).

Change-Id: Ic9e67ed04703306d614383ead14e2b2b059b2a8e
Approved-By: Tom Tromey <tom@tromey.com>
15 months agogdb: move execute function declarations from gdbcmd.h to top.h
Simon Marchi [Tue, 23 Apr 2024 19:22:41 +0000 (15:22 -0400)] 
gdb: move execute function declarations from gdbcmd.h to top.h

These functions are implemented in top.c, move their declarations to
top.h.

Change-Id: I8893ef91d955156a6530734fefe8002d78c3e5fc
Approved-By: Tom Tromey <tom@tromey.com>
15 months agoLoongArch: gas: Simplify relocations in sections without code flag
Jinyang He [Mon, 22 Apr 2024 09:49:50 +0000 (17:49 +0800)] 
LoongArch: gas: Simplify relocations in sections without code flag

Gas should not emit ADD/SUB relocation pairs for label differences
if they are in the same section without code flag even relax enabled.
Because the real value is not be affected by relaxation and it can be
compute out in assembly stage. Thus, correct the `TC_FORCE_RELOCATION
_SUB_SAME` and the label differences in same section without code
flag can be resolved in fixup_segment().

15 months agoLoongArch: Add bad static relocation check and output more information to user
Lulu Cai [Tue, 19 Mar 2024 09:51:19 +0000 (17:51 +0800)] 
LoongArch: Add bad static relocation check and output more information to user

Absolute address symbols cannot be used with -shared.
We output more information to the user than just BFD_ASSETR.

15 months agoLoongArch: The symbol got type can only be obtained after initialization
Lulu Cai [Fri, 19 Apr 2024 02:24:52 +0000 (10:24 +0800)] 
LoongArch: The symbol got type can only be obtained after initialization

When scanning relocations and determining whether TLS type transition is
possible, it will try to obtain the symbol got type. If the symbol got
type record has not yet been allocated space and initialized, it will
cause ld to crash. So when uninitialized, the symbol is set to GOT_UNKNOWN.

15 months agoAutomatic date update in version.in
GDB Administrator [Thu, 25 Apr 2024 00:00:13 +0000 (00:00 +0000)] 
Automatic date update in version.in

15 months agogdb/testsuite: Add libc_has_debug_info require helper
Thiago Jung Bauermann [Fri, 19 Apr 2024 06:02:46 +0000 (03:02 -0300)] 
gdb/testsuite: Add libc_has_debug_info require helper

Factor the test for libc debug info out of gdb.base/relativedebug.exp to
a new procedure.

Also, change the "info sharedlibrary" test to explicitly detect when
libc has debug info.

Approved-by: Kevin Buettner <kevinb@redhat.com>
15 months agogdb/doc: Fix incorrect information in RSP doc
Ciaran Woodward [Mon, 22 Apr 2024 15:09:57 +0000 (15:09 +0000)] 
gdb/doc: Fix incorrect information in RSP doc

The 'PacketSize' attribute of the qSupported packet was
documented to be the maximum size of the packet including
the frame and checksum bytes, however this is not how it
was treated in the code. In reality, PacketSize is the
maximum size of the data in the RSP packets, not including
the framing or checksum bytes.

For instance, GDB's remote.c treats it as the maximum
number of data bytes.  See remote_read_bytes_1, where the
size of the request is capped at PacketSize/2 (for
hex-encoding).

Also see gdbserver's server.cc, where the internal buffer
is sized as PBUFSIZ and PBUFSIZ-1 is used as PacketSize.
In gdbserver's case, the buffer is not used for any of the
framing or checksum characters. (I am not certain where the -1
comes from. I think it comes from back when there were no
binary packets, so packets were treated as strings with
null terminators).

It also seems like gdbservers in the wild treat it in
this way:

Embocosm doc:
https://www.embecosm.com/appnotes/ean4/embecosm-howto-rsp-server-ean4-issue-2.html#id3078000

A quick glance over openocd's gdb_server.c gdb_put_packet_inner()
function shows that the internal buffer also excludes the framing
and checksum.

Likewise, qEmu's gdbstub.c allocates PacketSize bytes for
the internal packet contents, and PacketSize+4 for the
full frame.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Pedro Alves <pedro@palves.net>
15 months agoHandle two-linetable function in find_epilogue_using_linetable
Bernd Edlinger [Tue, 9 Apr 2024 09:27:53 +0000 (09:27 +0000)] 
Handle two-linetable function in find_epilogue_using_linetable

Consider the following test-case:
...
$ cat hello.c
int main()
{
  printf("hello ");
  #include "world.inc"
$ cat world.inc
  printf("world\n");
  return 0;
}
$ gcc -g hello.c
...

The line table for the compilation unit, consisting just of
function main, is translated into these two gdb line tables, one for hello.c
and one for world.inc:
...
compunit_symtab: hello.c
symtab: hello.c
INDEX  LINE   REL-ADDRESS UNREL-ADDRESS IS-STMT PROLOGUE-END EPILOGUE-BEGIN
0      3      0x400557    0x400557      Y
1      4      0x40055b    0x40055b      Y
2      END    0x40056a    0x40056a      Y

compunit_symtab: hello.c
symtab: world.inc
INDEX  LINE   REL-ADDRESS UNREL-ADDRESS IS-STMT PROLOGUE-END EPILOGUE-BEGIN
0      1      0x40056a    0x40056a      Y
1      2      0x400574    0x400574      Y
2      3      0x400579    0x400579      Y
3      END    0x40057b    0x40057b      Y
...

The epilogue of main starts at 0x400579:
...
  400579: 5d                    pop    %rbp
  40057a: c3                    ret
...

Now, say we have an epilogue_begin marker in the line table at 0x400579.

We won't find it using find_epilogue_using_linetable, because it does:
...
  const struct symtab_and_line sal = find_pc_line (start_pc, 0);
...
which gets us the line table for hello.c.

Fix this by using "find_pc_line (end_pc - 1, 0)" instead.

Tested on x86_64-linux.

Co-Authored-By: Tom de Vries <tdevries@suse.de>
PR symtab/31622
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31622

15 months agoFix an out of bounds array access in find_epilogue_using_linetable
Bernd Edlinger [Tue, 9 Apr 2024 09:27:52 +0000 (09:27 +0000)] 
Fix an out of bounds array access in find_epilogue_using_linetable

An out of bounds array access in find_epilogue_using_linetable causes random
test failures like these:

FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: $fba_value == $fn_fba
FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: check frame-id matches
FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: bt 2
FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: up
FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: $sp_value == $::main_sp
FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: $fba_value == $::main_fba
FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: [string equal $fid $::main_fid]

Here the read happens below the first element of the line
table, and the test failure depends on the value that is
read from there.

It also happens that std::lower_bound returns a pointer exactly at the upper
bound of the line table, also here the read value is undefined, that happens
in this test:

FAIL: gdb.dwarf2/dw2-epilogue-begin.exp: confirm watchpoint doesn't trigger

Fixes: 528b729be1a2 ("gdb/dwarf2: Add support for DW_LNS_set_epilogue_begin in line-table")
Co-Authored-By: Tom de Vries <tdevries@suse.de>
PR symtab/31268
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31268

15 months ago[gdb/testsuite] Fix gdb.threads/threadcrash.exp for remote host
Tom de Vries [Wed, 24 Apr 2024 13:36:02 +0000 (15:36 +0200)] 
[gdb/testsuite] Fix gdb.threads/threadcrash.exp for remote host

With test-case gdb.threads/threadcrash.exp using host board local-remote-host
and target board remote-gdbserver-on-localhost I run into:
...
(gdb) PASS: gdb.threads/threadcrash.exp: test_gcore: continue to crash
gcore $outputs/gdb.threads/threadcrash/threadcrash.gcore^M
Failed to open '$outputs/gdb.threads/threadcrash/threadcrash.gcore' for output.^M
(gdb) FAIL: gdb.threads/threadcrash.exp: test_gcore: saving gcore
UNSUPPORTED: gdb.threads/threadcrash.exp: test_gcore: couldn't generate gcore file
...

The problem is that the gcore command tries to save a file on a remote host,
but the filename is a location on build.

Fix this by using host_standard_output_file.

Tested on x86_64-linux.

15 months ago[gdb/testsuite] Fix gdb.threads/threadcrash.exp with glibc debuginfo
Tom de Vries [Wed, 24 Apr 2024 13:36:02 +0000 (15:36 +0200)] 
[gdb/testsuite] Fix gdb.threads/threadcrash.exp with glibc debuginfo

After installing glibc debuginfo, I ran into:
...
FAIL: gdb.threads/threadcrash.exp: test_live_inferior: \
  $thread_count == [llength $test_list]
...

This happens because the clause:
...
-re "^\r\n${hs}main$hs$eol" {
...
which is intended to match only:
...
 #1  <hex> in main () at threadcrash.c:423^M
...
also matches "remaining" in:
...
 #1  <hex> in __GI___nanosleep (requested_time=<hex>, remaining=<hex>) at \
   nanosleep.c:27^M
...

Fix this by checking for "in main" instead.

Tested on x86_64-linux.

15 months agoUpdate readelf's display of RELR sections to include the number of locations relocated
Nick Clifton [Wed, 24 Apr 2024 11:45:04 +0000 (12:45 +0100)] 
Update readelf's display of RELR sections to include the number of locations relocated

15 months agogdb: include extract-store-integer.h in charset.c when PHONY_ICONV
Simon Marchi [Wed, 24 Apr 2024 02:52:00 +0000 (02:52 +0000)] 
gdb: include extract-store-integer.h in charset.c when PHONY_ICONV

When building on a system where "phony iconv" is used (NetBSD in this
case, not sure why), I get:

      CXX    charset.o
    /home/smarchi/src/binutils-gdb/gdb/charset.c: In function 'size_t phony_iconv(int, const char**, size_t*, char**, size_t*)':
    /home/smarchi/src/binutils-gdb/gdb/charset.c:140:8: error: 'extract_unsigned_integer' was not declared in this scope
          = extract_unsigned_integer ((const gdb_byte *)*inbuf, 4, endian);
            ^~~~~~~~~~~~~~~~~~~~~~~~
    /home/smarchi/src/binutils-gdb/gdb/charset.c:140:8: note: suggested alternative: 'btrace_insn_number'
          = extract_unsigned_integer ((const gdb_byte *)*inbuf, 4, endian);
            ^~~~~~~~~~~~~~~~~~~~~~~~
            btrace_insn_number

Add the necessary include.

Change-Id: I10b967584645961c86167a8395d88929a42bef03

15 months agoPPC maintainers
Alan Modra [Wed, 24 Apr 2024 01:34:04 +0000 (11:04 +0930)] 
PPC maintainers

I'm retiring from IBM, and Geoff hasn't been active for a very long
time.

* MAINTAINERS (ppc): Remove myself and Geoff Keating.  Add
Geoff to past maintainers.

15 months agobuffer overflow in libctf tests
Alan Modra [Wed, 24 Apr 2024 00:00:24 +0000 (09:30 +0930)] 
buffer overflow in libctf tests

       * testsuite/libctf-regression/gzrewrite.c (main): Don't overflow
       "a" buffer in "after adding types" check.
       * testsuite/libctf-regression/zrewrite.c (main): Likewise.

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

15 months agogdb: adjust copyright years of extract-store-integer.{c,h}
Simon Marchi [Tue, 23 Apr 2024 20:13:33 +0000 (16:13 -0400)] 
gdb: adjust copyright years of extract-store-integer.{c,h}

The contents of these files was copied from defs.h and findvar.  Copy
over the copyright years (1986-2024).

Change-Id: Idfb0f255fbcfda7e107e9a82804cece3d81ed5fc

15 months agoarm: Fix MVE vmla encoding
Claudio Bantaloukas [Tue, 23 Apr 2024 16:59:57 +0000 (17:59 +0100)] 
arm: Fix MVE vmla encoding

15 months agobfd: Remove duplicate word in elf-vxworks.c
Olivier Hainque [Mon, 22 Apr 2024 05:50:28 +0000 (02:50 -0300)] 
bfd: Remove duplicate word in elf-vxworks.c

PR ld/31652
* elf-vxworks.c  (elf_vxworks_emit_relocs): Drop duplicate word.

15 months agoobjcopy.c: Fix bfd_copy_private_symbol_data on 32-bit hosts
H.J. Lu [Tue, 23 Apr 2024 14:07:51 +0000 (07:07 -0700)] 
objcopy.c: Fix bfd_copy_private_symbol_data on 32-bit hosts

Use long with bfd_copy_private_symbol_data to fix

.../binutils/objcopy.c: In
function â€˜copy_object’:
.../binutils/objcopy.c:3383:17: error: comparison of integer expressions of different signedness: â€˜unsigned int’ and â€˜long int’ [-Werror=sign-compare]
 3383 |   for (i = 0; i < symcount; i++)
      |                 ^

on 32-bit hosts.

PR binutils/14493
* objcopy.c (copy_object): Use long with
bfd_copy_private_symbol_data.

15 months agogdb: move symbol_file_command declaration to symfile.h
Simon Marchi [Tue, 23 Apr 2024 13:23:02 +0000 (09:23 -0400)] 
gdb: move symbol_file_command declaration to symfile.h

Move it out of defs.h, the corresponding definition is in symfile.c.

Change-Id: I984666c3bcd213f8574e9ec91462e1d61f77f16b
Approved-By: Tom Tromey <tom@tromey.com>
15 months agogdb: remove enum precision_type
Simon Marchi [Tue, 23 Apr 2024 13:23:01 +0000 (09:23 -0400)] 
gdb: remove enum precision_type

It is unused.

Change-Id: Ic49a3ef03c21b209594cd567ae80b5441606bef6
Approved-By: Tom Tromey <tom@tromey.com>
15 months agogdb: move annotation_level declaration/definition to annotate.{h,c}
Simon Marchi [Tue, 23 Apr 2024 13:23:00 +0000 (09:23 -0400)] 
gdb: move annotation_level declaration/definition to annotate.{h,c}

The declaration of annotation_level is currently in defs.h, while the
definition is in stack.c.  I don't really understand why that variable
would live in stack.c, it seems completely unrelated.  Move it to
annotate.c, and move the declaration to annotate.h.

Change-Id: I6cf8e9bd20e83959bdf5ad58dd008b6e1187d7d8
Approved-By: Tom Tromey <tom@tromey.com>
15 months agogdb: move a bunch of quit-related things to event-top.{c,h}
Simon Marchi [Tue, 23 Apr 2024 13:22:59 +0000 (09:22 -0400)] 
gdb: move a bunch of quit-related things to event-top.{c,h}

Move some declarations related to the "quit" machinery from defs.h to
event-top.h.  Most of the definitions associated to these declarations
are in event-top.c.  The exceptions are `quit()` and `maybe_quit()`,
that are defined in utils.c.  For consistency, move these two
definitions to event-top.c.

Include "event-top.h" in many files that use these things.

Change-Id: I6594f6df9047a9a480e7b9934275d186afb14378
Approved-By: Tom Tromey <tom@tromey.com>
15 months agogdb: change type of quit_flag to bool
Simon Marchi [Tue, 23 Apr 2024 13:22:58 +0000 (09:22 -0400)] 
gdb: change type of quit_flag to bool

Change-Id: I7dc5189ee172e82ef5b2c4a739c011f43a84258b
Approved-By: Tom Tromey <tom@tromey.com>
15 months agogdb: change return type of check_quit_flag to bool
Simon Marchi [Tue, 23 Apr 2024 13:22:57 +0000 (09:22 -0400)] 
gdb: change return type of check_quit_flag to bool

Change the return type of the check_quit_flag function to bool.  Update
a few related spots.

Change-Id: I9d3a15d3f8651efb02c7d211f06222a592bd4184
Approved-By: Tom Tromey <tom@tromey.com>
15 months agogdb: move declarations of check_quit_flag and set_quit_flag to extension.h
Simon Marchi [Tue, 23 Apr 2024 13:22:56 +0000 (09:22 -0400)] 
gdb: move declarations of check_quit_flag and set_quit_flag to extension.h

Move them out of defs.h, to extension.h, since the implementations are
in extension.c.

Change-Id: Ie7321468bd7fecc684d70b09f72c3ee8ac75d8f4
Approved-By: Tom Tromey <tom@tromey.com>
15 months agogdb: remove unused include in infrun.c
Simon Marchi [Tue, 23 Apr 2024 15:18:06 +0000 (11:18 -0400)] 
gdb: remove unused include in infrun.c

Remove the gdbcmd.h, which is reported as unused by clangd.  Add
cli/cli-cmds.h instead, to get access to `cmdlist` and friends.

Change-Id: Ic0c60d2f6d3618f1bd9fd80b95ffd7c33c692a04

15 months agoobjdump: Round ASCII art lines in jump visualization
Waqar Hameed [Tue, 23 Apr 2024 15:10:50 +0000 (16:10 +0100)] 
objdump: Round ASCII art lines in jump visualization

15 months agogdb/dwarf2/read.c: remove pessimizing std::move
Simon Marchi [Mon, 22 Apr 2024 19:01:37 +0000 (15:01 -0400)] 
gdb/dwarf2/read.c: remove pessimizing std::move

When building with this clang:

    $ c++ --version
    FreeBSD clang version 16.0.6 (https://github.com/llvm/llvm-project.git llvmorg-16.0.6-0-g7cbf1a259152)

I see:

    $ gmake
      CXX    dwarf2/read.o
    /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:4890:6: error: moving a temporary object prevents copy elision [-Werror,-Wpessimizing-move]
                                            std::move (thread_storage.release_parent_map ()));
                                            ^
    /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:4890:6: note: remove std::move call here
                                            std::move (thread_storage.release_parent_map ()));
                                            ^~~~~~~~~~~                                    ~

The compiler seems right, there is not need to std::move the result of
`release_parent_map ()`, it's already going to be an rvalue.  Remove the
std::move.

The issue isn't FreeBSD-specific, I see it on Linux as well when
building hwith clang, I just noticed it on a FreeBSD build first.

Change-Id: I7aa20a4db56c799f20d838ad08099a01653bba19
Approved-By: Tom Tromey <tom@tromey.com>
15 months agogdb: bump black version to 24.4.0
Simon Marchi [Tue, 23 Apr 2024 01:43:02 +0000 (21:43 -0400)] 
gdb: bump black version to 24.4.0

Run `pre-commit autoupdate`, this is the outcome.  There is no change in
formatting of Python files.

Change-Id: I977781fa6cc924c398cc3b9d9954dc0fbb95d082

15 months agoPR31667, objcopy/strip corrupts solaris binaries
Alan Modra [Mon, 22 Apr 2024 09:38:51 +0000 (19:08 +0930)] 
PR31667, objcopy/strip corrupts solaris binaries

Using want_p_paddr_set_to_zero in commit 45d92439aebd was wrong.  Even
solaris targets don't have want_p_paddr_set_to_zero, but we should
handle them at least somewhat reasonably.

PR 31667
* elf.c (IS_SECTION_IN_INPUT_SEGMENT): Remove bed arg, add
paddr_valid.  Don't use bed->want_p_paddr_set_to_zero.
(INCLUDE_SECTION_IN_SEGMENT): Likewise.
(rewrite_elf_program_header): Adjust to suit.

15 months agoignore some symbols in elf.c:swap_out_syms
Alan Modra [Sun, 21 Apr 2024 23:59:28 +0000 (09:29 +0930)] 
ignore some symbols in elf.c:swap_out_syms

The reason behind this patch was noticing that generic ELF targets
fail to remove "bar" in the recently committed ld-elf/undefweak-1
test.  (Despite that, those targets pass the test due to it being too
strict when matching symbols.  "bar" gets turned into a local weak
defined absolute symbol.)

swap_out_syms currently drops local section syms that are defined in
discarded sections.  Extend that to also drop other symbols in
discarded sections too, even global symbols.  The linker goes to quite
a lot of effort to ensure globals in discarded section take a
definition from the kept linkonce or comdat group section.  So the
global sym change should only affect cases where something is quite
wrong about the set of linkonce or comdat group sections.  However
that change to elf_map_symbols meant we dropped _DYNAMIC_LINK /
_DYNAMIC_LINKING for mips, a global absolute symbol given STT_SECTION
type for some reason.  That problem is fixed by reverting the pr14493
change which is no longer needed due to a) BSF_SECTION_SYM_USED on
x86, and b) fixing objcopy to use copy_private_symbol_data.

bfd/
PR 14493
* elf.c (ignore_sym): Rename from ignore_section_sym.  Return
true for any symbol without a section or in a discarded section.
Revert pr14493 change.
(elf_map_symbols): Tidy.  Use ignore_sym on all symbols.
(swap_out_syms): Tidy.
ld/
* testsuite/ld-elf/undefweak-1.rd: Match any "bar".

15 months agoxfail undefweak-1 test for alpha
Alan Modra [Fri, 19 Apr 2024 23:24:07 +0000 (08:54 +0930)] 
xfail undefweak-1 test for alpha

".set" has a different meaning on alpha.  Changing it to ".equ" runs
into ".equ" having a different meaning on hppa, and changing it to "="
runs into trouble on bfin.

* testsuite/ld-elf/elf.exp (undefweak-1): xfail on alpha,
don't xfail for genelf.

15 months agouse copy_private_symbol_data in objcopy
Alan Modra [Mon, 22 Apr 2024 00:00:38 +0000 (09:30 +0930)] 
use copy_private_symbol_data in objcopy

osympp appearing twice here is not a bug.

PR 14493
* objcopy.c (copy_object): Run the symbols through
bfd_copy_private_symbol_data.

15 months agocopy_private_symbol_data
Alan Modra [Mon, 22 Apr 2024 00:00:23 +0000 (09:30 +0930)] 
copy_private_symbol_data

bfd_copy_private_symbol_data is a bfd function that appeared in
commit 89665c8562da a long time ago, but seemingly wasn't used
anywhere until Jan added it to gas/symbols.c in commit 6a2b6326c21e.

The function is used to modify ELF symbol st_shndx for symbols defined
in odd sections like .symtab, so that they get the corresponding
section st_shndx in an output file.  This patch fixes some bitrot in
the function.  After commit c03551323c04 which introduced
output_elf_obj_tdata, elf_strtab_sec and elf_shstrtab_sec will
segfault if used on an input bfd.

PR 14493
* elf.c (_bfd_elf_copy_private_symbol_data): Don't use
elf_strtab_sec and elf_shstrtab_sec.

15 months agogdb: don't include gdbsupport/array-view.h in defs.h
Simon Marchi [Mon, 22 Apr 2024 20:10:17 +0000 (16:10 -0400)] 
gdb: don't include gdbsupport/array-view.h in defs.h

Nothing in defs.h actually uses this.  Everything that I (and the
buildbot) can compile still compiles, so I guess that all users of
array_view already include it one way or another.  Worst case, if this
causes some build failure, the fix will be one #include away.

Change-Id: I981be98b0653cc18c929d85e9afd8732332efd15
Approved-By: John Baldwin <jhb@FreeBSD.org>
15 months agogdb: don't include hashtab.h in defs.h
Simon Marchi [Mon, 22 Apr 2024 20:10:16 +0000 (16:10 -0400)] 
gdb: don't include hashtab.h in defs.h

Nothing in defs.h actually uses this.

Add some includes for some spots using things from hashtab.h.  Note that
if the GDB build doesn't use libxxhash, hashtab.h is included by
gdbsupport/common-utils.h, so all files still see hashtab.h.  It puzzled
me for some time why I didn't see build failures in my build (which
didn't use libxxhash) but the buildbot gave build failures (it uses
libxxhash).

Change-Id: I8efd68decdaf579f048941c7537cd689885caa2a
Approved-By: John Baldwin <jhb@FreeBSD.org>
15 months agogdb: move RequireLongest to gdbsupport/traits.h
Simon Marchi [Mon, 22 Apr 2024 20:10:15 +0000 (16:10 -0400)] 
gdb: move RequireLongest to gdbsupport/traits.h

Move it out of defs.h.

Change-Id: Ie1743d41a57f81667650048563e66073c72230cf
Approved-By: John Baldwin <jhb@FreeBSD.org>
15 months agogdb: move store/extract integer functions to extract-store-integer.{c,h}
Simon Marchi [Mon, 22 Apr 2024 20:10:14 +0000 (16:10 -0400)] 
gdb: move store/extract integer functions to extract-store-integer.{c,h}

Move the declarations out of defs.h, and the implementations out of
findvar.c.

I opted for a new file, because this functionality of converting
integers to bytes and vice-versa seems a bit to generic to live in
findvar.c.

Change-Id: I524858fca33901ee2150c582bac16042148d2251
Approved-By: John Baldwin <jhb@FreeBSD.org>
15 months agogdb: remove extract_long_unsigned_integer
Simon Marchi [Mon, 22 Apr 2024 20:10:13 +0000 (16:10 -0400)] 
gdb: remove extract_long_unsigned_integer

It is unused.

Change-Id: I5d4091368c4dfc29752b12061e38f1df8353ba74
Approved-By: John Baldwin <jhb@FreeBSD.org>
15 months agogdb: move `enum compile_i_scope_types` to compile/compile.h
Simon Marchi [Mon, 22 Apr 2024 20:10:12 +0000 (16:10 -0400)] 
gdb: move `enum compile_i_scope_types` to compile/compile.h

Move it out of defs.h, adjust the includes here and there.

Change-Id: I11901fdce55d54f5e51723e123cef154cfb1bbc5
Approved-By: John Baldwin <jhb@FreeBSD.org>
15 months agogdb: move two declarations out of defs.h
Simon Marchi [Mon, 22 Apr 2024 20:10:11 +0000 (16:10 -0400)] 
gdb: move two declarations out of defs.h

Move declarations of initialize_progspace and initialize_inferiors to
progspace.h and inferior.h, respectively.

Change-Id: I62292ffda429861b9f27d8c836a56d161dfa548d
Approved-By: John Baldwin <jhb@FreeBSD.org>
15 months agoAutomatic date update in version.in
GDB Administrator [Tue, 23 Apr 2024 00:00:13 +0000 (00:00 +0000)] 
Automatic date update in version.in

15 months agogdb/testsuite: Use default gdb_expect timeout in runto
Thiago Jung Bauermann [Thu, 4 Apr 2024 17:22:22 +0000 (14:22 -0300)] 
gdb/testsuite: Use default gdb_expect timeout in runto

runto uses a hard-coded timeout of 30s in its invocation of gdb_expect.
This is normally fine, but for very a slow system (e.g., an emulator) it
may not be enough time for GDB to reach the intended breakpoint.

gdb_expect can obtain a timeout value from user-configurable variables
when it's not given one explicitly, so use that mechanism instead since
the user will have already adjusted the timeout variable to account for
the slow system.

Approved-By: Tom Tromey <tom@tromey.com>
15 months agogdb: fix unknown variable typo in c-exp.y
Andrew Burgess [Mon, 22 Apr 2024 09:25:51 +0000 (10:25 +0100)] 
gdb: fix unknown variable typo in c-exp.y

Fix 'val' -> 'value' typo in c-exp.y which was breaking the build.
Introduced in commit:

  commit e6375bc8ebbbc177c79f08e9616eb0b131229f65
  Date:   Wed Apr 17 16:17:33 2024 -0600

      Remove some alloca uses

15 months agoaarch64: Fix coding style issue in `aarch64-dis.c'
Victor Do Nascimento [Fri, 19 Apr 2024 13:01:43 +0000 (14:01 +0100)] 
aarch64: Fix coding style issue in `aarch64-dis.c'

Fix integer value being returned from boolean function, as introduced
in `aarch64: Remove asserts from operand qualifier decoders [PR31595]'.

15 months agoUse std::vector in event-loop.cc
Tom Tromey [Sat, 6 Apr 2024 18:37:37 +0000 (12:37 -0600)] 
Use std::vector in event-loop.cc

In my occasional and continuing campaign against realloc, this patch
changes event-loop.cc to use std::vector to keep track of pollfd
objects.  Regression tested on x86-64 Fedora 38.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
Approved-By: John Baldwin <jhb@FreeBSD.org>
15 months agox86/APX: Add invalid check for APX EVEX.X4.
Cui, Lili [Mon, 22 Apr 2024 01:25:56 +0000 (09:25 +0800)] 
x86/APX: Add invalid check for APX EVEX.X4.

gas/ChangeLog:

        * config/tc-i386.c (build_apx_evex_prefix): Added invalid check for APX
        X4.
        * testsuite/gas/i386/x86-64-apx-evex-promoted-bad.d: Added invalid
        testcase.
        * testsuite/gas/i386/x86-64-apx-evex-promoted-bad.s: Ditto.

opcodes/ChangeLog:

        * i386-dis.c (get_valid_dis386): Added invalid check for APX X4.

15 months agoAutomatic date update in version.in
GDB Administrator [Mon, 22 Apr 2024 00:00:10 +0000 (00:00 +0000)] 
Automatic date update in version.in

15 months agoRemove a couple of VLAs
Tom Tromey [Tue, 16 Apr 2024 19:12:28 +0000 (13:12 -0600)] 
Remove a couple of VLAs

I found a couple of spots where VLAs are in use but where they can
easily be removed.

In one spot, adding 'const' is enough -- and is already done in
similar code elsewhere in the file.

In another spot, one of two arrays will be used, so making the buffer
large enough for both works.

Approved-By: John Baldwin <jhb@FreeBSD.org>
15 months agoRemove some alloca uses
Tom Tromey [Wed, 17 Apr 2024 22:17:33 +0000 (16:17 -0600)] 
Remove some alloca uses

A few spots (mostly in the parsers) use alloca to ensure that a string
is terminated before passing it to a printf-like function (mostly
'error').  However, this isn't needed as the "%.*s" format can be used
instead.

This patch makes this change.

In one spot the alloca is dead code and is simply removed.

Regression tested on x86-64 Fedora 38.

Approved-By: John Baldwin <jhb@FreeBSD.org>
15 months agoAutomatic date update in version.in
GDB Administrator [Sun, 21 Apr 2024 00:00:08 +0000 (00:00 +0000)] 
Automatic date update in version.in

15 months agoLoongArch: Add -mignore-start-align option
mengqinggang [Sun, 7 Apr 2024 08:34:42 +0000 (16:34 +0800)] 
LoongArch: Add -mignore-start-align option

Ignore .align at the start of a section may result in misalignment when
partial linking. Manually add -mignore-start-align option without partial
linking.

Gcc -falign-functions add .align 5 to the start of a section, it causes some
error message mismatch. Set these testcases to xfail on LoongArch target.

15 months agoError compiling libctf-regression test
Alan Modra [Sat, 20 Apr 2024 00:33:09 +0000 (10:03 +0930)] 
Error compiling libctf-regression test

Seen on 64-bit targets.
ERROR: compilation of lookup program .../libctf-regression/gzrewrite.c failed

* testsuite/libctf-regression/gzrewrite.c (main): Use %zu to
print size_t values.
* testsuite/libctf-regression/zrewrite.c (main): Likewise.

15 months agoAutomatic date update in version.in
GDB Administrator [Sat, 20 Apr 2024 00:00:13 +0000 (00:00 +0000)] 
Automatic date update in version.in

15 months agogdb: add target_debug_printf and target_debug_printf_nofunc
Simon Marchi [Fri, 19 Apr 2024 19:46:54 +0000 (15:46 -0400)] 
gdb: add target_debug_printf and target_debug_printf_nofunc

Add the `target_debug_printf` and `target_debug_printf_nofunc` macros
and use them when outputting debug messages depending on `targetdebug`.
I opted for `target_debug_printf_nofunc` to follow the current style
where the function name is already printed, along with the arguments.

Modify the debug printfs in the `debug_target` methods (generated by
`make-target-delegates.py`) to use `target_debug_printf_nofunc` as well.

This makes the "target" debug prints integrate nicely with the other
debug prints that use the "new" debug print system:

    [infrun] proceed: enter
      [infrun] follow_fork: enter
        [target] -> multi-thread->record_will_replay (...)
        [target] <- multi-thread->record_will_replay (-1, 0) = false
        [target] -> multi-thread->supports_multi_process (...)
        [target] <- multi-thread->supports_multi_process () = true
      [infrun] follow_fork: exit
      ...

Change-Id: Ide3c8c1b8a30e6d4c353a29cba911c7192de29ac
Approved-By: Tom Tromey <tom@tromey.com>
15 months agogdb: make regcache::debug_print_register return a string
Simon Marchi [Fri, 19 Apr 2024 19:46:53 +0000 (15:46 -0400)] 
gdb: make regcache::debug_print_register return a string

Rename the method to `register_debug_string`.

This makes it easier to introduce `target_debug_printf` in a subsequent
patch.

Change-Id: I5bb2d49476d17940d503e66f40762e3f1e3baabc
Approved-By: Tom Tromey <tom@tromey.com>
15 months agogdb: make debug_target use one-liners
Simon Marchi [Fri, 19 Apr 2024 19:46:52 +0000 (15:46 -0400)] 
gdb: make debug_target use one-liners

Turn the debug prints in debug_target's method to be one liners.  For
instance, change this:

    gdb_printf (gdb_stdlog, "<- %s->wait (", this->beneath ()->shortname ());
    gdb_puts (target_debug_print_ptid_t (arg0), gdb_stdlog);
    gdb_puts (", ", gdb_stdlog);
    gdb_puts (target_debug_print_target_waitstatus_p (arg1), gdb_stdlog);
    gdb_puts (", ", gdb_stdlog);
    gdb_puts (target_debug_print_target_wait_flags (arg2), gdb_stdlog);
    gdb_puts (") = ", gdb_stdlog);
    target_debug_print_ptid_t (result);
    gdb_puts ("\n", gdb_stdlog);

into this:

    gdb_printf (gdb_stdlog,
               "<- %s->wait (%s, %s, %s) = %s\n",
               this->beneath ()->shortname (),
               target_debug_print_ptid_t (arg0).c_str (),
               target_debug_print_target_waitstatus_p (arg1).c_str (),
               target_debug_print_target_wait_flags (arg2).c_str (),
               target_debug_print_ptid_t (result).c_str ());

This makes it possible for a subsequent patch to turn this gdb_printf
call into a `target_debug_printf` call.

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