Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

dwarf_get_section_bytes(3) [freebsd man page]

DWARF_GET_SECTION_BYTES(3)				   BSD Library Functions Manual 				DWARF_GET_SECTION_BYTES(3)

NAME
dwarf_get_section_bytes -- retrieve ELF section byte streams LIBRARY
DWARF Access Library (libdwarf, -ldwarf) SYNOPSIS
#include <libdwarf.h> Dwarf_Ptr dwarf_get_section_bytes(Dwarf_P_Debug dbg, Dwarf_Signed dwarf_section, Dwarf_Signed *elf_section_index, Dwarf_Unsigned *length, Dwarf_Error *err); DESCRIPTION
Function dwarf_get_section_bytes() returns the ELF section byte streams generated by a prior call to function dwarf_transform_to_disk_form(3). Each call to function dwarf_get_section_bytes() will return the byte stream for one ELF section. The first call to this function will always return the first ELF section, and the subsequent calls will return the rest of sections in the order when they were generated, until the last one. The total number of sections generated is returned by the function dwarf_transform_to_disk_form(3). Argument dbg should reference a DWARF producer instance allocated using the functions dwarf_producer_init(3) or dwarf_producer_init_b(3). Argument dwarf_section is currently ignored. Argument elf_section_index should point to a location which will be set to the section index value of the returned ELF section. Argument length should point to a location which will hold the length in bytes of the returned ELF section. If argument err is not NULL, it will be used to store error information in case of an error. Memory Management The memory areas used for the returned ELF section byte streams should be freed using the function dwarf_producer_finish(). RETURN VALUES
On success, function dwarf_get_section_bytes() returns a pointer to a ELF section byte stream. In case of an error, function dwarf_get_section_bytes() will return NULL and set the argument err. ERRORS
Function dwarf_get_section_bytes() can fail with: [DW_DLE_ARGUMENT] One of the arguments dbg, elf_section_index, or length was NULL. [DW_DLE_NO_ENTRY] There were no more ELF sections to retrieve, or the function was called before a call to dwarf_transform_to_disk_form(3). EXAMPLES
To generate and retrieve ELF section byte streams, use: Dwarf_P_Debug dbg; Dwarf_Signed count, i, sec_index; Dwarf_Unsigned len; Dwarf_Ptr bytes; Dwarf_Error de; /* ... Assume that `dbg' refers to a DWARF producer instance, * and that application code has added DWARF debugging * information to the producer instance. ... */ if ((count = dwarf_transform_to_disk_form(dbg, &de)) == DW_DLV_NOCOUNT) { warnx("dwarf_transform_to_disk_form failed: %s", dwarf_errmsg(-1)); return; } /* Retrieve section data. */ for (i = 0; i < count; i++) { bytes = dwarf_get_section_bytes(dbg, i, &sec_index, &len, &de); if (bytes == NULL) { warnx("dwarf_get_section_bytes failed: %s", dwarf_errmsg(-1)); continue; } /* ... use the returned byte stream ... */ } /* Release resources. */ dwarf_producer_finish(dbg, &de); SEE ALSO
dwarf(3), dwarf_reset_section_bytes(3), dwarf_producer_finish(3), dwarf_producer_init(3), dwarf_producer_init_b(3), dwarf_transform_to_disk_form(3) BSD
August 26, 2011 BSD

Check Out this Related Man Page

DWARF_PRODUCER_INIT(3)					   BSD Library Functions Manual 				    DWARF_PRODUCER_INIT(3)

NAME
dwarf_producer_init dwarf_producer_init_b -- allocate a DWARF producer descriptor LIBRARY
DWARF Access Library (libdwarf, -ldwarf) SYNOPSIS
#include <libdwarf.h> Dwarf_P_Debug dwarf_producer_init(Dwarf_Unsigned flags, Dwarf_Callback_Func func, Dwarf_Handler errhand, Dwarf_Ptr errarg, Dwarf_Error *err); Dwarf_P_Debug dwarf_producer_init_b(Dwarf_Unsigned flags, Dwarf_Callback_Func_b func, Dwarf_Handler errhand, Dwarf_Ptr errarg, Dwarf_Error *error); DESCRIPTION
These functions allocate and return a Dwarf_P_Debug descriptor representing a DWARF producer instance. The argument errhand should contain the adddress of a function to be called in case of an error. If this argument is NULL, the default error handling scheme is used, see dwarf(3). The argument errarg will be passed to the error handler function when it is invoked. The argument err references a memory location that would hold a Dwarf_Error descriptor in case of an error. The argument flags specifies additional characteristics of the DWARF producer instance. The following flags are recognized: DW_DLC_ISA_IA64 (Deprecated) The target instruction set architecture is IA64. This flag is deprecated. Application code should use the dwarf_producer_set_isa(3) function to specify target instruction set architecture. DW_DLC_ISA_MIPS (Deprecated) The target instruction set architecture is MIPS. This flag is deprecated. Application code should use the dwarf_producer_set_isa(3) function to specify target instruction set architecture. DW_DLC_SIZE_32 (Default) The target address size is 32-bit. DW_DLC_SIZE_64 The target address size is 64-bit. DW_DLC_STREAM_RELOCATIONS (Default) Generate stream relocations. DW_DLC_SYMBOLIC_RELOCATIONS Generate symbolic relocations. DW_DLC_TARGET_BIGENDIAN The target is big endian. DW_DLC_TARGET_LITTLEENDIAN The target is little endian. DW_DLC_WRITE (Required) Permit writing of DWARF information. The following flags are mutually exclusive. o Flags DW_DLC_ISA_IA64 and DW_DLC_ISA_MIPS. o Flags DW_DLC_SIZE_32 and DW_DLC_SIZE_64. o Flags DW_DLC_STREAM_RELOCATIONS and DW_DLC_SYMBOLIC_RELOCATIONS. o Flags DW_DLC_TARGET_BIGENDIAN and DW_DLC_TARGET_LITTLEENDIAN. If neither of the flags DW_DLC_TARGET_BIGENDIAN and DW_DLC_TARGET_LITTLEENDIAN is set, the target's endianness is assumed to be the same as the host's endianness. Argument func should point to an application-provided callback function of type Dwarf_Callback_Func_b. The type Dwarf_Callback_Func_b is defined in the header file <libdwarf.h> as: typedef int (*Dwarf_Callback_Func_b)(char *name, int size, Dwarf_Unsigned type, Dwarf_Unsigned flags, Dwarf_Unsigned link, Dwarf_Unsigned info, Dwarf_Unsigned *index, int *error); This function is called by the DWARF Access Library (libdwarf, -ldwarf) once for each section in the object file that the library needs to create. The arguments to this callback function specify the values in the ELF section header for the section being created: name The name of the section being created. size The sh_size value in the section header. type The sh_type value in the section header. flags The sh_flags value in the section header. link The sh_link value in the section header. info The sh_info value in the section header. On success, the callback function should return the section index value of the created section, and set the location pointed to by argument index to the symbol table index of the symbol that associated with the newly created section. This symbol table index will be used in relo- cation entries referring to the created section. In case of failure, the callback function should return -1 and set the location pointed to by argument error to an application-defined error code. This application returned error code is currently ignored by the library. Function dwarf_producer_init() is deprecated. Function dwarf_producer_init() is identical to function dwarf_producer_init_b() except that the callback function it expects can not properly handle arbitrary section symbol index values. Memory Management The Dwarf_P_Debug instance returned by these functions should be freed using the function dwarf_producer_finish(). RETURN VALUES
On success, these functions return the created DWARF producer descriptor. In case of an error, they return DW_DLV_BADADDR and set the argu- ment err. ERRORS
These functions can fail with: [DW_DLE_ARGUMENT] Argument func was NULL. [DW_DLE_ARGUMENT] The flag DW_DLC_WRITE was not set in argument flags. [DW_DLE_ARGUMENT] The flags DW_DLC_SIZE_32 and DW_DLC_SIZE_64 were both set in argument flags. [DW_DLE_ARGUMENT] The flags DW_DLC_ISA_IA64 and DW_DLC_ISA_MIPS were both set in argument flags. [DW_DLE_ARGUMENT] The flags DW_DLC_TARGET_BIGENDIAN and DW_DLC_TARGET_LITTLEENDIAN were both set in argument flags. [DW_DLE_ARGUMENT] The flags DW_DLC_STREAM_RELOCATIONS and DW_DLC_SYMBOLIC_RELOCATIONS were both set in argument flags. [DW_DLE_MEMORY] An out of memory condition was encountered. EXAMPLES
To initialize a Dwarf_P_Debug instance for a MIPS32 big endian object, use: Dwarf_P_Debug dbg; Dwarf_Unsigned flags; Dwarf_Error de; /* ... assume cb_func points to the callback function ... */ flags = DW_DLC_WRITE | DW_DLC_SIZE_32 | DW_DLC_ISA_MIPS | DW_DLC_STREAM_RELOCATIONS | DW_DLC_TARGET_BIGENDIAN; if ((dbg = dwarf_producer_init(flags, cb_func, NULL, NULL, &de)) == DW_DLV_BADADDR) warnx("dwarf_producer_init failed: %s", dwarf_errmsg(-1)); SEE ALSO
dwarf(3), dwarf_errmsg(3), dwarf_producer_finish(3), dwarf_producer_set_isa(3), dwarf_transform_to_disk_form(3) BSD
August 20, 2011 BSD
Man Page