xref: /titanic_41/usr/src/cmd/mdb/tools/scripts/map2linktest.sh (revision 7fad02ee84994b49ae4b1505c21b22149e44d2a5)
17c478bd9Sstevel@tonic-gate#!/bin/ksh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6b272bda5Spetede# Common Development and Distribution License (the "License").
7b272bda5Spetede# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
227c478bd9Sstevel@tonic-gate#
23b272bda5Spetede# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate# Use is subject to license terms.
257c478bd9Sstevel@tonic-gate#
267c478bd9Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate#
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate#
307c478bd9Sstevel@tonic-gate# Create dummy functions for each of the functions in the module API.  We can
317c478bd9Sstevel@tonic-gate# then link a module against an object file created from the output of this
327c478bd9Sstevel@tonic-gate# script to determine whether or not that module restricts itself to the API.
337c478bd9Sstevel@tonic-gate# If the module uses functions outside of the module API, then it cannot be
347c478bd9Sstevel@tonic-gate# used as a kmdb module.
357c478bd9Sstevel@tonic-gate#
367c478bd9Sstevel@tonic-gatenawk '
377c478bd9Sstevel@tonic-gate	/^[ 	]*global:[ 	]*$/ {
387c478bd9Sstevel@tonic-gate		printing = 1;
397c478bd9Sstevel@tonic-gate		next;
407c478bd9Sstevel@tonic-gate	}
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate	/^[	]*local:[ 	]*$/ {
437c478bd9Sstevel@tonic-gate		printing = 0;
447c478bd9Sstevel@tonic-gate		next;
457c478bd9Sstevel@tonic-gate	}
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate	# Skip blank lines and comments
487c478bd9Sstevel@tonic-gate	/^$/ { next; }
497c478bd9Sstevel@tonic-gate	/^[ 	]*#/ { next;}
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate	# Print globals only
527c478bd9Sstevel@tonic-gate	printing == 0 { next; }
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate	# Symbols beginning with "kmdb_" are not in the module API - they are
557c478bd9Sstevel@tonic-gate	# private to kmdb.
567c478bd9Sstevel@tonic-gate	$1 ~ /^kmdb_/ { next; }
577c478bd9Sstevel@tonic-gate
58b272bda5Spetede	# Symbols which have the token "variable" are seen as an int
59b272bda5Spetede	$3 ~ /variable/ {
60b272bda5Spetede		if (seen[$1]) {
61b272bda5Spetede			next;
62b272bda5Spetede		}
63b272bda5Spetede
64b272bda5Spetede		seen[$1] = 1;
65b272bda5Spetede
66b272bda5Spetede		printf("int %s = 0;\n", substr($1, 1, length($1) - 1));
67b272bda5Spetede		next;
68b272bda5Spetede	}
69b272bda5Spetede
707c478bd9Sstevel@tonic-gate	$1 !~ /;$/ { next; }
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate	# Print everything else that we have not already seen as a function
737c478bd9Sstevel@tonic-gate	# definition so we can create our filter.
747c478bd9Sstevel@tonic-gate	{
757c478bd9Sstevel@tonic-gate		if (seen[$1]) {
767c478bd9Sstevel@tonic-gate			next;
777c478bd9Sstevel@tonic-gate		}
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate		seen[$1] = 1;
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate		printf("void %s(void) {}\n", substr($1, 1, length($1) - 1));
827c478bd9Sstevel@tonic-gate	}
837c478bd9Sstevel@tonic-gate'
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate#
867c478bd9Sstevel@tonic-gate# kmdb modules cannot have their own _init, _fini, or _info routines.  By
877c478bd9Sstevel@tonic-gate# creating dummies for them here, a link against an object file created from
887c478bd9Sstevel@tonic-gate# the output of this script will fail if the module defines one of them.
897c478bd9Sstevel@tonic-gate#
907c478bd9Sstevel@tonic-gateecho "void _init(void) {}"
917c478bd9Sstevel@tonic-gateecho "void _info(void) {}"
927c478bd9Sstevel@tonic-gateecho "void _fini(void) {}"
93*7fad02eeSpetede#
94*7fad02eeSpetede# The SunStudio compiler may generate calls to _memcpy and so we
95*7fad02eeSpetede# need to make sure that the correct symbol exists for these calls.
96*7fad02eeSpetede#
97*7fad02eeSpetedeecho "void _memcpy(void) {}"
98