1*7fd79137SRobert Mustacchi /*
2*7fd79137SRobert Mustacchi
3*7fd79137SRobert Mustacchi Copyright (C) 2000,2002,2004,2005,2006 Silicon Graphics, Inc. All Rights Reserved.
4*7fd79137SRobert Mustacchi Portions Copyright 2008-2010 David Anderson, Inc. 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 /* This source file used for SGI-IRIX rqs processing.
38*7fd79137SRobert Mustacchi Unused otherwise.
39*7fd79137SRobert Mustacchi */
40*7fd79137SRobert Mustacchi
41*7fd79137SRobert Mustacchi
42*7fd79137SRobert Mustacchi #include "config.h"
43*7fd79137SRobert Mustacchi #include "dwarf_incl.h"
44*7fd79137SRobert Mustacchi #include <stdio.h>
45*7fd79137SRobert Mustacchi #include "dwarf_line.h"
46*7fd79137SRobert Mustacchi
47*7fd79137SRobert Mustacchi /*
48*7fd79137SRobert Mustacchi Return DW_DLV_OK or, if error,
49*7fd79137SRobert Mustacchi DW_DLV_ERROR.
50*7fd79137SRobert Mustacchi
51*7fd79137SRobert Mustacchi Thru pointers, return 2 arrays and a count
52*7fd79137SRobert Mustacchi for rqs.
53*7fd79137SRobert Mustacchi */
54*7fd79137SRobert Mustacchi int
_dwarf_line_address_offsets(Dwarf_Debug dbg,Dwarf_Die die,Dwarf_Addr ** addrs,Dwarf_Off ** offs,Dwarf_Unsigned * returncount,Dwarf_Error * err)55*7fd79137SRobert Mustacchi _dwarf_line_address_offsets(Dwarf_Debug dbg,
56*7fd79137SRobert Mustacchi Dwarf_Die die,
57*7fd79137SRobert Mustacchi Dwarf_Addr ** addrs,
58*7fd79137SRobert Mustacchi Dwarf_Off ** offs,
59*7fd79137SRobert Mustacchi Dwarf_Unsigned * returncount,
60*7fd79137SRobert Mustacchi Dwarf_Error * err)
61*7fd79137SRobert Mustacchi {
62*7fd79137SRobert Mustacchi Dwarf_Addr *laddrs;
63*7fd79137SRobert Mustacchi Dwarf_Off *loffsets;
64*7fd79137SRobert Mustacchi Dwarf_Signed lcount;
65*7fd79137SRobert Mustacchi Dwarf_Signed i;
66*7fd79137SRobert Mustacchi int res;
67*7fd79137SRobert Mustacchi Dwarf_Line *linebuf;
68*7fd79137SRobert Mustacchi
69*7fd79137SRobert Mustacchi res = _dwarf_internal_srclines(die, &linebuf, &lcount, /* addrlist=
70*7fd79137SRobert Mustacchi */ true,
71*7fd79137SRobert Mustacchi /* linelist= */ false, err);
72*7fd79137SRobert Mustacchi if (res != DW_DLV_OK) {
73*7fd79137SRobert Mustacchi return res;
74*7fd79137SRobert Mustacchi }
75*7fd79137SRobert Mustacchi laddrs = (Dwarf_Addr *)
76*7fd79137SRobert Mustacchi _dwarf_get_alloc(dbg, DW_DLA_ADDR, lcount);
77*7fd79137SRobert Mustacchi if (laddrs == NULL) {
78*7fd79137SRobert Mustacchi dwarf_srclines_dealloc(dbg, linebuf, lcount);
79*7fd79137SRobert Mustacchi _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
80*7fd79137SRobert Mustacchi return (DW_DLV_ERROR);
81*7fd79137SRobert Mustacchi }
82*7fd79137SRobert Mustacchi loffsets = (Dwarf_Off *)
83*7fd79137SRobert Mustacchi _dwarf_get_alloc(dbg, DW_DLA_ADDR, lcount);
84*7fd79137SRobert Mustacchi if (loffsets == NULL) {
85*7fd79137SRobert Mustacchi dwarf_srclines_dealloc(dbg, linebuf, lcount);
86*7fd79137SRobert Mustacchi /* We already allocated what laddrs points at, so we'e better
87*7fd79137SRobert Mustacchi deallocate that space since we are not going to return the
88*7fd79137SRobert Mustacchi pointer to the caller. */
89*7fd79137SRobert Mustacchi dwarf_dealloc(dbg, laddrs, DW_DLA_ADDR);
90*7fd79137SRobert Mustacchi _dwarf_error(dbg, err, DW_DLE_ALLOC_FAIL);
91*7fd79137SRobert Mustacchi return (DW_DLV_ERROR);
92*7fd79137SRobert Mustacchi }
93*7fd79137SRobert Mustacchi
94*7fd79137SRobert Mustacchi for (i = 0; i < lcount; i++) {
95*7fd79137SRobert Mustacchi laddrs[i] = linebuf[i]->li_address;
96*7fd79137SRobert Mustacchi loffsets[i] = linebuf[i]->li_addr_line.li_offset;
97*7fd79137SRobert Mustacchi }
98*7fd79137SRobert Mustacchi dwarf_srclines_dealloc(dbg, linebuf, lcount);
99*7fd79137SRobert Mustacchi *returncount = lcount;
100*7fd79137SRobert Mustacchi *offs = loffsets;
101*7fd79137SRobert Mustacchi *addrs = laddrs;
102*7fd79137SRobert Mustacchi return DW_DLV_OK;
103*7fd79137SRobert Mustacchi }
104*7fd79137SRobert Mustacchi
105*7fd79137SRobert Mustacchi /*
106*7fd79137SRobert Mustacchi It's impossible for callers of dwarf_srclines() to get to and
107*7fd79137SRobert Mustacchi free all the resources (in particular, the li_context and its
108*7fd79137SRobert Mustacchi lc_file_entries).
109*7fd79137SRobert Mustacchi So this function, new July 2005, does it.
110*7fd79137SRobert Mustacchi */
111