2

I normally work with Qt Creator for my C++ needs. When an assertion in my program fails, it can show me which assertion failed. In Visual Studio, I only see this:

Failed assertion

I can click Retry to jump into the application, but it doesn't tell me which assertion failed. Even for a simple assert(false) Visual Studio tries to show me the source code for msvcr100d.dll, which isn't available.

How can I find out which assertion in my program failed? I really don't want to do a cumbersome manual search using a combination of breakpoints and std::couts for something that can be tracked down automatically.

Edit: Visual Studio did in fact generate a .PDB file for me, but it still isn't working. Although the debugger won't highlight the line with the failed assertion, I do see Assertion failed: false, file main.cpp, line 8 on the command line. Why can't it just show me the line and let me inspect the variables? I mean, all the information appears to be available...

Pieter
  • 31,619
  • 76
  • 167
  • 242

1 Answers1

6

All you should have to do is click "Retry" to break into the application's source code with the debugger. That will highlight the line containing the assertion that failed, so it's easy to see the culprit unless you like to cram multiple nested assertions onto a single line. And if you do, then you deserve all the pain that this might cause you.

The reason it's not working for you now is more than likely because you don't have the debugging symbols available from your application's current build. When you build an app with the compiler bundled with Visual Studio, depending on your project settings, it will generate a .PDB file, which contains the debug symbols. These are required to get useful information while debugging, such as what line produced the last failure.

Make sure that when you compile your application, you have it set to generate debug symbols. You should see a .PDB file in your /bin directory. As discussed here, the generation of debug symbols is orthogonal to whether optimizations are enabled (the configuration typically known as "Release").

Update: I just realized you're probably compiling/building the app in Qt Creator, and then trying to debug the binaries from Visual Studio. That's not going to work out well—if you don't compile using VS's tools, it's not going to generate debug symbols that the VS debugger can read.

I assume the problem would be the same in reverse: if you built with Visual Studio, then tried to debug with Qt Creator, it probably wouldn't be able to interpret the debugging symbols, either.

Therefore, I'd recommend sticking with a single toolset for building. It doesn't matter which IDE you use, but you'll need to compile/build with the same tools. You can configure either Qt Creator or Visual Studio to use the compiler and linker bundled with the other. Typically Qt Creator comes with a Win32 port of GCC, but it's trivial to get it to build with Microsoft's toolset instead, which would allow you to use VS to debug your code.

Community
  • 1
  • 1
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • This is what "Retry" gets me after executing `assert(false)`: http://i.imgur.com/w1zFL.png I don't see how this is helpful in any way. Can't Visual Studio just highlight the line where my assertion failed like Qt Creator does? – Pieter May 25 '12 at 09:31
  • @Pieter Yes, that's what my answer talks about. The error message says: *"No Source Available: No symbols are loaded for any call stack frame. [Thus,] The source code cannot be displayed"*. You fix that by generating debug symbols so that the VS debugger can find them. Presumably your settings in Qt Creator cause this to happen by default, but you've configured VS *not* to generate debug information. You need to change those settings. Once you do, VS will behave exactly as Qt Creator does now. I use this all the time. – Cody Gray - on strike May 25 '12 at 09:33
  • Oh sorry, I first thought you were talking about getting the debug symbols for the DLL. I didn't try to open this Visual Studio project in Qt Creator, by the way. I already have [this](http://i.imgur.com/fSrxK.png) setting enabled, but it doesn't fix the issue for me. What am I missing? A Google search for *visual studio 2010 generate debug symbols* didn't return anything I could use. – Pieter May 25 '12 at 10:38
  • I tried the steps outlined [here](http://msdn.microsoft.com/en-us/library/fsk896zz.aspx) followed by cleanup and rebuild, but it didn't resolve the issue. I verified that I'm using a Debug build. – Pieter May 25 '12 at 12:31
  • You *are* getting a stack, but the functions in the stack are in the system dlls. You need to right-click in the call stack window and select "Symbol Settings" and then opt to load the symbols from the Microsoft Symbol Servers. Then if you scroll up the callstack you should see something more meaningful in your own code – the_mandrill May 28 '12 at 10:53
  • @the_mandrill I followed your steps and I can now jump to the failed assertion. It's odd that I have to download additional debug symbols to walk through my own code but hey, it works now. Thanks a lot! – Pieter May 31 '12 at 18:04
  • 1
    I suspect that your own code would always have been visible if you scrolled far enough. Having the symbols for the system dlls is hugely useful though and gives you far more information for debugging in general. VS is pretty good at caching them and retrieving new ones when it needs to. – the_mandrill May 31 '12 at 21:01