1.\" $NetBSD: dwarf_expand_frame_instructions.3,v 1.6 2024/03/03 17:37:30 christos Exp $ 2.\" 3.\" Copyright (c) 2011 Kai Wang 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 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. 14.\" 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 25.\" SUCH DAMAGE. 26.\" 27.\" Id: dwarf_expand_frame_instructions.3 3962 2022-03-12 15:56:10Z jkoshy 28.\" 29.Dd November 9, 2011 30.Dt DWARF_EXPAND_FRAME_INSTRUCTIONS 3 31.Os 32.Sh NAME 33.Nm dwarf_expand_frame_instructions 34.Nd expand frame instructions 35.Sh LIBRARY 36.Lb libdwarf 37.Sh SYNOPSIS 38.In libdwarf.h 39.Ft int 40.Fo dwarf_expand_frame_instructions 41.Fa "Dwarf_Cie cie" 42.Fa "Dwarf_Ptr instructions" 43.Fa "Dwarf_Unsigned len" 44.Fa "Dwarf_Frame_Op **ret_ops" 45.Fa "Dwarf_Signed *ret_opcnt" 46.Fa "Dwarf_Error *error" 47.Fc 48.Sh DESCRIPTION 49Function 50.Fn dwarf_expand_frame_instructions 51translates DWARF frame instruction bytes into an array of 52.Vt Dwarf_Frame_Op 53descriptors. 54.Pp 55Argument 56.Fa cie 57should reference the CIE descriptor associated with the instructions 58to be translated. 59.Pp 60Arugment 61.Fa instructions 62should point to an array of frame instruction bytes, as 63returned by the functions 64.Xr dwarf_get_cie_info 3 65or 66.Xr dwarf_get_fde_instr_bytes 3 . 67.Pp 68Argument 69.Fa len 70should specify the number of the frame instruction bytes to be 71translated. 72.Pp 73Argument 74.Fa ret_ops 75should point to a location that will be set to a pointer to 76an array of translated 77.Vt Dwarf_Frame_Op 78descriptors. 79.Pp 80Argument 81.Fa ret_opcnt 82should point to a location that will hold the total number of the 83returned descriptors. 84.Pp 85If argument 86.Fa err 87is not 88.Dv NULL , 89it will be used to store error information in case of an error. 90.Ss Memory Management 91The memory area used for the descriptor array returned in argument 92.Fa ret_ops 93is allocated by 94.Lb libdwarf . 95Application code should use function 96.Xr dwarf_dealloc 3 97with type 98.Dv DW_DLA_FRAME_BLOCK 99to free the memory area when the descriptor array is no longer needed. 100.Sh RETURN VALUES 101Function 102.Fn dwarf_expand_frame_instructions 103returns 104.Dv DW_DLV_OK 105when it succeeds. 106In case of an error, it returns 107.Dv DW_DLV_ERROR 108and sets the argument 109.Fa err . 110.Sh EXAMPLES 111To retrieve and expand the frame instructions for a given FDE 112descriptor, use: 113.Bd -literal -offset indent 114Dwarf_Dbg dbg; 115Dwarf_Cie cie; 116Dwarf_Fde fde; 117Dwarf_Ptr fde_inst; 118Dwarf_Unsigned fde_instlen; 119Dwarf_Frame_Op *ops; 120Dwarf_Signed opcnt; 121Dwarf_Error de; 122 123/* ... assuming `dbg` references a valid DWARF debugging context, 124 `fde` references a valid FDE descriptor and `cie` holds the CIE 125 descriptor associated with the FDE descriptor ... */ 126 127if (dwarf_get_fde_instr_bytes(fde, &fde_inst, &fde_instlen, 128 &de) != DW_DLV_OK) 129 errx(EXIT_FAILURE, "dwarf_get_fde_instr_bytes failed: %s", 130 dwarf_errmsg(de)); 131 132if (dwarf_expand_frame_instructions(cie, fde_inst, fde_instlen, 133 &ops, &opcnt, &de) != DW_DLV_OK) 134 errx(EXIT_FAILURE, 135 "dwarf_expand_frame_instructions failed: %s", 136 dwarf_errmsg(de)); 137 138for (i = 0; i < opcnt; i++) { 139 /* ... use ops[i] ... */ 140} 141 142/* Free the memory area when no longer needed. */ 143dwarf_dealloc(dbg, ops, DW_DLA_FRAME_BLOCK); 144.Ed 145.Sh ERRORS 146Function 147.Fn dwarf_expand_frame_instructions 148can fail with: 149.Bl -tag -width ".Bq Er DW_DLE_ARGUMENT" 150.It Bq Er DW_DLE_ARGUMENT 151One of the arguments 152.Fa cie , 153.Fa instructions , 154.Fa ret_ops 155or 156.Fa ret_opcnt 157was 158.Dv NULL . 159.It Bq Er DW_DLE_ARGUMENT 160Argument 161.Fa len 162was 0. 163.It Bq Er DW_DLE_MEMORY 164An out of memory condition was encountered during the execution of 165this function. 166.It Bq Er DW_DLE_FRAME_INSTR_EXEC_ERROR 167An unknown instruction was found in the instruction bytes provided 168in argument 169.Fa instructions . 170.El 171.Sh SEE ALSO 172.Xr dwarf 3 , 173.Xr dwarf_frame_instructions_dealloc 3 , 174.Xr dwarf_get_cie_index 3 , 175.Xr dwarf_get_cie_info 3 , 176.Xr dwarf_get_cie_of_fde 3 , 177.Xr dwarf_get_fde_at_pc 3 , 178.Xr dwarf_get_fde_info_for_all_regs 3 , 179.Xr dwarf_get_fde_info_for_all_regs3 3 , 180.Xr dwarf_get_fde_info_for_cfa_reg3 3 , 181.Xr dwarf_get_fde_info_for_reg 3 , 182.Xr dwarf_get_fde_info_for_reg3 3 , 183.Xr dwarf_get_fde_instr_bytes 3 , 184.Xr dwarf_get_fde_list 3 , 185.Xr dwarf_get_fde_list_eh 3 , 186.Xr dwarf_get_fde_n 3 187