Using the GNU Debugger

Similar documents
Using the GNU Debugger

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

Intro x86 Part 3: Linux Tools & Analysis

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

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

buffer overflow exploitation

CSE 351: Week 4. Tom Bergan, TA

CS5460/6460: Operating Systems. Lecture 9: Finishing system boot, and system init. Anton Burtsev January, 2014

CS 161 Computer Security. Week of January 22, 2018: GDB and x86 assembly

Exercise Session 6 Computer Architecture and Systems Programming

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

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

CMSC Lecture 03. UMBC, CMSC313, Richard Chang

18-600: Recitation #3

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

GDB cheatsheet - page 1

CSE 351. GDB Introduction

Sistemi Operativi. Lez. 16 Elementi del linguaggio Assembler AT&T

Assembly Language Programming Debugging programs

CPEG421/621 Tutorial

CS / ECE , Spring 2010 Exam 1

CMSC 313 Lecture 08 Project 2 Questions Recap Indexed Addressing Examples Some i386 string instructions A Bigger Example: Escape Sequence Project

Recitation: Bomb Lab. September 17 th 2018

W4118: PC Hardware and x86. Junfeng Yang

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

Assembly Language: Function Calls

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

143A: Principles of Operating Systems. Lecture 7: System boot. Anton Burtsev January, 2017

Assembly Language: Function Calls" Goals of this Lecture"

CPS104 Recitation: Assembly Programming

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 7. Procedures and the Stack

Buffer Overflow Attack

The IA-32 Stack and Function Calls. CS4379/5375 Software Reverse Engineering Dr. Jaime C. Acosta

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

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

Assembly Language: Function Calls" Goals of this Lecture"

Assembly Language Lab # 9

CS/COE 0449 term 2174 Lab 5: gdb

GDB QUICK REFERENCE GDB Version 4

ROP It Like It s Hot!

Register Allocation, iii. Bringing in functions & using spilling & coalescing

Program Exploitation Intro

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

CS354 gdb Tutorial Written by Chris Feilbach

Program Design: Using the Debugger

Advanced Magic - GDB

Basic Information. CS318 Project #1. OS Bootup Process. Reboot. Bootup Mechanism

Chapter 7: User Defined Functions and Stack Mechanics

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING

Machine Programming 1: Introduction

U Reverse Engineering

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

CSCE 212H, Spring 2008 Lab Assignment 3: Assembly Language Assigned: Feb. 7, Due: Feb. 14, 11:59PM

x86 Assembly Tutorial COS 318: Fall 2017

143A: Principles of Operating Systems. Lecture 7: System boot. Anton Burtsev October, 2017

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

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

Debugging uclinux on Coldfire

Basics. Crash Dump Analysis 2015/2016. CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics.

238P: Operating Systems. Lecture 7: System boot. Anton Burtsev January, 2017

Lab 10: Introduction to x86 Assembly

CNIT 127: Exploit Development. Ch 3: Shellcode. Updated

ICS143A: Principles of Operating Systems. Midterm recap, sample questions. Anton Burtsev February, 2017

Assembly Language: Function Calls. Goals of this Lecture. Function Call Problems

3. Process Management in xv6

Using gdb to find the point of failure

MACHINE-LEVEL PROGRAMMING I: BASICS COMPUTER ARCHITECTURE AND ORGANIZATION

Basic functions of a debugger

Buffer Overflows. Buffer Overflow. Many of the following slides are based on those from

x86 assembly CS449 Fall 2017

Introduction to Computer Systems , fall th Lecture, Sep. 28 th

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

Machine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Source level debugging. October 18, 2016

ANITA S SUPER AWESOME RECITATION SLIDES

Function Calls COS 217. Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site)

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

Subprograms: Local Variables

Procedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27

CMSC 313 Lecture 12 [draft] How C functions pass parameters

CSE 410: Systems Programming

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

IA-32 & AMD64. Crash Dump Analysis 2015/2016. CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics.

Computer Architecture and Assembly Language. Practical Session 3

CSE 374 Programming Concepts & Tools

Introduction to GDB. Lezione 9 (taken from Owen HSU material)

20: Exploits and Containment

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction

Computer Organization & Assembly Language Programming (CSE 2312)

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

CS356: Discussion #5 Debugging with GDB. Marco Paolieri

X86 Stack Calling Function POV

Chapter 1. Bootstrap. Hardware

CS 2505 Computer Organization I Test 2. Do not start the test until instructed to do so! printed

CS 2505 Computer Organization I Test 2. Do not start the test until instructed to do so! printed

Using the Debugger. Michael Jantz Dr. Prasad Kulkarni

Stack overflow exploitation

Lecture 15 Intel Manual, Vol. 1, Chapter 3. Fri, Mar 6, Hampden-Sydney College. The x86 Architecture. Robb T. Koether. Overview of the x86

Homework / Exam. Return and Review Exam #1 Reading. Machine Projects. Labs. S&S Extracts , PIC Data Sheet. Start on mp3 (Due Class 19)

Instruction Set Architectures

Transcription:

Using the GNU Debugger 6.828 Fall 2016 September 14, 2016 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 1 / 14

Homework solution 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 2 / 14

Homework solution From bootasm.s: # Set up the stack pointer and call into C. movl $start, %esp call bootmain 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 2 / 14

Homework solution From bootasm.s: # Set up the stack pointer and call into C. movl $start, %esp call bootmain Later, in bootmain(): // Call the entry point from the ELF header. // Does not return! entry = (void(*)(void))(elf->entry); entry(); 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 2 / 14

What s on the stack? 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 3 / 14

What s on the stack? call bootmain pushes a return address 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 3 / 14

What s on the stack? call bootmain pushes a return address The prologue in bootmain() makes a stack frame 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 3 / 14

What s on the stack? call bootmain pushes a return address The prologue in bootmain() makes a stack frame push %ebp mov %esp,%ebp push %edi push %esi push %ebx sub $0x1c,%esp 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 3 / 14

What s on the stack? call bootmain pushes a return address The prologue in bootmain() makes a stack frame push %ebp mov %esp,%ebp push %edi push %esi push %ebx sub $0x1c,%esp The call to entry() pushes a return address 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 3 / 14

The stack when we get to 0x0010000c 0x7c00: 0x8ec031fa not the stack! 0x7bfc: 0x00007c4d bootmain() return address 0x7bf8: 0x00000000 old ebp 0x7bf4: 0x00000000 old edi 0x7bf0: 0x00000000 old esi 0x7bec: 0x00000000 old ebx 0x7be8: 0x00000000 0x7be4: 0x00000000 0x7be0: 0x00000000 0x7bdc: 0x00000000 local vars (sub $0x1c,%esp) 0x7bd8: 0x00000000 0x7bd4: 0x00000000 0x7bd0: 0x00000000 0x7bcc: 0x00007db7 entry() return address 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 4 / 14

GDB in 6.828 We provide a file called.gdbinit which automatically sets up GDB for use with QEMU. Must run GDB from the lab or xv6 directory Edit ~/.gdbinit to allow other gdbinits 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 5 / 14

GDB in 6.828 We provide a file called.gdbinit which automatically sets up GDB for use with QEMU. Must run GDB from the lab or xv6 directory Edit ~/.gdbinit to allow other gdbinits Use make to start QEMU with or without GDB. With GDB: run make qemu[-nox]-gdb, then start GDB in a second shell Use make qemu[-nox] when you don t need GDB 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 5 / 14

GDB commands Run help <command-name> if you re not sure how to use a command. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 6 / 14

GDB commands Run help <command-name> if you re not sure how to use a command. All commands may be abbreviated if unambiguous: c = co = cont = continue Some additional abbreviations are defined, e.g. s = step and si = stepi 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 6 / 14

Stepping step runs one line of code at a time. When there is a function call, it steps into the called function. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 7 / 14

Stepping step runs one line of code at a time. When there is a function call, it steps into the called function. next does the same thing, except that it steps over function calls. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 7 / 14

Stepping step runs one line of code at a time. When there is a function call, it steps into the called function. next does the same thing, except that it steps over function calls. stepi and nexti do the same thing for assembly instructions rather than lines of code. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 7 / 14

Stepping step runs one line of code at a time. When there is a function call, it steps into the called function. next does the same thing, except that it steps over function calls. stepi and nexti do the same thing for assembly instructions rather than lines of code. All take a numerical argument to specify repetition. Pressing the enter key repeats the previous command. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 7 / 14

Running continue runs code until a breakpoint is encountered or you interrupt it with Control-C. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 8 / 14

Running continue runs code until a breakpoint is encountered or you interrupt it with Control-C. finish runs code until the current function returns. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 8 / 14

Running continue runs code until a breakpoint is encountered or you interrupt it with Control-C. finish runs code until the current function returns. advance <location> runs code until the instruction pointer gets to the specified location. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 8 / 14

Breakpoints break <location> sets a breakpoint at the specified location. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 9 / 14

Breakpoints break <location> sets a breakpoint at the specified location. Locations can be memory addresses ( *0x7c00 ) or names ( mon backtrace, monitor.c:71 ). 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 9 / 14

Breakpoints break <location> sets a breakpoint at the specified location. Locations can be memory addresses ( *0x7c00 ) or names ( mon backtrace, monitor.c:71 ). Modify breakpoints using delete, disable, enable. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 9 / 14

Watchpoints Like breakpoints, but with more complicated conditions. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 10 / 14

Watchpoints Like breakpoints, but with more complicated conditions. watch <expression> will stop execution whenever the expression s value changes. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 10 / 14

Watchpoints Like breakpoints, but with more complicated conditions. watch <expression> will stop execution whenever the expression s value changes. watch -l <address> will stop execution whenever the contents of the specified memory address change. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 10 / 14

Watchpoints Like breakpoints, but with more complicated conditions. watch <expression> will stop execution whenever the expression s value changes. watch -l <address> will stop execution whenever the contents of the specified memory address change. What s the difference between wa var and wa -l &var? 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 10 / 14

Examining x prints the raw contents of memory in whatever format you specify (x/x for hexadecimal, x/i for assembly, etc). 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 11 / 14

Examining x prints the raw contents of memory in whatever format you specify (x/x for hexadecimal, x/i for assembly, etc). print evaluates a C expression and prints the result as its proper type. It is often more useful than x. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 11 / 14

Examining x prints the raw contents of memory in whatever format you specify (x/x for hexadecimal, x/i for assembly, etc). print evaluates a C expression and prints the result as its proper type. It is often more useful than x. The output from p *((struct elfhdr *) 0x10000) is much nicer than the output from x/13x 0x10000. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 11 / 14

More examining info registers prints the value of every register. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 12 / 14

More examining info registers prints the value of every register. info frame prints the current stack frame. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 12 / 14

More examining info registers prints the value of every register. info frame prints the current stack frame. list <location> prints the source code of the function at the specified location. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 12 / 14

More examining info registers prints the value of every register. info frame prints the current stack frame. list <location> prints the source code of the function at the specified location. backtrace might be useful as you work on lab 1! 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 12 / 14

Other tricks You can use the set command to change the value of a variable during execution. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 13 / 14

Other tricks You can use the set command to change the value of a variable during execution. You have to switch symbol files to get function and variable names for environments other than the kernel. For example, when debugging JOS: symbol-file obj/user/<name> symbol-file obj/kern/kernel 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 13 / 14

Summary Read the fine manual! Use the help command. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 14 / 14

Summary Read the fine manual! Use the help command. GDB is tremendously powerful and we ve only scratched the surface today. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 14 / 14

Summary Read the fine manual! Use the help command. GDB is tremendously powerful and we ve only scratched the surface today. It is well worth your time to spend an hour learning more about how to use it. 6.828 Fall 2016 Using the GNU Debugger September 14, 2016 14 / 14