Blame libdwelf/libdwelf.h

Packit Service 97d2fb
/* Interfaces for libdwelf. DWARF ELF Low-level Functions.
Packit Service 97d2fb
   Copyright (C) 2014, 2015, 2016, 2018 Red Hat, Inc.
Packit Service 97d2fb
   This file is part of elfutils.
Packit Service 97d2fb
Packit Service 97d2fb
   This file is free software; you can redistribute it and/or modify
Packit Service 97d2fb
   it under the terms of either
Packit Service 97d2fb
Packit Service 97d2fb
     * the GNU Lesser General Public License as published by the Free
Packit Service 97d2fb
       Software Foundation; either version 3 of the License, or (at
Packit Service 97d2fb
       your option) any later version
Packit Service 97d2fb
Packit Service 97d2fb
   or
Packit Service 97d2fb
Packit Service 97d2fb
     * the GNU General Public License as published by the Free
Packit Service 97d2fb
       Software Foundation; either version 2 of the License, or (at
Packit Service 97d2fb
       your option) any later version
Packit Service 97d2fb
Packit Service 97d2fb
   or both in parallel, as here.
Packit Service 97d2fb
Packit Service 97d2fb
   elfutils is distributed in the hope that it will be useful, but
Packit Service 97d2fb
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 97d2fb
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 97d2fb
   General Public License for more details.
Packit Service 97d2fb
Packit Service 97d2fb
   You should have received copies of the GNU General Public License and
Packit Service 97d2fb
   the GNU Lesser General Public License along with this program.  If
Packit Service 97d2fb
   not, see <http://www.gnu.org/licenses/>.  */
Packit Service 97d2fb
Packit Service 97d2fb
#ifndef _LIBDWELF_H
Packit Service 97d2fb
#define _LIBDWELF_H	1
Packit Service 97d2fb
Packit Service 97d2fb
#include "libdw.h"
Packit Service 97d2fb
Packit Service 97d2fb
#ifdef __cplusplus
Packit Service 97d2fb
extern "C" {
Packit Service 97d2fb
#endif
Packit Service 97d2fb
Packit Service 97d2fb
/* DWARF ELF Low-level Functions (dwelf).
Packit Service 97d2fb
   Functions starting with dwelf_elf will take a (libelf) Elf object as
Packit Service 97d2fb
   first argument and might set elf_errno on error.  Functions starting
Packit Service 97d2fb
   with dwelf_dwarf will take a (libdw) Dwarf object as first argument
Packit Service 97d2fb
   and might set dwarf_errno on error.  */
Packit Service 97d2fb
Packit Service 97d2fb
/* Returns the name and the CRC32 of the separate debug file from the
Packit Service 97d2fb
   .gnu_debuglink section if found in the ELF.  Return NULL if the ELF
Packit Service 97d2fb
   file didn't have a .gnu_debuglink section, had malformed data in the
Packit Service 97d2fb
   section or some other error occured.  */
Packit Service 97d2fb
extern const char *dwelf_elf_gnu_debuglink (Elf *elf, GElf_Word *crc);
Packit Service 97d2fb
Packit Service 97d2fb
/* Returns the name and build ID from the .gnu_debugaltlink section if
Packit Service 97d2fb
   found in the ELF.  On success, pointers to the name and build ID
Packit Service 97d2fb
   are written to *NAMEP and *BUILDID_P, and the positive length of
Packit Service 97d2fb
   the build ID is returned.  Returns 0 if the ELF lacks a
Packit Service 97d2fb
   .gnu_debugaltlink section.  Returns -1 in case of malformed data or
Packit Service 97d2fb
   other errors.  */
Packit Service 97d2fb
extern ssize_t dwelf_dwarf_gnu_debugaltlink (Dwarf *dwarf,
Packit Service 97d2fb
					     const char **namep,
Packit Service 97d2fb
					     const void **build_idp);
Packit Service 97d2fb
Packit Service 97d2fb
/* Returns the build ID as found in a NT_GNU_BUILD_ID note from either
Packit Service 97d2fb
   a SHT_NOTE section or from a PT_NOTE segment if the ELF file
Packit Service 97d2fb
   doesn't contain any section headers.  On success a pointer to the
Packit Service 97d2fb
   build ID is written to *BUILDID_P, and the positive length of the
Packit Service 97d2fb
   build ID is returned.  Returns 0 if the ELF lacks a NT_GNU_BUILD_ID
Packit Service 97d2fb
   note.  Returns -1 in case of malformed data or other errors.  */
Packit Service 97d2fb
extern ssize_t dwelf_elf_gnu_build_id (Elf *elf, const void **build_idp);
Packit Service 97d2fb
Packit Service 97d2fb
/* Returns the size of the uncompressed data of a GNU compressed
Packit Service 97d2fb
   section.  The section name should start with .zdebug (but this
Packit Service 97d2fb
   isn't checked by this function).  If the section isn't compressed
Packit Service 97d2fb
   (the section data doesn't start with ZLIB) -1 is returned. If an
Packit Service 97d2fb
   error occured -1 is returned and elf_errno is set.  */
Packit Service 97d2fb
extern ssize_t dwelf_scn_gnu_compressed_size (Elf_Scn *scn);
Packit Service 97d2fb
Packit Service 97d2fb
/* ELF/DWARF string table handling.  */
Packit Service 97d2fb
typedef struct Dwelf_Strtab Dwelf_Strtab;
Packit Service 97d2fb
typedef struct Dwelf_Strent Dwelf_Strent;
Packit Service 97d2fb
Packit Service 97d2fb
/* Create a new ELF/DWARF string table object in memory.  ELF string
Packit Service 97d2fb
   tables have a required zero length null string at offset zero.
Packit Service 97d2fb
   DWARF string tables don't require such a null entry (unless they
Packit Service 97d2fb
   are shared with an ELF string table).  If NULLSTR is true then a
Packit Service 97d2fb
   null entry is always created (even if the string table is empty
Packit Service 97d2fb
   otherwise).  */
Packit Service 97d2fb
extern Dwelf_Strtab *dwelf_strtab_init (bool nullstr);
Packit Service 97d2fb
Packit Service 97d2fb
/* Add string STR to string table ST.  Returns NULL if no memory could
Packit Service 97d2fb
   be allocated.  The given STR is owned by the called and must be
Packit Service 97d2fb
   valid till dwelf_strtab_free is called.  dwelf_strtab_finalize
Packit Service 97d2fb
   might copy the string into the final table and dwelf_strent_str
Packit Service 97d2fb
   might return it, or a reference to an identical copy/substring
Packit Service 97d2fb
   added to the string table.  */
Packit Service 97d2fb
extern Dwelf_Strent *dwelf_strtab_add (Dwelf_Strtab *st, const char *str)
Packit Service 97d2fb
  __nonnull_attribute__ (1, 2);
Packit Service 97d2fb
Packit Service 97d2fb
/* This is an optimized version of dwelf_strtab_add if the length of
Packit Service 97d2fb
   the string is already known.  LEN is the length of STR including
Packit Service 97d2fb
   zero terminator.  Calling dwelf_strtab_add (st, str) is similar to
Packit Service 97d2fb
   calling dwelf_strtab_len (st, str, strlen (str) + 1).  */
Packit Service 97d2fb
extern Dwelf_Strent *dwelf_strtab_add_len (Dwelf_Strtab *st,
Packit Service 97d2fb
					   const char *str, size_t len)
Packit Service 97d2fb
  __nonnull_attribute__ (1, 2);
Packit Service 97d2fb
Packit Service 97d2fb
/* Finalize string table ST and store size and memory location
Packit Service 97d2fb
   information in DATA d_size and d_buf.  DATA d_type will be set to
Packit Service 97d2fb
   ELF_T_BYTE, d_off will be zero, d_align will be 1 and d_version
Packit Service 97d2fb
   will be set to EV_CURRENT.  If no memory could be allocated NULL is
Packit Service 97d2fb
   returned and DATA->d_buf will be set to NULL.  Otherwise DATA will
Packit Service 97d2fb
   be returned.  */
Packit Service 97d2fb
extern Elf_Data *dwelf_strtab_finalize (Dwelf_Strtab *st,
Packit Service 97d2fb
					Elf_Data *data)
Packit Service 97d2fb
  __nonnull_attribute__ (1, 2);
Packit Service 97d2fb
Packit Service 97d2fb
/* Get offset in string table for string associated with entry.  Only
Packit Service 97d2fb
   valid after dwelf_strtab_finalize has been called.  */
Packit Service 97d2fb
extern size_t dwelf_strent_off (Dwelf_Strent *se)
Packit Service 97d2fb
  __nonnull_attribute__ (1);
Packit Service 97d2fb
Packit Service 97d2fb
/* Return the string associated with the entry.  */
Packit Service 97d2fb
extern const char *dwelf_strent_str (Dwelf_Strent *se)
Packit Service 97d2fb
  __nonnull_attribute__ (1);
Packit Service 97d2fb
Packit Service 97d2fb
/* Free resources allocated for the string table.  This invalidates
Packit Service 97d2fb
   any Dwelf_Strent references returned earlier. */
Packit Service 97d2fb
extern void dwelf_strtab_free (Dwelf_Strtab *st)
Packit Service 97d2fb
  __nonnull_attribute__ (1);
Packit Service 97d2fb
Packit Service 97d2fb
/* Creates a read-only Elf handle from the given file handle.  The
Packit Service 97d2fb
   file may be compressed and/or contain a linux kernel image header,
Packit Service 97d2fb
   in which case it is eagerly decompressed in full and the Elf handle
Packit Service 97d2fb
   is created as if created with elf_memory ().  On decompression or
Packit Service 97d2fb
   file errors NULL is returned (and elf_errno will be set).  If there
Packit Service 97d2fb
   was no error, but the file is not an ELF file, then an ELF_K_NONE
Packit Service 97d2fb
   Elf handle is returned (just like with elf_begin).  The Elf handle
Packit Service 97d2fb
   should be closed with elf_end ().  The file handle will not be
Packit Service 97d2fb
   closed.  */
Packit Service 97d2fb
extern Elf *dwelf_elf_begin (int fd);
Packit Service 97d2fb
Packit Service 97d2fb
/* Returns a human readable string for the given ELF header e_machine
Packit Service 97d2fb
   value, or NULL if the given number isn't currently known.  */
Packit Service 97d2fb
extern const char *dwelf_elf_e_machine_string (int machine);
Packit Service 97d2fb
Packit Service 97d2fb
#ifdef __cplusplus
Packit Service 97d2fb
}
Packit Service 97d2fb
#endif
Packit Service 97d2fb
Packit Service 97d2fb
#endif	/* libdwelf.h */