|
本人今天写程序的时候发现了下面一个问题。
[souldump@localhost bin]$ cat test.c
#include <stdio.h>
int main(int argc, char *argv[])
{
func(1, 2);
}
[souldump@localhost bin]$ cat test2.c
#include <stdio.h>
int func(int a, unsigned int flags, int third)
{
printf("in %s a is %d flags %d third %p \n", __FUNCTION__, a ,flags, third);
}
[souldump@localhost bin]$ gcc -o main test.c test2.c
[souldump@localhost bin]$ gdb main
GNU gdb Fedora (6.8-29.fc10)
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
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 "i386-redhat-linux-gnu"...
(no debugging symbols found)
(gdb) disass main
Dump of assembler code for function main:
0x080483c4 <main+0>: lea 0x4(%esp),%ecx
0x080483c8 <main+4>: and $0xfffffff0,%esp
0x080483cb <main+7>: pushl -0x4(%ecx)
0x080483ce <main+10>: push %ebp
0x080483cf <main+11>: mov %esp,%ebp
0x080483d1 <main+13>: push %ecx
0x080483d2 <main+14>: sub $0x14,%esp
0x080483d5 <main+17>: movl $0x2,0x4(%esp)
0x080483dd <main+25>: movl $0x1,(%esp)
0x080483e4 <main+32>: call 0x80483f4 <func>
0x080483e9 <main+37>: add $0x14,%esp
0x080483ec <main+40>: pop %ecx
0x080483ed <main+41>: pop %ebp
0x080483ee <main+42>: lea -0x4(%ecx),%esp
0x080483f1 <main+45>: ret
End of assembler dump.
(gdb) disass func
Dump of assembler code for function func:
0x080483f4 <func+0>: push %ebp
0x080483f5 <func+1>: mov %esp,%ebp
0x080483f7 <func+3>: sub $0x18,%esp
0x080483fa <func+6>: mov 0x10(%ebp),%eax
0x080483fd <func+9>: mov %eax,0x10(%esp)
0x08048401 <func+13>: mov 0xc(%ebp),%eax
0x08048404 <func+16>: mov %eax,0xc(%esp)
0x08048408 <func+20>: mov 0x8(%ebp),%eax
0x0804840b <func+23>: mov %eax,0x8(%esp)
0x0804840f <func+27>: movl $0x80484f4,0x4(%esp)
0x08048417 <func+35>: movl $0x80484fc,(%esp)
0x0804841e <func+42>: call 0x80482f4 <printf@plt>
0x08048423 <func+47>: leave
0x08048424 <func+48>: ret
End of assembler dump.
(gdb) r
Starting program: /home/souldump/bin/main
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
in func a is 1 flags 2 third 0xbffff478
Program exited with code 051.
Missing separate debuginfos, use: debuginfo-install glibc-2.9-3.i686
(gdb)
我有一个3个参数的函数,但是我传两个参数照样能编译过,
我又试了下,传5个参数也没问题。
GCC把我搞了,高手帮忙解决下吧。 |
|