Debugging: Tips and Tools Also, Aloha 15-441 Recitation Wednesday, February 7th, 2007.

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Advertisements

Why care about debugging? How many of you have written a program that worked perfectly the first time? No one (including me!) writes a program that works.
Version Control System (Sub)Version Control (SVN).
DEBUGGING IN THE REAL WORLD : Recitation 4.
Debugging Introduction to Computing Science and Programming I.
Traffic Server Debugging using ASAN / TSAN Brian Geffon.
Environment & tools Assistant Anssi Jääskeläinen Visiting hours: Tuesdays Room: 6606
THEMIS Science Software Training1July 2007 The THEMIS Graphical User Interface J. McTiernan 23-Jul-2007
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
16/27/2015 3:38 AM6/27/2015 3:38 AM6/27/2015 3:38 AMTesting and Debugging Testing The process of verifying the software performs to the specifications.
2/9/2007EECS150 Lab Lecture #41 Debugging EECS150 Spring2007 – Lab Lecture #4 Laura Pelton Greg Gibeling.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
Debugging Tips for Programmers. Outline Script debugging Script debugging –C shell –BASH/Bourne/Korn shell tips Compiled language debugging Compiled language.
CIS*2450 Seminar I Makefiles Debugging/Design Approaches Exception Handling Library Revision Control Designed by: Terry Moreland Updated by: Tom Crabtree.
Designing For Testability. Incorporate design features that facilitate testing Include features to: –Support test automation at all levels (unit, integration,
Problem Determination Your mind is your most important tool!
General Programming Introduction to Computing Science and Programming I.
CS 122 Engineering Computation Lab Lab 2 Dan De Sousa and Tim Cheeseman Department of Computer Science Drexel University April 2009 ©By the author. All.
Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.
Program Development Life Cycle (PDLC)
Compiling & Debugging Quick tutorial. What is gcc? Gcc is the GNU Project C compiler A command-line program Gcc takes C source files as input Outputs.
1 Debugging: Catching Bugs ( II ) Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures.
DEBUGGING. BUG A software bug is an error, flaw, failure, or fault in a computer program or system that causes it to produce an incorrect or unexpected.
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.
Debugging Strategies from Software Carpentry. Agan's Rules Many people make debugging harder than it needs to be by: Using inadequate tools Not going.
Making Good Code AKA: So, You Wrote Some Code. Now What? Ray Haggerty July 23, 2015.
Debugging and Profiling With some help from Software Carpentry resources.
CS Class 05 Topics  Selection: switch statement Announcements  Read pages 74-83, ,
CSE 332: C++ debugging Why Debug a Program? When your program crashes –Finding out where it crashed –Examining program memory at that point When a bug.
Agenda Attack Lab C Exercises C Conventions C Debugging
1 SEEM3460 Tutorial Compiling and Debugging C programs.
CSE 351 GDB Introduction. Lab 1 Status? How is Lab 1 going? I’ll be available at the end of class to answer questions There are office hours later today.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
Debugging Computer Networks Sep. 26, 2007 Seunghwan Hong.
Design - programming Cmpe 450 Fall Dynamic Analysis Software quality Design carefully from the start Simple and clean Fewer errors Finding errors.
C++ crash course Class 9 flight times program, using gdb.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
Object-Oriented Programming (Java). 2 Topics Covered Today Unit 1.1 Java Applications –1.1.8 Debugging –1.1.9 Debugging with Eclipse.
School of Computer Science & Information Technology G6DICP - Lecture 6 Errors, bugs and debugging.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Unit - V. Debugging GNU Debugger helps you in getting information about the following: 1.If a core dump happened, then what statement or expression did.
Lab 9 Department of Computer Science and Information Engineering National Taiwan University Lab9 - Debugging I 2014/11/4/ 28 1.
Efficiently Solving Computer Programming Problems Doncho Minkov Telerik Corporation Technical Trainer.
Systems Dev. Tutorial IV: Debugging: Tips and Tools Recitation Wednesday, Sept 27th, 2006.
CSE 332: C++ expressions Expressions: Operators and Operands Operators obey arity, associativity, and precedence int result = 2 * 3 + 5; // assigns 11.
1 ENERGY 211 / CME 211 Lecture 14 October 22, 2008.
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.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
C Debugging Workshop using gdb Jürgen Weigert Documentation & Legal Team openSUSE.org
Gnu Debugger (gdb) Debuggers are used to: Find semantic errors Locate seg faults and bus errors Prepared by Dr. Spiegel.
DEBUG.
Development Environment
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Programming and File Management Part 2
CSE 374 Programming Concepts & Tools
Testing and Debugging.
Debugging CMSC 202.
Lab: ssh, scp, gdb, valgrind
COMP 2710 Software Construction Introduction to GDB
TRANSLATORS AND IDEs Key Revision Points.
Lab: ssh, scp, gdb, valgrind
Common C Programming Errors, GDB Debugging
CSE 403 Lecture 17 Coding.
Debugging at Scale.
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science
Debugging EECS150 Fall Lab Lecture #4 Sarah Swisher
Debugging EECS150 Fall Lab Lecture #4 Sarah Swisher
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
Debugging.
Presentation transcript:

Debugging: Tips and Tools Also, Aloha Recitation Wednesday, February 7th, 2007

Aloha Radio protocol Pure/Slotted, whats the difference? Why bother? Chalkboard

Overview What is debugging? Strategies to live (or at least code) by. Tools of the trade gdb smart logging electric fence Good tip sheet from last semesters TA at :

What is debugging? You tell me! Everybody writes codes with bugs. What debugging have you needed to do already on the smtp project? Things to think about: - What caused the bug? - How did you end up finding it? - How could you have avoided the bug in the first- place?

Debugging Philosophy Guiding Steps: 1) Think about why you believe the program should produce the output you expected. 2) Make assertions until you understand how your view differs from the computer’s. Coder: code will produce output X … Computer: code will produce Z….

Requirements for Debugging WHAT program behavior to look for? Sometimes this is nearly free.... (e.g., compiler error, or segfault) Sometimes it is the hardest part.... (e.g., logic bugs, race conditions) How to easily expose information to test hypothesis? gdb, logging, strace, ethereal....

Strategies to Live By... Debugging is part art, part science. You’ll improve with experience…. … but we can try to give you a jump-start!

Strategy #1: Debug with Purpose Don't just change code and “hope” you'll fix the problem! Instead, make the bug reproducible, then use methodical “Hypothesis Testing”: While(bug) { Ask, what is the simplest input that produces the bug? Identify assumptions that you made about program operation that could be false. Ask yourself “How does the outcome of this test/change guide me toward finding the problem?” Use pen & paper to stay organized! }

Strategy #2: Explain it to Someone Else Often explaining the bug to “someone” unfamiliar with the program forces you to look at the problem in a different way. Before you actually the TA’s: Write an to convince them that you have eliminated all possible explanations....

Strategy #3: Focus on Recent Changes If you find a NEW bug, ask: what code did I change recently? This favors: - writing and testing code incrementally - using 'svn diff' to see recent changes - Lession: Check in often! - regression testing (making sure new changes don't break old code).

strategy #4: When in doubt, dump state In complex programs, reasoning about where the bug is can be hard, and stepping through in a debugger time-consuming. Sometimes its easier to just “dump state” and scan through for what seems “odd” to zero in on the problem. Example: Dumping all packets using tcpdump.

Strategy #5 : Get some distance... Sometimes, you can be TOO CLOSE to the code to see the problem. Go for a run, take a shower, whatever relaxes you but let's your mind continue to spin in the background.

strategy #6: Let others work for you! Sometimes, error detecting tools make certain bugs easy to find. We just have to use them. Electric Fence or Valgrind: runtime tools to detect memory errors Extra GCC flags to statically catch errors: -Wall, -Wextra, -Wshadow, -Wunreachable-code -Entire page of warnings goodness at gcc.gnu.org/onlinedocs/gcc4.1.1/WarningOption s.html

Strategy #7: Think Ahead Bugs often represent your misunderstanding of a software interface. Once you've fixed a bug: 1) Smile 2) Think about if the bug you fixed might manifest itself elsewhere in your code (a quick grep can help). 3) Think about how to avoid this bug in the future (maybe coding 36 straight hours before the deadline isn't the most efficient approach....)

Tools of the Trade Different bugs require different tools: 1) Program crashes with segfault -> gdb 2) Hard to reproduce or highly complex bugs -> logging & analysis 3) Program hangs waiting for network traffic -> tcpdump / ethereal

GDB: Learn to Love it Run a program, see where it crashes, or stop it in the middle of running to examine program state. Two ways to run: gdb binary (to run binary inside of gdb) gdb binary core-file (to debug crashed program)

GDB Commands Controlling Execution run break step next control-c Getting Info backtrace print info locals list up/down Tons of commands: google : gdb command list Watches!

GDB Tricks & Tips Remember: always compile with -g, and no optimizations. If your not getting core files, type: ‘unlimit coredumpsize’ You can use GDB in emacs! (see slides at end)

Smart Logging Use a debug macro that you can easily turn off to suppress output just by changing one line. (example posted online) Often smart to create generic log functions like dumpSMTPMessage() or dumpRoutingPacket() A tool like 'strace' or 'ktrace' may be able to log easily read information for free!

Electric Fence Adds run-time checks to your program to find errors related to malloc. e.g.: writing out of bounds, use after free... just compile your programs using -lefence Demo Alternative: Valgrind finds more memory errors, but is VERY slow.

Valgrind Just type valgrind -ax For example valgrind smtpsend -ax Demonstration

Time for a demonstration

Using GDB in Emacs The commands/keystrokes to make it happen: 1. Compile with -g and *NO* -O2 or -O3 2. build with a "make" 3. emacs smtpsend.c (or any other source file) 4. CTRL+x and then '3' (open a right frame) 5. CTRL+x and then 'o' (switch cursor to right frame) 6. ESC+x and then "gdb" and hit enter 7. Type in the name of your binary *only*, like "smtpsend" and hit enter 8. Set any break points you want, then type "run params...", for example "run andrew.cmu.edu" and hit enter 9. Use GDB with your code!! (next, step, print, display...)

GDB in Emacs Note the arrow in the left source file window shows the line being executed!

That’s It! Questions?