Graphics Programs Reference
In-Depth Information
Below, GDB is used to show the state of the processor registers right before
the program starts.
reader@hacking:~/booksrc $ gdb -q ./a.out
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) break main
Breakpoint 1 at 0x804837a
(gdb) run
Starting program: /home/reader/booksrc/a.out
Breakpoint 1, 0x0804837a in main ()
(gdb) info registers
eax 0xbffff894 -1073743724
ecx 0x48e0fe81 1222704769
edx 0x1 1
ebx 0xb7fd6ff4 -1208127500
esp 0xbffff800 0xbffff800
ebp 0xbffff808 0xbffff808
esi 0xb8000ce0 -1207956256
edi 0x0 0
eip 0x804837a 0x804837a <main+6>
eflags 0x286 [ PF SF IF ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
(gdb) quit
The program is running. Exit anyway? (y or n) y
reader@hacking:~/booksrc $
A breakpoint is set on the main() function so execution will stop right
before our code is executed. Then GDB runs the program, stops at the
breakpoint, and is told to display all the processor registers and their
current states.
The first four registers ( EAX , ECX , EDX , and EBX ) are known as general-
purpose registers. These are called the Accumulator , Counter , Data , and Base
registers, respectively. They are used for a variety of purposes, but they mainly
act as temporary variables for the CPU when it is executing machine
instructions.
The second four registers ( ESP , EBP , ESI , and EDI ) are also general-
purpose registers, but they are sometimes known as pointers and indexes.
These stand for Stack Pointer , Base Pointer , Source Index , and Destination Index ,
respectively. The first two registers are called pointers because they store 32-bit
addresses, which essentially point to that location in memory. These registers
are fairly important to program execution and memory management; we will
discuss them more later. The last two registers are also technically pointers,
Search WWH ::




Custom Search