2 * Copyright (c) 2009,2011 Kai Wang
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include "_libdwarf.h"
29 ELFTC_VCSID("$Id: dwarf_arange.c 2072 2011-10-27 03:26:49Z jkoshy $");
32 dwarf_get_aranges(Dwarf_Debug dbg, Dwarf_Arange **arlist,
33 Dwarf_Signed *ret_arange_cnt, Dwarf_Error *error)
36 if (dbg == NULL || arlist == NULL || ret_arange_cnt == NULL) {
37 DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
38 return (DW_DLV_ERROR);
41 if (dbg->dbg_arange_cnt == 0) {
42 if (_dwarf_arange_init(dbg, error) != DW_DLE_NONE)
43 return (DW_DLV_ERROR);
44 if (dbg->dbg_arange_cnt == 0) {
45 DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
46 return (DW_DLV_NO_ENTRY);
50 assert(dbg->dbg_arange_array != NULL);
52 *arlist = dbg->dbg_arange_array;
53 *ret_arange_cnt = dbg->dbg_arange_cnt;
59 dwarf_get_arange(Dwarf_Arange *arlist, Dwarf_Unsigned arange_cnt,
60 Dwarf_Addr addr, Dwarf_Arange *ret_arange, Dwarf_Error *error)
67 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
68 return (DW_DLV_ERROR);
71 dbg = (*arlist)->ar_as->as_cu->cu_dbg;
73 if (ret_arange == NULL || arange_cnt == 0) {
74 DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
75 return (DW_DLV_ERROR);
78 for (i = 0; (Dwarf_Unsigned)i < arange_cnt; i++) {
80 if (addr >= ar->ar_address && addr < ar->ar_address +
87 DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
89 return (DW_DLV_NO_ENTRY);
93 dwarf_get_cu_die_offset(Dwarf_Arange ar, Dwarf_Off *ret_offset,
100 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
101 return (DW_DLV_ERROR);
109 if (ret_offset == NULL) {
110 DWARF_SET_ERROR(cu->cu_dbg, error, DW_DLE_ARGUMENT);
111 return (DW_DLV_ERROR);
114 *ret_offset = cu->cu_1st_offset;
120 dwarf_get_arange_cu_header_offset(Dwarf_Arange ar, Dwarf_Off *ret_offset,
126 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
127 return (DW_DLV_ERROR);
133 if (ret_offset == NULL) {
134 DWARF_SET_ERROR(as->as_cu->cu_dbg, error, DW_DLE_ARGUMENT);
135 return (DW_DLV_ERROR);
138 *ret_offset = as->as_cu_offset;
144 dwarf_get_arange_info(Dwarf_Arange ar, Dwarf_Addr *start,
145 Dwarf_Unsigned *length, Dwarf_Off *cu_die_offset, Dwarf_Error *error)
151 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
152 return (DW_DLV_ERROR);
160 if (start == NULL || length == NULL ||
161 cu_die_offset == NULL) {
162 DWARF_SET_ERROR(cu->cu_dbg, error, DW_DLE_ARGUMENT);
163 return (DW_DLV_ERROR);
166 *start = ar->ar_address;
167 *length = ar->ar_range;
168 *cu_die_offset = cu->cu_1st_offset;