From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1167 invoked by alias); 12 Oct 2010 18:59:46 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 1150 invoked by uid 22791); 12 Oct 2010 18:59:45 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Date: Tue, 12 Oct 2010 18:59:00 -0000 From: Oleg Nesterov To: archer@sourceware.org Subject: BUG? gdb, software watchpoints && multithreading Message-ID: <20101012185548.GA19475@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) X-SW-Source: 2010-q4/txt/msg00012.txt.bz2 I am trying to understand how ugdb can implement software watchpoints. I am looking at what gdb does, and I am a bit confused. Trivial test-case: #include #include #include struct { long v; char pad[256]; } VAR; void *tfunc(void *arg) { for (;;) ; } int main(void) { pthread_t thr; printf("pid: %d\n", getpid()); pthread_create(&thr, NULL, tfunc, NULL); for (;;) VAR.v++; return 0; } The sub-thread T does nothing but spins in the endless loop, the main M thread changes VAR. But, according to gdb, they both change VAR. (gdb) attach PID ... (gdb) watch VAR (gdb) c -a Continuing. Watchpoint 1: VAR Old value = {v = 394344995, pad = '\000' } New value = {v = 394344996, pad = '\000' } 0x0000000000400634 in tfunc (arg=0x0) at /tmp/BWP.c:11 11 { (gdb) Watchpoint 1: VAR Old value = {v = 394344996, pad = '\000' } New value = {v = 394344997, pad = '\000' } 0x0000000000400683 in main () at /tmp/BWP.c:26 26 VAR.v++; gdb resumes (steps) both threads. If T reports %Stop while M changes the memory, gdb notices the change and updates its copy of VAR. Then it reports that VAR was changed to the user. After that it inspects the stopped M and reads VAR again. Since the copy was already updated it concludes it wasn't changed. It resumes M again and only then notices another change. Not that I really blame gdb, without hardware support it is not possible to implement this 100% correctly. But I assume this is not what we want? IOW, I think that ugdb should do the following. If any thread changes VAR, then all threads should stop and report T05watch to gdb. Correct? Another question. watch/Z2 is always per-process, there is no "thread-local" watches, right? And the last one. If gdb sends '$Z2' to gdbserver, the running threads do not participate in monitoring, until gdb stops the thread and resumes it again, correct? Oleg.