gdb:print sockaddr指针值

时间:2016-03-29 17:18:24

标签: c++ c gdb strace

目前我正在尝试部署用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)变量的值?

1 个答案:

答案 0 :(得分:3)

你可以"垂头丧气"并通过执行

取消引用指针(或其值)
(gdb) p *((struct sockaddr_in_or_whichever_you_use *) pointer_to_struct_sockaddr)

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