149d3bc91SRichard Lowe /*
249d3bc91SRichard Lowe
307dc1947SRichard Lowe Copyright (C) 2000,2002,2004 Silicon Graphics, Inc. All Rights Reserved.
4*4d9fdb46SRobert Mustacchi Portions Copyright 2011 David Anderson. All Rights Reserved.
549d3bc91SRichard Lowe
649d3bc91SRichard Lowe This program is free software; you can redistribute it and/or modify it
7*4d9fdb46SRobert Mustacchi under the terms of version 2.1 of the GNU Lesser General Public License
849d3bc91SRichard Lowe as published by the Free Software Foundation.
949d3bc91SRichard Lowe
1049d3bc91SRichard Lowe This program is distributed in the hope that it would be useful, but
1149d3bc91SRichard Lowe WITHOUT ANY WARRANTY; without even the implied warranty of
12*4d9fdb46SRobert Mustacchi MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1349d3bc91SRichard Lowe
1449d3bc91SRichard Lowe Further, this software is distributed without any warranty that it is
15*4d9fdb46SRobert Mustacchi free of the rightful claim of any third person regarding infringement
16*4d9fdb46SRobert Mustacchi or the like. Any license provided herein, whether implied or
1749d3bc91SRichard Lowe otherwise, applies only to this software file. Patent licenses, if
18*4d9fdb46SRobert Mustacchi any, provided herein do not apply to combinations of this program with
19*4d9fdb46SRobert Mustacchi other software, or any other product whatsoever.
2049d3bc91SRichard Lowe
21*4d9fdb46SRobert Mustacchi You should have received a copy of the GNU Lesser General Public
22*4d9fdb46SRobert Mustacchi License along with this program; if not, write the Free Software
2307dc1947SRichard Lowe Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
2449d3bc91SRichard Lowe USA.
2549d3bc91SRichard Lowe
2649d3bc91SRichard Lowe */
2749d3bc91SRichard Lowe
2849d3bc91SRichard Lowe #include "config.h"
2949d3bc91SRichard Lowe #include "libdwarfdefs.h"
3049d3bc91SRichard Lowe
3149d3bc91SRichard Lowe #include <stdio.h>
3249d3bc91SRichard Lowe #include <sys/stat.h>
3349d3bc91SRichard Lowe #include <sys/types.h>
34*4d9fdb46SRobert Mustacchi #ifdef HAVE_STDLIB_H
35*4d9fdb46SRobert Mustacchi #include <stdlib.h> /* for exit(), C89 malloc */
36*4d9fdb46SRobert Mustacchi #endif /* HAVE_STDLIB_H */
3749d3bc91SRichard Lowe #include "pro_incl.h"
38*4d9fdb46SRobert Mustacchi #include <stddef.h>
39*4d9fdb46SRobert Mustacchi #include "dwarf.h"
40*4d9fdb46SRobert Mustacchi #include "libdwarf.h"
41*4d9fdb46SRobert Mustacchi #include "pro_opaque.h"
42*4d9fdb46SRobert Mustacchi #include "pro_error.h"
43*4d9fdb46SRobert Mustacchi #include "pro_alloc.h"
44*4d9fdb46SRobert Mustacchi
4549d3bc91SRichard Lowe
4649d3bc91SRichard Lowe extern char *_dwarf_errmsgs[];
4749d3bc91SRichard Lowe
48*4d9fdb46SRobert Mustacchi /*
49*4d9fdb46SRobert Mustacchi This function performs error handling as described in the
5049d3bc91SRichard Lowe libdwarf consumer document section 3. Dbg is the Dwarf_P_debug
5149d3bc91SRichard Lowe structure being processed. Error is a pointer to the pointer
5249d3bc91SRichard Lowe to the error descriptor that will be returned. Errval is an
5349d3bc91SRichard Lowe error code listed in dwarf_error.h.
54*4d9fdb46SRobert Mustacchi
55*4d9fdb46SRobert Mustacchi The error number may be retrieved from the Dwarf_Error
56*4d9fdb46SRobert Mustacchi by calling dwarf_errno().
57*4d9fdb46SRobert Mustacchi The error string implied by the error number may be retrieved
58*4d9fdb46SRobert Mustacchi from the Dwarf_Error by calling dwarf_errmsg().
5949d3bc91SRichard Lowe */
6049d3bc91SRichard Lowe void
_dwarf_p_error(Dwarf_P_Debug dbg,Dwarf_Error * error,Dwarf_Unsigned errval)6149d3bc91SRichard Lowe _dwarf_p_error(Dwarf_P_Debug dbg,
62*4d9fdb46SRobert Mustacchi Dwarf_Error * error, Dwarf_Unsigned errval)
6349d3bc91SRichard Lowe {
6449d3bc91SRichard Lowe Dwarf_Error errptr;
6549d3bc91SRichard Lowe
66*4d9fdb46SRobert Mustacchi if (errval > DW_DLE_LAST) {
67*4d9fdb46SRobert Mustacchi /* We do not expect to ever see such an error number,
68*4d9fdb46SRobert Mustacchi DW_DLE_LO_USER is not used. */
69*4d9fdb46SRobert Mustacchi fprintf(stderr,"ERROR VALUE: %lu - %s\n",
70*4d9fdb46SRobert Mustacchi (unsigned long) errval, "this error value is unknown to libdwarf.");
71*4d9fdb46SRobert Mustacchi }
72*4d9fdb46SRobert Mustacchi /* Allow NULL dbg on entry, since sometimes that can happen and we
73*4d9fdb46SRobert Mustacchi want to report the upper-level error, not this one. */
7449d3bc91SRichard Lowe if (error != NULL) {
7507dc1947SRichard Lowe errptr = (Dwarf_Error)
7607dc1947SRichard Lowe _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_Error_s));
7707dc1947SRichard Lowe if (errptr == NULL) {
7807dc1947SRichard Lowe fprintf(stderr,
79*4d9fdb46SRobert Mustacchi "Could not allocate Dwarf_Error structure\n");
8007dc1947SRichard Lowe abort();
8107dc1947SRichard Lowe }
82*4d9fdb46SRobert Mustacchi errptr->er_errval = (Dwarf_Signed) errval;
8307dc1947SRichard Lowe *error = errptr;
8407dc1947SRichard Lowe return;
8549d3bc91SRichard Lowe }
8649d3bc91SRichard Lowe
8749d3bc91SRichard Lowe if (dbg != NULL && dbg->de_errhand != NULL) {
8807dc1947SRichard Lowe errptr = (Dwarf_Error)
8907dc1947SRichard Lowe _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_Error_s));
9007dc1947SRichard Lowe if (errptr == NULL) {
9107dc1947SRichard Lowe fprintf(stderr,
92*4d9fdb46SRobert Mustacchi "Could not allocate Dwarf_Error structure\n");
9307dc1947SRichard Lowe abort();
9407dc1947SRichard Lowe }
95*4d9fdb46SRobert Mustacchi errptr->er_errval = (Dwarf_Signed) errval;
9607dc1947SRichard Lowe dbg->de_errhand(errptr, dbg->de_errarg);
9707dc1947SRichard Lowe return;
9849d3bc91SRichard Lowe }
9949d3bc91SRichard Lowe
10049d3bc91SRichard Lowe abort();
10149d3bc91SRichard Lowe }
102