blob: 062b3dce7df66539cf260a70ebeea1b2533cce7b [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* Internal definitions for libdwarf.
2 Copyright (C) 2002, 2003, 2004, 2005 Red Hat, Inc.
3 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
4
5 This program is Open Source software; you can redistribute it and/or
6 modify it under the terms of the Open Software License version 1.0 as
7 published by the Open Source Initiative.
8
9 You should have received a copy of the Open Software License along
10 with this program; if not, you may obtain a copy of the Open Software
11 License version 1.0 from http://www.opensource.org/licenses/osl.php or
12 by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
13 3001 King Ranch Road, Ukiah, CA 95482. */
14
15#ifndef _LIBDWP_H
16#define _LIBDWP_H 1
17
18#include <libintl.h>
19#include <stdbool.h>
20
21#include <libdw.h>
22
23
24/* gettext helper macros. */
25#define _(Str) dgettext ("elfutils", Str)
26
27
28/* Version of the DWARF specification we support. */
29#define DWARF_VERSION 2
30
31/* Version of the CIE format. */
32#define CIE_VERSION 1
33
34
35/* Known location lists. */
36struct loc_s
37{
38 void *addr;
39 Dwarf_Loc *loc;
40 size_t nloc;
41};
42
43/* Valid indeces for the section data. */
44enum
45 {
46 IDX_debug_info = 0,
47 IDX_debug_abbrev,
48 IDX_debug_aranges,
49 IDX_debug_line,
50 IDX_debug_frame,
51 IDX_eh_frame,
52 IDX_debug_loc,
53 IDX_debug_pubnames,
54 IDX_debug_str,
55 IDX_debug_funcnames,
56 IDX_debug_typenames,
57 IDX_debug_varnames,
58 IDX_debug_weaknames,
59 IDX_debug_macinfo,
60 IDX_debug_ranges,
61 IDX_last
62 };
63
64
65/* Error values. */
66enum
67{
68 DWARF_E_NOERROR = 0,
69 DWARF_E_UNKNOWN_ERROR,
70 DWARF_E_INVALID_ACCESS,
71 DWARF_E_NO_REGFILE,
72 DWARF_E_IO_ERROR,
73 DWARF_E_INVALID_ELF,
74 DWARF_E_NO_DWARF,
75 DWARF_E_NOELF,
76 DWARF_E_GETEHDR_ERROR,
77 DWARF_E_NOMEM,
78 DWARF_E_UNIMPL,
79 DWARF_E_INVALID_CMD,
80 DWARF_E_INVALID_VERSION,
81 DWARF_E_INVALID_FILE,
82 DWARF_E_NO_ENTRY,
83 DWARF_E_INVALID_DWARF,
84 DWARF_E_NO_STRING,
85 DWARF_E_NO_ADDR,
86 DWARF_E_NO_CONSTANT,
87 DWARF_E_NO_REFERENCE,
88 DWARF_E_INVALID_REFERENCE,
89 DWARF_E_NO_DEBUG_LINE,
90 DWARF_E_INVALID_DEBUG_LINE,
91 DWARF_E_TOO_BIG,
92 DWARF_E_VERSION,
93 DWARF_E_INVALID_DIR_IDX,
94 DWARF_E_ADDR_OUTOFRANGE,
95 DWARF_E_NO_LOCLIST,
96 DWARF_E_NO_BLOCK,
97 DWARF_E_INVALID_LINE_IDX,
98 DWARF_E_INVALID_ARANGE_IDX,
99 DWARF_E_NO_MATCH,
100 DWARF_E_NO_FLAG,
101 DWARF_E_INVALID_OFFSET,
102 DWARF_E_NO_DEBUG_RANGES,
103};
104
105
106/* This is the structure representing the debugging state. */
107struct Dwarf
108{
109 /* The underlying ELF file. */
110 Elf *elf;
111
112 /* The section data. */
113 Elf_Data *sectiondata[IDX_last];
114
115 /* True if the file has a byte order different from the host. */
116 bool other_byte_order;
117
118 /* If true, we allocated the ELF descriptor ourselves. */
119 bool free_elf;
120
121 /* Information for traversing the .debug_pubnames section. This is
122 an array and separately allocated with malloc. */
123 struct pubnames_s
124 {
125 Dwarf_Off cu_offset;
126 Dwarf_Off set_start;
127 unsigned int cu_header_size;
128 int address_len;
129 } *pubnames_sets;
130 size_t pubnames_nsets;
131
132 /* Search tree for the CUs. */
133 void *cu_tree;
134 Dwarf_Off next_cu_offset;
135
136 /* Address ranges. */
137 Dwarf_Aranges *aranges;
138
139 /* Internal memory handling. This is basically a simplified
140 reimplementation of obstacks. Unfortunately the standard obstack
141 implementation is not usable in libraries. */
142 struct libdw_memblock
143 {
144 size_t size;
145 size_t remaining;
146 struct libdw_memblock *prev;
147 char mem[0];
148 } *mem_tail;
149
150 /* Default size of allocated memory blocks. */
151 size_t mem_default_size;
152
153 /* Registered OOM handler. */
154 Dwarf_OOM oom_handler;
155};
156
157
158/* Abbreviation representation. */
159struct Dwarf_Abbrev
160{
161 unsigned int code;
162 unsigned int tag;
163 int has_children;
164 unsigned int attrcnt;
165 unsigned char *attrp;
166 Dwarf_Off offset;
167};
168
169#include "dwarf_abbrev_hash.h"
170
171
172/* Files in line information records. */
173struct Dwarf_Files_s
174 {
175 Dwarf *dbg;
176 unsigned int nfiles;
177 struct Dwarf_Fileinfo_s
178 {
179 char *name;
180 Dwarf_Word mtime;
181 Dwarf_Word length;
182 } info[0];
183 };
184typedef struct Dwarf_Fileinfo_s Dwarf_Fileinfo;
185
186
187/* Representation of a row in the line table. */
188struct Dwarf_Lines_s
189 {
190 size_t nlines;
191
192 struct Dwarf_Line_s
193 {
194 Dwarf_Addr addr;
195 unsigned int file;
196 int line;
197 unsigned short int column;
198 unsigned int is_stmt:1;
199 unsigned int basic_block:1;
200 unsigned int end_sequence:1;
201 unsigned int prologue_end:1;
202 unsigned int epilogue_begin:1;
203
204 Dwarf_Files *files;
205 } info[0];
206 };
207
208
209/* Representation of address ranges. */
210struct Dwarf_Aranges_s
211{
212 Dwarf *dbg;
213 size_t naranges;
214
215 struct Dwarf_Arange_s
216 {
217 Dwarf_Addr addr;
218 Dwarf_Word length;
219 Dwarf_Off offset;
220 } info[0];
221};
222
223
224/* CU representation. */
225struct Dwarf_CU
226{
227 Dwarf *dbg;
228 Dwarf_Off start;
229 Dwarf_Off end;
230 uint8_t address_size;
231 uint8_t offset_size;
232
233 /* Hash table for the abbreviations. */
234 Dwarf_Abbrev_Hash abbrev_hash;
235 /* Offset of the first abbreviation. */
236 size_t orig_abbrev_offset;
237 /* Offset past last read abbreviation. */
238 size_t last_abbrev_offset;
239
240 /* The srcline information. */
241 Dwarf_Lines *lines;
242
243 /* The source file information. */
244 Dwarf_Files *files;
245
246 /* Known location lists. */
247 void *locs;
248};
249
250
251/* Function information. */
252struct Dwarf_Func_s
253{
254 // XXX If we want to cache functions, we need to change this struct.
255 Dwarf_Die *die;
256 Dwarf_Die *cudie;
257};
258
259
260/* Macro information. */
261struct Dwarf_Macro_s
262{
263 unsigned int opcode;
264 Dwarf_Word param1;
265 union
266 {
267 Dwarf_Word u;
268 const char *s;
269 } param2;
270};
271
272
273/* We have to include the file at this point because the inline
274 functions access internals of the Dwarf structure. */
275#include "memory-access.h"
276
277
278/* Set error value. */
279extern void __libdw_seterrno (int value) internal_function;
280
281
282/* Memory handling, the easy parts. This macro does not do any locking. */
283#define libdw_alloc(dbg, type, tsize, cnt) \
284 ({ struct libdw_memblock *_tail = (dbg)->mem_tail; \
285 size_t _required = (tsize) * (cnt); \
286 type *_result = (type *) (_tail->mem + (_tail->size - _tail->remaining));\
287 size_t _padding = ((__alignof (type) \
288 - ((uintptr_t) _result & (__alignof (type) - 1))) \
289 & (__alignof (type) - 1)); \
290 if (unlikely (_tail->remaining < _required + _padding)) \
291 { \
292 _result = (type *) __libdw_allocate (dbg, _required); \
293 _tail = (dbg)->mem_tail; \
294 } \
295 else \
296 { \
297 _required += _padding; \
298 _result = (type *) ((char *) _result + _padding); \
299 } \
300 _tail->remaining -= _required; \
301 _result; })
302
303#define libdw_typed_alloc(dbg, type) \
304 libdw_alloc (dbg, type, sizeof (type), 1)
305
306/* Callback to allocate more. */
307extern void *__libdw_allocate (Dwarf *dbg, size_t minsize)
308 __attribute__ ((__malloc__)) __nonnull_attribute__ (1);
309
310/* Default OOM handler. */
311extern void __libdw_oom (void) __attribute ((noreturn, visibility ("hidden")));
312
313/* Find CU for given offset. */
314extern struct Dwarf_CU *__libdw_findcu (Dwarf *dbg, Dwarf_Off offset)
315 __nonnull_attribute__ (1) internal_function;
316
317/* Return tag of given DIE. */
318extern Dwarf_Abbrev *__libdw_findabbrev (struct Dwarf_CU *cu,
319 unsigned int code)
320 __nonnull_attribute__ (1) internal_function;
321
322/* Get abbreviation at given offset. */
323extern Dwarf_Abbrev *__libdw_getabbrev (Dwarf *dbg, struct Dwarf_CU *cu,
324 Dwarf_Off offset, size_t *lengthp,
325 Dwarf_Abbrev *result)
326 __nonnull_attribute__ (1) internal_function;
327
328/* Helper functions for form handling. */
329extern size_t __libdw_form_val_len (Dwarf *dbg, struct Dwarf_CU *cu,
330 unsigned int form,
331 const unsigned char *valp)
332 __nonnull_attribute__ (1, 2, 4) internal_function;
333
334/* Helper function to locate attribute. */
335extern unsigned char *__libdw_find_attr (Dwarf_Die *die,
336 unsigned int search_name,
337 unsigned int *codep,
338 unsigned int *formp)
339 __nonnull_attribute__ (1) internal_function;
340
341/* Helper function to access integer attribute. */
342extern int __libdw_func_intval (Dwarf_Func *func, int *linep, int attval)
343 __nonnull_attribute__ (1, 2) internal_function;
344
345/* Return error code of last failing function call. This value is kept
346 separately for each thread. */
347extern int __dwarf_errno_internal (void);
348
349
350/* Aliases to avoid PLTs. */
351INTDECL (dwarf_attr)
352INTDECL (dwarf_attr_integrate)
353INTDECL (dwarf_begin_elf)
354INTDECL (dwarf_child)
355INTDECL (dwarf_dieoffset)
Roland McGrath4959bf82005-08-09 10:31:08 +0000356INTDECL (dwarf_end)
357INTDECL (dwarf_errmsg)
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000358INTDECL (dwarf_formaddr)
359INTDECL (dwarf_formblock)
360INTDECL (dwarf_formref)
361INTDECL (dwarf_formref_die)
362INTDECL (dwarf_formsdata)
363INTDECL (dwarf_formstring)
364INTDECL (dwarf_formudata)
365INTDECL (dwarf_getarange_addr)
366INTDECL (dwarf_getarangeinfo)
367INTDECL (dwarf_getaranges)
368INTDECL (dwarf_getsrcfiles)
369INTDECL (dwarf_getsrclines)
370INTDECL (dwarf_hasattr)
371INTDECL (dwarf_haschildren)
372INTDECL (dwarf_haspc)
373INTDECL (dwarf_highpc)
374INTDECL (dwarf_lowpc)
375INTDECL (dwarf_nextcu)
376INTDECL (dwarf_offdie)
377INTDECL (dwarf_siblingof)
378INTDECL (dwarf_tag)
379
380#endif /* libdwP.h */