]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
9 months agosim: msp430: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:08:07 +0000 (20:08 -0700)] 
sim: msp430: fix -Wunused-but-set-variable warnings

9 months agosim: mips: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:07:56 +0000 (20:07 -0700)] 
sim: mips: fix -Wunused-but-set-variable warnings

9 months agosim: mcore: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:07:50 +0000 (20:07 -0700)] 
sim: mcore: fix -Wunused-but-set-variable warnings

9 months agosim: m68hc11: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:07:44 +0000 (20:07 -0700)] 
sim: m68hc11: fix -Wunused-but-set-variable warnings

9 months agosim: h8300: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:07:34 +0000 (20:07 -0700)] 
sim: h8300: fix -Wunused-but-set-variable warnings

9 months agosim: ft32: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:07:32 +0000 (20:07 -0700)] 
sim: ft32: fix -Wunused-but-set-variable warnings

9 months agosim: frv: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:07:22 +0000 (20:07 -0700)] 
sim: frv: fix -Wunused-but-set-variable warnings

9 months agosim: erc32: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:07:11 +0000 (20:07 -0700)] 
sim: erc32: fix -Wunused-but-set-variable warnings

9 months agosim: d10v: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:07:06 +0000 (20:07 -0700)] 
sim: d10v: fix -Wunused-but-set-variable warnings

9 months agosim: cris: fix -Wunused-but-set-variable warnings
Mike Frysinger [Thu, 7 Dec 2023 03:06:07 +0000 (20:06 -0700)] 
sim: cris: fix -Wunused-but-set-variable warnings

We suppress the warning in the generated switch file because the cris
cpu file has a hack to workaround a cgen bug, but that generates a set
but unused variable which makes the compiler upset.

9 months agosim: bfin: fix -Wunused-but-set-variable warnings
Mike Frysinger [Wed, 6 Dec 2023 13:38:29 +0000 (06:38 -0700)] 
sim: bfin: fix -Wunused-but-set-variable warnings

9 months agosim: bfin: gui: fix -Wunused-but-set-variable warnings
Mike Frysinger [Wed, 6 Dec 2023 13:36:15 +0000 (06:36 -0700)] 
sim: bfin: gui: fix -Wunused-but-set-variable warnings

Rework the code to use static inline functions when it's disabled
rather than macros so the compiler knows the various function args
are always used.  The ifdef macros are a bit ugly, but get the job
done without duplicating the function prototypes.

9 months agosim: arm: fix -Wunused-but-set-variable warnings
Mike Frysinger [Wed, 6 Dec 2023 13:34:44 +0000 (06:34 -0700)] 
sim: arm: fix -Wunused-but-set-variable warnings

9 months agosim: m32r: fix syslog call
Mike Frysinger [Fri, 8 Dec 2023 04:40:00 +0000 (21:40 -0700)] 
sim: m32r: fix syslog call

The function returns void, not int.  We only pass one argument to
syslog (the format), so use %s as the static format instead since
the emulation layer doesn't handle passing additional arguments.

9 months agosim: m32r: include more glibc headers for the funcs we use [PR sim/29752]
Mike Frysinger [Fri, 8 Dec 2023 04:38:56 +0000 (21:38 -0700)] 
sim: m32r: include more glibc headers for the funcs we use [PR sim/29752]

Not exactly portable, but doesn't make the situation worse here, and
fixes a lot of implicit function warnings.

Bug: https://sourceware.org/PR29752

9 months agosim: m32r: add more cgen prototypes for traps
Mike Frysinger [Fri, 8 Dec 2023 04:38:11 +0000 (21:38 -0700)] 
sim: m32r: add more cgen prototypes for traps

The traps file uses a bunch of functions directly without prototypes,
and we can't safely include the relevant cpu*.h files for them.

9 months agoAutomatic date update in version.in
GDB Administrator [Fri, 8 Dec 2023 00:00:18 +0000 (00:00 +0000)] 
Automatic date update in version.in

9 months agosim: m32r: add more cgen prototypes to enable -Werror in most files
Mike Frysinger [Thu, 7 Dec 2023 13:22:32 +0000 (06:22 -0700)] 
sim: m32r: add more cgen prototypes to enable -Werror in most files

9 months agosim: warnings: disable -Wenum-conversion fow now [PR sim/29752]
Mike Frysinger [Thu, 7 Dec 2023 04:16:17 +0000 (21:16 -0700)] 
sim: warnings: disable -Wenum-conversion fow now [PR sim/29752]

The cgen code mixes virtual insn enums with insn enums, and there isn't
an obvious (to me) way to unravel this atm, so disable the warning.

sim/lm32/decode.c:45:5: error:
implicit conversion from enumeration type 'CGEN_INSN_VIRTUAL_TYPE'
to different enumeration type 'CGEN_INSN_TYPE' (aka 'enum cgen_insn_type')
[-Werror,-Wenum-conversion]
   45 |   { VIRTUAL_INSN_X_INVALID, LM32BF_INSN_X_INVALID, LM32BF_SFMT_EMPTY },
      |   ~ ^~~~~~~~~~~~~~~~~~~~~~

Bug: https://sourceware.org/PR29752

9 months agogdb/record: Support for rdtscp in i386_process_record.
Cupertino Miranda [Tue, 5 Dec 2023 23:09:57 +0000 (23:09 +0000)] 
gdb/record: Support for rdtscp in i386_process_record.

This patch adds support for process recording of the instruction rdtscp in
x86 architecture.
Debugging applications with "record full" fail to record with the error
message "Process record does not support instruction 0xf01f9".

Approved-by: Guinevere Larsen <blarsen@redhat.com>
9 months agosim: support dlopen in -lc
Mike Frysinger [Thu, 7 Dec 2023 03:28:40 +0000 (20:28 -0700)] 
sim: support dlopen in -lc

Stop assuming that dlopen is only available via -ldl.  Newer versions
of glibc have merged it into -lc which broke this configure test.

9 months agosim: cris: move generated file to right place
Mike Frysinger [Thu, 7 Dec 2023 02:52:48 +0000 (19:52 -0700)] 
sim: cris: move generated file to right place

Not sure why this ended up in the topdir, but it belongs under cris/.

9 months agosim: warnings: add more flags
Mike Frysinger [Wed, 6 Dec 2023 06:13:50 +0000 (23:13 -0700)] 
sim: warnings: add more flags

Sync with the list of flags from gdbsupport, and add a few more of
our own to catch recent issues.  Comment out the C++-specific flags
as we don't build with C++.

9 months agoAdd more 'step' tests to gdb.base/watchpoint.exp
Kevin Buettner [Thu, 7 Dec 2023 03:08:53 +0000 (20:08 -0700)] 
Add more 'step' tests to gdb.base/watchpoint.exp

The test gdb.base/watchpoint.exp has a proc named 'test_stepping'
which claims to "Test stepping and other mundane operations with
watchpoints enabled".  It sets a watchpoint on ival2, performs an
inferior function call (which is not at all mundane), and uses 'next',
'until', and, finally, does a 'step'.

However, that final 'step' command steps to (but not over/through) the
line at which the assignment to ival2 takes place.  At no time while
performing these operations is a watchpoint hit.

This commit adds a test to see what happens when stepping over/through
the assignment to ival2.  The watchpoint on ival2 should be triggered
during this step.  I've added another 'step' to make sure that the
correct statement is reached after performing the watchpoint-hitting
step.

After running the 'test_stepping' proc, gdb.base/watchpoint.exp does
a clean_restart before doing further tests, so nothing depends upon
'test_stepping' to stop at the particular statement at which it had
been stopping.

I've examined all tests which set watchpoints and step.  I haven't
been able to identify a(nother) test case which tests what happens
when stepping over/through a statement which triggers a watchpoint.
Therefore, adding these new 'step' tests is testing something which
hasn't being tested elsewhere.

Reviewed-By: John Baldwin <jhb@FreeBSD.org>
9 months agoRISC-V: Fix "withand" in LEB128 error messages
Palmer Dabbelt [Wed, 6 Dec 2023 17:52:31 +0000 (09:52 -0800)] 
RISC-V: Fix "withand" in LEB128 error messages

This was split over multiple lines and ended up missing a space.

Reported-by: David Abdurachmanov <davidlt@rivosinc.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
9 months agoAutomatic date update in version.in
GDB Administrator [Thu, 7 Dec 2023 00:00:20 +0000 (00:00 +0000)] 
Automatic date update in version.in

9 months agoFix DLL export forwarding
Hannes Domani [Wed, 6 Dec 2023 19:52:06 +0000 (20:52 +0100)] 
Fix DLL export forwarding

I noticed it when I was trying to set a breakpoint at ExitProcess:
```
(gdb) b ExitProcess
Breakpoint 1 at 0x14001fdd0
(gdb) r
Starting program: C:\qiewer\heob\heob64.exe
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x3dbf4120
Cannot insert breakpoint 1.
Cannot access memory at address 0x77644120
```

The problem doesn't exist in gdb 13.2, and the difference can easily be
seen when printing ExitProcess.
gdb 14.1:
```
(gdb) p ExitProcess
$1 = {<text variable, no debug info>} 0x77644120 <UserHandleGrantAccess+36128>
```
gdb 13.2:
```
(gdb) p ExitProcess
$1 = {<text variable, no debug info>} 0x77734120 <ntdll!RtlExitUserProcess>
```

The new behavior started with 9675da25357c7a3f472731ddc6eb3becc65b469a,
where VMA was then calculated relative to FORWARD_DLL_NAME, while it was
relative to DLL_NAME before.

Fixed by calculating VMA relative to DLL_NAME again.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31112
Approved-By: Tom Tromey <tom@tromey.com>
9 months agoFix minor grammar error in gdb.texinfo
Tom Tromey [Wed, 6 Dec 2023 19:32:57 +0000 (12:32 -0700)] 
Fix minor grammar error in gdb.texinfo

This fixes a small grammar issue in gdb.texinfo -- "additional" was
written where "additionally" is correct.

9 months agoRemove quick_symbol_functions::expand_matching_symbols
Tom Tromey [Fri, 10 Nov 2023 21:21:41 +0000 (14:21 -0700)] 
Remove quick_symbol_functions::expand_matching_symbols

The only caller of quick_symbol_functions::expand_matching_symbols was
removed, so now this method and all implementations of it can be
removed.

9 months agoRemove split_style::UNDERSCORE
Tom Tromey [Fri, 10 Nov 2023 21:13:23 +0000 (14:13 -0700)] 
Remove split_style::UNDERSCORE

The recent changes to the way Ada names are matched means that
split_style::UNDERSCORE is no longer used.  This patch removes it.

9 months agoAlways use expand_symtabs_matching in ada-lang.c
Tom Tromey [Fri, 10 Nov 2023 18:58:47 +0000 (11:58 -0700)] 
Always use expand_symtabs_matching in ada-lang.c

The previous patch fixed the immediate performance problem with Ada
name matching, by having a subset of matches call
expand_symtabs_matching rather than expand_matching_symbols.  However,
it seemed to me that expand_matching_symbols should not be needed at
all.

To achieve this, this patch changes ada_lookup_name_info::split_name
to use the decoded name, rather than the encoded name.  In order to
make this work correctly, a new decoded form is used: one that does
not decode operators (this is already done) and also does not decode
wide characters.  The latter change is done so that changes to the Ada
source charset don't affect the DWARF index.

With this in place, we can change ada-lang.c to always use
expand_symtabs_matching rather than expand_matching_symbols.

9 months agoImprove performance of Ada name searches
Tom Tromey [Fri, 10 Nov 2023 16:16:17 +0000 (09:16 -0700)] 
Improve performance of Ada name searches

A user reported that certain operations -- like printing a large
structure -- could be slow.  I tracked this down to
ada-lang.c:map_matching_symbols taking an inordinate amount of time.
Specifically, calls like the one to look for a parallel "__XVZ"
variable, in ada_to_fixed_type_1, could result in gdb walking over all
the entries in the cooked index over and over.

Looking into this reveals that
cooked_index_functions::expand_matching_symbols is not written
efficiently -- it ignores its "ordered_compare" parameter.  While
fixing this would be good, it turns out that this entire method isn't
needed; so this series removes it.

However, the deletion is not done in this patch.  This one, instead,
fixes the immediate cause of the slowdown, by using
objfile::expand_symtabs_matching when possible.  This approach is
faster because it is more selective about which index entries to
examine.

9 months agoStart abbrevs at 1 in DWARF assembler
Tom Tromey [Wed, 6 Dec 2023 16:26:33 +0000 (17:26 +0100)] 
Start abbrevs at 1 in DWARF assembler

I noticed that the DWARF assembler starts abbrevs at 2.
I think 1 should be preferred.

Co-Authored-By: Tom de Vries <tdevries@suse.de>
9 months agoFix hardware watchpoints in replay mode
Hannes Domani [Wed, 6 Dec 2023 12:45:51 +0000 (13:45 +0100)] 
Fix hardware watchpoints in replay mode

Changes introduced by commit 9e8915c6cee5c37637521b424d723e990e06d597
caused a regression that meant hardware watchpoint stops would not
trigger in reverse execution or replay mode.  This was documented in
PR breakpoints/21969.
The problem is that record_check_stopped_by_breakpoint always overwrites
record_full_stop_reason, thus loosing the TARGET_STOPPED_BY_WATCHPOINT
value which would be checked afterwards.

This commit fixes that by not overwriting the stop-reason in
record_full_stop_reason if we're not stopped at a breakpoint.

And the test for hw watchpoints in gdb.reverse/watch-reverse.exp actually
tested sw watchpoints again, since "set can-use-hw-watchpoints 1"
doesn't convert enabled watchpoints to use hardware.
This is fixed by disabling said watchpoint while enabling hw watchpoints.
The same is not done for gdb.reverse/watch-precsave.exp, since it's not
possible to use hw watchpoints in restored recordings anyways.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=21969
Approved-by: Guinevere Larsen <blarsen@redhat.com>
9 months agogdb: fix libstdc++ assert caused by invalid use of std::clamp
Andrew Burgess [Wed, 6 Dec 2023 11:16:49 +0000 (11:16 +0000)] 
gdb: fix libstdc++ assert caused by invalid use of std::clamp

After this commit:

  commit 33ae45434d0ab1f7de365b9140ad4e4ffc34b8a2
  Date:   Mon Dec 4 14:23:17 2023 +0000

      gdb: Enable early init of thread pool size

I am now seeing this assert from libstdc++:

  /usr/include/c++/9/bits/stl_algo.h:3715: constexpr const _Tp& std::clamp(const _Tp&, const _Tp&, const _Tp&) [with _Tp = int]: Assertion '!(__hi < __lo)' failed.

This may only be visible because I compile with:

  -D_GLIBCXX_DEBUG=1 -D_GLIBCXX_DEBUG_PEDANTIC=1

but I haven't checked.  The issue the assert is highlighting is real,
and is caused by this block of code:

  if (n_threads < 0)
    {
      const int hardware_threads = std::thread::hardware_concurrency ();
      /* Testing in #29959 indicates that parallel efficiency drops between
         n_threads=5 to 8.  Therefore, clamp the default value to 8 to avoid an
         excessive number of threads in the pool on many-core systems.  */
      const int throttle = 8;
      n_threads = std::clamp (hardware_threads, hardware_threads, throttle);
    }

The arguments to std::clamp are VALUE, LOW, HIGH, but in the above, if
we have more than 8 hardware threads available the LOW will be greater
than the HIGH, which is triggering the assert I see above.

I believe std::clamp is the wrong tool to use here.  Instead std::min
would be a better choice; we want the smaller value of
HARDWARE_THREADS or THROTTLE.  If h/w threads is 2, then we want 2,
but if h/w threads is 16 we want 8, this is what std::min gives us.

After this commit, I no longer see the assert.

9 months ago[gdb/symtab] Redo "Fix assert in set_length"
Tom de Vries via Gdb-patches [Wed, 6 Dec 2023 09:29:17 +0000 (10:29 +0100)] 
[gdb/symtab] Redo "Fix assert in set_length"

This reverts commit 1c04f72368c ("[gdb/symtab] Fix assert in set_length"), due
to a regression reported in PR29572, and implements a different fix for PR29453.

The fix is to not use the CU table in a .debug_names section to construct
all_units, but instead use create_all_units, and then verify the CU
table from .debug_names.  This also fixes PR25969, so remove the KFAIL.

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

9 months agosim: warnings: sync some build logic from gdbsupport
Mike Frysinger [Wed, 6 Dec 2023 01:49:27 +0000 (18:49 -0700)] 
sim: warnings: sync some build logic from gdbsupport

This fixes testing of -Wno flags, and adds some more portable ones.

9 months agoPR31096, nm shows 32bit addresses as 64bit addresses
Alan Modra [Mon, 4 Dec 2023 22:53:41 +0000 (09:23 +1030)] 
PR31096, nm shows 32bit addresses as 64bit addresses

Prior to commit 0e3c1eebb2 nm output depended on the host unsigned
long when printing "negative" symbol values for 32-bit targets.
Commit 0e3c1eebb22 made the output match that seen with a 64-bit host
unsigned long.  The fact that nm output changed depending on host is
of course a bug, but it is reasonable to expect 32-bit target output
is only 32 bits.  So this patch makes 32-bit target output the same as
it was on 32-bit hosts prior to 0e3c1eebb2.

PR 31096
* nm.c (print_format_string): Make it a static buffer.
(get_print_format): Merge into..
(set_print_format): ..this, renamed from set_print_width.  When
print_width is 32, set up print_format_string for an int32_t
value.  Don't malloc print_format_string.  Adjust calls.
(print_value): Correct printing of 32-bit values.

9 months agoAutomatic date update in version.in
GDB Administrator [Wed, 6 Dec 2023 00:00:14 +0000 (00:00 +0000)] 
Automatic date update in version.in

9 months agolibiberty: Fix build with GCC < 7
Jakub Jelinek [Tue, 5 Dec 2023 22:34:01 +0000 (23:34 +0100)] 
libiberty: Fix build with GCC < 7

Tobias reported on IRC that the linker fails to build with GCC 4.8.5.
In configure I've tried to use everything actually used in the sha1.c
x86 hw implementation, but unfortunately I forgot about implicit function
declarations.  GCC before 7 did have <cpuid.h> header and bit_SHA define
and __get_cpuid function defined inline, but it didn't define
__get_cpuid_count, which compiled fine (and the configure test is
intentionally compile time only) due to implicit function declaration,
but then failed to link when linking the linker, because
__get_cpuid_count wasn't defined anywhere.

The following patch fixes that by using what autoconf uses in AC_CHECK_DECL
to make sure the functions are declared.

2023-12-05  Jakub Jelinek  <jakub@redhat.com>

* configure.ac (HAVE_X86_SHA1_HW_SUPPORT): Verify __get_cpuid and
__get_cpuid_count are not implicitly declared.
* configure: Regenerated.

9 months agoFix breakpoints on symbols with multiple trampoline symbols
Hannes Domani [Tue, 5 Dec 2023 17:41:44 +0000 (18:41 +0100)] 
Fix breakpoints on symbols with multiple trampoline symbols

On mingw targets it's possible that there are multiple trampoline
symbols for __cxa_throw, in each module where a throw is done, but
without a corresponding global symbol.
Since commit 77f2120b200be6cabbf6f610942fc1173a8df6d3 they cancel each
other out in search_minsyms_for_name, which makes it impossible to set
a breakpoint there:

(gdb) b __cxa_throw
Function "__cxa_throw" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 2 (__cxa_throw) pending.
(gdb) c
Continuing.
[Inferior 1 (process 10004) exited with code 03]

With catch throw it also doesn't work, and you don't even get an error
message:

(gdb) catch throw
Catchpoint 2 (throw)
(gdb) c
Continuing.
[Inferior 1 (process 5532) exited with code 03]
(gdb)

The fix is to simply ignore other trampoline symbols when looking for
corresponding global symbols, and it's working as expected:

(gdb) b __cxa_throw
Breakpoint 2 at 0x13f091590 (2 locations)
(gdb) c
Continuing.

Breakpoint 2.1, 0x000000013f091590 in __cxa_throw ()
(gdb)

And catch throw also works again:

(gdb) catch throw
Catchpoint 2 (throw)
(gdb) c
Continuing.

Catchpoint 2.1 (exception thrown), 0x000000013f181590 in __cxa_throw ()
(gdb)

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29548
Approved-By: Tom Tromey <tom@tromey.com>
9 months agogdb/testsuite: Update worker thread show assertion
Richard Bunt [Tue, 5 Dec 2023 09:54:12 +0000 (09:54 +0000)] 
gdb/testsuite: Update worker thread show assertion

Commit 33ae45434d0 updated the text reported by GDB when showing the
number of worker threads. However, it neglected to update the assertions
using this text, which caused index-file.exp to fail. This commit
corrects this omission.

Tested index-file.exp is fixed on my local machine.

Approved-By: Tom Tromey <tom@tromey.com>
9 months agoRemove some DAP helper functions
Tom Tromey [Tue, 28 Nov 2023 16:18:13 +0000 (09:18 -0700)] 
Remove some DAP helper functions

Now that DAP requests are normally run on the gdb thread, some DAP
helper functions are no longer needed.  Removing these simplifies the
code.

9 months agoFix: strip --strip-debug breaks relocations
Nick Clifton [Tue, 5 Dec 2023 15:18:40 +0000 (15:18 +0000)] 
Fix: strip --strip-debug breaks relocations

  PR 31106
  * elfcode.h (elf_write_relocs): Do not convert a relocation against a zero-value absolute symbol into a relocation without a symbol if the symbol is being used for a complex relocation.

9 months agoFix off-by-one error in compute_delayed_physnames
Tom Tromey [Wed, 22 Nov 2023 23:36:02 +0000 (16:36 -0700)] 
Fix off-by-one error in compute_delayed_physnames

compute_delayed_physnames does this:

  size_t len = strlen (physname);
...
      if (physname[len] == ')') /* shortcut */
break;

However, physname[len] will always be \0.

This patch changes it to the correct len-1.

9 months agosim: mips: fix sim_fpu usage
Mike Frysinger [Tue, 5 Dec 2023 13:09:49 +0000 (06:09 -0700)] 
sim: mips: fix sim_fpu usage

Fix some of the sim_fpu calls to use the right types.  While I'm
not familiar with the MIPS ISA in these cases, these look like
simple oversights due to the name/type mismatches.  This at least
fixes compiling with -Wenum-conversion.

9 months agosim: sh: trim trailing whitespace in generated code
Mike Frysinger [Tue, 5 Dec 2023 13:05:19 +0000 (06:05 -0700)] 
sim: sh: trim trailing whitespace in generated code

No functional change here, but makes it a little easier to read the
generated code when editors aren't highlighting all the spurious
trailing whitespace on lines.

9 months agosim: mn10300: fix sim_engine_halt call
Mike Frysinger [Tue, 5 Dec 2023 12:56:52 +0000 (07:56 -0500)] 
sim: mn10300: fix sim_engine_halt call

The sim_stop argument is an enum and should only be one of those
values, not a signal constant.  Fix the logic to pass the right
sim_xxx & SIM_xxx values in the right arguments.

9 months agosim: m32c: use UTF-8 encoding
Mike Frysinger [Tue, 5 Dec 2023 12:48:21 +0000 (07:48 -0500)] 
sim: m32c: use UTF-8 encoding

We only support UTF-8 nowadays, so stop using ISO-8859-1.

Maybe we should delete this logic entirely, but for now,
do the bare min conversion to keep it compiling.

9 months agoAdd basic support for RISC-V 64-bit EFI objects
Andreas Schwab [Thu, 3 Aug 2023 15:22:42 +0000 (17:22 +0200)] 
Add basic support for RISC-V 64-bit EFI objects

This adds a new PEI target pei-riscv64-little.  Only objdump and objcopy
are supported.

bfd:
* .gitignore: Add pe-riscv64igen.c.
* Makefile.am (BFD64_BACKENDS): Add pei-riscv64.lo,
pe-riscv64igen.lo.
(BFD64_BACKENDS_CFILES): Add pei-riscv64.c.
(BUILD_CFILES): Add pe-riscv64igen.c.
(pe-riscv64igen.c): New rule.
* Makefile.in: Regenerate.
* bfd.c (bfd_get_sign_extend_vma): Add pei-riscv64-little.
* coff-riscv64.c: New file.
* coffcode.h (coff_set_arch_mach_hook, coff_set_flags)
(coff_write_object_contents): Add riscv64 (riscv64_pei_vec)
support.
* config.bfd (targ_selvecs): Add riscv64_pei_vec to all riscv*
targets.
* configure.ac: Handle riscv64_pei_vec.
* configure: Regenerate.
* libpei.h (GET_OPTHDR_IMAGE_BASE, PUT_OPTHDR_IMAGE_BASE)
(GET_OPTHDR_SIZE_OF_STACK_RESERVE)
(PUT_OPTHDR_SIZE_OF_STACK_RESERVE)
(GET_OPTHDR_SIZE_OF_STACK_COMMIT, PUT_OPTHDR_SIZE_OF_STACK_COMMIT)
(GET_OPTHDR_SIZE_OF_HEAP_RESERVE, PUT_OPTHDR_SIZE_OF_HEAP_RESERVE)
(GET_OPTHDR_SIZE_OF_HEAP_COMMIT, PUT_OPTHDR_SIZE_OF_HEAP_COMMIT)
(GET_PDATA_ENTRY, _bfd_XX_bfd_copy_private_bfd_data_common)
(_bfd_XX_bfd_copy_private_section_data)
(_bfd_XX_get_symbol_info, _bfd_XX_only_swap_filehdr_out)
(_bfd_XX_print_private_bfd_data_common)
(_bfd_XXi_final_link_postscript, _bfd_XXi_only_swap_filehdr_out)
(_bfd_XXi_swap_aouthdr_in, _bfd_XXi_swap_aouthdr_out)
(_bfd_XXi_swap_aux_in, _bfd_XXi_swap_aux_out)
(_bfd_XXi_swap_lineno_in, _bfd_XXi_swap_lineno_out)
(_bfd_XXi_swap_scnhdr_out, _bfd_XXi_swap_sym_in)
(_bfd_XXi_swap_sym_out, _bfd_XXi_swap_debugdir_in)
(_bfd_XXi_swap_debugdir_out, _bfd_XXi_write_codeview_record)
(_bfd_XXi_slurp_codeview_record) [COFF_WITH_peRiscV64]: Define.
(_bfd_peRiscV64_print_ce_compressed_pdata): Declare.
* peXXigen.c (_bfd_XXi_swap_aouthdr_in, _bfd_XXi_swap_aouthdr_out)
(_bfd_XXi_swap_scnhdr_out, pe_print_pdata)
(_bfd_XX_print_private_bfd_data_common)
(_bfd_XX_bfd_copy_private_section_data)
(_bfd_XXi_final_link_postscript): Support COFF_WITH_peRiscV64.
* pei-riscv64.c: New file.
* peicode.h (coff_swap_scnhdr_in, pe_ILF_build_a_bfd)
(pe_ILF_object_p): Support COFF_WITH_peRiscV64.
(jtab): Add dummy entry that traps.
* targets.c (_bfd_target_vector): Add riscv64_pei_vec.

binutils:
* testsuite/binutils-all/riscv/pei-riscv64.d: New.
* testsuite/binutils-all/riscv/pei-riscv64.s: New.

include:
* coff/riscv64.h: New file.
* coff/pe.h (IMAGE_FILE_MACHINE_RISCV32)
(IMAGE_FILE_MACHINE_RISCV64): Define.

9 months agoalpha_ecoff_get_relocated_section_contents buffer overflow
Alan Modra [Tue, 5 Dec 2023 06:02:34 +0000 (16:32 +1030)] 
alpha_ecoff_get_relocated_section_contents buffer overflow

This is aimed at fixing holes in two alpha-ecoff relocation functions
that access section contents without first bounds checking offsets.
I've also rewritten ALPHA_R_OP_STORE handling to support writing to
the bytes near the end of the section.

* coff-alpha.c (alpha_ecoff_get_relocated_section_contents): Don't
bother checking ALPHA_R_LITERAL insn.  Range check before reading
contents for ALPHA_R_GPDISP, and simplify handling.  Rewrite
ALPHA_R_OP_STORE handling.  Correct error callback args.
(alpha_relocate_section): Similarly.  Don't abort, report errors.

9 months agomemory leak in display_debug_addr
Alan Modra [Tue, 5 Dec 2023 06:01:38 +0000 (16:31 +1030)] 
memory leak in display_debug_addr

* dwarf.c (display_debug_addr): Free dummy debug_addr_info entry.
Don't return without freeing debug_addr_info on error paths.

9 months agoDon't use free_contents in _bfd_elf_slurp_version_tables
Alan Modra [Tue, 5 Dec 2023 06:01:13 +0000 (16:31 +1030)] 
Don't use free_contents in _bfd_elf_slurp_version_tables

In commit 7ac6d0c38c36 I made more use of free_contents in
_bfd_elf_slurp_version_tables, a variable added to tag the case where
raw verneed and verdefs have been read locally by the function, and
thus should be freed before returning.  In retrospect it may have been
better to do without the extra variable entirely.  It's easy to infer
when "contents" should be freed, costing a little extra on an error
path but costing less elsewhere.

* elf.c (_bfd_elf_slurp_version_tables): Don't use free_contents.

9 months agoHandle "efi-app-riscv64" and similar targets in objcopy.
Peter Jones [Wed, 6 Sep 2023 20:01:34 +0000 (16:01 -0400)] 
Handle "efi-app-riscv64" and similar targets in objcopy.

This adds the efi target name handling for riscv64 to objcopy.

binutils:
* binutils/objcopy.c: add riscv64 handling to
  convert_efi_target()

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
9 months agosim: rx: mark unused static var as unused
Mike Frysinger [Tue, 5 Dec 2023 04:49:48 +0000 (23:49 -0500)] 
sim: rx: mark unused static var as unused

This seems like a useful utility func that mirrors the int2float
helper, so mark it as unused rather than delete.

9 months agosim: rx: constify some read-only global vars
Mike Frysinger [Tue, 5 Dec 2023 04:48:48 +0000 (23:48 -0500)] 
sim: rx: constify some read-only global vars

9 months agosim: warnings: enable only for development builds
Mike Frysinger [Tue, 5 Dec 2023 04:43:51 +0000 (23:43 -0500)] 
sim: warnings: enable only for development builds

Reuse the bfd/development.sh script like most other project to
determine whether the current source tree is a dev build (e.g.
git) or a release build, and disable the warnings for releases.

9 months agosim: ppc: fix implicit enum conversion
Mike Frysinger [Tue, 5 Dec 2023 04:40:05 +0000 (23:40 -0500)] 
sim: ppc: fix implicit enum conversion

This code tries to use attach_type enums as hw_phb_decode, and while
they're setup to have compatible values, the compiler doesn't like it
when the cast is missing.  So cast it explicitly and then use that.

sim/ppc/hw_phb.c:322:28: error:
implicit conversion from enumeration type 'attach_type'
(aka 'enum _attach_type') to different enumeration type
'hw_phb_decode' [-Werror,-Wenum-conversion]

9 months agosim: ppc: fix -Wmisleading-indentation warnings
Mike Frysinger [Tue, 5 Dec 2023 04:38:55 +0000 (23:38 -0500)] 
sim: ppc: fix -Wmisleading-indentation warnings

Fix building with -Wmisleading-indentation.

9 months agosim: ppc: cleanup getrusage decls
Mike Frysinger [Tue, 5 Dec 2023 04:32:51 +0000 (23:32 -0500)] 
sim: ppc: cleanup getrusage decls

Don't conflate HAVE_GETRUSAGE & HAVE_SYS_RESOURCE_H.  Use the latter
to include the header and nothing else.  Use the former to determine
whether to use the function and nothing else.  If we find a system
that doesn't follow POSIX and provides only one of these, we can
figure out how to support it then.  The manual local definition is
clashing with the system ones and leading to build failures with
newer C standards.

sim/ppc/emul_netbsd.c:51:5: error: a function declaration without a
prototype is deprecated in all versions of C and is treated as a
zero-parameter prototype in C2x, conflicting with a previous
declaration [-Werror,-Wdeprecated-non-prototype]

9 months agoaarch64-elf: FAIL: indirect call stub to BTI stub relaxation
Alan Modra [Sun, 3 Dec 2023 22:18:34 +0000 (08:48 +1030)] 
aarch64-elf: FAIL: indirect call stub to BTI stub relaxation

aarch64-elf fails the ld-aarch64/bfd-far-3.d test, due to the stubs
being emitted in a different order to that of aarch64-linux.  They are
emitted in a different order due to stub names for local symbols
having the section id in the stub name.  aarch64-linux-ld generates
one more section than aarch64-elf-ld.  That section is .gnu.hash.  So
the stub names differ and are hashed to different slots in
stub_hash_table.

Fix this by running the test with --hash-style=sysv, and adjust
expected output.  I've also changed the branch over stubs emitted at
the start of a group of stubs to not care about the symbol, for all
groups not just the one that needed changing.

* ld-aarch64/bti-far-3.d: Add --hash-style=sysv.  Adjust
expected output.

9 months agoAutomatic date update in version.in
GDB Administrator [Tue, 5 Dec 2023 00:00:33 +0000 (00:00 +0000)] 
Automatic date update in version.in

9 months agogdb/testsuite: fix directory name in test name
Andrew Burgess [Mon, 4 Dec 2023 18:55:24 +0000 (18:55 +0000)] 
gdb/testsuite: fix directory name in test name

In the commit:

  commit 4793f551a5aa68522fd5fbbb7e8f621148f410cd
  Date:   Mon Nov 27 13:33:17 2023 +0000

      gdb: allow use of ~ in 'save gdb-index' command

I added a test which has a directory name within the GDB command,
which then appears in the test name as I failed to give the test a
better name.

Fixed in this commit.

9 months ago[gdb/doc] Escape the '@' symbols in generated texinfo files.
Ciaran Woodward [Mon, 4 Dec 2023 18:49:26 +0000 (18:49 +0000)] 
[gdb/doc] Escape the '@' symbols in generated texinfo files.

'@' is a special symbol meaning 'command' in GNU texinfo.

If the GDBINIT or GDBINIT_DIR path during configuration
included an '@' character, the makeinfo command would fail,
as it interpreted the '@' in the path as a start of a command
when expanding the path in the docs.

This patch simply escapes any '@' characters in the path,
by replacing them with '@@'. This was already done for the
bugurl variable.

This was detected because the 'Jenkins' tool sometimes puts
an '@' in the workspace path.

Approved-By: Tom Tromey <tom@tromey.com>
9 months agoFix two buglets in .debug_names dumping
Tom Tromey [Mon, 4 Dec 2023 14:48:42 +0000 (07:48 -0700)] 
Fix two buglets in .debug_names dumping

While working on gdb's .debug_names writer, I found a couple of small
bugs in binutils .debug_names dumping.

First, the DWARF spec (section 6.1.1.4.6 Name Table) says:

    These two arrays are indexed starting at 1, [...]

I think it is clearer for binutils to follow this, particularly
because DW_IDX_parent refers to this number.

Second, I think the handling of an empty hash table is slightly wrong.
Currently the dumping code assumes there is always an array of hashes.
However, section 6.1.1.4.5 Hash Lookup Table says:

    The optional hash lookup table immediately follows the list of
    type signatures.

and then:

    The hash lookup table is actually two separate arrays: an array of
    buckets, followed immediately by an array of hashes.

My reading of this is that the hash table as a whole is optional, and
so the hashes will not exist in this case.  (This also makes sense
because the hashes are not useful without the buckets anyway.)

This patch fixes both of these problems.  FWIW I have some gdb patches
in progress that change gdb both to omit the hash table and to use
DW_IDX_parent.

2023-12-04  Tom Tromey  <tom@tromey.com>

* dwarf.c (display_debug_names): Handle empty .debug_names hash
table.  Name entries start at 1.

9 months agogdb: add Ciaran Woodward to gdb/MAINTAINERS
Ciaran Woodward [Mon, 4 Dec 2023 18:15:08 +0000 (18:15 +0000)] 
gdb: add Ciaran Woodward to gdb/MAINTAINERS

9 months agos390: Support for jump visualization in disassembly
Jens Remus [Wed, 29 Nov 2023 20:44:34 +0000 (21:44 +0100)] 
s390: Support for jump visualization in disassembly

Add support for jump visualization for the s390 architecture in
disassembly:

objdump -d --visualize-jumps ...

Annotate the (conditional) jump and branch relative instructions with
information required for jump visualization:
- jump: Unconditional jump / branch relative.
- condjump: Conditional jump / branch relative.
- jumpsr: Jump / branch relative to subroutine.

Unconditional jump and branch relative instructions are annotated as
jump.
Conditional jump and branch relative instructions, jump / branch
relative on count/index, and compare and jump / branch relative
instructions are annotated as condjump.
Jump and save (jas, jasl) and branch relative and save (bras, brasl)
instructions are annotated as jumpsr (jump to subroutine).

Provide instruction information required for jump visualization during
disassembly.
The instruction type is provided after determining the opcode.
For non-code it is set to dis_noninsn. Otherwise it defaults to
dis_nonbranch. No annotation is done for data reference instructions
(i.e. instruction types dis_dref and dis_dref2). Note that the
instruction type needs to be provided before printing of the
instruction, as it is used in print_address_func() to translate the
argument value into an address if it is assumed to be a PC-relative
offset. Note that this is never the case on s390, as
print_address_func() is only called with addresses and never with
offsets.
The target of the (conditional) jump and branch relative instructions
is provided during print, when the PC relative operand is decoded.

include/
* opcode/s390.h: Define opcode flags to annotate instruction
  class information for jump visualization:
  S390_INSTR_FLAG_CLASS_BRANCH, S390_INSTR_FLAG_CLASS_RELATIVE,
  S390_INSTR_FLAG_CLASS_CONDITIONAL, and
  S390_INSTR_FLAG_CLASS_SUBROUTINE.
  Define opcode flags mask S390_INSTR_FLAG_CLASS_MASK for above
  instruction class information.
  Define helpers for common instruction class flag combinations:
  S390_INSTR_FLAGS_CLASS_JUMP, S390_INSTR_FLAGS_CLASS_CONDJUMP,
  and S390_INSTR_FLAGS_CLASS_JUMPSR.

opcodes/
* s390-mkopc.c: Add opcode flags to annotate information
  for jump visualization: jump, condjump, and jumpsr.
* s390-opc.txt: Annotate (conditional) jump and branch relative
  instructions with information for jump visualization.
* s390-dis.c (print_insn_s390, s390_print_insn_with_opcode):
  Provide instruction information for jump visualization.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
Reviewed-by: Andreas Krebbel <krebbel@linux.ibm.com>
9 months agoRemove incorrect "fall-through" comment
Tom Tromey [Mon, 4 Dec 2023 15:59:56 +0000 (08:59 -0700)] 
Remove incorrect "fall-through" comment

I found a "fall-through" comment in gdb/remote.c that was incorrect --
the code here cannot in fact fall through.

9 months agoUpdate fall-through comment in gdbserver
Tom Tromey [Mon, 4 Dec 2023 15:23:34 +0000 (08:23 -0700)] 
Update fall-through comment in gdbserver

I noticed that gdbserver/win32-low.cc has a fall-through comment that
should have been converted to use the annotation instead.

This patch makes the change.

9 months agogdb: Enable early init of thread pool size
Richard Bunt [Mon, 4 Dec 2023 14:23:17 +0000 (14:23 +0000)] 
gdb: Enable early init of thread pool size

This commit enables the early initialization commands (92e4e97a9f5) to
modify the number of threads used by gdb's thread pool.

The motivation here is to prevent gdb from spawning a detrimental number
of threads on many-core systems under environments with restrictive
ulimits.

With gdb before this commit, the thread pool takes the following sizes:

1. Thread pool size is initialized to 0.

2. After the maintenance commands are defined, the thread pool size is
set to the number of system cores (if it has not already been set).

3. Using early initialization commands, the thread pool size can be
changed using "maint set worker-threads".

4. After the first prompt, the thread pool size can be changed as in the
previous step.

Therefore after step 2. gdb has potentially launched hundreds of threads
on a many-core system.

After this change, step 2 and 3 are reversed so there is an opportunity
to set the required number of threads without needing to default to the
number of system cores first.

There does exist a configure option (added in 261b07488b9) to disable
multithreading, but this does not allow for an already deployed gdb to
be configured.

Additionally, the default number of worker threads is clamped at eight
to control the number of worker threads spawned on many-core systems.
This value was chosen as testing recorded on bugzilla issue 29959
indicates that parallel efficiency drops past this point.

GDB built with GCC 13.

No test suite regressions detected. Compilers: GCC, ACfL, Intel, Intel
LLVM, NVHPC; Platforms: x86_64, aarch64.

The scenario that interests me the most involves preventing GDB from
spawning any worker threads at all. This was tested by counting the
number of clones observed by strace:

    strace -e clone,clone3 gdb/gdb -q \
    --early-init-eval-command="maint set worker-threads 0" \
    -ex q ./gdb/gdb |& grep --count clone

The new test relies on "gdb: install CLI uiout while processing early
init files" developed by Andrew Burgess. This patch will need pushing
prior to this change.

The clamping was tested on machines with both 16 cores and a single
core.  "maint show worker-threads" correctly reported eight and one
respectively.

Approved-By: Tom Tromey <tom@tromey.com>
9 months agogdb: install CLI uiout while processing early init files
Andrew Burgess [Mon, 4 Dec 2023 14:23:17 +0000 (14:23 +0000)] 
gdb: install CLI uiout while processing early init files

The next commit wants to use a 'show' command within an early
initialisation file, despite these commands not being in the list of
acceptable commands for use within an early initialisation file.

The problem we run into is that the early initialisation files are
processed before GDB has installed the top level interpreter.  The
interpreter is responsible to installing the default uiout (accessed
through current_uiout), and as a result code that depends on
uiout (e.g. 'show' commands) will end up dereferencing a nullptr, and
crashing GDB.

I did consider moving the interpreter installation before the early
initialisation, and this would work fine except for the new DAP
interpreter, which relies on having Python available during its
initialisation.  Which means we can't install the interpreter until
after Python has been initialised, and the early initialisation
handling has to occur before Python is setup -- that's the whole point
of this feature (to allow customisation of how Python is setup).

So, what I propose is that early within captured_main_1, we install a
temporary cli_ui_out as the current_uiout.  This will remain in place
until the top-level interpreter is installed, at which point the
temporary will be replaced.

What this means is that current_uiout will no longer be nullptr,
instead, any commands within an early initialisation file that trigger
output, will perform that output in a CLI style.

I propose that we don't update the documentation for early
initialisation files, we leave the user advice as being only 'set' and
'source' commands are acceptable.  But now, if a user does try a
'show' command, then instead of crashing, GDB will do something
predictable.

I've not added a test in this commit.  The next commit relies on this
patch and will serve as a test.

Tested-By: Richard Bunt <richard.bunt@linaro.org>
9 months ago[gdb/tui] Fix wrapping strings
Tom de Vries [Mon, 4 Dec 2023 07:48:48 +0000 (08:48 +0100)] 
[gdb/tui] Fix wrapping strings

I noticed that after resizing to a narrow window, I got:
...
┌────────────────┐
│                │
│[ No Source Avail
able ]           │
│                │
└────────────────┘
...

Fix this by adding two new functions:
- tui_win_info::display_string (int y, int x, const char *str)
- tui_win_info::display_string (const char *str)
that make sure that borders are not overwritten, which get us instead:
...
┌────────────────┐
│                │
│[ No Source Avai│
│                │
│                │
└────────────────┘
...

Tested on x86_64-linux.

9 months agoAutomatic date update in version.in
GDB Administrator [Mon, 4 Dec 2023 00:00:11 +0000 (00:00 +0000)] 
Automatic date update in version.in

9 months agoFix detach bug when lwp has exited/terminated
Kevin Buettner [Sun, 3 Dec 2023 03:25:31 +0000 (20:25 -0700)] 
Fix detach bug when lwp has exited/terminated

When using GDB on native linux, it can happen that, while attempting
to detach an inferior, the inferior may have been exited or have been
killed, yet still be in the list of lwps.  Should that happen, the
assert in x86_linux_update_debug_registers in
gdb/nat/x86-linux-dregs.c will trigger.  The line in question looks
like this:

  gdb_assert (lwp_is_stopped (lwp));

For this case, the lwp isn't stopped - it's dead.

The bug which brought this problem to my attention is one in which the
pwntools library uses GDB to to debug a process; as the script is
shutting things down, it kills the process that GDB is debugging and
also sends GDB a SIGTERM signal, which causes GDB to detach all
inferiors prior to exiting.  Here's a link to the bug:

https://bugzilla.redhat.com/show_bug.cgi?id=2192169

The following shell command mimics part of what the pwntools
reproducer script does (with regard to shutting things down), but
reproduces the bug much less reliably.  I have found it necessary to
run the command a bunch of times before seeing the bug.  (I usually
see it within 5-10 repetitions.)  If you choose to try this command,
make sure that you have no running "cat" or "gdb" processes first!

  cat </dev/zero >/dev/null & \
  (sleep 5; (kill -KILL `pgrep cat` & kill -TERM `pgrep gdb`)) & \
  sleep 1 ; \
  gdb -q -iex 'set debuginfod enabled off' -ex 'set height 0' \
      -ex c /usr/bin/cat `pgrep cat`

So, basically, the idea here is to kill both gdb and cat at roughly
the same time.  If we happen to attempt the detach before the process
lwp has been deleted from GDB's (linux native) LWP data structures,
then the assert will trigger.  The relevant part of the backtrace
looks like this:

  #8  0x00000000008a83ae in x86_linux_update_debug_registers (lwp=0x1873280)
      at gdb/nat/x86-linux-dregs.c:146
  #9  0x00000000008a862f in x86_linux_prepare_to_resume (lwp=0x1873280)
      at gdb/nat/x86-linux.c:81
  #10 0x000000000048ea42 in x86_linux_nat_target::low_prepare_to_resume (
      this=0x121eee0 <the_amd64_linux_nat_target>, lwp=0x1873280)
      at gdb/x86-linux-nat.h:70
  #11 0x000000000081a452 in detach_one_lwp (lp=0x1873280, signo_p=0x7fff8ca3441c)
      at gdb/linux-nat.c:1374
  #12 0x000000000081a85f in linux_nat_target::detach (
      this=0x121eee0 <the_amd64_linux_nat_target>, inf=0x16e8f70, from_tty=0)
      at gdb/linux-nat.c:1450
  #13 0x000000000083a23b in thread_db_target::detach (
      this=0x1206ae0 <the_thread_db_target>, inf=0x16e8f70, from_tty=0)
      at gdb/linux-thread-db.c:1385
  #14 0x0000000000a66722 in target_detach (inf=0x16e8f70, from_tty=0)
      at gdb/target.c:2526
  #15 0x0000000000a8f0ad in kill_or_detach (inf=0x16e8f70, from_tty=0)
      at gdb/top.c:1659
  #16 0x0000000000a8f4fa in quit_force (exit_arg=0x0, from_tty=0)
      at gdb/top.c:1762
  #17 0x000000000070829c in async_sigterm_handler (arg=0x0)
      at gdb/event-top.c:1141

My colleague, Andrew Burgess, has done some recent work on other
problems with detach.  Upon hearing of this problem, he came up a test
case which reliably reproduces the problem and tests for a few other
problems as well.  In addition to testing detach when the inferior has
terminated due to a signal, it also tests detach when the inferior has
exited normally.  Andrew observed that the linux-native-only
"checkpoint" command would be affected too, so the test also tests
those cases when there's an active checkpoint.

For the LWP exit / termination case with no checkpoint, that's handled
via newly added checks of the waitstatus in detach_one_lwp in
linux-nat.c.

For the checkpoint detach problem, I chose to pass the lwp_info
to linux_fork_detach in linux-fork.c.  With that in place, suitable
tests were added before attempting a PTRACE_DETACH operation.

I added a few asserts at the beginning of linux_fork_detach and
modified the caller code so that the newly added asserts shouldn't
trigger.  (That's what the 'pid == inferior_ptid.pid' check is about
in gdb/linux-nat.c.)

Lastly, I'll note that the checkpoint code needs some work with regard
to background execution.  This patch doesn't attempt to fix that
problem, but it doesn't make it any worse.  It does slightly improve
the situation with detach because, due to the check noted above,
linux_fork_detach() won't be called for the wrong inferior when there
are multiple inferiors.  (There are at least two other problems with
the checkpoint code when there are multiple inferiors.  See:
https://sourceware.org/bugzilla/show_bug.cgi?id=31065)

This commit also adds a new test,
gdb.base/process-dies-while-detaching.exp.  Andrew Burgess is the
primary author of this test case.  Its design is similar to that of
gdb.threads/main-thread-exit-during-detach.exp, which was also written
by Andrew.

This test checks that GDB correctly handles several cases that can
occur when GDB attempts to detach an inferior process.  The process
can exit or be terminated (e.g.  via SIGKILL) prior to GDB's event
loop getting a chance to remove it from GDB's internal data
structures.  To complicate things even more, detach works differently
when a checkpoint (created via GDB's "checkpoint" command) exists for
the inferior.  This test checks all four possibilities: process exit
with no checkpoint, process termination with no checkpoint, process
exit with a checkpoint, and process termination with a checkpoint.

Co-Authored-By: Andrew Burgess <aburgess@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
9 months agoAutomatic date update in version.in
GDB Administrator [Sun, 3 Dec 2023 00:00:16 +0000 (00:00 +0000)] 
Automatic date update in version.in

9 months agobinutils: Fix documentation typo in the --set-sect-name option
Petr Tesarik [Sat, 2 Dec 2023 16:35:40 +0000 (17:35 +0100)] 
binutils: Fix documentation typo in the --set-sect-name option

Fix a --set-sect-name typo in the description of objcopy
--rename-section.

9 months agogdb: Update Petr Tesarik's email address in gdb/MAINTAINERS
Petr Tesarik [Sat, 2 Dec 2023 16:27:55 +0000 (17:27 +0100)] 
gdb: Update Petr Tesarik's email address in gdb/MAINTAINERS

9 months agoFix ld/x86: reduce testsuite dependency on system object files
H.J. Lu [Fri, 1 Dec 2023 17:13:08 +0000 (09:13 -0800)] 
Fix ld/x86: reduce testsuite dependency on system object files

commit eab996435fe65a421541f59557c5f1fd427573a3
Author: Jan Beulich <jbeulich@suse.com>
Date:   Tue Nov 7 13:58:32 2023 +0100

    ld/x86: reduce testsuite dependency on system object files

changed some C compiler tests to assembler/linker tests which introduced
2 problems:

1. It broke x32 binutils tests since --64 was passed to assembler, but
-m elf_x86_64 wasn't passed to linker.
2. -nostdlib was passed to C compiler driver to exclude standard run-time
files which should be avoided with -r option for linker tests.

Fix them by passing -m elf_x86_64 to linker and removing -nostdlib for
linker tests with -r.

PR ld/30722
* testsuite/ld-x86-64/x86-64.exp: Pass -m elf_x86_64 to linker
for tests with --64.  Remove -nostdlib for tests with -r.

9 months agoAutomatic date update in version.in
GDB Administrator [Sat, 2 Dec 2023 00:00:14 +0000 (00:00 +0000)] 
Automatic date update in version.in

9 months agoBail out of "attach" if a thread cannot be traced
Tom Tromey [Fri, 8 Sep 2023 14:25:15 +0000 (08:25 -0600)] 
Bail out of "attach" if a thread cannot be traced

On Linux, threads are treated much like separate processes by the
kernel.  In particular, it's possible to ptrace just a single thread.
If gdb tries to attach to a multi-threaded inferior, where a non-main
thread is already being traced (e.g., by strace), then gdb will get
into an infinite loop attempting to attach.

This patch fixes this problem by having the attach fail if ptrace
fails to attach to any thread of the inferior.

9 months agoUse gdb_dir_up in linux_proc_attach_tgid_threads
Tom Tromey [Thu, 7 Sep 2023 15:04:37 +0000 (09:04 -0600)] 
Use gdb_dir_up in linux_proc_attach_tgid_threads

This changes linux_proc_attach_tgid_threads to use gdb_dir_up.  This
makes it robust against exceptions.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
9 months agoMinor cleanup in linux_proc_attach_tgid_threads
Tom Tromey [Thu, 7 Sep 2023 15:03:43 +0000 (09:03 -0600)] 
Minor cleanup in linux_proc_attach_tgid_threads

linux_proc_attach_tgid_threads computes a file name, and then
re-computes it for a warning.  It is better to reuse the
already-computed name here.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
9 months agogdb: add missing regcache_map_entry array null terminators in aarch64-linux-tdep.c
Simon Marchi [Wed, 29 Nov 2023 16:35:23 +0000 (11:35 -0500)] 
gdb: add missing regcache_map_entry array null terminators in aarch64-linux-tdep.c

Fix two spots in aarch64-linux-tdep.c that build regcache_map_entry
arrays without a null terminator.  The null terminators are needed for
regcache::transfer_regset and regcache_map_entry_size to work properly.

Change-Id: I3224a314e1360b319438f32de8c81e70ab42e105
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
Approved-By: Luis Machado <luis.machado@arm.com>
9 months agogdb: return when exceeding buffer size in regcache::transfer_regset
Simon Marchi [Tue, 28 Nov 2023 19:48:57 +0000 (14:48 -0500)] 
gdb: return when exceeding buffer size in regcache::transfer_regset

regcache::transfer_regset iterates over an array of regcache_map_entry,
transferring the registers (between regcache and buffer) described by
those entries.  It stops either when it reaches the end of the
regcache_map_entry array (marked by a null entry) or (it seems like the
intent is) when it reaches the end of the buffer (in which case not all
described registers are transferred).

I said "seems like the intent is", because there appears to be a small
bug.  transfer_regset is made of two loops:

    foreach regcache_map_entry:
      foreach register described by the regcache_map_entry:
        if the register doesn't fit in the remainder of the buffer:
  break

        transfer register

When stopping because we have reached the end of the buffer, the break
only breaks out of the inner loop.

This problem causes some failures when I run tests such as
gdb.arch/aarch64-sme-core-3.exp (on AArch64 Linux, in qemu).  This is
partly due to aarch64_linux_iterate_over_regset_sections failing to add
a null terminator in its regcache_map_entry array, but I think there is
still a problem in transfer_regset.

The sequence to the crash is:

 - The `regcache_map_entry za_regmap` object built in
   aarch64_linux_iterate_over_regset_sections does not have a null
   terminator.
 - When the target does not have a ZA register,
   aarch64_linux_collect_za_regset calls `regcache->collect_regset` with
   a size of 0 (it's actually pointless, but still it should work).
 - transfer_regset gets called with a buffer size of 0.
 - transfer_regset detects that the register to transfer wouldn't fit in
   0 bytes, so it breaks out of the inner loop.
 - The outer loop tries to go read the next regcache_map_entry, but
   there isn't one, and we start reading garbage.

Obviously, this would get fixed by making
aarch64_linux_iterate_over_regset_sections use a null terminator (which
is what the following patch does).  But I think that when detecting that
there is not enough buffer left for the current register,
transfer_regset should return, not only break out of the inner loop.

This is a kind of contrived scenario, but imagine we have these two
regcache_map_entry objects:

  - 2 registers of 8 bytes
  - 2 registers of 4 bytes

For some reason, the caller passes a buffer of 12 bytes.
transfer_regset will detect that the second 8 byte register does not
fit, and break out of the inner loop.  However, it will then go try the
next regcache_map_entry.  It will see that it can fit one 4 byte
register in the remaining buffer space, and transfer it from/to there.
This is very likely not an expected behavior, we wouldn't expect to
read/write this sequence of registers from/to the buffer.

In this example, whether passing a 12 bytes buffer makes sense or
whether it is a size computation bug in the caller, we don't know, but I
think that exiting as soon as a register doesn't fit is the sane thing
to do.

Change-Id: Ia349627d2e5d281822ade92a8e7a4dea4f839e07
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
Reviewed-By: Luis Machado <luis.machado@arm.com>
9 months agoAdd link to Debugger Adapter Protocol node in documentation
Tom Tromey [Thu, 30 Nov 2023 19:27:04 +0000 (12:27 -0700)] 
Add link to Debugger Adapter Protocol node in documentation

I noticed that the interpreters node in the docs links to the DAP
protocol docs, but I thought the DAP node ought to as well.  This
patch adds a bit of introductory text there.

Approved-By: Eli Zaretskii <eliz@gnu.org>
9 months agoFix right shifts in mcore simulator on 64 bit hosts.
Jeff Law [Fri, 1 Dec 2023 14:19:50 +0000 (07:19 -0700)] 
Fix right shifts in mcore simulator on 64 bit hosts.

If the value to be shifted has the sign bit set, the sign
bit would get copied into bits 32..63 of the temporary.  Those
would then be right shifted into the final value giving an
incorrect final result.

This was observed with upcoming GCC improvements which eliminate
unnecessary extensions.

9 months agogdb/testsuite: fix completion tests when using READ1
Guinevere Larsen [Wed, 26 Jul 2023 08:08:10 +0000 (10:08 +0200)] 
gdb/testsuite: fix completion tests when using READ1

The commit a3da2e7e550c4fe79128b5e532dbb90df4d4f418 has introduced
regressions when testing using the READ1 mechanism. The reason for that
is the new failure path in proc test_gdb_complete_tab_unique, which
looks for GDB suggesting more than what the test inputted, but not the
correct answer, followed by a white space. Consider the following case:

int foo(int bar, int baz);

Sending the command "break foo<tab>" to GDB will return

break foo(int, int)

which easily fits the buffer in normal testing, so everything works, but
when reading one character at a time, the test will find the partial
"break foo(int, " and assume that there was a mistake, so we get a
spurious FAIL.

That change was added because we wanted to avoid forcing a completion
failure to fail through timeout, which it had to do because there is no
way to verify that the output is done, mostly because when I was trying
to solve a different problem I kept getting reading errors and testing
completion was frustrating.

This commit implements a better way to avoid that frustration, by first
testing gdb's complete command and only if that passes we will test tab
completion. The difference is that when testing with the complete
command, we can tell when the output is over when we receive the GDB
prompt again, so we don't need to rely on timeouts. With this, the
change to test_gdb_complete_tab_unique has been removed as that test
will only be run and fail in the very unlikely scenario that tab
completion is different than command completion.

Approved-By: Andrew Burgess <aburgess@redhat.com>
9 months agoRemove unnecessary returns and unused variables in AIX.
Aditya Vidyadhar Kamath [Fri, 1 Dec 2023 07:43:04 +0000 (01:43 -0600)] 
Remove unnecessary returns and unused variables in AIX.

This is a patch to simplify the pd_activate () in aix-thread.c incase of a failure to start a thread session
, since pd_activate () now has return type void.

Also this patch fixes the shadow declarartion warning in sync-threadlists.

9 months agoFix: nm -U short flag erroneously consumes argument
Nick Clifton [Fri, 1 Dec 2023 09:52:11 +0000 (09:52 +0000)] 
Fix: nm -U short flag erroneously consumes argument

  PR 31105
  * nm.c (main): Remove spurious colon after U in the call to getopt_long

9 months agold: fix build with old makeinfo
Jan Beulich [Fri, 1 Dec 2023 09:13:36 +0000 (10:13 +0100)] 
ld: fix build with old makeinfo

Makeinfo 4.12 is unhappy about the new "Special Sections" without that
also having a @chapter line.

9 months agobinutils/Dwarf: avoid "shadowing" of glibc function name
Jan Beulich [Fri, 1 Dec 2023 09:13:17 +0000 (10:13 +0100)] 
binutils/Dwarf: avoid "shadowing" of glibc function name

Yet once again: Old enough glibc has an (unguarded) declaration of
index() in string.h, which triggers a "shadows a global declaration"
warning with at least some gcc versions.

9 months agogas: drop unused fields from struct segment_info_struct
Jan Beulich [Fri, 1 Dec 2023 07:29:33 +0000 (08:29 +0100)] 
gas: drop unused fields from struct segment_info_struct

user_stuff, dot, and lineno_list_{head,tail} have no users (left), while
bfd_section was only ever written.

9 months agox86: adjust NOP generation after potential non-insn
Jan Beulich [Fri, 1 Dec 2023 07:29:11 +0000 (08:29 +0100)] 
x86: adjust NOP generation after potential non-insn

Just like avoiding to do certain transformations potentially affected by
stand-alone prefixes or direct data emission, also avoid emitting
optimized NOPs right afterwards; insert a plain old NOP first in such
cases.

9 months agox86: i386_cons_align() badly affects diagnostics
Jan Beulich [Fri, 1 Dec 2023 07:28:45 +0000 (08:28 +0100)] 
x86: i386_cons_align() badly affects diagnostics

Warning without knowing what's going to follow isn't useful, the more
that appropriate warnings are emitted elsewhere in all cases. Not
updating state (file/line in particular) also isn't helpful, as it's
always the last directive ahead of a construct potentially needing
fiddling with that's "guilty" in that fiddling being suppressed.

9 months agogas: no md_cons_align() for .nop{,s}
Jan Beulich [Fri, 1 Dec 2023 07:28:20 +0000 (08:28 +0100)] 
gas: no md_cons_align() for .nop{,s}

.nop and .nops generate code, not data. Hence them invoking
md_cons_align() is at best inappropriate. In fact it actually gets in
the of x86'es state maintenance involving i386_cons_align().

9 months agox86: suppress optimization after potential non-insn
Jan Beulich [Fri, 1 Dec 2023 07:27:49 +0000 (08:27 +0100)] 
x86: suppress optimization after potential non-insn

Just like avoiding to do other transformations potentially affected by
stand-alone prefixes or direct data emission, also avoid optimization
on the following insn.

9 months agox86: last-insn recording should be per-section
Jan Beulich [Fri, 1 Dec 2023 07:27:22 +0000 (08:27 +0100)] 
x86: last-insn recording should be per-section

Otherwise intermediate section switches result in inconsistent behavior.
Note, however, that intermediate sub-section switches will continue to
result in inconsistent or even inappropriate behavior.

While there also add recording of state to s_insn().

9 months agox86: allow 32-bit reg to be used with U{RD,WR}MSR
Jan Beulich [Fri, 1 Dec 2023 07:26:36 +0000 (08:26 +0100)] 
x86: allow 32-bit reg to be used with U{RD,WR}MSR

... as MSR index specifier: It is unreasonable to demand that people
write less readable / understandable code, just because the present
documentation mentions only Reg64. Whether to also adjust the
disassembler is a separate question, perhaps indeed more tightly tied
to what the spec says.

9 months agogdb: fix warnings about invalid [[fallthrough]] usage
Simon Marchi [Thu, 30 Nov 2023 20:59:16 +0000 (15:59 -0500)] 
gdb: fix warnings about invalid [[fallthrough]] usage

Fix these two warnings, when building on macos:

      CXX    cp-name-parser.o
    /Users/smarchi/src/binutils-gdb/gdb/cp-name-parser.y:1644:7: error: fallthrough annotation does not directly precede switch label
          [[fallthrough]];
          ^

      CXX    dbxread.o
    /Users/smarchi/src/binutils-gdb/gdb/dbxread.c:2809:7: error: fallthrough annotation does not directly precede switch label
          [[fallthrough]];
          ^

In these two cases, we [[fallthrough]], followed by a regular label,
followed by a case label.  Move the [[fallthrough]] below the regular
label.

Change-Id: If4a3145139e050bdb6950c7f239badd5778e6f64
Approved-By: Tom Tromey <tom@tromey.com>
9 months agoRISC-V: Make riscv_is_mapping_symbol stricter
Patrick O'Neill [Fri, 1 Dec 2023 02:47:39 +0000 (18:47 -0800)] 
RISC-V: Make riscv_is_mapping_symbol stricter

riscv_is_mapping_symbol currently accepts any symbol that starts with $x
or $d. This patch makes the check more strict, requiring exactly $x, $d,
or $xrv. It also makes use of this stricter mapping in
riscv_is_valid_mapping_symbol.

ChangeLog:

* bfd/cpu-riscv.c (riscv_elf_is_mapping_symbols): Match only
strings that are exactly $x, $d, or $xrv.
* opcodes/riscv-dis.c (riscv_is_valid_mapping_symbol): Use
riscv_elf_is_mapping_symbols.

Signed-off-by: Patrick O'Neill <patrick@rivosinc.com>