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