xref: /illumos-gate/usr/src/lib/libdwarf/common/dwarf_pubtypes.c (revision 856f710c9dc323b39da5935194d7928ffb99b67f)
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   Contact information:  Silicon Graphics, Inc., 1500 Crittenden Lane,
27   Mountain View, CA 94043, or:
28 
29   http://www.sgi.com
30 
31   For further information regarding this notice, see:
32 
33   http://oss.sgi.com/projects/GenInfo/NoticeExplan
34 
35 */
36 
37 /* Reads DWARF3 .debug_pubtypes section. */
38 
39 
40 #include "config.h"
41 #include "dwarf_incl.h"
42 #include <stdio.h>
43 #include "dwarf_types.h"
44 #include "dwarf_global.h"
45 
46 int
47 dwarf_get_pubtypes(Dwarf_Debug dbg,
48     Dwarf_Type ** types,
49     Dwarf_Signed * ret_type_count, Dwarf_Error * error)
50 {
51     int res = _dwarf_load_section(dbg, &dbg->de_debug_pubtypes,error);
52     if (res != DW_DLV_OK) {
53         return res;
54     }
55 
56     return _dwarf_internal_get_pubnames_like_data(dbg,
57         dbg->de_debug_pubtypes.dss_data,
58         dbg->de_debug_pubtypes.dss_size,
59         (Dwarf_Global **) types, /* Type punning for sections
60             with identical format. */
61         ret_type_count, error,
62         DW_DLA_PUBTYPES_CONTEXT,
63         DW_DLA_GLOBAL, /* We don't have DW_DLA_PUBTYPES,
64             so use DW_DLA_GLOBAL. */
65         DW_DLE_DEBUG_PUBTYPES_LENGTH_BAD,
66         DW_DLE_DEBUG_PUBTYPES_VERSION_ERROR);
67 }
68 
69 /* Deallocating fully requires deallocating the list
70    and all entries.  But some internal data is
71    not exposed, so we need a function with internal knowledge.
72 */
73 
74 void
75 dwarf_pubtypes_dealloc(Dwarf_Debug dbg, Dwarf_Type * dwgl,
76     Dwarf_Signed count)
77 {
78     _dwarf_internal_globals_dealloc(dbg,
79         (Dwarf_Global *) dwgl,
80         count,
81         DW_DLA_PUBTYPES_CONTEXT,
82         DW_DLA_GLOBAL, /* We don't have DW_DLA_PUBTYPES,
83             so use DW_DLA_GLOBAL. */
84         DW_DLA_LIST);
85     return;
86 }
87 
88 
89 
90 int
91 dwarf_pubtypename(Dwarf_Type type_in, char **ret_name,
92     Dwarf_Error * error)
93 {
94     Dwarf_Global type = (Dwarf_Global) type_in;
95     if (type == NULL) {
96         _dwarf_error(NULL, error, DW_DLE_TYPE_NULL);
97         return (DW_DLV_ERROR);
98     }
99     *ret_name = (char *) (type->gl_name);
100     return DW_DLV_OK;
101 }
102 
103 
104 int
105 dwarf_pubtype_type_die_offset(Dwarf_Type type_in,
106     Dwarf_Off * ret_offset,
107     Dwarf_Error * error)
108 {
109     Dwarf_Global type = (Dwarf_Global) type_in;
110 
111     return dwarf_global_die_offset(type, ret_offset, error);
112 }
113 
114 
115 int
116 dwarf_pubtype_cu_offset(Dwarf_Type type_in,
117     Dwarf_Off * ret_offset, Dwarf_Error * error)
118 {
119     Dwarf_Global type = (Dwarf_Global) type_in;
120 
121     return dwarf_global_cu_offset(type, ret_offset, error);
122 
123 }
124 
125 
126 int
127 dwarf_pubtype_name_offsets(Dwarf_Type type_in,
128     char **returned_name,
129     Dwarf_Off * die_offset,
130     Dwarf_Off * cu_die_offset,
131     Dwarf_Error * error)
132 {
133     Dwarf_Global type = (Dwarf_Global) type_in;
134 
135     return dwarf_global_name_offsets(type,
136         returned_name,
137         die_offset, cu_die_offset, error);
138 }
139