From patchwork Fri Mar 16 14:06:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Roirand X-Patchwork-Id: 26338 Received: (qmail 106499 invoked by alias); 16 Mar 2018 14:07:02 -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 106482 invoked by uid 89); 16 Mar 2018 14:07:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_NEUTRAL autolearn=ham version=3.3.2 spammy= X-HELO: mail-wr0-f171.google.com Received: from mail-wr0-f171.google.com (HELO mail-wr0-f171.google.com) (209.85.128.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Mar 2018 14:07:00 +0000 Received: by mail-wr0-f171.google.com with SMTP id v65so11801842wrc.11 for ; Fri, 16 Mar 2018 07:07:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=7YJi81iYxG2MGy7FksRbW/CS1QZIMv0ugakkaxiaeZg=; b=tRXm/jWrYFpuZkFRP9TNvhQrziNDyHWqTXG2uGE63+RazzmAHV0uBmANk7rzlR98u3 ZljKbNp7vicOqJlZKYVK7zA03WjN3FpwL8lvHeaweZzIg0C1IOkmnDVZ6bEZc6X+S3KN m4XLY9Lp2xQ719Nwh7lVISI9XMPCzyS9PkHGRZUwcz4O0+Otx/tWkdWaG+Xl/yrPu/sY w/hzJm1CnIaDD4I7Hjw2JVB7VApZqx1bVOJoc3vV9gzGFSMLvyEAqBWvTAOHDVNimhV5 wzwJQT3BXZV4VHJNKF8uoy9rXU4GQHp28+ttRr/hqtW1RmhwDqhn3sVl7ZPE1nNAFSLn jeNw== X-Gm-Message-State: AElRT7E81WxBcaRetL6HYFR7YvgxR0QI+OfUGo88YSFjTTIy+rlHxwHP zATjbEtQ8DXqnUAqOJGlv3s+u/8K X-Google-Smtp-Source: AG47ELtfJOMVpy9dpqBuz5AxuceYGwge0PteNFEGGDxgBK4RSWBMvc9PKD4WGIXSjmMWdloKFEJ+Rg== X-Received: by 10.223.151.129 with SMTP id s1mr1863201wrb.206.1521209218177; Fri, 16 Mar 2018 07:06:58 -0700 (PDT) Received: from adacore.com ([46.18.100.10]) by smtp.gmail.com with ESMTPSA id 140sm8085584wmy.38.2018.03.16.07.06.56 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 16 Mar 2018 07:06:57 -0700 (PDT) Received: by adacore.com (sSMTP sendmail emulation); Fri, 16 Mar 2018 15:06:53 +0100 From: Xavier Roirand To: gdb-patches@sourceware.org Cc: brobecker@adacore.com, Xavier Roirand Subject: [RFA] (x86) Fix watchpoint using hardware breakpoint for some distro Date: Fri, 16 Mar 2018 15:06:52 +0100 Message-Id: <1521209212-11264-1-git-send-email-roirand@adacore.com> X-IsSubscribed: yes Running watch*.exp tests in gdb.base shows this: on x86_64/Ubuntu 16.04: # of expected passes 2631 # of unexpected failures 0 on x86_64/Ubuntu CentOS 5.11: # of expected passes 2535 # of unexpected failures 96 The problem can be easily shown in a debug session: (gdb) watch val Hardware watchpoint 2: val (gdb) c Continuing. Program received signal SIGTRAP, Trace/breakpoint trap. ... Whereas it should be: (gdb) watch val Hardware watchpoint 2: val (gdb) c Continuing. val before change = 0 Hardware watchpoint 2: val Old value = ... New value = ... The Linux target and gdbserver now check the siginfo si_code reported on a SIGTRAP to detect whether the trap indicates a hardware breakpoint was hit. Unfortunately, on some distro (CentOS 5, Suse 11) the returned si_code value is not equal to TRAP_HWBKPT when a hardware breakpoint is hit thus the hardware breakpoint is not handled as it should be, which is also the case for watchpoint when based on hardware breakpoint. This patch adds an additional check when the inferior reported a SIGTRAP in order to detect this case. No test have been created since all the existing ones are enough to validate the fix. BTW, with this fix, the tests results for the watchpoint tests are (for CentOS 5.11): # of expected passes 2630 # of unexpected failures 1 The remaining failure is located in watch-vfork test which explicitly disable the use of hardware breakpoint which is out of scope here. gdb/ChangeLog: * linux-nat.c (save_stop_reason): Add an additional check to detect hardware watchpoint. gdbserver/ChangeLog: * linux-low.c (save_stop_reason): Add an additional check to detect hardware watchpoint. For R309-004 Test: x86_64/gdb /ubuntu 16.04 x86_64/gdbserver/ubuntu 16.04 x86 /gdbs /ubuntu 16.04 x86 /gdbserver/ubuntu 16.04 x86_64/gdb /centos 5.11 x86_64/gdbserver/centos 5.11 x86 /gdb /centos 5.11 x86 /gdbserver/centos 5.11 Change-Id: I2546aca9827d9ae12ab86deb7aa4acc60c82b4b4 --- gdb/gdbserver/linux-low.c | 7 +++++++ gdb/linux-nat.c | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 2e5e19d..fe61026 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -866,6 +866,13 @@ save_stop_reason (struct lwp_info *lwp) if (!check_stopped_by_watchpoint (lwp)) lwp->stop_reason = TARGET_STOPPED_BY_SINGLE_STEP; } + else + { + /* The si_code is not TRAP_HWBKPT whereas it should + on some distro (CentOS 5, Suse 11) so still check + if stopped due to watchpoint. */ + check_stopped_by_watchpoint (lwp); + } } } #else diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 1bbad7b..0d97aa1 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -2798,6 +2798,13 @@ save_stop_reason (struct lwp_info *lp) the debug registers separately. */ check_stopped_by_watchpoint (lp); } + else + { + /* The si_code is not TRAP_HWBKPT whereas it should + on some distro (CentOS 5, Suse 11) so still check + if stopped due to watchpoint. */ + check_stopped_by_watchpoint (lp); + } } } #else