From patchwork Thu May 10 19:35:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew D'Addesio X-Patchwork-Id: 27207 Received: (qmail 34002 invoked by alias); 10 May 2018 19:35:14 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 33988 invoked by uid 89); 10 May 2018 19:35:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.2 required=5.0 tests=AWL, BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=launch, world!, rewind X-HELO: mail-qt0-f181.google.com Received: from mail-qt0-f181.google.com (HELO mail-qt0-f181.google.com) (209.85.216.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 10 May 2018 19:35:12 +0000 Received: by mail-qt0-f181.google.com with SMTP id f1-v6so4106929qtj.6 for ; Thu, 10 May 2018 12:35:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=OU5WoReDRvq4dtJaukjWTWt1EzF2ZELGv8QHmjJFTV8=; b=tfGQhRZbIBWz3rxmQf0kudhM8gBNhOhFjwiyZx0O8SwdPW5Jf9H6NjV3f97J3a+fu8 8BvseKFOEKoTq9IW/peNt+NTvU2dYDJ38o8dAvf8S1HSeVSnesqyn/ILd6TGeF5m505S Wvzn5Lt1DrS2myuCwTIvWHu9FBCYNX6uknXEt/NoiLghh4G0XgTr8JjGuIsuaHDWr4FY PNQ4uHkJlcTln/GI+dANY+D7j68WvWWQp5BHWhxvd24AT9YjI7V9XOUO+vqWmrB+cMIE BWTnseD84Lx3sjk9NIwVbgrYYqme3aZC/GErdmyIVWUxIgmObZ2qFXl6BuFnJpi50gvc O6RA== X-Gm-Message-State: ALKqPwfp1qKCMjRG5Yp37DZ+RyNvtkrbsQqitnQ9AxDroCx6TVHp81hZ 4bBlYSKuNSmIMqKbwm8s+0C2yP/OxqqBzXxjuopqgg== X-Google-Smtp-Source: AB8JxZoPrFd3nXGu6p8qR2DmPuUv7ZAtsOg7DHfKmLGAqsdSOecozRtbP0EeCsavkhB9kWXHiDduS++XxydMfKXhXgo= X-Received: by 2002:ac8:389b:: with SMTP id f27-v6mr2849650qtc.9.1525980910262; Thu, 10 May 2018 12:35:10 -0700 (PDT) MIME-Version: 1.0 Received: by 10.237.52.103 with HTTP; Thu, 10 May 2018 12:35:09 -0700 (PDT) In-Reply-To: <1525980536-26548-1-git-send-email-modchipv12@gmail.com> References: <1525980536-26548-1-git-send-email-modchipv12@gmail.com> From: "Andrew D'Addesio" Date: Thu, 10 May 2018 14:35:09 -0500 Message-ID: Subject: Re: [PATCH] Process record: Log %rax after syscall under amd64-linux To: gdb-patches@sourceware.org Cc: "Andrew D'Addesio" 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 .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 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 > > * 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 > 1c1 < Test Run By daddesio on Thu May 10 12:52:45 2018 --- > Test Run By daddesio on Thu May 10 13:26:51 2018 48196c48196 < FAIL: gdb.multi/multi-term-settings.exp: inf1_how=attach: inf2_how=attach: stop with control-c (the program is no longer running) --- > FAIL: gdb.multi/multi-term-settings.exp: inf1_how=attach: inf2_how=attach: stop with control-c 48206c48206 < FAIL: gdb.multi/multi-term-settings.exp: inf1_how=attach: inf2_how=tty: stop with control-c --- > PASS: gdb.multi/multi-term-settings.exp: inf1_how=attach: inf2_how=tty: stop with control-c 56094c56094 < PASS: gdb.threads/non-ldr-exit.exp: program exits normally --- > KFAIL: gdb.threads/non-ldr-exit.exp: program exits normally (PRMS: gdb/18717) 56713c56713 < KFAIL: gdb.threads/process-dies-while-handling-bp.exp: non_stop=on: cond_bp_target=1: inferior 1 exited (prompt) (PRMS: gdb/18749) --- > KFAIL: gdb.threads/process-dies-while-handling-bp.exp: non_stop=on: cond_bp_target=1: inferior 1 exited (memory error) (PRMS: gdb/18749) 56717c56717,56718 < KFAIL: gdb.threads/process-dies-while-handling-bp.exp: non_stop=on: cond_bp_target=0: inferior 1 exited (prompt) (PRMS: gdb/18749) --- > PASS: gdb.threads/process-dies-while-handling-bp.exp: non_stop=on: cond_bp_target=0: inferior 1 exited > PASS: gdb.threads/process-dies-while-handling-bp.exp: non_stop=on: cond_bp_target=0: no threads left 56726c56727,56728 < KFAIL: gdb.threads/process-dies-while-handling-bp.exp: non_stop=off: cond_bp_target=0: inferior 1 exited (prompt) (PRMS: gdb/18749) --- > PASS: gdb.threads/process-dies-while-handling-bp.exp: non_stop=off: cond_bp_target=0: inferior 1 exited > PASS: gdb.threads/process-dies-while-handling-bp.exp: non_stop=off: cond_bp_target=0: no threads left 57142c57144 < FAIL: gdb.threads/signal-while-stepping-over-bp-other-thread.exp: step (pattern 3) --- > PASS: gdb.threads/signal-while-stepping-over-bp-other-thread.exp: step 58389,58390c58391,58392 < # of expected passes 54578 < # of unexpected failures 1623 --- > # of expected passes 54583 > # of unexpected failures 1621 58393c58395 < # of known failures 65 --- > # of known failures 64