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