xref: /aosp_15_r20/external/elfutils/libdwfl/libdwfl.h (revision 7304104da70ce23c86437a01be71edd1a2d7f37e)
1*7304104dSAndroid Build Coastguard Worker /* Interfaces for libdwfl.
2*7304104dSAndroid Build Coastguard Worker    Copyright (C) 2005-2010, 2013 Red Hat, Inc.
3*7304104dSAndroid Build Coastguard Worker    This file is part of elfutils.
4*7304104dSAndroid Build Coastguard Worker 
5*7304104dSAndroid Build Coastguard Worker    This file is free software; you can redistribute it and/or modify
6*7304104dSAndroid Build Coastguard Worker    it under the terms of either
7*7304104dSAndroid Build Coastguard Worker 
8*7304104dSAndroid Build Coastguard Worker      * the GNU Lesser General Public License as published by the Free
9*7304104dSAndroid Build Coastguard Worker        Software Foundation; either version 3 of the License, or (at
10*7304104dSAndroid Build Coastguard Worker        your option) any later version
11*7304104dSAndroid Build Coastguard Worker 
12*7304104dSAndroid Build Coastguard Worker    or
13*7304104dSAndroid Build Coastguard Worker 
14*7304104dSAndroid Build Coastguard Worker      * the GNU General Public License as published by the Free
15*7304104dSAndroid Build Coastguard Worker        Software Foundation; either version 2 of the License, or (at
16*7304104dSAndroid Build Coastguard Worker        your option) any later version
17*7304104dSAndroid Build Coastguard Worker 
18*7304104dSAndroid Build Coastguard Worker    or both in parallel, as here.
19*7304104dSAndroid Build Coastguard Worker 
20*7304104dSAndroid Build Coastguard Worker    elfutils is distributed in the hope that it will be useful, but
21*7304104dSAndroid Build Coastguard Worker    WITHOUT ANY WARRANTY; without even the implied warranty of
22*7304104dSAndroid Build Coastguard Worker    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23*7304104dSAndroid Build Coastguard Worker    General Public License for more details.
24*7304104dSAndroid Build Coastguard Worker 
25*7304104dSAndroid Build Coastguard Worker    You should have received copies of the GNU General Public License and
26*7304104dSAndroid Build Coastguard Worker    the GNU Lesser General Public License along with this program.  If
27*7304104dSAndroid Build Coastguard Worker    not, see <http://www.gnu.org/licenses/>.  */
28*7304104dSAndroid Build Coastguard Worker 
29*7304104dSAndroid Build Coastguard Worker #ifndef _LIBDWFL_H
30*7304104dSAndroid Build Coastguard Worker #define _LIBDWFL_H	1
31*7304104dSAndroid Build Coastguard Worker 
32*7304104dSAndroid Build Coastguard Worker #include "libdw.h"
33*7304104dSAndroid Build Coastguard Worker #include <stdio.h>
34*7304104dSAndroid Build Coastguard Worker 
35*7304104dSAndroid Build Coastguard Worker /* Handle for a session using the library.  */
36*7304104dSAndroid Build Coastguard Worker typedef struct Dwfl Dwfl;
37*7304104dSAndroid Build Coastguard Worker 
38*7304104dSAndroid Build Coastguard Worker /* Handle for a module.  */
39*7304104dSAndroid Build Coastguard Worker typedef struct Dwfl_Module Dwfl_Module;
40*7304104dSAndroid Build Coastguard Worker 
41*7304104dSAndroid Build Coastguard Worker /* Handle describing a line record.  */
42*7304104dSAndroid Build Coastguard Worker typedef struct Dwfl_Line Dwfl_Line;
43*7304104dSAndroid Build Coastguard Worker 
44*7304104dSAndroid Build Coastguard Worker /* This holds information common for all the frames of one backtrace for
45*7304104dSAndroid Build Coastguard Worker    a particular thread/task/TID.  Several threads belong to one Dwfl.  */
46*7304104dSAndroid Build Coastguard Worker typedef struct Dwfl_Thread Dwfl_Thread;
47*7304104dSAndroid Build Coastguard Worker 
48*7304104dSAndroid Build Coastguard Worker /* This holds everything we know about the state of the frame at a particular
49*7304104dSAndroid Build Coastguard Worker    PC location described by an FDE belonging to Dwfl_Thread.  */
50*7304104dSAndroid Build Coastguard Worker typedef struct Dwfl_Frame Dwfl_Frame;
51*7304104dSAndroid Build Coastguard Worker 
52*7304104dSAndroid Build Coastguard Worker /* Handle for debuginfod-client connection.  */
53*7304104dSAndroid Build Coastguard Worker #ifndef _ELFUTILS_DEBUGINFOD_CLIENT_TYPEDEF
54*7304104dSAndroid Build Coastguard Worker typedef struct debuginfod_client debuginfod_client;
55*7304104dSAndroid Build Coastguard Worker #define _ELFUTILS_DEBUGINFOD_CLIENT_TYPEDEF 1
56*7304104dSAndroid Build Coastguard Worker #endif
57*7304104dSAndroid Build Coastguard Worker 
58*7304104dSAndroid Build Coastguard Worker /* Callbacks.  */
59*7304104dSAndroid Build Coastguard Worker typedef struct
60*7304104dSAndroid Build Coastguard Worker {
61*7304104dSAndroid Build Coastguard Worker   int (*find_elf) (Dwfl_Module *mod, void **userdata,
62*7304104dSAndroid Build Coastguard Worker 		   const char *modname, Dwarf_Addr base,
63*7304104dSAndroid Build Coastguard Worker 		   char **file_name, Elf **elfp);
64*7304104dSAndroid Build Coastguard Worker 
65*7304104dSAndroid Build Coastguard Worker   int (*find_debuginfo) (Dwfl_Module *mod, void **userdata,
66*7304104dSAndroid Build Coastguard Worker 			 const char *modname, Dwarf_Addr base,
67*7304104dSAndroid Build Coastguard Worker 			 const char *file_name,
68*7304104dSAndroid Build Coastguard Worker 			 const char *debuglink_file, GElf_Word debuglink_crc,
69*7304104dSAndroid Build Coastguard Worker 			 char **debuginfo_file_name);
70*7304104dSAndroid Build Coastguard Worker 
71*7304104dSAndroid Build Coastguard Worker   /* Fill *ADDR with the loaded address of the section called SECNAME in
72*7304104dSAndroid Build Coastguard Worker      the given module.  Use (Dwarf_Addr) -1 if this section is omitted from
73*7304104dSAndroid Build Coastguard Worker      accessible memory.  This is called exactly once for each SHF_ALLOC
74*7304104dSAndroid Build Coastguard Worker      section that relocations affecting DWARF data refer to, so it can
75*7304104dSAndroid Build Coastguard Worker      easily be used to collect state about the sections referenced.  */
76*7304104dSAndroid Build Coastguard Worker   int (*section_address) (Dwfl_Module *mod, void **userdata,
77*7304104dSAndroid Build Coastguard Worker 			  const char *modname, Dwarf_Addr base,
78*7304104dSAndroid Build Coastguard Worker 			  const char *secname,
79*7304104dSAndroid Build Coastguard Worker 			  GElf_Word shndx, const GElf_Shdr *shdr,
80*7304104dSAndroid Build Coastguard Worker 			  Dwarf_Addr *addr);
81*7304104dSAndroid Build Coastguard Worker 
82*7304104dSAndroid Build Coastguard Worker   char **debuginfo_path;	/* See dwfl_standard_find_debuginfo.  */
83*7304104dSAndroid Build Coastguard Worker } Dwfl_Callbacks;
84*7304104dSAndroid Build Coastguard Worker 
85*7304104dSAndroid Build Coastguard Worker 
86*7304104dSAndroid Build Coastguard Worker #ifdef __cplusplus
87*7304104dSAndroid Build Coastguard Worker extern "C" {
88*7304104dSAndroid Build Coastguard Worker #endif
89*7304104dSAndroid Build Coastguard Worker 
90*7304104dSAndroid Build Coastguard Worker /* Start a new session with the library.  */
91*7304104dSAndroid Build Coastguard Worker extern Dwfl *dwfl_begin (const Dwfl_Callbacks *callbacks)
92*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1);
93*7304104dSAndroid Build Coastguard Worker 
94*7304104dSAndroid Build Coastguard Worker 
95*7304104dSAndroid Build Coastguard Worker /* End a session.  */
96*7304104dSAndroid Build Coastguard Worker extern void dwfl_end (Dwfl *);
97*7304104dSAndroid Build Coastguard Worker 
98*7304104dSAndroid Build Coastguard Worker /* Return implementation's version string suitable for printing.  */
99*7304104dSAndroid Build Coastguard Worker extern const char *dwfl_version (Dwfl *);
100*7304104dSAndroid Build Coastguard Worker 
101*7304104dSAndroid Build Coastguard Worker /* Return error code of last failing function call.  This value is kept
102*7304104dSAndroid Build Coastguard Worker    separately for each thread.  */
103*7304104dSAndroid Build Coastguard Worker extern int dwfl_errno (void);
104*7304104dSAndroid Build Coastguard Worker 
105*7304104dSAndroid Build Coastguard Worker /* Return error string for ERROR.  If ERROR is zero, return error string
106*7304104dSAndroid Build Coastguard Worker    for most recent error or NULL if none occurred.  If ERROR is -1 the
107*7304104dSAndroid Build Coastguard Worker    behaviour is similar to the last case except that not NULL but a legal
108*7304104dSAndroid Build Coastguard Worker    string is returned.  */
109*7304104dSAndroid Build Coastguard Worker extern const char *dwfl_errmsg (int err);
110*7304104dSAndroid Build Coastguard Worker 
111*7304104dSAndroid Build Coastguard Worker 
112*7304104dSAndroid Build Coastguard Worker /* Start reporting the current set of segments and modules to the library.
113*7304104dSAndroid Build Coastguard Worker    All existing segments are wiped.  Existing modules are marked to be
114*7304104dSAndroid Build Coastguard Worker    deleted, and will not be found via dwfl_addrmodule et al if they are not
115*7304104dSAndroid Build Coastguard Worker    re-reported before dwfl_report_end is called.  */
116*7304104dSAndroid Build Coastguard Worker extern void dwfl_report_begin (Dwfl *dwfl);
117*7304104dSAndroid Build Coastguard Worker 
118*7304104dSAndroid Build Coastguard Worker /* Report that segment NDX begins at PHDR->p_vaddr + BIAS.
119*7304104dSAndroid Build Coastguard Worker    If NDX is < 0, the value succeeding the last call's NDX
120*7304104dSAndroid Build Coastguard Worker    is used instead (zero on the first call).  IDENT is ignored.
121*7304104dSAndroid Build Coastguard Worker 
122*7304104dSAndroid Build Coastguard Worker    If nonzero, the smallest PHDR->p_align value seen sets the
123*7304104dSAndroid Build Coastguard Worker    effective page size for the address space DWFL describes.
124*7304104dSAndroid Build Coastguard Worker    This is the granularity at which reported module boundary
125*7304104dSAndroid Build Coastguard Worker    addresses will be considered to fall in or out of a segment.
126*7304104dSAndroid Build Coastguard Worker 
127*7304104dSAndroid Build Coastguard Worker    Returns -1 for errors, or NDX (or its assigned replacement) on success.
128*7304104dSAndroid Build Coastguard Worker 
129*7304104dSAndroid Build Coastguard Worker    Reporting segments at all is optional.  Its only benefit to the caller is to
130*7304104dSAndroid Build Coastguard Worker    offer this quick lookup via dwfl_addrsegment, or use other segment-based
131*7304104dSAndroid Build Coastguard Worker    calls.  */
132*7304104dSAndroid Build Coastguard Worker extern int dwfl_report_segment (Dwfl *dwfl, int ndx,
133*7304104dSAndroid Build Coastguard Worker 				const GElf_Phdr *phdr, GElf_Addr bias,
134*7304104dSAndroid Build Coastguard Worker 				const void *ident);
135*7304104dSAndroid Build Coastguard Worker 
136*7304104dSAndroid Build Coastguard Worker /* Report that a module called NAME spans addresses [START, END).
137*7304104dSAndroid Build Coastguard Worker    Returns the module handle, either existing or newly allocated,
138*7304104dSAndroid Build Coastguard Worker    or returns a null pointer for an allocation error.  */
139*7304104dSAndroid Build Coastguard Worker extern Dwfl_Module *dwfl_report_module (Dwfl *dwfl, const char *name,
140*7304104dSAndroid Build Coastguard Worker 					Dwarf_Addr start, Dwarf_Addr end);
141*7304104dSAndroid Build Coastguard Worker 
142*7304104dSAndroid Build Coastguard Worker /* Report a module to address BASE with start and end addresses computed
143*7304104dSAndroid Build Coastguard Worker    from the ELF program headers in the given file - see the table below.
144*7304104dSAndroid Build Coastguard Worker    FD may be -1 to open FILE_NAME.  On success, FD is consumed by the
145*7304104dSAndroid Build Coastguard Worker    library, and the `find_elf' callback will not be used for this module.
146*7304104dSAndroid Build Coastguard Worker 	    ADD_P_VADDR  BASE
147*7304104dSAndroid Build Coastguard Worker    ET_EXEC  ignored      ignored
148*7304104dSAndroid Build Coastguard Worker    ET_DYN   false        absolute address where to place the file
149*7304104dSAndroid Build Coastguard Worker 	    true         start address relative to ELF's phdr p_vaddr
150*7304104dSAndroid Build Coastguard Worker    ET_REL   ignored      absolute address where to place the file
151*7304104dSAndroid Build Coastguard Worker    ET_CORE  ignored      ignored
152*7304104dSAndroid Build Coastguard Worker    ET_DYN ELF phdr p_vaddr address can be non-zero if the shared library
153*7304104dSAndroid Build Coastguard Worker    has been prelinked by tool prelink(8).  */
154*7304104dSAndroid Build Coastguard Worker extern Dwfl_Module *dwfl_report_elf (Dwfl *dwfl, const char *name,
155*7304104dSAndroid Build Coastguard Worker 				     const char *file_name, int fd,
156*7304104dSAndroid Build Coastguard Worker 				     GElf_Addr base, bool add_p_vaddr);
157*7304104dSAndroid Build Coastguard Worker 
158*7304104dSAndroid Build Coastguard Worker /* Similar, but report the module for offline use.  All ET_EXEC files
159*7304104dSAndroid Build Coastguard Worker    being reported must be reported before any relocatable objects.
160*7304104dSAndroid Build Coastguard Worker    If this is used, dwfl_report_module and dwfl_report_elf may not be
161*7304104dSAndroid Build Coastguard Worker    used in the same reporting session.  */
162*7304104dSAndroid Build Coastguard Worker extern Dwfl_Module *dwfl_report_offline (Dwfl *dwfl, const char *name,
163*7304104dSAndroid Build Coastguard Worker 					 const char *file_name, int fd);
164*7304104dSAndroid Build Coastguard Worker 
165*7304104dSAndroid Build Coastguard Worker /* Similar, but report ELF from memory region.  */
166*7304104dSAndroid Build Coastguard Worker extern Dwfl_Module *dwfl_report_offline_memory (Dwfl *dwfl, const char *name,
167*7304104dSAndroid Build Coastguard Worker 						const char *file_name,
168*7304104dSAndroid Build Coastguard Worker 						char *data, size_t size);
169*7304104dSAndroid Build Coastguard Worker 
170*7304104dSAndroid Build Coastguard Worker /* Finish reporting the current set of modules to the library.
171*7304104dSAndroid Build Coastguard Worker    If REMOVED is not null, it's called for each module that
172*7304104dSAndroid Build Coastguard Worker    existed before but was not included in the current report.
173*7304104dSAndroid Build Coastguard Worker    Returns a nonzero return value from the callback.
174*7304104dSAndroid Build Coastguard Worker    The callback may call dwfl_report_module; doing so with the
175*7304104dSAndroid Build Coastguard Worker    details of the module being removed prevents its removal.
176*7304104dSAndroid Build Coastguard Worker    DWFL cannot be used until this function has returned zero.  */
177*7304104dSAndroid Build Coastguard Worker extern int dwfl_report_end (Dwfl *dwfl,
178*7304104dSAndroid Build Coastguard Worker 			    int (*removed) (Dwfl_Module *, void *,
179*7304104dSAndroid Build Coastguard Worker 					    const char *, Dwarf_Addr,
180*7304104dSAndroid Build Coastguard Worker 					    void *arg),
181*7304104dSAndroid Build Coastguard Worker 			    void *arg);
182*7304104dSAndroid Build Coastguard Worker 
183*7304104dSAndroid Build Coastguard Worker /* Start reporting additional modules to the library.  No calls but
184*7304104dSAndroid Build Coastguard Worker    dwfl_report_* can be made on DWFL until dwfl_report_end is called.
185*7304104dSAndroid Build Coastguard Worker    This is like dwfl_report_begin, but all the old modules are kept on.
186*7304104dSAndroid Build Coastguard Worker    More dwfl_report_* calls can follow to add more modules.
187*7304104dSAndroid Build Coastguard Worker    When dwfl_report_end is called, no old modules will be removed.  */
188*7304104dSAndroid Build Coastguard Worker extern void dwfl_report_begin_add (Dwfl *dwfl);
189*7304104dSAndroid Build Coastguard Worker 
190*7304104dSAndroid Build Coastguard Worker 
191*7304104dSAndroid Build Coastguard Worker /* Return the name of the module, and for each non-null argument store
192*7304104dSAndroid Build Coastguard Worker    interesting details: *USERDATA is a location for storing your own
193*7304104dSAndroid Build Coastguard Worker    pointer, **USERDATA is initially null; *START and *END give the address
194*7304104dSAndroid Build Coastguard Worker    range covered by the module; *DWBIAS is the address bias for debugging
195*7304104dSAndroid Build Coastguard Worker    information, and *SYMBIAS for symbol table entries (either is -1 if not
196*7304104dSAndroid Build Coastguard Worker    yet accessed); *MAINFILE is the name of the ELF file, and *DEBUGFILE the
197*7304104dSAndroid Build Coastguard Worker    name of the debuginfo file (might be equal to *MAINFILE; either is null
198*7304104dSAndroid Build Coastguard Worker    if not yet accessed).  */
199*7304104dSAndroid Build Coastguard Worker extern const char *dwfl_module_info (Dwfl_Module *mod, void ***userdata,
200*7304104dSAndroid Build Coastguard Worker 				     Dwarf_Addr *start, Dwarf_Addr *end,
201*7304104dSAndroid Build Coastguard Worker 				     Dwarf_Addr *dwbias, Dwarf_Addr *symbias,
202*7304104dSAndroid Build Coastguard Worker 				     const char **mainfile,
203*7304104dSAndroid Build Coastguard Worker 				     const char **debugfile);
204*7304104dSAndroid Build Coastguard Worker 
205*7304104dSAndroid Build Coastguard Worker /* Iterate through the modules, starting the walk with OFFSET == 0.
206*7304104dSAndroid Build Coastguard Worker    Calls *CALLBACK for each module as long as it returns DWARF_CB_OK.
207*7304104dSAndroid Build Coastguard Worker    When *CALLBACK returns another value, the walk stops and the
208*7304104dSAndroid Build Coastguard Worker    return value can be passed as OFFSET to resume it.  Returns 0 when
209*7304104dSAndroid Build Coastguard Worker    there are no more modules, or -1 for errors.  */
210*7304104dSAndroid Build Coastguard Worker extern ptrdiff_t dwfl_getmodules (Dwfl *dwfl,
211*7304104dSAndroid Build Coastguard Worker 				  int (*callback) (Dwfl_Module *, void **,
212*7304104dSAndroid Build Coastguard Worker 						   const char *, Dwarf_Addr,
213*7304104dSAndroid Build Coastguard Worker 						   void *arg),
214*7304104dSAndroid Build Coastguard Worker 				  void *arg,
215*7304104dSAndroid Build Coastguard Worker 				  ptrdiff_t offset);
216*7304104dSAndroid Build Coastguard Worker 
217*7304104dSAndroid Build Coastguard Worker /* Find the module containing the given address.  */
218*7304104dSAndroid Build Coastguard Worker extern Dwfl_Module *dwfl_addrmodule (Dwfl *dwfl, Dwarf_Addr address);
219*7304104dSAndroid Build Coastguard Worker 
220*7304104dSAndroid Build Coastguard Worker /* Find the segment, if any, and module, if any, containing ADDRESS.
221*7304104dSAndroid Build Coastguard Worker    Returns a segment index returned by dwfl_report_segment, or -1
222*7304104dSAndroid Build Coastguard Worker    if no segment matches the address.  Regardless of the return value,
223*7304104dSAndroid Build Coastguard Worker    *MOD is always set to the module containing ADDRESS, or to null.  */
224*7304104dSAndroid Build Coastguard Worker extern int dwfl_addrsegment (Dwfl *dwfl, Dwarf_Addr address, Dwfl_Module **mod);
225*7304104dSAndroid Build Coastguard Worker 
226*7304104dSAndroid Build Coastguard Worker 
227*7304104dSAndroid Build Coastguard Worker 
228*7304104dSAndroid Build Coastguard Worker /* Report the known build ID bits associated with a module.
229*7304104dSAndroid Build Coastguard Worker    If VADDR is nonzero, it gives the absolute address where those
230*7304104dSAndroid Build Coastguard Worker    bits are found within the module.  This can be called at any
231*7304104dSAndroid Build Coastguard Worker    time, but is usually used immediately after dwfl_report_module.
232*7304104dSAndroid Build Coastguard Worker    Once the module's main ELF file is opened, the ID note found
233*7304104dSAndroid Build Coastguard Worker    there takes precedence and cannot be changed.  */
234*7304104dSAndroid Build Coastguard Worker extern int dwfl_module_report_build_id (Dwfl_Module *mod,
235*7304104dSAndroid Build Coastguard Worker 					const unsigned char *bits, size_t len,
236*7304104dSAndroid Build Coastguard Worker 					GElf_Addr vaddr)
237*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (2);
238*7304104dSAndroid Build Coastguard Worker 
239*7304104dSAndroid Build Coastguard Worker /* Extract the build ID bits associated with a module.
240*7304104dSAndroid Build Coastguard Worker    Returns -1 for errors, 0 if no ID is known, or the number of ID bytes.
241*7304104dSAndroid Build Coastguard Worker    When an ID is found, *BITS points to it; *VADDR is the absolute address
242*7304104dSAndroid Build Coastguard Worker    at which the ID bits are found within the module, or 0 if unknown.
243*7304104dSAndroid Build Coastguard Worker 
244*7304104dSAndroid Build Coastguard Worker    This returns 0 when the module's main ELF file has not yet been loaded
245*7304104dSAndroid Build Coastguard Worker    and its build ID bits were not reported.  To ensure the ID is always
246*7304104dSAndroid Build Coastguard Worker    returned when determinable, call dwfl_module_getelf first.  */
247*7304104dSAndroid Build Coastguard Worker extern int dwfl_module_build_id (Dwfl_Module *mod,
248*7304104dSAndroid Build Coastguard Worker 				 const unsigned char **bits, GElf_Addr *vaddr)
249*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (2, 3);
250*7304104dSAndroid Build Coastguard Worker 
251*7304104dSAndroid Build Coastguard Worker 
252*7304104dSAndroid Build Coastguard Worker /*** Standard callbacks ***/
253*7304104dSAndroid Build Coastguard Worker 
254*7304104dSAndroid Build Coastguard Worker /* These standard find_elf and find_debuginfo callbacks are
255*7304104dSAndroid Build Coastguard Worker    controlled by a string specifying directories to look in.
256*7304104dSAndroid Build Coastguard Worker    If `debuginfo_path' is set in the Dwfl_Callbacks structure
257*7304104dSAndroid Build Coastguard Worker    and the char * it points to is not null, that supplies the
258*7304104dSAndroid Build Coastguard Worker    string.  Otherwise a default path is used.
259*7304104dSAndroid Build Coastguard Worker 
260*7304104dSAndroid Build Coastguard Worker    If the first character of the string is + or - that enables or
261*7304104dSAndroid Build Coastguard Worker    disables CRC32 checksum validation when it's necessary.  The
262*7304104dSAndroid Build Coastguard Worker    remainder of the string is composed of elements separated by
263*7304104dSAndroid Build Coastguard Worker    colons.  Each element can start with + or - to override the
264*7304104dSAndroid Build Coastguard Worker    global checksum behavior.  This flag is never relevant when
265*7304104dSAndroid Build Coastguard Worker    working with build IDs, but it's always parsed in the path
266*7304104dSAndroid Build Coastguard Worker    string.  The remainder of the element indicates a directory.
267*7304104dSAndroid Build Coastguard Worker 
268*7304104dSAndroid Build Coastguard Worker    Searches by build ID consult only the elements naming absolute
269*7304104dSAndroid Build Coastguard Worker    directory paths.  They look under those directories for a link
270*7304104dSAndroid Build Coastguard Worker    named ".build-id/xx/yy" or ".build-id/xx/yy.debug", where "xxyy"
271*7304104dSAndroid Build Coastguard Worker    is the lower-case hexadecimal representation of the ID bytes.
272*7304104dSAndroid Build Coastguard Worker 
273*7304104dSAndroid Build Coastguard Worker    In searches for debuginfo by name, if the remainder of the
274*7304104dSAndroid Build Coastguard Worker    element is empty, the directory containing the main file is
275*7304104dSAndroid Build Coastguard Worker    tried; if it's an absolute path name, the absolute directory path
276*7304104dSAndroid Build Coastguard Worker    (and any subdirectory of that path) containing the main file is
277*7304104dSAndroid Build Coastguard Worker    taken as a subdirectory of this path; a relative path name is taken
278*7304104dSAndroid Build Coastguard Worker    as a subdirectory of the directory containing the main file.
279*7304104dSAndroid Build Coastguard Worker    Hence for /usr/bin/ls, the default string ":.debug:/usr/lib/debug"
280*7304104dSAndroid Build Coastguard Worker    says to look in /usr/bin, then /usr/bin/.debug, then the path subdirs
281*7304104dSAndroid Build Coastguard Worker    under /usr/lib/debug, in the order /usr/lib/debug/usr/bin, then
282*7304104dSAndroid Build Coastguard Worker    /usr/lib/debug/bin, and finally /usr/lib/debug, for the file name in
283*7304104dSAndroid Build Coastguard Worker    the .gnu_debuglink section (or "ls.debug" if none was found).  */
284*7304104dSAndroid Build Coastguard Worker 
285*7304104dSAndroid Build Coastguard Worker /* Standard find_elf callback function working solely on build ID.
286*7304104dSAndroid Build Coastguard Worker    This can be tried first by any find_elf callback, to use the
287*7304104dSAndroid Build Coastguard Worker    bits passed to dwfl_module_report_build_id, if any.  */
288*7304104dSAndroid Build Coastguard Worker extern int dwfl_build_id_find_elf (Dwfl_Module *, void **,
289*7304104dSAndroid Build Coastguard Worker 				   const char *, Dwarf_Addr,
290*7304104dSAndroid Build Coastguard Worker 				   char **, Elf **);
291*7304104dSAndroid Build Coastguard Worker 
292*7304104dSAndroid Build Coastguard Worker /* Standard find_debuginfo callback function working solely on build ID.
293*7304104dSAndroid Build Coastguard Worker    This can be tried first by any find_debuginfo callback,
294*7304104dSAndroid Build Coastguard Worker    to use the build ID bits from the main file when present.  */
295*7304104dSAndroid Build Coastguard Worker extern int dwfl_build_id_find_debuginfo (Dwfl_Module *, void **,
296*7304104dSAndroid Build Coastguard Worker 					 const char *, Dwarf_Addr,
297*7304104dSAndroid Build Coastguard Worker 					 const char *, const char *,
298*7304104dSAndroid Build Coastguard Worker 					 GElf_Word, char **);
299*7304104dSAndroid Build Coastguard Worker 
300*7304104dSAndroid Build Coastguard Worker /* Standard find_debuginfo callback function.
301*7304104dSAndroid Build Coastguard Worker    If a build ID is available, this tries first to use that.
302*7304104dSAndroid Build Coastguard Worker    If there is no build ID or no valid debuginfo found by ID,
303*7304104dSAndroid Build Coastguard Worker    it searches the debuginfo path by name, as described above.
304*7304104dSAndroid Build Coastguard Worker    Any file found in the path is validated by build ID if possible,
305*7304104dSAndroid Build Coastguard Worker    or else by CRC32 checksum if enabled, and skipped if it does not match.  */
306*7304104dSAndroid Build Coastguard Worker extern int dwfl_standard_find_debuginfo (Dwfl_Module *, void **,
307*7304104dSAndroid Build Coastguard Worker 					 const char *, Dwarf_Addr,
308*7304104dSAndroid Build Coastguard Worker 					 const char *, const char *,
309*7304104dSAndroid Build Coastguard Worker 					 GElf_Word, char **);
310*7304104dSAndroid Build Coastguard Worker 
311*7304104dSAndroid Build Coastguard Worker 
312*7304104dSAndroid Build Coastguard Worker /* This callback must be used when using dwfl_offline_* to report modules,
313*7304104dSAndroid Build Coastguard Worker    if ET_REL is to be supported.  */
314*7304104dSAndroid Build Coastguard Worker extern int dwfl_offline_section_address (Dwfl_Module *, void **,
315*7304104dSAndroid Build Coastguard Worker 					 const char *, Dwarf_Addr,
316*7304104dSAndroid Build Coastguard Worker 					 const char *, GElf_Word,
317*7304104dSAndroid Build Coastguard Worker 					 const GElf_Shdr *,
318*7304104dSAndroid Build Coastguard Worker 					 Dwarf_Addr *addr);
319*7304104dSAndroid Build Coastguard Worker 
320*7304104dSAndroid Build Coastguard Worker 
321*7304104dSAndroid Build Coastguard Worker /* Callbacks for working with kernel modules in the running Linux kernel.  */
322*7304104dSAndroid Build Coastguard Worker extern int dwfl_linux_kernel_find_elf (Dwfl_Module *, void **,
323*7304104dSAndroid Build Coastguard Worker 				       const char *, Dwarf_Addr,
324*7304104dSAndroid Build Coastguard Worker 				       char **, Elf **);
325*7304104dSAndroid Build Coastguard Worker extern int dwfl_linux_kernel_module_section_address (Dwfl_Module *, void **,
326*7304104dSAndroid Build Coastguard Worker 						     const char *, Dwarf_Addr,
327*7304104dSAndroid Build Coastguard Worker 						     const char *, GElf_Word,
328*7304104dSAndroid Build Coastguard Worker 						     const GElf_Shdr *,
329*7304104dSAndroid Build Coastguard Worker 						     Dwarf_Addr *addr);
330*7304104dSAndroid Build Coastguard Worker 
331*7304104dSAndroid Build Coastguard Worker /* Call dwfl_report_elf for the running Linux kernel.
332*7304104dSAndroid Build Coastguard Worker    Returns zero on success, -1 if dwfl_report_module failed,
333*7304104dSAndroid Build Coastguard Worker    or an errno code if opening the kernel binary failed.  */
334*7304104dSAndroid Build Coastguard Worker extern int dwfl_linux_kernel_report_kernel (Dwfl *dwfl);
335*7304104dSAndroid Build Coastguard Worker 
336*7304104dSAndroid Build Coastguard Worker /* Call dwfl_report_module for each kernel module in the running Linux kernel.
337*7304104dSAndroid Build Coastguard Worker    Returns zero on success, -1 if dwfl_report_module failed,
338*7304104dSAndroid Build Coastguard Worker    or an errno code if reading the list of modules failed.  */
339*7304104dSAndroid Build Coastguard Worker extern int dwfl_linux_kernel_report_modules (Dwfl *dwfl);
340*7304104dSAndroid Build Coastguard Worker 
341*7304104dSAndroid Build Coastguard Worker /* Report a kernel and its modules found on disk, for offline use.
342*7304104dSAndroid Build Coastguard Worker    If RELEASE starts with '/', it names a directory to look in;
343*7304104dSAndroid Build Coastguard Worker    if not, it names a directory to find under /lib/modules/;
344*7304104dSAndroid Build Coastguard Worker    if null, /lib/modules/`uname -r` is used.
345*7304104dSAndroid Build Coastguard Worker    Returns zero on success, -1 if dwfl_report_module failed,
346*7304104dSAndroid Build Coastguard Worker    or an errno code if finding the files on disk failed.
347*7304104dSAndroid Build Coastguard Worker 
348*7304104dSAndroid Build Coastguard Worker    If PREDICATE is not null, it is called with each module to be reported;
349*7304104dSAndroid Build Coastguard Worker    its arguments are the module name, and the ELF file name or null if unknown,
350*7304104dSAndroid Build Coastguard Worker    and its return value should be zero to skip the module, one to report it,
351*7304104dSAndroid Build Coastguard Worker    or -1 to cause the call to fail and return errno.  */
352*7304104dSAndroid Build Coastguard Worker extern int dwfl_linux_kernel_report_offline (Dwfl *dwfl, const char *release,
353*7304104dSAndroid Build Coastguard Worker 					     int (*predicate) (const char *,
354*7304104dSAndroid Build Coastguard Worker 							       const char *));
355*7304104dSAndroid Build Coastguard Worker 
356*7304104dSAndroid Build Coastguard Worker /* Examine an ET_CORE file and report modules based on its contents.
357*7304104dSAndroid Build Coastguard Worker    This can follow a dwfl_report_offline call to bootstrap the
358*7304104dSAndroid Build Coastguard Worker    DT_DEBUG method of following the dynamic linker link_map chain, in
359*7304104dSAndroid Build Coastguard Worker    case the core file does not contain enough of the executable's text
360*7304104dSAndroid Build Coastguard Worker    segment to locate its PT_DYNAMIC in the dump.  In such case you need to
361*7304104dSAndroid Build Coastguard Worker    supply non-NULL EXECUTABLE, otherwise dynamic libraries will not be loaded
362*7304104dSAndroid Build Coastguard Worker    into the DWFL map.  This might call dwfl_report_elf on file names found in
363*7304104dSAndroid Build Coastguard Worker    the dump if reading some link_map files is the only way to ascertain those
364*7304104dSAndroid Build Coastguard Worker    modules' addresses.  Returns the number of modules reported, or -1 for
365*7304104dSAndroid Build Coastguard Worker    errors.  */
366*7304104dSAndroid Build Coastguard Worker extern int dwfl_core_file_report (Dwfl *dwfl, Elf *elf, const char *executable);
367*7304104dSAndroid Build Coastguard Worker 
368*7304104dSAndroid Build Coastguard Worker /* Call dwfl_report_module for each file mapped into the address space of PID.
369*7304104dSAndroid Build Coastguard Worker    Returns zero on success, -1 if dwfl_report_module failed,
370*7304104dSAndroid Build Coastguard Worker    or an errno code if opening the proc files failed.  */
371*7304104dSAndroid Build Coastguard Worker extern int dwfl_linux_proc_report (Dwfl *dwfl, pid_t pid);
372*7304104dSAndroid Build Coastguard Worker 
373*7304104dSAndroid Build Coastguard Worker /* Similar, but reads an input stream in the format of Linux /proc/PID/maps
374*7304104dSAndroid Build Coastguard Worker    files giving module layout, not the file for a live process.  */
375*7304104dSAndroid Build Coastguard Worker extern int dwfl_linux_proc_maps_report (Dwfl *dwfl, FILE *);
376*7304104dSAndroid Build Coastguard Worker 
377*7304104dSAndroid Build Coastguard Worker /* Trivial find_elf callback for use with dwfl_linux_proc_report.
378*7304104dSAndroid Build Coastguard Worker    This uses the module name as a file name directly and tries to open it
379*7304104dSAndroid Build Coastguard Worker    if it begin with a slash, or handles the magic string "[vdso]".  */
380*7304104dSAndroid Build Coastguard Worker extern int dwfl_linux_proc_find_elf (Dwfl_Module *mod, void **userdata,
381*7304104dSAndroid Build Coastguard Worker 				     const char *module_name, Dwarf_Addr base,
382*7304104dSAndroid Build Coastguard Worker 				     char **file_name, Elf **);
383*7304104dSAndroid Build Coastguard Worker 
384*7304104dSAndroid Build Coastguard Worker /* Standard argument parsing for using a standard callback set.  */
385*7304104dSAndroid Build Coastguard Worker struct argp;
386*7304104dSAndroid Build Coastguard Worker extern const struct argp *dwfl_standard_argp (void) __const_attribute__;
387*7304104dSAndroid Build Coastguard Worker 
388*7304104dSAndroid Build Coastguard Worker 
389*7304104dSAndroid Build Coastguard Worker /*** Relocation of addresses from Dwfl ***/
390*7304104dSAndroid Build Coastguard Worker 
391*7304104dSAndroid Build Coastguard Worker /* Return the number of relocatable bases associated with the module,
392*7304104dSAndroid Build Coastguard Worker    which is zero for ET_EXEC and one for ET_DYN.  Returns -1 for errors.  */
393*7304104dSAndroid Build Coastguard Worker extern int dwfl_module_relocations (Dwfl_Module *mod);
394*7304104dSAndroid Build Coastguard Worker 
395*7304104dSAndroid Build Coastguard Worker /* Return the relocation base index associated with the *ADDRESS location,
396*7304104dSAndroid Build Coastguard Worker    and adjust *ADDRESS to be an offset relative to that base.
397*7304104dSAndroid Build Coastguard Worker    Returns -1 for errors.  */
398*7304104dSAndroid Build Coastguard Worker extern int dwfl_module_relocate_address (Dwfl_Module *mod,
399*7304104dSAndroid Build Coastguard Worker 					 Dwarf_Addr *address);
400*7304104dSAndroid Build Coastguard Worker 
401*7304104dSAndroid Build Coastguard Worker /* Return the ELF section name for the given relocation base index;
402*7304104dSAndroid Build Coastguard Worker    if SHNDXP is not null, set *SHNDXP to the ELF section index.
403*7304104dSAndroid Build Coastguard Worker    For ET_DYN, returns "" and sets *SHNDXP to SHN_ABS; the relocation
404*7304104dSAndroid Build Coastguard Worker    base is the runtime start address reported for the module.
405*7304104dSAndroid Build Coastguard Worker    Returns null for errors.  */
406*7304104dSAndroid Build Coastguard Worker extern const char *dwfl_module_relocation_info (Dwfl_Module *mod,
407*7304104dSAndroid Build Coastguard Worker 						unsigned int idx,
408*7304104dSAndroid Build Coastguard Worker 						GElf_Word *shndxp);
409*7304104dSAndroid Build Coastguard Worker 
410*7304104dSAndroid Build Coastguard Worker /* Validate that ADDRESS and ADDRESS+OFFSET lie in a known module
411*7304104dSAndroid Build Coastguard Worker    and both within the same contiguous region for relocation purposes.
412*7304104dSAndroid Build Coastguard Worker    Returns zero for success and -1 for errors.  */
413*7304104dSAndroid Build Coastguard Worker extern int dwfl_validate_address (Dwfl *dwfl,
414*7304104dSAndroid Build Coastguard Worker 				  Dwarf_Addr address, Dwarf_Sword offset);
415*7304104dSAndroid Build Coastguard Worker 
416*7304104dSAndroid Build Coastguard Worker 
417*7304104dSAndroid Build Coastguard Worker /*** ELF access functions ***/
418*7304104dSAndroid Build Coastguard Worker 
419*7304104dSAndroid Build Coastguard Worker /* Fetch the module main ELF file (where the allocated sections
420*7304104dSAndroid Build Coastguard Worker    are found) for use with libelf.  If successful, fills in *BIAS
421*7304104dSAndroid Build Coastguard Worker    with the difference between addresses within the loaded module
422*7304104dSAndroid Build Coastguard Worker    and those in symbol tables or Dwarf information referring to it.  */
423*7304104dSAndroid Build Coastguard Worker extern Elf *dwfl_module_getelf (Dwfl_Module *, GElf_Addr *bias)
424*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (2);
425*7304104dSAndroid Build Coastguard Worker 
426*7304104dSAndroid Build Coastguard Worker /* Return the number of symbols in the module's symbol table,
427*7304104dSAndroid Build Coastguard Worker    or -1 for errors.  */
428*7304104dSAndroid Build Coastguard Worker extern int dwfl_module_getsymtab (Dwfl_Module *mod);
429*7304104dSAndroid Build Coastguard Worker 
430*7304104dSAndroid Build Coastguard Worker /* Return the index of the first global symbol in the module's symbol
431*7304104dSAndroid Build Coastguard Worker    table, or -1 for errors.  In each symbol table, all symbols with
432*7304104dSAndroid Build Coastguard Worker    STB_LOCAL binding precede the weak and global symbols.  This
433*7304104dSAndroid Build Coastguard Worker    function returns the symbol table index one greater than the last
434*7304104dSAndroid Build Coastguard Worker    local symbol.  */
435*7304104dSAndroid Build Coastguard Worker extern int dwfl_module_getsymtab_first_global (Dwfl_Module *mod);
436*7304104dSAndroid Build Coastguard Worker 
437*7304104dSAndroid Build Coastguard Worker /* Fetch one entry from the module's symbol table.  On errors, returns
438*7304104dSAndroid Build Coastguard Worker    NULL.  If successful, fills in *SYM and returns the string for st_name.
439*7304104dSAndroid Build Coastguard Worker    This works like gelf_getsym except that st_value is always adjusted to
440*7304104dSAndroid Build Coastguard Worker    an absolute value based on the module's location, when the symbol is in
441*7304104dSAndroid Build Coastguard Worker    an SHF_ALLOC section.  If SHNDXP is non-null, it's set with the section
442*7304104dSAndroid Build Coastguard Worker    index (whether from st_shndx or extended index table); in case of a
443*7304104dSAndroid Build Coastguard Worker    symbol in a non-allocated section, *SHNDXP is instead set to -1.
444*7304104dSAndroid Build Coastguard Worker    Note that since symbols can come from either the main, debug or auxiliary
445*7304104dSAndroid Build Coastguard Worker    ELF symbol file (either dynsym or symtab) the section index can only
446*7304104dSAndroid Build Coastguard Worker    be reliably used to compare against special section constants like
447*7304104dSAndroid Build Coastguard Worker    SHN_UNDEF or SHN_ABS.  It is recommended to use dwfl_module_getsym_info
448*7304104dSAndroid Build Coastguard Worker    which doesn't have these deficiencies.  */
449*7304104dSAndroid Build Coastguard Worker extern const char *dwfl_module_getsym (Dwfl_Module *mod, int ndx,
450*7304104dSAndroid Build Coastguard Worker 				       GElf_Sym *sym, GElf_Word *shndxp)
451*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (3);
452*7304104dSAndroid Build Coastguard Worker 
453*7304104dSAndroid Build Coastguard Worker /* Fetch one entry from the module's symbol table and the associated
454*7304104dSAndroid Build Coastguard Worker    address value.  On errors, returns NULL.  If successful, fills in
455*7304104dSAndroid Build Coastguard Worker    *SYM, *ADDR and returns the string for st_name.  This works like
456*7304104dSAndroid Build Coastguard Worker    gelf_getsym.  *ADDR is set to the st_value adjusted to an absolute
457*7304104dSAndroid Build Coastguard Worker    value based on the module's location, when the symbol is in an
458*7304104dSAndroid Build Coastguard Worker    SHF_ALLOC section.  For non-ET_REL files, if the arch uses function
459*7304104dSAndroid Build Coastguard Worker    descriptors, and the st_value points to one, *ADDR will be resolved
460*7304104dSAndroid Build Coastguard Worker    to the actual function entry address.  The SYM->ST_VALUE itself
461*7304104dSAndroid Build Coastguard Worker    isn't adjusted in any way.  Fills in ELFP, if not NULL, with the
462*7304104dSAndroid Build Coastguard Worker    ELF file the symbol originally came from.  Note that symbols can
463*7304104dSAndroid Build Coastguard Worker    come from either the main, debug or auxiliary ELF symbol file
464*7304104dSAndroid Build Coastguard Worker    (either dynsym or symtab).  If SHNDXP is non-null, it's set with
465*7304104dSAndroid Build Coastguard Worker    the section index (whether from st_shndx or extended index table);
466*7304104dSAndroid Build Coastguard Worker    in case of a symbol in a non-allocated section, *SHNDXP is instead
467*7304104dSAndroid Build Coastguard Worker    set to -1.  Fills in BIAS, if not NULL, with the difference between
468*7304104dSAndroid Build Coastguard Worker    addresses within the loaded module and those in symbol table of the
469*7304104dSAndroid Build Coastguard Worker    ELF file.  Note that the address associated with the symbol might
470*7304104dSAndroid Build Coastguard Worker    be in a different section than the returned symbol.  The section in
471*7304104dSAndroid Build Coastguard Worker    the main elf file in which returned ADDR falls can be found with
472*7304104dSAndroid Build Coastguard Worker    dwfl_module_address_section.  */
473*7304104dSAndroid Build Coastguard Worker extern const char *dwfl_module_getsym_info (Dwfl_Module *mod, int ndx,
474*7304104dSAndroid Build Coastguard Worker 					    GElf_Sym *sym, GElf_Addr *addr,
475*7304104dSAndroid Build Coastguard Worker 					    GElf_Word *shndxp,
476*7304104dSAndroid Build Coastguard Worker 					    Elf **elfp, Dwarf_Addr *bias)
477*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (3, 4);
478*7304104dSAndroid Build Coastguard Worker 
479*7304104dSAndroid Build Coastguard Worker /* Find the symbol that ADDRESS lies inside, and return its name.  */
480*7304104dSAndroid Build Coastguard Worker extern const char *dwfl_module_addrname (Dwfl_Module *mod, GElf_Addr address);
481*7304104dSAndroid Build Coastguard Worker 
482*7304104dSAndroid Build Coastguard Worker /* Find the symbol associated with ADDRESS.  Return its name or NULL
483*7304104dSAndroid Build Coastguard Worker    when nothing was found.  If the architecture uses function
484*7304104dSAndroid Build Coastguard Worker    descriptors, and symbol st_value points to one, ADDRESS will be
485*7304104dSAndroid Build Coastguard Worker    matched against either the adjusted st_value or the associated
486*7304104dSAndroid Build Coastguard Worker    function entry value as described in dwfl_module_getsym_info.
487*7304104dSAndroid Build Coastguard Worker    OFFSET will be filled in with the difference from the start of the
488*7304104dSAndroid Build Coastguard Worker    symbol (or function entry), OFFSET cannot be NULL.  SYM is filled
489*7304104dSAndroid Build Coastguard Worker    in with the symbol associated with the matched ADDRESS, SYM cannot
490*7304104dSAndroid Build Coastguard Worker    be NULL.  The SYM->ST_VALUE itself isn't adjusted in any way.
491*7304104dSAndroid Build Coastguard Worker    Fills in ELFP, if not NULL, with the ELF file the symbol originally
492*7304104dSAndroid Build Coastguard Worker    came from.  Note that symbols can come from either the main, debug
493*7304104dSAndroid Build Coastguard Worker    or auxiliary ELF symbol file (either dynsym or symtab).  If SHNDXP
494*7304104dSAndroid Build Coastguard Worker    is non-null, it's set with the section index (whether from st_shndx
495*7304104dSAndroid Build Coastguard Worker    or extended index table).  Fills in BIAS, if not NULL, with the
496*7304104dSAndroid Build Coastguard Worker    difference between addresses within the loaded module and those in
497*7304104dSAndroid Build Coastguard Worker    symbol table of the ELF file.  Note that the address matched
498*7304104dSAndroid Build Coastguard Worker    against the symbol might be in a different section than the
499*7304104dSAndroid Build Coastguard Worker    returned symbol.  The section in the main elf file in ADDRESS falls
500*7304104dSAndroid Build Coastguard Worker    can be found with dwfl_module_address_section.  */
501*7304104dSAndroid Build Coastguard Worker extern const char *dwfl_module_addrinfo (Dwfl_Module *mod, GElf_Addr address,
502*7304104dSAndroid Build Coastguard Worker 					 GElf_Off *offset, GElf_Sym *sym,
503*7304104dSAndroid Build Coastguard Worker 					 GElf_Word *shndxp, Elf **elfp,
504*7304104dSAndroid Build Coastguard Worker 					 Dwarf_Addr *bias)
505*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (3, 4);
506*7304104dSAndroid Build Coastguard Worker 
507*7304104dSAndroid Build Coastguard Worker /* Find the symbol that ADDRESS lies inside, and return detailed
508*7304104dSAndroid Build Coastguard Worker    information as for dwfl_module_getsym (above).  Note that like
509*7304104dSAndroid Build Coastguard Worker    dwfl_module_getsym this function also adjusts SYM->ST_VALUE to an
510*7304104dSAndroid Build Coastguard Worker    absolute value based on the module's location.  ADDRESS is only
511*7304104dSAndroid Build Coastguard Worker    matched against this adjusted SYM->ST_VALUE.  This means that
512*7304104dSAndroid Build Coastguard Worker    depending on architecture this might only match symbols that
513*7304104dSAndroid Build Coastguard Worker    represent function descriptor addresses (and not function entry
514*7304104dSAndroid Build Coastguard Worker    addresses).  For these reasons it is recommended to use
515*7304104dSAndroid Build Coastguard Worker    dwfl_module_addrinfo instead.  */
516*7304104dSAndroid Build Coastguard Worker extern const char *dwfl_module_addrsym (Dwfl_Module *mod, GElf_Addr address,
517*7304104dSAndroid Build Coastguard Worker 					GElf_Sym *sym, GElf_Word *shndxp)
518*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (3);
519*7304104dSAndroid Build Coastguard Worker 
520*7304104dSAndroid Build Coastguard Worker /* Find the ELF section that *ADDRESS lies inside and return it.
521*7304104dSAndroid Build Coastguard Worker    On success, adjusts *ADDRESS to be relative to the section,
522*7304104dSAndroid Build Coastguard Worker    and sets *BIAS to the difference between addresses used in
523*7304104dSAndroid Build Coastguard Worker    the returned section's headers and run-time addresses.  */
524*7304104dSAndroid Build Coastguard Worker extern Elf_Scn *dwfl_module_address_section (Dwfl_Module *mod,
525*7304104dSAndroid Build Coastguard Worker 					     Dwarf_Addr *address,
526*7304104dSAndroid Build Coastguard Worker 					     Dwarf_Addr *bias)
527*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (2, 3);
528*7304104dSAndroid Build Coastguard Worker 
529*7304104dSAndroid Build Coastguard Worker 
530*7304104dSAndroid Build Coastguard Worker /*** Dwarf access functions ***/
531*7304104dSAndroid Build Coastguard Worker 
532*7304104dSAndroid Build Coastguard Worker /* Fetch the module's debug information for use with libdw.
533*7304104dSAndroid Build Coastguard Worker    If successful, fills in *BIAS with the difference between
534*7304104dSAndroid Build Coastguard Worker    addresses within the loaded module and those  to use with libdw.  */
535*7304104dSAndroid Build Coastguard Worker extern Dwarf *dwfl_module_getdwarf (Dwfl_Module *, Dwarf_Addr *bias)
536*7304104dSAndroid Build Coastguard Worker      __nonnull_attribute__ (2);
537*7304104dSAndroid Build Coastguard Worker 
538*7304104dSAndroid Build Coastguard Worker /* Get the libdw handle for each module.  */
539*7304104dSAndroid Build Coastguard Worker extern ptrdiff_t dwfl_getdwarf (Dwfl *,
540*7304104dSAndroid Build Coastguard Worker 				int (*callback) (Dwfl_Module *, void **,
541*7304104dSAndroid Build Coastguard Worker 						 const char *, Dwarf_Addr,
542*7304104dSAndroid Build Coastguard Worker 						 Dwarf *, Dwarf_Addr, void *),
543*7304104dSAndroid Build Coastguard Worker 				void *arg, ptrdiff_t offset);
544*7304104dSAndroid Build Coastguard Worker 
545*7304104dSAndroid Build Coastguard Worker /* Look up the module containing ADDR and return its debugging information,
546*7304104dSAndroid Build Coastguard Worker    loading it if necessary.  */
547*7304104dSAndroid Build Coastguard Worker extern Dwarf *dwfl_addrdwarf (Dwfl *dwfl, Dwarf_Addr addr, Dwarf_Addr *bias)
548*7304104dSAndroid Build Coastguard Worker      __nonnull_attribute__ (3);
549*7304104dSAndroid Build Coastguard Worker 
550*7304104dSAndroid Build Coastguard Worker 
551*7304104dSAndroid Build Coastguard Worker /* Find the CU containing ADDR and return its DIE.  */
552*7304104dSAndroid Build Coastguard Worker extern Dwarf_Die *dwfl_addrdie (Dwfl *dwfl, Dwarf_Addr addr, Dwarf_Addr *bias)
553*7304104dSAndroid Build Coastguard Worker      __nonnull_attribute__ (3);
554*7304104dSAndroid Build Coastguard Worker extern Dwarf_Die *dwfl_module_addrdie (Dwfl_Module *mod,
555*7304104dSAndroid Build Coastguard Worker 				       Dwarf_Addr addr, Dwarf_Addr *bias)
556*7304104dSAndroid Build Coastguard Worker      __nonnull_attribute__ (3);
557*7304104dSAndroid Build Coastguard Worker 
558*7304104dSAndroid Build Coastguard Worker /* Iterate through the CUs, start with null for LASTCU.  */
559*7304104dSAndroid Build Coastguard Worker extern Dwarf_Die *dwfl_nextcu (Dwfl *dwfl, Dwarf_Die *lastcu, Dwarf_Addr *bias)
560*7304104dSAndroid Build Coastguard Worker      __nonnull_attribute__ (3);
561*7304104dSAndroid Build Coastguard Worker extern Dwarf_Die *dwfl_module_nextcu (Dwfl_Module *mod,
562*7304104dSAndroid Build Coastguard Worker 				      Dwarf_Die *lastcu, Dwarf_Addr *bias)
563*7304104dSAndroid Build Coastguard Worker      __nonnull_attribute__ (3);
564*7304104dSAndroid Build Coastguard Worker 
565*7304104dSAndroid Build Coastguard Worker /* Return the module containing the CU DIE.  */
566*7304104dSAndroid Build Coastguard Worker extern Dwfl_Module *dwfl_cumodule (Dwarf_Die *cudie);
567*7304104dSAndroid Build Coastguard Worker 
568*7304104dSAndroid Build Coastguard Worker 
569*7304104dSAndroid Build Coastguard Worker /* Cache the source line information for the CU and return the
570*7304104dSAndroid Build Coastguard Worker    number of Dwfl_Line entries it has.  */
571*7304104dSAndroid Build Coastguard Worker extern int dwfl_getsrclines (Dwarf_Die *cudie, size_t *nlines);
572*7304104dSAndroid Build Coastguard Worker 
573*7304104dSAndroid Build Coastguard Worker /* Access one line number entry within the CU.  */
574*7304104dSAndroid Build Coastguard Worker extern Dwfl_Line *dwfl_onesrcline (Dwarf_Die *cudie, size_t idx);
575*7304104dSAndroid Build Coastguard Worker 
576*7304104dSAndroid Build Coastguard Worker /* Get source for address.  */
577*7304104dSAndroid Build Coastguard Worker extern Dwfl_Line *dwfl_module_getsrc (Dwfl_Module *mod, Dwarf_Addr addr);
578*7304104dSAndroid Build Coastguard Worker extern Dwfl_Line *dwfl_getsrc (Dwfl *dwfl, Dwarf_Addr addr);
579*7304104dSAndroid Build Coastguard Worker 
580*7304104dSAndroid Build Coastguard Worker /* Get address for source.  */
581*7304104dSAndroid Build Coastguard Worker extern int dwfl_module_getsrc_file (Dwfl_Module *mod,
582*7304104dSAndroid Build Coastguard Worker 				    const char *fname, int lineno, int column,
583*7304104dSAndroid Build Coastguard Worker 				    Dwfl_Line ***srcsp, size_t *nsrcs);
584*7304104dSAndroid Build Coastguard Worker 
585*7304104dSAndroid Build Coastguard Worker /* Return the module containing this line record.  */
586*7304104dSAndroid Build Coastguard Worker extern Dwfl_Module *dwfl_linemodule (Dwfl_Line *line);
587*7304104dSAndroid Build Coastguard Worker 
588*7304104dSAndroid Build Coastguard Worker /* Return the CU containing this line record.  */
589*7304104dSAndroid Build Coastguard Worker extern Dwarf_Die *dwfl_linecu (Dwfl_Line *line);
590*7304104dSAndroid Build Coastguard Worker 
591*7304104dSAndroid Build Coastguard Worker /* Return the source file name and fill in other information.
592*7304104dSAndroid Build Coastguard Worker    Arguments may be null for unneeded fields.  */
593*7304104dSAndroid Build Coastguard Worker extern const char *dwfl_lineinfo (Dwfl_Line *line, Dwarf_Addr *addr,
594*7304104dSAndroid Build Coastguard Worker 				  int *linep, int *colp,
595*7304104dSAndroid Build Coastguard Worker 				  Dwarf_Word *mtime, Dwarf_Word *length);
596*7304104dSAndroid Build Coastguard Worker 
597*7304104dSAndroid Build Coastguard Worker   /* Return the equivalent Dwarf_Line and the bias to apply to its address.  */
598*7304104dSAndroid Build Coastguard Worker extern Dwarf_Line *dwfl_dwarf_line (Dwfl_Line *line, Dwarf_Addr *bias);
599*7304104dSAndroid Build Coastguard Worker 
600*7304104dSAndroid Build Coastguard Worker /* Return the compilation directory (AT_comp_dir) from this line's CU.  */
601*7304104dSAndroid Build Coastguard Worker extern const char *dwfl_line_comp_dir (Dwfl_Line *line);
602*7304104dSAndroid Build Coastguard Worker 
603*7304104dSAndroid Build Coastguard Worker 
604*7304104dSAndroid Build Coastguard Worker /*** Machine backend access functions ***/
605*7304104dSAndroid Build Coastguard Worker 
606*7304104dSAndroid Build Coastguard Worker /* Return location expression to find return value given a
607*7304104dSAndroid Build Coastguard Worker    DW_TAG_subprogram, DW_TAG_subroutine_type, or similar DIE describing
608*7304104dSAndroid Build Coastguard Worker    function itself (whose DW_AT_type attribute describes its return type).
609*7304104dSAndroid Build Coastguard Worker    The given DIE must come from the given module.  Returns -1 for errors.
610*7304104dSAndroid Build Coastguard Worker    Returns zero if the function has no return value (e.g. "void" in C).
611*7304104dSAndroid Build Coastguard Worker    Otherwise, *LOCOPS gets a location expression to find the return value,
612*7304104dSAndroid Build Coastguard Worker    and returns the number of operations in the expression.  The pointer is
613*7304104dSAndroid Build Coastguard Worker    permanently allocated at least as long as the module is live.  */
614*7304104dSAndroid Build Coastguard Worker extern int dwfl_module_return_value_location (Dwfl_Module *mod,
615*7304104dSAndroid Build Coastguard Worker 					      Dwarf_Die *functypedie,
616*7304104dSAndroid Build Coastguard Worker 					      const Dwarf_Op **locops);
617*7304104dSAndroid Build Coastguard Worker 
618*7304104dSAndroid Build Coastguard Worker /* Enumerate the DWARF register numbers and their names.
619*7304104dSAndroid Build Coastguard Worker    For each register, CALLBACK gets its DWARF number, a string describing
620*7304104dSAndroid Build Coastguard Worker    the register set (such as "integer" or "FPU"), a prefix used in
621*7304104dSAndroid Build Coastguard Worker    assembler syntax (such as "%" or "$", may be ""), and the name for the
622*7304104dSAndroid Build Coastguard Worker    register (contains identifier characters only, possibly all digits).
623*7304104dSAndroid Build Coastguard Worker    The REGNAME string is valid only during the callback. */
624*7304104dSAndroid Build Coastguard Worker extern int dwfl_module_register_names (Dwfl_Module *mod,
625*7304104dSAndroid Build Coastguard Worker 				       int (*callback) (void *arg,
626*7304104dSAndroid Build Coastguard Worker 							int regno,
627*7304104dSAndroid Build Coastguard Worker 							const char *setname,
628*7304104dSAndroid Build Coastguard Worker 							const char *prefix,
629*7304104dSAndroid Build Coastguard Worker 							const char *regname,
630*7304104dSAndroid Build Coastguard Worker 							int bits, int type),
631*7304104dSAndroid Build Coastguard Worker 				       void *arg);
632*7304104dSAndroid Build Coastguard Worker 
633*7304104dSAndroid Build Coastguard Worker 
634*7304104dSAndroid Build Coastguard Worker /* Find the CFI for this module.  Returns NULL if there is no CFI.
635*7304104dSAndroid Build Coastguard Worker    On success, fills in *BIAS with the difference between addresses
636*7304104dSAndroid Build Coastguard Worker    within the loaded module and those in the CFI referring to it.
637*7304104dSAndroid Build Coastguard Worker    The pointer returned can be used until the module is cleaned up.
638*7304104dSAndroid Build Coastguard Worker    Calling these more than once returns the same pointers.
639*7304104dSAndroid Build Coastguard Worker 
640*7304104dSAndroid Build Coastguard Worker    dwfl_module_dwarf_cfi gets the '.debug_frame' information found with the
641*7304104dSAndroid Build Coastguard Worker    rest of the DWARF information.  dwfl_module_eh_cfi gets the '.eh_frame'
642*7304104dSAndroid Build Coastguard Worker    information found linked into the text.  A module might have either or
643*7304104dSAndroid Build Coastguard Worker    both.  */
644*7304104dSAndroid Build Coastguard Worker extern Dwarf_CFI *dwfl_module_dwarf_cfi (Dwfl_Module *mod, Dwarf_Addr *bias);
645*7304104dSAndroid Build Coastguard Worker extern Dwarf_CFI *dwfl_module_eh_cfi (Dwfl_Module *mod, Dwarf_Addr *bias);
646*7304104dSAndroid Build Coastguard Worker 
647*7304104dSAndroid Build Coastguard Worker 
648*7304104dSAndroid Build Coastguard Worker typedef struct
649*7304104dSAndroid Build Coastguard Worker {
650*7304104dSAndroid Build Coastguard Worker   /* Called to iterate through threads.  Returns next TID (thread ID) on
651*7304104dSAndroid Build Coastguard Worker      success, a negative number on failure and zero if there are no more
652*7304104dSAndroid Build Coastguard Worker      threads.  dwfl_errno () should be set if negative number has been
653*7304104dSAndroid Build Coastguard Worker      returned.  *THREAD_ARGP is NULL on first call, and may be optionally
654*7304104dSAndroid Build Coastguard Worker      set by the implementation. The value set by the implementation will
655*7304104dSAndroid Build Coastguard Worker      be passed in on the next call to NEXT_THREAD.  THREAD_ARGP is never
656*7304104dSAndroid Build Coastguard Worker      NULL.  *THREAD_ARGP will be passed to set_initial_registers or
657*7304104dSAndroid Build Coastguard Worker      thread_detach callbacks together with Dwfl_Thread *thread.  This
658*7304104dSAndroid Build Coastguard Worker      method must not be NULL.  */
659*7304104dSAndroid Build Coastguard Worker   pid_t (*next_thread) (Dwfl *dwfl, void *dwfl_arg, void **thread_argp)
660*7304104dSAndroid Build Coastguard Worker     __nonnull_attribute__ (1);
661*7304104dSAndroid Build Coastguard Worker 
662*7304104dSAndroid Build Coastguard Worker   /* Called to get a specific thread.  Returns true if there is a
663*7304104dSAndroid Build Coastguard Worker      thread with the given thread id number, returns false if no such
664*7304104dSAndroid Build Coastguard Worker      thread exists and will set dwfl_errno in that case.  THREAD_ARGP
665*7304104dSAndroid Build Coastguard Worker      is never NULL.  *THREAD_ARGP will be passed to
666*7304104dSAndroid Build Coastguard Worker      set_initial_registers or thread_detach callbacks together with
667*7304104dSAndroid Build Coastguard Worker      Dwfl_Thread *thread.  This method may be NULL and will then be
668*7304104dSAndroid Build Coastguard Worker      emulated using the next_thread callback. */
669*7304104dSAndroid Build Coastguard Worker   bool (*get_thread) (Dwfl *dwfl, pid_t tid, void *dwfl_arg,
670*7304104dSAndroid Build Coastguard Worker 		      void **thread_argp)
671*7304104dSAndroid Build Coastguard Worker     __nonnull_attribute__ (1);
672*7304104dSAndroid Build Coastguard Worker 
673*7304104dSAndroid Build Coastguard Worker   /* Called during unwinding to access memory (stack) state.  Returns true for
674*7304104dSAndroid Build Coastguard Worker      successfully read *RESULT or false and sets dwfl_errno () on failure.
675*7304104dSAndroid Build Coastguard Worker      This method may be NULL - in such case dwfl_thread_getframes will return
676*7304104dSAndroid Build Coastguard Worker      only the initial frame.  */
677*7304104dSAndroid Build Coastguard Worker   bool (*memory_read) (Dwfl *dwfl, Dwarf_Addr addr, Dwarf_Word *result,
678*7304104dSAndroid Build Coastguard Worker                        void *dwfl_arg)
679*7304104dSAndroid Build Coastguard Worker     __nonnull_attribute__ (1, 3);
680*7304104dSAndroid Build Coastguard Worker 
681*7304104dSAndroid Build Coastguard Worker   /* Called on initial unwind to get the initial register state of the first
682*7304104dSAndroid Build Coastguard Worker      frame.  Should call dwfl_thread_state_registers, possibly multiple times
683*7304104dSAndroid Build Coastguard Worker      for different ranges and possibly also dwfl_thread_state_register_pc, to
684*7304104dSAndroid Build Coastguard Worker      fill in initial (DWARF) register values.  After this call, till at least
685*7304104dSAndroid Build Coastguard Worker      thread_detach is called, the thread is assumed to be frozen, so that it is
686*7304104dSAndroid Build Coastguard Worker      safe to unwind.  Returns true on success or false and sets dwfl_errno ()
687*7304104dSAndroid Build Coastguard Worker      on failure.  In the case of a failure thread_detach will not be called.
688*7304104dSAndroid Build Coastguard Worker      This method must not be NULL.  */
689*7304104dSAndroid Build Coastguard Worker   bool (*set_initial_registers) (Dwfl_Thread *thread, void *thread_arg)
690*7304104dSAndroid Build Coastguard Worker     __nonnull_attribute__ (1);
691*7304104dSAndroid Build Coastguard Worker 
692*7304104dSAndroid Build Coastguard Worker   /* Called by dwfl_end.  All thread_detach method calls have been already
693*7304104dSAndroid Build Coastguard Worker      done.  This method may be NULL.  */
694*7304104dSAndroid Build Coastguard Worker   void (*detach) (Dwfl *dwfl, void *dwfl_arg)
695*7304104dSAndroid Build Coastguard Worker     __nonnull_attribute__ (1);
696*7304104dSAndroid Build Coastguard Worker 
697*7304104dSAndroid Build Coastguard Worker   /* Called when unwinding is done.  No callback will be called after
698*7304104dSAndroid Build Coastguard Worker      this method has been called.  Iff set_initial_registers was called for
699*7304104dSAndroid Build Coastguard Worker      a TID and it returned success thread_detach will be called before the
700*7304104dSAndroid Build Coastguard Worker      detach method above.  This method may be NULL.  */
701*7304104dSAndroid Build Coastguard Worker   void (*thread_detach) (Dwfl_Thread *thread, void *thread_arg)
702*7304104dSAndroid Build Coastguard Worker     __nonnull_attribute__ (1);
703*7304104dSAndroid Build Coastguard Worker } Dwfl_Thread_Callbacks;
704*7304104dSAndroid Build Coastguard Worker 
705*7304104dSAndroid Build Coastguard Worker /* PID is the process id associated with the DWFL state.  Architecture of DWFL
706*7304104dSAndroid Build Coastguard Worker    modules is specified by ELF, ELF must remain valid during DWFL lifetime.
707*7304104dSAndroid Build Coastguard Worker    Use NULL ELF to detect architecture from DWFL, the function will then detect
708*7304104dSAndroid Build Coastguard Worker    it from arbitrary Dwfl_Module of DWFL.  DWFL_ARG is the callback backend
709*7304104dSAndroid Build Coastguard Worker    state.  DWFL_ARG will be provided to the callbacks.  *THREAD_CALLBACKS
710*7304104dSAndroid Build Coastguard Worker    function pointers must remain valid during lifetime of DWFL.  Function
711*7304104dSAndroid Build Coastguard Worker    returns true on success, false otherwise.  */
712*7304104dSAndroid Build Coastguard Worker bool dwfl_attach_state (Dwfl *dwfl, Elf *elf, pid_t pid,
713*7304104dSAndroid Build Coastguard Worker                         const Dwfl_Thread_Callbacks *thread_callbacks,
714*7304104dSAndroid Build Coastguard Worker 			void *dwfl_arg)
715*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1, 4);
716*7304104dSAndroid Build Coastguard Worker 
717*7304104dSAndroid Build Coastguard Worker /* Calls dwfl_attach_state with Dwfl_Thread_Callbacks setup for extracting
718*7304104dSAndroid Build Coastguard Worker    thread state from the ELF core file.  Returns the pid number extracted
719*7304104dSAndroid Build Coastguard Worker    from the core file, or -1 for errors.  */
720*7304104dSAndroid Build Coastguard Worker extern int dwfl_core_file_attach (Dwfl *dwfl, Elf *elf);
721*7304104dSAndroid Build Coastguard Worker 
722*7304104dSAndroid Build Coastguard Worker /* Calls dwfl_attach_state with Dwfl_Thread_Callbacks setup for extracting
723*7304104dSAndroid Build Coastguard Worker    thread state from the proc file system.  Uses ptrace to attach and stop
724*7304104dSAndroid Build Coastguard Worker    the thread under inspection and detaches when thread_detach is called
725*7304104dSAndroid Build Coastguard Worker    and unwinding for the thread is done, unless ASSUME_PTRACE_STOPPED is
726*7304104dSAndroid Build Coastguard Worker    true.  If ASSUME_PTRACE_STOPPED is true the caller should make sure that
727*7304104dSAndroid Build Coastguard Worker    the thread is ptrace attached and stopped before unwinding by calling
728*7304104dSAndroid Build Coastguard Worker    either dwfl_thread_getframes or dwfl_getthread_frames.  Returns zero on
729*7304104dSAndroid Build Coastguard Worker    success, -1 if dwfl_attach_state failed, or an errno code if opening the
730*7304104dSAndroid Build Coastguard Worker    proc files failed.  */
731*7304104dSAndroid Build Coastguard Worker extern int dwfl_linux_proc_attach (Dwfl *dwfl, pid_t pid,
732*7304104dSAndroid Build Coastguard Worker 				   bool assume_ptrace_stopped);
733*7304104dSAndroid Build Coastguard Worker 
734*7304104dSAndroid Build Coastguard Worker /* Return PID for the process associated with DWFL.  Function returns -1 if
735*7304104dSAndroid Build Coastguard Worker    dwfl_attach_state was not called for DWFL.  */
736*7304104dSAndroid Build Coastguard Worker pid_t dwfl_pid (Dwfl *dwfl)
737*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1);
738*7304104dSAndroid Build Coastguard Worker 
739*7304104dSAndroid Build Coastguard Worker /* Return DWFL from which THREAD was created using dwfl_getthreads.  */
740*7304104dSAndroid Build Coastguard Worker Dwfl *dwfl_thread_dwfl (Dwfl_Thread *thread)
741*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1);
742*7304104dSAndroid Build Coastguard Worker 
743*7304104dSAndroid Build Coastguard Worker /* Return positive TID (thread ID) for THREAD.  This function never fails.  */
744*7304104dSAndroid Build Coastguard Worker pid_t dwfl_thread_tid (Dwfl_Thread *thread)
745*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1);
746*7304104dSAndroid Build Coastguard Worker 
747*7304104dSAndroid Build Coastguard Worker /* Return thread for frame STATE.  This function never fails.  */
748*7304104dSAndroid Build Coastguard Worker Dwfl_Thread *dwfl_frame_thread (Dwfl_Frame *state)
749*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1);
750*7304104dSAndroid Build Coastguard Worker 
751*7304104dSAndroid Build Coastguard Worker /* Called by Dwfl_Thread_Callbacks.set_initial_registers implementation.
752*7304104dSAndroid Build Coastguard Worker    For every known continuous block of registers <FIRSTREG..FIRSTREG+NREGS)
753*7304104dSAndroid Build Coastguard Worker    (inclusive..exclusive) set their content to REGS (array of NREGS items).
754*7304104dSAndroid Build Coastguard Worker    Function returns false if any of the registers has invalid number.  */
755*7304104dSAndroid Build Coastguard Worker bool dwfl_thread_state_registers (Dwfl_Thread *thread, int firstreg,
756*7304104dSAndroid Build Coastguard Worker                                   unsigned nregs, const Dwarf_Word *regs)
757*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1, 4);
758*7304104dSAndroid Build Coastguard Worker 
759*7304104dSAndroid Build Coastguard Worker /* Called by Dwfl_Thread_Callbacks.set_initial_registers implementation.
760*7304104dSAndroid Build Coastguard Worker    If PC is not contained among DWARF registers passed by
761*7304104dSAndroid Build Coastguard Worker    dwfl_thread_state_registers on the target architecture pass the PC value
762*7304104dSAndroid Build Coastguard Worker    here.  */
763*7304104dSAndroid Build Coastguard Worker void dwfl_thread_state_register_pc (Dwfl_Thread *thread, Dwarf_Word pc)
764*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1);
765*7304104dSAndroid Build Coastguard Worker 
766*7304104dSAndroid Build Coastguard Worker /* Iterate through the threads for a process.  Returns zero if all threads have
767*7304104dSAndroid Build Coastguard Worker    been processed by the callback, returns -1 on error, or the value of the
768*7304104dSAndroid Build Coastguard Worker    callback when not DWARF_CB_OK.  -1 returned on error will set dwfl_errno ().
769*7304104dSAndroid Build Coastguard Worker    Keeps calling the callback with the next thread while the callback returns
770*7304104dSAndroid Build Coastguard Worker    DWARF_CB_OK, till there are no more threads.  */
771*7304104dSAndroid Build Coastguard Worker int dwfl_getthreads (Dwfl *dwfl,
772*7304104dSAndroid Build Coastguard Worker 		     int (*callback) (Dwfl_Thread *thread, void *arg),
773*7304104dSAndroid Build Coastguard Worker 		     void *arg)
774*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1, 2);
775*7304104dSAndroid Build Coastguard Worker 
776*7304104dSAndroid Build Coastguard Worker /* Iterate through the frames for a thread.  Returns zero if all frames
777*7304104dSAndroid Build Coastguard Worker    have been processed by the callback, returns -1 on error, or the value of
778*7304104dSAndroid Build Coastguard Worker    the callback when not DWARF_CB_OK.  -1 returned on error will
779*7304104dSAndroid Build Coastguard Worker    set dwfl_errno ().  Some systems return error instead of zero on end of the
780*7304104dSAndroid Build Coastguard Worker    backtrace, for cross-platform compatibility callers should consider error as
781*7304104dSAndroid Build Coastguard Worker    a zero.  Keeps calling the callback with the next frame while the callback
782*7304104dSAndroid Build Coastguard Worker    returns DWARF_CB_OK, till there are no more frames.  On start will call the
783*7304104dSAndroid Build Coastguard Worker    set_initial_registers callback and on return will call the detach_thread
784*7304104dSAndroid Build Coastguard Worker    callback of the Dwfl_Thread.  */
785*7304104dSAndroid Build Coastguard Worker int dwfl_thread_getframes (Dwfl_Thread *thread,
786*7304104dSAndroid Build Coastguard Worker 			   int (*callback) (Dwfl_Frame *state, void *arg),
787*7304104dSAndroid Build Coastguard Worker 			   void *arg)
788*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1, 2);
789*7304104dSAndroid Build Coastguard Worker 
790*7304104dSAndroid Build Coastguard Worker /* Like dwfl_thread_getframes, but specifying the thread by its unique
791*7304104dSAndroid Build Coastguard Worker    identifier number.  Returns zero if all frames have been processed
792*7304104dSAndroid Build Coastguard Worker    by the callback, returns -1 on error (and when no thread with
793*7304104dSAndroid Build Coastguard Worker    the given thread id number exists), or the value of the callback
794*7304104dSAndroid Build Coastguard Worker    when not DWARF_CB_OK.  -1 returned on error will set dwfl_errno ().  */
795*7304104dSAndroid Build Coastguard Worker int dwfl_getthread_frames (Dwfl *dwfl, pid_t tid,
796*7304104dSAndroid Build Coastguard Worker 			   int (*callback) (Dwfl_Frame *thread, void *arg),
797*7304104dSAndroid Build Coastguard Worker 			   void *arg)
798*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1, 3);
799*7304104dSAndroid Build Coastguard Worker 
800*7304104dSAndroid Build Coastguard Worker /* Return *PC (program counter) for thread-specific frame STATE.
801*7304104dSAndroid Build Coastguard Worker    Set *ISACTIVATION according to DWARF frame "activation" definition.
802*7304104dSAndroid Build Coastguard Worker    Typically you need to subtract 1 from *PC if *ACTIVATION is false to safely
803*7304104dSAndroid Build Coastguard Worker    find function of the caller.  ACTIVATION may be NULL.  PC must not be NULL.
804*7304104dSAndroid Build Coastguard Worker    Function returns false if it failed to find *PC.  */
805*7304104dSAndroid Build Coastguard Worker bool dwfl_frame_pc (Dwfl_Frame *state, Dwarf_Addr *pc, bool *isactivation)
806*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1, 2);
807*7304104dSAndroid Build Coastguard Worker 
808*7304104dSAndroid Build Coastguard Worker /* Get the value of the DWARF register number in the given frame.
809*7304104dSAndroid Build Coastguard Worker    Returns zero on success, -1 on error (invalid DWARF register
810*7304104dSAndroid Build Coastguard Worker    number) or 1 if the value of the register in the frame is unknown.  */
811*7304104dSAndroid Build Coastguard Worker int dwfl_frame_reg (Dwfl_Frame *state, unsigned regno, Dwarf_Word *val)
812*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1);
813*7304104dSAndroid Build Coastguard Worker 
814*7304104dSAndroid Build Coastguard Worker /* Return the internal debuginfod-client connection handle for the DWFL session.
815*7304104dSAndroid Build Coastguard Worker    When the client connection has not yet been initialized, it will be done on the
816*7304104dSAndroid Build Coastguard Worker    first call to this function. If elfutils is compiled without support for debuginfod,
817*7304104dSAndroid Build Coastguard Worker    NULL will be returned.
818*7304104dSAndroid Build Coastguard Worker  */
819*7304104dSAndroid Build Coastguard Worker extern debuginfod_client *dwfl_get_debuginfod_client (Dwfl *dwfl);
820*7304104dSAndroid Build Coastguard Worker 
821*7304104dSAndroid Build Coastguard Worker #ifdef __cplusplus
822*7304104dSAndroid Build Coastguard Worker }
823*7304104dSAndroid Build Coastguard Worker #endif
824*7304104dSAndroid Build Coastguard Worker 
825*7304104dSAndroid Build Coastguard Worker #endif	/* libdwfl.h */
826