xref: /netbsd-src/external/bsd/elftoolchain/dist/libdwarf/dwarf_add_line_entry.3 (revision 82d56013d7b633d116a93943de88e08335357a7c)
1.\"	$NetBSD: dwarf_add_line_entry.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_add_line_entry.3 3644 2018-10-15 19:55:01Z jkoshy
28.\"
29.Dd June 30, 2013
30.Dt DWARF_ADD_LINE_ENTRY 3
31.Os
32.Sh NAME
33.Nm dwarf_add_line_entry
34.Nd add a line number information entry to a producer instance
35.Sh LIBRARY
36.Lb libdwarf
37.Sh SYNOPSIS
38.In libdwarf.h
39.Ft "Dwarf_Unsigned"
40.Fo dwarf_add_line_entry
41.Fa "Dwarf_P_Debug dbg"
42.Fa "Dwarf_Unsigned filendx"
43.Fa "Dwarf_Addr off"
44.Fa "Dwarf_Unsigned lineno"
45.Fa "Dwarf_Signed column"
46.Fa "Dwarf_Bool is_stmt"
47.Fa "Dwarf_Bool basic_block"
48.Fa "Dwarf_Error *err"
49.Fc
50.Sh DESCRIPTION
51Function
52.Fn dwarf_add_line_entry
53adds a line number information entry to a DWARF producer instance.
54.Pp
55Argument
56.Ar dbg
57should reference a DWARF producer instance allocated using
58.Xr dwarf_producer_init 3
59or
60.Xr dwarf_producer_init_b 3 .
61.Pp
62Argument
63.Ar filendx
64specifies the index of the source file that contains the source line
65in question.
66Valid source file indices are those returned by the function
67.Xr dwarf_add_file_decl 3 .
68.Pp
69Argument
70.Ar off
71specifies a relocatable program address.
72The ELF symbol to be used
73for relocation is set by a prior call to the function
74.Xr dwarf_lne_set_address 3 .
75.Pp
76Argument
77.Ar lineno
78specifies the line number of the source line.
79.Pp
80Argument
81.Ar column
82specifies the column number within the source line.
83.Pp
84If the argument
85.Ar is_stmt
86is set to true, it indicates that the instruction at the address
87specified by argument
88.Ar off
89is a recommended breakpoint location, i.e., the first instruction in
90the instruction sequence generated by the source line.
91.Pp
92If the argument
93.Ar basic_block
94is set to true, it indicates that the instruction at the address
95specified by argument
96.Ar off
97is the first instruction of a basic block.
98.Pp
99If argument
100.Ar err
101is not NULL, it will be used to store error information in case
102of an error.
103.Sh RETURN VALUES
104On success, function
105.Fn dwarf_add_line_entry
106returns
107.Dv DW_DLV_OK .
108In case of an error, function
109.Fn dwarf_add_line_entry
110returns
111.Dv DW_DLV_NOCOUNT
112and sets the argument
113.Ar err .
114.Sh EXAMPLES
115To add line number information to the producer instance, use:
116.Bd -literal -offset indent
117Dwarf_P_Debug dbg;
118Dwarf_Error de;
119Dwarf_Unsigned dir, filendx;
120
121/* ... assume dbg refers to a DWARF producer instance ... */
122
123dir = dwarf_add_directory_decl(dbg, "/home/foo", &de);
124if (dir == DW_DLV_NOCOUNT)
125	errx(EXIT_FAILURE, "dwarf_add_directory_decl failed: %s",
126	    dwarf_errmsg(-1));
127
128filendx = dwarf_add_file_decl(dbg, "bar.c", dir, 0, 1234, &de);
129if (filendx == DW_DLV_NOCOUNT)
130	errx(EXIT_FAILURE, "dwarf_add_file_decl failed: %s",
131	    dwarf_errmsg(-1));
132
133if (dwarf_lne_set_address(dbg, 0x4012b0, 12, &de) != DW_DLV_OK)
134	errx(EXIT_FAILURE, "dwarf_lne_set_address failed: %s",
135	    dwarf_errmsg(-1));
136
137if (dwarf_add_line_entry(dbg, filendx, 10, 258, 0, 1, 1, &de) !=
138    DW_DLV_OK)
139	errx(EXIT_FAILURE, "dwarf_add_line_entry failed: %s",
140	    dwarf_errmsg(-1));
141.Ed
142.Sh ERRORS
143Function
144.Fn dwarf_add_line_entry
145can fail with:
146.Bl -tag -width ".Bq Er DW_DLE_ARGUMENT"
147.It Bq Er DW_DLE_ARGUMENT
148Argument
149.Ar dbg
150was NULL.
151.It Bq Er DW_DLE_ARGUMENT
152The function
153.Xr dwarf_lne_set_address 3
154was not called before calling this function.
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_directory_decl 3 ,
162.Xr dwarf_add_file_decl 3 ,
163.Xr dwarf_lne_end_sequence 3 ,
164.Xr dwarf_lne_set_address 3 ,
165.Xr dwarf_producer_init 3 ,
166.Xr dwarf_producer_init_b 3
167