aboutsummaryrefslogtreecommitdiff
path: root/libdwarf/libdwarfP.h
blob: 155b2f15a36ec8b97152f7457f5b54c138187b85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/* Internal definitions for libdwarf.
   Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
   This file is part of Red Hat elfutils.
   Written by Ulrich Drepper <drepper@redhat.com>, 2000.

   Red Hat elfutils is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by the
   Free Software Foundation; version 2 of the License.

   Red Hat elfutils is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with Red Hat elfutils; if not, write to the Free Software Foundation,
   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.

   Red Hat elfutils is an included package of the Open Invention Network.
   An included package of the Open Invention Network is a package for which
   Open Invention Network licensees cross-license their patents.  No patent
   license is granted, either expressly or impliedly, by designation as an
   included package.  Should you wish to participate in the Open Invention
   Network licensing program, please visit www.openinventionnetwork.com
   <http://www.openinventionnetwork.com>.  */

#ifndef _LIBDWARFP_H
#define _LIBDWARFP_H 1

#include <libdwarf.h>
#include <libintl.h>
#include <limits.h>

#include <dwarf_abbrev_hash.h>


/* Version of the DWARF specification we support.  */
#define DWARF_VERSION 2

/* Version of the CIE format.  */
#define CIE_VERSION 1

/* Some additional basic types.  */
typedef unsigned int Dwarf_Word;


/* Valid indeces for the section data.  */
enum
  {
    IDX_debug_info = 0,
    IDX_debug_abbrev,
    IDX_debug_aranges,
    IDX_debug_line,
    IDX_debug_frame,
    IDX_eh_frame,
    IDX_debug_loc,
    IDX_debug_pubnames,
    IDX_debug_str,
    IDX_debug_funcnames,
    IDX_debug_typenames,
    IDX_debug_varnames,
    IDX_debug_weaknames,
    IDX_debug_macinfo,
    IDX_last
  };


/* This is the structure representing the debugging state.  */
struct Dwarf_Debug_s
  {
#ifdef DWARF_DEBUG
    int memtag;
#endif

    Dwarf_Handler dbg_errhand;
    Dwarf_Ptr dbg_errarg;

    Elf *elf;
    int other_byte_order;

    Dwarf_Unsigned access;

    /* The section data.  */
    struct
    {
      Dwarf_Small *addr;
      Dwarf_Unsigned size;
    } sections[IDX_last];

    /* Compilation unit handling.  To enable efficient searching we
       keep track of the unit we already found.  */
    struct Dwarf_CU_Info_s
    {
      /* This is the information the 'dwarf_next_cu_header' function
	 is supposed to return.  */
      Dwarf_Unsigned header_length;
      Dwarf_Unsigned length;
      Dwarf_Unsigned abbrev_offset;
      Dwarf_Half version_stamp;
      Dwarf_Half address_size;

      Dwarf_Unsigned offset;		/* In .debug_info section.  */

      /* Used to distinguish between 32-bit and 64-bit DWARF.  */
      Dwarf_Half offset_size;

      /* Hash table for the abbreviations.  */
      Dwarf_Abbrev_Hash abbrev_hash;
      Dwarf_Unsigned last_abbrev_offset;

      Dwarf_Debug dbg;

      struct Dwarf_CU_Info_s *next;
    } *cu_list;
    struct Dwarf_CU_Info_s *cu_list_current;
    struct Dwarf_CU_Info_s *cu_list_tail;

    Dwarf_Unsigned cie_cnt;
    Dwarf_Unsigned fde_cnt;
  };
typedef struct Dwarf_CU_Info_s *Dwarf_CU_Info;


/* Memory access macros.  We have to define it here since code in the
   header needs to know the structure of Dwarf_Debug.  */
#include "memory-access.h"


/* DWARF die representation.  */
struct Dwarf_Die_s
  {
#ifdef DWARF_DEBUG
    int memtag;
#endif

    Dwarf_Small *addr;
    Dwarf_Abbrev abbrev;
    Dwarf_CU_Info cu;
  };


/* Abbreviation list.  */
struct Dwarf_Abbrev_s
  {
    Dwarf_Unsigned code;	/* The code.  */
    Dwarf_Half tag;		/* The tag.  */
    Dwarf_Small *attrp;		/* Pointer to beginning of attributes.  */
    Dwarf_Unsigned attrcnt;	/* Number of attributes.  */
    int has_children;		/* Nonzero of abbreviation has children.  */
    Dwarf_Unsigned offset;	/* Offset in the .debug_abbrev section.  */
  };


/* Attribute list.  */
struct Dwarf_Attribute_s
  {
    Dwarf_Half code;		/* DWARF attribute code.  */
    Dwarf_Half form;		/* DWARF form.  */
    Dwarf_Small *valp;
    Dwarf_CU_Info cu;
  };


/* Structure for error values.  */
struct Dwarf_Error_s
  {
    unsigned int de_error;
  };


/* Files in line information records.  */
typedef struct Dwarf_File_s
  {
    Dwarf_Debug dbg;
    unsigned int nfiles;
    struct Dwarf_Fileinfo_s
    {
      char *name;
      Dwarf_Unsigned mtime;
      Dwarf_Unsigned length;
    } info[0];
  } *Dwarf_File;
typedef struct Dwarf_Fileinfo_s Dwarf_Fileinfo;


/* Representation of a row in the line table.  */
struct Dwarf_Line_s
  {
    Dwarf_Addr addr;
    unsigned int file;
    int line;
    unsigned short int column;
    unsigned int is_stmt:1;
    unsigned int basic_block:1;
    unsigned int end_sequence:1;
    unsigned int prologue_end:1;
    unsigned int epilogue_begin:1;

    Dwarf_File files;
  };


/* Additional, shared information required for Dwarf_Global handling.  */
typedef struct Dwarf_Global_Info_s
  {
    Dwarf_Debug dbg;
    Dwarf_Unsigned offset;
  } *Dwarf_Global_Info;

/* Representation of a global name entry.  */
struct Dwarf_Global_s
  {
    Dwarf_Unsigned offset;
    char *name;
    Dwarf_Global_Info info;
  };


/* Additional, shared information required for Dwarf_Arange handling.  */
typedef struct Dwarf_Arange_Info_s
  {
    Dwarf_Debug dbg;
    Dwarf_Unsigned offset;
  } *Dwarf_Arange_Info;

/* Representation of an address range entry.  */
struct Dwarf_Arange_s
  {
    Dwarf_Addr address;
    Dwarf_Unsigned length;
    Dwarf_Arange_Info info;
  };


/* Representation of a common information entry.  */
struct Dwarf_Cie_s
  {
    Dwarf_Debug dbg;
    Dwarf_Unsigned length;
    char *augmentation;
    Dwarf_Unsigned code_alignment_factor;
    Dwarf_Signed data_alignment_factor;
    Dwarf_Small *initial_instructions;
    Dwarf_Unsigned initial_instructions_length;
    Dwarf_Small return_address_register;
    Dwarf_Unsigned offset;
    Dwarf_Signed index;
  };


/* Representation of a frame descriptor entry.  */
struct Dwarf_Fde_s
  {
    Dwarf_Cie cie;
    Dwarf_Addr initial_location;
    Dwarf_Unsigned address_range;
    Dwarf_Small *instructions;
    Dwarf_Unsigned instructions_length;
    Dwarf_Unsigned offset;
    Dwarf_Small *fde_bytes;
    Dwarf_Unsigned fde_byte_length;
  };


/* Internal error values.  */
enum
  {
    DW_E_NOERROR = 0,
    DW_E_INVALID_ACCESS,
    DW_E_NO_REGFILE,
    DW_E_IO_ERROR,
    DW_E_NOMEM,
    DW_E_NOELF,
    DW_E_GETEHDR_ERROR,
    DW_E_INVALID_ELF,
    DW_E_INVALID_DWARF,
    DW_E_NO_DWARF,
    DW_E_NO_CU,
    DW_E_1ST_NO_CU,
    DW_E_INVALID_OFFSET,
    DW_E_INVALID_REFERENCE,
    DW_E_NO_REFERENCE,
    DW_E_NO_ADDR,
    DW_E_NO_FLAG,
    DW_E_NO_CONSTANT,
    DW_E_NO_BLOCK,
    DW_E_NO_STRING,
    DW_E_WRONG_ATTR,
    DW_E_NO_DATA,
    DW_E_NO_DEBUG_LINE,
    DW_E_VERSION_ERROR,
    DW_E_INVALID_DIR_IDX,
    DW_E_INVALID_ADDR,
    DW_E_NO_ABBR,
  };


/* Handle error according to user's wishes.  */
extern void __libdwarf_error (Dwarf_Debug dbg, Dwarf_Error *err, int errval)
     internal_function;


/* Find CU at given offset.  */
extern int __libdwarf_get_cu_at_offset (Dwarf_Debug dbg, Dwarf_Unsigned offset,
					Dwarf_CU_Info *result_cu,
					Dwarf_Error *err) internal_function;

/* Find abbreviation.  */
extern Dwarf_Abbrev __libdwarf_get_abbrev (Dwarf_Debug dbg,
					   Dwarf_CU_Info cu,
					   Dwarf_Word code,
					   Dwarf_Error *err)
     internal_function;

/* Get constant type attribute value.  */
extern int __libdwarf_getconstant (Dwarf_Die die, Dwarf_Half name,
				   Dwarf_Unsigned *return_size,
				   Dwarf_Error *err) internal_function;

/* Determine length of form parameters.  */
extern int __libdwarf_form_val_len (Dwarf_Debug dbg, Dwarf_CU_Info cu,
				    Dwarf_Word form, Dwarf_Small *valp,
				    size_t *len, Dwarf_Error *err)
     internal_function;


/* gettext helper macros.  */
#define _(Str) dgettext ("libdwarf", Str)
#define N_(Str) Str

#endif	/* libdwarfP.h */