libdw.h revision 593c365a822e505dae3aaa4d8d66eca333911624
1076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Interfaces for libdw.
2076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian   Copyright (C) 2002, 2004 Red Hat, Inc.
3076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
4076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
5076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian   This program is Open Source software; you can redistribute it and/or
6076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian   modify it under the terms of the Open Software License version 1.0 as
7076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian   published by the Open Source Initiative.
8076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
9076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian   You should have received a copy of the Open Software License along
10076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian   with this program; if not, you may obtain a copy of the Open Software
11076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian   License version 1.0 from http://www.opensource.org/licenses/osl.php or
12076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian   by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
13076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian   3001 King Ranch Road, Ukiah, CA 95482.   */
14076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
15076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#ifndef _LIBDW_H
16076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#define _LIBDW_H	1
17076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
18076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#include <gelf.h>
19076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#include <stdbool.h>
20076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#include <stddef.h>
21076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
224243e666213029a293935987c979831093fb0779Mathias Agopian
234243e666213029a293935987c979831093fb0779Mathias Agopian#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
24076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian# define __nonnull_attribute__(...) __attribute__ ((__nonnull__ (__VA_ARGS__)))
25076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#else
26076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian# define __nonnull_attribute__(args...)
27076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#endif
28076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
29076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
30076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Mode for the session.  */
31076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef enum
32076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  {
33076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    DWARF_C_READ,		/* Read .. */
34076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    DWARF_C_RDWR,		/* Read and write .. */
35076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    DWARF_C_WRITE,		/* Write .. */
36076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  }
374243e666213029a293935987c979831093fb0779Mathias AgopianDwarf_Cmd;
384243e666213029a293935987c979831093fb0779Mathias Agopian
394243e666213029a293935987c979831093fb0779Mathias Agopian
40076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Callback results.  */
41076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopianenum
42076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{
43076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  DWARF_CB_OK = 0,
44076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  DWARF_CB_ABORT
45076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian};
46076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
47076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
48076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Error values.  */
49076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopianenum
50076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  {
51076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    DW_TAG_invalid = 0
52076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#define DW_TAG_invalid	DW_TAG_invalid
53076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  };
54076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
55076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
56076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Type for offset in DWARF file.  */
57076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef GElf_Off Dwarf_Off;
58076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
59076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Type for address in DWARF file.  */
60076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef GElf_Addr Dwarf_Addr;
61076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
62076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Integer types.  Big enough to hold any numeric value.  */
63076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef GElf_Xword Dwarf_Word;
64076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef GElf_Sxword Dwarf_Sword;
65076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* For the times we know we do not need that much.  */
66076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef GElf_Half Dwarf_Half;
67076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
68076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
69076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* DWARF abbreviation record.  */
70076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef struct Dwarf_Abbrev Dwarf_Abbrev;
71076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
72076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Source code line information for CU.  */
73076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef struct Dwarf_Lines_s Dwarf_Lines;
74076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
75076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* One source code line information.  */
76076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef struct Dwarf_Line_s Dwarf_Line;
77076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
78076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Source file information.  */
79076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef struct Dwarf_Files_s Dwarf_Files;
80076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
81076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* One address range record.  */
82076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef struct Dwarf_Arange_s Dwarf_Arange;
83076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
84076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Address ranges of a file.  */
85076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef struct Dwarf_Aranges_s Dwarf_Aranges;
86076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
87076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* CU representation.  */
88076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopianstruct Dwarf_CU;
89076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
90076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Attribute representation.  */
91076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef struct
92076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{
93076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  unsigned int code;
94076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  unsigned int form;
95076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  unsigned char *valp;
96076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  struct Dwarf_CU *cu;
97076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian} Dwarf_Attribute;
98076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
99076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
100076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Data block representation.  */
101076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef struct
102076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{
103076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  Dwarf_Word length;
104076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  unsigned char *data;
105076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian} Dwarf_Block;
106076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
107076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
108076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Macro information.  */
109076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef struct
110076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{
111076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  unsigned int opcode;
1128b765b7f5ea7f56963ea0e3141d043d20944dbccMathias Agopian  Dwarf_Word param1;
1138b765b7f5ea7f56963ea0e3141d043d20944dbccMathias Agopian  union
1144243e666213029a293935987c979831093fb0779Mathias Agopian  {
1154243e666213029a293935987c979831093fb0779Mathias Agopian    Dwarf_Word u;
1164243e666213029a293935987c979831093fb0779Mathias Agopian    const char *s;
1174243e666213029a293935987c979831093fb0779Mathias Agopian  } param2;
1184243e666213029a293935987c979831093fb0779Mathias Agopian} Dwarf_Macro;
1194243e666213029a293935987c979831093fb0779Mathias Agopian
1208b765b7f5ea7f56963ea0e3141d043d20944dbccMathias Agopian
1214243e666213029a293935987c979831093fb0779Mathias Agopian/* DIE information.  */
1228b765b7f5ea7f56963ea0e3141d043d20944dbccMathias Agopiantypedef struct
1238b765b7f5ea7f56963ea0e3141d043d20944dbccMathias Agopian{
1248b765b7f5ea7f56963ea0e3141d043d20944dbccMathias Agopian  /* The offset can be computed from the address.  */
1258b765b7f5ea7f56963ea0e3141d043d20944dbccMathias Agopian  void *addr;
126076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  struct Dwarf_CU *cu;
127076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  Dwarf_Abbrev *abbrev;
128076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  // XXX We'll see what other information will be needed.
129076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian} Dwarf_Die;
130076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
131076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Returned to show the last DIE has be returned.  */
132076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#define DWARF_END_DIE ((Dwarf_Die *) -1l)
133076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
134076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
135076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Global symbol information.  */
136076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef struct
137076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{
138076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  Dwarf_Off cu_offset;
139076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  Dwarf_Off die_offset;
140076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  const char *name;
1414243e666213029a293935987c979831093fb0779Mathias Agopian} Dwarf_Global;
142076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
143076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
144076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian// XXX It remains to be seen whether the next two need to be exported.
145076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Location record.  */
146076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef struct
147076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{
148076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  uint8_t atom;			/* Operation */
149076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  Dwarf_Word number;		/* Operand */
150076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  Dwarf_Word number2;		/* Possible second operand */
151076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian  Dwarf_Word offset;		/* Offset in location expression */
152076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian} Dwarf_Loc;
153076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
154076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
155076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Handle for debug sessions.  */
156076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef struct Dwarf Dwarf;
1574243e666213029a293935987c979831093fb0779Mathias Agopian
158076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
159076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Out-Of-Memory handler.  */
160076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef void (*__attribute__ ((noreturn)) Dwarf_OOM) (void);
161076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
162076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
163076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Create a handle for a new debug session.  */
164076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopianextern Dwarf *dwarf_begin (int fildes, Dwarf_Cmd cmd);
165076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
166076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Create a handle for a new debug session for an ELF file.  */
167076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopianextern Dwarf *dwarf_begin_elf (Elf *elf, Dwarf_Cmd cmd, Elf_Scn *scngrp);
168076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
169076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* Retrieve ELF descriptor used for DWARF access.  */
170076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopianextern Elf *dwarf_getelf (Dwarf *dwarf);
171076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
172/* Release debugging handling context.  */
173extern int dwarf_end (Dwarf *dwarf);
174
175
176/* Get the data block for the .debug_info section.  */
177extern Elf_Data *dwarf_getscn_info (Dwarf *dwarf);
178
179/* Read the header for the DWARF CU header.  */
180extern int dwarf_nextcu (Dwarf *dwarf, Dwarf_Off off, Dwarf_Off *next_off,
181			 size_t *header_sizep, Dwarf_Off *abbrev_offsetp,
182			 uint8_t *address_sizep, uint8_t *offset_sizep)
183     __nonnull_attribute__ (3);
184
185
186/* Return DIE at given offset.  */
187extern Dwarf_Die *dwarf_offdie (Dwarf *dbg, Dwarf_Off offset,
188				Dwarf_Die *result) __nonnull_attribute__ (3);
189
190/* Return offset of DIE.  */
191extern Dwarf_Off dwarf_dieoffset (Dwarf_Die *die);
192
193/* Return offset of DIE in CU.  */
194extern Dwarf_Off dwarf_cuoffset (Dwarf_Die *die);
195
196/* Return vhild of current DIE.  */
197extern int dwarf_child (Dwarf_Die *die, Dwarf_Die *result)
198     __nonnull_attribute__ (2);
199
200/* Return sibling of given DIE.  */
201extern int dwarf_siblingof (Dwarf_Die *die, Dwarf_Die *result)
202     __nonnull_attribute__ (2);
203
204/* Check whether the DIE has children.  */
205extern int dwarf_haschildren (Dwarf_Die *die);
206
207/* Get attributes of the DIE.  */
208extern ptrdiff_t dwarf_getattrs (Dwarf_Die *die,
209				 int (*callback) (Dwarf_Attribute *, void *),
210				 void *arg, ptrdiff_t offset);
211
212/* Return tag of given DIE.  */
213extern int dwarf_tag (Dwarf_Die *die);
214
215
216/* Return specific attribute of DIE.  */
217extern Dwarf_Attribute *dwarf_attr (Dwarf_Die *die, unsigned int search_name,
218				    Dwarf_Attribute *result)
219     __nonnull_attribute__ (3);
220
221/* Check whether given DIE has specific attribute.  */
222extern int dwarf_hasattr (Dwarf_Die *die, unsigned int search_name);
223
224
225/* Check whether given attribute has specific form.  */
226extern int dwarf_hasform (Dwarf_Attribute *attr, unsigned int search_form);
227
228/* Return attribute code of given attribute.  */
229extern unsigned int dwarf_whatattr (Dwarf_Attribute *attr);
230
231/* Return form code of given attribute.  */
232extern unsigned int dwarf_whatform (Dwarf_Attribute *attr);
233
234
235/* Return string associated with given attribute.  */
236extern const char *dwarf_formstring (Dwarf_Attribute *attrp);
237
238/* Return unsigned constant represented by attribute.  */
239extern int dwarf_formudata (Dwarf_Attribute *attr, Dwarf_Word *return_uval)
240     __nonnull_attribute__ (2);
241
242/* Return signed constant represented by attribute.  */
243extern int dwarf_formsdata (Dwarf_Attribute *attr, Dwarf_Sword *return_uval)
244     __nonnull_attribute__ (2);
245
246/* Return address represented by attribute.  */
247extern int dwarf_formaddr (Dwarf_Attribute *attr, Dwarf_Addr *return_addr)
248     __nonnull_attribute__ (2);
249
250/* Return reference offset represented by attribute.  */
251extern int dwarf_formref (Dwarf_Attribute *attr, Dwarf_Off *return_offset)
252     __nonnull_attribute__ (2);
253
254/* Return block represented by attribute.  */
255extern int dwarf_formblock (Dwarf_Attribute *attr, Dwarf_Block *return_block)
256     __nonnull_attribute__ (2);
257
258/* Return flag represented by attribute.  */
259extern int dwarf_formflag (Dwarf_Attribute *attr, bool *return_bool)
260     __nonnull_attribute__ (2);
261
262
263/* Simplified attribute value access functions.  */
264
265/* Return string in name attribute of DIE.  */
266extern const char *dwarf_diename (Dwarf_Die *die);
267
268/* Return high PC attribute of DIE.  */
269extern int dwarf_highpc (Dwarf_Die *die, Dwarf_Addr *return_addr)
270     __nonnull_attribute__ (2);
271
272/* Return low PC attribute of DIE.  */
273extern int dwarf_lowpc (Dwarf_Die *die, Dwarf_Addr *return_addr)
274     __nonnull_attribute__ (2);
275
276/* Return byte size attribute of DIE.  */
277extern int dwarf_bytesize (Dwarf_Die *die);
278
279/* Return bit size attribute of DIE.  */
280extern int dwarf_bitsize (Dwarf_Die *die);
281
282/* Return bit offset attribute of DIE.  */
283extern int dwarf_bitoffset (Dwarf_Die *die);
284
285/* Return array order attribute of DIE.  */
286extern int dwarf_arrayorder (Dwarf_Die *die);
287
288/* Return source language attribute of DIE.  */
289extern int dwarf_srclang (Dwarf_Die *die);
290
291
292/* Get abbreviation at given offset for given DIE.  */
293extern Dwarf_Abbrev *dwarf_getabbrev (Dwarf_Die *die, Dwarf_Off offset,
294				      size_t *lengthp);
295
296/* Get abbreviation at given offset in .debug_abbrev section.  */
297extern int dwarf_offabbrev (Dwarf *dbg, Dwarf_Off offset, size_t *lengthp,
298			    Dwarf_Abbrev *abbrevp)
299     __nonnull_attribute__ (4);
300
301/* Get abbreviation code.  */
302extern unsigned int dwarf_getabbrevcode (Dwarf_Abbrev *abbrev);
303
304/* Get abbreviation tag.  */
305extern unsigned int dwarf_getabbrevtag (Dwarf_Abbrev *abbrev);
306
307/* Return true if abbreviation is children flag set.  */
308extern int dwarf_abbrevhaschildren (Dwarf_Abbrev *abbrev);
309
310/* Get number of attributes of abbreviation.  */
311extern int dwarf_getattrcnt (Dwarf_Abbrev *abbrev, size_t *attrcntp)
312     __nonnull_attribute__ (2);
313
314/* Get specific attribute of abbreviation.  */
315extern int dwarf_getabbrevattr (Dwarf_Abbrev *abbrev, size_t idx,
316				unsigned int *namep, unsigned int *formp,
317				Dwarf_Off *offset);
318
319
320/* Get string from-debug_str section.  */
321extern const char *dwarf_getstring (Dwarf *dbg, Dwarf_Off offset,
322				    size_t *lenp);
323
324
325/* Get public symbol information.  */
326extern ptrdiff_t dwarf_getpubnames (Dwarf *dbg,
327				    int (*callback) (Dwarf *, Dwarf_Global *,
328						     void *),
329				    void *arg, ptrdiff_t offset)
330     __nonnull_attribute__ (2);
331
332
333/* Get source file information for CU.  */
334extern int dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines,
335			      size_t *nlines) __nonnull_attribute__ (2, 3);
336
337/* Return one of the source lines of the CU.  */
338extern Dwarf_Line *dwarf_onesrcline (Dwarf_Lines *lines, size_t idx);
339
340/* Get the file source files used in the CU.  */
341extern int dwarf_getsrcfiles (Dwarf_Die *cudie, Dwarf_Files **files,
342			      size_t *nfiles)
343     __nonnull_attribute__ (2);
344
345
346/* Get source for address in CU.  */
347extern Dwarf_Line *dwarf_getsrc_die (Dwarf_Die *cudie, Dwarf_Addr addr);
348
349/* Return line address.  */
350extern int dwarf_lineaddr (Dwarf_Line *line, Dwarf_Addr *addrp);
351
352/* Return line number.  */
353extern int dwarf_lineno (Dwarf_Line *line, int *linep)
354     __nonnull_attribute__ (2);
355
356/* Return column in line.  */
357extern int dwarf_linecol (Dwarf_Line *line, int *colp)
358     __nonnull_attribute__ (2);
359
360/* Return true if record is for beginning of a statement.  */
361extern int dwarf_linebeginstatement (Dwarf_Line *line, bool *flagp)
362     __nonnull_attribute__ (2);
363
364/* Return true if record is for end of sequence.  */
365extern int dwarf_lineendsequence (Dwarf_Line *line, bool *flagp)
366     __nonnull_attribute__ (2);
367
368/* Return true if record is for beginning of a basic block.  */
369extern int dwarf_lineblock (Dwarf_Line *line, bool *flagp)
370     __nonnull_attribute__ (2);
371
372/* Return true if record is for end of prologue.  */
373extern int dwarf_lineprologueend (Dwarf_Line *line, bool *flagp)
374     __nonnull_attribute__ (2);
375
376/* Return true if record is for beginning of epilogue.  */
377extern int dwarf_lineepiloguebegin (Dwarf_Line *line, bool *flagp)
378     __nonnull_attribute__ (2);
379
380
381/* Find line information for address.  */
382extern const char *dwarf_linesrc (Dwarf_Line *line,
383				  Dwarf_Word *mtime, Dwarf_Word *length);
384
385/* Return file information.  */
386extern const char *dwarf_filesrc (Dwarf_Files *file, size_t idx,
387				  Dwarf_Word *mtime, Dwarf_Word *length);
388
389
390/* Return location expression list.  */
391extern int dwarf_getloclist (Dwarf_Attribute *attr, Dwarf_Loc **llbuf,
392			     size_t *listlen) __nonnull_attribute__ (2, 3);
393
394
395
396/* Return list address ranges.  */
397extern int dwarf_getaranges (Dwarf *dbg, Dwarf_Aranges **aranges,
398			     size_t *naranges)
399     __nonnull_attribute__ (2);
400
401/* Return one of the address range entries.  */
402extern Dwarf_Arange *dwarf_onearange (Dwarf_Aranges *aranges, size_t idx);
403
404/* Return information in address range record.  */
405extern int dwarf_getarangeinfo (Dwarf_Arange *arange, Dwarf_Addr *addrp,
406				Dwarf_Word *lengthp, Dwarf_Off *offsetp);
407
408/* Get address range which includes given address.  */
409extern Dwarf_Arange *dwarf_getarange_addr (Dwarf_Aranges *aranges,
410					   Dwarf_Addr addr);
411
412
413/* Call callback function for each of the macro information entry for
414   the CU.  */
415extern ptrdiff_t dwarf_getmacros (Dwarf_Die *cudie,
416				  int (*callback) (Dwarf_Macro *, void *),
417				  void *arg, ptrdiff_t offset)
418     __nonnull_attribute__ (2);
419
420
421/* Return error code of last failing function call.  This value is kept
422   separately for each thread.  */
423extern int dwarf_errno (void);
424
425/* Return error string for ERROR.  If ERROR is zero, return error string
426   for most recent error or NULL is none occurred.  If ERROR is -1 the
427   behaviour is similar to the last case except that not NULL but a legal
428   string is returned.  */
429extern const char *dwarf_errmsg (int err);
430
431
432/* Register new Out-Of-Memory handler.  The old handler is returned.  */
433extern Dwarf_OOM dwarf_new_oom_handler (Dwarf *dbg, Dwarf_OOM handler);
434
435
436/* Inline optimizations.  */
437#ifdef __OPTIMIZE__
438/* Return attribute code of given attribute.  */
439extern inline unsigned int
440dwarf_whatattr (Dwarf_Attribute *attr)
441{
442  return attr == NULL ? 0 : attr->code;
443}
444
445/* Return attribute code of given attribute.  */
446extern inline unsigned int
447dwarf_whatform (Dwarf_Attribute *attr)
448{
449  return attr == NULL ? 0 : attr->form;
450}
451#endif	/* Optimize.  */
452
453#endif	/* libdw.h */
454