1/* 2 3 Copyright (C) 2000,2002,2004,2005,2006 Silicon Graphics, Inc. All Rights Reserved. 4 5 This program is free software; you can redistribute it and/or modify it 6 under the terms of version 2.1 of the GNU Lesser General Public License 7 as published by the Free Software Foundation. 8 9 This program is distributed in the hope that it would be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 13 Further, this software is distributed without any warranty that it is 14 free of the rightful claim of any third person regarding infringement 15 or the like. Any license provided herein, whether implied or 16 otherwise, applies only to this software file. Patent licenses, if 17 any, provided herein do not apply to combinations of this program with 18 other software, or any other product whatsoever. 19 20 You should have received a copy of the GNU Lesser General Public 21 License along with this program; if not, write the Free Software 22 Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, 23 USA. 24 25 Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, 26 Mountain View, CA 94043, or: 27 28 http://www.sgi.com 29 30 For further information regarding this notice, see: 31 32 http://oss.sgi.com/projects/GenInfo/NoticeExplan 33 34*/ 35 36/* This source file used for SGI-IRIX rqs processing. 37 Unused otherwise. 38*/ 39 40 41#include "config.h" 42#include "dwarf_incl.h" 43#include <stdio.h> 44#include "dwarf_line.h" 45#ifdef HAVE_ALLOCA_H 46#include <alloca.h> 47#endif 48 49 50 51/* 52 Return DW_DLV_OK or, if error, 53 DW_DLV_ERROR. 54 55 Thru pointers, return 2 arrays and a count 56 for rqs. 57*/ 58int 59_dwarf_line_address_offsets(Dwarf_Debug dbg, 60 Dwarf_Die die, 61 Dwarf_Addr ** addrs, 62 Dwarf_Off ** offs, 63 Dwarf_Unsigned * returncount, 64 Dwarf_Error * err) 65{ 66 Dwarf_Addr *laddrs; 67 Dwarf_Off *loffsets; 68 Dwarf_Signed lcount; 69 Dwarf_Signed i; 70 int res; 71 Dwarf_Line *linebuf; 72 73 res = _dwarf_internal_srclines(die, &linebuf, &lcount, /* addrlist= 74 */ true, 75 /* linelist= */ false, err); 76 if (res != DW_DLV_OK) { 77 return res; 78 } 79 laddrs = (Dwarf_Addr *) 80 _dwarf_get_alloc(dbg, DW_DLA_ADDR, lcount); 81 if (laddrs == NULL) { 82 dwarf_srclines_dealloc(dbg, linebuf, lcount); 83 _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL); 84 return (DW_DLV_ERROR); 85 } 86 loffsets = (Dwarf_Off *) 87 _dwarf_get_alloc(dbg, DW_DLA_ADDR, lcount); 88 if (loffsets == NULL) { 89 dwarf_srclines_dealloc(dbg, linebuf, lcount); 90 /* We already allocated what laddrs points at, so we'e better 91 deallocate that space since we are not going to return the 92 pointer to the caller. */ 93 dwarf_dealloc(dbg, laddrs, DW_DLA_ADDR); 94 _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL); 95 return (DW_DLV_ERROR); 96 } 97 98 for (i = 0; i < lcount; i++) { 99 laddrs[i] = linebuf[i]->li_address; 100 loffsets[i] = linebuf[i]->li_addr_line.li_offset; 101 } 102 dwarf_srclines_dealloc(dbg, linebuf, lcount); 103 *returncount = lcount; 104 *offs = loffsets; 105 *addrs = laddrs; 106 return DW_DLV_OK; 107} 108 109/* 110 It's impossible for callers of dwarf_srclines() to get to and 111 free all the resources (in particular, the li_context and its 112 lc_file_entries). 113 So this function, new July 2005, does it. 114*/ 115