This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH, ppc] Fix hw *points for embedded ppc in a threaded environment.
- From: Luis Gustavo <luis_gustavo at mentor dot com>
- To: gdb-patches at sourceware dot org
- Cc: prasad at linux dot vnet dot ibm dot com, benh at kernel dot crashing dot org
- Date: Mon, 06 Aug 2012 11:33:58 -0300
- Subject: [PATCH, ppc] Fix hw *points for embedded ppc in a threaded environment.
- Reply-to: "Gustavo, Luis" <luis_gustavo at mentor dot com>
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
2012-08-06 Luis Machado <lgustavo@codesourcery.com>
* 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);