Blame libdwfl/libdwfl.h

Packit Service 97d2fb
/* Interfaces for libdwfl.
Packit Service 97d2fb
   Copyright (C) 2005-2010, 2013 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 _LIBDWFL_H
Packit Service 97d2fb
#define _LIBDWFL_H	1
Packit Service 97d2fb
Packit Service 97d2fb
#include "libdw.h"
Packit Service 97d2fb
#include <stdio.h>
Packit Service 97d2fb
Packit Service 97d2fb
/* Handle for a session using the library.  */
Packit Service 97d2fb
typedef struct Dwfl Dwfl;
Packit Service 97d2fb
Packit Service 97d2fb
/* Handle for a module.  */
Packit Service 97d2fb
typedef struct Dwfl_Module Dwfl_Module;
Packit Service 97d2fb
Packit Service 97d2fb
/* Handle describing a line record.  */
Packit Service 97d2fb
typedef struct Dwfl_Line Dwfl_Line;
Packit Service 97d2fb
Packit Service 97d2fb
/* This holds information common for all the frames of one backtrace for
Packit Service 97d2fb
   a partical thread/task/TID.  Several threads belong to one Dwfl.  */
Packit Service 97d2fb
typedef struct Dwfl_Thread Dwfl_Thread;
Packit Service 97d2fb
Packit Service 97d2fb
/* This holds everything we know about the state of the frame at a particular
Packit Service 97d2fb
   PC location described by an FDE belonging to Dwfl_Thread.  */
Packit Service 97d2fb
typedef struct Dwfl_Frame Dwfl_Frame;
Packit Service 97d2fb
Packit Service 97d2fb
/* Callbacks.  */
Packit Service 97d2fb
typedef struct
Packit Service 97d2fb
{
Packit Service 97d2fb
  int (*find_elf) (Dwfl_Module *mod, void **userdata,
Packit Service 97d2fb
		   const char *modname, Dwarf_Addr base,
Packit Service 97d2fb
		   char **file_name, Elf **elfp);
Packit Service 97d2fb
Packit Service 97d2fb
  int (*find_debuginfo) (Dwfl_Module *mod, void **userdata,
Packit Service 97d2fb
			 const char *modname, Dwarf_Addr base,
Packit Service 97d2fb
			 const char *file_name,
Packit Service 97d2fb
			 const char *debuglink_file, GElf_Word debuglink_crc,
Packit Service 97d2fb
			 char **debuginfo_file_name);
Packit Service 97d2fb
Packit Service 97d2fb
  /* Fill *ADDR with the loaded address of the section called SECNAME in
Packit Service 97d2fb
     the given module.  Use (Dwarf_Addr) -1 if this section is omitted from
Packit Service 97d2fb
     accessible memory.  This is called exactly once for each SHF_ALLOC
Packit Service 97d2fb
     section that relocations affecting DWARF data refer to, so it can
Packit Service 97d2fb
     easily be used to collect state about the sections referenced.  */
Packit Service 97d2fb
  int (*section_address) (Dwfl_Module *mod, void **userdata,
Packit Service 97d2fb
			  const char *modname, Dwarf_Addr base,
Packit Service 97d2fb
			  const char *secname,
Packit Service 97d2fb
			  GElf_Word shndx, const GElf_Shdr *shdr,
Packit Service 97d2fb
			  Dwarf_Addr *addr);
Packit Service 97d2fb
Packit Service 97d2fb
  char **debuginfo_path;	/* See dwfl_standard_find_debuginfo.  */
Packit Service 97d2fb
} Dwfl_Callbacks;
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
#ifdef __cplusplus
Packit Service 97d2fb
extern "C" {
Packit Service 97d2fb
#endif
Packit Service 97d2fb
Packit Service 97d2fb
/* Start a new session with the library.  */
Packit Service 97d2fb
extern Dwfl *dwfl_begin (const Dwfl_Callbacks *callbacks)
Packit Service 97d2fb
  __nonnull_attribute__ (1);
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
/* End a session.  */
Packit Service 97d2fb
extern void dwfl_end (Dwfl *);
Packit Service 97d2fb
Packit Service 97d2fb
/* Return implementation's version string suitable for printing.  */
Packit Service 97d2fb
extern const char *dwfl_version (Dwfl *);
Packit Service 97d2fb
Packit Service 97d2fb
/* Return error code of last failing function call.  This value is kept
Packit Service 97d2fb
   separately for each thread.  */
Packit Service 97d2fb
extern int dwfl_errno (void);
Packit Service 97d2fb
Packit Service 97d2fb
/* Return error string for ERROR.  If ERROR is zero, return error string
Packit Service 97d2fb
   for most recent error or NULL if none occurred.  If ERROR is -1 the
Packit Service 97d2fb
   behaviour is similar to the last case except that not NULL but a legal
Packit Service 97d2fb
   string is returned.  */
Packit Service 97d2fb
extern const char *dwfl_errmsg (int err);
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
/* Start reporting the current set of segments and modules to the library.
Packit Service 97d2fb
   All existing segments are wiped.  Existing modules are marked to be
Packit Service 97d2fb
   deleted, and will not be found via dwfl_addrmodule et al if they are not
Packit Service 97d2fb
   re-reported before dwfl_report_end is called.  */
Packit Service 97d2fb
extern void dwfl_report_begin (Dwfl *dwfl);
Packit Service 97d2fb
Packit Service 97d2fb
/* Report that segment NDX begins at PHDR->p_vaddr + BIAS.
Packit Service 97d2fb
   If NDX is < 0, the value succeeding the last call's NDX
Packit Service 97d2fb
   is used instead (zero on the first call).  IDENT is ignored.
Packit Service 97d2fb
Packit Service 97d2fb
   If nonzero, the smallest PHDR->p_align value seen sets the
Packit Service 97d2fb
   effective page size for the address space DWFL describes.
Packit Service 97d2fb
   This is the granularity at which reported module boundary
Packit Service 97d2fb
   addresses will be considered to fall in or out of a segment.
Packit Service 97d2fb
Packit Service 97d2fb
   Returns -1 for errors, or NDX (or its assigned replacement) on success.
Packit Service 97d2fb
Packit Service 97d2fb
   Reporting segments at all is optional.  Its only benefit to the caller is to
Packit Service 97d2fb
   offer this quick lookup via dwfl_addrsegment, or use other segment-based
Packit Service 97d2fb
   calls.  */
Packit Service 97d2fb
extern int dwfl_report_segment (Dwfl *dwfl, int ndx,
Packit Service 97d2fb
				const GElf_Phdr *phdr, GElf_Addr bias,
Packit Service 97d2fb
				const void *ident);
Packit Service 97d2fb
Packit Service 97d2fb
/* Report that a module called NAME spans addresses [START, END).
Packit Service 97d2fb
   Returns the module handle, either existing or newly allocated,
Packit Service 97d2fb
   or returns a null pointer for an allocation error.  */
Packit Service 97d2fb
extern Dwfl_Module *dwfl_report_module (Dwfl *dwfl, const char *name,
Packit Service 97d2fb
					Dwarf_Addr start, Dwarf_Addr end);
Packit Service 97d2fb
Packit Service 97d2fb
/* Report a module to address BASE with start and end addresses computed
Packit Service 97d2fb
   from the ELF program headers in the given file - see the table below.
Packit Service 97d2fb
   FD may be -1 to open FILE_NAME.  On success, FD is consumed by the
Packit Service 97d2fb
   library, and the `find_elf' callback will not be used for this module.
Packit Service 97d2fb
	    ADD_P_VADDR  BASE
Packit Service 97d2fb
   ET_EXEC  ignored      ignored
Packit Service 97d2fb
   ET_DYN   false        absolute address where to place the file
Packit Service 97d2fb
	    true         start address relative to ELF's phdr p_vaddr
Packit Service 97d2fb
   ET_REL   ignored      absolute address where to place the file
Packit Service 97d2fb
   ET_CORE  ignored      ignored
Packit Service 97d2fb
   ET_DYN ELF phdr p_vaddr address can be non-zero if the shared library
Packit Service 97d2fb
   has been prelinked by tool prelink(8).  */
Packit Service 97d2fb
extern Dwfl_Module *dwfl_report_elf (Dwfl *dwfl, const char *name,
Packit Service 97d2fb
				     const char *file_name, int fd,
Packit Service 97d2fb
				     GElf_Addr base, bool add_p_vaddr);
Packit Service 97d2fb
Packit Service 97d2fb
/* Similar, but report the module for offline use.  All ET_EXEC files
Packit Service 97d2fb
   being reported must be reported before any relocatable objects.
Packit Service 97d2fb
   If this is used, dwfl_report_module and dwfl_report_elf may not be
Packit Service 97d2fb
   used in the same reporting session.  */
Packit Service 97d2fb
extern Dwfl_Module *dwfl_report_offline (Dwfl *dwfl, const char *name,
Packit Service 97d2fb
					 const char *file_name, int fd);
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
/* Finish reporting the current set of modules to the library.
Packit Service 97d2fb
   If REMOVED is not null, it's called for each module that
Packit Service 97d2fb
   existed before but was not included in the current report.
Packit Service 97d2fb
   Returns a nonzero return value from the callback.
Packit Service 97d2fb
   The callback may call dwfl_report_module; doing so with the
Packit Service 97d2fb
   details of the module being removed prevents its removal.
Packit Service 97d2fb
   DWFL cannot be used until this function has returned zero.  */
Packit Service 97d2fb
extern int dwfl_report_end (Dwfl *dwfl,
Packit Service 97d2fb
			    int (*removed) (Dwfl_Module *, void *,
Packit Service 97d2fb
					    const char *, Dwarf_Addr,
Packit Service 97d2fb
					    void *arg),
Packit Service 97d2fb
			    void *arg);
Packit Service 97d2fb
Packit Service 97d2fb
/* Start reporting additional modules to the library.  No calls but
Packit Service 97d2fb
   dwfl_report_* can be made on DWFL until dwfl_report_end is called.
Packit Service 97d2fb
   This is like dwfl_report_begin, but all the old modules are kept on.
Packit Service 97d2fb
   More dwfl_report_* calls can follow to add more modules.
Packit Service 97d2fb
   When dwfl_report_end is called, no old modules will be removed.  */
Packit Service 97d2fb
extern void dwfl_report_begin_add (Dwfl *dwfl);
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
/* Return the name of the module, and for each non-null argument store
Packit Service 97d2fb
   interesting details: *USERDATA is a location for storing your own
Packit Service 97d2fb
   pointer, **USERDATA is initially null; *START and *END give the address
Packit Service 97d2fb
   range covered by the module; *DWBIAS is the address bias for debugging
Packit Service 97d2fb
   information, and *SYMBIAS for symbol table entries (either is -1 if not
Packit Service 97d2fb
   yet accessed); *MAINFILE is the name of the ELF file, and *DEBUGFILE the
Packit Service 97d2fb
   name of the debuginfo file (might be equal to *MAINFILE; either is null
Packit Service 97d2fb
   if not yet accessed).  */
Packit Service 97d2fb
extern const char *dwfl_module_info (Dwfl_Module *mod, void ***userdata,
Packit Service 97d2fb
				     Dwarf_Addr *start, Dwarf_Addr *end,
Packit Service 97d2fb
				     Dwarf_Addr *dwbias, Dwarf_Addr *symbias,
Packit Service 97d2fb
				     const char **mainfile,
Packit Service 97d2fb
				     const char **debugfile);
Packit Service 97d2fb
Packit Service 97d2fb
/* Iterate through the modules, starting the walk with OFFSET == 0.
Packit Service 97d2fb
   Calls *CALLBACK for each module as long as it returns DWARF_CB_OK.
Packit Service 97d2fb
   When *CALLBACK returns another value, the walk stops and the
Packit Service 97d2fb
   return value can be passed as OFFSET to resume it.  Returns 0 when
Packit Service 97d2fb
   there are no more modules, or -1 for errors.  */
Packit Service 97d2fb
extern ptrdiff_t dwfl_getmodules (Dwfl *dwfl,
Packit Service 97d2fb
				  int (*callback) (Dwfl_Module *, void **,
Packit Service 97d2fb
						   const char *, Dwarf_Addr,
Packit Service 97d2fb
						   void *arg),
Packit Service 97d2fb
				  void *arg,
Packit Service 97d2fb
				  ptrdiff_t offset);
Packit Service 97d2fb
Packit Service 97d2fb
/* Find the module containing the given address.  */
Packit Service 97d2fb
extern Dwfl_Module *dwfl_addrmodule (Dwfl *dwfl, Dwarf_Addr address);
Packit Service 97d2fb
Packit Service 97d2fb
/* Find the segment, if any, and module, if any, containing ADDRESS.
Packit Service 97d2fb
   Returns a segment index returned by dwfl_report_segment, or -1
Packit Service 97d2fb
   if no segment matches the address.  Regardless of the return value,
Packit Service 97d2fb
   *MOD is always set to the module containing ADDRESS, or to null.  */
Packit Service 97d2fb
extern int dwfl_addrsegment (Dwfl *dwfl, Dwarf_Addr address, Dwfl_Module **mod);
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
/* Report the known build ID bits associated with a module.
Packit Service 97d2fb
   If VADDR is nonzero, it gives the absolute address where those
Packit Service 97d2fb
   bits are found within the module.  This can be called at any
Packit Service 97d2fb
   time, but is usually used immediately after dwfl_report_module.
Packit Service 97d2fb
   Once the module's main ELF file is opened, the ID note found
Packit Service 97d2fb
   there takes precedence and cannot be changed.  */
Packit Service 97d2fb
extern int dwfl_module_report_build_id (Dwfl_Module *mod,
Packit Service 97d2fb
					const unsigned char *bits, size_t len,
Packit Service 97d2fb
					GElf_Addr vaddr)
Packit Service 97d2fb
  __nonnull_attribute__ (2);
Packit Service 97d2fb
Packit Service 97d2fb
/* Extract the build ID bits associated with a module.
Packit Service 97d2fb
   Returns -1 for errors, 0 if no ID is known, or the number of ID bytes.
Packit Service 97d2fb
   When an ID is found, *BITS points to it; *VADDR is the absolute address
Packit Service 97d2fb
   at which the ID bits are found within the module, or 0 if unknown.
Packit Service 97d2fb
Packit Service 97d2fb
   This returns 0 when the module's main ELF file has not yet been loaded
Packit Service 97d2fb
   and its build ID bits were not reported.  To ensure the ID is always
Packit Service 97d2fb
   returned when determinable, call dwfl_module_getelf first.  */
Packit Service 97d2fb
extern int dwfl_module_build_id (Dwfl_Module *mod,
Packit Service 97d2fb
				 const unsigned char **bits, GElf_Addr *vaddr)
Packit Service 97d2fb
  __nonnull_attribute__ (2, 3);
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
/*** Standard callbacks ***/
Packit Service 97d2fb
Packit Service 97d2fb
/* These standard find_elf and find_debuginfo callbacks are
Packit Service 97d2fb
   controlled by a string specifying directories to look in.
Packit Service 97d2fb
   If `debuginfo_path' is set in the Dwfl_Callbacks structure
Packit Service 97d2fb
   and the char * it points to is not null, that supplies the
Packit Service 97d2fb
   string.  Otherwise a default path is used.
Packit Service 97d2fb
Packit Service 97d2fb
   If the first character of the string is + or - that enables or
Packit Service 97d2fb
   disables CRC32 checksum validation when it's necessary.  The
Packit Service 97d2fb
   remainder of the string is composed of elements separated by
Packit Service 97d2fb
   colons.  Each element can start with + or - to override the
Packit Service 97d2fb
   global checksum behavior.  This flag is never relevant when
Packit Service 97d2fb
   working with build IDs, but it's always parsed in the path
Packit Service 97d2fb
   string.  The remainder of the element indicates a directory.
Packit Service 97d2fb
Packit Service 97d2fb
   Searches by build ID consult only the elements naming absolute
Packit Service 97d2fb
   directory paths.  They look under those directories for a link
Packit Service 97d2fb
   named ".build-id/xx/yy" or ".build-id/xx/yy.debug", where "xxyy"
Packit Service 97d2fb
   is the lower-case hexadecimal representation of the ID bytes.
Packit Service 97d2fb
Packit Service 97d2fb
   In searches for debuginfo by name, if the remainder of the
Packit Service 97d2fb
   element is empty, the directory containing the main file is
Packit Service 97d2fb
   tried; if it's an absolute path name, the absolute directory path
Packit Service 97d2fb
   (and any subdirectory of that path) containing the main file is
Packit Service 97d2fb
   taken as a subdirectory of this path; a relative path name is taken
Packit Service 97d2fb
   as a subdirectory of the directory containing the main file.
Packit Service 97d2fb
   Hence for /usr/bin/ls, the default string ":.debug:/usr/lib/debug"
Packit Service 97d2fb
   says to look in /usr/bin, then /usr/bin/.debug, then the path subdirs
Packit Service 97d2fb
   under /usr/lib/debug, in the order /usr/lib/debug/usr/bin, then
Packit Service 97d2fb
   /usr/lib/debug/bin, and finally /usr/lib/debug, for the file name in
Packit Service 97d2fb
   the .gnu_debuglink section (or "ls.debug" if none was found).  */
Packit Service 97d2fb
Packit Service 97d2fb
/* Standard find_elf callback function working solely on build ID.
Packit Service 97d2fb
   This can be tried first by any find_elf callback, to use the
Packit Service 97d2fb
   bits passed to dwfl_module_report_build_id, if any.  */
Packit Service 97d2fb
extern int dwfl_build_id_find_elf (Dwfl_Module *, void **,
Packit Service 97d2fb
				   const char *, Dwarf_Addr,
Packit Service 97d2fb
				   char **, Elf **);
Packit Service 97d2fb
Packit Service 97d2fb
/* Standard find_debuginfo callback function working solely on build ID.
Packit Service 97d2fb
   This can be tried first by any find_debuginfo callback,
Packit Service 97d2fb
   to use the build ID bits from the main file when present.  */
Packit Service 97d2fb
extern int dwfl_build_id_find_debuginfo (Dwfl_Module *, void **,
Packit Service 97d2fb
					 const char *, Dwarf_Addr,
Packit Service 97d2fb
					 const char *, const char *,
Packit Service 97d2fb
					 GElf_Word, char **);
Packit Service 97d2fb
Packit Service 97d2fb
/* Standard find_debuginfo callback function.
Packit Service 97d2fb
   If a build ID is available, this tries first to use that.
Packit Service 97d2fb
   If there is no build ID or no valid debuginfo found by ID,
Packit Service 97d2fb
   it searches the debuginfo path by name, as described above.
Packit Service 97d2fb
   Any file found in the path is validated by build ID if possible,
Packit Service 97d2fb
   or else by CRC32 checksum if enabled, and skipped if it does not match.  */
Packit Service 97d2fb
extern int dwfl_standard_find_debuginfo (Dwfl_Module *, void **,
Packit Service 97d2fb
					 const char *, Dwarf_Addr,
Packit Service 97d2fb
					 const char *, const char *,
Packit Service 97d2fb
					 GElf_Word, char **);
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
/* This callback must be used when using dwfl_offline_* to report modules,
Packit Service 97d2fb
   if ET_REL is to be supported.  */
Packit Service 97d2fb
extern int dwfl_offline_section_address (Dwfl_Module *, void **,
Packit Service 97d2fb
					 const char *, Dwarf_Addr,
Packit Service 97d2fb
					 const char *, GElf_Word,
Packit Service 97d2fb
					 const GElf_Shdr *,
Packit Service 97d2fb
					 Dwarf_Addr *addr);
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
/* Callbacks for working with kernel modules in the running Linux kernel.  */
Packit Service 97d2fb
extern int dwfl_linux_kernel_find_elf (Dwfl_Module *, void **,
Packit Service 97d2fb
				       const char *, Dwarf_Addr,
Packit Service 97d2fb
				       char **, Elf **);
Packit Service 97d2fb
extern int dwfl_linux_kernel_module_section_address (Dwfl_Module *, void **,
Packit Service 97d2fb
						     const char *, Dwarf_Addr,
Packit Service 97d2fb
						     const char *, GElf_Word,
Packit Service 97d2fb
						     const GElf_Shdr *,
Packit Service 97d2fb
						     Dwarf_Addr *addr);
Packit Service 97d2fb
Packit Service 97d2fb
/* Call dwfl_report_elf for the running Linux kernel.
Packit Service 97d2fb
   Returns zero on success, -1 if dwfl_report_module failed,
Packit Service 97d2fb
   or an errno code if opening the kernel binary failed.  */
Packit Service 97d2fb
extern int dwfl_linux_kernel_report_kernel (Dwfl *dwfl);
Packit Service 97d2fb
Packit Service 97d2fb
/* Call dwfl_report_module for each kernel module in the running Linux kernel.
Packit Service 97d2fb
   Returns zero on success, -1 if dwfl_report_module failed,
Packit Service 97d2fb
   or an errno code if reading the list of modules failed.  */
Packit Service 97d2fb
extern int dwfl_linux_kernel_report_modules (Dwfl *dwfl);
Packit Service 97d2fb
Packit Service 97d2fb
/* Report a kernel and its modules found on disk, for offline use.
Packit Service 97d2fb
   If RELEASE starts with '/', it names a directory to look in;
Packit Service 97d2fb
   if not, it names a directory to find under /lib/modules/;
Packit Service 97d2fb
   if null, /lib/modules/`uname -r` is used.
Packit Service 97d2fb
   Returns zero on success, -1 if dwfl_report_module failed,
Packit Service 97d2fb
   or an errno code if finding the files on disk failed.
Packit Service 97d2fb
Packit Service 97d2fb
   If PREDICATE is not null, it is called with each module to be reported;
Packit Service 97d2fb
   its arguments are the module name, and the ELF file name or null if unknown,
Packit Service 97d2fb
   and its return value should be zero to skip the module, one to report it,
Packit Service 97d2fb
   or -1 to cause the call to fail and return errno.  */
Packit Service 97d2fb
extern int dwfl_linux_kernel_report_offline (Dwfl *dwfl, const char *release,
Packit Service 97d2fb
					     int (*predicate) (const char *,
Packit Service 97d2fb
							       const char *));
Packit Service 97d2fb
Packit Service 97d2fb
/* Examine an ET_CORE file and report modules based on its contents.
Packit Service 97d2fb
   This can follow a dwfl_report_offline call to bootstrap the
Packit Service 97d2fb
   DT_DEBUG method of following the dynamic linker link_map chain, in
Packit Service 97d2fb
   case the core file does not contain enough of the executable's text
Packit Service 97d2fb
   segment to locate its PT_DYNAMIC in the dump.  In such case you need to
Packit Service 97d2fb
   supply non-NULL EXECUTABLE, otherwise dynamic libraries will not be loaded
Packit Service 97d2fb
   into the DWFL map.  This might call dwfl_report_elf on file names found in
Packit Service 97d2fb
   the dump if reading some link_map files is the only way to ascertain those
Packit Service 97d2fb
   modules' addresses.  Returns the number of modules reported, or -1 for
Packit Service 97d2fb
   errors.  */
Packit Service 97d2fb
extern int dwfl_core_file_report (Dwfl *dwfl, Elf *elf, const char *executable);
Packit Service 97d2fb
Packit Service 97d2fb
/* Call dwfl_report_module for each file mapped into the address space of PID.
Packit Service 97d2fb
   Returns zero on success, -1 if dwfl_report_module failed,
Packit Service 97d2fb
   or an errno code if opening the proc files failed.  */
Packit Service 97d2fb
extern int dwfl_linux_proc_report (Dwfl *dwfl, pid_t pid);
Packit Service 97d2fb
Packit Service 97d2fb
/* Similar, but reads an input stream in the format of Linux /proc/PID/maps
Packit Service 97d2fb
   files giving module layout, not the file for a live process.  */
Packit Service 97d2fb
extern int dwfl_linux_proc_maps_report (Dwfl *dwfl, FILE *);
Packit Service 97d2fb
Packit Service 97d2fb
/* Trivial find_elf callback for use with dwfl_linux_proc_report.
Packit Service 97d2fb
   This uses the module name as a file name directly and tries to open it
Packit Service 97d2fb
   if it begin with a slash, or handles the magic string "[vdso]".  */
Packit Service 97d2fb
extern int dwfl_linux_proc_find_elf (Dwfl_Module *mod, void **userdata,
Packit Service 97d2fb
				     const char *module_name, Dwarf_Addr base,
Packit Service 97d2fb
				     char **file_name, Elf **);
Packit Service 97d2fb
Packit Service 97d2fb
/* Standard argument parsing for using a standard callback set.  */
Packit Service 97d2fb
struct argp;
Packit Service 97d2fb
extern const struct argp *dwfl_standard_argp (void) __const_attribute__;
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
/*** Relocation of addresses from Dwfl ***/
Packit Service 97d2fb
Packit Service 97d2fb
/* Return the number of relocatable bases associated with the module,
Packit Service 97d2fb
   which is zero for ET_EXEC and one for ET_DYN.  Returns -1 for errors.  */
Packit Service 97d2fb
extern int dwfl_module_relocations (Dwfl_Module *mod);
Packit Service 97d2fb
Packit Service 97d2fb
/* Return the relocation base index associated with the *ADDRESS location,
Packit Service 97d2fb
   and adjust *ADDRESS to be an offset relative to that base.
Packit Service 97d2fb
   Returns -1 for errors.  */
Packit Service 97d2fb
extern int dwfl_module_relocate_address (Dwfl_Module *mod,
Packit Service 97d2fb
					 Dwarf_Addr *address);
Packit Service 97d2fb
Packit Service 97d2fb
/* Return the ELF section name for the given relocation base index;
Packit Service 97d2fb
   if SHNDXP is not null, set *SHNDXP to the ELF section index.
Packit Service 97d2fb
   For ET_DYN, returns "" and sets *SHNDXP to SHN_ABS; the relocation
Packit Service 97d2fb
   base is the runtime start address reported for the module.
Packit Service 97d2fb
   Returns null for errors.  */
Packit Service 97d2fb
extern const char *dwfl_module_relocation_info (Dwfl_Module *mod,
Packit Service 97d2fb
						unsigned int idx,
Packit Service 97d2fb
						GElf_Word *shndxp);
Packit Service 97d2fb
Packit Service 97d2fb
/* Validate that ADDRESS and ADDRESS+OFFSET lie in a known module
Packit Service 97d2fb
   and both within the same contiguous region for relocation purposes.
Packit Service 97d2fb
   Returns zero for success and -1 for errors.  */
Packit Service 97d2fb
extern int dwfl_validate_address (Dwfl *dwfl,
Packit Service 97d2fb
				  Dwarf_Addr address, Dwarf_Sword offset);
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
/*** ELF access functions ***/
Packit Service 97d2fb
Packit Service 97d2fb
/* Fetch the module main ELF file (where the allocated sections
Packit Service 97d2fb
   are found) for use with libelf.  If successful, fills in *BIAS
Packit Service 97d2fb
   with the difference between addresses within the loaded module
Packit Service 97d2fb
   and those in symbol tables or Dwarf information referring to it.  */
Packit Service 97d2fb
extern Elf *dwfl_module_getelf (Dwfl_Module *, GElf_Addr *bias)
Packit Service 97d2fb
  __nonnull_attribute__ (2);
Packit Service 97d2fb
Packit Service 97d2fb
/* Return the number of symbols in the module's symbol table,
Packit Service 97d2fb
   or -1 for errors.  */
Packit Service 97d2fb
extern int dwfl_module_getsymtab (Dwfl_Module *mod);
Packit Service 97d2fb
Packit Service 97d2fb
/* Return the index of the first global symbol in the module's symbol
Packit Service 97d2fb
   table, or -1 for errors.  In each symbol table, all symbols with
Packit Service 97d2fb
   STB_LOCAL binding precede the weak and global symbols.  This
Packit Service 97d2fb
   function returns the symbol table index one greater than the last
Packit Service 97d2fb
   local symbol.  */
Packit Service 97d2fb
extern int dwfl_module_getsymtab_first_global (Dwfl_Module *mod);
Packit Service 97d2fb
Packit Service 97d2fb
/* Fetch one entry from the module's symbol table.  On errors, returns
Packit Service 97d2fb
   NULL.  If successful, fills in *SYM and returns the string for st_name.
Packit Service 97d2fb
   This works like gelf_getsym except that st_value is always adjusted to
Packit Service 97d2fb
   an absolute value based on the module's location, when the symbol is in
Packit Service 97d2fb
   an SHF_ALLOC section.  If SHNDXP is non-null, it's set with the section
Packit Service 97d2fb
   index (whether from st_shndx or extended index table); in case of a
Packit Service 97d2fb
   symbol in a non-allocated section, *SHNDXP is instead set to -1.
Packit Service 97d2fb
   Note that since symbols can come from either the main, debug or auxiliary
Packit Service 97d2fb
   ELF symbol file (either dynsym or symtab) the section index can only
Packit Service 97d2fb
   be reliably used to compare against special section constants like
Packit Service 97d2fb
   SHN_UNDEF or SHN_ABS.  It is recommended to use dwfl_module_getsym_info
Packit Service 97d2fb
   which doesn't have these deficiencies.  */
Packit Service 97d2fb
extern const char *dwfl_module_getsym (Dwfl_Module *mod, int ndx,
Packit Service 97d2fb
				       GElf_Sym *sym, GElf_Word *shndxp)
Packit Service 97d2fb
  __nonnull_attribute__ (3);
Packit Service 97d2fb
Packit Service 97d2fb
/* Fetch one entry from the module's symbol table and the associated
Packit Service 97d2fb
   address value.  On errors, returns NULL.  If successful, fills in
Packit Service 97d2fb
   *SYM, *ADDR and returns the string for st_name.  This works like
Packit Service 97d2fb
   gelf_getsym.  *ADDR is set to the st_value adjusted to an absolute
Packit Service 97d2fb
   value based on the module's location, when the symbol is in an
Packit Service 97d2fb
   SHF_ALLOC section.  For non-ET_REL files, if the arch uses function
Packit Service 97d2fb
   descriptors, and the st_value points to one, *ADDR will be resolved
Packit Service 97d2fb
   to the actual function entry address.  The SYM->ST_VALUE itself
Packit Service 97d2fb
   isn't adjusted in any way.  Fills in ELFP, if not NULL, with the
Packit Service 97d2fb
   ELF file the symbol originally came from.  Note that symbols can
Packit Service 97d2fb
   come from either the main, debug or auxiliary ELF symbol file
Packit Service 97d2fb
   (either dynsym or symtab).  If SHNDXP is non-null, it's set with
Packit Service 97d2fb
   the section index (whether from st_shndx or extended index table);
Packit Service 97d2fb
   in case of a symbol in a non-allocated section, *SHNDXP is instead
Packit Service 97d2fb
   set to -1.  Fills in BIAS, if not NULL, with the difference between
Packit Service 97d2fb
   addresses within the loaded module and those in symbol table of the
Packit Service 97d2fb
   ELF file.  Note that the address associated with the symbol might
Packit Service 97d2fb
   be in a different section than the returned symbol.  The section in
Packit Service 97d2fb
   the main elf file in which returned ADDR falls can be found with
Packit Service 97d2fb
   dwfl_module_address_section.  */
Packit Service 97d2fb
extern const char *dwfl_module_getsym_info (Dwfl_Module *mod, int ndx,
Packit Service 97d2fb
					    GElf_Sym *sym, GElf_Addr *addr,
Packit Service 97d2fb
					    GElf_Word *shndxp,
Packit Service 97d2fb
					    Elf **elfp, Dwarf_Addr *bias)
Packit Service 97d2fb
  __nonnull_attribute__ (3, 4);
Packit Service 97d2fb
Packit Service 97d2fb
/* Find the symbol that ADDRESS lies inside, and return its name.  */
Packit Service 97d2fb
extern const char *dwfl_module_addrname (Dwfl_Module *mod, GElf_Addr address);
Packit Service 97d2fb
Packit Service 97d2fb
/* Find the symbol associated with ADDRESS.  Return its name or NULL
Packit Service 97d2fb
   when nothing was found.  If the architecture uses function
Packit Service 97d2fb
   descriptors, and symbol st_value points to one, ADDRESS wil be
Packit Service 97d2fb
   matched against either the adjusted st_value or the associated
Packit Service 97d2fb
   function entry value as described in dwfl_module_getsym_info.  If
Packit Service 97d2fb
   OFFSET is not NULL it will be filled in with the difference from
Packit Service 97d2fb
   the start of the symbol (or function entry).  If SYM is not NULL it
Packit Service 97d2fb
   is filled in with the symbol associated with the matched ADDRESS.
Packit Service 97d2fb
   The SYM->ST_VALUE itself isn't adjusted in any way.  Fills in ELFP,
Packit Service 97d2fb
   if not NULL, with the ELF file the symbol originally came from.
Packit Service 97d2fb
   Note that symbols can come from either the main, debug or auxiliary
Packit Service 97d2fb
   ELF symbol file (either dynsym or symtab).  If SHNDXP is non-null,
Packit Service 97d2fb
   it's set with the section index (whether from st_shndx or extended
Packit Service 97d2fb
   index table).  Fills in BIAS, if not NULL, with the difference
Packit Service 97d2fb
   between addresses within the loaded module and those in symbol
Packit Service 97d2fb
   table of the ELF file.  Note that the address matched against the
Packit Service 97d2fb
   symbol might be in a different section than the returned symbol.
Packit Service 97d2fb
   The section in the main elf file in ADDRESS falls can be found with
Packit Service 97d2fb
   dwfl_module_address_section.  */
Packit Service 97d2fb
extern const char *dwfl_module_addrinfo (Dwfl_Module *mod, GElf_Addr address,
Packit Service 97d2fb
					 GElf_Off *offset, GElf_Sym *sym,
Packit Service 97d2fb
					 GElf_Word *shndxp, Elf **elfp,
Packit Service 97d2fb
					 Dwarf_Addr *bias)
Packit Service 97d2fb
  __nonnull_attribute__ (3);
Packit Service 97d2fb
Packit Service 97d2fb
/* Find the symbol that ADDRESS lies inside, and return detailed
Packit Service 97d2fb
   information as for dwfl_module_getsym (above).  Note that like
Packit Service 97d2fb
   dwfl_module_getsym this function also adjusts SYM->ST_VALUE to an
Packit Service 97d2fb
   absolute value based on the module's location.  ADDRESS is only
Packit Service 97d2fb
   matched against this adjusted SYM->ST_VALUE.  This means that
Packit Service 97d2fb
   depending on architecture this might only match symbols that
Packit Service 97d2fb
   represent function descriptor addresses (and not function entry
Packit Service 97d2fb
   addresses).  For these reasons it is recommended to use
Packit Service 97d2fb
   dwfl_module_addrinfo instead.  */
Packit Service 97d2fb
extern const char *dwfl_module_addrsym (Dwfl_Module *mod, GElf_Addr address,
Packit Service 97d2fb
					GElf_Sym *sym, GElf_Word *shndxp)
Packit Service 97d2fb
  __nonnull_attribute__ (3);
Packit Service 97d2fb
Packit Service 97d2fb
/* Find the ELF section that *ADDRESS lies inside and return it.
Packit Service 97d2fb
   On success, adjusts *ADDRESS to be relative to the section,
Packit Service 97d2fb
   and sets *BIAS to the difference between addresses used in
Packit Service 97d2fb
   the returned section's headers and run-time addresses.  */
Packit Service 97d2fb
extern Elf_Scn *dwfl_module_address_section (Dwfl_Module *mod,
Packit Service 97d2fb
					     Dwarf_Addr *address,
Packit Service 97d2fb
					     Dwarf_Addr *bias)
Packit Service 97d2fb
  __nonnull_attribute__ (2, 3);
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
/*** Dwarf access functions ***/
Packit Service 97d2fb
Packit Service 97d2fb
/* Fetch the module's debug information for use with libdw.
Packit Service 97d2fb
   If successful, fills in *BIAS with the difference between
Packit Service 97d2fb
   addresses within the loaded module and those  to use with libdw.  */
Packit Service 97d2fb
extern Dwarf *dwfl_module_getdwarf (Dwfl_Module *, Dwarf_Addr *bias)
Packit Service 97d2fb
     __nonnull_attribute__ (2);
Packit Service 97d2fb
Packit Service 97d2fb
/* Get the libdw handle for each module.  */
Packit Service 97d2fb
extern ptrdiff_t dwfl_getdwarf (Dwfl *,
Packit Service 97d2fb
				int (*callback) (Dwfl_Module *, void **,
Packit Service 97d2fb
						 const char *, Dwarf_Addr,
Packit Service 97d2fb
						 Dwarf *, Dwarf_Addr, void *),
Packit Service 97d2fb
				void *arg, ptrdiff_t offset);
Packit Service 97d2fb
Packit Service 97d2fb
/* Look up the module containing ADDR and return its debugging information,
Packit Service 97d2fb
   loading it if necessary.  */
Packit Service 97d2fb
extern Dwarf *dwfl_addrdwarf (Dwfl *dwfl, Dwarf_Addr addr, Dwarf_Addr *bias)
Packit Service 97d2fb
     __nonnull_attribute__ (3);
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
/* Find the CU containing ADDR and return its DIE.  */
Packit Service 97d2fb
extern Dwarf_Die *dwfl_addrdie (Dwfl *dwfl, Dwarf_Addr addr, Dwarf_Addr *bias)
Packit Service 97d2fb
     __nonnull_attribute__ (3);
Packit Service 97d2fb
extern Dwarf_Die *dwfl_module_addrdie (Dwfl_Module *mod,
Packit Service 97d2fb
				       Dwarf_Addr addr, Dwarf_Addr *bias)
Packit Service 97d2fb
     __nonnull_attribute__ (3);
Packit Service 97d2fb
Packit Service 97d2fb
/* Iterate through the CUs, start with null for LASTCU.  */
Packit Service 97d2fb
extern Dwarf_Die *dwfl_nextcu (Dwfl *dwfl, Dwarf_Die *lastcu, Dwarf_Addr *bias)
Packit Service 97d2fb
     __nonnull_attribute__ (3);
Packit Service 97d2fb
extern Dwarf_Die *dwfl_module_nextcu (Dwfl_Module *mod,
Packit Service 97d2fb
				      Dwarf_Die *lastcu, Dwarf_Addr *bias)
Packit Service 97d2fb
     __nonnull_attribute__ (3);
Packit Service 97d2fb
Packit Service 97d2fb
/* Return the module containing the CU DIE.  */
Packit Service 97d2fb
extern Dwfl_Module *dwfl_cumodule (Dwarf_Die *cudie);
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
/* Cache the source line information fo the CU and return the
Packit Service 97d2fb
   number of Dwfl_Line entries it has.  */
Packit Service 97d2fb
extern int dwfl_getsrclines (Dwarf_Die *cudie, size_t *nlines);
Packit Service 97d2fb
Packit Service 97d2fb
/* Access one line number entry within the CU.  */
Packit Service 97d2fb
extern Dwfl_Line *dwfl_onesrcline (Dwarf_Die *cudie, size_t idx);
Packit Service 97d2fb
Packit Service 97d2fb
/* Get source for address.  */
Packit Service 97d2fb
extern Dwfl_Line *dwfl_module_getsrc (Dwfl_Module *mod, Dwarf_Addr addr);
Packit Service 97d2fb
extern Dwfl_Line *dwfl_getsrc (Dwfl *dwfl, Dwarf_Addr addr);
Packit Service 97d2fb
Packit Service 97d2fb
/* Get address for source.  */
Packit Service 97d2fb
extern int dwfl_module_getsrc_file (Dwfl_Module *mod,
Packit Service 97d2fb
				    const char *fname, int lineno, int column,
Packit Service 97d2fb
				    Dwfl_Line ***srcsp, size_t *nsrcs);
Packit Service 97d2fb
Packit Service 97d2fb
/* Return the module containing this line record.  */
Packit Service 97d2fb
extern Dwfl_Module *dwfl_linemodule (Dwfl_Line *line);
Packit Service 97d2fb
Packit Service 97d2fb
/* Return the CU containing this line record.  */
Packit Service 97d2fb
extern Dwarf_Die *dwfl_linecu (Dwfl_Line *line);
Packit Service 97d2fb
Packit Service 97d2fb
/* Return the source file name and fill in other information.
Packit Service 97d2fb
   Arguments may be null for unneeded fields.  */
Packit Service 97d2fb
extern const char *dwfl_lineinfo (Dwfl_Line *line, Dwarf_Addr *addr,
Packit Service 97d2fb
				  int *linep, int *colp,
Packit Service 97d2fb
				  Dwarf_Word *mtime, Dwarf_Word *length);
Packit Service 97d2fb
Packit Service 97d2fb
  /* Return the equivalent Dwarf_Line and the bias to apply to its address.  */
Packit Service 97d2fb
extern Dwarf_Line *dwfl_dwarf_line (Dwfl_Line *line, Dwarf_Addr *bias);
Packit Service 97d2fb
Packit Service 97d2fb
/* Return the compilation directory (AT_comp_dir) from this line's CU.  */
Packit Service 97d2fb
extern const char *dwfl_line_comp_dir (Dwfl_Line *line);
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
/*** Machine backend access functions ***/
Packit Service 97d2fb
Packit Service 97d2fb
/* Return location expression to find return value given a
Packit Service 97d2fb
   DW_TAG_subprogram, DW_TAG_subroutine_type, or similar DIE describing
Packit Service 97d2fb
   function itself (whose DW_AT_type attribute describes its return type).
Packit Service 97d2fb
   The given DIE must come from the given module.  Returns -1 for errors.
Packit Service 97d2fb
   Returns zero if the function has no return value (e.g. "void" in C).
Packit Service 97d2fb
   Otherwise, *LOCOPS gets a location expression to find the return value,
Packit Service 97d2fb
   and returns the number of operations in the expression.  The pointer is
Packit Service 97d2fb
   permanently allocated at least as long as the module is live.  */
Packit Service 97d2fb
extern int dwfl_module_return_value_location (Dwfl_Module *mod,
Packit Service 97d2fb
					      Dwarf_Die *functypedie,
Packit Service 97d2fb
					      const Dwarf_Op **locops);
Packit Service 97d2fb
Packit Service 97d2fb
/* Enumerate the DWARF register numbers and their names.
Packit Service 97d2fb
   For each register, CALLBACK gets its DWARF number, a string describing
Packit Service 97d2fb
   the register set (such as "integer" or "FPU"), a prefix used in
Packit Service 97d2fb
   assembler syntax (such as "%" or "$", may be ""), and the name for the
Packit Service 97d2fb
   register (contains identifier characters only, possibly all digits).
Packit Service 97d2fb
   The REGNAME string is valid only during the callback. */
Packit Service 97d2fb
extern int dwfl_module_register_names (Dwfl_Module *mod,
Packit Service 97d2fb
				       int (*callback) (void *arg,
Packit Service 97d2fb
							int regno,
Packit Service 97d2fb
							const char *setname,
Packit Service 97d2fb
							const char *prefix,
Packit Service 97d2fb
							const char *regname,
Packit Service 97d2fb
							int bits, int type),
Packit Service 97d2fb
				       void *arg);
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
/* Find the CFI for this module.  Returns NULL if there is no CFI.
Packit Service 97d2fb
   On success, fills in *BIAS with the difference between addresses
Packit Service 97d2fb
   within the loaded module and those in the CFI referring to it.
Packit Service 97d2fb
   The pointer returned can be used until the module is cleaned up.
Packit Service 97d2fb
   Calling these more than once returns the same pointers.
Packit Service 97d2fb
Packit Service 97d2fb
   dwfl_module_dwarf_cfi gets the '.debug_frame' information found with the
Packit Service 97d2fb
   rest of the DWARF information.  dwfl_module_eh_cfi gets the '.eh_frame'
Packit Service 97d2fb
   information found linked into the text.  A module might have either or
Packit Service 97d2fb
   both.  */
Packit Service 97d2fb
extern Dwarf_CFI *dwfl_module_dwarf_cfi (Dwfl_Module *mod, Dwarf_Addr *bias);
Packit Service 97d2fb
extern Dwarf_CFI *dwfl_module_eh_cfi (Dwfl_Module *mod, Dwarf_Addr *bias);
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
typedef struct
Packit Service 97d2fb
{
Packit Service 97d2fb
  /* Called to iterate through threads.  Returns next TID (thread ID) on
Packit Service 97d2fb
     success, a negative number on failure and zero if there are no more
Packit Service 97d2fb
     threads.  dwfl_errno () should be set if negative number has been
Packit Service 97d2fb
     returned.  *THREAD_ARGP is NULL on first call, and may be optionally
Packit Service 97d2fb
     set by the implementation. The value set by the implementation will
Packit Service 97d2fb
     be passed in on the next call to NEXT_THREAD.  THREAD_ARGP is never
Packit Service 97d2fb
     NULL.  *THREAD_ARGP will be passed to set_initial_registers or
Packit Service 97d2fb
     thread_detach callbacks together with Dwfl_Thread *thread.  This
Packit Service 97d2fb
     method must not be NULL.  */
Packit Service 97d2fb
  pid_t (*next_thread) (Dwfl *dwfl, void *dwfl_arg, void **thread_argp)
Packit Service 97d2fb
    __nonnull_attribute__ (1);
Packit Service 97d2fb
Packit Service 97d2fb
  /* Called to get a specific thread.  Returns true if there is a
Packit Service 97d2fb
     thread with the given thread id number, returns false if no such
Packit Service 97d2fb
     thread exists and will set dwfl_errno in that case.  THREAD_ARGP
Packit Service 97d2fb
     is never NULL.  *THREAD_ARGP will be passed to
Packit Service 97d2fb
     set_initial_registers or thread_detach callbacks together with
Packit Service 97d2fb
     Dwfl_Thread *thread.  This method may be NULL and will then be
Packit Service 97d2fb
     emulated using the next_thread callback. */
Packit Service 97d2fb
  bool (*get_thread) (Dwfl *dwfl, pid_t tid, void *dwfl_arg,
Packit Service 97d2fb
		      void **thread_argp)
Packit Service 97d2fb
    __nonnull_attribute__ (1);
Packit Service 97d2fb
Packit Service 97d2fb
  /* Called during unwinding to access memory (stack) state.  Returns true for
Packit Service 97d2fb
     successfully read *RESULT or false and sets dwfl_errno () on failure.
Packit Service 97d2fb
     This method may be NULL - in such case dwfl_thread_getframes will return
Packit Service 97d2fb
     only the initial frame.  */
Packit Service 97d2fb
  bool (*memory_read) (Dwfl *dwfl, Dwarf_Addr addr, Dwarf_Word *result,
Packit Service 97d2fb
                       void *dwfl_arg)
Packit Service 97d2fb
    __nonnull_attribute__ (1, 3);
Packit Service 97d2fb
Packit Service 97d2fb
  /* Called on initial unwind to get the initial register state of the first
Packit Service 97d2fb
     frame.  Should call dwfl_thread_state_registers, possibly multiple times
Packit Service 97d2fb
     for different ranges and possibly also dwfl_thread_state_register_pc, to
Packit Service 97d2fb
     fill in initial (DWARF) register values.  After this call, till at least
Packit Service 97d2fb
     thread_detach is called, the thread is assumed to be frozen, so that it is
Packit Service 97d2fb
     safe to unwind.  Returns true on success or false and sets dwfl_errno ()
Packit Service 97d2fb
     on failure.  In the case of a failure thread_detach will not be called.
Packit Service 97d2fb
     This method must not be NULL.  */
Packit Service 97d2fb
  bool (*set_initial_registers) (Dwfl_Thread *thread, void *thread_arg)
Packit Service 97d2fb
    __nonnull_attribute__ (1);
Packit Service 97d2fb
Packit Service 97d2fb
  /* Called by dwfl_end.  All thread_detach method calls have been already
Packit Service 97d2fb
     done.  This method may be NULL.  */
Packit Service 97d2fb
  void (*detach) (Dwfl *dwfl, void *dwfl_arg)
Packit Service 97d2fb
    __nonnull_attribute__ (1);
Packit Service 97d2fb
Packit Service 97d2fb
  /* Called when unwinding is done.  No callback will be called after
Packit Service 97d2fb
     this method has been called.  Iff set_initial_registers was called for
Packit Service 97d2fb
     a TID and it returned success thread_detach will be called before the
Packit Service 97d2fb
     detach method above.  This method may be NULL.  */
Packit Service 97d2fb
  void (*thread_detach) (Dwfl_Thread *thread, void *thread_arg)
Packit Service 97d2fb
    __nonnull_attribute__ (1);
Packit Service 97d2fb
} Dwfl_Thread_Callbacks;
Packit Service 97d2fb
Packit Service 97d2fb
/* PID is the process id associated with the DWFL state.  Architecture of DWFL
Packit Service 97d2fb
   modules is specified by ELF, ELF must remain valid during DWFL lifetime.
Packit Service 97d2fb
   Use NULL ELF to detect architecture from DWFL, the function will then detect
Packit Service 97d2fb
   it from arbitrary Dwfl_Module of DWFL.  DWFL_ARG is the callback backend
Packit Service 97d2fb
   state.  DWFL_ARG will be provided to the callbacks.  *THREAD_CALLBACKS
Packit Service 97d2fb
   function pointers must remain valid during lifetime of DWFL.  Function
Packit Service 97d2fb
   returns true on success, false otherwise.  */
Packit Service 97d2fb
bool dwfl_attach_state (Dwfl *dwfl, Elf *elf, pid_t pid,
Packit Service 97d2fb
                        const Dwfl_Thread_Callbacks *thread_callbacks,
Packit Service 97d2fb
			void *dwfl_arg)
Packit Service 97d2fb
  __nonnull_attribute__ (1, 4);
Packit Service 97d2fb
Packit Service 97d2fb
/* Calls dwfl_attach_state with Dwfl_Thread_Callbacks setup for extracting
Packit Service 97d2fb
   thread state from the ELF core file.  Returns the pid number extracted
Packit Service 97d2fb
   from the core file, or -1 for errors.  */
Packit Service 97d2fb
extern int dwfl_core_file_attach (Dwfl *dwfl, Elf *elf);
Packit Service 97d2fb
Packit Service 97d2fb
/* Calls dwfl_attach_state with Dwfl_Thread_Callbacks setup for extracting
Packit Service 97d2fb
   thread state from the proc file system.  Uses ptrace to attach and stop
Packit Service 97d2fb
   the thread under inspection and detaches when thread_detach is called
Packit Service 97d2fb
   and unwinding for the thread is done, unless ASSUME_PTRACE_STOPPED is
Packit Service 97d2fb
   true.  If ASSUME_PTRACE_STOPPED is true the caller should make sure that
Packit Service 97d2fb
   the thread is ptrace attached and stopped before unwinding by calling
Packit Service 97d2fb
   either dwfl_thread_getframes or dwfl_getthread_frames.  Returns zero on
Packit Service 97d2fb
   success, -1 if dwfl_attach_state failed, or an errno code if opening the
Packit Service 97d2fb
   proc files failed.  */
Packit Service 97d2fb
extern int dwfl_linux_proc_attach (Dwfl *dwfl, pid_t pid,
Packit Service 97d2fb
				   bool assume_ptrace_stopped);
Packit Service 97d2fb
Packit Service 97d2fb
/* Return PID for the process associated with DWFL.  Function returns -1 if
Packit Service 97d2fb
   dwfl_attach_state was not called for DWFL.  */
Packit Service 97d2fb
pid_t dwfl_pid (Dwfl *dwfl)
Packit Service 97d2fb
  __nonnull_attribute__ (1);
Packit Service 97d2fb
Packit Service 97d2fb
/* Return DWFL from which THREAD was created using dwfl_getthreads.  */
Packit Service 97d2fb
Dwfl *dwfl_thread_dwfl (Dwfl_Thread *thread)
Packit Service 97d2fb
  __nonnull_attribute__ (1);
Packit Service 97d2fb
Packit Service 97d2fb
/* Return positive TID (thread ID) for THREAD.  This function never fails.  */
Packit Service 97d2fb
pid_t dwfl_thread_tid (Dwfl_Thread *thread)
Packit Service 97d2fb
  __nonnull_attribute__ (1);
Packit Service 97d2fb
Packit Service 97d2fb
/* Return thread for frame STATE.  This function never fails.  */
Packit Service 97d2fb
Dwfl_Thread *dwfl_frame_thread (Dwfl_Frame *state)
Packit Service 97d2fb
  __nonnull_attribute__ (1);
Packit Service 97d2fb
Packit Service 97d2fb
/* Called by Dwfl_Thread_Callbacks.set_initial_registers implementation.
Packit Service 97d2fb
   For every known continuous block of registers 
Packit Service 97d2fb
   (inclusive..exclusive) set their content to REGS (array of NREGS items).
Packit Service 97d2fb
   Function returns false if any of the registers has invalid number.  */
Packit Service 97d2fb
bool dwfl_thread_state_registers (Dwfl_Thread *thread, int firstreg,
Packit Service 97d2fb
                                  unsigned nregs, const Dwarf_Word *regs)
Packit Service 97d2fb
  __nonnull_attribute__ (1, 4);
Packit Service 97d2fb
Packit Service 97d2fb
/* Called by Dwfl_Thread_Callbacks.set_initial_registers implementation.
Packit Service 97d2fb
   If PC is not contained among DWARF registers passed by
Packit Service 97d2fb
   dwfl_thread_state_registers on the target architecture pass the PC value
Packit Service 97d2fb
   here.  */
Packit Service 97d2fb
void dwfl_thread_state_register_pc (Dwfl_Thread *thread, Dwarf_Word pc)
Packit Service 97d2fb
  __nonnull_attribute__ (1);
Packit Service 97d2fb
Packit Service 97d2fb
/* Iterate through the threads for a process.  Returns zero if all threads have
Packit Service 97d2fb
   been processed by the callback, returns -1 on error, or the value of the
Packit Service 97d2fb
   callback when not DWARF_CB_OK.  -1 returned on error will set dwfl_errno ().
Packit Service 97d2fb
   Keeps calling the callback with the next thread while the callback returns
Packit Service 97d2fb
   DWARF_CB_OK, till there are no more threads.  */
Packit Service 97d2fb
int dwfl_getthreads (Dwfl *dwfl,
Packit Service 97d2fb
		     int (*callback) (Dwfl_Thread *thread, void *arg),
Packit Service 97d2fb
		     void *arg)
Packit Service 97d2fb
  __nonnull_attribute__ (1, 2);
Packit Service 97d2fb
Packit Service 97d2fb
/* Iterate through the frames for a thread.  Returns zero if all frames
Packit Service 97d2fb
   have been processed by the callback, returns -1 on error, or the value of
Packit Service 97d2fb
   the callback when not DWARF_CB_OK.  -1 returned on error will
Packit Service 97d2fb
   set dwfl_errno ().  Some systems return error instead of zero on end of the
Packit Service 97d2fb
   backtrace, for cross-platform compatibility callers should consider error as
Packit Service 97d2fb
   a zero.  Keeps calling the callback with the next frame while the callback
Packit Service 97d2fb
   returns DWARF_CB_OK, till there are no more frames.  On start will call the
Packit Service 97d2fb
   set_initial_registers callback and on return will call the detach_thread
Packit Service 97d2fb
   callback of the Dwfl_Thread.  */
Packit Service 97d2fb
int dwfl_thread_getframes (Dwfl_Thread *thread,
Packit Service 97d2fb
			   int (*callback) (Dwfl_Frame *state, void *arg),
Packit Service 97d2fb
			   void *arg)
Packit Service 97d2fb
  __nonnull_attribute__ (1, 2);
Packit Service 97d2fb
Packit Service 97d2fb
/* Like dwfl_thread_getframes, but specifying the thread by its unique
Packit Service 97d2fb
   identifier number.  Returns zero if all frames have been processed
Packit Service 97d2fb
   by the callback, returns -1 on error (and when no thread with
Packit Service 97d2fb
   the given thread id number exists), or the value of the callback
Packit Service 97d2fb
   when not DWARF_CB_OK.  -1 returned on error will set dwfl_errno ().  */
Packit Service 97d2fb
int dwfl_getthread_frames (Dwfl *dwfl, pid_t tid,
Packit Service 97d2fb
			   int (*callback) (Dwfl_Frame *thread, void *arg),
Packit Service 97d2fb
			   void *arg)
Packit Service 97d2fb
  __nonnull_attribute__ (1, 3);
Packit Service 97d2fb
Packit Service 97d2fb
/* Return *PC (program counter) for thread-specific frame STATE.
Packit Service 97d2fb
   Set *ISACTIVATION according to DWARF frame "activation" definition.
Packit Service 97d2fb
   Typically you need to substract 1 from *PC if *ACTIVATION is false to safely
Packit Service 97d2fb
   find function of the caller.  ACTIVATION may be NULL.  PC must not be NULL.
Packit Service 97d2fb
   Function returns false if it failed to find *PC.  */
Packit Service 97d2fb
bool dwfl_frame_pc (Dwfl_Frame *state, Dwarf_Addr *pc, bool *isactivation)
Packit Service 97d2fb
  __nonnull_attribute__ (1, 2);
Packit Service 97d2fb
Packit Service 97d2fb
#ifdef __cplusplus
Packit Service 97d2fb
}
Packit Service 97d2fb
#endif
Packit Service 97d2fb
Packit Service 97d2fb
#endif	/* libdwfl.h */