xref: /netbsd-src/external/cddl/osnet/dist/tools/ctf/cvt/compare.c (revision a864dc36a152ff257761882aea174a236eb36c81)
1*a864dc36Sdarran /*
2*a864dc36Sdarran  * CDDL HEADER START
3*a864dc36Sdarran  *
4*a864dc36Sdarran  * The contents of this file are subject to the terms of the
5*a864dc36Sdarran  * Common Development and Distribution License, Version 1.0 only
6*a864dc36Sdarran  * (the "License").  You may not use this file except in compliance
7*a864dc36Sdarran  * with the License.
8*a864dc36Sdarran  *
9*a864dc36Sdarran  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*a864dc36Sdarran  * or http://www.opensolaris.org/os/licensing.
11*a864dc36Sdarran  * See the License for the specific language governing permissions
12*a864dc36Sdarran  * and limitations under the License.
13*a864dc36Sdarran  *
14*a864dc36Sdarran  * When distributing Covered Code, include this CDDL HEADER in each
15*a864dc36Sdarran  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*a864dc36Sdarran  * If applicable, add the following below this CDDL HEADER, with the
17*a864dc36Sdarran  * fields enclosed by brackets "[]" replaced with your own identifying
18*a864dc36Sdarran  * information: Portions Copyright [yyyy] [name of copyright owner]
19*a864dc36Sdarran  *
20*a864dc36Sdarran  * CDDL HEADER END
21*a864dc36Sdarran  */
22*a864dc36Sdarran /*
23*a864dc36Sdarran  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*a864dc36Sdarran  * Use is subject to license terms.
25*a864dc36Sdarran  */
26*a864dc36Sdarran 
27*a864dc36Sdarran #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*a864dc36Sdarran 
29*a864dc36Sdarran /*
30*a864dc36Sdarran  * This is a test program designed to catch mismerges and mistranslations from
31*a864dc36Sdarran  * stabs to CTF.
32*a864dc36Sdarran  *
33*a864dc36Sdarran  * Given a file with stabs data and a file with CTF data, determine whether
34*a864dc36Sdarran  * or not all of the data structures and objects described by the stabs data
35*a864dc36Sdarran  * are present in the CTF data.
36*a864dc36Sdarran  */
37*a864dc36Sdarran 
38*a864dc36Sdarran #include <stdio.h>
39*a864dc36Sdarran #include <stdlib.h>
40*a864dc36Sdarran #include <assert.h>
41*a864dc36Sdarran 
42*a864dc36Sdarran #include "ctftools.h"
43*a864dc36Sdarran 
44*a864dc36Sdarran char *progname;
45*a864dc36Sdarran int debug_level = DEBUG_LEVEL;
46*a864dc36Sdarran 
47*a864dc36Sdarran static void
usage(void)48*a864dc36Sdarran usage(void)
49*a864dc36Sdarran {
50*a864dc36Sdarran 	fprintf(stderr, "Usage: %s ctf_file stab_file\n", progname);
51*a864dc36Sdarran }
52*a864dc36Sdarran 
53*a864dc36Sdarran int
main(int argc,char ** argv)54*a864dc36Sdarran main(int argc, char **argv)
55*a864dc36Sdarran {
56*a864dc36Sdarran 	tdata_t *ctftd, *stabrtd, *stabtd, *difftd;
57*a864dc36Sdarran 	char *ctfname, *stabname;
58*a864dc36Sdarran 	int new;
59*a864dc36Sdarran 
60*a864dc36Sdarran 	progname = argv[0];
61*a864dc36Sdarran 
62*a864dc36Sdarran 	if (argc != 3) {
63*a864dc36Sdarran 		usage();
64*a864dc36Sdarran 		exit(2);
65*a864dc36Sdarran 	}
66*a864dc36Sdarran 
67*a864dc36Sdarran 	ctfname = argv[1];
68*a864dc36Sdarran 	stabname = argv[2];
69*a864dc36Sdarran 
70*a864dc36Sdarran 	stabrtd = tdata_new();
71*a864dc36Sdarran 	stabtd = tdata_new();
72*a864dc36Sdarran 	difftd = tdata_new();
73*a864dc36Sdarran 
74*a864dc36Sdarran 	if (read_stabs(stabrtd, stabname, 0) != 0)
75*a864dc36Sdarran 		merge_into_master(stabrtd, stabtd, NULL, 1);
76*a864dc36Sdarran 	else if (read_ctf(&stabname, 1, NULL, read_ctf_save_cb, &stabtd, 0)
77*a864dc36Sdarran 	    == 0)
78*a864dc36Sdarran 		terminate("%s doesn't have stabs or CTF\n", stabname);
79*a864dc36Sdarran 
80*a864dc36Sdarran 	if (read_ctf(&ctfname, 1, NULL, read_ctf_save_cb, &ctftd, 0) == 0)
81*a864dc36Sdarran 		terminate("%s doesn't contain CTF data\n", ctfname);
82*a864dc36Sdarran 
83*a864dc36Sdarran 	merge_into_master(stabtd, ctftd, difftd, 0);
84*a864dc36Sdarran 
85*a864dc36Sdarran 	if ((new = hash_count(difftd->td_iihash)) != 0) {
86*a864dc36Sdarran 		(void) hash_iter(difftd->td_iihash, (int (*)())iidesc_dump,
87*a864dc36Sdarran 		    NULL);
88*a864dc36Sdarran 		terminate("%s grew by %d\n", stabname, new);
89*a864dc36Sdarran 	}
90*a864dc36Sdarran 
91*a864dc36Sdarran 	return (0);
92*a864dc36Sdarran }
93