From patchwork Thu Apr 3 08:12:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hui Zhu X-Patchwork-Id: 396 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx23.g.dreamhost.com (mx2.sub5.homie.mail.dreamhost.com [208.113.200.128]) by wilcox.dreamhost.com (Postfix) with ESMTP id B9DC8360096 for ; Thu, 3 Apr 2014 01:12:38 -0700 (PDT) Received: by homiemail-mx23.g.dreamhost.com (Postfix, from userid 14314964) id 562C7621EAE0C; Thu, 3 Apr 2014 01:12:38 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx23.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx23.g.dreamhost.com (Postfix) with ESMTPS id 30814621EAE0C for ; Thu, 3 Apr 2014 01:12:38 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:subject :content-type:content-transfer-encoding; q=dns; s=default; b=QU5 p5BQ9MaIy5HD3IeCx7dfGLEQ3p73zXZneZowju4q4IidgB553GVXp2E1gxTZfsOH 9o+vuVaWAG62DrZI2XMZdq424uQf7HhF79qp4XfeB3KlSQMvHPzFrrsZ/4FIN6kl l+fu7Bq1x5AN8VCoSI2N3ZmeJIhBrw9BdZyeM14o= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:subject :content-type:content-transfer-encoding; s=default; bh=QZcZ/E+GH ZqRpZurFTrcvdy01AI=; b=fczpHXZxnvcRP09pF2LizDA4UErhm/35vbafBZdBx kSUC2smHuojnXrB9PlQLajSz/f4+97dsk0aMJmLks3e9azEfluVV7/BH3xbKF6tK 78U+sN1c/F+THO/Ks9ARTq6KphK1bKosfDLePG12kuzd5UdI5JFFnvllnUqARY3d J0= Received: (qmail 4600 invoked by alias); 3 Apr 2014 08:12:36 -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 4587 invoked by uid 89); 3 Apr 2014 08:12:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 03 Apr 2014 08:12:34 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1WVclC-0003lp-Q6 from Hui_Zhu@mentor.com for gdb-patches@sourceware.org; Thu, 03 Apr 2014 01:12:30 -0700 Received: from SVR-ORW-FEM-05.mgc.mentorg.com ([147.34.97.43]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Thu, 3 Apr 2014 01:12:30 -0700 Received: from localhost.localdomain (147.34.91.1) by svr-orw-fem-05.mgc.mentorg.com (147.34.97.43) with Microsoft SMTP Server id 14.2.247.3; Thu, 3 Apr 2014 01:11:18 -0700 Message-ID: <533D17E2.9070402@mentor.com> Date: Thu, 3 Apr 2014 16:12:18 +0800 From: Hui Zhu User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: gdb-patches ml Subject: [PATCH] Fix gdb.base/watch-vfork.exp: Watchpoint triggers after vfork (sw) (timeout) with Linux 2.6.32 and older version X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in Got gdb.base/watch-vfork.exp: Watchpoint triggers after vfork (sw) (timeout) with Linux 2.6.32 and older version. The rootcause is after the test use "set can-use-hw-watchpoints 0" let GDB doesn't use hardware breakpoint and set a watchpoint on "global", GDB continue will keep single step inside function "vfork". The Linux 2.6.32 and older version doesn't have commit 6580807da14c423f0d0a708108e6df6ebc8bc83d (get more info please goto http://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/commit/?id=6580807da14c423f0d0a708108e6df6ebc8bc83d). When the function "vfork" do syscall, the single step flag TIF_SINGLESTEP will copy to child process. Then GDB detach it, child process and parent process will be hanged. So I make a patch that do a single step before detach. Then TIF_SINGLESTEP of child process in old Linux kernel will be cleared before detach. Child process in new Linux kernel will not be affected by this single step. The patch was tested and pass regression in new linux kernel (3.13.6-200.fc20.x86_64) and old Linux kernel (2.6.32-38-server). Please help me review it. Thanks, Hui 2014-04-03 Hui Zhu * linux-nat.c (linux_child_follow_fork): do a single step before detach. --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -442,6 +442,26 @@ holding the child stopped. Try \"set de if (linux_nat_prepare_to_resume != NULL) linux_nat_prepare_to_resume (child_lp); + + /* When debug a inferior in the architecture that support + hardware single step and the Linux kernel without commit + 6580807da14c423f0d0a708108e6df6ebc8bc83d, the vfork child + process will starts with TIF_SINGLESTEP/X86_EFLAGS_TF bits + if the parent process has it. + So let child process do a single step under GDB control + before detach it to remove this flags. */ + + if (!gdbarch_software_single_step_p (target_thread_architecture + (child_lp->ptid))) + { + int status; + + if (ptrace (PTRACE_SINGLESTEP, child_pid, 0, 0) < 0) + perror_with_name (_("Couldn't do single step")); + if (my_waitpid (child_pid, &status, 0) < 0) + perror_with_name (_("Couldn't wait vfork process")); + } + ptrace (PTRACE_DETACH, child_pid, 0, 0); do_cleanups (old_chain);