1 /*
2 Copyright (C) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
3 Portions Copyright (C) 2009-2011 David Anderson. All Rights Reserved.
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of version 2.1 of the GNU Lesser General Public License
7 as published by the Free Software Foundation.
8
9 This program is distributed in the hope that it would be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 Further, this software is distributed without any warranty that it is
14 free of the rightful claim of any third person regarding infringement
15 or the like. Any license provided herein, whether implied or
16 otherwise, applies only to this software file. Patent licenses, if
17 any, provided herein do not apply to combinations of this program with
18 other software, or any other product whatsoever.
19
20 You should have received a copy of the GNU Lesser General Public
21 License along with this program; if not, write the Free Software
22 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
23 USA.
24
25 */
26
27 #include "config.h"
28 #include <stdio.h>
29 #include "dwarf_incl.h"
30 #include "dwarf_error.h"
31 #include "dwarf_types.h"
32 #include "dwarf_global.h"
33
34 int
dwarf_get_types(Dwarf_Debug dbg,Dwarf_Type ** types,Dwarf_Signed * ret_type_count,Dwarf_Error * error)35 dwarf_get_types(Dwarf_Debug dbg,
36 Dwarf_Type ** types,
37 Dwarf_Signed * ret_type_count, Dwarf_Error * error)
38 {
39 int res = _dwarf_load_section(dbg, &dbg->de_debug_typenames,error);
40 if (res != DW_DLV_OK) {
41 return res;
42 }
43 if (!dbg->de_debug_typenames.dss_size) {
44 return (DW_DLV_NO_ENTRY);
45 }
46
47
48 return _dwarf_internal_get_pubnames_like_data(dbg,
49 dbg->de_debug_typenames.dss_data,
50 dbg->de_debug_typenames.dss_size,
51 (Dwarf_Global **) types, /* type punning, Dwarf_Type is
52 never a completed type */
53 ret_type_count,
54 error,
55 DW_DLA_TYPENAME_CONTEXT,
56 DW_DLA_TYPENAME,
57 DW_DLE_DEBUG_TYPENAMES_LENGTH_BAD,
58 DW_DLE_DEBUG_TYPENAMES_VERSION_ERROR);
59 }
60
61 /* Deallocating fully requires deallocating the list
62 and all entries. But some internal data is
63 not exposed, so we need a function with internal knowledge. */
64
65 void
dwarf_types_dealloc(Dwarf_Debug dbg,Dwarf_Type * dwgl,Dwarf_Signed count)66 dwarf_types_dealloc(Dwarf_Debug dbg, Dwarf_Type * dwgl,
67 Dwarf_Signed count)
68 {
69 _dwarf_internal_globals_dealloc(dbg, (Dwarf_Global *) dwgl,
70 count,
71 DW_DLA_TYPENAME_CONTEXT,
72 DW_DLA_TYPENAME, DW_DLA_LIST);
73 return;
74 }
75
76
77 int
dwarf_typename(Dwarf_Type type_in,char ** ret_name,Dwarf_Error * error)78 dwarf_typename(Dwarf_Type type_in, char **ret_name, Dwarf_Error * error)
79 {
80 Dwarf_Global type = (Dwarf_Global) type_in;
81
82 if (type == NULL) {
83 _dwarf_error(NULL, error, DW_DLE_TYPE_NULL);
84 return (DW_DLV_ERROR);
85 }
86
87 *ret_name = (char *) (type->gl_name);
88 return DW_DLV_OK;
89 }
90
91
92 int
dwarf_type_die_offset(Dwarf_Type type_in,Dwarf_Off * ret_offset,Dwarf_Error * error)93 dwarf_type_die_offset(Dwarf_Type type_in,
94 Dwarf_Off * ret_offset, Dwarf_Error * error)
95 {
96 Dwarf_Global type = (Dwarf_Global) type_in;
97
98 return dwarf_global_die_offset(type, ret_offset, error);
99 }
100
101
102 int
dwarf_type_cu_offset(Dwarf_Type type_in,Dwarf_Off * ret_offset,Dwarf_Error * error)103 dwarf_type_cu_offset(Dwarf_Type type_in,
104 Dwarf_Off * ret_offset, Dwarf_Error * error)
105 {
106 Dwarf_Global type = (Dwarf_Global) type_in;
107
108 return dwarf_global_cu_offset(type, ret_offset, error);
109 }
110
111
112 int
dwarf_type_name_offsets(Dwarf_Type type_in,char ** returned_name,Dwarf_Off * die_offset,Dwarf_Off * cu_die_offset,Dwarf_Error * error)113 dwarf_type_name_offsets(Dwarf_Type type_in,
114 char **returned_name,
115 Dwarf_Off * die_offset,
116 Dwarf_Off * cu_die_offset, Dwarf_Error * error)
117 {
118 Dwarf_Global type = (Dwarf_Global) type_in;
119 return dwarf_global_name_offsets(type,
120 returned_name,
121 die_offset, cu_die_offset, error);
122 }
123