Systems Dev. Tutorial IV: Debugging: Tips and Tools 15-441 Recitation Wednesday, Sept 27th, 2006.

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.
DEBUGGING IN THE REAL WORLD : Recitation 4.
Debugging Introduction to Computing Science and Programming I.
THEMIS Science Software Training1July 2007 The THEMIS Graphical User Interface J. McTiernan 23-Jul-2007
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.
Activity 1 - WBs 5 mins Go online and spend a moment trying to find out the difference between: HIGH LEVEL programming languages and LOW LEVEL programming.
How Do I Find a Job to Apply to?
Debugging Tips for Programmers. Outline Script debugging Script debugging –C shell –BASH/Bourne/Korn shell tips Compiled language debugging Compiled language.
Chocolate Bar! luqili. Milestone 3 Speed 11% of final mark 7%: path quality and speed –Some cleverness required for full marks –Implement some A* techniques.
CIS*2450 Seminar I Makefiles Debugging/Design Approaches Exception Handling Library Revision Control Designed by: Terry Moreland Updated by: Tom Crabtree.
Problem Determination Your mind is your most important tool!
General Programming Introduction to Computing Science and Programming I.
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.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
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, ,
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.
Debugging of # P. Hristov 04/03/2013. Introduction Difficult problem – The behavior is “random” and depends on the “history” – The debugger doesn’t.
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.
Intermediate 2 Computing Unit 2 - Software Development.
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.
CS12230 Introduction to Programming Lecture 6-2 –Errors and Exceptions 1.
How to Improve Your Grades Are your grades rather low? Maybe it's the beginning of school, and your not getting off to a good start. Well, this easy to.
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.
Debugging: Tips and Tools Also, Aloha Recitation Wednesday, February 7th, 2007.
CSE 332: C++ expressions Expressions: Operators and Operands Operators obey arity, associativity, and precedence int result = 2 * 3 + 5; // assigns 11.
How to Revise well… By 10W. Equipment Creating good notes to revise from is important when working, the following equipment can help create imaginative.
Overview of OpenPegasus Debugging Hints and Tips Karl Schopmeyer Project Coordinator, Pegasus Open Source Project October 2013.
1 ENERGY 211 / CME 211 Lecture 14 October 22, 2008.
10 Great Ways to Stop Procrastinating and Get More Done in Less Time Time Management Tips by Arman Sadeghi.
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
DEBUG.
Development Environment
Introduction to Computing Science and Programming I
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Programming and File Management Part 2
CSE 374 Programming Concepts & Tools
CS1101X Programming Methodology
Testing and Debugging.
Debugging CMSC 202.
Lab: ssh, scp, gdb, valgrind
COMP 2710 Software Construction Introduction to GDB
Lab: ssh, scp, gdb, valgrind
Common C Programming Errors, GDB Debugging
CSCE 315 – Programming Studio, Fall 2017 Tanzir Ahmed
CSE 403 Lecture 17 Coding.
Debugging at Scale.
Using a Debugger 1-Jan-19.
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
Debugging.
Presentation transcript:

Systems Dev. Tutorial IV: Debugging: Tips and Tools Recitation Wednesday, Sept 27th, 2006

Overview What is debugging? Strategies to live (or at least code) by. Tools of the trade gdb smart logging electric fence ethereal/tcpdump

What is debugging? You tell me! Everybody writes codes with bugs. What debugging have you needed to do already on the IRC 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 - 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

Strategy #7: Think Ahead Bugs often represent your misunderstanding of a software interface. Once you've fixed a bug: 1) Smile and do a little victory dance.... 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

GDB Tricks & Tips See handout for detailed explanations, and abbreviations 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 dumpIRCMessage() 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 Alternative: Valgrind finds more memory errors, but is VERY slow.

tcpdump & ethereal Helps you understand what is happening “below” your networking code. Benefits Often will automatically parse well known protocols for you! (like, say... IRC) Accept filters to ignore unimportant packets Downsides Need root access

That’s It! Questions? Feedback from Checkpoint 2?

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 sircd.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 "sircd" and hit enter 8. Set any break points you want, then type "run params...", for example "run 1 node1.conf" 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!