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