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

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

Using the Debugger. Michael Jantz Dr. Prasad Kulkarni

Debugging Techniques. CEFET Engineering Week

You can also start with both an executable program and a core file specified:

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

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

Laboratory Assignment #4 Debugging in Eclipse CDT 1

Laboratory 1 Semester 1 11/12

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

CSE 351. GDB Introduction

Using gdb to find the point of failure

Exercise Session 6 Computer Architecture and Systems Programming

Programming Logic - Beginning

CSE 374 Programming Concepts & Tools

The NetBeans Debugger: A Brief Tutorial

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

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.

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

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

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

Intro to MS Visual C++ Debugging

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

Development Environment of Embedded System

Code::Blocks Student Manual

CS354 gdb Tutorial Written by Chris Feilbach

Programming Tips for CS758/858

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

Libgdb. Version 0.3 Oct Thomas Lord

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

Basic functions of a debugger

The CS-220 Development Environment

Visual Studio.NET. Although it is possible to program.net using only the command OVERVIEW OF VISUAL STUDIO.NET

Code::Blocks Student Manual

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

Problem Set 1: Unix Commands 1

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

Supplement: Visual C++ Debugging

Source level debugging. October 18, 2016

SGI Altix Getting Correct Code Reiner Vogelsang SGI GmbH

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

Debugging with GDB and DDT

Starting Embedded C Programming CM0506 Small Embedded Systems

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

Eclipse CDT Tutorial. Eclipse CDT Homepage: Tutorial written by: James D Aniello

Debugging (Part 1) The material for this lecture is drawn, in part, from The Practice of Programming (Kernighan & Pike) Chapter 5

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

Portland State University Maseeh College of Engineering and Computer Science. Proficiency Examination Process

1 Basic functions of a debugger

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

1 A Brief Introduction To GDB

EL2310 Scientific Programming

Unix and C Program Development SEEM

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

CS 11 C track: lecture 6

Introduction to the Command line. Introduction to the command line. Introduction to the Command line. GNU/Linux at South Wales

GDB QUICK REFERENCE GDB Version 4

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

Reviewing gcc, make, gdb, and Linux Editors 1

Programming Studio #9 ECE 190

Development Environment & Linux Guide

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

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

18-600: Recitation #3

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

GDB Tutorial. University of Waterloo

CMPSC 311- Introduction to Systems Programming Module: Debugging

Should you know scanf and printf?

1.00 Lecture 2. What s an IDE?

TotalView Debugger New Features Guide. version 8.4.0

Laboratory Assignment #3 Eclipse CDT

Eclipse Tutorial. For Introduction to Java Programming By Y. Daniel Liang

ARM DS-5. Using the Debugger. Copyright 2010 ARM. All rights reserved. ARM DUI 0446A (ID070310)

Debugging with GDB and DDT

SOME PRELIMINARIES FOR BEGINNERS AND PROS

CS2141 Software Development using C/C++ Debugging

At the shell prompt, enter idlde

Program Design: Using the Debugger

Mobi View. Charging: Turning on Mobi View: Using Your Mobi View: Writing Notes:

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

CMPSC 311- Introduction to Systems Programming Module: Debugging

PetaLinux SDK User Guide. Application Development Guide

COP 3014: Spring 2018 A Guide to Using CLion

2 Getting Started. Getting Started (v1.8.6) 3/5/2007

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

Integration with IDE tools

Coordinator of Education and Training Programs

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

Class Information ANNOUCEMENTS

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

JCreator. Starting JCreator

CSE 410: Systems Programming

Introduction to IntelliJ

Using the GNU Debugger

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

ECE 3210 Laboratory 1: Develop an Assembly Program

Supplement H.1: JBuilder X Tutorial. For Introduction to Java Programming, 5E By Y. Daniel Liang

Simulator. Chapter 4 Tutorial: The SDL

Using the GNU Debugger

ICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit

Supplement II.B(1): JBuilder X Tutorial. For Introduction to Java Programming By Y. Daniel Liang

Transcription:

ddd Tips This provides some helpful information about the Unix ddd debugger. with more detailed information: There are other resources available gnu ddd manual matloff ddd information Contents Prerequisites... 1 Launching ddd... 1 Overview of ddd... 1 How can I tell ddd to show line numbers?... 3 Running Your Program... 4 What happens after run begins?... 6 How can I set breakpoints?... 6 How can I set a breakpoint in another source file?... 7 How can I remove a breakpoint?... 7 How can I look at the value of a variable?... 7 How can I look at an array or complex structure?... 7 How can I remove something from the Display Area?... 10 How can I tell ddd to interrupt execution when a variable's value changes?... 10 How can I fix the "GDB is Busy" error?... 10 Prerequisites Your code must have been compiled with the -g compiler option. Example: gcc -g -o executablename programname.c ddd uses an x-window display. If you are using it remotely, you must have ubuntu (or a unixemulation product such as cygwin) and started an x-window terminal window. Launching ddd ddd executablename Overview of ddd When ddd starts (it takes a while, if it takes longer than 30 seconds, see How can I fix the "GDB is Busy" error?. Error! Bookmark not defined.), it shows a Tip of the Day. These will be helpful for most students. It shows the initial DDD window (see Figure 1: Initial Display) which consists of the following areas:

Menu Bar Tool Bar Data Area Source File Area Command Tool Area Console Area This is at the menu at the top of the window and includes File, Edit, View, etc. This is immediately below the menu bar and contains some important tools like Find and Break. At the beginning, this shows an empty grid area. It is used to show values of variables which you wish to closely examine. This displays your source code. This appears on the right side of the Source File Area and includes buttons: Run Step Next Cont Finish Kill run the program. This is at the bottom of the screen: execute the current step. It will step into a called function. execute the current step, but do not step into a called function. Continue execution until the next break or stdin. continue execution until the finish of the current function. Kill the execution of your program. debugger commands are shown/entered standard input is entered (depending on preferences) standard output is shown (depending on preferences)

Figure 1: Initial Display How can I tell ddd to show line numbers? This is done via the Source menu item. Source > Display Line Numbers

Figure 2: Showing Line Numbers Running Your Program Although there are multiple mechanisms provided to run your code within ddd, it is easiest to specify program arguments and how to handle stdin by using the Program menu item. If you are using stdin, it is easier to first tell ddd to use an Execution Window: Program > Run in Execution Window (you only have to do this one time) Figure 3: Running in an Execution Window

And then to tell ddd to run it: Program > Run Figure 4: Run If you need to enter command line arguments for your program, use Program > Run ddd will show a window which allows you to either select previously entered arguments or enter new ones If you want to redirect stdin to come from a file, use Program > Run ddd will show a window which allows you to either select previously entered arguments or enter new ones. You can specify command line arguments, stdin redirection or both: args <inputfilename args <inputfilename

Figure 5: Redirecting stdin What happens after run begins? After run, your code will execute until whichever it first encounters program exit or program return a request for stdin from the keyboard a Breakpoint (which you must manually set) a Watch Point variable's value changes How can I set breakpoints? Click on a line number. Your right mouse button will give you a popup menu where you can set a breakpoint. When you set it, a stop sign will appear. Figure 6: Setting a Break Point

When you run your code, if the breakpoint is encountered, execution will stop at it. The current point of execution is shown with a large arrow. Figure 7: Program Breaking at a Breakpoint How can I set a breakpoint in another source file? Sometimes programs are separated into multiple source files. ddd starts by showing the main function. If you would like to set a breakpoint in a function named "insert" which is in another source file, simply click in the source function reference window on the tool bar. Replace "main" with your function name (e.g., insert). See figure 1 for location of the function reference window. How can I remove a breakpoint? Click on the line number containing the breakpoint. Your right mouse button will give you a popup menu allowing you to delete the breakpoint. How can I look at the value of a variable? For a simple variable, you can hover the mouse over the variable and its value will show during execution. For an array reference (e.g., studentm[i].szstudentfullnm), highlight the entire reference and then hover over that selected text. You can also display a variable in the Display Area. Right click on a variable and it will be shown in the Display Area. This is useful to see how the variable changes as the code executes. How can I look at an array or complex structure? Arrays and complex structures are usually shown in the Display Area. Right click on the array and select Display. If your variable is a pointer, you might prefer to display what it references by selecting Display*. The example in Figure 8 shows what is displayed for the following array:

typedef struct { double dexam1; double dexam2; double dfinalexam; char szstudentidnr[7]; char szstudentfullnm[21]; } Student; Student studentm[10]; // exam #1 score // exam #2 score // final exam score // Student Identification Nr // Student full Nm Figure 8: Display of studentm To examine the contents of an element of that array, click on the element and then you can do any of the following on that element: right click menu and select show all. Figure 9 shows what would then be displayed for that element. right click menu, select New Display, select Other, and a New Dependent Display window appears. It should show you which element you selected. Press the Display button in that dialogue window. Figure 10 shows the display. Figure 9: Showing the contents of studentm[0] using show all

Figure 10: Showing the contents of studentm[1] using a New Display. You can also display slices of an array. In the Display Area, right click and select New Display. In the Display Expression, specify a slice of an array as shown below:

When the array display appears, it may appear across the page. If your right click and select Rotate, it will display vertically. How can I remove something from the Display Area? Right click on it and select Undisplay. Figure 11: Removing a Display How can I tell ddd to interrupt execution when a variable's value changes? This is done by setting a watch point. While running, select what you want to watch using the mouse and press the Watch button (it looks like two eyeballs) in the Tool Bar. When you continue executing your code, it will interrupt execution at the point in the code where the value of that variable changes. How can I fix the "GDB is Busy" error? ddd is a GUI around the GDB debugger. Unfortunately, ddd sometimes gets hung without it being something you did incorrectly. To fix that problem: exit out of ddd completely Execute the following command in a Linux terminal session: rm -r ~/.ddd