1*0a6a1f1dSLionel Sambuc.\" $NetBSD: dwarf_expand_frame_instructions.3,v 1.2 2014/03/09 16:58:03 christos Exp $ 2*0a6a1f1dSLionel Sambuc.\" 3*0a6a1f1dSLionel Sambuc.\" Copyright (c) 2011 Kai Wang 4*0a6a1f1dSLionel Sambuc.\" All rights reserved. 5*0a6a1f1dSLionel Sambuc.\" 6*0a6a1f1dSLionel Sambuc.\" Redistribution and use in source and binary forms, with or without 7*0a6a1f1dSLionel Sambuc.\" modification, are permitted provided that the following conditions 8*0a6a1f1dSLionel Sambuc.\" are met: 9*0a6a1f1dSLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright 10*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer. 11*0a6a1f1dSLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright 12*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer in the 13*0a6a1f1dSLionel Sambuc.\" documentation and/or other materials provided with the distribution. 14*0a6a1f1dSLionel Sambuc.\" 15*0a6a1f1dSLionel Sambuc.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16*0a6a1f1dSLionel Sambuc.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17*0a6a1f1dSLionel Sambuc.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18*0a6a1f1dSLionel Sambuc.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19*0a6a1f1dSLionel Sambuc.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20*0a6a1f1dSLionel Sambuc.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21*0a6a1f1dSLionel Sambuc.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22*0a6a1f1dSLionel Sambuc.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23*0a6a1f1dSLionel Sambuc.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24*0a6a1f1dSLionel Sambuc.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25*0a6a1f1dSLionel Sambuc.\" SUCH DAMAGE. 26*0a6a1f1dSLionel Sambuc.\" 27*0a6a1f1dSLionel Sambuc.\" Id: dwarf_expand_frame_instructions.3 2122 2011-11-09 15:35:14Z jkoshy 28*0a6a1f1dSLionel Sambuc.\" 29*0a6a1f1dSLionel Sambuc.Dd November 9, 2011 30*0a6a1f1dSLionel Sambuc.Os 31*0a6a1f1dSLionel Sambuc.Dt DWARF_EXPAND_FRAME_INSTRUCTIONS 3 32*0a6a1f1dSLionel Sambuc.Sh NAME 33*0a6a1f1dSLionel Sambuc.Nm dwarf_expand_frame_instructions 34*0a6a1f1dSLionel Sambuc.Nd expand frame instructions 35*0a6a1f1dSLionel Sambuc.Sh LIBRARY 36*0a6a1f1dSLionel Sambuc.Lb libdwarf 37*0a6a1f1dSLionel Sambuc.Sh SYNOPSIS 38*0a6a1f1dSLionel Sambuc.In libdwarf.h 39*0a6a1f1dSLionel Sambuc.Ft int 40*0a6a1f1dSLionel Sambuc.Fo dwarf_expand_frame_instructions 41*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Cie cie" 42*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Ptr instructions" 43*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Unsigned len" 44*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Frame_Op **ret_ops" 45*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Signed *ret_opcnt" 46*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Error *error" 47*0a6a1f1dSLionel Sambuc.Fc 48*0a6a1f1dSLionel Sambuc.Sh DESCRIPTION 49*0a6a1f1dSLionel SambucFunction 50*0a6a1f1dSLionel Sambuc.Fn dwarf_expand_frame_instructions 51*0a6a1f1dSLionel Sambuctranslates DWARF frame instruction bytes into an array of 52*0a6a1f1dSLionel Sambuc.Vt Dwarf_Frame_Op 53*0a6a1f1dSLionel Sambucdescriptors. 54*0a6a1f1dSLionel Sambuc.Pp 55*0a6a1f1dSLionel SambucArgument 56*0a6a1f1dSLionel Sambuc.Ar cie 57*0a6a1f1dSLionel Sambucshould reference the CIE descriptor associated with the instructions 58*0a6a1f1dSLionel Sambucto be translated. 59*0a6a1f1dSLionel Sambuc.Pp 60*0a6a1f1dSLionel SambucArugment 61*0a6a1f1dSLionel Sambuc.Ar instructions 62*0a6a1f1dSLionel Sambucshould point to an array of frame instruction bytes, as 63*0a6a1f1dSLionel Sambucreturned by the functions 64*0a6a1f1dSLionel Sambuc.Xr dwarf_get_cie_info 3 65*0a6a1f1dSLionel Sambucor 66*0a6a1f1dSLionel Sambuc.Xr dwarf_get_fde_instr_bytes 3 . 67*0a6a1f1dSLionel Sambuc.Pp 68*0a6a1f1dSLionel SambucArgument 69*0a6a1f1dSLionel Sambuc.Ar len 70*0a6a1f1dSLionel Sambucshould specify the number of the frame instruction bytes to be 71*0a6a1f1dSLionel Sambuctranslated. 72*0a6a1f1dSLionel Sambuc.Pp 73*0a6a1f1dSLionel SambucArgument 74*0a6a1f1dSLionel Sambuc.Ar ret_ops 75*0a6a1f1dSLionel Sambucshould point to a location that will be set to a pointer to 76*0a6a1f1dSLionel Sambucan array of translated 77*0a6a1f1dSLionel Sambuc.Vt Dwarf_Frame_Op 78*0a6a1f1dSLionel Sambucdescriptors. 79*0a6a1f1dSLionel Sambuc.Pp 80*0a6a1f1dSLionel SambucArgument 81*0a6a1f1dSLionel Sambuc.Ar ret_opcnt 82*0a6a1f1dSLionel Sambucshould point to a location that will hold the total number of the 83*0a6a1f1dSLionel Sambucreturned descriptors. 84*0a6a1f1dSLionel Sambuc.Pp 85*0a6a1f1dSLionel SambucIf argument 86*0a6a1f1dSLionel Sambuc.Ar err 87*0a6a1f1dSLionel Sambucis not NULL, it will be used to store error information in case of an 88*0a6a1f1dSLionel Sambucerror. 89*0a6a1f1dSLionel Sambuc.Ss Memory Management 90*0a6a1f1dSLionel SambucThe memory area used for the descriptor array returned in argument 91*0a6a1f1dSLionel Sambuc.Ar ret_ops 92*0a6a1f1dSLionel Sambucis allocated by 93*0a6a1f1dSLionel Sambuc.Lb libdwarf . 94*0a6a1f1dSLionel SambucApplication code should use function 95*0a6a1f1dSLionel Sambuc.Xr dwarf_dealloc 3 96*0a6a1f1dSLionel Sambucwith type 97*0a6a1f1dSLionel Sambuc.Dv DW_DLA_FRAME_BLOCK 98*0a6a1f1dSLionel Sambucto free the memory area when the descriptor array is no longer needed. 99*0a6a1f1dSLionel Sambuc.Sh RETURN VALUES 100*0a6a1f1dSLionel SambucFunction 101*0a6a1f1dSLionel Sambuc.Fn dwarf_expand_frame_instructions 102*0a6a1f1dSLionel Sambucreturns 103*0a6a1f1dSLionel Sambuc.Dv DW_DLV_OK 104*0a6a1f1dSLionel Sambucwhen it succeeds. 105*0a6a1f1dSLionel SambucIn case of an error, it returns 106*0a6a1f1dSLionel Sambuc.Dv DW_DLV_ERROR 107*0a6a1f1dSLionel Sambucand sets the argument 108*0a6a1f1dSLionel Sambuc.Ar err . 109*0a6a1f1dSLionel Sambuc.Sh ERRORS 110*0a6a1f1dSLionel SambucFunction 111*0a6a1f1dSLionel Sambuc.Fn dwarf_expand_frame_instructions 112*0a6a1f1dSLionel Sambuccan fail with: 113*0a6a1f1dSLionel Sambuc.Bl -tag -width ".Bq Er DW_DLE_ARGUMENT" 114*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_ARGUMENT 115*0a6a1f1dSLionel SambucOne of the arguments 116*0a6a1f1dSLionel Sambuc.Ar cie , 117*0a6a1f1dSLionel Sambuc.Ar instructions , 118*0a6a1f1dSLionel Sambuc.Ar ret_ops 119*0a6a1f1dSLionel Sambucor 120*0a6a1f1dSLionel Sambuc.Ar ret_opcnt 121*0a6a1f1dSLionel Sambucwas NULL. 122*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_ARGUMENT 123*0a6a1f1dSLionel SambucArgument 124*0a6a1f1dSLionel Sambuc.Ar len 125*0a6a1f1dSLionel Sambucwas 0. 126*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_MEMORY 127*0a6a1f1dSLionel SambucAn out of memory condition was encountered during the execution of 128*0a6a1f1dSLionel Sambucthis function. 129*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_FRAME_INSTR_EXEC_ERROR 130*0a6a1f1dSLionel SambucAn unknown instruction was found in the instruction bytes provided 131*0a6a1f1dSLionel Sambucin argument 132*0a6a1f1dSLionel Sambuc.Ar instructions . 133*0a6a1f1dSLionel Sambuc.El 134*0a6a1f1dSLionel Sambuc.Sh EXAMPLE 135*0a6a1f1dSLionel SambucTo retrieve and expand the frame instructions for a given FDE 136*0a6a1f1dSLionel Sambucdescriptor, use: 137*0a6a1f1dSLionel Sambuc.Bd -literal -offset indent 138*0a6a1f1dSLionel SambucDwarf_Dbg dbg; 139*0a6a1f1dSLionel SambucDwarf_Cie cie; 140*0a6a1f1dSLionel SambucDwarf_Fde fde; 141*0a6a1f1dSLionel SambucDwarf_Ptr fde_inst; 142*0a6a1f1dSLionel SambucDwarf_Unsigned fde_instlen; 143*0a6a1f1dSLionel SambucDwarf_Frame_Op *ops; 144*0a6a1f1dSLionel SambucDwarf_Signed opcnt; 145*0a6a1f1dSLionel SambucDwarf_Error de; 146*0a6a1f1dSLionel Sambuc 147*0a6a1f1dSLionel Sambuc/* ... assuming `dbg` references a valid DWARF debugging context, 148*0a6a1f1dSLionel Sambuc `fde` references a valid FDE descriptor and `cie` holds the CIE 149*0a6a1f1dSLionel Sambuc descriptor associated with the FDE descriptor ... */ 150*0a6a1f1dSLionel Sambuc 151*0a6a1f1dSLionel Sambucif (dwarf_get_fde_instr_bytes(fde, &fde_inst, &fde_instlen, 152*0a6a1f1dSLionel Sambuc &de) != DW_DLV_OK) 153*0a6a1f1dSLionel Sambuc errx(EXIT_FAILURE, "dwarf_get_fde_instr_bytes failed: %s", 154*0a6a1f1dSLionel Sambuc dwarf_errmsg(de)); 155*0a6a1f1dSLionel Sambuc 156*0a6a1f1dSLionel Sambucif (dwarf_expand_frame_instructions(cie, fde_inst, fde_instlen, 157*0a6a1f1dSLionel Sambuc &ops, &opcnt, &de) != DW_DLV_OK) 158*0a6a1f1dSLionel Sambuc errx(EXIT_FAILURE, 159*0a6a1f1dSLionel Sambuc "dwarf_expand_frame_instructions failed: %s", 160*0a6a1f1dSLionel Sambuc dwarf_errmsg(de)); 161*0a6a1f1dSLionel Sambuc 162*0a6a1f1dSLionel Sambucfor (i = 0; i < opcnt; i++) { 163*0a6a1f1dSLionel Sambuc /* ... use ops[i] ... */ 164*0a6a1f1dSLionel Sambuc} 165*0a6a1f1dSLionel Sambuc 166*0a6a1f1dSLionel Sambuc/* Free the memory area when no longer needed. */ 167*0a6a1f1dSLionel Sambucdwarf_dealloc(dbg, ops, DW_DLA_FRAME_BLOCK); 168*0a6a1f1dSLionel Sambuc.Ed 169*0a6a1f1dSLionel Sambuc.Sh SEE ALSO 170*0a6a1f1dSLionel Sambuc.Xr dwarf 3 , 171*0a6a1f1dSLionel Sambuc.Xr dwarf_frame_instructions_dealloc 3 , 172*0a6a1f1dSLionel Sambuc.Xr dwarf_get_cie_info 3 , 173*0a6a1f1dSLionel Sambuc.Xr dwarf_get_cie_index 3 , 174*0a6a1f1dSLionel Sambuc.Xr dwarf_get_cie_of_fde , 175*0a6a1f1dSLionel Sambuc.Xr dwarf_get_fde_at_pc 3 , 176*0a6a1f1dSLionel Sambuc.Xr dwarf_get_fde_info_for_all_regs 3 , 177*0a6a1f1dSLionel Sambuc.Xr dwarf_get_fde_info_for_all_regs3 3 , 178*0a6a1f1dSLionel Sambuc.Xr dwarf_get_fde_info_for_cfa_reg3 3 , 179*0a6a1f1dSLionel Sambuc.Xr dwarf_get_fde_info_for_reg 3 , 180*0a6a1f1dSLionel Sambuc.Xr dwarf_get_fde_info_for_reg3 3 , 181*0a6a1f1dSLionel Sambuc.Xr dwarf_get_fde_instr_bytes 3 , 182*0a6a1f1dSLionel Sambuc.Xr dwarf_get_fde_list 3 , 183*0a6a1f1dSLionel Sambuc.Xr dwarf_get_fde_list_eh 3 , 184*0a6a1f1dSLionel Sambuc.Xr dwarf_get_fde_n 3 185