1*ed81dd52SAlek Pinchuk #!/usr/sbin/dtrace -s 2*ed81dd52SAlek Pinchuk /* 3*ed81dd52SAlek Pinchuk * This file and its contents are supplied under the terms of the 4*ed81dd52SAlek Pinchuk * Common Development and Distribution License ("CDDL"), version 1.0. 5*ed81dd52SAlek Pinchuk * You may only use this file in accordance with the terms of version 6*ed81dd52SAlek Pinchuk * 1.0 of the CDDL. 7*ed81dd52SAlek Pinchuk * 8*ed81dd52SAlek Pinchuk * A full copy of the text of the CDDL should have accompanied this 9*ed81dd52SAlek Pinchuk * source. A copy of the CDDL is also available via the Internet at 10*ed81dd52SAlek Pinchuk * http://www.illumos.org/license/CDDL. 11*ed81dd52SAlek Pinchuk */ 12*ed81dd52SAlek Pinchuk 13*ed81dd52SAlek Pinchuk /* 14*ed81dd52SAlek Pinchuk * Copyright 2014 Nexenta Systems, Inc. All rights reserved. 15*ed81dd52SAlek Pinchuk */ 16*ed81dd52SAlek Pinchuk 17*ed81dd52SAlek Pinchuk /* 18*ed81dd52SAlek Pinchuk * User-level dtrace for smbd. Watch everything it does. 19*ed81dd52SAlek Pinchuk * Usage: dtrace -s smbd-all.d -p `pgrep smbd` 20*ed81dd52SAlek Pinchuk */ 21*ed81dd52SAlek Pinchuk 22*ed81dd52SAlek Pinchuk #pragma D option flowindent 23*ed81dd52SAlek Pinchuk 24*ed81dd52SAlek Pinchuk self int trace; 25*ed81dd52SAlek Pinchuk self int mask; 26*ed81dd52SAlek Pinchuk 27*ed81dd52SAlek Pinchuk /* 28*ed81dd52SAlek Pinchuk * Trace everything in smbd 29*ed81dd52SAlek Pinchuk */ 30*ed81dd52SAlek Pinchuk pid$target:*smbd::entry, 31*ed81dd52SAlek Pinchuk pid$target:libmlsvc.so.1::entry, 32*ed81dd52SAlek Pinchuk pid$target:libmlrpc.so.1::entry, 33*ed81dd52SAlek Pinchuk pid$target:libsmbns.so.1::entry, 34*ed81dd52SAlek Pinchuk pid$target:libsmb.so.1::entry, 35*ed81dd52SAlek Pinchuk pid$target:libads.so.1::entry 36*ed81dd52SAlek Pinchuk { 37*ed81dd52SAlek Pinchuk self->trace++; 38*ed81dd52SAlek Pinchuk } 39*ed81dd52SAlek Pinchuk 40*ed81dd52SAlek Pinchuk /* 41*ed81dd52SAlek Pinchuk * If traced and not masked, print entry/return 42*ed81dd52SAlek Pinchuk */ 43*ed81dd52SAlek Pinchuk pid$target:*smbd::entry, 44*ed81dd52SAlek Pinchuk pid$target:libmlsvc.so.1::entry, 45*ed81dd52SAlek Pinchuk pid$target:libmlrpc.so.1::entry, 46*ed81dd52SAlek Pinchuk pid$target:libsmbns.so.1::entry, 47*ed81dd52SAlek Pinchuk pid$target:libsmb.so.1::entry, 48*ed81dd52SAlek Pinchuk pid$target:libads.so.1::entry 49*ed81dd52SAlek Pinchuk /self->trace > 0 && self->mask == 0/ 50*ed81dd52SAlek Pinchuk { 51*ed81dd52SAlek Pinchuk printf("\t0x%x", arg0); 52*ed81dd52SAlek Pinchuk printf("\t0x%x", arg1); 53*ed81dd52SAlek Pinchuk printf("\t0x%x", arg2); 54*ed81dd52SAlek Pinchuk printf("\t0x%x", arg3); 55*ed81dd52SAlek Pinchuk printf("\t0x%x", arg4); 56*ed81dd52SAlek Pinchuk printf("\t0x%x", arg5); 57*ed81dd52SAlek Pinchuk } 58*ed81dd52SAlek Pinchuk 59*ed81dd52SAlek Pinchuk /* 60*ed81dd52SAlek Pinchuk * Mask (don't print) all function calls below these functions. 61*ed81dd52SAlek Pinchuk * These make many boring, repetitive function calls like 62*ed81dd52SAlek Pinchuk * smb_mbtowc, smb_msgbuf_has_space, ... 63*ed81dd52SAlek Pinchuk * 64*ed81dd52SAlek Pinchuk * Also, libmlrpc has rather deep call stacks, particularly under 65*ed81dd52SAlek Pinchuk * ndr_encode_decode_common(), so this stops traces below there. 66*ed81dd52SAlek Pinchuk * Remove that from the mask actions to see the details. 67*ed81dd52SAlek Pinchuk */ 68*ed81dd52SAlek Pinchuk pid$target::ht_findfirst:entry, 69*ed81dd52SAlek Pinchuk pid$target::ht_findnext:entry, 70*ed81dd52SAlek Pinchuk pid$target::ndr_encode_decode_common:entry, 71*ed81dd52SAlek Pinchuk pid$target::smb_msgbuf_decode:entry, 72*ed81dd52SAlek Pinchuk pid$target::smb_msgbuf_encode:entry, 73*ed81dd52SAlek Pinchuk pid$target::smb_strlwr:entry, 74*ed81dd52SAlek Pinchuk pid$target::smb_strupr:entry, 75*ed81dd52SAlek Pinchuk pid$target::smb_wcequiv_strlen:entry 76*ed81dd52SAlek Pinchuk { 77*ed81dd52SAlek Pinchuk self->mask++; 78*ed81dd52SAlek Pinchuk } 79*ed81dd52SAlek Pinchuk 80*ed81dd52SAlek Pinchuk /* 81*ed81dd52SAlek Pinchuk * Get some of the smbd debug messages, etc. 82*ed81dd52SAlek Pinchuk */ 83*ed81dd52SAlek Pinchuk pid$target:libsmb.so.1:smb_trace:entry 84*ed81dd52SAlek Pinchuk /self->trace > 0 && self->mask == 0/ 85*ed81dd52SAlek Pinchuk { 86*ed81dd52SAlek Pinchuk printf("%s", copyinstr(arg0)); 87*ed81dd52SAlek Pinchuk } 88*ed81dd52SAlek Pinchuk 89*ed81dd52SAlek Pinchuk pid$target:libsmb.so.1:smb_syslog:entry 90*ed81dd52SAlek Pinchuk /self->trace > 0 && self->mask == 0/ 91*ed81dd52SAlek Pinchuk { 92*ed81dd52SAlek Pinchuk printf("%s", copyinstr(arg1)); 93*ed81dd52SAlek Pinchuk } 94*ed81dd52SAlek Pinchuk 95*ed81dd52SAlek Pinchuk pid$target:libc_hwcap1.so.1:syslog:entry 96*ed81dd52SAlek Pinchuk /self->trace > 0 && self->mask == 0/ 97*ed81dd52SAlek Pinchuk { 98*ed81dd52SAlek Pinchuk printf("%s", copyinstr(arg1)); 99*ed81dd52SAlek Pinchuk } 100*ed81dd52SAlek Pinchuk 101*ed81dd52SAlek Pinchuk /* 102*ed81dd52SAlek Pinchuk * Now inverses of above, unwind order. 103*ed81dd52SAlek Pinchuk */ 104*ed81dd52SAlek Pinchuk 105*ed81dd52SAlek Pinchuk pid$target::ht_findfirst:return, 106*ed81dd52SAlek Pinchuk pid$target::ht_findnext:return, 107*ed81dd52SAlek Pinchuk pid$target::ndr_encode_decode_common:return, 108*ed81dd52SAlek Pinchuk pid$target::smb_msgbuf_decode:return, 109*ed81dd52SAlek Pinchuk pid$target::smb_msgbuf_encode:return, 110*ed81dd52SAlek Pinchuk pid$target::smb_strlwr:return, 111*ed81dd52SAlek Pinchuk pid$target::smb_strupr:return, 112*ed81dd52SAlek Pinchuk pid$target::smb_wcequiv_strlen:return 113*ed81dd52SAlek Pinchuk { 114*ed81dd52SAlek Pinchuk self->mask--; 115*ed81dd52SAlek Pinchuk } 116*ed81dd52SAlek Pinchuk 117*ed81dd52SAlek Pinchuk pid$target:*smbd::return, 118*ed81dd52SAlek Pinchuk pid$target:libmlsvc.so.1::return, 119*ed81dd52SAlek Pinchuk pid$target:libmlrpc.so.1::return, 120*ed81dd52SAlek Pinchuk pid$target:libsmbns.so.1::return, 121*ed81dd52SAlek Pinchuk pid$target:libsmb.so.1::return, 122*ed81dd52SAlek Pinchuk pid$target:libads.so.1::return 123*ed81dd52SAlek Pinchuk /self->trace > 0 && self->mask == 0/ 124*ed81dd52SAlek Pinchuk { 125*ed81dd52SAlek Pinchuk printf("\t0x%x", arg1); 126*ed81dd52SAlek Pinchuk } 127*ed81dd52SAlek Pinchuk 128*ed81dd52SAlek Pinchuk pid$target:*smbd::return, 129*ed81dd52SAlek Pinchuk pid$target:libmlsvc.so.1::return, 130*ed81dd52SAlek Pinchuk pid$target:libmlrpc.so.1::return, 131*ed81dd52SAlek Pinchuk pid$target:libsmbns.so.1::return, 132*ed81dd52SAlek Pinchuk pid$target:libsmb.so.1::return, 133*ed81dd52SAlek Pinchuk pid$target:libads.so.1::return 134*ed81dd52SAlek Pinchuk { 135*ed81dd52SAlek Pinchuk self->trace--; 136*ed81dd52SAlek Pinchuk } 137