xref: /netbsd-src/external/bsd/elftoolchain/dist/libdwarf/dwarf_add_line_entry.3 (revision 5ac3bc719ce6e70593039505b491894133237d12)
1.\"	$NetBSD: dwarf_add_line_entry.3,v 1.6 2024/03/03 17:37:30 christos 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 3961 2022-03-12 15:13:22Z 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.Fa 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.Fa 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.Fa 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.Fa lineno
78specifies the line number of the source line.
79.Pp
80Argument
81.Fa column
82specifies the column number within the source line.
83.Pp
84If the argument
85.Fa is_stmt
86is set to true, it indicates that the instruction at the address
87specified by argument
88.Fa 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.Fa basic_block
94is set to true, it indicates that the instruction at the address
95specified by argument
96.Fa off
97is the first instruction of a basic block.
98.Pp
99If argument
100.Fa err
101is not
102.Dv NULL ,
103it will be used to store error information in case of an error.
104.Sh RETURN VALUES
105On success, function
106.Fn dwarf_add_line_entry
107returns
108.Dv DW_DLV_OK .
109In case of an error, function
110.Fn dwarf_add_line_entry
111returns
112.Dv DW_DLV_NOCOUNT
113and sets the argument
114.Fa err .
115.Sh EXAMPLES
116To add line number information to the producer instance, use:
117.Bd -literal -offset indent
118Dwarf_P_Debug dbg;
119Dwarf_Error de;
120Dwarf_Unsigned dir, filendx;
121
122/* ... assume dbg refers to a DWARF producer instance ... */
123
124dir = dwarf_add_directory_decl(dbg, "/home/foo", &de);
125if (dir == DW_DLV_NOCOUNT)
126	errx(EXIT_FAILURE, "dwarf_add_directory_decl failed: %s",
127	    dwarf_errmsg(-1));
128
129filendx = dwarf_add_file_decl(dbg, "bar.c", dir, 0, 1234, &de);
130if (filendx == DW_DLV_NOCOUNT)
131	errx(EXIT_FAILURE, "dwarf_add_file_decl failed: %s",
132	    dwarf_errmsg(-1));
133
134if (dwarf_lne_set_address(dbg, 0x4012b0, 12, &de) != DW_DLV_OK)
135	errx(EXIT_FAILURE, "dwarf_lne_set_address failed: %s",
136	    dwarf_errmsg(-1));
137
138if (dwarf_add_line_entry(dbg, filendx, 10, 258, 0, 1, 1, &de) !=
139    DW_DLV_OK)
140	errx(EXIT_FAILURE, "dwarf_add_line_entry failed: %s",
141	    dwarf_errmsg(-1));
142.Ed
143.Sh ERRORS
144Function
145.Fn dwarf_add_line_entry
146can fail with:
147.Bl -tag -width ".Bq Er DW_DLE_ARGUMENT"
148.It Bq Er DW_DLE_ARGUMENT
149Argument
150.Fa dbg
151was
152.Dv NULL .
153.It Bq Er DW_DLE_ARGUMENT
154The function
155.Xr dwarf_lne_set_address 3
156was not called before calling this function.
157.It Bq Er DW_DLE_MEMORY
158An out of memory condition was encountered during the execution of the
159function.
160.El
161.Sh SEE ALSO
162.Xr dwarf 3 ,
163.Xr dwarf_add_directory_decl 3 ,
164.Xr dwarf_add_file_decl 3 ,
165.Xr dwarf_lne_end_sequence 3 ,
166.Xr dwarf_lne_set_address 3 ,
167.Xr dwarf_producer_init 3 ,
168.Xr dwarf_producer_init_b 3
169