Debugging. Erwan Demairy Dream

Similar documents
CS2141 Software Development using C/C++ Debugging

Jlint status of version 3.0

Reviewing gcc, make, gdb, and Linux Editors 1

Welcome. HRSK Practical on Debugging, Zellescher Weg 12 Willers-Bau A106 Tel

Testing and Debugging C Programming and Software Tools. N.C. State Department of Computer Science

Debugging with gdb and valgrind

Computer Labs: Debugging

int n = 10; int sum = 10; while (n > 1) { sum = sum + n; n--; } cout << "The sum of the integers 1 to 10 is " << sum << endl;

CptS 360 (System Programming) Unit 4: Debugging

Programming Studio #9 ECE 190

Debugging with GDB and DDT

Debugging and Profiling

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

Performance Measurement

Programming in C First meeting Tiina Niklander

12. Debugging. Overview. COMP1917: Computing 1. Developing Programs. The Programming Cycle. Programming cycle. Do-it-yourself debugging

Bug Hunting and Static Analysis

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

COSC Software Engineering. Lecture 16: Managing Memory Managers

Embedded Software TI2726 B. 3. C tools. Koen Langendoen. Embedded Software Group

Using a debugger. Segmentation fault? GDB to the rescue!

Programming in C First meeting

Undefined Behaviour in C

Systems software design. Software build configurations; Debugging, profiling & Quality Assurance tools

A Novel Approach to Explain the Detection of Memory Errors and Execution on Different Application Using Dr Memory.

Data and File Structures Laboratory

Debugging with GDB and DDT

CS354 gdb Tutorial Written by Chris Feilbach

Scientific Programming in C IX. Debugging

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

Deep C (and C++) by Olve Maudal

Regression testing. Whenever you find a bug. Why is this a good idea?

CS 240 Final Exam Review

Steps for project success. git status. Milestones. Deliverables. Homework 1 submitted Homework 2 will be posted October 26.

CSE 374 Programming Concepts & Tools

CSE 303, Winter 2006, Final Examination 16 March Please do not turn the page until everyone is ready.

TOS Test Center (TTC)

Debugging. Marcelo Ponce SciNet HPC Consortium University of Toronto. July 15, /41 Ontario HPC Summerschool 2016 Central Edition: Toronto

Introduction to Problem Solving and Programming in Python.

Outline. Computer programming. Debugging. What is it. Debugging. Hints. Debugging

Programming II (CS300)

CS 520 Theory and Practice of Software Engineering Fall 2018

DEBUGGING: DYNAMIC PROGRAM ANALYSIS

Programming Tips for CS758/858

Lab 8. Follow along with your TA as they demo GDB. Make sure you understand all of the commands, how and when to use them.

Formal Methods for Program Analysis and Generation

Introduction to debugging. Martin Čuma Center for High Performance Computing University of Utah

CSE 333 Midterm Exam Sample Solution 5/10/13

LAB #8. GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:

Programming in C week 1 meeting Tiina Niklander

Advanced Debugging and the Address Sanitizer

Profiling & Optimization

Assertions and Exceptions Lecture 11 Fall 2005

Intermediate Programming, Spring 2017*

EW The Source Browser might fail to start data collection properly in large projects until the Source Browser window is opened manually.

Intel Parallel Studio XE 2017 Composer Edition BETA C++ - Debug Solutions Release Notes

Computer Components. Software{ User Programs. Operating System. Hardware

Computer Organization: A Programmer's Perspective

18-600: Recitation #3

DAY 4. CS3600, Northeastern University. Alan Mislove

Programming II (CS300)

Program Correctness and Efficiency. Chapter 2

Lecture 2: C Programm

Jackson Marusarz Software Technical Consulting Engineer

CS 31: Intro to Systems Pointers and Memory. Martin Gagne Swarthmore College February 16, 2016

TI2725-C, C programming lab, course

Core dumped - on debuggers and other tools

Object Oriented Programming Exception Handling

Recitation: C Review. TA s 20 Feb 2017

ICHEC. Using Valgrind. Using Valgrind :: detecting memory errors. Introduction. Program Compilation TECHNICAL REPORT

The NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software.

Advanced Programming & C++ Language

Deep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems

Improving Linux Development with better tools. Andi Kleen. Oct 2013 Intel Corporation

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3

High Performance Computing Lecture 1. Matthew Jacob Indian Institute of Science

ECE 3210 Laboratory 1: Develop an Assembly Program

Profiling & Optimization

CSE 303 Concepts and Tools for Software Development. Magdalena Balazinska Winter 2010 Lecture 27 Final Exam Revision

DEBUGGING: OBSERVING AND TRACKING

SimGrid MC 101. Getting Started with the SimGrid Model-Checker. Da SimGrid Team. April 11, 2017

Problem Set 1: Unix Commands 1

Verification and Validation

An Overview of the BLITZ System

Making things work as expected

KDev-Valgrind : User Documentation

Lecture 07 Debugging Programs with GDB

LAB #8. Last Survey, I promise!!! Please fill out this really quick survey about paired programming and information about your declared major and CS.

Using Static Code Analysis to Find Bugs Before They Become Failures

Debugging. ICS312 Machine-Level and Systems Programming. Henri Casanova

Memory Analysis tools

Introduction to Programming (Java) 2/12

EL2310 Scientific Programming

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

Performance Measurement

Improving Linux development with better tools

Lecture 3: C Programm

CIS 551 / TCOM 401 Computer and Network Security. Spring 2007 Lecture 2

Come and join us at WebLyceum

Test- Case Reduc-on for C Compiler Bugs. John Regehr, Yang Chen, Pascal Cuoq, Eric Eide, Chucky Ellison, Xuejun Yang

Transcription:

1 Debugging Erwan Demairy Dream

2 Where are we? Tools Requirements Global architecture UML Local architecture Implementation Compilation Link Editor Compiler Linker Tests Debug Profiling Build IDE Debugger Profiler Install Time Distribution 2

3 Overview Introduction Debugging Rules Is it really a bug? Reproduce and document the bug Dichotomic search Ask for help Tools Static checking Assert statements Print statements Log files Debuggers Memory checkers Demonstrations 3

4 Bug = «something is wrong» Bug causing crash Memory mismanagement Bug causing unexpected result Right algorithm badly written Bad algorithm 4

5 Some common causes Analyse Behaviour of the written code float x = 3/2; Behaviour of the libraries strcpy( static_string, blablabla ); Behaviour of the compilation tools Failure in linking,... Behaviour of the OS, or of the programs use Several simultaneous signals,... Hardware Failures Hard disk sectors broken... 5

6 Debugging Rules 1.Document THE problem (how to reproduce the bug) BUGS file, Bugzilla, Forge bug-tracker,... 2.Clarify whether it is really a bug Is it a requirements or design mistake? E.g.: an interrupt-driven program Bad understanding of the usage? E.g.: use your washing-machine to wash your dishes Transient problems that are not considered by the program? E.g.: network failure 3.Estimate the priority and the time needed to find the bug 4.If your schedule allows it or the bug-priority requires it: Write a non-regression test Find the cause(s) of the bug 6

7 Find the cause of the bug: where is it? Dichotomy on the program Divide-and-conquer Starting point of the interval = the program's start Ending point = when the program is obviously wrong (crash or incorrect behaviour or result). The failure is before or after midway? Refine criteria that defines a program failure Ask for help when stuck Explaining objectively what is going wrong can unlock your mind Do not present your conclusions Accept a naive view Getting a fresh view on your code can open your eyes 7

8 Overview Introduction Debugging Rules Is it really a bug? Reproduce and document the bug Dichotomic search Ask for help Debugging Tools Static checking Assert statements Print statements Log files Debuggers Memory checkers Demonstrations 8

9 Debugging Tools: Static Checking 1.Use a high-level warning compiler switchs Warning = Error Can detect : Unitialized variables Dead code Forgotten returns in a non-void function gcc : -Wall -Wextra -Wfloat-equal -Werror java : -warn:+unused,uselesstypecheck,unnecessaryelse 2.Lint-like tools : more detailed check than the compiler Splint for C (not C++) Jlint for Java Ftncheck for Fortran 77 9

10 Debugging Tools: Assert Statements Assertions Pre- and post-conditions checked at runtime in a function Interrupt the program if the assertion is false and locate the failure Help to detect critical failures. E.g.: Values obviously wrong (division by zero) Impossible behavior: e.g. «assert(false)» for a default case. en C/C++ assert( x>0 ); Abort the process: a.out: assert.c:6: int main(int, char**): Assertion `x>0' failed. en Java assert( x>0 ): x = +x; Throws an AssertionError exception 10

11 Debugging Tools: Print Statements Quick and dirty way to know values at runtime Pollute your code Can slow down your program Screen IO is much slower than disk IO Change the timing of some applications Main default: you need to rebuild for each new information Conclusion For immediate debugging : better to use a debugger For production debugging : better to log to a trace file Just when you can not avoid it! 11

12 Debugging Tools: Log Used when software is distributed Similar to print statements, with disk IO instead of screen IO Example in C++ #define Nominal( A ) clog << NIV_NOMINAL << FILE << func << LINE << : << A << endl; Different debugging levels: Functional level File opened, algorithm applied,... Logging level can be changed for more details Tools Log4j, log4cpp,... 12

13 Debugging Tools: (gdb, jdb) Powerful command-line tools Thread Stack States of the variables Breakpoints, conditional breakpoints. Can give a lot of information in a single build-debugging cycle Steep Learning Curve Read the manual Fluency comes with practice Help command Switchs for the compiler gcc -g 13

14 Debugging Tools: Memory Checking Valgrind : runtime memory check for C/C++ Comes with plugins to check specific program behaviour Memcheck : default tools for pointer problems, memory leaks,... Massif : heap usage... Other tools : Electric Fence-DUMA, Mpatrol, purify, zerofault,... Main difficulties: Slow and waste a lot of memory They produce large quantities of output A lot of false positives Need practice to grasp the useful data 14

15 Examples 1. Core autopsy with gdb 2. Valgrind (plugin «memcheck») In both cases: Compile your software with -g g++ -g exemple1.cpp 15

16 Core Autopsy with gdb 16

17 Core Autopsy with gdb 17

18 Core Autopsy with gdb 18

19 Core Autopsy with gdb 19

20 Valgrind Usage Example Valgrind./a.out 20

21 Valgrind 21

22 Core Autopsy with gdb 22

23 Conclusion Use static checking tools as often as possible Set your compiler's warning-level properly and understand the output When debugging Better use a debugger Use print or log statements if no other choice Use memory checker to track down memory mismanagement Complementary Tools Ask for help when you are stuck 23

24 References Debugging: the 9 indispensable rules for finding the most elusive software and hardware problems by David J. Agans Tool manuals Library manuals Developper documentation Links: valgrind: http://valgrind.org gdb: http://www.gnu.org/software/gdb jdb: http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/jdb.html 24