Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame^] | 1 | /* Internal definitions for libdwarf. |
| 2 | Copyright (C) 2000, 2001, 2002 Red Hat, Inc. |
| 3 | Written by Ulrich Drepper <drepper@redhat.com>, 2000. |
| 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 _LIBDWARFP_H |
| 16 | #define _LIBDWARFP_H 1 |
| 17 | |
| 18 | #include <libdwarf.h> |
| 19 | #include <libintl.h> |
| 20 | #include <limits.h> |
| 21 | |
| 22 | #include <dwarf_abbrev_hash.h> |
| 23 | |
| 24 | |
| 25 | /* Version of the DWARF specification we support. */ |
| 26 | #define DWARF_VERSION 2 |
| 27 | |
| 28 | /* Version of the CIE format. */ |
| 29 | #define CIE_VERSION 1 |
| 30 | |
| 31 | /* Some additional basic types. */ |
| 32 | typedef unsigned int Dwarf_Word; |
| 33 | |
| 34 | |
| 35 | /* Valid indeces for the section data. */ |
| 36 | enum |
| 37 | { |
| 38 | IDX_debug_info = 0, |
| 39 | IDX_debug_abbrev, |
| 40 | IDX_debug_aranges, |
| 41 | IDX_debug_line, |
| 42 | IDX_debug_frame, |
| 43 | IDX_eh_frame, |
| 44 | IDX_debug_loc, |
| 45 | IDX_debug_pubnames, |
| 46 | IDX_debug_str, |
| 47 | IDX_debug_funcnames, |
| 48 | IDX_debug_typenames, |
| 49 | IDX_debug_varnames, |
| 50 | IDX_debug_weaknames, |
| 51 | IDX_debug_macinfo, |
| 52 | IDX_last |
| 53 | }; |
| 54 | |
| 55 | |
| 56 | /* This is the structure representing the debugging state. */ |
| 57 | struct Dwarf_Debug_s |
| 58 | { |
| 59 | #ifdef DWARF_DEBUG |
| 60 | int memtag; |
| 61 | #endif |
| 62 | |
| 63 | Dwarf_Handler dbg_errhand; |
| 64 | Dwarf_Ptr dbg_errarg; |
| 65 | |
| 66 | Elf *elf; |
| 67 | int other_byte_order; |
| 68 | |
| 69 | Dwarf_Unsigned access; |
| 70 | |
| 71 | /* The section data. */ |
| 72 | struct |
| 73 | { |
| 74 | Dwarf_Small *addr; |
| 75 | Dwarf_Unsigned size; |
| 76 | } sections[IDX_last]; |
| 77 | |
| 78 | /* Compilation unit handling. To enable efficient searching we |
| 79 | keep track of the unit we already found. */ |
| 80 | struct Dwarf_CU_Info_s |
| 81 | { |
| 82 | /* This is the information the 'dwarf_next_cu_header' function |
| 83 | is supposed to return. */ |
| 84 | Dwarf_Unsigned header_length; |
| 85 | Dwarf_Unsigned length; |
| 86 | Dwarf_Unsigned abbrev_offset; |
| 87 | Dwarf_Half version_stamp; |
| 88 | Dwarf_Half address_size; |
| 89 | |
| 90 | Dwarf_Unsigned offset; /* In .debug_info section. */ |
| 91 | |
| 92 | /* Used to distinguish between 32-bit and 64-bit DWARF. */ |
| 93 | Dwarf_Half offset_size; |
| 94 | |
| 95 | /* Hash table for the abbreviations. */ |
| 96 | Dwarf_Abbrev_Hash abbrev_hash; |
| 97 | Dwarf_Unsigned last_abbrev_offset; |
| 98 | |
| 99 | Dwarf_Debug dbg; |
| 100 | |
| 101 | struct Dwarf_CU_Info_s *next; |
| 102 | } *cu_list; |
| 103 | struct Dwarf_CU_Info_s *cu_list_current; |
| 104 | struct Dwarf_CU_Info_s *cu_list_tail; |
| 105 | |
| 106 | Dwarf_Unsigned cie_cnt; |
| 107 | Dwarf_Unsigned fde_cnt; |
| 108 | }; |
| 109 | typedef struct Dwarf_CU_Info_s *Dwarf_CU_Info; |
| 110 | |
| 111 | |
| 112 | /* Memory access macros. We have to define it here since code in the |
| 113 | header needs to know the structure of Dwarf_Debug. */ |
| 114 | #include "memory-access.h" |
| 115 | |
| 116 | |
| 117 | /* DWARF die representation. */ |
| 118 | struct Dwarf_Die_s |
| 119 | { |
| 120 | #ifdef DWARF_DEBUG |
| 121 | int memtag; |
| 122 | #endif |
| 123 | |
| 124 | Dwarf_Small *addr; |
| 125 | Dwarf_Abbrev abbrev; |
| 126 | Dwarf_CU_Info cu; |
| 127 | }; |
| 128 | |
| 129 | |
| 130 | /* Abbreviation list. */ |
| 131 | struct Dwarf_Abbrev_s |
| 132 | { |
| 133 | Dwarf_Unsigned code; /* The code. */ |
| 134 | Dwarf_Half tag; /* The tag. */ |
| 135 | Dwarf_Small *attrp; /* Pointer to beginning of attributes. */ |
| 136 | Dwarf_Unsigned attrcnt; /* Number of attributes. */ |
| 137 | int has_children; /* Nonzero of abbreviation has children. */ |
| 138 | Dwarf_Unsigned offset; /* Offset in the .debug_abbrev section. */ |
| 139 | }; |
| 140 | |
| 141 | |
| 142 | /* Attribute list. */ |
| 143 | struct Dwarf_Attribute_s |
| 144 | { |
| 145 | Dwarf_Half code; /* DWARF attribute code. */ |
| 146 | Dwarf_Half form; /* DWARF form. */ |
| 147 | Dwarf_Small *valp; |
| 148 | Dwarf_CU_Info cu; |
| 149 | }; |
| 150 | |
| 151 | |
| 152 | /* Structure for error values. */ |
| 153 | struct Dwarf_Error_s |
| 154 | { |
| 155 | unsigned int de_error; |
| 156 | }; |
| 157 | |
| 158 | |
| 159 | /* Files in line information records. */ |
| 160 | typedef struct Dwarf_File_s |
| 161 | { |
| 162 | Dwarf_Debug dbg; |
| 163 | unsigned int nfiles; |
| 164 | struct Dwarf_Fileinfo_s |
| 165 | { |
| 166 | char *name; |
| 167 | Dwarf_Unsigned mtime; |
| 168 | Dwarf_Unsigned length; |
| 169 | } info[0]; |
| 170 | } *Dwarf_File; |
| 171 | typedef struct Dwarf_Fileinfo_s Dwarf_Fileinfo; |
| 172 | |
| 173 | |
| 174 | /* Representation of a row in the line table. */ |
| 175 | struct Dwarf_Line_s |
| 176 | { |
| 177 | Dwarf_Addr addr; |
| 178 | unsigned int file; |
| 179 | int line; |
| 180 | unsigned short int column; |
| 181 | unsigned int is_stmt:1; |
| 182 | unsigned int basic_block:1; |
| 183 | unsigned int end_sequence:1; |
| 184 | unsigned int prologue_end:1; |
| 185 | unsigned int epilogue_begin:1; |
| 186 | |
| 187 | Dwarf_File files; |
| 188 | }; |
| 189 | |
| 190 | |
| 191 | /* Additional, shared information required for Dwarf_Global handling. */ |
| 192 | typedef struct Dwarf_Global_Info_s |
| 193 | { |
| 194 | Dwarf_Debug dbg; |
| 195 | Dwarf_Unsigned offset; |
| 196 | } *Dwarf_Global_Info; |
| 197 | |
| 198 | /* Representation of a global name entry. */ |
| 199 | struct Dwarf_Global_s |
| 200 | { |
| 201 | Dwarf_Unsigned offset; |
| 202 | char *name; |
| 203 | Dwarf_Global_Info info; |
| 204 | }; |
| 205 | |
| 206 | |
| 207 | /* Additional, shared information required for Dwarf_Arange handling. */ |
| 208 | typedef struct Dwarf_Arange_Info_s |
| 209 | { |
| 210 | Dwarf_Debug dbg; |
| 211 | Dwarf_Unsigned offset; |
| 212 | } *Dwarf_Arange_Info; |
| 213 | |
| 214 | /* Representation of an address range entry. */ |
| 215 | struct Dwarf_Arange_s |
| 216 | { |
| 217 | Dwarf_Addr address; |
| 218 | Dwarf_Unsigned length; |
| 219 | Dwarf_Arange_Info info; |
| 220 | }; |
| 221 | |
| 222 | |
| 223 | /* Representation of a common information entry. */ |
| 224 | struct Dwarf_Cie_s |
| 225 | { |
| 226 | Dwarf_Debug dbg; |
| 227 | Dwarf_Unsigned length; |
| 228 | char *augmentation; |
| 229 | Dwarf_Unsigned code_alignment_factor; |
| 230 | Dwarf_Signed data_alignment_factor; |
| 231 | Dwarf_Small *initial_instructions; |
| 232 | Dwarf_Unsigned initial_instructions_length; |
| 233 | Dwarf_Small return_address_register; |
| 234 | Dwarf_Unsigned offset; |
| 235 | Dwarf_Signed index; |
| 236 | }; |
| 237 | |
| 238 | |
| 239 | /* Representation of a frame descriptor entry. */ |
| 240 | struct Dwarf_Fde_s |
| 241 | { |
| 242 | Dwarf_Cie cie; |
| 243 | Dwarf_Addr initial_location; |
| 244 | Dwarf_Unsigned address_range; |
| 245 | Dwarf_Small *instructions; |
| 246 | Dwarf_Unsigned instructions_length; |
| 247 | Dwarf_Unsigned offset; |
| 248 | Dwarf_Small *fde_bytes; |
| 249 | Dwarf_Unsigned fde_byte_length; |
| 250 | }; |
| 251 | |
| 252 | |
| 253 | /* Internal error values. */ |
| 254 | enum |
| 255 | { |
| 256 | DW_E_NOERROR = 0, |
| 257 | DW_E_INVALID_ACCESS, |
| 258 | DW_E_NO_REGFILE, |
| 259 | DW_E_IO_ERROR, |
| 260 | DW_E_NOMEM, |
| 261 | DW_E_NOELF, |
| 262 | DW_E_GETEHDR_ERROR, |
| 263 | DW_E_INVALID_ELF, |
| 264 | DW_E_INVALID_DWARF, |
| 265 | DW_E_NO_DWARF, |
| 266 | DW_E_NO_CU, |
| 267 | DW_E_1ST_NO_CU, |
| 268 | DW_E_INVALID_OFFSET, |
| 269 | DW_E_INVALID_REFERENCE, |
| 270 | DW_E_NO_REFERENCE, |
| 271 | DW_E_NO_ADDR, |
| 272 | DW_E_NO_FLAG, |
| 273 | DW_E_NO_CONSTANT, |
| 274 | DW_E_NO_BLOCK, |
| 275 | DW_E_NO_STRING, |
| 276 | DW_E_WRONG_ATTR, |
| 277 | DW_E_NO_DATA, |
| 278 | DW_E_NO_DEBUG_LINE, |
| 279 | DW_E_VERSION_ERROR, |
| 280 | DW_E_INVALID_DIR_IDX, |
| 281 | DW_E_INVALID_ADDR, |
| 282 | DW_E_NO_ABBR, |
| 283 | }; |
| 284 | |
| 285 | |
| 286 | /* Handle error according to user's wishes. */ |
| 287 | extern void __libdwarf_error (Dwarf_Debug dbg, Dwarf_Error *err, int errval) |
| 288 | internal_function; |
| 289 | |
| 290 | |
| 291 | /* Find CU at given offset. */ |
| 292 | extern int __libdwarf_get_cu_at_offset (Dwarf_Debug dbg, Dwarf_Unsigned offset, |
| 293 | Dwarf_CU_Info *result_cu, |
| 294 | Dwarf_Error *err) internal_function; |
| 295 | |
| 296 | /* Find abbreviation. */ |
| 297 | extern Dwarf_Abbrev __libdwarf_get_abbrev (Dwarf_Debug dbg, |
| 298 | Dwarf_CU_Info cu, |
| 299 | Dwarf_Word code, |
| 300 | Dwarf_Error *err) |
| 301 | internal_function; |
| 302 | |
| 303 | /* Get constant type attribute value. */ |
| 304 | extern int __libdwarf_getconstant (Dwarf_Die die, Dwarf_Half name, |
| 305 | Dwarf_Unsigned *return_size, |
| 306 | Dwarf_Error *err) internal_function; |
| 307 | |
| 308 | /* Determine length of form parameters. */ |
| 309 | extern int __libdwarf_form_val_len (Dwarf_Debug dbg, Dwarf_CU_Info cu, |
| 310 | Dwarf_Word form, Dwarf_Small *valp, |
| 311 | size_t *len, Dwarf_Error *err) |
| 312 | internal_function; |
| 313 | |
| 314 | |
| 315 | /* gettext helper macros. */ |
| 316 | #define _(Str) dgettext ("libdwarf", Str) |
| 317 | #define N_(Str) Str |
| 318 | |
| 319 | #endif /* libdwarfP.h */ |