The variable content printed by gdb debugging is inconsistent with the output of the program.

topic description

in the fun call of the TcpSocket, function derived from the base class socketBase, the this pointer of the derived class is passed to the function that takes the socketBase pointer of the base class as an argument. In the function, the type is converted to TcpSocket, but it is found that all the members in the TcpSocket are set to 0, and the members in the base class are correct.
debug with gdb, but in the debugging tool, the contents of variables in the TcpSocket class in fun are normal, but the contents of the variables printed out by the actual running of the program are 0 for no reason.

the picture is as follows:
gdb debugging:

(gdb) p tcpSocket->m_bConnected
$2 = true
(gdb) p tcpSocket->m_uid
$3 = 12
(gdb) p tcpSocket->m_iLastRecvTime
$4 = 1532751659

Program run print:

TrackerMgr::onClose m_bConnected 0, uid 0, lasttime 0.

idea:
you can basically make sure that there is no problem with type conversion, and you can also see that there is no problem with member variable access in the debugging tool. I really don"t know what the reason is.

Apr.30,2021

results obtained from debugging tools such as gdb sometimes are not guaranteed to be correct. As for why, it may be a question of gdb , which I don't understand in depth (if anyone knows, please comment in the comments section). This is why it may sometimes be incorrect to use the single-step trace of IDE to see the value of a variable.

if you type log , you can guarantee that it is completely correct.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bdca07-31330.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bdca07-31330.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?