1174782Smarcel/*-
2174782Smarcel * Copyright (c) 2010 Kai Wang
3174782Smarcel * All rights reserved.
4174782Smarcel *
5174782Smarcel * Redistribution and use in source and binary forms, with or without
6174782Smarcel * modification, are permitted provided that the following conditions
7174782Smarcel * are met:
8174782Smarcel * 1. Redistributions of source code must retain the above copyright
9174782Smarcel *    notice, this list of conditions and the following disclaimer.
10174782Smarcel * 2. Redistributions in binary form must reproduce the above copyright
11174782Smarcel *    notice, this list of conditions and the following disclaimer in the
12174782Smarcel *    documentation and/or other materials provided with the distribution.
13174782Smarcel *
14174782Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15174782Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16174782Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17174782Smarcel * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18174782Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19174782Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20174782Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21174782Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22174782Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23174782Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24174782Smarcel * SUCH DAMAGE.
25174782Smarcel */
26174782Smarcel
27174782Smarcel#include "_libdwarf.h"
28174782Smarcel
29174782SmarcelELFTC_VCSID("$Id: dwarf_pro_sections.c 2074 2011-10-27 03:34:33Z jkoshy $");
30174782Smarcel
31174782SmarcelDwarf_Signed
32174782Smarceldwarf_transform_to_disk_form(Dwarf_P_Debug dbg, Dwarf_Error *error)
33174782Smarcel{
34174782Smarcel
35191447Smarcel	if (dbg == NULL) {
36191447Smarcel		DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
37191447Smarcel		return (DW_DLV_NOCOUNT);
38174782Smarcel	}
39174782Smarcel
40174782Smarcel	if (_dwarf_generate_sections(dbg, error) != DW_DLE_NONE)
41191447Smarcel		return (DW_DLV_NOCOUNT);
42190681Snwhitehorn
43190681Snwhitehorn	return (dbg->dbgp_seccnt);
44174782Smarcel}
45174782Smarcel
46174782SmarcelDwarf_Ptr
47190681Snwhitehorndwarf_get_section_bytes(Dwarf_P_Debug dbg, Dwarf_Signed dwarf_section,
48174782Smarcel    Dwarf_Signed *elf_section_index, Dwarf_Unsigned *length, Dwarf_Error *error)
49174782Smarcel{
50174782Smarcel	Dwarf_Ptr data;
51190681Snwhitehorn
52190681Snwhitehorn	(void) dwarf_section;	/* ignored. */
53190681Snwhitehorn
54257178Snwhitehorn	if (dbg == NULL || elf_section_index == NULL || length == NULL) {
55190681Snwhitehorn		DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
56190681Snwhitehorn		return (NULL);
57213307Snwhitehorn	}
58190681Snwhitehorn
59190681Snwhitehorn	if (dbg->dbgp_secpos == NULL) {
60190681Snwhitehorn		DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
61190681Snwhitehorn		return (NULL);
62190681Snwhitehorn	}
63174782Smarcel
64174782Smarcel	*elf_section_index = dbg->dbgp_secpos->ds_ndx;
65174782Smarcel	*length = dbg->dbgp_secpos->ds_size;
66174782Smarcel	data = dbg->dbgp_secpos->ds_data;
67174782Smarcel
68174782Smarcel	dbg->dbgp_secpos = STAILQ_NEXT(dbg->dbgp_secpos, ds_next);
69174782Smarcel
70213307Snwhitehorn	return (data);
71174782Smarcel}
72174782Smarcel
73213307Snwhitehornvoid
74213307Snwhitehorndwarf_reset_section_bytes(Dwarf_P_Debug dbg)
75190681Snwhitehorn{
76190681Snwhitehorn
77190681Snwhitehorn	assert(dbg != NULL);
78190681Snwhitehorn
79190681Snwhitehorn	dbg->dbgp_secpos = STAILQ_FIRST(&dbg->dbgp_seclist);
80190681Snwhitehorn	dbg->dbgp_drspos = STAILQ_FIRST(&dbg->dbgp_drslist);
81190681Snwhitehorn}
82190681Snwhitehorn