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