目前,我正尝试部署一个用C++编写的网络应用程序,看起来它由于网络问题而陷入无限循环:

[isaev@feck-5 ~]$ sudo strace -p 26252 -f -e trace=network -s 10000
[pid 26272] getpeername(30, 0x7f1699ddfb60, [28]) = -1 ENOTCONN (Transport endpoint is not connected)
[pid 26272] getpeername(30, 0x7f1699ddfb60, [28]) = -1 ENOTCONN (Transport endpoint is not connected)
[pid 26272] getpeername(30, 0x7f1699ddfb60, [28]) = -1 ENOTCONN (Transport endpoint is not connected)
[pid 26272] getpeername(30, 0x7f1699ddfb60, [28]) = -1 ENOTCONN (Transport endpoint is not connected)
[pid 26272] getpeername(30, 0x7f1699ddfb60, [28]) = -1 ENOTCONN (Transport endpoint is not connected)
[pid 26272] getpeername(30, 0x7f1699ddfb60, [28]) = -1 ENOTCONN (Transport endpoint is not connected)
[pid 26272] getpeername(30, 0x7f1699ddfb60, [28]) = -1 ENOTCONN (Transport endpoint is not connected)

我需要知道应用程序缺少哪个网络连接。
假设我可以用gdb附加到进程,那么如何打印truct sockaddr *指向的0x7f1699ddfb60man getpeername)变量的值?

最佳答案

您可以“向下转换”并通过执行以下操作取消对指针(或其值)的引用

(gdb) p *((struct sockaddr_in_or_whichever_you_use *) pointer_to_struct_sockaddr)


(gdb) p *((struct sockaddr_in_or_whichever_you_use *) 0x7f1699ddfb60)

10-08 05:48