1 /*
2 
3   Copyright (C) 2000-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 
38 
39 #include "config.h"
40 #include "dwarf_incl.h"
41 #include <stdio.h>
42 #include "dwarf_weaks.h"
43 #include "dwarf_global.h"
44 
45 int
46 dwarf_get_weaks(Dwarf_Debug dbg,
47     Dwarf_Weak ** weaks,
48     Dwarf_Signed * ret_weak_count, Dwarf_Error * error)
49 {
50     int res = _dwarf_load_section(dbg, &dbg->de_debug_weaknames,error);
51     if (res != DW_DLV_OK) {
52         return res;
53     }
54 
55     return _dwarf_internal_get_pubnames_like_data(dbg,
56         dbg->de_debug_weaknames.dss_data,
57         dbg->de_debug_weaknames.dss_size,
58         (Dwarf_Global **) weaks, /* Type punning for sections
59             with identical format. */
60         ret_weak_count,
61         error,
62         DW_DLA_WEAK_CONTEXT,
63         DW_DLA_WEAK,
64         DW_DLE_DEBUG_WEAKNAMES_LENGTH_BAD,
65         DW_DLE_DEBUG_WEAKNAMES_VERSION_ERROR);
66 }
67 
68 /* Deallocating fully requires deallocating the list
69    and all entries.  But some internal data is
70    not exposed, so we need a function with internal knowledge.
71 */
72 
73 void
74 dwarf_weaks_dealloc(Dwarf_Debug dbg, Dwarf_Weak * dwgl,
75     Dwarf_Signed count)
76 {
77     _dwarf_internal_globals_dealloc(dbg, (Dwarf_Global *) dwgl,
78         count,
79         DW_DLA_WEAK_CONTEXT,
80         DW_DLA_WEAK, DW_DLA_LIST);
81     return;
82 }
83 
84 
85 
86 int
87 dwarf_weakname(Dwarf_Weak weak_in, char **ret_name, Dwarf_Error * error)
88 {
89     Dwarf_Global weak = (Dwarf_Global) weak_in;
90 
91     if (weak == NULL) {
92         _dwarf_error(NULL, error, DW_DLE_WEAK_NULL);
93         return (DW_DLV_ERROR);
94     }
95     *ret_name = (char *) (weak->gl_name);
96     return DW_DLV_OK;
97 }
98 
99 
100 int
101 dwarf_weak_die_offset(Dwarf_Weak weak_in,
102     Dwarf_Off * weak_off, Dwarf_Error * error)
103 {
104     Dwarf_Global weak = (Dwarf_Global) weak_in;
105 
106     return dwarf_global_die_offset(weak, weak_off, error);
107 }
108 
109 
110 int
111 dwarf_weak_cu_offset(Dwarf_Weak weak_in,
112     Dwarf_Off * weak_off, Dwarf_Error * error)
113 {
114     Dwarf_Global weak = (Dwarf_Global) weak_in;
115 
116     return dwarf_global_cu_offset(weak, weak_off, error);
117 }
118 
119 
120 int
121 dwarf_weak_name_offsets(Dwarf_Weak weak_in,
122     char **weak_name,
123     Dwarf_Off * die_offset,
124     Dwarf_Off * cu_offset, Dwarf_Error * error)
125 {
126     Dwarf_Global weak = (Dwarf_Global) weak_in;
127 
128     return dwarf_global_name_offsets(weak,
129         weak_name, die_offset, cu_offset, error);
130 }
131