xref: /freebsd/contrib/elftoolchain/libdwarf/dwarf_srclines.3 (revision ae500c1ff8974130f7f2692772cf288b90349e0d)
12de3b87aSKai Wang.\" Copyright (c) 2010 Joseph Koshy.  All rights reserved.
22de3b87aSKai Wang.\"
32de3b87aSKai Wang.\" Redistribution and use in source and binary forms, with or without
42de3b87aSKai Wang.\" modification, are permitted provided that the following conditions
52de3b87aSKai Wang.\" are met:
62de3b87aSKai Wang.\" 1. Redistributions of source code must retain the above copyright
72de3b87aSKai Wang.\"    notice, this list of conditions and the following disclaimer.
82de3b87aSKai Wang.\" 2. Redistributions in binary form must reproduce the above copyright
92de3b87aSKai Wang.\"    notice, this list of conditions and the following disclaimer in the
102de3b87aSKai Wang.\"    documentation and/or other materials provided with the distribution.
112de3b87aSKai Wang.\"
122de3b87aSKai Wang.\" This software is provided by Joseph Koshy ``as is'' and
132de3b87aSKai Wang.\" any express or implied warranties, including, but not limited to, the
142de3b87aSKai Wang.\" implied warranties of merchantability and fitness for a particular purpose
152de3b87aSKai Wang.\" are disclaimed.  in no event shall Joseph Koshy be liable
162de3b87aSKai Wang.\" for any direct, indirect, incidental, special, exemplary, or consequential
172de3b87aSKai Wang.\" damages (including, but not limited to, procurement of substitute goods
182de3b87aSKai Wang.\" or services; loss of use, data, or profits; or business interruption)
192de3b87aSKai Wang.\" however caused and on any theory of liability, whether in contract, strict
202de3b87aSKai Wang.\" liability, or tort (including negligence or otherwise) arising in any way
212de3b87aSKai Wang.\" out of the use of this software, even if advised of the possibility of
222de3b87aSKai Wang.\" such damage.
232de3b87aSKai Wang.\"
24*ae500c1fSEd Maste.\" $Id: dwarf_srclines.3 3644 2018-10-15 19:55:01Z jkoshy $
252de3b87aSKai Wang.\"
262de3b87aSKai Wang.Dd November 9, 2011
272de3b87aSKai Wang.Dt DWARF_SRCLINES 3
28*ae500c1fSEd Maste.Os
292de3b87aSKai Wang.Sh NAME
302de3b87aSKai Wang.Nm dwarf_srclines
312de3b87aSKai Wang.Nd retrieve line number information for a debugging information entry
322de3b87aSKai Wang.Sh LIBRARY
332de3b87aSKai Wang.Lb libdwarf
342de3b87aSKai Wang.Sh SYNOPSIS
352de3b87aSKai Wang.In libdwarf.h
362de3b87aSKai Wang.Ft int
372de3b87aSKai Wang.Fo dwarf_srclines
382de3b87aSKai Wang.Fa "Dwarf_Die die"
392de3b87aSKai Wang.Fa "Dwarf_Line **lines"
402de3b87aSKai Wang.Fa "Dwarf_Signed *nlines"
412de3b87aSKai Wang.Fa "Dwarf_Error *err"
422de3b87aSKai Wang.Fc
432de3b87aSKai Wang.Sh DESCRIPTION
442de3b87aSKai WangFunction
452de3b87aSKai Wang.Fn dwarf_srclines
462de3b87aSKai Wangreturns line number information associated with a compilation unit.
472de3b87aSKai WangLine number information is returned as an array of
482de3b87aSKai Wang.Vt Dwarf_Line
492de3b87aSKai Wangdescriptors.
502de3b87aSKai Wang.Pp
512de3b87aSKai WangArgument
522de3b87aSKai Wang.Ar die
532de3b87aSKai Wangshould reference a DWARF debugging information entry descriptor
542de3b87aSKai Wangwith line number information, see
552de3b87aSKai Wang.Xr dwarf 3 .
562de3b87aSKai WangArgument
572de3b87aSKai Wang.Ar lines
582de3b87aSKai Wangshould point to a location that will hold a pointer to the returned array
592de3b87aSKai Wangof
602de3b87aSKai Wang.Vt Dwarf_Line
612de3b87aSKai Wangdescriptors.
622de3b87aSKai WangArgument
632de3b87aSKai Wang.Ar nlines
642de3b87aSKai Wangshould point to a location that will hold the number of descriptors
652de3b87aSKai Wangreturned.
662de3b87aSKai WangIf argument
672de3b87aSKai Wang.Ar err
682de3b87aSKai Wangis not NULL, it will be used to store error information in case of an
692de3b87aSKai Wangerror.
702de3b87aSKai Wang.Pp
712de3b87aSKai WangThe returned
722de3b87aSKai Wang.Vt Dwarf_Line
732de3b87aSKai Wangdescriptors may be passed to the other line number functions in the
742de3b87aSKai WangAPI set to retrieve specific information about each source line.
752de3b87aSKai Wang.Ss Memory Management
762de3b87aSKai WangThe memory area used for the array of
772de3b87aSKai Wang.Vt Dwarf_Line
782de3b87aSKai Wangdescriptors returned in argument
792de3b87aSKai Wang.Ar lines
802de3b87aSKai Wangis owned by the
812de3b87aSKai Wang.Lb libdwarf .
822de3b87aSKai WangThe application should not attempt to free this pointer.
832de3b87aSKai WangPortable code should instead use
842de3b87aSKai Wang.Fn dwarf_srclines_dealloc
852de3b87aSKai Wangto indicate that the memory may be freed.
862de3b87aSKai Wang.Sh RETURN VALUES
872de3b87aSKai WangFunction
882de3b87aSKai Wang.Fn dwarf_srclines
892de3b87aSKai Wangreturns
902de3b87aSKai Wang.Dv DW_DLV_OK
912de3b87aSKai Wangwhen it succeeds.
922de3b87aSKai WangIn case of an error, it returns
932de3b87aSKai Wang.Dv DW_DLV_ERROR
942de3b87aSKai Wangand sets the argument
952de3b87aSKai Wang.Ar err .
96*ae500c1fSEd Maste.Sh EXAMPLES
972de3b87aSKai WangTo obtain an array of
982de3b87aSKai Wang.Vt Dwarf_Line
992de3b87aSKai Wangdescriptors and to retrieve the source file, line number, and virtual address
1002de3b87aSKai Wangassociated with each descriptor:
1012de3b87aSKai Wang.Bd -literal -offset indent
1022de3b87aSKai Wangint n;
1032de3b87aSKai WangDwarf_Die die;
1042de3b87aSKai WangDwarf_Error de;
1052de3b87aSKai Wangchar *filename;
1062de3b87aSKai WangDwarf_Line *lines;
1072de3b87aSKai WangDwarf_Signed nlines;
1082de3b87aSKai WangDwarf_Addr lineaddr;
1092de3b87aSKai WangDwarf_Unsigned lineno;
1102de3b87aSKai Wang
1112de3b87aSKai Wang/* variable "die" should reference a DIE for a compilation unit */
1122de3b87aSKai Wang
1132de3b87aSKai Wangif (dwarf_srclines(die, &lines, &nlines, &de) != DW_DLV_OK)
1142de3b87aSKai Wang	errx(EXIT_FAILURE, "dwarf_srclines: %s", dwarf_errmsg(de));
1152de3b87aSKai Wang
1162de3b87aSKai Wangfor (n = 0; n < nlines; n++) {
1172de3b87aSKai Wang	/* Retrieve the file name for this descriptor. */
1182de3b87aSKai Wang	if (dwarf_linesrc(lines[n], &filename, &de))
1192de3b87aSKai Wang		errx(EXIT_FAILURE, "dwarf_linesrc: %s",
1202de3b87aSKai Wang		    dwarf_errmsg(de));
1212de3b87aSKai Wang
1222de3b87aSKai Wang	/* Retrieve the line number in the source file. */
1232de3b87aSKai Wang	if (dwarf_lineno(lines[n], &lineno, &de))
1242de3b87aSKai Wang		errx(EXIT_FAILURE, "dwarf_lineno: %s",
1252de3b87aSKai Wang		    dwarf_errmsg(de));
1262de3b87aSKai Wang	/* Retrieve the virtual address for this line. */
1272de3b87aSKai Wang	if (dwarf_lineaddr(lines[n], &lineaddr, &de))
1282de3b87aSKai Wang		errx(EXIT_FAILURE, "dwarf_lineaddr: %s",
1292de3b87aSKai Wang		    dwarf_errmsg(de));
1302de3b87aSKai Wang	}
1312de3b87aSKai Wang.Ed
132*ae500c1fSEd Maste.Sh ERRORS
133*ae500c1fSEd MasteFunction
134*ae500c1fSEd Maste.Fn dwarf_srclines
135*ae500c1fSEd Mastecan fail with:
136*ae500c1fSEd Maste.Bl -tag -width ".Bq Er DW_DLE_ARGUMENT"
137*ae500c1fSEd Maste.It Bq Er DW_DLE_ARGUMENT
138*ae500c1fSEd MasteOne of the arguments
139*ae500c1fSEd Maste.Ar die ,
140*ae500c1fSEd Maste.Ar lines
141*ae500c1fSEd Masteor
142*ae500c1fSEd Maste.Ar nlines
143*ae500c1fSEd Mastewas NULL.
144*ae500c1fSEd Maste.It Bq Er DW_DLE_NO_ENTRY
145*ae500c1fSEd MasteThe compilation unit referenced by argument
146*ae500c1fSEd Maste.Ar die
147*ae500c1fSEd Mastedoes not have associated line number information.
148*ae500c1fSEd Maste.It Bq Er DW_DLE_MEMORY
149*ae500c1fSEd MasteAn out of memory condition was encountered during the execution of
150*ae500c1fSEd Mastethis function.
151*ae500c1fSEd Maste.El
1522de3b87aSKai Wang.Sh SEE ALSO
1532de3b87aSKai Wang.Xr dwarf 3 ,
1542de3b87aSKai Wang.Xr dwarf_line_srcfileno 3 ,
1552de3b87aSKai Wang.Xr dwarf_lineaddr 3 ,
1562de3b87aSKai Wang.Xr dwarf_linebeginstatement 3 ,
1572de3b87aSKai Wang.Xr dwarf_lineblock 3 ,
1582de3b87aSKai Wang.Xr dwarf_lineendsequence 3 ,
1592de3b87aSKai Wang.Xr dwarf_lineno 3 ,
1602de3b87aSKai Wang.Xr dwarf_lineoff 3 ,
1612de3b87aSKai Wang.Xr dwarf_linesrc 3 ,
1622de3b87aSKai Wang.Xr dwarf_srcfiles 3 ,
1632de3b87aSKai Wang.Xr dwarf_srclines_dealloc 3
164