xref: /illumos-gate/usr/src/lib/libdwarf/common/dwarf_loclists.h (revision a92282e44f968185a6bba094d1e5fece2da819cf)
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_LOCLISTS_H
33 #define DWARF_LOCLISTS_H
34 #ifdef __cplusplus
35 extern "C" {
36 #endif /* __cplusplus */
37 
38 #if 0
39 /*  THIS IS NOT IN FINAL FORM!! BE WARNED! */
40 
41 /*  Loclists header for a CU. The
42     type is never visible to libdwarf callers  */
43 typedef struct Dwarf_Loclists_Context_s *Dwarf_Loclists_Context;
44 struct Dwarf_Loclists_Context_s {
45     Dwarf_Debug    lc_dbg;
46     Dwarf_Unsigned lc_index; /* An index  assigned by
47         libdwarf to each loclists context. Starting
48         with zero at the zero offset in .debug_loclists. */
49 
50     /* Offset of the .debug_loclists header involved. */
51     Dwarf_Unsigned  lc_header_offset;
52     Dwarf_Unsigned  lc_length;
53 
54     /* Many places in in libdwarf this is called length_size. */
55     Dwarf_Small     lc_offset_size;
56 
57     /*  rc_extension_size is zero unless this is standard
58         DWARF3 and later 64bit dwarf using the extension mechanism.
59         64bit DWARF3 and later: rc_extension_size is 4.
60         64bit DWARF2 MIPS/IRIX: rc_extension_size is zero.
61         32bit DWARF:            rc_extension_size is zero.  */
62     Dwarf_Small     lc_extension_size;
63 
64     unsigned        lc_version; /* 5 */
65     Dwarf_Small     lc_address_size;
66     Dwarf_Small     lc_segment_selector_size;
67     Dwarf_Unsigned  lc_offset_entry_count;
68 
69     /* offset in the section of the offset entries */
70     Dwarf_Unsigned  lc_offsets_off_in_sect;
71 
72     /* Do not free. Points into section memory */
73     Dwarf_Small   * lc_offsets_array;
74 
75     /*  Offset in the .debug_loclists section of the
76         first loclist in the set of loclists for the
77         CU. */
78     Dwarf_Unsigned  lc_first_loclist_offset;
79     Dwarf_Unsigned  lc_past_last_loclist_offset;
80 
81     /* pointer to 1st byte of loclist header*/
82     Dwarf_Small *  lc_loclists_header;
83     /*  pointer to first byte of the loclist data
84         for loclist involved. Do not free. */
85     Dwarf_Small    *lc_startaddr;
86     /*  pointer one past end of the loclist data. */
87     Dwarf_Small    *lc_endaddr;
88 };
89 
90 typedef struct Dwarf_Loclists_Entry_s *Dwarf_Loclists_Entry;
91 struct Dwarf_Loclists_Entry_s {
92     unsigned       lle_entrylen;
93     unsigned       lle_code;
94     Dwarf_Unsigned lle_raw1;
95     Dwarf_Unsigned lle_raw2;
96     /*  Cooked means the raw values from the .debug_loclists
97         section translated to DIE-specific addresses. */
98     Dwarf_Unsigned lle_cooked1;
99     Dwarf_Unsigned lle_cooked2;
100     Dwarf_Loclists_Entry lle_next;
101 };
102 
103 
104 struct Dwarf_Loclists_Head_s {
105     Dwarf_Loclists_Entry *lh_loclists;
106     /*  rh_last and rh_first used during build-up.
107         Zero when array rh_loclists built. */
108     Dwarf_Loclists_Entry  lh_first;
109     Dwarf_Loclists_Entry  lh_last;
110     Dwarf_Unsigned        lh_count;
111     Dwarf_Unsigned        lh_bytes_total;
112 
113     /*  A global Loclists  Context, */
114     Dwarf_CU_Context      lh_context;
115     Dwarf_Debug           lh_dbg;
116     Dwarf_Loclists_Context lh_localcontext;
117     Dwarf_Unsigned         lh_version;
118     Dwarf_Unsigned         lh_index;
119     Dwarf_Unsigned         lh_offset_size;
120     Dwarf_Unsigned         lh_address_size;
121     unsigned               lh_segment_selector_size;
122 
123     /*  DW_AT_loclists_base */
124     Dwarf_Bool      lh_at_loclists_base_present;
125     Dwarf_Unsigned  lh_at_loclists_base;
126 
127     /* DW_AT_low_pc of CU or zero if none. */
128     Dwarf_Bool      lh_cu_base_address_present;
129     Dwarf_Unsigned  lh_cu_base_address;
130 
131     /*  DW_AT_addr_base, so we can use .debug_addr
132         if such is needed. */
133     Dwarf_Bool      lh_cu_addr_base_present;
134     Dwarf_Unsigned  lh_cu_addr_base;
135     Dwarf_Small    * lh_rlepointer;
136     Dwarf_Unsigned   lh_rlearea_offset;
137     Dwarf_Small    * lh_end_data_area;
138 };
139 #endif
140 
141 void _dwarf_loclists_head_destructor(void *l);
142 
143 #ifdef __cplusplus
144 }
145 #endif /* __cplusplus */
146 #endif /* DWARF_LOCLISTS_H */
147