1*2de3b87aSKai Wang.\" Copyright (c) 2011 Kai Wang 2*2de3b87aSKai Wang.\" All rights reserved. 3*2de3b87aSKai Wang.\" 4*2de3b87aSKai Wang.\" Redistribution and use in source and binary forms, with or without 5*2de3b87aSKai Wang.\" modification, are permitted provided that the following conditions 6*2de3b87aSKai Wang.\" are met: 7*2de3b87aSKai Wang.\" 1. Redistributions of source code must retain the above copyright 8*2de3b87aSKai Wang.\" notice, this list of conditions and the following disclaimer. 9*2de3b87aSKai Wang.\" 2. Redistributions in binary form must reproduce the above copyright 10*2de3b87aSKai Wang.\" notice, this list of conditions and the following disclaimer in the 11*2de3b87aSKai Wang.\" documentation and/or other materials provided with the distribution. 12*2de3b87aSKai Wang.\" 13*2de3b87aSKai Wang.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14*2de3b87aSKai Wang.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15*2de3b87aSKai Wang.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16*2de3b87aSKai Wang.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17*2de3b87aSKai Wang.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18*2de3b87aSKai Wang.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19*2de3b87aSKai Wang.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20*2de3b87aSKai Wang.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21*2de3b87aSKai Wang.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22*2de3b87aSKai Wang.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23*2de3b87aSKai Wang.\" SUCH DAMAGE. 24*2de3b87aSKai Wang.\" 25*2de3b87aSKai Wang.\" $Id: dwarf_get_section_bytes.3 2071 2011-10-27 03:20:00Z jkoshy $ 26*2de3b87aSKai Wang.\" 27*2de3b87aSKai Wang.Dd August 26, 2011 28*2de3b87aSKai Wang.Os 29*2de3b87aSKai Wang.Dt DWARF_GET_SECTION_BYTES 3 30*2de3b87aSKai Wang.Sh NAME 31*2de3b87aSKai Wang.Nm dwarf_get_section_bytes 32*2de3b87aSKai Wang.Nd retrieve ELF section byte streams 33*2de3b87aSKai Wang.Sh LIBRARY 34*2de3b87aSKai Wang.Lb libdwarf 35*2de3b87aSKai Wang.Sh SYNOPSIS 36*2de3b87aSKai Wang.In libdwarf.h 37*2de3b87aSKai Wang.Ft Dwarf_Ptr 38*2de3b87aSKai Wang.Fo dwarf_get_section_bytes 39*2de3b87aSKai Wang.Fa "Dwarf_P_Debug dbg" 40*2de3b87aSKai Wang.Fa "Dwarf_Signed dwarf_section" 41*2de3b87aSKai Wang.Fa "Dwarf_Signed *elf_section_index" 42*2de3b87aSKai Wang.Fa "Dwarf_Unsigned *length" 43*2de3b87aSKai Wang.Fa "Dwarf_Error *err" 44*2de3b87aSKai Wang.Fc 45*2de3b87aSKai Wang.Sh DESCRIPTION 46*2de3b87aSKai WangFunction 47*2de3b87aSKai Wang.Fn dwarf_get_section_bytes 48*2de3b87aSKai Wangreturns the ELF section byte streams generated by a prior call 49*2de3b87aSKai Wangto function 50*2de3b87aSKai Wang.Xr dwarf_transform_to_disk_form 3 . 51*2de3b87aSKai Wang.Pp 52*2de3b87aSKai WangEach call to function 53*2de3b87aSKai Wang.Fn dwarf_get_section_bytes 54*2de3b87aSKai Wangwill return the byte stream for one ELF section. 55*2de3b87aSKai WangThe first call to this function will always return the first ELF 56*2de3b87aSKai Wangsection, and the subsequent calls will return the rest of sections 57*2de3b87aSKai Wangin the order when they were generated, until the last one. 58*2de3b87aSKai WangThe total number of sections generated is returned by the function 59*2de3b87aSKai Wang.Xr dwarf_transform_to_disk_form 3 . 60*2de3b87aSKai Wang.Pp 61*2de3b87aSKai WangArgument 62*2de3b87aSKai Wang.Ar dbg 63*2de3b87aSKai Wangshould reference a DWARF producer instance allocated using the 64*2de3b87aSKai Wangfunctions 65*2de3b87aSKai Wang.Xr dwarf_producer_init 3 66*2de3b87aSKai Wangor 67*2de3b87aSKai Wang.Xr dwarf_producer_init_b 3 . 68*2de3b87aSKai Wang.Pp 69*2de3b87aSKai WangArgument 70*2de3b87aSKai Wang.Ar dwarf_section 71*2de3b87aSKai Wangis currently ignored. 72*2de3b87aSKai Wang.Pp 73*2de3b87aSKai WangArgument 74*2de3b87aSKai Wang.Ar elf_section_index 75*2de3b87aSKai Wangshould point to a location which will be set to the section index value 76*2de3b87aSKai Wangof the returned ELF section. 77*2de3b87aSKai Wang.Pp 78*2de3b87aSKai WangArgument 79*2de3b87aSKai Wang.Ar length 80*2de3b87aSKai Wangshould point to a location which will hold the length in bytes of the 81*2de3b87aSKai Wangreturned ELF section. 82*2de3b87aSKai Wang.Pp 83*2de3b87aSKai WangIf argument 84*2de3b87aSKai Wang.Ar err 85*2de3b87aSKai Wangis not NULL, it will be used to store error information in case of an 86*2de3b87aSKai Wangerror. 87*2de3b87aSKai Wang.Ss Memory Management 88*2de3b87aSKai WangThe memory areas used for the returned ELF section byte streams should 89*2de3b87aSKai Wangbe freed using the function 90*2de3b87aSKai Wang.Fn dwarf_producer_finish . 91*2de3b87aSKai Wang.Sh RETURN VALUES 92*2de3b87aSKai WangOn success, function 93*2de3b87aSKai Wang.Fn dwarf_get_section_bytes 94*2de3b87aSKai Wangreturns a pointer to a ELF section byte stream. 95*2de3b87aSKai WangIn case of an error, function 96*2de3b87aSKai Wang.Fn dwarf_get_section_bytes 97*2de3b87aSKai Wangwill return NULL and set the argument 98*2de3b87aSKai Wang.Ar err . 99*2de3b87aSKai Wang.Sh ERRORS 100*2de3b87aSKai WangFunction 101*2de3b87aSKai Wang.Fn dwarf_get_section_bytes 102*2de3b87aSKai Wangcan fail with: 103*2de3b87aSKai Wang.Bl -tag -width ".Bq Er DW_DLE_NO_ENTRY" 104*2de3b87aSKai Wang.It Bq Er DW_DLE_ARGUMENT 105*2de3b87aSKai WangOne of the arguments 106*2de3b87aSKai Wang.Ar dbg , 107*2de3b87aSKai Wang.Ar elf_section_index , 108*2de3b87aSKai Wangor 109*2de3b87aSKai Wang.Ar length 110*2de3b87aSKai Wangwas NULL. 111*2de3b87aSKai Wang.It Bq Er DW_DLE_NO_ENTRY 112*2de3b87aSKai WangThere were no more ELF sections to retrieve, or the function was 113*2de3b87aSKai Wangcalled before a call to 114*2de3b87aSKai Wang.Xr dwarf_transform_to_disk_form 3 . 115*2de3b87aSKai Wang.El 116*2de3b87aSKai Wang.Sh EXAMPLES 117*2de3b87aSKai WangTo generate and retrieve ELF section byte streams, use: 118*2de3b87aSKai Wang.Bd -literal -offset indent 119*2de3b87aSKai WangDwarf_P_Debug dbg; 120*2de3b87aSKai WangDwarf_Signed count, i, sec_index; 121*2de3b87aSKai WangDwarf_Unsigned len; 122*2de3b87aSKai WangDwarf_Ptr bytes; 123*2de3b87aSKai WangDwarf_Error de; 124*2de3b87aSKai Wang 125*2de3b87aSKai Wang/* ... Assume that `dbg' refers to a DWARF producer instance, 126*2de3b87aSKai Wang * and that application code has added DWARF debugging 127*2de3b87aSKai Wang * information to the producer instance. ... 128*2de3b87aSKai Wang */ 129*2de3b87aSKai Wangif ((count = dwarf_transform_to_disk_form(dbg, &de)) == 130*2de3b87aSKai Wang DW_DLV_NOCOUNT) { 131*2de3b87aSKai Wang warnx("dwarf_transform_to_disk_form failed: %s", 132*2de3b87aSKai Wang dwarf_errmsg(-1)); 133*2de3b87aSKai Wang return; 134*2de3b87aSKai Wang} 135*2de3b87aSKai Wang 136*2de3b87aSKai Wang/* Retrieve section data. */ 137*2de3b87aSKai Wangfor (i = 0; i < count; i++) { 138*2de3b87aSKai Wang bytes = dwarf_get_section_bytes(dbg, i, &sec_index, &len, 139*2de3b87aSKai Wang &de); 140*2de3b87aSKai Wang if (bytes == NULL) { 141*2de3b87aSKai Wang warnx("dwarf_get_section_bytes failed: %s", 142*2de3b87aSKai Wang dwarf_errmsg(-1)); 143*2de3b87aSKai Wang continue; 144*2de3b87aSKai Wang } 145*2de3b87aSKai Wang /* ... use the returned byte stream ... */ 146*2de3b87aSKai Wang} 147*2de3b87aSKai Wang 148*2de3b87aSKai Wang/* Release resources. */ 149*2de3b87aSKai Wangdwarf_producer_finish(dbg, &de); 150*2de3b87aSKai Wang.Ed 151*2de3b87aSKai Wang.Sh SEE ALSO 152*2de3b87aSKai Wang.Xr dwarf 3 , 153*2de3b87aSKai Wang.Xr dwarf_reset_section_bytes 3 , 154*2de3b87aSKai Wang.Xr dwarf_producer_finish 3 , 155*2de3b87aSKai Wang.Xr dwarf_producer_init 3 , 156*2de3b87aSKai Wang.Xr dwarf_producer_init_b 3 , 157*2de3b87aSKai Wang.Xr dwarf_transform_to_disk_form 3 158