xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/pid/tst.provregex2.ksh (revision f41150baf74bdaf964ddfe42d865d3c2380b3623)
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 2008 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27# ident	"%Z%%M%	%I%	%E% SMI"
28
29#
30# This test verifies that probes will be picked up after a dlopen(3C)
31# when the pid provider is specified as a glob (e.g., p*d$target.)
32#
33
34if [ $# != 1 ]; then
35	echo expected one argument: '<'dtrace-path'>'
36	exit 2
37fi
38
39dtrace=$1
40DIR=${TMPDIR:-/tmp}/dtest.$$
41
42mkdir $DIR
43cd $DIR
44
45cat > Makefile <<EOF
46all: main altlib.so
47
48main: main.o
49	cc -o main main.o
50
51main.o: main.c
52	cc -c main.c
53
54altlib.so: altlib.o
55	cc -z defs -G -o altlib.so altlib.o -lc
56
57altlib.o: altlib.c
58	cc -c altlib.c
59EOF
60
61cat > altlib.c <<EOF
62void
63go(void)
64{
65}
66EOF
67
68cat > main.c <<EOF
69#include <dlfcn.h>
70#include <unistd.h>
71#include <stdio.h>
72
73void
74go(void)
75{
76}
77
78int
79main(int argc, char **argv)
80{
81	void *alt;
82	void *alt_go;
83
84	go();
85
86	if ((alt = dlopen("./altlib.so", RTLD_LAZY | RTLD_LOCAL)) 
87	    == NULL) {
88		printf("dlopen of altlib.so failed: %s\n", dlerror());
89		return (1);
90	}
91
92	if ((alt_go = dlsym(alt, "go")) == NULL) {
93		printf("failed to lookup 'go' in altlib.so\n");
94		return (1);
95	}
96
97	((void (*)(void))alt_go)();
98
99	return (0);
100}
101EOF
102
103make > /dev/null
104if [ $? -ne 0 ]; then
105	print -u2 "failed to build"
106	exit 1
107fi
108
109cat > main.d <<'EOF'
110p*d$target::go:entry
111{
112	@foo[probemod, probefunc, probename] = count();
113}
114
115END
116{
117	printa("%s:%s:%s %@u\n",@foo);
118}
119EOF
120
121script() {
122	$dtrace -q -s ./main.d -c ./main
123}
124
125script
126status=$?
127
128cd /tmp
129/usr/bin/rm -rf $DIR
130
131exit $status
132