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