about the print command in gdb.

S

sunil

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
 
P

p_cricket_guy

sunil said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top