Debugging 15-441 Computer Networks Sep. 26, 2007 Seunghwan Hong.

Slides:



Advertisements
Similar presentations
Detecting Bugs Using Assertions Ben Scribner. Defining the Problem  Bugs exist  Unexpected errors happen Hardware failures Loss of data Data may exist.
Advertisements

COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Version Control System (Sub)Version Control (SVN).
DEBUGGING IN THE REAL WORLD : Recitation 4.
How to Optimize Your Existing Regression Testing Arthur Hicken May 2012.
Race Conditions. Isolated & Non-Isolated Processes Isolated: Do not share state with other processes –The output of process is unaffected by run of other.
Debugging Introduction to Computing Science and Programming I.
Ch. 1: Software Development (Read) 5 Phases of Software Life Cycle: Problem Analysis and Specification Design Implementation (Coding) Testing, Execution.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
Introduction to a Programming Environment
DEBUGGERS For CS302 Data Structures Course Slides prepared by TALHA OZ (most of the text is from
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
Debugging Tips for Programmers. Outline Script debugging Script debugging –C shell –BASH/Bourne/Korn shell tips Compiled language debugging Compiled language.
CSE 486/586 CSE 486/586 Distributed Systems PA Best Practices Steve Ko Computer Sciences and Engineering University at Buffalo.
Homework Reading Programming Assignments
CIS*2450 Seminar I Makefiles Debugging/Design Approaches Exception Handling Library Revision Control Designed by: Terry Moreland Updated by: Tom Crabtree.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 15: Linked data structures.
Designing For Testability. Incorporate design features that facilitate testing Include features to: –Support test automation at all levels (unit, integration,
DEBUGGING CHAPTER Topics  Getting Started with Debugging  Types of Bugs –Compile-Time Bugs –Bugs Attaching Scripts –Runtime Errors  Stepping.
General Programming Introduction to Computing Science and Programming I.
1 Boot Camp Dave Eckhardt 1 This Is a Hard Class ● Traditional hazards – 410 letter grade one lower than other classes – All other.
1 Project Information and Acceptance Testing Integrating Your Code Final Code Submission Acceptance Testing Other Advice and Reminders.
Errors And How to Handle Them. GIGO There is a saying in computer science: “Garbage in, garbage out.” Is this true, or is it just an excuse for bad programming?
Creating your first C++ program
Goals: To gain an understanding of assembly To get your hands dirty in GDB.
Debugging. Compile problems Read the whole complaint! Runtime problems –Exceptions –Incorrect behavior.
1 Debugging: Catching Bugs ( II ) Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures.
Problem of the Day  Why are manhole covers round?
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.
COMP 111 Threads and concurrency Sept 28, Tufts University Computer Science2 Who is this guy? I am not Prof. Couch Obvious? Sam Guyer New assistant.
CSE 232: C++ debugging in Visual Studio and emacs C++ Debugging (in Visual Studio and emacs) We’ve looked at programs from a text-based mode –Shell commands.
Debugging and Profiling With some help from Software Carpentry resources.
CS Class 05 Topics  Selection: switch statement Announcements  Read pages 74-83, ,
Slide 1 Project 1 Task 2 T&N3311 PJ1 Information & Communications Technology HD in Telecommunications and Networking Task 2 Briefing The Design of a Computer.
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.
CSE 123 Discussion 10/05/2015 Updated from Anup and Narendran’s excellent notes.
Design - programming Cmpe 450 Fall Dynamic Analysis Software quality Design carefully from the start Simple and clean Fewer errors Finding errors.
Debugging of # P. Hristov 04/03/2013. Introduction Difficult problem – The behavior is “random” and depends on the “history” – The debugger doesn’t.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
12/14/2015 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada 1 Automated Testing Environment Concepts.
CPS120: Introduction to Computer Science Compiling a C++ Program From The Command Line.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Version Control and SVN ECE 297. Why Do We Need Version Control?
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.
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.
Defensive Programming. Good programming practices that protect you from your own programming mistakes, as well as those of others – Assertions – Parameter.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
1 ENERGY 211 / CME 211 Lecture 14 October 22, 2008.
CS 5150 Software Engineering Lecture 21 Reliability 2.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Institute of Radio Physics and Electronics and Indian GNU/Linux Users Group Kolkata.
Development Environment
Unit Testing.
Dynamic Analysis ddaa.
CSE 374 Programming Concepts & Tools
Testing and Debugging.
gdb gdb is the GNU debugger on our CS machines.
Lab: ssh, scp, gdb, valgrind
TRANSLATORS AND IDEs Key Revision Points.
Lab: ssh, scp, gdb, valgrind
Common C Programming Errors, GDB Debugging
Homework Reading Programming Assignments Finish K&R Chapter 1
CS 240 – Advanced Programming Concepts
Error Handling.
The Troubleshooting theory
Debugging.
Presentation transcript:

Debugging Computer Networks Sep. 26, 2007 Seunghwan Hong

Project 1 Finished 1. Start working on Project 2 a) many debugging issues for this project b) start early (time is short) 2. Questions a) don’t hesitate to contact staff members b) send to or post on

Overview 1. What is Debugging? 2. Debugging Strategies 3. Debugging Tools Printf(), GDB, Smart Logging, Electric Fence, Valgrind, and GDB on emacs

What is Debugging? 1. Everybody writes bugs Fixing bugs is a part of your assignment Writing a clean code is a part of debugging process 2. Things to think about what causes the bug? how do you find it? how can you avoid it?

How to avoid Bug? 1. Write a clean design a) What type of data structure to use b) How different modules interact c) Document it before actual coding! 2. Use assertion / sanity check

Debugging Strategy #1 Debug requires deep thinking… If you have no idea what causes the error…. - Make hypothesis (assumptions) on your code Don’t just change your code Think of the architecture, data structure, etc Use pen & paper to organize your thinking

Debugging Strategy #2 Don’t think too much ALONE! - Use your teammate, course staff Ask to someone who don’t know your code - Ask to TA’s: you need to carefully tell what is wrong

Debugging Strategy #3 Writing and testing code incrementally - Recommend to write a new code, test it, and then integrate with the previous work - Prevents combination of errors from different modules - Look at the recent modifications if you find a new bug - svn diff Helps a LOT

Debugging Strategy #4 You are writing a complex code for this class - thousands of lines total - thousands of packets are sent/received at a second - various data structures are involved in one program Catching a bug by stepping through? - DUMP information (to be discussed later…) - Search information to find the oddity

Debugging Strategy #5 Take a BREAK! sometimes, it is more efficient to rest your brain and return to work later Suggested Options: a) nap – dangerous if you are spending the whole night b) shower – you can help removing the common myth: “CS people don’t take a shower” c) running – from the former recitation note

Printf(“We found a bug!\n”) 1. Easy to write printf()! a) Easy to implement: unless you don’t know C… b) Easy to catch where the bug happens 2. printf() is not easy a) You may need to insert printf() b/w every instruction b) Difficult to catch why the bug happens c) You may print all data structures, possible? d) Not a safe way to debug

GDB 1. Be familiar with it a) We provide basic commands b) Search on the web if you forget…. c) You must be familiar with this from ! 2. Easier to find what causes the bug

GDB - Continued 1. GDB can be a bad choice! a) network programming b) multi-thread programming 2. Specific for GDB stops a program at a specific location - On communication, stopping one program means ‘connection lost’

GDB Commands Control Executions run break stepi nexti Get Info backtrace print Info registers /locals list up/down Find more commands on Google!

GDB Help 1. For debugging, always compile with –g, and no optimizations. 2. Two ways to run GDB a) gdb binary (to run binary on gdb) b) gdb binary core-file (to debug crashed program) c) Type ‘unlimit coredumpsize’ to get core files. 3. Use GDB on emacs

Log Files 1. Main Idea: dump useful information - create a log file - what information should be dumped? 2. Efficient at catching logic bugs 3. Effective when it is hard to generate the same outcome again (network programming) - the order or arriving packets can be different from each simulation, therefore different result

Log Files Example /* example code for P2 */ #define FILENAME “441_p2_dummy_” // file name /* flag: dump if TRUE, take no action otherwise modify the value before compile */ int dump_flag = FALSE;/* initialization */ /* function prototypes */ void dump_packet (struct packet *p); void dump_graph(struct graph *g);

Log Files Example - Continue int receive_pkt (struct packet *p) { … /* some code */ /* dump packet info to check everything is OK */ dump_packet(p); /* process graph */ /* dump graph info to check everything is OK */ dump_graph(graph); … }

Electric Fence 1. Finds memory-related errors in your program - e.g.: writing out of bounds, use after free… 2. Compile your program using –lefence 3. Demo…..

Valgrind 1. Type valgrind -ax 2. Demo…

Using GDB on 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 "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...)

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

Questions?

Have a Nice Day!