Yann-Gaël Guéhéneuc
This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 3.0 Unported License
CSE3010: 소프트웨어패턴 이론및실험
(Software Pattern Theory and Practice)
The Be a Debugger process pattern
CSE3010: (Software Pattern Theory and Practice) - - PowerPoint PPT Presentation
CSE3010: (Software Pattern Theory and Practice) Yann-Gal Guhneuc The Be a Debugger process pattern This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 3.0 Unported
Yann-Gaël Guéhéneuc
This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 3.0 Unported License
The Be a Debugger process pattern
2/40
3/40
4/40
Definition Method Tools
– Logging – Debugger
Conclusion
5/40
Definition Method Tools
– Logging – Debugger
Conclusion
6/40
7/40
8/40
Error, aka crash, exception…
– A difference between a computed result and the correct (expected) result
Failure
– The (incorrect) result of a fault
Fault, aka defect, flaw
– An incorrect step, process, or data definition includes also non-functional (design) defects
Mistake
– A human action that produces an incorrect result
9/40
A mistake may lead to a fault, which may lead to a failure, which may lead to an error
10/40
A mistake may lead to a fault, which may lead to a failure, which may lead to an error
11/40
Definition Method Tools
– Logging – Debugger
Conclusion
12/40
13/40
Method
– Process to collect, analyse, understand, and fix the bug (error, failure, fault, mistake)
Tools
– To concretely apply the process
14/40
Descriptive NOT informative Essentially useless…
15/40
Minimum
– Crash report
Better
– Steps to reproduce
Even better
– Short, Self Contained, Correct Example
16/40
Minimum
– Crash report
Better
– Steps to reproduce
Even better
– Short, Self Contained, Correct Example
17/40
Short, Self Contained, Correct Example
http://sscce.org/ – Actually a (simple) test case – Descriptive – Informative – Can be use repeatedly until fixed – Can be used as regression test too
18/40
Short, Self Contained, Correct Example
– Ockham's razor is “a principle of parsimony, economy, or succinctness used in logic and problem-solving” [Wikipedia] – Why use more when you can use less?
19/40
To build the SSCCE and to solve the error
20/40
To build the SSCCE and to solve the error
21/40
To build the SSCCE and to solve the error
22/40
Scientific method
– Daniel ( לאֵיִּנָדּ), 7th century BCE – Thales (Θαλῆς), 6th BCE – Plato (Πλάτων), 4th BCE – Aristotle (Ἀριστοτέλης), 3th BCE – … – al-Ḥasan (مﺛﯾﮭﻟا نﺑ نﺳﺣﻟا نﺑ نﺳﺣﻟا ،ﻲﻠﻋ وﺑأ), 8th c. CE – …
23/40
Scientific method
– … – Roger Bacon, 13th century CE – Francis Bacon, 17th CE – Descartes, 17th CE – … – Charles Sanders Peirce, 19th CE – Popper, 20th CE
24/40
Scientific method
– Falsifiability
http://karl-popper.over-blog.com
“Are all swans white?” “Do mermaids exist?”
Sir Karl Raimund Popper
28 July 1902–17 Septembre 1994
25/40
Hypothesise where the Failure / fault / mistake is From your hypothesis, set breakpoints Test your hypothesis, i.e., debug the SSCCE Analyse whether you can fix the failure / fault / mistake can Yes? Next bug No? Continue
26/40
Definition Method Tools
– Logging – Debugger
Conclusion
27/40
Poor man’s debugger
– System.out.println(…);
Better
– Logging (e.g., Log4J) logger.debug(…);
(Even) better
– Use the debugger
28/40
System.out.println(…);
– Not scalable – Clutter the output
Logging
– Scalable, levels – Off-line, remote
Debugger
– On-line (interactive) – SSCCE
29/40
System.out.println(…);
– Not scalable – Clutter the output
Logging
– Scalable, levels – Off-line, remote
Debugger
– On-line (interactive) – SSCCE
30/40
Definition Method Tools
– Logging – Debugger
Conclusion
31/40
Logging, e.g., Log4J
// Get a logger instance named "com.foo" Logger logger = Logger.getLogger("com.foo"); // Normally you do not set the level of a logger in code. logger.setLevel(Level.INFO); // This request is enabled, because WARN >= INFO. logger.warn("Low fuel level."); // This request is disabled, because DEBUG < INFO. logger.debug("Starting search for nearest gas station."); // The logger instance barlogger inherits its level from // the logger named "com.foo". This request is enabled // because INFO >= INFO. Logger barlogger = Logger.getLogger("com.foo.Bar"); barlogger.info("Located gas station."); // This request is disabled, because DEBUG < INFO. barlogger.debug("Exiting gas station search");
32/40
DEBUG | 2008-09-06 10:51:44,817 | DefaultBeanDefinitionDocumentReader.java | 86 | Loading bean DEBUG | 2008-09-06 10:51:44,848 | AbstractBeanDefinitionReader.java | 185 | Loaded 5 bean defini INFO | 2008-09-06 10:51:44,848 | XmlBeanDefinitionReader.java | 323 | Loading XML bean definition DEBUG | 2008-09-06 10:51:44,848 | DefaultDocumentLoader.java | 72 | Using JAXP provider [com.su DEBUG | 2008-09-06 10:51:44,848 | BeansDtdResolver.java | 72 | Found beans DTD [http://www.spr DEBUG | 2008-09-06 10:51:44,864 | DefaultBeanDefinitionDocumentReader.java | 86 | Loading bean … DEBUG | 2008-09-06 10:51:45,473 | AbstractAutowireCapableBeanFactory.java | 383 | Creating insta DEBUG | 2008-09-06 10:51:45,473 | AbstractAutowireCapableBeanFactory.java | 459 | Eagerly cachi 10:51:45,473 | AbstractAutowireCapableBeanFactory.java | 411 | Finished creating instance of bean ' INFO | 2008-09-06 10:51:45,473 | SQLErrorCodesFactory.java | 128 | SQLErrorCodes loaded: [DB2, …
33/40
Logging, e.g., Log4J
– DEBUG: low level things, e.g., cache hit, cache miss, opening database connection… – INFO: events that have business meaning, e.g., creating a customer, charging a card… – WARN: any problem that does not stop the program, e.g., email address not found… – ERROR: unexpected problem that could prevent the program to work, e.g., failed to open a database connection...
34/40
Definition Method Tools
– Logging – Debugger
Conclusion
35/40
Debugger
– “Usual” features
– Reverse debugging
36/40
Debugger
– Hardware support for single-stepping a program
– Instruction set simulator – Virtual machine
37/40
38/40
39/40
Definition Method Tools
– Logging – Debugger
Conclusion
40/40
Beware of the ubiquitous term “bug” Debug with (scientific) method
– Use SSCCE!
Use the tools to your advantage