From: "MCG LU Fengcheng" <Fengcheng.LU@alcatel-sbell.com.cn>
To: <gdb@sourceware.org>
Subject: Why are NOT the function parametters in the stack. They are in the register!
Date: Wed, 02 Nov 2005 06:11:00 -0000 [thread overview]
Message-ID: <7E98B33B3500C0409DBEC5C0E3FDEF120230B583@htmail.sbell.com.cn> (raw)
Hello all
In my program, I have a confused problem. Any helps are welcome!
I have the following function with variable parameters
void PrintTrace(char* fileName, int lineNo, char* traceType, char* fmt,...)
{
va_list args;
char buf[MX_SIZE];
...........................................................
va_start(args,fmt);
vsnprintf(buf,MX_SIZE,fmt,args);
va_end(args);
..............................................................
}
Sometimes, program crash when PrintTrace is called. I use the gdb to analyze the problem.
root@aaa-n3s30#gdb a.out core.1462
GNU gdb 6.1.1
.......................................
Core was generated by `/home/lfc/a.out'.
Program terminated with signal 11, Segmentation fault.
.....................................................
#0 0x4013641b in vfprintf () from /lib/libc.so.6
Then I run the bt, get the output:
(gdb) bt
#0 0x4013641b in vfprintf () from /lib/libc.so.6
#1 0x40154b7c in vsnprintf () from /lib/libc.so.6
#2 0x40079316 in PrintTrace (fileName=0x400a07a0 "/home/lfc/test.c", lineNo=340, traceType=0x0, fmt=0x0) at test.c:248
#3 0x400934d2 in CmwInit (vceId=1003) at /home/lfc/test.c:340
#4 0x08049281 in main (argc=1, argv=0xbffff954) at test.c:463
In the PrintTrace, traceType and fmt are both NULL. It's impossible. I always give the valid pointer for the traceType and fmt.
I run f 2 and try to print the traceType and fmt address.
(gdb) f 2
#2 0x40079316 in PrintTrace (fileName=0x400a07a0 "/home/lfc/test.c", lineNo=340, traceType=0x0, fmt=0x0) at test.c:248
(gdb) p &traceType
Address requested for identifier "traceType" which is in register $eax
(gdb) p &fmt
Address requested for identifier "fmt" which is in register $eax
gdb complains fmt and traceType are in the register eax. Why not in the stack. In fact, lineNo and filename are in the stack. Gdb can print their address out.
I check the eax value. It is zero. I also check the stack. I found the fmt and traceType address were in the stack.
It's the gdb issue? I can't understand it.
Help me!!!!!!!!!!!!!!!!!!
B.R.
Lu
next reply other threads:[~2005-11-02 6:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-02 6:11 MCG LU Fengcheng [this message]
2005-11-02 13:45 ` Daniel Jacobowitz
2005-11-02 18:28 ` Jim Blandy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7E98B33B3500C0409DBEC5C0E3FDEF120230B583@htmail.sbell.com.cn \
--to=fengcheng.lu@alcatel-sbell.com.cn \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).