xref: /illumos-gate/usr/src/lib/libdwarf/common/dwarf_macro5.h (revision 9868091de5a69073a55e3b8cc1a378cac9220edf)
1 /*
2   Copyright (C) 2015-2015 David Anderson. All Rights Reserved.
3 
4   This program is free software; you can redistribute it and/or modify it
5   under the terms of version 2.1 of the GNU Lesser General Public License
6   as published by the Free Software Foundation.
7 
8   This program is distributed in the hope that it would be useful, but
9   WITHOUT ANY WARRANTY; without even the implied warranty of
10   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 
12   Further, this software is distributed without any warranty that it is
13   free of the rightful claim of any third person regarding infringement
14   or the like.  Any license provided herein, whether implied or
15   otherwise, applies only to this software file.  Patent licenses, if
16   any, provided herein do not apply to combinations of this program with
17   other software, or any other product whatsoever.
18 
19   You should have received a copy of the GNU Lesser General Public
20   License along with this program; if not, write the Free Software
21   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
22   USA.
23 */
24 
25 /*
26    dwarf_macro5.h
27    For the DWARF5 .debug_macro section
28    (also appears as an extension to DWARF4)
29 */
30 
31 struct Dwarf_Macro_Forms_s {
32     /* Code means DW_MACRO_define etc. */
33     Dwarf_Small         mf_code;
34 
35     /* How many entries in mf_formbytes array. */
36     Dwarf_Small         mf_formcount;
37 
38     /* Never free these, these are in the object file memory */
39     const Dwarf_Small * mf_formbytes;
40 };
41 
42 struct Dwarf_Macro_OperationsList_s {
43     unsigned mol_count;
44     struct Dwarf_Macro_Forms_s * mol_data;
45 };
46 
47 struct Dwarf_Macro_Operator_s {
48     /*  mo_opcode == mo_form->mf_code */
49     Dwarf_Small      mo_opcode;
50 
51     struct Dwarf_Macro_Forms_s * mo_form;
52 
53     /*  Points at the first byte of the data, meaning
54         it points one-past the macro operation code byte. */
55     Dwarf_Small *    mo_data;
56 };
57 
58 #define MACRO_OFFSET_SIZE_FLAG 1
59 #define MACRO_LINE_OFFSET_FLAG 2
60 #define MACRO_OP_TABLE_FLAG 4
61 
62 /*  Could be reordered to be most space efficient.
63     That might be a little harder to read.  Hmm. */
64 struct Dwarf_Macro_Context_s {
65     Dwarf_Unsigned     mc_sentinel;
66     Dwarf_Half     mc_version_number;
67 
68     /* Section_offset in .debug_macro of macro header */
69     Dwarf_Unsigned mc_section_offset;
70 
71     /*  Total length of the macro data for this CU.
72         Calculated, not part of header. */
73     Dwarf_Unsigned mc_total_length;
74 
75     Dwarf_Half     mc_macro_header_length;
76 
77     Dwarf_Small    mc_flags;
78 
79     /*  If DW_MACRO_start_file is in the operators of this
80         table then the mc_debug_line_offset must be present from
81         the header. */
82     Dwarf_Unsigned mc_debug_line_offset;
83 
84     /* the following three set from the bits in mc_flags  */
85     /* If 1, offsets 64 bits */
86     Dwarf_Bool mc_offset_size_flag;
87 
88     /* if 1, debug_line offset is present. */
89     Dwarf_Bool mc_debug_line_offset_flag;
90 
91     /* 4 or 8, depending on mc_offset_size_flag */
92     Dwarf_Small    mc_offset_size;
93 
94     /*  If one the operands/opcodes (mc_opcode_forms) table is present
95         in the header. If not we use a default table.
96 
97         Even when there are operands in the  header
98         the standardops may or may not be
99         defined in the header. */
100     Dwarf_Bool mc_operands_table_flag;
101 
102     /*  Count of the Dwarf_Macro_Forms_s structs pointed to by
103         mc_opcode_forms.  These from the header. */
104     Dwarf_Small                 mc_opcode_count;
105     struct Dwarf_Macro_Forms_s *mc_opcode_forms;
106 
107     /*  mc_ops must be free()d, but pointers inside
108         mc_ops are to static or section data so must not
109         be freed. */
110     Dwarf_Unsigned                 mc_macro_ops_count;
111     Dwarf_Unsigned                 mc_ops_data_length;
112     struct Dwarf_Macro_Operator_s *mc_ops;
113 
114     Dwarf_Small * mc_macro_header;
115     Dwarf_Small * mc_macro_ops;
116 
117     /*  These are malloc space, not _dwarf_get_alloc()
118         so the  DW_DLA_MACRO_CONTEXT dealloc will
119         free them. */
120     char **       mc_srcfiles;
121     Dwarf_Signed  mc_srcfiles_count;
122 
123     /*  These are from CU DIE attribute names.
124         They may be NULL or point at data in
125         a dwarf section. Do not free().
126         This attempts to make up for the lack of a
127         base file name
128         in DWARF2,3,4 line tables.
129     */
130     const char *  mc_at_comp_dir;
131     const char *  mc_at_name;
132     /*  The following is malloc,so macro_context_s destructor
133         needs to free it. */
134     const char *  mc_file_path;
135 
136     Dwarf_Debug      mc_dbg;
137     Dwarf_CU_Context mc_cu_context;
138 };
139 
140 
141 int _dwarf_macro_constructor(Dwarf_Debug dbg, void *m);
142 void _dwarf_macro_destructor(void *m);
143