I have a small Win32 console application and when executing from the debugger the console takes about five seconds to appear. If I place a breakpoint on the last line of main, the break point is hit immediately, so the application is already finished but the console does not appear for about five seconds. I have removed all my breakpoints using 'Remove All Breakpoints', restarted Visual Studio. No dice. The console appears very quickly launching outside of the debugger, using CTRL-F5. Any ideas?
Thanks
Debugging an application causes all sorts of notifications to be sent to the debugger - all DLL loads, thread creates, etc. The debugger may be loading symbols during this time as well. All of this will slow down the launch of the process and it'll take longer to get to the point where it creates the console.
Related
I have a simple batch script running constantly on a Windows 10 PC at work that performs relatively simple tasks over and over again throughout the day, basically testing certain server diagnostics while I'm working on it.
Every once in a while, the program will crash, so I have another program I downloaded that will auto-start up the program if it does crash and close.
However, there is one scenario where instead of the program just crashing and closing completely, a message box will pop up saying the program has stopped responding, with a 'Close Program' button. In this case, the auto-start program I have thinks the program is still running, so it won't attempt to re-run the batch script.
Is there a way to auto close the program when it crashes this way, or something that will automatically click the 'Close Program' button for me when it appears?
I suspect the messages comes out when the main thread hangs for too long. It may be cleaner to spawn another thread to take care of expensive / slow computation, Windows should not bother to kill the main thread (and your program) in first place like that.
Recently my Visual Studio started to experience a delay before the program Starts Without Debugging.
This happens only when the following are met:
Console application
Start Without Debugging
There has been any change in the editor window from the last time program run.
After pressing Ctrl+F5 console application window opens and the cursor is active, but the execution is delayed.
The delay seems to be consistent in length (7-10 seconds), and not depend on the size of the code. I have checked two different installations of VS (2013 and 2015) on the same computer and the problem persists.
I have also checked that this delay occurs even for an empty Main().
There is a possibility that I have enabled some kind of an option/function in VS that causes this very specific delay, but I am not sure when this issue started occurring so I cannot trace back the change.
What could be the reason for this delay?
I will be grateful for help in this matter.
I made many attempts to diagnose the issue of the delay and one of the times that I pressed ctrl + F5 I have spotted a window opening in the background.
(It was definitely not visible everytime i tried to run without debugging).
It turns out that a functionality of Avira anti-virus had been scanning the code before it run for the first time. That is why when I made no changes to the code there was no delay.
Avira "Protection Cloud" is the name of the functionality responsible for the delays.
Link to Avira page about it and how to disable it: https://www.avira.com/en/support-for-home-knowledgebase-detail/kbid/1514
Sometimes if I have multiple editting windows open, this slows starting and stopping the debugger. Close all but those you are interested in and try again.
I want to capture a stacktrace of an application which sometimes stops responding for few minutes.
When the application stops responding, the windows desktop also stops responding to mouse clicks, although some other already running applications are working fine at that time (for example windbg works fine, ProcessExplorer refreshes its screen, but does not respond to mouse events).
While the application is non responsive, it is actually taking about 80% of one CPU core. That is why I would like to get a stacktrace.
The misbehaving application usually takes about 2-3 minutes to do its strange job or if Ctrl+Esc is pressed it becomes responsive immediately (and the start menu opens of course...)
I have WinDbg attached to the misbehaving application and when I issue the Break command, the break-in does not happen until the application starts to respond again.
From what I understand the break-in actually creates a remote thread which pretty soon calls DbgBreakPoint.
What could be preventing debugger's thread from executing?
EDIT:
First of all thanks for your help!
I was also thinking that this might be caused by a bad device driver or something that installs a system wide hook somewhere.
I was thinking to enable kernel debugging and get a stack trace from the kernel for the offending thread or enable manual bluescreen trigger to produce a dump and look at that afterwards.
Process Explorer and Process Monitor does not reveal anything interesting. They also become unusable when the bug is triggered (updating their windows but not responsive to mouse or keyboard).
EDIT2:
Background info:
App uses QT, OpenGL and also DirectSound and runs on Windows 7 SP1 x64
I am currently suspecting something with the graphics part.
The strange thing is that if a system-wide lock is taken (like GDI Lock), this would prevent drawing of other Windows, but that does not happen. WinDbg on same machine works fine. ProcessExplorer updates but does not receive mouse clicks, Desktop updates but no mouse clicks.
I currently have a kernel debugger attached...
EDIT3
ETW was most useful for debugging. It turns out that Qt's main event processing loop goes crazy. PeekMessage and MsgWaitForMultipleObjectsEx (with 0 timeout) gets called in a tight loop. That is where the high CPU usage comes from.
It looks like the App is generating/getting loads of messages at that time. But it is not easy to see what the messages are (or I don't know how to access function parameters in ETW). Using a debugger also does not help much but, with a breakpoint in the QT's event loop leads me to believe that WM_TIMER messages are the culprit.
Given that the desktop also misbehaves during this time, it sounds like your app isn't necessarily misbehaving but merely aggravating a bug elsewhere (e.g., in a device driver or some crummy anti-malware code that has injected itself into other processes). Stack traces from your app may or may not be very revealing.
If the problem is easily reproducible, I'd set a breakpoint somewhere in the "middle" of the app and see if the problem happens before or after that. Then move the breakpoint until you find the last instruction your app executes before things go bonkers. Figuring out what your app does that triggers this behavior may give a clue as what's going on.
Another option is to try using some system-wide debugging tools. First, I'd peak in the Event Viewer to see if there are suspicious error or warning events posting in proximity to the moment the machine goes haywire. Then I'd try a tool like Sysinternal's Process Monitor or Process Explorer to get a better view of what's happening. You might also try ETW to capture a system-wide trace of what's happening on the system that you can study after the fact. (ETW can be hard to use, so check out Bruce Dawson's UIforETW.)
Use ETW to find the cause. Install the Windows Performance Toolkit (part of the Win10 v1511 SDK: https://go.microsoft.com/fwlink/p/?LinkID=698771 which is the last version that works in Win7), run WPRUI.exe, select CPU Usage and click on Start.
After you captured the hang, click on Save. Wait until WPRUI is finished, open the ETL in WPA, setup and load debug symbols in WPA.
Drag & Drop the CPU Usage (Precise) graph to analyse pane and look for WAIT (µs) max for your process to see that long hang and expand the stack to see where it happens.
We have configured WER (Windows Error Reporting) to create dumps every time some applications crash.
It normally works but we have found several scenarios where it does not work. We will take as an example Winword.exe:
On some cases the process simply disappears. No window, no event log, no crash dump. Nothing.
On other cases a window telling you that the application has stopped working appears but automatically the application gets restarted and no crash dump is generated too.
Other times the application ends as expected with the "Application stopped working" and it works normally.
Any idea about why this happens and how to trap these crashes and generate a dump?
Visual Studio 2005 C++
Windows XP Pro
I have a sample application that I am testing, that links with boost libraries.
However, the program runs ok. However, when I try and stop the program by clicking the 'Stop Debugging' button. The program ends, but the console window remains open. So I have many of them, as during my testing I am starting and stopping the application.
Even when I try and close it by clicking the close button it has no affect. And it doesn't seem to appear under task manager when the program ends.
The only way I can close them if I reboot windows.
I am thinking it might be a thread that has not closed, and maybe that is keeping the console windows open.
Many thanks for any advice,
I have also seen this issue, I think it happens when a mutex or semaphore is still locked, or a thread hasn't cleanly exited. The only way I've found to prevent this is to make sure all mutexes/ semaphores/threads are cleaned up after before stopping the debugger.
Also it's interesting to note that this problem doesn't happen on Windows 7 or Linux. I have tried stopping the same program at the same places and the program always cleanly exits.
Good luck and happy coding!