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