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