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#ident "%Z%%M% %I% %E% SMI" 28 29DIR=/var/tmp/dtest.$$ 30 31mkdir $DIR 32cd $DIR 33 34cat > Makefile <<EOF 35all: main livelib.so deadlib.so 36 37main: main.o prov.o 38 cc -o main main.o 39 40main.o: main.c 41 cc -c main.c 42 43 44livelib.so: livelib.o prov.o 45 cc -z defs -G -o livelib.so livelib.o prov.o -lc 46 47livelib.o: livelib.c prov.h 48 cc -c livelib.c 49 50prov.o: livelib.o prov.d 51 dtrace -G -s prov.d livelib.o 52 53prov.h: prov.d 54 dtrace -h -s prov.d 55 56 57deadlib.so: deadlib.o 58 cc -z defs -G -o deadlib.so deadlib.o -lc 59 60deadlib.o: deadlib.c 61 cc -c deadlib.c 62 63clean: 64 rm -f main.o livelib.o prov.o prov.h deadlib.o 65 66clobber: clean 67 rm -f main livelib.so deadlib.so 68EOF 69 70cat > prov.d <<EOF 71provider test_prov { 72 probe go(); 73}; 74EOF 75 76cat > livelib.c <<EOF 77#include "prov.h" 78 79void 80go(void) 81{ 82 TEST_PROV_GO(); 83} 84EOF 85 86cat > deadlib.c <<EOF 87void 88go(void) 89{ 90} 91EOF 92 93 94cat > main.c <<EOF 95#include <dlfcn.h> 96#include <unistd.h> 97#include <stdio.h> 98 99int 100main(int argc, char **argv) 101{ 102 void *live, *dead; 103 void *go; 104 105 if ((live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) { 106 printf("dlopen of livelib.so failed: %s\n", dlerror()); 107 return (1); 108 } 109 110 (void) dlclose(live); 111 112 if ((dead = dlopen("./deadlib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) { 113 printf("dlopen of deadlib.so failed: %s\n", dlerror()); 114 return (1); 115 } 116 117 if ((live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) { 118 printf("dlopen of livelib.so failed: %s\n", dlerror()); 119 return (1); 120 } 121 122 if ((go = dlsym(live, "go")) == NULL) { 123 printf("failed to lookup 'go' in livelib.so\n"); 124 return (1); 125 } 126 127 ((void (*)(void))go)(); 128 129 return (0); 130} 131EOF 132 133/usr/ccs/bin/make > /dev/null 134if [ $? -ne 0 ]; then 135 print -u2 "failed to build" 136 exit 1 137fi 138 139script() { 140 dtrace -w -c ./main -Zqs /dev/stdin <<EOF 141 test_prov*::: 142 { 143 printf("%s:%s:%s\n", probemod, probefunc, probename); 144 } 145EOF 146} 147 148script 149status=$? 150 151cd / 152/usr/bin/rm -rf $DIR 153 154exit $status 155