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

Similar documents
Lab2 - Bootloader. Conventions. Department of Computer Science and Information Engineering National Taiwan University

Source level debugging. October 18, 2016

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

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

Lab11 - Bare Metal Programming. Department of Computer Science and Information Engineering National Taiwan University

Development Environment & Linux Guide

Development Environment Embedded Linux Primer Ch 1&2

Today s presentation. Git gdb Project 1

Laboratory 1 Semester 1 11/12

Exercise Session 6 Computer Architecture and Systems Programming

CMPSC 311- Introduction to Systems Programming Module: Debugging

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

Using the Debugger. Michael Jantz Dr. Prasad Kulkarni

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

Understanding Software Vulnerabilities: C, Debugging Assembly, and Buffer Overflows

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

CS356: Discussion #5 Debugging with GDB. Marco Paolieri

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

ECE 3210 Laboratory 1: Develop an Assembly Program

CMPSC 311- Introduction to Systems Programming Module: Debugging

18-600: Recitation #3

μc/probe on the element14 BeagleBone Black

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

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

Spring 2017 Gabriel Kuri

Using gdb to find the point of failure

Problem Set 1: Unix Commands 1

CS 642 Homework #4. Due Date: 11:59 p.m. on Tuesday, May 1, Warning!

Recitation: Bomb Lab. September 17 th 2018

CSE 374 Programming Concepts & Tools

CSE 351. GDB Introduction

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

CS/COE 0449 term 2174 Lab 5: gdb

F&S Introduction to Eclipse

Code::Blocks Student Manual

Raspberry Pi Setup Tutorial

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

Code::Blocks Student Manual

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

Data and File Structures Laboratory

Download, Install and Setup the Linux Development Workload Create a New Linux Project Configure a Linux Project Configure a Linux CMake Project

Chapter 7: User Defined Functions and Stack Mechanics

Lab 0: Intro to running Jupyter Notebook on a Raspberry Pi

Scientific Programming in C IX. Debugging

DAY 4. CS3600, Northeastern University. Alan Mislove

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

Labs instructions for Enabling BeagleBone with TI SDK 5.x

Digital Design and Computer Architecture Harris and Harris, J. Spjut Elsevier, 2007

Exercise 1: Basic Tools

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Profiling Applications and Creating Accelerators

F28HS2 Hardware-Software Interfaces. Lecture 6: ARM Assembly Language 1

Debugging with GDB and DDT

CS354 gdb Tutorial Written by Chris Feilbach

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

buffer overflow exploitation

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

Lab 1 Introduction to UNIX and C

Linux Essentials. Smith, Roderick W. Table of Contents ISBN-13: Introduction xvii. Chapter 1 Selecting an Operating System 1

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

CS155: Computer Security Spring Project #1

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

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

Introduction to Linux

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

Reviewing gcc, make, gdb, and Linux Editors 1

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

Debugging. John Lockman Texas Advanced Computing Center

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

A113X1 Development Kit

IDE: Integrated Development Environment

Starting Embedded C Programming CM0506 Small Embedded Systems

Topics. What is a RaspberryPi? Why should I want one? What is Raspbian? What is SSH? What is FTP? What is LAMP? Making a LAMP Stack!

EE516: Embedded Software Project 1. Setting Up Environment for Projects

ROS Qt Creator Plug-in. Release

Introduction to Linux (Part II) BUPT/QMUL 2018/03/21

Setting up the K70 with KDS

Programming Studio #9 ECE 190

Unix and C Program Development SEEM

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

EE 355 Lab 3 - Algorithms & Control Structures

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

Lab4 Embedded Linux. Introduction

Interfacing with Raspberry Pi 3 Model B Updated: 9/19/17

Carnegie Mellon. Linux Boot Camp. Jack, Matthew, Nishad, Stanley 6 Sep 2016

1. Conventions in this tutorial Introduction Check and change configuration settings as needed Start Digi ESP...

Lecture 4 Processes. Dynamic Analysis. GDB

XLink Kai Raspberry Pi Beginners Tutorial

Lab: Setting up PL-App with a Raspberry Pi

Systems Programming. Fatih Kesgin &Yusuf Yaslan Istanbul Technical University Computer Engineering Department 18/10/2005

Embedded Linux. A Tour inside ARM's Kernel

Pengwyn Documentation

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

ROS Qt Creator Plug-in. Release

Qualcomm Snapdragon Profiler

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

PRINCIPLES OF OPERATING SYSTEMS

Program Design: Using the Debugger

CS Programming Languages Fall Homework #2

Debugging Your CUDA Applications With CUDA-GDB

Transcription:

Lab6 GDB debugging 1 / 15

Learn how to perform source-level debugging with GDB. 2 / 15

Host Machine OS: Windows Target Machine Raspberry Pi (2 or 3) Build Machine A computer with a SD card slot OS: Ubuntu 15.10 (or above) 64-bit 3 / 15

Host Machine PL2303 Driver PuTTY Target Machine GDB Some buggy programs You may find all software on the CSL Course Software. 4 / 15

Raspberry Pi Power supply Micro SD card and card reader USB-TTL cable Network cable 5 / 15

If you are using RPi 3 and suffer from serial connection problem, please connect to it with ssh. To achieve this, insert the SD card into the build machine, and chroot into the root filesystem to install openssh-server. You may also install GDB for later use. % # chroot into the root filesystem on the SD card % apt-get install openssh-server gdb Configure network for both RPi and the host machine, and plug the network cable between them. Now, you should be able to launch ssh connection from putty to RPi. % vi /etc/network/interfaces 6 / 15

7 / 15

How do you debug without a debugger? Human brain compiler printf printf printf... A debugger allows you to runtime inspect and control the behavior of your program. Step by step execute the code. Examine process state (e.g. CPU registers, memory) at any time. Manually modify process state. The debugger we are going to use is GDB, the GNU Project debugger. 8 / 15

First, install GDB in your RPi. $ sudo apt-get install gdb Suppose you write a source file hello.c, and you want to trace it with GDB. When you compile it with GCC, you need an additional option to add debugging information to the executable hello. $ gcc g o hello hello.c Don t change the relative path between hello.c and hello since GDB require the source file to perform source-level debugging. Now, you can start GDB. $ gdb hello (gdb) (gdb) help (gdb) help command (gdb) (gdb) # Tips: you may type fewer characters if not ambiguous (gdb) h command 9 / 15

break: Set breakpoint to make program stop at certain line or address. (gdb) b line_number (gdb) b main info: Show various kind of information. We use it for breakpoints here. (gdb) i b delete: Delete a breakpoint (gdb) d breakpoint_number run: Start the program (gdb) r (gdb) r arg1 arg2 (gdb) r < input_file > output_file step: Execute a line of source code (gdb) s next: Like step but steps over function calls instead of step into them. (gdb) n 10 / 15

print: Print variables. Both local and global are available. (gdb) p variable (gdb) p &variable (gdb) p *pointer (gdb) p/x variable_in_hex set: Set variables. If variable and subcommand conflicts in names, add the keyword variable. (gdb) set variable=value (gdb) set variable variable=value 11 / 15

12 / 15

layout src: Display source code window and command line window at the same time. The line highlighted in the source code window is the next line to be execute. (gdb) la src focus: Focusing on source code window let you scroll the source code up and down. Focusing on command line window let you search for history command. (gdb) foc src (gdb) foc cmd Ctrl-x Ctrl-a: Turn off TUI mode and back to pure command line mode. 13 / 15

Download the buggy programs here. Extract the archive and you will find 3 exercises. $ tar xf gdb_exercise.tar Exercise 1: Given the dividend and the divisor, the program modulo calculates the remainder by repeatedly subtracting the divisor from the dividend. However, the calculation just don t stop. Use GDB to find the reason if you have no idea. $./modulo 100 3 Exersice 2 & 3: The program sof allows users to modify and print the content of an array. The program fmt receives strings from users and echoes them back. The two programs behave oddly under some special inputs (i.e. payload.txt in each directory). That is, their executions fall into a function called loop(). Show that you can use GDB to find the last statement before executing loop(). $./sof < payload.txt $./fmt < payload.txt 14 / 15

Debugging with GDB Stack buffer overflow - Wikipedia Uncontrolled format string Wikipedia 15 / 15