Bug 587470

Summary: Windows Softdebugger implementation consumes 100% CPU
Product: [Mono] Mono: Runtime Reporter: andreas flucke <andreas.flucke>
Component: debugAssignee: Jonathan Chambers <joncham>
Status: RESOLVED FIXED QA Contact: Mono Bugs <mono-bugs>
Severity: Normal    
Priority: P5 - None CC: forgotten_vxPDddArjq, joncham, taktaktaktaktaktaktaktaktaktak
Version: 2.6.x   
Target Milestone: ---   
Hardware: x86   
OS: Windows XP   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Bug Depends on:    
Bug Blocks: 594193    
Attachments: test program, run using gtest.exe <app to debug>
New stripped gtest
GTest with ReadLine :-)

Description andreas flucke 2010-03-11 13:12:37 UTC
User-Agent:       Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)

When using the Mono.Debugger.Soft in Windows, the CPU usage is 100 percent (of one core) mostly waiting in VirtualMachine.GetNextEvent()


Reproducible: Always

Steps to Reproduce:
1.
2.
3.
Comment 1 Forgotten User vxPDddArjq 2010-03-11 20:45:09 UTC
Are you using mono 2.6.2 ? If so, there were a large amount of fixes to the soft debugger which will be in the upcoming mono 2.6.3.
Comment 2 andreas flucke 2010-03-12 07:12:49 UTC
I'm now using 2.6.1 with monocharge-20100303.
So i guess this isn't solved yet.
(Is there a way of getting a 2.6.2 release for win without compiling ?)
Comment 3 Forgotten User vxPDddArjq 2010-03-12 20:25:22 UTC
Unfortunately, we don't have daily builds of the windows installer.
Comment 4 Forgotten User vxPDddArjq 2010-03-21 01:20:35 UTC
Could you try with the newly released mono 2.6.3 ?

http://www.go-mono.com/mono-downloads/download.html
Comment 5 andreas flucke 2010-03-21 08:08:36 UTC
Already done - result without change.
Comment 6 Forgotten User vxPDddArjq 2010-04-03 01:08:39 UTC
So I tested this on windows using 2.6.3 with a command line test program, and it runs fine. Could you create a test case which reproduces the problem ?
Comment 7 andreas flucke 2010-04-03 08:44:18 UTC
Thanks for investigating this.
Surely i cannot claim to have a perfect implementation.
The reason for posting this was that the same program/implementation
runs without this problem under OpenSuse Linux.
I cannot post my implementation here because it's to complex (and it's surely not your task to find somebody elses bugs :-)
But if you would be able to send me your implementation i can see what's the difference and maybe work out the point which causese this behavior.
Comment 8 Forgotten User vxPDddArjq 2010-04-03 09:50:05 UTC
Created attachment 352330 [details]
test program, run using gtest.exe <app to debug>
Comment 9 andreas flucke 2010-04-04 16:00:09 UTC
Created attachment 352351 [details]
New stripped gtest

Seems i've leaded you in the wrong direction.
Waiting in GetNextEvent isn't the point.
The problem occurs when the vm is suspended.
In the modified testcase i've inserted a stupid Console.ReadLine(), which normally doesn't cost CPU usage, but in this case.
Comment 10 Forgotten User vxPDddArjq 2010-04-04 16:39:06 UTC
That testcase doesn't contain a Console.ReadLine (). Also, what is the app which needs to be debugged for the problem to occur ?
Comment 11 andreas flucke 2010-04-05 07:40:58 UTC
Created attachment 352378 [details]
GTest with ReadLine :-)

Sorry, i picked the wrong one.
Comment 12 Forgotten User vxPDddArjq 2010-04-05 16:45:34 UTC
I can reproduce this now. It looks the debuggee is spinning, not the debugger process.
Comment 13 Forgotten User vxPDddArjq 2010-04-05 19:51:24 UTC
Jonathan, could you look at this ? I can't debug anything under windows.

Basically, when running the testcase in the last attachment, like this:

mono test.exe hello.exe

the debuggee starts to spin when it is suspended, consuming 100% cpu and/or crashes.
Comment 14 Jonathan Chambers 2010-04-05 19:58:13 UTC
I'll take a look at it.
Comment 15 Forgotten User vxPDddArjq 2010-04-05 20:12:11 UTC
It seems to be spinning here:

#ifdef HOST_WIN32
		if (WAIT_TIMEOUT == WaitForSingleObject(suspend_cond, 0))
		{
			mono_mutex_unlock (&suspend_mutex);
			Sleep(0);
			mono_mutex_lock (&suspend_mutex);
		}
		else
		{
		}
Comment 16 Jonathan Chambers 2010-04-07 18:36:18 UTC
Looking at this.
Comment 17 andreas flucke 2010-04-28 06:31:31 UTC
Windows Softdebugger doesn't work any more with 2.6.4 :-)
After loading the assemblies there's an unspecified NullReferenceException.
Should i file a bug or is this a temporarily side effect ?
Comment 18 andreas flucke 2010-04-28 06:35:53 UTC
What i meant was :-(
Comment 19 Forgotten User vxPDddArjq 2010-04-28 13:55:19 UTC
No idea, the debugger is not really tested under windows. Also, its possible that that NullReferenceException is thrown by your code, not the debugger code.
Comment 20 andreas flucke 2010-04-28 14:12:16 UTC
No. Just use the testcase to reproduce this.
Comment 21 Jonathan Pobst 2010-04-28 18:50:23 UTC
I can reproduce the NRE in 2.6.4.

It appears to be in the runtime.  If I copy the 2.6.3 mono.dll on top of my 2.6.4 install, the issue goes away.
Comment 22 Jonathan Chambers 2010-05-09 19:54:40 UTC
Fixed in HEAD and backported to 2-6 in r156908.
Comment 23 Jonathan Chambers 2010-05-09 21:20:06 UTC
NullReferenceException fixed in 2.6 branch at r156975.
Comment 24 andreas flucke 2010-08-04 14:18:03 UTC
While the NRE seems to be fixed in 2.6.7, the CPU usage remains 100% :-(
So this should be reopen.
Comment 25 Jonathan Chambers 2010-11-20 13:55:13 UTC
Still exists in HEAD. Code in question is used because mono_cond_wait is not implemented correctly for Windows.

Google shows a few ways to implement condition variables for Windows. Section 3.4 seems to be the recommended approach.

http://www.cs.wustl.edu/~schmidt/win32-cv-1.html

At Vista, MS added support for condition variables to Win32 API.
http://msdn.microsoft.com/en-us/library/ms682052(VS.85).aspx

Should we use Win32 ones on Vista+, and another implementation on XP and before?
Comment 26 Forgotten User vxPDddArjq 2010-11-20 16:21:44 UTC
The problem with using the vista functions is that it would require us to compile different binaries for vista.
Comment 27 Levi Bard 2010-11-23 15:28:31 UTC
I'm seeing the high cpu usage as well, when the runtime is suspended during a debugging session on windows.
(Windows 7 64bit, in my case)
Comment 28 Forgotten User vxPDddArjq 2010-11-23 20:07:41 UTC
Changing that line to Sleep(1) or Sleep(2) would help mitigate the issue.
Comment 29 Levi Bard 2010-12-30 13:13:22 UTC
Can we not dynamically check for those functions at runtime, and fallback to the current implementation (also with nonzero sleep)?
Comment 30 Forgotten User vxPDddArjq 2011-02-11 01:06:04 UTC
Fixed in HEAD/2.10/2.6 branches by using a Sleep(1) instead of Sleep(0).