xref: /illumos-gate/usr/src/lib/libdwarf/common/dwarf_rnglists.h (revision 20a7641f9918de8574b8b3b47dbe35c4bfc78df1)
1 /*
2 Copyright (c) 2020, 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 /*  Rangelists header for a CU. The
39     type is never visible to libdwarf callers  */
40 struct Dwarf_Rnglists_Context_s {
41     Dwarf_Debug    rc_dbg;
42     Dwarf_Unsigned rc_index; /* An index  assigned by
43         libdwarf to each rnglists context. Starting
44         with zero at the zero offset in .debug_rnglists. */
45 
46     /* Offset of the .debug_rnglists header involved. */
47     Dwarf_Unsigned  rc_header_offset;
48     Dwarf_Unsigned  rc_length;
49 
50     /* Many places in in libdwarf this is called length_size. */
51     Dwarf_Small     rc_offset_size;
52 
53     /*  rc_extension_size is zero unless this is standard
54         DWARF3 and later 64bit dwarf using the extension mechanism.
55         64bit DWARF3 and later: rc_extension_size is 4.
56         64bit DWARF2 MIPS/IRIX: rc_extension_size is zero.
57         32bit DWARF:            rc_extension_size is zero.  */
58     Dwarf_Small     rc_extension_size;
59 
60     unsigned        rc_version; /* 5 */
61     Dwarf_Small     rc_address_size;
62     Dwarf_Small     rc_segment_selector_size;
63     Dwarf_Unsigned  rc_offset_entry_count;
64 
65     /* offset in the section of the offset entries */
66     Dwarf_Unsigned  rc_offsets_off_in_sect;
67 
68     /* Do not free. Points into section memory */
69     Dwarf_Small   * rc_offsets_array;
70 
71     /*  Offset in the .debug_rnglists section of the
72         first rangelist in the set of rangelists for the
73         CU. */
74     Dwarf_Unsigned  rc_first_rnglist_offset;
75     Dwarf_Unsigned  rc_past_last_rnglist_offset;
76 
77     /* pointer to 1st byte of rangelist header*/
78     Dwarf_Small *  rc_rnglists_header;
79     /*  pointer to first byte of the rnglist data
80         for rnglist involved. Do not free. */
81     Dwarf_Small    *rc_startaddr;
82     /*  pointer one past end of the rnglist data. */
83     Dwarf_Small    *rc_endaddr;
84 };
85 
86 struct Dwarf_Rnglists_Entry_s {
87     unsigned       rle_entrylen;
88     unsigned       rle_code;
89     Dwarf_Unsigned rle_raw1;
90     Dwarf_Unsigned rle_raw2;
91     /*  Cooked means the raw values from the .debug_rnglists
92         section translated to DIE-specific addresses. */
93     Dwarf_Unsigned rle_cooked1;
94     Dwarf_Unsigned rle_cooked2;
95     Dwarf_Rnglists_Entry rle_next;
96 };
97 
98 
99 struct Dwarf_Rnglists_Head_s {
100     Dwarf_Rnglists_Entry *rh_rnglists;
101     /*  rh_last and rh_first used during build-up.
102         Zero when array rh_rnglists built. */
103     Dwarf_Rnglists_Entry  rh_first;
104     Dwarf_Rnglists_Entry  rh_last;
105     Dwarf_Unsigned        rh_count;
106     Dwarf_Unsigned        rh_bytes_total;
107 
108     /*  A global Rnglists Context, */
109     Dwarf_CU_Context      rh_context;
110     Dwarf_Debug           rh_dbg;
111     Dwarf_Rnglists_Context rh_localcontext;
112     Dwarf_Unsigned         rh_version;
113     Dwarf_Unsigned         rh_index;
114     Dwarf_Unsigned         rh_offset_size;
115     Dwarf_Unsigned         rh_address_size;
116     unsigned               rh_segment_selector_size;
117 
118     /*  DW_AT_rnglists_base */
119     Dwarf_Bool      rh_at_rnglists_base_present;
120     Dwarf_Unsigned  rh_at_rnglists_base;
121 
122     /* DW_AT_low_pc of CU or zero if none. */
123     Dwarf_Bool      rh_cu_base_address_present;
124     Dwarf_Unsigned  rh_cu_base_address;
125 
126     /*  DW_AT_addr_base, so we can use .debug_addr
127         if such is needed. */
128     Dwarf_Bool      rh_cu_addr_base_present;
129     Dwarf_Unsigned  rh_cu_addr_base;
130     Dwarf_Small    * rh_rlepointer;
131     Dwarf_Unsigned   rh_rlearea_offset;
132     Dwarf_Small    * rh_end_data_area;
133 };
134 
135 void _dwarf_rnglists_head_destructor(void *m);
136 
137 #ifdef __cplusplus
138 }
139 #endif /* __cplusplus */
140 #endif /* DWARF_RNGLISTS_H */
141