Debian Codegraph @

src/lib/libdwarf/dwarf_rnglists.h

raw
1 /*
2 Copyright (c) 2020-2023, David Anderson
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with
6 or without modification, are permitted provided that the
7 following conditions are met:
8
9 Redistributions of source code must retain the above
10 copyright notice, this list of conditions and the following
11 disclaimer.
12
13 Redistributions in binary form must reproduce the above
14 copyright notice, this list of conditions and the following
15 disclaimer in the documentation and/or other materials
16 provided with the distribution.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 #ifndef DWARF_RNGLISTS_H
33 #define DWARF_RNGLISTS_H
34 #ifdef __cplusplus
35 extern "C" {
36 #endif /* __cplusplus */
37
38 #define RNGLISTS_MAGIC 0xabcd
39
40 /* Rangelists header for a CU. The
41 type is never visible to libdwarf callers */
42 struct Dwarf_Rnglists_Context_s {
43 Dwarf_Debug rc_dbg;
44 Dwarf_Unsigned rc_index; /* An index assigned by
45 libdwarf to each rnglists context. Starting
46 with zero at the zero offset in .debug_rnglists. */
47
48 /* Offset of the .debug_rnglists header involved. */
49 Dwarf_Unsigned rc_header_offset;
50 Dwarf_Unsigned rc_length;
51
52 /* Many places in in libdwarf this is called length_size. */
53 Dwarf_Small rc_offset_size;
54 unsigned long rc_magic;
55
56 /* rc_extension_size is zero unless this is standard
57 DWARF3 and later 64bit dwarf using the extension mechanism.
58 64bit DWARF3 and later: rc_extension_size is 4.
59 64bit DWARF2 MIPS/IRIX: rc_extension_size is zero.
60 32bit DWARF: rc_extension_size is zero. */
61 Dwarf_Small rc_extension_size;
62
63 unsigned rc_version; /* 5 */
64 Dwarf_Small rc_address_size;
65 Dwarf_Small rc_segment_selector_size;
66
67 /* The next three are the table of offsets.
68 used by DW_FORM_rnglistx.
69 The count may be zero if no DW_FORM_rnglistx.
70 If they exist the
71 index values in the array are offsets into area starting
72 with rc_first_rnglist_offset */
73 Dwarf_Unsigned rc_offset_entry_count;
74 /* rc_offset_entry_count values. Each local offset to
75 a locdesc set. We need this as a way to know
76 which lle entry offsets are relevant from a loclistx.
77 as nothing else reveals these special LLE entries. */
78 Dwarf_Unsigned *rc_offset_value_array;
79
80 /* offset in the section of the offset entries */
81 Dwarf_Unsigned rc_offsets_off_in_sect;
82
83 /* Do not free. Points into section memory */
84 Dwarf_Small * rc_offsets_array;
85 /* End table of offsets */
86
87 /* Now to the rnglists. If DW_AT_ranges FORM is
88 DW_FORM_sec_offset those offsets are inside
89 here.
90 Offset in the .debug_rnglists section of the
91 first rangelist in the set of rangelists for the
92 CU. */
93 Dwarf_Unsigned rc_first_rnglist_offset;
94 Dwarf_Unsigned rc_past_last_rnglist_offset;
95
96 /* pointer to 1st byte of rangelist header*/
97 Dwarf_Small * rc_rnglists_header;
98 /* pointer to first byte of the rnglist data
99 for rnglist involved. Do not free. */
100 Dwarf_Small *rc_startaddr;
101 /* pointer one past end of the rnglist data. */
102 Dwarf_Small *rc_endaddr;
103 };
104
105 typedef struct Dwarf_Rnglists_Entry_s *Dwarf_Rnglists_Entry;
106 struct Dwarf_Rnglists_Entry_s {
107 unsigned rle_entrylen;
108 unsigned rle_code;
109 /* Failed means .debug_addr section needed but missing.
110 (possibly tied file needed) */
111 Dwarf_Bool rle_index_failed;
112 Dwarf_Unsigned rle_raw1;
113 Dwarf_Unsigned rle_raw2;
114 /* Cooked means the raw values from the .debug_rnglists
115 section translated to CU-specific addresses. */
116 Dwarf_Unsigned rle_cooked1;
117 Dwarf_Unsigned rle_cooked2;
118 Dwarf_Rnglists_Entry rle_next;
119 };
120
121 struct Dwarf_Rnglists_Head_s {
122 Dwarf_Rnglists_Entry *rh_rnglists;
123 /* rh_last and rh_first used during build-up.
124 Zero when array rh_rnglists built. */
125 Dwarf_Rnglists_Entry rh_first;
126 Dwarf_Rnglists_Entry rh_last;
127 Dwarf_Unsigned rh_count;
128 Dwarf_Unsigned rh_bytes_total;
129
130 /* A global Rnglists Context, */
131 unsigned long rh_magic;
132 Dwarf_CU_Context rh_context;
133 Dwarf_Debug rh_dbg;
134 Dwarf_Rnglists_Context rh_localcontext;
135 Dwarf_Unsigned rh_version;
136 Dwarf_Unsigned rh_index;
137 Dwarf_Unsigned rh_offset_size;
138 Dwarf_Unsigned rh_address_size;
139 unsigned rh_segment_selector_size;
140
141 /* DW_AT_rnglists_base */
142 Dwarf_Bool rh_at_rnglists_base_present;
143 Dwarf_Unsigned rh_at_rnglists_base;
144
145 /* DW_AT_low_pc of CU or zero if none. */
146 Dwarf_Bool rh_cu_base_address_present;
147 Dwarf_Unsigned rh_cu_base_address;
148
149 /* DW_AT_addr_base, so we can use .debug_addr
150 if such is needed. */
151 Dwarf_Bool rh_cu_addr_base_offset_present;
152 Dwarf_Unsigned rh_cu_addr_base_offset;
153 Dwarf_Small * rh_rlepointer;
154 Dwarf_Unsigned rh_rlearea_offset;
155 Dwarf_Small * rh_end_data_area;
156 };
157
158 int _dwarf_internal_read_rnglists_header(Dwarf_Debug dbg,
159 Dwarf_Bool build_offsets_array,
160 Dwarf_Unsigned contextnum,
161 Dwarf_Unsigned sectionlength,
162 Dwarf_Small *data,
163 Dwarf_Small *end_data,
164 Dwarf_Unsigned offset,
165 Dwarf_Rnglists_Context buildhere,
166 Dwarf_Unsigned *next_offset,
167 Dwarf_Error *error);
168
169 void _dwarf_rnglists_head_destructor(void *m);
170
171 #ifdef __cplusplus
172 }
173 #endif /* __cplusplus */
174 #endif /* DWARF_RNGLISTS_H */