1 #!/bin/ksh -p
   2 #
   3 # CDDL HEADER START
   4 #
   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 # or http://www.opensolaris.org/os/licensing.
  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  14 # When distributing Covered Code, include this CDDL HEADER in each
  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 #
  24 # Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 
  28 if [ $# != 1 ]; then
  29         echo expected one argument: '<'dtrace-path'>'
  30         exit 2
  31 fi
  32 
  33 dtrace=$1
  34 DIR=/var/tmp/dtest.$$
  35 
  36 mkdir $DIR
  37 cd $DIR
  38 
  39 cat > Makefile <<EOF
  40 all: main livelib.so deadlib.so
  41 
  42 main: main.o prov.o
  43         gcc -m32 -o main main.o
  44 
  45 main.o: main.c
  46         gcc -m32 -c main.c
  47 
  48 
  49 livelib.so: livelib.o prov.o
  50         gcc -m32 -shared -o livelib.so livelib.o prov.o -lc
  51 
  52 livelib.o: livelib.c prov.h
  53         gcc -m32 -fPIC -c livelib.c
  54 
  55 prov.o: livelib.o prov.d
  56         $dtrace -G -s prov.d livelib.o
  57 
  58 prov.h: prov.d
  59         $dtrace -h -s prov.d
  60 
  61 
  62 deadlib.so: deadlib.o
  63         gcc -m32 -shared -o deadlib.so deadlib.o -lc
  64 
  65 deadlib.o: deadlib.c
  66         gcc -m32 -fPIC -c deadlib.c
  67 
  68 clean:
  69         rm -f main.o livelib.o prov.o prov.h deadlib.o
  70 
  71 clobber: clean
  72         rm -f main livelib.so deadlib.so
  73 EOF
  74 
  75 cat > prov.d <<EOF
  76 provider test_prov {
  77         probe go();
  78 };
  79 EOF
  80 
  81 cat > livelib.c <<EOF
  82 #include "prov.h"
  83 
  84 void
  85 go(void)
  86 {
  87         TEST_PROV_GO();
  88 }
  89 EOF
  90 
  91 cat > deadlib.c <<EOF
  92 void
  93 go(void)
  94 {
  95 }
  96 EOF
  97 
  98 
  99 cat > main.c <<EOF
 100 #include <dlfcn.h>
 101 #include <unistd.h>
 102 #include <stdio.h>
 103 
 104 int
 105 main(int argc, char **argv)
 106 {
 107         void *live, *dead;
 108         void *go;
 109 
 110         if ((live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) {
 111                 printf("dlopen of livelib.so failed: %s\n", dlerror());
 112                 return (1);
 113         }
 114 
 115         (void) dlclose(live);
 116 
 117         if ((dead = dlopen("./deadlib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) {
 118                 printf("dlopen of deadlib.so failed: %s\n", dlerror());
 119                 return (1);
 120         }
 121 
 122         if ((live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) {
 123                 printf("dlopen of livelib.so failed: %s\n", dlerror());
 124                 return (1);
 125         }
 126 
 127         if ((go = dlsym(live, "go")) == NULL) {
 128                 printf("failed to lookup 'go' in livelib.so\n");
 129                 return (1);
 130         }
 131 
 132         ((void (*)(void))go)();
 133 
 134         return (0);
 135 }
 136 EOF
 137 
 138 make > /dev/null
 139 if [ $? -ne 0 ]; then
 140         print -u2 "failed to build"
 141         exit 1
 142 fi
 143 
 144 script() {
 145         $dtrace -w -c ./main -Zqs /dev/stdin <<EOF
 146         test_prov*:::
 147         {
 148                 printf("%s:%s:%s\n", probemod, probefunc, probename);
 149         }
 150 EOF
 151 }
 152 
 153 script
 154 status=$?
 155 
 156 cd /
 157 /usr/bin/rm -rf $DIR
 158 
 159 exit $status