Debugging with GDB and DDT

Similar documents
Debugging with GDB and DDT

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

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

DDT: A visual, parallel debugger on Ra

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

Guillimin HPC Users Meeting July 14, 2016

Debugging with TotalView

Debugging. John Lockman Texas Advanced Computing Center

DDT Debugging Techniques

Parallel Debugging with TotalView BSC-CNS

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

CSCI0330 Intro Computer Systems Doeppner. Lab 02 - Tools Lab. Due: Sunday, September 23, 2018 at 6:00 PM. 1 Introduction 0.

Debugging and profiling of MPI programs

CS2141 Software Development using C/C++ Debugging

CSE 374 Programming Concepts & Tools. Brandon Myers Winter 2015 Lecture 11 gdb and Debugging (Thanks to Hal Perkins)

SGI Altix Getting Correct Code Reiner Vogelsang SGI GmbH

Allinea DDT Debugger. Dan Mazur, McGill HPC March 5,

Debugging and Profiling

CSE 374 Programming Concepts & Tools

Parallel Debugging. ª Objective. ª Contents. ª Learn the basics of debugging parallel programs

Chapter 12 Visual Program Debugger

Data and File Structures Laboratory

GPU Debugging Made Easy. David Lecomber CTO, Allinea Software

Debugging Your CUDA Applications With CUDA-GDB

Debugging with gdb and valgrind

Debugging at Scale Lindon Locks

Using gdb to find the point of failure

TotalView. Debugging Tool Presentation. Josip Jakić

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

CSE 351. GDB Introduction

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

Laboratory Assignment #4 Debugging in Eclipse CDT 1

CS354 gdb Tutorial Written by Chris Feilbach

Using the Debugger. Michael Jantz Dr. Prasad Kulkarni

Debugging in Small Basic is the process of analysing a program to detect and fix errors or improve functionality in some way.

Source level debugging. October 18, 2016

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

Programming Studio #9 ECE 190

The First Real Bug. gdb. Computer Organization I McQuain

Short Introduction to Debugging Tools on the Cray XC40

Program Debugging. David Newman (from Tom Logan Slides from Ed Kornkven)

Exercise Session 6 Computer Architecture and Systems Programming

Performance Analysis and Debugging Tools

Tips on Using GDB to Track Down and Stamp Out Software Bugs

Laboratory 1 Semester 1 11/12

Your code must have been compiled with the -g compiler option. Example:

COSC 6374 Parallel Computation. Debugging MPI applications. Edgar Gabriel. Spring 2008

DAY 4. CS3600, Northeastern University. Alan Mislove

Le Yan Louisiana Optical Network Initiative. 8/3/2009 Scaling to Petascale Virtual Summer School

18-600: Recitation #3

Typical Bugs in parallel Programs

Debugging on Blue Waters

CS 270 Systems Programming. Debugging Tools. CS 270: Systems Programming. Instructor: Raphael Finkel

CSE 160 Discussion Section. Winter 2017 Week 3

Debugging HPC Applications. David Lecomber CTO, Allinea Software

Hands-on Workshop on How To Debug Codes at the Institute

Reviewing gcc, make, gdb, and Linux Editors 1

Debugging, benchmarking, tuning i.e. software development tools. Martin Čuma Center for High Performance Computing University of Utah

Prerequisites for Eclipse

Program Design: Using the Debugger

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

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

ECE/ME/EMA/CS 759 High Performance Computing for Engineering Applications

Introduction to the SHARCNET Environment May-25 Pre-(summer)school webinar Speaker: Alex Razoumov University of Ontario Institute of Technology

Debugging Techniques. CEFET Engineering Week

Debugging. Erwan Demairy Dream

Supplement: Visual C++ Debugging

CS/COE 0449 term 2174 Lab 5: gdb

Debugging CUDA Applications with Allinea DDT. Ian Lumb Sr. Systems Engineer, Allinea Software Inc.

HOW TO USE CODE::BLOCKS IDE FOR COMPUTER PROGRAMMING LABORATORY SESSIONS

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:

Distributed Memory Programming With MPI Computer Lab Exercises

Princeton University COS 217: Introduction to Programming Systems GDB Tutorial and Reference

Lecture 07 Debugging Programs with GDB

Developing, Debugging, and Optimizing GPU Codes for High Performance Computing with Allinea Forge

Our new HPC-Cluster An overview

Blue Gene/Q User Workshop. Debugging

Lab6 GDB debugging. Conventions. Department of Computer Science and Information Engineering National Taiwan University

Today s presentation. Git gdb Project 1

Debugging with Totalview. Martin Čuma Center for High Performance Computing University of Utah

Development in code_aster Debugging a code_aster execution

Scientific Programming in C IX. Debugging

CptS 360 (System Programming) Unit 4: Debugging

Debugging Intel Xeon Phi KNC Tutorial

DEBUGGING ON FERMI PREPARING A DEBUGGABLE APPLICATION GDB. GDB on front-end nodes

Debugging with TotalView

ECE 3210 Laboratory 1: Develop an Assembly Program

1. Allowed you to see the value of one or more variables, or 2. Indicated where you were in the execution of a program

GPU Technology Conference Three Ways to Debug Parallel CUDA Applications: Interactive, Batch, and Corefile

April 4-7, 2016 Silicon Valley. CUDA DEBUGGING TOOLS IN CUDA8 Vyas Venkataraman, Kudbudeen Jalaludeen, April 6, 2016

7 The Integrated Debugger

IBM VisualAge for Java,Version3.5. Distributed Debugger for Workstations

Intro to Segmentation Fault Handling in Linux. By Khanh Ngo-Duy

CMPT 300. Operating Systems. Brief Intro to UNIX and C

Implementation of Parallelization

Short Introduction to tools on the Cray XC system. Making it easier to port and optimise apps on the Cray XC30

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

We first learn one useful option of gcc. Copy the following C source file to your

Tools and Methodology for Ensuring HPC Programs Correctness and Performance. Beau Paisley

ncsa eclipse internal training

Transcription:

Debugging with GDB and DDT Ramses van Zon SciNet HPC Consortium University of Toronto June 13, 2014 1/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Outline Debugging Basics Debugging with the command line: GDB Debugging with DDT 2/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Debugging basics 3/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Debugging basics Help, my program doesn t work! a miracle occurs My program works brilliantly! $ gcc -O3 answer.c $./a.out Segmentation fault $ gcc -O3 answer.c $./a.out 42 Unfortunately, miracles are not yet supported by SciNet. Debugging: Methodical process of finding and fixing flaws in software 4/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Common symptoms Errors at compile time Syntax errors: easy to fix Library issues Cross-compiling Compiler warnings Always switch this on, and fix or understand them! But just because it compiles does not mean it is correct! Runtime errors Floating point exceptions Segmentation fault Aborted Incorrect output (nans) 5/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Common issues Arithmetic Memory access Logic Misuse Syntax Resource starvation Parallel corner cases (sqrt(-0.0)), infinities Index out of range, uninitialized pointers. Infinite loop, corner cases wrong input, ignored error, no initialization wrong operators/arguments memory leak, quota overflow race conditions, deadlock 6/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

What is going on? Almost always, a condition you are sure is satisfied, is not. But your programs likely relies on many such assumptions. First order of business is finding out what goes wrong, and what assumption is not warranted. Debugger: program to help detect errors in other programs. You are the real debugger. 7/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Ways to debug Preemptive: Turn on compiler warnings: fix or understand them! $ gcc/gfortran -Wall Check your assumptions (e.g. use assert). Inspect the exit code and read the error messages! Use a debugger Add print statements No way to debug! 8/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

What s wrong with using print statements? Strategy Constant cycle: 1. strategically add print statements 2. compile 3. run 4. analyze output bug not found? Removing the extra code after the bug is fixed Repeat for each bug Problems with this approach Time consuming Error prone Changes memory, timing... There s a better way! 9/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Symbolic debuggers 10/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Symbolic debuggers Features 1. Crash inspection 2. Function call stack 3. Step through code 4. Automated interruption 5. Variable checking and setting Use a graphical debugger or not? Local work station: graphical is convenient Remotely (SciNet): can be slow In any case, graphical and text-based debuggers use the same concepts. 11/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Symbolic debuggers Preparing the executable Add required compilination flags: $ gcc/g++/gfortran -g [-gstabs] $ icc/icpc/ifort -g [-debug parallel] $ nvcc -g -G Optional: switch off optimization -O0 Command-line based symbolic debuggers: gdb 12/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

GDB 13/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

What is GDB? Free, GNU license, symbolic debugger. Available on many systems. Been around for a while, but still developed and up-to-date Text based, but has a -tui option. $ module load gcc/4.8.1 $ gcc -g -O0 example.c -o example $ module load gdb/7.6 $ gdb -tui example... (gdb) 14/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

GDB basic building blocks 15/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

GDB building block #1: Inspect crashes Inspecting core files Core = file containing state of program after a crash needs max core size set (ulimit -c <number>) gdb reads with gdb <executable> <corefile> it will show you where the program crashed No core file? can start gdb as gdb <executable> type run to start program gdb will show you where the program crashed if it does. 16/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

GDB building block #2: Function call stack Interrupting program Press Crtl-C while program is running in gdb gdb will show you where the program was. Stack trace From what functions was this line reached? What were the arguments of those function calls? gdb commands backtrace continue down up function call stack continue go to called function go to caller 17/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

GDB building block #3: Step through code Stepping through code Line-by-line Choose to step into or over functions Can show surrounding lines or use -tui gdb commands list next step finish until list part of code continue until next line step into function continue until function end continue until line/function 18/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

GDB building block #4: Automatic interruption Breakpoints break [file:]<line> <function> each breakpoint gets a number when run, automatically stops there can add conditions, temporarily remote breaks, etc. Related gdb commands delete condition disable enable info breakpoints tbreak unset breakpoint break if condition met disable breakpoint enable breakpoint list breakpoints temporary breakpoint 19/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

GDB building block #5: Variables Checking a variable Can print the value of a variable Can keep track of variable (print at prompt) Can stop the program when variable changes Can change a variable ( what if... ) gdb commands print display set variable watch print variable print at every prompt change variable stop if variable changes 20/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Demonstration GDB $ ssh USER@login.scinet.utoronto.ca -X $ ssh gpc01 -X $ qsub -l nodes=1:ppn=8,walltime=4:00:00 -I -X $ cd $SCRATCH $ cp -r /scinet/course/ss2014. $ cd ss2014/hpc245 debug/code $ source setup $ cd ex1 $ make dbgtest #(or dbgtestf) $ ulimit -c 1024 $./dbgtest #(or dbgtestf) Hello Hi You ll find that the latter does not work. Start up $ gdb -tui dbgtest #(or dbgtestf) 21/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Graphical symbolic debuggers 22/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Graphical symbolic debuggers Features Nice, more intuitive graphical user interface Front to command-line based tools: Same concepts Need graphics support: X forwarding (or VNC) Available on SciNet: ddd and ddt ddd $ module load gcc ddd $ ddd <executable compiled with -g flag> ddt $ module load ddt $ ddt <executable compiled with -g flag> (more later) 23/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Graphical symbolic debuggers - ddd 24/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Graphical symbolic debuggers - ddt 25/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Parallel debugging 26/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Parallel debugging - 1 Shared memory Use gdb for Tracking each thread s execution and variables OpenMP serialization: p omp set num threads(1) Stepping into OpenMP block: break at first line! Thread-specific breakpoint: b <line> thread <n> Use helgrind for Finding race conditions: $ module load valgrind $ valgrind --tool=helgrind <exe> &> out $ grep <source> out where <source> is the name of the source file where you suspect race conditions (valgrind reports a lot more) 27/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Parallel debugging - 2 Distributed memory Multiple MPI processes Your code is running on different cores! Where to run debugger? Where to send debugger output? Much going on at same time. No universal free solution. Good approach: 1. Write your code so it can run in serial: perfect that first. 2. Deal with communication, synchronization and deadlock on smaller number of MPI processes/threads. 3. Only then try full size. Parallel debugging demands specialized tools: ddt 28/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

DDT 29/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

DDT Distributed Debugging Tool Powerful GUI-based commercial debugger by Allinea. Supports C, C++ and Fortran Supports MPI, OpenMP, threads, CUDA and more Available on all SciNet clusters (GPC, TCS, ARC, P7) Available on SHARCNET s kraken, requin, orca and monk. 30/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Launching ddt Load your compiler and MPI modules. Load the ddt module: $ module load ddt Start ddt with one of these: $ ddt $ ddt <executable compiled with -g flag> $ ddt <executable compiled with -g flag> <arguments> First time: create config file: OpenMPI (skip other steps) Then gui for setting up debug session. 31/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Run and Debug a Program (session setup) 32/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

User interface (1) 33/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

User interface (2) DDT uses a tabbed-document interface. 34/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

User interface (3) When the session begins, DDT automatically finds source code from information compiled in the executable. 35/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

User interface (4) Process Control and Process Groups: Can group process together. Predefined groups All, Root, Workers. (Session options, automatically create) Can create, delete modify groups (drag drop, right click stacks,... ) 36/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

User interface (5) Different colour coding for each group s current source line. 37/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

User interface (6) Session Control Dialog: Control program execution, e.g., play/continue, pause, step into, step over, step out 38/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

User interface (7) Breakpoints Tab Can suspend, jump to, delete, load, save 39/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

User interface (8) Focus: Choose between Group, process or thread 40/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

User interface (9) Stacks: Current and Parallel Tree of functions (merged) Click on branch to see source Hover to see process ranks Use to gather processes in new groups 41/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

User interface (10) Current line variables 42/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

User interface (11) Local variables for process 43/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

User interface (12) Evaluate window 44/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Demonstration DDT $ cd $SCRATCH/ss2014/HPC245 debug/code $ source setup $ cd ex2 $ make $ ddt ex2 45/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Other features of DDT (1) Some of the user-modified parameters and windows are saved by right-clicking and selecting a save option in the corresponding window (Groups; Evaluations) DDT can load and save sessions. Find and Find in Files in the Search menu. Goto line in Search menu (or Ctrl-G) Synchronize processes in group: Right-click, Run to here. View multiple source codes simultaneously: Right-click, Split Right-click power! 46/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Other features of DDT (2) Signal handling: SEGV, FPE, PIPE,ILL Support for Fortran modules Change data values in evaluate window Examine pointers (vector, reference, dereference) Multi-dimensional arrays Viewer 47/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Other features of DDT (3) Message Queue View show message queue produces both a graphical view and table for active communications Helps to find e.g. deadlocks 48/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Demonstration DDT $ cd $SCRATCH/ss2014/HPC245 debug/code $ source setup $ cd ex3 $ make $ ddt ex3 49/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Other features of DDT (4) Memory debugging Select memory debug in Run window Stops on error (before crash or corruption) Check pointer (right click in evaluate) View, overall memory stats 50/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Demonstration DDT $ cd $SCRATCH/ss2014/HPC245 debug/code $ source setup $ cd ex4 $ make $ ddt ex4 51/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Other features of DDT (5) Thread debugging $ cd $SCRATCH/ss2014/HPC245 debug/code $ source setup $ cd ex5 $ make $ ddt ex5 52/41 Ontario HPC Summerschool 2014 Central Edition: Toronto

Useful references G Wilson Software Carpentry software-carpentry.org/3 0/debugging.html N Matloff and PJ Salzman The Art of Debugging with GDB, DDD and Eclipse GDB: DDT: SciNet Wiki: sources.redhat.com/gdb www.allinea.com/products/ddt-support wiki.scinethpc.ca: Tutorials & Manuals 53/41 Ontario HPC Summerschool 2014 Central Edition: Toronto