Commit Graph

112718 Commits

Author SHA1 Message Date
Bruno Larsen
e24d337e21 gdb: add 'maintenance print record-instruction' command
While chasing some reverse debugging bugs, I found myself wondering what
was recorded by GDB to undo and redo a certain instruction. This commit
implements a simple way of printing that information.

If there isn't enough history to print the desired instruction (such as
when the user hasn't started recording yet or when they request 2
instructions back but only 1 was recorded), GDB warns the user like so:

(gdb) maint print record-instruction
Not enough recorded history

If there is enough, GDB prints the instruction like so:

(gdb) maint print record-instruction
4 bytes of memory at address 0x00007fffffffd5dc changed from: 01 00 00 00
Register eflags changed: [ IF ]
Register rip changed: (void (*)()) 0x401115 <main+15>

Approved-by: Eli Zaretskii <eliz@gnu.org>
Reviewed-by: Alexandra Hajkova <ahajkova@redhat.com>
Reviewed-by: Lancelot Six <lsix@lancelotsix.com>
Approved-by: Tom Tromey <tom@tromey.com>
2023-01-04 11:21:57 +01:00
Andreas K. Huettel
502c7218da Fix AArch64 linker testsuite failures trigeered by differences in build environments.
PR 29843
	* testsuite/ld-aarch64/bti-plt-5.d: Relax regxps slightly to allow
	for differences in build environments.
	* testsuite/ld-aarch64/tls-relax-gdesc-le-now.d: Likewise.
2023-01-04 09:30:14 +00:00
Mark Harmstone
8819b23615 Avoid unaligned pointer reads in PEP .idata section
This is something I discovered when working on aarch64, though it's
relevant to x86_64 too.

The PE32+ imports are located in the .idata section, which starts off
with a 20-byte structure for each DLL, containing offsets into the rest
of the section. This is the Import Directory Table in
https://learn.microsoft.com/en-us/windows/win32/debug/pe-format, which
is a concatenation of the .idata$2 sections. This is then followed by an
20 zero bytes generated by the linker script, which calls this .idata$3.

After this comes the .idata$4 entries for each function, which the
loader overwrites with the function pointers. Because there's no padding
between .idata$3 and .idata$4, this means that if there's an even number
of DLLs, the function pointers won't be aligned on an 8-byte boundary.

Misaligned reads are slower on x86_64, but this is more important on
aarch64, as the e.g. `ldr x0, [x0, :lo12:__imp__func]` the compiler
might generate requires __imp__func (the .idata$4 entry) to be aligned
to 8 bytes. Without this you get IMAGE_REL_ARM64_PAGEOFFSET_12L overflow
errors.
2023-01-04 03:47:09 +00:00
Alan Modra
6f3674d7e5 Merge config/picflag.m4 from gcc
and regen libiberty/configure
2023-01-04 13:23:54 +10:30
Tsukasa OI
bd87d4ef88 sim: Regenerate using the maintainer mode
Those files have changed by regenerating using the maintainer mode.
The first line of sim/ppc/pk.h have changed by an effect of the commit
319e41e83a ("sim: ppc: inline the sim-packages option").
2023-01-04 02:14:51 +00:00
GDB Administrator
e346efcde0 Automatic date update in version.in 2023-01-04 00:00:12 +00:00
Max Filippov
e80512c8d8 opcodes: xtensa: fix jump visualization for FLIX
opcodes/
	* xtensa-dis.c (print_insn_xtensa): Add local variables
	insn_type, target and imm_pcrel to track control flow across
	multiple slots.
2023-01-03 13:30:57 -08:00
Max Filippov
39086586b7 opcodes: xtensa: implement styled disassembly
opcodes/
	* xtensa-dis.c (print_xtensa_operand)
	(print_insn_xtensa): Replace fprintf_func with
	fprintf_styled_func.
2023-01-03 13:30:57 -08:00
Tom Tromey
a7d5fcaf8e Add test case for "finish" with variably-sized types
This adds a test case for "finish" with variably-sized types, and for
inferior calls as well.  This also extends the "runto" proc to handle
temporary breakpoints.
2023-01-03 08:45:01 -07:00
Tom Tromey
3360bae61f Use value_at_non_lval in get_call_return_value
get_call_return_value can handle RETURN_VALUE_STRUCT_CONVENTION,
because the call is completely managed by gdb.  However, it does not
handle variably-sized types correctly.  The simplest way to fix this
is to use value_at_non_lval, which does type resolution.
2023-01-03 08:45:01 -07:00
Tom Tromey
911627e7b1 Fix inferior calls with variably-sized return type
This patch updates the gdbarch_return_value_as_value implementations
to work correctly with variably-sized return types.
2023-01-03 08:45:01 -07:00
Tom Tromey
5cb0f2d5b6 Convert selected architectures to gdbarch_return_value_as_value
This converts a few selected architectures to use
gdbarch_return_value_as_value rather than gdbarch_return_value.  The
architectures are just the ones that I am able to test.  This patch
should not introduce any behavior changes.
2023-01-03 08:45:01 -07:00
Tom Tromey
12bb802fab Don't let property evaluation affect the current language
On PPC, we saw that calling an inferior function could sometimes
change the current language, because gdb would select the call dummy
frame -- associated with _start.

This patch changes gdb so that the current language is never affected
by DWARF property evaluation.
2023-01-03 08:45:01 -07:00
Tom Tromey
7f22044a6b Introduce value_at_non_lval
In some cases, while a value might be read from memory, gdb should not
record the value as being equivalent to that memory.

In Ada, the inferior call code will call ada_convert_actual -- and
here, if the argument is already in memory, that address will simply
be reused.  However, for a call like "f(g())", the result of "g" might
be on the stack and thus overwritten by the call to "f".

This patch introduces a new function that is like value_at but that
ensures that the result is non-lvalue.
2023-01-03 08:45:01 -07:00
Tom Tromey
43f2b4583f Don't emit gdbarch_return_value
The previous patch introduced a new overload of gdbarch_return_value.
The intent here is that this new overload always be called by the core
of gdb -- the previous implementation is effectively deprecated,
because a call to the old-style method will not work with any
converted architectures (whereas calling the new-style method is will
delegate when needed).

This patch changes gdbarch.py so that the old gdbarch_return_value
wrapper function can be omitted.  This will prevent any errors from
creeping in.
2023-01-03 08:45:00 -07:00
Tom Tromey
4e1d2f5814 Add new overload of gdbarch_return_value
The gdbarch "return_value" can't correctly handle variably-sized
types.  The problem here is that the TYPE_LENGTH of such a type is 0,
until the type is resolved, which requires reading memory.  However,
gdbarch_return_value only accepts a buffer as an out parameter.

Fixing this requires letting the implementation of the gdbarch method
resolve the type and return a value -- that is, both the contents and
the new type.

After an attempt at this, I realized I wouldn't be able to correctly
update all implementations (there are ~80) of this method.  So,
instead, this patch adds a new method that falls back to the current
method, and it updates gdb to only call the new method.  This way it's
possible to incrementally convert the architectures that I am able to
test.
2023-01-03 08:45:00 -07:00
Tom Tromey
862ebb27bb Fix crash in amd64-tdep.c
amd64-tdep.c could crash when 'finish'ing from a function whose return
type had variable length.  In this situation, the value will be passed
by reference, and this patch avoids the crash.

(Note that this does not fully fix the bug reported, but it does fix
the crash, so it seems worthwhile to land independently.)
2023-01-03 08:45:00 -07:00
Tom de Vries
b46632ca16 [gdb/testsuite] Add xfail in gdb.arch/i386-pkru.exp
On a x86_64-linux machine with pkru register, I run into:
...
(gdb) PASS: gdb.arch/i386-pkru.exp: set pkru value
info register pkru^M
pkru           0x12345678          305419896^M
(gdb) FAIL: gdb.arch/i386-pkru.exp: read value after setting value
...

This is a regression due to kernel commit e84ba47e313d ("x86/fpu: Hook up PKRU
onto ptrace()").  This is fixed by recent kernel commit 4a804c4f8356
("x86/fpu: Allow PKRU to be (once again) written by ptrace.").

The regression occurs for kernel versions v5.14-rc1 (the first tag containing
the regression) up to but excluding v6.2-rc1 (the first tag containing the fix).

Fix this by adding an xfail for the appropriate kernel versions.

Tested on x86_64-linux.

PR testsuite/29790
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29790
2023-01-03 16:41:05 +01:00
Tom Tromey
5aea5eca6c Do not use PyObject_CallNoArgs
PyObject_CallNoArgs was introduced in Python 3.9, so avoid it in favor
of PyObject_CallObject.
2023-01-03 07:13:01 -07:00
Himal
a8cf07d37b Fix a potential problem in the BFD library when accessing the Windows' nul device driver.
PR 29947
	* bfdio.c (_bfd_real_fopen): Do not add a prefix to the Windows'
	nul device filename.
2023-01-03 12:07:16 +00:00
Nick Clifton
e8b4b7b258 Fix a translation problem in the x86 assembler.
PR 29952
	* config/tc-i386.c (md_assemble): Avoid constructing translatable
	strings.
2023-01-03 12:03:02 +00:00
Nick Clifton
11982f9f8b Updated translations for various languages and sub-directories 2023-01-03 11:32:42 +00:00
Luis Machado
a8f175d9d0 Add new NT_ARM_ZA and NT_ARM_SSVE register set constants. 2023-01-03 11:15:26 +00:00
Andrew Burgess
08fd407675 [gdb] Fix segfault during inferior call to ifunc
With a simple test-case:
...
$ cat test.c
char *p = "a";
int main (void) {
  return strlen (p);
}
$ gcc -g test.c
...
we run into this segfault:
...
$ gdb -q -batch a.out -ex start -ex "p strlen (p)"
Temporary breakpoint 1 at 0x1151: file test.c, line 4.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Temporary breakpoint 1, main () at test.c:4
4	  return strlen (p);

Fatal signal: Segmentation fault
...

The strlen is an ifunc, and consequently during the call to
call_function_by_hand_dummy for "p strlen (p)" another call
to call_function_by_hand_dummy is used to resolve the ifunc.

This invalidates the get_current_frame () result in the outer call.

Fix this by using prepare_reinflate and reinflate.

Note that this series (
https://inbox.sourceware.org/gdb-patches/20221214033441.499512-1-simon.marchi@polymtl.ca/ )
should address this problem, but this patch is a simpler fix which is easy to
backport.

Tested on x86_64-linux.

Co-Authored-By: Tom de Vries <tdevries@suse.de>
PR gdb/29941
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29941
2023-01-03 10:18:48 +01:00
Mike Frysinger
fdbd297027 sim: sh: move some generated source files to built sources
This should have been part of the previous commit 80636a54bc
("sim: build: move generated headers to built sources"), but they were
missed because they're .c files effectively treated as .h files.
2023-01-02 22:48:13 -05:00
Mike Frysinger
7c9a934c4d sim: build: add var for tracking sim enable directly
Rather than rely on SIM_SUBDIRS being set, add a dedicated variable
to track whether to enable the sim.  While the current code works
fine, it won't work as we remove the recursive make logic (i.e. the
SIM_SUBDIRS variable).
2023-01-02 22:40:49 -05:00
Mike Frysinger
127d167a98 sim: common: drop libcommon.a linkage
All of these objects should be in libsim.a already, so don't link to
it too.  In practice it never gets used, but no point in listing it.
2023-01-02 22:21:01 -05:00
Mike Frysinger
80636a54bc sim: build: move generated headers to built sources
Automake's automatic header deptracking has a bootstrap problem where
it can't detect generated headers when compiling.  We've been handling
that by adding a custom SIM_ALL_RECURSIVE_DEPS variable, but that only
works when building objects recursively in subdirs.  As we move those
out to the top-level, we don't have any recursive steps anymore.  The
Automake approach is to declare those headers in BUILT_SOURCES.

This isn't completely foolproof as the Automake manual documents: it
only activates for `make all`, not `make foo.o`, but that shouldn't be
a huge limitation as it only affects the initial compile.  After that,
rebuilds should work fine.
2023-01-02 21:16:19 -05:00
Mike Frysinger
3b89a7b8ce sim: cgen: drop common subdir build rules
Now that everything has been hoisted to the top-level, we can delete
this unused logic.
2023-01-02 20:31:56 -05:00
Mike Frysinger
f1a0a99c04 sim: or1k: hoist cgen rules to top-level 2023-01-02 20:31:54 -05:00
Mike Frysinger
cf764309dc sim: m32r: hoist cgen rules to top-level 2023-01-02 20:31:29 -05:00
Mike Frysinger
869585833a sim: lm32: hoist cgen rules to top-level 2023-01-02 20:30:54 -05:00
Mike Frysinger
d5dd8f5d16 sim: iq2000: hoist cgen rules to top-level 2023-01-02 20:30:20 -05:00
Mike Frysinger
cd313814aa sim: frv: hoist cgen rules to top-level 2023-01-02 20:29:52 -05:00
Mike Frysinger
3298ee7a2c sim: cris: hoist cgen rules to top-level 2023-01-02 20:29:21 -05:00
Mike Frysinger
3abb19ad7e sim: bpf: hoist cgen rules to top-level 2023-01-02 20:28:08 -05:00
Mike Frysinger
93b937c903 sim: cgen: hoist rules to the top-level build
The rules seem to generate the same output as existing subdir cgen
rules with cgen ports, so hopefully this should be correct.  These
are the last set of codegen rules that we run in subdirs, so this
will help unblock killing off subdir builds entirely.
2023-01-02 20:26:27 -05:00
Mike Frysinger
4d4996a55e sim: build: use Automake include vars
Rather than define our own hack for emitting an include statement,
use the existing Automake include variables.  These have the nice
side-effect of being more portable.
2023-01-02 19:30:22 -05:00
GDB Administrator
eb9afa6362 Automatic date update in version.in 2023-01-03 00:00:11 +00:00
Tom Tromey
ce6fcad80e Simplify debug_exp
debug_exp should call expression::dump rather than using the 'op'
member.
2023-01-02 10:37:15 -07:00
Tom Tromey
de7d7cb58e Initial implementation of Debugger Adapter Protocol
The Debugger Adapter Protocol is a JSON-RPC protocol that IDEs can use
to communicate with debuggers.  You can find more information here:

    https://microsoft.github.io/debug-adapter-protocol/

Frequently this is implemented as a shim, but it seemed to me that GDB
could implement it directly, via the Python API.  This patch is the
initial implementation.

DAP is implemented as a new "interp".  This is slightly weird, because
it doesn't act like an ordinary interpreter -- for example it doesn't
implement a command syntax, and doesn't use GDB's ordinary event loop.
However, this seemed like the best approach overall.

To run GDB in this mode, use:

    gdb -i=dap

The DAP code will accept JSON-RPC messages on stdin and print
responses to stdout.  GDB redirects the inferior's stdout to a new
pipe so that output can be encapsulated by the protocol.

The Python code uses multiple threads to do its work.  Separate
threads are used for reading JSON from the client and for writing JSON
to the client.  All GDB work is done in the main thread.  (The first
implementation used asyncio, but this had some limitations, and so I
rewrote it to use threads instead.)

This is not a complete implementation of the protocol, but it does
implement enough to demonstrate that the overall approach works.

There is a rudimentary test suite.  It uses a JSON parser written in
pure Tcl.  This parser is under the same license as Tcl itself, so I
felt it was acceptable to simply import it into the tree.

There is also a bit of documentation -- just documenting the new
interpreter name.
2023-01-02 09:49:37 -07:00
Jonas Hoerberg
c43d829bca Fix target remote pipe command for MinGW
The cced7cacec ("gdb: preserve `|` in connection details string")
commit added '|' detection and removal to ser-pipe.c, but missed to add it
to ser-mingw.c.

This results in the error message below for MinGW hosts:
error starting child process '| <executable> <args>': CreateProcess: No such file or directory

This commit add the missing '|' detection and removal to ser-mingw.c.
2023-01-02 07:58:58 -07:00
Tom Tromey
dacf80765d Remove target: prefix from gdb_sysroot in find_separate_debug_file
I noticed that, when using gdbserver, gdb might print:

Reading /usr/lib/debug/lib64//libcap.so.2.48-2.48-4.fc36.x86_64.debug from remote target...
Reading target:/usr/lib/debug/lib64//libcap.so.2.48-2.48-4.fc36.x86_64.debug from remote target...

The second line has the "target:" prefix, but from the code it's clear
that this string is being passed verbatim to gdbserver -- which seems
wrong.

I filed PR remote/29929 for this.

The problem here is that find_separate_debug_file uses gdb_sysroot
without checking to see if it starts with the "target:" prefix.  This
patch changes this code to be a little more careful.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29929
2023-01-02 06:48:31 -07:00
Tom de Vries
b9877acc81 [gdb/testsuite] Fix gdb.python/py-breakpoint.exp with libstdc++ debug info
On x86_64-linux, I run into:
...
(gdb) python hbp1 = gdb.Breakpoint("add", type=gdb.BP_HARDWARE_BREAKPOINT)^M
Hardware assisted breakpoint 2 at 0x40072e: add. (7 locations)^M
(gdb) FAIL: gdb.python/py-breakpoint.exp: test_hardware_breakpoints: \
  Set hardware breakpoint
...
due to libstdc++ debug info:
...
$ gdb -q -batch outputs/gdb.python/py-breakpoint/py-breakpoint \
  -ex start \
  -ex "b add" \
  -ex "info break"
Temporary breakpoint 1 at 0x40076a: file py-breakpoint.c, line 50.

Temporary breakpoint 1, main (argc=1, argv=$hex) at py-breakpoint.c:50
50        int foo = 5;
Breakpoint 2 at 0x40072e: add. (7 locations)
Num     Type           Disp Enb Address            What
2       breakpoint     keep y   <MULTIPLE>
2.1                         y   0x000000000040072e in add(int) at \
  py-breakpoint.c:39
2.2                         y   0x00007ffff7b131de in \
  (anonymous namespace)::fast_float::bigint::add at \
  ../../../../../libstdc++-v3/src/c++17/fast_float/fast_float.h:1815
  ...
2.7                         y   0x00007ffff7b137e4 in \
  (anonymous namespace)::fast_float::bigint::add at \
  ../../../../../libstdc++-v3/src/c++17/fast_float/fast_float.h:1815
...

Fix this by using qualified=True.

Tested on x86_64-linux.
PR testsuite/29910
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29910
2023-01-02 11:59:17 +01:00
Mike Frysinger
c217e3d54e sim: replace -I$srcroot/bfd include with -I$srcroot
Clean up includes a bit by making ports include bfd/ headers
explicitly.  This matches other projects, and makes it more clear
where these headers are coming from.
2023-01-01 23:17:07 -05:00
Mike Frysinger
60a1031181 sim: replace -I$srcroot/opcodes include with -I$srcroot
Clean up includes a bit by making ports include opcodes/ headers
explicitly.  This matches other projects, and makes it more clear
where these headers are coming from.
2023-01-01 23:14:19 -05:00
Alan Modra
3002e78a7d obsolete target tidy
Delete a few files only used for obsolete targets, and tidy config,
xfails and other pieces of support specific to those targets.  And
since I was editing target triplets in test files, fix the nm
alpha-linuxecoff fails.
2023-01-02 14:03:22 +10:30
GDB Administrator
e2a3b3256f Automatic date update in version.in 2023-01-02 00:00:08 +00:00
Mike Frysinger
33383d1674 sim: build: drop unused SIM_EXTRA_LIBS
Now that all run binaries are linked in the topdir, this subdir libs
variable isn't used anywhere, so punt it.
2023-01-01 17:46:15 -05:00
Mike Frysinger
2a1b3235f2 sim: erc32: drop -I$(srcroot)
Since the port doesn't actually use this include, drop it.
No other port is doing this either.
2023-01-01 17:43:25 -05:00