1 /* $NetBSD: dwarf_arange.c,v 1.2 2014/03/09 16:58:03 christos Exp $ */
4 * Copyright (c) 2009,2011 Kai Wang
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include "_libdwarf.h"
31 __RCSID("$NetBSD: dwarf_arange.c,v 1.2 2014/03/09 16:58:03 christos Exp $");
32 ELFTC_VCSID("Id: dwarf_arange.c 2072 2011-10-27 03:26:49Z jkoshy ");
35 dwarf_get_aranges(Dwarf_Debug dbg
, Dwarf_Arange
**arlist
,
36 Dwarf_Signed
*ret_arange_cnt
, Dwarf_Error
*error
)
39 if (dbg
== NULL
|| arlist
== NULL
|| ret_arange_cnt
== NULL
) {
40 DWARF_SET_ERROR(dbg
, error
, DW_DLE_ARGUMENT
);
41 return (DW_DLV_ERROR
);
44 if (dbg
->dbg_arange_cnt
== 0) {
45 if (_dwarf_arange_init(dbg
, error
) != DW_DLE_NONE
)
46 return (DW_DLV_ERROR
);
47 if (dbg
->dbg_arange_cnt
== 0) {
48 DWARF_SET_ERROR(dbg
, error
, DW_DLE_NO_ENTRY
);
49 return (DW_DLV_NO_ENTRY
);
53 assert(dbg
->dbg_arange_array
!= NULL
);
55 *arlist
= dbg
->dbg_arange_array
;
56 *ret_arange_cnt
= dbg
->dbg_arange_cnt
;
62 dwarf_get_arange(Dwarf_Arange
*arlist
, Dwarf_Unsigned arange_cnt
,
63 Dwarf_Addr addr
, Dwarf_Arange
*ret_arange
, Dwarf_Error
*error
)
70 DWARF_SET_ERROR(NULL
, error
, DW_DLE_ARGUMENT
);
71 return (DW_DLV_ERROR
);
74 dbg
= (*arlist
)->ar_as
->as_cu
->cu_dbg
;
76 if (ret_arange
== NULL
|| arange_cnt
== 0) {
77 DWARF_SET_ERROR(dbg
, error
, DW_DLE_ARGUMENT
);
78 return (DW_DLV_ERROR
);
81 for (i
= 0; (Dwarf_Unsigned
)i
< arange_cnt
; i
++) {
83 if (addr
>= ar
->ar_address
&& addr
< ar
->ar_address
+
90 DWARF_SET_ERROR(dbg
, error
, DW_DLE_NO_ENTRY
);
92 return (DW_DLV_NO_ENTRY
);
96 dwarf_get_cu_die_offset(Dwarf_Arange ar
, Dwarf_Off
*ret_offset
,
103 DWARF_SET_ERROR(NULL
, error
, DW_DLE_ARGUMENT
);
104 return (DW_DLV_ERROR
);
112 if (ret_offset
== NULL
) {
113 DWARF_SET_ERROR(cu
->cu_dbg
, error
, DW_DLE_ARGUMENT
);
114 return (DW_DLV_ERROR
);
117 *ret_offset
= cu
->cu_1st_offset
;
123 dwarf_get_arange_cu_header_offset(Dwarf_Arange ar
, Dwarf_Off
*ret_offset
,
129 DWARF_SET_ERROR(NULL
, error
, DW_DLE_ARGUMENT
);
130 return (DW_DLV_ERROR
);
136 if (ret_offset
== NULL
) {
137 DWARF_SET_ERROR(as
->as_cu
->cu_dbg
, error
, DW_DLE_ARGUMENT
);
138 return (DW_DLV_ERROR
);
141 *ret_offset
= as
->as_cu_offset
;
147 dwarf_get_arange_info(Dwarf_Arange ar
, Dwarf_Addr
*start
,
148 Dwarf_Unsigned
*length
, Dwarf_Off
*cu_die_offset
, Dwarf_Error
*error
)
154 DWARF_SET_ERROR(NULL
, error
, DW_DLE_ARGUMENT
);
155 return (DW_DLV_ERROR
);
163 if (start
== NULL
|| length
== NULL
||
164 cu_die_offset
== NULL
) {
165 DWARF_SET_ERROR(cu
->cu_dbg
, error
, DW_DLE_ARGUMENT
);
166 return (DW_DLV_ERROR
);
169 *start
= ar
->ar_address
;
170 *length
= ar
->ar_range
;
171 *cu_die_offset
= cu
->cu_1st_offset
;