Feeds:
Posts
Comments

Archive for the ‘debugger’ Category

What is stack register?
Stack is a group of memory which is use for storage informations during the execution of program. It’s temporary area in CPU.
How it work?
The First data that goes into the stack is the Last data that come out from the stack.

In this article I will show you how it works using gdb (gnu debugger).
First, I create a program named stack in assembly language. I name the file stack.asm.

section .text
 global _start
 _start:

push 0xAAAAAAAA
 push 0xBBBBBBBB
 push 0xCCCCCCCC
 push 0xDDDDDDDD

pop eax
 pop ebx
 pop ecx
 pop edx

exit:
 mov eax,1
 mov ebx,0
 int 0x80

stack01
Then I compile with “nasm” and link with “ld”. I add option -gstabs+ to tell nasm to save debugging information that I will use in gdb to print the line of assembler code that correspond to each assembler instruction. Since my processor is 32 bit, the format will be elf32.

$ nasm -f elf32 -gstabs+ stack.asm -o stack.o
$ ld stack.o - stack

stack02
Now, let start using gdb.
Type “gdb” followed by the program “stack”.

$ gdb stack
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08 
Copyright (C) 2011 Free Software Foundation, Inc. 
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it. 
There is NO WARRANTY, to the extent permitted by law. Type "show copying" 
and "show warranty" for details. 
This GDB was configured as "i686-linux-gnu". 
For bug reporting instructions, please see: 
... 
Reading symbols from /home/darklinux/assembly/stack...done. 
(gdb)

(more…)

Read Full Post »