GoingNative 28: The VS Debugger: How It Works + Tips and Tricks

Sign in to queue

Description

We hope, for the better, that you'll never look at your debugger the same way again after watching this video! Learn about how the Visual Studio debugger works, as well as numerous super-useful features you may not have known were contained therein =)

Jump to:
[03:46] how the VS debugger works
[11:56] .exe projects
[13:34] /d2zi+
[14:27] trace points
[15:57] expression evaluation
[17:33] pseudo-variables
[19:19] more format specifiers (click here for the msdn page)
[20:48] additional visualizers
[21:27] Natvis (Native Visualizer)
[23:35] modules window
[24:42] step into specific
[25:24] parallel windows

Be sure to watch through to the end for some special news.

Embed

Download

Download this episode

The Discussion

  • User profile image
    felix9

    interesting !

  • User profile image
    cppForMe

    Bye Ale. Hi Steve! This was very helpful.

    As a Mixed mode dev I have to add another plea to the devs who could probably make this happen. Please, please, please make .natvis work in Mixed Mode debugging. Even if it's only when I'm in a file which was compiled w/o /clr.  All of this goodness is unavailable to my team because we need to debug Native and C++/CLI code.  

    My uservoice: http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/4192306-support-natvis-debug-visualizers-in-mixed-mode-deb

    $env and $cmdline also do not work when debugging in Mixed Mode :(

     

    Would it be possible to add a right-click, Break on Specific in the future?  This would help when I must debug (others) code like this:

    if (test) DoSomething();

    I want to break if test is true but the granularity is at the line level instead of the expression level.

    John

  • User profile image
    Gregg Miskelly

    Thanks for the feedback John. The issue is that natvis is supported by our new C++ expression evaluator and our new C++ expression evaluator requires our new debug engine. The Managed C++ expression evaluator on the other hand only works with our old debug engine, and it isn't possible to have both debug engines debugging the same process at the same time. It is possible to use natvis while mixed mode debugging, but only if managed C++ support is disabled. If that is a useful tradeoff for you, you can enable that by setting your launching project to either a C# project (using the support to launch an external program if you want to load this in a native executable) or an exe project. Coming up with some way to enable managed C++ expression evaluation while using our new debug engine is something we are very interested. But it is also a lot of work, and we haven't gotten to it yet.

  • User profile image
    eduquint

    Thanks for the excellent show, as always.

    Alas, the .exe projects did not work in my case. I tried Notepad.exe, as you suggest, but all I get is assembly code, and a message saying the source code is not available. Does it require the Ultimate SKU, or should it work with the Professional SKU, which is my case?

    My PC has Windows 8.1 update 1, 64 bits.

    If I may suggest a topic for your show, I would like to see some discussion on how to efficiently access SQL Server (2012/2014) using C++ 11/14. All I have been able to do is use third-party libraries, which are not really reliable.

    Thanks again for your superb show. And good luck Ale in your new endeavors.

  • User profile image
    sandeep

    Really helpful. .Net example would have been much better.

  • User profile image
    Ivan

    Again nice job tagging this. :/

  • User profile image
    Ofek_Shilon

    @Gregg - your old blog was great!   I wish you'd go back to posting..

  • User profile image
    cppForMe

    @Gregg Miskelly:Thanks for the reply Gregg.  I do have "Use Managed Compatibility Mode" disabled and our main entry point is a Native .exe (with a C++/CLI DLL and a C# Assembly loaded later). I am not getting natviz support with "Mixed Mode" selected as the debugger type. We only use C++/CLI and not the older Managed C++. Would love to know how to turn it off if there's something other than un-checking "Use Managed Compatibility Mode".

     

    I'm thrilled that you are interesting in enabling managed expression eval with the new debugging engine. I hope you are able to get to it soon :)

     

  • User profile image
    Gregg Miskelly

    @cppForMe - So the C++ project system is setup so that any launches for managed or mixed debugging will use Managed Compatibility Mode, regardless as to what is set in Tools->Options->Debugging. So if you really want to try this, you will need to use on of the other projects (see description from my first reply). Keep in mind that if you disable managed compatibility mode in this way that you will loose the ability to debug the C++/CLI code, so be careful with this.

    We would also really like to get this to work with the new debug engine as we would really like to get rid of our old one completely. But sadly there is always more to do than we have time to do, so no promises.

  • User profile image
    Gregg Miskelly

    @eduquint - So the exe project system doesn't have some special reverse-compiler in it or something like that. So if you don't have symbols and sources for any of the code in the exe that you would like to debug it will not be much help. For example, you can use the exe project system to launch notepad, but as you have seen, if you don't have access to its symbols and sources, it doesn't give you much. Exe projects are really there so that you can debug an exe without needing its project - for example if you are on a test computer where you don't want to download the real solution, or if the exe was built on the command line without a project.

  • User profile image
    cppForMe

    @Gregg Miskelly: Ugh, that's what I was afraid of. 

    What you've described, we can get now if we select "Native Only" debugging. ie. We turn off C++/CLI support and debug -- our exe entry point is Native but soon thereafter we head into Managed code. We're hoping that we can one day debug in mixed mode and still see natvis content. Clearly you understand the request so I'll just leave it at +25 requests from a bunch of statisticians who wish they could see their structures.

  • User profile image
    asc

    We need more shows like this, been using VS for 15 years and the 'hidden' features I had to stop and replay with VS open because I'd never managed to find them before

  • User profile image
    Sri Sarma

    Hi Chaps,
    I was wondering if you could elaborate on the difference between the PDB generated by the compiler versus the PDB generated by the linker.
    I understand that the PDB generated by the linker is used for debugging. But what purpose does the PDB generated by the complier serve and where is it used? I can only think of lib files with complier generated pdb being used somehow to generate a linker pdb when the lib is linked into a dll/exe.
    I'd appreciate some detailed information.

  • User profile image
    Gregg Miskelly

    I am afraid as a debugger person I don't know the full answer to this -- I only need to deal with the linker PDBs. The linker uses the various compiler PDBs as a data source to write out the final PDB, for example, merging together the various descriptions of types. But I am not sure if compiler PDBs are used by anything other than the linker.

  • User profile image
    edd

    What do you do if you need to debug the debugger itself?

  • User profile image
    Gregg Miskelly

    We start two instances of VS - a 'target' instance and a 'dogfood' instance (which is debugging the target, see http://en.wikipedia.org/wiki/Eating_your_own_dog_food for the definition of dogfood).

    People on the team have different preferences on how to do that. Some of us use a totally different copy of the debugger on another computer (using remote debugging) so that we can patch the target debugger without needing to restart the dogfood debugger. Other people really want to keep their dogfood debugger the latest and greatest, and so they will use the same copy of VS for both the dogfood and target instances.

  • User profile image
    YUVAL

    i get this error:
    Fatal error: Expected element with namespace

    XML is :

    <Type Name="std::vector&lt;*&gt;">
    <DisplayString>{{ size={_Mylast - _Myfirst} }}</DisplayString>
    <Expand>
    <Item Name="[size]" ExcludeView="simple">_Mylast - _Myfirst</Item>
    <Item Name="[capacity]" ExcludeView="simple">_Myend - _Myfirst</Item>
    <ArrayItems>
    <Size>_Mylast - _Myfirst</Size>
    <ValuePointer>_Myfirst</ValuePointer>
    </ArrayItems>
    </Expand>
    </Type>


Add Your 2 Cents