xref: /freebsd/contrib/elftoolchain/libdwarf/dwarf_errmsg.c (revision 98e0ffaefb0f241cda3a72395d3be04192ae0d47)
12de3b87aSKai Wang /*-
22de3b87aSKai Wang  * Copyright (c) 2007 John Birrell (jb@freebsd.org)
32de3b87aSKai Wang  * All rights reserved.
42de3b87aSKai Wang  *
52de3b87aSKai Wang  * Redistribution and use in source and binary forms, with or without
62de3b87aSKai Wang  * modification, are permitted provided that the following conditions
72de3b87aSKai Wang  * are met:
82de3b87aSKai Wang  * 1. Redistributions of source code must retain the above copyright
92de3b87aSKai Wang  *    notice, this list of conditions and the following disclaimer.
102de3b87aSKai Wang  * 2. Redistributions in binary form must reproduce the above copyright
112de3b87aSKai Wang  *    notice, this list of conditions and the following disclaimer in the
122de3b87aSKai Wang  *    documentation and/or other materials provided with the distribution.
132de3b87aSKai Wang  *
142de3b87aSKai Wang  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
152de3b87aSKai Wang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
162de3b87aSKai Wang  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
172de3b87aSKai Wang  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
182de3b87aSKai Wang  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
192de3b87aSKai Wang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
202de3b87aSKai Wang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
212de3b87aSKai Wang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
222de3b87aSKai Wang  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
232de3b87aSKai Wang  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
242de3b87aSKai Wang  * SUCH DAMAGE.
252de3b87aSKai Wang  */
262de3b87aSKai Wang 
272de3b87aSKai Wang #include "_libdwarf.h"
282de3b87aSKai Wang 
29*cf781b2eSEd Maste ELFTC_VCSID("$Id: dwarf_errmsg.c 2975 2014-01-21 20:08:04Z kaiwang27 $");
302de3b87aSKai Wang 
315371959eSKai Wang static const char *_libdwarf_errors[] = {
322de3b87aSKai Wang #define	DEFINE_ERROR(N,S)		[DW_DLE_##N] = S
332de3b87aSKai Wang 	DEFINE_ERROR(NONE, "No Error"),
342de3b87aSKai Wang 	DEFINE_ERROR(ERROR, "An error"),
352de3b87aSKai Wang 	DEFINE_ERROR(NO_ENTRY, "No entry found"),
362de3b87aSKai Wang 	DEFINE_ERROR(ARGUMENT, "Invalid argument"),
372de3b87aSKai Wang 	DEFINE_ERROR(DEBUG_INFO_NULL, "Debug info NULL"),
382de3b87aSKai Wang 	DEFINE_ERROR(MEMORY, "Insufficient memory"),
392de3b87aSKai Wang 	DEFINE_ERROR(ELF, "ELF error"),
402de3b87aSKai Wang 	DEFINE_ERROR(CU_LENGTH_ERROR, "Invalid compilation unit data"),
412de3b87aSKai Wang 	DEFINE_ERROR(VERSION_STAMP_ERROR, "Unsupported version"),
422de3b87aSKai Wang 	DEFINE_ERROR(DEBUG_ABBREV_NULL, "Abbrev not found"),
432de3b87aSKai Wang 	DEFINE_ERROR(DIE_NO_CU_CONTEXT,	"No current compilation unit"),
442de3b87aSKai Wang 	DEFINE_ERROR(LOC_EXPR_BAD, "Invalid location expression"),
452de3b87aSKai Wang 	DEFINE_ERROR(EXPR_LENGTH_BAD, "Invalid DWARF expression length"),
462de3b87aSKai Wang 	DEFINE_ERROR(DEBUG_LOC_SECTION_SHORT, "Loclist section too short"),
472de3b87aSKai Wang 	DEFINE_ERROR(ATTR_FORM_BAD, "Invalid attribute form"),
482de3b87aSKai Wang 	DEFINE_ERROR(DEBUG_LINE_LENGTH_BAD, "Line info section too short"),
492de3b87aSKai Wang 	DEFINE_ERROR(LINE_FILE_NUM_BAD, "Invalid file number."),
502de3b87aSKai Wang 	DEFINE_ERROR(DIR_INDEX_BAD, "Invalid dir index."),
512de3b87aSKai Wang 	DEFINE_ERROR(DEBUG_FRAME_LENGTH_BAD, "Frame section too short"),
522de3b87aSKai Wang 	DEFINE_ERROR(NO_CIE_FOR_FDE, "FDE without corresponding CIE"),
532de3b87aSKai Wang 	DEFINE_ERROR(FRAME_AUGMENTATION_UNKNOWN, "Unknown CIE augmentation"),
542de3b87aSKai Wang 	DEFINE_ERROR(FRAME_INSTR_EXEC_ERROR, "Frame instruction exec error"),
552de3b87aSKai Wang 	DEFINE_ERROR(FRAME_VERSION_BAD, "Unsupported frame section version"),
562de3b87aSKai Wang 	DEFINE_ERROR(FRAME_TABLE_COL_BAD, "Invalid table column value"),
572de3b87aSKai Wang 	DEFINE_ERROR(DF_REG_NUM_TOO_HIGH, "Register number too large"),
582de3b87aSKai Wang 	DEFINE_ERROR(PC_NOT_IN_FDE_RANGE, "PC requested not in the FDE range"),
592de3b87aSKai Wang 	DEFINE_ERROR(ARANGE_OFFSET_BAD, "Invalid address range offset"),
602de3b87aSKai Wang 	DEFINE_ERROR(DEBUG_MACRO_INCONSISTENT, "Invalid macinfo data"),
612de3b87aSKai Wang 	DEFINE_ERROR(ELF_SECT_ERR, "Application callback failed"),
622de3b87aSKai Wang 	DEFINE_ERROR(NUM, "Unknown DWARF error")
632de3b87aSKai Wang #undef	DEFINE_ERROR
642de3b87aSKai Wang };
652de3b87aSKai Wang 
662de3b87aSKai Wang const char *
dwarf_errmsg_(Dwarf_Error * error)672de3b87aSKai Wang dwarf_errmsg_(Dwarf_Error *error)
682de3b87aSKai Wang {
692de3b87aSKai Wang 	const char *p;
702de3b87aSKai Wang 
712de3b87aSKai Wang 	if (error == NULL)
722de3b87aSKai Wang 		return NULL;
732de3b87aSKai Wang 
742de3b87aSKai Wang 	if (error->err_error < 0 || error->err_error >= DW_DLE_NUM)
752de3b87aSKai Wang 		return _libdwarf_errors[DW_DLE_NUM];
762de3b87aSKai Wang 	else if (error->err_error == DW_DLE_NONE)
772de3b87aSKai Wang 		return _libdwarf_errors[DW_DLE_NONE];
782de3b87aSKai Wang 	else
792de3b87aSKai Wang 		p = _libdwarf_errors[error->err_error];
802de3b87aSKai Wang 
812de3b87aSKai Wang 	if (error->err_error == DW_DLE_ELF)
822de3b87aSKai Wang 		snprintf(error->err_msg, sizeof(error->err_msg),
832de3b87aSKai Wang 		    "ELF error : %s [%s(%d)]", elf_errmsg(error->err_elferror),
842de3b87aSKai Wang 		    error->err_func, error->err_line);
852de3b87aSKai Wang 	else
862de3b87aSKai Wang 		snprintf(error->err_msg, sizeof(error->err_msg),
872de3b87aSKai Wang 		    "%s [%s(%d)]", p, error->err_func, error->err_line);
882de3b87aSKai Wang 
892de3b87aSKai Wang 	return (const char *) error->err_msg;
902de3b87aSKai Wang }
91