Google Search

Google
 

Thursday, July 24, 2008

Video: Mechanics - Controlling Debugger Display for Your Types

Presenter:Mike Taulty

The Visual Studio debugger can be configured to display custom output for your own data types. This session looks at how you do that.

The following text is a software generated transcript of the video. Click on a minute link to jump to a location within the video


Minute 0

A low outlook and its MSDN nugget in one in a series of short sessions where we spent 10 minutes looking keyconceptstechnologiesindie net frameworks and net languages and in visual studio is Tolkien I work in a development platform group at Microsoft UK and in this particular setting a look at the visual studio details of ugly bugger although I will say it is also common as three and in particular how we can control what the debugger displays when there are instances of datatypes on the screen so let s wander straight into visual studio I do a project that already built here just to illustrate some of the things that we can do and it s all very simple stuff to have a go and open project in this astute thousand five using the beta to build here and feel that this project then is a few things I want to illustrate so if I m the screen face a simple console advocate

Minute 1

And plays with a couple of tights so we have a tackle person and we have a titled address and a person has an address property is it which is making in a sign of their animal calling the print method on the person object now let s just reminded a bugger to get a breakpoint and assessing it is that when you hover over the person or indeed if we were to go and get a watch window you consider the debugger displays a really nice formats of the person it tells me that this is Jack Smith and his 50 years old and has not the default display format for a random object and the net framework the debugger is that you getting this from the person class itself and if we go and look at the person that appear you see that the person class has an after recycled debugger display which is telling the debugger what to display by default one of the centres selected data delivered is flanker

Minute 2

Is on first name last name and age and years old justice in spring and these things and curly braces here are just standard net properties on this class to assent is going to go and evaluate the first and last name in the eight property in order to build the strain and that s where we re getting at this profit this display here where we get Jack Smith 50 years olds were taking customisation and built in the way we want to build a second aim to notice about the person customer won t visualise in the debugger is if we have over this then expanded as it noticed that the person that seems to contain directly a public property called county and house number and postcode and street and I don t really make sense in in a person class solidarity having a white wavy seams being displayed this way and if you look at the person that s what s what s going on here is the person class has an address property which is at

Minute 3

Address and what we said it is used as debugger browsable attribute to say the root of this class should be hidden to what this is doing is taking tea and address object and collapsing it as though it was directly part of that Person object when in fact it s not as if it were to change this to say most as having collapsed by default as opposed to hidden in a rebuild that code then when we run a game we should get different format flapping in the debugger to feel about p a lot of the addresses the address is now their has collapsed a letter that seems to me a nicer way of laying out the know what we were doing before a enemy can of course go and expand this than it expands out as a stock property instead of all been flat within the person that you can do that if you want to do it you can control up the debugger browsable other things you can do with debugger browsable well in the first is that if we don t look at that Person object again just hover over that thing

Minute 4

Noticeably that some public properties here addressed a seminar today but there seems to be a private field called a patch that is not really the case if we don t look at the object of the class layout itself you see that there is indeed a public property called H but the debugger is not showing it as a reason why Vickers is set this to be browsable never am constantly debugger is not showing that thinking will so that this is something that you could do if you wanted to am hiding your state from Sandy Strang to determine what it is in the debugger might give a nasty trick to play on but if you want to do it you can use debugger browsable to learn to control that is we have those three states all found collapsed root hidden or never as the house of properties display oh some of the things we can do here if we take a look at them this call you to this print effort if I was to try and step into this method with an effort

Minute 5

Was wondering right now you noticed that the Devo Rashid is a definite steps over other reason why it steps over is because on my person class print method which is just here you can see that thought is that recycle debugger steps through an essentially what this is saying his son don t show this to the person whose debugging the code are essentially make them step over it rather than what that s stepping into it city wanted a high implementation details from user and again you could use his attribute it to control that once again adding as it pretty careful with this you don t want to put this on every method to try and hide implementation somebody s debugging your code from reason and trying to trick them and keep them away from the coast robbing up not the best practice but unlikely occasions where pheasants are known a simple property access like this one sometimes has little value in stepping into these methods are just really muddies a picture of debugging so it might be vital by one of his things to a simple property

Minute 6

To encephalitis and just keep it out of that code so just to illustrate a point here lets remove this debugger steps to attribute on Honours method and rebuild the code and then get back to breakpoints are stratified to run and will press at 11 against step in notice that now react to step into the massive and reducing printing here and I recall an address doctrine so we print address is part of printing the person a generous impressive 11 here then what happens as we step over so propagating well okay you ve just got one of these attributes are prior applied to this method is well actually that s not exactly the case is very similar if you look at the print method on the address object which is just a few you see that the print method on address it doesn t say debugger steps through it says debugger non user code so this is a new act of its visual studio 2005

Minute 7

And essentially what this marries up with its own asserting that we can use in the debugger and is essentially that setting with his hands out on the tools options debugging general menu is whether to have just my code debugging on to assess what this is saying is trying the bug and other surely the things I wrote and one of the ways in which the setting is guided its true and these attributes are like debugger nonuser code Savalas switches off at this point is that I don t want to do just my code debugging want to debug everything and then rerun this out in the debugger again the notice of this final step into print but also when we get to address the friend will step into that as well so whether we going to hear depends on whether I ve switched on just my code debugging have just my code debugging on we will go in here otherwise we will so again you d need to use this bearing the

Minute 8

Very single method in the world you can imagine some writers of that framework libraries might not want users to keep people away from code that is not really that relevant to them by the use of this understand that they can topple that value and stepping on art depending on whether they have that value set now just one final thing to look to look at here we did take some control over the formatting objects in the debuggers have used them and if have to be to control out my debugger display and debugger browsable there is another thing that we can do for particular object types like a dress title here we can to introduce a frock see to the debugger so we can to tell the debugger that when somebody tries to display one of these things what we acting like the debugger to do is display one of these things instead to a suitably weird but what the saying is if somebody tries to display an address class actually create an instance of address the frock

Minute 9

Seen as show that to them instead as a hurricane address proxy the way that these glasses work is that they will always have a constructor on them which takes an instance of the object that they are a proxy for so this is a proxy for an address to consequently is to have a constructor that takes an address because the evil is going to constructors that way you again that the atavism use before like debugger display work just as well on this proxy as they do wound on the real class itself and so hear what we re doing is done as you bring out a string so that is generated by a property to enable this at the moment we got this comment analysis we say that when the debugger displays and address we actually wanted to use our proxy to do that display as a rebuild the code and run back down to a brake pipe there was easier than only look inside this object and get the address

Minute 10

Then actually was being used to do a display on this address object here is proxies you can see that it says is generated by proxy and it gives the details of the address following in a seat with a very very neat single entry there in the debuggers display despite using that proxy note though that when you do use a proxy the user can still get a for the use of the real view of the object that hasn t gone through the proxy and so here s the real objects underneath the user still gets a choice and I are fully debugging net framework objects you will see this rule that you have been presented to an essentially what that s about is that somebody has written a proxy to the debugger is shown the both representations of the object through the proxy and not through the proxy we ve seen quite a few athletes who is seeing people can browse always seem debugger display we seem debuggers stepped through debugger nonuser code

Minute 11

Finish that by looking at debugger type proxy signal that do for us still just as I m writing it would be seen in the short session only seen that we can attribute our own types are methods are classes and so on in order to control what the debugger shows on the screen when a user perhaps class libraries action walking through code at the Ash recently got favoured listed there on the screen I see this affects things like the data tips and watch windows and it also affects the behaviour of the debugger when people can step into code in that we can control whether they can do that on with the debugger stepped through the debugger nonuser code attribute to it can get quite rich control over a user s experience as their debugging code just to finish up here what can you do if you want its more information on visual studio 2005 world as a whole MSDN developer Santa outfit and is the end Microsoft com PS2 thousand five

Minute 12

At those U2 and grab a copy of one of the express editions of the Jew as an adviser in their current beta to form a MSDN Microsoft com express and you can download the singular and to register anything like that Brabham straight away or if Italy specifically want to talk and they set off the back of an assassin then feel free to drop e mail and anthology of Microsoft comalt I ll get back to you other than scientific tuning in

Click here to go to original video page

No comments: