libdw.h revision df72c45805a859891ed0dcb854ee766f8ebef372
1/* Interfaces for libdw.
2   Copyright (C) 2002, 2004, 2005, 2006 Red Hat, Inc.
3   This file is part of Red Hat elfutils.
4
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.
8
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.
13
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.
17
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.
41
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>.  */
49
50#ifndef _LIBDW_H
51#define _LIBDW_H	1
52
53#include <gelf.h>
54#include <stdbool.h>
55#include <stddef.h>
56
57
58#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
59# define __nonnull_attribute__(...) __attribute__ ((__nonnull__ (__VA_ARGS__)))
60#else
61# define __nonnull_attribute__(args...)
62#endif
63
64
65/* Mode for the session.  */
66typedef enum
67  {
68    DWARF_C_READ,		/* Read .. */
69    DWARF_C_RDWR,		/* Read and write .. */
70    DWARF_C_WRITE,		/* Write .. */
71  }
72Dwarf_Cmd;
73
74
75/* Callback results.  */
76enum
77{
78  DWARF_CB_OK = 0,
79  DWARF_CB_ABORT
80};
81
82
83/* Error values.  */
84enum
85  {
86    DW_TAG_invalid = 0
87#define DW_TAG_invalid	DW_TAG_invalid
88  };
89
90
91/* Type for offset in DWARF file.  */
92typedef GElf_Off Dwarf_Off;
93
94/* Type for address in DWARF file.  */
95typedef GElf_Addr Dwarf_Addr;
96
97/* Integer types.  Big enough to hold any numeric value.  */
98typedef GElf_Xword Dwarf_Word;
99typedef GElf_Sxword Dwarf_Sword;
100/* For the times we know we do not need that much.  */
101typedef GElf_Half Dwarf_Half;
102
103
104/* DWARF abbreviation record.  */
105typedef struct Dwarf_Abbrev Dwarf_Abbrev;
106
107/* Returned to show the last DIE has be returned.  */
108#define DWARF_END_ABBREV ((Dwarf_Abbrev *) -1l)
109
110/* Source code line information for CU.  */
111typedef struct Dwarf_Lines_s Dwarf_Lines;
112
113/* One source code line information.  */
114typedef struct Dwarf_Line_s Dwarf_Line;
115
116/* Source file information.  */
117typedef struct Dwarf_Files_s Dwarf_Files;
118
119/* One address range record.  */
120typedef struct Dwarf_Arange_s Dwarf_Arange;
121
122/* Address ranges of a file.  */
123typedef struct Dwarf_Aranges_s Dwarf_Aranges;
124
125/* CU representation.  */
126struct Dwarf_CU;
127
128/* Macro information.  */
129typedef struct Dwarf_Macro_s Dwarf_Macro;
130
131/* Attribute representation.  */
132typedef struct
133{
134  unsigned int code;
135  unsigned int form;
136  unsigned char *valp;
137  struct Dwarf_CU *cu;
138} Dwarf_Attribute;
139
140
141/* Data block representation.  */
142typedef struct
143{
144  Dwarf_Word length;
145  unsigned char *data;
146} Dwarf_Block;
147
148
149/* DIE information.  */
150typedef struct
151{
152  /* The offset can be computed from the address.  */
153  void *addr;
154  struct Dwarf_CU *cu;
155  Dwarf_Abbrev *abbrev;
156  // XXX We'll see what other information will be needed.
157  long int padding__;
158} Dwarf_Die;
159
160/* Returned to show the last DIE has be returned.  */
161#define DWARF_END_DIE ((Dwarf_Die *) -1l)
162
163
164/* Global symbol information.  */
165typedef struct
166{
167  Dwarf_Off cu_offset;
168  Dwarf_Off die_offset;
169  const char *name;
170} Dwarf_Global;
171
172
173/* One operation in a DWARF location expression.
174   A location expression is an array of these.  */
175typedef struct
176{
177  uint8_t atom;			/* Operation */
178  Dwarf_Word number;		/* Operand */
179  Dwarf_Word number2;		/* Possible second operand */
180  Dwarf_Word offset;		/* Offset in location expression */
181} Dwarf_Op;
182
183
184/* Handle for debug sessions.  */
185typedef struct Dwarf Dwarf;
186
187
188/* Out-Of-Memory handler.  */
189#if __GNUC__ < 4
190typedef void (*Dwarf_OOM) (void);
191#else
192typedef void (*__attribute__ ((noreturn)) Dwarf_OOM) (void);
193#endif
194
195
196#ifdef __cplusplus
197extern "C" {
198#endif
199
200/* Create a handle for a new debug session.  */
201extern Dwarf *dwarf_begin (int fildes, Dwarf_Cmd cmd);
202
203/* Create a handle for a new debug session for an ELF file.  */
204extern Dwarf *dwarf_begin_elf (Elf *elf, Dwarf_Cmd cmd, Elf_Scn *scngrp);
205
206/* Retrieve ELF descriptor used for DWARF access.  */
207extern Elf *dwarf_getelf (Dwarf *dwarf);
208
209/* Release debugging handling context.  */
210extern int dwarf_end (Dwarf *dwarf);
211
212
213/* Get the data block for the .debug_info section.  */
214extern Elf_Data *dwarf_getscn_info (Dwarf *dwarf);
215
216/* Read the header for the DWARF CU header.  */
217extern int dwarf_nextcu (Dwarf *dwarf, Dwarf_Off off, Dwarf_Off *next_off,
218			 size_t *header_sizep, Dwarf_Off *abbrev_offsetp,
219			 uint8_t *address_sizep, uint8_t *offset_sizep)
220     __nonnull_attribute__ (3);
221
222
223/* Return DIE at given offset.  */
224extern Dwarf_Die *dwarf_offdie (Dwarf *dbg, Dwarf_Off offset,
225				Dwarf_Die *result) __nonnull_attribute__ (3);
226
227/* Return offset of DIE.  */
228extern Dwarf_Off dwarf_dieoffset (Dwarf_Die *die);
229
230/* Return offset of DIE in CU.  */
231extern Dwarf_Off dwarf_cuoffset (Dwarf_Die *die);
232
233/* Return CU DIE containing given DIE.  */
234extern Dwarf_Die *dwarf_diecu (Dwarf_Die *die, Dwarf_Die *result,
235			       uint8_t *address_sizep, uint8_t *offset_sizep);
236
237/* Return CU DIE containing given address.  */
238extern Dwarf_Die *dwarf_addrdie (Dwarf *dbg, Dwarf_Addr addr,
239				 Dwarf_Die *result) __nonnull_attribute__ (3);
240
241/* Return child of current DIE.  */
242extern int dwarf_child (Dwarf_Die *die, Dwarf_Die *result)
243     __nonnull_attribute__ (1, 2);
244
245/* Return sibling of given DIE.  */
246extern int dwarf_siblingof (Dwarf_Die *die, Dwarf_Die *result)
247     __nonnull_attribute__ (2);
248
249/* Check whether the DIE has children.  */
250extern int dwarf_haschildren (Dwarf_Die *die) __nonnull_attribute__ (1);
251
252/* Get attributes of the DIE.  */
253extern ptrdiff_t dwarf_getattrs (Dwarf_Die *die,
254				 int (*callback) (Dwarf_Attribute *, void *),
255				 void *arg, ptrdiff_t offset)
256     __nonnull_attribute__ (2);
257
258/* Return tag of given DIE.  */
259extern int dwarf_tag (Dwarf_Die *die) __nonnull_attribute__ (1);
260
261
262/* Return specific attribute of DIE.  */
263extern Dwarf_Attribute *dwarf_attr (Dwarf_Die *die, unsigned int search_name,
264				    Dwarf_Attribute *result)
265     __nonnull_attribute__ (3);
266
267/* Check whether given DIE has specific attribute.  */
268extern int dwarf_hasattr (Dwarf_Die *die, unsigned int search_name);
269
270/* These are the same as dwarf_attr and dwarf_hasattr, respectively,
271   but they resolve an indirect attribute through DW_AT_abstract_origin.  */
272extern Dwarf_Attribute *dwarf_attr_integrate (Dwarf_Die *die,
273					      unsigned int search_name,
274					      Dwarf_Attribute *result)
275     __nonnull_attribute__ (3);
276extern int dwarf_hasattr_integrate (Dwarf_Die *die, unsigned int search_name);
277
278
279
280
281/* Check whether given attribute has specific form.  */
282extern int dwarf_hasform (Dwarf_Attribute *attr, unsigned int search_form);
283
284/* Return attribute code of given attribute.  */
285extern unsigned int dwarf_whatattr (Dwarf_Attribute *attr);
286
287/* Return form code of given attribute.  */
288extern unsigned int dwarf_whatform (Dwarf_Attribute *attr);
289
290
291/* Return string associated with given attribute.  */
292extern const char *dwarf_formstring (Dwarf_Attribute *attrp);
293
294/* Return unsigned constant represented by attribute.  */
295extern int dwarf_formudata (Dwarf_Attribute *attr, Dwarf_Word *return_uval)
296     __nonnull_attribute__ (2);
297
298/* Return signed constant represented by attribute.  */
299extern int dwarf_formsdata (Dwarf_Attribute *attr, Dwarf_Sword *return_uval)
300     __nonnull_attribute__ (2);
301
302/* Return address represented by attribute.  */
303extern int dwarf_formaddr (Dwarf_Attribute *attr, Dwarf_Addr *return_addr)
304     __nonnull_attribute__ (2);
305
306/* Return reference offset represented by attribute.  */
307extern int dwarf_formref (Dwarf_Attribute *attr, Dwarf_Off *return_offset)
308     __nonnull_attribute__ (2);
309
310/* Look up the DIE in a reference-form attribute.  */
311extern Dwarf_Die *dwarf_formref_die (Dwarf_Attribute *attr, Dwarf_Die *die_mem)
312     __nonnull_attribute__ (2);
313
314/* Return block represented by attribute.  */
315extern int dwarf_formblock (Dwarf_Attribute *attr, Dwarf_Block *return_block)
316     __nonnull_attribute__ (2);
317
318/* Return flag represented by attribute.  */
319extern int dwarf_formflag (Dwarf_Attribute *attr, bool *return_bool)
320     __nonnull_attribute__ (2);
321
322
323/* Simplified attribute value access functions.  */
324
325/* Return string in name attribute of DIE.  */
326extern const char *dwarf_diename (Dwarf_Die *die);
327
328/* Return high PC attribute of DIE.  */
329extern int dwarf_highpc (Dwarf_Die *die, Dwarf_Addr *return_addr)
330     __nonnull_attribute__ (2);
331
332/* Return low PC attribute of DIE.  */
333extern int dwarf_lowpc (Dwarf_Die *die, Dwarf_Addr *return_addr)
334     __nonnull_attribute__ (2);
335
336/* Return entry_pc or low_pc attribute of DIE.  */
337extern int dwarf_entrypc (Dwarf_Die *die, Dwarf_Addr *return_addr)
338     __nonnull_attribute__ (2);
339
340/* Return 1 if DIE's lowpc/highpc or ranges attributes match the PC address,
341   0 if not, or -1 for errors.  */
342extern int dwarf_haspc (Dwarf_Die *die, Dwarf_Addr pc);
343
344/* Enumerate the PC address ranges covered by this DIE, covering all
345   addresses where dwarf_haspc returns true.  In the first call OFFSET
346   should be zero and *BASEP need not be initialized.  Returns -1 for
347   errors, zero when there are no more address ranges to report, or a
348   nonzero OFFSET value to pass to the next call.  Each subsequent call
349   must preserve *BASEP from the prior call.  Successful calls fill in
350   *STARTP and *ENDP with a contiguous address range.  */
351extern ptrdiff_t dwarf_ranges (Dwarf_Die *die,
352			       ptrdiff_t offset, Dwarf_Addr *basep,
353			       Dwarf_Addr *startp, Dwarf_Addr *endp);
354
355
356/* Return byte size attribute of DIE.  */
357extern int dwarf_bytesize (Dwarf_Die *die);
358
359/* Return bit size attribute of DIE.  */
360extern int dwarf_bitsize (Dwarf_Die *die);
361
362/* Return bit offset attribute of DIE.  */
363extern int dwarf_bitoffset (Dwarf_Die *die);
364
365/* Return array order attribute of DIE.  */
366extern int dwarf_arrayorder (Dwarf_Die *die);
367
368/* Return source language attribute of DIE.  */
369extern int dwarf_srclang (Dwarf_Die *die);
370
371
372/* Get abbreviation at given offset for given DIE.  */
373extern Dwarf_Abbrev *dwarf_getabbrev (Dwarf_Die *die, Dwarf_Off offset,
374				      size_t *lengthp);
375
376/* Get abbreviation at given offset in .debug_abbrev section.  */
377extern int dwarf_offabbrev (Dwarf *dbg, Dwarf_Off offset, size_t *lengthp,
378			    Dwarf_Abbrev *abbrevp)
379     __nonnull_attribute__ (4);
380
381/* Get abbreviation code.  */
382extern unsigned int dwarf_getabbrevcode (Dwarf_Abbrev *abbrev);
383
384/* Get abbreviation tag.  */
385extern unsigned int dwarf_getabbrevtag (Dwarf_Abbrev *abbrev);
386
387/* Return true if abbreviation is children flag set.  */
388extern int dwarf_abbrevhaschildren (Dwarf_Abbrev *abbrev);
389
390/* Get number of attributes of abbreviation.  */
391extern int dwarf_getattrcnt (Dwarf_Abbrev *abbrev, size_t *attrcntp)
392     __nonnull_attribute__ (2);
393
394/* Get specific attribute of abbreviation.  */
395extern int dwarf_getabbrevattr (Dwarf_Abbrev *abbrev, size_t idx,
396				unsigned int *namep, unsigned int *formp,
397				Dwarf_Off *offset);
398
399
400/* Get string from-debug_str section.  */
401extern const char *dwarf_getstring (Dwarf *dbg, Dwarf_Off offset,
402				    size_t *lenp);
403
404
405/* Get public symbol information.  */
406extern ptrdiff_t dwarf_getpubnames (Dwarf *dbg,
407				    int (*callback) (Dwarf *, Dwarf_Global *,
408						     void *),
409				    void *arg, ptrdiff_t offset)
410     __nonnull_attribute__ (2);
411
412
413/* Get source file information for CU.  */
414extern int dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines,
415			      size_t *nlines) __nonnull_attribute__ (2, 3);
416
417/* Return one of the source lines of the CU.  */
418extern Dwarf_Line *dwarf_onesrcline (Dwarf_Lines *lines, size_t idx);
419
420/* Get the file source files used in the CU.  */
421extern int dwarf_getsrcfiles (Dwarf_Die *cudie, Dwarf_Files **files,
422			      size_t *nfiles)
423     __nonnull_attribute__ (2);
424
425
426/* Get source for address in CU.  */
427extern Dwarf_Line *dwarf_getsrc_die (Dwarf_Die *cudie, Dwarf_Addr addr);
428
429/* Get source for file and line number.  */
430extern int dwarf_getsrc_file (Dwarf *dbg, const char *fname, int line, int col,
431			      Dwarf_Line ***srcsp, size_t *nsrcs)
432     __nonnull_attribute__ (2, 5, 6);
433
434
435/* Return line address.  */
436extern int dwarf_lineaddr (Dwarf_Line *line, Dwarf_Addr *addrp);
437
438/* Return line number.  */
439extern int dwarf_lineno (Dwarf_Line *line, int *linep)
440     __nonnull_attribute__ (2);
441
442/* Return column in line.  */
443extern int dwarf_linecol (Dwarf_Line *line, int *colp)
444     __nonnull_attribute__ (2);
445
446/* Return true if record is for beginning of a statement.  */
447extern int dwarf_linebeginstatement (Dwarf_Line *line, bool *flagp)
448     __nonnull_attribute__ (2);
449
450/* Return true if record is for end of sequence.  */
451extern int dwarf_lineendsequence (Dwarf_Line *line, bool *flagp)
452     __nonnull_attribute__ (2);
453
454/* Return true if record is for beginning of a basic block.  */
455extern int dwarf_lineblock (Dwarf_Line *line, bool *flagp)
456     __nonnull_attribute__ (2);
457
458/* Return true if record is for end of prologue.  */
459extern int dwarf_lineprologueend (Dwarf_Line *line, bool *flagp)
460     __nonnull_attribute__ (2);
461
462/* Return true if record is for beginning of epilogue.  */
463extern int dwarf_lineepiloguebegin (Dwarf_Line *line, bool *flagp)
464     __nonnull_attribute__ (2);
465
466
467/* Find line information for address.  */
468extern const char *dwarf_linesrc (Dwarf_Line *line,
469				  Dwarf_Word *mtime, Dwarf_Word *length);
470
471/* Return file information.  */
472extern const char *dwarf_filesrc (Dwarf_Files *file, size_t idx,
473				  Dwarf_Word *mtime, Dwarf_Word *length);
474
475
476/* Return location expression, decoded as a list of operations.  */
477extern int dwarf_getlocation (Dwarf_Attribute *attr, Dwarf_Op **expr,
478			      size_t *exprlen) __nonnull_attribute__ (2, 3);
479
480/* Return location expressions.  If the attribute uses a location list,
481   ADDRESS selects the relevant location expressions from the list.
482   There can be multiple matches, resulting in multiple expressions to
483   return.  EXPRS and EXPRLENS are parallel arrays of NLOCS slots to
484   fill in.  Returns the number of locations filled in, or -1 for
485   errors.  If EXPRS is a null pointer, stores nothing and returns the
486   total number of locations.  A return value of zero means that the
487   location list indicated no value is accessible.  */
488extern int dwarf_getlocation_addr (Dwarf_Attribute *attr, Dwarf_Addr address,
489				   Dwarf_Op **exprs, size_t *exprlens,
490				   size_t nlocs);
491
492
493/* Return scope DIEs containing PC address.
494   Sets *SCOPES to a malloc'd array of Dwarf_Die structures,
495   and returns the number of elements in the array.
496   (*SCOPES)[0] is the DIE for the innermost scope containing PC,
497   (*SCOPES)[1] is the DIE for the scope containing that scope, and so on.
498   Returns -1 for errors or 0 if no scopes match PC.  */
499extern int dwarf_getscopes (Dwarf_Die *cudie, Dwarf_Addr pc,
500			    Dwarf_Die **scopes);
501
502/* Return scope DIEs containing the given DIE.
503   Sets *SCOPES to a malloc'd array of Dwarf_Die structures,
504   and returns the number of elements in the array.
505   (*SCOPES)[0] is a copy of DIE.
506   (*SCOPES)[1] is the DIE for the scope containing that scope, and so on.
507   Returns -1 for errors or 0 if DIE is not found in any scope entry.  */
508extern int dwarf_getscopes_die (Dwarf_Die *die, Dwarf_Die **scopes);
509
510
511/* Search SCOPES[0..NSCOPES-1] for a variable called NAME.
512   Ignore the first SKIP_SHADOWS scopes that match the name.
513   If MATCH_FILE is not null, accept only declaration in that source file;
514   if MATCH_LINENO or MATCH_LINECOL are also nonzero, accept only declaration
515   at that line and column.
516
517   If successful, fill in *RESULT with the DIE of the variable found,
518   and return N where SCOPES[N] is the scope defining the variable.
519   Return -1 for errors or -2 for no matching variable found.  */
520extern int dwarf_getscopevar (Dwarf_Die *scopes, int nscopes,
521			      const char *name, int skip_shadows,
522			      const char *match_file,
523			      int match_lineno, int match_linecol,
524			      Dwarf_Die *result);
525
526
527
528/* Return list address ranges.  */
529extern int dwarf_getaranges (Dwarf *dbg, Dwarf_Aranges **aranges,
530			     size_t *naranges)
531     __nonnull_attribute__ (2);
532
533/* Return one of the address range entries.  */
534extern Dwarf_Arange *dwarf_onearange (Dwarf_Aranges *aranges, size_t idx);
535
536/* Return information in address range record.  */
537extern int dwarf_getarangeinfo (Dwarf_Arange *arange, Dwarf_Addr *addrp,
538				Dwarf_Word *lengthp, Dwarf_Off *offsetp);
539
540/* Get address range which includes given address.  */
541extern Dwarf_Arange *dwarf_getarange_addr (Dwarf_Aranges *aranges,
542					   Dwarf_Addr addr);
543
544
545
546/* Get functions in CUDIE.  */
547extern ptrdiff_t dwarf_getfuncs (Dwarf_Die *cudie,
548				 int (*callback) (Dwarf_Die *, void *),
549				 void *arg, ptrdiff_t offset);
550
551
552/* Return file name containing definition of the given declaration.  */
553extern const char *dwarf_decl_file (Dwarf_Die *decl);
554
555/* Get line number of beginning of given declaration.  */
556extern int dwarf_decl_line (Dwarf_Die *decl, int *linep)
557     __nonnull_attribute__ (2);
558
559/* Get column number of beginning of given declaration.  */
560extern int dwarf_decl_column (Dwarf_Die *decl, int *colp)
561     __nonnull_attribute__ (2);
562
563
564/* Return nonzero if given function is an abstract inline definition.  */
565extern int dwarf_func_inline (Dwarf_Die *func);
566
567/* Find each concrete inlined instance of the abstract inline definition.  */
568extern int dwarf_func_inline_instances (Dwarf_Die *func,
569					int (*callback) (Dwarf_Die *, void *),
570					void *arg);
571
572
573/* Find the appropriate PC location or locations for function entry
574   breakpoints for the given DW_TAG_subprogram DIE.  Returns -1 for errors.
575   On success, returns the number of breakpoint locations (never zero)
576   and sets *BKPTS to a malloc'd vector of addresses.  */
577extern int dwarf_entry_breakpoints (Dwarf_Die *die, Dwarf_Addr **bkpts);
578
579
580/* Call callback function for each of the macro information entry for
581   the CU.  */
582extern ptrdiff_t dwarf_getmacros (Dwarf_Die *cudie,
583				  int (*callback) (Dwarf_Macro *, void *),
584				  void *arg, ptrdiff_t offset)
585     __nonnull_attribute__ (2);
586
587/* Return macro opcode.  */
588extern int dwarf_macro_opcode (Dwarf_Macro *macro, unsigned int *opcodep)
589     __nonnull_attribute__ (2);
590
591/* Return first macro parameter.  */
592extern int dwarf_macro_param1 (Dwarf_Macro *macro, Dwarf_Word *paramp)
593     __nonnull_attribute__ (2);
594
595/* Return second macro parameter.  */
596extern int dwarf_macro_param2 (Dwarf_Macro *macro, Dwarf_Word *paramp,
597			       const char **strp);
598
599
600/* Return error code of last failing function call.  This value is kept
601   separately for each thread.  */
602extern int dwarf_errno (void);
603
604/* Return error string for ERROR.  If ERROR is zero, return error string
605   for most recent error or NULL is none occurred.  If ERROR is -1 the
606   behaviour is similar to the last case except that not NULL but a legal
607   string is returned.  */
608extern const char *dwarf_errmsg (int err);
609
610
611/* Register new Out-Of-Memory handler.  The old handler is returned.  */
612extern Dwarf_OOM dwarf_new_oom_handler (Dwarf *dbg, Dwarf_OOM handler);
613
614
615/* Inline optimizations.  */
616#ifdef __OPTIMIZE__
617/* Return attribute code of given attribute.  */
618extern inline unsigned int
619dwarf_whatattr (Dwarf_Attribute *attr)
620{
621  return attr == NULL ? 0 : attr->code;
622}
623
624/* Return attribute code of given attribute.  */
625extern inline unsigned int
626dwarf_whatform (Dwarf_Attribute *attr)
627{
628  return attr == NULL ? 0 : attr->form;
629}
630#endif	/* Optimize.  */
631
632#ifdef __cplusplus
633}
634#endif
635
636#endif	/* libdw.h */
637