$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/specs
Configured with: ../configure --PRefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-24)
$ gdb -v
GNU gdb Red Hat Linux (6.0post-0.20031117.6rh)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu".
$ uname -a
Linux candy 2.4.21-9.EL #1 Thu Jan 8 17:03:13 EST 2004 i686 athlon i386 GNU/Linux
實例: /************
* a.c
************/
void function(void)
{
char buffer[5];
int* ret;
ret=buffer+28;
(*ret)+=10;
}
void main()
{
int x;
x=0;
function();
x=1;
printf("%d/n",x);
return;
}
/*end*/
懂C語言的人都會認為最后的輸出結果是1,可惜輸出結果為0.為什么呢?請聽解釋. ret=buffer+28;
(*ret)+=10;
中的28 和 10
編譯(會有warning,不用管他.) $gcc -g -o a a.c //加上-g 用來在gdb中調試
$gdb a
(gdb)disas main //得到反匯編代碼 如下:
Dump of assembler code for function main:
0x08048366 <main+0>: push %ebp
0x08048367 <main+1>: mov %esp,%ebp
0x08048369 <main+3>: sub $0x8,%esp
0x0804836c <main+6>: and $0xfffffff0,%esp
0x0804836f <main+9>: mov $0x0,%eax
0x08048374 <main+14>: sub %eax,%esp
0x08048376 <main+16>: movl $0x0,0xfffffffc(%ebp)
0x0804837d <main+23>: call 0x8048348 <function>
0x08048382 <main+28>: movl $0x1,0xfffffffc(%ebp)
0x08048389 <main+35>: sub $0x8,%esp
0x0804838c <main+38>: pushl 0xfffffffc(%ebp)
0x0804838f <main+41>: push $0x8048474
0x08048394 <main+46>: call 0x8048288
0x08048399 <main+51>: add $0x10,%esp
0x0804839c <main+54>: leave
0x0804839d <main+55>: ret
End of assembler dump.
(gdb)disas function
Dump of assembler code for function function:
0x08048348 <
新聞熱點
疑難解答