IMGD 1001: Debugging by Mark Claypool Robert W. Lindeman

Slides:



Advertisements
Similar presentations
VCE SD Theory Slideshows By Mark Kelly Vceit.com Debugging Techniques.
Advertisements

Chapter 5 Errors Bjarne Stroustrup
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Annoucements  Next labs 9 and 10 are paired for everyone. So don’t miss the lab.  There is a review session for the quiz on Monday, November 4, at 8:00.
Debugging Mohammad Zikky, M.T. 2 Debugging Introduction (1 of 2)  Debugging is methodical process for removing mistakes in a program  So important,
IMGD 1001: Debugging. 2 Debugging Introduction (1 of 2)  Debugging is methodical process for removing mistakes in a program  So important, whole set.
 Introduction to Programming History of programming.
Chapter 7: Introduction to Debugging TECH Prof. Jeff Cheng.
Announcements Wednesday's test will be postponed until Thursday – July 7 th, See me if this won’t work for you. Project 1 will be due Monday – July.
Programming Logic and Design, Third Edition Comprehensive
Interactive Media and Game Development Debugging.
Chapter 3.5 Debugging Games
Interactive Media and Game Development Debugging.
Debugging Introduction to Computing Science and Programming I.
Interactive Media and Game Development Debugging.
Debugging CPSC 315 – Programming Studio Fall 2008.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
How to Debug VB .NET Code.
Interactive Media and Game Development Debugging.
2/9/2007EECS150 Lab Lecture #41 Debugging EECS150 Spring2007 – Lab Lecture #4 Laura Pelton Greg Gibeling.
Programming Fundamentals (750113) Ch1. Problem Solving
02/10/06EECS150 Lab Lecture #41 Debugging EECS150 Spring 2006 – Lab Lecture #4 Philip Godoy Greg Gibeling.
JS Arrays, Functions, Events Week 5 INFM 603. Agenda Arrays Functions Event-Driven Programming.
Using a Debugger. SWC What is ”debugging”? An error in a computer program is often called a ”bug”… …so, to ”debug” is to find and get rid of errors in.
Jun 16, 2014IAT 2651 Debugging. Dialectical Materialism  Dialectical materialism is a strand of Marxism, synthesizing Hegel's dialectics, which proposes.
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
Structured programming 4 Day 34 LING Computational Linguistics Harry Howard Tulane University.
Debugging & Troubleshooting “To err is human, but it takes a computer to really foul things up” © 2004 Lawrence Snyder.
Debugging in Java. Common Bugs Compilation or syntactical errors are the first that you will encounter and the easiest to debug They are usually the result.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
Chapter 22 Developer testing Peter J. Lane. Testing can be difficult for developers to follow  Testing’s goal runs counter to the goals of the other.
Testing and Debugging Session 9 LBSC 790 / INFM 718B Building the Human-Computer Interface.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Debugging and Profiling With some help from Software Carpentry resources.
BMTRY 789 Lecture 11: Debugging Readings – Chapter 10 (3 rd Ed) from “The Little SAS Book” Lab Problems – None Homework Due – None Final Project Presentations.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
Design - programming Cmpe 450 Fall Dynamic Analysis Software quality Design carefully from the start Simple and clean Fewer errors Finding errors.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
Scientific Debugging. Errors in Software Errors are unexpected behaviors or outputs in programs As long as software is developed by humans, it will contain.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
Software Quality Assurance and Testing Fazal Rehman Shamil.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
CompSci 100E 18.1 Testing and Debugging Robert A Wagner.
Source Level Debugging of Parallel Programs Roland Wismüller LRR-TUM, TU München Germany.
Debugging tools in Flash CIS 126. Debugging Flash provides several tools for testing ActionScript in your SWF files. –The Debugger, lets you find errors.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
AVCE ICT – Unit 7 - Programming Session 12 - Debugging.
CSE 332: C++ expressions Expressions: Operators and Operands Operators obey arity, associativity, and precedence int result = 2 * 3 + 5; // assigns 11.
Debugging using By: Samuel Ashby. What is debugging?  A bug is an error in either a program or the hardware itself.  Debugging is first locating and.
Protecting Memory What is there to protect in memory?
Debugging Intermittent Issues
Protecting Memory What is there to protect in memory?
Protecting Memory What is there to protect in memory?
CSE 374 Programming Concepts & Tools
Libraries and Debugging
CSS 161: Fundamentals of Computing
Chapter 15 Debugging.
CSCE 315 – Programming Studio, Fall 2017 Tanzir Ahmed
Programming Fundamentals (750113) Ch1. Problem Solving
Debugging Taken from notes by Dr. Neil Moore
Chapter 15 Debugging.
EECS150 Fall 2007 – Lab Lecture #4 Shah Bawany
Debugging EECS150 Fall Lab Lecture #4 Sarah Swisher
Debugging Taken from notes by Dr. Neil Moore
Debugging EECS150 Fall Lab Lecture #4 Sarah Swisher
An Introduction to Debugging
Chapter 3 Debugging Section 3.4
Presentation transcript:

IMGD 1001: Debugging by Mark Claypool Robert W. Lindeman

Claypool and Lindeman, WPI, CS and IMGD2 Debugging Introduction (1 of 2)  Debugging is methodical process for removing mistakes in a program  So important, whole set of tools to help. Called "debuggers" Trace code, print values, profile Integrated Development Environments (IDEs) (such as Game Maker) have one built in  A good debugger is really useful... Based on Chapter 3.5, Introduction to Game Development

Claypool and Lindeman, WPI, CS and IMGD3 Debugging Introduction (2 of 2)  But debugging still frustrating Beginners don't know how to proceed Even advanced can get "stuck"  Don't know how long it takes to find Variance can be high But can treat them in aggregate for predictions  What are some tips?  What methods can be applied?

Claypool and Lindeman, WPI, CS and IMGD4 Outline  Five-step debugging process  Prevention  Game Maker specifics  Debugging tips

Claypool and Lindeman, WPI, CS and IMGD5 Similar steps to Scientific Method  Evaluation  Conjecture  Deduction  Test  Lather, rinse, repeat  Let’s do one

Claypool and Lindeman, WPI, CS and IMGD6 The Problem: Bubble Sort  We need a routine to sort a list  Algorithm: Compare adjacent entries in the list If they’re out of order, swap them Move on to the next pair Repeat until the list is sorted  Yes, this is vague But you might be lucky to get this much description of an algorithm in your code!

Claypool and Lindeman, WPI, CS and IMGD7 Work Through …  Consider array: 3512  Evaluate, then Conjecture/Deduction, then Fix, then Test

Claypool and Lindeman, WPI, CS and IMGD8 Step 1: Reproduce the Problem Consistently  Find case where always occurs Things like this: "Sometimes game crashes after kill boss" don’t help much  Identify steps to get to bug Ex: start single player, room 2, jump to top platform, attack left, … Produces systematic way to reproduce  Consider record/playback Console developers use camcorder!

Claypool and Lindeman, WPI, CS and IMGD9 Step 2: Collect Clues  Collect clues as to where is bug Clues suggest where problem might be Ex: if crash using projectile, what about that code that handles projectile creation and shooting?  And beware that some clues are false Ex: if bug follows explosion, may think they are related, but may be from something else  Don't spend too long - get in and observe Ex: crash when shooting arrow. See reference pointer from arrow to unit that shot arrow should get experience points, but it is NULL That's the bug, but why is it NULL?

Claypool and Lindeman, WPI, CS and IMGD10 Step 3: Pinpoint Error 1) Propose a hypothesis and prove or disprove Ex: suppose arrow pointer corrupted during flight. Add code to print out values of arrow in air. But equals same value that crashes.  Hypothesis is wrong. But now have new clue! Ex: suppose unit deleted before experience points added. Print out values of all units before fire and after all deleted.  Yep, that's it! 2) Binary-search method (note, can use in conjunction with hypothesis test above, too) Sherlock Holmes: "when you have eliminated the impossible, whatever remains, however improbably, must be the truth." Setting breakpoints, look at all values, until discover bug The "divide" part means break it into smaller sections  Ex: if crash, put breakpoint ½ way. Is it before or after? Repeat. Look for anomalies, NULL or NaN values

Claypool and Lindeman, WPI, CS and IMGD11 Step 4: Repair the Problem  Propose solution. Exact solution depends upon stage of problem. Ex: late in code cannot change data structures. Too many other parts use it! Worry about "ripple" effects.  Ideally, want original coder to fix. If not possible, at least try to talk with original coder for insights.  Consider other similar cases, even if not yet reported Ex: other projectiles may cause same problem as arrows did

Claypool and Lindeman, WPI, CS and IMGD12 Step 5: Test Solution  Obvious, but can be overlooked if programmer is "sure" they have fix Programmer can be wrong!  So, test that the solution repairs bug Best done by independent tester  Test if other bugs introduced Beware of "ripple" effect

Claypool and Lindeman, WPI, CS and IMGD13 Debugging Prevention  Use consistent style, variable names  Indent code, use comments  Always initialize variables when declared  Avoid hard-coded constants They make code brittle  Add infrastructure, tools to assist Alter game variables on fly (speed up) Visual diagnostics (maybe on avatars) Log data (events, units, code, time stamps)  Avoid identical code Harder to fix if bug found Use a script/function  Verify coverage (test all code) when testing

Claypool and Lindeman, WPI, CS and IMGD14 Game Maker: Print Messages  Display a Message object  main2  info  Or, in code show_message(‘Executed this code’) show_message(‘num:’ + string(number_here))  Beware if done every step! Save code ahead of time

Claypool and Lindeman, WPI, CS and IMGD15 Game Maker: Debug Mode

Claypool and Lindeman, WPI, CS and IMGD16 Game Maker: Print Debug Messages  Like show_message but in debug mode only Note, doesn’t pause  In code show_debug_message (‘Executed this code’)  Need to run in debug mode  Debug Information  Tools  Show Messages

Claypool and Lindeman, WPI, CS and IMGD17 Game Maker: Log Messages  Write messages to file  Example: At beginning (maybe create log object)  global.log_name = “logfile”; global.fid = file_text_open_write(global.log_name); Then, where needed:  file_text_write_string(global.fid, “Debug message here”) ; Close when done (object  event other  game end):  file_text_close(global.fid)  Note: files also useful for save/load game, etc.

Claypool and Lindeman, WPI, CS and IMGD18 Game Maker: Script/Code Syntax

Claypool and Lindeman, WPI, CS and IMGD19 Game Maker: Error Messages (1 of 2)  Help pinpoint problem Refer to object and method and offending code Pay attention! Refers to: -Object -Event -Line number -Variable name

Claypool and Lindeman, WPI, CS and IMGD20 Game Maker: Error Messages (2 of 2)  Can write messages to log file  Can ignore messages Use "error_last" and "error_occurred" for custom handling Typically, use only in release

Claypool and Lindeman, WPI, CS and IMGD21 Debugging Tips (1 of 3)  Fix one thing at a time Don’t try to fix multiple problems  Change one thing at a time Tests hypothesis. Change back if doesn't fix problem!  Start with simpler case that works Then add more complex code, one thing at a time  Question your assumptions Don’t even assume simple stuff works, or "mature" products Ex: libraries and tutorials can have bugs  Minimize interactions Systems can interfere, or make slower, so isolate the bug to avoid complications

Claypool and Lindeman, WPI, CS and IMGD22 Debugging Tips (2 of 3)  Minimize randomness Ex: can be caused by random seed or player input. Fix input (script player) so reproducible  Break complex calculations into steps May be equation that is at fault or "cast" badly  Check boundary conditions Classic "off by one" for loops, etc.  Use debugger Breakpoints, memory watches, stack …  Check code recently changed If bug appears, may be in latest code (not even yours!)

Claypool and Lindeman, WPI, CS and IMGD23 Debugging Tips (3 of 3)  Take a break! Too close, can't see it Provide fresh prospective  Explain bug to someone else Helps retrace steps, and others provide alternate hypotheses  Debug with partner Provides new techniques Same advantage with code reviews, peer programming  Get outside help Tech support for consoles, Web examples, libraries, …

Claypool and Lindeman, WPI, CS and IMGD24 Tough Debugging Scenarios and Patterns (1 of 3)  Bug in Release but not in Debug Often in initialized code Or in optimized code  Turn on optimizations one-by-one  Bug in Hardware but not in Dev Kit Usually dev kit has extra memory (for tracing, etc.). Suggests memory problem (pointers), stack overflow, not checking memory allocation  Bug Disappears when Changing Something Innocuous Likely timing problem (race condition) or memory problem Even if looks like gone, probably just moved  Keep looking! Based on Chapter 3.5, Introduction to Game Development

Claypool and Lindeman, WPI, CS and IMGD25 Tough Debugging Scenarios and Patterns (2 of 3)  Truly Intermittent Problems Maybe best you can do is grab all data values (and stack, etc.) and look at ("Send Error Report")  Unexplainable Behavior Ex: values change without touching. Usually memory problem. Could be from supporting system. Retry, rebuild, reboot, re-install. Based on Chapter 3.5, Introduction to Game Development

Claypool and Lindeman, WPI, CS and IMGD26 Tough Debugging Scenarios and Patterns (3 of 3)  Bug in Someone Else’s Code “No it is not.” Be persistent with own code first. Find concrete support for your claim!  Small reproduction case It's not in hardware  Ok, very, rarely, but expect it not to be, unless you are designing the hardware too!  Download latest firmware, drivers If really is, best bet is to help isolate to speed others in fixing it Meanwhile, you probably need to find a workaround or alternative  There is usually more than one way to write the code you want!