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