Commit Graph

115163 Commits

Author SHA1 Message Date
H.J. Lu
a61cb9dbc6 Revert "x86: Don't check if AVX512 template requires AVX512VL"
This reverts commit c7face1422.
2023-06-22 12:37:51 -07:00
Tom de Vries
d4d5b57195 [gdb/testsuite] Clean or check standard_output_file dir in gdb_init
In commit e2adba909e ("[gdb/testsuite] Clean up before compilation in
gdb.ada/call-no-debug.exp") I added some code in the test-case to remove some
files at the start of the test-case:
...
remote_file host delete [standard_output_file prog.o]
remote_file host delete [standard_output_file prog.ali]
...

Then in commit b7b77500dc ("[gdb/testsuite] Clean standard_output_file dir in
gdb_init") I tried to do this more structurally, by cleaning up the entire
standard_output_file directory, for all test-cases.

This caused a regression when using "make check -j 2", due to the cleanup
removing the active gdb.log, so I reverted the commit.

Try again, this time handling the two cases separately.

If the standard_output_file directory contains an active gdb.log, check that
the directory contains no files other than gdb.log and gdb.sum.  This puts
the reponsibility for the cleanup at the callers in gdb/testsuite/Makefile.in
which use --outdir.

If the standard_output_file directory doesn't contain an active gdb.log, clean
it by removing the entire directory.

An exception is made for performance tests, where cleaning up the
standard_output_file dir is the wrong thing to do, because an invocation with
GDB_PERFTEST_MODE == run is intended to reuse binaries left there by an
earlier invocation with GDB_PERFTEST_MODE == compile.

Tested on x86_64-linux.

Suggested-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Tom Tromey <tom@tromey.com>
Tested-By: Luis Machado <luis.machado@arm.com>
2023-06-22 19:15:23 +02:00
Tom Tromey
d8a001f570 Implement DAP "hover" context
A DAP client can request that an expression be evaluated in "hover"
context, meaning that it should not cause side effects.  In gdb, this
can be implemented by temporarily setting a few "may-" parameters to
"off".

In order to make this work, I had to also change "may-write-registers"
so that it can be changed while the program is running.  I don't think
there was any reason for this prohibition in the first place.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30476
2023-06-22 09:46:24 -06:00
Tom Tromey
0aafd5d038 Implement DAP logging breakpoints
DAP allows a source breakpoint to specify a log message.  When this is
done, the breakpoint acts more like gdb's dprintf: it logs a message
but does not cause a stop.

I looked into implement this using dprintf with the new %V printf
format.  However, my initial attempt at this did not work, because
when the inferior is continued, the dprintf output is captured by the
gdb.execute call.  Maybe this could be fixed by having all
inferior-continuation commands use the "&" form; the main benefit of
this would be that expressions are only parsed a single time.
2023-06-22 09:46:24 -06:00
Tom Tromey
59e75852dd Handle supportsVariablePaging in DAP
A bug report about the supportsVariablePaging capability in DAP
resulted in a clarification: when this capability is not present, DAP
implementations should ignore the paging parameters to the "variables"
request.  This patch implements this clarification.
2023-06-22 09:46:23 -06:00
Tom Tromey
5ad513ae62 Implement type checking for DAP breakpoint requests
I realized that with a small refactoring, it is possible to type-check
the parameters to the various DAP breakpoint requests.  This would
have caught the earlier bug involving hitCondition.
2023-06-22 09:46:23 -06:00
Tom Tromey
c1dad46f35 Handle exceptions when creating DAP breakpoints
When creating a DAP breakpoint, a failure should be returned by
setting "verified" to False.  gdb didn't properly implement this, and
there was a FIXME comment to this effect.  This patch fixes the
problem.
2023-06-22 09:46:23 -06:00
Tom Tromey
44fc43e5c8 Reuse breakpoints more frequently in DAP
The DAP breakpoint code tries to reuse a breakpoint when possible.
Currently it uses the condition and the hit condition (aka ignore
count) when making this determination.  However, these attributes are
just going to be reset anyway, so this patch changes the code to
exclude these from the reuse decision.
2023-06-22 09:46:23 -06:00
Tom Tromey
32594d975a Fix type of DAP hitCondition
DAP specifies a breakpoint's hitCondition as a string, meaning it is
an expression to be evaluated.  However, gdb implemented this as if it
were an integer instead.  This patch fixes this oversight.
2023-06-22 09:46:23 -06:00
Simon Farre
596c507f5d gdb/DAP Few bug fixes & Evaluate Array Watch vars
v2.

EvaluateResult does not need a name, just as what Tom pointed out in
previous review. It's only the *children* that need to be made sure that
their names are valid. An identifier for a variable, can't ever have an
integer as a name, anyhow (not as far as I am aware, no programming
languages allow for that).

Removed the f-strings and use str() instead as pointed out that
f-strings might not be supported fully.

v1.

This patch fixes a few bugs.

First of all, name of VariableReferences must always be of string type.
This patch makes sure that this is the case by formatting the name. If
(when) the name is an integer, this will cause clients to fail or throw
errors.

Fixes a bug in NoOpArrayPrinter that calculated children to be N, but
only ever retrieves N-1 children, which makes Python at some time later
(during fetch_children -> fetch_one_child(N) ) raise an exception (out
of list index) which makes the entire request go bad.

The result[self.result_name] also f-strings the printer.to_string()
value, because this can potentially be a LazyString (which is a Python
object, not a string) and is not serializable by json.dumps.

Approved-By: Tom Tromey <tom@tromey.com>
2023-06-22 17:42:27 +02:00
GDB Administrator
07a88d7f21 Automatic date update in version.in 2023-06-22 00:00:07 +00:00
H.J. Lu
d8bcb87236 x86: Free the symbol buffer and the relocation buffer after use
When --no-keep-memory is used, the symbol buffer and the relocation
buffer aren't cached.  When packing relative relocations, we may
allocate a new symbol buffer and a new relocation buffer for each
eligible section in an object file.  If there are many sections,
memory may be exhausted.  In this case, we should free the symbol
buffer and the relocation buffer after use.  If symbol buffer entries
are used to track relative relocations against local symbols for later
use, the symbol buffer should be cached.

	PR ld/30566
	* elfxx-x86.c (elf_x86_relative_reloc_record_add): Add an
	argument to inform caller if the symbol buffer should be kept.
	(_bfd_x86_elf_link_relax_section): Call
	_bfd_elf_link_info_read_relocs instead of
	_bfd_elf_link_read_relocs.  Free the symbol buffer and the
	relocation buffer after use.  Cache the symbol buffer if it
	is used.
2023-06-21 09:13:34 -07:00
Tom Tromey
c9097e37c7 Add missing backslash to update-gnulib.sh
A user on irc noticed a missing backslash on one line in
update-gnulib.sh.  This patch adds it.

Re-running update-gnulib.sh causes a few copyright notices to change.
Presumably these are from upstream gnulib and shouldn't be touched by
our yearly update.  I've updated the script to account for this, but I
did not want to try testing it...
2023-06-21 08:47:05 -06:00
Tom de Vries
83aa25512d [gdb/testsuite] Add have_host_locale
With test-case gdb.tui/pr30056.exp, I run into:
...
sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)^M
...
and then subsequently into:
...
WARNING: timeout in accept_gdb_output
FAIL: gdb.tui/pr30056.exp: Control-C
...

This is on a CentOS 7 distro for powerpc64le.

Either it has no C.UTF-8 support, or it's not installed:
...
$ locale -a | grep ^C
C
$
...

Fix this by:
- adding a new proc have_host_locale, and
- using it in all test-cases using setenv LC_ALL.

Tested on powerpc64le-linux and x86_64-linux.
2023-06-21 16:29:04 +02:00
Tom de Vries
b96cac1607 [gdb/testsuite] Fix gdb.tui/wrap-line.exp
PR testsuite/30458 reports the following FAIL:
...
PASS: gdb.tui/wrap-line.exp: width-auto-detected: cli: wrap
^CQuit
(gdb) WARNING: timeout in accept_gdb_output
Screen Dump (size 50 columns x 24 rows, cursor at column 6, row 3):
    0 Quit
    1 (gdb) 7890123456789012345678901234567890123456789
    2 W^CQuit
    3 (gdb)
  ...
FAIL: gdb.tui/wrap-line.exp: width-auto-detected: cli: prompt after wrap
...

The problem is that the regexp doesn't account for the ^C:
...
    gdb_assert { [Term::wait_for "^WQuit"] } "prompt after wrap"
...

The ^C occurs occasionally.  This is something we'd like to fix.  It's
reported as a readline problem here (
https://lists.gnu.org/archive/html/bug-readline/2023-06/msg00000.html ).

For now, fix this by updating the regexp, and likewise in another place in the
test-case where we use ^C.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30458
2023-06-21 16:16:50 +02:00
Alan Modra
dc808a2eba PR30536, ppc64el gold linker produces unusable clang-16 binary
In commit 0961e63157, the fix for PR30217, make_lplt_section and
make_brlt_section were changed to use rela_dyn_ rather than their own
separate dynamic reloc sections.  This fails miserably whenever brlt_
is needed for long branches, due to needing to iterate sizing and thus
reset brlt_ sizes.

	PR 30536
	PR 30217
	* powerpc.cc (Target_powerpc::make_brlt_section): Don't use
	rela_dyn_.
2023-06-21 23:02:29 +09:30
Tom de Vries
9f889c4856 [gdb/testsuite] Reimplement Term::command_no_prompt_prefix
Say we run test-case gdb.tui/basic.exp.  It calls Term::enter_tui, which does:
...
	command_no_prompt_prefix "tui enable"
...

The proc command_no_prompt_prefix is documented as:
...
    # As proc command, but don't wait for an initial prompt.  This is used for
    # initial terminal commands, where there's no prompt yet.
...

Indeed, before the "tui enable" command, the tuiterm is empty, so there is no
prompt and just before switching to TUI we have in the tuiterm:
...
tui enable
...

The reason that there is no prompt, is that:
- in order for tuiterm to show something, its input processing procs need to
  be called, and
- the initial gdb prompt, and subsequent prompts generated by gdb_test-style
  procs, are all consumed by those procs instead.

This is in principle not a problem, but the absence of a prompt makes a
tuiterm session look less like a session on an actual xterm.

Add a new proc gen_prompt, that:
- generates a prompt using echo
- consumes the response before the prompt using gdb_expect
- consumes the prompt using Term::wait_for "".

This allows us to reimplement Term::command_no_prompt_prefix using
Term::command, and just before switching to TUI we have in the tuiterm:
...
(gdb) tui enable
...

Tested on x86_64-linux.
2023-06-21 15:31:37 +02:00
Tom de Vries
c9966f7a8e [gdb/testsuite] Make Term::wait_for "" match only a prompt
The semantics of Term::wait_for is:
...
    # Accept some output from gdb and update the screen.  WAIT_FOR is
    # a regexp matching the line to wait for.  Return 0 on timeout, 1
    # on success.
    proc wait_for {wait_for} {
...

Note that besides the regexp, also a subsequent gdb prompt is matched.

I recently used wait_for "" in a few test-cases, thinking that this would
match just a prompt, but in fact that's not the case.

Fix this in wait_for, and add a corresponding test in gdb.tui/tuiterm-2.exp.

Tested on x86_64-linux.
2023-06-21 15:31:37 +02:00
Nick Clifton
340640f710 Prune linker warnings about an executable stack being created with the -z execstack option.
* testsuite/lib/binutils-common.exp (prune_warnings_extra): Prune warnings about -z execstack creating an executable stack.
2023-06-21 12:10:03 +01:00
Nick Clifton
0ab7005043 For test for PR 29072 when the linker is configured with --enable-default-execstack=no.
PR 29072
  * testsuite/ld-elf/elf.exp (target_defaults_to_execstack): Always return false for linkers configured with the --enable-default-execstack=no option.
2023-06-21 11:47:19 +01:00
Tankut Baris Aktemur
94dd9fb748 gdbserver: use target_waitstatus::to_string in 'prepare_resume_reply'
Use the to_string method of target_waitstatus in
'prepare_resume_reply' for a more readable log message.

Approved-By: Tom Tromey <tom@tromey.com>
2023-06-21 08:47:13 +02:00
Jan Beulich
fffb10b122 x86: fix expansion of %XV
Only %LV should continue on to S handling; avoid emitting a stray 'l'
(typically) in suffix-always mode.
2023-06-21 08:32:13 +02:00
Alan Modra
08edd97611 elf32_arm_get_synthetic_symtab memory leak
ARM get_synthetic_symtab reads .plt and caches that data.  Caching the
data doesn't make a lot of sense since get_synthetic_symtab is only
called once per bfd, and the memory might be put to better use.  It
also leaks on closing the bfd.

	* elf32-arm.c (elf32_arm_get_synthetic_symtab): Don't cache
	plt contents.  Free plt data before returning.
2023-06-21 15:49:39 +09:30
Alan Modra
9a925d0dad macho-o.c don't leak strtab
* mach-o.c (bfd_mach_o_write_symtab_content): Free strtab on
	success path.
2023-06-21 15:49:39 +09:30
GDB Administrator
69141f080c Automatic date update in version.in 2023-06-21 00:00:16 +00:00
Tom Tromey
00a8542877 Use ARRAY_SIZE in ax-general.c
This changes a couple of spots in ax-general.c to use ARRAY_SIZE.
While making this change, I noticed that one of the bounds checks was
incorrect.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
2023-06-20 11:21:51 -06:00
Tom Tromey
3ba0581955 Remove aop_last
aop_last is only used for an assertion.  However, due to the '.def'
construct in the sources, this assert could never plausibly trigger
(the assert predates the use of a .def file here).  This patch removes
the constant and the assert.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
2023-06-20 11:21:51 -06:00
Tom Tromey
1e0e3ecd67 Make aop_map 'static'
This changes aop_map to be 'static'.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
2023-06-20 11:21:51 -06:00
Tom Tromey
da25448d52 Use bool for agent_expr::tracing
This changese agent_expr::tracing to have type bool, allowing inline
initialization and cleaning up the code a little.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
2023-06-20 11:21:51 -06:00
Tom Tromey
b0b5ba6b7f Simplify agent_expr constructor
This simplifies the agent_expr constructor a bit, and removes the
destructor entirely.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
2023-06-20 11:21:51 -06:00
Tom Tromey
a2bbca9fa5 Use std::vector<bool> for agent_expr::reg_mask
agent_expr::reg_mask implements its own packed boolean vector.  This
patch replaces it with a std::vector<bool>, simplifying the code.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
2023-06-20 11:21:51 -06:00
Tom Tromey
6f96f4854f Use gdb::byte_vector in agent_expr
This changes agent_expr to use gdb::byte_vector rather than manually
reimplementing a vector.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
2023-06-20 11:00:19 -06:00
Tom Tromey
90db289d0d Remove mem2hex
tracepoint.c has a 'mem2hex' function that is functionally equivalent
to bin2hex.  This patch removes the redundancy.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
2023-06-20 11:00:19 -06:00
H.J. Lu
c7face1422 x86: Don't check if AVX512 template requires AVX512VL
If the ZMM operand in an AVX12 template also allows XMM or ZMM, this
template must require AVX512VL.  Drop the AVX512VL requirement check
on such AVX512 templates.

	* config/tc-i386.c (check_VecOperands): Don't check if AVX512
	template requires AVX512VL.
2023-06-20 09:43:58 -07:00
Tom Tromey
c65030964b Use std::string in do_set_command
do_set_command manually updates a string, only to copy it to a
std::string and free the working copy.  This patch changes this code
to use std::string for everything, simplifying the code and removing a
copy.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
2023-06-20 07:52:28 -06:00
Tom Tromey
6b19f38ae3 Use byte_vector in remote.c:readahead_cache
This patch changes the remote.c readahead_cache to use
gdb::byte_vector.  This simplifies the code by removing manual memory
management.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
2023-06-20 07:52:28 -06:00
Tom Tromey
b68e4ea64e Use std::string in linux-osdata.c
I found some code in linux-osdata that manually managed a string.
Replacing this with std::string simplifies it.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
2023-06-20 07:52:28 -06:00
Tom Tromey
8ca8b801ed Use unique_xmalloc_ptr for mi_parse::command
This changes mi_parse::command to be a unique_xmalloc_ptr and fixes up
all the uses.  This avoids some manual memory management.  std::string
is not used here due to how the Python API works -- this approach
avoids an extra copy there.

Reviewed-by: Keith Seitz <keiths@redhat.com>
2023-06-20 06:23:30 -06:00
Tom Tromey
550194db38 Use std::string for MI token
This changes the MI "token" to be a std::string, removing some manual
memory management.  It also makes current_token 'const' in order to
support this change.

Reviewed-by: Keith Seitz <keiths@redhat.com>
2023-06-20 06:23:30 -06:00
Alan Modra
75e73c6cad Don't segfault in mips reloc special_functions
A symbol defined in a section from a shared library will have a NULL
section->output_section during linking.

	* elf32-mips.c (gprel32_with_gp): Don't segfault on NULL
	symbol->section->output_section.
	* elf64-mips.c (mips_elf64_gprel32_reloc): Likewise.
	* elfn32-mips.c (mips_elf_gprel16_reloc): Likewise.
	(mips_elf_literal_reloc, mips_elf_gprel32_reloc): Likewise.
	(gprel32_with_gp, mips16_gprel_reloc): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_gprel16_with_gp): Likewise.
	(_bfd_mips_elf_generic_reloc): Likewise.
2023-06-20 10:01:50 +09:30
GDB Administrator
a89e364b45 Automatic date update in version.in 2023-06-20 00:00:13 +00:00
Tom de Vries
e11a2ebb8e Revert "[gdb/testsuite] Clean standard_output_file dir in gdb_init"
This reverts commit b7b77500dc.
2023-06-19 19:09:58 +02:00
Simon Farre
d32d7e918d Fixes 28ab59607e
Python formatting errors fixed, introduced by this commit.
2023-06-19 17:13:05 +02:00
Simon Farre
ce65796b17 Fixes f1a614dc8f
Fixes failure reported by buildbot regarding ill-formatted Python code.
2023-06-19 17:06:05 +02:00
Simon Farre
28ab59607e gdb/Python: Added ThreadExitedEvent
v6:
Fix comments.
Fix copyright
Remove unnecessary test suite stuff. save_var had to stay, as it mutates
some test suite state that otherwise fails.

v5:
Did what Tom Tromey requested in v4; which can be found here: https://pi.simark.ca/gdb-patches/87pmjm0xar.fsf@tromey.com/

v4:
Doc formatting fixed.

v3:
Eli:
Updated docs & NEWS to reflect new changes. Added
a reference from the .ptid attribute of the ThreadExitedEvent
to the ptid attribute of InferiorThread. To do this,
I've added an anchor to that attribute.

Tom:
Tom requested that I should probably just emit the thread object;
I ran into two issues for this, which I could not resolve in this patch;

1 - The Thread Object (the python type) checks it's own validity
by doing a comparison of it's `thread_info* thread` to nullptr. This
means that any access of it's attributes may (probably, since we are
in "async" land) throw Python exceptions because the thread has been
removed from the thread object. Therefore I've decided in v3 of this
patch to just emit most of the same fields that gdb.InferiorThread has, namely
global_num, name, num and ptid (the 3-attribute tuple provided by
gdb.InferiorThread.ptid).

2 - A python user can hold a global reference to an exiting thread. Thus
in order to have a ThreadExit event that can provide attribute access
reliably (both as a global reference, but also inside the thread exit
handler, as we can never guarantee that it's executed _before_ the
thread_info pointer is removed from the gdbpy thread object),
the `thread_info *` thread pointer must not be null. However, this
comes at the cost of gdb.InferiorThread believing it is "valid" - which means,
that if a user holds takes a global reference to that
exiting event thread object, they can some time later do `t.switch()` at which
point GDB will 'explode' so to speak.

v2:
Fixed white space issues and NULL/nullptr stuff,
as requested by Tom Tromey.

v1:
Currently no event is emitted for a thread exit.

This adds this functionality by emitting a new gdb.ThreadExitedEvent.

It currently provides four attributes:
- global_num: The GDB assigned global thread number
- num: the per-inferior thread number
- name: name of the thread or none if not set
- ptid: the PTID of the thread, a 3-attribute tuple, identical to
InferiorThread.ptid attribute

Added info to docs & the NEWS file as well.

Added test to test suite.

Fixed formatting.

Feedback wanted and appreciated.
2023-06-19 16:17:21 +02:00
Simon Farre
f1a614dc8f gdb/dap - Getting thread names
Renamed thread_name according to convention (_ first)

When testing firefox tests, it is apparent that
_get_threads returns threads with name field = None.

I had initially thought that this was due to Firefox setting the names
using /proc/pid/task/tid/comm, by writing directly to the proc fs the
names, but apparently GDB seems to catch this, because I re-wrote
the basic-dap.exp/c to do this specifically and it saw the changes.

So I couldn't determine right now, what operation of name change that
GDB does not pick up, but with this patch, GDB will pick up the thread
names for an applications that set the name of a thread in ways that
aren't obvious.
2023-06-19 16:08:45 +02:00
Nick Clifton
74d39f70cd Fix illegal memory access implementing relocs in a fuzzed x86_64 object file.
PR 30560
  * elf64-x86-64.c (elf_x86_64_relocate_section): Add more checks for a valid relocation offset.
2023-06-19 12:09:11 +01:00
Tom de Vries
319626ca73 [gdb/testsuite] Add shared_gnat_runtime_has_debug_info
Test-case gdb.ada/catch_ex_std.exp passes for me with package
libada7-debuginfo installed, but after removing it I get:
...
(gdb) catch exception some_kind_of_error^M
Your Ada runtime appears to be missing some debugging information.^M
Cannot insert Ada exception catchpoint in this configuration.^M
(gdb) FAIL: gdb.ada/catch_ex_std.exp: catch exception some_kind_of_error
...

The test-case contains a require gnat_runtime_has_debug_info to deal with
this, but the problem is that this checks the static gnat runtime, while this
test-case uses the shared one.

Fix this by introducing shared_gnat_runtime_has_debug_info, and requiring that
one instead.

Tested on x86_64-linux.

PR testsuite/30094
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30094
2023-06-19 11:47:29 +02:00
Tom de Vries
ba769bb0e6 [gdb/tui] Simplify tui_update_variables
Simplify tui_update_variables by using template function
assign_return_if_changed.

Tested on x86_64-linux.
2023-06-19 11:15:56 +02:00
Tom de Vries
2e12e79882 [gdb] Add template functions assign_return/set_if_changed
Add template functions assign_return_if_changed and assign_set_if_changed in
gdb/utils.h:
...
template<typename T> void assign_set_if_changed (T &lval, const T &val, bool &changed)
{ ... }
template<typename T> bool assign_return_if_changed (T &lval, const T &val)
{ ... }
...

This allows us to rewrite code like this:
...
  if (tui_border_attrs != entry->value)
    {
      tui_border_attrs = entry->value;
      need_redraw = true;
    }
...
into this:
...
  need_redraw |= assign_return_if_changed<int> (tui_border_attrs, entry->value);
...
or:
...
  assign_set_if_changed<int> (tui_border_attrs, entry->value, need_redraw);
...

The names are a composition of the functionality.  The functions:
- assign VAL to LVAL, and either
- return true if the assignment changed LVAL, or
- set CHANGED to true if the assignment changed LVAL.

Tested on x86_64-linux.
2023-06-19 11:15:56 +02:00