By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,133 Members | 1,294 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,133 IT Pros & Developers. It's quick & easy.

about the print command in gdb.

P: n/a
Hi,
I am trying to print a variable port using print command , the
port variable is coming as function arguement.See the snippet below.

680 printf("The port number is %d\n",port);
(gdb) p port
$1 = 0
(gdb) n
The port number is 7710
681 while ((stat=listenerSocketFd.Open( port)) != OK &&
triedCount++ < 6 )
(gdb) p port
$2 = 0
(gdb)
The port number is 7710

Why it is showing different value what the actually the
variable is having.But some times it shows the correct value.
Is there any reason,if anybody knows please help me out.

Regards
Sunil

Dec 19 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
sunil wrote:
Hi,
I am trying to print a variable port using print command , the
port variable is coming as function arguement.See the snippet below.

680 printf("The port number is %d\n",port);
(gdb) p port
$1 = 0
(gdb) n
The port number is 7710
681 while ((stat=listenerSocketFd.Open( port)) != OK &&
triedCount++ < 6 )
(gdb) p port
$2 = 0
(gdb)
The port number is 7710

Why it is showing different value what the actually the
variable is having.But some times it shows the correct value.
Is there any reason,if anybody knows please help me out.
Debuggers are off-topic here. Please post in a gnu/gdb specific or
your OS specific newsgroups.

<OT>
Just a guess: your compiler might have optimized the code. Try
compiling with optimization turned off and then debug.
You can also look into assembly code (you can do that within gdb)
and see how "port" is handled.

Dec 19 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.