xref: /freebsd/contrib/elftoolchain/libdwarf/dwarf_new_die.3 (revision 02e9120893770924227138ba49df1edb3896112a)
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_die.3 3644 2018-10-15 19:55:01Z jkoshy $
26.\"
27.Dd September 4, 2011
28.Dt DWARF_NEW_DIE 3
29.Os
30.Sh NAME
31.Nm dwarf_new_die
32.Nd allocate a new debugging information entry
33.Sh LIBRARY
34.Lb libdwarf
35.Sh SYNOPSIS
36.In libdwarf.h
37.Ft Dwarf_P_Die
38.Fo dwarf_new_die
39.Fa "Dwarf_P_Debug dbg"
40.Fa "Dwarf_Tag tag"
41.Fa "Dwarf_P_Die parent"
42.Fa "Dwarf_P_Die child"
43.Fa "Dwarf_P_Die left"
44.Fa "Dwarf_P_Die right"
45.Fa "Dwarf_Error *err"
46.Fc
47.Sh DESCRIPTION
48Function
49.Fn dwarf_new_die
50allocates a new DWARF debugging information entry and links it
51to another debugging information entry.
52.Pp
53Argument
54.Ar dbg
55should reference a DWARF producer instance allocated using
56.Xr dwarf_producer_init 3
57or
58.Xr dwarf_producer_init_b 3 .
59.Pp
60Argument
61.Ar tag
62should specify the tag of the newly created debugging information entry.
63Valid values for this argument are those for the
64.Dv DW_TAG_ Ns *
65symbols defined in
66.In libdwarf.h .
67.Pp
68Argument
69.Ar parent
70specifies the parent link of the debugging information entry.
71.Pp
72Argument
73.Ar child
74specifies the first child link of the debugging information entry.
75.Pp
76Argument
77.Ar left
78specifies the left sibling link of the debugging information entry.
79.Pp
80Argument
81.Ar right
82specifies the right sibling link of the debugging information entry.
83.Pp
84Only one of arguments
85.Ar parent ,
86.Ar child ,
87.Ar left
88and
89.Ar right
90is allowed to be non-NULL.
91Application code can subsequently call the function
92.Xr dwarf_die_link 3
93to change the links for the created debugging information entry.
94.Pp
95If argument
96.Ar err
97is not NULL, it will be used to store error information in case
98of an error.
99.Sh RETURN VALUES
100On success, function
101.Fn dwarf_new_die
102returns the newly created debugging information entry.
103In case of an error, function
104.Fn dwarf_new_die
105returns
106.Dv DW_DLV_BADADDR
107and sets the argument
108.Ar err .
109.Sh EXAMPLES
110To create debugging information entries and add them to the producer
111instance, use:
112.Bd -literal -offset indent
113Dwarf_P_Debug dbg;
114Dwarf_P_Die die1, die2;
115Dwarf_Error de;
116
117/* ... assume dbg refers to a DWARF producer instance ... */
118
119die1 = dwarf_new_die(dbg, DW_TAG_compilation_unit, NULL, NULL, NULL,
120    NULL, &de);
121if (die1 == NULL) {
122	warnx("dwarf_new_die failed: %s", dwarf_errmsg(-1));
123	return;
124}
125
126die2 = dwarf_new_die(dbg, DW_TAG_base_type, die1, NULL, NULL,
127    NULL, &de);
128if (die1 == NULL) {
129	warnx("dwarf_new_die failed: %s", dwarf_errmsg(-1));
130	return;
131}
132
133if (dwarf_add_die_to_debug(dbg, die1, &de) != DW_DLV_OK) {
134	warnx("dwarf_add_die_to_debug failed: %s", dwarf_errmsg(-1));
135	return;
136}
137.Ed
138.Sh ERRORS
139Function
140.Fn dwarf_new_die
141can fail with:
142.Bl -tag -width ".Bq Er DW_DLE_ARGUMENT"
143.It Bq Er DW_DLE_ARGUMENT
144Argument
145.Ar dbg
146was NULL.
147.It Bq Er DW_DLE_ARGUMENT
148More than one of the arguments
149.Ar parent ,
150.Ar child ,
151.Ar left
152and
153.Ar right
154were non-NULL.
155.It Bq Er DW_DLE_MEMORY
156An out of memory condition was encountered during the execution of the
157function.
158.El
159.Sh SEE ALSO
160.Xr dwarf 3 ,
161.Xr dwarf_add_die_to_debug 3 ,
162.Xr dwarf_die_link 3 ,
163.Xr dwarf_producer_init 3 ,
164.Xr dwarf_producer_init_b 3
165