Is it possible to skip STL Code when using the C++ debugger (native, x64) in Visual Studio 2012? Quite often when debugging C++ code I step into STL code. I expect that the STL code provided by Microsoft is correct - I am not interested in debugging it - I am only interested in debugging my own (self-written) code.
For instacne when setting a break point at this function:
foo(std::make_shared<int>(6));
where foo is defined as:
void foo(std::shared_ptr<int> x)
{
// do something
}
I do not want to dive into the details of std::make_shared - what I want is to step directly into the function foo. But this seems not to be possible. If the breakpoint at foo(std::make_shared<int>(6)); is reached and I press the 'Step Into' button (or F11) it first steps into the 'memory' header file (STL):
So again I have to press the 'Step Out' button than again the 'Step Into' button to get into the foo function. What I want is to skip the STL related parameter initialization or a possibility to jump directly into the function.
There's Step Into Specific available on the right-click menu:
Though for a single argument, I'll more often do Step Into + Step Out + Step Into from the keyboard instead of navigating the menus for Step Into Specific.
An unofficial registry key for always stepping over certain code is described in an MSDN blog post, How to Not Step Into Functions using the Visual C++ Debugger.
With Visual Studio, whenever you are about to step into a function, you can actually right-click onto the statement and select in a cascaded menu called "Step Into Specific" the destination you want to reach. You can then bypass copy constructor/getter/etc. passed as argument to the function. See http://msdn.microsoft.com/en-us/library/7ad07721(v=vs.100).aspx for more information.
For new version of Visual Studio like VS2019, we have new chosen: Just my code
https://learn.microsoft.com/en-us/visualstudio/debugger/just-my-code?view=vs-2019
There used to be a registry key to do that, but this has changed in VS2012:
Visual Studio 2012 (dev11)
Everything has changed! Until the VC++ team put something on their blog (feel free to bug them to do this), take a peek at this file:
C:\Program Files[ (x86)]\Microsoft Visual Studio 11.0\Common7\Packages\Debugger\Visualizers\default.natstepfilter
For VS 2013 and 2015, the Just my code setting, known from .NET projects, was extended to work for native C++ too.
Move the STL call (make_shared) outside of foo, and pass the result into foo. Then the breakpoint set on the call to foo should be beyond that STL code. Otherwise could you not put the breakpoint inside the foo definition itself?
Related
I'm building a game in UE5 with C++. If you have access to the Unreal Engine source code (get it here), I'm hitting an assertion on this line: https://github.com/EpicGames/UnrealEngine/blob/d9d435c9c280b99a6c679b517adedd3f4b02cfd7/Engine/Plugins/Runtime/StateTree/Source/StateTreeModule/Private/StateTreeExecutionContext.cpp#L682
When I look at the Visual Studio debugger it shows the assertion error:
Array index out of bounds: 65533 from an array of size 5
But when I look at the Locals window that array index (stored in CurrentStatus.State.Index) has a value of2, not 65533. How can this be?
The relevant source code is:
for (FStateTreeHandle Handle = CurrentStatus.State; Handle.IsValid(); Handle = StateTree->States[Handle.Index].Parent)
{
const FBakedStateTreeState& State = StateTree->States[Handle.Index];
...
}
The assertion is hit the first time through the for loop when calling StateTree->States[Handle.Index], so Handle.Index is getting the value CurrentStatus.State.Index (which is 2).
If I click into the frame where it's validating the array index, the Locals window does show Index is 65533.
See a screenshot of this issue here: Visual Studio debugger
Per this screenshot the variable Handle was optimized away, but it seems it was optimized to have the wrong value. I can't imagine this is a bug in the C++ compiler, so what else could it be?
Turns out the comments on the question gave me the right clue here:
The bottom line is that you cannot simply debug optimized code, and expect the debugger to adjust itself to the optimizations done by the compiler.
When I debugged using a non-optimized build of UE5, I quickly saw the issue, and the CurrentStatus.State.Index is in fact 65533.
In case others run into this, it's not enough to use the "DebugGame Editor" config in the Visual Studio project for your game. That config only compiles your game's code without optimizations, the engine is still run using optimized code.
To run the engine without optimized code, you need to build it from source and use the "Debug Editor" Visual Studio config to disable optimizations. Then you can run your game by changing the path of the UE exe it uses in the Visual Studio project of your game from the project Property Pages under the Debugging section.
Sometimes when using the data viewer in debug mode in Visual Studio 2010 (C++), I cannot see the data. I can see the data of many other variables, but not the one shown below. The element below is an array. How do I get rid of the "(error)" messages and see the data?
Update: I wrote a member function called "view". If I jump into the function call, the debugger works fine and I can see all the class variables. So maybe this is an issue with the debugger following pointers.
Is your object "test" one of standard STL class (vector, set, etc..)?
If yes, usually you should get also size in debugger tooltip - and this looks like corrupted autoexp.dat file.
If you did some modification in autoexp.dat, then try to revert it back and check if this helps.
I'm using visual studio for kernel debugging. Yes, I know all the tutorials say to use WinDbg, but visual studio is actually spectacular now for Kernel debugging. It's a more recent development.
When I have a pointer in the watch window, assuming it is an array, I would like to see multiple items in its list at once as a drop down. Normally in Visual Studio you would add ",AMOUNT" after the pointer to get multiple items, but this does not work when in kernel debugging mode.
Is this option available?
[Edit] As requested, I have attached an example image. In the watch window I have included multiple attempts to access the data in the "ProcessPath" variable.
During Kernel Mode Debugging, Watch window appears to work through WinDBG expression evaluator. That is, it works pretty much the same as WinDBG's Watch window. Therefore, your question is not really Visual Studio related, but rather it boils down to WinDBG's watch.
This is why ,amount syntax will result in showing amount as result - WinDBG treats , as "evaluate and discard", just like c++ does. This also explains why you prepend variables with $! which is WinDBG syntax for local variables.
While WinDBG supports quite a bit of c++ syntax, it will unfortunately fail to recognize c++ cast-to-array syntax such as (char(*)[4])$!ProcessPath (by the way, this works when debugging a usermode target in in VS debugger).
I have not found a single way to cast to array in WinDBG. It seems the only workaround available is to add specific elements of array to watch, like
ProcessPath[0]
ProcessPath[1]
ProcessPath[2]
ProcessPath[3]
ProcessPath[4]
ProcessPath[5]
ProcessPath[6]
ProcessPath[7]
ProcessPath[8]
I'm reading source codes of a huge project.Some functions are encapsulated in dlls.
So I want to add breakpoints before every functions defined in codes,in order to follow the process of this project by F5 and avoid the disassembly window show on visual studio.
There are thousands functions in codes, I can't add every breakpoints by manual work.Is there any method or add-in to help me to do this work?
Tks!
Good approach in your case would be start with F10 instead of F5. And in VS you can check all calls with one break point. You should make use of call stack window provided by Visual studio. Whenever a break point will be hit, it will show the whole path from where the call was initiated. After a break point hit, the "call stack" tab will appear with other tabs at the bottom of VS like Error List, Output, Find Results.
Visual Studio 2013 closes console window in after my C++ console program has finished. Is it possible to ask for a key press instead, while
not modifying the source code of the program. (Writing system("pause") surrounded by the proper #ifs at the end of every program is not a solution I call elegant.)
running the program in debug mode. (The "magic" key Ctrl+F5 works, but that runs the program without debugging)
not using breakpoints. (So far the best solution is to put a breakpoint at the end of the main function but that solution is not really convenient either.)
I know that this has been asked many times before (like here) but neither answers satisfy the requirements above.
If there is no way to do this than I'm interested in why the feature was removed as clearly a lot of users miss it and say that it worked in previous versions. Also it seems that there are some users who does not want it. A configuration option or plugin would be nice.