dwarf_cu.c revision 1.2
1/*	$NetBSD: dwarf_cu.c,v 1.2 2014/03/09 16:58:03 christos Exp $	*/
2
3/*-
4 * Copyright (c) 2007 John Birrell (jb@freebsd.org)
5 * All rights reserved.
6 *
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.
15 *
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.
27 */
28
29#include "_libdwarf.h"
30
31__RCSID("$NetBSD: dwarf_cu.c,v 1.2 2014/03/09 16:58:03 christos Exp $");
32ELFTC_VCSID("Id: dwarf_cu.c 2072 2011-10-27 03:26:49Z jkoshy ");
33
34int
35dwarf_next_cu_header_b(Dwarf_Debug dbg, Dwarf_Unsigned *cu_length,
36    Dwarf_Half *cu_version, Dwarf_Off *cu_abbrev_offset,
37    Dwarf_Half *cu_pointer_size, Dwarf_Half *cu_offset_size,
38    Dwarf_Half *cu_extension_size, Dwarf_Unsigned *cu_next_offset,
39    Dwarf_Error *error)
40{
41	Dwarf_CU cu;
42	int ret;
43
44	if (dbg == NULL) {
45		DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
46		return (DW_DLV_ERROR);
47	}
48
49	if (dbg->dbg_cu_current == NULL)
50		ret = _dwarf_info_first_cu(dbg, error);
51	else
52		ret = _dwarf_info_next_cu(dbg, error);
53
54	if (ret == DW_DLE_NO_ENTRY) {
55		DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
56		return (DW_DLV_NO_ENTRY);
57	} else if (ret != DW_DLE_NONE)
58		return (DW_DLV_ERROR);
59
60	if (dbg->dbg_cu_current == NULL) {
61		DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
62		return (DW_DLV_NO_ENTRY);
63	}
64	cu = dbg->dbg_cu_current;
65
66	if (cu_length)
67		*cu_length = cu->cu_length;
68	if (cu_version)
69		*cu_version = cu->cu_version;
70	if (cu_abbrev_offset)
71		*cu_abbrev_offset = (Dwarf_Off) cu->cu_abbrev_offset;
72	if (cu_pointer_size)
73		*cu_pointer_size = cu->cu_pointer_size;
74	if (cu_offset_size) {
75		if (cu->cu_length_size == 4)
76			*cu_offset_size = 4;
77		else
78			*cu_offset_size = 8;
79	}
80	if (cu_extension_size) {
81		if (cu->cu_length_size == 4)
82			*cu_extension_size = 0;
83		else
84			*cu_extension_size = 4;
85	}
86	if (cu_next_offset)
87		*cu_next_offset	= dbg->dbg_cu_current->cu_next_offset;
88
89	return (DW_DLV_OK);
90}
91
92int
93dwarf_next_cu_header(Dwarf_Debug dbg, Dwarf_Unsigned *cu_length,
94    Dwarf_Half *cu_version, Dwarf_Off *cu_abbrev_offset,
95    Dwarf_Half *cu_pointer_size, Dwarf_Unsigned *cu_next_offset,
96    Dwarf_Error *error)
97{
98
99	return (dwarf_next_cu_header_b(dbg, cu_length, cu_version,
100	    cu_abbrev_offset, cu_pointer_size, NULL, NULL, cu_next_offset,
101	    error));
102}
103