# # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License, Version 1.0 only # (the "License"). You may not use this file except in compliance # with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2004 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # Copyright 2022 Garrett D'Amore # include $(SRC)/Makefile.master SUBDIRS = scripts setdynflag .PARALLEL: $(SUBDIRS) include ../Makefile.subdirs # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License, Version 1.0 only # (the "License"). You may not use this file except in compliance # with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2004 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" # %.o: ../../common/%.c $(COMPILE.c) $< $(POST_PROCESS_O) %.ln: ../../common/%.c $(LINT.c) -c $< /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #include #include #include #include #include #include #include void die(char *format, ...) { va_list ap; int err = errno; (void) fprintf(stderr, "%s: ", progname); va_start(ap, format); /* LINTED - variable format specifier */ (void) vfprintf(stderr, format, ap); va_end(ap); if (format[strlen(format) - 1] != '\n') (void) fprintf(stderr, ": %s\n", strerror(err)); exit(1); } void elfdie(char *format, ...) { va_list ap; (void) fprintf(stderr, "%s: ", progname); va_start(ap, format); /* LINTED - variable format specifier */ (void) vfprintf(stderr, format, ap); va_end(ap); if (format[strlen(format) - 1] != '\n') (void) fprintf(stderr, ": %s\n", elf_errmsg(elf_errno())); exit(1); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #include #include #include #include int findelfsecidx(Elf *elf, char *tofind) { Elf_Scn *scn = NULL; GElf_Ehdr ehdr; GElf_Shdr shdr; if (gelf_getehdr(elf, &ehdr) == NULL) elfdie("failed to get ELF header"); while ((scn = elf_nextscn(elf, scn)) != NULL) { char *name; if (gelf_getshdr(scn, &shdr) == NULL || (name = elf_strptr(elf, ehdr.e_shstrndx, (size_t)shdr.sh_name)) == NULL) elfdie("failed to get section header"); if (strcmp(name, tofind) == 0) return (elf_ndxscn(scn)); } return (-1); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _UTIL_H #define _UTIL_H #include #ifdef __cplusplus extern "C" { #endif extern int findelfsecidx(Elf *, char *); extern void die(char *, ...) __NORETURN; extern void elfdie(char *, ...) __NORETURN; extern const char *progname; #ifdef __cplusplus } #endif #endif /* _UTIL_H */ # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. # #ident "%Z%%M% %I% %E% SMI" .KEEP_STATE: .SUFFIXES: .pl include ../../../Makefile.cmd PKGSCRIPTS = mdb mkmodules BLDSCRIPTS = tigen map2linktest hdr2map ROOTOPTPKGBIN = $(ROOT)/opt/SUNWonmdb/bin ROOTPKGSCRIPTS = $(PKGSCRIPTS:%=$(ROOTOPTPKGBIN)/%) all install: $(BLDSCRIPTS) $(PKGSCRIPTS) clean.lint dmods install_h lint: clobber: clean clean: $(RM) $(BLDSCRIPTS) $(PKGSCRIPTS) pkg: $(ROOTPKGSCRIPTS) $(ROOTOPTPKGBIN): $(INS.dir) $(ROOTPKGSCRIPTS): $(ROOTOPTPKGBIN) $(ROOTOPTPKGBIN)/%: %.sh $(INS.rename) #!/bin/ksh # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2006 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # #ident "%Z%%M% %I% %E% SMI" # # # Given a header file, extract function prototypes and global variable # declarations in a form that can be used in a mapfile. The list of extracted # functions and variables will be combined with a user-specified template to # create a complete mapfile. # # Template # -------- # # The template contains two sections - the prologue, and the epilogue. These # sections are used, verbatim, as the beginning and the end of the mapfile. # Sections begin and end with single-line comments whose sole contents are # "/* BEGIN $section */" and "/* END $section */". # # Template example: # # /* BEGIN PROLOGUE */ # [ ... prologue goes here ... ] # /* END PROLOGUE */ # /* BEGIN EPILOGUE */ # [ ... epilogue goes here ... ] # /* END EPILOGUE */ # # Selective Exportation # --------------------- # # Some header files will have a public/private interface mix that is strongly # biased towards private interfaces. That is, of the interfaces declared by # a given header file, the majority of them are private. Only a small subset # of interfaces are to be exported publicly. Using Selective Exportation, a # special comment is included in the header file, declaring to this script that # only a subset of interfaces - those with a marking declared in the comment - # should be included in the mapfile. The marking is itself a special comment, # whose format is declared using a directive like this: # # MAPFILE: export "Driver OK" # # Using the above directive, only those function prototypes and variable # declarations with "/* Driver OK */" comments included in the mapfile. Note # that the comment must be at the end of the first line. If the declaration # spans multiple lines, the exportation comment must appear on the first line. # # Examples of functions selected for exportation: # # MAPFILE: export "Driver OK" # # extern int foo(int); /* Driver OK */ # extern void bar(int, int, /* Driver OK */ # int, void *); # # Selective Exportation may not be used in the same file as Selective Exclusion. # # Selective Exclusion # ------------------- # # Selective Exclusion is to be used in cases where the public/private interface # mix is reversed - where public interfaces greatly outnumber the private ones. # In this case, we want to be able to mark the private ones, thus telling this # script that the marked interfaces are to be excluded from the mapfile. # Marking is accomplished via a process similar to that used for Selective # Exportation. A directive is included in a comment, and is formatted like # this: # # MAPFILE: exclude "Internal" # # Using the above directive, function prototypes and variable declarations with # "/* Internal */" comments would be excluded. Note that the comment must be at # the end of the first line. If the declaration spans multiple lines, the # exclusion comment must appear on the first line. # # Examples of functions excluded from exportation: # # MAPFILE: exclude "Internal" # # extern int foo(int); /* Internal */ # extern void bar(int, int, /* Internal */ # int, void *); # # Selective Exclusion may not be used in the same file as Selective Exportation. # function extract_prototypes { typeset header="$1" typeset prefix="$2" nawk -v prefix="$prefix" <$header ' /^.*MAPFILE: export \"[^\"]*\"$/ { if (protoexclude) { print "ERROR: export after exclude\n"; exit(1); } sub(/^[^\"]*\"/, ""); sub(/\"$/, ""); exportmark=sprintf("/* %s */", $0); next; } /^.*MAPFILE: exclude \"[^\"]*\"$/ { if (protomatch) { print "ERROR: exclude after export"; exit(1); } sub(/^[^\"]*\"/, ""); sub(/\"$/, ""); excludemark=sprintf("/* %s */", $0); next; } exportmark { # Selective Exportation has been selected (exportmark is # set), so exclude this line if it does not have the # magic export mark. if (length($0) < length(exportmark) || substr($0, length($0) - length(exportmark) + 1) != \ exportmark) next; } excludemark { # Selective Exclusion has been selected (excludemark is # set), so exclude this line only if it has the magic # exclude mark. if (length($0) > length(excludemark) && substr($0, \ length($0) - length(excludemark) + 1) == \ excludemark) next; } # Functions /^extern.*\(/ { for (i = 1; i <= NF; i++) { if (sub(/\(.*$/, "", $i)) { sub(/^\*/, "", $i); if (!seenfn[$i]) { printf("%s%s;\n", prefix, $i); seenfn[$i] = 1; } break; } } next; } # Global variables /^extern[^\(\)]*;/ { for (i = 1; i <= NF; i++) { if (match($i, /;$/)) { printf("%s%s; /* variable */\n", prefix, substr($i, 1, length($i) - 1)); break; } } next; } ' || die "Extraction failed" } function extract_section { typeset skel="$1" typeset secname="$2" nawk <$skel -v name=$secname -v skel=$skel ' /\/\* [^ ]* [^ ]* \*\// && $3 == name { if ($2 == "BEGIN") { printing = 1; } else { printing = 0; } next; } printing != 0 { print; } ' } function die { echo "$PROGNAME: $@" >&2 exit 1 } function usage { echo "Usage: $PROGNAME -t tmplfile header [header ...]" >&2 exit 2 } PROGNAME=$(basename "$0") while getopts t: c ; do case $c in t) mapfile_skel=$OPTARG ;; ?) usage esac done [[ -z "$mapfile_skel" ]] && usage [[ ! -f $mapfile_skel ]] && die "Couldn't open template $tmplfile" shift $(($OPTIND - 1)) [[ $# -lt 1 ]] && usage for file in $@ ; do [[ ! -f $file ]] && die "Can't open input file $file" done extract_section $mapfile_skel PROLOGUE for file in $@ ; do echo "\t\t/*" echo "\t\t * Exported functions and variables from:" echo "\t\t * $file" echo "\t\t */" extract_prototypes $file "\t\t" echo done extract_section $mapfile_skel EPILOGUE #!/bin/ksh # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2006 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # #ident "%Z%%M% %I% %E% SMI" # # # Create dummy functions for each of the functions in the module API. We can # then link a module against an object file created from the output of this # script to determine whether or not that module restricts itself to the API. # If the module uses functions outside of the module API, then it cannot be # used as a kmdb module. # nawk ' /^[ ]*global:[ ]*$/ { printing = 1; next; } /^[ ]*local:[ ]*$/ { printing = 0; next; } # Skip blank lines and comments /^$/ { next; } /^[ ]*#/ { next;} # Print globals only printing == 0 { next; } # Symbols beginning with "kmdb_" are not in the module API - they are # private to kmdb. $1 ~ /^kmdb_/ { next; } # Symbols which have the token "variable" are seen as an int $3 ~ /variable/ { if (seen[$1]) { next; } seen[$1] = 1; printf("int %s = 0;\n", substr($1, 1, length($1) - 1)); next; } $1 !~ /;$/ { next; } # Print everything else that we have not already seen as a function # definition so we can create our filter. { if (seen[$1]) { next; } seen[$1] = 1; printf("void %s(void) {}\n", substr($1, 1, length($1) - 1)); } ' # # kmdb modules cannot have their own _init, _fini, or _info routines. By # creating dummies for them here, a link against an object file created from # the output of this script will fail if the module defines one of them. # echo "void _init(void) {}" echo "void _info(void) {}" echo "void _fini(void) {}" # # The SunStudio compiler may generate calls to _memcpy and so we # need to make sure that the correct symbol exists for these calls. # echo "void _memcpy(void) {}" #!/bin/sh # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License, Version 1.0 only # (the "License"). You may not use this file except in compliance # with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright (c) 1998-2001 by Sun Microsystems, Inc. # All rights reserved. # #ident "%Z%%M% %I% %E% SMI" mdb_lib=/net/mdb.eng/mdb/archives # Archive library path mdb_ws=/net/mdb.eng/mdb/snapshot/latest # Snapshot of latest workspace mdb_args= # Debugger argument string os_name='s81' # Default OS name prefix os_rel='5.9' # Default OS release number mach=`/bin/uname -p` # Machine type unset mdb_exec build root # Local variables # # Attempt to locate a suitable mdb binary to execute, first on the local # machine, then in the user's workspace, and finally on the MDB server. # If we select the user's workspace, we also set $root to their proto area # to force MDB to use shared libraries installed there as well. # if [ -n "$CODEMGR_WS" -a -x $CODEMGR_WS/proto/root_$mach/usr/bin/mdb ]; then mdb_exec=$CODEMGR_WS/proto/root_$mach/usr/bin/mdb root=$CODEMGR_WS/proto/root_$mach elif [ -x /usr/bin/mdb -a ! -d /mdb ]; then mdb_exec=/usr/bin/mdb root=$mdb_lib/$mach/%R/%V elif [ -x /usr/bin/mdb -a -d /mdb ]; then for isa in `isalist`; do if [ -x /usr/bin/$isa/mdb ]; then mdb_exec=/usr/bin/$isa/mdb break fi done if [ -z "$mdb_exec" ]; then echo "$0: cannot find mdb binary in ISA subdirectories" >& 2 exit 1 fi root=$mdb_lib/$mach/%R/%V elif [ -x $mdb_ws/proto/root_$mach/usr/bin/mdb ]; then mdb_exec=$mdb_ws/proto/root_$mach/usr/bin/mdb root=$mdb_lib/$mach/%R/%V fi # # Abort if we were not able to locate a copy of mdb to execute. # if [ -z "$mdb_exec" ]; then echo "$0: failed to locate mdb executable" >& 2 exit 1 fi # # The wrapper script handles several special command-line arguments that are # used to select a desired set of MDB macros, modules, and a libkvm binary. # if [ $# -gt 0 ]; then case "$1" in -s[0-9]*) build=`echo "$1" | tr -d -` shift ;; -[0-9]|-[0-9][0-9]) build=`echo "$1" | tr -d -` if [ $build -lt 10 ]; then build=${os_name}_0$build else build=${os_name}_$build fi shift ;; -[0-9][0-9]-|-[0-9][0-9][A-Za-z]) build=${os_name}_`echo "$1" | cut -c2- | tr '[A-Z]' '[a-z]'` shift ;; -B) build=$os_rel/Beta; shift ;; -U) build=$os_rel/Beta_Update; shift ;; -G) build=$os_rel/Generic; shift ;; -\?) echo "Usage: $0" \ "[ -s | -s | -[0-9]+ | -B | -G | -U ] args ..." echo "\t-s Use proto area for specified release" echo "\t e.g. -${os_name}" echo "\t-s Use proto area for specified build" echo "\t e.g. -${os_name}_01" echo "\t-[0-9]+ Use proto area for specified build of $os_name" echo "\t-B Use proto area for $os_rel Beta build" echo "\t-G Use proto area for $os_rel Generic build\n" echo "\t-U Use proto area for $os_rel Beta_Update build" ;; esac fi # # If a build was specified, using the corresponding proto area from $mdb_lib. # Note that this will override the $root setting determined above. # [ -n "$build" ] && root=$mdb_lib/$mach/$build # # If a proto area was set either by specifying a build number, or by using # mdb from $CODEMGR_WS, set LD_LIBRARY_PATH accordingly. This allows mdb to # pick up the appropriate libkvm.so to examine dumps from that build. # We also add the -R flag to the mdb command line so that mdb will modify # its default macro include and module library paths to use the build root. # if [ -n "$build" -o "$root" = "$CODEMGR_WS/proto/root_$mach" ]; then if [ -n "$build" -a ! -d $root ]; then echo "mdb: $root is missing or not a directory" >& 2 exit 1 fi [ -n "$LD_LIBRARY_PATH" ] && LD_LIBRARY_PATH=$LD_LIBRARY_PATH: LD_LIBRARY_PATH="$LD_LIBRARY_PATH$root/usr/lib" [ -n "$LD_LIBRARY_PATH_64" ] && LD_LIBRARY_PATH_64=$LD_LIBRARY_PATH_64: LD_LIBRARY_PATH_64="$LD_LIBRARY_PATH_64$root/usr/lib/sparcv9" export LD_LIBRARY_PATH LD_LIBRARY_PATH_64 elif [ $mdb_exec = $mdb_ws/proto/root_$mach/usr/bin/mdb ]; then # # We also need to set LD_LIBRARY_PATH if we're using mdb.eng's mdb # binary -- it requires the new libproc.so to work properly. # usrlib=$mdb_ws/proto/root_$mach/usr/lib [ -n "$LD_LIBRARY_PATH" ] && LD_LIBRARY_PATH=$LD_LIBRARY_PATH: LD_LIBRARY_PATH="$LD_LIBRARY_PATH$usrlib" [ -n "$LD_LIBRARY_PATH_64" ] && LD_LIBRARY_PATH_64=$LD_LIBRARY_PATH_64: LD_LIBRARY_PATH_64="$LD_LIBRARY_PATH_64$usrlib/sparcv9" export LD_LIBRARY_PATH LD_LIBRARY_PATH_64 fi exec $mdb_exec -R $root $mdb_args "$@" #!/bin/sh # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License, Version 1.0 only # (the "License"). You may not use this file except in compliance # with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright (c) 1998-2001 by Sun Microsystems, Inc. # All rights reserved. # #ident "%Z%%M% %I% %E% SMI" # # Script to build the MDB modules present in a workspace against the set of # include files saved in an MDB "root" (created with mkroot.sh), and install # resulting modules into this tree so that it can be used as the argument # to ``mdb -R'' or by mdb's auto-detect code, used by the mdb.sh wrapper. # We use the ``make dmods'' target to do the build -- this is equivalent to # make install, but does not build the debugger itself, and pass a special # define (_MDB_BLDID) into the compilation environment so that the module # source can detect the various changes in header files, etc. This is only # used for module source kept on mdb.eng that needs to compile against # legacy builds of the operating system. # PNAME=`basename $0` opt_R=false umask 022 if [ $# -ne 0 -a "x$1" = x-R ]; then opt_R=true shift fi if [ $# -ne 1 -o -z "${INCROOT:=$1}" -o ! -d "$INCROOT" ]; then echo "Usage: $PNAME [-R] root-dir" exit 2 fi if $opt_R; then ROOT="$INCROOT" export ROOT fi if [ -z "$SRC" -a -z "$CODEMGR_WS" ]; then echo "$PNAME: \$SRC or \$CODEMGR_WS must be set" >& 2 exit 1 fi if [ -z "$ROOT" ]; then echo "$PNAME: \$ROOT must be set" >& 2 exit 1 fi if [ -z "$SRC" ]; then SRC="$CODEMGR_WS/usr/src" export SRC fi # # Derive a build-id based on the name of the $ROOT directory. The build-id # is passed into the compilation environment as _MDB_BLDID, and consists of # a 4-digit hexadecimal number whose first two digits are the release number # (e.g. 0x27XX for Solaris 2.7) and whose last two digits are the build number. # case "`basename $INCROOT`" in s297_fcs) BLDID=0x2637 ;; s998_fcs) BLDID=0x2721 ;; s28_fcs) BLDID=0x2838 ;; s399_*) BLDID=0x27FF ;; s599_*) BLDID=0x27FF ;; s899_*) BLDID=0x27FF ;; s1199_*) BLDID=0x27FF ;; s81_*) BLDID=0x81`basename $INCROOT | sed 's/s81_//' | tr -cd '[0-9]'` ;; *) echo "$PNAME: cannot derive _MDB_BLDID for $INCROOT" >& 2; exit 1 ;; esac # # Set up the necessary environment variables to perform a build. Basically # we need to do the same stuff as bld_env or bfmenv. # [ `id | cut -d'(' -f1` != 'uid=0' ] && CH='#' || CH=; export CH VERSION=${VERSION:-"`basename $INCROOT`:`date '+%m/%d/%y'`"}; export VERSION MACH=`uname -p`; export MACH TMPDIR=/tmp; export TMPDIR NODENAME=`uname -n`; export NODENAME PATH="$PUBLIC/bin:$PUBLIC/bin/$MACH:/opt/onbld/bin:/opt/onbld/bin/$MACH:/bin:/sbin:/usr/bin:/usr/sbin:."; export PATH INS=/opt/onbld/bin/$MACH/install.bin; export INS MAKEFLAGS=e; export MAKEFLAGS # # We need to export $BLDID into the compilation environment, and make sure # to remap the default include path from /usr/include to $INCROOT/usr/include. # ENVCPPFLAGS1="-YI,$INCROOT/usr/include"; export ENVCPPFLAGS1 ENVCPPFLAGS2="-D_MDB_BLDID=$BLDID"; export ENVCPPFLAGS2 ENVCPPFLAGS3=; export ENVCPPFLAGS3 ENVCPPFLAGS4=; export ENVCPPFLAGS4 ENVLDLIBS1=; export ENVLDLIBS1 ENVLDLIBS2=; export ENVLDLIBS2 ENVLDLIBS3=; export ENVLDLIBS3 cd $SRC && make clobber && make dmods #!/bin/ksh # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License, Version 1.0 only # (the "License"). You may not use this file except in compliance # with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2004 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # # Terminal Info Generator # # This script generates a static terminfo database for use by mdb. For each # of the terminal properties used by mdb_termio.c, this script uses tput(1) # to determine the value of the given attribute for each specified terminal # type. The script produces an ANSI-C source file which contains a static # array for each terminal type storing the properties. An additional array # is then declared containing a list of the terminal types and pointers to # the previous arrays. Finally, source code for several terminfo routines # are included that simply access the arrays and return the saved properties. # # Hammerhead: /bin is a separate directory (not symlinked to /usr/bin) PATH=/bin:/usr/bin; export PATH PROGNAME=$(basename "$0") usage() { echo "Usage: $PROGNAME -s skel -t termio [-v] term ..." >&2 exit 2 } extract_section() { typeset skel="$1" typeset secname="$2" nawk <$skel -v name=$secname -v skel=$skel ' /\/\* [^ ]* [^ ]* \*\// && $3 == name { if ($2 == "BEGIN") { printing = 1; printf("# %d \"%s\"\n", NR + 1, skel); } else { printing = 0; } next; } printing != 0 { print; } ' } verbose=false termio_c= terminfo_skel= while getopts s:t:v name ; do case $name in v) verbose=true ;; s) terminfo_skel=$OPTARG ;; t) termio_c=$OPTARG ;; ?) usage ;; esac done shift $(($OPTIND - 1)) [[ -z "$terminfo_skel" || -z "$termio_c" || $# -eq 0 ]] && usage termlist=$* for term in $termlist; do tput -T $term init >/dev/null 2>&1 if [ $? -ne 0 ]; then echo "`basename $0`: invalid terminal -- $term" >& 2 exit 1 fi done # Extract the prologue from the skeleton extract_section $terminfo_skel PROLOGUE # # For each terminal in the terminal list, produce a property definition array # listing each property we need in mdb_termio.c and its current value. # for term in $termlist; do # # We don't want the compiler to blame the skeleton if it doesn't like # the array we generate here, so point the finger elsewhere # echo "# 1 \"dynamic $term data from tigen\"" cterm=$(echo "$term" |tr '-' '_') $verbose && echo "loading terminfo for $term ... \c" >& 2 echo "static const termio_attr_t ${cterm}_attrs[] = {" sed -n '/termio_attrs\[\] = /,/^}/p' $termio_c | \ sed -n \ 's/{ "\([a-z0-9]*\)", \([A-Z_]*\),.*/\1 \2/p' | \ while read attr type; do case "$type" in TIO_ATTR_REQSTR|TIO_ATTR_STR) data="\"`tput -T $term $attr | od -bv | sed 's/^[0-9]*//;s/ /\\\\\\\\/g;/^\$/d'`\"" [ "$data" = '""' ] && data=NULL ;; TIO_ATTR_BOOL) tput -T $term $attr data=`expr 1 - $?` ;; TIO_ATTR_INT) data=`tput -T $term $attr` ;; *) echo "`basename $0`: unknown type for $attr: $type" >& 2 exit 1 esac echo "\t{ \"$attr\", $type, (void *)$data }," done echo "\t{ NULL, 0, NULL }" printf '};\n\n' $verbose && echo "done" >& 2 done # # For each terminal in the terminal list, produce an entry in the terminal # database array linking this terminal to its terminfo property array. # echo "# 1 \"dynamic array from tigen\"" echo "static const termio_desc_t termio_db[] = {" for term in $termlist; do cterm=$(echo "$term" |tr '-' '_') echo "\t{ \"$term\", ${cterm}_attrs }," done printf '\t{ NULL, NULL }\n};\n' extract_section $terminfo_skel EPILOGUE exit 0 # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License, Version 1.0 only # (the "License"). You may not use this file except in compliance # with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2004 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # include ../../../Makefile.cmd # Hammerhead: amd64-only SUBDIRS = $(MACH64) include ../../Makefile.subdirs # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License, Version 1.0 only # (the "License"). You may not use this file except in compliance # with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2004 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # .KEEP_STATE: PROG = setdynflag SRCS = \ die.c \ findscn.c \ setdynflag.c OBJS = $(SRCS:%.c=%.o) include $(SRC)/cmd/Makefile.cmd include ../../common/Makefile.util # # We're going to run this as part of the build, so we want it to use the # running kernel's includes and libraries. # include $(SRC)/Makefile.native CPPFLAGS = -I../../common CFLAGS += $(CCVERBOSE) CFLAGS64 += $(CCVERBOSE) CERRWARN += $(CNOWARN_UNINIT) LDFLAGS += $(ZLAZYLOAD) $(BDIRECT) LDLIBS = -lelf NATIVE_LIBS += libelf.so libc.so install all: $(PROG) clobber clean: $(RM) $(OBJS) $(PROG) $(PROG): $(OBJS) $(LINK.c) $(OBJS) -o $@ $(LDLIBS) $(POST_PROCESS) %.o: ../common/%.c $(COMPILE.c) $< $(POST_PROCESS_O) # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # Copyright 2025 Hammerhead Project # include ../Makefile.com include $(SRC)/cmd/Makefile.cmd.64 install: all $(ROOTPROG64) /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* * Set bits in the DT_FLAGS_1 member of the .dynamic section of an object. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* * These are here because we can't be sure (yet) that the build machine has a * sys/link.h that includes the following #defines. This tool will be executed * on the build machine, so we have to use its headers (rather than the ones * in $ROOT which will, by definition, be up to date). These #defines can be * removed when we're sure that all build machines have recent copies of * sys/link.h. */ #ifndef DF_1_IGNMULDEF #define DF_1_IGNMULDEF 0x00040000 #endif #ifndef DF_1_NOKSYMS #define DF_1_NOKSYMS 0x00080000 #endif struct dtflagval { char *fv_name; ulong_t fv_val; }; static struct dtflagval dtflagvals[] = { { "DF_1_IGNMULDEF", DF_1_IGNMULDEF }, { "DF_1_NOKSYMS", DF_1_NOKSYMS }, { NULL } }; const char *progname; static void usage(void) { (void) fprintf(stderr, "Usage: %s -f flag_val file\n", progname); exit(2); } static void set_flag(char *ifile, ulong_t flval) { Elf *elf; Elf_Scn *scn; Elf_Data *data; GElf_Shdr shdr; GElf_Dyn dyn; int fd, secidx, nent, i; (void) elf_version(EV_CURRENT); if ((fd = open(ifile, O_RDWR)) < 0) die("Can't open %s", ifile); if ((elf = elf_begin(fd, ELF_C_RDWR, NULL)) == NULL) elfdie("Can't start ELF for %s", ifile); if ((secidx = findelfsecidx(elf, ".dynamic")) == -1) die("Can't find .dynamic section in %s\n", ifile); if ((scn = elf_getscn(elf, secidx)) == NULL) elfdie("elf_getscn (%d)", secidx); if (gelf_getshdr(scn, &shdr) == NULL) elfdie("gelf_shdr"); if ((data = elf_getdata(scn, NULL)) == NULL) elfdie("elf_getdata"); nent = shdr.sh_size / shdr.sh_entsize; for (i = 0; i < nent; i++) { if (gelf_getdyn(data, i, &dyn) == NULL) elfdie("gelf_getdyn"); if (dyn.d_tag == DT_FLAGS_1) { dyn.d_un.d_val |= (Elf64_Xword)flval; if (gelf_update_dyn(data, i, &dyn) == 0) elfdie("gelf_update_dyn"); break; } } if (i == nent) { die("%s's .dynamic section doesn't have a DT_FLAGS_1 " "field\n", ifile); } if (elf_update(elf, ELF_C_WRITE) == -1) elfdie("Couldn't update %s with changes", ifile); (void) elf_end(elf); (void) close(fd); } static ulong_t parse_flag(char *optarg) { ulong_t flval = 0L; char *arg; int i; for (arg = strtok(optarg, ","); arg != NULL; arg = strtok(NULL, ",")) { for (i = 0; dtflagvals[i].fv_name != NULL; i++) { if (strcmp(dtflagvals[i].fv_name, arg) == 0) flval |= dtflagvals[i].fv_val; } } return (flval); } int main(int argc, char **argv) { ulong_t flval = 0L; int c; progname = basename(argv[0]); while ((c = getopt(argc, argv, "f:")) != EOF) { switch (c) { case 'f': if ((flval = strtoul(optarg, NULL, 0)) == 0 && (flval = parse_flag(optarg)) == 0) usage(); break; default: usage(); } } if (flval == 0 || argc - optind != 1) usage(); set_flag(argv[optind], flval); return (0); }