Vitaly Isaev
Vitaly Isaev

Reputation: 5815

gdb: print sockaddr pointer value

Currently I'm trying to deploy a network application written in C++, and it looks like it falls into infinite loop due to networking problems:

[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)

I need to know which network connection does the application lack.

Assumming that I can attach to the process with gdb, how can I print the value of a truct sockaddr * (man getpeername) variable that 0x7f1699ddfb60 points to?

Upvotes: 0

Views: 756

Answers (1)

alk
alk

Reputation: 70981

You could "downcast" and dereference the pointer (or its value) by doing

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

or

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

Upvotes: 3

Related Questions