public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nick Alcock <nick.alcock@oracle.com>
To: binutils@sourceware.org
Subject: [PATCH 05/19] libctf: error handling
Date: Tue, 30 Apr 2019 22:57:00 -0000	[thread overview]
Message-ID: <20190430225706.159422-6-nick.alcock@oracle.com> (raw)
In-Reply-To: <20190430225706.159422-1-nick.alcock@oracle.com>

CTF functions return zero on success or an extended errno value which
can be translated into a string via the functions in this commit.

The errno numbers start at -CTF_BASE.

libctf/
	* ctf-error.c: New file.

include/
	* ctf-api.h (ctf_errno): New declaration.
	(ctf_errmsg): Likewise.
---
 include/ctf-api.h  |  2 +
 libctf/ctf-error.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+)
 create mode 100644 libctf/ctf-error.c

diff --git a/include/ctf-api.h b/include/ctf-api.h
index e2f5dc7571..646e848c84 100644
--- a/include/ctf-api.h
+++ b/include/ctf-api.h
@@ -122,6 +122,8 @@ enum
 #define	CTF_ADD_NONROOT	0	/* Type only visible in nested scope.  */
 #define	CTF_ADD_ROOT	1	/* Type visible at top-level scope.  */
 
+extern int ctf_errno (ctf_file_t *);
+extern const char *ctf_errmsg (int);
 
 #ifdef	__cplusplus
 }
diff --git a/libctf/ctf-error.c b/libctf/ctf-error.c
new file mode 100644
index 0000000000..ea3e113145
--- /dev/null
+++ b/libctf/ctf-error.c
@@ -0,0 +1,93 @@
+/* Error table.
+   Copyright (C) 2003-2019 Free Software Foundation, Inc.
+
+   This file is part of libctf.
+
+   libctf is free software; you can redistribute it and/or modify it under
+   the terms of the GNU General Public License as published by the Free
+   Software Foundation; either version 2, or (at your option) any later
+   version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+   See the GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; see the file COPYING.  If not see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <ctf-impl.h>
+
+static const char *const _ctf_errlist[] = {
+  "File is not in CTF or ELF format",		     /* ECTF_FMT */
+  "File uses more recent ELF version than libctf",   /* ECTF_ELFVERS */
+  "File uses more recent CTF version than libctf",   /* ECTF_CTFVERS */
+  "File is a different endian-ness than libctf",     /* ECTF_ENDIAN */
+  "Symbol table uses invalid entry size",	     /* ECTF_SYMTAB */
+  "Symbol table data buffer is not valid",	     /* ECTF_SYMBAD */
+  "String table data buffer is not valid",	     /* ECTF_STRBAD */
+  "File data structure corruption detected",	     /* ECTF_CORRUPT */
+  "File does not contain CTF data",		     /* ECTF_NOCTFDATA */
+  "Buffer does not contain CTF data",		     /* ECTF_NOCTFBUF */
+  "Symbol table information is not available",	     /* ECTF_NOSYMTAB */
+  "Type information is in parent and unavailable",   /* ECTF_NOPARENT */
+  "Cannot import types with different data model",   /* ECTF_DMODEL */
+  "Failed to mmap a needed data section",	     /* ECTF_MMAP */
+  "Failed to allocate (de)compression buffer",	     /* ECTF_ZALLOC */
+  "Failed to decompress CTF data",		     /* ECTF_DECOMPRESS */
+  "External string table is not available",	     /* ECTF_STRTAB */
+  "String name offset is corrupt",		     /* ECTF_BADNAME */
+  "Invalid type identifier",			     /* ECTF_BADID */
+  "Type is not a struct or union",		     /* ECTF_NOTSOU */
+  "Type is not an enum",			     /* ECTF_NOTENUM */
+  "Type is not a struct, union, or enum",	     /* ECTF_NOTSUE */
+  "Type is not an integer, float, or enum",	     /* ECTF_NOTINTFP */
+  "Type is not an array",			     /* ECTF_NOTARRAY */
+  "Type does not reference another type",	     /* ECTF_NOTREF */
+  "Input buffer is too small for type name",	     /* ECTF_NAMELEN */
+  "No type information available for that name",     /* ECTF_NOTYPE */
+  "Syntax error in type name",			     /* ECTF_SYNTAX */
+  "Symbol table entry is not a function",	     /* ECTF_NOTFUNC */
+  "No function information available for symbol",    /* ECTF_NOFUNCDAT */
+  "Symbol table entry is not a data object",	     /* ECTF_NOTDATA */
+  "No type information available for symbol",	     /* ECTF_NOTYPEDAT */
+  "No label information available for that name",    /* ECTF_NOLABEL */
+  "File does not contain any labels",		     /* ECTF_NOLABELDATA */
+  "Feature not supported",			     /* ECTF_NOTSUP */
+  "Invalid enum element name",			     /* ECTF_NOENUMNAM */
+  "Invalid member name",			     /* ECTF_NOMEMBNAM */
+  "CTF container is read-only",			     /* ECTF_RDONLY */
+  "Limit on number of dynamic type members reached", /* ECTF_DTFULL */
+  "Limit on number of dynamic types reached",	     /* ECTF_FULL */
+  "Duplicate member or variable name",		     /* ECTF_DUPLICATE */
+  "Conflicting type is already defined",	     /* ECTF_CONFLICT */
+  "Attempt to roll back past a ctf_update",	     /* ECTF_OVERROLLBACK */
+  "Failed to compress CTF data",		     /* ECTF_COMPRESS */
+  "Failed to create CTF archive",		     /* ECTF_ARCREATE */
+  "Name not found in CTF archive",		     /* ECTF_ARNNAME */
+  "Overflow of type bitness or offset in slice",     /* ECTF_SLICEOVERFLOW */
+  "Unknown section number in dump",		     /* ECTF_DUMPSECTUNKNOWN */
+  "Section changed in middle of dump"		     /* ECTF_DUMPSECTCHANGED */
+};
+
+static const int _ctf_nerr = sizeof (_ctf_errlist) / sizeof (_ctf_errlist[0]);
+
+const char *
+ctf_errmsg (int error)
+{
+  const char *str;
+
+  if (error >= ECTF_BASE && (error - ECTF_BASE) < _ctf_nerr)
+    str = _ctf_errlist[error - ECTF_BASE];
+  else
+    str = ctf_strerror (error);
+
+  return (str ? str : "Unknown error");
+}
+
+int
+ctf_errno (ctf_file_t * fp)
+{
+  return fp->ctf_errno;
+}
-- 
2.21.0.237.gd0cfaa883d

  parent reply	other threads:[~2019-04-30 22:57 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-30 22:57 [PATCH 00/19] libctf, and CTF support for objdump and readelf Nick Alcock
2019-04-30 22:57 ` [PATCH 19/19] binutils: " Nick Alcock
2019-04-30 22:57 ` [PATCH 08/19] libctf: creation functions Nick Alcock
2019-04-30 22:57 ` CTF format overview Nick Alcock
2019-04-30 22:57 ` [PATCH 15/19] libctf: mmappable archives Nick Alcock
2019-04-30 22:57 ` [PATCH 01/19] include: new header ctf.h: file format description Nick Alcock
2019-05-01 16:57   ` Nick Clifton
2019-05-01 21:29     ` Jim Wilson
2019-05-03 11:15       ` Nick Alcock
2019-04-30 22:57 ` [PATCH 13/19] libctf: type copying Nick Alcock
2019-04-30 22:57 ` Nick Alcock [this message]
2019-05-02 16:10   ` [PATCH 05/19] libctf: error handling Nick Clifton
2019-05-03 19:31     ` Nick Alcock
2019-04-30 22:57 ` [PATCH 02/19] include: new header ctf-api.h Nick Alcock
2019-05-02 15:07   ` Nick Clifton
2019-05-03 11:23     ` Nick Alcock
2019-04-30 22:57 ` [PATCH 06/19] libctf: hashing Nick Alcock
2019-05-02 16:16   ` Nick Clifton
2019-05-03 19:33     ` Nick Alcock
2019-04-30 22:57 ` [PATCH 10/19] libctf: ELF file opening Nick Alcock
2019-04-30 22:57 ` [PATCH 09/19] libctf: opening Nick Alcock
2019-04-30 22:57 ` [PATCH 03/19] libctf: lowest-level memory allocation and debug-dumping wrappers Nick Alcock
2019-05-02 15:29   ` Nick Clifton
2019-05-03 19:12     ` Nick Alcock
2019-04-30 22:57 ` [PATCH 12/19] libctf: lookups by name and symbol Nick Alcock
2019-04-30 22:57 ` [PATCH 14/19] libctf: library version enforcement Nick Alcock
2019-04-30 22:57 ` [PATCH 11/19] libctf: core type lookup Nick Alcock
2019-04-30 22:57 ` [PATCH 04/19] libctf: low-level list manipulation and helper utilities Nick Alcock
2019-05-02 16:04   ` Nick Clifton
2019-05-03 19:25     ` Nick Alcock
2019-04-30 22:58 ` [PATCH 18/19] libctf: build system Nick Alcock
2019-05-01  0:13 ` [PATCH 17/19] libctf: debug dumping Nick Alcock
2019-05-01  0:19 ` [PATCH 16/19] libctf: labels Nick Alcock
2019-05-01  1:57 ` [PATCH 07/19] libctf: implementation definitions related to file creation Nick Alcock
2019-05-01 16:02 ` [PATCH 00/19] libctf, and CTF support for objdump and readelf Nick Clifton
2019-05-01 16:16   ` Jose E. Marchesi
2019-05-03 10:47     ` Nick Alcock
2019-05-02 15:22 ` Joseph Myers
2019-05-03 12:33   ` Nick Clifton
2019-05-06 16:40     ` Nick Alcock
2019-05-08 14:34     ` Michael Matz
2019-05-08 16:01       ` Nick Clifton
2019-05-08 16:20         ` Nick Alcock
2019-05-03 14:23   ` Nick Alcock
     [not found]     ` <alpine.DEB.2.21.1905072117440.19308@digraph.polyomino.org.uk>
2019-05-08 11:39       ` Nick Alcock
2019-05-24  8:57     ` Pedro Alves
2019-05-24 16:05       ` Nick Alcock
2019-05-24 16:19         ` Pedro Alves
2019-05-24 20:09           ` Nick Alcock
2019-05-03 16:19 ` Florian Weimer
2019-05-03 19:45   ` Nick Alcock
2019-05-06 12:07     ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190430225706.159422-6-nick.alcock@oracle.com \
    --to=nick.alcock@oracle.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).