5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License, Version 1.0 only
7 # (the "License"). You may not use this file except in compliance
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 # or http://www.opensolaris.org/os/licensing.
12 # See the License for the specific language governing permissions
13 # and limitations under the License.
15 # When distributing Covered Code, include this CDDL HEADER in each
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 # If applicable, add the following below this CDDL HEADER, with the
18 # fields enclosed by brackets "[]" replaced with your own identifying
19 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # Copyright 2004 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
27 # ident "%Z%%M% %I% %E% SMI"
31 # ctfstabs requires an object file with CTF data, and a file containing
32 # directives which indicate the types and members for which offsets are to
33 # be generated. The developer provides a single input file containing both
34 # the #include directives used to generate the object file as well as the
35 # offset directives. This script automates the splitting of the master file,
36 # the generation of the object file, the invocation of ctfstabs, and cleanup.
43 use POSIX
qw(:sys_wait_h);
46 our $PROGNAME = basename
($0);
47 our ($CTmp, $OTmp, $GenTmp, $GenPPTmp, $Keep, $Verbose);
50 print STDERR
"Usage: $PROGNAME [-k] [-s ctfstabs] [-r ctfconvert] ",
51 "compiler [options]\n";
52 print STDERR
" NOTE: compiler options must enable stabs or DWARF as ",
60 unlink($CTmp) if (-f
$CTmp);
61 unlink($OTmp) if (-f
$OTmp);
62 unlink($GenTmp) if (-f
$GenTmp);
63 unlink($GenPPTmp) if (-f
$GenPPTmp);
67 print STDERR
"$PROGNAME: ", join(" ", @_), "\n";
74 my ($arg, $name, $default) = @_;
78 } elsif (defined $ENV{$name}) {
90 print STDERR
"+ @argv\n";
92 if ((my $rc = system(@argv)) == -1) {
93 bail
("Failed to execute $argv[0]: $!");
94 } elsif (WIFEXITED
($rc)) {
95 $_ = WEXITSTATUS
($rc);
99 bail
("$argv[0] failed with status $_");
101 } elsif (WSIGNALLED
($rc)) {
103 # WCOREDUMP isn't a POSIX macro, do it the non-portable way.
105 bail
("$argv[0] failed with signal $_ (core dumped)");
107 bail
("$argv[0] failed with signal $_");
117 getopts
("kr:s:v", \
%opts) || usage
();
118 usage
() if (@ARGV < 1);
120 my $ctfstabs = findprog
($opts{"s"}, "CTFSTABS", "ctfstabs");
121 my $ctfconvert = findprog
($opts{"r"}, "CTFCONVERT", "ctfconvert");
124 $Verbose = $opts{k
} || $opts{v
};
125 my ($cc, @cflags) = @ARGV;
127 $CTmp = "ctfstabs.tmp.$$.c"; # The C file used to generate CTF
128 $OTmp = "ctfstabs.tmp.$$.o"; # Object file with CTF
129 $GenTmp = "ctfstabs.tmp.$$.gen.c"; # genassym directives
130 $GenPPTmp = "ctfstabs.tmp.$$.genpp"; # Post-processed genassym directives
132 my ($cfile, $genfile);
133 open($cfile, '>', $CTmp) || bail
("failed to create $CTmp: $!");
134 open($genfile, '>', $GenTmp) || bail
("failed to create $GenTmp: $!");
137 print STDERR
"Splitting from stdin to $CTmp and $GenTmp\n";
141 # #includes go to the C file. All other preprocessor directives
142 # go to both the C file and the offsets input file. Anything
143 # that's not a preprocessor directive goes into the offsets input
144 # file. Also strip comments from the genfile, as they can confuse
157 close($cfile) || bail
("can't close $CTmp: $!");
158 close($genfile) || bail
("can't close $GenTmp: $!");
160 # Compile the C file.
161 runit
($cc, @cflags, '-c', '-o', $OTmp, $CTmp);
163 # Convert the debugging information to CTF.
164 runit
($ctfconvert, '-l', 'ctfstabs', $OTmp);
166 # Run ctfstabs on the resulting mess.
167 runit
($cc, @cflags, "-P", "-o", "$GenPPTmp", $GenTmp);
168 runit
($ctfstabs, "-t", "genassym", "-i", $GenPPTmp, $OTmp);