Debugging. John Lockman Texas Advanced Computing Center

Similar documents
Profiling and debugging. Carlos Rosales September 18 th 2009 Texas Advanced Computing Center The University of Texas at Austin

Profiling and debugging. John Cazes Texas Advanced Computing Center

Profiling and debugging. Yaakoub El Khamra Texas Advanced Computing Center

Debugging with TotalView

CSE 351. GDB Introduction

Data and File Structures Laboratory

Debugging with GDB and DDT

Debugging with GDB and DDT

DDT Debugging Techniques

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

Guillimin HPC Users Meeting July 14, 2016

Debugging. P.Dagna, M.Cremonesi. May 2015

DDT: A visual, parallel debugger on Ra

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

EE 355 Lab 3 - Algorithms & Control Structures

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

Debug for GDB Users. Action Description Debug GDB $debug <program> <args> >create <program> <args>

CSE 374 Programming Concepts & Tools

Using gdb to find the point of failure

Parallel Debugging with TotalView BSC-CNS

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

Debugging process. The debugging process can be divided into four main steps: 1. Start your program, specifying anything that might affect its

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

Exercise Session 6 Computer Architecture and Systems Programming

CSE 410: Systems Programming

Lecture 07 Debugging Programs with GDB

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

Program Design: Using the Debugger

Scientific Programming in C IX. Debugging

Programming Studio #9 ECE 190

Problem Set 1: Unix Commands 1

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.

Source level debugging. October 18, 2016

Debugging and Debugger. Terminology. GNU gcc and gdb. Debugging C programs in Unix and Windows Environments - Part One

CS2141 Software Development using C/C++ Debugging

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

GDB cheatsheet - page 1

CS/COE 0449 term 2174 Lab 5: gdb

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

gdbtui - Linux Command

HPCC - Hrothgar. Getting Started User Guide TotalView. High Performance Computing Center Texas Tech University

Debugging and Profiling

1 A Brief Introduction To GDB

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

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

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

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

CS354 gdb Tutorial Written by Chris Feilbach

The Dynamic Debugger gdb

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

Using the Debugger. Michael Jantz Dr. Prasad Kulkarni

The Eclipse Parallel Tools Platform

Performance Metrics (I)

CNIT 127: Exploit Development. Ch 2: Stack Overflows in Linux

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

Development Environment & Linux Guide

TotalView. Debugging Tool Presentation. Josip Jakić

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

Debugging at Scale Lindon Locks

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

Reviewing gcc, make, gdb, and Linux Editors 1

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

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

Laboratory 1 Semester 1 11/12

Section 1: Tools. Contents CS162. January 19, Make More details about Make Git Commands to know... 3

18-600: Recitation #3

Software Development With Emacs: The Edit-Compile-Debug Cycle

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

Debugging Techniques. CEFET Engineering Week

GDB 1 GDB 2 GDB. Fortran Pascal GDB 4. hoge.c. Fig. 1. calc.c. Fig GDB. GDB Debian. # apt-get install gdb

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:

Jackson State University Department of Computer Science CSC / Advanced Information Security Spring 2013 Lab Project # 5

SU 2017 May 18/23 LAB 3 Bitwise operations, Program structures, Functions (pass-by-value), local vs. global variables. Debuggers

Debugging for the hybrid-multicore age (A HPC Perspective) David Lecomber CTO, Allinea Software

Debugging HPC Applications. David Lecomber CTO, Allinea Software

Chapter - 17 Debugging and Optimization. Practical C++ Programming Copyright 2003 O'Reilly and Associates Page 1

COSC 4397 Parallel Computation. Debugging and Performance Analysis of Parallel MPI Applications

SGI Altix Getting Correct Code Reiner Vogelsang SGI GmbH

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

Laboratory Assignment #4 Debugging in Eclipse CDT 1

Supplement: Visual C++ Debugging

IBM i Debugger. Overview Service Entry Points Debugger Functions Attach to an IBM i Job Launch Configurations and Settings

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

Project #1: Tracing, System Calls, and Processes

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

Programming in C S c o t t S c h r e m m e r

CMPSC 311- Introduction to Systems Programming Module: Debugging

Review of Scientific Programming in C and Fortran. Michael McLennan Software Architect HUBzero Platform for Scientific Collaboration

MPI Runtime Error Detection with MUST

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

Software Engineering Testing and Debugging Debugging

Software Engineering

GDB Linux GNU Linux Distribution. gdb gcc g++ -g gdb EB_01.cpp

Today s Topic. Software Engineering Testing and Debugging Debugging. Today s Topic. The Main Steps in Systematic Debugging

CMPSC 311- Introduction to Systems Programming Module: Debugging

Debugging Your CUDA Applications With CUDA-GDB

The First Real Bug. gdb. Computer Organization I McQuain

XSEDE New User Tutorial

Computer Science II Lab 3 Testing and Debugging

Basic functions of a debugger

Transcription:

Debugging John Lockman Texas Advanced Computing Center

Debugging Outline GDB Basic use Attaching to a running job DDT Identify MPI problems using Message Queues Catch memory errors PTP For the extremely patient*

Debugging gdb and ddt

Why use a debugger? You ve got code -> you ve got bugs Buffered output (printf / write may not help) Fast & Accurate Many errors are difficult to find without one!

About GDB GDB is the GNU Project DeBugger www.gnu.org/software/gdb/ Looks inside a running program (SERIAL) From the GDB website: GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act: Start your program, specifying anything that might affect its behavior. Make your program stop on specified conditions. Examine what has happened, when your program has stopped. Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.

Using GDB Compile with debug flags: gcc g O0./srcFile.c The -g flag generates the symbol table and provides the debugger with line-by-line information about the source code. Execute debugger loading source dir: gdb d srcdir./exefile The -d option is useful when source and executable reside in different directories. Use the -q option to skip the licensing message. Type help at any time to see a list of the debugger options and commands.

Two levels of control Basic: Run the code and wait for it to crash. Identify line where it crashes. With luck the problem is obvious. Advanced: Set breakpoints Analyze data at breakpoints Watch specific variables

GDB basic commands command shorthand argument description run/kill r / k NA start/end program being debugged continue c NA continue running program from last breakpoint step s NA take a single step in the program from the last position where NA NA equivalent to backtrace print p variablename show value of a variable list l srcfile.c:linenumber show the specified source code line break b srcfile.c:linenumber functionname set a breakpoint by line number or function name watch NA variablename stops when the variable changes value

GDB example divcrash.c #include <stdio.h> #include <stdlib.h> int mydiv(int, int); int main(void) { int res, x = 5, y; for(y = 1; y < 10; y++){ res = mydiv(x,y); printf("%d,%d,%d\n",x,y,res); } return 0; } int mydiv(int x, int y){ return 1/( x - y); } divcrash.f90 PROGRAM main INTEGER :: mydiv INTEGER :: res, x = 5, y DO y = 1, 10 res = mydiv(x,y) WRITE(*,*) x,y,res END DO END PROGRAM FUNCTION mydiv(x,y) INTEGER, INTENT(IN) :: x, y mydiv = 1/(x-y) RETURN END FUNCTION mydiv

GDB example Compile the program and start the debugger: % gcc g O0./divcrash.c % gdb./a.out Start the program: (gdb) run The debugger will stop program execution with the following message: Program received signal SIGFPE, Arithmetic exception. 0x000000000040051e in mydiv (x=5, y=5) at divcrash.c:28 28 return 1/( x - y); We can use gdb commands to obtain more information about the problem: (gdb) where #0 0x000000000040051e in mydiv (x=5, y=5) at divcrash.c:28 #1 0x00000000004004cf in main () at divcrash.c:19

GDB example In this case the problem is clear: a divide-by-zero exception happens in line 28 when variables x and y are the same. This is related to the call to mydiv from line 19 that is within a for loop: 18: for(y = 1; y < 10; y++){ 19: res = mydiv(x,y); Eventually the loop sets the value of y equal to 5 (the value of x) producing the exception: 28: return 1/( x - y); With the problem identified we can kill the program and exit the debugger : (gdb) kill (gdb) quit

Examining data C Fortran Result (gdb) p x (gdb) p x Print scalar data x value (gdb) p V (gdb) p V Print all vector V components (gdb) p V[i] (gdb) p V(i) Print element i of vector V (gdb) p V[i]@n (gdb) p V(i)@n Print n consecutive elements starting with V i (gdb) p M (gdb) p M Print all matrix M elements (gdb) p M[i] Not Available Print row i of matrix M (gdb) p M[i]@n Not Available Print n consecutive rows starting with row i (gdb) p M[i][j] (gdb) p M(i,j) Print matrix element Mij (gdb) p M[i][j]@n (gdb) p M(i,j)@n Print n consecutive elements starting with Mij No simple way to print columns in C or rows in Fortran Some debuggers print array slices (pgdbg, dbx), i.e. p M(1:3,3:7)

Breakpoint control Stop the execution of the program Allow you to examine the execution state in detail Can be assigned to a line or function Can be set conditionally command argument description info breakpoints/b/br Prints to screen all breakpoints breakpoint srcfile:linenumber if a < b Conditional insertion of breakpoint enable/disable breakpointnumber Enable/disable a breakpoint delete breakpointnumber Delete a breakpoint clear srcfile:linenumber functionname Clear breakpoints at a given line or function

Attaching GDB to a running program Use top to find out the PID of the tasks run by your program (in the top listing PIDs appear on the left, job names on the right). % top Attach gdb to the relevant PID: % gdb p <PID> or: % gdb (gdb) attach <PID> Once attached the debugger pauses execution of the program. Same level of control than in a standard debugging session.

Attaching GDB to a running program Best way to debug production runs. Don t wait for your wall time to run out! From the output of qstat obtain the node name where your code is running. In the queue field you will find an entry like development@i182-103.ta queue name partial node name: i182-103.tacc.utexas.edu

GDB Summary Compile using debug flags: % icc -g -O0./srcFile.c Run indicating the directory where the source is: % gdb -d srcdir./exefile Main commands: run/kill continue/next/step break/watch print where help

DDT: Parallel Debugger with GUI Allinea Distributed Debugger Tool www.allinea.com Multiplatform Supports all MPI distributions Capable of debugging large scale OMP/MPI Comprehensive Memory checking MPI message tracking Useful Graphical User Interface

General Options Queue Submission Parameters Processor and thread number Advanced Options DDT - Run

General Options Queue Submission Parameters Processor and thread number Advanced Options DDT 3.2 DDT - Run

DDT Queue Parameters Each of these parameters may be changed Project must be set!!

DDT: The debug session Process controls Process groups window Project navigation window Code window Variable window Stack view and output window Evaluation window

DDT: Memory Leaks Go to View -> Current Memory Usage Process 0 is using much more memory than the others. This looks like a memory leak.

DDT Summary ssh to Lonestar or Stampede allowing X11 forwarding: % ssh -X username@<lonestar / stampede>.tacc.utexas.edu Compile with debugging flags: % mpicc -g -O0./srcFile.c Load the ddt module % module load ddt Run ddt % ddt./exefile Configure ddt properly before submission: Options MPI version Queue Parameters Wallclock/CPUs/Project Advanced Memory Checking

Notes on Eclipse PTP Eclipse PTP is FREE Eclipse PTP is part of XSEDE: your tickets about Eclipse PTP will be answered by the Eclipse PTP developers (they are good about tickets) Eclipse PTP is a great tool to debug code locally (i.e. on your own workstation/laptop) before moving to production on XSEDE systems Eclipse PTP supports remote development, with existing configurations for all XSEDE machines including TACC systems Power IDE with refactoring, code completion, static analysis, collaborative code development

Debugging: Conclusions You ALWAYS want to debug your code if: o Program exhibits erratic, random behavior when you are not using random o o o variables in control statements (hint: memory corruption/stomping) Program appears to "hang" somewhere: attach a debugger and see "where" it is stuck. Profiling will NOT help with "stuck" program flow Program exits way too fast (and you do not have exit error messages built into your code, which you want to consider) Wrong/bad results: unless you are working with infinite or semi-infinite Cantor sets, or attempting to use GiNaC, you should not be getting NaN's or Inf's in your variables: add conditional watch expressions to halt execution when you encounter these values (or use isnan, isinf functions in C) This is not to say that you cannot debug your code with print statements. Whatever gets your code operating at designed parameters: performance, readability, maintainability, rapid development, informative crashes/bug-free/idiot-proof etc... that is what you want to be doing. Debuggers get you there quicker