Copyright (c) 2011 Joseph Koshy
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

$Id: dwarf_object_init.3 3644 2018-10-15 19:55:01Z jkoshy $

.Dd September 29, 2011 .Dt DWARF_OBJECT_INIT 3 .Os .Sh NAME .Nm dwarf_object_init .Nd allocate a DWARF debug descriptor with application-specific file \ access methods .Sh LIBRARY .Lb libdwarf .Sh SYNOPSIS n libdwarf.h .Ft int .Fo dwarf_object_init .Fa "Dwarf_Obj_Access_Interface *iface" .Fa "Dwarf_Handler errhand" .Fa "Dwarf_Ptr errarg" .Fa "Dwarf_Debug *dbg" .Fa "Dwarf_Error *err" .Fc .Sh DESCRIPTION The .Fn dwarf_object_init function allocates and returns a .Vt Dwarf_Debug instance that uses application-supplied access methods to read file content.

p The argument .Ar iface should point to a populated .Vt Dwarf_Obj_Access_Interface structure. The contents of the .Vt Dwarf_Obj_Access_Interface structure are described in the section .Sx "Object Access Functions" below.

p The argument .Ar errhand should point to a function to be called in case of an error. If this argument is .Dv NULL then a default error handling scheme is used. See .Xr dwarf 3 for a description of the error handling schemes available.

p The argument .Ar errarg will be passed to the error handler function pointed to by argument .Ar errhand .

p The argument .Ar dbg should point to a memory location that will be set to a reference to the returned .Vt Dwarf_Debug descriptor.

p The argument .Ar err will be used to return a .Vt Dwarf_Error descriptor in case of an error. .Ss Object Access Functions The data structures used to specify object access methods are defined in n libdwarf.h . l -tag -width indent t Vt "Dwarf_Obj_Access_Interface" This structure bundles together a set of file access methods along with a pointer to application-private state. d -literal -offset indent typedef struct { void *object; const Dwarf_Obj_Access_Methods *methods; } Dwarf_Obj_Access_Interface; .Ed

p l -tag -width ".Ar methods" -compact t Ar object This field points to application-specific state that will be passed as the first parameter to the actual access object methods. t Ar methods This structure contains pointers to the functions implementing the access methods, as described below. .El t Vt Dwarf_Obj_Access_Methods This structure specifies the functions implementing low-level access. d -literal -offset indent typedef struct { int (*get_section_info)(void *obj, Dwarf_Half index, Dwarf_Obj_Access_Section *ret, int *error); Dwarf_Endianness (*get_byte_order)(void *obj); Dwarf_Small (*get_length_size)(void *obj); Dwarf_Small (*get_pointer_size)(void *obj); Dwarf_Unsigned (*get_section_count)(void *obj); int (*load_section)(void *obj, Dwarf_Half ndx, Dwarf_Small **ret_data, int *error); } Dwarf_Obj_Access_Methods; .Ed

p l -tag -width ".Ar get_section_count" -compact t Ar get_byte_order This function should return the endianness of the DWARF object by returning one of the constants .Dv DW_OBJECT_MSB or .Dv DW_OBJECT_LSB . t Ar get_length_size This function should return the number of bytes needed to represent a DWARF offset in the object being debugged. t Ar get_pointer_size This function should return the size in bytes, in the object being debugged, of a memory address. t Ar get_section_count This function should return the number of sections in the object being debugged. t Ar get_section_info This function should return information about the section at the index .Ar ndx by filling in the structure of type .Vt Dwarf_Obj_Access_Section pointed to by argument .Ar ret . The .Vt Dwarf_Obj_Access_Section structure is described below. t Ar load_section This function should load the section specified by argument .Ar ndx into memory and place a pointer to the section's data into the location pointed to by argument .Ar ret_data . .El

p The argument .Ar obj passed to these functions will be set to the pointer value in the .Ar object field of the associated .Vt Dwarf_Obj_Access_Interface structure.

p The argument .Ar error is used to return an error code in case of an error. t Vt Dwarf_Obj_Access_Section This structure describes the layout of a section in the DWARF object. d -literal -offset indent typedef struct { Dwarf_Addr addr; Dwarf_Unsigned size; const char *name; } Dwarf_Obj_Access_Section; .Ed

p l -tag -width ".Ar name" -compact t Ar addr A pointer to the start of the section's data. t Ar size The size of the section in bytes. t Ar name A pointer to a NUL-terminated string containing the name of the section. .El .El .Sh RETURN VALUES On success, the .Fn dwarf_object_init function returns .Dv DW_DLV_OK . In case of an error, the function returns .Dv DW_DLV_ERROR and sets the argument .Ar err . .Sh ERRORS The .Fn dwarf_object_init function may fail with the following errors: l -tag -width ".Bq Er DW_DLE_DEBUG_INFO_NULL" t Bq Er DW_DLE_ARGUMENT One of the arguments .Ar iface or .Ar dbg was NULL. t Bq Er DW_DLE_DEBUG_INFO_NULL The underlying object did not contain debugging information. t Bq Er DW_DLE_MEMORY An out of memory condition was encountered during the execution of the function. .El .Sh SEE ALSO .Xr dwarf 3 , .Xr dwarf_init 3 , .Xr dwarf_init_elf 3 , .Xr dwarf_object_finish 3