[PATCH] Process record: Log %rax after syscall under amd64-linux
Andrew D'Addesio
modchipv12@gmail.com
Thu May 10 19:59:00 GMT 2018
Hi all,
This is my first patch for gdb, so if there are any issues with my
patch, just tell me and I'll fix it.
Here's a longer explanation of the bug I'm fixing:
Description:
While recording execution using the "record" command under 64-bit Linux,
gdb forgets to log the return value (%rax) after executing a 'syscall'
instruction. If the user seeks backwards to before the syscall (via
"record goto"), %rax will not revert to the old value.
Steps to reproduce the bug:
1. Compile the following hello world using:
gcc -Wall -nostartfiles -o helloworld helloworld.S
#include <asm/unistd.h>
.intel_syntax noprefix
.global _start
.data
msg:
.ascii "hello, world!\n"
msg_end:
.text
_start:
mov rax, __NR_write
mov rdi, 1 # STDOUT_FILENO
lea rsi, [rip + msg]
mov rdx, (msg_end - msg)
syscall
mov rax, __NR_exit
mov rdi, 0 # EXIT_SUCCESS
syscall
2. Launch gdb using: gdb ./helloworld
3. Execute these commands:
break _start
run
record
stepi 4
# %rax is 0x1 just before executing the syscall
disassemble
info reg
stepi
# %rax is 0xe just after executing the syscall
disassemble
info reg
record goto 4
# Oops! %rax is still 0xe when we rewind to before the syscall.
disassemble
info reg
Notes:
* The existing code tries to save the return value, but it only saves
%rcx and %r11, not %rax.
* On other archs (i386-linux-tdep.c, etc.), we do properly save the
return value. Grep the *-tdep.c files for this comment:
/* Record the return value of the system call. */
* Passing test suite results are attached.
Andrew
On Thu, May 10, 2018 at 2:28 PM, Andrew D'Addesio <modchipv12@gmail.com> wrote:
> Log the return value after executing a system call instruction, as
> we do for other archs (i386-linux, arm-linux, etc.)
>
> gdb/ChangeLog:
> 2018-05-10 Andrew D'Addesio <modchipv12@gmail.com>
>
> * amd64-linux-tdep.c (amd64_linux_syscall_record_common): Record
> %rax.
> ---
> gdb/amd64-linux-tdep.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
> index 2bd3d31..917ecf5 100644
> --- a/gdb/amd64-linux-tdep.c
> +++ b/gdb/amd64-linux-tdep.c
> @@ -1510,6 +1510,9 @@ amd64_linux_syscall_record_common (struct regcache *regcache,
>
> record_regs:
> /* Record the return value of the system call. */
> + if (record_full_arch_list_add_reg (regcache, AMD64_RAX_REGNUM))
> + return -1;
> + /* Record registers clobbered by the 'syscall' instruction. */
> if (record_full_arch_list_add_reg (regcache, AMD64_RCX_REGNUM))
> return -1;
> if (record_full_arch_list_add_reg (regcache, AMD64_R11_REGNUM))
> --
> 2.7.4
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gdb.sum.diff
Type: text/x-patch
Size: 2127 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20180510/da094011/attachment.bin>
More information about the Gdb-patches
mailing list