]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/elftoolchain/libdwarf/dwarf_new_expr.3
MFV r368464:
[FreeBSD/FreeBSD.git] / contrib / elftoolchain / libdwarf / dwarf_new_expr.3
1 .\" Copyright (c) 2011 Kai Wang
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\"
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 .\" SUCH DAMAGE.
24 .\"
25 .\" $Id: dwarf_new_expr.3 3644 2018-10-15 19:55:01Z jkoshy $
26 .\"
27 .Dd September 8, 2011
28 .Dt DWARF_NEW_EXPR 3
29 .Os
30 .Sh NAME
31 .Nm dwarf_new_expr
32 .Nd create a location expression descriptor
33 .Sh LIBRARY
34 .Lb libdwarf
35 .Sh SYNOPSIS
36 .In libdwarf.h
37 .Ft "Dwarf_P_Expr"
38 .Fo dwarf_new_expr
39 .Fa "Dwarf_P_Debug dbg"
40 .Fa "Dwarf_Error *err"
41 .Fc
42 .Sh DESCRIPTION
43 Function
44 .Fn dwarf_new_expr
45 allocates a DWARF location expression descriptor used to build up a
46 location expression stream.
47 .Pp
48 The application can use the functions
49 .Xr dwarf_add_expr_gen 3
50 and
51 .Xr dwarf_add_expr_addr_b 3
52 to add location expression operators to the created descriptor.
53 When done, the application can call the function
54 .Xr dwarf_expr_into_block 3
55 to retrieve the generated byte stream for the location expression,
56 or call the function
57 .Xr dwarf_add_AT_location_expr 3
58 to create an attribute with the location expression stream as its
59 value.
60 .Pp
61 Argument
62 .Ar dbg
63 should reference a DWARF producer instance allocated using
64 .Xr dwarf_producer_init 3
65 or
66 .Xr dwarf_producer_init_b 3 .
67 .Pp
68 If argument
69 .Ar err
70 is not NULL, it will be used to store error information in case
71 of an error.
72 .Sh RETURN VALUES
73 On success, function
74 .Fn dwarf_new_expr
75 returns the created location expression descriptor.
76 In case of an error, function
77 .Fn dwarf_new_expr
78 returns
79 .Dv DW_DLV_BADADDR
80 and sets the argument
81 .Ar err .
82 .Sh EXAMPLES
83 To create a location expression descriptor, add location expression
84 operators to it and to retrieve the generated byte stream,
85 use:
86 .Bd -literal -offset indent
87 Dwarf_P_Debug dbg;
88 Dwarf_Error de;
89 Dwarf_P_Expr pe;
90 Dwarf_Addr buf;
91 Dwarf_Unsigned len;
92
93 /* ...Assume that `dbg' refers to a DWARF producer instance... */
94
95 if ((pe = dwarf_new_expr(dbg, &de)) == DW_DLV_BADADDR) {
96         warnx("dwarf_new_expr failed: %s", dwarf_errmsg(-1));
97         return;
98 }
99
100 if (dwarf_add_expr_gen(pe, DW_OP_regx, 55, 0, &de) ==
101     DW_DLV_NOCOUNT) {
102         warnx("dwarf_add_expr_gen failed: %s", dwarf_errmsg(-1));
103         return;
104 }
105
106 if ((buf = dwarf_expr_into_block(pe, &len, &de)) ==
107     DW_DLV_BADADDR) {
108         warnx("dwarf_expr_into_block failed: %s",
109             dwarf_errmsg(-1));
110         return;
111 }
112 .Ed
113 .Sh ERRORS
114 Function
115 .Fn dwarf_new_expr
116 can fail with:
117 .Bl -tag -width ".Bq Er DW_DLE_ARGUMENT"
118 .It Bq Er DW_DLE_ARGUMENT
119 Argument
120 .Ar dbg
121 was NULL.
122 .It Bq Er DW_DLE_MEMORY
123 An out of memory condition was encountered during the execution of
124 the function.
125 .El
126 .Sh SEE ALSO
127 .Xr dwarf 3 ,
128 .Xr dwarf_add_AT_location_expr 3 ,
129 .Xr dwarf_add_expr_addr 3 ,
130 .Xr dwarf_add_expr_addr_b 3 ,
131 .Xr dwarf_add_expr_gen 3 ,
132 .Xr dwarf_expr_current_offset 3 ,
133 .Xr dwarf_expr_into_block 3 ,
134 .Xr dwarf_producer_init 3 ,
135 .Xr dwarf_producer_init_b 3