1 /*
2 
3   Copyright (C) 2000,2002,2004,2005 Silicon Graphics, Inc.  All Rights Reserved.
4   Portions Copyright (C) 2009-2011 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 #include "config.h"
29 #include <stdio.h>
30 #include "dwarf_incl.h"
31 #include "dwarf_error.h"
32 #include "dwarf_vars.h"
33 #include "dwarf_global.h"
34 
35 int
dwarf_get_vars(Dwarf_Debug dbg,Dwarf_Var ** vars,Dwarf_Signed * ret_var_count,Dwarf_Error * error)36 dwarf_get_vars(Dwarf_Debug dbg,
37     Dwarf_Var ** vars,
38     Dwarf_Signed * ret_var_count, Dwarf_Error * error)
39 {
40     int res = _dwarf_load_section(dbg, &dbg->de_debug_varnames,error);
41     if (res != DW_DLV_OK) {
42         return res;
43     }
44     if (!dbg->de_debug_abbrev.dss_size) {
45         return (DW_DLV_NO_ENTRY);
46     }
47 
48     return _dwarf_internal_get_pubnames_like_data(dbg,
49         dbg->de_debug_varnames.dss_data,
50         dbg->de_debug_varnames.dss_size,
51         (Dwarf_Global **) vars, /* Type punning for sections
52             with identical format. */
53         ret_var_count,
54         error,
55         DW_DLA_VAR_CONTEXT,
56         DW_DLA_VAR,
57         DW_DLE_DEBUG_VARNAMES_LENGTH_BAD,
58         DW_DLE_DEBUG_VARNAMES_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 
66 void
dwarf_vars_dealloc(Dwarf_Debug dbg,Dwarf_Var * dwgl,Dwarf_Signed count)67 dwarf_vars_dealloc(Dwarf_Debug dbg, Dwarf_Var * dwgl,
68     Dwarf_Signed count)
69 {
70     _dwarf_internal_globals_dealloc(dbg, (Dwarf_Global *) dwgl,
71         count,
72         DW_DLA_VAR_CONTEXT,
73         DW_DLA_VAR, DW_DLA_LIST);
74     return;
75 }
76 
77 
78 int
dwarf_varname(Dwarf_Var var_in,char ** ret_varname,Dwarf_Error * error)79 dwarf_varname(Dwarf_Var var_in, char **ret_varname, Dwarf_Error * error)
80 {
81     Dwarf_Global var = (Dwarf_Global) var_in;
82 
83     if (var == NULL) {
84         _dwarf_error(NULL, error, DW_DLE_VAR_NULL);
85         return (DW_DLV_ERROR);
86     }
87 
88     *ret_varname = (char *) (var->gl_name);
89     return DW_DLV_OK;
90 }
91 
92 
93 int
dwarf_var_die_offset(Dwarf_Var var_in,Dwarf_Off * returned_offset,Dwarf_Error * error)94 dwarf_var_die_offset(Dwarf_Var var_in,
95     Dwarf_Off * returned_offset, Dwarf_Error * error)
96 {
97     Dwarf_Global var = (Dwarf_Global) var_in;
98 
99     return dwarf_global_die_offset(var, returned_offset, error);
100 
101 }
102 
103 
104 int
dwarf_var_cu_offset(Dwarf_Var var_in,Dwarf_Off * returned_offset,Dwarf_Error * error)105 dwarf_var_cu_offset(Dwarf_Var var_in,
106     Dwarf_Off * returned_offset, Dwarf_Error * error)
107 {
108     Dwarf_Global var = (Dwarf_Global) var_in;
109 
110     return dwarf_global_cu_offset(var, returned_offset, error);
111 }
112 
113 
114 int
dwarf_var_name_offsets(Dwarf_Var var_in,char ** returned_name,Dwarf_Off * die_offset,Dwarf_Off * cu_offset,Dwarf_Error * error)115 dwarf_var_name_offsets(Dwarf_Var var_in,
116     char **returned_name,
117     Dwarf_Off * die_offset,
118     Dwarf_Off * cu_offset, Dwarf_Error * error)
119 {
120     Dwarf_Global var = (Dwarf_Global) var_in;
121 
122     return
123         dwarf_global_name_offsets(var,
124             returned_name, die_offset, cu_offset,
125             error);
126 }
127