CSE 351 Section 4 Program Stack & Procedure Calls Bomb Lab! - - PowerPoint PPT Presentation

cse 351 section 4
SMART_READER_LITE
LIVE PREVIEW

CSE 351 Section 4 Program Stack & Procedure Calls Bomb Lab! - - PowerPoint PPT Presentation

CSE 351 Section 4 Program Stack & Procedure Calls Bomb Lab! How is it going? Bomb-defusing tips If you have trouble figuring out what a phase is doing, try working backwards Write out everything that happens, and you might be


slide-1
SLIDE 1

CSE 351 Section 4

Program Stack & Procedure Calls

slide-2
SLIDE 2

Bomb Lab!

  • How is it going?
slide-3
SLIDE 3

Bomb-defusing tips

  • If you have trouble figuring out what a phase

is doing, try working backwards

  • Write out everything that happens, and you

might be able to look back and see a pattern

  • Try to understand what the phase is doing

based on assembly code, then predict variable values and check your understanding in gdb

slide-4
SLIDE 4

Memory Layout

slide-5
SLIDE 5

STACK

Program Memory Layout

HEAP STATIC DATA STRINGS INSTRUCTIONS

LOWER ADDRESSES HIGHER ADDRESSES

slide-6
SLIDE 6

Program Memory Layout

STACK HEAP STATIC DATA STRINGS INSTRUCTIONS

Writeable; not executable Writeable; not executable Writeable; not executable Read-only; not executable Read-only; executable

slide-7
SLIDE 7

IA32/Linux Register Usage

%eax %edx %ecx %ebx %edi %esi %ebp %esp Caller Save Callee Save Special

slide-8
SLIDE 8

x86-64 Register Usage

%r8 Argument #5 %r9 Argument #6 %r10 Caller Saved %r11 Caller Saved %r12 Callee Saved %r13 Callee Saved %r14 Callee Saved %r15 Callee Saved %rax Return Value %rbx Callee Saved %rcx Argument #4 %rdx Argument #3 %rsi Argument #2 %rdi Argument #1 %rsp Stack Pointer %rbp Callee Saved

slide-9
SLIDE 9

Demos

slide-10
SLIDE 10

Download these demos

Multiple parameters demo

http://www.cs.washington.edu/education/courses/cse351/12au/section-slides/multi-param.c wget http://www.cs.washington.edu/education/courses/cse351/12au/section-slides/multi-param.c

Recursive stack frame demo

http://www.cs.washington.edu/education/courses/cse351/12au/section-slides/fact_check.c wget http://www.cs.washington.edu/education/courses/cse351/12au/section-slides/fact_check.c

slide-11
SLIDE 11

Multiple Parameters Demo

Demo commands:

gcc -g -m64 multi-param.c -o multi-param64 gcc -g -m32 multi-param.c -o multi-param32

  • bjdump -d multi-param64 | less
  • bjdump -d multi-param32 | less

gdb multi-param64 GDB commands: break addEight, run, disas, info registers

slide-12
SLIDE 12

Recursive Stack Frame Demo

Demo commands:

gcc -g fact_check.c -o fact_check

  • bjdump -d fact_check.c | less

gdb fact_check GDB commands: break factorial, run, disas, info frame, x /20x $esp