Commit Graph

115662 Commits

Author SHA1 Message Date
Tom Tromey
e76d241a64 C++-ify minidebug.c
I noticed minidebug.c was still using explicit malloc and free, where
a vector would be more automatic.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
2023-08-17 17:41:05 -06:00
Vladimir Mezentsev
1f572864da gprofng: Use execvp instead of execv
gp-display-gui (https://savannah.gnu.org/projects/gprofng-gui)
can be installed in a different directory.
In this case, $PATH is used to look up gp-display-text.
execv() does not use $PATH to find the executable.

gprofng/ChangeLog
2023-08-15  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

	* src/gp-display-text.cc (reexec): Use execvp instead of execv.
2023-08-17 13:15:10 -07:00
Andrew Burgess
b080fe54fb gdb: add inferior-specific breakpoints
This commit extends the breakpoint mechanism to allow for inferior
specific breakpoints (but not watchpoints in this commit).

As GDB gains better support for multiple connections, and so for
running multiple (possibly unrelated) inferiors, then it is not hard
to imagine that a user might wish to create breakpoints that apply to
any thread in a single inferior.  To achieve this currently, the user
would need to create a condition possibly making use of the $_inferior
convenience variable, which, though functional, isn't the most user
friendly.

This commit adds a new 'inferior' keyword that allows for the creation
of inferior specific breakpoints.

Inferior specific breakpoints are automatically deleted when the
associated inferior is removed from GDB, this is similar to how
thread-specific breakpoints are deleted when the associated thread is
deleted.

Watchpoints are already per-program-space, which in most cases mean
watchpoints are already inferior specific.  There is a small window
where inferior-specific watchpoints might make sense, which is after a
vfork, when two processes are sharing the same address space.
However, I'm leaving that as an exercise for another day.  For now,
attempting to use the inferior keyword with a watchpoint will give an
error, like this:

  (gdb) watch a8 inferior 1
  Cannot use 'inferior' keyword with watchpoints

A final note on the implementation: currently, inferior specific
breakpoints, like thread-specific breakpoints, are inserted into every
inferior, GDB then checks once the inferior stops if we are in the
correct thread or inferior, and resumes automatically if we stopped in
the wrong thread/inferior.

An obvious optimisation here is to only insert breakpoint locations
into the specific program space (which mostly means inferior) that
contains either the inferior or thread we are interested in.  This
would reduce the number times GDB has to stop and then resume again in
a multi-inferior setup.

I have a series on the mailing list[1] that implements this
optimisation for thread-specific breakpoints.  Once this series has
landed I'll update that series to also handle inferior specific
breakpoints in the same way.  For now, inferior specific breakpoints
are just slightly less optimal, but this is no different to
thread-specific breakpoints in a multi-inferior debug session, so I
don't see this as a huge problem.

[1] https://inbox.sourceware.org/gdb-patches/cover.1685479504.git.aburgess@redhat.com/
2023-08-17 16:42:39 +01:00
Tom de Vries
0c9546b152 [gdb/build] Fix yysymbol_kind_t odr violation
When building gdb with -O2 -flto on openSUSE Tumbleweed (using bison 3.8.2) I
run into:
...
ada-exp.c.tmp:653: warning: type 'yysymbol_kind_t' violates the C++ One \
  Definition Rule [-Wodr]
c-exp.c.tmp:398: note: an enum with different value name is defined in \
  another translation unit
ada-exp.c.tmp:660: note: name 'YYSYMBOL_NULL_PTR' differs from name \
  'YYSYMBOL_COMPLEX_INT' defined in another translation unit
c-exp.c.tmp:405: note: mismatching definition
...

Fix this by renaming to ada_exp_yysymbol_kind_t and likewise for other .y
files.

Tested on x86_64-linux.

PR build/22395
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
2023-08-17 17:09:39 +02:00
Alan Modra
05fbbeacaa generated bfd files, and kvx regen
The elf32-kvx.c and elf64-kvx.c rules in the bfd makefile are
different to the other similar generated files, and that reminded me
that we need to have $srcdir in the generated #line reference back to
the source for debugging, but don't want it for comments in bfd.pot
(because then bfd.pot will likely reference Nick's source tree).
This patch fixes that by making all the #line use $srcdir by virtue of
using $<, and edits bfd.pot.

I also uniq list of files to remove duplicated elfxx-x86.c, sort lists
of files and regen with our standard automake/autoconf.

	* configure: Regenerate.
bfd/
	* Makefile.am: Sort various lists of files.  Use $< in #line
	directive of generated C files.
	(po/SRC-POTFILES.in): uniq SRC_POTFILES.
	(po/BLD-POTFILES.in): uniq BFD_POTFILES.
	* Makefile.in: Regenerate.
	* po/Make-in (bfd.pot): Edit out source dir from comments.
	* po/SRC-POTFILES.in: Regenerate.
gas/
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* po/POTFILES.in: Regenerate.
ld/
	* Makefile.am (ALL_64_EMULATION_SOURCES): Sort.
	* Makefile.in: Regenerate.
2023-08-17 21:44:04 +09:30
Alan Modra
880802688c Re: sim frv: Add a missing return value for frvbf_check_acc_range.
Commit f00b50d057 went the wrong way.  As the comment says this
function is only applicable to fr550.  If not fr550 return 1,
meaning we don't have acc restrictions.
2023-08-17 21:44:04 +09:30
Tom de Vries
6feae66da1 [gdb/build, c++20] Handle deprecated std::allocator::construct
When building gdb with -std=c++20, I run into:
...
gdbsupport/default-init-alloc.h:52:12: error: ‘construct’ has not been \
  declared in ‘class std::allocator<unsigned char>’
   52 |   using A::construct;
      |            ^~~~~~~~~
...

Indeed, std::allocator::construct has been deprecated in c++17 and removed in
c++20.

Fix this by using instead std::pmr::polymorphic_allocator for c++20.

Tested on x86_64-linux.
2023-08-17 10:41:34 +02:00
Tom de Vries
9246b7bd6d [gdb/build] Return const reference in target_read_auxv
In target_read_auxv we return a copy of an object:
...
gdb::optional<gdb::byte_vector>
target_read_auxv ()
{
  ...
  return info->data;
}
...

Return a const reference instead, saving a copy.

This is exposed by using std::pmr::polymorphic_allocator instead of
std::allocator in default_init_allocator.

Tested on x86_64-linux.
2023-08-17 10:41:34 +02:00
Tom de Vries
2b9ed6db3f [gdb/build, c++20] Fix invalid conversion in test_symbols
When building gdb with -std=c++20, I run into:
...
gdb/dwarf2/read.c:2709:3: error: invalid conversion from ‘const char8_t*’ to \
  ‘const char*’ [-fpermissive]
 2709 |   u8"u8função",
      |   ^~~~~~~~~~~~
      |   |
      |   const char8_t*
...

Fix this by making the conversion explicit.

Tested on x86_64-linux.
2023-08-17 10:41:34 +02:00
Tom de Vries
5bd5fecdd2 [gdb/build, c++20] Fix deprecated implicit capture of this
When building gdb with -std=c++20 I run into:
...
gdb/ada-lang.c:10713:16: error: implicit capture of ‘this’ via ‘[=]’ is \
  deprecated in C++20 [-Werror=deprecated]
10713 |   auto do_op = [=] (LONGEST x, LONGEST y)
      |                ^
gdb/ada-lang.c:10713:16: note: add explicit ‘this’ or ‘*this’ capture
...

Fix this by using "[this]".

Likewise in two more spots.

Tested on x86_64-linux.
2023-08-17 10:41:34 +02:00
Tom de Vries
63b87362a5 [gdb/build, c++20] Fix DISABLE_COPY_AND_ASSIGN use in ui_out_emit_type
When building gdb with -std=c++20, I run into:
...
include/ansidecl.h:342:9: error: expected unqualified-id before ‘const’
  342 |   TYPE (const TYPE&) = delete;                  \
      |         ^~~~~
gdb/ui-out.h:412:3: note: in expansion of macro ‘DISABLE_COPY_AND_ASSIGN’
  412 |   DISABLE_COPY_AND_ASSIGN (ui_out_emit_type<Type>);
      |   ^~~~~~~~~~~~~~~~~~~~~~~
...

Fix this by using "DISABLE_COPY_AND_ASSIGN (ui_out_emit_type)".

Tested on x86_64-linux.
2023-08-17 10:41:34 +02:00
Tom de Vries
84c9951ebd [gdb/build, c++20] Stop using deprecated is_pod
When building gdb with clang 15 and -std=c++20, I run into:
...
gdbsupport/poison.h:52:11: error: 'is_pod<timeval>' is deprecated: use \
  is_standard_layout && is_trivial instead [-Werror,-Wdeprecated-declarations]
            std::is_pod<T>>
                 ^
...

Fix this by following the suggestion.

Likewise in gdb/unittests/ptid-selftests.c.

Tested on x86_64-linux.
2023-08-17 10:41:34 +02:00
Tom de Vries
24a601dd70 [gdb/build, c++20] Fix Wdeprecated-enum-enum-conversion
When building gdb with clang 15 and -std=c++20, I run into:
...
gdbsupport/common-exceptions.h:203:32: error: arithmetic between different \
  enumeration types ('const enum return_reason' and 'const enum errors') is \
  deprecated [-Werror,-Wdeprecated-enum-enum-conversion]
    size_t result = exc.reason + exc.error;
                    ~~~~~~~~~~ ^ ~~~~~~~~~
...

Fix this by using to_underlying.

Likewise in a few other places.

Tested on x86_64-linux.
2023-08-17 10:41:34 +02:00
Tom de Vries
f0ae7030f0 [gdb/testsuite] Fix copy-to-remote in gdb.base/vfork-follow-parent.exp
When running test-case gdb.base/vfork-follow-parent.exp, I run into:
...
ERROR: tcl error sourcing gdb/testsuite/gdb.base/vfork-follow-parent.exp.
ERROR: error copying "vforked-prog": no such file or directory
    while executing
"file copy -force $fromfile $tofile"
    (procedure "gdb_remote_download" line 29)
    invoked from within
"gdb_remote_download target $binfile3"
...

Fix this by:
- making the copy-to-remote conditional on is_remote target, and
- allowing gdb_remote_download to find $binfile3 by using
  standard_output_file.

Also remove unused variable remote_exec_prog.

Tested on x86_64-linux.
2023-08-17 10:21:18 +02:00
Jose E. Marchesi
3afe50fe19 gas: tc-sparc.c: undo spurious change in 5be1b78727 2023-08-17 10:03:54 +02:00
Jose E. Marchesi
5be1b78727 bpf: gas: consolidate handling of immediate overflows
This commit changes the BPF GAS port in order to handle immediate
overflows the same way than the clang BPF assembler:

- For an immediate field of N bits, any written number (positive or
  negative) whose two's complement encoding fit in N its is accepted.
  This means that -2 is the same than 0xffffffe.  It is up to the
  instructions to decide how to interpret the encoded value.

- Immediate fields in jump instructions are no longer relaxed.
  Relaxing to jump instructions with wider range is only performed
  when expressions are involved.

- The manual is updated to document this, and testsuite adapted
  accordingly.

Tested in x86_64-linux-gnu host, bpf-unknown-none target.

gas/ChangeLog:

2023-08-17  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* config/tc-bpf.c (check_immediate_overflow): New function.
	(encode_insn): Use check_immediate_overflow.
	(md_assemble): Do not relax instructions with
	constant disp16 fields.
	* doc/c-bpf.texi (BPF Instructions): Add note about how numerical
	literal values are interpreted for instruction immediate operands.
	* testsuite/gas/bpf/disp16-overflow.s: Adapt accordingly.
	* testsuite/gas/bpf/jump-relax-jump.s: Likewise.
	* testsuite/gas/bpf/jump-relax-jump.d: Likewise.
	* testsuite/gas/bpf/jump-relax-jump-be.d: Likewise.
	* testsuite/gas/bpf/jump-relax-ja.s: Likewise.
	* testsuite/gas/bpf/jump-relax-ja.d: Likewise.
	* testsuite/gas/bpf/jump-relax-ja-be.d: Likewise.
	* testsuite/gas/bpf/disp16-overflow-relax.l: Likewise.
	* testsuite/gas/bpf/imm32-overflow.s: Likewise.
	* testsuite/gas/bpf/disp32-overflow.s: Likewise.
	* testsuite/gas/bpf/disp16-overflow.l: Likewise.
	* testsuite/gas/bpf/disp32-overflow.l: Likewise.
	* testsuite/gas/bpf/imm32-overflow.l: Likewise.
	* testsuite/gas/bpf/offset16-overflow.l: Likewise.
2023-08-17 09:41:43 +02:00
Sam James
646657284f ld: ld-lib.exp: log failed dump.out contents for debugging
If we're using dump_prog in a test which fails, log the dump.out contents
to ld.log to aid debugging.

This avoids needing to ask reporters to manually run e.g. `objdump` commands
when making bug reports.

PR30722
	* ld/testsuite/lib/ld-lib.exp: Log failed dump.out contents to aid
	debugging.

Approved-by: Nick Clifton <nickc@redhat.com>
Signed-off-by: Sam James <sam@gentoo.org>
2023-08-17 05:21:02 +01:00
GDB Administrator
4c072eb629 Automatic date update in version.in 2023-08-17 00:00:26 +00:00
Tom de Vries
eeee4389cf [gdb/symtab] Handle self-reference DIE
While working on a dwarf assembly test-case I accidentally created the
following pathological dwarf:
...
 <1><be>: Abbrev Number: 3 (DW_TAG_class_type)
    <bf>   DW_AT_name        : c1
    <c2>   DW_AT_specification: <0xbe>
...
and noticed gdb segfaulting during cooked index creating due to running out of
stack.  This is a regression from gdb-12, where gdb just hung.

Fix this by inhibiting the scan_attributes self-recursion for self-references.

The same test-case with -readnow makes gdb hang, so also fix this in
dwarf2_attr and follow_die_ref.

Note that this doesn't fix the same problems for the more complicated case of:
...
 <1><be>: Abbrev Number: 3 (DW_TAG_class_type)
    <bf>   DW_AT_name        : c1
    <c2>   DW_AT_specification: <0xc6>
 <1><c6>: Abbrev Number: 4 (DW_TAG_class_type)
    <c7>   DW_AT_name        : c2
    <ca>   DW_AT_specification: <0xbe>
...
but the approach for deciding whether to fix pathological dwarf cases is as
per PR27981 comment 3:
...
yes if it is cheap/obvious, and no if it is something complicated or expensive.
...
and at this point I'm not sure whether fixing this will fall in the first
category.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2023-08-16 23:43:25 +02:00
Tom Tromey
033bc52bb6 Avoid buffer overflow in ada_decode
A bug report pointed out a buffer overflow in ada_decode, which Keith
helpfully analyzed.  ada_decode had a logic error when the input was
all digits.  While this isn't valid -- and would probably only appear
in fuzzer tests -- it still should be handled properly.

This patch adds a missing bounds check.  Tested with the self-tests in
an asan build.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30639
Reviewed-by: Keith Seitz <keiths@redhat.com>
2023-08-16 13:07:08 -06:00
Tom Tromey
94c5098e4d Fix obvious bug in aggregate expression
I found an obvious bug in Ada aggregate expression handling:

	  if (vvo != nullptr)
 	    error (_("Invalid record component association."));
 	  name = vvo->get_symbol ()->natural_name ();

Here the code errors when vvo is not null -- and then proceeds to use
vvo.

This hasn't caused a crash because, I believe, there's currently no
way to reach this code in the null case.  However, I'm not really
willing to assert this...

Fixing this shows another bug, which is that due to the way the parser
works, a field name in an aggregate expression might erroneously be
fully qualified if some global variable with the same base name
exists.

The included test case triggers both bugs.  Note that the test
includes a confounding case for array aggregates as well, but as these
are harder to fix, I've left it as kfail.

As this is Ada-specific, and has already been tested internally at
AdaCore, I am checking it in.
2023-08-16 11:43:40 -06:00
Tom Tromey
100dbc6de5 Implement DAP module-removed event
DAP specifies an event that should be sent when a module is removed.
This patch implements this.

Tested-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
2023-08-16 09:55:10 -06:00
Andrew Burgess
a345d14fa6 gdb/testsuite: fix race condition in gdb.python/py-thread-exited.exp
I ran into a test failure on gdb.python/py-thread-exited.c.  The test
creates two threads and then catches the thread exits in Python.  The
test expects the threads to exit in a specific order.

As the test is currently written, it is _likely_, but not guaranteed,
that the threads will exit in the same order they are created, which
is what the test expects.

When running on a loaded system I ran into a case where the threads
exited in the reverse creation order, which caused the test to fail.

I could fix this by having the .exp file not care about the thread
order, or by changing the C file to force the order. I chose the
later, and added a pthread_barrier_t to ensure the threads exit in the
correct order.

There should be no change in what is tested after this commit.
2023-08-16 15:03:56 +01:00
Andrew Burgess
05e1cac249 gdb: fix vfork regressions when target-non-stop is off
It was pointed out on the mailing list[1] that after this commit:

  commit b1e0126ec5
  Date:   Wed Jun 21 14:18:54 2023 +0100

      gdb: don't resume vfork parent while child is still running

the test gdb.base/vfork-follow-parent.exp now has some failures when
run with the native-gdbserver or native-extended-gdbserver boards:

  FAIL: gdb.base/vfork-follow-parent.exp: resolution_method=schedule-multiple: continue to end of inferior 2 (timeout)
  FAIL: gdb.base/vfork-follow-parent.exp: resolution_method=schedule-multiple: inferior 1 (timeout)
  FAIL: gdb.base/vfork-follow-parent.exp: resolution_method=schedule-multiple: print unblock_parent = 1 (timeout)
  FAIL: gdb.base/vfork-follow-parent.exp: resolution_method=schedule-multiple: continue to break_parent (timeout)

The reason that these failures don't show up when run on the standard
unix board is that the test is only run in the default operating mode,
so for Linux this will be all-stop on top of non-stop.

If we adjust the test script so that it runs in the default mode and
with target-non-stop turned off, then we see the same failures on the
unix board.  This commit includes this change.

The way that the test is written means that it is not (currently)
possible to turn on non-stop mode and have the test still work, so
this commit does not do that.

I have also updated the test script so that the vfork child performs
an exec as well as the current exit.  Exec and exit are the two ways
in which a vfork child can release the vfork parent, so testing both
of these cases is useful I think.

In this test the inferior performs a vfork and the vfork-child
immediately exits.  The vfork-parent will wait for the vfork-child and
then blocks waiting for gdb.  Once gdb has released the vfork-parent,
the vfork-parent also exits.

In the test that fails, GDB sets 'detach-on-fork off' and then runs to
the vfork.  At this point the test tries to just "continue", but this
fails as the vfork-parent is still selected, and the parent can't
continue until the vfork-child completes.  As the vfork-child is
stopped by GDB the parent will never stop once resumed, so GDB refuses
to resume it.

The test script then sets 'schedule-multiple on' and once again
continues.  This time GDB, in theory, resumes both the parent and the
child, the parent will be held blocked by the kernel, but the child
will run until it exits, and which point GDB stops again, this time
with inferior 2, the newly exited vfork-child, selected.

What happens after this in the test script is irrelevant as far as
this failure is concerned.

To understand why the test started failing we should consider the
behaviour of four different cases:

  1. All-stop-on-non-stop before commit b1e0126ec5,

  2. All-stop-on-non-stop after commit b1e0126ec5,

  3. All-stop-on-all-stop before commit b1e0126ec5, and

  4. All-stop-on-all-stop after commit b1e0126ec5.

Only case #4 is failing after commit b1e0126ec5, but I think the
other cases are interesting because, (a) they inform how we might fix
the regression, and (b) it turns out the behaviour of #2 changed too
with the commit, but the change was harmless.

For #1 All-stop-on-non-stop before commit b1e0126ec5, what happens
is:

  1. GDB calls proceed with the vfork-parent selected, as schedule
     multiple is on user_visible_resume_ptid returns -1 (everything)
     as the resume_ptid (see proceed function),

  2. As this is all-stop-on-non-stop, every thread is resumed
    individually, so GDB tries to resume both the vfork-parent and the
    vfork-child, both of which succeed,

  3. The vfork-parent is held stopped by the kernel,

  4. The vfork-child completes (exits) at which point the GDB sees the
     EXITED event for the vfork-child and the VFORK_DONE event for the
     vfork-parent,

  5. At this point we might take two paths depending on which event
     GDB handles first, if GDB handles the VFORK_DONE first then:

     (a) As GDB is controlling both parent and child the VFORK_DONE is
         ignored (see handle_vfork_done), the vfork-parent will be
	 resumed,

     (b) GDB processes the EXITED event, selects the (now defunct)
         vfork-child, and stops, returning control to the user.

     Alternatively, if GDB selects the EXITED event first then:

     (c) GDB processes the EXITED event, selects the (now defunct)
         vfork-child, and stops, returning control to the user.

     (d) At some future time the user resumes the vfork-parent, at
         which point the VFORK_DONE is reported to GDB, however, GDB
	 is ignoring the VFORK_DONE (see handle_vfork_done), so the
	 parent is resumed.

For case #2, all-stop-on-non-stop after commit b1e0126ec5, the
important difference is in step (2) above, now, instead of resuming
both the vfork-parent and the vfork-child, only the vfork-child is
resumed.  As such, when we get to step (5), only a single event, the
EXITED event is reported.

GDB handles the EXITED just as in (5)(c), then, later, when the user
resumes the vfork-parent, the VFORKED_DONE is immediately delivered
from the kernel, but this is ignored just as in (5)(d), and so,
though the pattern of when the vfork-parent is resumed changes, the
overall pattern of which events are reported and when, doesn't
actually change.  In fact, by not resuming the vfork-parent, the order
of events (in this test) is now deterministic, which (maybe?) is a
good thing.

If we now consider case #3, all-stop-on-all-stop before commit
b1e0126ec5, then what happens is:

  1. GDB calls proceed with the vfork-parent selected, as schedule
     multiple is on user_visible_resume_ptid returns -1 (everything)
     as the resume_ptid (see proceed function),

  2. As this is all-stop-on-all-stop, the resume is passed down to the
     linux-nat target, the vfork-parent is the event thread, while the
     vfork-child is a sibling of the event thread,

  3. In linux_nat_target::resume, GDB calls linux_nat_resume_callback
     for all threads, this causes the vfork-child to be resumed.  Then
     in linux_nat_target::resume, the event thread, the vfork-parent,
     is also resumed.

  4. The vfork-parent is held stopped by the kernel,

  5. The vfork-child completes (exits) at which point the GDB sees the
     EXITED event for the vfork-child and the VFORK_DONE event for the
     vfork-parent,

  6. We are now in a situation identical to step (5) as for
     all-stop-on-non-stop above, GDB selects one of the events to
     handle, and whichever we select the user sees the correct
     behaviour.

And so, finally, we can consider #4, all-stop-on-all-stop after commit
b1e0126ec5, this is the case that started failing.

We start out just like above, in proceed, the resume_ptid is
-1 (resume everything), due to schedule multiple being on.  And just
like above, due to the target being all-stop, we call
proceed_resume_thread_checked just once, for the current thread,
which, remember, is the vfork-parent thread.

The change in commit b1e0126ec5 was to avoid resuming a vfork-parent
thread, read the commit message for the justification for this change.

However, this means that GDB now rejects resuming the vfork-parent in
this case, which means that nothing gets resumed!  Obviously, if
nothing resumes, then nothing will ever stop, and so GDB appears to
hang.

I considered a couple of solutions which, in the end, I didn't go
with, these were:

  1. Move the vfork-parent check out of proceed_resume_thread_checked,
     and place it in proceed, but only on the all-stop-on-non-stop
     path, this should still address the issue seen in b1e0126ec5,
     but would avoid the issue seen here.  I rejected this just
     because it didn't feel great to split the checks that exist in
     proceed_resume_thread_checked like this,

  2. Extend the condition in proceed_resume_thread_checked by adding a
     target_is_non_stop_p check.  This would have the same effect as
     idea 1, but leaves all the checks in the same place, which I
     think would be better, but this still just didn't feel right to
     me, and so,

What I noticed was that for the all-stop-on-non-stop, after commit
b1e0126ec5, we only resumed the vfork-child, and this seems fine.
The vfork-parent isn't going to run anyway (the kernel will hold it
back), so if feels like we there's no harm in just waiting for the
child to complete, and then resuming the parent.

So then I started looking at follow_fork, which is called from the top
of proceed.  This function already has the task of switching between
the parent and child based on which the user wishes to follow.  So, I
wondered, could we use this to switch to the vfork-child in the case
that we are attached to both?

Turns out this is pretty simple to do.

Having done that, now the process is for all-stop-on-all-stop after
commit b1e0126ec5, and with this new fix is:

  1. GDB calls proceed with the vfork-parent selected, but,

  2. In follow_fork, and follow_fork_inferior, GDB switches the
     selected thread to be that of the vfork-child,

  3. Back in proceed user_visible_resume_ptid returns -1 (everything)
     as the resume_ptid still, but now,

  4. When GDB calls proceed_resume_thread_checked, the vfork-child is
     the current selected thread, this is not a vfork-parent, and so
     GDB allows the proceed to continue to the linux-nat target,

  5. In linux_nat_target::resume, GDB calls linux_nat_resume_callback
     for all threads, this does not resume the vfork-parent (because
     it is a vfork-parent), and then the vfork-child is resumed as
     this is the event thread,

At this point we are back in the same situation as for
all-stop-on-non-stop after commit b1e0126ec5, that is, the
vfork-child is resumed, while the vfork-parent is held stopped by
GDB.

Eventually the vfork-child will exit or exec, at which point the
vfork-parent will be resumed.

[1] https://inbox.sourceware.org/gdb-patches/3e1e1db0-13d9-dd32-b4bb-051149ae6e76@simark.ca/
2023-08-16 14:59:51 +01:00
Paul Iannetta
6e712424f5 kvx: New port. 2023-08-16 14:22:54 +01:00
Richard Ball
7d6a2e34ee aarch64: Enable Cortex-A720 CPU
This patch adds support for the Cortex-A720 CPU to binutils.

bfd/ChangeLog:

	* cpu-aarch64.c: Add Cortex-A720.

gas/ChangeLog:

	* NEWS: Update docs.
	* config/tc-aarch64.c: Add Cortex-A720.
	* doc/c-aarch64.texi: Update docs.
	* testsuite/gas/aarch64/cpu-cortex-a720.d: New test.
2023-08-16 14:08:09 +01:00
Puputti, Matti
da1f552dc7 gdb, infcmd: support jump command in multi-inferior case
Fixes the issue where jump failed if multiple inferiors run the same
source.

See the below example

    $ gdb -q ./simple
    Reading symbols from ./simple...
    (gdb) break 2
    Breakpoint 1 at 0x114e: file simple.c, line 2.
    (gdb) run
    Starting program: /temp/simple

    Breakpoint 1, main () at simple.c:2
    2         int a = 42;
    (gdb) add-inferior
    [New inferior 2]
    Added inferior 2 on connection 1 (native)
    (gdb) inferior 2
    [Switching to inferior 2 [<null>] (<noexec>)]
    (gdb) info inferiors
      Num  Description       Connection           Executable
      1    process 6250      1 (native)           /temp/simple
    * 2    <null>            1 (native)
    (gdb) file ./simple
    Reading symbols from ./simple...
    (gdb) run
    Starting program: /temp/simple

    Thread 2.1 "simple" hit Breakpoint 1, main () at simple.c:2
    2         int a = 42;
    (gdb) info inferiors
      Num  Description       Connection           Executable
      1    process 6250      1 (native)           /temp/simple
    * 2    process 6705      1 (native)           /temp/simple
    (gdb) jump 3
    Unreasonable jump request
    (gdb)

In this example, jump fails because the debugger finds two different
locations, one for each inferior.

Solution is to limit the search to the current program space.

This is done by having the jump_command function use
decode_line_with_current_source rather than
decode_line_with_last_displayed, which makes sense,
the *_current_source function always looks up a location based on the
current thread's location -- if a user is asking the current thread to
jump, then surely their destination should be relative to where the
current thread is located.

Then, inside decode_line_with_current_source, the call to
decode_line_1 is updated to pass through the current program_space,
which will limit the returned locations to those in the current
program space.

Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-08-16 09:55:52 +01:00
GDB Administrator
ba22cd5e88 Automatic date update in version.in 2023-08-16 00:00:30 +00:00
Tom Tromey
2a3f442df9 Mention process_stratum in inferior::priv comment
From what I can tell, inferior::priv is reserved for the
process_stratum target.  It seems to me that it has to be, because
currenlty only such targets use it, and if a target at another stratum
started using this field, then conflicts could occur.  This patch
documents this.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
2023-08-15 07:35:17 -06:00
Nick Clifton
22b6999fa0 Updated Russian translation for the bfd directory 2023-08-15 14:26:45 +01:00
Tsukasa OI
f9280e396f RISC-V: Make T-Head testing pattern more generic
On some T-Head vendor extensions, we test against the constant
18446744073709551615 (2**64-1) to detect invalid immediate errors on -1.
However, it heavily depends on the fact that the value used to print
immediate value is a 64-bit unsigned type and this constant is not (and
should not be) important (we just want to know that -1 is not valid).

This commit replaces all such occurrences of 18446744073709551615 with
a more generic regular expression.

gas/ChangeLog:

	* testsuite/gas/riscv/x-thead-ba-fail.l: Replace
	18446744073709551615 with generic regular expression.
	* testsuite/gas/riscv/x-thead-bb-fail.l: Likewise.
	* testsuite/gas/riscv/x-thead-bs-fail.l: Likewise.
	* testsuite/gas/riscv/x-thead-fmemidx-fail.l: Likewise.
	* testsuite/gas/riscv/x-thead-memidx-fail.l: Likewise.
	* testsuite/gas/riscv/x-thead-mempair-fail.l: Likewise.
2023-08-15 06:46:18 +00:00
Tsukasa OI
239af8cbd1 RISC-V: Make "fli.h" available to 'Zvfh' + 'Zfa'
The documentation of the 'Zfa' extension states that "fli.h" is available
"if the Zfh or Zvfh extension is implemented" (both the latest and the
oldest editions are checked).

This fact was not reflected in Binutils ('Zvfh' implies 'Zfhmin', not full
'Zfh' extension and "fli.h" required 'Zfh' and 'Zfa' extensions).
This commit makes "fli.h" also available when both 'Zfa' and 'Zvfh'
extensions are implemented.

bfd/ChangeLog:

	* elfxx-riscv.c (riscv_multi_subset_supports): Add new
	instruction class handling.
	(riscv_multi_subset_supports_ext): Likewise.

gas/ChangeLog:

	* testsuite/gas/riscv/zfa-zvfh.s: New test.
	* testsuite/gas/riscv/zfa-zvfh.d: Ditto.

include/ChangeLog:

	* opcode/riscv.h (enum riscv_insn_class): Add new instruction
	class.

opcodes/ChangeLog:

	* riscv-opc.c (riscv_opcodes): Change instruction class of "fli.h"
	from INSN_CLASS_ZFH_AND_ZFA to new INSN_CLASS_ZFH_OR_ZVFH_AND_ZFA.
2023-08-15 06:46:18 +00:00
Tsukasa OI
2266f86318 RISC-V: Add support for the 'Zihintntl' extension
This commit adds 'Zihintntl' extension and its hint instructions.

This is based on:
<0dc91f505e>,
the first ISA Manual noting that the 'Zihintntl' extension is ratified.

Note that compressed 'Zihintntl' hints require either 'C' or
'Zca' extension.

Co-authored-by: Nelson Chu <nelson@rivosinc.com>

bfd/ChangeLog:

	* elfxx-riscv.c (riscv_supported_std_z_ext): Add 'Zihintntl'
	standard hint 'Z' extension.
	(riscv_multi_subset_supports): Support new instruction classes.
	(riscv_multi_subset_supports_ext): Likewise.

gas/ChangeLog:

	* testsuite/gas/riscv/zihintntl.s: New test for 'Zihintntl'
	including auto-compression without C prefix and explicit C prefix.
	* testsuite/gas/riscv/zihintntl.d: Likewise.
	* testsuite/gas/riscv/zihintntl-na.d: Likewise.
	* testsuite/gas/riscv/zihintntl-base.s: New test for correspondence
	between 'Zihintntl' and base 'I' or 'C' instructions.
	* testsuite/gas/riscv/zihintntl-base.d: Likewise.

include/ChangeLog:

	* opcode/riscv.h (enum riscv_insn_class): Add new instruction
	classes: INSN_CLASS_ZIHINTNTL and INSN_CLASS_ZIHINTNTL_AND_C.
	(MASK_NTL_P1, MATCH_NTL_P1, MASK_NTL_PALL,
	MATCH_NTL_PALL, MASK_NTL_S1, MATCH_NTL_S1, MASK_NTL_ALL,
	MATCH_NTL_ALL, MASK_C_NTL_P1, MATCH_C_NTL_P1, MASK_C_NTL_PALL,
	MATCH_C_NTL_PALL, MASK_C_NTL_S1, MATCH_C_NTL_S1, MASK_C_NTL_ALL,
	MATCH_C_NTL_ALL): New.

opcodes/ChangeLog:

	* riscv-opc.c (riscv_opcodes): Add instructions from the
	'Zihintntl' extension.
2023-08-15 06:45:26 +00:00
Jan Beulich
02a63525ef RISC-V: remove indirection from register tables
The longest register name is 4 characters (plus a nul one), so using a
4- or 8-byte pointer to get at it is neither space nor time efficient.
Embed the names right into the array. For PIE this also reduces the
number of base relocations in the final image.

To avoid old gcc, when generating 32-bit code, bogusly warning about
bounds being exceeded in the code processing Cs/Cw, Ct/Cx, and CD,
an adjustment to EXTRACT_BITS() is needed: This macro shouldn't supply
a 64-bit value, and it also doesn't need to - all operand fields to
date are far more narrow than 32 bits. This in turn allows dropping a
number of casts elsewhere.
2023-08-15 08:34:56 +02:00
Jan Beulich
a2182c73d2 PPC: remove indirection from struct pd_reg
The longest register name is 5 characters (plus a nul one), so using a
4- or 8-byte pointer to get at it is neither space nor time efficient.
Embed the names right into the array. For PIE this also reduces the
number of base relocations in the final image.
2023-08-15 08:34:13 +02:00
GDB Administrator
2d7f31063b Automatic date update in version.in 2023-08-15 00:00:32 +00:00
Tom de Vries
bc6c74b140 [gdb/build] Fix YYSTYPE and yyalloc odr violation
When building gdb with -O2 -flto I run into:
...
ada-exp.c.tmp:576:7: error: type ‘union YYSTYPE’ violates the C++ One \
  Definition Rule [-Werror=odr]
...

Fix this by renaming to ada_exp_YYSTYPE and likewise for other .y files.

Likewise for yyalloc.

Tested on x86_64-linux.  Also tested with byacc rather than bison on
suggestion of Tom Tromey.

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

PR build/22395
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
2023-08-14 22:52:52 +02:00
John Baldwin
fdeef5e428 fbsd-nat: Stop a process if it is running before killing it.
In addition, detach from any child processes implicitly attached to by
the kernel due to fork following that have not yet been processed by
GDB's core.
2023-08-14 13:38:42 -07:00
John Baldwin
57c28d45f9 fbsd-nat: Fix thread_alive against a running thread.
FreeBSD's ptrace fails requests with EBUSY against a running process.
Report that the thread is alive instead of dead if ptrace fails with
EBUSY.

This fixes an internal error in the gdb.threads/detach-step-over.exp
test where one process was detached while a thread in a second process
was being stepped.  The core incorrectly assumed the stepping thread
had vanished and discarded the pending stepping state.  When the
thread later reported a SIGTRAP from completing the step, this
triggered an assertion.
2023-08-14 13:38:42 -07:00
John Baldwin
e1d94b3b52 fbsd-nat: Fix several issues with detaching.
- Detach from any child processes implicitly attached to by the kernel
  due to fork following that have not yet been processed by GDB's
  core.

- Delete breakpoints before detaching.

  inf-ptrace::detach does not do this (somewhat surprisingly), so add
  an override to remove breakpoints from a process before detaching
  from it.

  This also requires explicitly draining any pending SIGTRAP events
  for software breakpoints before detaching.  In particular, threads
  may need their PC adjusted due to the software breakpoint before
  being resumed after detach.  On more modern systems using the si_code
  from SIGTRAP to identify software breakpoint traps, the PC is adjusted
  in ::wait_1 as a side effect of parsing the event.  To support older
  kernels, ::detach fixes up the PC for any SIGTRAP stop whose potential
  new PC matches an existing software breakpoint.
2023-08-14 13:38:42 -07:00
John Baldwin
12e5b10965 fbsd-nat: Fix resuming and waiting with multiple processes.
I did not fully understand the requirements of multiple process
support when I enabled it previously and several parts were broken.
In particular, the resume method was only resuming a single process,
and wait was not stopping other processes when reporting an event.

To support multiple running inferiors, add a new per-inferior
structure which trackes the number of existing and running LWPs for
each process.  The structure also stores a ptid_t describing the
set of LWPs currently resumed for each process.

For the resume method, iterate over all non-exited inferiors resuming
each process matching the passed in ptid rather than only resuming the
current inferior's process for a wildcard ptid.  If a resumed process
has a pending event, don't actually resume the process, but other
matching processes without a pending event are still resumed in case
the later call to the wait method requests an event from one of the
processes without a pending event.

For the wait method, stop other running processes before returning an
event to the core.  When stopping a process, first check to see if an
event is already pending.  If it is, queue the event to be reported
later.  If not, send a SIGSTOP to the process and wait for it to stop.
If the event reported by the wait is not for the SIGSTOP, queue the
event and remember to ignore a future SIGSTOP event for the process.

Note that, unlike the Linux native target, entire processes are
stopped rather than individual LWPs.  In FreeBSD one can only wait on
processes (via pid), not for an event from a specific thread.

Other changes in this commit handle bookkeeping for the per-inferior
data such as migrating the data to the new inferior in the follow_exec
method.  The per-inferior data is created in the attach,
create_inferior, and follow_fork methods.
2023-08-14 13:38:42 -07:00
John Baldwin
a6f5154294 fbsd-nat: Defer any ineligible events reported by wait.
If wait_1 finds an event for a thread or process that does not match
the set of threads and processes previously resumed, defer the event.
If the event is for a specific thread, suspend the thread and continue
the associated process before waiting for another event.

One specific example of such an event is if a thread is created while
another thread in the same process hits a breakpoint.  If the second
thread's event is reported first, the target resume method does not
yet "know" about the new thread and will not suspend it via
PT_SUSPEND.  When wait is called, it will probably return the event
from the first thread before the result of the step from second
thread.  This is the case reported in PR 21497.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=21497
2023-08-14 13:38:42 -07:00
John Baldwin
1b0fa45741 fbsd-nat: Add a list of pending events.
The m_pending_events list stores a queue of deferred events that might
be reported by the next call to the target's wait method.  The set of
events that are eligible is filtered by the ptid passed to resume.

For now this just replaces the list of vfork_done events.  A
subsequent commit will reuse this to store other events.
2023-08-14 13:38:42 -07:00
Tom Tromey
dad9ed2f25 Remove alloca from osabi.c
I noticed that the call to alloca in osabi.c can be replaced with a
statically-sized buffer, because some code just before the declaration
ensures that the length is bounded.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
2023-08-14 14:12:29 -06:00
Tom de Vries
e72b937ddd [gdb/build] Fix struct token odr violation
When building gdb with -O2 -flto I run into:
...
/data/vries/gdb/src/gdb/c-exp.y:2450:8: warning: type 'struct token' \
  violates the C++ One Definition Rule [-Wodr]
 struct token
        ^
/data/vries/gdb/src/gdb/d-exp.y:939:8: note: a different type is defined in \
  another translation unit
 struct token
        ^
...

Fix this by renaming to c_token and d_token.

Likewise in:
- fortran-exp.y, renaming to f_token,
- go-exp.y, renaming to go_token, and
- p-exp.y, renaming to p_token.

Tested on x86_64-linux.

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

PR build/22395
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
2023-08-14 18:32:29 +02:00
Tom de Vries
9972aac27d [gdb/build] Fix struct token_and_value odr violation
When build gdb with -O2 -flto I run into:
...
gdb/c-exp.y:3003:8: warning: type 'struct token_and_value' violates the C++ \
  One Definition Rule [-Wodr]
 struct token_and_value
        ^
gdb/d-exp.y:1310:8: note: a different type is defined in another translation \
  unit
 struct token_and_value
        ^
...

Fix this by renaming to c_token_and_value and d_token_and_value.

Likewise in gdb/go-exp.y, renaming to go_token_and_value.

Tested on x86_64-linux.

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

PR build/22395
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
2023-08-14 18:32:29 +02:00
Tom de Vries
6a93ab8af4 [gdb/build] Fix enum param_types odr violation
When building gdb with -O2 -flto, I run into:
...
gdb/guile/scm-param.c:121:6: warning: type 'param_types' violates the C++ \
  One Definition Rule [-Wodr]
 enum param_types
      ^
gdb/python/py-param.c:33:6: note: an enum with different value name is \
  defined in another translation unit
 enum param_types
      ^
...

Fix this by renaming to enum scm_param_types and py_param_types.

Tested on x86_64-linux.

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

PR build/22395
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
2023-08-14 18:32:29 +02:00
Tom de Vries
7f7ecb46c1 [gdb/build] Remove superfluous variable param_types in gdb/python/py-param.c
In gdb/python/py-param.c we have:
...
enum param_types
{
  ...
}
param_types;
...
which declares both an enum param_types, and an unused variable param_types.

Fix this by removing the variable.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2023-08-14 18:32:29 +02:00
Tom de Vries
980111642d [gdb] Fix maint print symbols/psymbols help text
Consider the help text of "maint print symbols":
...
(gdb) help maint print symbols
Print dump of current symbol definitions.
Usage: mt print symbols [-pc ADDRESS] [--] [OUTFILE]
       mt print symbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]
Entries in the full symbol table are dumped to file OUTFILE,
or the terminal if OUTFILE is unspecified.
If ADDRESS is provided, dump only the file for that address.
If SOURCE is provided, dump only that file's symbols.
If OBJFILE is provided, dump only that file's minimal symbols.
...
and "maint print psymbols":
...
(gdb) help maint print psymbols
Print dump of current partial symbol definitions.
Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]
       mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]
Entries in the partial symbol table are dumped to file OUTFILE,
or the terminal if OUTFILE is unspecified.
If ADDRESS is provided, dump only the file for that address.
If SOURCE is provided, dump only that file's symbols.
If OBJFILE is provided, dump only that file's minimal symbols.
...

The OBJFILE lines mistakingly mention minimal symbols.

Fix this by reformulating as "dump only that object file's symbols".

Also make the ADDRESS lines more clear by using the formulation: "dump only
the symbols for the file with code at that address".

Tested on x86_64-linux.

Co-Authored-By: Eli Zaretskii <eliz@gnu.org>

PR gdb/30742
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30742
2023-08-14 18:27:02 +02:00
H.J. Lu
51dd9e7c4c ld: Build libpr23169a.so with -z lazy
pr23169b test only works with lazy binding.  To work with linker which
disables lazy binding by default, build pr23169b binaries with -z lazy.

	PR ld/30698
	* ld-ifunc/ifunc.exp: Build pr23169b binaries with -z lazy.
2023-08-14 08:43:01 -07:00