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