xref: /netbsd-src/external/bsd/elftoolchain/dist/libdwarf/dwarf_srclines.3 (revision 3117ece4fc4a4ca4489ba793710b60b0d26bab6c)
1.\"	$NetBSD: dwarf_srclines.3,v 1.6 2024/03/03 17:37:32 christos Exp $
2.\"
3.\" Copyright (c) 2010 Joseph Koshy.  All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" This software is provided by Joseph Koshy ``as is'' and
15.\" any express or implied warranties, including, but not limited to, the
16.\" implied warranties of merchantability and fitness for a particular purpose
17.\" are disclaimed.  in no event shall Joseph Koshy be liable
18.\" for any direct, indirect, incidental, special, exemplary, or consequential
19.\" damages (including, but not limited to, procurement of substitute goods
20.\" or services; loss of use, data, or profits; or business interruption)
21.\" however caused and on any theory of liability, whether in contract, strict
22.\" liability, or tort (including negligence or otherwise) arising in any way
23.\" out of the use of this software, even if advised of the possibility of
24.\" such damage.
25.\"
26.\" Id: dwarf_srclines.3 3963 2022-03-12 16:07:32Z jkoshy
27.\"
28.Dd November 9, 2011
29.Dt DWARF_SRCLINES 3
30.Os
31.Sh NAME
32.Nm dwarf_srclines
33.Nd retrieve line number information for a debugging information entry
34.Sh LIBRARY
35.Lb libdwarf
36.Sh SYNOPSIS
37.In libdwarf.h
38.Ft int
39.Fo dwarf_srclines
40.Fa "Dwarf_Die die"
41.Fa "Dwarf_Line **lines"
42.Fa "Dwarf_Signed *nlines"
43.Fa "Dwarf_Error *err"
44.Fc
45.Sh DESCRIPTION
46Function
47.Fn dwarf_srclines
48returns line number information associated with a compilation unit.
49Line number information is returned as an array of
50.Vt Dwarf_Line
51descriptors.
52.Pp
53Argument
54.Fa die
55should reference a DWARF debugging information entry descriptor
56with line number information, see
57.Xr dwarf 3 .
58Argument
59.Fa lines
60should point to a location that will hold a pointer to the returned array
61of
62.Vt Dwarf_Line
63descriptors.
64Argument
65.Fa nlines
66should point to a location that will hold the number of descriptors
67returned.
68If argument
69.Fa err
70is not
71.Dv NULL ,
72it will be used to store error information in case of an error.
73.Pp
74The returned
75.Vt Dwarf_Line
76descriptors may be passed to the other line number functions in the
77API set to retrieve specific information about each source line.
78.Ss Memory Management
79The memory area used for the array of
80.Vt Dwarf_Line
81descriptors returned in argument
82.Fa lines
83is owned by the
84.Lb libdwarf .
85The application should not attempt to free this pointer.
86Portable code should instead use
87.Fn dwarf_srclines_dealloc
88to indicate that the memory may be freed.
89.Sh RETURN VALUES
90Function
91.Fn dwarf_srclines
92returns
93.Dv DW_DLV_OK
94when it succeeds.
95In case of an error, it returns
96.Dv DW_DLV_ERROR
97and sets the argument
98.Fa err .
99.Sh EXAMPLES
100To obtain an array of
101.Vt Dwarf_Line
102descriptors and to retrieve the source file, line number, and virtual address
103associated with each descriptor:
104.Bd -literal -offset indent
105int n;
106Dwarf_Die die;
107Dwarf_Error de;
108char *filename;
109Dwarf_Line *lines;
110Dwarf_Signed nlines;
111Dwarf_Addr lineaddr;
112Dwarf_Unsigned lineno;
113
114/* variable "die" should reference a DIE for a compilation unit */
115
116if (dwarf_srclines(die, &lines, &nlines, &de) != DW_DLV_OK)
117	errx(EXIT_FAILURE, "dwarf_srclines: %s", dwarf_errmsg(de));
118
119for (n = 0; n < nlines; n++) {
120	/* Retrieve the file name for this descriptor. */
121	if (dwarf_linesrc(lines[n], &filename, &de))
122		errx(EXIT_FAILURE, "dwarf_linesrc: %s",
123		    dwarf_errmsg(de));
124
125	/* Retrieve the line number in the source file. */
126	if (dwarf_lineno(lines[n], &lineno, &de))
127		errx(EXIT_FAILURE, "dwarf_lineno: %s",
128		    dwarf_errmsg(de));
129	/* Retrieve the virtual address for this line. */
130	if (dwarf_lineaddr(lines[n], &lineaddr, &de))
131		errx(EXIT_FAILURE, "dwarf_lineaddr: %s",
132		    dwarf_errmsg(de));
133	}
134.Ed
135.Sh ERRORS
136Function
137.Fn dwarf_srclines
138can fail with:
139.Bl -tag -width ".Bq Er DW_DLE_ARGUMENT"
140.It Bq Er DW_DLE_ARGUMENT
141One of the arguments
142.Fa die ,
143.Fa lines
144or
145.Fa nlines
146was
147.Dv NULL .
148.It Bq Er DW_DLE_NO_ENTRY
149The compilation unit referenced by argument
150.Fa die
151does not have associated line number information.
152.It Bq Er DW_DLE_MEMORY
153An out of memory condition was encountered during the execution of
154this function.
155.El
156.Sh SEE ALSO
157.Xr dwarf 3 ,
158.Xr dwarf_line_srcfileno 3 ,
159.Xr dwarf_lineaddr 3 ,
160.Xr dwarf_linebeginstatement 3 ,
161.Xr dwarf_lineblock 3 ,
162.Xr dwarf_lineendsequence 3 ,
163.Xr dwarf_lineno 3 ,
164.Xr dwarf_lineoff 3 ,
165.Xr dwarf_linesrc 3 ,
166.Xr dwarf_srcfiles 3 ,
167.Xr dwarf_srclines_dealloc 3
168