xref: /netbsd-src/external/bsd/elftoolchain/dist/libdwarf/dwarf_get_str.3 (revision 5ac3bc719ce6e70593039505b491894133237d12)
1*5ac3bc71Schristos.\"	$NetBSD: dwarf_get_str.3,v 1.6 2024/03/03 17:37:31 christos Exp $
2e81373b4Schristos.\"
39dd9d0cfSchristos.\" Copyright (c) 2011 Kai Wang
49dd9d0cfSchristos.\" All rights reserved.
59dd9d0cfSchristos.\"
69dd9d0cfSchristos.\" Redistribution and use in source and binary forms, with or without
79dd9d0cfSchristos.\" modification, are permitted provided that the following conditions
89dd9d0cfSchristos.\" are met:
99dd9d0cfSchristos.\" 1. Redistributions of source code must retain the above copyright
109dd9d0cfSchristos.\"    notice, this list of conditions and the following disclaimer.
119dd9d0cfSchristos.\" 2. Redistributions in binary form must reproduce the above copyright
129dd9d0cfSchristos.\"    notice, this list of conditions and the following disclaimer in the
139dd9d0cfSchristos.\"    documentation and/or other materials provided with the distribution.
149dd9d0cfSchristos.\"
159dd9d0cfSchristos.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
169dd9d0cfSchristos.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
179dd9d0cfSchristos.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
189dd9d0cfSchristos.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199dd9d0cfSchristos.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
209dd9d0cfSchristos.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
219dd9d0cfSchristos.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
229dd9d0cfSchristos.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
239dd9d0cfSchristos.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
249dd9d0cfSchristos.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
259dd9d0cfSchristos.\" SUCH DAMAGE.
269dd9d0cfSchristos.\"
27cdbf1fe1Sjkoshy.\" Id: dwarf_get_str.3 3963 2022-03-12 16:07:32Z jkoshy
289dd9d0cfSchristos.\"
299dd9d0cfSchristos.Dd April 3, 2011
309dd9d0cfSchristos.Dt DWARF_GET_STR 3
31604b0842Sjkoshy.Os
329dd9d0cfSchristos.Sh NAME
339dd9d0cfSchristos.Nm dwarf_get_str
349dd9d0cfSchristos.Nd retrieve a string from the DWARF string section
359dd9d0cfSchristos.Sh LIBRARY
369dd9d0cfSchristos.Lb libdwarf
379dd9d0cfSchristos.Sh SYNOPSIS
389dd9d0cfSchristos.In libdwarf.h
399dd9d0cfSchristos.Ft int
409dd9d0cfSchristos.Fo dwarf_get_str
419dd9d0cfSchristos.Fa "Dwarf_Debug dbg"
429dd9d0cfSchristos.Fa "Dwarf_Off offset"
439dd9d0cfSchristos.Fa "char **string"
449dd9d0cfSchristos.Fa "Dwarf_Signed *len"
459dd9d0cfSchristos.Fa "Dwarf_Error *err"
469dd9d0cfSchristos.Fc
479dd9d0cfSchristos.Sh DESCRIPTION
489dd9d0cfSchristosFunction
499dd9d0cfSchristos.Fn dwarf_get_str
509dd9d0cfSchristosretrieves a NUL-terminated string from the DWARF string section
519dd9d0cfSchristos.Dq ".debug_str" .
529dd9d0cfSchristos.Pp
539dd9d0cfSchristosArgument
54cdbf1fe1Sjkoshy.Fa dbg
559dd9d0cfSchristosshould reference a DWARF debug context allocated using
569dd9d0cfSchristos.Xr dwarf_init 3 .
579dd9d0cfSchristos.Pp
589dd9d0cfSchristosArgument
59cdbf1fe1Sjkoshy.Fa offset
609dd9d0cfSchristosshould be an offset, relative to the
619dd9d0cfSchristos.Dq ".debug_str"
629dd9d0cfSchristossection, specifying the start of the desired string.
639dd9d0cfSchristos.Pp
649dd9d0cfSchristosArgument
65cdbf1fe1Sjkoshy.Fa string
669dd9d0cfSchristosshould point to a location which will hold a returned
679dd9d0cfSchristospointer to a NUL-terminated string.
689dd9d0cfSchristos.Pp
699dd9d0cfSchristosArgument
70cdbf1fe1Sjkoshy.Fa len
719dd9d0cfSchristosshould point to a location which will hold the length
729dd9d0cfSchristosof the returned string.
739dd9d0cfSchristosThe returned length does not include the space needed for
749dd9d0cfSchristosthe NUL-terminator.
759dd9d0cfSchristos.Pp
769dd9d0cfSchristosIf argument
77cdbf1fe1Sjkoshy.Fa err
78cdbf1fe1Sjkoshyis not
79cdbf1fe1Sjkoshy.Dv NULL ,
80cdbf1fe1Sjkoshyit will be used to store error information in case of an error.
819dd9d0cfSchristos.Sh RETURN VALUES
829dd9d0cfSchristosFunction
839dd9d0cfSchristos.Fn dwarf_get_str
849dd9d0cfSchristosreturns
859dd9d0cfSchristos.Dv DW_DLV_OK
869dd9d0cfSchristoswhen it succeeds.
879dd9d0cfSchristosIt returns
889dd9d0cfSchristos.Dv DW_DLV_NO_ENTRY
899dd9d0cfSchristosif there is no
909dd9d0cfSchristos.Dq ".debug_str"
919dd9d0cfSchristossection associated with the specified debugging context,
929dd9d0cfSchristosor if the provided offset
93cdbf1fe1Sjkoshy.Fa offset
949dd9d0cfSchristosis at the very end of
959dd9d0cfSchristos.Dq ".debug_str"
969dd9d0cfSchristossection.
979dd9d0cfSchristosIn case of an error, it returns
989dd9d0cfSchristos.Dv DW_DLV_ERROR
999dd9d0cfSchristosand sets the argument
100cdbf1fe1Sjkoshy.Fa err .
101604b0842Sjkoshy.Sh EXAMPLES
102604b0842SjkoshyTo retrieve all the strings in the DWARF string section, use:
103604b0842Sjkoshy.Bd -literal -offset indent
104604b0842SjkoshyDwarf_Debug dbg;
105604b0842SjkoshyDwarf_Off offset;
106604b0842SjkoshyDwarf_Signed len;
107604b0842SjkoshyDwarf_Error de;
108604b0842Sjkoshychar *str;
109604b0842Sjkoshyint ret
110604b0842Sjkoshy
111604b0842Sjkoshyoffset = 0;
112604b0842Sjkoshywhile ((ret = dwarf_get_str(dbg, offset, &str, &len, &de)) ==
113604b0842Sjkoshy	DW_DLV_OK) {
114604b0842Sjkoshy	/* .. Use the retrieved string. .. */
115604b0842Sjkoshy	offset += len + 1; /* Account for the terminating NUL. */
116604b0842Sjkoshy}
117604b0842Sjkoshy
118604b0842Sjkoshyif (ret == DW_DLV_ERROR)
119604b0842Sjkoshy	warnx("dwarf_get_str: %s", dwarf_errmsg(de));
120604b0842Sjkoshy.Ed
1219dd9d0cfSchristos.Sh ERRORS
1229dd9d0cfSchristosFunction
1239dd9d0cfSchristos.Fn dwarf_get_str
1249dd9d0cfSchristoscan fail with:
1259dd9d0cfSchristos.Bl -tag -width ".Bq Er DW_DLE_NO_ENTRY"
1269dd9d0cfSchristos.It Bq Er DW_DLE_ARGUMENT
1279dd9d0cfSchristosOne of the arguments
128cdbf1fe1Sjkoshy.Fa dbg ,
129cdbf1fe1Sjkoshy.Fa string
1309dd9d0cfSchristosor
131cdbf1fe1Sjkoshy.Fa len
132cdbf1fe1Sjkoshywas
133cdbf1fe1Sjkoshy.Dv NULL .
1349dd9d0cfSchristos.It Bq Er DW_DLE_ARGUMENT
1359dd9d0cfSchristosArgument
136cdbf1fe1Sjkoshy.Fa offset
1379dd9d0cfSchristoswas out of range.
1389dd9d0cfSchristos.It Bq Er DW_DLE_NO_ENTRY
1399dd9d0cfSchristosThe debugging context
140cdbf1fe1Sjkoshy.Fa dbg
1419dd9d0cfSchristosdid not contain a
1429dd9d0cfSchristos.Dq ".debug_str"
1439dd9d0cfSchristosstring section.
1449dd9d0cfSchristos.It Bq Er DW_DLE_NO_ENTRY
1459dd9d0cfSchristosArgument
146cdbf1fe1Sjkoshy.Fa offset
1479dd9d0cfSchristoswas at the very end of the
1489dd9d0cfSchristos.Dq ".debug_str"
1499dd9d0cfSchristossection.
1509dd9d0cfSchristos.El
1519dd9d0cfSchristos.Sh SEE ALSO
1529dd9d0cfSchristos.Xr dwarf 3 ,
1539dd9d0cfSchristos.Xr dwarf_init 3
154