1#!/bin/ksh -p
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright (c) 2013 Joyent, Inc.  All rights reserved.
15#
16
17DIR=/var/tmp/dtest.$$
18mkdir $DIR
19cd $DIR
20
21cat > foo.c <<EOF
22#include <stdlib.h>
23
24extern void foo();
25
26void
27main()
28{
29	foo();
30}
31EOF
32
33cat > libfoo.c <<EOF
34#include <stdio.h>
35
36void
37foo()
38{
39	printf("called foo\n");
40}
41EOF
42
43if ! gcc -m32 -fPIC -shared -o libføo.so libfoo.c -lc ; then
44	print -u 2 "failed to compile libfoo in $DIR"
45	exit 1
46fi
47
48
49if ! gcc -m32 -o foo foo.c -lføo -L. ; then
50	print -u 2 "failed to compile foo in $DIR"
51	exit 1
52fi
53
54export LD_LIBRARY_PATH=`pwd`
55
56if ! dtrace -n 'pid$target:libf*::entry{printf("probemod: %s\n", probemod)}' \
57    -qc ./foo ; then
58	print -u 2 "dtrace failed in $DIR"
59	exit 1
60fi
61
62cd
63rm -rf $DIR
64
65