libdwfl: Introduce dwfl_module_getsym_info and dwfl_module_addrinfo.
[platform/upstream/elfutils.git] / libdwfl / libdwflP.h
1 /* Internal definitions for libdwfl.
2    Copyright (C) 2005-2013 Red Hat, Inc.
3    This file is part of elfutils.
4
5    This file is free software; you can redistribute it and/or modify
6    it under the terms of either
7
8      * the GNU Lesser General Public License as published by the Free
9        Software Foundation; either version 3 of the License, or (at
10        your option) any later version
11
12    or
13
14      * the GNU General Public License as published by the Free
15        Software Foundation; either version 2 of the License, or (at
16        your option) any later version
17
18    or both in parallel, as here.
19
20    elfutils is distributed in the hope that it will be useful, but
21    WITHOUT ANY WARRANTY; without even the implied warranty of
22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23    General Public License for more details.
24
25    You should have received copies of the GNU General Public License and
26    the GNU Lesser General Public License along with this program.  If
27    not, see <http://www.gnu.org/licenses/>.  */
28
29 #ifndef _LIBDWFLP_H
30 #define _LIBDWFLP_H     1
31
32 #ifndef PACKAGE_NAME
33 # include <config.h>
34 #endif
35 #include <libdwfl.h>
36 #include <libebl.h>
37 #include <assert.h>
38 #include <errno.h>
39 #include <stdbool.h>
40 #include <stdlib.h>
41 #include <string.h>
42
43 #include "../libdw/libdwP.h"    /* We need its INTDECLs.  */
44
45 typedef struct Dwfl_Process Dwfl_Process;
46
47 /* gettext helper macros.  */
48 #define _(Str) dgettext ("elfutils", Str)
49
50 #define DWFL_ERRORS                                                           \
51   DWFL_ERROR (NOERROR, N_("no error"))                                        \
52   DWFL_ERROR (UNKNOWN_ERROR, N_("unknown error"))                             \
53   DWFL_ERROR (NOMEM, N_("out of memory"))                                     \
54   DWFL_ERROR (ERRNO, N_("See errno"))                                         \
55   DWFL_ERROR (LIBELF, N_("See elf_errno"))                                    \
56   DWFL_ERROR (LIBDW, N_("See dwarf_errno"))                                   \
57   DWFL_ERROR (LIBEBL, N_("See ebl_errno (XXX missing)"))                      \
58   DWFL_ERROR (ZLIB, N_("gzip decompression failed"))                          \
59   DWFL_ERROR (BZLIB, N_("bzip2 decompression failed"))                        \
60   DWFL_ERROR (LZMA, N_("LZMA decompression failed"))                          \
61   DWFL_ERROR (UNKNOWN_MACHINE, N_("no support library found for machine"))    \
62   DWFL_ERROR (NOREL, N_("Callbacks missing for ET_REL file"))                 \
63   DWFL_ERROR (BADRELTYPE, N_("Unsupported relocation type"))                  \
64   DWFL_ERROR (BADRELOFF, N_("r_offset is bogus"))                             \
65   DWFL_ERROR (BADSTROFF, N_("offset out of range"))                           \
66   DWFL_ERROR (RELUNDEF, N_("relocation refers to undefined symbol"))          \
67   DWFL_ERROR (CB, N_("Callback returned failure"))                            \
68   DWFL_ERROR (NO_DWARF, N_("No DWARF information found"))                     \
69   DWFL_ERROR (NO_SYMTAB, N_("No symbol table found"))                         \
70   DWFL_ERROR (NO_PHDR, N_("No ELF program headers"))                          \
71   DWFL_ERROR (OVERLAP, N_("address range overlaps an existing module"))       \
72   DWFL_ERROR (ADDR_OUTOFRANGE, N_("address out of range"))                    \
73   DWFL_ERROR (NO_MATCH, N_("no matching address range"))                      \
74   DWFL_ERROR (TRUNCATED, N_("image truncated"))                               \
75   DWFL_ERROR (ALREADY_ELF, N_("ELF file opened"))                             \
76   DWFL_ERROR (BADELF, N_("not a valid ELF file"))                             \
77   DWFL_ERROR (WEIRD_TYPE, N_("cannot handle DWARF type description"))         \
78   DWFL_ERROR (WRONG_ID_ELF, N_("ELF file does not match build ID"))           \
79   DWFL_ERROR (BAD_PRELINK, N_("corrupt .gnu.prelink_undo section data"))      \
80   DWFL_ERROR (LIBEBL_BAD, N_("Internal error due to ebl"))                    \
81   DWFL_ERROR (CORE_MISSING, N_("Missing data in core file"))                  \
82   DWFL_ERROR (INVALID_REGISTER, N_("Invalid register"))                       \
83   DWFL_ERROR (PROCESS_MEMORY_READ, N_("Error reading process memory"))        \
84   DWFL_ERROR (PROCESS_NO_ARCH, N_("Couldn't find architecture of any ELF"))   \
85   DWFL_ERROR (PARSE_PROC, N_("Error parsing /proc filesystem"))               \
86   DWFL_ERROR (INVALID_DWARF, N_("Invalid DWARF"))                             \
87   DWFL_ERROR (UNSUPPORTED_DWARF, N_("Unsupported DWARF"))                     \
88   DWFL_ERROR (NEXT_THREAD_FAIL, N_("Unable to find more threads"))            \
89   DWFL_ERROR (ATTACH_STATE_CONFLICT, N_("Dwfl already has attached state"))   \
90   DWFL_ERROR (NO_ATTACH_STATE, N_("Dwfl has no attached state"))              \
91   DWFL_ERROR (NO_UNWIND, N_("Unwinding not supported for this architecture")) \
92   DWFL_ERROR (INVALID_ARGUMENT, N_("Invalid argument"))
93
94 #define DWFL_ERROR(name, text) DWFL_E_##name,
95 typedef enum { DWFL_ERRORS DWFL_E_NUM } Dwfl_Error;
96 #undef  DWFL_ERROR
97
98 #define OTHER_ERROR(name)       ((unsigned int) DWFL_E_##name << 16)
99 #define DWFL_E(name, errno)     (OTHER_ERROR (name) | (errno))
100
101 extern int __libdwfl_canon_error (Dwfl_Error) internal_function;
102 extern void __libdwfl_seterrno (Dwfl_Error) internal_function;
103
104 struct Dwfl
105 {
106   const Dwfl_Callbacks *callbacks;
107
108   Dwfl_Module *modulelist;    /* List in order used by full traversals.  */
109
110   Dwfl_Process *process;
111   Dwfl_Error process_attach_error;
112
113   GElf_Addr offline_next_address;
114
115   GElf_Addr segment_align;      /* Smallest granularity of segments.  */
116
117   /* Binary search table in three parallel malloc'd arrays.  */
118   size_t lookup_elts;           /* Elements in use.  */
119   size_t lookup_alloc;          /* Elements allococated.  */
120   GElf_Addr *lookup_addr;       /* Start address of segment.  */
121   Dwfl_Module **lookup_module;  /* Module associated with segment, or null.  */
122   int *lookup_segndx;           /* User segment index, or -1.  */
123
124   /* Cache from last dwfl_report_segment call.  */
125   const void *lookup_tail_ident;
126   GElf_Off lookup_tail_vaddr;
127   GElf_Off lookup_tail_offset;
128   int lookup_tail_ndx;
129
130   char *executable_for_core;    /* --executable if --core was specified.  */
131 };
132
133 #define OFFLINE_REDZONE         0x10000
134
135 struct dwfl_file
136 {
137   char *name;
138   int fd;
139   bool valid;                   /* The build ID note has been matched.  */
140   bool relocated;               /* Partial relocation of all sections done.  */
141
142   Elf *elf;
143
144   /* This is the lowest p_vaddr in this ELF file, aligned to p_align.
145      For a file without phdrs, this is zero.  */
146   GElf_Addr vaddr;
147
148   /* This is an address chosen for synchronization between the main file
149      and the debug file.  See dwfl_module_getdwarf.c for how it's chosen.  */
150   GElf_Addr address_sync;
151 };
152
153 struct Dwfl_Module
154 {
155   Dwfl *dwfl;
156   struct Dwfl_Module *next;     /* Link on Dwfl.modulelist.  */
157
158   void *userdata;
159
160   char *name;                   /* Iterator name for this module.  */
161   GElf_Addr low_addr, high_addr;
162
163   struct dwfl_file main, debug, aux_sym;
164   GElf_Addr main_bias;
165   Ebl *ebl;
166   GElf_Half e_type;             /* GElf_Ehdr.e_type cache.  */
167   Dwfl_Error elferr;            /* Previous failure to open main file.  */
168
169   struct dwfl_relocation *reloc_info; /* Relocatable sections.  */
170
171   struct dwfl_file *symfile;    /* Either main or debug.  */
172   Elf_Data *symdata;            /* Data in the ELF symbol table section.  */
173   Elf_Data *aux_symdata;        /* Data in the auxiliary ELF symbol table.  */
174   size_t syments;               /* sh_size / sh_entsize of that section.  */
175   size_t aux_syments;           /* sh_size / sh_entsize of aux_sym section.  */
176   int first_global;             /* Index of first global symbol of table.  */
177   int aux_first_global;         /* Index of first global of aux_sym table.  */
178   Elf_Data *symstrdata;         /* Data for its string table.  */
179   Elf_Data *aux_symstrdata;     /* Data for aux_sym string table.  */
180   Elf_Data *symxndxdata;        /* Data in the extended section index table. */
181   Elf_Data *aux_symxndxdata;    /* Data in the extended auxiliary table. */
182
183   Dwarf *dw;                    /* libdw handle for its debugging info.  */
184
185   Dwfl_Error symerr;            /* Previous failure to load symbols.  */
186   Dwfl_Error dwerr;             /* Previous failure to load DWARF.  */
187
188   /* Known CU's in this module.  */
189   struct dwfl_cu *first_cu, **cu;
190
191   void *lazy_cu_root;           /* Table indexed by Dwarf_Off of CU.  */
192
193   struct dwfl_arange *aranges;  /* Mapping of addresses in module to CUs.  */
194
195   void *build_id_bits;          /* malloc'd copy of build ID bits.  */
196   GElf_Addr build_id_vaddr;     /* Address where they reside, 0 if unknown.  */
197   int build_id_len;             /* -1 for prior failure, 0 if unset.  */
198
199   unsigned int ncu;
200   unsigned int lazycu;          /* Possible users, deleted when none left.  */
201   unsigned int naranges;
202
203   Dwarf_CFI *dwarf_cfi;         /* Cached DWARF CFI for this module.  */
204   Dwarf_CFI *eh_cfi;            /* Cached EH CFI for this module.  */
205
206   int segment;                  /* Index of first segment table entry.  */
207   bool gc;                      /* Mark/sweep flag.  */
208 };
209
210 /* This holds information common for all the threads/tasks/TIDs of one process
211    for backtraces.  */
212
213 struct Dwfl_Process
214 {
215   struct Dwfl *dwfl;
216   pid_t pid;
217   const Dwfl_Thread_Callbacks *callbacks;
218   void *callbacks_arg;
219   struct ebl *ebl;
220   bool ebl_close:1;
221 };
222
223 /* See its typedef in libdwfl.h.  */
224
225 struct Dwfl_Thread
226 {
227   Dwfl_Process *process;
228   pid_t tid;
229   /* The current frame being unwound.  Initially it is the bottom frame.
230      Later the processed frames get freed and this pointer is updated.  */
231   Dwfl_Frame *unwound;
232   void *callbacks_arg;
233 };
234
235 /* See its typedef in libdwfl.h.  */
236
237 struct Dwfl_Frame
238 {
239   Dwfl_Thread *thread;
240   /* Previous (outer) frame.  */
241   Dwfl_Frame *unwound;
242   bool signal_frame : 1;
243   bool initial_frame : 1;
244   enum
245   {
246     /* This structure is still being initialized or there was an error
247        initializing it.  */
248     DWFL_FRAME_STATE_ERROR,
249     /* PC field is valid.  */
250     DWFL_FRAME_STATE_PC_SET,
251     /* PC field is undefined, this means the next (inner) frame was the
252        outermost frame.  */
253     DWFL_FRAME_STATE_PC_UNDEFINED
254   } pc_state;
255   /* Either initialized from appropriate REGS element or on some archs
256      initialized separately as the return address has no DWARF register.  */
257   Dwarf_Addr pc;
258   /* (1 << X) bitmask where 0 <= X < ebl_frame_nregs.  */
259   uint64_t regs_set[3];
260   /* REGS array size is ebl_frame_nregs.
261      REGS_SET tells which of the REGS are valid.  */
262   Dwarf_Addr regs[];
263 };
264
265 /* Fetch value from Dwfl_Frame->regs indexed by DWARF REGNO.
266    No error code is set if the function returns FALSE.  */
267 bool __libdwfl_frame_reg_get (Dwfl_Frame *state, unsigned regno,
268                               Dwarf_Addr *val)
269   internal_function;
270
271 /* Store value to Dwfl_Frame->regs indexed by DWARF REGNO.
272    No error code is set if the function returns FALSE.  */
273 bool __libdwfl_frame_reg_set (Dwfl_Frame *state, unsigned regno,
274                               Dwarf_Addr val)
275   internal_function;
276
277 /* Information cached about each CU in Dwfl_Module.dw.  */
278 struct dwfl_cu
279 {
280   /* This caches libdw information about the CU.  It's also the
281      address passed back to users, so we take advantage of the
282      fact that it's placed first to cast back.  */
283   Dwarf_Die die;
284
285   Dwfl_Module *mod;             /* Pointer back to containing module.  */
286
287   struct dwfl_cu *next;         /* CU immediately following in the file.  */
288
289   struct Dwfl_Lines *lines;
290 };
291
292 struct Dwfl_Lines
293 {
294   struct dwfl_cu *cu;
295
296   /* This is what the opaque Dwfl_Line * pointers we pass to users are.
297      We need to recover pointers to our struct dwfl_cu and a record in
298      libdw's Dwarf_Line table.  To minimize the memory used in addition
299      to libdw's Dwarf_Lines buffer, we just point to our own index in
300      this table, and have one pointer back to the CU.  The indices here
301      match those in libdw's Dwarf_CU.lines->info table.  */
302   struct Dwfl_Line
303   {
304     unsigned int idx;           /* My index in the dwfl_cu.lines table.  */
305   } idx[0];
306 };
307
308 static inline struct dwfl_cu *
309 dwfl_linecu_inline (const Dwfl_Line *line)
310 {
311   const struct Dwfl_Lines *lines = ((const void *) line
312                                     - offsetof (struct Dwfl_Lines,
313                                                 idx[line->idx]));
314   return lines->cu;
315 }
316 #define dwfl_linecu dwfl_linecu_inline
317
318 static inline GElf_Addr
319 dwfl_adjusted_address (Dwfl_Module *mod, GElf_Addr addr)
320 {
321   return addr + mod->main_bias;
322 }
323
324 static inline GElf_Addr
325 dwfl_deadjust_address (Dwfl_Module *mod, GElf_Addr addr)
326 {
327   return addr - mod->main_bias;
328 }
329
330 static inline Dwarf_Addr
331 dwfl_adjusted_dwarf_addr (Dwfl_Module *mod, Dwarf_Addr addr)
332 {
333   return dwfl_adjusted_address (mod, (addr
334                                       - mod->debug.address_sync
335                                       + mod->main.address_sync));
336 }
337
338 static inline Dwarf_Addr
339 dwfl_deadjust_dwarf_addr (Dwfl_Module *mod, Dwarf_Addr addr)
340 {
341   return (dwfl_deadjust_address (mod, addr)
342           - mod->main.address_sync
343           + mod->debug.address_sync);
344 }
345
346 static inline Dwarf_Addr
347 dwfl_adjusted_aux_sym_addr (Dwfl_Module *mod, Dwarf_Addr addr)
348 {
349   return dwfl_adjusted_address (mod, (addr
350                                       - mod->aux_sym.address_sync
351                                       + mod->main.address_sync));
352 }
353
354 static inline Dwarf_Addr
355 dwfl_deadjust_aux_sym_addr (Dwfl_Module *mod, Dwarf_Addr addr)
356 {
357   return (dwfl_deadjust_address (mod, addr)
358           - mod->main.address_sync
359           + mod->aux_sym.address_sync);
360 }
361
362 static inline GElf_Addr
363 dwfl_adjusted_st_value (Dwfl_Module *mod, Elf *symelf, GElf_Addr addr)
364 {
365   if (symelf == mod->main.elf)
366     return dwfl_adjusted_address (mod, addr);
367   if (symelf == mod->debug.elf)
368     return dwfl_adjusted_dwarf_addr (mod, addr);
369   return dwfl_adjusted_aux_sym_addr (mod, addr);
370 }
371
372 static inline GElf_Addr
373 dwfl_deadjust_st_value (Dwfl_Module *mod, Elf *symelf, GElf_Addr addr)
374 {
375   if (symelf == mod->main.elf)
376     return dwfl_deadjust_address (mod, addr);
377   if (symelf == mod->debug.elf)
378     return dwfl_deadjust_dwarf_addr (mod, addr);
379   return dwfl_deadjust_aux_sym_addr (mod, addr);
380 }
381
382 /* This describes a contiguous address range that lies in a single CU.
383    We condense runs of Dwarf_Arange entries for the same CU into this.  */
384 struct dwfl_arange
385 {
386   struct dwfl_cu *cu;
387   size_t arange;                /* Index in Dwarf_Aranges.  */
388 };
389
390
391 /* Internal wrapper for old dwfl_module_getsym and new dwfl_module_getsym_info.
392    adjust_st_value set to true returns adjusted SYM st_value, set to false
393    it will not adjust SYM at all, but does match against resolved *ADDR. */
394 extern const char *__libdwfl_getsym (Dwfl_Module *mod, int ndx, GElf_Sym *sym,
395                                      GElf_Addr *addr, GElf_Word *shndxp,
396                                      Elf **elfp, Dwarf_Addr *biasp,
397                                      bool *resolved, bool adjust_st_value)
398   internal_function;
399
400 /* Internal wrapper for old dwfl_module_addrsym and new dwfl_module_addrinfo.
401    adjust_st_value set to true returns adjusted SYM st_value, set to false
402    it will not adjust SYM at all, but does match against resolved values. */
403 extern const char *__libdwfl_addrsym (Dwfl_Module *mod, GElf_Addr addr,
404                                       GElf_Off *off, GElf_Sym *sym,
405                                       GElf_Word *shndxp, Elf **elfp,
406                                       Dwarf_Addr *bias,
407                                       bool adjust_st_value) internal_function;
408
409 extern void __libdwfl_module_free (Dwfl_Module *mod) internal_function;
410
411 /* Find the main ELF file, update MOD->elferr and/or MOD->main.elf.  */
412 extern void __libdwfl_getelf (Dwfl_Module *mod) internal_function;
413
414 /* Process relocations in debugging sections in an ET_REL file.
415    FILE must be opened with ELF_C_READ_MMAP_PRIVATE or ELF_C_READ,
416    to make it possible to relocate the data in place (or ELF_C_RDWR or
417    ELF_C_RDWR_MMAP if you intend to modify the Elf file on disk).  After
418    this, dwarf_begin_elf on FILE will read the relocated data.
419
420    When DEBUG is false, apply partial relocation to all sections.  */
421 extern Dwfl_Error __libdwfl_relocate (Dwfl_Module *mod, Elf *file, bool debug)
422   internal_function;
423
424 /* Find the section index in mod->main.elf that contains the given
425    *ADDR.  Adjusts *ADDR to be section relative on success, returns
426    SHN_UNDEF on failure.  */
427 extern size_t __libdwfl_find_section_ndx (Dwfl_Module *mod, Dwarf_Addr *addr)
428   internal_function;
429
430 /* Process (simple) relocations in arbitrary section TSCN of an ET_REL file.
431    RELOCSCN is SHT_REL or SHT_RELA and TSCN is its sh_info target section.  */
432 extern Dwfl_Error __libdwfl_relocate_section (Dwfl_Module *mod, Elf *relocated,
433                                               Elf_Scn *relocscn, Elf_Scn *tscn,
434                                               bool partial)
435   internal_function;
436
437 /* Adjust *VALUE from section-relative to absolute.
438    MOD->dwfl->callbacks->section_address is called to determine the actual
439    address of a loaded section.  */
440 extern Dwfl_Error __libdwfl_relocate_value (Dwfl_Module *mod, Elf *elf,
441                                             size_t *shstrndx_cache,
442                                             Elf32_Word shndx,
443                                             GElf_Addr *value)
444      internal_function;
445
446 /* Ensure that MOD->ebl is set up.  */
447 extern Dwfl_Error __libdwfl_module_getebl (Dwfl_Module *mod) internal_function;
448
449 /* Install a new Dwarf_CFI in *SLOT (MOD->eh_cfi or MOD->dwarf_cfi).  */
450 extern Dwarf_CFI *__libdwfl_set_cfi (Dwfl_Module *mod, Dwarf_CFI **slot,
451                                      Dwarf_CFI *cfi)
452   internal_function;
453
454 /* Iterate through all the CU's in the module.  Start by passing a null
455    LASTCU, and then pass the last *CU returned.  Success return with null
456    *CU no more CUs.  */
457 extern Dwfl_Error __libdwfl_nextcu (Dwfl_Module *mod, struct dwfl_cu *lastcu,
458                                     struct dwfl_cu **cu) internal_function;
459
460 /* Find the CU by address.  */
461 extern Dwfl_Error __libdwfl_addrcu (Dwfl_Module *mod, Dwarf_Addr addr,
462                                     struct dwfl_cu **cu) internal_function;
463
464 /* Ensure that CU->lines (and CU->cu->lines) is set up.  */
465 extern Dwfl_Error __libdwfl_cu_getsrclines (struct dwfl_cu *cu)
466   internal_function;
467
468 /* Look in ELF for an NT_GNU_BUILD_ID note.  Store it to BUILD_ID_BITS,
469    its vaddr in ELF to BUILD_ID_VADDR (it is unrelocated, even if MOD is not
470    NULL) and store length to BUILD_ID_LEN.  Returns -1 for errors, 1 if it was
471    stored and 0 if no note is found.  MOD may be NULL, MOD must be non-NULL
472    only if ELF is ET_REL.  */
473 extern int __libdwfl_find_elf_build_id (Dwfl_Module *mod, Elf *elf,
474                                         const void **build_id_bits,
475                                         GElf_Addr *build_id_elfaddr,
476                                         int *build_id_len)
477   internal_function;
478
479 /* Look in ELF for an NT_GNU_BUILD_ID note.  If SET is true, store it
480    in MOD and return its length.  If SET is false, instead compare it
481    to that stored in MOD and return 2 if they match, 1 if they do not.
482    Returns -1 for errors, 0 if no note is found.  */
483 extern int __libdwfl_find_build_id (Dwfl_Module *mod, bool set, Elf *elf)
484   internal_function;
485
486 /* Open a main or debuginfo file by its build ID, returns the fd.  */
487 extern int __libdwfl_open_by_build_id (Dwfl_Module *mod, bool debug,
488                                        char **file_name) internal_function;
489
490 extern uint32_t __libdwfl_crc32 (uint32_t crc, unsigned char *buf, size_t len)
491   attribute_hidden;
492 extern int __libdwfl_crc32_file (int fd, uint32_t *resp) attribute_hidden;
493
494
495 /* Given ELF and some parameters return TRUE if the *P return value parameters
496    have been successfully filled in.  Any of the *P parameters can be NULL.  */
497 extern bool __libdwfl_elf_address_range (Elf *elf, GElf_Addr base,
498                                          bool add_p_vaddr, bool sanity,
499                                          GElf_Addr *vaddrp,
500                                          GElf_Addr *address_syncp,
501                                          GElf_Addr *startp, GElf_Addr *endp,
502                                          GElf_Addr *biasp, GElf_Half *e_typep)
503   internal_function;
504
505 /* Meat of dwfl_report_elf, given elf_begin just called.
506    Consumes ELF on success, not on failure.  */
507 extern Dwfl_Module *__libdwfl_report_elf (Dwfl *dwfl, const char *name,
508                                           const char *file_name, int fd,
509                                           Elf *elf, GElf_Addr base,
510                                           bool add_p_vaddr, bool sanity)
511   internal_function;
512
513 /* Meat of dwfl_report_offline.  */
514 extern Dwfl_Module *__libdwfl_report_offline (Dwfl *dwfl, const char *name,
515                                               const char *file_name,
516                                               int fd, bool closefd,
517                                               int (*predicate) (const char *,
518                                                                 const char *))
519   internal_function;
520
521 /* Free PROCESS.  Unlink and free also any structures it references.  */
522 extern void __libdwfl_process_free (Dwfl_Process *process)
523   internal_function;
524
525 /* Update STATE->unwound for the unwound frame.
526    On error STATE->unwound == NULL
527    or STATE->unwound->pc_state == DWFL_FRAME_STATE_ERROR;
528    in such case dwfl_errno () is set.
529    If STATE->unwound->pc_state == DWFL_FRAME_STATE_PC_UNDEFINED
530    then STATE was the last valid frame.  */
531 extern void __libdwfl_frame_unwind (Dwfl_Frame *state)
532   internal_function;
533
534 /* Call dwfl_attach_state for PID, return true if successful.  */
535 extern bool __libdwfl_attach_state_for_pid (Dwfl *dwfl, pid_t pid)
536   internal_function;
537
538 /* Call dwfl_attach_state for CORE, return true if successful.  */
539 extern bool __libdwfl_attach_state_for_core (Dwfl *dwfl, Elf *core)
540   internal_function;
541
542 /* Align segment START downwards or END upwards addresses according to DWFL.  */
543 extern GElf_Addr __libdwfl_segment_start (Dwfl *dwfl, GElf_Addr start)
544   internal_function;
545 extern GElf_Addr __libdwfl_segment_end (Dwfl *dwfl, GElf_Addr end)
546   internal_function;
547
548 /* Decompression wrappers: decompress whole file into memory.  */
549 extern Dwfl_Error __libdw_gunzip  (int fd, off64_t start_offset,
550                                    void *mapped, size_t mapped_size,
551                                    void **whole, size_t *whole_size)
552   internal_function;
553 extern Dwfl_Error __libdw_bunzip2 (int fd, off64_t start_offset,
554                                    void *mapped, size_t mapped_size,
555                                    void **whole, size_t *whole_size)
556   internal_function;
557 extern Dwfl_Error __libdw_unlzma (int fd, off64_t start_offset,
558                                   void *mapped, size_t mapped_size,
559                                   void **whole, size_t *whole_size)
560   internal_function;
561
562 /* Skip the image header before a file image: updates *START_OFFSET.  */
563 extern Dwfl_Error __libdw_image_header (int fd, off64_t *start_offset,
564                                         void *mapped, size_t mapped_size)
565   internal_function;
566
567 /* Open Elf handle on *FDP.  This handles decompression and checks
568    elf_kind.  Succeed only for ELF_K_ELF, or also ELF_K_AR if ARCHIVE_OK.
569    Returns DWFL_E_NOERROR and sets *ELFP on success, resets *FDP to -1 if
570    it's no longer used.  Resets *FDP on failure too iff CLOSE_ON_FAIL.  */
571 extern Dwfl_Error __libdw_open_file (int *fdp, Elf **elfp,
572                                      bool close_on_fail, bool archive_ok)
573   internal_function;
574
575 /* Fetch PT_DYNAMIC P_VADDR from ELF and store it to *VADDRP.  Return success.
576    *VADDRP is not modified if the function fails.  */
577 extern bool __libdwfl_dynamic_vaddr_get (Elf *elf, GElf_Addr *vaddrp)
578   internal_function;
579
580 /* These are working nicely for --core, but are not ready to be
581    exported interfaces quite yet.  */
582
583 /* Type of callback function ...
584  */
585 typedef bool Dwfl_Memory_Callback (Dwfl *dwfl, int segndx,
586                                    void **buffer, size_t *buffer_available,
587                                    GElf_Addr vaddr, size_t minread, void *arg);
588
589 /* Type of callback function ...
590  */
591 typedef bool Dwfl_Module_Callback (Dwfl_Module *mod, void **userdata,
592                                    const char *name, Dwarf_Addr base,
593                                    void **buffer, size_t *buffer_available,
594                                    GElf_Off cost, GElf_Off worthwhile,
595                                    GElf_Off whole, GElf_Off contiguous,
596                                    void *arg, Elf **elfp);
597
598 /* One shared library (or executable) info from DT_DEBUG link map.  */
599 struct r_debug_info_module
600 {
601   struct r_debug_info_module *next;
602   /* FD is -1 iff ELF is NULL.  */
603   int fd;
604   Elf *elf;
605   GElf_Addr l_ld;
606   /* START and END are both zero if not valid.  */
607   GElf_Addr start, end;
608   bool disk_file_has_build_id;
609   char name[0];
610 };
611
612 /* Information gathered from DT_DEBUG by dwfl_link_map_report hinted to
613    dwfl_segment_report_module.  */
614 struct r_debug_info
615 {
616   struct r_debug_info_module *module;
617 };
618
619 /* ...
620  */
621 extern int dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
622                                        Dwfl_Memory_Callback *memory_callback,
623                                        void *memory_callback_arg,
624                                        Dwfl_Module_Callback *read_eagerly,
625                                        void *read_eagerly_arg,
626                                        const struct r_debug_info *r_debug_info);
627
628 /* Report a module for entry in the dynamic linker's struct link_map list.
629    For each link_map entry, if an existing module resides at its address,
630    this just modifies that module's name and suggested file name.  If
631    no such module exists, this calls dwfl_report_elf on the l_name string.
632
633    If AUXV is not null, it points to AUXV_SIZE bytes of auxiliary vector
634    data as contained in an NT_AUXV note or read from a /proc/pid/auxv
635    file.  When this is available, it guides the search.  If AUXV is null
636    or the memory it points to is not accessible, then this search can
637    only find where to begin if the correct executable file was
638    previously reported and preloaded as with dwfl_report_elf.
639
640    Fill in R_DEBUG_INFO if it is not NULL.  It should be cleared by the
641    caller, this function does not touch fields it does not need to modify.
642    If R_DEBUG_INFO is not NULL then no modules get added to DWFL, caller
643    has to add them from filled in R_DEBUG_INFO.
644
645    Returns the number of modules found, or -1 for errors.  */
646 extern int dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
647                                  Dwfl_Memory_Callback *memory_callback,
648                                  void *memory_callback_arg,
649                                  struct r_debug_info *r_debug_info);
650
651
652 /* Avoid PLT entries.  */
653 INTDECL (dwfl_begin)
654 INTDECL (dwfl_errmsg)
655 INTDECL (dwfl_errno)
656 INTDECL (dwfl_addrmodule)
657 INTDECL (dwfl_addrsegment)
658 INTDECL (dwfl_addrdwarf)
659 INTDECL (dwfl_addrdie)
660 INTDECL (dwfl_core_file_report)
661 INTDECL (dwfl_getmodules)
662 INTDECL (dwfl_module_addrdie)
663 INTDECL (dwfl_module_address_section)
664 INTDECL (dwfl_module_addrinfo)
665 INTDECL (dwfl_module_addrsym)
666 INTDECL (dwfl_module_build_id)
667 INTDECL (dwfl_module_getdwarf)
668 INTDECL (dwfl_module_getelf)
669 INTDECL (dwfl_module_getsym)
670 INTDECL (dwfl_module_getsym_info)
671 INTDECL (dwfl_module_getsymtab)
672 INTDECL (dwfl_module_getsymtab_first_global)
673 INTDECL (dwfl_module_getsrc)
674 INTDECL (dwfl_module_report_build_id)
675 INTDECL (dwfl_report_elf)
676 INTDECL (dwfl_report_begin)
677 INTDECL (dwfl_report_begin_add)
678 INTDECL (dwfl_report_module)
679 INTDECL (dwfl_report_segment)
680 INTDECL (dwfl_report_offline)
681 INTDECL (dwfl_report_end)
682 INTDECL (dwfl_build_id_find_elf)
683 INTDECL (dwfl_build_id_find_debuginfo)
684 INTDECL (dwfl_standard_find_debuginfo)
685 INTDECL (dwfl_link_map_report)
686 INTDECL (dwfl_linux_kernel_find_elf)
687 INTDECL (dwfl_linux_kernel_module_section_address)
688 INTDECL (dwfl_linux_proc_report)
689 INTDECL (dwfl_linux_proc_maps_report)
690 INTDECL (dwfl_linux_proc_find_elf)
691 INTDECL (dwfl_linux_kernel_report_kernel)
692 INTDECL (dwfl_linux_kernel_report_modules)
693 INTDECL (dwfl_linux_kernel_report_offline)
694 INTDECL (dwfl_offline_section_address)
695 INTDECL (dwfl_module_relocate_address)
696 INTDECL (dwfl_module_dwarf_cfi)
697 INTDECL (dwfl_module_eh_cfi)
698 INTDECL (dwfl_attach_state)
699 INTDECL (dwfl_pid)
700 INTDECL (dwfl_thread_dwfl)
701 INTDECL (dwfl_thread_tid)
702 INTDECL (dwfl_frame_thread)
703 INTDECL (dwfl_thread_state_registers)
704 INTDECL (dwfl_thread_state_register_pc)
705 INTDECL (dwfl_getthreads)
706 INTDECL (dwfl_thread_getframes)
707 INTDECL (dwfl_frame_pc)
708
709 /* Leading arguments standard to callbacks passed a Dwfl_Module.  */
710 #define MODCB_ARGS(mod) (mod), &(mod)->userdata, (mod)->name, (mod)->low_addr
711 #define CBFAIL          (errno ? DWFL_E (ERRNO, errno) : DWFL_E_CB);
712
713
714 /* The default used by dwfl_standard_find_debuginfo.  */
715 #define DEFAULT_DEBUGINFO_PATH ":.debug:/usr/lib/debug"
716
717
718 #endif  /* libdwflP.h */