Lancelot SIX [Thu, 14 Apr 2022 09:41:48 +0000 (10:41 +0100)]
gdb/testsuite: Introduce and use gdb_spawn_attach_cmdline
Following a7e6a19e87f3d719ea23c65b580a6d9bca4ccab3 "gdb: testsuite: add
new gdb_attach to check "attach" command", this commit proposes to
introduce the gdb_spawn_attach_cmdline helper and use it in
gdb.base/attach.exp.
This helper starts GDB and adds the "--pid=$PID" argument.
Also note that both the original and new implementation use
gdb_spawn_with_cmdline_opts, which in the end uses default_gdb_spawn.
This makes sure that we use $INTERNAL_GDBFLAGS, which by default already
contain "-iex \"set height 0\" -iex \"set width 0\"". To avoid
repetition of those arguments, gdb_spawn_attach_cmdline does not repeat
those arguments.
To maintain a behavior similat to what gdb.base/attach.exp used to do,
gdb_spawn_attach_cmdline keeps the -quiet flag.
Tom Tromey [Tue, 23 Nov 2021 00:05:55 +0000 (17:05 -0700)]
Unify the DWARF index holders
The dwarf2_per_bfd object has a separate field for each possible kind
of index. Until an earlier patch in this series, two of these were
even derived from a common base class, but still had separate slots.
This patch unifies all the index fields using the common base class
that was introduced earlier in this series. This makes it more
obvious that only a single index can be active at a time, and also
removes some code from dwarf2_initialize_objfile.
Tom Tromey [Mon, 22 Nov 2021 23:53:34 +0000 (16:53 -0700)]
Add an ad hoc version check to dwarf_scanner_base
Some generic code in the DWARF reader has a special case for older
versions of .gdb_index. This patch adds an ad hoc version check
method so that these spots can work without specific knowledge of
which index is in use.
Tom Tromey [Mon, 22 Nov 2021 23:50:46 +0000 (16:50 -0700)]
Simplify version check in dw2_symtab_iter_next
This simplifies the index versio check in dw2_symtab_iter_next, by
passing a reference to the index object to this function. This avoids
an indirection via the per_bfd object.
Tom Tromey [Mon, 22 Nov 2021 23:43:47 +0000 (16:43 -0700)]
Introduce and use dwarf_scanner_base
This introduces dwarf_scanner_base, a base class for all the index
readers in the DWARF code. Then, it changes both mapped_index_base
and cooked_index_vector to derive from this new base class.
Tom Tromey [Tue, 30 Mar 2021 02:14:30 +0000 (20:14 -0600)]
Introduce readnow_functions
This introduces readnow_functions, a new subclass of
dwarf2_base_index_functions, and changes the DWARF reader to use it.
This lets us drop the "index is NULL" hack from the gdb index code.
Tom Tromey [Tue, 30 Mar 2021 00:31:31 +0000 (18:31 -0600)]
Remove some "OBJF_READNOW" code from dwarf2_debug_names_index
The dwarf2_debug_names_index code treats a NULL debug_names_table as
if it were from OBJF_READNOW. However, this trick is only done for
gdb_index, never for debug_names -- see dwarf2_initialize_objfile.
Tom Tromey [Mon, 29 Mar 2021 23:58:21 +0000 (17:58 -0600)]
Let mapped index classes create the quick_symbol_functions object
This changes the mapped index classes to create the
quick_symbol_functions objects. This is a step toward having a more
abstract interface to mapped indices.
Jan Beulich [Wed, 20 Apr 2022 14:56:05 +0000 (16:56 +0200)]
x86: reject all invalid SAE variants
So far an SAE-only specifier was accepted for static-rounding insns,
while SAE-only insns didn't accept static rounding specifiers. If
anything it would make sense the other way around, allowing SAE-only
insns to have the (ignored) rounding mode specified individually rather
than globally via -mevexrcig=. But for now make things match the SDM.
* coff-rs6000.c (xcoff_reloc_type_noop): Add info argument.
(xcoff_reloc_type_fail): Likewise.
(xcoff_reloc_type_pos): Likewise.
(xcoff_reloc_type_neg): Likewise.
(xcoff_reloc_type_rel): Likewise.
(xcoff_reloc_type_toc): Likewise.
(xcoff_reloc_type_ba): Likewise.
(xcoff_reloc_type_crel): Likewise.
(xcoff_reloc_type_tls): Likewise.
(xcoff_reloc_type_br): Add stub handler.
(xcoff_ppc_relocate_section): Add info to
xcoff_calculate_relocation.
(xcoff_stub_indirect_call_code): New constant.
(xcoff_stub_shared_call_code): Likewise.
(bfd_xcoff_backend_data): Add stub code fields.
(bfd_pmac_xcoff_backend_data): Likewise.
* coff64-rs6000.c (xcoff64_reloc_type_br): Add stub handler.
(xcoff64_ppc_relocate_section): Add info to
xcoff64_calculate_relocation.
(xcoff64_stub_indirect_call_code): New constant.
(xcoff64_stub_shared_call_code): Likewise.
(bfd_xcoff_backend_data): Add stub code fields.
(bfd_xcoff_aix5_backend_data): Likewise.
* libxcoff.h (struct xcoff_backend_data_rec): Add stub fields.
(bfd_xcoff_stub_indirect_call_code): New define.
(bfd_xcoff_stub_indirect_call_size): New define.
(bfd_xcoff_stub_shared_call_code): New define.
(bfd_xcoff_stub_shared_call_size): New define.
(xcoff_reloc_function): Add info argument.
(enum xcoff_stub_type): New enum.
(struct xcoff_stub_hash_entry): New structure.
* xcofflink.c (struct xcoff_link_hash_table): Add stub hash
table and params fields.
(xcoff_stub_hash_entry): New define.
(xcoff_stub_hash_lookup): New define.
(stub_hash_newfunc): New function.
(_bfd_xcoff_bfd_link_hash_table_free): Free the new stub hash
table.
(_bfd_xcoff_bfd_link_hash_table_create): Create the new stub
hash table.
(xcoff_link_add_symbols): Save rawsize for XTY_SD.
(bfd_xcoff_link_init): New function.
(xcoff_stub_csect_name): New function.
(xcoff_stub_get_csect_in_range): New function.
(xcoff_stub_name): New function.
(bfd_xcoff_get_stub_entry): New function.
(bfd_xcoff_type_of_stub): New function.
(xcoff_add_stub): New function.
(xcoff_build_one_stub): New function.
(bfd_xcoff_size_stubs): New function.
(bfd_xcoff_build_stubs): New function.
(xcoff_stub_create_relocations): New function.
(xcoff_link_input_bfd): Adapt relocations to stub.
(xcoff_write_global_symbol): Adapt to new TOC entries generated
for stubs.
(_bfd_xcoff_bfd_final_link): Handle stub file.
* xcofflink.h (struct bfd_xcoff_link_params): New structure.
ld/ChangeLog:
* emultempl/aix.em (params): New variable.
(stub_file): New variable.
(xcoff_add_stub_section): New function.
(xcoff_layout_sections_again): New function
(hook_in_stub): New function.
(_after_allocation): Add stub creation.
(_create_output_section_statements): Allocate stub file and
pass params to backend.
Stubs (added in a later patch) will generate new .loader symbols, once the allocations have been done. Thus, the .loader section cannot be layout before that.
bfd/ChangeLog:
* coff-rs6000.c (_bfd_xcoff_put_ldsymbol_name): Write len in
ldinfo->strings instead of directly in the output_bfd.
* coff64-rs6000.c (_bfd_xcoff64_put_ldsymbol_name): Likewise.
* xcofflink.c (struct xcoff_link_hash_table): Remove ldrel_count
field. Add ldinfo field.
(xcoff_mark_symbol): Adjust to new ldinfo field.
(xcoff_mark): Likewise.
(bfd_xcoff_link_count_reloc): Likewise.
(xcoff_build_loader_section): Split into two functions: one that
build the loader section (this function) and one that only size
it...
(xcoff_size_loader_section): ... (this function).
(bfd_xcoff_size_dynamic_sections): Adapt to new ldinfo field.
Move the part where the dynamic sections are build to ...
(bfd_xcoff_build_dynamic_sections): ... this function.
* xcofflink.h: Add bfd_xcoff_build_dynamic_sections prototype.
include/ChangeLog:
* coff/xcoff.h (struct xcoff_loader_info): Add ldrel_count and
libpath fields.
ld/ChangeLog:
* emultempl/aix.em (_after_allocation): New function.
Tom Tromey [Sat, 16 Apr 2022 20:19:18 +0000 (14:19 -0600)]
Use symbol_symtab accessor in compile-object-load.c
I noticed that compile-object-load.c directly references owner.symtab
of a symbol. However, I think it's better for all users to call
symbol_symtab. This patch makes this change.
If can't determine prologue from the symbol table, need to examine
instructions. Implement loongarch_scan_prologue() to analyze the
function prologue from START_PC to LIMIT_PC, return the address of
the first instruction past the prologue.
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Lancelot SIX [Tue, 22 Mar 2022 14:02:54 +0000 (10:02 -0400)]
gdb/selftest-arch: Make register_test_foreach_arch generate arch tests lazily
The register_test_foreach_arch is used to instantiate a given selftest
for all architectures supported by GDB. It is used in many _initialize_*
functions (under initialize_all_files, called by gdb_init).
Because the call is done during GDB's initialization, and because there
is no guaranty about the order in which all the _initialize_* functions
are executed, when register_test_foreach_arch is called, GDB is not
fully initialized. Specifically, when a particular initialize function
is executed, only the architectures registered at that point are listed
by gdbarch_printable_names.
As a consequence, the list of selftest effectively executed depends on
the order the _initialize_* functions are called. This can be observed
with the following:
$ ./gdb/gdb \
-data-directory ./gdb/data-directory \
-quiet -batch -ex "maint selftest" 2>&1 \
| grep -E "Ran [0-9]+ unit tests"
Ran 145 unit tests, 0 failed
$ GDB_REVERSE_INIT_FUNCTIONS=1 ./gdb/gdb \
-data-directory ./gdb/data-directory \
-quiet -batch -ex "maint selftest" 2>&1 \
| grep -E "Ran [0-9]+ unit tests"
Ran 82 unit tests, 0 failed
To fix this, make register_test_foreach_arch register a lazy selftest
generator. This way when the test generator is eventually executed, all
architectures are registered and we do not have a dependency on the
order the initialize functions are executed in.
Lancelot SIX [Tue, 22 Mar 2022 12:09:40 +0000 (08:09 -0400)]
gdbsupport/selftest: Allow lazy registration
This patch adds a way to delay the registration of tests until the
latest possible moment. This is intended for situations where GDB needs
to be fully initialized in order to decide if a particular selftest can
be executed or not.
Lancelot SIX [Wed, 23 Mar 2022 15:29:53 +0000 (15:29 +0000)]
gdbsupport/selftest: Replace for_each_selftest with an iterator_range
Remove the callback-based selftests::for_each_selftest function and use
an iterator_range instead.
Also use this iterator range in run_tests so all iterations over the
selftests are done in a consistent way. This will become useful in a
later commit.
Jan Beulich [Tue, 19 Apr 2022 07:26:17 +0000 (09:26 +0200)]
x86: don't mistake ordinary immediates for SAE / rounding control
The way SAE templates are constructed was always puzzling me (including
the need for separate templates in the first place), and expressing the
extzra attribute via Imm8 actually has a bad effect: Ordinary immediates
would also be accepted, leading to an extra byte being added after the
instruction (i.e. generating bad code). Before re-working this (in
particular to accept proper Intel syntax there), fix the immediate issue
by adding the so far missing check.
Jan Beulich [Tue, 19 Apr 2022 07:24:24 +0000 (09:24 +0200)]
x86/Intel: test non-legacy VCVT{,U}SI2SH insn forms
For an unclear reason corresponding AVX512F tests were apparently not
cloned or used as reference here, and instead the bogus legacy forms of
the insns (with the embedded rounding specifier not last) were used.
Jan Beulich [Tue, 19 Apr 2022 07:23:49 +0000 (09:23 +0200)]
x86: correct and simplify NOP disassembly
It's not just REX.W which is ignored with opcode 0x90. The same goes for
REX.R and REX.X as well as empty REX. None of these are forms of
"xchg %eax,%eax" (which would mean zero-extending %eax to %rax), so they
also shouldn't be disassembled this way.
While there simplify things: A single hook function suffices, thus
making it unnecessary to keep two expressions in sync. And checking
ins->address_mode for mode_64bit also is unnecessary, as "rex" can be
non-zero only in that case anyway.
Simon Marchi [Thu, 7 Apr 2022 01:51:56 +0000 (21:51 -0400)]
gdb/testsuite/dwarf: don't automatically add directory and file entry for DWARF 5
To support DWARF 5 in the DWARF assembler line tables, we currently copy
the first user-provided directory and the first user-provided files and
make them elements at indices 0 in the directory and file name tables.
That was a sufficient behavior at the time (see commit 44fda089397a
("[gdb/testsuite] Support .debug_line v5 in dwarf assembler")), but in
the following patches, I would need to have finer grained control on
what is generated exactly. For example, I'd like to generate a DWARF 5 line
table with just a single file and a single directory.
Get rid of this behavior, and implement what is suggested in 44fda089397a: make include_dir return the directory index that can be
used to refer to that directory entry (based on the DWARF version), and
use it afterwards.
Adjust dw2-lines.exp and dw2-prologue-end.exp accordingly. Their produced
DWARF5 binaries will change a bit, in that they will now have a single
directory and file, where they had two before. But it doesn't change
the expected GDB behavior.
Simon Marchi [Wed, 13 Apr 2022 21:39:06 +0000 (17:39 -0400)]
gdbsupport: make gdb_realpath_keepfile return an std::string
I'm trying to switch these functions to use std::string instead of char
arrays, as much as possible. Some callers benefit from it (can avoid
doing a copy of the result), while others suffer (have to make one more
copy).
Simon Marchi [Wed, 13 Apr 2022 21:31:02 +0000 (17:31 -0400)]
gdbsupport: make gdb_abspath return an std::string
I'm trying to switch these functions to use std::string instead of char
arrays, as much as possible. Some callers benefit from it (can avoid
doing a copy of the result), while others suffer (have to make one more
copy).
Tom Tromey [Sat, 2 Apr 2022 15:54:40 +0000 (09:54 -0600)]
Fix C++ cast of derived class to base class
PR c++/28907 points out that casting from a derived class to a base
class fails in some situations. The problem turned out to be a
missing use of value_embedded_offset. One peculiarity here is that,
if you managed to construct a pointer-to-derived with an embedded
offset of 0, the cast would work -- for example, one of the two new
tests here passes without the patch.
This embedded offset stuff is an endless source of bugs. I wonder if
it's possible to get rid of it somehow.
Simon Marchi [Thu, 14 Apr 2022 16:26:33 +0000 (12:26 -0400)]
gdb/testsuite: make gdb.ada/mi_prot.exp stop at expected location
This test attempts to run until the line marked "STOP", which is at
prot.adb:34. It first runs until the "main" symbol, then tries to place
a breakpoint by line at line 34, without specifying the source file. When looking at the logs:
... we see that the breakpoint is placed in some generated file, not in
the test source file as we expect. The problem is that "b main" in Ada
does not place a breakpoint on the "Ada main", but on some symbol in a
generated source file. So when stopped at the "main" symbol, we are not
stopped in the file that contains the STOP marker at line 34.
The test passes anyway today, so it doesn't seem to matter that we are
stopped at an unexpected location. But it starts failing with this
patch [1], because b~prot.adb:34 happens to be between two functions, so
the breakpoint doesn't resolve.
Fix this by placing the breakpoint at "$srcfile:$line", which works
regardless of what is the current source file.
However, this ends up introducing a path in the test name. Modify
mi_tbreak and mi_continue_to_line to avoid that.
gdb/testsuite: add text_segment option to gdb_compile
LLVM's lld linker doesn't have the "-Ttext-segment" option, but
"--image-base" can be used instead.
To centralize the logic of checking which option is supported, add the
text_segment option to gdb_compile. Change tests that are currently
using -Ttext-segment to use that new option instead.
This patch fixes only compilation error, for example:
$ make check TESTS="gdb.base/jit-elf.exp" RUNTESTFLAGS="CC_FOR_TARGET=clang LDFLAGS_FOR_TARGET=-fuse-ld=ld"
Running /home/simark/src/binutils-gdb/gdb/testsuite/gdb.base/jit-elf.exp ...
FAIL: gdb.base/jit-elf.exp: one_jit_test-1: continue to breakpoint: break here 1
FAIL: gdb.base/jit-elf.exp: one_jit_test-1: continue to breakpoint: break here 2
FAIL: gdb.base/jit-elf.exp: one_jit_test-2: continue to breakpoint: break here 1
FAIL: gdb.base/jit-elf.exp: one_jit_test-2: info function ^jit_function
FAIL: gdb.base/jit-elf.exp: one_jit_test-2: continue to breakpoint: break here 2
FAIL: gdb.base/jit-elf.exp: attach: one_jit_test-2: continue to breakpoint: break here 1
FAIL: gdb.base/jit-elf.exp: attach: one_jit_test-2: break here 1: attach
FAIL: gdb.base/jit-elf.exp: PIE: one_jit_test-1: continue to breakpoint: break here 1
FAIL: gdb.base/jit-elf.exp: PIE: one_jit_test-1: continue to breakpoint: break here 2
=== gdb Summary ===
# of expected passes 26
# of unexpected failures 9
Tom Tromey [Sat, 16 Apr 2022 19:58:34 +0000 (13:58 -0600)]
Add comments to dwarf2/abbrev-cache.h
This patch started when I noticed that the unordered_set include
wasn't needed in abbrev-cache.h. (That was probably leftover from
some earlier implementation of the class.) Then, I noticed that the
class itself was under-commented. This patch fixes both issues.
Tom Tromey [Sun, 9 Jan 2022 02:37:38 +0000 (19:37 -0700)]
Handle "set height 1"
PR cli/17151 points out that "set height 1" has pathological behavior
in gdb. What I see is that gdb will endlessly print the pagination
prompt. This patch takes a simple and expedient approach to a fix:
pretend that the height is really 2.
Tom Tromey [Sun, 9 Jan 2022 01:26:35 +0000 (18:26 -0700)]
Allow word wrapping even when paging is disabled
PR cli/20741 points out that when pagination is disabled, this also
disabled word wrapping. However, the manual documents that these
settings are separate -- if you intend to disable the wrapping, you
must use "set width unlimited".
This patch fixes the bug by letting the pagination-disabled case fall
through to the code that also handles word-wrapping.
Tom Tromey [Sun, 27 Mar 2022 21:29:28 +0000 (15:29 -0600)]
Implement value_print for Rust
This adds an implementation of the value_print method to Rust. As
described in PR rust/22254, this removes a bit of weird-looking output
from some "print"s -- because c_value_print is bypassed. I don't have
a test for the bug that inspired this patch, because I only know how
to reproduce it when using a relatively old Rust compiler. However,
the new "cast-printing" code in value_print is required, because
omitting this causes some existing tests to fail.
Tom Tromey [Fri, 25 Mar 2022 19:36:53 +0000 (13:36 -0600)]
Reimplement Rust slice printing
The current nightly Rust compiler (aka 1.61) added better DWARF
representation for unsized types. Fixing this is PR rust/21466; but
the code is actually the same as what is required to make slice
printing more useful, which is PR rust/23871. This patch implements
this. I tested this against various Rust compilers: 1.48, current
stable, current beta, and current nightly.
Tom Tromey [Fri, 25 Mar 2022 19:43:27 +0000 (13:43 -0600)]
Remove some dead code from the Rust value printer
This removes a bit of dead code from the Rust value printer. This
code wasn't always dead -- it fixed a real bug, and a test case was
added for it. However, once val_print was removed, it became
unnecessary.
Fix this by testing whether 16llf is supported by doing ptype long_long_float
which gets us either:
...
type = <16-byte float>^M
...
or:
...
type = <12-byte float>^M
...
Tom de Vries [Fri, 15 Apr 2022 14:53:08 +0000 (16:53 +0200)]
[gdb/testsuite] Fix gdb.go/methods.exp with check-readmore
When running test-case gdb.go/methods.exp with make check we have:
...
(gdb) break main.T.Foo^M
Function "main.T.Foo" not defined.^M
Make breakpoint pending on future shared library load? (y or [n]) n^M
(gdb) XFAIL: gdb.go/methods.exp: gdb_breakpoint: set breakpoint at main.T.Foo
...
but with make check-readmore the XFAIL fails to trigger:
...
(gdb) break main.T.Foo^M
Function "main.T.Foo" not defined.^M
Make breakpoint pending on future shared library load? (y or [n]) n^M
(gdb) FAIL: gdb.go/methods.exp: gdb_breakpoint: set breakpoint at main.T.Foo
...
This happens because this gdb_test_multiple "maintenance print symbols"
regexp:
...
-re "\r\n$gdb_prompt $" {
...
matches the entire command output.
Fix this by adding the missing ^ at the regexp start.
Pedro Alves [Tue, 29 Mar 2022 12:32:48 +0000 (13:32 +0100)]
gdbserver: Eliminate prepare_to_access_memory
Given:
- The prepare_to_access_memory machinery was added for non-stop mode.
- Only Linux supports non-stop.
- Linux no longer needs the prepare_to_access_memory machinery. In
fact, after the previous patch,
linux_process_target::prepare_to_access_memory became a nop.
Thus, prepare_to_access_memory can go away, simplifying core GDBserver
code.
Pedro Alves [Mon, 28 Mar 2022 17:35:34 +0000 (18:35 +0100)]
gdbserver/linux: Access memory even if threads are running
Similarly to how the native Linux target was changed
and subsequently reworked in these commits:
05c06f318fd9 Linux: Access memory even if threads are running 8a89ddbda2ec Avoid /proc/pid/mem races (PR 28065)
... teach GDBserver to access memory even when the current thread is
running, by always accessing memory via /proc/PID/mem.
The existing comment:
/* Neither ptrace nor /proc/PID/mem allow accessing memory through a
running LWP. */
... is incorrect for /proc/PID/mem does allow that.
Actually, from GDB's perspective, GDBserver could already access
memory while threads were running, but at the expense of pausing all
threads for the duration of the memory access, via
prepare_to_access_memory. This new implementation does not require
pausing any thread, thus
linux_process_target::prepare_to_access_memory /
linux_process_target::done_accessing_memory become nops. A subsequent
patch will remove the whole prepare_to_access_memory infrastructure
completely.
The GDBserver linux-low.cc implementation is simpler than GDB's
linux-nat.c's, because GDBserver always adds the unfollowed vfork/fork
children to the process list immediately when the fork/vfork event is
seen out of ptrace. I.e., there's no need to keep the file descriptor
stored on a side map, we can store it directly in the process
structure.
Surprisingly, the assertion fails. That happens because it can happen
that target_write_memory is called with LEN==0, due to this in
gdb/remote.c:
/* Determine whether the remote target supports binary downloading.
This is accomplished by sending a no-op memory write of zero length
to the target at the specified address. (...) */
In this scenario, in gdbserver's target_write_memory, the "myaddr"
argument of the_target->write_memory is passed the data() of a local
gdb::byte_vector (which is a specialized std::vector). It's valid for
std::vector::data() to return NULL when the vector is empty.
This commit adds an early return to target_write_memory to avoid
target backends having to care about this. For good measure, do the
same on the read side, in read_inferior_memory.
handle_qxfer_threads_proper needs to pause all threads even if the
target can read memory when threads are running, so use
target_pause_all instead, which is what the Linux implementation of
prepare_to_access_memory uses. (Only Linux implements this hook.)
A following patch will make the Linux backend be able to access memory
when threads are running, and thus will also make
prepare_to_access_memory do nothing, which would cause testsuite
regressions without this change.
Tom Tromey [Thu, 14 Apr 2022 15:36:09 +0000 (09:36 -0600)]
Ignore 0,0 entries in .debug_aranges
When running the internal AdaCore test suite against the new DWARF
indexer, I found one regression on RISC-V. The test in question uses
--gc-sections, and winds up with an entry in the middle of a
.debug_aranges that has both address and length of 0. In this
scenario, gdb assumes the entries are terminated and then proceeds to
reject the section because it reads a subsequent entry as if it were a
header.
It seems to me that, because each header describes the size of each
.debug_aranges CU, it's better to simply ignore 0,0 entries and simply
read to the end. That is what this patch does.
I've patched an existing test to provide a regression test for this.
Tom Tromey [Wed, 13 Apr 2022 14:45:34 +0000 (08:45 -0600)]
Use GetThreadDescription on Windows
Windows 10 introduced SetThreadDescription and GetThreadDescription, a
simpler way to set a thread's name. This changes gdb and gdbserver to
use this convention when it is available.
Tom Tromey [Wed, 13 Apr 2022 14:12:52 +0000 (08:12 -0600)]
Set the worker thread name on Windows
This patch is a bit different from the rest of the series, in that it
is a change to gdb's behavior on the host. It changes gdb's thread
pool to try to set the thread name on Windows, if SetThreadDescription
is available.
This is part of PR win32/29050.
This patch isn't likely to be useful to many people in the short term,
because the Windows port of the libstdc++ thread code is not upstream.
(AdaCore uses it, and sent it upstream, but it did not land, I don't
know why.) However, if that patch does ever go in, or presumably if
you build using some other C++ runtime library, then this will be
useful.
Tom Tromey [Tue, 12 Apr 2022 20:25:44 +0000 (14:25 -0600)]
Share handle_ms_vc_exception with gdbserver
Currently, gdb's native Windows target implements the exception-based
approach for setting thread names, but gdbserver does not. This patch
moves handle_ms_vc_exception to the shared nat/windows-nat.c code, as
preparation for adding this support to gdbserver.
Tom Tromey [Wed, 13 Apr 2022 12:32:28 +0000 (06:32 -0600)]
Remove the byte order parameter to target_read_string
target_read_string takes a byte order parameter, but only uses this to
check whether a given character is zero. This is readily done without
requiring the parameter, so remove it.
Tom Tromey [Wed, 13 Apr 2022 12:55:30 +0000 (06:55 -0600)]
Fix possible Cygwin build problem
I noticed that nat/windows-nat.c checks __USEWIDE, but nothing sets it
there -- I forgot to copy over the definition when making this file.
This patch tries to fix the problem. I don't have a Cygwin setup, so
I don't know whether this is sufficient, but it's probably necessary.
Lancelot SIX [Thu, 14 Apr 2022 17:21:04 +0000 (18:21 +0100)]
gdb/testsuite: Fix race in gdb.dwarf2/calling-convention.exp
Pedro Alves warned me that there is a race in
gdb.dwarf2/calling-convention.exp making the test sometimes fail on his
setup. This can be reliably reproduced using :
make check-read1 TESTS="gdb.dwarf2/calling-convention.exp"
The relevant part of the gdb.log file is:
return 35
Function 'foo' does not follow the target calling convention.
If you continue, setting the return value will probably lead to unpredictable behaviors.
Make foo return now? (y or n) PASS: gdb.dwarf2/calling-convention.exp: return 35
n
Not confirmed
(gdb) FAIL: gdb.dwarf2/calling-convention.exp: finish
The issue is that when doing the test for "return 35", the DejaGnu test
sends "n" (to tell GDB not to perform the return action) but never
consumes the "Not confirmed" acknowledgment sent by GDB. Later, when
trying to do the next test, DejaGnu tries to match the leftover output
from the "return" test. As this output is not expected, the test fails.
Fix by using gdb_test to send the "n" answer and match the confirmation
and consume all output to the prompt.
Also do minor adjustments to the main regex:
- Remove the leading ".*" which is not required.
- Ensure that the "?" from the question is properly escaped.
Tested on x86_64-gnu-linux, using
- make check TESTS="gdb.dwarf2/calling-convention.exp"
- make check-read1 TESTS="gdb.dwarf2/calling-convention.exp"
- make check-readmore TESTS="gdb.dwarf2/calling-convention.exp"
Co-authored-by: Pedro Alves <pedro@palves.net>
Change-Id: I42858b13db2cbd623c5c1739de65ad423e0c0938
Tom Tromey [Thu, 7 Apr 2022 16:17:02 +0000 (10:17 -0600)]
Silence -Wmaybe-uninitialized warning from target_waitstatus
Currently, one use of target_waitstatus yields a warning:
target/waitstatus.h: In function 'void stop_all_threads()':
target/waitstatus.h:175:13: warning: 'ws.target_waitstatus::m_value' may be used uninitialized in this function [-Wmaybe-uninitialized]
175 | m_value = other.m_value;
| ~~~~~~~~^~~~~~~~~~~~~~~
This patch silences the warning. I tried the "volatile member"
approach that was used for gdb::optional, but that didn't work, so
this patch simply initializes the member.
Tom Tromey [Thu, 31 Mar 2022 13:55:09 +0000 (07:55 -0600)]
Fix regression on Windows with WOW64
Internally at AdaCore, we recently started testing a 64-bit gdb
debugging 32-bit processes. This failed with gdb head, but not with
gdb 11.
The tests fail like this:
Starting program: [...].exe
warning: Could not load shared library symbols for WOW64_IMAGE_SECTION.
Do you need "set solib-search-path" or "set sysroot"?
warning: Could not load shared library symbols for WOW64_IMAGE_SECTION.
Do you need "set solib-search-path" or "set sysroot"?
warning: Could not load shared library symbols for NOT_AN_IMAGE.
Do you need "set solib-search-path" or "set sysroot"?
warning: Could not load shared library symbols for NOT_AN_IMAGE.
Do you need "set solib-search-path" or "set sysroot"?
After some debugging and bisecting, to my surprise the bug was
introduced by commit 183be222 ("gdb, gdbserver: make target_waitstatus
safe").
The problem occurs in handle_exception. Previously the code did:
However, in the new code, the fallthrough case does:
+ ourstatus->set_stopped (GDB_SIGNAL_TRAP);
... which changes the 'kind' in 'ourstatus' after falling through.
This patch rearranges the 'last_sig' setting to more closely match
what was done before (this is probably not strictly needed but also
seemed harmless), and removes the fall-through in the
'ignore_first_breakpoint' case when __x86_64__ is defined.
Tom Tromey [Fri, 25 Feb 2022 18:33:32 +0000 (11:33 -0700)]
Reorganize Python events documentation
This slightly reorganizes the Python events documentation. It hoists
the "ThreadEvent" text out of the list of events, where it seemed to
be misplaced. It tidies the formatting a little bit (adding some
vertical space for easier reading in info), fixes a typo, adds some
missing commas, and fixes an incorrect reference to NewInferiorEvent.
Simon Marchi [Thu, 14 Apr 2022 15:32:34 +0000 (11:32 -0400)]
gdb: remove move constructor and move assignment operator from cooked_index
Building with clang++-14, I see:
CXX dwarf2/cooked-index.o
In file included from /home/smarchi/src/binutils-gdb/gdb/dwarf2/cooked-index.c:21:
/home/smarchi/src/binutils-gdb/gdb/dwarf2/cooked-index.h:172:12: error: explicitly defaulted move constructor is implicitly deleted [-Werror,-Wdefaulted-function-deleted]
explicit cooked_index (cooked_index &&other) = default;
^
/home/smarchi/src/binutils-gdb/gdb/dwarf2/cooked-index.h:225:16: note: move constructor of 'cooked_index' is implicitly deleted because field 'm_storage' has a deleted move constructor
auto_obstack m_storage;
^
/home/smarchi/src/binutils-gdb/gdb/../gdbsupport/gdb_obstack.h:128:28: note: 'auto_obstack' has been explicitly marked deleted here
DISABLE_COPY_AND_ASSIGN (auto_obstack);
^
In file included from /home/smarchi/src/binutils-gdb/gdb/dwarf2/cooked-index.c:21:
/home/smarchi/src/binutils-gdb/gdb/dwarf2/cooked-index.h:174:17: error: explicitly defaulted move assignment operator is implicitly deleted [-Werror,-Wdefaulted-function-deleted]
cooked_index &operator= (cooked_index &&other) = default;
^
/home/smarchi/src/binutils-gdb/gdb/dwarf2/cooked-index.h:225:16: note: move assignment operator of 'cooked_index' is implicitly deleted because field 'm_storage' has a deleted move assignment operator
auto_obstack m_storage;
^
/home/smarchi/src/binutils-gdb/gdb/../gdbsupport/gdb_obstack.h:128:3: note: 'operator=' has been explicitly marked deleted here
DISABLE_COPY_AND_ASSIGN (auto_obstack);
^
/home/smarchi/src/binutils-gdb/gdb/../include/ansidecl.h:425:8: note: expanded from macro 'DISABLE_COPY_AND_ASSIGN'
void operator= (const TYPE &) = delete
^
We explicitly make cooked_index have a default move constructor and
move assignment operator. But it doesn't actually happen because
cooked_index has a field of type auto_obstack, which isn't movable.
We don't actually need cooked_index to be movable at the moment, so
remove those lines.
Tom Tromey [Thu, 31 Mar 2022 14:26:12 +0000 (08:26 -0600)]
Let std::thread check pass even without pthreads
Currently, the configure check for std::thread relies on pthreads
existing. However, this means that if std::thread is implemented for
a non-pthreads host, then the check will yield the wrong answer. This
happened in AdaCore internal builds. Here, we have this GCC patch:
Tiezhu Yang [Thu, 14 Apr 2022 02:37:30 +0000 (10:37 +0800)]
gdb: fix build errors in gdbsupport/thread-pool.h used with old gcc
When I build gdb with gcc 8.3, there exist the following build errors,
rename the typedef to task_t to fix them.
CXX thread-pool.o
In file included from /home/loongson/gdb.git/gdbsupport/thread-pool.cc:21:
/home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h: In member function ‘std::future<void> gdb::thread_pool::post_task(std::function<void()>&&)’:
/home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h:69:44: error: declaration of ‘task’ shadows a previous local [-Werror=shadow=local]
std::packaged_task<void ()> task (std::move (func));
^~~~
/home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h:102:39: note: shadowed declaration is here
typedef std::packaged_task<void ()> task;
^~~~
/home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h: In member function ‘std::future<_Res> gdb::thread_pool::post_task(std::function<T()>&&)’:
/home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h:80:41: error: declaration of ‘task’ shadows a previous local [-Werror=shadow=local]
std::packaged_task<T ()> task (std::move (func));
^~~~
/home/loongson/gdb.git/gdbsupport/../gdbsupport/thread-pool.h:102:39: note: shadowed declaration is here
typedef std::packaged_task<void ()> task;
^~~~
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Tom de Vries [Thu, 14 Apr 2022 10:32:51 +0000 (12:32 +0200)]
[gdb/testsuite] Detect 'No MPX support'
On openSUSE Leap 15.3, mpx support has been disabled for m32, so I run into:
...
(gdb) run ^M
Starting program: outputs/gdb.arch/i386-mpx/i386-mpx ^M
[Thread debugging using libthread_db enabled]^M
Using host libthread_db library "/lib64/libthread_db.so.1".^M
No MPX support^M
...
and eventually into all sort of fails in this and other mpx test-cases.
Fix this by detecting the "No MPX support" message in have_mpx.
Tested on x86_64-linux with target boards unix and unix/-m32.
M68K: avoid quadratic slowdlow in label alignment check
Before the change tc-m68k maintained a list of seen labels.
Alignment check traversed label list to resolve symbol to label.
This caused quadratic slowdown as each symbol was checked against
each label. Worst affected files are the ones built with debugging
enabled as DWARF generates many labels.
The change embeds auxiliary label information right into symbol using
TC_SYMFIELD_TYPE.
Before the change test from PR 29058 did not finish in 10 minutes. After
the change it finishes in 2 seconds.
gas/ChangeLog:
PR 29058
* config/tc-m68k.h (TC_SYMFIELD_TYPE): define as m68k_tc_sy.
* config/tc-m68k.c (m68k_frob_label): Use TC_SYMFIELD_TYPE to
store label information.
Simon Marchi [Wed, 13 Apr 2022 15:15:38 +0000 (11:15 -0400)]
gdb: add ATTRIBUTE_PRINTF to complaint_interceptor::issue_complaint
Fix this error when building with clang++-14:
CXX complaints.o
/home/smarchi/src/binutils-gdb/gdb/complaints.c:130:65: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
g_complaint_interceptor->m_complaints.insert (string_vprintf (fmt, args));
^~~
Simon Marchi [Wed, 13 Apr 2022 15:25:08 +0000 (11:25 -0400)]
gdb: fix clang build failure in msymbol_is_mips
Building with clang++-14, I see:
CXX mips-tdep.o
/home/smarchi/src/binutils-gdb/gdb/mips-tdep.c:453:12: error: use of bitwise '|' with boolean operands [-Werror,-Wbitwise-instead-of-logical]
return !(MSYMBOL_TARGET_FLAG_MIPS16 (msym)
~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/smarchi/src/binutils-gdb/gdb/mips-tdep.h:54:2: note: expanded from macro 'MSYMBOL_TARGET_FLAG_MIPS16'
(sym)->target_flag_1 ()
^
/home/smarchi/src/binutils-gdb/gdb/mips-tdep.c:453:12: note: cast one or both operands to int to silence this warning
/home/smarchi/src/binutils-gdb/gdb/mips-tdep.h:54:2: note: expanded from macro 'MSYMBOL_TARGET_FLAG_MIPS16'
(sym)->target_flag_1 ()
^
That's since commit e165fcef1e7 ("gdb: remove MSYMBOL_TARGET_FLAG_{1,2}
macros"). Fix this by using the boolean || rather than the bitwise |,
since the new methods return bool values. No change in behavior
expected.
Pedro Alves [Fri, 8 Apr 2022 19:03:46 +0000 (20:03 +0100)]
Make intrusive_list_node's next/prev private
Tromey noticed that intrusive_list_node leaves its data members
public, which seems sub-optimal.
This commit makes intrusive_list_node's data fields private.
intrusive_list_iterator, intrusive_list_reverse_iterator, and
intrusive_list do need to access the fields, so they are made friends.
Tom Tromey [Fri, 8 Apr 2022 16:11:58 +0000 (10:11 -0600)]
Fix bug in Ada number lexing
On irc, Pedro pointed out that Ada couldn't properly handle
0xffffffffffffffff. This used to work, but is a regression due to
some patches I wrote in the Ada lexer. This patch fixes the bug.
Reading symbols from /tmp/cwd/a.out...
/home/smarchi/src/binutils-gdb/gdb/dwarf2/cooked-index.c:332:11: runtime error: null pointer passed as argument 2, which is declared to never be null
It looks like even if the size is 0 (the size of the `entries` vector is
0), we shouldn't be passing a NULL pointer to memcpy. And
`entries.data ()` returns NULL.
Fix that by using std::vector::insert to insert the items of entries
into m_entries. I haven't checked, but it should essentially compile
down to a memcpy, since the vector elements are trivially copyiable.