Debian Codegraph @

src/lib/libdwarfp/dwarf_pro_error.c

raw
1 /*
2
3 Copyright (C) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
4 Portions Copyright 2011-2020 David Anderson. All Rights Reserved.
5
6 This program is free software; you can redistribute it
7 and/or modify it under the terms of version 2.1 of the
8 GNU Lesser General Public License as published by the Free
9 Software Foundation.
10
11 This program is distributed in the hope that it would be
12 useful, but WITHOUT ANY WARRANTY; without even the implied
13 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE.
15
16 Further, this software is distributed without any warranty
17 that it is free of the rightful claim of any third person
18 regarding infringement or the like. Any license provided
19 herein, whether implied or otherwise, applies only to this
20 software file. Patent licenses, if any, provided herein
21 do not apply to combinations of this program with other
22 software, or any other product whatsoever.
23
24 You should have received a copy of the GNU Lesser General
25 Public License along with this program; if not, write the
26 Free Software Foundation, Inc., 51 Franklin Street - Fifth
27 Floor, Boston MA 02110-1301, USA.
28
29 */
30
31 #include <config.h>
32
33 #include <stddef.h> /* NULL */
34 #include <stdio.h> /* stderr fprintf() */
35
36 #include "dwarf.h"
37 #include "libdwarf.h"
38 #include "dwarf_base_types.h"
39 #include "libdwarfp.h"
40 #include "dwarf_pro_incl.h"
41 #include "dwarf_pro_opaque.h"
42 #include "dwarf_pro_error.h"
43 #include "dwarf_pro_alloc.h"
44
45 extern char *_dwarf_errmsgs[];
46
47 /*
48 This function performs error handling as described in the
49 libdwarf consumer document section 3. Dbg is the Dwarf_P_debug
50 structure being processed. Error is a pointer to the pointer
51 to the error descriptor that will be returned. Errval is an
52 error code listed in dwarf_error.h.
53
54 The error number may be retrieved from the Dwarf_Error
55 by calling dwarf_errno().
56 The error string implied by the error number may be retrieved
57 from the Dwarf_Error by calling dwarf_errmsg().
58 */
59 void
60 _dwarf_p_error(Dwarf_P_Debug dbg,
61 Dwarf_Error * error, Dwarf_Unsigned errval)
62 {
63 Dwarf_Error errptr;
64
65 if (errval > DW_DLE_LAST) {
66 /* We do not expect to ever see such an error number,
67 DW_DLE_LO_USER is not used. */
68 fprintf(stderr,"ERROR VALUE: %lu - %s\n",
69 (unsigned long) errval,
70 "this error value is unknown to libdwarf.");
71 }
72 /* Allow NULL dbg on entry, since sometimes
73 that can happen and we
74 want to report the upper-level error, not this one. */
75 if (error != NULL) {
76 errptr = (Dwarf_Error)
77 _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_Error_s));
78 if (errptr == NULL) {
79 fprintf(stderr,
80 "libdwarf: Out of memory. "
81 "Could not allocate Dwarf_Error structure "
82 "for error number %lu\n",
83 (unsigned long)errval);
84 return;
85 }
86 errptr->er_errval = (Dwarf_Signed) errval;
87 *error = errptr;
88 return;
89 }
90
91 if (dbg != NULL && dbg->de_errhand != NULL) {
92 errptr = (Dwarf_Error)
93 _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_Error_s));
94 if (errptr == NULL) {
95 fprintf(stderr,
96 "libdwarf: Out of memory.. "
97 "Could not allocate Dwarf_Error structure "
98 "for error number %lu\n",
99 (unsigned long)errval);
100 return;
101 }
102 errptr->er_errval = (Dwarf_Signed) errval;
103 dbg->de_errhand(errptr, dbg->de_errarg);
104 return;
105 }
106 /* No way to report. */
107 fprintf(stderr,
108 "libdwarf: "
109 "Could not return any error details for "
110 "error number %lu\n",
111 (unsigned long)errval);
112 return;
113 }