149d3bc9Richard Lowe/*
249d3bc9Richard Lowe
307dc194Richard Lowe  Copyright (C) 2000,2002,2004 Silicon Graphics, Inc.  All Rights Reserved.
449d3bc9Richard Lowe
549d3bc9Richard Lowe  This program is free software; you can redistribute it and/or modify it
649d3bc9Richard Lowe  under the terms of version 2.1 of the GNU Lesser General Public License
749d3bc9Richard Lowe  as published by the Free Software Foundation.
849d3bc9Richard Lowe
949d3bc9Richard Lowe  This program is distributed in the hope that it would be useful, but
1049d3bc9Richard Lowe  WITHOUT ANY WARRANTY; without even the implied warranty of
1149d3bc9Richard Lowe  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1249d3bc9Richard Lowe
1349d3bc9Richard Lowe  Further, this software is distributed without any warranty that it is
1449d3bc9Richard Lowe  free of the rightful claim of any third person regarding infringement
1549d3bc9Richard Lowe  or the like.  Any license provided herein, whether implied or
1649d3bc9Richard Lowe  otherwise, applies only to this software file.  Patent licenses, if
1749d3bc9Richard Lowe  any, provided herein do not apply to combinations of this program with
1849d3bc9Richard Lowe  other software, or any other product whatsoever.
1949d3bc9Richard Lowe
2049d3bc9Richard Lowe  You should have received a copy of the GNU Lesser General Public
2149d3bc9Richard Lowe  License along with this program; if not, write the Free Software
2207dc194Richard Lowe  Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
2349d3bc9Richard Lowe  USA.
2449d3bc9Richard Lowe
2507dc194Richard Lowe  Contact information:  Silicon Graphics, Inc., 1500 Crittenden Lane,
2649d3bc9Richard Lowe  Mountain View, CA 94043, or:
2749d3bc9Richard Lowe
2849d3bc9Richard Lowe  http://www.sgi.com
2949d3bc9Richard Lowe
3049d3bc9Richard Lowe  For further information regarding this notice, see:
3149d3bc9Richard Lowe
3249d3bc9Richard Lowe  http://oss.sgi.com/projects/GenInfo/NoticeExplan
3349d3bc9Richard Lowe
3449d3bc9Richard Lowe*/
3549d3bc9Richard Lowe
3649d3bc9Richard Lowe
3749d3bc9Richard Lowe
3849d3bc9Richard Lowe#include "config.h"
3949d3bc9Richard Lowe#include "libdwarfdefs.h"
4049d3bc9Richard Lowe#ifdef HAVE_ELF_H
4149d3bc9Richard Lowe#include <elf.h>
4249d3bc9Richard Lowe#endif
4349d3bc9Richard Lowe
4449d3bc9Richard Lowe#include <stdio.h>
4549d3bc9Richard Lowe#include <sys/stat.h>
4649d3bc9Richard Lowe#include <sys/types.h>
4749d3bc9Richard Lowe#include <stdlib.h>
4849d3bc9Richard Lowe#include "pro_incl.h"
4949d3bc9Richard Lowe
5049d3bc9Richard Loweextern char *_dwarf_errmsgs[];
5149d3bc9Richard Lowe
5249d3bc9Richard Lowe/*
5349d3bc9Richard Lowe    This function performs error handling as described in the
5449d3bc9Richard Lowe    libdwarf consumer document section 3.  Dbg is the Dwarf_P_debug
5549d3bc9Richard Lowe    structure being processed.  Error is a pointer to the pointer
5649d3bc9Richard Lowe    to the error descriptor that will be returned.  Errval is an
5749d3bc9Richard Lowe    error code listed in dwarf_error.h.
5849d3bc9Richard Lowe*/
5949d3bc9Richard Lowevoid
6049d3bc9Richard Lowe_dwarf_p_error(Dwarf_P_Debug dbg,
6107dc194Richard Lowe               Dwarf_Error * error, Dwarf_Word errval)
6249d3bc9Richard Lowe{
6349d3bc9Richard Lowe    Dwarf_Error errptr;
6449d3bc9Richard Lowe
6549d3bc9Richard Lowe    /* Allow NULL dbg on entry, since sometimes that can happen and we
6649d3bc9Richard Lowe       want to report the upper-level error, not this one. */
6749d3bc9Richard Lowe    if ((Dwarf_Sword) errval < 0)
6807dc194Richard Lowe        printf("ERROR VALUE: %ld - %s\n",
6907dc194Richard Lowe               (long) errval, _dwarf_errmsgs[-errval - 1]);
7049d3bc9Richard Lowe    if (error != NULL) {
7107dc194Richard Lowe        errptr = (Dwarf_Error)
7207dc194Richard Lowe            _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_Error_s));
7307dc194Richard Lowe        if (errptr == NULL) {
7407dc194Richard Lowe            fprintf(stderr,
7507dc194Richard Lowe                    "Could not allocate Dwarf_Error structure\n");
7607dc194Richard Lowe            abort();
7707dc194Richard Lowe        }
7807dc194Richard Lowe        errptr->er_errval = (Dwarf_Sword) errval;
7907dc194Richard Lowe        *error = errptr;
8007dc194Richard Lowe        return;
8149d3bc9Richard Lowe    }
8249d3bc9Richard Lowe
8349d3bc9Richard Lowe    if (dbg != NULL && dbg->de_errhand != NULL) {
8407dc194Richard Lowe        errptr = (Dwarf_Error)
8507dc194Richard Lowe            _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_Error_s));
8607dc194Richard Lowe        if (errptr == NULL) {
8707dc194Richard Lowe            fprintf(stderr,
8807dc194Richard Lowe                    "Could not allocate Dwarf_Error structure\n");
8907dc194Richard Lowe            abort();
9007dc194Richard Lowe        }
9107dc194Richard Lowe        errptr->er_errval = (Dwarf_Sword) errval;
9207dc194Richard Lowe        dbg->de_errhand(errptr, dbg->de_errarg);
9307dc194Richard Lowe        return;
9449d3bc9Richard Lowe    }
9549d3bc9Richard Lowe
9649d3bc9Richard Lowe    abort();
9749d3bc9Richard Lowe}
98