xref: /freebsd-src/contrib/elftoolchain/libdwarf/dwarf_object_init.3 (revision ae500c1ff8974130f7f2692772cf288b90349e0d)
12de3b87aSKai Wang.\" Copyright (c) 2011 Joseph Koshy
22de3b87aSKai Wang.\" All rights reserved.
32de3b87aSKai Wang.\"
42de3b87aSKai Wang.\" Redistribution and use in source and binary forms, with or without
52de3b87aSKai Wang.\" modification, are permitted provided that the following conditions
62de3b87aSKai Wang.\" are met:
72de3b87aSKai Wang.\" 1. Redistributions of source code must retain the above copyright
82de3b87aSKai Wang.\"    notice, this list of conditions and the following disclaimer.
92de3b87aSKai Wang.\" 2. Redistributions in binary form must reproduce the above copyright
102de3b87aSKai Wang.\"    notice, this list of conditions and the following disclaimer in the
112de3b87aSKai Wang.\"    documentation and/or other materials provided with the distribution.
122de3b87aSKai Wang.\"
132de3b87aSKai Wang.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
142de3b87aSKai Wang.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
152de3b87aSKai Wang.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
162de3b87aSKai Wang.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
172de3b87aSKai Wang.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
182de3b87aSKai Wang.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
192de3b87aSKai Wang.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
202de3b87aSKai Wang.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
212de3b87aSKai Wang.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
222de3b87aSKai Wang.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
232de3b87aSKai Wang.\" SUCH DAMAGE.
242de3b87aSKai Wang.\"
25*ae500c1fSEd Maste.\" $Id: dwarf_object_init.3 3644 2018-10-15 19:55:01Z jkoshy $
262de3b87aSKai Wang.\"
272de3b87aSKai Wang.Dd September 29, 2011
282de3b87aSKai Wang.Dt DWARF_OBJECT_INIT 3
29*ae500c1fSEd Maste.Os
302de3b87aSKai Wang.Sh NAME
312de3b87aSKai Wang.Nm dwarf_object_init
322de3b87aSKai Wang.Nd allocate a DWARF debug descriptor with application-specific file \
332de3b87aSKai Wangaccess methods
342de3b87aSKai Wang.Sh LIBRARY
352de3b87aSKai Wang.Lb libdwarf
362de3b87aSKai Wang.Sh SYNOPSIS
372de3b87aSKai Wang.In libdwarf.h
382de3b87aSKai Wang.Ft int
392de3b87aSKai Wang.Fo dwarf_object_init
402de3b87aSKai Wang.Fa "Dwarf_Obj_Access_Interface *iface"
412de3b87aSKai Wang.Fa "Dwarf_Handler errhand"
422de3b87aSKai Wang.Fa "Dwarf_Ptr errarg"
432de3b87aSKai Wang.Fa "Dwarf_Debug *dbg"
442de3b87aSKai Wang.Fa "Dwarf_Error *err"
452de3b87aSKai Wang.Fc
462de3b87aSKai Wang.Sh DESCRIPTION
472de3b87aSKai WangThe
482de3b87aSKai Wang.Fn dwarf_object_init
492de3b87aSKai Wangfunction allocates and returns a
502de3b87aSKai Wang.Vt Dwarf_Debug
512de3b87aSKai Wanginstance that uses application-supplied access methods to read file
522de3b87aSKai Wangcontent.
532de3b87aSKai Wang.Pp
542de3b87aSKai WangThe argument
552de3b87aSKai Wang.Ar iface
562de3b87aSKai Wangshould point to a populated
572de3b87aSKai Wang.Vt Dwarf_Obj_Access_Interface
582de3b87aSKai Wangstructure.
592de3b87aSKai WangThe contents of the
602de3b87aSKai Wang.Vt Dwarf_Obj_Access_Interface
612de3b87aSKai Wangstructure are described in the section
622de3b87aSKai Wang.Sx "Object Access Functions"
632de3b87aSKai Wangbelow.
642de3b87aSKai Wang.Pp
652de3b87aSKai WangThe argument
662de3b87aSKai Wang.Ar errhand
672de3b87aSKai Wangshould point to a function to be called in case of an error.
682de3b87aSKai WangIf this argument is
692de3b87aSKai Wang.Dv NULL
702de3b87aSKai Wangthen a default error handling scheme is used.
712de3b87aSKai WangSee
722de3b87aSKai Wang.Xr dwarf 3
732de3b87aSKai Wangfor a description of the error handling schemes available.
742de3b87aSKai Wang.Pp
752de3b87aSKai WangThe argument
762de3b87aSKai Wang.Ar errarg
772de3b87aSKai Wangwill be passed to the error handler function pointed to by argument
782de3b87aSKai Wang.Ar errhand .
792de3b87aSKai Wang.Pp
802de3b87aSKai WangThe argument
812de3b87aSKai Wang.Ar dbg
822de3b87aSKai Wangshould point to a memory location that will be set to a reference to
832de3b87aSKai Wangthe returned
842de3b87aSKai Wang.Vt Dwarf_Debug
852de3b87aSKai Wangdescriptor.
862de3b87aSKai Wang.Pp
872de3b87aSKai WangThe argument
882de3b87aSKai Wang.Ar err
892de3b87aSKai Wangwill be used to return a
902de3b87aSKai Wang.Vt Dwarf_Error
912de3b87aSKai Wangdescriptor in case of an error.
922de3b87aSKai Wang.Ss Object Access Functions
932de3b87aSKai WangThe data structures used to specify object access methods are defined
942de3b87aSKai Wangin
952de3b87aSKai Wang.In libdwarf.h .
962de3b87aSKai Wang.Bl -tag -width indent
972de3b87aSKai Wang.It Vt "Dwarf_Obj_Access_Interface"
982de3b87aSKai WangThis structure bundles together a set of file access methods along
992de3b87aSKai Wangwith a pointer to application-private state.
1002de3b87aSKai Wang.Bd -literal -offset indent
1012de3b87aSKai Wangtypedef struct {
1022de3b87aSKai Wang	void *object;
1032de3b87aSKai Wang	const Dwarf_Obj_Access_Methods *methods;
1042de3b87aSKai Wang} Dwarf_Obj_Access_Interface;
1052de3b87aSKai Wang.Ed
1062de3b87aSKai Wang.Pp
1072de3b87aSKai Wang.Bl -tag -width ".Ar methods" -compact
1082de3b87aSKai Wang.It Ar object
1092de3b87aSKai WangThis field points to application-specific state that will be passed as
1102de3b87aSKai Wangthe first parameter to the actual access object methods.
1112de3b87aSKai Wang.It Ar methods
1122de3b87aSKai WangThis structure contains pointers to the functions implementing the
1132de3b87aSKai Wangaccess methods, as described below.
1142de3b87aSKai Wang.El
1152de3b87aSKai Wang.It Vt Dwarf_Obj_Access_Methods
1162de3b87aSKai WangThis structure specifies the functions implementing low-level access.
1172de3b87aSKai Wang.Bd -literal -offset indent
1182de3b87aSKai Wangtypedef struct {
1192de3b87aSKai Wang	int (*get_section_info)(void *obj, Dwarf_Half index,
1202de3b87aSKai Wang	    Dwarf_Obj_Access_Section *ret, int *error);
1212de3b87aSKai Wang	Dwarf_Endianness (*get_byte_order)(void *obj);
1222de3b87aSKai Wang	Dwarf_Small (*get_length_size)(void *obj);
1232de3b87aSKai Wang	Dwarf_Small (*get_pointer_size)(void *obj);
1242de3b87aSKai Wang	Dwarf_Unsigned (*get_section_count)(void *obj);
1252de3b87aSKai Wang	int (*load_section)(void *obj, Dwarf_Half ndx,
1262de3b87aSKai Wang	    Dwarf_Small **ret_data, int *error);
1272de3b87aSKai Wang} Dwarf_Obj_Access_Methods;
1282de3b87aSKai Wang.Ed
1292de3b87aSKai Wang.Pp
1302de3b87aSKai Wang.Bl -tag -width ".Ar get_section_count" -compact
1312de3b87aSKai Wang.It Ar get_byte_order
1322de3b87aSKai WangThis function should return the endianness of the DWARF object by
1332de3b87aSKai Wangreturning one of the constants
1342de3b87aSKai Wang.Dv DW_OBJECT_MSB
1352de3b87aSKai Wangor
1362de3b87aSKai Wang.Dv DW_OBJECT_LSB .
1372de3b87aSKai Wang.It Ar get_length_size
1382de3b87aSKai WangThis function should return the number of bytes needed to represent a
1392de3b87aSKai WangDWARF offset in the object being debugged.
1402de3b87aSKai Wang.It Ar get_pointer_size
1412de3b87aSKai WangThis function should return the size in bytes, in the object being
1422de3b87aSKai Wangdebugged, of a memory address.
1432de3b87aSKai Wang.It Ar get_section_count
1442de3b87aSKai WangThis function should return the number of sections in the object being
1452de3b87aSKai Wangdebugged.
1462de3b87aSKai Wang.It Ar get_section_info
1472de3b87aSKai WangThis function should return information about the section at the
1482de3b87aSKai Wangindex
1492de3b87aSKai Wang.Ar ndx
1502de3b87aSKai Wangby filling in the structure of type
1512de3b87aSKai Wang.Vt Dwarf_Obj_Access_Section
1522de3b87aSKai Wangpointed to by argument
1532de3b87aSKai Wang.Ar ret .
1542de3b87aSKai WangThe
1552de3b87aSKai Wang.Vt Dwarf_Obj_Access_Section
1562de3b87aSKai Wangstructure is described below.
1572de3b87aSKai Wang.It Ar load_section
1582de3b87aSKai WangThis function should load the section specified by argument
1592de3b87aSKai Wang.Ar ndx
1602de3b87aSKai Wanginto memory and place a pointer to the section's data into
1612de3b87aSKai Wangthe location pointed to by argument
1622de3b87aSKai Wang.Ar ret_data .
1632de3b87aSKai Wang.El
1642de3b87aSKai Wang.Pp
1652de3b87aSKai WangThe argument
1662de3b87aSKai Wang.Ar obj
1672de3b87aSKai Wangpassed to these functions will be set to the pointer value in the
1682de3b87aSKai Wang.Ar object
1692de3b87aSKai Wangfield of the associated
1702de3b87aSKai Wang.Vt Dwarf_Obj_Access_Interface
1712de3b87aSKai Wangstructure.
1722de3b87aSKai Wang.Pp
1732de3b87aSKai WangThe argument
1742de3b87aSKai Wang.Ar error
1752de3b87aSKai Wangis used to return an error code in case of an error.
1762de3b87aSKai Wang.It Vt Dwarf_Obj_Access_Section
1772de3b87aSKai WangThis structure describes the layout of a section in the DWARF object.
1782de3b87aSKai Wang.Bd -literal -offset indent
1792de3b87aSKai Wangtypedef struct {
1802de3b87aSKai Wang	Dwarf_Addr addr;
1812de3b87aSKai Wang	Dwarf_Unsigned size;
1822de3b87aSKai Wang	const char *name;
1832de3b87aSKai Wang} Dwarf_Obj_Access_Section;
1842de3b87aSKai Wang.Ed
1852de3b87aSKai Wang.Pp
1862de3b87aSKai Wang.Bl -tag -width ".Ar name" -compact
1872de3b87aSKai Wang.It Ar addr
1882de3b87aSKai WangA pointer to the start of the section's data.
1892de3b87aSKai Wang.It Ar size
1902de3b87aSKai WangThe size of the section in bytes.
1912de3b87aSKai Wang.It Ar name
1922de3b87aSKai WangA pointer to a NUL-terminated string containing the name of the
1932de3b87aSKai Wangsection.
1942de3b87aSKai Wang.El
1952de3b87aSKai Wang.El
1962de3b87aSKai Wang.Sh RETURN VALUES
1972de3b87aSKai WangOn success, the
1982de3b87aSKai Wang.Fn dwarf_object_init
1992de3b87aSKai Wangfunction returns
2002de3b87aSKai Wang.Dv DW_DLV_OK .
2012de3b87aSKai WangIn case of an error, the function returns
2022de3b87aSKai Wang.Dv DW_DLV_ERROR
2032de3b87aSKai Wangand sets the argument
2042de3b87aSKai Wang.Ar err .
2052de3b87aSKai Wang.Sh ERRORS
2062de3b87aSKai WangThe
2072de3b87aSKai Wang.Fn dwarf_object_init
2082de3b87aSKai Wangfunction may fail with the following errors:
2092de3b87aSKai Wang.Bl -tag -width ".Bq Er DW_DLE_DEBUG_INFO_NULL"
2102de3b87aSKai Wang.It Bq Er DW_DLE_ARGUMENT
2112de3b87aSKai WangOne of the arguments
2122de3b87aSKai Wang.Ar iface
2132de3b87aSKai Wangor
2142de3b87aSKai Wang.Ar dbg
2152de3b87aSKai Wangwas NULL.
2162de3b87aSKai Wang.It Bq Er DW_DLE_DEBUG_INFO_NULL
2172de3b87aSKai WangThe underlying object did not contain debugging information.
2182de3b87aSKai Wang.It Bq Er DW_DLE_MEMORY
2192de3b87aSKai WangAn out of memory condition was encountered during the execution of the
2202de3b87aSKai Wangfunction.
2212de3b87aSKai Wang.El
2222de3b87aSKai Wang.Sh SEE ALSO
2232de3b87aSKai Wang.Xr dwarf 3 ,
2242de3b87aSKai Wang.Xr dwarf_init 3 ,
2252de3b87aSKai Wang.Xr dwarf_init_elf 3 ,
2262de3b87aSKai Wang.Xr dwarf_object_finish 3
227