public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
* BUG? gdb, software watchpoints && multithreading
@ 2010-10-12 18:59 Oleg Nesterov
  2010-10-19 18:19 ` Oleg Nesterov
  0 siblings, 1 reply; 2+ messages in thread
From: Oleg Nesterov @ 2010-10-12 18:59 UTC (permalink / raw)
  To: archer

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 <stdio.h>
	#include <unistd.h>
	#include <pthread.h>

	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' <repeats 255 times>}
	New value = {v = 394344996, pad = '\000' <repeats 255 times>}
	0x0000000000400634 in tfunc (arg=0x0) at /tmp/BWP.c:11
	11	{
	(gdb) Watchpoint 1: VAR

	Old value = {v = 394344996, pad = '\000' <repeats 255 times>}
	New value = {v = 394344997, pad = '\000' <repeats 255 times>}
	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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: BUG? gdb, software watchpoints && multithreading
  2010-10-12 18:59 BUG? gdb, software watchpoints && multithreading Oleg Nesterov
@ 2010-10-19 18:19 ` Oleg Nesterov
  0 siblings, 0 replies; 2+ messages in thread
From: Oleg Nesterov @ 2010-10-19 18:19 UTC (permalink / raw)
  To: archer

On 10/12, Oleg Nesterov wrote:
>
> 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.

This can't help, see "Q: ugdb && watchpoints" I sent.

> 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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-10-19 18:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-12 18:59 BUG? gdb, software watchpoints && multithreading Oleg Nesterov
2010-10-19 18:19 ` Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).