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