1*5ac3bc71Schristos.\" $NetBSD: dwarf_expand_frame_instructions.3,v 1.6 2024/03/03 17:37:30 christos Exp $ 2e81373b4Schristos.\" 39dd9d0cfSchristos.\" Copyright (c) 2011 Kai Wang 49dd9d0cfSchristos.\" All rights reserved. 59dd9d0cfSchristos.\" 69dd9d0cfSchristos.\" Redistribution and use in source and binary forms, with or without 79dd9d0cfSchristos.\" modification, are permitted provided that the following conditions 89dd9d0cfSchristos.\" are met: 99dd9d0cfSchristos.\" 1. Redistributions of source code must retain the above copyright 109dd9d0cfSchristos.\" notice, this list of conditions and the following disclaimer. 119dd9d0cfSchristos.\" 2. Redistributions in binary form must reproduce the above copyright 129dd9d0cfSchristos.\" notice, this list of conditions and the following disclaimer in the 139dd9d0cfSchristos.\" documentation and/or other materials provided with the distribution. 149dd9d0cfSchristos.\" 159dd9d0cfSchristos.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 169dd9d0cfSchristos.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 179dd9d0cfSchristos.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 189dd9d0cfSchristos.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 199dd9d0cfSchristos.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 209dd9d0cfSchristos.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 219dd9d0cfSchristos.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 229dd9d0cfSchristos.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 239dd9d0cfSchristos.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 249dd9d0cfSchristos.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 259dd9d0cfSchristos.\" SUCH DAMAGE. 269dd9d0cfSchristos.\" 27cdbf1fe1Sjkoshy.\" Id: dwarf_expand_frame_instructions.3 3962 2022-03-12 15:56:10Z jkoshy 289dd9d0cfSchristos.\" 299dd9d0cfSchristos.Dd November 9, 2011 309dd9d0cfSchristos.Dt DWARF_EXPAND_FRAME_INSTRUCTIONS 3 31604b0842Sjkoshy.Os 329dd9d0cfSchristos.Sh NAME 339dd9d0cfSchristos.Nm dwarf_expand_frame_instructions 349dd9d0cfSchristos.Nd expand frame instructions 359dd9d0cfSchristos.Sh LIBRARY 369dd9d0cfSchristos.Lb libdwarf 379dd9d0cfSchristos.Sh SYNOPSIS 389dd9d0cfSchristos.In libdwarf.h 399dd9d0cfSchristos.Ft int 409dd9d0cfSchristos.Fo dwarf_expand_frame_instructions 419dd9d0cfSchristos.Fa "Dwarf_Cie cie" 429dd9d0cfSchristos.Fa "Dwarf_Ptr instructions" 439dd9d0cfSchristos.Fa "Dwarf_Unsigned len" 449dd9d0cfSchristos.Fa "Dwarf_Frame_Op **ret_ops" 459dd9d0cfSchristos.Fa "Dwarf_Signed *ret_opcnt" 469dd9d0cfSchristos.Fa "Dwarf_Error *error" 479dd9d0cfSchristos.Fc 489dd9d0cfSchristos.Sh DESCRIPTION 499dd9d0cfSchristosFunction 509dd9d0cfSchristos.Fn dwarf_expand_frame_instructions 519dd9d0cfSchristostranslates DWARF frame instruction bytes into an array of 529dd9d0cfSchristos.Vt Dwarf_Frame_Op 539dd9d0cfSchristosdescriptors. 549dd9d0cfSchristos.Pp 559dd9d0cfSchristosArgument 56cdbf1fe1Sjkoshy.Fa cie 579dd9d0cfSchristosshould reference the CIE descriptor associated with the instructions 589dd9d0cfSchristosto be translated. 599dd9d0cfSchristos.Pp 609dd9d0cfSchristosArugment 61cdbf1fe1Sjkoshy.Fa instructions 629dd9d0cfSchristosshould point to an array of frame instruction bytes, as 639dd9d0cfSchristosreturned by the functions 649dd9d0cfSchristos.Xr dwarf_get_cie_info 3 659dd9d0cfSchristosor 669dd9d0cfSchristos.Xr dwarf_get_fde_instr_bytes 3 . 679dd9d0cfSchristos.Pp 689dd9d0cfSchristosArgument 69cdbf1fe1Sjkoshy.Fa len 709dd9d0cfSchristosshould specify the number of the frame instruction bytes to be 719dd9d0cfSchristostranslated. 729dd9d0cfSchristos.Pp 739dd9d0cfSchristosArgument 74cdbf1fe1Sjkoshy.Fa ret_ops 759dd9d0cfSchristosshould point to a location that will be set to a pointer to 769dd9d0cfSchristosan array of translated 779dd9d0cfSchristos.Vt Dwarf_Frame_Op 789dd9d0cfSchristosdescriptors. 799dd9d0cfSchristos.Pp 809dd9d0cfSchristosArgument 81cdbf1fe1Sjkoshy.Fa ret_opcnt 829dd9d0cfSchristosshould point to a location that will hold the total number of the 839dd9d0cfSchristosreturned descriptors. 849dd9d0cfSchristos.Pp 859dd9d0cfSchristosIf argument 86cdbf1fe1Sjkoshy.Fa err 87cdbf1fe1Sjkoshyis not 88cdbf1fe1Sjkoshy.Dv NULL , 89cdbf1fe1Sjkoshyit will be used to store error information in case of an error. 909dd9d0cfSchristos.Ss Memory Management 919dd9d0cfSchristosThe memory area used for the descriptor array returned in argument 92cdbf1fe1Sjkoshy.Fa ret_ops 939dd9d0cfSchristosis allocated by 949dd9d0cfSchristos.Lb libdwarf . 959dd9d0cfSchristosApplication code should use function 969dd9d0cfSchristos.Xr dwarf_dealloc 3 979dd9d0cfSchristoswith type 989dd9d0cfSchristos.Dv DW_DLA_FRAME_BLOCK 999dd9d0cfSchristosto free the memory area when the descriptor array is no longer needed. 1009dd9d0cfSchristos.Sh RETURN VALUES 1019dd9d0cfSchristosFunction 1029dd9d0cfSchristos.Fn dwarf_expand_frame_instructions 1039dd9d0cfSchristosreturns 1049dd9d0cfSchristos.Dv DW_DLV_OK 1059dd9d0cfSchristoswhen it succeeds. 1069dd9d0cfSchristosIn case of an error, it returns 1079dd9d0cfSchristos.Dv DW_DLV_ERROR 1089dd9d0cfSchristosand sets the argument 109cdbf1fe1Sjkoshy.Fa err . 110604b0842Sjkoshy.Sh EXAMPLES 1119dd9d0cfSchristosTo retrieve and expand the frame instructions for a given FDE 1129dd9d0cfSchristosdescriptor, use: 1139dd9d0cfSchristos.Bd -literal -offset indent 1149dd9d0cfSchristosDwarf_Dbg dbg; 1159dd9d0cfSchristosDwarf_Cie cie; 1169dd9d0cfSchristosDwarf_Fde fde; 1179dd9d0cfSchristosDwarf_Ptr fde_inst; 1189dd9d0cfSchristosDwarf_Unsigned fde_instlen; 1199dd9d0cfSchristosDwarf_Frame_Op *ops; 1209dd9d0cfSchristosDwarf_Signed opcnt; 1219dd9d0cfSchristosDwarf_Error de; 1229dd9d0cfSchristos 1239dd9d0cfSchristos/* ... assuming `dbg` references a valid DWARF debugging context, 1249dd9d0cfSchristos `fde` references a valid FDE descriptor and `cie` holds the CIE 1259dd9d0cfSchristos descriptor associated with the FDE descriptor ... */ 1269dd9d0cfSchristos 1279dd9d0cfSchristosif (dwarf_get_fde_instr_bytes(fde, &fde_inst, &fde_instlen, 1289dd9d0cfSchristos &de) != DW_DLV_OK) 1299dd9d0cfSchristos errx(EXIT_FAILURE, "dwarf_get_fde_instr_bytes failed: %s", 1309dd9d0cfSchristos dwarf_errmsg(de)); 1319dd9d0cfSchristos 1329dd9d0cfSchristosif (dwarf_expand_frame_instructions(cie, fde_inst, fde_instlen, 1339dd9d0cfSchristos &ops, &opcnt, &de) != DW_DLV_OK) 1349dd9d0cfSchristos errx(EXIT_FAILURE, 1359dd9d0cfSchristos "dwarf_expand_frame_instructions failed: %s", 1369dd9d0cfSchristos dwarf_errmsg(de)); 1379dd9d0cfSchristos 1389dd9d0cfSchristosfor (i = 0; i < opcnt; i++) { 1399dd9d0cfSchristos /* ... use ops[i] ... */ 1409dd9d0cfSchristos} 1419dd9d0cfSchristos 1429dd9d0cfSchristos/* Free the memory area when no longer needed. */ 1439dd9d0cfSchristosdwarf_dealloc(dbg, ops, DW_DLA_FRAME_BLOCK); 1449dd9d0cfSchristos.Ed 145604b0842Sjkoshy.Sh ERRORS 146604b0842SjkoshyFunction 147604b0842Sjkoshy.Fn dwarf_expand_frame_instructions 148604b0842Sjkoshycan fail with: 149604b0842Sjkoshy.Bl -tag -width ".Bq Er DW_DLE_ARGUMENT" 150604b0842Sjkoshy.It Bq Er DW_DLE_ARGUMENT 151604b0842SjkoshyOne of the arguments 152cdbf1fe1Sjkoshy.Fa cie , 153cdbf1fe1Sjkoshy.Fa instructions , 154cdbf1fe1Sjkoshy.Fa ret_ops 155604b0842Sjkoshyor 156cdbf1fe1Sjkoshy.Fa ret_opcnt 157cdbf1fe1Sjkoshywas 158cdbf1fe1Sjkoshy.Dv NULL . 159604b0842Sjkoshy.It Bq Er DW_DLE_ARGUMENT 160604b0842SjkoshyArgument 161cdbf1fe1Sjkoshy.Fa len 162604b0842Sjkoshywas 0. 163604b0842Sjkoshy.It Bq Er DW_DLE_MEMORY 164604b0842SjkoshyAn out of memory condition was encountered during the execution of 165604b0842Sjkoshythis function. 166604b0842Sjkoshy.It Bq Er DW_DLE_FRAME_INSTR_EXEC_ERROR 167604b0842SjkoshyAn unknown instruction was found in the instruction bytes provided 168604b0842Sjkoshyin argument 169cdbf1fe1Sjkoshy.Fa instructions . 170604b0842Sjkoshy.El 1719dd9d0cfSchristos.Sh SEE ALSO 1729dd9d0cfSchristos.Xr dwarf 3 , 1739dd9d0cfSchristos.Xr dwarf_frame_instructions_dealloc 3 , 1749dd9d0cfSchristos.Xr dwarf_get_cie_index 3 , 175604b0842Sjkoshy.Xr dwarf_get_cie_info 3 , 176604b0842Sjkoshy.Xr dwarf_get_cie_of_fde 3 , 1779dd9d0cfSchristos.Xr dwarf_get_fde_at_pc 3 , 1789dd9d0cfSchristos.Xr dwarf_get_fde_info_for_all_regs 3 , 1799dd9d0cfSchristos.Xr dwarf_get_fde_info_for_all_regs3 3 , 1809dd9d0cfSchristos.Xr dwarf_get_fde_info_for_cfa_reg3 3 , 1819dd9d0cfSchristos.Xr dwarf_get_fde_info_for_reg 3 , 1829dd9d0cfSchristos.Xr dwarf_get_fde_info_for_reg3 3 , 1839dd9d0cfSchristos.Xr dwarf_get_fde_instr_bytes 3 , 1849dd9d0cfSchristos.Xr dwarf_get_fde_list 3 , 1859dd9d0cfSchristos.Xr dwarf_get_fde_list_eh 3 , 1869dd9d0cfSchristos.Xr dwarf_get_fde_n 3 187