xref: /netbsd-src/external/cddl/osnet/dist/common/ctf/ctf_error.c (revision 81dbb529d3e27f6f274bb177e60b0b82c1c59def)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 #ifdef HAVE_NBTOOL_CONFIG_H
23 #include "nbtool_config.h"
24 #endif
25 /*
26  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 /*
30  * Copyright (c) 2012, Joyent, Inc.
31  */
32 
33 #include <ctf_impl.h>
34 
35 static const char *const _ctf_errlist[] = {
36 	"File is not in CTF or ELF format",		 /* ECTF_FMT */
37 	"File uses more recent ELF version than libctf", /* ECTF_ELFVERS */
38 	"File uses more recent CTF version than libctf", /* ECTF_CTFVERS */
39 	"File is a different endian-ness than libctf",	 /* ECTF_ENDIAN */
40 	"Symbol table uses invalid entry size",		 /* ECTF_SYMTAB */
41 	"Symbol table data buffer is not valid",	 /* ECTF_SYMBAD */
42 	"String table data buffer is not valid",	 /* ECTF_STRBAD */
43 	"File data structure corruption detected",	 /* ECTF_CORRUPT */
44 	"File does not contain CTF data",		 /* ECTF_NOCTFDATA */
45 	"Buffer does not contain CTF data",		 /* ECTF_NOCTFBUF */
46 	"Symbol table information is not available",	 /* ECTF_NOSYMTAB */
47 	"Type information is in parent and unavailable", /* ECTF_NOPARENT */
48 	"Cannot import types with different data model", /* ECTF_DMODEL */
49 	"Failed to mmap a needed data section",		 /* ECTF_MMAP */
50 	"Decompression package SUNWzlib not installed",	 /* ECTF_ZMISSING */
51 	"Failed to initialize decompression library",	 /* ECTF_ZINIT */
52 	"Failed to allocate decompression buffer",	 /* ECTF_ZALLOC */
53 	"Failed to decompress CTF data",		 /* ECTF_DECOMPRESS */
54 	"External string table is not available",	 /* ECTF_STRTAB */
55 	"String name offset is corrupt",		 /* ECTF_BADNAME */
56 	"Invalid type identifier",			 /* ECTF_BADID */
57 	"Type is not a struct or union",		 /* ECTF_NOTSOU */
58 	"Type is not an enum",				 /* ECTF_NOTENUM */
59 	"Type is not a struct, union, or enum",		 /* ECTF_NOTSUE */
60 	"Type is not an integer or float",		 /* ECTF_NOTINTFP */
61 	"Type is not an array",				 /* ECTF_NOTARRAY */
62 	"Type does not reference another type",		 /* ECTF_NOTREF */
63 	"Input buffer is too small for type name",	 /* ECTF_NAMELEN */
64 	"No type information available for that name",	 /* ECTF_NOTYPE */
65 	"Syntax error in type name",			 /* ECTF_SYNTAX */
66 	"Symbol table entry is not a function",		 /* ECTF_NOTFUNC */
67 	"No function information available for symbol",	 /* ECTF_NOFUNCDAT */
68 	"Symbol table entry is not a data object",	 /* ECTF_NOTDATA */
69 	"No type information available for symbol",	 /* ECTF_NOTYPEDAT */
70 	"No label information available for that name",	 /* ECTF_NOLABEL */
71 	"File does not contain any labels",		 /* ECTF_NOLABELDATA */
72 	"Feature not supported",			 /* ECTF_NOTSUP */
73 	"Invalid enum element name",			 /* ECTF_NOENUMNAM */
74 	"Invalid member name",				 /* ECTF_NOMEMBNAM */
75 	"CTF container is read-only",			 /* ECTF_RDONLY */
76 	"Limit on number of dynamic type members reached", /* ECTF_DTFULL */
77 	"Limit on number of dynamic types reached",	 /* ECTF_FULL */
78 	"Duplicate member name definition",		 /* ECTF_DUPMEMBER */
79 	"Conflicting type is already defined",		 /* ECTF_CONFLICT */
80 	"Type has outstanding references",		 /* ECTF_REFERENCED */
81 	"Type is not a dynamic type"			 /* ECTF_NOTDYN */
82 };
83 
84 static const int _ctf_nerr = sizeof (_ctf_errlist) / sizeof (_ctf_errlist[0]);
85 
86 const char *
ctf_errmsg(int error)87 ctf_errmsg(int error)
88 {
89 	const char *str;
90 
91 	if (error >= ECTF_BASE && (error - ECTF_BASE) < _ctf_nerr)
92 		str = _ctf_errlist[error - ECTF_BASE];
93 	else
94 		str = ctf_strerror(error);
95 
96 	return (str ? str : "Unknown error");
97 }
98 
99 int
ctf_errno(ctf_file_t * fp)100 ctf_errno(ctf_file_t *fp)
101 {
102 	return (fp->ctf_errno);
103 }
104