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

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

GDB cheatsheet - page 1

CSE 351. GDB Introduction

CSE 351 Section 4 GDB and x86-64 Assembly Hi there! Welcome back to section, we re happy that you re here

18-600: Recitation #3

Using gdb to find the point of failure

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

Source level debugging. October 18, 2016

EE 355 Lab 3 - Algorithms & Control Structures

CSE 374 Programming Concepts & Tools

Problem Set 1: Unix Commands 1

Compilation, Disassembly, and Profiling (in Linux)

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

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

CS354 gdb Tutorial Written by Chris Feilbach

Exercise Session 6 Computer Architecture and Systems Programming

Intro x86 Part 3: Linux Tools & Analysis

Exploits and gdb. Tutorial 5

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

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

GDB QUICK REFERENCE GDB Version 4

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

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

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

CS/COE 0449 term 2174 Lab 5: gdb

Laboratory 1 Semester 1 11/12

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

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

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

Advanced Magic - GDB

Using the GNU Debugger

Using the GNU Debugger

Systems/DBG Debugger Version 2.20

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

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

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

CMPSC 311- Introduction to Systems Programming Module: Debugging

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

Testing and Debugging C Programming and Software Tools. N.C. State Department of Computer Science

Scientific Programming in C IX. Debugging

CS356: Discussion #5 Debugging with GDB. Marco Paolieri

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

CS 105 Lab 2: Debugger Playing with X86-64 Assembly

CMPSC 311- Introduction to Systems Programming Module: Debugging

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

Functions. Ray Seyfarth. August 4, Bit Intel Assembly Language c 2011 Ray Seyfarth

Programming Studio #9 ECE 190

Reviewing gcc, make, gdb, and Linux Editors 1

Binghamton University. CS-220 Spring X86 Debug. Computer Systems Section 3.11

CS 105 Lab 2: Debugger Playing with X86-64 Assembly

ECE 3210 Laboratory 1: Develop an Assembly Program

Debugging. John Lockman Texas Advanced Computing Center

Development Environment & Linux Guide

Data and File Structures Laboratory

Lecture 07 Debugging Programs with GDB

Binghamton University. CS-220 Spring X86 Debug. Computer Systems Section 3.11

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

1 A Brief Introduction To GDB

Program Design: Using the Debugger

Code Review and Debugging (Lab 05)

CSE 124 Discussion (10/3) C/C++ Basics

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

Compila(on, Disassembly, and Profiling

CS Programming In C

CS2141 Software Development using C/C++ Debugging

Using the Debugger. Michael Jantz Dr. Prasad Kulkarni

Today s presentation. Git gdb Project 1

F28HS2 Hardware-Software Interface. Lecture 1: Programming in C 1

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

Programming Tips for CS758/858

Basic functions of a debugger

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.

Debugging with GDB and DDT

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

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

Chapter 7: User Defined Functions and Stack Mechanics

Binghamton University. CS-220 Spring C Debugging Basics. No relevant text

Lecture 3: C Programm

DAY 4. CS3600, Northeastern University. Alan Mislove

CSE 410: Systems Programming

Debugging Your CUDA Applications With CUDA-GDB

Simple C Program. Assembly Ouput. Using GCC to produce Assembly. Assembly produced by GCC is easy to recognize:

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

Lab 03 - x86-64: atoi

CS 314 Principles of Programming Languages. Lecture 9

1. A student is testing an implementation of a C function; when compiled with gcc, the following x86-32 assembly code is produced:

{C} Tools of the Trade

CS 392/681 Lab 6 Experiencing Buffer Overflows and Format String Vulnerabilities

CS429: Computer Organization and Architecture

PRINCIPLES OF OPERATING SYSTEMS

Xuan Guo. CSC 3210 Computer Organization and Programming Georgia State University. March 12, Xuan Guo

Recitation: Bomb Lab. September 17 th 2018

EL2310 Scientific Programming

Topics. CS429: Computer Organization and Architecture. File Inclusion. A Simple C Program. Intro to C

Lecture 4 Processes. Dynamic Analysis. GDB

Introduction. Overview and Getting Started. CS 161 Computer Security Lab 1 Buffer Overflows v.01 Due Date: September 17, 2012 by 11:59pm

gdbtui - Linux Command

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

When you add a number to a pointer, that number is added, but first it is multiplied by the sizeof the type the pointer points to.

U Reverse Engineering

Transcription:

Debugging Tools CS 270: Systems Programming Instructor: Raphael Finkel

Gdb: The Gnu debugger It runs on most computers and operating systems. It allows you to examine a running executable program. It does not require the source code that created the executable. If you have the source code, compile the program to include debugging information (such as symbol tables and line numbers): gcc g hello.c To run gdb on an executable file: gdb a.out Gdb then presents a command line interface. Using the command line interface, you can get help by typing help help subtopic (where subtopic is one of the main subtopic areas listed by typing help). Examples include: help data help breakpoints help command (where command is a gdb command). Examples include: help print help run

Breakpoints Breakpoints are points in the program where you would like the program to stop so that you can examine what is going on (e.g., look at the contents of memory, registers, variables). In the absence of breakpoints, the program runs as normal until it completes or encounters an error. Typically you want to set a breakpoint near the point in the program where you think there is a problem before you run the program within gdb. You can enable and disable breakpoints. There are several ways to set a breakpoint. Examples include: break function_name break linenumber, or break filename:linenumber break address

Running a program run Run the program within gdb continue Continue the program after encountering a breakpoint step Run the program until it encounters the next line in the source file. stepi Run the program until it encounters the next machine instruction next Like step, but continue through procedure calls

Examining memory x/nfu address Examine memory or register at location address, where n is the number of items to examine f is the format to use when displaying values l s for strings l d for integers l u for unsigned integers l x for hexadecimal l a for address/pointer l f for floating point u is the unit l b for byte l h for halfword l w for word l g for giant word

Printing memory contents print exp Print the value of expression exp; let gdb determine the right format. print /f exp Print the value of expression exp using format f (see format specifications above). printf string, expressions print the list of expressions using the c-style format string string. display /f exp Print the value of expression exp using format f every time there is a break in execution.

Examining registers info registers Print a list of the register contents Registers can be referenced in expressions by a predefined variable name that corresponds to the usual term used for the register. Variable names start with $. For example: x/d $eax Prints the contents of the eax register as a number x/s $rax Prints the string starting at the address represented by the address held in the rax register print $pc Prints the address in the pc register

Miscellaneous commands bt Print the contents of the current stack (backtrace). info frame Print information about the current stack frame. info args Print information about the arguments passed to the current procedure. info locals Print information about the current local variables. list linenumber Show the source code lines around the given linenumber.

Help/tutorial pages Documentation http://web.mit.edu/gnu/doc/html/gdb_1.html ftp://ftp.gnu.org/old-gnu/manuals/gdb/html_node/gdb_toc.html http://www.cs.hmc.edu/~geoff/classes/hmc.cs105.200901/labs/gdbin fo.html Tutorials Google for gdb tutorial You can find lots of good tutorials