blob: c0baa2193ff6bd4f46d0b7a55fe38eeb3e9706d0 [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* Interfaces for libdw.
Mark Wielaard209f1492014-08-15 13:08:24 +02002 Copyright (C) 2002-2010, 2013, 2014 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02003 This file is part of elfutils.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00004
Mark Wielaardde2ed972012-06-05 17:15:16 +02005 This file is free software; you can redistribute it and/or modify
6 it under the terms of either
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00007
Mark Wielaardde2ed972012-06-05 17:15:16 +02008 * the GNU Lesser General Public License as published by the Free
9 Software Foundation; either version 3 of the License, or (at
10 your option) any later version
11
12 or
13
14 * the GNU General Public License as published by the Free
15 Software Foundation; either version 2 of the License, or (at
16 your option) any later version
17
18 or both in parallel, as here.
19
20 elfutils is distributed in the hope that it will be useful, but
Ulrich Drepper361df7d2006-04-04 21:38:57 +000021 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
24
Mark Wielaardde2ed972012-06-05 17:15:16 +020025 You should have received copies of the GNU General Public License and
26 the GNU Lesser General Public License along with this program. If
27 not, see <http://www.gnu.org/licenses/>. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000028
29#ifndef _LIBDW_H
30#define _LIBDW_H 1
31
32#include <gelf.h>
33#include <stdbool.h>
34#include <stddef.h>
35
36
37#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
38# define __nonnull_attribute__(...) __attribute__ ((__nonnull__ (__VA_ARGS__)))
Roland McGrathe4c22ea2007-10-23 13:07:39 +000039# define __deprecated_attribute__ __attribute__ ((__deprecated__))
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000040#else
41# define __nonnull_attribute__(args...)
Roland McGrathe4c22ea2007-10-23 13:07:39 +000042# define __deprecated_attribute__
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000043#endif
44
Roland McGrathe4c22ea2007-10-23 13:07:39 +000045
Roland McGrath87d47802007-07-16 22:23:37 +000046#ifdef __GNUC_STDC_INLINE__
Ulrich Drepperb597dfa2007-10-16 05:21:27 +000047# define __libdw_extern_inline extern __inline __attribute__ ((__gnu_inline__))
Roland McGrath87d47802007-07-16 22:23:37 +000048#else
Ulrich Drepperb597dfa2007-10-16 05:21:27 +000049# define __libdw_extern_inline extern __inline
Roland McGrath87d47802007-07-16 22:23:37 +000050#endif
51
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000052
53/* Mode for the session. */
54typedef enum
55 {
56 DWARF_C_READ, /* Read .. */
57 DWARF_C_RDWR, /* Read and write .. */
58 DWARF_C_WRITE, /* Write .. */
59 }
60Dwarf_Cmd;
61
62
63/* Callback results. */
64enum
65{
66 DWARF_CB_OK = 0,
67 DWARF_CB_ABORT
68};
69
70
71/* Error values. */
72enum
73 {
74 DW_TAG_invalid = 0
75#define DW_TAG_invalid DW_TAG_invalid
76 };
77
78
79/* Type for offset in DWARF file. */
80typedef GElf_Off Dwarf_Off;
81
82/* Type for address in DWARF file. */
83typedef GElf_Addr Dwarf_Addr;
84
85/* Integer types. Big enough to hold any numeric value. */
86typedef GElf_Xword Dwarf_Word;
87typedef GElf_Sxword Dwarf_Sword;
88/* For the times we know we do not need that much. */
89typedef GElf_Half Dwarf_Half;
90
91
92/* DWARF abbreviation record. */
93typedef struct Dwarf_Abbrev Dwarf_Abbrev;
94
95/* Returned to show the last DIE has be returned. */
96#define DWARF_END_ABBREV ((Dwarf_Abbrev *) -1l)
97
98/* Source code line information for CU. */
99typedef struct Dwarf_Lines_s Dwarf_Lines;
100
101/* One source code line information. */
102typedef struct Dwarf_Line_s Dwarf_Line;
103
104/* Source file information. */
105typedef struct Dwarf_Files_s Dwarf_Files;
106
107/* One address range record. */
108typedef struct Dwarf_Arange_s Dwarf_Arange;
109
110/* Address ranges of a file. */
111typedef struct Dwarf_Aranges_s Dwarf_Aranges;
112
113/* CU representation. */
114struct Dwarf_CU;
Mark Wielaard209f1492014-08-15 13:08:24 +0200115typedef struct Dwarf_CU Dwarf_CU;
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000116
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000117/* Macro information. */
118typedef struct Dwarf_Macro_s Dwarf_Macro;
119
120/* Attribute representation. */
121typedef struct
122{
123 unsigned int code;
124 unsigned int form;
125 unsigned char *valp;
126 struct Dwarf_CU *cu;
127} Dwarf_Attribute;
128
129
130/* Data block representation. */
131typedef struct
132{
133 Dwarf_Word length;
134 unsigned char *data;
135} Dwarf_Block;
136
137
138/* DIE information. */
139typedef struct
140{
141 /* The offset can be computed from the address. */
142 void *addr;
143 struct Dwarf_CU *cu;
144 Dwarf_Abbrev *abbrev;
145 // XXX We'll see what other information will be needed.
146 long int padding__;
147} Dwarf_Die;
148
149/* Returned to show the last DIE has be returned. */
150#define DWARF_END_DIE ((Dwarf_Die *) -1l)
151
152
153/* Global symbol information. */
154typedef struct
155{
156 Dwarf_Off cu_offset;
157 Dwarf_Off die_offset;
158 const char *name;
159} Dwarf_Global;
160
161
Roland McGrath6724c902005-10-28 07:07:19 +0000162/* One operation in a DWARF location expression.
163 A location expression is an array of these. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000164typedef struct
165{
166 uint8_t atom; /* Operation */
167 Dwarf_Word number; /* Operand */
168 Dwarf_Word number2; /* Possible second operand */
169 Dwarf_Word offset; /* Offset in location expression */
Roland McGrath6724c902005-10-28 07:07:19 +0000170} Dwarf_Op;
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000171
172
Roland McGrath3c84db32009-06-24 17:41:40 -0700173/* This describes one Common Information Entry read from a CFI section.
174 Pointers here point into the DATA->d_buf block passed to dwarf_next_cfi. */
175typedef struct
176{
177 Dwarf_Off CIE_id; /* Always DW_CIE_ID_64 in Dwarf_CIE structures. */
178
179 /* Instruction stream describing initial state used by FDEs. If
180 we did not understand the whole augmentation string and it did
181 not use 'z', then there might be more augmentation data here
182 (and in FDEs) before the actual instructions. */
183 const uint8_t *initial_instructions;
184 const uint8_t *initial_instructions_end;
185
186 Dwarf_Word code_alignment_factor;
187 Dwarf_Sword data_alignment_factor;
188 Dwarf_Word return_address_register;
189
190 const char *augmentation; /* Augmentation string. */
191
192 /* Augmentation data, might be NULL. The size is correct only if
193 we understood the augmentation string sufficiently. */
194 const uint8_t *augmentation_data;
195 size_t augmentation_data_size;
196 size_t fde_augmentation_data_size;
197} Dwarf_CIE;
198
199/* This describes one Frame Description Entry read from a CFI section.
200 Pointers here point into the DATA->d_buf block passed to dwarf_next_cfi. */
201typedef struct
202{
203 /* Section offset of CIE this FDE refers to. This will never be
204 DW_CIE_ID_64 in an FDE. If this value is DW_CIE_ID_64, this is
205 actually a Dwarf_CIE structure. */
206 Dwarf_Off CIE_pointer;
207
208 /* We can't really decode anything further without looking up the CIE
209 and checking its augmentation string. Here follows the encoded
210 initial_location and address_range, then any augmentation data,
211 then the instruction stream. This FDE describes PC locations in
212 the byte range [initial_location, initial_location+address_range).
213 When the CIE augmentation string uses 'z', the augmentation data is
214 a DW_FORM_block (self-sized). Otherwise, when we understand the
215 augmentation string completely, fde_augmentation_data_size gives
216 the number of bytes of augmentation data before the instructions. */
217 const uint8_t *start;
218 const uint8_t *end;
219} Dwarf_FDE;
220
221/* Each entry in a CFI section is either a CIE described by Dwarf_CIE or
222 an FDE described by Dward_FDE. Check CIE_id to see which you have. */
223typedef union
224{
225 Dwarf_Off CIE_id; /* Always DW_CIE_ID_64 in Dwarf_CIE structures. */
226 Dwarf_CIE cie;
227 Dwarf_FDE fde;
228} Dwarf_CFI_Entry;
229
Mark Wielaard08e71db2010-05-31 15:39:15 +0200230#define dwarf_cfi_cie_p(entry) ((entry)->cie.CIE_id == DW_CIE_ID_64)
231
Roland McGrath3c84db32009-06-24 17:41:40 -0700232/* Opaque type representing a frame state described by CFI. */
233typedef struct Dwarf_Frame_s Dwarf_Frame;
234
235/* Opaque type representing a CFI section found in a DWARF or ELF file. */
236typedef struct Dwarf_CFI_s Dwarf_CFI;
237
238
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000239/* Handle for debug sessions. */
240typedef struct Dwarf Dwarf;
241
242
243/* Out-Of-Memory handler. */
244#if __GNUC__ < 4
245typedef void (*Dwarf_OOM) (void);
246#else
247typedef void (*__attribute__ ((noreturn)) Dwarf_OOM) (void);
248#endif
249
250
Ulrich Drepper3be74472006-05-27 18:15:40 +0000251#ifdef __cplusplus
252extern "C" {
253#endif
254
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000255/* Create a handle for a new debug session. */
256extern Dwarf *dwarf_begin (int fildes, Dwarf_Cmd cmd);
257
258/* Create a handle for a new debug session for an ELF file. */
259extern Dwarf *dwarf_begin_elf (Elf *elf, Dwarf_Cmd cmd, Elf_Scn *scngrp);
260
261/* Retrieve ELF descriptor used for DWARF access. */
262extern Elf *dwarf_getelf (Dwarf *dwarf);
263
Mark Wielaard209f1492014-08-15 13:08:24 +0200264/* Retieve DWARF descriptor used for a Dwarf_Die or Dwarf_Attribute.
265 A Dwarf_Die or a Dwarf_Attribute is associated with a particular
266 Dwarf_CU handle. This function returns the DWARF descriptor for
267 that Dwarf_CU. */
268extern Dwarf *dwarf_cu_getdwarf (Dwarf_CU *cu);
269
Florian Weimer35e2a762014-04-15 14:31:55 +0200270/* Retrieves the DWARF descriptor for debugaltlink data. Returns NULL
271 if no alternate debug data has been supplied. */
272extern Dwarf *dwarf_getalt (Dwarf *main);
273
274/* Provides the data referenced by the .gnu_debugaltlink section. The
275 caller should check that MAIN and ALT match (i.e., they have the
276 same build ID). It is the responsibility of the caller to ensure
277 that the data referenced by ALT stays valid while it is used by
278 MAIN, until dwarf_setalt is called on MAIN with a different
279 descriptor, or dwarf_end. */
280extern void dwarf_setalt (Dwarf *main, Dwarf *alt);
281
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000282/* Release debugging handling context. */
283extern int dwarf_end (Dwarf *dwarf);
284
285
286/* Get the data block for the .debug_info section. */
287extern Elf_Data *dwarf_getscn_info (Dwarf *dwarf);
288
Roland McGrath3e0f7d12010-06-15 23:10:35 -0700289/* Read the header for the DWARF CU. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000290extern int dwarf_nextcu (Dwarf *dwarf, Dwarf_Off off, Dwarf_Off *next_off,
291 size_t *header_sizep, Dwarf_Off *abbrev_offsetp,
292 uint8_t *address_sizep, uint8_t *offset_sizep)
293 __nonnull_attribute__ (3);
294
Roland McGrath3e0f7d12010-06-15 23:10:35 -0700295/* Read the header of a DWARF CU or type unit. If TYPE_SIGNATUREP is not
296 null, this reads a type unit from the .debug_types section; otherwise
297 this reads a CU from the .debug_info section. */
298extern int dwarf_next_unit (Dwarf *dwarf, Dwarf_Off off, Dwarf_Off *next_off,
Roland McGrath2b1f0952010-06-20 17:55:50 -0700299 size_t *header_sizep, Dwarf_Half *versionp,
Roland McGrath3e0f7d12010-06-15 23:10:35 -0700300 Dwarf_Off *abbrev_offsetp,
301 uint8_t *address_sizep, uint8_t *offset_sizep,
302 uint64_t *type_signaturep, Dwarf_Off *type_offsetp)
303 __nonnull_attribute__ (3);
304
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000305
Roland McGrath3c84db32009-06-24 17:41:40 -0700306/* Decode one DWARF CFI entry (CIE or FDE) from the raw section data.
307 The E_IDENT from the originating ELF file indicates the address
308 size and byte order used in the CFI section contained in DATA;
309 EH_FRAME_P should be true for .eh_frame format and false for
310 .debug_frame format. OFFSET is the byte position in the section
311 to start at; on return *NEXT_OFFSET is filled in with the byte
312 position immediately after this entry.
313
314 On success, returns 0 and fills in *ENTRY; use dwarf_cfi_cie_p to
315 see whether ENTRY->cie or ENTRY->fde is valid.
316
317 On errors, returns -1. Some format errors will permit safely
318 skipping to the next CFI entry though the current one is unusable.
319 In that case, *NEXT_OFF will be updated before a -1 return.
320
321 If there are no more CFI entries left in the section,
322 returns 1 and sets *NEXT_OFFSET to (Dwarf_Off) -1. */
323extern int dwarf_next_cfi (const unsigned char e_ident[],
324 Elf_Data *data, bool eh_frame_p,
325 Dwarf_Off offset, Dwarf_Off *next_offset,
326 Dwarf_CFI_Entry *entry)
327 __nonnull_attribute__ (1, 2, 5, 6);
328
329/* Use the CFI in the DWARF .debug_frame section.
330 Returns NULL if there is no such section (not an error).
331 The pointer returned can be used until dwarf_end is called on DWARF,
332 and must not be passed to dwarf_cfi_end.
333 Calling this more than once returns the same pointer. */
334extern Dwarf_CFI *dwarf_getcfi (Dwarf *dwarf);
335
336/* Use the CFI in the ELF file's exception-handling data.
337 Returns NULL if there is no such data.
338 The pointer returned can be used until elf_end is called on ELF,
339 and must be passed to dwarf_cfi_end before then.
340 Calling this more than once allocates independent data structures. */
341extern Dwarf_CFI *dwarf_getcfi_elf (Elf *elf);
342
343/* Release resources allocated by dwarf_getcfi_elf. */
344extern int dwarf_cfi_end (Dwarf_CFI *cache);
345
346
Mark Wielaard0b72b652011-07-14 12:59:26 +0200347/* Return DIE at given offset in .debug_info section. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000348extern Dwarf_Die *dwarf_offdie (Dwarf *dbg, Dwarf_Off offset,
349 Dwarf_Die *result) __nonnull_attribute__ (3);
350
Roland McGrath2b1f0952010-06-20 17:55:50 -0700351/* Return DIE at given offset in .debug_types section. */
352extern Dwarf_Die *dwarf_offdie_types (Dwarf *dbg, Dwarf_Off offset,
353 Dwarf_Die *result)
354 __nonnull_attribute__ (3);
355
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000356/* Return offset of DIE. */
357extern Dwarf_Off dwarf_dieoffset (Dwarf_Die *die);
358
359/* Return offset of DIE in CU. */
360extern Dwarf_Off dwarf_cuoffset (Dwarf_Die *die);
361
Roland McGrath07d4f2f2005-10-28 06:56:24 +0000362/* Return CU DIE containing given DIE. */
363extern Dwarf_Die *dwarf_diecu (Dwarf_Die *die, Dwarf_Die *result,
Roland McGrathc373d852006-10-10 00:25:21 +0000364 uint8_t *address_sizep, uint8_t *offset_sizep)
365 __nonnull_attribute__ (2);
Roland McGrath07d4f2f2005-10-28 06:56:24 +0000366
Mark Wielaardf18f2332014-08-15 16:03:21 +0200367/* Return the CU DIE and the header info associated with a Dwarf_Die
368 or Dwarf_Attribute. A Dwarf_Die or a Dwarf_Attribute is associated
369 with a particular Dwarf_CU handle. This function returns the CU or
370 type unit DIE and header information for that Dwarf_CU. The
371 returned DIE is either a compile_unit, partial_unit or type_unit.
372 If it is a type_unit, then the type signature and type offset are
373 also provided, otherwise type_offset will be set to zero. See also
374 dwarf_diecu and dwarf_next_unit. */
375extern Dwarf_Die *dwarf_cu_die (Dwarf_CU *cu, Dwarf_Die *result,
376 Dwarf_Half *versionp,
377 Dwarf_Off *abbrev_offsetp,
378 uint8_t *address_sizep,
379 uint8_t *offset_sizep,
380 uint64_t *type_signaturep,
381 Dwarf_Off *type_offsetp)
382 __nonnull_attribute__ (2);
383
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000384/* Return CU DIE containing given address. */
385extern Dwarf_Die *dwarf_addrdie (Dwarf *dbg, Dwarf_Addr addr,
386 Dwarf_Die *result) __nonnull_attribute__ (3);
387
388/* Return child of current DIE. */
389extern int dwarf_child (Dwarf_Die *die, Dwarf_Die *result)
Roland McGrathc373d852006-10-10 00:25:21 +0000390 __nonnull_attribute__ (2);
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000391
Ulrich Drepper35f08c42008-01-18 19:59:08 +0000392/* Locates the first sibling of DIE and places it in RESULT.
393 Returns 0 if a sibling was found, -1 if something went wrong.
394 Returns 1 if no sibling could be found and, if RESULT is not
395 the same as DIE, it sets RESULT->addr to the address of the
396 (non-sibling) DIE that follows this one, or NULL if this DIE
Roland McGrathebc5c882010-01-05 22:53:31 -0800397 was the last one in the compilation unit. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000398extern int dwarf_siblingof (Dwarf_Die *die, Dwarf_Die *result)
399 __nonnull_attribute__ (2);
400
Mark Wielaard3a36e8a2014-10-06 22:00:16 +0200401/* For type aliases and qualifier type DIEs follow the DW_AT_type
402 attribute (recursively) and return the underlying type Dwarf_Die.
403 Returns 0 when RESULT contains a Dwarf_Die (possibly equal to the
404 given DIE) that isn't a type alias or qualifier type. Returns 1
405 when RESULT contains a type alias or qualifier Dwarf_Die that
406 couldn't be peeled further (it doesn't have a DW_TAG_type
407 attribute). Returns -1 when an error occured.
408
409 The current DWARF specification defines one type alias tag
410 (DW_TAG_typedef) and three qualifier type tags (DW_TAG_const_type,
411 DW_TAG_volatile_type, DW_TAG_restrict_type). A future version of
412 this function might peel other alias or qualifier type tags if a
413 future DWARF version or GNU extension defines other type aliases or
414 qualifier type tags that don't modify or change the structural
415 layout of the underlying type. */
416extern int dwarf_peel_type (Dwarf_Die *die, Dwarf_Die *result)
417 __nonnull_attribute__ (2);
418
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000419/* Check whether the DIE has children. */
Ulrich Drepper4f3d2a22006-05-22 01:30:56 +0000420extern int dwarf_haschildren (Dwarf_Die *die) __nonnull_attribute__ (1);
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000421
Ulrich Drepper35f08c42008-01-18 19:59:08 +0000422/* Walks the attributes of DIE, starting at the one OFFSET bytes in,
423 calling the CALLBACK function for each one. Stops if the callback
424 function ever returns a value other than DWARF_CB_OK and returns the
425 offset of the offending attribute. If the end of the attributes
426 is reached 1 is returned. If something goes wrong -1 is returned and
427 the dwarf error number is set. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000428extern ptrdiff_t dwarf_getattrs (Dwarf_Die *die,
429 int (*callback) (Dwarf_Attribute *, void *),
Ulrich Drepper4f3d2a22006-05-22 01:30:56 +0000430 void *arg, ptrdiff_t offset)
431 __nonnull_attribute__ (2);
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000432
433/* Return tag of given DIE. */
Ulrich Drepper4f3d2a22006-05-22 01:30:56 +0000434extern int dwarf_tag (Dwarf_Die *die) __nonnull_attribute__ (1);
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000435
436
437/* Return specific attribute of DIE. */
438extern Dwarf_Attribute *dwarf_attr (Dwarf_Die *die, unsigned int search_name,
439 Dwarf_Attribute *result)
440 __nonnull_attribute__ (3);
441
442/* Check whether given DIE has specific attribute. */
443extern int dwarf_hasattr (Dwarf_Die *die, unsigned int search_name);
444
445/* These are the same as dwarf_attr and dwarf_hasattr, respectively,
446 but they resolve an indirect attribute through DW_AT_abstract_origin. */
447extern Dwarf_Attribute *dwarf_attr_integrate (Dwarf_Die *die,
448 unsigned int search_name,
449 Dwarf_Attribute *result)
450 __nonnull_attribute__ (3);
451extern int dwarf_hasattr_integrate (Dwarf_Die *die, unsigned int search_name);
452
453
454
455
456/* Check whether given attribute has specific form. */
457extern int dwarf_hasform (Dwarf_Attribute *attr, unsigned int search_form);
458
459/* Return attribute code of given attribute. */
460extern unsigned int dwarf_whatattr (Dwarf_Attribute *attr);
461
462/* Return form code of given attribute. */
463extern unsigned int dwarf_whatform (Dwarf_Attribute *attr);
464
465
466/* Return string associated with given attribute. */
467extern const char *dwarf_formstring (Dwarf_Attribute *attrp);
468
469/* Return unsigned constant represented by attribute. */
470extern int dwarf_formudata (Dwarf_Attribute *attr, Dwarf_Word *return_uval)
471 __nonnull_attribute__ (2);
472
473/* Return signed constant represented by attribute. */
474extern int dwarf_formsdata (Dwarf_Attribute *attr, Dwarf_Sword *return_uval)
475 __nonnull_attribute__ (2);
476
477/* Return address represented by attribute. */
478extern int dwarf_formaddr (Dwarf_Attribute *attr, Dwarf_Addr *return_addr)
479 __nonnull_attribute__ (2);
480
Roland McGrathe4c22ea2007-10-23 13:07:39 +0000481/* This function is deprecated. Always use dwarf_formref_die instead.
482 Return reference offset represented by attribute. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000483extern int dwarf_formref (Dwarf_Attribute *attr, Dwarf_Off *return_offset)
Roland McGrathe4c22ea2007-10-23 13:07:39 +0000484 __nonnull_attribute__ (2) __deprecated_attribute__;
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000485
486/* Look up the DIE in a reference-form attribute. */
487extern Dwarf_Die *dwarf_formref_die (Dwarf_Attribute *attr, Dwarf_Die *die_mem)
488 __nonnull_attribute__ (2);
489
490/* Return block represented by attribute. */
491extern int dwarf_formblock (Dwarf_Attribute *attr, Dwarf_Block *return_block)
492 __nonnull_attribute__ (2);
493
494/* Return flag represented by attribute. */
495extern int dwarf_formflag (Dwarf_Attribute *attr, bool *return_bool)
496 __nonnull_attribute__ (2);
497
498
499/* Simplified attribute value access functions. */
500
501/* Return string in name attribute of DIE. */
502extern const char *dwarf_diename (Dwarf_Die *die);
503
504/* Return high PC attribute of DIE. */
505extern int dwarf_highpc (Dwarf_Die *die, Dwarf_Addr *return_addr)
506 __nonnull_attribute__ (2);
507
508/* Return low PC attribute of DIE. */
509extern int dwarf_lowpc (Dwarf_Die *die, Dwarf_Addr *return_addr)
510 __nonnull_attribute__ (2);
511
Roland McGrath07d4f2f2005-10-28 06:56:24 +0000512/* Return entry_pc or low_pc attribute of DIE. */
513extern int dwarf_entrypc (Dwarf_Die *die, Dwarf_Addr *return_addr)
514 __nonnull_attribute__ (2);
515
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000516/* Return 1 if DIE's lowpc/highpc or ranges attributes match the PC address,
517 0 if not, or -1 for errors. */
518extern int dwarf_haspc (Dwarf_Die *die, Dwarf_Addr pc);
519
Roland McGrath07d4f2f2005-10-28 06:56:24 +0000520/* Enumerate the PC address ranges covered by this DIE, covering all
521 addresses where dwarf_haspc returns true. In the first call OFFSET
522 should be zero and *BASEP need not be initialized. Returns -1 for
523 errors, zero when there are no more address ranges to report, or a
524 nonzero OFFSET value to pass to the next call. Each subsequent call
525 must preserve *BASEP from the prior call. Successful calls fill in
526 *STARTP and *ENDP with a contiguous address range. */
527extern ptrdiff_t dwarf_ranges (Dwarf_Die *die,
528 ptrdiff_t offset, Dwarf_Addr *basep,
529 Dwarf_Addr *startp, Dwarf_Addr *endp);
530
531
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000532/* Return byte size attribute of DIE. */
533extern int dwarf_bytesize (Dwarf_Die *die);
534
535/* Return bit size attribute of DIE. */
536extern int dwarf_bitsize (Dwarf_Die *die);
537
538/* Return bit offset attribute of DIE. */
539extern int dwarf_bitoffset (Dwarf_Die *die);
540
541/* Return array order attribute of DIE. */
542extern int dwarf_arrayorder (Dwarf_Die *die);
543
544/* Return source language attribute of DIE. */
545extern int dwarf_srclang (Dwarf_Die *die);
546
547
548/* Get abbreviation at given offset for given DIE. */
549extern Dwarf_Abbrev *dwarf_getabbrev (Dwarf_Die *die, Dwarf_Off offset,
550 size_t *lengthp);
551
552/* Get abbreviation at given offset in .debug_abbrev section. */
553extern int dwarf_offabbrev (Dwarf *dbg, Dwarf_Off offset, size_t *lengthp,
554 Dwarf_Abbrev *abbrevp)
555 __nonnull_attribute__ (4);
556
557/* Get abbreviation code. */
558extern unsigned int dwarf_getabbrevcode (Dwarf_Abbrev *abbrev);
559
560/* Get abbreviation tag. */
561extern unsigned int dwarf_getabbrevtag (Dwarf_Abbrev *abbrev);
562
563/* Return true if abbreviation is children flag set. */
564extern int dwarf_abbrevhaschildren (Dwarf_Abbrev *abbrev);
565
566/* Get number of attributes of abbreviation. */
567extern int dwarf_getattrcnt (Dwarf_Abbrev *abbrev, size_t *attrcntp)
568 __nonnull_attribute__ (2);
569
570/* Get specific attribute of abbreviation. */
571extern int dwarf_getabbrevattr (Dwarf_Abbrev *abbrev, size_t idx,
572 unsigned int *namep, unsigned int *formp,
573 Dwarf_Off *offset);
574
575
576/* Get string from-debug_str section. */
577extern const char *dwarf_getstring (Dwarf *dbg, Dwarf_Off offset,
578 size_t *lenp);
579
580
581/* Get public symbol information. */
582extern ptrdiff_t dwarf_getpubnames (Dwarf *dbg,
583 int (*callback) (Dwarf *, Dwarf_Global *,
584 void *),
585 void *arg, ptrdiff_t offset)
586 __nonnull_attribute__ (2);
587
588
589/* Get source file information for CU. */
590extern int dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines,
591 size_t *nlines) __nonnull_attribute__ (2, 3);
592
593/* Return one of the source lines of the CU. */
594extern Dwarf_Line *dwarf_onesrcline (Dwarf_Lines *lines, size_t idx);
595
596/* Get the file source files used in the CU. */
597extern int dwarf_getsrcfiles (Dwarf_Die *cudie, Dwarf_Files **files,
598 size_t *nfiles)
599 __nonnull_attribute__ (2);
600
601
602/* Get source for address in CU. */
603extern Dwarf_Line *dwarf_getsrc_die (Dwarf_Die *cudie, Dwarf_Addr addr);
604
605/* Get source for file and line number. */
606extern int dwarf_getsrc_file (Dwarf *dbg, const char *fname, int line, int col,
607 Dwarf_Line ***srcsp, size_t *nsrcs)
608 __nonnull_attribute__ (2, 5, 6);
609
610
611/* Return line address. */
612extern int dwarf_lineaddr (Dwarf_Line *line, Dwarf_Addr *addrp);
613
Roland McGrathc70cf4e2010-06-18 17:01:05 -0700614/* Return line VLIW operation index. */
615extern int dwarf_lineop_index (Dwarf_Line *line, unsigned int *op_indexp);
616
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000617/* Return line number. */
618extern int dwarf_lineno (Dwarf_Line *line, int *linep)
619 __nonnull_attribute__ (2);
620
621/* Return column in line. */
622extern int dwarf_linecol (Dwarf_Line *line, int *colp)
623 __nonnull_attribute__ (2);
624
625/* Return true if record is for beginning of a statement. */
626extern int dwarf_linebeginstatement (Dwarf_Line *line, bool *flagp)
627 __nonnull_attribute__ (2);
628
629/* Return true if record is for end of sequence. */
630extern int dwarf_lineendsequence (Dwarf_Line *line, bool *flagp)
631 __nonnull_attribute__ (2);
632
633/* Return true if record is for beginning of a basic block. */
634extern int dwarf_lineblock (Dwarf_Line *line, bool *flagp)
635 __nonnull_attribute__ (2);
636
637/* Return true if record is for end of prologue. */
638extern int dwarf_lineprologueend (Dwarf_Line *line, bool *flagp)
639 __nonnull_attribute__ (2);
640
641/* Return true if record is for beginning of epilogue. */
642extern int dwarf_lineepiloguebegin (Dwarf_Line *line, bool *flagp)
643 __nonnull_attribute__ (2);
644
Roland McGrathc70cf4e2010-06-18 17:01:05 -0700645/* Return instruction-set architecture in this record. */
646extern int dwarf_lineisa (Dwarf_Line *line, unsigned int *isap)
647 __nonnull_attribute__ (2);
648
649/* Return code path discriminator in this record. */
650extern int dwarf_linediscriminator (Dwarf_Line *line, unsigned int *discp)
651 __nonnull_attribute__ (2);
652
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000653
654/* Find line information for address. */
655extern const char *dwarf_linesrc (Dwarf_Line *line,
656 Dwarf_Word *mtime, Dwarf_Word *length);
657
658/* Return file information. */
659extern const char *dwarf_filesrc (Dwarf_Files *file, size_t idx,
660 Dwarf_Word *mtime, Dwarf_Word *length);
661
Roland McGrath43da9892007-04-16 23:13:37 +0000662/* Return the directory list used in the file information extracted.
663 (*RESULT)[0] is the CU's DW_AT_comp_dir value, and may be null.
664 (*RESULT)[0..*NDIRS-1] are the compile-time include directory path
665 encoded by the compiler. */
666extern int dwarf_getsrcdirs (Dwarf_Files *files,
667 const char *const **result, size_t *ndirs)
668 __nonnull_attribute__ (2, 3);
669
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000670
Roland McGrath6724c902005-10-28 07:07:19 +0000671/* Return location expression, decoded as a list of operations. */
672extern int dwarf_getlocation (Dwarf_Attribute *attr, Dwarf_Op **expr,
673 size_t *exprlen) __nonnull_attribute__ (2, 3);
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000674
Roland McGrath6724c902005-10-28 07:07:19 +0000675/* Return location expressions. If the attribute uses a location list,
676 ADDRESS selects the relevant location expressions from the list.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000677 There can be multiple matches, resulting in multiple expressions to
Roland McGrath6724c902005-10-28 07:07:19 +0000678 return. EXPRS and EXPRLENS are parallel arrays of NLOCS slots to
679 fill in. Returns the number of locations filled in, or -1 for
680 errors. If EXPRS is a null pointer, stores nothing and returns the
681 total number of locations. A return value of zero means that the
682 location list indicated no value is accessible. */
683extern int dwarf_getlocation_addr (Dwarf_Attribute *attr, Dwarf_Addr address,
684 Dwarf_Op **exprs, size_t *exprlens,
685 size_t nlocs);
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000686
Mark Wielaard66eaae92013-08-23 16:12:37 +0200687/* Enumerate the locations ranges and descriptions covered by the
688 given attribute. In the first call OFFSET should be zero and
689 *BASEP need not be initialized. Returns -1 for errors, zero when
690 there are no more locations to report, or a nonzero OFFSET
691 value to pass to the next call. Each subsequent call must preserve
692 *BASEP from the prior call. Successful calls fill in *STARTP and
693 *ENDP with a contiguous address range and *EXPR with a pointer to
694 an array of operations with length *EXPRLEN. If the attribute
695 describes a single location description and not a location list the
696 first call (with OFFSET zero) will return the location description
697 in *EXPR with *STARTP set to zero and *ENDP set to minus one. */
698extern ptrdiff_t dwarf_getlocations (Dwarf_Attribute *attr,
699 ptrdiff_t offset, Dwarf_Addr *basep,
700 Dwarf_Addr *startp, Dwarf_Addr *endp,
701 Dwarf_Op **expr, size_t *exprlen);
702
Roland McGrathf0371042009-09-10 12:39:09 -0700703/* Return the block associated with a DW_OP_implicit_value operation.
704 The OP pointer must point into an expression that dwarf_getlocation
705 or dwarf_getlocation_addr has returned given the same ATTR. */
706extern int dwarf_getlocation_implicit_value (Dwarf_Attribute *attr,
Roland McGrath7e0aecd2009-09-17 15:02:34 -0700707 const Dwarf_Op *op,
Roland McGrathf0371042009-09-10 12:39:09 -0700708 Dwarf_Block *return_block)
709 __nonnull_attribute__ (2, 3);
710
Roland McGrath932585d2010-05-08 04:01:14 -0700711/* Return the attribute indicated by a DW_OP_GNU_implicit_pointer operation.
712 The OP pointer must point into an expression that dwarf_getlocation
713 or dwarf_getlocation_addr has returned given the same ATTR.
714 The result is the DW_AT_location or DW_AT_const_value attribute
715 of the OP->number DIE. */
716extern int dwarf_getlocation_implicit_pointer (Dwarf_Attribute *attr,
717 const Dwarf_Op *op,
718 Dwarf_Attribute *result)
719 __nonnull_attribute__ (2, 3);
720
Mark Wielaardb2535b62013-08-30 23:55:12 +0200721/* Return the DIE associated with an operation such as
722 DW_OP_GNU_implicit_pointer, DW_OP_GNU_parameter_ref, DW_OP_GNU_convert,
723 DW_OP_GNU_reinterpret, DW_OP_GNU_const_type, DW_OP_GNU_regval_type or
724 DW_OP_GNU_deref_type. The OP pointer must point into an expression that
725 dwarf_getlocation or dwarf_getlocation_addr has returned given the same
726 ATTR. The RESULT is a DIE that expresses a type or value needed by the
727 given OP. */
728extern int dwarf_getlocation_die (Dwarf_Attribute *attr,
729 const Dwarf_Op *op,
730 Dwarf_Die *result)
731 __nonnull_attribute__ (2, 3);
732
733/* Return the attribute expressing a value associated with an operation such
734 as DW_OP_implicit_value, DW_OP_GNU_entry_value or DW_OP_GNU_const_type.
735 The OP pointer must point into an expression that dwarf_getlocation
736 or dwarf_getlocation_addr has returned given the same ATTR.
737 The RESULT is a value expressed by an attribute such as DW_AT_location
738 or DW_AT_const_value. */
739extern int dwarf_getlocation_attr (Dwarf_Attribute *attr,
740 const Dwarf_Op *op,
741 Dwarf_Attribute *result)
742 __nonnull_attribute__ (2, 3);
743
Roland McGrathf0371042009-09-10 12:39:09 -0700744
Roland McGrathebc5c882010-01-05 22:53:31 -0800745/* Compute the byte-size of a type DIE according to DWARF rules.
746 For most types, this is just DW_AT_byte_size.
747 For DW_TAG_array_type it can apply much more complex rules. */
748extern int dwarf_aggregate_size (Dwarf_Die *die, Dwarf_Word *size);
749
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000750
751/* Return scope DIEs containing PC address.
752 Sets *SCOPES to a malloc'd array of Dwarf_Die structures,
753 and returns the number of elements in the array.
754 (*SCOPES)[0] is the DIE for the innermost scope containing PC,
755 (*SCOPES)[1] is the DIE for the scope containing that scope, and so on.
756 Returns -1 for errors or 0 if no scopes match PC. */
757extern int dwarf_getscopes (Dwarf_Die *cudie, Dwarf_Addr pc,
758 Dwarf_Die **scopes);
759
Roland McGrath71e15a02005-08-27 10:33:26 +0000760/* Return scope DIEs containing the given DIE.
761 Sets *SCOPES to a malloc'd array of Dwarf_Die structures,
762 and returns the number of elements in the array.
763 (*SCOPES)[0] is a copy of DIE.
764 (*SCOPES)[1] is the DIE for the scope containing that scope, and so on.
765 Returns -1 for errors or 0 if DIE is not found in any scope entry. */
766extern int dwarf_getscopes_die (Dwarf_Die *die, Dwarf_Die **scopes);
767
768
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000769/* Search SCOPES[0..NSCOPES-1] for a variable called NAME.
770 Ignore the first SKIP_SHADOWS scopes that match the name.
771 If MATCH_FILE is not null, accept only declaration in that source file;
772 if MATCH_LINENO or MATCH_LINECOL are also nonzero, accept only declaration
773 at that line and column.
774
775 If successful, fill in *RESULT with the DIE of the variable found,
776 and return N where SCOPES[N] is the scope defining the variable.
777 Return -1 for errors or -2 for no matching variable found. */
778extern int dwarf_getscopevar (Dwarf_Die *scopes, int nscopes,
779 const char *name, int skip_shadows,
780 const char *match_file,
781 int match_lineno, int match_linecol,
782 Dwarf_Die *result);
783
784
785
786/* Return list address ranges. */
787extern int dwarf_getaranges (Dwarf *dbg, Dwarf_Aranges **aranges,
788 size_t *naranges)
789 __nonnull_attribute__ (2);
790
791/* Return one of the address range entries. */
792extern Dwarf_Arange *dwarf_onearange (Dwarf_Aranges *aranges, size_t idx);
793
794/* Return information in address range record. */
795extern int dwarf_getarangeinfo (Dwarf_Arange *arange, Dwarf_Addr *addrp,
796 Dwarf_Word *lengthp, Dwarf_Off *offsetp);
797
798/* Get address range which includes given address. */
799extern Dwarf_Arange *dwarf_getarange_addr (Dwarf_Aranges *aranges,
800 Dwarf_Addr addr);
801
802
803
Mark Wielaard1b734df2013-09-20 09:50:42 -0400804/* Get functions in CUDIE. The given callback will be called for all
805 defining DW_TAG_subprograms in the CU DIE tree. If the callback
806 returns DWARF_CB_ABORT the return value can be used as offset argument
807 to resume the function to find all remaining functions (this is not
808 really recommended, since it needs to rewalk the CU DIE tree first till
809 that offset is found again). If the callback returns DWARF_CB_OK
810 dwarf_getfuncs will not return but keep calling the callback for each
811 function DIE it finds. Pass zero for offset on the first call to walk
812 the full CU DIE tree. If no more functions can be found and the callback
813 returned DWARF_CB_OK then the function returns zero. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000814extern ptrdiff_t dwarf_getfuncs (Dwarf_Die *cudie,
Roland McGrath6724c902005-10-28 07:07:19 +0000815 int (*callback) (Dwarf_Die *, void *),
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000816 void *arg, ptrdiff_t offset);
817
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000818
Roland McGrath6724c902005-10-28 07:07:19 +0000819/* Return file name containing definition of the given declaration. */
820extern const char *dwarf_decl_file (Dwarf_Die *decl);
821
822/* Get line number of beginning of given declaration. */
823extern int dwarf_decl_line (Dwarf_Die *decl, int *linep)
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000824 __nonnull_attribute__ (2);
825
Roland McGrath6724c902005-10-28 07:07:19 +0000826/* Get column number of beginning of given declaration. */
827extern int dwarf_decl_column (Dwarf_Die *decl, int *colp)
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000828 __nonnull_attribute__ (2);
829
Roland McGrath1ecb6062005-08-15 09:53:04 +0000830
831/* Return nonzero if given function is an abstract inline definition. */
Roland McGrath6724c902005-10-28 07:07:19 +0000832extern int dwarf_func_inline (Dwarf_Die *func);
Roland McGrath1ecb6062005-08-15 09:53:04 +0000833
834/* Find each concrete inlined instance of the abstract inline definition. */
Roland McGrath6724c902005-10-28 07:07:19 +0000835extern int dwarf_func_inline_instances (Dwarf_Die *func,
Roland McGrath1ecb6062005-08-15 09:53:04 +0000836 int (*callback) (Dwarf_Die *, void *),
837 void *arg);
838
839
Roland McGrath07d4f2f2005-10-28 06:56:24 +0000840/* Find the appropriate PC location or locations for function entry
841 breakpoints for the given DW_TAG_subprogram DIE. Returns -1 for errors.
842 On success, returns the number of breakpoint locations (never zero)
843 and sets *BKPTS to a malloc'd vector of addresses. */
844extern int dwarf_entry_breakpoints (Dwarf_Die *die, Dwarf_Addr **bkpts);
845
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000846
Petr Machatafb90bf32014-10-17 02:47:03 +0200847/* Iterate through the macro unit referenced by CUDIE and call
848 CALLBACK for each macro information entry. Keeps iterating while
849 CALLBACK returns DWARF_CB_OK. If the callback returns
850 DWARF_CB_ABORT, it stops iterating and returns a continuation
851 token, which can be used to restart the iteration at the point
852 where it ended. A TOKEN of 0 starts the iteration. Returns -1 for
853 errors or 0 if there are no more macro entries.
854
855 Note that the Dwarf_Macro pointer passed to the callback is only
856 valid for the duration of the callback invocation.
857
858 Note that this interface will refuse to serve opcode 0xff from
859 .debug_macro sections. Such opcode is considered invalid and will
860 cause dwarf_getmacros to return with error. Note that this should
861 be no limitation as of now, as DW_MACRO_GNU_* domain doesn't
862 allocate 0xff. It is however a theoretical possibility with future
863 Dwarf standards. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000864extern ptrdiff_t dwarf_getmacros (Dwarf_Die *cudie,
865 int (*callback) (Dwarf_Macro *, void *),
Petr Machatafb90bf32014-10-17 02:47:03 +0200866 void *arg, ptrdiff_t token)
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000867 __nonnull_attribute__ (2);
868
Petr Machatafb90bf32014-10-17 02:47:03 +0200869/* This is similar in operation to dwarf_getmacros, but selects the
870 unit to iterate through by offset instead of by CU, and always
871 iterates .debug_macro. This can be used for handling
872 DW_MACRO_GNU_transparent_include's or similar opcodes.
873
874 It is not appropriate to obtain macro unit offset by hand from a CU
875 DIE and then request iteration through this interface. The reason
876 for this is that if a dwarf_macro_getsrcfiles is later called,
877 there would be no way to figure out what DW_AT_comp_dir was present
878 on the CU DIE, and file names referenced in either the macro unit
879 itself, or the .debug_line unit that it references, might be wrong.
880 Use dwarf_getmacro. */
881extern ptrdiff_t dwarf_getmacros_off (Dwarf *dbg, Dwarf_Off macoff,
882 int (*callback) (Dwarf_Macro *, void *),
883 void *arg, ptrdiff_t token)
884 __nonnull_attribute__ (3);
885
886/* Get the source files used by the macro entry. You shouldn't assume
887 that Dwarf_Files references will remain valid after MACRO becomes
888 invalid. (Which is to say it's only valid within the
889 dwarf_getmacros* callback.) Returns 0 for success or a negative
890 value in case of an error. */
891extern int dwarf_macro_getsrcfiles (Dwarf *dbg, Dwarf_Macro *macro,
892 Dwarf_Files **files, size_t *nfiles)
893 __nonnull_attribute__ (2, 3, 4);
894
895/* Return macro opcode. That's a constant that can be either from
896 DW_MACINFO_* domain or DW_MACRO_GNU_* domain. The two domains have
897 compatible values, so it's OK to use either of them for
898 comparisons. The only differences is 0xff, which currently is
899 never served from .debug_macro, and can thus be safely assumed to
900 mean DW_MACINFO_vendor_ext. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000901extern int dwarf_macro_opcode (Dwarf_Macro *macro, unsigned int *opcodep)
902 __nonnull_attribute__ (2);
903
Petr Machatafb90bf32014-10-17 02:47:03 +0200904/* Get number of parameters of MACRO and store it to *PARAMCNTP. */
905extern int dwarf_macro_getparamcnt (Dwarf_Macro *macro, size_t *paramcntp);
906
907/* Get IDX-th parameter of MACRO (numbered from zero), and stores it
908 to *ATTRIBUTE. Returns 0 on success or -1 for errors.
909
910 After a successful call, you can query ATTRIBUTE by dwarf_whatform
911 to determine which of the dwarf_formX calls to make to get actual
912 value out of ATTRIBUTE. Note that calling dwarf_whatattr is not
913 meaningful for pseudo-attributes formed this way. */
914extern int dwarf_macro_param (Dwarf_Macro *macro, size_t idx,
915 Dwarf_Attribute *attribute);
916
917/* Return macro parameter with index 0. This will return -1 if the
918 parameter is not an integral value. Use dwarf_macro_param for more
919 general access. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000920extern int dwarf_macro_param1 (Dwarf_Macro *macro, Dwarf_Word *paramp)
921 __nonnull_attribute__ (2);
922
Petr Machatafb90bf32014-10-17 02:47:03 +0200923/* Return macro parameter with index 1. This will return -1 if the
924 parameter is not an integral or string value. Use
925 dwarf_macro_param for more general access. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000926extern int dwarf_macro_param2 (Dwarf_Macro *macro, Dwarf_Word *paramp,
927 const char **strp);
928
Roland McGrath3c84db32009-06-24 17:41:40 -0700929/* Compute what's known about a call frame when the PC is at ADDRESS.
930 Returns 0 for success or -1 for errors.
931 On success, *FRAME is a malloc'd pointer. */
932extern int dwarf_cfi_addrframe (Dwarf_CFI *cache,
933 Dwarf_Addr address, Dwarf_Frame **frame)
934 __nonnull_attribute__ (3);
935
936/* Return the DWARF register number used in FRAME to denote
937 the return address in FRAME's caller frame. The remaining
938 arguments can be non-null to fill in more information.
939
940 Fill [*START, *END) with the PC range to which FRAME's information applies.
941 Fill in *SIGNALP to indicate whether this is a signal-handling frame.
942 If true, this is the implicit call frame that calls a signal handler.
943 This frame's "caller" is actually the interrupted state, not a call;
944 its return address is an exact PC, not a PC after a call instruction. */
945extern int dwarf_frame_info (Dwarf_Frame *frame,
946 Dwarf_Addr *start, Dwarf_Addr *end, bool *signalp);
947
Roland McGrathaf800142009-07-22 13:55:50 -0700948/* Return a DWARF expression that yields the Canonical Frame Address at
949 this frame state. Returns -1 for errors, or zero for success, with
950 *NOPS set to the number of operations stored at *OPS. That pointer
951 can be used only as long as FRAME is alive and unchanged. *NOPS is
952 zero if the CFA cannot be determined here. Note that if nonempty,
953 *OPS is a DWARF expression, not a location description--append
954 DW_OP_stack_value to a get a location description for the CFA. */
955extern int dwarf_frame_cfa (Dwarf_Frame *frame, Dwarf_Op **ops, size_t *nops)
Roland McGrath3c84db32009-06-24 17:41:40 -0700956 __nonnull_attribute__ (2);
957
Roland McGrathaf800142009-07-22 13:55:50 -0700958/* Deliver a DWARF location description that yields the location or
959 value of DWARF register number REGNO in the state described by FRAME.
Roland McGrath3c84db32009-06-24 17:41:40 -0700960
Roland McGrathaf800142009-07-22 13:55:50 -0700961 Returns -1 for errors or zero for success, setting *NOPS to the
962 number of operations in the array stored at *OPS. Note the last
963 operation is DW_OP_stack_value if there is no mutable location but
964 only a computable value.
Roland McGrath3c84db32009-06-24 17:41:40 -0700965
Roland McGrathaf800142009-07-22 13:55:50 -0700966 *NOPS zero with *OPS set to OPS_MEM means CFI says the caller's
967 REGNO is "undefined", i.e. it's call-clobbered and cannot be recovered.
Roland McGrath3c84db32009-06-24 17:41:40 -0700968
Roland McGrathaf800142009-07-22 13:55:50 -0700969 *NOPS zero with *OPS set to a null pointer means CFI says the
970 caller's REGNO is "same_value", i.e. this frame did not change it;
971 ask the caller frame where to find it.
Roland McGrath3c84db32009-06-24 17:41:40 -0700972
973 For common simple expressions *OPS is OPS_MEM. For arbitrary DWARF
974 expressions in the CFI, *OPS is an internal pointer that can be used as
975 long as the Dwarf_CFI used to create FRAME remains alive. */
976extern int dwarf_frame_register (Dwarf_Frame *frame, int regno,
Roland McGrathaf800142009-07-22 13:55:50 -0700977 Dwarf_Op ops_mem[3],
Roland McGrath3c84db32009-06-24 17:41:40 -0700978 Dwarf_Op **ops, size_t *nops)
979 __nonnull_attribute__ (3, 4, 5);
980
981
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000982/* Return error code of last failing function call. This value is kept
983 separately for each thread. */
984extern int dwarf_errno (void);
985
986/* Return error string for ERROR. If ERROR is zero, return error string
987 for most recent error or NULL is none occurred. If ERROR is -1 the
988 behaviour is similar to the last case except that not NULL but a legal
989 string is returned. */
990extern const char *dwarf_errmsg (int err);
991
992
993/* Register new Out-Of-Memory handler. The old handler is returned. */
994extern Dwarf_OOM dwarf_new_oom_handler (Dwarf *dbg, Dwarf_OOM handler);
995
996
997/* Inline optimizations. */
998#ifdef __OPTIMIZE__
999/* Return attribute code of given attribute. */
Ulrich Drepperb597dfa2007-10-16 05:21:27 +00001000__libdw_extern_inline unsigned int
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001001dwarf_whatattr (Dwarf_Attribute *attr)
1002{
1003 return attr == NULL ? 0 : attr->code;
1004}
1005
1006/* Return attribute code of given attribute. */
Ulrich Drepperb597dfa2007-10-16 05:21:27 +00001007__libdw_extern_inline unsigned int
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001008dwarf_whatform (Dwarf_Attribute *attr)
1009{
1010 return attr == NULL ? 0 : attr->form;
1011}
1012#endif /* Optimize. */
1013
Ulrich Drepper3be74472006-05-27 18:15:40 +00001014#ifdef __cplusplus
1015}
1016#endif
1017
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001018#endif /* libdw.h */