1b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Internal definitions for libdwfl.
2355b408bb9aa49703544fa4086e1ae463737fcf6Mark Wielaard   Copyright (C) 2005-2015 Red Hat, Inc.
3de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   This file is part of elfutils.
4b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
5de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   This file is free software; you can redistribute it and/or modify
6de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   it under the terms of either
7b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
8de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard     * the GNU Lesser General Public License as published by the Free
9de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       Software Foundation; either version 3 of the License, or (at
10de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       your option) any later version
11de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
12de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   or
13de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
14de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard     * the GNU General Public License as published by the Free
15de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       Software Foundation; either version 2 of the License, or (at
16de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       your option) any later version
17de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
18de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   or both in parallel, as here.
19de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
20de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   elfutils is distributed in the hope that it will be useful, but
21361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   WITHOUT ANY WARRANTY; without even the implied warranty of
22361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   General Public License for more details.
24361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper
25de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   You should have received copies of the GNU General Public License and
26de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   the GNU Lesser General Public License along with this program.  If
27de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   not, see <http://www.gnu.org/licenses/>.  */
28b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
29b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#ifndef _LIBDWFLP_H
30b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define _LIBDWFLP_H	1
31b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
3255d34a5ac854be02fa10186182bc22685923c703Roland McGrath#ifndef PACKAGE_NAME
33b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper# include <config.h>
34b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif
35b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <libdwfl.h>
36b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <libebl.h>
37b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <assert.h>
384b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard#include <dirent.h>
39b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <errno.h>
40b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <stdbool.h>
41b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <stdlib.h>
42b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <string.h>
43b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
444959bf89d92b59ba72bea5786d7b3f9b5564f750Roland McGrath#include "../libdw/libdwP.h"	/* We need its INTDECLs.  */
459380297e130e6ccc829c8d56d701fb539b27bb0fMark Wielaard#include "../libdwelf/libdwelfP.h"
464959bf89d92b59ba72bea5786d7b3f9b5564f750Roland McGrath
470b867460075c9f02cb305abc91a0e12b90017583Jan Kratochviltypedef struct Dwfl_Process Dwfl_Process;
480b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil
49b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* gettext helper macros.  */
50b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define _(Str) dgettext ("elfutils", Str)
51b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
52b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define DWFL_ERRORS							      \
53b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (NOERROR, N_("no error"))					      \
54b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (UNKNOWN_ERROR, N_("unknown error"))			      \
55b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (NOMEM, N_("out of memory"))				      \
56b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (ERRNO, N_("See errno"))					      \
57b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (LIBELF, N_("See elf_errno"))				      \
58b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (LIBDW, N_("See dwarf_errno"))				      \
59b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (LIBEBL, N_("See ebl_errno (XXX missing)"))		      \
60bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath  DWFL_ERROR (ZLIB, N_("gzip decompression failed"))			      \
61bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath  DWFL_ERROR (BZLIB, N_("bzip2 decompression failed"))			      \
62241696467caa087278576291cb3b89693668df0bRoland McGrath  DWFL_ERROR (LZMA, N_("LZMA decompression failed"))			      \
6307d4f2fc1cb53f170a71bc13617bbdd9cb1c3c60Roland McGrath  DWFL_ERROR (UNKNOWN_MACHINE, N_("no support library found for machine"))    \
64b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (NOREL, N_("Callbacks missing for ET_REL file"))		      \
65b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (BADRELTYPE, N_("Unsupported relocation type"))		      \
66b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (BADRELOFF, N_("r_offset is bogus"))			      \
67b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (BADSTROFF, N_("offset out of range"))			      \
68b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (RELUNDEF, N_("relocation refers to undefined symbol"))	      \
69b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (CB, N_("Callback returned failure"))			      \
70b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (NO_DWARF, N_("No DWARF information found"))		      \
71b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (NO_SYMTAB, N_("No symbol table found"))			      \
72b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (NO_PHDR, N_("No ELF program headers"))			      \
73b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (OVERLAP, N_("address range overlaps an existing module"))	      \
74b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (ADDR_OUTOFRANGE, N_("address out of range"))		      \
75b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (NO_MATCH, N_("no matching address range"))		      \
76b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWFL_ERROR (TRUNCATED, N_("image truncated"))				      \
7759ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath  DWFL_ERROR (ALREADY_ELF, N_("ELF file opened"))			      \
78e47ab76f02c2a4f4d802ec298969ba67956435feRoland McGrath  DWFL_ERROR (BADELF, N_("not a valid ELF file"))			      \
79ed431ddb74331f24add8c6d932ebed129c4385d8Roland McGrath  DWFL_ERROR (WEIRD_TYPE, N_("cannot handle DWARF type description"))	      \
805ad466d544bdca479626d07d65288b2cc2638b4aRoland McGrath  DWFL_ERROR (WRONG_ID_ELF, N_("ELF file does not match build ID"))	      \
810b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  DWFL_ERROR (BAD_PRELINK, N_("corrupt .gnu.prelink_undo section data"))      \
820b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  DWFL_ERROR (LIBEBL_BAD, N_("Internal error due to ebl"))		      \
830b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  DWFL_ERROR (CORE_MISSING, N_("Missing data in core file"))		      \
840b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  DWFL_ERROR (INVALID_REGISTER, N_("Invalid register"))			      \
850b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  DWFL_ERROR (PROCESS_MEMORY_READ, N_("Error reading process memory"))	      \
860b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  DWFL_ERROR (PROCESS_NO_ARCH, N_("Couldn't find architecture of any ELF"))   \
870b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  DWFL_ERROR (PARSE_PROC, N_("Error parsing /proc filesystem"))		      \
880b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  DWFL_ERROR (INVALID_DWARF, N_("Invalid DWARF"))			      \
890b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  DWFL_ERROR (UNSUPPORTED_DWARF, N_("Unsupported DWARF"))		      \
900b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  DWFL_ERROR (NEXT_THREAD_FAIL, N_("Unable to find more threads"))	      \
910b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  DWFL_ERROR (ATTACH_STATE_CONFLICT, N_("Dwfl already has attached state"))   \
920b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  DWFL_ERROR (NO_ATTACH_STATE, N_("Dwfl has no attached state"))	      \
930b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  DWFL_ERROR (NO_UNWIND, N_("Unwinding not supported for this architecture")) \
9414beac3b6f22b8d7a054980f74c4f8d33b969fc4Mark Wielaard  DWFL_ERROR (INVALID_ARGUMENT, N_("Invalid argument"))			      \
9514beac3b6f22b8d7a054980f74c4f8d33b969fc4Mark Wielaard  DWFL_ERROR (NO_CORE_FILE, N_("Not an ET_CORE ELF file"))
96b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
97b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define DWFL_ERROR(name, text) DWFL_E_##name,
98b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef enum { DWFL_ERRORS DWFL_E_NUM } Dwfl_Error;
99b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#undef	DWFL_ERROR
100b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
101b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define OTHER_ERROR(name)	((unsigned int) DWFL_E_##name << 16)
102b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define DWFL_E(name, errno)	(OTHER_ERROR (name) | (errno))
103b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
104d11f9cbecac4a5ac3848a68597028d1924f3ff6bRoland McGrathextern int __libdwfl_canon_error (Dwfl_Error) internal_function;
105d11f9cbecac4a5ac3848a68597028d1924f3ff6bRoland McGrathextern void __libdwfl_seterrno (Dwfl_Error) internal_function;
106b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
107355b408bb9aa49703544fa4086e1ae463737fcf6Mark Wielaard/* Resources we might keep for the user about the core file that the
108355b408bb9aa49703544fa4086e1ae463737fcf6Mark Wielaard   Dwfl might have been created from.  Can currently only be set
109355b408bb9aa49703544fa4086e1ae463737fcf6Mark Wielaard   through std-argp.  */
110355b408bb9aa49703544fa4086e1ae463737fcf6Mark Wielaardstruct Dwfl_User_Core
111355b408bb9aa49703544fa4086e1ae463737fcf6Mark Wielaard{
112355b408bb9aa49703544fa4086e1ae463737fcf6Mark Wielaard  char *executable_for_core;	/* --executable if --core was specified.  */
113355b408bb9aa49703544fa4086e1ae463737fcf6Mark Wielaard  Elf *core;                    /* non-NULL if we need to free it.  */
114355b408bb9aa49703544fa4086e1ae463737fcf6Mark Wielaard  int fd;                       /* close if >= 0.  */
115355b408bb9aa49703544fa4086e1ae463737fcf6Mark Wielaard};
116355b408bb9aa49703544fa4086e1ae463737fcf6Mark Wielaard
117b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct Dwfl
118b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
119b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  const Dwfl_Callbacks *callbacks;
120b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
121b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Dwfl_Module *modulelist;    /* List in order used by full traversals.  */
122b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
1230b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  Dwfl_Process *process;
12414beac3b6f22b8d7a054980f74c4f8d33b969fc4Mark Wielaard  Dwfl_Error attacherr;      /* Previous error attaching process.  */
1250b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil
126d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrath  GElf_Addr offline_next_address;
127b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath
128b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath  GElf_Addr segment_align;	/* Smallest granularity of segments.  */
129b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath
130b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath  /* Binary search table in three parallel malloc'd arrays.  */
131b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath  size_t lookup_elts;		/* Elements in use.  */
132b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath  size_t lookup_alloc;		/* Elements allococated.  */
133b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath  GElf_Addr *lookup_addr;	/* Start address of segment.  */
134b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath  Dwfl_Module **lookup_module;	/* Module associated with segment, or null.  */
135b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath  int *lookup_segndx;		/* User segment index, or -1.  */
136b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath
137b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath  /* Cache from last dwfl_report_segment call.  */
138b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath  const void *lookup_tail_ident;
139b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath  GElf_Off lookup_tail_vaddr;
140b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath  GElf_Off lookup_tail_offset;
141b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath  int lookup_tail_ndx;
142d5784afaf49cd59b9286e766cd9b1cf00cb43553Jan Kratochvil
143355b408bb9aa49703544fa4086e1ae463737fcf6Mark Wielaard  struct Dwfl_User_Core *user_core;
144b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper};
145b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
146d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrath#define OFFLINE_REDZONE		0x10000
147d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrath
148b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct dwfl_file
149b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
150b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  char *name;
151b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  int fd;
15259ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath  bool valid;			/* The build ID note has been matched.  */
153e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath  bool relocated;		/* Partial relocation of all sections done.  */
154b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
155b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Elf *elf;
1561743d7f010bead5e869d097e23ce840583913381Roland McGrath
1571743d7f010bead5e869d097e23ce840583913381Roland McGrath  /* This is the lowest p_vaddr in this ELF file, aligned to p_align.
1581743d7f010bead5e869d097e23ce840583913381Roland McGrath     For a file without phdrs, this is zero.  */
1591743d7f010bead5e869d097e23ce840583913381Roland McGrath  GElf_Addr vaddr;
1601743d7f010bead5e869d097e23ce840583913381Roland McGrath
1611743d7f010bead5e869d097e23ce840583913381Roland McGrath  /* This is an address chosen for synchronization between the main file
1622c7d0ddfb8a08b8c450d0d3a5e297ec5d624661dRoland McGrath     and the debug file.  See dwfl_module_getdwarf.c for how it's chosen.  */
1631743d7f010bead5e869d097e23ce840583913381Roland McGrath  GElf_Addr address_sync;
164b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper};
165b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
166b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct Dwfl_Module
167b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
168b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Dwfl *dwfl;
169d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrath  struct Dwfl_Module *next;	/* Link on Dwfl.modulelist.  */
170b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
171b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  void *userdata;
172b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
173b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  char *name;			/* Iterator name for this module.  */
174b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  GElf_Addr low_addr, high_addr;
175b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
1765083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard  struct dwfl_file main, debug, aux_sym;
1771743d7f010bead5e869d097e23ce840583913381Roland McGrath  GElf_Addr main_bias;
178b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Ebl *ebl;
179d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrath  GElf_Half e_type;		/* GElf_Ehdr.e_type cache.  */
180b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Dwfl_Error elferr;		/* Previous failure to open main file.  */
181b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
182d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrath  struct dwfl_relocation *reloc_info; /* Relocatable sections.  */
183d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrath
184b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  struct dwfl_file *symfile;	/* Either main or debug.  */
185b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Elf_Data *symdata;		/* Data in the ELF symbol table section.  */
1865083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard  Elf_Data *aux_symdata;	/* Data in the auxiliary ELF symbol table.  */
187b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  size_t syments;		/* sh_size / sh_entsize of that section.  */
1885083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard  size_t aux_syments;		/* sh_size / sh_entsize of aux_sym section.  */
189ef431cd30b8a1a6b12a8783516fc95da88a9a636Mark Wielaard  int first_global;		/* Index of first global symbol of table.  */
1905083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard  int aux_first_global;		/* Index of first global of aux_sym table.  */
191e1812e1d90090450e3d93be56a487e2f11affcedUlrich Drepper  Elf_Data *symstrdata;		/* Data for its string table.  */
1925083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard  Elf_Data *aux_symstrdata;	/* Data for aux_sym string table.  */
193b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Elf_Data *symxndxdata;	/* Data in the extended section index table. */
1945083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard  Elf_Data *aux_symxndxdata;	/* Data in the extended auxiliary table. */
195b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
196b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Dwarf *dw;			/* libdw handle for its debugging info.  */
197df85bf99021119fcbb2ced66dd69f1cceafb180cMark Wielaard  Dwarf *alt;			/* Dwarf used for dwarf_setalt, or NULL.  */
198df85bf99021119fcbb2ced66dd69f1cceafb180cMark Wielaard  int alt_fd; 			/* descriptor, only valid when alt != NULL.  */
199df85bf99021119fcbb2ced66dd69f1cceafb180cMark Wielaard  Elf *alt_elf; 		/* Elf for alt Dwarf.  */
200fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath
201fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath  Dwfl_Error symerr;		/* Previous failure to load symbols.  */
202fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath  Dwfl_Error dwerr;		/* Previous failure to load DWARF.  */
203b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
204b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Known CU's in this module.  */
205b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  struct dwfl_cu *first_cu, **cu;
206b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
207b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  void *lazy_cu_root;		/* Table indexed by Dwarf_Off of CU.  */
208b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
209b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  struct dwfl_arange *aranges;	/* Mapping of addresses in module to CUs.  */
210fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath
211fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath  void *build_id_bits;		/* malloc'd copy of build ID bits.  */
212fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath  GElf_Addr build_id_vaddr;	/* Address where they reside, 0 if unknown.  */
213fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath  int build_id_len;		/* -1 for prior failure, 0 if unset.  */
214fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath
215fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath  unsigned int ncu;
216fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath  unsigned int lazycu;		/* Possible users, deleted when none left.  */
217b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  unsigned int naranges;
218b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
2193c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath  Dwarf_CFI *dwarf_cfi;		/* Cached DWARF CFI for this module.  */
2203c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath  Dwarf_CFI *eh_cfi;		/* Cached EH CFI for this module.  */
2213c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath
222b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath  int segment;			/* Index of first segment table entry.  */
223b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  bool gc;			/* Mark/sweep flag.  */
2246097c00a539873e9baa22e10f9387b9c36c4fa25Jan Kratochvil  bool is_executable;		/* Use Dwfl::executable_for_core?  */
225b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper};
226b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
2270b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil/* This holds information common for all the threads/tasks/TIDs of one process
2280b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil   for backtraces.  */
2290b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil
2300b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvilstruct Dwfl_Process
2310b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil{
2320b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  struct Dwfl *dwfl;
2330b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  pid_t pid;
2340b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  const Dwfl_Thread_Callbacks *callbacks;
2350b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  void *callbacks_arg;
2360b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  struct ebl *ebl;
2370b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  bool ebl_close:1;
2380b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil};
2390b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil
2400b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil/* See its typedef in libdwfl.h.  */
2410b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil
2420b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvilstruct Dwfl_Thread
2430b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil{
2440b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  Dwfl_Process *process;
2450b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  pid_t tid;
2460b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  /* The current frame being unwound.  Initially it is the bottom frame.
2470b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil     Later the processed frames get freed and this pointer is updated.  */
2480b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  Dwfl_Frame *unwound;
2490b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  void *callbacks_arg;
2500b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil};
2510b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil
2520b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil/* See its typedef in libdwfl.h.  */
2530b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil
2540b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvilstruct Dwfl_Frame
2550b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil{
2560b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  Dwfl_Thread *thread;
2570b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  /* Previous (outer) frame.  */
2580b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  Dwfl_Frame *unwound;
2590b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  bool signal_frame : 1;
2600b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  bool initial_frame : 1;
2610b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  enum
2620b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  {
2630b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil    /* This structure is still being initialized or there was an error
2640b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil       initializing it.  */
2650b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil    DWFL_FRAME_STATE_ERROR,
2660b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil    /* PC field is valid.  */
2670b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil    DWFL_FRAME_STATE_PC_SET,
2680b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil    /* PC field is undefined, this means the next (inner) frame was the
2690b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil       outermost frame.  */
2700b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil    DWFL_FRAME_STATE_PC_UNDEFINED
2710b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  } pc_state;
2720b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  /* Either initialized from appropriate REGS element or on some archs
2730b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil     initialized separately as the return address has no DWARF register.  */
2740b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  Dwarf_Addr pc;
2750b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  /* (1 << X) bitmask where 0 <= X < ebl_frame_nregs.  */
2760b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  uint64_t regs_set[3];
2770b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  /* REGS array size is ebl_frame_nregs.
2780b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil     REGS_SET tells which of the REGS are valid.  */
2790b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  Dwarf_Addr regs[];
2800b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil};
2810b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil
2820b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil/* Fetch value from Dwfl_Frame->regs indexed by DWARF REGNO.
2830b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil   No error code is set if the function returns FALSE.  */
2840b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvilbool __libdwfl_frame_reg_get (Dwfl_Frame *state, unsigned regno,
2850b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil			      Dwarf_Addr *val)
2860b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  internal_function;
287b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
2880b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil/* Store value to Dwfl_Frame->regs indexed by DWARF REGNO.
2890b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil   No error code is set if the function returns FALSE.  */
2900b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvilbool __libdwfl_frame_reg_set (Dwfl_Frame *state, unsigned regno,
2910b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil			      Dwarf_Addr val)
2920b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  internal_function;
293b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
294b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Information cached about each CU in Dwfl_Module.dw.  */
295b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct dwfl_cu
296b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
297b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* This caches libdw information about the CU.  It's also the
298b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     address passed back to users, so we take advantage of the
299b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     fact that it's placed first to cast back.  */
300b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Dwarf_Die die;
301b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
302b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Dwfl_Module *mod;		/* Pointer back to containing module.  */
303b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
304b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  struct dwfl_cu *next;		/* CU immediately following in the file.  */
305b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
306b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  struct Dwfl_Lines *lines;
307b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper};
308b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
309b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct Dwfl_Lines
310b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
311b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  struct dwfl_cu *cu;
312b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
313b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* This is what the opaque Dwfl_Line * pointers we pass to users are.
314b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     We need to recover pointers to our struct dwfl_cu and a record in
315b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     libdw's Dwarf_Line table.  To minimize the memory used in addition
316b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     to libdw's Dwarf_Lines buffer, we just point to our own index in
317b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     this table, and have one pointer back to the CU.  The indices here
318b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     match those in libdw's Dwarf_CU.lines->info table.  */
319b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  struct Dwfl_Line
320b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  {
321b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    unsigned int idx;		/* My index in the dwfl_cu.lines table.  */
322b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  } idx[0];
323b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper};
324b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
325b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic inline struct dwfl_cu *
326e1812e1d90090450e3d93be56a487e2f11affcedUlrich Drepperdwfl_linecu_inline (const Dwfl_Line *line)
327b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
328b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  const struct Dwfl_Lines *lines = ((const void *) line
329b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper				    - offsetof (struct Dwfl_Lines,
330b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper						idx[line->idx]));
331b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  return lines->cu;
332b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}
333e1812e1d90090450e3d93be56a487e2f11affcedUlrich Drepper#define dwfl_linecu dwfl_linecu_inline
334b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
3351743d7f010bead5e869d097e23ce840583913381Roland McGrathstatic inline GElf_Addr
3361743d7f010bead5e869d097e23ce840583913381Roland McGrathdwfl_adjusted_address (Dwfl_Module *mod, GElf_Addr addr)
3371743d7f010bead5e869d097e23ce840583913381Roland McGrath{
3381743d7f010bead5e869d097e23ce840583913381Roland McGrath  return addr + mod->main_bias;
3391743d7f010bead5e869d097e23ce840583913381Roland McGrath}
3401743d7f010bead5e869d097e23ce840583913381Roland McGrath
3411743d7f010bead5e869d097e23ce840583913381Roland McGrathstatic inline GElf_Addr
3421743d7f010bead5e869d097e23ce840583913381Roland McGrathdwfl_deadjust_address (Dwfl_Module *mod, GElf_Addr addr)
3431743d7f010bead5e869d097e23ce840583913381Roland McGrath{
3441743d7f010bead5e869d097e23ce840583913381Roland McGrath  return addr - mod->main_bias;
3451743d7f010bead5e869d097e23ce840583913381Roland McGrath}
3461743d7f010bead5e869d097e23ce840583913381Roland McGrath
3471743d7f010bead5e869d097e23ce840583913381Roland McGrathstatic inline Dwarf_Addr
3481743d7f010bead5e869d097e23ce840583913381Roland McGrathdwfl_adjusted_dwarf_addr (Dwfl_Module *mod, Dwarf_Addr addr)
3491743d7f010bead5e869d097e23ce840583913381Roland McGrath{
3501743d7f010bead5e869d097e23ce840583913381Roland McGrath  return dwfl_adjusted_address (mod, (addr
3511743d7f010bead5e869d097e23ce840583913381Roland McGrath				      - mod->debug.address_sync
3521743d7f010bead5e869d097e23ce840583913381Roland McGrath				      + mod->main.address_sync));
3531743d7f010bead5e869d097e23ce840583913381Roland McGrath}
3541743d7f010bead5e869d097e23ce840583913381Roland McGrath
3551743d7f010bead5e869d097e23ce840583913381Roland McGrathstatic inline Dwarf_Addr
3561743d7f010bead5e869d097e23ce840583913381Roland McGrathdwfl_deadjust_dwarf_addr (Dwfl_Module *mod, Dwarf_Addr addr)
3571743d7f010bead5e869d097e23ce840583913381Roland McGrath{
3581743d7f010bead5e869d097e23ce840583913381Roland McGrath  return (dwfl_deadjust_address (mod, addr)
3591743d7f010bead5e869d097e23ce840583913381Roland McGrath	  - mod->main.address_sync
3601743d7f010bead5e869d097e23ce840583913381Roland McGrath	  + mod->debug.address_sync);
3611743d7f010bead5e869d097e23ce840583913381Roland McGrath}
3621743d7f010bead5e869d097e23ce840583913381Roland McGrath
3635083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaardstatic inline Dwarf_Addr
3645083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaarddwfl_adjusted_aux_sym_addr (Dwfl_Module *mod, Dwarf_Addr addr)
3655083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard{
3665083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard  return dwfl_adjusted_address (mod, (addr
3675083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard				      - mod->aux_sym.address_sync
3685083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard				      + mod->main.address_sync));
3695083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard}
3705083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard
3715083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaardstatic inline Dwarf_Addr
3725083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaarddwfl_deadjust_aux_sym_addr (Dwfl_Module *mod, Dwarf_Addr addr)
3735083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard{
3745083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard  return (dwfl_deadjust_address (mod, addr)
3755083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard	  - mod->main.address_sync
3765083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard	  + mod->aux_sym.address_sync);
3775083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard}
3785083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard
3791743d7f010bead5e869d097e23ce840583913381Roland McGrathstatic inline GElf_Addr
380819c349f6339512d6961a6172c539fdf2c2f1328Mark Wielaarddwfl_adjusted_st_value (Dwfl_Module *mod, Elf *symelf, GElf_Addr addr)
3811743d7f010bead5e869d097e23ce840583913381Roland McGrath{
382819c349f6339512d6961a6172c539fdf2c2f1328Mark Wielaard  if (symelf == mod->main.elf)
3831743d7f010bead5e869d097e23ce840583913381Roland McGrath    return dwfl_adjusted_address (mod, addr);
384819c349f6339512d6961a6172c539fdf2c2f1328Mark Wielaard  if (symelf == mod->debug.elf)
3855083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard    return dwfl_adjusted_dwarf_addr (mod, addr);
3865083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard  return dwfl_adjusted_aux_sym_addr (mod, addr);
3871743d7f010bead5e869d097e23ce840583913381Roland McGrath}
3881743d7f010bead5e869d097e23ce840583913381Roland McGrath
3891743d7f010bead5e869d097e23ce840583913381Roland McGrathstatic inline GElf_Addr
390819c349f6339512d6961a6172c539fdf2c2f1328Mark Wielaarddwfl_deadjust_st_value (Dwfl_Module *mod, Elf *symelf, GElf_Addr addr)
3911743d7f010bead5e869d097e23ce840583913381Roland McGrath{
392819c349f6339512d6961a6172c539fdf2c2f1328Mark Wielaard  if (symelf == mod->main.elf)
3931743d7f010bead5e869d097e23ce840583913381Roland McGrath    return dwfl_deadjust_address (mod, addr);
394819c349f6339512d6961a6172c539fdf2c2f1328Mark Wielaard  if (symelf == mod->debug.elf)
3955083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard    return dwfl_deadjust_dwarf_addr (mod, addr);
3965083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard  return dwfl_deadjust_aux_sym_addr (mod, addr);
3971743d7f010bead5e869d097e23ce840583913381Roland McGrath}
3981743d7f010bead5e869d097e23ce840583913381Roland McGrath
399b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* This describes a contiguous address range that lies in a single CU.
400b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   We condense runs of Dwarf_Arange entries for the same CU into this.  */
401b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct dwfl_arange
402b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
403b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  struct dwfl_cu *cu;
404b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  size_t arange;		/* Index in Dwarf_Aranges.  */
405b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper};
406b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
407b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
4084b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard/* Structure used for keeping track of ptrace attaching a thread.
4094b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard   Shared by linux-pid-attach and linux-proc-maps.  If it has been setup
4104b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard   then get the instance through __libdwfl_get_pid_arg.  */
4114b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaardstruct __libdwfl_pid_arg
4124b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard{
413879850950bd56255cb5796c86b62bf3bdedd4fb9Mark Wielaard  /* /proc/PID/task/.  */
4144b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard  DIR *dir;
415879850950bd56255cb5796c86b62bf3bdedd4fb9Mark Wielaard  /* Elf for /proc/PID/exe.  Set to NULL if it couldn't be opened.  */
416879850950bd56255cb5796c86b62bf3bdedd4fb9Mark Wielaard  Elf *elf;
417879850950bd56255cb5796c86b62bf3bdedd4fb9Mark Wielaard  /* fd for /proc/PID/exe.  Set to -1 if it couldn't be opened.  */
418879850950bd56255cb5796c86b62bf3bdedd4fb9Mark Wielaard  int elf_fd;
4194b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard  /* It is 0 if not used.  */
4204b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard  pid_t tid_attached;
4214b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard  /* Valid only if TID_ATTACHED is not zero.  */
4224b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard  bool tid_was_stopped;
4234b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard  /* True if threads are ptrace stopped by caller.  */
4244b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard  bool assume_ptrace_stopped;
4254b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard};
4264b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard
4274b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard/* If DWfl is not NULL and a Dwfl_Process has been setup that has
4284b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard   Dwfl_Thread_Callbacks set to pid_thread_callbacks, then return the
4294b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard   callbacks_arg, which will be a struct __libdwfl_pid_arg.  Otherwise
4304b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard   returns NULL.  */
4314b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaardextern struct __libdwfl_pid_arg *__libdwfl_get_pid_arg (Dwfl *dwfl)
4324b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard  internal_function;
4334b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard
4344b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard/* Makes sure the given tid is attached. On success returns true and
4354b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard   sets tid_was_stopped.  */
4364b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaardextern bool __libdwfl_ptrace_attach (pid_t tid, bool *tid_was_stoppedp)
4374b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard  internal_function;
4384b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard
4394b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard/* Detaches a tid that was attached through
4404b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard   __libdwfl_ptrace_attach. Must be given the tid_was_stopped as set
4414b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard   by __libdwfl_ptrace_attach.  */
4424b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaardextern void __libdwfl_ptrace_detach (pid_t tid, bool tid_was_stopped)
4434b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard  internal_function;
4444b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard
4454b9e1433d2272f5f68b3227abdd9cf6817a0afd3Mark Wielaard
446159ac52b061c60947a943c102298cd692223274fMark Wielaard/* Internal wrapper for old dwfl_module_getsym and new dwfl_module_getsym_info.
447159ac52b061c60947a943c102298cd692223274fMark Wielaard   adjust_st_value set to true returns adjusted SYM st_value, set to false
448159ac52b061c60947a943c102298cd692223274fMark Wielaard   it will not adjust SYM at all, but does match against resolved *ADDR. */
449159ac52b061c60947a943c102298cd692223274fMark Wielaardextern const char *__libdwfl_getsym (Dwfl_Module *mod, int ndx, GElf_Sym *sym,
450159ac52b061c60947a943c102298cd692223274fMark Wielaard				     GElf_Addr *addr, GElf_Word *shndxp,
451159ac52b061c60947a943c102298cd692223274fMark Wielaard				     Elf **elfp, Dwarf_Addr *biasp,
452159ac52b061c60947a943c102298cd692223274fMark Wielaard				     bool *resolved, bool adjust_st_value)
453159ac52b061c60947a943c102298cd692223274fMark Wielaard  internal_function;
454159ac52b061c60947a943c102298cd692223274fMark Wielaard
455159ac52b061c60947a943c102298cd692223274fMark Wielaard/* Internal wrapper for old dwfl_module_addrsym and new dwfl_module_addrinfo.
456159ac52b061c60947a943c102298cd692223274fMark Wielaard   adjust_st_value set to true returns adjusted SYM st_value, set to false
457159ac52b061c60947a943c102298cd692223274fMark Wielaard   it will not adjust SYM at all, but does match against resolved values. */
458159ac52b061c60947a943c102298cd692223274fMark Wielaardextern const char *__libdwfl_addrsym (Dwfl_Module *mod, GElf_Addr addr,
459159ac52b061c60947a943c102298cd692223274fMark Wielaard				      GElf_Off *off, GElf_Sym *sym,
460159ac52b061c60947a943c102298cd692223274fMark Wielaard				      GElf_Word *shndxp, Elf **elfp,
461159ac52b061c60947a943c102298cd692223274fMark Wielaard				      Dwarf_Addr *bias,
462159ac52b061c60947a943c102298cd692223274fMark Wielaard				      bool adjust_st_value) internal_function;
463b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
464b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern void __libdwfl_module_free (Dwfl_Module *mod) internal_function;
465b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
466a605a3c8f354895f4cca56aca8f8aa468b506fdfRoland McGrath/* Find the main ELF file, update MOD->elferr and/or MOD->main.elf.  */
467a605a3c8f354895f4cca56aca8f8aa468b506fdfRoland McGrathextern void __libdwfl_getelf (Dwfl_Module *mod) internal_function;
468b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
469b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Process relocations in debugging sections in an ET_REL file.
470e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath   FILE must be opened with ELF_C_READ_MMAP_PRIVATE or ELF_C_READ,
471b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   to make it possible to relocate the data in place (or ELF_C_RDWR or
472b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   ELF_C_RDWR_MMAP if you intend to modify the Elf file on disk).  After
473e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath   this, dwarf_begin_elf on FILE will read the relocated data.
474e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath
475e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath   When DEBUG is false, apply partial relocation to all sections.  */
476e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrathextern Dwfl_Error __libdwfl_relocate (Dwfl_Module *mod, Elf *file, bool debug)
477e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath  internal_function;
478e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath
479159ac52b061c60947a943c102298cd692223274fMark Wielaard/* Find the section index in mod->main.elf that contains the given
480159ac52b061c60947a943c102298cd692223274fMark Wielaard   *ADDR.  Adjusts *ADDR to be section relative on success, returns
481159ac52b061c60947a943c102298cd692223274fMark Wielaard   SHN_UNDEF on failure.  */
482159ac52b061c60947a943c102298cd692223274fMark Wielaardextern size_t __libdwfl_find_section_ndx (Dwfl_Module *mod, Dwarf_Addr *addr)
483159ac52b061c60947a943c102298cd692223274fMark Wielaard  internal_function;
484159ac52b061c60947a943c102298cd692223274fMark Wielaard
485e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath/* Process (simple) relocations in arbitrary section TSCN of an ET_REL file.
486e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath   RELOCSCN is SHT_REL or SHT_RELA and TSCN is its sh_info target section.  */
487e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrathextern Dwfl_Error __libdwfl_relocate_section (Dwfl_Module *mod, Elf *relocated,
488e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath					      Elf_Scn *relocscn, Elf_Scn *tscn,
489e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath					      bool partial)
490d2c5996f70844ae7816034b56e769ce163251718Roland McGrath  internal_function;
491b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
492b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Adjust *VALUE from section-relative to absolute.
493b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   MOD->dwfl->callbacks->section_address is called to determine the actual
494b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   address of a loaded section.  */
495b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepperextern Dwfl_Error __libdwfl_relocate_value (Dwfl_Module *mod, Elf *elf,
496b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper					    size_t *shstrndx_cache,
497b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper					    Elf32_Word shndx,
498b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper					    GElf_Addr *value)
499b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     internal_function;
500b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
501994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath/* Ensure that MOD->ebl is set up.  */
502994b4899278199fc4d307780dac0ea50b238bc74Roland McGrathextern Dwfl_Error __libdwfl_module_getebl (Dwfl_Module *mod) internal_function;
503994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath
5043c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath/* Install a new Dwarf_CFI in *SLOT (MOD->eh_cfi or MOD->dwarf_cfi).  */
5053c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrathextern Dwarf_CFI *__libdwfl_set_cfi (Dwfl_Module *mod, Dwarf_CFI **slot,
5063c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath				     Dwarf_CFI *cfi)
5073c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath  internal_function;
5083c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath
509b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Iterate through all the CU's in the module.  Start by passing a null
510b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   LASTCU, and then pass the last *CU returned.  Success return with null
511b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   *CU no more CUs.  */
512b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Dwfl_Error __libdwfl_nextcu (Dwfl_Module *mod, struct dwfl_cu *lastcu,
513b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper				    struct dwfl_cu **cu) internal_function;
514b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
515b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Find the CU by address.  */
516b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Dwfl_Error __libdwfl_addrcu (Dwfl_Module *mod, Dwarf_Addr addr,
517b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper				    struct dwfl_cu **cu) internal_function;
518b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
519b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Ensure that CU->lines (and CU->cu->lines) is set up.  */
520b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Dwfl_Error __libdwfl_cu_getsrclines (struct dwfl_cu *cu)
52159ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath  internal_function;
52259ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath
5238ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil/* Look in ELF for an NT_GNU_BUILD_ID note.  Store it to BUILD_ID_BITS,
5248ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil   its vaddr in ELF to BUILD_ID_VADDR (it is unrelocated, even if MOD is not
5258ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil   NULL) and store length to BUILD_ID_LEN.  Returns -1 for errors, 1 if it was
5268ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil   stored and 0 if no note is found.  MOD may be NULL, MOD must be non-NULL
5278ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil   only if ELF is ET_REL.  */
5288ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvilextern int __libdwfl_find_elf_build_id (Dwfl_Module *mod, Elf *elf,
5298ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil					const void **build_id_bits,
5308ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil					GElf_Addr *build_id_elfaddr,
5318af254a19665c3baf6074a36ba2618413b80d169Jan Kratochvil					int *build_id_len)
5328af254a19665c3baf6074a36ba2618413b80d169Jan Kratochvil  internal_function;
5338ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil
53459ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath/* Look in ELF for an NT_GNU_BUILD_ID note.  If SET is true, store it
53559ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath   in MOD and return its length.  If SET is false, instead compare it
53659ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath   to that stored in MOD and return 2 if they match, 1 if they do not.
53759ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath   Returns -1 for errors, 0 if no note is found.  */
53859ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrathextern int __libdwfl_find_build_id (Dwfl_Module *mod, bool set, Elf *elf)
53959ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath  internal_function;
540b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
54159ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath/* Open a main or debuginfo file by its build ID, returns the fd.  */
542df85bf99021119fcbb2ced66dd69f1cceafb180cMark Wielaardextern int __libdwfl_open_mod_by_build_id (Dwfl_Module *mod, bool debug,
543df85bf99021119fcbb2ced66dd69f1cceafb180cMark Wielaard					   char **file_name) internal_function;
544df85bf99021119fcbb2ced66dd69f1cceafb180cMark Wielaard
545df85bf99021119fcbb2ced66dd69f1cceafb180cMark Wielaard/* Same, but takes an explicit build_id, can also be used for alt debug.  */
54659ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrathextern int __libdwfl_open_by_build_id (Dwfl_Module *mod, bool debug,
547df85bf99021119fcbb2ced66dd69f1cceafb180cMark Wielaard				       char **file_name, const size_t id_len,
548df85bf99021119fcbb2ced66dd69f1cceafb180cMark Wielaard				       const uint8_t *id) internal_function;
549b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
55018618fd74777576cc20dce341bb71be327f9ed48Ulrich Drepperextern uint32_t __libdwfl_crc32 (uint32_t crc, unsigned char *buf, size_t len)
55159ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath  attribute_hidden;
55218618fd74777576cc20dce341bb71be327f9ed48Ulrich Drepperextern int __libdwfl_crc32_file (int fd, uint32_t *resp) attribute_hidden;
55318618fd74777576cc20dce341bb71be327f9ed48Ulrich Drepper
554b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
555596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil/* Given ELF and some parameters return TRUE if the *P return value parameters
556596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil   have been successfully filled in.  Any of the *P parameters can be NULL.  */
557596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvilextern bool __libdwfl_elf_address_range (Elf *elf, GElf_Addr base,
558596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil					 bool add_p_vaddr, bool sanity,
559596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil					 GElf_Addr *vaddrp,
560596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil					 GElf_Addr *address_syncp,
561596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil					 GElf_Addr *startp, GElf_Addr *endp,
562744fc6f97f1c32fbab0f2a124bfa053e88fc3697Jan Kratochvil					 GElf_Addr *biasp, GElf_Half *e_typep)
563596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil  internal_function;
564596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil
565b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper/* Meat of dwfl_report_elf, given elf_begin just called.
566b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper   Consumes ELF on success, not on failure.  */
567b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepperextern Dwfl_Module *__libdwfl_report_elf (Dwfl *dwfl, const char *name,
568b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper					  const char *file_name, int fd,
569904aec2c2f62b729a536c2259274fdd440b0d923Jan Kratochvil					  Elf *elf, GElf_Addr base,
570904aec2c2f62b729a536c2259274fdd440b0d923Jan Kratochvil					  bool add_p_vaddr, bool sanity)
571b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper  internal_function;
572b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper
573b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper/* Meat of dwfl_report_offline.  */
574b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepperextern Dwfl_Module *__libdwfl_report_offline (Dwfl *dwfl, const char *name,
575b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper					      const char *file_name,
576b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper					      int fd, bool closefd,
577b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper					      int (*predicate) (const char *,
578b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper								const char *))
579b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper  internal_function;
580b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper
5810b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil/* Free PROCESS.  Unlink and free also any structures it references.  */
5820b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvilextern void __libdwfl_process_free (Dwfl_Process *process)
5830b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  internal_function;
5840b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil
5850b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil/* Update STATE->unwound for the unwound frame.
5860b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil   On error STATE->unwound == NULL
5870b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil   or STATE->unwound->pc_state == DWFL_FRAME_STATE_ERROR;
5880b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil   in such case dwfl_errno () is set.
5890b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil   If STATE->unwound->pc_state == DWFL_FRAME_STATE_PC_UNDEFINED
5900b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil   then STATE was the last valid frame.  */
5910b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvilextern void __libdwfl_frame_unwind (Dwfl_Frame *state)
5920b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  internal_function;
5930b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil
5940b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil/* Align segment START downwards or END upwards addresses according to DWFL.  */
5950b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvilextern GElf_Addr __libdwfl_segment_start (Dwfl *dwfl, GElf_Addr start)
5960b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  internal_function;
5970b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvilextern GElf_Addr __libdwfl_segment_end (Dwfl *dwfl, GElf_Addr end)
5980b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil  internal_function;
5990b867460075c9f02cb305abc91a0e12b90017583Jan Kratochvil
600bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath/* Decompression wrappers: decompress whole file into memory.  */
6013425454a10d307fae891fb667cf7969e945cde79Josh Stoneextern Dwfl_Error __libdw_gunzip  (int fd, off_t start_offset,
602bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath				   void *mapped, size_t mapped_size,
603bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath				   void **whole, size_t *whole_size)
604bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath  internal_function;
6053425454a10d307fae891fb667cf7969e945cde79Josh Stoneextern Dwfl_Error __libdw_bunzip2 (int fd, off_t start_offset,
606241696467caa087278576291cb3b89693668df0bRoland McGrath				   void *mapped, size_t mapped_size,
607241696467caa087278576291cb3b89693668df0bRoland McGrath				   void **whole, size_t *whole_size)
608241696467caa087278576291cb3b89693668df0bRoland McGrath  internal_function;
6093425454a10d307fae891fb667cf7969e945cde79Josh Stoneextern Dwfl_Error __libdw_unlzma (int fd, off_t start_offset,
610241696467caa087278576291cb3b89693668df0bRoland McGrath				  void *mapped, size_t mapped_size,
611241696467caa087278576291cb3b89693668df0bRoland McGrath				  void **whole, size_t *whole_size)
612bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath  internal_function;
6136bb90710916169e242ce39b12831c5a22a57fcd4Roland McGrath
6146bb90710916169e242ce39b12831c5a22a57fcd4Roland McGrath/* Skip the image header before a file image: updates *START_OFFSET.  */
6153425454a10d307fae891fb667cf7969e945cde79Josh Stoneextern Dwfl_Error __libdw_image_header (int fd, off_t *start_offset,
6166bb90710916169e242ce39b12831c5a22a57fcd4Roland McGrath					void *mapped, size_t mapped_size)
6176bb90710916169e242ce39b12831c5a22a57fcd4Roland McGrath  internal_function;
618bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath
619bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath/* Open Elf handle on *FDP.  This handles decompression and checks
620bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath   elf_kind.  Succeed only for ELF_K_ELF, or also ELF_K_AR if ARCHIVE_OK.
621bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath   Returns DWFL_E_NOERROR and sets *ELFP on success, resets *FDP to -1 if
622bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath   it's no longer used.  Resets *FDP on failure too iff CLOSE_ON_FAIL.  */
623bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrathextern Dwfl_Error __libdw_open_file (int *fdp, Elf **elfp,
624bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath				     bool close_on_fail, bool archive_ok)
625bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath  internal_function;
626b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
627463e983e20fdb945b11bb175ca71e23b31146d8eJan Kratochvil/* Fetch PT_DYNAMIC P_VADDR from ELF and store it to *VADDRP.  Return success.
628463e983e20fdb945b11bb175ca71e23b31146d8eJan Kratochvil   *VADDRP is not modified if the function fails.  */
629463e983e20fdb945b11bb175ca71e23b31146d8eJan Kratochvilextern bool __libdwfl_dynamic_vaddr_get (Elf *elf, GElf_Addr *vaddrp)
630463e983e20fdb945b11bb175ca71e23b31146d8eJan Kratochvil  internal_function;
631463e983e20fdb945b11bb175ca71e23b31146d8eJan Kratochvil
632b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath/* These are working nicely for --core, but are not ready to be
633b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath   exported interfaces quite yet.  */
634b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath
635b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath/* Type of callback function ...
636b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath */
637b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathtypedef bool Dwfl_Memory_Callback (Dwfl *dwfl, int segndx,
638b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath				   void **buffer, size_t *buffer_available,
639b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath				   GElf_Addr vaddr, size_t minread, void *arg);
640b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath
641b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath/* Type of callback function ...
642b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath */
643b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathtypedef bool Dwfl_Module_Callback (Dwfl_Module *mod, void **userdata,
644b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath				   const char *name, Dwarf_Addr base,
645b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath				   void **buffer, size_t *buffer_available,
646b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath				   GElf_Off cost, GElf_Off worthwhile,
647b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath				   GElf_Off whole, GElf_Off contiguous,
648b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath				   void *arg, Elf **elfp);
649b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath
6508ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil/* One shared library (or executable) info from DT_DEBUG link map.  */
6518ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvilstruct r_debug_info_module
6528ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil{
6538ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil  struct r_debug_info_module *next;
654596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil  /* FD is -1 iff ELF is NULL.  */
655596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil  int fd;
656596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil  Elf *elf;
65735d95f378d2f2732055523abcbbfd58f7a404dcdJan Kratochvil  GElf_Addr l_ld;
658596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil  /* START and END are both zero if not valid.  */
659596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil  GElf_Addr start, end;
660596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil  bool disk_file_has_build_id;
6618ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil  char name[0];
6628ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil};
6638ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil
6648ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil/* Information gathered from DT_DEBUG by dwfl_link_map_report hinted to
6658ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil   dwfl_segment_report_module.  */
6668ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvilstruct r_debug_info
6678ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil{
6688ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil  struct r_debug_info_module *module;
6698ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil};
6708ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil
671b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath/* ...
672b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath */
673b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathextern int dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
674b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath				       Dwfl_Memory_Callback *memory_callback,
675b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath				       void *memory_callback_arg,
676b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath				       Dwfl_Module_Callback *read_eagerly,
6778ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil				       void *read_eagerly_arg,
6786d48bbf406851b56920582b8ce29db13ad4f4e2eJan Kratochvil				       const void *note_file,
6796d48bbf406851b56920582b8ce29db13ad4f4e2eJan Kratochvil				       size_t note_file_size,
6808ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil				       const struct r_debug_info *r_debug_info);
681b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath
682b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath/* Report a module for entry in the dynamic linker's struct link_map list.
683b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath   For each link_map entry, if an existing module resides at its address,
684b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath   this just modifies that module's name and suggested file name.  If
685b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath   no such module exists, this calls dwfl_report_elf on the l_name string.
686b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath
687b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath   If AUXV is not null, it points to AUXV_SIZE bytes of auxiliary vector
688b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath   data as contained in an NT_AUXV note or read from a /proc/pid/auxv
689b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath   file.  When this is available, it guides the search.  If AUXV is null
690b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath   or the memory it points to is not accessible, then this search can
691b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath   only find where to begin if the correct executable file was
692b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath   previously reported and preloaded as with dwfl_report_elf.
693b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath
6948ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil   Fill in R_DEBUG_INFO if it is not NULL.  It should be cleared by the
6958ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil   caller, this function does not touch fields it does not need to modify.
696596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil   If R_DEBUG_INFO is not NULL then no modules get added to DWFL, caller
697596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil   has to add them from filled in R_DEBUG_INFO.
6988ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil
699b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath   Returns the number of modules found, or -1 for errors.  */
700b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathextern int dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
701b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath				 Dwfl_Memory_Callback *memory_callback,
7028ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil				 void *memory_callback_arg,
7038ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil				 struct r_debug_info *r_debug_info);
704b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath
705bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath
706b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Avoid PLT entries.  */
707b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_begin)
708b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_errmsg)
709ed431ddb74331f24add8c6d932ebed129c4385d8Roland McGrathINTDECL (dwfl_errno)
710b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_addrmodule)
711b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathINTDECL (dwfl_addrsegment)
712b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_addrdwarf)
713b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_addrdie)
71419108019192ab273c53ae324be448d29dac806caMark WielaardINTDECL (dwfl_core_file_attach)
715b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathINTDECL (dwfl_core_file_report)
716b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathINTDECL (dwfl_getmodules)
717b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_module_addrdie)
718b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathINTDECL (dwfl_module_address_section)
719159ac52b061c60947a943c102298cd692223274fMark WielaardINTDECL (dwfl_module_addrinfo)
7206258e7486eb3eed6e50005946795c5fbf73aa106Ulrich DrepperINTDECL (dwfl_module_addrsym)
72159ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrathINTDECL (dwfl_module_build_id)
722b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_module_getdwarf)
723b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_module_getelf)
724e1812e1d90090450e3d93be56a487e2f11affcedUlrich DrepperINTDECL (dwfl_module_getsym)
725159ac52b061c60947a943c102298cd692223274fMark WielaardINTDECL (dwfl_module_getsym_info)
726e1812e1d90090450e3d93be56a487e2f11affcedUlrich DrepperINTDECL (dwfl_module_getsymtab)
72714c2d9e614cb0e3fd50ad757eaba686b37699580Mark WielaardINTDECL (dwfl_module_getsymtab_first_global)
728b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_module_getsrc)
72959ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrathINTDECL (dwfl_module_report_build_id)
730b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_report_elf)
731b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_report_begin)
7326258e7486eb3eed6e50005946795c5fbf73aa106Ulrich DrepperINTDECL (dwfl_report_begin_add)
733b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_report_module)
734b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathINTDECL (dwfl_report_segment)
735d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrathINTDECL (dwfl_report_offline)
736b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_report_end)
73759ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrathINTDECL (dwfl_build_id_find_elf)
73859ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrathINTDECL (dwfl_build_id_find_debuginfo)
739b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_standard_find_debuginfo)
740b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathINTDECL (dwfl_link_map_report)
741b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_linux_kernel_find_elf)
742b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_linux_kernel_module_section_address)
74319108019192ab273c53ae324be448d29dac806caMark WielaardINTDECL (dwfl_linux_proc_attach)
744b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_linux_proc_report)
7451656bc00ae97fa16a941a8cefacc4e01488d0e8aRoland McGrathINTDECL (dwfl_linux_proc_maps_report)
746b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_linux_proc_find_elf)
747b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_linux_kernel_report_kernel)
748b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_linux_kernel_report_modules)
749d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrathINTDECL (dwfl_linux_kernel_report_offline)
750d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrathINTDECL (dwfl_offline_section_address)
751d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrathINTDECL (dwfl_module_relocate_address)
7523c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrathINTDECL (dwfl_module_dwarf_cfi)
7533c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrathINTDECL (dwfl_module_eh_cfi)
7540b867460075c9f02cb305abc91a0e12b90017583Jan KratochvilINTDECL (dwfl_attach_state)
7550b867460075c9f02cb305abc91a0e12b90017583Jan KratochvilINTDECL (dwfl_pid)
7560b867460075c9f02cb305abc91a0e12b90017583Jan KratochvilINTDECL (dwfl_thread_dwfl)
7570b867460075c9f02cb305abc91a0e12b90017583Jan KratochvilINTDECL (dwfl_thread_tid)
7580b867460075c9f02cb305abc91a0e12b90017583Jan KratochvilINTDECL (dwfl_frame_thread)
7590b867460075c9f02cb305abc91a0e12b90017583Jan KratochvilINTDECL (dwfl_thread_state_registers)
7600b867460075c9f02cb305abc91a0e12b90017583Jan KratochvilINTDECL (dwfl_thread_state_register_pc)
761e962ec3bcbe8eccdcded36aaafee7bec41fa1bc4Mark WielaardINTDECL (dwfl_getthread_frames)
7620b867460075c9f02cb305abc91a0e12b90017583Jan KratochvilINTDECL (dwfl_getthreads)
7630b867460075c9f02cb305abc91a0e12b90017583Jan KratochvilINTDECL (dwfl_thread_getframes)
7640b867460075c9f02cb305abc91a0e12b90017583Jan KratochvilINTDECL (dwfl_frame_pc)
765b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
766b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Leading arguments standard to callbacks passed a Dwfl_Module.  */
767b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define MODCB_ARGS(mod)	(mod), &(mod)->userdata, (mod)->name, (mod)->low_addr
768b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define CBFAIL		(errno ? DWFL_E (ERRNO, errno) : DWFL_E_CB);
769b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
770b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
771a1cee0760dceaeca52aff9498b144978537d5a16Roland McGrath/* The default used by dwfl_standard_find_debuginfo.  */
772a1cee0760dceaeca52aff9498b144978537d5a16Roland McGrath#define DEFAULT_DEBUGINFO_PATH ":.debug:/usr/lib/debug"
773a1cee0760dceaeca52aff9498b144978537d5a16Roland McGrath
774a1cee0760dceaeca52aff9498b144978537d5a16Roland McGrath
775b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif	/* libdwflP.h */
776