From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16977 invoked by alias); 6 Aug 2012 14:33:50 -0000 Received: (qmail 16962 invoked by uid 22791); 6 Aug 2012 14:33:49 -0000 X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 06 Aug 2012 14:33:36 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1SyONA-0002Dq-Ri from Luis_Gustavo@mentor.com ; Mon, 06 Aug 2012 07:33:32 -0700 Received: from NA1-MAIL.mgc.mentorg.com ([147.34.98.181]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 6 Aug 2012 07:33:32 -0700 Received: from [0.0.0.0] ([172.16.63.104]) by NA1-MAIL.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 6 Aug 2012 07:33:31 -0700 Message-ID: <501FD5D6.30005@mentor.com> Date: Mon, 06 Aug 2012 14:33:00 -0000 From: Luis Gustavo Reply-To: "Gustavo, Luis" User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.28) Gecko/20120313 Lightning/1.0b2 Thunderbird/3.1.20 MIME-Version: 1.0 To: gdb-patches@sourceware.org CC: prasad@linux.vnet.ibm.com, benh@kernel.crashing.org Subject: [PATCH, ppc] Fix hw *points for embedded ppc in a threaded environment. Content-Type: multipart/mixed; boundary="------------060305050104040403030406" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-08/txt/msg00173.txt.bz2 This is a multi-part message in MIME format. --------------060305050104040403030406 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1371 Hi, GDB has always assumed that hardware watchpoints and breakpoints should be replicated for every new thread in ppc. This worked fine for the old DABR-based mechanism since both server and embedded ppc's supported only a single hw watchpoint or breakpoint. With the somewhat recent booke kernel interface, more hw watchpoints/breakpoints are available to GDB. The logic of replicating the existing process' debug state to the new thread is still there though, but the new booke interface in the kernel already replicates that state. More precisely, the kernel gives the new thread the debug state of its parent thread. When GDB tries to replicate the debug state, it will actually cause the kernel to allocate a new hw *point entry, leading to inadequate consumption of hw debug resources. It's still unclear if the kernel is supposed to do this and i'm chasing answers with the ppc linux kernel folks (https://lists.ozlabs.org/pipermail/linuxppc-dev/2012-August/100083.html). Nonetheless, the kernel is out and it has such behavior. This patch tries to address this problem by clearing any debug state prior to replicating *points to the new thread. If the kernel is doing something it's not supposed to, then this is a workaround for the broken kernels. This would be nice to include before 7.5, as it's an annoying problem. OK? Regards, Luis --------------060305050104040403030406 Content-Type: text/x-patch; name="0001-fix_ppc_hw_watch.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-fix_ppc_hw_watch.diff" Content-length: 1467 2012-08-06 Luis Machado * ppc-linux-nat.c (ppc_linux_new_thread): Clear the new thread's debug state prior to replicating existing hardware watchpoints or breakpoints. Index: gdb_head/gdb/ppc-linux-nat.c =================================================================== --- gdb_head.orig/gdb/ppc-linux-nat.c 2012-08-06 11:02:12.538532628 -0300 +++ gdb_head/gdb/ppc-linux-nat.c 2012-08-06 11:04:38.486536320 -0300 @@ -2179,7 +2179,21 @@ ppc_linux_new_thread (struct lwp_info *l /* Copy that thread's breakpoints and watchpoints to the new thread. */ for (i = 0; i < max_slots_number; i++) if (hw_breaks[i].hw_break) - booke_insert_point (hw_breaks[i].hw_break, tid); + { + /* The ppc Linux kernel causes a thread to inherit its parent + thread's debug state, and that includes any hardware + watchpoints or breakpoints that the parent thread may have set. + + For this reason, the debug state of the new thread is cleared + before trying to replicate any hardware watchpoints or + breakpoints contained in other threads. */ + + /* The ppc debug resource accounting is done through "slots". + Ask the kernel the deallocate this specific *point's slot. */ + ptrace (PPC_PTRACE_DELHWDEBUG, tid, 0, hw_breaks[i].slot); + + booke_insert_point (hw_breaks[i].hw_break, tid); + } } else ptrace (PTRACE_SET_DEBUGREG, tid, 0, saved_dabr_value); --------------060305050104040403030406--