Académique Documents
Professionnel Documents
Culture Documents
Password
Sig i
J i
Home
Articles
C#
Quick Answers
Beginners
Discussions
Learning Zones
Features
Help!
The Lounge
ho
e c ha p deb gge i
al
dio
Languages
See Also
More like this More by this author
Describes all debugging features like Breakpoints, DataTips, Watch Windows, Multithreaded Debugging, Parallel Program Debugging and IntelliTrace Debugging
Article Browse Code Stats Revisions (6)
128
Table of Contents
Introduction How to Start? Breakpoints Debugging with Breakpoints Step Over Step Into Step Out Continue Set Next Statement Show Next Statement Labeling in Break Point Conditional Breakpoint Import / Export Breakpoint Breakpoint Hit Count Breakpoint When Hit Breakpoint Filter Data Tip Pin Inspect Value During Debugging Drag-Drop Pin Data Tip Adding Comments Last Session Debugging Value Import Export Data Tips Change Value Using Data Tips Clear Data Tips Watch Windows Locals Autos Watch Creating Object ID Immediate Window Call Stack Debugging Multithreaded Program Exploring Threads Window Flag Just My Code Break Point Filter - Multithread Debugging Debugging Parallel Program Parallel Task and Parallel Stacks Debugging with IntelliTrace Overview Mapping with IntelliTrace Filter IntelliTrace Data Useful Shortcut Keys For VS Debugging Further Study Summary
codeproject.com/ /Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
Related Articles
Beginner's Walk - Web Development Excellent Debugging Features in Visual Studio 2010 Beta 2 Implementing a Basic Hello World WC F Service Setting Up Kernel Mode Debugger in Windows
1/27
2/8/12
Introduction
In the software development life cycle, testing and defect fixing take more time than actually code writing. In general, debugging is a process of finding out defects in the program and fixing them. Defect fixing comes after the debugging, or you can say they are co-related. When you have some defects in your code, first of all you need to identify the root cause of the defect, which is called the debugging. When you have the root cause, you can fix the defect to make the program behavior as expected. Now how to debug the code? Visual Studio IDE gives us a lot of tools to debug our application. Sometimes debugging activity takes a very long time to identify the root cause. But VS IDE provides a lot of handy tools which help to debug code in a better way. Debugger features include error listing, adding breakpoints, visualize the program flow, control the flow of execution, data tips, watch variables and many more. Many of them are very common for many developers and many are not. In this article, I have discussed all the important features of VS IDE for debugging like Breakpoint, labeling and saving breakpoints, putting conditions and filter on breakpoints, DataTips, Watch windows, Multithreaded debugging, Thread window, overview of parallel debugging and overview of IntelliTrace Debugging. I hope this will be very helpful for beginners to start up with and for becoming an expert on debugging. Please note, targeted Visual Studio version is Visual Studio 2010. Many things are common in older versions, but many features such as Labeling breakpoint, Pinned DataTip, Multithreaded Debugging, Parallel debugging and IntelliTrace are added in VS 2010. Please provide your valuable suggestions and feedback to improve my article.
How to Start?
You can start debugging from the Debug menu of VS IDE. From the Debug Menu, you can select "Start Debugging" or just press F5 to start the program. If you have placed breakpoints in your code, then execution will begin automatically.
There is another way to start the debugging by "Attach Process". Attach process will start a debug session for the application. Mainly we are very much familiar with the attach process debugging for ASP.NET Web Application. I have published two different articles on the same on CodeProject. You may have a look into this. Debug Your ASP.NET Application that Hosted on IIS Remote IIS Debugging: Debug your ASP.NET Application which is hosted on "Remote IIS Server" We generally start debugging any application just by putting breakpoint on code where we think the problem may occur. So, let s start with breakpoints.
Breakpoints
Breakpoint is used to notify debugger where and when to pause the execution of program. You can put a breakpoint in code by clicking on the side bar of code or by just pressing F9 at the front of the line. So before keeping a breakpoint, you should know what is going wrong in your code and where it has to be stopped. When the debugger reaches the breakpoint, you can check out what's going wrong within the code by using a different debugging tool.
codeproject.com/
/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
2/27
2/8/12
Deb gging
i h B eakpoin
Yo ha e al ead e a b eakpoin in o code he e o an o pa e he e ec ion. And no a he p og am b p e ing "F5". When he p og am eache he b eakpoin , e ec ion ill a oma icall pa e. No o ha e e e al op ion o check o code. Af e hi ing he b eakpoin , b eakpoin line ill ho a ello colo hich indica e ha hi i he line hich ill e ec e ne . No o ha e e e al command a ailable in b eak mode, f he deb gging. ing hich o can p oceed fo
S ep O e Af e deb gge hi he b eakpoin , o ma need o e ec O e " [ F10 ] command i ed o e ec e he code line b c en l highligh ed line and hen pa e. If o elec F10 highligh ed, he e ec ion ill op af e he ne line of he e ec e he en i e me hod a a ime. e he code line b line. "S ep line. Thi ill e ec e he hile a me hod call a emen i calling a emen . S ep O e ill
S ep In o Thi i imila o S ep O e . The onl diffe ence i , if he c en highligh ed ec ion i an me hod call, he deb gge ill go in ide he me hod. Sho c ke fo S ep In o i "F11".
codeproject.com/
/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
3/27
2/8/12
Step Out This is related when you are debugging inside a method. If you press the Shift - F11 within the current method, then the execution will complete the execution of the method and will pause at the next statement from where it called. Continue It's like run your application again. It will continue the program flow unless it reaches the next breakpoint. The shortcut key for continue is "F5". Set Ne t Statement This is quite an interesting feature. Set Next Statement allows you to change the path of e ecution of program while debugging. If your program paused in a particular line and you want to change the execution path, go to the particular line, Right click on the line and select "Set Ne t Statement" from the context menu. You will see, execution comes to that line without executing the previous lines of code. This is quite useful when you found some line of code may causing breaking your application and you don t want to break at that time. Shortcut key for Set Next Statement is Ctrl + Shift + F10.
Sho
Ne t Statement [ Ctrl+* ]
This line is marked as a yellow arrow. These lines indicate that it will be executed next when we continue the program.
2/8/12
to better group and filter breakpoints. It's kind of categorization of breakpoints. If you are having different types of breakpoints which are related with a particular functionality, you can give their name and can enable, disable, filter based on the requirements. To understand the whole functionality, let's assume that you have the below code block which you want to debug.
C ollapse C opy C ode
casPorm ls rga { sai vi Mi(tig]ag) ttc od ansrn[ rs { srn[ srae ={"ae" "ae" "ae" "ae" "ae" "ae" tig] tNms Nm1, Nm2, Nm3, Nm4, Nm5, Nm6 ; frah(tignm i srae) oec srn ae n tNms { CnoeWieienm) osl.rtLn(ae; / Bekon / raPi ittm =4 n ep ; fr(n i=1 i< 1;i+ o it ; = 0 +) { i ( >6 f i ) tm =5 ep ;
pbi sai vi Mto1) ulc ttc od ehd( { CnoeWieie"ra Piti Mto1) osl.rtLn(Bek on n ehd";
/ Bekon / raPi
pbi sai vi Mto2) ulc ttc od ehd( { CnoeWieie"ra Piti Mto2) / Bekon osl.rtLn(Bek on n ehd"; / raPi CnoeWieie"ra Piti Mto2) / Bekon osl.rtLn(Bek on n ehd"; / raPi
pbi sai vi Mto3) ulc ttc od ehd( { CnoeWieie"ra Piti Mto3) / Bekon osl.rtLn(Bek on n ehd"; / rapi
If you run the program, execution will pause on the first breakpoint. Now see the below picture, where you have the list of breakpoints.
Fig
e: B eakpoin Li
In the given picture label column in blank. Now, see how you can set the label on break point and what is the use of it. To set label for any breakpoint, you just need to right click on the breakpoint symbol on the particular line or you can set it directly from breakpoint window.
codeproject.com/
/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
5/27
2/8/12
Fig
Righ Click on Breakpoint, Click on the Edi Label link, you can add the label for each and every breakpoints. As per the sample code, I have given very simple understandable names for all the breakpoints.
Fig
Let's have a look at how this labeling helps us during debugging. At this time, all the break points are enabled. Now if you don t want to debug the m h d , in a general case you need e o2 to go to the particular method and need to disable the breakpoints one by one, here you can filter/search them by label name and can disable easily by selecting them together.
Fig
This is all about the Breakpoint labeling. The example I have shown to you is very basic, but it is very much useful when you have huge lines of code, multiple projects, etc.
2/8/12
Breakpoints allow you to put conditional breakpoint. So if and only if that condition is satisfied, the deb gger will pause the execution. To do this, first of all you need to put the breakpoint on a particular line where you want to pause execution. Then just "Right Click" on the "Red" breakpoint icon. From there you just click on "Condition" .
Fig
By clicking on the "Condition" link from context menu, the below screen will come where you can set the condition for breakpoints.
Fig
casPorm ls rga { sai vi Mi(tig]ag) ttc od ansrn[ rs { srn [ srae ={"ae""ae" "ae" "ae" "ae" "ae"; tig ] tNms Nm1,Nm2, Nm3, Nm4, Nm5, Nm6 frahsrn nm i srae) oec(tig ae n tNms { CnoeWieienm) / Bekon i h e osl.rtLn(ae; / api e
You have a breakpoint on C n o e W i e i e ) statement. On running of the program, osl.rtLn( execution will stop every time inside that f r e c statement. Now if you want your code to o- ah break only when n m = N m 3 . What needs to be done? This is very simple, you need to ae"ae" give the condition like n m . q a s " a e " . aeEul(Nm3)
codeproject.com/
/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
7/27
2/8/12
Check he B eakpoin S mbol. I ho ld look like a pl hich indica e he condi ional b eakpoin .
(+)
Af e e p of he condi ion of o b eakpoin , if o n he applica ion o deb g i , o ill ee e ec ion of p og am i onl pa ed hen i a i fied he gi en condi ion i h b eakpoin . In hi ca e hen a e " a e " =N 3.
intellisense In Condition Te t Bo : The b eakpoin condi ion hich I ha e demon a ed he e i e imple and can be i en ea il in ide condi ion e bo . Some ime , o ma need o pecif oo big o comple condi ion al o. Fo ha , o do no need o o , VS IDE p o ide he in elli en e i hin he condi ion e bo al o. So hene e o a e going o pe an hing in ide he condi ion bo , o ill feel like ping in ide he edi o i elf. Ha e a look in o he belo pic e.
I ha e almo co e ed all abo he condi ional b eakpoin e cep one hing. In condi ion indo o ha e een ha he e a e o op ion a ailable: 1. Is Tr e and 2. Has Changed We ha e al ead een ha i he e of "Is Tr e" op ion. "Has changed" i an o b eak he code if ome al e ha changed fo ome pa ic la al e.
codeproject.com/ /Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
ed
hen o
8/27
2/8/12
Fig
e: Sa e B eakpoin
You can use the saved XML file for the future and ou can pass the same to other developers. You can also save breakpoints based on the search on labels. Let's have a quick look inside the content of the XML File. The XML file is collection of B e k o n aPi tag within B e k o n C l e i n Each breakpoints tag contains information about the particular api olc o. breakpoint like line n mber, is enabled, etc.
Fig
If ou delete all the breakpoints from our code at an time, ou can easil import them b just clicking on the "I p m o " breakpoints button. This will restore all of our saved breakpoints. Note: Breakpoint Import depends on the line number where ou have set our breakpoint earlier. If our line number changed, breakpoint will set on the previous line number onl , so
codeproject.com/ /Mastering-Debugging-in-Visual-Studio-2010-A-Beginn 9/27
2/8/12
Breakpoin Hi Co n
Breakpoint Hit Count is used to keep track of how many times the deb gger has paused at some particular breakpoint. You also have some option like to choose when the deb gger will stop. "Breakpoin Hi Co n " window having the following: 1. 2. 3. 4. Break Break Break Break always when the hit count is equal to a specified number when the hit count is a multiple of a specified number when the hit count is greater than or equal to a specified number.
Fig
e: B eakpoin Hi Co n
By default, it's set to always. So, whenever the breakpoints hits, hit count will increase automatically. Now we can set some condition as earlier mentioned. So based on that condition, breakpoint will hit and counter will be increased.
Fig
e: B eakpoin Hi Co n Op ion
If you want your code to break when hit count is a multiple of 2, you need to select the third option from the dropdown list. After that, your code line should break only when the hit count is 2,4,6,... etc.
codeproject.com/
/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
10/27
2/8/12
Fig
e: Hi Co n Condi ion
Till no , I hope o a e e m ch clea abo b eakpoin , labeling, hi co n , e c. No a look a ha i "Breakpoin When Hi " op ion.
ha e
Breakpoin When Hi
Thi i apa f om o no mal deb g ep , o an o do ome hing el e hile b eakpoin i hi , like p in a me age o n ome mac o . Fo ho e pe of cena io , o ma go fo hi op ion. Yo can open hi indo b j igh clicking on b eakpoin .
Fig
e: When B eakpoin I Hi
The fi hing ha o need o no ice i he mbol of b eakpoin . B eakpoin mbol ha changed o a diamond and o can al o check o he ool ip me age hich indica e ha i i going o do hen e ec ion eache he e.
Fig
e: When B eakpoin I Hi
Breakpoin Fil er
Yo can e ic he b eakpoin o hi fo ce ain p oce e o h ead . Thi i e hile o a e dealing i h m l i h eading p og am. To open he fil e indo , o click on he b eakpoin and elec "Fil er".
codeproject.com/ /Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
11/27
2/8/12
Fig
e: B eakpoin Fil e
can e he p oce name, Id, Machine name, Th ead ID, e c. I ha e e in M l i h eading deb gging ec ion.
Da a Tip
Da a ip i kind of an ad anced ool ip me age hich i ed o in pec he objec o a iable d ing he deb gging of he applica ion. When deb gge hi he b eakpoin , if o mo e o e o an of he objec o a iable , o can ee hei c en al e . E en o can ge he de ail of ome comple objec like d a e , d a a l , e c. The e i a "+" ign a a be a ocia ed i h he da aTip hich i ed o e pand i child objec o a iable .
Fig
e: Da aTip
Fe
mon h ago, I p bli hed one a icle on VS 2010 Da aTip Deb gging Tip . cool fea e ha o can e d ing deb gging of o applica ion.
He e a e a fe
While deb gging in Vi al S dio, e gene all ed mo e o e on he objec o a iable o in pec he c en al e. Thi ho he c en da a i em held b he in pec ed objec . B hi i fo a limi ed ime, a long a he mo e i poin ed o ha objec ho e al e ill be a ailable. B in Vi al S dio 2010 Be a 2, he e i a g ea fea e o pin and npin hi in pec ed al e. We can pin a man of an objec and hei b objec al e al o. Plea e ha e a look in o he belo pic e:
codeproject.com/
/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
12/27
2/8/12
Fig
When you mouse over on the inspect object, you will get pin icon with each and every object's properties, variable. Click on that pin icon to make it pinned. Unless you manually close these pinned items, they will be visible in the IDE.
Fig
e: D ag D op Da a Tip
Adding Comments
You can add comments on the pinned data tip. For providing comments, you need to click on E pand to see the comments button. This will brings up an additional textbox to add comments.
Fig
e: Commen
in Da aTip
2/8/12
The e a ed da a i fi e i e be :
ca
be i
ed d i g a
f i e f
codeproject.com/
/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
14/27
2/8/12
Fig
Yo
can f
an
o kno
mo e de ail abo
i . :)
Fig
1. Clea All Da a Tip 2. Clea All Da a Tip Pinned To [ File Name.C ] So if o an o clea all he Da a Tip f om all o e o p ojec / ol ion, j elec he fi op ion. B if o an o dele e he pinned da a ip f om a pa ic la file, hen o need o open ha pa ic la file, he e o ha e he econd op ion o elec . Yo can e en dele e pa ic la pinned da a ip b j igh clicking on i and clicking "Clear".
Fig
e: Clea Da a Tip
Watch Windo
Yo can a i i an in e iga ion indo . Af e b eakpoin ha been hi , he ne hing o an o do i o in e iga e he c en objec and a iable al e . When o mo e ho e on he a iable, i ho he info ma ion a a da a ip hich o can e pand, pin, impo hich I ha e al ead e plained. The e a e a io pe of a ch indo like A o , Local, e c. Le ' ha e a look in o hei de ail .
codeproject.com/ /Mastering-Debugging-in-Visual-Studio-2010-A-Beginn 15/27
2/8/12
Local
It automaticall displa s the list of variables within the scope of current methods. If our deb gge currentl hits a particular breakpoint and if ou open the "Autos" window, it will show ou the current scope object variable along with the value.
Fig
e: Local Va iable
These variables are automaticall detect b the VS deb gge during the debugging. Vi al S dio determines which objects or variables are important for the current code statement and based on that, it lists down the "A o " variable. Shortcut ke for the Autos Variable is "C l + D + A".
Fig
e: A
- C l+D, A
Wa ch
Watch windows are used for adding variables as per requirement. It displa s variables that ou have added. You can add as man variables as ou want into the watch window. To add variables in the watch window, ou need to "Righ Click" on variable and then select "Add To Wa ch".
Fig
e: A
- C l+D, W
You can also use D ag and D op to add variables in watch windows. If ou want to delete an variable from watch window, just right click on that variable and select "Dele e Wa ch". From the debug window, ou can also edit the variable value at run time. There are 4 different watch windows available which ou can use parallell .
codeproject.com/
/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
16/27
2/8/12
If an of he o a iable of he abo e indo hold he objec in ance, o can ha e a "+" mbol i h he a iable o e plo e he p ope ie and membe of ha objec a iable.
C ea ing Objec ID Vi al S dio Deb gge ha ano he g ea f nc ionali he e o can c ea e an objec ID fo an pa ic la in ance of objec . Thi i e m ch helpf l hen o an o moni o an objec a an poin of ime e en if i goe o of cope. To c ea e Objec Id, f om a ch indo o need o igh click on a pa ic la objec a iable and hen need o click on "Make Objec ID".
Af e adding Objec Id i h a pa ic la objec a iable, Vi al S dio add a n me ic n mbe i h "#" i h ha objec o indica e ha one Objec ID ha been c ea ed.
codeproject.com/
/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
17/27
2/8/12
Immediate Windo
Immediate window is very much common and a favorite with all developers. It's very much helpful in debug mode of the application if you want to change the variable values or execute some statement without impacting your current debugging steps. You can open the Immediate window from menu Debug > Windo > Immediate Windo { Ctrl + D, I / Alt + Ctrl - I . Immediate window has a set of commands which can be executed any time during debugging. It also supports Intellisense. During Debug mode, you can execute any command or execute any code statement from here.
These are very much common features for all the developers, so I am not going into details of each and every command of Immediate window.
Call Stack
These calling where shows features also improve the productivity during debugging. If you have multiple method or nested calling all over your application and during debugging, you want to check from this method has invoked, "Call Stack" comes into the picture. The Call Stack Window that current method call nesting.
In Call Stack window if you clicked on any of the rows, it will point you to the actual code of line of Visual Studio Code Editor. You can also customize the call stack row view by selecting different types of columns. To customize, Right Click on the "Call Stack" window, and from the context menu, you can select or deselect the option.
codeproject.com/
/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
18/27
2/8/12
Call stack is very much important when you have multiple methods call all across the application and one particular method throwing an exception on some particular case. At that time, you can use call stack to see from where this method is getting invoked, based on that you can fix the defect.
casTraTs ls hedet { sai vi Mi( ttc od an) { Tra t=nwTra(e TraSatG); hed e hednw hedtr(o) tNm ="hed1; .ae Tra " Tra t =nwTra(e TraSatG); hed 1 e hednw hedtr(o) t.ae="hed2; 1Nm Tra " tSat) .tr(; t.tr(; 1Sat) G(; o) sai vi G( ttc od o) { CnoeWieie"el!) osl.rtLn(hlo";
In the sample code, you have three different threads - Main Thread, Thread 1, Thread 2. I have given a thread name to make you understand better. Now set a breakpoint inside "Go()" and run the application. When debugger hits the breakpoint, Press Ctrl+D,T or Navigate through Debug > Windo > Threads. Threads window will appeared on the screen.
codeproject.com/
/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
19/27
2/8/12
Fig
e: De ail
ie
of Th ead
indo
B defa l h ead indo ha ing ID, Managed ID, Ca ego , Name, Loca ion and P io i col mn. A he a , e ec ion pa e a "Main Th ead". "Yello A o " indica e he c en e ec able h ead. Ca ego col mn indica e he ca ego of h ead , like main h ead o o ke h ead. If o check he h ead loca ion, i i no hing b Namespace > Class > Method name. In he diag am, i i ho ing ha he Main Thread ill be e ec ed ne . No o e plo e he ne ep b j p e ing "F5" and ee ha a e he change in h ead indo .
Fig
e: De ail
ie
of Th ead
indo
- Fo Ne
S ep
So af e p e ing F5, i j mped o he ne ep o h ead 1. o can al o check he c en loca ion fo Main Th ead. I a "Sleep/ Wait / Join" , mean ai ing fo ome hing o comple e. Simila l he ne ep ill mo e o o h ead 2. F om he Th ead indo , o can nde and ho ea i i o moni o o h ead ing hi debugger ool. The e i ano he g ea fea e a ailable i hin he h ead indo . Yo can e pand/collapse he Thread Loca ion and can ee ha i ne . Fo e ample, if o e pand he loca ion fo "Main Thread", i ill look like he diag am gi en belo :
Fig
Fo Th ead
Flag Just M Code The ample code hich I ha e e plained fo he h ead deb gging i e imple. Wha ill happen if o ha e a h ge code block i h m l iple n mbe of h ead . Then i ill be e diffic l fo o o iden if hich h ead i pa of o code o hich one a e no ela ed. Th ead indo gi e o e ea fea e o e he "Flag" fo all he h ead hich a e pa of o code. Fo ha , o need o j flag o h ead b op ion "Flag Just M Code".
codeproject.com/
/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
20/27
2/8/12
Code
Break Point Filter - Multithread Debugging Whi e di c i g ab b ea i fi e i b ea i ec i , I aid ha b ea i fi e i e ch he f f M i h eaded deb ggi g de. N hi i he i e e e i . I c e e a e, e ha e h ee h ead Mai Th ead, Th ead1 a d Th ead 2. N ha if a breakpoint to hit onl for "Thread 2". Wha i d ? He e i he e f b ea i fi e . Righ c ic he b ea i , e ec "Filter" f he c e e . N i b ea i fi e i d , eed fi he fi e c i e ia. A e e ie e , eed ecif "T e d a e " h e d 2 . h aNm=T a "
ca fi e e i g he b ea
i fi d
ga
e ec
ha
ed d i g he e ec ica i a
f "Thread 2" .
Thi i a ab e hi g f
codeproject.com/
i h eaded a he i
/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
2/8/12
uigSse; sn ytm uigSse.olcin.eei; sn ytmCletosGnrc uigSse.iq sn ytmLn; uigSse.et sn ytmTx; uigSse.hedn; sn ytmTraig uigSse.hedn.ak; sn ytmTraigTss nmsaePrleakeugn aepc aalTsDbgig { casPorm ls rga { sai vi Mi(tig]ag) ttc od ansrn[ rs { vrts_ =Ts.atr.trNw( = DSmWr(00); a aka akFcoySate() > ooeok100) vrts_ =Ts.atr.trNw( = DSmWr(00) a akb akFcoySate() > ooeok50); vrts_ =Ts.atr.trNw( = DSmWr(00) a akc akFcoySate() > ooeok10); Ts.atl(aka ts_,ts_) akWiAlts_, akb akc;
To understand the parallel program debugging, we need to be aware about two window options: 1. Pa allel Ta k 2. Pa allel S ack
codeproject.com/
/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
22/27
2/8/12
Pa allel Ta k window will show you what are the different tasks that have been created for the program and what is their current status. On the other hand, Parallel Stacks will show you the graphical view of all thread creation, containing tasks, how they are related. If you click on the thread from the Parallel Stacks, it will show you the code line related with the thread (as shown in the picture with a Green Arrow). To move ahead, press F5. Let's see what comes next.
In the above diagram, you can find one of the tasks has been executed and the other two are remaining. Current execution point is set to A y c e h d 1 so if you continue, this method snMto_, will execute first and next time the others. When you are working with parallel programming, there are many scenarios which will come like Deadlock, Dependency problem, etc. These topics is very interesting and long to discuss. Please check further study section of the article to know more details.
Deb gging
i h In elliT ace - O e
ie
This is another great feature of Vi al S dio 2010 IDE. IntelliTrace Debugging is sometimes called as historical Debugging. IntelliTrace operates in the background, records what you are doing during debugging. When you want the information of previous event or some particular event, you can easily get it from intelliTrace information, a past state of your application. In this mode, you can navigate to various events, steps that are recorded. In this section, I will give you a basic overview of how to use IntelliTrace. Here I am using one sample program by which I will show you what IntelliTrace does. Below is the sample code block:
C ollapse C opy C ode
casPorm ls rga { sai vi Mi(tig]ag) ttc od ansrn[ rs { CnoeWieie"nelTakret) osl.rtLn(ItlirceTs"; ClTsMto() aletehd5;
pbi sai vi ClTsMto(n TsVle ulc ttc od aletehdit etau) { CnoeWieie"nClTsMto :"+TsVleTSrn() osl.rtLn(I aletehd etau.otig); CnoeWieie"atSaeet..) osl.rtLn(Ls ttmn..";
Run the program and Open In elliT ace window from Debug menu, you will find the below screen added in the right hand side of Vi al S dio.
codeproject.com/
/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
23/27
2/8/12
Mapping
i h In elliT ace
Did you find any relationship with your code and with the In elliT acke Li ie ? I guess you should. If not, let me explain about it. Let's have a look into the below picture:
From the picture, I am sure you have got the idea what IntelliTrace is doing. Yes, exactly its eco d /cap e what your code is doing. If you call a method, it will capture. If code fired an event, it will trap. Yes at a single statement, I will capture each and everything. Now from the In elliT ace window, you can navigate your code with any part and see what s happened internally. If you can get the call stack, Local variables information are recorded. To navigate, just click any of the events that you want to explore, that block will automatically expand.
ith Code
When you will select any block, it will expand automatically and that line will be highlighted. As per the given picture, I have highlighted the first console section and you can see the corresponding code block has also been highlight. You can now easily map them. In the expanded block (Ligh O ange), there are two Related View Sections Local and S ack Call. I have already explained Locals and Stack Calls. But can you imagine what is the use of Locals and Call Stack over here. Yes, you guessed it correctly, it will show you the Locals and Call Stack status for that time period when the selected block has been executed. What a nice feature this is.
codeproject.com/
/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
24/27
2/8/12
Note: B defa l , Visual Studio o ed In elliT ace info ma ion in "\Mic o of Visual Studio\10.0\T aceDeb gging" Loca ion in a iTrace file. Yo ma change he loca ion. Deb gging i h In elliT ace i i elf a big opic. So i i e m ch diffic l fo me o co e hem p i hin hi a icle. I j gi e o he ba ic o e ie o ha o can a lea e plo e i b o elf no . Plea e check he f he d ec ion o kno mo e abo i .
all of he b eakpoin
he b eakpoin on he c
a ne
e ec
/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
2/8/12
Ctrl-ShiftSets the execution point to the line of code you choose F10 Alt-NUM * Highlights the next statement F5 Ctrl-F5 F11 Shift-F11 F10 Shift-F5 Ctrl-Alt-H F9 Ctrl-AltW, 1 Ctrl-Alt-P Ctrl-D,V If not currently debugging, this runs the startup project or projects and attaches the debugger. Runs the code without invoking the debugger Step Into Executes the remaining lines out from procedure Executes the next line of code but does not step into any function calls Available in break and run modes, this terminates the debugging session Displays the Threads window to view all of the threads for the current process Sets or removes a breakpoint at the current line Displays the Watch 1 window to view the values of variables or watch expressions Displays the Processes dialog, which allows you to attach or detach the debugger to one or more running processes IntelliTrace Event
I am stopping here. Hope you have enjoyed the full article. Please share your feedback and suggestions.
Further Stud
Debugging Task-Based Parallel Applications in Visual Studio 2010 By Daniel Moth and Stephen Toub Debugging With IntelliTrace
Summar
This article covers basic fundamentals of debugging procedure. It describes how to debug an application using VS IDE. I have explained almost all important tools and their uses. For Parallel program debugging, I have covered only basics. In further study section, there is a great article on Parallel debugging procedure. If you are interested, please go through the link. My main objective was to cover almost all utilities that are available in Visual Studio debugging. Hope you have learned something new from this article. Please share your valuable feedback and suggestions to improve this.
Histor
6th May, 2010: Initial post
License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
codeproject.com/
/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
26/27
2/8/12
Follow on Twitter
Article Top
Sign Up to vote
Poor
E cellent Vo e
Nice Job M M M M M M M M vote of 5 vote of 5 vote of 5 vote of 5 vote of 5 vote of 5 vote of 5 vote of 5
Ama ing post M M M M vote of 5 vote of 5 vote of 5 vote of 5 Re: My vote of 5 M vote of 5 Re: My vote of 5 M vote of 5
8:18 15 Mar '11 15:55 2 Mar '11 12:14 9 Feb '11 23:40 8 Feb '11 4:57 12 Jan '11 5:33 12 Jan '11 0:23 10 Jan '11 5:55 12 Jan '11 1:46 4 Jan '11 1 2 3 4 5 6 Next Rant
Use C trl+Left/Right to switch messages, C trl+Up/Down to switch threads, C trl+Shift+Left/Right to switch pages.
P ermalink | A dvertis e | P rivac y | M obile L ayout: fixed | Web0 4 | 2 .5 .1 2 0 2 0 6 .1 | L as t U pdated 6 M ay 2 0 1 0 fluid A rtic le C opyright 2 0 1 0 by A bhijit J ana E verything els e C opyright C odeP rojec t, 1 9 9 9 - 2 0 1 2 T erms of U s e
codeproject.com/
/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
27/27