17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
260a47c91cSRobert Mustacchi /*
27*f3e7f55eSRobert Mustacchi * Copyright (c) 2015, Joyent, Inc.
280a47c91cSRobert Mustacchi */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate #include <ctf_impl.h>
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate static const char *const _ctf_errlist[] = {
337c478bd9Sstevel@tonic-gate "File is not in CTF or ELF format", /* ECTF_FMT */
347c478bd9Sstevel@tonic-gate "File uses more recent ELF version than libctf", /* ECTF_ELFVERS */
357c478bd9Sstevel@tonic-gate "File uses more recent CTF version than libctf", /* ECTF_CTFVERS */
367c478bd9Sstevel@tonic-gate "File is a different endian-ness than libctf", /* ECTF_ENDIAN */
377c478bd9Sstevel@tonic-gate "Symbol table uses invalid entry size", /* ECTF_SYMTAB */
387c478bd9Sstevel@tonic-gate "Symbol table data buffer is not valid", /* ECTF_SYMBAD */
397c478bd9Sstevel@tonic-gate "String table data buffer is not valid", /* ECTF_STRBAD */
407c478bd9Sstevel@tonic-gate "File data structure corruption detected", /* ECTF_CORRUPT */
417c478bd9Sstevel@tonic-gate "File does not contain CTF data", /* ECTF_NOCTFDATA */
427c478bd9Sstevel@tonic-gate "Buffer does not contain CTF data", /* ECTF_NOCTFBUF */
437c478bd9Sstevel@tonic-gate "Symbol table information is not available", /* ECTF_NOSYMTAB */
447c478bd9Sstevel@tonic-gate "Type information is in parent and unavailable", /* ECTF_NOPARENT */
457c478bd9Sstevel@tonic-gate "Cannot import types with different data model", /* ECTF_DMODEL */
467c478bd9Sstevel@tonic-gate "Failed to mmap a needed data section", /* ECTF_MMAP */
477c478bd9Sstevel@tonic-gate "Decompression package SUNWzlib not installed", /* ECTF_ZMISSING */
487c478bd9Sstevel@tonic-gate "Failed to initialize decompression library", /* ECTF_ZINIT */
497c478bd9Sstevel@tonic-gate "Failed to allocate decompression buffer", /* ECTF_ZALLOC */
507c478bd9Sstevel@tonic-gate "Failed to decompress CTF data", /* ECTF_DECOMPRESS */
517c478bd9Sstevel@tonic-gate "External string table is not available", /* ECTF_STRTAB */
527c478bd9Sstevel@tonic-gate "String name offset is corrupt", /* ECTF_BADNAME */
537c478bd9Sstevel@tonic-gate "Invalid type identifier", /* ECTF_BADID */
547c478bd9Sstevel@tonic-gate "Type is not a struct or union", /* ECTF_NOTSOU */
557c478bd9Sstevel@tonic-gate "Type is not an enum", /* ECTF_NOTENUM */
567c478bd9Sstevel@tonic-gate "Type is not a struct, union, or enum", /* ECTF_NOTSUE */
577c478bd9Sstevel@tonic-gate "Type is not an integer or float", /* ECTF_NOTINTFP */
587c478bd9Sstevel@tonic-gate "Type is not an array", /* ECTF_NOTARRAY */
597c478bd9Sstevel@tonic-gate "Type does not reference another type", /* ECTF_NOTREF */
607c478bd9Sstevel@tonic-gate "Input buffer is too small for type name", /* ECTF_NAMELEN */
617c478bd9Sstevel@tonic-gate "No type information available for that name", /* ECTF_NOTYPE */
627c478bd9Sstevel@tonic-gate "Syntax error in type name", /* ECTF_SYNTAX */
637c478bd9Sstevel@tonic-gate "Symbol table entry is not a function", /* ECTF_NOTFUNC */
647c478bd9Sstevel@tonic-gate "No function information available for symbol", /* ECTF_NOFUNCDAT */
657c478bd9Sstevel@tonic-gate "Symbol table entry is not a data object", /* ECTF_NOTDATA */
667c478bd9Sstevel@tonic-gate "No type information available for symbol", /* ECTF_NOTYPEDAT */
677c478bd9Sstevel@tonic-gate "No label information available for that name", /* ECTF_NOLABEL */
687c478bd9Sstevel@tonic-gate "File does not contain any labels", /* ECTF_NOLABELDATA */
697c478bd9Sstevel@tonic-gate "Feature not supported", /* ECTF_NOTSUP */
707c478bd9Sstevel@tonic-gate "Invalid enum element name", /* ECTF_NOENUMNAM */
717c478bd9Sstevel@tonic-gate "Invalid member name", /* ECTF_NOMEMBNAM */
727c478bd9Sstevel@tonic-gate "CTF container is read-only", /* ECTF_RDONLY */
737c478bd9Sstevel@tonic-gate "Limit on number of dynamic type members reached", /* ECTF_DTFULL */
747c478bd9Sstevel@tonic-gate "Limit on number of dynamic types reached", /* ECTF_FULL */
757c478bd9Sstevel@tonic-gate "Duplicate member name definition", /* ECTF_DUPMEMBER */
767c478bd9Sstevel@tonic-gate "Conflicting type is already defined", /* ECTF_CONFLICT */
770a47c91cSRobert Mustacchi "Type has outstanding references", /* ECTF_REFERENCED */
78*f3e7f55eSRobert Mustacchi "Type is not a dynamic type", /* ECTF_NOTDYN */
79*f3e7f55eSRobert Mustacchi "Elf library failure", /* ECTF_ELF */
80*f3e7f55eSRobert Mustacchi "Cannot merge child container", /* ECTF_MCHILD */
81*f3e7f55eSRobert Mustacchi "Label already exists", /* ECTF_LABEL */
82*f3e7f55eSRobert Mustacchi "Merged labels conflict", /* ECTF_LCONFLICT */
83*f3e7f55eSRobert Mustacchi "Zlib library failure", /* ECTF_ZLIB */
84*f3e7f55eSRobert Mustacchi "CTF conversion backend error", /* ECTF_CONVBKERR */
85*f3e7f55eSRobert Mustacchi "No C source to convert from", /* ECTF_CONVNOCSRC */
86*f3e7f55eSRobert Mustacchi "No applicable conversion backend" /* ECTF_NOCONVBKEND */
877c478bd9Sstevel@tonic-gate };
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate static const int _ctf_nerr = sizeof (_ctf_errlist) / sizeof (_ctf_errlist[0]);
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate const char *
ctf_errmsg(int error)927c478bd9Sstevel@tonic-gate ctf_errmsg(int error)
937c478bd9Sstevel@tonic-gate {
947c478bd9Sstevel@tonic-gate const char *str;
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate if (error >= ECTF_BASE && (error - ECTF_BASE) < _ctf_nerr)
977c478bd9Sstevel@tonic-gate str = _ctf_errlist[error - ECTF_BASE];
987c478bd9Sstevel@tonic-gate else
997c478bd9Sstevel@tonic-gate str = ctf_strerror(error);
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate return (str ? str : "Unknown error");
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate int
ctf_errno(ctf_file_t * fp)1057c478bd9Sstevel@tonic-gate ctf_errno(ctf_file_t *fp)
1067c478bd9Sstevel@tonic-gate {
1077c478bd9Sstevel@tonic-gate return (fp->ctf_errno);
1087c478bd9Sstevel@tonic-gate }
109