h>
main(){
exit(0);
}
Go ahead and compile the program. Use the -static flag to compile in the library call to
exit as well.
$ gcc -static -o exit exit.c
NOTE If you receive the following error, you do not have the glibc-staticdevel
package installed on your system:
/usr/bin/ld: cannot find -lc
You can either install that rpm or try to remove the -static flag. Many recent
compilers will link in the exit call without the -static flag.
Now launch gdb in quiet mode (skip banner) with the -q flag. Start by setting a breakpoint
at the main function; then run the program with r. Finally, disassemble the _exit
function call with disass _exit.
$ gdb exit -q
(gdb) b main
Breakpoint 1 at 0x80481d6
(gdb) r
Starting program: /root/book/chapt11/exit
Breakpoint 1, 0x080481d6 in main ()
(gdb) disass _exit
Dump of assembler code for function _exit:
0x804c56c <_exit>: mov 0x4(%esp,1),%ebx
0x804c570 <_exit+4>: mov $0xfc,%eax
0x804c575 <_exit+9>: int $0x80
0x804c577 <_exit+11>: mov $0x1,%eax
0x804c57c <_exit+16>: int $0x80
0x804c57e <_exit+18>: hlt
0x804c57f <_exit+19>: nop
End of assembler dump.
(gdb) q
You can see that the function starts by loading our user argument into ebx (in our
case, 0). Next, line _exit+11 loads the value 0x1 into eax; then the interrupt (int $0x80)
is called at line _exit+16.
Pages:
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415