]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
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>
15 months agogdb: make target debug functions return std::string
Simon Marchi [Fri, 19 Apr 2024 19:46:51 +0000 (15:46 -0400)] 
gdb: make target debug functions return std::string

Change the functions in target-debug.h to return string representations
in an std::string, such that they don't need to know how the printing
part is done.  This also helps the following patch that makes the debug
prints in debug_target one-liners.

Update target-delegates.c (through make-target-delegates.py) to do the
printing.

Add an overload of gdb_puts to avoid using `.c_str ()`.

Change-Id: I55cbff1c1b03a3b24a81740e34c6ad41ac4f8453
Approved-By: Tom Tromey <tom@tromey.com>
15 months agogdb: fix include for gdb_signal in target/waitstatus.h
Simon Marchi [Fri, 19 Apr 2024 20:04:32 +0000 (16:04 -0400)] 
gdb: fix include for gdb_signal in target/waitstatus.h

clangd tells me that the gdb_signals.h include in target/waitstatus.h is
unused.  This include was probably to give access to `enum gdb_signal`,
but this is in fact defined in gdb/signals.h.  Change the include to
gdb/signals.h.  Include gdbsupport/gdb_signals.h in some files that were
relying on the transitive include.

Change-Id: I6f4361b3d801394bf29abe8c1393aff110aa0ad6

15 months agogdb: convert target debug macros to functions
Simon Marchi [Wed, 17 Apr 2024 20:54:07 +0000 (16:54 -0400)] 
gdb: convert target debug macros to functions

Convert all the macros to static functions.  Some macros were unused,
and now that they are functions, got flagged by the compiler, so I
omitted them.

No behavior change expected.

Change-Id: Ia88e61d95e29a0378901c71aa50df7c37d16bebe
Approved-By: Tom Tromey <tom@tromey.com>
15 months agogdb: add includes in target-debug.h
Simon Marchi [Fri, 12 Apr 2024 18:44:38 +0000 (18:44 +0000)] 
gdb: add includes in target-debug.h

Editing target-debug.h with clangd shows a bunch of errors.  Add some
includes to fix that (make target-debug.h include what it uses).

Change-Id: I49075a171e6875fa516d6b2ce56b4a03ac7b3376

15 months agolibctf: do not include undefined functions in libctf.ver
Nick Alcock [Wed, 17 Apr 2024 18:06:17 +0000 (19:06 +0100)] 
libctf: do not include undefined functions in libctf.ver

libctf's version script is applied to two libraries: libctf.so,
and libctf-nobfd.so.  The latter library is a subset of the former
which does not link to libbfd and does not include a few public
entry points that use it (found in libctf-open-bfd.c).  This means
that some of the symbols in this version script only exist in one
of the libraries it's applied to.

A number of linkers dislike this: before now, only Solaris's linker
caused serious problems, introducing NOTYPE-typed symbols when such
things were found, but now LLD has started to complain as well:

ld: error: version script assignment of 'LIBCTF_1.0' to symbol 'ctf_arc_open' failed: symbol not defined
ld: error: version script assignment of 'LIBCTF_1.0' to symbol 'ctf_fdopen' failed: symbol not defined
ld: error: version script assignment of 'LIBCTF_1.0' to symbol 'ctf_open' failed: symbol not defined
ld: error: version script assignment of 'LIBCTF_1.0' to symbol 'ctf_bfdopen' failed: symbol not defined
ld: error: version script assignment of 'LIBCTF_1.0' to symbol 'ctf_bfdopen_ctfsect' failed: symbol not defined

Rather than adding more and more whack-a-mole fixes for every
linker we encounter that does this, simply exclude such symbols
unconditionally, using the same trick we used to use for Solaris.
(Well, unconditionally if we can use version scripts with this
linker at all, which is not always the case.)

Thanks to Nicholas Vinson for the original report and a fix very
similar to this one (but not quite identical).

libctf/

* configure.ac: Always exclude libctf symbols from
libctf-nobfd's version script.
* configure: Regenerated.

15 months agolibctf: Remove undefined functions from ver. map
Nicholas Vinson [Wed, 17 Apr 2024 17:52:45 +0000 (18:52 +0100)] 
libctf: Remove undefined functions from ver. map

Starting with ld.lld-17, ld.lld is invoked with the option
--no-undefined-version enabled by default. Furthermore, The functions
ctf_label_set() and ctf_label_get() are not defined. Their inclusion in
libctf/libctf.ver causes ld.lld-17 to fail emitting the following error
messages:

ld.lld: error: version script assignment of 'LIBCTF_1.0' to symbol 'ctf_label_set' failed: symbol not defined
ld.lld: error: version script assignment of 'LIBCTF_1.0' to symbol 'ctf_label_get' failed: symbol not defined

This patch fixes the issue by removing the symbol names from
libctf/libctf.ver.

[nca: fused in later commit that marked ctf_arc_open as libctf
      only as well.  Added ChangeLog entry.]

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
libctf/
* libctf.ver: drop nonexistent label functions: mark
ctf_arc_open as libctf-only.

15 months agolibctf: don't pass errno into ctf_err_warn so often
Nick Alcock [Fri, 12 Apr 2024 13:46:00 +0000 (14:46 +0100)] 
libctf: don't pass errno into ctf_err_warn so often

The libctf-internal warning function ctf_err_warn() can be passed a libctf
errno as a parameter, and will add its textual errmsg form to the passed-in
error message. But if there is an error on the fp already, and this is
specifically an error and not a warning, ctf_err_warn() will print the error
out regardless: there's no need to pass in anything but 0.

There are still a lot of places where we do

ctf_err_warn (fp, 0, EFOO, ...);
return ctf_set_errno (fp, 0, EFOO);

I've left all of those alone, because fixing it makes the code a bit longer:
but fixing the cases where no return is involved and the error has just been
set on the fp itself costs nothing and reduces redundancy a bit.

libctf/

* ctf-dedup.c (ctf_dedup_walk_output_mapping): Drop the errno arg.
(ctf_dedup_emit): Likewise.
(ctf_dedup_type_mapping): Likewise.
* ctf-link.c (ctf_create_per_cu): Likewise.
(ctf_link_deduplicating_close_inputs): Likewise.
(ctf_link_deduplicating_one_symtypetab): Likewise.
(ctf_link_deduplicating_per_cu): Likewise.
* ctf-lookup.c (ctf_lookup_symbol_idx): Likewise.
* ctf-subr.c (ctf_assert_fail_internal): Likewise.

15 months agolibctf: fix leak in test
Nick Alcock [Wed, 3 Apr 2024 13:18:25 +0000 (14:18 +0100)] 
libctf: fix leak in test

This purely serves to make it easier to interpret valgrind output.
No functional effect.

libctf/
* testsuite/libctf-lookup/conflicting-type-syms.c: Free everything.

15 months agolibctf: add rewriting tests
Nick Alcock [Tue, 2 Apr 2024 15:13:46 +0000 (16:13 +0100)] 
libctf: add rewriting tests

Now there's a chance of it actually working, we can add more tests for
the long-broken dict read-and-rewrite cases.  This is the first ever
test for the (rarely-used, unpleasant, and until recently completely
broken) ctf_gzwrite function.

libctf/

* testsuite/libctf-regression/gzrewrite*: New test.
* testsuite/libctf-regression/zrewrite*: Likewise.

15 months agolibctf: fix a debugging typo
Nick Alcock [Tue, 2 Apr 2024 15:09:11 +0000 (16:09 +0100)] 
libctf: fix a debugging typo

libctf/

* ctf-lookup.c (ctf_symidx_sort): Fix a debugging typo.

15 months agolibctf: make ctf_lookup of symbols by name work in more cases
Nick Alcock [Tue, 2 Apr 2024 15:06:50 +0000 (16:06 +0100)] 
libctf: make ctf_lookup of symbols by name work in more cases

In particular, we don't need a symbol table if we're looking up a
symbol by name and that type of symbol has an indexed symtypetab,
since in that case we get the name from the symtypetab index, not
from the symbol table.

This lets you do symbol lookups in unlinked object files and unlinked
dicts written out via libctf's writeout functions.

libctf/

* ctf-lookup.c (ctf_lookup_by_sym_or_name): Allow lookups
by index even when there is no symtab.

15 months agolibctf: improve handling of type dumping errors
Nick Alcock [Tue, 2 Apr 2024 12:48:13 +0000 (13:48 +0100)] 
libctf: improve handling of type dumping errors

When dumping a type fails with an error, we want to emit a warning noting
this: a warning because it's not fatal and we can continue.  But warnings
don't automatically print out the ctf_errno (because not all cases causing
warnings set the errno at all), so we must do it at warning-emission time or
lose track of what's gone wrong.

libctf/

* ctf-dump.c (ctf_dump_format_type): Dump the underlying error on
type dump failure.