xref: /netbsd-src/external/bsd/elftoolchain/dist/libdwarf/dwarf_new_expr.3 (revision 53d1339bf7f9c7367b35a9e1ebe693f9b047a47b)
1.\"	$NetBSD: dwarf_new_expr.3,v 1.4 2020/11/26 22:51:35 jkoshy 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_new_expr.3 3644 2018-10-15 19:55:01Z jkoshy
28.\"
29.Dd September 8, 2011
30.Dt DWARF_NEW_EXPR 3
31.Os
32.Sh NAME
33.Nm dwarf_new_expr
34.Nd create a location expression descriptor
35.Sh LIBRARY
36.Lb libdwarf
37.Sh SYNOPSIS
38.In libdwarf.h
39.Ft "Dwarf_P_Expr"
40.Fo dwarf_new_expr
41.Fa "Dwarf_P_Debug dbg"
42.Fa "Dwarf_Error *err"
43.Fc
44.Sh DESCRIPTION
45Function
46.Fn dwarf_new_expr
47allocates a DWARF location expression descriptor used to build up a
48location expression stream.
49.Pp
50The application can use the functions
51.Xr dwarf_add_expr_gen 3
52and
53.Xr dwarf_add_expr_addr_b 3
54to add location expression operators to the created descriptor.
55When done, the application can call the function
56.Xr dwarf_expr_into_block 3
57to retrieve the generated byte stream for the location expression,
58or call the function
59.Xr dwarf_add_AT_location_expr 3
60to create an attribute with the location expression stream as its
61value.
62.Pp
63Argument
64.Ar dbg
65should reference a DWARF producer instance allocated using
66.Xr dwarf_producer_init 3
67or
68.Xr dwarf_producer_init_b 3 .
69.Pp
70If argument
71.Ar err
72is not NULL, it will be used to store error information in case
73of an error.
74.Sh RETURN VALUES
75On success, function
76.Fn dwarf_new_expr
77returns the created location expression descriptor.
78In case of an error, function
79.Fn dwarf_new_expr
80returns
81.Dv DW_DLV_BADADDR
82and sets the argument
83.Ar err .
84.Sh EXAMPLES
85To create a location expression descriptor, add location expression
86operators to it and to retrieve the generated byte stream,
87use:
88.Bd -literal -offset indent
89Dwarf_P_Debug dbg;
90Dwarf_Error de;
91Dwarf_P_Expr pe;
92Dwarf_Addr buf;
93Dwarf_Unsigned len;
94
95/* ...Assume that `dbg' refers to a DWARF producer instance... */
96
97if ((pe = dwarf_new_expr(dbg, &de)) == DW_DLV_BADADDR) {
98	warnx("dwarf_new_expr failed: %s", dwarf_errmsg(-1));
99	return;
100}
101
102if (dwarf_add_expr_gen(pe, DW_OP_regx, 55, 0, &de) ==
103    DW_DLV_NOCOUNT) {
104	warnx("dwarf_add_expr_gen failed: %s", dwarf_errmsg(-1));
105	return;
106}
107
108if ((buf = dwarf_expr_into_block(pe, &len, &de)) ==
109    DW_DLV_BADADDR) {
110	warnx("dwarf_expr_into_block failed: %s",
111	    dwarf_errmsg(-1));
112	return;
113}
114.Ed
115.Sh ERRORS
116Function
117.Fn dwarf_new_expr
118can fail with:
119.Bl -tag -width ".Bq Er DW_DLE_ARGUMENT"
120.It Bq Er DW_DLE_ARGUMENT
121Argument
122.Ar dbg
123was NULL.
124.It Bq Er DW_DLE_MEMORY
125An out of memory condition was encountered during the execution of
126the function.
127.El
128.Sh SEE ALSO
129.Xr dwarf 3 ,
130.Xr dwarf_add_AT_location_expr 3 ,
131.Xr dwarf_add_expr_addr 3 ,
132.Xr dwarf_add_expr_addr_b 3 ,
133.Xr dwarf_add_expr_gen 3 ,
134.Xr dwarf_expr_current_offset 3 ,
135.Xr dwarf_expr_into_block 3 ,
136.Xr dwarf_producer_init 3 ,
137.Xr dwarf_producer_init_b 3
138