Presenter:Mike Taulty
Maximise your debugging by ensuring that your applications are built with the right debugging and tracing output from day 1.
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 and welcome to this MSDN Nugget session 1 in a series of short sessions were uninvited and it is looking a key concepts technologies in the net framework is in visual studio and did not let languages and Mike Tolkien I worked in the developer and platform group in Microsoft in the UK and in this particular set of another visual studio 2005 at talk about what you can do to build debug and facing output into your code in order that you can get good diagnostics out of the code where applications are running and perhaps try and avoid having to actually launch debugger and debug code at all okay so that s not visual studio let s make a simple project so it is throughout the vacancy shall console application and if it rises have had a general purpose code so perhaps arises a guy routine that reverses the strengths of searching sequels reverse
Minute 1
String of how the world of something like that and we can use visual studio to go to write that stuff for us and really what happens in the implementation heroes is rather irrelevant that perhaps we can do is get some some characters from the stone and their average very to raid a reversal that honours characters and then we can return as the kindly string vest and characters that should and should is rumoured to live with in this retain we want to make a general purpose and a robust it would be good pasta out of debugging information to trace an insult to it and that we can see at debug time in a debug build and with a lead system diagnosticsthere are some great classes for doing a daddy like other thing to the first thing we can do is something that will be very common to a sea or a C programmer we have a
Minute 2
Of an equivalent of the assert macro in the system diagnostics at the assertions were through the old code is built around a bunch of assumptions and assertions allow you the luxury of testing your assumptions in debug builds Welsh unitary product testing to cycle sofas and say what we could do with what we might order to assess the severity of asses is an all spring here as we get into trouble so we can use the debug assert are call and we can say p is not equal denial is an assumption that we have made about the string that comes to assert we are essentially saying I don t work with an old strain soproblem for us here at the city s legal bill that debug us a call then a hand something was to call at reverse strength with a null and whatever happened at that point of his runner in the debug if
Minute 3
To get an assertion dialogue from the code so that certain has been checked the condition has been checked and there was found to be false and consequently the style dialogue is lacked from the code and if we were to run retry at this point what will do is take it straight into the debugger and show us the point at which the assertions failed and indeed even if we are outside the debugger something just wander out into work and one from the going to consular application for to get ourselves into a folder here I flew to run the application here noticed that it also comes up with the assertion dialogue and again if we retry what that will do is is offered to launch the debugger for us and we ll just go ahead here are debugging with this instance and once again he could see the debugger has been enlarged to tell us what assertion has failed so assertions ran a very very powerful thing there are other things we can do with a deeper class and particularly one thing we could do this is take
Minute 4
To approach him so well if p is vital to know we can do it debug fail am I fail the something like that of the buildup to build and run it you see that there s a lot of again and will come straight in online echoed across the failures that is just and a way of doing what we were just doing but we cannot see is a deeper class in order to earn right at information so we can use debug print and we can use debug write in with use debug at right line and it is also versions will write death so we can test a building condition of the two tracing it if that condition is true but if SSO wanted to write out the value of the parameter passed it as we could do it debug write line with his string format here and was a reverse drink called out without the value of the parameter as three p
Minute 5
I was estate where the cult hit in all samples to crash and every just build and run then be application runs on if we were to view output window in visual studio you see that the Tracey s hearing output window seat like a vigil that can hand if you re running in the debugger book but what if you re not the one thing you can do is you can use of tools such as feeding a viewer from the system tunnels website so that it s just down to be de rigueur assistant hurdles com and outlook of the wicked Exley and if the reviews that guys such as runner up is if this comes out as this code runs you ll see that people who will display the people tracing from a code as well so that s what I ve been posting totally onto the screen even if you are running under a debugger and we can control where things like assertions go have her assertion here something like that
Minute 6
And every precious fault in my assertion shall refund to fail if we can control whether a thing goes by adding a configuration file into the project surfaced on and new item here and over configuration file and into here we can go and configure essentially where that s just goes just sickly commuter and Alison do this for us and what we should go to go do its own configure system diagnostics and essentially to reassert we can specify whether we want to let you I not so I offer you my writing anti services online r surgeons onto the screen readers make a stencil is a long switched off at that point and in this case of prolonged for the things at the file instead summer let s call this file and see my assertions txt or something like that in which case then if we had any assertions as we do in our code at the moment only run this or we should find this a
Minute 7
Since been redirected for about two a file purchase if we got see my assertions txt and start again on that see my assertions txt and you can see his my assertions are even if the race of the minister of headless mode without you why we can still use the people are not the important thing to say about the deeper class it is that all the code that you put in here using the deeper class so assertions on right lines and so on simply doesn t exist in a release build off your code and the reason for that is is that these methods are essentially conditional letters and are compiled around a traditional symbol that has caught the bug and as the working capital and the compiler of visual studio fact doesn t define that thing for a release build what the
Minute 8
It is any great use of this file for other things as well be I eat right methods such as zone check parameter and will pass that runs across and what will do is remove these assertions are crossing to check parameters will have a private static for its check parameter is a thicker string and would as with those assertions across there and you can make your own methods conditional so we could say this is a conditional method and it depends on the symbol debug being set if this symbol is not set this method you simply won t happen and that is the way that debug the uncertainty but got right line work if this is the symbol isn t defined to the compiler then these methods simply get removed they simply don t exist because it is if we built this debug them naturally we re going to get their assertions of erroneous code was in the assertion fires our cottage is configured to run
Minute 9
Not come up on the screen select medical on screen and will see that this thing will fire there is just aboard in that case I forgot this with release then what will find it if it run that then the code will just run and we wanted an assertion at all tax rate and the scene that we can use the deeper class and in debug builds this code will appear and in release builds in one but there are times when want to have tracing information that we can just simply switched on so we can walk up to an application on customer site and switch few settings are starting trace information out of it and because we got masses to do that within the system diagnosticsas well and the primary class savers remove some of this code from an aids and the trace gas so we have a classical trace and essentially it looks very much like debug and you can see it also has an assert so again you can be the sense of fear and
Minute 10
Also has a right and right line and right is right life as well so we can be traced at Ryton this is his information and a centre that will come out in tracing where the application is run to get pretty granular control as to whether tracing goes so what we can do primarily through the consideration file we can specify where we want our diagnostic tracing to go and then have a collection for listeners and usher in his text only that but the oddest robin here and we could have any number of listeners to this collection so by default listeners are writing to the files on salon you can write your own listeners are writing anywhere you like a value on the right things into the event log such as the standard framework class that writing is an event log as if it had gone built of stone then we would see that time I tracing the
Minute 11
Out in the event log Sophie run that look at the event log in to refresh that thing you see here that we ve done our tracing information at an event log now normally when you are facing in Iraq because she only tracing coat and executing all the time and so we got switch classes within the framework that can help with that so particular to switch classes there is a classical Boolean switch and essentially what we can do is to construct one of those things it knew the names that got my switch I want a description which will provide Ryanair animal is lazy if this is enabled and do the tracing so that is very easily switching on and off tracing and through the configuration file to the application we can go and add out switches to continue without the switch on my switch is currently switched on as if we don t build the application and we were to run down to hear what you find is that when Hitler
Minute 12
Line that these switches that enabled us consequently our tracing is not to occur at that point we can control switching with a four level switch or the trace we create one of these things up again to give it a name and wants a description and what this thing can do for us it is a control switching at four different levels you can see those levels reach from verbose through to information through to warning and through to error and you can even check the levels well to what we can say here is we can have asked switching such their turn with his if we are tracing of the errors then let us write out on our information and we to say if we are tracing her warnings as well perhaps instead of we can trace
Minute 13
Some warning information and so on and so forth to attach it for levels of granular tracing here at depending on what you want to get to we can build nothing up then when we go out and run this one will see it is that in our event log this time we re going to get an error information out of the event log but that s because we got the switch set a certain value ran out of the on switch the valley to have a value of two which means errors and warnings that the rebuild that impressed the fight against the run down this time what was says the of that love should get to you events in his the first one which is errors are easy that the warning result of interest as well so this is quite nice and they don t put it here in that we can ground the lowly control what level of tracing contest the application to straight everything would original different warning Saracens
Minute 14
On and being other configure listeners this way gives us a lot of flexibility as to where these events ultimately end up now just if always around net framework 2 0 in that there is this a trace of the social reducing state and accurate was there as a new classes in tracing in 2 0 in particular there is a classical trace source and we can create a new one of those things and give the name my source or something like that and any can say that this combined summer that sometimes it just seems that this has a collection of listeners and it has these methods trace information trace Sun day Tetris event of these from the most comprehensive this trace events and if you look at trace of endlessly takes the type of event to trace and there s a lot long the list of categories Sony hand in hand the standard tracing with 1 0 to get it including application
Minute 15
But we superset what we already had an inkling is a critical error information verbose and warning so we can go ahead and trace a warning that this class every trace of their needs and identify longitude zero and will say this is a warning that if there is a little idiocy but this is not a framework 2 0 code and the main changes here it really that the tracing architecture has been beefed up in 2 0 so essentially what we have is a trace also number of trade sources and I consider the subsystem level in your architecture those sources are controlled by one or more switches and are so many to many relationship there and then each source can have any number of listeners associated with big uploads and events that its tracing publish them somewhere and those listeners can also have filters so we can have a number of listeners configured to pick up
Minute 16
Draws Birtley to those listeners might have a different filter of the kicks of certain invention and sought to get very very flexible configurable powerful architecture sitting behind Tracy in 2 0 which is really a result of taking what happened in 10 and adding in customer feedback is what people wanted to see suggesting a simple case either at rear of a new config file destruct config file in here who we ve got sources here is the source of my source if you are switching out the value to be all this could be critical or warning on whatever I won I m saying all and here s our listener live addict and is just the consul listener to put the tracing output to their a free run like that then we would see that just by running the code will get at Port out of the consul to a very simple way of configuring it but this is ultimately flexible and configurable to do really like anything he won so whether you re ever in 2 0 tray sources from where you would start of
Minute 17
Debilitating and the application just before we finish up here there is one more class than system diagnostics which is worth having a quick look at and it s not quite related to the tracing and a deeper class but it s a classical debugger and if you are debugging applications then you can use this debugger class to do some interesting things so and for instance it can be debugger break at notice that were saying there this thing will only cause of breakpoint in the debugger if the debugger is attached it won t automatically attack in debugger for you notice you can check to see whether a debugger is present mark to application classic detect that notice that you can launch the debugger so if you do want to run the debugger from some way to do debugger launch Andy Castleknock thanks to a debugger s locking window so you can post a message and have the debugger can for you so it s handy if you mark to launch a debugger from your own code or cause of
Minute 18
Pontiffs on his effigy by the things it were thing only can control and manipulate the debugger from your own code and build that in order to do that kind of work so just to be Here will be seen in the short session only harder than mostly in system diagnostics and this is your friend iswho get to know that while we looked at a deeper class and what we can do with debugger of cert and didn t got right line and how that is compiled in out of the debugger of his field looked at faith as it is very similar and I had that stays in the release build on how we control it through switches and reluctantly waved in tracing a 90 005 frame 2 0 and we don t receive at the debugger class or Harry can manipulate that talk to the debugger and should we want to do that just to finish out here what can you do if you want its more information on visual studio 2005 world as a whole MSDN developer Centre outfit and is the end of my
Minute 19
com Fiesta tears and five at illegitimate and grab a copy of one of the express editions of the unity as an adviser in the current beta to form there about MSDN Microsoft com express and you can just download the singularity register anything like that describe them straight away or if Italy specifically want to talk and assess your feedback on an assassin then feel free to drop me a mail and an insult to Microsoft comalt I ll get back to you or the lack of activity in a
Click here to go to original video page
Thursday, July 24, 2008
Video: Preparation - Building Debug and Tracing into Your Code
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment