1 /* Internal definitions for libdwfl.
2 Copyright (C) 2005, 2006 Red Hat, Inc.
3 This file is part of Red Hat elfutils.
5 Red Hat elfutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by the
7 Free Software Foundation; version 2 of the License.
9 Red Hat elfutils is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with Red Hat elfutils; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
18 In addition, as a special exception, Red Hat, Inc. gives You the
19 additional right to link the code of Red Hat elfutils with code licensed
20 under any Open Source Initiative certified open source license
21 (http://www.opensource.org/licenses/index.php) which requires the
22 distribution of source code with any binary distribution and to
23 distribute linked combinations of the two. Non-GPL Code permitted under
24 this exception must only link to the code of Red Hat elfutils through
25 those well defined interfaces identified in the file named EXCEPTION
26 found in the source code files (the "Approved Interfaces"). The files
27 of Non-GPL Code may instantiate templates or use macros or inline
28 functions from the Approved Interfaces without causing the resulting
29 work to be covered by the GNU General Public License. Only Red Hat,
30 Inc. may make changes or additions to the list of Approved Interfaces.
31 Red Hat's grant of this exception is conditioned upon your not adding
32 any new exceptions. If you wish to add a new Approved Interface or
33 exception, please contact Red Hat. You must obey the GNU General Public
34 License in all respects for all of the Red Hat elfutils code and other
35 code used in conjunction with Red Hat elfutils except the Non-GPL Code
36 covered by this exception. If you modify this file, you may extend this
37 exception to your version of the file, but you are not obligated to do
38 so. If you do not wish to provide this exception without modification,
39 you must delete this exception statement from your version and license
40 this file solely under the GPL without exception.
42 Red Hat elfutils is an included package of the Open Invention Network.
43 An included package of the Open Invention Network is a package for which
44 Open Invention Network licensees cross-license their patents. No patent
45 license is granted, either expressly or impliedly, by designation as an
46 included package. Should you wish to participate in the Open Invention
47 Network licensing program, please visit www.openinventionnetwork.com
48 <http://www.openinventionnetwork.com>. */
64 #include "../libdw/libdwP.h" /* We need its INTDECLs. */
66 /* gettext helper macros. */
67 #define _(Str) dgettext ("elfutils", Str)
70 DWFL_ERROR (NOERROR, N_("no error")) \
71 DWFL_ERROR (UNKNOWN_ERROR, N_("unknown error")) \
72 DWFL_ERROR (NOMEM, N_("out of memory")) \
73 DWFL_ERROR (ERRNO, N_("See errno")) \
74 DWFL_ERROR (LIBELF, N_("See elf_errno")) \
75 DWFL_ERROR (LIBDW, N_("See dwarf_errno")) \
76 DWFL_ERROR (LIBEBL, N_("See ebl_errno (XXX missing)")) \
77 DWFL_ERROR (UNKNOWN_MACHINE, N_("no support library found for machine")) \
78 DWFL_ERROR (NOREL, N_("Callbacks missing for ET_REL file")) \
79 DWFL_ERROR (BADRELTYPE, N_("Unsupported relocation type")) \
80 DWFL_ERROR (BADRELOFF, N_("r_offset is bogus")) \
81 DWFL_ERROR (BADSTROFF, N_("offset out of range")) \
82 DWFL_ERROR (RELUNDEF, N_("relocation refers to undefined symbol")) \
83 DWFL_ERROR (CB, N_("Callback returned failure")) \
84 DWFL_ERROR (NO_DWARF, N_("No DWARF information found")) \
85 DWFL_ERROR (NO_SYMTAB, N_("No symbol table found")) \
86 DWFL_ERROR (NO_PHDR, N_("No ELF program headers")) \
87 DWFL_ERROR (OVERLAP, N_("address range overlaps an existing module")) \
88 DWFL_ERROR (ADDR_OUTOFRANGE, N_("address out of range")) \
89 DWFL_ERROR (NO_MATCH, N_("no matching address range")) \
90 DWFL_ERROR (TRUNCATED, N_("image truncated")) \
91 DWFL_ERROR (BADELF, N_("not a valid ELF file")) \
92 DWFL_ERROR (WEIRD_TYPE, N_("cannot handle DWARF type description"))
94 #define DWFL_ERROR(name, text) DWFL_E_##name,
95 typedef enum { DWFL_ERRORS DWFL_E_NUM } Dwfl_Error;
98 #define OTHER_ERROR(name) ((unsigned int) DWFL_E_##name << 16)
99 #define DWFL_E(name, errno) (OTHER_ERROR (name) | (errno))
101 extern int __libdwfl_canon_error (Dwfl_Error error) internal_function;
102 extern void __libdwfl_seterrno (Dwfl_Error error) internal_function;
106 const Dwfl_Callbacks *callbacks;
108 Dwfl_Module *modulelist; /* List in order used by full traversals. */
110 Dwfl_Module **modules;
113 GElf_Addr offline_next_address;
116 #define OFFLINE_REDZONE 0x10000
124 GElf_Addr bias; /* Actual load address - p_vaddr. */
130 struct Dwfl_Module *next; /* Link on Dwfl.modulelist. */
134 char *name; /* Iterator name for this module. */
135 GElf_Addr low_addr, high_addr;
137 struct dwfl_file main, debug;
139 GElf_Half e_type; /* GElf_Ehdr.e_type cache. */
140 Dwfl_Error elferr; /* Previous failure to open main file. */
142 struct dwfl_relocation *reloc_info; /* Relocatable sections. */
144 struct dwfl_file *symfile; /* Either main or debug. */
145 Elf_Data *symdata; /* Data in the ELF symbol table section. */
146 size_t syments; /* sh_size / sh_entsize of that section. */
147 Elf_Data *symstrdata; /* Data for its string table. */
148 Elf_Data *symxndxdata; /* Data in the extended section index table. */
149 Dwfl_Error symerr; /* Previous failure to load symbols. */
151 Dwarf *dw; /* libdw handle for its debugging info. */
152 Dwfl_Error dwerr; /* Previous failure to load info. */
154 /* Known CU's in this module. */
155 struct dwfl_cu *first_cu, **cu;
158 void *lazy_cu_root; /* Table indexed by Dwarf_Off of CU. */
159 unsigned int lazycu; /* Possible users, deleted when none left. */
161 struct dwfl_arange *aranges; /* Mapping of addresses in module to CUs. */
162 unsigned int naranges;
164 bool gc; /* Mark/sweep flag. */
169 /* Information cached about each CU in Dwfl_Module.dw. */
172 /* This caches libdw information about the CU. It's also the
173 address passed back to users, so we take advantage of the
174 fact that it's placed first to cast back. */
177 Dwfl_Module *mod; /* Pointer back to containing module. */
179 struct dwfl_cu *next; /* CU immediately following in the file. */
181 struct Dwfl_Lines *lines;
188 /* This is what the opaque Dwfl_Line * pointers we pass to users are.
189 We need to recover pointers to our struct dwfl_cu and a record in
190 libdw's Dwarf_Line table. To minimize the memory used in addition
191 to libdw's Dwarf_Lines buffer, we just point to our own index in
192 this table, and have one pointer back to the CU. The indices here
193 match those in libdw's Dwarf_CU.lines->info table. */
196 unsigned int idx; /* My index in the dwfl_cu.lines table. */
200 static inline struct dwfl_cu *
201 dwfl_linecu_inline (const Dwfl_Line *line)
203 const struct Dwfl_Lines *lines = ((const void *) line
204 - offsetof (struct Dwfl_Lines,
208 #define dwfl_linecu dwfl_linecu_inline
210 /* This describes a contiguous address range that lies in a single CU.
211 We condense runs of Dwarf_Arange entries for the same CU into this. */
215 size_t arange; /* Index in Dwarf_Aranges. */
220 extern void __libdwfl_module_free (Dwfl_Module *mod) internal_function;
223 /* Process relocations in debugging sections in an ET_REL file.
224 DEBUGFILE must be opened with ELF_C_READ_MMAP_PRIVATE or ELF_C_READ,
225 to make it possible to relocate the data in place (or ELF_C_RDWR or
226 ELF_C_RDWR_MMAP if you intend to modify the Elf file on disk). After
227 this, dwarf_begin_elf on DEBUGFILE will read the relocated data. */
228 extern Dwfl_Error __libdwfl_relocate (Dwfl_Module *mod, Elf *debugfile)
231 /* Adjust *VALUE from section-relative to absolute.
232 MOD->dwfl->callbacks->section_address is called to determine the actual
233 address of a loaded section. */
234 extern Dwfl_Error __libdwfl_relocate_value (Dwfl_Module *mod,
241 /* Ensure that MOD->ebl is set up. */
242 extern Dwfl_Error __libdwfl_module_getebl (Dwfl_Module *mod) internal_function;
244 /* Iterate through all the CU's in the module. Start by passing a null
245 LASTCU, and then pass the last *CU returned. Success return with null
247 extern Dwfl_Error __libdwfl_nextcu (Dwfl_Module *mod, struct dwfl_cu *lastcu,
248 struct dwfl_cu **cu) internal_function;
250 /* Find the CU by address. */
251 extern Dwfl_Error __libdwfl_addrcu (Dwfl_Module *mod, Dwarf_Addr addr,
252 struct dwfl_cu **cu) internal_function;
254 /* Ensure that CU->lines (and CU->cu->lines) is set up. */
255 extern Dwfl_Error __libdwfl_cu_getsrclines (struct dwfl_cu *cu)
259 extern uint32_t __libdwfl_crc32 (uint32_t crc, unsigned char *buf, size_t len)
261 extern int __libdwfl_crc32_file (int fd, uint32_t *resp) attribute_hidden;
265 /* Avoid PLT entries. */
267 INTDECL (dwfl_errmsg)
268 INTDECL (dwfl_addrmodule)
269 INTDECL (dwfl_addrdwarf)
270 INTDECL (dwfl_addrdie)
271 INTDECL (dwfl_module_addrdie)
272 INTDECL (dwfl_module_getdwarf)
273 INTDECL (dwfl_module_getelf)
274 INTDECL (dwfl_module_getsym)
275 INTDECL (dwfl_module_getsymtab)
276 INTDECL (dwfl_module_getsrc)
277 INTDECL (dwfl_report_elf)
278 INTDECL (dwfl_report_begin)
279 INTDECL (dwfl_report_module)
280 INTDECL (dwfl_report_offline)
281 INTDECL (dwfl_report_end)
282 INTDECL (dwfl_standard_find_debuginfo)
283 INTDECL (dwfl_linux_kernel_find_elf)
284 INTDECL (dwfl_linux_kernel_module_section_address)
285 INTDECL (dwfl_linux_proc_report)
286 INTDECL (dwfl_linux_proc_maps_report)
287 INTDECL (dwfl_linux_proc_find_elf)
288 INTDECL (dwfl_linux_kernel_report_kernel)
289 INTDECL (dwfl_linux_kernel_report_modules)
290 INTDECL (dwfl_linux_kernel_report_offline)
291 INTDECL (dwfl_offline_section_address)
292 INTDECL (dwfl_module_relocate_address)
294 /* Leading arguments standard to callbacks passed a Dwfl_Module. */
295 #define MODCB_ARGS(mod) (mod), &(mod)->userdata, (mod)->name, (mod)->low_addr
296 #define CBFAIL (errno ? DWFL_E (ERRNO, errno) : DWFL_E_CB);
299 /* The default used by dwfl_standard_find_debuginfo. */
300 #define DEFAULT_DEBUGINFO_PATH ":.debug:/usr/lib/debug"
303 #endif /* libdwflP.h */