How to enter in the body of a destructor in MS VS 2010? - c++-cli

When I try to debug a C++/CLI program in MS VS 2010 and use key F11 to enter the body of a destructor of some class the debugger skips this step.
How to force the debugger to enter the body of a destructor?

This is another leaky abstraction issue, you can tell what's going on when you look in the Output window after you tried to step:
Step into: Stepping over method without symbols 'Foo.Dispose'
Luckily the debugger still allows you to set a breakpoint on the destructor. Which is the workaround.

Related

Can I set a breakpoint condition over entire form?

When running a program I need to see every time a certain button is disabled and step through the code at that point.
If I set a breakpoint with a condition
(ex: only hit when button1.enabled=false) it will only hit in that specific place.
Is it possible to set a breakpoint on the entire program so that i can see when a condition changes across many forms and locations?
You can't set one breakpoint and have it apply to every line of the file, but you can set a breakpoint on the setter of Enabled and then filter it to a specific filter condition. That would give you the desired result. (Note, you might need to turn off "Just my code", see this question for more info)
Set a breakpoint using the "New Breakpoint At Function" as described here, though in Visual Studio 2013, I seem to need to use a slightly different notation:
Then set the breakpoint to funtion:
System.Windows.Forms.Control.Enabled
in C# or for VB.NET:
System.Windows.Forms.Control.set_Enabled(bool)
(You seem to need to use the class that actually defines the property, which in case of the Button class' Enabled property, is the Control class the Button inherits from.
Ignore the warning about it not being able to find the function (it does that for properties somehow), or uncheck the Intellisense lookup.
Now look up the breakpoint in the Breakpoints list and customize the condition so it breaks on the right button
Use the Name property (or any other filter that makes the breakpoint unique) to trigger when you need it to:
When it breaks, it will break in the sources of Control (if you have Framework Source Stepping enabled), which may be confusing. Use the Stack Trace window to find the location where the method was invoked exactly.
Another way of setting the breakpoint is through the Stacktrace window. Set a breakpoint on any line that has your property of interest on it. Launch the debugger and make it break on that line, now use "Step into Specific" to step into the property that you want to break on.
Use the "Stack" window to generate the breakpoint for you:
Since in your case you're looking to break on a function from the Microsoft .NET framework, there is another way. Enabled Framework Source Stepping.
Open the Visual Studio Debugger options and enable "Framework Source Stepping" and disable "Just My Code".
Then enable the Microsoft Symbol Servers in as instructed. Now load up your application under the debugger and wait for the symbol files to be downloaded.
set a break point anywhere in your code that is somehow related to System.Windows.Forms (The constructor of your MainForm for example) and rightclick any function from the "System.Windows.Forms" assembly to load the symbols for that assembly. This will allow you to step into the "Enabled" property and set a break point there.
A full tutorial can be found here:
http://blogs.msdn.com/b/sburke/archive/2008/01/16/configuring-visual-studio-to-debug-net-framework-source-code.aspx

Why doesn't Visual Studio debug my VB.NET application?

I recently have encountered a weird issue with my project: as soon as I click debug and it builds the project, it stops debugging. There isn't any error message, or anything else that comes up, including the form itself.
I've tried messing with the settings: no splash screen and I've even changed the startup form to a blank Windows form. What could be causing this problem? Is it Visual Studio or my code?
Probably your program is exiting normally. Set a breakpoint at the first statement to be executed, press F5, then single-step through the program until you get to the last statement executed.
If the first statement is never reached, then one of two things probably happened:
You're mistaken about which statement is executed first, or
The program is terminating during initialization, probably because a class constructor is exiting the program either normally or abnormally.
A few ideas:
Use Debug->Exceptions, and check all the checkboxes so you break when an exception is thrown.
Use Debug->Step into to step into your code.
Then you can use Step Over and Step Into (look at the menu for the keyboard shortcuts)
I found a solution, but not the problem.
How I fixed it:
I just created a template for each form, created a new project, and imported everything into the new project. One thing that I found useful is in the new project is to add an existing item (CTRL + D), and group select (maybe, don't know if you can) and select all the non-code/form/designer/etc. files (like text files or images) and then import them.
I have found a possible solution after I had the same problem.
You probably have more than one project in your solution (The main project, plus an "InstallShield" project",perhaps)
Make sure you have the main project set up as "Startup Project".
In the Solution Explorer, right click on the Main Project and select "Set as Startup Project".
Everything will then run OK.
If you get the error like: "The debug mode is program but there is no program specified....." Go to Solution Explorer then Right Click on main project's name and Click on Set as StartUp project. You can debug your program.

How do I output code while debugging in Visual Basic 2010?

When I'm debugging my application something is not right, and I can't continue.
So is it possible to see the output code of my app while I'm testing it to see what is wrong?
I open the output window but nothing happens in there it's just stay blank.
In two words: I want to see what my app is actually doing while I'm testing it.
I'm using Visual Studio 2010.
So is it possible to see the output code of my app while im testing it to see what is wrong?
Yes, but you actually have to output something, otherwise nothing will show up. In VB.NET (which is the language you're using if you have Visual Studio 2010), this is accomplished with the following code:
Debug.Print("Here is some text that will be output.")
The documentation for the Debug.Print method is here. In order to call it like that, you will also have to have imported the System.Diagnostics namespace. You do so by placing the following line at the top of your code file (with all the other statements that look like it):
Imports System.Diagnostics
The output will automatically appear in the Output Window. If you still don't see anything, ensure that output is not being redirected to the Immediate Window instead: Tools -> Options -> Debugging -> General -> uncheck the option "Redirect all Output Window text to the Immediate Window".
Confusingly, you use the word "code" in your question, saying that you wish to "see the output code of [your] app while testing it". I'm not sure if by "code" you actually mean "output", in which case the solution above will work for you.
If you actually mean code, as in your program's source code, then you can use the Break toolbar button (or press Ctrl+Break) in the IDE to pause the execution of your program. This will automatically dump you back into the code editor with the currently-executing line of code highlighted.
Visual Studio has some very powerful debugging tools. If you don't already have a general idea of how to use them, I strongly recommend picking up a book on either it or VB 2010 that will teach these things to you. They can be very confusing to learn by trial and error, but are not all that difficult if you have a good guide. Spend that time debugging your code, not figuring out how to use the IDE.

VB 2008 & Debugger?

using vb.net 2008
When I put a break on a line and then press F5 the debugger does break on the line which I put the Break (F9) but Step In (F8) as well as F5 are grayed out, not working, as well as a bunch of other debug tools.
Any clue why this is? Is there a setting that needs to be set?
It's probably because you're running a Release Build. Check if you have a combobox somewhere on your toolbars with the text Release... you should select Debug instead.
If you have trouble finding this toolbar, this MSDN article might help you.
Is it because that breakpoint will never be hit because it is not lying in your path of execution?
Make sure that you can F5 into the entry point ( typically, the main() method) and start from there.

How do I prevent Visual Basic 2008 from automatically indenting namespaces?

Is there a way to prevent this from happening?
Namespace testing
Public Module TestModule
Public testobj As New test
End Module
End Namespace
It is extremely annoying to have to start out two tabs to the right on new code. Is there anyway to disable auto-indenting just for namespace declarations in visual studio 2008?
There is no setting for turning off specific block type indentations. (There is a setting for C# to turn off block indenting altogether, but again, not specific to certain block types like namespace blocks).
You shouldn't need to hit tab twice though - when you press "enter" on a line of code, it should automatically indent you to where the last line was indented to.
And no matter how you type in your code, it's just a quick keystroke to auto-format the whole document (Ctrl-K followed by Ctrl-D). So you can ignore idents until you're done typing and then auto-format.