Remove building with NOCRYPTO option
[minix3.git] / external / bsd / elftoolchain / dist / libdwarf / dwarf_arange.c
blob75dc218f389e78ffd8082e3f0cc74cb6f49b982a
1 /* $NetBSD: dwarf_arange.c,v 1.2 2014/03/09 16:58:03 christos Exp $ */
3 /*-
4 * Copyright (c) 2009,2011 Kai Wang
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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
26 * SUCH DAMAGE.
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 ");
34 int
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;
58 return (DW_DLV_OK);
61 int
62 dwarf_get_arange(Dwarf_Arange *arlist, Dwarf_Unsigned arange_cnt,
63 Dwarf_Addr addr, Dwarf_Arange *ret_arange, Dwarf_Error *error)
65 Dwarf_Arange ar;
66 Dwarf_Debug dbg;
67 int i;
69 if (arlist == NULL) {
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++) {
82 ar = arlist[i];
83 if (addr >= ar->ar_address && addr < ar->ar_address +
84 ar->ar_range) {
85 *ret_arange = ar;
86 return (DW_DLV_OK);
90 DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
92 return (DW_DLV_NO_ENTRY);
95 int
96 dwarf_get_cu_die_offset(Dwarf_Arange ar, Dwarf_Off *ret_offset,
97 Dwarf_Error *error)
99 Dwarf_CU cu;
100 Dwarf_ArangeSet as;
102 if (ar == NULL) {
103 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
104 return (DW_DLV_ERROR);
107 as = ar->ar_as;
108 assert(as != NULL);
109 cu = as->as_cu;
110 assert(cu != NULL);
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;
119 return (DW_DLV_OK);
123 dwarf_get_arange_cu_header_offset(Dwarf_Arange ar, Dwarf_Off *ret_offset,
124 Dwarf_Error *error)
126 Dwarf_ArangeSet as;
128 if (ar == NULL) {
129 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
130 return (DW_DLV_ERROR);
133 as = ar->ar_as;
134 assert(as != NULL);
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;
143 return (DW_DLV_OK);
147 dwarf_get_arange_info(Dwarf_Arange ar, Dwarf_Addr *start,
148 Dwarf_Unsigned *length, Dwarf_Off *cu_die_offset, Dwarf_Error *error)
150 Dwarf_CU cu;
151 Dwarf_ArangeSet as;
153 if (ar == NULL) {
154 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
155 return (DW_DLV_ERROR);
158 as = ar->ar_as;
159 assert(as != NULL);
160 cu = as->as_cu;
161 assert(cu != NULL);
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;
173 return (DW_DLV_OK);