Breakpoint: Break when c++ exception is thrown - why so slow? - c++

Using Qt Creator, Qt 5.3, VC12 (VS2013)
When I set a "Break when c++ exception is thrown" breakpoint in Qt creator, my application becomes extremely slow. Maybe 5-10 slower than running with other breakpoints such as "File name and line number"
Why is debugging with this kind of breakpoint so slow? Just curious ..
-- Edit --
As of CR's comment, do I face an abnormality on my system?

It is a problem with the Microsoft-provided debugger that you have downloaded to use with Qt Creator. The debugger that Qt Creator uses is not the visual studio debugger, since the latter IIRC can't be easily used externally. Unfortunately there's nothing that Qt Creator could do to improve things, I don't think, short of using a non-existent port of, say, lldb.

Related

Setting breakpoints in release mode in Qt creator

I am using Qt creator and cdb debugger for my c++ project. I need to set some breakpoints in code and see what happens during runtime. Unfortunately because of some third party library I absolutely can not use Debug mode so I have to stick to the release mode.
In visual studio I always do such thing and use breakpoints in the release mode easily but how could I do that in Qt creator?
(Versions: Qt 5.12 / Qt creator 4.8)
Try using a "Profile" build in Qt Creator. That will include separate debugging line information in a "Release" (optimized) build. You can then launch it using the Debug button in Qt Creator and set breakpoints as you need.
Caveats:
You may not be able to get the exact line you want because of optimizations by the compiler.
You most variables will be optimized into registers, so you can't view them. If you need to view registers, try the good, old fashion method of printing their values out with a qDebug() statement. (When in doubt, print it out.)

QStrings not showing when debugging with Qt Creator on Windows

I'm debugging a Qt 5.5 application with Qt Creator on Windows 10 using MSVC 2013 compiler.
CDB Debugger is set up in Qt Creator and I can start the debug session. However variable contents of Qt objects (QStrings...) can not be inspected, I just get the memory location, size etc.
I expect I'm missing for debugging helpers or the debugger extension mentioned here.
Any clues what to do?
I temporarily deleted qtcreatorcdbext.dll, started debugger (forcing to diplay an error) and moved the dll back. Now everything works.
It seems there was a problem with the setup procedure, maybe because debugging tools were installed after Qt Creator.
I had to update qtcreatorcdbext.dll in /lib/qtcreatorcdbext32 folder. My Qt creator installed separatly from the Qt pack so I copied the dll from the Qt installation/tools/qtcreator/lib/qtcreatorcdbext32 to the separatly installed qtcreator

Qt Creator can't break on thrown exceptions (when using CDB as debugger)

I set Qt Creator to break when a C++ exception is thrown:
I then tested it with this code:
try {
throw std::runtime_error("error");
} catch (std::exception &e) {
qDebug("%s", e.what());
}
But it didn't break on throw std::runtime_error("error");. I'm using CDB, not GDB, because I'm using the MSVC Kit.
Edit: There is another question where CDB is working for the OP, even if slowly. So it should work in principle. My configuration is: Qt Creator 3.3.0, compiling with Qt4/MSVC 9.0 (x86), the debugger is CDB 6.2.9200.16384.
Edit 2: This is what I'm getting in the CDB log window (I made a diff between the CDB log with and without the breakpoint):
<bu100400 CxxThrowException
<!qtcreatorcdbext.breakpoints -t 1 -v
<!qtcreatorcdbext.pid -t 2
dATTEMPT SYNC
d*** Bp expression 'CxxThrowException' contains symbols not qualified with module name.
1 breakpoint(s) pending...
*** Unable to resolve unqualified symbol in Bp expression 'CxxThrowException' from module 'C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.18201_none_ec80f00e8593ece5\comctl32.dll'.
Full CDB log (in case needed): http://pastebin.com/jhNRy9bE
Edit 3: #HansPassant's explained why it fails in the comments:
Keep in mind that you are using a very old version of MSVC++, big changes at VS2012. The pastebin shows it being out of sync pretty badly, never getting to the DLL that contains __CxxThrowException#8 (MSVCR90D.dll) before the exception is thrown. It is simple with the sxe debugger command, automatic break when any exception is thrown.. Maybe you shouldn't be using QT's UI at all, it looks too gimpy. – Hans Passant 10 hours ago
Just look at the trace, the debugger shows what DLLs it is searching for "CxxThrowException". It never gets to msvcr90d.dll. And the exception is thrown while it is searching for the symbol after which it all ends. Completely out of sync. – Hans Passant 56 mins ago
I'll just write up why this is going wrong, a workaround is going to be difficult to find. The debugger trace in your pastebin tells the tale.
The basic issue is that the communication between the debugger and the QT front-end is rather poor. And in your case it gets out of sync, QT doesn't wait long enough for the debugger to complete the command. QT tries to set a breakpoint on the msvcr90d.dll!__CxxThrowException#8 function, the one that raises a C++ exception in the Microsoft CRT. This function can be present in more than one executable file if the program uses multiple CRTs. A pretty common mishap, caused by building with /MT. And sometimes intentional if you use a well-isolated DLL that you interface with by using COM.
This takes a while as you might imagine, the complaint in the linked question, the debugger has to plow through the symbol information for every DLL that's loaded. It will take especially long if the PDB for the DLL needs to be downloaded from the symbol server and doesn't otherwise get cached so it is available the next time you debug. Not your issue afaict, it does setup the cache location to C:\Users\sasho\AppData\Local\Temp\symbolcache. Go have a look-see to verify that you do see PDBs for the operating system DLLs there.
This operation is tricky, the debugger doesn't give a good signal that it is done searching the DLLs. What the QT should do is verify the debugger feedback against the list of DLLs it obtained. It does not do that, it issues the g command before the debugger is done searching. Could be a timeout that is too short but it actually looks like QT doesn't count on the debugger performing this command in the background. A convenience to a human, not exactly very helpful here :)
There ought to be a way to configure CDB to not perform this search in the background. This is well-hidden, I don't see anything in the debugger.chm help file but it probably wasn't updated in a while. Google doesn't help either. I'd recommend you ask a question about it. Most significantly perhaps is that you have a rather major mismatch in version numbers. The compiler you use is 2008 vintage, the debugger is quite new, SDK 8.0 version, I can't tell what QT version you use.
So a possible workaround is to intentionally use an older version of CDB, one that's more likely to have been tested with the QT front-end version you use. Download the corresponding SDK version, version 6.0 matches the VS2008 time frame. I think the "Debugging Tools for Windows" was still a separate download back then and not yet included in the SDK. Another workaround is to stop relying on the friendly QT front-end and learn to drive CDB from the command prompt. Moderately more useful is WINDBG, uses the same debugging engine but has a GUI interface. Just moderate, it is still mostly prompt driven. You do lose several days of your life learning the commands however. Getting the debugger to break when an exception is thrown is trivial, use the sxe command.

Show command prompt with Qt Creator and CMake

The dev environment in question consists of:
Windows 7
MinGW (g++)
CMake
Qt Creator
The problem is that Qt Creator, a lovely IDE as far as I can tell, does not display programs' command-line output. It seems to have its own proprietary debug pane, but it doesn't give me, for example, runtime errors. It just tells me that the program has failed and gives me the exit code. I'm using Creator only for its C++ capabilities, and not using Qt in any way, so the proprietary pane is useless to me.
So I ask this: Can something be done? Am I missing something really, stupidly obvious like a built-in command line? Or, if not, can I at least use some filthy and/or repulsive hack to get it to display the Windows command prompt upon running a program?
Last thing; I did do some research, and found a way to edit the Qt project file to display the prompt, but... I'm using CMake, not Qt projects. So that doesn't answer my question. If I can do something similar with CMakeLists.txt, that would be wonderful. But Google has failed me on that front, so I'm not holding out too much hope.
EDIT:
I'm specifically worried about runtime errors. cout and printf are rerouted to Qt Creator's window, so that's fine. I don't get runtime errors unless the debugger catches them, and the frequency of that is less than ideal.
Windows GUI programs don't have standard output.
In Windows there are two possible entry points in the standard runtime. The console one and the windows one. The console one will inherit console window from parent process or create a new one and connect the standard input/output/error streams to it, while the windows one will leave them unconnected unless they were explicitly redirected by the invoking process. A Qt application is (probably; you could have console Qt-Core application) a GUI application and Qt Creator (nor any other Windows IDE) does not redirect the output explicitly. Therefore the standard output is not open at all and the writes are being discarded.
However windows have separate logging facility for debugging purpose. This is what you see in the debug window. You can write to it using the native OutputDebugString API. I am sure you can also direct the Qt debug log there.
Note, that when it tells you the program has exited with status 0, it means the program ran, which in turn means it compiled successfully and thus there were no errors from g++. There may have been warnings, in which case you should see them in the appropriate other window. Compiler and program output are different things; the IDE does read the compiler output.

QT Creator - breakpoint not persistent for every build

I'm trying to use QT Creator for an open-source project I downloaded from github.
After some fuddling around I managed to get the project to compile in QT Creator and run in debug mode.
However, I have an issue : strangely the breakpoints that I set are only available for that instance for the debug run for QT Creator. When I stop the debugging, and relaunch the debugging, the previously stated breakpoints are still there, but they are no longer valid. (meaning Qt Creator skips over them). I've verified that new breakpoints are still valid - it's the old ones that become invalid even though they are still listed.
I did not even update any code, just added breakpoints, hit debug and the old breakpoints became invalid even though they are still showing.
No sacarsm intended, but is this a "feature"? If so, how do I turn it off?
If not a feature, what can I try?
It's very painful to re-add breakpoints every time I run a debug.
Using Mac OSX 10.9 here, Qt 5.2, with Qt Creator 3.0 for Mac.
Thanks.
EDIT : Some more info. I realised that whenever the breakpoint works, it has a tiny hour glass next to it, like in the picture. What does the hour glass mean? It could just be something dumb that I'm not doing....
in the end I filed a bug with Qt Creator. For those interested pls check here.
https://bugreports.qt-project.org/browse/QTCREATORBUG-11184