Project

General

Profile

Bug #7093

libdtrace mangles userland struct keywords

Added by Robert Mustacchi over 3 years ago.

Status:
New
Priority:
Normal
Category:
DTrace
Start date:
2016-06-09
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:

Description

While trying to trace a sendmsg function call, I get:

[root@7011a0de-5c06-4605-a4d0-d809b4995996 ~]# dtrace -n 'pid$target::sendmsg:entry { print(*(args[1])); ustack(); }' -c ./a.out 
dtrace: description 'pid$target::sendmsg:entry ' matched 1 probe
dtrace: allowing destructive actions
CPU     ID                    FUNCTION:NAME
  0  82503                    sendmsg:entry struct pid62665`libsocket.so.1`msghdr <forward decl>

              libsocket.so.1`sendmsg
              a.out`main+0x160
              a.out`_start+0x83

Failed to send ICMPv6 message: Message too long
dtrace: pid 62665 has exited

Inspecting libsocket, though, the proper information seems to be there:

[root@7011a0de-5c06-4605-a4d0-d809b4995996 ~]# ctfdump -t /usr/lib/libsocket.so.1 | tail -n 30
  <309> struct msghdr (24 bytes)
        msg_name type=22 off=0
        msg_namelen type=77 off=32
        msg_iov type=316 off=64
        msg_iovlen type=1 off=96
        msg_accrights type=47 off=128
        msg_accrightslen type=1 off=160

  <310> typedef sctp_assoc_t refers to 1
  <311> struct sctp_sndrcvinfo (32 bytes)
        sinfo_stream type=42 off=0
        sinfo_ssn type=42 off=16
        sinfo_flags type=42 off=32
        sinfo_ppid type=43 off=64
        sinfo_context type=43 off=96
        sinfo_timetolive type=43 off=128
        sinfo_tsn type=43 off=160
        sinfo_cumtsn type=43 off=192
        sinfo_assoc_id type=310 off=224

  <312> struct sctpopt (16 bytes)
        sopt_aid type=310 off=0
        sopt_name type=1 off=32
        sopt_len type=46 off=64
        sopt_val type=47 off=96

  [313] const struct msghdr refers to 309
  <314> const struct msghdr * refers to 313
  <315> struct msghdr * refers to 309
  [316] struct iovec * refers to 308

This is on a recent build of the platform, and I built the binary only linking against libsocket and libnsl:

[root@7011a0de-5c06-4605-a4d0-d809b4995996 ~]# uname -a
SunOS 7011a0de-5c06-4605-a4d0-d809b4995996 5.11 joyent_20151120T194028Z i86pc i386 i86pc
[root@7011a0de-5c06-4605-a4d0-d809b4995996 ~]# gcc -lsocket -lnsl foo.c

DTrace refers to such types as struct pidXXXX`libsocket.so.1`msghdr; however, when we come into the function dtrace_lookup_by_type, when we see that it's a type that refers to a module, we have a type that looks like struct libsocket.so.1`msghdr. We unfortunately currently just split on the ` character in the type. Instead, we need to rearrange the name here such that if we have a struct, enum, or union keyword, we don't include that, which is what the current solution does and causes the example here to work.

Also available in: Atom PDF