Debugging & Profiling with Open Source SW Tools



Similar documents
Understanding and Detec.ng Real- World Performance Bugs

Testing for Security

Monitoring, Tracing, Debugging (Under Construction)

Get the Better of Memory Leaks with Valgrind Whitepaper

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

Debugging with TotalView

Protec'ng Informa'on Assets - Week 8 - Business Continuity and Disaster Recovery Planning. MIS 5206 Protec/ng Informa/on Assets Greg Senko

Valgrind BoF Ideas, new features and directions

Oracle Solaris Studio Code Analyzer

Overview on Modern Accelerators and Programming Paradigms Ivan Giro7o

System/Networking performance analytics with perf. Hannes Frederic Sowa

Introducing the IBM Software Development Kit for PowerLinux

Leak Check Version 2.1 for Linux TM

Real-time Debugging using GDB Tracepoints and other Eclipse features

Building Embedded Systems

Peach Fuzzer Platform

Offensive & Defensive & Forensic Techniques for Determining Web User Iden<ty

Security Testing OpenGGSN: a Case Study

Effec%ve AX 2012 Upgrade Project Planning and Microso< Sure Step. Arbela Technologies

id_prob_result_coredump_aix.ppt Page 1 of 15

Kaseya Fundamentals Workshop DAY THREE. Developed by Kaseya University. Powered by IT Scholars

CSE/ISE 311: Systems Administra5on Logging

Software Development Tools for Embedded Systems. Hesen Zhang

OS/Run'me and Execu'on Time Produc'vity

High Performance Computing Facility Specifications, Policies and Usage. Supercomputer Project. Bibliotheca Alexandrina

Mission. To provide higher technological educa5on with quality, preparing. competent professionals, with sound founda5ons in science, technology

Nodes, Ties and Influence

Suppor&ng the Design of Safety Cri&cal Systems Using AADL

This presentation explains how to monitor memory consumption of DataStage processes during run time.

Example of Standard API

Eliminate Memory Errors and Improve Program Stability

Perf Tool: Performance Analysis Tool for Linux

Protec'ng Communica'on Networks, Devices, and their Users: Technology and Psychology

Compute Cluster Server Lab 3: Debugging the parallel MPI programs in Microsoft Visual Studio 2005

Bug hunting. Vulnerability finding methods in Windows 32 environments compared. FX of Phenoelit

Software Development Processes For Embedded Development A checklist for efficient development using open-source tools

Introduction. Created by Richard Bell 10/29/2014

DTCC Data Quality Survey Industry Report

C Programming Review & Productivity Tools

Winning the Battle against Automated Testing. Elena Laskavaia March 2016

Frysk The Systems Monitoring and Debugging Tool. Andrew Cagney

Introduction to Java and Eclipse

Week 2 Practical Objects and Turtles

1. Base Programming. GIORGIO RUSSOLILLO - Cours de prépara+on à la cer+fica+on SAS «Base Programming»

Getting Started with CodeXL

Parallel Debugging with DDT

Parallel and Distributed Computing Programming Assignment 1

Red Hat Linux Internals

Achieving business benefits through automated software testing. By Dr. Mike Bartley, Founder and CEO, TVS

Valgrind Documentation

Announcement. SOFT1902 Software Development Tools. Today s Lecture. Version Control. Multiple iterations. What is Version Control

GPU Tools Sandra Wienke

Development at the Speed and Scale of Google. Ashish Kumar Engineering Tools

RTOS Debugger for ecos

Introduction. Application Security. Reasons For Reverse Engineering. This lecture. Java Byte Code

find model parameters, to validate models, and to develop inputs for models. c 1994 Raj Jain 7.1

What is Assessment? Assessment is a process of collec3ng data for the purpose of making decisions about individuals and groups

Basic Unix/Linux 1. Software Testing Interview Prep

Java Debugging Ľuboš Koščo

Bacula Open Source Project Bacula Systems (professional support)

OpenFOAM: Computational Fluid Dynamics. Gauss Siedel iteration : (L + D) * x new = b - U * x old

Jonathan Worthington Scarborough Linux User Group

Introduc)on to. Eric Nagler 11/15/11

#pragma omp critical x = x + 1; !$OMP CRITICAL X = X + 1!$OMP END CRITICAL. (Very inefficiant) example using critical instead of reduction:

CodeWarrior for Power Architecture Errata

Instrumentation Software Profiling

ELEC 377. Operating Systems. Week 1 Class 3

Oak Ridge National Laboratory Computing and Computational Sciences Directorate. Lustre Crash Dumps And Log Files

Attacking Obfuscated Code with IDA Pro. Chris Eagle

Java Troubleshooting and Performance

Legacy Archiving How many lights do you leave on? September 14 th, 2015

Using the Intel Inspector XE

Red Hat Developer Toolset 1.1

Sequential Performance Analysis with Callgrind and KCachegrind

Chapter 9: Building Bigger Programs

Phone Systems Buyer s Guide

Table of Contents. The RCS MINI HOWTO


Zend Server 4.0 Beta 2 Release Announcement What s new in Zend Server 4.0 Beta 2 Updates and Improvements Resolved Issues Installation Issues

Helping you avoid stack overflow crashes!

Ubuntu, FEAP, and Virtualiza3on. Jonathan Wong Lab Mee3ng 11/08/10

Basics of VTune Performance Analyzer. Intel Software College. Objectives. VTune Performance Analyzer. Agenda

Online Enrollment Op>ons - Sales Training Benefi+ocus.com, Inc. All rights reserved. Confiden>al and Proprietary 1

co Characterizing and Tracing Packet Floods Using Cisco R

Andreas Burghart 6 October 2014 v1.0

Time Limit: X Flags: -std=gnu99 -w -O2 -fomitframe-pointer. Time Limit: X. Flags: -std=c++0x -w -O2 -fomit-frame-pointer - lm

Transcription:

Debugging & Profiling with Open Source SW Tools Ivan Giro*o igiro*o@ictp.it Informa(on & Communica(on Technology Sec(on (ICTS) Interna(onal Centre for Theore(cal Physics (ICTP)

What is Debugging?! Iden(fying the cause of an error and correc(ng it Once you have iden(fied defects, you need to: find and understand the cause remove the defect from your code In a large number of cases bug fixes are wrong: they remove the symptom, but not the cause Improve produc(vity by geing it right the first (me A lot of programmers don't know how to debug! Doesn't add func(onality & doesn't improve the science Debugging needs prac(ce and experience: understand the science and the tools 2

Lot of (me debugging. We did learn also from it, but I have the feeling we could have learnt more things about Quantum Espresso if we hadn't had to be debugging for so long (some of the bugs we had were due to our lack of excellence in programming skills and were not specific to QE issues) (Cit. from ICTP Ac(vity evalua(on) 3

Errors are Opportuni(es Learn from the program you're working on: Errors mean you didn't understand the program. If you knew it bener, it wouldn't have an error. You would have fixed it already Learn about the kinds of mistakes you make: If you wrote the program, you inserted the error Once you find a mistake, ask yourself: Why did you make it? How could you have found it more quickly? How could you have prevented it? Are there other similar mistakes in the code? 4

The Nature of Bugs Straigh\orward bug to intercept and solve The program crashes unexpectedly the problem can be easily reproduced (lucky) bug whose causes are too complex to be reliably reproduced; it thus defies repair bug disappears when debugging a problem (compiling with - g or adding prints) The produced numbers differ from what we expected bug generated by an invalid opera(ons bug disappears when debugging a problem (compiling with - g or adding prints) 5

Main Reasons of Debugging Floa(ng Point Excep(ons (FPE) Overflow Invalid Number Division by Zero Out of bound Segmenta(on Fault Not expected execu(on flow The Program Hangs 6

Purpose of a Debugger More informa(on than print statements Allows to stop/start/single step execu(on Look at data and modify it 'Post mortem' analysis from core dumps Prove / disprove hypotheses No subs(tute for good thinking But, some(mes good thinking is not a subs(tute for effec(vely using a debugger! Easier to use with modular code 7

Approaches Print Messages and Variables J Compiler Debug Op(ons Core analysis Run the Program with a Debugger ANach Debugger to a running process Ask for help! 8

Using a Debugger When compiling use - g op(on to include debug info in object (.o) and executable (and possibly - O0) 1:1 mapping of execu(on and source code only when op(miza(on is turned off problem when op(miza(on uncovers bug GNU compilers allow - g with op(miza(on not always correct line numbers variables/code can be 'op(mized away progress confusing with loop unrolling 9

Using gdb as a Debugger gdb ex01- c launches debugger, loads binary, stops with (gdb) prompt wai(ng for input: run starts executable, arguments are passed Running program can be interrupted (ctrl- c) gdb./prog - - args arg1 - flag passes all arguments to the run command inside gdb conjnue con(nues stopped program finish con(nues un(l the end of a subrou(ne step single steps through program line by line next single steps but doesn't step into subrou(nes 10

More Basic gdb Commands print displays contents of a known data object display is like print but shows updates every step where shows stack trace (of func(on calls) up/down allows to move up/down on the stack break sets break point (uncondi(onal stop), loca(on indicated by file name+line no. or func(on watch sets a condi(onal break point (breaks when an expression changes, e.g. a variable) delete removes display or break points 11

Post Mortem Analysis Enable core dumps: ulimit - c unlimited Run executable un(l it crashes; will generate a file core or core.<pid> with memory image Load executable and core dump into debugger gdb myexe core.<pid> Inspect loca(on of crash through commands: where, up, down, list Use directory to point to loca(on of sources 12

Using valgrind Run valgrind - v./exe to instrument and run - - leak- check=full - - track- origins=yes Output will list individual errors and summary With debug info present can resolve problems to line of code, otherwise to name of func(on Also monitors memory alloca(on / dealloca(on to flag memory leaks ( forgonen alloca(ons) Instrumenta(on slows down execu(on Can produce false posi(ves (flag non- errors) 13

How to NOT do Debugging Find the error by guessing Change things randomly un(l it works (again) Don't keep track of what you changed Don't make a backup of the original Fix the error with the most obvious fix If wrong code gives the correct result, and changing it doesn't work, don't correct it. If the error is gone, the problem is solved. Trying to understand the problem, is a waste of (me 14

Debugging Tools Source code comparison and management tools: diff, vimdiff, emacs/ediff, cvs/svn/git Help you to find differences, origins of changes Source code analysis tools: compiler warnings, wnchek, lint Help you to find problema(c code Always enable warnings when programming Always take warnings seriously (but not all) Always compile/test on mul(ple pla\orms Bounds checking allows checking of (sta(c) memory alloca(on viola(ons (no malloc) 15

More Debugging Tools Using different compilers (Intel, GCC, Clang,...) Debuggers and debugger frontends: gdb (GNU compilers), idb (Intel compilers), ddd (GUI), eclipse (IDE), and many more... gprof (profiler) as it can generate call graphs valgrind, an instrumenta(on framework Memcheck: detects memory management problems Cachegrind: cache profiler, detects cache misses Callgrind: call graph crea(on tool 16

How to Report a Bug(?) to Others Research whether bug is known/fixed web search, mailing list archive, bugzilla Provide descrip(on on how to reproduce the problem. Find a minimal input to show bug. Always state hardware/sowware you are using (distribu(on, compilers, code version) Demonstrate, that you have invested effort Make it easy for others to help you! 17

Profiling Essen(al opera(on for code op(miza(on Profiling usually means: Instrumenta(on of code (e.g. during compila(on) Automated collec(on of (ming data during execu(on Analysis of collected data, breakdown by func(on Example: gcc - o some_exe.x - pg some_code.c./some_exe.x gprof some_exe.x gmon.out Profiling is owen incompa(ble with code op(miza(on or can be misleading (inlining) 18

19

PERF Hardware Assisted Profiling Modern x86 CPUs contain performance monitor tools included in their hardware Linux kernel versions support this feature which allows for very low overhead profiling without instrumenta(on of binaries perf stat./a.out - > profile summary perf record./a.out; perf report - i perf.data gprof like func(on level profiling (with coverage report and disassembly, if debug info present) 20

21

Func(on for Internal Profiling #include <time.h> #include <ctype.h> #include <sys/types.h> #include <sys/time.h> double seconds() /* Returns elepsed seconds past from the last call to timer rest */ { } struct timeval tmp; double sec; gettimeofday( &tmp, (struct timezone *)0 ); sec = tmp.tv_sec + ((double)tmp.tv_usec)/1000000.0; return sec; 22

Ivan GiroNo Debugging & Profiling with Open Source SW Tools 23

Profiling in Python individual func(ons: import cprofile cprofile.run('some_func()', 'profile.tmp') whole script: python - m cprofile [- o output_file] [- s sort_order] myscript.py Analyze profile file: import pstats p = pstats.stats('profile.tmp') p.strip_dirs().sort_stats(- 1).print_stats() More info at hnp://docs.python.org/2/library/profile.html 24

Debugging Python typically very easy to do interac(vely with "print()" and "exit()" statements in the code More featureful debugger available in module "pdb", see: hnp://docs.python.org/2.7/library/pdb.html 25

References PERF wiki 26