Exercise 1.
The GNU assembler can embed debugging symbols into object files. This can facilitate debugging your programs, and allows you to step through your source code when debugging.Use the following commands to re-assemble and re-link the hello_x86 program:
x86_64-linux-gnu-as --32 -g -o hello_x86.o hello_x86.asm
x86_64-linux-gnu-ld -m elf_i386 -o hello_x86 hello_x86.o
Note: the -g switch enables gdb debugging symbols.
Open the executable with gdb and step through the source.
Exercise 2.
Examine a disassembly of the hello_x86.o object file by entering:
x86_64-linux-gnu-objdump -d -M intel hello_x86.o
What happened to the print_message label? Why doesn't it appear?
Why is there no address in the lea ecx instruction?
Exercise 3.
Examine the binary file's header info with:
readelf -h hello_x86
What are the magic byte(s)?
What are the other flags in the ELF header?
Exercise 4.
Load the hello_x86 executable in gdb and examine the machine code with the following instructions:
(gdb) info file
Symbols from "/home/pete/Documents/ASM/hello_world/x86/hello_x86".
Local exec file:
`/home/pete/Documents/ASM/hello_world/x86/hello_x86', file type elf32-i386.
Entry point: 0x8049000
0x08049000 - 0x0804903a is .text
0x0804a000 - 0x0804a01a is .data
(gdb) set $code_start = 0x08049000
(gdb) set $code_end = 0x0804903a
(gdb) print ($code_end - $code_start)
$1 = 58
(gdb) x /58xb $code_start
0x8049000 <_start>: 0xb8 0x04 0x00 0x00 0x00 0xbb 0x01 0x00
0x8049008 <_start+8>: 0x00 0x00 0x8d 0x0d 0x00 0xa0 0x04 0x08
0x8049010 <_start+16>: 0xba 0x0d 0x00 0x00 0x00 0xcd 0x80 0xb8
0x8049018 <print_hex_message+1>: 0x04 0x00 0x00 0x00 0xbb 0x01 0x00 0x00
0x8049020 <print_hex_message+9>: 0x00 0x8d 0x0d 0x0d 0xa0 0x04 0x08 0xba
0x8049028 <print_hex_message+17>: 0x0d 0x00 0x00 0x00 0xcd 0x80 0xb8 0x01
0x8049030 <exit_program+2>: 0x00 0x00 0x00 0xbb 0x00 0x00 0x00 0x00
0x8049038 <exit_program+10>: 0xcd 0x80
(gdb)
How many machine code instructions can you recognize?