Commit Graph

118900 Commits

Author SHA1 Message Date
Tom Tromey
a2f972b330 Add symbol, line, and location to DAP disassemble result
The DAP spec allows a number of attributes on the resulting
instructions that gdb currently does not emit.  A user requested some
of these, so this patch adds the 'symbol', 'line', and 'location'
attributes.  While the spec lets the implementation omit 'location' in
some cases, it was simpler in the code to just always emit it, as then
no extra tracking was needed.
2024-05-10 12:09:32 -06:00
Tom Tromey
400d4e3290 Implement tp_richcompare for gdb.Block
I noticed that two gdb.Block objects will never compare as equal with
'=='.  This patch fixes the problem by implementing tp_richcompare, as
was done for gdb.Frame.
2024-05-10 12:09:32 -06:00
Tom Tromey
4b09134a09 Simplify DAP make_source callers
A couple callers of make_source call basename by hand.  Rather than
add another caller like this, I thought it would be better to put this
ability into make_source itself.
2024-05-10 12:09:32 -06:00
Tom Tromey
674dea05e3 Remove FIXME from DAP
This patch removes one of the few DAP "FIXME" comments.  This
particular comment is already covered by PR dap/31036.
2024-05-10 12:08:27 -06:00
Tom Tromey
c610012988 Pass stream to remote_console_output
I noticed that remote_target::rcmd did not pass its ui_file argument
down to remote_console_output.  This patch fixes this oversight.

Tested-By: Ciaran Woodward <ciaranwoodward@xmos.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-05-10 11:24:47 -06:00
Nick Clifton
6e8376fa56 Add --section-ordering command line option to the bfd linker. 2024-05-10 16:59:05 +01:00
Alan Modra
ad658482c1 Re: PR31692, objdump fails .debug_info size check
The fuzzers found a hole.  bfd_section_size_insane doesn't check
!SEC_HAS_CONTENTS sections against file size for obvious reasons,
which allows fuzzed debug sections to be stupidly large.  Real debug
sections of course always have contents.

	PR 31692
	* objdump.c (load_specific_debug_section): Don't allow sections
	without contents.
2024-05-10 23:17:03 +09:30
Andrew Burgess
a4f76c0765 gdb: add gdbarch_stack_grows_down function
In another patch I'm working on I needed to ask: does the stack grow
down, or grow up?

Looking around I found in infcall.c some code where we needed to ask
the same question, what we do there is ask:

  gdbarch_inner_than (gdbarch, 1, 2)

which should do the job.  However, I don't particularly like copying
this, it feels like we're asking something slightly different that
just happens to align with the question we're actually asking.

I propose adding a new function `gdbarch_stack_grows_down`.  This is
not going to be a gdbarch method that can be overridden, instead, this
will just call the gdbarch_inner_than function.  We already have some
gdbarch methods like this, checkout arch-utils.c for examples.

I think it's now clearer what we're actually doing.

A new self-test ensures that all architectures have a stack that
either grows down, or grows up.

There should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
2024-05-10 14:21:21 +01:00
Nick Clifton
2b34e06765 Add missing \n to the end of warning messages in dwarf.c.
PR 31722
2024-05-10 13:23:41 +01:00
Pedro Alves
78b2db9e7f gdb sim testing, set gdb_protocol to "sim"
Bernd reported that when testing with riscv-unknown-elf target using
the simulator, before commit c7a2ee6491 ("gdb_is_target_native ->
gdb_protocol_is_native"), he had:

 PASS: gdb.base/load-command.exp: probe for target native
 PASS: gdb.base/load-command.exp: check initial value of the_variable
 PASS: gdb.base/load-command.exp: manually change the_variable
 PASS: gdb.base/load-command.exp: check manually changed value of the_variable
 PASS: gdb.base/load-command.exp: reload: re-load binary
 PASS: gdb.base/load-command.exp: reload: check initial value of the_variable

and now:

 UNSUPPORTED: gdb.base/load-command.exp: the native target does not support the load command

The problem is that the sim board/config isn't setting gdb_protocol
anywhere, so gdb_protocol_is_native returns true.

This commit fixes it by making gdb/testsuite/config/sim.exp set
gdb_protocol to "sim".

Reported-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Tested-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Change-Id: I48a7afed004a3517b90220674fe5bc856fe7d09a
2024-05-10 11:48:57 +01:00
Tom de Vries
408bc9c5fc [gdb/python] Make gdb.UnwindInfo.add_saved_register more robust (fixup)
In commit 2236c5e384 ("[gdb/python] Make gdb.UnwindInfo.add_saved_register
more robust") I added this code in unwind_infopy_add_saved_register:
...
  if (value->optimized_out () || !value->entirely_available ())
...
which may throw c++ exceptions.

This needs to be caught and transformed into a python exception.

Fix this by using GDB_PY_HANDLE_EXCEPTION.

Tested on x86_64-linux.

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

Fixes: 2236c5e384 ("[gdb/python] Make gdb.UnwindInfo.add_saved_register more robust")
2024-05-10 08:46:21 +02:00
GDB Administrator
65924bda46 Automatic date update in version.in 2024-05-10 00:00:16 +00:00
Bernd Edlinger
b75187cd94 sim: riscv: Fix build issue due to recent binutils commit
The commit c144f63833 removed INSN_CLASS_A and
added INSN_CLASS_ZAAMO and INSN_CLASS_ZALRSC instead,
which broke the build of the sim for riscv targets.

Fix that by using the new INSN_CLASS types.

Fixes: c144f63833 ("RISC-V: Support B, Zaamo and Zalrsc extensions.")

Approved-By: Tom Tromey <tom@tromey.com>
2024-05-09 17:04:14 +02:00
Eli Zaretskii
5021daf303 Fix typo in gdb/README.
Patch from Tiezhu Yang <yangtiezhu@loongson.cn>.
2024-05-09 12:47:28 +03:00
Andrew Burgess
cba95c2787 gdb: convert address_in_mem_range to mem_range::contains
Replace the global function address_in_mem_range with the member
function mem_range::contains.  The implementation of the function
doesn't change.

There should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
2024-05-09 10:10:50 +01:00
Andrew Burgess
cb1a6b85b8 gdb: add a new build_id_equal function
Add two versions of a new function build_id_equal which can be used to
compare build-ids, then make use of these functions in GDB.  It seems
better to have a specific function for the task of comparing build-ids
rather than having a length check followed by a memcmp call.

There should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
2024-05-09 10:09:28 +01:00
Vladimir Mezentsev
e5b12a313f Fix hard-coded bash path in gprofng
When running 'make check', the default gprofng test suite creates a
shell script for which it used a hardcoded shebang of '/usr/bin/bash'
this script would not run if bash is in a different location, like
/bin/bash

This commit adds 'AC_PATH_PROG(BASH, bash)' to configure.ac so the
installation path of bash is detected at configuration time. The
configuration is propagated to the runtest command line where it is
needed.
2024-05-08 22:18:24 -07:00
GDB Administrator
46b6ba96d0 Automatic date update in version.in 2024-05-09 00:00:16 +00:00
Andrew Burgess
824083f34c gdb/doc: use silent-rules.mk in the Makefile
Make use of silent-rules.mk when building the GDB docs.

During review it was requested that there be more specific rules than
just reusing the general 'GEN' rule everywhere in the doc/ directory,
so I've added:

  ECHO_DVIPS =    @echo "  DVIPS    $@";
  ECHO_TEX =      @echo "  TEX      $@";
  ECHO_PDFTEX =   @echo "  PDFTEX   $@";
  ECHO_TEXI2DVI = @echo "  TEXI2DVI $@";
  ECHO_MAKEHTML = @echo "  MAKEHTML $@";
  ECHO_TEXI2POD = @echo "  TEXI2POD $@";
  ECHO_TEXI2MAN = @echo "  TEXI2MAN $@";
  ECHO_MAKEINFO = @echo "  MAKEINFO $@";

Then I've made use of these new silent rules and added lots of uses of
SILENT to reduce additional clutter.

As the man page generation is done in two phases, first the creation
of a .pod file, then the creation of the final man page file, I've
restructured the man page rules.  Previously we had one rule for each
of the 5 man pages.  I now have one general rule that will generate
all of the 5 .pod files, then I have two rules that convert the .pod
files into the final man pages.

I needed two rules for the man page generation as some man pages match
%.1 and some match %.5.  I could combine these by using the GNU Make
.SECONDARYEXPANSION extension, but I think having two rules like this
is probably clearer, and the duplication is minimal.

Cleaning up the temporary .pod files is now moved into the
'mostlyclean' target rather than being done as soon as the man page is
created.

I've added a new SILENT_Q_FLAG to silent-rules.mk, this is like
SILENT_FLAG, but is set to '-q' when in silent mode, this can be used
with the 'dvips' and 'texi2dvi' commands, both of which use '-q' to
mean: only report errors.

As with the rest of the GDB makefiles, I've only converted the
"generation" rules to use silent-rules.mk, the install / uninstall
rules are left unchanged.

When looking at the 'diststuff' target, which generates the info and
man pages, I noticed the recipe for this rule just deleted a temporary
file.  As that temporary file is already cleaned up as part of the
'clean' rule I've removed the deletion from the 'diststuff' target.

There are still a few "generation" targets that produce output, there
seems to be no flag to silence the 'tex' and 'pdftex' commands which
some recipes use, I've not worried about these for now, e.g. the
refcard.dvi and refcard.pdf targets still produce some output.

Luckily, when doing a 'make all' in the gdb/ directory, we only build
the info docs by default, and those rules are now nice and silent, so
a complete GDB build is now looking nice and quiet by default.

While working on this patch I noticed that 'make -j all-doc' doesn't
work (reliably), this is a preexisting bug in the way that dvi/pdf
targets are generated.  For example gdb.dvi and gdb.pdf both use the
texi2dvi tool, which relies on temporary files to hold state.  If both
these rules run in parallel then one (or both) of the recipes will
fail.

Luckily, the default docs target (all), which is what gets run when we
do 'make all' in the gdb/ directory, doesn't build the dvi and pdf
targets, so we're OK in that case.

I've not tried to fix this problem in this commit as it already
existed, and I don't want to do too much in one commit.  I mention it
only because I ran into this issue while testing this commit.
2024-05-08 18:44:03 +01:00
Guinevere Larsen
e61c7092f7 gdb: Change "list ." command's error when no debuginfo is available
Currently, when a user tries to list the current location, there are 2
different error messages that can happen, either:

    (gdb) list .
    No symbol table is loaded.  Use the "file" command.
or
    (gdb) list .
    No debug information available to print source lines.

The difference here is if gdb can find any symtabs at all or not, which
is not something too important for end-users - and isn't informative at
all. This commit changes it so that the error always says that there
isn't debug information available, with these two variants:

    (gdb) list .
    Insufficient debug info for showing source lines at current PC (0x55555555511d).
or
    (gdb) list .
    Insufficient debug info for showing source lines at default location.

The difference now is if the inferior has started already, which is
controlled by the user and may be useful.

Unfortunately, it isn't as easy to differentiate if the symtab found for
other list parameters is correct, so other invocations, such as "list +"
still retain their original error message.

Co-Authored-By: Simon Marchi <simark@simark.ca>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-05-08 14:08:16 -03:00
Andrew Burgess
189d3013ee gdb: more filename styling
I spotted a few places in solib.c and build-id.c where we could apply
file name styling.

Other than the extra styling, there should be no user visible changes
after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
2024-05-08 17:49:04 +01:00
Tom de Vries
0fd705062e [gdb/testsuite] Add gdb.tui/reread.exp
Add a regression test for commit d68f983f88 ("Fix heap-use-after-free because
all_objfiles_removed triggers tui_display_main").

When building with address sanitizer, and reverting the commit it triggers the
heap-use-after-free.

Tested on aarch64-linux.

PR symtab/31697
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31697
2024-05-08 17:02:15 +02:00
Aditya Vidyadhar Kamath
c70ccf9248 Fix AIX thread exit events not being reported and UI to show kernel thread ID.
In AIX when a thread exits we were not showing that a thread exit event happened
and GDB continued to keep the terminated threads.

If we have terminated threads then the UI on info threads command will look like
(gdb) info threads
  Id   Target Id                                          Frame
* 1    Thread 1 (tid 26607979, running)    0xd0611d70 in _p_nsleep () from /usr/lib/libpthreads.a(_shr_xpg5.o)
  2    Thread 258 (tid 30998799, finished) aix-thread: ptrace (52, 30998799) returned -1 (errno = 3 The process does not exist.)

If we see the frame is not getting displayed correctly.

The reason for the same is that in AIX we were not managing thread states. In particular we do not know
when a thread terminates.

The reason being in sync_threadlists () the pbuf and gbuf lists remain the same though certain threads exit.

This patch is a fix to the same.

Also certain UI is changed.

On a new thread born and exit the UI in AIX will be similar to Linux with both user and kernel thread information.

[New Thread 258 (tid 32178533)]
[New Thread 515 (tid 30343651)]
[New Thread 772 (tid 33554909)]
[New Thread 1029 (tid 24969489)]
[New Thread 1286 (tid 18153945)]
[New Thread 1543 (tid 30736739)]
[Thread 258 (tid 32178533) exited]
[Thread 515 (tid 30343651) exited]
[Thread 772 (tid 33554909) exited]
[Thread 1029 (tid 24969489) exited]
[Thread 1286 (tid 18153945) exited]
[Thread 1543 (tid 30736739) exited]

and info threads will look like
(gdb) info threads
  Id   Target Id                           Frame
* 1    Thread 1 (tid 31326579) ([running]) 0xd0611d70 in _p_nsleep () from /usr/lib/libpthread.a(_shr_xpg5.o)

Also a small change to testcase gdb.threads/thread_events.exp to make sure this test runs on AIX as well.
2024-05-08 16:53:03 +02:00
Tom Tromey
573b697e9d Fix typo in binutils manual
I happened to notice that the binutils manual has a typo in the name
of a command-line option.
2024-05-08 08:38:05 -06:00
H.J. Lu
1509f0c231 ld: Add PR ld/31710 tests
PR ld/31710
	* testsuite/ld-elf/wrap.exp: Run ld/31710 tests.
	* testsuite/ld-elf/wrap2.h: New file.
	* testsuite/ld-elf/wrap2a.c: Likewise.
	* testsuite/ld-elf/wrap2b.c: Likewise.
2024-05-08 07:01:24 -07:00
H.J. Lu
1dfd6a2f93 ld: Run --wrap tests only if supported
Run --wrap tests with shared library only if -shared is supported.

	* testsuite/ld-elf/wrap.exp: Run --wrap tests with shared library
	only if -shared is supported.
2024-05-08 07:00:49 -07:00
Nick Clifton
43bb6c0e08 Fix RELOC_FOR_GLOBAL_SYMBOLS macro so that it can cope with user defined symbols that start with __wrap_.
PR 31710
2024-05-08 13:42:22 +01:00
Tom de Vries
2236c5e384 [gdb/python] Make gdb.UnwindInfo.add_saved_register more robust
On arm-linux, until commit bbb12eb9c8 ("gdb/arm: Remove tpidruro register
from non-FreeBSD target descriptions") I ran into:
...
FAIL: gdb.base/inline-frame-cycle-unwind.exp: cycle at level 5: \
  backtrace when the unwind is broken at frame 5
...

What happens is the following:
- the TestUnwinder from inline-frame-cycle-unwind.py calls
  gdb.UnwindInfo.add_saved_register with reg == tpidruro and value
  "<unavailable>",
- pyuw_sniffer calls value->contents ().data () to access the value of the
  register, which throws an UNAVAILABLE_ERROR,
- this causes the TestUnwinder unwinder to fail, after which another unwinder
  succeeds and returns the correct frame, and
- the test-case fails because it's counting on the TestUnwinder to succeed and
  return an incorrect frame.

Fix this by checking for !value::entirely_available as well as
valued::optimized_out in unwind_infopy_add_saved_register.

Tested on x86_64-linux and arm-linux.

Approved-By: Andrew Burgess <aburgess@redhat.com>

PR python/31437
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31437
2024-05-08 14:13:11 +02:00
Nelson Chu
c144f63833 RISC-V: Support B, Zaamo and Zalrsc extensions.
* https://github.com/riscv/riscv-b/tags
Added standard B extension back, which implies Zba, Zbb and Zbs extensions.

* https://github.com/riscv/riscv-zaamo-zalrsc/tags
Splited standard A extension into two new extensions, Zaamo and Zalrsc.
The A extension implies Zaamo and Zalrsc extensions.

Not sure if we need to do the similar check as i and zicsr/zifencei.

Passed riscv[32|64]-[elf/linux] binutils testcases.

bfd/
	* elfxx-riscv.c (riscv_implicit_subsets): Added imply rules
	for A and B extensions.  The A implies Zaamo and Zalrsc, the
	B implies Zba, Zbb and Zbs.
	(riscv_supported_std_ext): Supported B extension with v1.0.
	(riscv_supported_std_z_ext): Supported Zaamo and Zalrsc with v1.0.
	(riscv_multi_subset_supports, riscv_multi_subset_supports_ext): Updated.
include/
	* opcode/riscv.h (riscv_insn_class): Removed INSN_CLASS_A, Added
	INSN_CLASS_ZAAMO and INSN_CLASS_ZALRSC.
opcodes/
	* riscv-opc.c (riscv_opcodes): Splited standard A extension into two
	new extensions, Zaamo and Zalrsc.
gas/
	* testsuite/gas/riscv/march-imply-a.d: New testcase.
	* testsuite/gas/riscv/march-imply-b.d: New testcase.
	* testsuite/gas/riscv/attribute-01.d: Updated.
	* testsuite/gas/riscv/attribute-02.d: Updated.
	* testsuite/gas/riscv/attribute-03.d: Updated.
	* testsuite/gas/riscv/attribute-04.d: Updated.
	* testsuite/gas/riscv/attribute-05.d: Updated.
	* testsuite/gas/riscv/attribute-10.d: Updated.
	* testsuite/gas/riscv/mapping-symbols.d: Updated.
	* testsuite/gas/riscv/march-imply-g.d: Updated.
	* testsuite/gas/riscv/march-imply-unsupported.d: Updated.
	* testsuite/gas/riscv/march-ok-reorder.d: Updated.
ld/
	* testsuite/ld-riscv-elf/attr-merge-arch-01.d: Updated.
	* testsuite/ld-riscv-elf/attr-merge-arch-02.d: Updated.
	* testsuite/ld-riscv-elf/attr-merge-arch-03.d: Updated.
	* testsuite/ld-riscv-elf/attr-merge-user-ext-01.d: Updated.
2024-05-08 12:34:58 +08:00
GDB Administrator
f0dbbf5401 Automatic date update in version.in 2024-05-08 00:00:17 +00:00
Hannes Domani
d68f983f88 Fix heap-use-after-free because all_objfiles_removed triggers tui_display_main
Since gdb-10 there is a heap-use-after free happening if starting the
target in TUI triggers a re-reading of symbols.

It can be reproduced with:

$ gdb -q -batch a.out -ex "tui enable" -ex "shell touch a.out" -ex start

==28392== Invalid read of size 1
==28392==    at 0x79E97E: lookup_global_or_static_symbol(char const*, block_enum, objfile*, domain_enum) (symtab.h:503)
==28392==    by 0x79F859: lookup_global_symbol(char const*, block const*, domain_enum) (symtab.c:2641)
==28392==    by 0x79F8E9: language_defn::lookup_symbol_nonlocal(char const*, block const*, domain_enum) const (symtab.c:2473)
==28392==    by 0x7A66EE: lookup_symbol_aux(char const*, symbol_name_match_type, block const*, domain_enum, language, field_of_this_result*) (symtab.c:2150)
==28392==    by 0x7A68C9: lookup_symbol_in_language(char const*, block const*, domain_enum, language, field_of_this_result*) (symtab.c:1958)
==28392==    by 0x7A6A25: lookup_symbol(char const*, block const*, domain_enum, field_of_this_result*) (symtab.c:1970)
==28392==    by 0x77120F: select_source_symtab() (source.c:319)
==28392==    by 0x7EE2D5: tui_get_begin_asm_address(gdbarch**, unsigned long*) (tui-disasm.c:401)
==28392==    by 0x807558: tui_display_main() (tui-winsource.c:55)
==28392==    by 0x7937B5: clear_symtab_users(enum_flags<symfile_add_flag>) (functional:2464)
==28392==    by 0x794F40: reread_symbols(int) (symfile.c:2690)
==28392==    by 0x6497D1: run_command_1(char const*, int, run_how) (infcmd.c:398)
==28392==  Address 0x4e67848 is 3,864 bytes inside a block of size 4,064 free'd
==28392==    at 0x4A0A430: free (vg_replace_malloc.c:446)
==28392==    by 0x936B63: _obstack_free (obstack.c:280)
==28392==    by 0x79541E: reread_symbols(int) (symfile.c:2579)
==28392==    by 0x6497D1: run_command_1(char const*, int, run_how) (infcmd.c:398)
==28392==    by 0x4FFC45: cmd_func(cmd_list_element*, char const*, int) (cli-decode.c:2735)
==28392==    by 0x7DAB50: execute_command(char const*, int) (top.c:575)
==28392==    by 0x5D2B43: command_handler(char const*) (event-top.c:552)
==28392==    by 0x5D3A50: command_line_handler(std::unique_ptr<char, gdb::xfree_deleter<char> >&&) (event-top.c:788)
==28392==    by 0x5D1F4B: gdb_rl_callback_handler(char*) (event-top.c:259)
==28392==    by 0x857B3F: rl_callback_read_char (callback.c:290)
==28392==    by 0x5D215D: gdb_rl_callback_read_char_wrapper_noexcept() (event-top.c:195)
==28392==    by 0x5D232F: gdb_rl_callback_read_char_wrapper(void*) (event-top.c:234)

The problem is that tui_display_main is called by the all_objfiles_removed
hook, which tries to access the symbol cache.
This symbol cache is actually stale at this point, and would have been
flushed immediately afterwards by that same all_objfiles_removed hook.

It's not possible to tell the hook to call the observers in a specific
order, but in this case the tui_all_objfiles_removed observer is actually
not needed, since it only calls tui_display_main, and a 'main' can only
be found if objfiles are added, not removed.

So the fix is to simply remove the tui_all_objfiles_removed observer.

The clearing of the source window (if symbols were removed by e.g. 'file'
without arguments) still works, since this is done by the
tui_before_prompt observer.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31697
Approved-By: Tom Tromey <tom@tromey.com>
2024-05-07 19:29:29 +02:00
Andrew Burgess
868883583e gdb/arch: assert that X86_XSTATE_MPX is not set for x32
While rebasing this series[1] past this commit:

  commit 4bb20a6244
  Date:   Wed Mar 20 04:13:18 2024 -0700

      gdbserver: Clear X86_XSTATE_MPX bits in xcr0 on x32

I worried that there could be other paths that might result in an xcr0
value which has X86_XSTATE_MPX set in x32 mode.  As everyone
eventually calls amd64_create_target_description to build their target
description, I figured we could assert in here that if X86_XSTATE_MPX
is set then we should not be an x32 target, this will uncover any
other bugs in this area.

I'm not currently able to build/run any x32 binaries, so I have no way
to test this, but the author of commit 4bb20a6244 did test this
series with that assert in place and didn't see any problems.

[1] https://inbox.sourceware.org/gdb-patches/cover.1714143669.git.aburgess@redhat.com

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31511

Approved-By: Felix Willgerodt <felix.willgerodt@intel.com>
2024-05-07 17:05:10 +01:00
Andrew Burgess
0c58b372e0 gdbserver: convert have_ptrace_getregset to a tribool
Convert the have_ptrace_getregset global within gdbserver to a
tribool.  This brings the flag into alignment with the corresponding
flag in GDB.

The gdbserver have_ptrace_getregset variable is already used as a
tribool, it just doesn't have the tribool type.

In a future commit I plan to share more code between GDB and
gdbserver, and having this variable be the same type in both code
bases will make the sharing much easier.

There should be no user visible changes after this commit.

Approved-By: John Baldwin <jhb@FreeBSD.org>
Reviewed-By: Felix Willgerodt <felix.willgerodt@intel.com>
2024-05-07 16:26:43 +01:00
Andrew Burgess
3f1438a5b2 gdbserver/ipa/x86: remove unneeded declarations
Spotted some declarations in gdbserver/linux-amd64-ipa.cc that are no
longer needed.  These are:

  1. 'init_registers_amd64_linux' - the comment claims this function
  is auto generated, but I don't believe that this is still the case.
  Also the function is not used in this file,

  2. 'tdesc_amd64_linux' - this variable doesn't seem to exist any
  more, I suspect this was renamed to 'tdesc_amd64_linux_no_xml', but
  neither are used in this file, so lets remove the declaration.

The amd64 in-process-agent still builds fine after this commit.

There should be no user visible changes after this commit.

Approved-By: Felix Willgerodt <felix.willgerodt@intel.com>
2024-05-07 16:04:20 +01:00
Pedro Alves
810203888d gdb.base/watchpoint-running.exp: Run sw watch tests even if no hw watch
The code in gdb.base/watchpoint-running.exp that is trying to skip
testing with hardware watchpoints also skips testing with software
watchpoints if hardware watchpoints aren't supported by the target.
This fixes it.

Change-Id: Iaed62ac827b32b4fd73b732ad81fa4a5aa5784ba
2024-05-07 13:10:21 +01:00
Pedro Alves
1d2db4525c Remove gdb.base/watchpoint-running.exp leftover
Remove accidentally leftover commented-out line from
gdb.base/watchpoint-running.exp.

Change-Id: Ie1c3b85997d2ca92a2159a539d24b02fd3c9e697
2024-05-07 13:10:21 +01:00
Lancelot SIX
20100e09dd gdb/testsuite/lib/rocm: Fix with_rocm_gpu_lock
A recent commit refactored with_rocm_gpu_lock:

    commit fbb0edfe60
    Date:   Sat May 4 10:41:09 2024 +0200

        [gdb/testsuite] Factor out proc with_lock

        Factor out proc with_lock from with_rocm_gpu_lock, and move required procs
        lock_file_acquire and lock_file_release to lib/gdb-utils.exp.

This causes regressions in gdb.rocm/*.exp (as well as in downstream
rocgdb).  The issue can be reproduced in the following minimal test:

    load_lib rocm.exp
    set foo hello
    with_rocm_gpu_lock {
        verbose -logs $foo
    }

The issue is that the body to execute under the lock is executed in the
context of with_rocm_gpu_lock (uplevel 1 used in with_lock) instead of
in the context of the "original" caller.

This patch adjusted with_rocm_gpu_lock to account for the new extra
frame in the call stack between the caller of with_rocm_gpu_lock and
where the code execution is triggered.

Approved-By: Tom de Vries <tdevries@suse.de>

Change-Id: I79ce2c9615012215867ed5bb60144abe7dce28fe
2024-05-07 10:33:45 +01:00
Lulu Cai
d264d04ac4 LoongArch: Fix ld test failures caused by using instruction aliases
Different versions of objdump may take different forms of output
for instructions. Use -M no-aliases to avoid the failure of ld
test cases caused by objdump using aliases.
2024-05-07 16:38:25 +08:00
GDB Administrator
cdf5362f56 Automatic date update in version.in 2024-05-07 00:00:21 +00:00
Bernd Edlinger
45e83f8658 Fix build issues with mingw toolchain
With a x86_64-pc-mingw32 toolchain there is a build issue
whether or not the --disable-threading option is used.
The problem happens because _WIN32_WINNT is defined to 0x501
before #include <mutex> which makes the compilation abort
due to missing support for __gthread_cond_t in std_mutex.h,
which is conditional on _WIN32_WINNT >= 0x600.

Fix the case when --disable-threading is used, by only
including <mutex> in gdb/complaints.c when STD_CXX_THREAD
is defined.

Additionally make the configure script try to #include <mutex>
to automatically select --disable-threading when the header file
is not able to compile.

Approved-By: Tom Tromey <tom@tromey.com>
2024-05-06 18:44:54 +02:00
Tom de Vries
147fe7f9fb [gdb/testsuite] Handle ptrace operation not permitted in can_spawn_for_attach
When running the testsuite on a system with kernel.yama.ptrace_scope set to 1,
we run into attach failures.

Fix this by recognizing "ptrace: Operation not permitted" in
can_spawn_for_attach.

Tested on aarch64-linux and x86_64-linux.

Approved-By: Pedro Alves <pedro@palves.net>
2024-05-06 14:27:09 +02:00
Tom de Vries
5edbb6ed92 [gdb/exp] Redo cast handling for indirection
In commit ed8fd0a342 ("[gdb/exp] Fix cast handling for indirection"), I
introduced the behaviour that even though we have:
...
(gdb) p *a_loc ()
'a_loc' has unknown return type; cast the call to its declared return type
...
we get:
...
(gdb) p (char)*a_loc ()
$1 = 97 'a'
...

In other words, the unknown return type of a_loc is inferred from the cast,
effectually evaluating:
...
(gdb) p (char)*(char *)a_loc ()
...

This is convient for the case that errno is defined as:
...
 #define errno (*__errno_location ())
...
and the return type of __errno_location is unknown but the macro definition is
known, such that we can use:
...
(gdb) p (int)errno
...
instead of
...
(gdb) p *(int *)__errno_location ()
...

However, as Pedro has pointed out in post-commit review [1], this makes it
harder to reason about the semantics of an expression.

For instance, this:
...
(gdb) p (long long)*a_loc ()"
...
would be evaluated without debug info as:
...
(gdb) p (long long)*(long long *)a_loc ()"
...
but with debug info as:
...
(gdb) p (long long)*(char *)a_loc ()"
...

Fix this by instead simply erroring out for this case:
...
(gdb) p (char)*a_loc ()
'a_loc' has unknown return type; cast the call to its declared return type
...

Tested on x86_64-linux.

Approved-By: Pedro Alves <pedro@palves.net>

[1] https://sourceware.org/pipermail/gdb-patches/2024-May/208821.html
2024-05-06 14:23:25 +02:00
Cui, Lili
c8866e3ec5 x86: Drop using extension_opcode to encode vvvv register
gas/ChangeLog:

        * config/tc-i386.c (build_modrm_byte): Dropped the use of
        extension_opcode to encode the vvvv register.
        * testsuite/gas/i386/x86-64-sse2avx.d: Added new testcases.
        * testsuite/gas/i386/x86-64-sse2avx.s: Diito.

opcodes/ChangeLog:

        * i386-opc.tbl: Added DstVVVV to some extension_opcode instructions.
	* i386-tbl.h: Regenerated.
2024-05-06 18:33:45 +08:00
Cui, Lili
0820c9f5fc x86: Drop SwapSources
gas/ChangeLog:

        * config/tc-i386.c (build_modrm_byte): Dropped the use of
	SWAP_SOURCES to encode the vvvv register.

opcodes/ChangeLog:

        * i386-opc.h (SWAP_SOURCES): Dropped.
        (NO_DEFAULT_MASK): Adjusted the value.
        (ADDR_PREFIX_OP_REG): Ditto.
        (DISTINCT_DEST): Ditto.
        (IMPLICIT_STACK_OP): Ditto.
        (VexVVVV_SRC2): New.
        * i386-opc.tbl: Dropped SwapSources and replaced its VexVVVV
	with Src1VVVV.
	* i386-tbl.h: Regenerated.
2024-05-06 18:21:28 +08:00
Cui, Lili
f2a3a8814d x86: Use vexvvvv as the switch state to encode the vvvv register
Use vexvvvv as the switch state, and replace VexVVVV with Src1VVVV.
Src1VVVV means using VEX.vvvv encodes the first source register
operand. The old logic did not check vexvvvv first, which made the
logic here very complicated.

gas/ChangeLog:

        * config/tc-i386.c (optimize_encoding): Replaced 1 with Src1VVVV.
        (build_modrm_byte): Used vexvvvv to encode the vvvv register.
        (s_insn): Replaced 1 with Src1VVVV.

opcodes/ChangeLog:

        * i386-opc.h (VexVVVV_DST): Adjusted the value.
        (Src1VVVV): New.
        * i386-opc.tbl: Replaced part VexVVVV with Src1VVVV.
	* i386-tbl.h: Regenerated.
2024-05-06 18:16:42 +08:00
GDB Administrator
f4c1c984bf Automatic date update in version.in 2024-05-06 00:00:15 +00:00
GDB Administrator
bf79d8caea Automatic date update in version.in 2024-05-05 00:00:13 +00:00
Hannes Domani
5140d8e013 Fix heap-use-after-free in index-cached with --disable-threading
If threads are disabled, either by --disable-threading explicitely, or by
missing std::thread support, you get the following ASAN error when
loading symbols:

==7310==ERROR: AddressSanitizer: heap-use-after-free on address 0x614000002128 at pc 0x00000098794a bp 0x7ffe37e6af70 sp 0x7ffe37e6af68
READ of size 1 at 0x614000002128 thread T0
    #0 0x987949 in index_cache_store_context::store() const ../../gdb/dwarf2/index-cache.c:163
    #1 0x943467 in cooked_index_worker::write_to_cache(cooked_index const*, deferred_warnings*) const ../../gdb/dwarf2/cooked-index.c:601
    #2 0x1705e39 in std::function<void ()>::operator()() const /gcc/9/include/c++/9.2.0/bits/std_function.h:690
    #3 0x1705e39 in gdb::task_group::impl::~impl() ../../gdbsupport/task-group.cc:38

0x614000002128 is located 232 bytes inside of 408-byte region [0x614000002040,0x6140000021d8)
freed by thread T0 here:
    #0 0x7fd75ccf8ea5 in operator delete(void*, unsigned long) ../../.././libsanitizer/asan/asan_new_delete.cc:177
    #1 0x9462e5 in cooked_index::index_for_writing() ../../gdb/dwarf2/cooked-index.h:689
    #2 0x9462e5 in operator() ../../gdb/dwarf2/cooked-index.c:657
    #3 0x9462e5 in _M_invoke /gcc/9/include/c++/9.2.0/bits/std_function.h:300

It's happening because cooked_index_worker::wait always returns true in
this case, which tells cooked_index::wait it can delete the m_state
cooked_index_worker member, but cooked_index_worker::write_to_cache tries
to access it immediately afterwards.

Fixed by making cooked_index_worker::wait only return true if desired_state
is CACHE_DONE, same as if threading was enabled, so m_state will not be
prematurely deleted.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31694
Approved-By: Tom Tromey <tom@tromey.com>
2024-05-04 18:55:20 +02:00
Tom Tromey
b42d685452 Remove dwarf2_per_objfile::adjust
All the calls to dwarf2_per_objfile::adjust have been removed, so we
can remove this function entirely.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31261
2024-05-04 09:30:31 -06:00
Tom Tromey
12fddc10c3 Remove call to dwarf2_per_objfile::adjust from read_attribute_value
Currently, read_attribute_value calls dwarf2_per_objfile::adjust on
any address.  This seems wrong, because the address may not even be in
the text section.

Luckily, this call is also not needed, because read_func_scope calls
'relocate', which does the same work.
2024-05-04 09:30:30 -06:00