Debuggig
Defiitios Error A wrog decisio made durig software developmet
Defiitios 2 Error A wrog decisio made durig software developmet Defect bug sometimes meas this The term Fault is also used Property of software that may cause the system to deviate from its iteded behaviour
Defiitios 3 Error A wrog decisio made durig software developmet Defect bug sometimes meas this The term Fault is also used Property of software that may cause the system to deviate from its iteded behaviour Fault bug sometimes meas this The term Failure is also used The evet i which software deviates from its iteded behaviour
Defiitios 4 Error A wrog decisio made durig software developmet Defect bug sometimes meas this The term Fault is also used Property of software that may cause the system to deviate from its iteded behaviour Fault bug sometimes meas this The term Failure is also used The evet i which software deviates from its iteded behaviour Error ==> Defect ==> Fault Error ==> Fault ==> Failure
What is debuggig? Debug 6
What is debuggig? 2 You have ru a test that detects a fault Debug 7
What is debuggig? 3 You have ru a test that detects a fault Assumig the test is correct, that implies there is a defect i the program you are testig Debug 8
What is debuggig? 4 You have ru a test that detects a fault Assumig the test is correct, that implies there is a defect i the program you are testig You wat to fid the error i your desig / implemetatio that led to the defect Debug 9
What is debuggig? 5 You have ru a test that detects a fault Assumig the test is correct, that implies there is a defect i the program you are testig You wat to fid the error i your desig / implemetatio that led to the defect What do you do? Debug 10
What is debuggig? 6 You have ru a test that detects a fault Assumig the test is correct, that implies there is a defect i the program you are testig You wat to fid the error i your desig / implemetatio that led to the defect What do you do? You trace the executio path followed by the test Debug 11
What is debuggig? 7 You have ru a test that detects a fault Assumig the test is correct, that implies there is a defect i the program you are testig You wat to fid the error i your desig / implemetatio that led to the defect What do you do? You trace the executio path followed by the test Check the state of the program at each step Debug 12
What is debuggig? 8 You have ru a test that detects a fault Assumig the test is correct, that implies there is a defect i the program you are testig You wat to fid the error i your desig / implemetatio that led to the defect What do you do? You trace the executio path followed by the test Check the state of the program at each step Util you fid the error Debug 13
What is debuggig? 9 You have ru a test that detects a fault Assumig the test is correct, that implies there is a defect i the program you are testig You wat to fid the error i your desig / implemetatio that led to the defect What do you do? You trace the executio path followed by the test Check the state of the program at each step Util you fid the error Correct the error by??? Debug 14
What is debuggig? 10 You have ru a test that detects a fault Assumig the test is correct, that implies there is a defect i the program you are testig You wat to fid the error i your desig / implemetatio that led to the defect What do you do? You trace the executio path followed by the test Check the state of the program at each step Util you fid the error Correct the error by Esurig the program correctly implemets the desig Esurig the desig is correct Debug 15
Fudametal method prit the (sub)state Beefit The method works i the vast majority of cases, i all laguages ad all operatig systems Debug 16
Fudametal method prit the (sub)state Beefit The method works i the vast majority of cases, i all laguages ad all operatig systems No eed to lear or deped upo a tool customized for the laguage ad operatig system Debug 17
Fudametal method prit the (sub)state Beefit The method works i the vast majority of cases, i all laguages ad all operatig systems No eed to lear or deped upo a tool customized for the laguage ad operatig system After makig a chage, you ru the program ad see if state is correct where it was wrog before Debug 18
Fudametal method prit the (sub)state Drawback It is primitive ad very ad hoc Debug 19
Fudametal method prit the (sub)state Drawback It is primitive ad very ad hoc Program text is added to the system, that eeds to be removed oce the error has bee fixed Debug 20
Fudametal method prit the (sub)state Drawback It is primitive ad very ad hoc Program text is added to the system, that eeds to be removed oce the error has bee fixed It iteracts with the ormal output of the program Debug 21
Fudametal method prit the (sub)state Drawback It is primitive ad very ad hoc Program text is added to the system, that eeds to be removed oce the error has bee fixed It iteracts with the ormal output of the program Ca produce volumious output Debug 22
Fudametal method prit the (sub)state Drawback It is primitive ad very ad hoc Program text is added to the system, that eeds to be removed oce the error has bee fixed It iteracts with the ormal output of the program Ca produce volumious output Have to worry about buffered output, which meas the last few output lies may ot appear Debug 23
Loggig Use the Logger class istead of usig System.out.pritl Logger.getGlobal().ifo Debug 24
Loggig Use the Logger class istead of usig System.out.pritl Logger.getGlobal().ifo You ca have fier-grai loggig. Use fie or severe, i place of ifo Debug 25
Loggig Use the Logger class istead of usig System.out.pritl Logger.getGlobal().ifo You ca have fier-grai loggig. Use fie or severe, i place of ifo The API is i java.util.loggig Debug 26
Loggig Use the Logger class istead of usig System.out.pritl Logger.getGlobal().ifo You ca have fier-grai loggig. Use fie or severe, i place of ifo The API is i java.util.loggig You ca tur off all loggig with Logger.getGlobal().setLevel(Level.OFF); Debug 27
Assertios Be defesive, add assertios to the program Debug 28
Assertios Be defesive, add assertios to the program See Programmig with Assertios docs.oracle.com/javase/7/docs/techotes/guides/laguage/assert.html Debug 29
Assertios Be defesive, add assertios to the program See Programmig with Assertios docs.oracle.com/javase/7/docs/techotes/guides/laguage/assert.html Assert statemets exist i C, C++, Java, Eiffel Check existece i other laguages Debug 30
Assertios Be defesive, add assertios to the program See Programmig with Assertios docs.oracle.com/javase/7/docs/techotes/guides/laguage/assert.html Assert statemets exist i C, C++, Java, Eiffel Check existece i other laguages Assertios ca be implemeted with if the If ot assertio the have a exceptio / problem fi Debug 31
Assertios Be defesive, add assertios to the program See Programmig with Assertios docs.oracle.com/javase/7/docs/techotes/guides/laguage/assert.html Assert statemets exist i C, C++, Java, Eiffel Check existece i other laguages Assertios ca be implemeted with if the If ot assertio the have a exceptio / problem fi Jet Propulsio Lab has all its software i C ad madates the use of assertios Debug 32
Eable assertios i Eclipse Go to Ru à ru cofiguratios Uder Java Applicatio select the applicatio to use assertios Here Copy_Examples Select Argumets tab Add ea i VM argumets Debug 33
Debug Flags Whe debuggig it is useful to tur o ad off various features i a program Debug 34
Debug Flags Whe debuggig it is useful to tur o ad off various features i a program Especially debug output Debug 35
Debug Flags Whe debuggig it is useful to tur o ad off various features i a program Especially debug output Create a Debug class that cotais Boolea flags that ca be set, reset ad toggled Debug 36
Debug Flags Whe debuggig it is useful to tur o ad off various features i a program Especially debug output Create a Debug class that cotais Boolea flags that ca be set, reset ad toggled Use the flags i if statemets that surroud iterestig sectios of your program Debug 37
Debug Flags Whe debuggig it is useful to tur o ad off various features i a program Especially debug output Create a Debug class that cotais Boolea flags that ca be set, reset ad toggled Use the flags i if statemets that surroud iterestig sectios of your program For differet test rus give differet settigs of true ad false to the flags Debug 38
Debug Flags 2 Example if Debug.flag0 the Block1 fi if Debug.flag1 the Block2 fi if Debug.flag3 the Block3 if Debug.flag4 the Block4 fi fi Depedig upo the values of flag0.. flag3 differet combiatios of Block1.. Block4 are executed Debug 39
Program istrumetatio Isertig debug write / log statemets ad usig debug flags is called program istrumetatio Debug 40
Program istrumetatio Isertig debug write / log statemets ad usig debug flags is called program istrumetatio Used judiciously it is a useful method Debug 41