From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7271 invoked by alias); 30 Apr 2019 22:57:20 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 7147 invoked by uid 89); 30 Apr 2019 22:57:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.5 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,SPF_HELO_PASS,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 spammy= X-HELO: userp2130.oracle.com Received: from userp2130.oracle.com (HELO userp2130.oracle.com) (156.151.31.86) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 30 Apr 2019 22:57:17 +0000 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3UMsO8D079916 for ; Tue, 30 Apr 2019 22:57:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2018-07-02; bh=dYBA3y6As9NTsRfV6fNneWChCdENuUuHLw7xOBOr0Jg=; b=g56oI6camYQzMjntpa+wm+IhYKzWTZGvttrSk4O/AdVhuYo2jra3QgTX2yE13kGD7PX8 +3SzkAMnJ8M0jWnb0HMp9glposVWnAk/KhUygeilvrVOA5L8EyaeY1hvO/8gLSYaASgS 4wtQnN1dCkiDJzzIRaRhqNu2FwHVttrm91LVa6GImAgx7LUOu2oHBp7sg9OfiSu/KC0N +vFtkKbVLmU65jhyLrjF3NFF35A33gMFXq9AHZPSEw9L219+vo+AD2KUCWduI9exS7I6 sukEXu8Xx/aexktmzLF/hK5nWG0QMIf1/9l6etSMYcI+so9iHfeypHamHahtQ5QNrJW9 Jg== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2s6xhy86y6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 30 Apr 2019 22:57:15 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3UMtZ02161513 for ; Tue, 30 Apr 2019 22:57:15 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 2s6xhh0q5p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 30 Apr 2019 22:57:15 +0000 Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x3UMvFhp006636 for ; Tue, 30 Apr 2019 22:57:15 GMT Received: from loom.srvr.nix (/81.187.191.129) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 30 Apr 2019 15:57:14 -0700 From: Nick Alcock To: binutils@sourceware.org Subject: [PATCH 05/19] libctf: error handling Date: Tue, 30 Apr 2019 22:57:00 -0000 Message-Id: <20190430225706.159422-6-nick.alcock@oracle.com> In-Reply-To: <20190430225706.159422-1-nick.alcock@oracle.com> References: <20190430225706.159422-1-nick.alcock@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2019-04/txt/msg00270.txt.bz2 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 + . */ + +#include + +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