1*5ac3bc71Schristos.\" $NetBSD: dwarf_new_expr.3,v 1.6 2024/03/03 17:37:31 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_new_expr.3 3963 2022-03-12 16:07:32Z jkoshy 289dd9d0cfSchristos.\" 299dd9d0cfSchristos.Dd September 8, 2011 309dd9d0cfSchristos.Dt DWARF_NEW_EXPR 3 31604b0842Sjkoshy.Os 329dd9d0cfSchristos.Sh NAME 339dd9d0cfSchristos.Nm dwarf_new_expr 349dd9d0cfSchristos.Nd create a location expression descriptor 359dd9d0cfSchristos.Sh LIBRARY 369dd9d0cfSchristos.Lb libdwarf 379dd9d0cfSchristos.Sh SYNOPSIS 389dd9d0cfSchristos.In libdwarf.h 399dd9d0cfSchristos.Ft "Dwarf_P_Expr" 409dd9d0cfSchristos.Fo dwarf_new_expr 419dd9d0cfSchristos.Fa "Dwarf_P_Debug dbg" 429dd9d0cfSchristos.Fa "Dwarf_Error *err" 439dd9d0cfSchristos.Fc 449dd9d0cfSchristos.Sh DESCRIPTION 459dd9d0cfSchristosFunction 469dd9d0cfSchristos.Fn dwarf_new_expr 479dd9d0cfSchristosallocates a DWARF location expression descriptor used to build up a 489dd9d0cfSchristoslocation expression stream. 499dd9d0cfSchristos.Pp 509dd9d0cfSchristosThe application can use the functions 519dd9d0cfSchristos.Xr dwarf_add_expr_gen 3 529dd9d0cfSchristosand 539dd9d0cfSchristos.Xr dwarf_add_expr_addr_b 3 549dd9d0cfSchristosto add location expression operators to the created descriptor. 559dd9d0cfSchristosWhen done, the application can call the function 569dd9d0cfSchristos.Xr dwarf_expr_into_block 3 579dd9d0cfSchristosto retrieve the generated byte stream for the location expression, 589dd9d0cfSchristosor call the function 599dd9d0cfSchristos.Xr dwarf_add_AT_location_expr 3 609dd9d0cfSchristosto create an attribute with the location expression stream as its 619dd9d0cfSchristosvalue. 629dd9d0cfSchristos.Pp 639dd9d0cfSchristosArgument 64cdbf1fe1Sjkoshy.Fa dbg 659dd9d0cfSchristosshould reference a DWARF producer instance allocated using 669dd9d0cfSchristos.Xr dwarf_producer_init 3 679dd9d0cfSchristosor 689dd9d0cfSchristos.Xr dwarf_producer_init_b 3 . 699dd9d0cfSchristos.Pp 709dd9d0cfSchristosIf argument 71cdbf1fe1Sjkoshy.Fa err 72cdbf1fe1Sjkoshyis not 73cdbf1fe1Sjkoshy.Dv NULL , 74cdbf1fe1Sjkoshyit will be used to store error information in case of an error. 759dd9d0cfSchristos.Sh RETURN VALUES 769dd9d0cfSchristosOn success, function 779dd9d0cfSchristos.Fn dwarf_new_expr 789dd9d0cfSchristosreturns the created location expression descriptor. 799dd9d0cfSchristosIn case of an error, function 809dd9d0cfSchristos.Fn dwarf_new_expr 819dd9d0cfSchristosreturns 829dd9d0cfSchristos.Dv DW_DLV_BADADDR 839dd9d0cfSchristosand sets the argument 84cdbf1fe1Sjkoshy.Fa err . 859dd9d0cfSchristos.Sh EXAMPLES 869dd9d0cfSchristosTo create a location expression descriptor, add location expression 879dd9d0cfSchristosoperators to it and to retrieve the generated byte stream, 889dd9d0cfSchristosuse: 899dd9d0cfSchristos.Bd -literal -offset indent 909dd9d0cfSchristosDwarf_P_Debug dbg; 919dd9d0cfSchristosDwarf_Error de; 929dd9d0cfSchristosDwarf_P_Expr pe; 939dd9d0cfSchristosDwarf_Addr buf; 949dd9d0cfSchristosDwarf_Unsigned len; 959dd9d0cfSchristos 969dd9d0cfSchristos/* ...Assume that `dbg' refers to a DWARF producer instance... */ 979dd9d0cfSchristos 989dd9d0cfSchristosif ((pe = dwarf_new_expr(dbg, &de)) == DW_DLV_BADADDR) { 999dd9d0cfSchristos warnx("dwarf_new_expr failed: %s", dwarf_errmsg(-1)); 1009dd9d0cfSchristos return; 1019dd9d0cfSchristos} 1029dd9d0cfSchristos 1039dd9d0cfSchristosif (dwarf_add_expr_gen(pe, DW_OP_regx, 55, 0, &de) == 1049dd9d0cfSchristos DW_DLV_NOCOUNT) { 1059dd9d0cfSchristos warnx("dwarf_add_expr_gen failed: %s", dwarf_errmsg(-1)); 1069dd9d0cfSchristos return; 1079dd9d0cfSchristos} 1089dd9d0cfSchristos 1099dd9d0cfSchristosif ((buf = dwarf_expr_into_block(pe, &len, &de)) == 1109dd9d0cfSchristos DW_DLV_BADADDR) { 1119dd9d0cfSchristos warnx("dwarf_expr_into_block failed: %s", 1129dd9d0cfSchristos dwarf_errmsg(-1)); 1139dd9d0cfSchristos return; 1149dd9d0cfSchristos} 1159dd9d0cfSchristos.Ed 116604b0842Sjkoshy.Sh ERRORS 117604b0842SjkoshyFunction 118604b0842Sjkoshy.Fn dwarf_new_expr 119604b0842Sjkoshycan fail with: 120604b0842Sjkoshy.Bl -tag -width ".Bq Er DW_DLE_ARGUMENT" 121604b0842Sjkoshy.It Bq Er DW_DLE_ARGUMENT 122604b0842SjkoshyArgument 123cdbf1fe1Sjkoshy.Fa dbg 124cdbf1fe1Sjkoshywas 125cdbf1fe1Sjkoshy.Dv NULL . 126604b0842Sjkoshy.It Bq Er DW_DLE_MEMORY 127604b0842SjkoshyAn out of memory condition was encountered during the execution of 128604b0842Sjkoshythe function. 129604b0842Sjkoshy.El 1309dd9d0cfSchristos.Sh SEE ALSO 1319dd9d0cfSchristos.Xr dwarf 3 , 1329dd9d0cfSchristos.Xr dwarf_add_AT_location_expr 3 , 1339dd9d0cfSchristos.Xr dwarf_add_expr_addr 3 , 1349dd9d0cfSchristos.Xr dwarf_add_expr_addr_b 3 , 135604b0842Sjkoshy.Xr dwarf_add_expr_gen 3 , 1369dd9d0cfSchristos.Xr dwarf_expr_current_offset 3 , 1379dd9d0cfSchristos.Xr dwarf_expr_into_block 3 , 1389dd9d0cfSchristos.Xr dwarf_producer_init 3 , 1399dd9d0cfSchristos.Xr dwarf_producer_init_b 3 140