2 * Copyright (c) 2007 John Birrell (jb@freebsd.org)
3 * Copyright (c) 2014 Kai Wang
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include "_libdwarf.h"
30 ELFTC_VCSID("$Id: dwarf_cu.c 3041 2014-05-18 15:11:03Z kaiwang27 $");
33 dwarf_next_cu_header_c(Dwarf_Debug dbg, Dwarf_Bool is_info,
34 Dwarf_Unsigned *cu_length, Dwarf_Half *cu_version,
35 Dwarf_Off *cu_abbrev_offset, Dwarf_Half *cu_pointer_size,
36 Dwarf_Half *cu_offset_size, Dwarf_Half *cu_extension_size,
37 Dwarf_Sig8 *type_signature, Dwarf_Unsigned *type_offset,
38 Dwarf_Unsigned *cu_next_offset, Dwarf_Error *error)
44 DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
45 return (DW_DLV_ERROR);
49 if (dbg->dbg_cu_current == NULL)
50 ret = _dwarf_info_first_cu(dbg, error);
52 ret = _dwarf_info_next_cu(dbg, error);
54 if (dbg->dbg_tu_current == NULL)
55 ret = _dwarf_info_first_tu(dbg, error);
57 ret = _dwarf_info_next_tu(dbg, error);
60 if (ret == DW_DLE_NO_ENTRY) {
61 DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
62 return (DW_DLV_NO_ENTRY);
63 } else if (ret != DW_DLE_NONE)
64 return (DW_DLV_ERROR);
67 if (dbg->dbg_cu_current == NULL) {
68 DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
69 return (DW_DLV_NO_ENTRY);
71 cu = dbg->dbg_cu_current;
73 if (dbg->dbg_tu_current == NULL) {
74 DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
75 return (DW_DLV_NO_ENTRY);
77 cu = dbg->dbg_tu_current;
81 *cu_length = cu->cu_length;
83 *cu_version = cu->cu_version;
85 *cu_abbrev_offset = (Dwarf_Off) cu->cu_abbrev_offset;
87 *cu_pointer_size = cu->cu_pointer_size;
89 if (cu->cu_length_size == 4)
94 if (cu_extension_size) {
95 if (cu->cu_length_size == 4)
96 *cu_extension_size = 0;
98 *cu_extension_size = 4;
101 *cu_next_offset = cu->cu_next_offset;
105 *type_signature = cu->cu_type_sig;
107 *type_offset = cu->cu_type_offset;
115 dwarf_next_cu_header_b(Dwarf_Debug dbg, Dwarf_Unsigned *cu_length,
116 Dwarf_Half *cu_version, Dwarf_Off *cu_abbrev_offset,
117 Dwarf_Half *cu_pointer_size, Dwarf_Half *cu_offset_size,
118 Dwarf_Half *cu_extension_size, Dwarf_Unsigned *cu_next_offset,
122 return (dwarf_next_cu_header_c(dbg, 1, cu_length, cu_version,
123 cu_abbrev_offset, cu_pointer_size, cu_offset_size,
124 cu_extension_size, NULL, NULL, cu_next_offset, error));
128 dwarf_next_cu_header(Dwarf_Debug dbg, Dwarf_Unsigned *cu_length,
129 Dwarf_Half *cu_version, Dwarf_Off *cu_abbrev_offset,
130 Dwarf_Half *cu_pointer_size, Dwarf_Unsigned *cu_next_offset,
134 return (dwarf_next_cu_header_b(dbg, cu_length, cu_version,
135 cu_abbrev_offset, cu_pointer_size, NULL, NULL, cu_next_offset,
140 dwarf_next_types_section(Dwarf_Debug dbg, Dwarf_Error *error)
143 /* Free resource allocated for current .debug_types section. */
144 _dwarf_type_unit_cleanup(dbg);
145 dbg->dbg_types_loaded = 0;
146 dbg->dbg_types_off = 0;
148 /* Reset type unit pointer. */
149 dbg->dbg_tu_current = NULL;
151 /* Search for the next .debug_types section. */
152 dbg->dbg_types_sec = _dwarf_find_next_types_section(dbg,
155 if (dbg->dbg_types_sec == NULL) {
156 DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
157 return (DW_DLV_NO_ENTRY);