Fixes all warnings given by pyright.
Change-Id: I480521bfc62960c4eccd9d32c886392b05a1ddaa
Reviewed-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
Add the Entry type and use it in the `entries` map, rather than using an
ad-hoc str -> str map that comes from the re.match. This will make it
easier to make typing work in a subsequent patch, but it also helps
readers know what attributes exist for entries, which is not clear
currently.
Change-Id: I5b58dee1ed7ae85987b99bd417e641ede718624c
Reviewed-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
Add type annotations to gdbarch*.py to fix all errors shown by pyright.
There is one change in copyright.py too, to fix this one:
/home/simark/src/binutils-gdb/gdb/gdbarch.py
/home/simark/src/binutils-gdb/gdb/gdbarch.py:206:13 - error: Type of "copyright" is partially unknown
Type of "copyright" is "(tool: Unknown, description: Unknown) -> str" (reportUnknownMemberType)
Change-Id: Ia109b53e267f6e2f5bd79a1288d0d5c9508c9ac4
Reviewed-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
Editing gdbarch-components.py is not an experience in an editor that is
minimally smart about Python. Because gdbarch-components.py is read and
exec'd by gdbarch.py, it doesn't import the Info / Method / Function /
Value types. And because these types are defined in gdbarch.py, it
can't import them, as that would make a cyclic dependency.
Solve this by introducing a third file, gdbarch_types.py, to define
these types. Make gdbarch.py and gdbarch-components.py import it.
Also, replace the read & exec of gdbarch-components.py by a regular
import. For this to work though, gdbarch-components.py needs to be
renamed to gdbarch_components.py.
Change-Id: Ibe994d56ef9efcc0698b3ca9670d4d9bf8bbb853
Reviewed-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
While working on other projects, I found the pyright type checker very
helpful when editing Python code. I don't think I have to explain the
advantages of type checking to a crowd used to C/C++.
Setting typeCheckingMode to "strict" makes pyright flag a bit more type
issues than the default of "basic".
Change-Id: I38818ec59f7f73c2ab020cc9226286cdd485abc7
Reviewed-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
Info.__init__ currently assigns `self.predicate = None`. This was
helpful to ensure that all component types had a `predicate` attribute.
The generator code could then avoid having code like "if the component
is anything but Info, use predicate". Since the previous commit, all
component types have a predicate attribute which defaults to False. We
can therefore remove the assignment in Info.__init__, and in turn remove
Info.__init__. We however need to make the printer parameter of
_Component.__init__ optional, as Info don't need a printer.
Change-Id: I611edeca9cc9837eb49dddfe038595e1ff3b7239
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
The way _Component uses kwargs is handy to save a few characters, but it
doesn't play well with static analysis. When editing gdbarch.py, my
editor (which uses pylance under the hood) knows nothing about the
properties of components. So it's full of squiggly lines, and typing
analysis (which I find really helpful) doesn't work. I therefore think
it would be better to spell out the parameters.
Change-Id: Iaf561beb0d0fbe170ce1c79252a291e0945e1830
Reviewed-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
My editor flagged that the variable `c` (in the lines removed by this
patch) was unknown. I guess it ends up working because there is a `c`
variable in the global scope. I tried putting `assert False` inside
that if, and it is not hit, showing that we never enter this if. So,
remove it. There is no change in the generated files.
Change-Id: Id3b9f67719e88cada7c6fde673c8d7842ab13617
Reviewed-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
PR rust/30090 points out that a certain "finish" in a Rust program
will cause gdb to crash. This happens due to some confusion about
field indices in rust_language::print_enum. The fix is to use
value_primitive_field so that the correct type can be passed; other
spots in rust-lang.c already do this.
Note that the enclosed test case comes with an xfail. This is needed
because for this function, rustc doesn't follow the platform ABI.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30090
A range type can usually be treated the same as its underlying integer
type, at least for the purposes of agent expressions. This patch
arranges for range types to be handled this way in ax-gdb.c, letting a
somewhat larger subset of Ada expressions be compiled.
Ada historically has not implemented agent expressions, and some Ada
constructs probably cannot reasonably be converted to agent
expressions. However, a subset of simple operations can be, and this
patch represents a first step in that direction.
On one internal AdaCore test case, this improves the performance of a
conditional breakpoint from 5 minutes to 5 seconds.
The main tricky part in this patch is ensuring the converted
expressions detect the cases that will not work. This is done by
examining the code in the corresponding evaluation methods.
I noticed that "catch syscall group:process" doesn't catch clone3,
while it does catch clone.
The catch syscall group information is recorded in the
gdb/syscalls/linux-defaults.xml.in file, which says:
<!-- The group field information was based on strace. -->
So I looked at the strace sources, to confirm that clone3 is in fact
recorded in the "process" group there too, and to check what other
syscalls might be missing groups.
After some digging, I found that strace records the group info in C
arrays, with entries like:
...
[ 61] = { 4, TP, SEN(wait4), "wait4" },
[ 62] = { 2, TS|TP, SEN(kill), "kill" },
[ 63] = { 1, 0, SEN(uname), "uname" },
...
You can see the current master's table for Linux x86-64 here:
e88e5e9ae6/src/linux/x86_64/syscallent.h
The column with TS|TP above is what defines each syscall's groups. So
I wrote a script that extracts this information and generates
linux-defaults.xml.in.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I679d59d42fb2a914bf7a99e4c558e9696e5adff1
As 1fafeaac85, "line.s" and "Line.s" are
identical in case insensitive file systems. Thus, gas doesn't trigger
an input file switch.
gas/ChangeLog:
* testsuite/gas/elf/dwarf-5-macro.s: Change Line.s to Line2.s.
In C++ it is possible to use an empty enum as a strong typedef. For
example, a user could write:
enum class my_type : unsigned char {};
Now my_type can be used like 'unsigned char' except the compiler will
not allow implicit conversion too and from the native 'unsigned char'
type.
This is used in the standard library for things like std::byte.
Currently, when GDB prints a value of type my_type, it looks like
this:
(gdb) print my_var
$1 = (unknown: 0x4)
Which isn't great. This gets worse when we consider something like:
std::vector<my_type> vec;
When using a pretty-printer, this could look like this:
std::vector of length 2, capacity 2 = {(unknown: 0x2), (unknown: 0x4)}
Clearly not great. This is described in PR gdb/30148.
The problem here is in dwarf2/read.c, we assume all enums are flag
enums unless we find an enumerator with a non-flag like value.
Clearly an empty enum contains no non-flag values, so we assume the
enum is a flag enum.
I propose adding an extra check here; that is, an empty enum should
never be a flag enum.
With this the above cases look more like:
(gdb) print my_var
$1 = 4
and:
std::vector of length 2, capacity 2 = {2, 4}
Which look much better.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30148
Reviewed-By: Tom Tromey <tom@tromey.com>
When looking at some failures of gdb.linespec/cp-completion-aliases.exp,
I noticed that when a completion test will fail, it always fails with a
timeout. This is because most completion tests use gdb_test_multiple
and only add a check for the correct output. This commit adds new
options for both, tab and command completion.
For command completion, the new option will check if the prompt was
printed, and fail in this case. This is enough to know that the test has
failed because the check comes after the PASS path. For tab completion,
we have to check if GDB outputted more than just the input line, because
sometimes GDB would have printed a partial line before finishing with
the correct completion.
Approved-By: Tom Tromey <tom@tromey.com>
Replace a couple of uses of xmalloc and alloc with a gdb::byte_vector
local variable instead.
There should be no user visible changes after this commit.
Reviewed-By: Tom Tromey <tom@tromey.com>
The following commit added libopcodes styling for m68k:
commit c22ff44927
Date: Tue Feb 14 18:07:19 2023 +0100
opcodes: style m68k disassembler output
but didn't set disassemble_info::created_styled_output in
disassemble.c, which is needed in order for GDB to start using the
libopcodes based styling.
This commit fixes this small oversight. GDB now styles correctly.
I've long wanted to remove 'struct buffer', and thanks to Simon's
earlier patch, I was finally able to do so. My feeling has been that
gdb already has several decent structures available for growing
strings: std::string of course, but also obstack and even objalloc
from BFD and dyn-string from libiberty. The previous patches in this
series removed all the uses of struct buffer, so this one can remove
the code and the remaining #includes.
This changes top.c to use std::string rather than struct buffer. Like
the event-top.c change, this is not completely ideal in that it
requires a copy of the string.
This changes event-top.c to use std::string rather than struct buffer.
This isn't completely ideal, in that it requires a copy of the string
to be made.
The new DWARF cooked indexer interacts poorly with the DWARF index
cache. In particular, the cache will require gdb to wait for the
cooked index to be finalized. As this happens in the foreground, it
means that users with this setting enabled will see a slowdown.
This patch changes gdb to write the cache entry a worker thread. (As
usual, in the absence of threads, this work is simply done immediately
in the main thread.)
Some care is taken to ensure that this can't crash, and that gdb will
not exit before the task is complete.
To avoid use-after-free problems, the DWARF per-BFD object explicitly
waits for the index cache task to complete.
To avoid gdb exiting early, an exit observer is used to wait for all
such pending tasks.
In normal use, neither of these waits will be very visible. For users
using "-batch" to pre-generate the index, though, it would be.
However I don't think there is much to be done about this, as it was
the status quo ante.
The DWARF index does not need access to the objfile or per-objfile
objects when writing -- it's entirely based on the objfile-independent
per-BFD data.
This patch implements this idea by changing the entire API to only be
passed the per-BFD object. This simplifies some lifetime reasoning
for the next patch.
This patch removes some code that ensures that the BFD came from a
file. It seems to me that checking for the existence of a build-id is
good enough for the index cache.
On DOS systems, absolute paths start with the drive letter. This can
trigger failures in the regexp from dump tests, especially for those
checking for warnings or errors. They are usually skipping everything
before the first ":" as it has to be the file path.
| [^:]*: warning: ...
In order to avoid modifying many regexps to allow such drive letters,
prune them from all the outputs if they are found at the beginning of
a line.
binutils/ChangeLog:
* testsuite/lib/binutils-common.exp (prune_dump_output): New
(run_dump_test): Use it.
ld/ChangeLog:
* testsuite/ld-elf/noinit-sections-2.l: Remove DOS drive letter
handler.
Several insns have a (typically shorter) non-ModR/M and a (typically
longer) ModR/M encoding. In most cases the former is used by default.
This isn't too dissimilar from register-only insns sometimes having two
encoding forms. In those cases {load} or {store} can be used to control
the encoding used. Extend this to ModR/M-less encodings which have a
ModR/M counterpart (note that BSWAP hasn't). For insn reading and
writing their (explicit) memory operand, both prefixes are honored;
otherwise only the applicable one is.
Note that for some forms of XCHG, {store} has already been performing
this function, apparently as an unnoticed side effect of adding D to
the template.
The feature isn't universally available on 64-bit CPUs.
Note that in i386-gen.c:isa_dependencies[] I'm only adding it to models
where I'm certain the functionality exists. For Nocona and Core I'm
uncertain in particular.
While MOV to/from segment register as well as selector storing insns
already permit 32- and 64-bit GPR operands, selector loading insns and
ARPL do not. Split templates accordingly.
For shifts (but not ordinary rotates) and other cases where an immediate
describes e.g. a bit count or position, allowing negative operands is at
best confusing. An extreme example would be the two rotate-through-carry
insns, where a negative value would _not_ mean rotating the
corresponding number of bits in the other direction. To refuse such,
give meaning to the combination of Imm8 and Imm8S in templates (so far
these weren't used together anywhere). The issue was with
smallest_imm_type() blindly setting .imm8 for signed numbers determined
to fit in a byte.
VPROT{B,W,D,Q} is a little special: The rotate count there is a signed
quantity, so Imm8 is replaced by Imm8S. Adjust affected testcases
accordingly as well.
Another small adjustment to the testsuite is necessary: AAM and AAD were
never sensible to use with 0xffffff90 operands. This should have been an
error.
In a recent commit I've added:
...
require {expr [have_compile_flag -fsplit-stack]}
...
but actually the expr bit is unnecessary, and we can just use:
...
require {have_compile_flag -fsplit-stack}
...
Reported-By: Tom Tromey <tom@tromey.com>
Fix accesses to limited-length values in `contents_copy_raw' and
`contents_copy_raw_bitwise' so that they observe the limit of the
original allocation.
Reported by Simon Marchi as a heap-buffer-overflow AddressSanitizer
issue triggered with gdb.ada/limited-length.exp.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
The segfault was a symptom of messing with the absolute section next
field, confusing bfd_section_removed_from_list in linker.c:fix_syms.
That's not all that was going wrong. The INSERT list of output
sections was being inserted into itself, ie. lost from the main
list of linker statements.
PR 30155
* ldlang.c (process_insert_statements): Handle pathological
case of the insert script being inserted before the first
output section statement in the default script.
(output_prev_sec_find): Don't test section owner here.
(insert_os_after): Change parameter to a list union pointer.
(lang_insert_orphan): Test section owner here and adjust
insert_os_after call.