MIT OpenCourseWare Multicore Programming Primer, January (IAP) Please use the following citation format:

Similar documents
MIT OpenCourseWare Multicore Programming Primer, January (IAP) Please use the following citation format:

MIT OpenCourseWare Multicore Programming Primer, January (IAP) Please use the following citation format:

6.189 IAP Recitations 2-3. Cell Programming Hands-on. David Zhang, MIT IAP 2007 MIT

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

Using gdb to find the point of failure

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

GDB QUICK REFERENCE GDB Version 4

Source level debugging. October 18, 2016

Problem Set 1: Unix Commands 1

SGI Altix Getting Correct Code Reiner Vogelsang SGI GmbH

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

Using the Debugger. Michael Jantz Dr. Prasad Kulkarni

Exercise Session 6 Computer Architecture and Systems Programming

GDB Tutorial. Young W. Lim Tue. Young W. Lim GDB Tutorial Tue 1 / 32

GDB cheatsheet - page 1

Concurrent Programming with the Cell Processor. Dietmar Kühl Bloomberg L.P.

MIT OpenCourseWare Multicore Programming Primer, January (IAP) Please use the following citation format:

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

Program Design: Using the Debugger

CMPSC 311- Introduction to Systems Programming Module: Debugging

Basic functions of a debugger

CMPSC 311- Introduction to Systems Programming Module: Debugging

Laboratory 1 Semester 1 11/12

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

CS/COE 0449 term 2174 Lab 5: gdb

GDB Tutorial. Young W. Lim Thr. Young W. Lim GDB Tutorial Thr 1 / 24

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

CSE 410: Systems Programming

Princeton University COS 217: Introduction to Programming Systems GDB Tutorial and Reference for x86-64 Assembly Language

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

GDB Tutorial. Young W. Lim Fri. Young W. Lim GDB Tutorial Fri 1 / 24

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger.

1 Basic functions of a debugger

Reviewing gcc, make, gdb, and Linux Editors 1

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

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

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

CSE 351. GDB Introduction

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

CSE 374 Programming Concepts & Tools

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

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

Data and File Structures Laboratory

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

Programming Studio #9 ECE 190

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

This chapter introduces how to use the emulator of TOPICE quickly.

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

Debugging with GDB and DDT

1 A Brief Introduction To GDB

dbx90: Fortran debugger March 9, 2009

ALD Assembly Language Debugger Copyright (C) Patrick Alken

CS3210: Tutorial Session 2. Kyuhong Park-- edited by Kyle Harrigan

Supplement: Visual C++ Debugging

Computer Science II Lab 3 Testing and Debugging

CS168: Debugging. Introduc)on to GDB, Wireshark and Valgrind. CS168 - Debugging Helpsession

The NetBeans Debugger: A Brief Tutorial

TotalView. Debugging Tool Presentation. Josip Jakić

18-600: Recitation #3

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

EE 355 Lab 3 - Algorithms & Control Structures

Debugging with GDB and DDT

DEBUGGING: DYNAMIC PROGRAM ANALYSIS

MIT OpenCourseWare Multicore Programming Primer, January (IAP) Please use the following citation format:

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

int32_t Buffer[BUFFSZ] = {-1, -1, -1, 1, -1, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, -1, -1, -1, -1, -1}; int32_t* A = &Buffer[5];

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

Systems/DBG Debugger Version 2.20

NetBeans Tutorial. For Introduction to Java Programming By Y. Daniel Liang. This tutorial applies to NetBeans 6, 7, or a higher version.

Disassemble the machine code present in any memory region. Single step through each assembly language instruction in the Nios II application.

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

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

Debugging uclinux on Coldfire

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

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

PathFinder-XD for MIPS Powered Devices. Simulator

Understanding the Program Run

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

UNIX Makefile. C Project Library Distribution and Installation.

Debugging Your CUDA Applications With CUDA-GDB

Lab 3-2: Exploring the Heap

CS201 Lecture 2 GDB, The C Library

Section 1: Tools. Kaifei Chen, Luca Zuccarini. January 23, Make Motivation How... 2

Lab 7 Linux Debugging. EECS 448: Software Engineering I Mark Calnon October 17, 2011

Code Review and Debugging (Lab 05)

Today s presentation. Git gdb Project 1

Using the KD30 Debugger

CSE 361S Intro to Systems Software Lab Assignment #4

Data Communication and Synchronization

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

Debugging Runtime Scripts in Operations Manager and Essentials 2007 The third installment in the System Center Forum Scripting Series

C Program Development and Debugging under Unix SEEM 3460

CS2: Debugging in Java

PS3 Programming. Week 4. Events, Signals, Mailbox Chap 7 and Chap 13

Introduction. Key features and lab exercises to familiarize new users to the Visual environment

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

Trace Getting Started V8.02

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

Laboratory Assignment #4 Debugging in Eclipse CDT 1

RVDS 3.0 Introductory Tutorial

Transcription:

MIT OpenCourseWare http://ocw.mit.edu 6.189 Multicore Programming Primer, January (IAP) 2007 Please use the following citation format: Phil Sung, 6.189 Multicore Programming Primer, January (IAP) 2007. (Massachusetts Institute of Technology: MIT OpenCourseWare). http://ocw.mit.edu (accessed MM DD, YYYY). License: Creative Commons Attribution-Noncommercial-Share Alike. Note: Please use the actual date you accessed this material in your citation. For more information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms

6.189 IAP 2007 Recitation 4 Cell Debugging Tools Phil Sung, MIT. 1 6.189 IAP 2007 MIT

Preparing for Debugging Two methods Get program state on crash Attach and step through program Compile for debugging Use gcc g or xlc g to generate debugging info or, in our Makefile: CC_OPT_LEVEL = $(CC_OPT_LEVEL_DEBUG) Phil Sung, MIT. 2 6.189 IAP 2007 MIT

Running Processes Under GDB ppu-gdb./hello-world (gdb) run [args] (gdb) quit export SPU_INFO=1 for extra information about threads Phil Sung, MIT. 3 6.189 IAP 2007 MIT

Attaching to Running Programs ppu-gdb./hello -p 1234 (gdb) continue (gdb) detach Finding the PID./hello & [1] 1234 ps -e grep hello 1234 pts/2 00:00:01 hello top Phil Sung, MIT. 4 6.189 IAP 2007 MIT

Examining Program State Stack trace (gdb) bt #0 0x0f6a7fc8 in mmap () from /lib/libc.so.6 #1 0x0f2a62e0 in pthread_create@@glibc_2.1 () fro #2 0x0ff98168 in spe_create_thread () from /usr/l #3 0x01801bec in calc_dist () at dist.c:36 #4 0x01801cdc in main () at dist.c:55 Phil Sung, MIT. 5 6.189 IAP 2007 MIT

Examining Program State Examine variables id = {0x181e038, 0x1} (gdb) info locals i = 1.2 Evaluate expressions (gdb) print VARNAME (gdb) print 'FILENAME'::VARNAME (gdb) print 'FUNCTION'::VARNAME (gdb) print EXPR Example: (gdb) print x + 100 * y gdb knows data types and prints values appropriately To show type: (gdb) whatis VARNAME Phil Sung, MIT. 6 6.189 IAP 2007 MIT

Examining Code View code at a specific location (gdb) list LINENUM (gdb) list FUNCTION (gdb) list FILENAME:FUNCTION Display code above/below previous snippet (gdb) list (gdb) list - 21 calc_dist() 22 { 23 speid_t id[2]; 24 25 // Set up different co Phil Sung, MIT. 7 6.189 IAP 2007 MIT

Controlling Program Execution Run to first line of main procedure (gdb) start Next line in current procedure (gdb) next gen_points () at dist.c:67 Descend into function calls (gdb) step Run until function exit, return to caller (gdb) finish Resume execution until next breakpoint (gdb) continue Cease debugging Allow program to continue after gdb exits: (gdb) detach Exit gdb: (gdb) quit 67 srand(time(null)); Phil Sung, MIT. 8 6.189 IAP 2007 MIT

Breakpoints Halt program when a certain point is reached in execution Setting breakpoints (gdb) break FUNCTION (gdb) break LINENUM (gdb) break FILENAME:FUNCTION (gdb) break FILENAME:LINENUM Conditional breakpoints: (gdb) break if EXPR Example expression: (x == 1 && y == 2) Viewing or removing breakpoints (gdb) info breakpoints (gdb) remove 2 Breakpoint 2 at 0x1801740: file dist.c, line 70. Phil Sung, MIT. 9 6.189 IAP 2007 MIT

Watchpoints Halt program when a value changes (gdb) watch VAR watch myvar watch myarray[6] Phil Sung, MIT. 10 6.189 IAP 2007 MIT

Examining Memory (gdb) x/ni ADDR N = how many units (machine words) to show Default N = 1 Flag before address controls how to interpret data i: machine instructions x: hex d: decimal a: address (calculates offset from nearest symbol) f: floating point numbers s: string Phil Sung, MIT. 11 6.189 IAP 2007 MIT

Examining Memory: Example const char* a = "cell-processor\n"; Display as string Note that count ("1") is by strings, not words (gdb) x/1s a 0x10000bc0 < dso_handle+4>: "cell-processor\n" Display as hex (gdb) x/4x a 0x10000bc0 < dso_handle+4>: 0x63656c6c 0x2d70726f 0x63657373 0x6f720a00 " c e l l - p r o c e s s o r\n\0" Phil Sung, MIT. 12 6.189 IAP 2007 MIT

Selecting Frames View state higher up in the call stack Frame numbers are given by bt (gdb) frame 0 (gdb) frame 1 (gdb) frame 2 (gdb) up (gdb) down Phil Sung, MIT. 13 6.189 IAP 2007 MIT

Debugging From emacs M-x gdb invokes gdb Replace 'gdb' with 'ppu-gdb' when prompted Specify executable path relative to current buffer's directory Enter gdb commands in *gud- * buffer Active line in current frame is highlighted in editor Keyboard shortcuts available in source code files Set breakpoint: C-x SPC Print value of selected expression: C-x C-a C-p Step: C-x C-a C-s Next: C-x C-a C-n Down frame: C-x C-a > Up frame: C-x C-a < Phil Sung, MIT. 14 6.189 IAP 2007 MIT

Exercise 1 (5 minutes) Find the value of control block (cb) in SPU thread Get the recitation tarball See example code in recitations section. tar zxf rec4.tar.gz Build the program cd rec4/dma-alignment/ make Run to the error with ppu-gdb Debug Phil Sung, MIT. 15 6.189 IAP 2007 MIT

Debugging Threaded Programs When a new thread is entered, gdb prints [New Thread 123 (LWP 6041)] List threads (gdb) info threads gdb maintains 'current thread', used for bt, etc. Switch threads: (gdb) thread 2 On breakpoint or signal, gdb makes the triggered thread current 3 Thread 4151747792 (LWP 6042) 0x0f6ac0c8 in clone () * 2 Thread 4160398544 (LWP 6041) 0x000002f8 in main (speid=25288760, argp=25269760, envp=0) at dist_spu.c:16 1 Thread 4160663552 (LWP 6038) 0x0f6ac0c8 in clone () Phil Sung, MIT. 16 6.189 IAP 2007 MIT

Exercise 2 (10 minutes) Verify that cb in the first SPU thread is the same as cb[0] in the PPU program You will need to qualify names Build the program typedef struct { cd rec4/lab1/ uintptr32_t a_addr; uintptr32_t b_addr; make uintptr32_t c_addr; uint32_t padding; Set breakpoints, run and debug } CONTROL_BLOCK; Also examine the PPU thread state in Exercise 1 when the bus error occurs Phil Sung, MIT. 17 6.189 IAP 2007 MIT

Exercise 2 (gdb) break dist_spu.c:19 (gdb) run (gdb) print cb $1 = {a_addr = 25286272, b_addr = 25269248, res_addr = 25269888, padding = 0} (gdb) thread 1 (gdb) print 'dist.c'::cb $2 = {{a_addr = 25286272, b_addr = 25269248, res_addr = 25269888, padding = 0}, {a_addr = 25286528, b_addr = 25269248, res_addr = 25278080, padding = 0}} Phil Sung, MIT. 18 6.189 IAP 2007 MIT

Exercise 2 Types are consistent with source code (gdb) whatis cb type = CONTROL_BLOCK (gdb) whatis 'dist.c'::cb type = CONTROL_BLOCK [2] Phil Sung, MIT. 19 6.189 IAP 2007 MIT

Debugging Threaded Programs gdb can get confused by SPU threads gdb removes breakpoint after first thread exits gdb may complain about source files for SPU program "No source file named dist_spu.c. Make breakpoint pending on future shared library load? (y or [n])" Choose "y" and continue, source should be visible later Phil Sung, MIT. 20 6.189 IAP 2007 MIT

Debugging SPU Threads Alone Use spu-gdb to debug individual SPU threads SPU_DEBUG_START=1./hello & Prints PIDs of threads; threads wait for debugger to attach "Starting SPE thread 0x181e038, to attach debugger use: spu-gdb -p 1234" spu-gdb./spu-hello -p 1234 Attach gdb to SPU thread Phil Sung, MIT. 21 6.189 IAP 2007 MIT

Troubleshooting Common gdb Issues Problem: gdb examines wrong variable when names are ambiguous Use spu-gdb or rename variables Problem: breakpoints are deleted prematurely Use spu-gdb or keep threads alive for as long as possible Error: "Thread Event Breakpoint: gdb should not stop!" Use spu-gdb Phil Sung, MIT. 22 6.189 IAP 2007 MIT

Errors that Debugger Can Help With "Bus error" DMA transfer problem Memory misalignment "Segmentation fault" Invalid address Deadlock Attach and examine state Phil Sung, MIT. 23 6.189 IAP 2007 MIT