xref: /titanic_50/usr/src/lib/libdwarf/common/dwarf_vars.c (revision f3e7f55e73a39377d55a030f124cc86b3b66a9cc)
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 
38 
39 #include "config.h"
40 #include "dwarf_incl.h"
41 #include <stdio.h>
42 #include "dwarf_vars.h"
43 #include "dwarf_global.h"
44 
45 int
dwarf_get_vars(Dwarf_Debug dbg,Dwarf_Var ** vars,Dwarf_Signed * ret_var_count,Dwarf_Error * error)46 dwarf_get_vars(Dwarf_Debug dbg,
47     Dwarf_Var ** vars,
48     Dwarf_Signed * ret_var_count, Dwarf_Error * error)
49 {
50     int res = _dwarf_load_section(dbg, &dbg->de_debug_varnames,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_varnames.dss_data,
57         dbg->de_debug_varnames.dss_size,
58         (Dwarf_Global **) vars, /* Type punning for sections
59             with identical format. */
60         ret_var_count,
61         error,
62         DW_DLA_VAR_CONTEXT,
63         DW_DLA_VAR,
64         DW_DLE_DEBUG_VARNAMES_LENGTH_BAD,
65         DW_DLE_DEBUG_VARNAMES_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
dwarf_vars_dealloc(Dwarf_Debug dbg,Dwarf_Var * dwgl,Dwarf_Signed count)74 dwarf_vars_dealloc(Dwarf_Debug dbg, Dwarf_Var * dwgl,
75                    Dwarf_Signed count)
76 {
77     _dwarf_internal_globals_dealloc(dbg, (Dwarf_Global *) dwgl,
78         count,
79         DW_DLA_VAR_CONTEXT,
80         DW_DLA_VAR, DW_DLA_LIST);
81     return;
82 }
83 
84 
85 int
dwarf_varname(Dwarf_Var var_in,char ** ret_varname,Dwarf_Error * error)86 dwarf_varname(Dwarf_Var var_in, char **ret_varname, Dwarf_Error * error)
87 {
88     Dwarf_Global var = (Dwarf_Global) var_in;
89 
90     if (var == NULL) {
91         _dwarf_error(NULL, error, DW_DLE_VAR_NULL);
92         return (DW_DLV_ERROR);
93     }
94 
95     *ret_varname = (char *) (var->gl_name);
96     return DW_DLV_OK;
97 }
98 
99 
100 int
dwarf_var_die_offset(Dwarf_Var var_in,Dwarf_Off * returned_offset,Dwarf_Error * error)101 dwarf_var_die_offset(Dwarf_Var var_in,
102         Dwarf_Off * returned_offset, Dwarf_Error * error)
103 {
104     Dwarf_Global var = (Dwarf_Global) var_in;
105 
106     return dwarf_global_die_offset(var, returned_offset, error);
107 
108 }
109 
110 
111 int
dwarf_var_cu_offset(Dwarf_Var var_in,Dwarf_Off * returned_offset,Dwarf_Error * error)112 dwarf_var_cu_offset(Dwarf_Var var_in,
113                     Dwarf_Off * returned_offset, Dwarf_Error * error)
114 {
115     Dwarf_Global var = (Dwarf_Global) var_in;
116 
117     return dwarf_global_cu_offset(var, returned_offset, error);
118 }
119 
120 
121 int
dwarf_var_name_offsets(Dwarf_Var var_in,char ** returned_name,Dwarf_Off * die_offset,Dwarf_Off * cu_offset,Dwarf_Error * error)122 dwarf_var_name_offsets(Dwarf_Var var_in,
123         char **returned_name,
124         Dwarf_Off * die_offset,
125         Dwarf_Off * cu_offset, Dwarf_Error * error)
126 {
127     Dwarf_Global var = (Dwarf_Global) var_in;
128 
129     return
130         dwarf_global_name_offsets(var,
131             returned_name, die_offset, cu_offset,
132             error);
133 }
134