Commits

Wez Furlong  committed c2f14b3

Pull in the CTF sources from the FreeBSD 8.2 tree; arrange for them
to build under autoconf.

  • Participants

Comments (0)

Files changed (65)

+syntax: glob
+*.o
+*.lo
+*.la
+*.dylib
+autom4te.cache
+.libs
+.deps
+Makefile
+Makefile.in
+aclocal.m4
+compile
+config.guess
+config.log
+config.status
+config.sub
+configure
+depcomp
+pctf_config.h
+pctf_config.h.in
+pctf_config.h.in~
+install-sh
+libtool
+ltmain.sh
+missing
+stamp-h1
+.dirstamp
+ctfmerge
+ctfconvert
+ctfdump
+AUTOMAKE_OPTIONS = subdir-objects
+bin_PROGRAMS = ctfconvert ctfmerge ctfdump
+CFLAGS += -I$(top_srcdir)
+lib_LTLIBRARIES = libpctf.la
+noinst_LTLIBRARIES = libpctfcommon.la libcvt.la
+man1_MANS = man/ctfconvert.1 man/ctfmerge.1 man/ctfdump.1
+include_HEADERS = pctf/libctf.h pctf/ctf_api.h pctf/ctf.h
+
+libpctfcommon_la_SOURCES = \
+	common/list.c \
+	common/memory.c \
+	common/symbol.c \
+	common/utils.c
+
+libpctf_la_SOURCES = \
+	libctf/ctf_create.c \
+	libctf/ctf_decl.c \
+	libctf/ctf_error.c \
+	libctf/ctf_hash.c \
+	libctf/ctf_labels.c \
+	libctf/ctf_lib.c \
+	libctf/ctf_lookup.c \
+	libctf/ctf_open.c \
+	libctf/ctf_subr.c \
+	libctf/ctf_types.c \
+	libctf/ctf_util.c
+
+ctfdump_SOURCES = dump/dump.c
+ctfdump_LDADD = libpctfcommon.la
+
+libcvt_la_SOURCES = \
+	cvt/alist.c \
+	cvt/barrier.c \
+	cvt/compare.c \
+	cvt/ctf.c \
+	cvt/dwarf.c \
+	cvt/fifo.c \
+	cvt/fixup_tdescs.c \
+	cvt/hash.c \
+	cvt/iidesc.c \
+	cvt/input.c \
+	cvt/merge.c \
+	cvt/output.c \
+	cvt/st_parse.c \
+	cvt/stabs.c \
+	cvt/stack.c \
+	cvt/strtab.c \
+	cvt/tdata.c \
+	cvt/traverse.c \
+	cvt/util.c 
+
+ctfconvert_SOURCES = cvt/ctfconvert.c 
+ctfconvert_LDADD = libcvt.la libpctfcommon.la
+
+ctfmerge_SOURCES = cvt/ctfmerge.c 
+ctfmerge_LDADD = libcvt.la libpctfcommon.la
+
+

File OPENSOLARIS.LICENSE

+Unless otherwise noted, all files in this distribution are released
+under the Common Development and Distribution License (CDDL).
+Exceptions are noted within the associated source files.
+
+--------------------------------------------------------------------
+
+
+COMMON DEVELOPMENT AND DISTRIBUTION LICENSE Version 1.0
+
+1. Definitions.
+
+    1.1. "Contributor" means each individual or entity that creates
+         or contributes to the creation of Modifications.
+
+    1.2. "Contributor Version" means the combination of the Original
+         Software, prior Modifications used by a Contributor (if any),
+         and the Modifications made by that particular Contributor.
+
+    1.3. "Covered Software" means (a) the Original Software, or (b)
+         Modifications, or (c) the combination of files containing
+         Original Software with files containing Modifications, in
+         each case including portions thereof.
+
+    1.4. "Executable" means the Covered Software in any form other
+         than Source Code.
+
+    1.5. "Initial Developer" means the individual or entity that first
+         makes Original Software available under this License.
+
+    1.6. "Larger Work" means a work which combines Covered Software or
+         portions thereof with code not governed by the terms of this
+         License.
+
+    1.7. "License" means this document.
+
+    1.8. "Licensable" means having the right to grant, to the maximum
+         extent possible, whether at the time of the initial grant or
+         subsequently acquired, any and all of the rights conveyed
+         herein.
+
+    1.9. "Modifications" means the Source Code and Executable form of
+         any of the following:
+
+        A. Any file that results from an addition to, deletion from or
+           modification of the contents of a file containing Original
+           Software or previous Modifications;
+
+        B. Any new file that contains any part of the Original
+           Software or previous Modifications; or
+
+        C. Any new file that is contributed or otherwise made
+           available under the terms of this License.
+
+    1.10. "Original Software" means the Source Code and Executable
+          form of computer software code that is originally released
+          under this License.
+
+    1.11. "Patent Claims" means any patent claim(s), now owned or
+          hereafter acquired, including without limitation, method,
+          process, and apparatus claims, in any patent Licensable by
+          grantor.
+
+    1.12. "Source Code" means (a) the common form of computer software
+          code in which modifications are made and (b) associated
+          documentation included in or with such code.
+
+    1.13. "You" (or "Your") means an individual or a legal entity
+          exercising rights under, and complying with all of the terms
+          of, this License.  For legal entities, "You" includes any
+          entity which controls, is controlled by, or is under common
+          control with You.  For purposes of this definition,
+          "control" means (a) the power, direct or indirect, to cause
+          the direction or management of such entity, whether by
+          contract or otherwise, or (b) ownership of more than fifty
+          percent (50%) of the outstanding shares or beneficial
+          ownership of such entity.
+
+2. License Grants.
+
+    2.1. The Initial Developer Grant.
+
+    Conditioned upon Your compliance with Section 3.1 below and
+    subject to third party intellectual property claims, the Initial
+    Developer hereby grants You a world-wide, royalty-free,
+    non-exclusive license:
+
+        (a) under intellectual property rights (other than patent or
+            trademark) Licensable by Initial Developer, to use,
+            reproduce, modify, display, perform, sublicense and
+            distribute the Original Software (or portions thereof),
+            with or without Modifications, and/or as part of a Larger
+            Work; and
+
+        (b) under Patent Claims infringed by the making, using or
+            selling of Original Software, to make, have made, use,
+            practice, sell, and offer for sale, and/or otherwise
+            dispose of the Original Software (or portions thereof).
+
+        (c) The licenses granted in Sections 2.1(a) and (b) are
+            effective on the date Initial Developer first distributes
+            or otherwise makes the Original Software available to a
+            third party under the terms of this License.
+
+        (d) Notwithstanding Section 2.1(b) above, no patent license is
+            granted: (1) for code that You delete from the Original
+            Software, or (2) for infringements caused by: (i) the
+            modification of the Original Software, or (ii) the
+            combination of the Original Software with other software
+            or devices.
+
+    2.2. Contributor Grant.
+
+    Conditioned upon Your compliance with Section 3.1 below and
+    subject to third party intellectual property claims, each
+    Contributor hereby grants You a world-wide, royalty-free,
+    non-exclusive license:
+
+        (a) under intellectual property rights (other than patent or
+            trademark) Licensable by Contributor to use, reproduce,
+            modify, display, perform, sublicense and distribute the
+            Modifications created by such Contributor (or portions
+            thereof), either on an unmodified basis, with other
+            Modifications, as Covered Software and/or as part of a
+            Larger Work; and
+
+        (b) under Patent Claims infringed by the making, using, or
+            selling of Modifications made by that Contributor either
+            alone and/or in combination with its Contributor Version
+            (or portions of such combination), to make, use, sell,
+            offer for sale, have made, and/or otherwise dispose of:
+            (1) Modifications made by that Contributor (or portions
+            thereof); and (2) the combination of Modifications made by
+            that Contributor with its Contributor Version (or portions
+            of such combination).
+
+        (c) The licenses granted in Sections 2.2(a) and 2.2(b) are
+            effective on the date Contributor first distributes or
+            otherwise makes the Modifications available to a third
+            party.
+
+        (d) Notwithstanding Section 2.2(b) above, no patent license is
+            granted: (1) for any code that Contributor has deleted
+            from the Contributor Version; (2) for infringements caused
+            by: (i) third party modifications of Contributor Version,
+            or (ii) the combination of Modifications made by that
+            Contributor with other software (except as part of the
+            Contributor Version) or other devices; or (3) under Patent
+            Claims infringed by Covered Software in the absence of
+            Modifications made by that Contributor.
+
+3. Distribution Obligations.
+
+    3.1. Availability of Source Code.
+
+    Any Covered Software that You distribute or otherwise make
+    available in Executable form must also be made available in Source
+    Code form and that Source Code form must be distributed only under
+    the terms of this License.  You must include a copy of this
+    License with every copy of the Source Code form of the Covered
+    Software You distribute or otherwise make available.  You must
+    inform recipients of any such Covered Software in Executable form
+    as to how they can obtain such Covered Software in Source Code
+    form in a reasonable manner on or through a medium customarily
+    used for software exchange.
+
+    3.2. Modifications.
+
+    The Modifications that You create or to which You contribute are
+    governed by the terms of this License.  You represent that You
+    believe Your Modifications are Your original creation(s) and/or
+    You have sufficient rights to grant the rights conveyed by this
+    License.
+
+    3.3. Required Notices.
+
+    You must include a notice in each of Your Modifications that
+    identifies You as the Contributor of the Modification.  You may
+    not remove or alter any copyright, patent or trademark notices
+    contained within the Covered Software, or any notices of licensing
+    or any descriptive text giving attribution to any Contributor or
+    the Initial Developer.
+
+    3.4. Application of Additional Terms.
+
+    You may not offer or impose any terms on any Covered Software in
+    Source Code form that alters or restricts the applicable version
+    of this License or the recipients' rights hereunder.  You may
+    choose to offer, and to charge a fee for, warranty, support,
+    indemnity or liability obligations to one or more recipients of
+    Covered Software.  However, you may do so only on Your own behalf,
+    and not on behalf of the Initial Developer or any Contributor.
+    You must make it absolutely clear that any such warranty, support,
+    indemnity or liability obligation is offered by You alone, and You
+    hereby agree to indemnify the Initial Developer and every
+    Contributor for any liability incurred by the Initial Developer or
+    such Contributor as a result of warranty, support, indemnity or
+    liability terms You offer.
+
+    3.5. Distribution of Executable Versions.
+
+    You may distribute the Executable form of the Covered Software
+    under the terms of this License or under the terms of a license of
+    Your choice, which may contain terms different from this License,
+    provided that You are in compliance with the terms of this License
+    and that the license for the Executable form does not attempt to
+    limit or alter the recipient's rights in the Source Code form from
+    the rights set forth in this License.  If You distribute the
+    Covered Software in Executable form under a different license, You
+    must make it absolutely clear that any terms which differ from
+    this License are offered by You alone, not by the Initial
+    Developer or Contributor.  You hereby agree to indemnify the
+    Initial Developer and every Contributor for any liability incurred
+    by the Initial Developer or such Contributor as a result of any
+    such terms You offer.
+
+    3.6. Larger Works.
+
+    You may create a Larger Work by combining Covered Software with
+    other code not governed by the terms of this License and
+    distribute the Larger Work as a single product.  In such a case,
+    You must make sure the requirements of this License are fulfilled
+    for the Covered Software.
+
+4. Versions of the License.
+
+    4.1. New Versions.
+
+    Sun Microsystems, Inc. is the initial license steward and may
+    publish revised and/or new versions of this License from time to
+    time.  Each version will be given a distinguishing version number.
+    Except as provided in Section 4.3, no one other than the license
+    steward has the right to modify this License.
+
+    4.2. Effect of New Versions.
+
+    You may always continue to use, distribute or otherwise make the
+    Covered Software available under the terms of the version of the
+    License under which You originally received the Covered Software.
+    If the Initial Developer includes a notice in the Original
+    Software prohibiting it from being distributed or otherwise made
+    available under any subsequent version of the License, You must
+    distribute and make the Covered Software available under the terms
+    of the version of the License under which You originally received
+    the Covered Software.  Otherwise, You may also choose to use,
+    distribute or otherwise make the Covered Software available under
+    the terms of any subsequent version of the License published by
+    the license steward.
+
+    4.3. Modified Versions.
+
+    When You are an Initial Developer and You want to create a new
+    license for Your Original Software, You may create and use a
+    modified version of this License if You: (a) rename the license
+    and remove any references to the name of the license steward
+    (except to note that the license differs from this License); and
+    (b) otherwise make it clear that the license contains terms which
+    differ from this License.
+
+5. DISCLAIMER OF WARRANTY.
+
+    COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS"
+    BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
+    INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED
+    SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR
+    PURPOSE OR NON-INFRINGING.  THE ENTIRE RISK AS TO THE QUALITY AND
+    PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU.  SHOULD ANY
+    COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE
+    INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY
+    NECESSARY SERVICING, REPAIR OR CORRECTION.  THIS DISCLAIMER OF
+    WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.  NO USE OF
+    ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS
+    DISCLAIMER.
+
+6. TERMINATION.
+
+    6.1. This License and the rights granted hereunder will terminate
+    automatically if You fail to comply with terms herein and fail to
+    cure such breach within 30 days of becoming aware of the breach.
+    Provisions which, by their nature, must remain in effect beyond
+    the termination of this License shall survive.
+
+    6.2. If You assert a patent infringement claim (excluding
+    declaratory judgment actions) against Initial Developer or a
+    Contributor (the Initial Developer or Contributor against whom You
+    assert such claim is referred to as "Participant") alleging that
+    the Participant Software (meaning the Contributor Version where
+    the Participant is a Contributor or the Original Software where
+    the Participant is the Initial Developer) directly or indirectly
+    infringes any patent, then any and all rights granted directly or
+    indirectly to You by such Participant, the Initial Developer (if
+    the Initial Developer is not the Participant) and all Contributors
+    under Sections 2.1 and/or 2.2 of this License shall, upon 60 days
+    notice from Participant terminate prospectively and automatically
+    at the expiration of such 60 day notice period, unless if within
+    such 60 day period You withdraw Your claim with respect to the
+    Participant Software against such Participant either unilaterally
+    or pursuant to a written agreement with Participant.
+
+    6.3. In the event of termination under Sections 6.1 or 6.2 above,
+    all end user licenses that have been validly granted by You or any
+    distributor hereunder prior to termination (excluding licenses
+    granted to You by any distributor) shall survive termination.
+
+7. LIMITATION OF LIABILITY.
+
+    UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
+    (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE
+    INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF
+    COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE
+    LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+    CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT
+    LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK
+    STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
+    COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
+    INFORMED OF THE POSSIBILITY OF SUCH DAMAGES.  THIS LIMITATION OF
+    LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL
+    INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT
+    APPLICABLE LAW PROHIBITS SUCH LIMITATION.  SOME JURISDICTIONS DO
+    NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR
+    CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT
+    APPLY TO YOU.
+
+8. U.S. GOVERNMENT END USERS.
+
+    The Covered Software is a "commercial item," as that term is
+    defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial
+    computer software" (as that term is defined at 48
+    C.F.R. 252.227-7014(a)(1)) and "commercial computer software
+    documentation" as such terms are used in 48 C.F.R. 12.212
+    (Sept. 1995).  Consistent with 48 C.F.R. 12.212 and 48
+    C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all
+    U.S. Government End Users acquire Covered Software with only those
+    rights set forth herein.  This U.S. Government Rights clause is in
+    lieu of, and supersedes, any other FAR, DFAR, or other clause or
+    provision that addresses Government rights in computer software
+    under this License.
+
+9. MISCELLANEOUS.
+
+    This License represents the complete agreement concerning subject
+    matter hereof.  If any provision of this License is held to be
+    unenforceable, such provision shall be reformed only to the extent
+    necessary to make it enforceable.  This License shall be governed
+    by the law of the jurisdiction specified in a notice contained
+    within the Original Software (except to the extent applicable law,
+    if any, provides otherwise), excluding such jurisdiction's
+    conflict-of-law provisions.  Any litigation relating to this
+    License shall be subject to the jurisdiction of the courts located
+    in the jurisdiction and venue specified in a notice contained
+    within the Original Software, with the losing party responsible
+    for costs, including, without limitation, court costs and
+    reasonable attorneys' fees and expenses.  The application of the
+    United Nations Convention on Contracts for the International Sale
+    of Goods is expressly excluded.  Any law or regulation which
+    provides that the language of a contract shall be construed
+    against the drafter shall not apply to this License.  You agree
+    that You alone are responsible for compliance with the United
+    States export administration regulations (and the export control
+    laws and regulation of any other countries) when You use,
+    distribute or otherwise make available any Covered Software.
+
+10. RESPONSIBILITY FOR CLAIMS.
+
+    As between Initial Developer and the Contributors, each party is
+    responsible for claims and damages arising, directly or
+    indirectly, out of its utilization of rights under this License
+    and You agree to work with Initial Developer and Contributors to
+    distribute such responsibility on an equitable basis.  Nothing
+    herein is intended or shall be deemed to constitute any admission
+    of liability.
+
+--------------------------------------------------------------------
+
+NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND
+DISTRIBUTION LICENSE (CDDL)
+
+For Covered Software in this distribution, this License shall
+be governed by the laws of the State of California (excluding
+conflict-of-law provisions).
+
+Any litigation relating to this License shall be subject to the
+jurisdiction of the Federal Courts of the Northern District of
+California and the state courts of the State of California, with
+venue lying in Santa Clara County, California.
+Portable CTF
+------------
+
+This distribution contains the Compact ANSI-C Type Format source code,
+re-arranged for portability and re-use.
+
+It does not use the system CTF facilities, as those are explicitly labelled
+as unstable and subject to change.
+
+Instead, it provides those same APIs as supported functions, but these are
+namespaced as pctf (header file and library name; function names are unchanged).
+
+#!/bin/sh -x
+# vim:ts=2:sw=2:et:
+
+if test `uname` = "Darwin" ; then
+  glibtoolize --automake
+else
+  libtoolize --automake
+fi
+autoheader
+aclocal 
+automake --add-missing --foreign
+autoconf
+

File common/ctf_headers.h

+/*
+ * 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 2003 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _CTF_HEADERS_H
+#define	_CTF_HEADERS_H
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+/*
+ * Because the ON tools are executed on the system where they are built,
+ * the tools need to include the headers installed on the build system,
+ * rather than those in the ON source tree. However, some of the headers
+ * required by the tools are part of the ON source tree, but not delivered
+ * as part of Solaris.  These include the following:
+ *
+ * $(SRC)/lib/libctf/common/libctf.h
+ * $(SRC)/uts/common/sys/ctf_api.h
+ * $(SRC)/uts/common/sys/ctf.h
+ *
+ * These headers get installed in the proto area in the build environment
+ * under $(ROOT)/usr/include and $(ROOT)/usr/include/sys. Though these
+ * headers are not part of the release, in releases including and prior to
+ * Solaris 9, they did get installed on the build system via bfu. Therefore,
+ * we can not simply force the order of inclusion with -I/usr/include first
+ * in Makefile.ctf because we might actually get downlevel versions of the
+ * ctf headers. Depending on the order of the -I includes, we can also have
+ * a problem with mismatched headers when building the ctf tools with some
+ * headers getting pulled in from /usr/include and others from
+ * $(SRC)/uts/common/sys.
+ *
+ * To address the problem, we have done two things:
+ * 1) Created this header with a specific order of inclusion for the
+ *    ctf headers.  Because the <libctf.h> header includes <sys/ctf_api.h>
+ *    which in turn includes <sys/ctf.h> we need to include these in
+ *    reverse order to guarantee that we get the correct versions of
+ *    the headers.
+ * 2) In $(SRC)/tools/ctf/Makefile.ctf, we order the -I includes such
+ *    that we first search the directories where the ctf headers
+ *    live, followed by /usr/include, followed by $(SRC)/uts/common.
+ *    This last -I include is needed in order to prevent a build failure
+ *    when <sys/ctf_api.h> is included via a nested #include rather than
+ *    an explicit path #include.
+ */
+
+#include <uts/common/sys/ctf.h>
+#include <uts/common/sys/ctf_api.h>
+#include <lib/libctf/common/libctf.h>
+
+#endif /* _CTF_HEADERS_H */

File common/list.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 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+/*
+ * Routines for manipulating linked lists
+ */
+
+#include <stdio.h>
+#include <assert.h>
+#include <stdlib.h>
+
+#include "list.h"
+#include "memory.h"
+
+struct list {
+	void *l_data;
+	struct list *l_next;
+};
+
+/* Add an element to a list */
+void
+list_add(list_t **list, void *data)
+{
+	list_t *le;
+
+	le = xmalloc(sizeof (list_t));
+	le->l_data = data;
+	le->l_next = *list;
+	*list = le;
+}
+
+/* Add an element to a sorted list */
+void
+slist_add(list_t **list, void *data, int (*cmp)(void *, void *))
+{
+	list_t **nextp;
+
+	for (nextp = list; *nextp; nextp = &((*nextp)->l_next)) {
+		if (cmp((*nextp)->l_data, data) > 0)
+			break;
+	}
+
+	list_add(nextp, data);
+}
+
+/*ARGSUSED2*/
+static int
+list_defcmp(void *d1, void *d2, void *private __unused)
+{
+	return (d1 != d2);
+}
+
+void *
+list_remove(list_t **list, void *data, int (*cmp)(void *, void *, void *),
+    void *private)
+{
+	list_t *le, **le2;
+	void *led;
+
+	if (!cmp)
+		cmp = list_defcmp;
+
+	for (le = *list, le2 = list; le; le2 = &le->l_next, le = le->l_next) {
+		if (cmp(le->l_data, data, private) == 0) {
+			*le2 = le->l_next;
+			led = le->l_data;
+			free(le);
+			return (led);
+		}
+	}
+
+	return (NULL);
+}
+
+void
+list_free(list_t *list, void (*datafree)(void *, void *), void *private)
+{
+	list_t *le;
+
+	while (list) {
+		le = list;
+		list = list->l_next;
+		if (le->l_data && datafree)
+			datafree(le->l_data, private);
+		free(le);
+	}
+}
+
+/*
+ * This iterator is specifically designed to tolerate the deletion of the
+ * node being iterated over.
+ */
+int
+list_iter(list_t *list, int (*func)(void *, void *), void *private)
+{
+	list_t *lnext;
+	int cumrc = 0;
+	int cbrc;
+
+	while (list) {
+		lnext = list->l_next;
+		if ((cbrc = func(list->l_data, private)) < 0)
+			return (cbrc);
+		cumrc += cbrc;
+		list = lnext;
+	}
+
+	return (cumrc);
+}
+
+/*ARGSUSED*/
+static int
+list_count_cb(void *data __unused, void *private __unused)
+{
+	return (1);
+}
+
+int
+list_count(list_t *list)
+{
+	return (list_iter(list, list_count_cb, NULL));
+}
+
+int
+list_empty(list_t *list)
+{
+	return (list == NULL);
+}
+
+void *
+list_find(list_t *list, void *tmpl, int (*cmp)(void *, void *))
+{
+	for (; list; list = list->l_next) {
+		if (cmp(list->l_data, tmpl) == 0)
+			return (list->l_data);
+	}
+
+	return (NULL);
+}
+
+void *
+list_first(list_t *list)
+{
+	return (list ? list->l_data : NULL);
+}
+
+void
+list_concat(list_t **list1, list_t *list2)
+{
+	list_t *l, *last;
+
+	for (l = *list1, last = NULL; l; last = l, l = l->l_next)
+		continue;
+
+	if (last == NULL)
+		*list1 = list2;
+	else
+		last->l_next = list2;
+}
+
+/*
+ * Merges two sorted lists.  Equal nodes (as determined by cmp) are retained.
+ */
+void
+slist_merge(list_t **list1p, list_t *list2, int (*cmp)(void *, void *))
+{
+	list_t *list1, *next2;
+	list_t *last1 = NULL;
+
+	if (*list1p == NULL) {
+		*list1p = list2;
+		return;
+	}
+
+	list1 = *list1p;
+	while (list2 != NULL) {
+		if (cmp(list1->l_data, list2->l_data) > 0) {
+			next2 = list2->l_next;
+
+			if (last1 == NULL) {
+				/* Insert at beginning */
+				*list1p = last1 = list2;
+				list2->l_next = list1;
+			} else {
+				list2->l_next = list1;
+				last1->l_next = list2;
+				last1 = list2;
+			}
+
+			list2 = next2;
+		} else {
+
+			last1 = list1;
+			list1 = list1->l_next;
+
+			if (list1 == NULL) {
+				/* Add the rest to the end of list1 */
+				last1->l_next = list2;
+				list2 = NULL;
+			}
+		}
+	}
+}

File common/list.h

+/*
+ * 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 2001-2002 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _LIST_H
+#define	_LIST_H
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+/*
+ * Routines for manipulating linked lists
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct list list_t;
+
+void list_add(list_t **, void *);
+void slist_add(list_t **, void *, int (*)(void *, void *));
+void *list_remove(list_t **, void *, int (*)(void *, void *, void *), void *);
+void list_free(list_t *, void (*)(void *, void *), void *);
+void *list_find(list_t *, void *, int (*)(void *, void *));
+void *list_first(list_t *);
+int list_iter(list_t *, int (*)(void *, void *), void *);
+int list_count(list_t *);
+int list_empty(list_t *);
+void list_concat(list_t **, list_t *);
+void slist_merge(list_t **, list_t *, int (*)(void *, void *));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LIST_H */

File common/memory.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 2001-2002 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+/*
+ * Routines for memory management
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "memory.h"
+
+static void
+memory_bailout(void)
+{
+	(void) fprintf(stderr, "Out of memory\n");
+	exit(1);
+}
+
+void *
+xmalloc(size_t size)
+{
+	void *mem;
+
+	if ((mem = malloc(size)) == NULL)
+		memory_bailout();
+
+	return (mem);
+}
+
+void *
+xcalloc(size_t size)
+{
+	void *mem;
+
+	mem = xmalloc(size);
+	bzero(mem, size);
+
+	return (mem);
+}
+
+char *
+xstrdup(const char *str)
+{
+	char *newstr;
+
+	if ((newstr = strdup(str)) == NULL)
+		memory_bailout();
+
+	return (newstr);
+}
+
+char *
+xstrndup(char *str, size_t len)
+{
+	char *newstr;
+
+	if ((newstr = malloc(len + 1)) == NULL)
+		memory_bailout();
+
+	(void) strncpy(newstr, str, len);
+	newstr[len] = '\0';
+
+	return (newstr);
+}
+
+void *
+xrealloc(void *ptr, size_t size)
+{
+	void *mem;
+
+	if ((mem = realloc(ptr, size)) == NULL)
+		memory_bailout();
+
+	return (mem);
+}

File common/memory.h

+/*
+ * 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 2001-2002 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _MEMORY_H
+#define	_MEMORY_H
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+/*
+ * Routines for memory management
+ */
+
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void *xmalloc(size_t);
+void *xcalloc(size_t);
+char *xstrdup(const char *);
+char *xstrndup(char *, size_t);
+void *xrealloc(void *, size_t);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MEMORY_H */

File common/symbol.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.
+ */
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+#include "libctf/ctf_impl.h"
+
+#include "symbol.h"
+
+int
+ignore_symbol(GElf_Sym *sym, const char *name)
+{
+	uchar_t type = GELF_ST_TYPE(sym->st_info);
+
+	/*
+	 * As an optimization, we do not output function or data object
+	 * records for undefined or anonymous symbols.
+	 */
+	if (sym->st_shndx == SHN_UNDEF || sym->st_name == 0)
+		return (1);
+
+	/*
+	 * _START_ and _END_ are added to the symbol table by the
+	 * linker, and will never have associated type information.
+	 */
+	if (strcmp(name, "_START_") == 0 || strcmp(name, "_END_") == 0)
+		return (1);
+
+	/*
+	 * Do not output records for absolute-valued object symbols
+	 * that have value zero.  The compiler insists on generating
+	 * things like this for __fsr_init_value settings, etc.
+	 */
+	if (type == STT_OBJECT && sym->st_shndx == SHN_ABS &&
+	    sym->st_value == 0)
+		return (1);
+	return (0);
+}

File common/symbol.h

+/*
+ * 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 _SYMBOL_H
+#define	_SYMBOL_H
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+#include <gelf.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int ignore_symbol(GElf_Sym *sym, const char *name);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SYMBOL_H */

File common/utils.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 (c) 1998-2001 by Sun Microsystems, Inc.
+ * All rights reserved.
+ */
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+#include "libctf/ctf_impl.h"
+#include "common/utils.h"
+
+/*LINTLIBRARY*/
+
+static const char *pname;
+
+#pragma init(getpname)
+const char *
+getpname(void)
+{
+	const char *p, *q;
+
+	if (pname != NULL)
+		return (pname);
+
+#if HAVE_GETEXECNAME
+	p = getexecname();
+#elif HAVE_GETPROGNAME
+	p = getprogname();
+#else
+# error dont know how to find my executable name
+#endif
+
+	if (p != NULL)
+		q = strrchr(p, '/');
+	else
+		q = NULL;
+
+	if (q == NULL)
+		pname = p;
+	else
+		pname = q + 1;
+
+	return (pname);
+}
+
+void
+vwarn(const char *format, va_list alist)
+{
+	int err = errno;
+
+	if (pname != NULL)
+		(void) fprintf(stderr, "%s: ", pname);
+
+	(void) vfprintf(stderr, format, alist);
+
+	if (strchr(format, '\n') == NULL)
+		(void) fprintf(stderr, ": %s\n", strerror(err));
+}
+
+/*PRINTFLIKE1*/
+void
+warn(const char *format, ...)
+{
+	va_list alist;
+
+	va_start(alist, format);
+	vwarn(format, alist);
+	va_end(alist);
+}
+
+void
+vdie(const char *format, va_list alist)
+{
+	vwarn(format, alist);
+	exit(E_ERROR);
+}
+
+/*PRINTFLIKE1*/
+void
+die(const char *format, ...)
+{
+	va_list alist;
+
+	va_start(alist, format);
+	vdie(format, alist);
+	va_end(alist);
+}

File common/utils.h

+/*
+ * 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.
+ */
+
+#ifndef	_UTILS_H
+#define	_UTILS_H
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+#include <stdarg.h>
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+#define	E_SUCCESS	0		/* Exit status for success */
+#define	E_ERROR		1		/* Exit status for error */
+#define	E_USAGE		2		/* Exit status for usage error */
+
+extern void vwarn(const char *, va_list);
+extern void warn(const char *, ...);
+extern void vdie(const char  *, va_list);
+extern void die(const char *, ...);
+
+extern const char *getpname(void);
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* _UTILS_H */

File configure.ac

+# vim:ts=2:sw=2:et:
+AC_INIT(pctf,1.1,,pctf)
+AM_INIT_AUTOMAKE([foreign])
+AC_PROG_CC
+AM_PROG_CC_C_O
+AC_C_INLINE
+AC_C_BIGENDIAN
+AC_PROG_LIBTOOL
+
+AC_CHECK_SIZEOF(void*)
+
+AC_CHECK_TYPE(ulong_t, unsigned long)
+AC_CHECK_TYPE(u_longlong_t, unsigned long long)
+AC_CHECK_TYPE(ushort_t, unsigned short)
+AC_CHECK_TYPE(uint_t, unsigned int)
+AC_CHECK_TYPE(off64_t, off_t)
+AC_CHECK_TYPE(uchar_t, unsigned char)
+
+AC_CHECK_FUNCS([ \
+getexecname \
+getprogname \
+])
+
+AC_CHECK_LIB(z, uncompress)
+AC_CHECK_LIB(elf, gelf_getshdr)
+AC_CHECK_LIB(dwarf, dwarf_elf_init)
+AC_CHECK_LIB(pthread, pthread_create)
+
+AC_CHECK_HEADERS([ \
+ctype.h \
+dwarf.h \
+errno.h \
+fcntl.h \
+gelf.h \
+libdwarf.h \
+libelf.h \
+libgen.h \
+limits.h \
+pthread.h \
+stdint.h \
+string.h \
+strings.h \
+sys/elf.h \
+sys/errno.h \
+sys/mman.h \
+sys/stat.h \
+sys/sysmacros.h \
+unistd.h \
+zlib.h \
+])
+
+AC_CONFIG_HEADERS(pctf_config.h)
+AC_CONFIG_FILES(Makefile)
+AC_OUTPUT
+
+/*
+ * 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 2001-2003 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+/*
+ * Create, manage, and destroy association lists.  alists are arrays with
+ * arbitrary index types, and are also commonly known as associative arrays.
+ */
+
+#include "libctf/ctf_impl.h"
+
+#include "alist.h"
+#include "memory.h"
+#include "hash.h"
+
+#define	ALIST_HASH_SIZE	997
+
+struct alist {
+	hash_t *al_elements;
+	void (*al_namefree)(void *);
+	void (*al_valfree)(void *);
+};
+
+typedef struct alist_el {
+	void *ale_name;
+	void *ale_value;
+} alist_el_t;
+
+static int
+alist_hash(int nbuckets, void *arg)
+{
+	alist_el_t *el = arg;
+	uintptr_t num = (uintptr_t)el->ale_name;
+
+	return (num % nbuckets);
+}
+
+static int
+alist_cmp(void *arg1, void *arg2)
+{
+	alist_el_t *el1 = arg1;
+	alist_el_t *el2 = arg2;
+	return ((uintptr_t)el1->ale_name != (uintptr_t)el2->ale_name);
+}
+
+alist_t *
+alist_xnew(int nbuckets, void (*namefree)(void *),
+    void (*valfree)(void *), int (*hashfn)(int, void *),
+    int (*cmpfn)(void *, void *))
+{
+	alist_t *alist;
+
+	alist = xcalloc(sizeof (alist_t));
+	alist->al_elements = hash_new(nbuckets, hashfn, cmpfn);
+	alist->al_namefree = namefree;
+	alist->al_valfree = valfree;
+
+	return (alist);
+}
+
+alist_t *
+alist_new(void (*namefree)(void *), void (*valfree)(void *))
+{
+	return (alist_xnew(ALIST_HASH_SIZE, namefree, valfree,
+	    alist_hash, alist_cmp));
+}
+
+static void
+alist_free_cb(void *arg1, void *arg2)
+{
+	alist_el_t *el = arg1;
+	alist_t *alist = arg2;
+	if (alist->al_namefree)
+		alist->al_namefree(el->ale_name);
+	if (alist->al_valfree)
+		alist->al_valfree(el->ale_name);
+	free(el);
+}
+
+void
+alist_free(alist_t *alist)
+{
+	hash_free(alist->al_elements, alist_free_cb, alist);
+	free(alist);
+}
+
+void
+alist_add(alist_t *alist, void *name, void *value)
+{
+	alist_el_t *el;
+
+	el = xmalloc(sizeof (alist_el_t));
+	el->ale_name = name;
+	el->ale_value = value;
+	hash_add(alist->al_elements, el);
+}
+
+int
+alist_find(alist_t *alist, void *name, void **value)
+{
+	alist_el_t template, *retx;
+	void *ret;
+
+	template.ale_name = name;
+	if (!hash_find(alist->al_elements, &template, &ret))
+		return (0);
+
+	if (value) {
+		retx = ret;
+		*value = retx->ale_value;
+	}
+
+	return (1);
+}
+
+typedef struct alist_iter_data {
+	int (*aid_func)(void *, void *, void *);
+	void *aid_priv;
+} alist_iter_data_t;
+
+static int
+alist_iter_cb(void *arg1, void *arg2)
+{
+	alist_el_t *el = arg1;
+	alist_iter_data_t *aid = arg2;
+	return (aid->aid_func(el->ale_name, el->ale_value, aid->aid_priv));
+}
+
+int
+alist_iter(alist_t *alist, int (*func)(void *, void *, void *), void *private)
+{
+	alist_iter_data_t aid;
+
+	aid.aid_func = func;
+	aid.aid_priv = private;
+
+	return (hash_iter(alist->al_elements, alist_iter_cb, &aid));
+}
+
+/*
+ * Debugging support.  Used to print the contents of an alist.
+ */
+
+void
+alist_stats(alist_t *alist, int verbose)
+{
+	printf("Alist statistics\n");
+	hash_stats(alist->al_elements, verbose);
+}
+
+static int alist_def_print_cb_key_int = 1;
+static int alist_def_print_cb_value_int = 1;
+
+static int
+alist_def_print_cb(void *key, void *value)
+{
+	printf("Key: ");
+	if (alist_def_print_cb_key_int == 1)
+		printf("%5lu ", (ulong_t)key);
+	else
+		printf("%s\n", (char *)key);
+
+	printf("Value: ");
+	if (alist_def_print_cb_value_int == 1)
+		printf("%5lu\n", (ulong_t)value);
+	else
+		printf("%s\n", (char *)key);
+
+	return (1);
+}
+
+static int
+alist_dump_cb(void *node, void *private)
+{
+	int (*printer)(void *, void *) = private;
+	alist_el_t *el = node;
+
+	printer(el->ale_name, el->ale_value);
+
+	return (1);
+}
+
+int
+alist_dump(alist_t *alist, int (*printer)(void *, void *))
+{
+	if (!printer)
+		printer = alist_def_print_cb;
+
+	return (hash_iter(alist->al_elements, alist_dump_cb, (void *)printer));
+}
+/*
+ * 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 2001-2003 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _ASSOC_H
+#define	_ASSOC_H
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+/*
+ * Create, manage, and destroy association lists.  alists are arrays with
+ * arbitrary index types.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct alist alist_t;
+
+alist_t *alist_new(void (*)(void *), void (*)(void *));
+alist_t *alist_xnew(int, void (*)(void *), void (*)(void *),
+    int (*)(int, void *), int (*)(void *, void *));
+void alist_free(alist_t *);
+void alist_add(alist_t *, void *, void *);
+int alist_find(alist_t *, void *, void **);
+int alist_iter(alist_t *, int (*)(void *, void *, void *), void *);
+void alist_stats(alist_t *, int);
+int alist_dump(alist_t *, int (*)(void *, void *));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ASSOC_H */

File cvt/barrier.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 2002 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+#include "libctf/ctf_impl.h"
+
+/*
+ * This file implements a barrier, a synchronization primitive designed to allow
+ * threads to wait for each other at given points.  Barriers are initialized
+ * with a given number of threads, n, using barrier_init().  When a thread calls
+ * barrier_wait(), that thread blocks until n - 1 other threads reach the
+ * barrier_wait() call using the same barrier_t.  When n threads have reached
+ * the barrier, they are all awakened and sent on their way.  One of the threads
+ * returns from barrier_wait() with a return code of 1; the remaining threads
+ * get a return code of 0.
+ */
+
+#include <pthread.h>
+#if defined(sun)
+#include <synch.h>
+#endif
+#include <stdio.h>
+
+#include "barrier.h"
+
+void
+barrier_init(barrier_t *bar, int nthreads)
+{
+	pthread_mutex_init(&bar->bar_lock, NULL);
+#if defined(sun)
+	sema_init(&bar->bar_sem, 0, USYNC_THREAD, NULL);
+#else
+	sem_init(&bar->bar_sem, 0, 0);
+#endif
+
+	bar->bar_numin = 0;
+	bar->bar_nthr = nthreads;
+}
+
+int
+barrier_wait(barrier_t *bar)
+{
+	pthread_mutex_lock(&bar->bar_lock);
+
+	if (++bar->bar_numin < bar->bar_nthr) {
+		pthread_mutex_unlock(&bar->bar_lock);
+#if defined(sun)
+		sema_wait(&bar->bar_sem);
+#else
+		sem_wait(&bar->bar_sem);
+#endif
+
+		return (0);
+
+	} else {
+		int i;
+
+		/* reset for next use */
+		bar->bar_numin = 0;
+		for (i = 1; i < bar->bar_nthr; i++)
+#if defined(sun)
+			sema_post(&bar->bar_sem);
+#else
+			sem_post(&bar->bar_sem);
+#endif
+		pthread_mutex_unlock(&bar->bar_lock);
+
+		return (1);
+	}
+}

File cvt/barrier.h

+/*
+ * 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 2002 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _BARRIER_H
+#define	_BARRIER_H
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+/*
+ * APIs for the barrier synchronization primitive.
+ */
+
+#if defined(sun)
+#include <synch.h>
+#else
+#include <semaphore.h>
+typedef sem_t	sema_t;
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct barrier {
+	pthread_mutex_t bar_lock;	/* protects bar_numin */
+	int bar_numin;			/* current number of waiters */
+
+	sema_t bar_sem;			/* where everyone waits */
+	int bar_nthr;			/* # of waiters to trigger release */
+} barrier_t;
+
+extern void barrier_init(barrier_t *, int);
+extern int barrier_wait(barrier_t *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _BARRIER_H */

File cvt/compare.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.
+ */
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+/*
+ * This is a test program designed to catch mismerges and mistranslations from
+ * stabs to CTF.
+ *
+ * Given a file with stabs data and a file with CTF data, determine whether
+ * or not all of the data structures and objects described by the stabs data
+ * are present in the CTF data.
+ */
+
+#include "libctf/ctf_impl.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "ctftools.h"
+
+const char *progname;
+int debug_level = DEBUG_LEVEL;
+
+static void
+usage(void)
+{
+	fprintf(stderr, "Usage: %s ctf_file stab_file\n", progname);
+}
+
+int
+main(int argc, char **argv)
+{
+	tdata_t *ctftd, *stabrtd, *stabtd, *difftd;
+	char *ctfname, *stabname;
+	int new;
+
+	progname = argv[0];
+
+	if (argc != 3) {
+		usage();
+		exit(2);
+	}
+
+	ctfname = argv[1];
+	stabname = argv[2];
+
+	stabrtd = tdata_new();
+	stabtd = tdata_new();
+	difftd = tdata_new();
+
+	if (read_stabs(stabrtd, stabname, 0) != 0)
+		merge_into_master(stabrtd, stabtd, NULL, 1);
+	else if (read_ctf(&stabname, 1, NULL, read_ctf_save_cb, &stabtd, 0)
+	    == 0)
+		terminate("%s doesn't have stabs or CTF\n", stabname);
+
+	if (read_ctf(&ctfname, 1, NULL, read_ctf_save_cb, &ctftd, 0) == 0)
+		terminate("%s doesn't contain CTF data\n", ctfname);
+
+	merge_into_master(stabtd, ctftd, difftd, 0);
+
+	if ((new = hash_count(difftd->td_iihash)) != 0) {
+		(void) hash_iter(difftd->td_iihash, (int (*)())iidesc_dump,
+		    NULL);
+		terminate("%s grew by %d\n", stabname, new);
+	}
+
+	return (0);
+}
+/*
+ * 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 2009 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * Create and parse buffers containing CTF data.
+ */
+
+#include "libctf/ctf_impl.h"
+#include "ctftools.h"
+#include "strtab.h"
+#include "memory.h"
+
+/*
+ * Name of the file currently being read, used to print error messages.  We
+ * assume that only one file will be read at a time, and thus make no attempt
+ * to allow curfile to be used simultaneously by multiple threads.
+ *
+ * The value is only valid during a call to ctf_load.
+ */
+char *curfile;
+
+#define	CTF_BUF_CHUNK_SIZE	(64 * 1024)
+#define	RES_BUF_CHUNK_SIZE	(64 * 1024)
+
+struct ctf_buf {
+	strtab_t ctb_strtab;	/* string table */
+	caddr_t ctb_base;	/* pointer to base of buffer */
+	caddr_t ctb_end;	/* pointer to end of buffer */
+	caddr_t ctb_ptr;	/* pointer to empty buffer space */
+	size_t ctb_size;	/* size of buffer */
+	int nptent;		/* number of processed types */
+	int ntholes;		/* number of type holes */
+};
+
+/*PRINTFLIKE1*/
+static void
+parseterminate(const char *fmt, ...)
+{
+	static char msgbuf[1024]; /* sigh */
+	va_list ap;
+
+	va_start(ap, fmt);
+	vsnprintf(msgbuf, sizeof (msgbuf), fmt, ap);
+	va_end(ap);
+
+	terminate("%s: %s\n", curfile, msgbuf);
+}
+
+static void
+ctf_buf_grow(ctf_buf_t *b)
+{
+	off_t ptroff = b->ctb_ptr - b->ctb_base;
+
+	b->ctb_size += CTF_BUF_CHUNK_SIZE;
+	b->ctb_base = xrealloc(b->ctb_base, b->ctb_size);
+	b->ctb_end = b->ctb_base + b->ctb_size;
+	b->ctb_ptr = b->ctb_base + ptroff;
+}
+
+static ctf_buf_t *
+ctf_buf_new(void)
+{
+	ctf_buf_t *b = xcalloc(sizeof (ctf_buf_t));
+
+	strtab_create(&b->ctb_strtab);
+	ctf_buf_grow(b);
+
+	return (b);
+}
+
+static void
+ctf_buf_free(ctf_buf_t *b)
+{
+	strtab_destroy(&b->ctb_strtab);
+	free(b->ctb_base);
+	free(b);
+}
+
+static uint_t
+ctf_buf_cur(ctf_buf_t *b)
+{
+	return (b->ctb_ptr - b->ctb_base);
+}
+
+static void
+ctf_buf_write(ctf_buf_t *b, void const *p, size_t n)
+{
+	size_t len;
+
+	while (n != 0) {
+		if (b->ctb_ptr == b->ctb_end)
+			ctf_buf_grow(b);
+
+		len = MIN((size_t)(b->ctb_end - b->ctb_ptr), n);
+		bcopy(p, b->ctb_ptr, len);
+		b->ctb_ptr += len;
+
+		p = (char const *)p + len;
+		n -= len;
+	}
+}
+
+static int
+write_label(void *arg1, void *arg2)
+{
+	labelent_t *le = arg1;
+	ctf_buf_t *b = arg2;
+	ctf_lblent_t ctl;
+
+	ctl.ctl_label = strtab_insert(&b->ctb_strtab, le->le_name);
+	ctl.ctl_typeidx = le->le_idx;
+
+	ctf_buf_write(b, &ctl, sizeof (ctl));
+
+	return (1);
+}
+
+static void
+write_objects(iidesc_t *idp, ctf_buf_t *b)
+{
+	ushort_t id = (idp ? idp->ii_dtype->t_id : 0);
+
+	ctf_buf_write(b, &id, sizeof (id));
+
+	debug(3, "Wrote object %s (%d)\n", (idp ? idp->ii_name : "(null)"), id);
+}
+
+static void
+write_functions(iidesc_t *idp, ctf_buf_t *b)
+{
+	ushort_t fdata[2];
+	ushort_t id;
+	int nargs;
+	int i;
+
+	if (!idp) {
+		fdata[0] = 0;
+		ctf_buf_write(b, &fdata[0], sizeof (fdata[0]));
+
+		debug(3, "Wrote function (null)\n");
+		return;
+	}
+
+	nargs = idp->ii_nargs + (idp->ii_vargs != 0);
+
+	if (nargs > CTF_MAX_VLEN) {
+		terminate("function %s has too many args: %d > %d\n",
+		    idp->ii_name, nargs, CTF_MAX_VLEN);
+	}
+
+	fdata[0] = CTF_TYPE_INFO(CTF_K_FUNCTION, 1, nargs);
+	fdata[1] = idp->ii_dtype->t_id;
+	ctf_buf_write(b, fdata, sizeof (fdata));
+
+	for (i = 0; i < idp->ii_nargs; i++) {
+		id = idp->ii_args[i]->t_id;
+		ctf_buf_write(b, &id, sizeof (id));
+	}
+
+	if (idp->ii_vargs) {
+		id = 0;
+		ctf_buf_write(b, &id, sizeof (id));
+	}
+
+	debug(3, "Wrote function %s (%d args)\n", idp->ii_name, nargs);
+}
+
+/*
+ * Depending on the size of the type being described, either a ctf_stype_t (for
+ * types with size < CTF_LSTRUCT_THRESH) or a ctf_type_t (all others) will be
+ * written.  We isolate the determination here so the rest of the writer code
+ * doesn't need to care.
+ */
+static void
+write_sized_type_rec(ctf_buf_t *b, ctf_type_t *ctt, size_t size)
+{
+	if (size > CTF_MAX_SIZE) {
+		ctt->ctt_size = CTF_LSIZE_SENT;
+		ctt->ctt_lsizehi = CTF_SIZE_TO_LSIZE_HI(size);
+		ctt->ctt_lsizelo = CTF_SIZE_TO_LSIZE_LO(size);
+		ctf_buf_write(b, ctt, sizeof (*ctt));
+	} else {
+		ctf_stype_t *cts = (ctf_stype_t *)ctt;
+
+		cts->ctt_size = (ushort_t)size;
+		ctf_buf_write(b, cts, sizeof (*cts));
+	}
+}
+
+static void
+write_unsized_type_rec(ctf_buf_t *b, ctf_type_t *ctt)
+{
+	ctf_stype_t *cts = (ctf_stype_t *)ctt;
+
+	ctf_buf_write(b, cts, sizeof (*cts));
+}
+
+static int
+write_type(void *arg1, void *arg2)
+{
+	tdesc_t *tp = arg1;
+	ctf_buf_t *b = arg2;
+	elist_t *ep;
+	mlist_t *mp;
+	intr_t *ip;
+
+	size_t offset;
+	uint_t encoding;
+	uint_t data;
+	int isroot = tp->t_flags & TDESC_F_ISROOT;
+	int i;
+
+	ctf_type_t ctt;
+	ctf_array_t cta;
+	ctf_member_t ctm;
+	ctf_lmember_t ctlm;
+	ctf_enum_t cte;
+	ushort_t id;
+
+	ctlm.ctlm_pad = 0;
+
+	/*
+	 * There shouldn't be any holes in the type list (where a hole is
+	 * defined as two consecutive tdescs without consecutive ids), but
+	 * check for them just in case.  If we do find holes, we need to make
+	 * fake entries to fill the holes, or we won't be able to reconstruct
+	 * the tree from the written data.
+	 */
+	if (++b->nptent < CTF_TYPE_TO_INDEX(tp->t_id)) {