rdwarf 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +28 -0
- data/README.md +39 -0
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/ext/rdwarf/depend +5 -0
- data/ext/rdwarf/extconf.rb +29 -0
- data/ext/rdwarf/libdwarf/CHANGES +102 -0
- data/ext/rdwarf/libdwarf/CODINGSTYLE +71 -0
- data/ext/rdwarf/libdwarf/COPYING +28 -0
- data/ext/rdwarf/libdwarf/ChangeLog +619 -0
- data/ext/rdwarf/libdwarf/ChangeLog2006 +835 -0
- data/ext/rdwarf/libdwarf/ChangeLog2007 +217 -0
- data/ext/rdwarf/libdwarf/ChangeLog2008 +263 -0
- data/ext/rdwarf/libdwarf/ChangeLog2009 +348 -0
- data/ext/rdwarf/libdwarf/ChangeLog2010 +175 -0
- data/ext/rdwarf/libdwarf/ChangeLog2011 +297 -0
- data/ext/rdwarf/libdwarf/ChangeLog2012 +131 -0
- data/ext/rdwarf/libdwarf/ChangeLog2013 +238 -0
- data/ext/rdwarf/libdwarf/ChangeLog2014 +399 -0
- data/ext/rdwarf/libdwarf/LGPL.txt +504 -0
- data/ext/rdwarf/libdwarf/LIBDWARFCOPYRIGHT +40 -0
- data/ext/rdwarf/libdwarf/Makefile.in +220 -0
- data/ext/rdwarf/libdwarf/NEWS +535 -0
- data/ext/rdwarf/libdwarf/README +235 -0
- data/ext/rdwarf/libdwarf/checkexamples.c +1179 -0
- data/ext/rdwarf/libdwarf/cmplrs/dwarf_addr_finder.h +55 -0
- data/ext/rdwarf/libdwarf/common.c +62 -0
- data/ext/rdwarf/libdwarf/common.h +38 -0
- data/ext/rdwarf/libdwarf/config.h.in +146 -0
- data/ext/rdwarf/libdwarf/configure +5581 -0
- data/ext/rdwarf/libdwarf/configure.in +167 -0
- data/ext/rdwarf/libdwarf/dw-linetableheader.txt +39 -0
- data/ext/rdwarf/libdwarf/dwarf.h +1342 -0
- data/ext/rdwarf/libdwarf/dwarf_abbrev.c +291 -0
- data/ext/rdwarf/libdwarf/dwarf_abbrev.h +45 -0
- data/ext/rdwarf/libdwarf/dwarf_addr_finder.c +676 -0
- data/ext/rdwarf/libdwarf/dwarf_alloc.c +685 -0
- data/ext/rdwarf/libdwarf/dwarf_alloc.h +38 -0
- data/ext/rdwarf/libdwarf/dwarf_arange.c +595 -0
- data/ext/rdwarf/libdwarf/dwarf_arange.h +62 -0
- data/ext/rdwarf/libdwarf/dwarf_base_types.h +157 -0
- data/ext/rdwarf/libdwarf/dwarf_die_deliv.c +1802 -0
- data/ext/rdwarf/libdwarf/dwarf_die_deliv.h +46 -0
- data/ext/rdwarf/libdwarf/dwarf_elf_access.c +1348 -0
- data/ext/rdwarf/libdwarf/dwarf_elf_access.h +46 -0
- data/ext/rdwarf/libdwarf/dwarf_error.c +492 -0
- data/ext/rdwarf/libdwarf/dwarf_error.h +53 -0
- data/ext/rdwarf/libdwarf/dwarf_form.c +1302 -0
- data/ext/rdwarf/libdwarf/dwarf_frame.c +2454 -0
- data/ext/rdwarf/libdwarf/dwarf_frame.h +418 -0
- data/ext/rdwarf/libdwarf/dwarf_frame2.c +1533 -0
- data/ext/rdwarf/libdwarf/dwarf_frame3.c +282 -0
- data/ext/rdwarf/libdwarf/dwarf_funcs.c +123 -0
- data/ext/rdwarf/libdwarf/dwarf_funcs.h +33 -0
- data/ext/rdwarf/libdwarf/dwarf_gdbindex.c +520 -0
- data/ext/rdwarf/libdwarf/dwarf_gdbindex.h +97 -0
- data/ext/rdwarf/libdwarf/dwarf_global.c +612 -0
- data/ext/rdwarf/libdwarf/dwarf_global.h +117 -0
- data/ext/rdwarf/libdwarf/dwarf_harmless.c +228 -0
- data/ext/rdwarf/libdwarf/dwarf_harmless.h +31 -0
- data/ext/rdwarf/libdwarf/dwarf_incl.h +61 -0
- data/ext/rdwarf/libdwarf/dwarf_init_finish.c +1263 -0
- data/ext/rdwarf/libdwarf/dwarf_leb.c +159 -0
- data/ext/rdwarf/libdwarf/dwarf_line.c +1822 -0
- data/ext/rdwarf/libdwarf/dwarf_line.h +446 -0
- data/ext/rdwarf/libdwarf/dwarf_line2.c +98 -0
- data/ext/rdwarf/libdwarf/dwarf_line_table_reader_common.c +1583 -0
- data/ext/rdwarf/libdwarf/dwarf_loc.c +1525 -0
- data/ext/rdwarf/libdwarf/dwarf_loc.h +149 -0
- data/ext/rdwarf/libdwarf/dwarf_loc2.c +833 -0
- data/ext/rdwarf/libdwarf/dwarf_macro.c +479 -0
- data/ext/rdwarf/libdwarf/dwarf_macro.h +35 -0
- data/ext/rdwarf/libdwarf/dwarf_opaque.h +778 -0
- data/ext/rdwarf/libdwarf/dwarf_original_elf_init.c +219 -0
- data/ext/rdwarf/libdwarf/dwarf_print_lines.c +631 -0
- data/ext/rdwarf/libdwarf/dwarf_pubtypes.c +132 -0
- data/ext/rdwarf/libdwarf/dwarf_query.c +1594 -0
- data/ext/rdwarf/libdwarf/dwarf_ranges.c +194 -0
- data/ext/rdwarf/libdwarf/dwarf_reloc_arm.h +308 -0
- data/ext/rdwarf/libdwarf/dwarf_reloc_mips.h +117 -0
- data/ext/rdwarf/libdwarf/dwarf_reloc_ppc.h +242 -0
- data/ext/rdwarf/libdwarf/dwarf_reloc_ppc64.h +272 -0
- data/ext/rdwarf/libdwarf/dwarf_reloc_x86_64.h +127 -0
- data/ext/rdwarf/libdwarf/dwarf_sort_line.c +665 -0
- data/ext/rdwarf/libdwarf/dwarf_string.c +82 -0
- data/ext/rdwarf/libdwarf/dwarf_stubs.c +38 -0
- data/ext/rdwarf/libdwarf/dwarf_tied.c +423 -0
- data/ext/rdwarf/libdwarf/dwarf_tsearch.h +125 -0
- data/ext/rdwarf/libdwarf/dwarf_tsearchhash.c +675 -0
- data/ext/rdwarf/libdwarf/dwarf_types.c +121 -0
- data/ext/rdwarf/libdwarf/dwarf_types.h +32 -0
- data/ext/rdwarf/libdwarf/dwarf_util.c +913 -0
- data/ext/rdwarf/libdwarf/dwarf_util.h +324 -0
- data/ext/rdwarf/libdwarf/dwarf_vars.c +125 -0
- data/ext/rdwarf/libdwarf/dwarf_vars.h +29 -0
- data/ext/rdwarf/libdwarf/dwarf_weaks.c +123 -0
- data/ext/rdwarf/libdwarf/dwarf_weaks.h +29 -0
- data/ext/rdwarf/libdwarf/dwarf_xu_index.c +579 -0
- data/ext/rdwarf/libdwarf/dwarf_xu_index.h +68 -0
- data/ext/rdwarf/libdwarf/dwgetopt.c +181 -0
- data/ext/rdwarf/libdwarf/dwgetopt.h +51 -0
- data/ext/rdwarf/libdwarf/gennames.c +531 -0
- data/ext/rdwarf/libdwarf/install.sh +119 -0
- data/ext/rdwarf/libdwarf/libdwarf.h.in +3746 -0
- data/ext/rdwarf/libdwarf/libdwarf2.1.mm +9805 -0
- data/ext/rdwarf/libdwarf/libdwarf2.1.pdf +0 -0
- data/ext/rdwarf/libdwarf/libdwarf2p.1.mm +2807 -0
- data/ext/rdwarf/libdwarf/libdwarf2p.1.pdf +0 -0
- data/ext/rdwarf/libdwarf/libdwarfdefs.h +81 -0
- data/ext/rdwarf/libdwarf/malloc_check.c +327 -0
- data/ext/rdwarf/libdwarf/malloc_check.h +52 -0
- data/ext/rdwarf/libdwarf/mips_extensions.mm +1266 -0
- data/ext/rdwarf/libdwarf/mips_extensions.pdf +0 -0
- data/ext/rdwarf/libdwarf/pro_alloc.c +179 -0
- data/ext/rdwarf/libdwarf/pro_alloc.h +33 -0
- data/ext/rdwarf/libdwarf/pro_arange.c +310 -0
- data/ext/rdwarf/libdwarf/pro_arange.h +51 -0
- data/ext/rdwarf/libdwarf/pro_die.c +431 -0
- data/ext/rdwarf/libdwarf/pro_die.h +59 -0
- data/ext/rdwarf/libdwarf/pro_encode_nm.c +108 -0
- data/ext/rdwarf/libdwarf/pro_encode_nm.h +39 -0
- data/ext/rdwarf/libdwarf/pro_error.c +96 -0
- data/ext/rdwarf/libdwarf/pro_error.h +43 -0
- data/ext/rdwarf/libdwarf/pro_expr.c +575 -0
- data/ext/rdwarf/libdwarf/pro_expr.h +36 -0
- data/ext/rdwarf/libdwarf/pro_finish.c +45 -0
- data/ext/rdwarf/libdwarf/pro_forms.c +1271 -0
- data/ext/rdwarf/libdwarf/pro_frame.c +572 -0
- data/ext/rdwarf/libdwarf/pro_frame.h +120 -0
- data/ext/rdwarf/libdwarf/pro_funcs.c +50 -0
- data/ext/rdwarf/libdwarf/pro_incl.h +91 -0
- data/ext/rdwarf/libdwarf/pro_init.c +327 -0
- data/ext/rdwarf/libdwarf/pro_line.c +373 -0
- data/ext/rdwarf/libdwarf/pro_line.h +112 -0
- data/ext/rdwarf/libdwarf/pro_macinfo.c +457 -0
- data/ext/rdwarf/libdwarf/pro_macinfo.h +31 -0
- data/ext/rdwarf/libdwarf/pro_opaque.h +513 -0
- data/ext/rdwarf/libdwarf/pro_pubnames.c +60 -0
- data/ext/rdwarf/libdwarf/pro_reloc.c +253 -0
- data/ext/rdwarf/libdwarf/pro_reloc.h +38 -0
- data/ext/rdwarf/libdwarf/pro_reloc_stream.c +256 -0
- data/ext/rdwarf/libdwarf/pro_reloc_stream.h +52 -0
- data/ext/rdwarf/libdwarf/pro_reloc_symbolic.c +245 -0
- data/ext/rdwarf/libdwarf/pro_reloc_symbolic.h +45 -0
- data/ext/rdwarf/libdwarf/pro_section.c +2233 -0
- data/ext/rdwarf/libdwarf/pro_section.h +100 -0
- data/ext/rdwarf/libdwarf/pro_types.c +274 -0
- data/ext/rdwarf/libdwarf/pro_types.h +34 -0
- data/ext/rdwarf/libdwarf/pro_util.h +38 -0
- data/ext/rdwarf/libdwarf/pro_vars.c +52 -0
- data/ext/rdwarf/libdwarf/pro_weaks.c +51 -0
- data/ext/rdwarf/rdwarf.c +765 -0
- data/ext/rdwarf/rdwarf.h +52 -0
- data/ext/rdwarf/rdwarf_names_gen.rb +109 -0
- data/lib/rdwarf.rb +181 -0
- data/lib/rdwarf/version.rb +3 -0
- data/rdwarf.gemspec +30 -0
- metadata +251 -0
@@ -0,0 +1,1525 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (C) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
|
3
|
+
Portions Copyright (C) 2007-2015 David Anderson. All Rights Reserved.
|
4
|
+
Portions Copyright (C) 2010-2012 SN Systems Ltd. All Rights Reserved.
|
5
|
+
|
6
|
+
This program is free software; you can redistribute it and/or modify it
|
7
|
+
under the terms of version 2.1 of the GNU Lesser General Public License
|
8
|
+
as published by the Free Software Foundation.
|
9
|
+
|
10
|
+
This program is distributed in the hope that it would be useful, but
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
13
|
+
|
14
|
+
Further, this software is distributed without any warranty that it is
|
15
|
+
free of the rightful claim of any third person regarding infringement
|
16
|
+
or the like. Any license provided herein, whether implied or
|
17
|
+
otherwise, applies only to this software file. Patent licenses, if
|
18
|
+
any, provided herein do not apply to combinations of this program with
|
19
|
+
other software, or any other product whatsoever.
|
20
|
+
|
21
|
+
You should have received a copy of the GNU Lesser General Public
|
22
|
+
License along with this program; if not, write the Free Software
|
23
|
+
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
|
24
|
+
USA.
|
25
|
+
|
26
|
+
*/
|
27
|
+
|
28
|
+
#include "config.h"
|
29
|
+
#include "dwarf_incl.h"
|
30
|
+
#include "dwarf_loc.h"
|
31
|
+
#include <stdio.h> /* for debugging only. */
|
32
|
+
|
33
|
+
#define TRUE 1
|
34
|
+
#define FALSE 0
|
35
|
+
|
36
|
+
/* Richard Henderson, on DW_OP_GNU_encoded_addr:
|
37
|
+
The operand is an absolute
|
38
|
+
address. The first byte of the value
|
39
|
+
is an encoding length: 0 2 4 or 8. If zero
|
40
|
+
it means the following is address-size.
|
41
|
+
The address then follows immediately for
|
42
|
+
that number of bytes. */
|
43
|
+
static int
|
44
|
+
read_encoded_addr(Dwarf_Small *loc_ptr, Dwarf_Debug dbg,
|
45
|
+
Dwarf_Unsigned * val_out,
|
46
|
+
int * len_out,
|
47
|
+
Dwarf_Error *error)
|
48
|
+
{
|
49
|
+
int len = 0;
|
50
|
+
Dwarf_Small op = *loc_ptr;
|
51
|
+
Dwarf_Unsigned operand = 0;
|
52
|
+
len++;
|
53
|
+
if (op == 0) {
|
54
|
+
/* FIXME: should be CU specific. */
|
55
|
+
op = dbg->de_pointer_size;
|
56
|
+
}
|
57
|
+
switch (op) {
|
58
|
+
case 1:
|
59
|
+
*val_out = *loc_ptr;
|
60
|
+
len++;
|
61
|
+
break;
|
62
|
+
|
63
|
+
case 2:
|
64
|
+
READ_UNALIGNED(dbg, operand, Dwarf_Unsigned, loc_ptr, 2);
|
65
|
+
*val_out = operand;
|
66
|
+
len +=2;
|
67
|
+
break;
|
68
|
+
case 4:
|
69
|
+
READ_UNALIGNED(dbg, operand, Dwarf_Unsigned, loc_ptr, 4);
|
70
|
+
*val_out = operand;
|
71
|
+
len +=4;
|
72
|
+
break;
|
73
|
+
case 8:
|
74
|
+
READ_UNALIGNED(dbg, operand, Dwarf_Unsigned, loc_ptr, 8);
|
75
|
+
*val_out = operand;
|
76
|
+
len +=8;
|
77
|
+
break;
|
78
|
+
default:
|
79
|
+
/* We do not know how much to read. */
|
80
|
+
_dwarf_error(dbg, error, DW_DLE_GNU_OPCODE_ERROR);
|
81
|
+
return DW_DLV_ERROR;
|
82
|
+
};
|
83
|
+
*len_out = len;
|
84
|
+
return DW_DLV_OK;
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
/* Return DW_DLV_NO_ENTRY when at the end of
|
91
|
+
the ops for this block (a single Dwarf_Loccesc
|
92
|
+
and multiple Dwarf_Locs will eventually result
|
93
|
+
from calling this till DW_DLV_NO_ENTRY).
|
94
|
+
|
95
|
+
All op reader code should call this to
|
96
|
+
extract operator fields. For any
|
97
|
+
DWARF version.
|
98
|
+
*/
|
99
|
+
static int
|
100
|
+
_dwarf_read_loc_expr_op(Dwarf_Debug dbg,
|
101
|
+
Dwarf_Block_c * loc_block,
|
102
|
+
/* Caller: Start numbering at 0. */
|
103
|
+
Dwarf_Signed opnumber,
|
104
|
+
|
105
|
+
/* 2 for DWARF 2 etc. */
|
106
|
+
Dwarf_Half version_stamp,
|
107
|
+
Dwarf_Half offset_size, /* 4 or 8 */
|
108
|
+
Dwarf_Half address_size, /* 2,4, 8 */
|
109
|
+
Dwarf_Signed startoffset_in, /* offset in block,
|
110
|
+
not section offset */
|
111
|
+
|
112
|
+
/* nextoffset_out so caller knows next entry startoffset */
|
113
|
+
Dwarf_Unsigned *nextoffset_out,
|
114
|
+
|
115
|
+
/* The values picked up. */
|
116
|
+
Dwarf_Loc_c curr_loc,
|
117
|
+
Dwarf_Error * error)
|
118
|
+
{
|
119
|
+
Dwarf_Small *loc_ptr = 0;
|
120
|
+
Dwarf_Unsigned loc_len = 0;
|
121
|
+
Dwarf_Unsigned offset = startoffset_in;
|
122
|
+
Dwarf_Unsigned operand1 = 0;
|
123
|
+
Dwarf_Unsigned operand2 = 0;
|
124
|
+
Dwarf_Unsigned operand3 = 0;
|
125
|
+
Dwarf_Small atom = 0;
|
126
|
+
Dwarf_Word leb128_length = 0;
|
127
|
+
|
128
|
+
loc_len = loc_block->bl_len;
|
129
|
+
loc_ptr = loc_block->bl_data + offset;
|
130
|
+
|
131
|
+
if (offset == loc_len) {
|
132
|
+
return DW_DLV_NO_ENTRY;
|
133
|
+
}
|
134
|
+
|
135
|
+
memset(curr_loc,0,sizeof(*curr_loc));
|
136
|
+
|
137
|
+
curr_loc->lr_opnumber = opnumber;
|
138
|
+
curr_loc->lr_offset = offset;
|
139
|
+
|
140
|
+
atom = *(Dwarf_Small *) loc_ptr;
|
141
|
+
loc_ptr++;
|
142
|
+
offset++;
|
143
|
+
curr_loc->lr_atom = atom;
|
144
|
+
switch (atom) {
|
145
|
+
|
146
|
+
case DW_OP_reg0:
|
147
|
+
case DW_OP_reg1:
|
148
|
+
case DW_OP_reg2:
|
149
|
+
case DW_OP_reg3:
|
150
|
+
case DW_OP_reg4:
|
151
|
+
case DW_OP_reg5:
|
152
|
+
case DW_OP_reg6:
|
153
|
+
case DW_OP_reg7:
|
154
|
+
case DW_OP_reg8:
|
155
|
+
case DW_OP_reg9:
|
156
|
+
case DW_OP_reg10:
|
157
|
+
case DW_OP_reg11:
|
158
|
+
case DW_OP_reg12:
|
159
|
+
case DW_OP_reg13:
|
160
|
+
case DW_OP_reg14:
|
161
|
+
case DW_OP_reg15:
|
162
|
+
case DW_OP_reg16:
|
163
|
+
case DW_OP_reg17:
|
164
|
+
case DW_OP_reg18:
|
165
|
+
case DW_OP_reg19:
|
166
|
+
case DW_OP_reg20:
|
167
|
+
case DW_OP_reg21:
|
168
|
+
case DW_OP_reg22:
|
169
|
+
case DW_OP_reg23:
|
170
|
+
case DW_OP_reg24:
|
171
|
+
case DW_OP_reg25:
|
172
|
+
case DW_OP_reg26:
|
173
|
+
case DW_OP_reg27:
|
174
|
+
case DW_OP_reg28:
|
175
|
+
case DW_OP_reg29:
|
176
|
+
case DW_OP_reg30:
|
177
|
+
case DW_OP_reg31:
|
178
|
+
break;
|
179
|
+
|
180
|
+
case DW_OP_regx:
|
181
|
+
operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
|
182
|
+
loc_ptr = loc_ptr + leb128_length;
|
183
|
+
offset = offset + leb128_length;
|
184
|
+
break;
|
185
|
+
|
186
|
+
case DW_OP_lit0:
|
187
|
+
case DW_OP_lit1:
|
188
|
+
case DW_OP_lit2:
|
189
|
+
case DW_OP_lit3:
|
190
|
+
case DW_OP_lit4:
|
191
|
+
case DW_OP_lit5:
|
192
|
+
case DW_OP_lit6:
|
193
|
+
case DW_OP_lit7:
|
194
|
+
case DW_OP_lit8:
|
195
|
+
case DW_OP_lit9:
|
196
|
+
case DW_OP_lit10:
|
197
|
+
case DW_OP_lit11:
|
198
|
+
case DW_OP_lit12:
|
199
|
+
case DW_OP_lit13:
|
200
|
+
case DW_OP_lit14:
|
201
|
+
case DW_OP_lit15:
|
202
|
+
case DW_OP_lit16:
|
203
|
+
case DW_OP_lit17:
|
204
|
+
case DW_OP_lit18:
|
205
|
+
case DW_OP_lit19:
|
206
|
+
case DW_OP_lit20:
|
207
|
+
case DW_OP_lit21:
|
208
|
+
case DW_OP_lit22:
|
209
|
+
case DW_OP_lit23:
|
210
|
+
case DW_OP_lit24:
|
211
|
+
case DW_OP_lit25:
|
212
|
+
case DW_OP_lit26:
|
213
|
+
case DW_OP_lit27:
|
214
|
+
case DW_OP_lit28:
|
215
|
+
case DW_OP_lit29:
|
216
|
+
case DW_OP_lit30:
|
217
|
+
case DW_OP_lit31:
|
218
|
+
operand1 = atom - DW_OP_lit0;
|
219
|
+
break;
|
220
|
+
|
221
|
+
case DW_OP_addr:
|
222
|
+
READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned,
|
223
|
+
loc_ptr, address_size);
|
224
|
+
loc_ptr += address_size;
|
225
|
+
offset += address_size;
|
226
|
+
break;
|
227
|
+
|
228
|
+
case DW_OP_const1u:
|
229
|
+
operand1 = *(Dwarf_Small *) loc_ptr;
|
230
|
+
loc_ptr = loc_ptr + 1;
|
231
|
+
offset = offset + 1;
|
232
|
+
break;
|
233
|
+
|
234
|
+
case DW_OP_const1s:
|
235
|
+
operand1 = *(Dwarf_Sbyte *) loc_ptr;
|
236
|
+
SIGN_EXTEND(operand1,1);
|
237
|
+
loc_ptr = loc_ptr + 1;
|
238
|
+
offset = offset + 1;
|
239
|
+
break;
|
240
|
+
|
241
|
+
case DW_OP_const2u:
|
242
|
+
READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2);
|
243
|
+
loc_ptr = loc_ptr + 2;
|
244
|
+
offset = offset + 2;
|
245
|
+
break;
|
246
|
+
|
247
|
+
case DW_OP_const2s:
|
248
|
+
READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2);
|
249
|
+
SIGN_EXTEND(operand1,2);
|
250
|
+
loc_ptr = loc_ptr + 2;
|
251
|
+
offset = offset + 2;
|
252
|
+
break;
|
253
|
+
|
254
|
+
case DW_OP_const4u:
|
255
|
+
READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 4);
|
256
|
+
loc_ptr = loc_ptr + 4;
|
257
|
+
offset = offset + 4;
|
258
|
+
break;
|
259
|
+
|
260
|
+
case DW_OP_const4s:
|
261
|
+
READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 4);
|
262
|
+
SIGN_EXTEND(operand1,4);
|
263
|
+
loc_ptr = loc_ptr + 4;
|
264
|
+
offset = offset + 4;
|
265
|
+
break;
|
266
|
+
|
267
|
+
case DW_OP_const8u:
|
268
|
+
READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 8);
|
269
|
+
loc_ptr = loc_ptr + 8;
|
270
|
+
offset = offset + 8;
|
271
|
+
break;
|
272
|
+
|
273
|
+
case DW_OP_const8s:
|
274
|
+
READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 8);
|
275
|
+
loc_ptr = loc_ptr + 8;
|
276
|
+
offset = offset + 8;
|
277
|
+
break;
|
278
|
+
|
279
|
+
case DW_OP_constu:
|
280
|
+
operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
|
281
|
+
loc_ptr = loc_ptr + leb128_length;
|
282
|
+
offset = offset + leb128_length;
|
283
|
+
break;
|
284
|
+
|
285
|
+
case DW_OP_consts:
|
286
|
+
operand1 = _dwarf_decode_s_leb128(loc_ptr, &leb128_length);
|
287
|
+
loc_ptr = loc_ptr + leb128_length;
|
288
|
+
offset = offset + leb128_length;
|
289
|
+
break;
|
290
|
+
|
291
|
+
case DW_OP_fbreg:
|
292
|
+
operand1 = _dwarf_decode_s_leb128(loc_ptr, &leb128_length);
|
293
|
+
loc_ptr = loc_ptr + leb128_length;
|
294
|
+
offset = offset + leb128_length;
|
295
|
+
break;
|
296
|
+
|
297
|
+
case DW_OP_breg0:
|
298
|
+
case DW_OP_breg1:
|
299
|
+
case DW_OP_breg2:
|
300
|
+
case DW_OP_breg3:
|
301
|
+
case DW_OP_breg4:
|
302
|
+
case DW_OP_breg5:
|
303
|
+
case DW_OP_breg6:
|
304
|
+
case DW_OP_breg7:
|
305
|
+
case DW_OP_breg8:
|
306
|
+
case DW_OP_breg9:
|
307
|
+
case DW_OP_breg10:
|
308
|
+
case DW_OP_breg11:
|
309
|
+
case DW_OP_breg12:
|
310
|
+
case DW_OP_breg13:
|
311
|
+
case DW_OP_breg14:
|
312
|
+
case DW_OP_breg15:
|
313
|
+
case DW_OP_breg16:
|
314
|
+
case DW_OP_breg17:
|
315
|
+
case DW_OP_breg18:
|
316
|
+
case DW_OP_breg19:
|
317
|
+
case DW_OP_breg20:
|
318
|
+
case DW_OP_breg21:
|
319
|
+
case DW_OP_breg22:
|
320
|
+
case DW_OP_breg23:
|
321
|
+
case DW_OP_breg24:
|
322
|
+
case DW_OP_breg25:
|
323
|
+
case DW_OP_breg26:
|
324
|
+
case DW_OP_breg27:
|
325
|
+
case DW_OP_breg28:
|
326
|
+
case DW_OP_breg29:
|
327
|
+
case DW_OP_breg30:
|
328
|
+
case DW_OP_breg31:
|
329
|
+
operand1 = _dwarf_decode_s_leb128(loc_ptr, &leb128_length);
|
330
|
+
loc_ptr = loc_ptr + leb128_length;
|
331
|
+
offset = offset + leb128_length;
|
332
|
+
break;
|
333
|
+
|
334
|
+
case DW_OP_bregx:
|
335
|
+
/* uleb reg num followed by sleb offset */
|
336
|
+
operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
|
337
|
+
loc_ptr = loc_ptr + leb128_length;
|
338
|
+
offset = offset + leb128_length;
|
339
|
+
|
340
|
+
operand2 = _dwarf_decode_s_leb128(loc_ptr, &leb128_length);
|
341
|
+
loc_ptr = loc_ptr + leb128_length;
|
342
|
+
offset = offset + leb128_length;
|
343
|
+
break;
|
344
|
+
|
345
|
+
case DW_OP_dup:
|
346
|
+
case DW_OP_drop:
|
347
|
+
break;
|
348
|
+
|
349
|
+
case DW_OP_pick:
|
350
|
+
operand1 = *(Dwarf_Small *) loc_ptr;
|
351
|
+
loc_ptr = loc_ptr + 1;
|
352
|
+
offset = offset + 1;
|
353
|
+
break;
|
354
|
+
|
355
|
+
case DW_OP_over:
|
356
|
+
case DW_OP_swap:
|
357
|
+
case DW_OP_rot:
|
358
|
+
case DW_OP_deref:
|
359
|
+
break;
|
360
|
+
|
361
|
+
case DW_OP_deref_size:
|
362
|
+
operand1 = *(Dwarf_Small *) loc_ptr;
|
363
|
+
loc_ptr = loc_ptr + 1;
|
364
|
+
offset = offset + 1;
|
365
|
+
break;
|
366
|
+
|
367
|
+
case DW_OP_xderef:
|
368
|
+
break;
|
369
|
+
|
370
|
+
case DW_OP_xderef_type: /* DWARF5 */
|
371
|
+
operand1 = *(Dwarf_Small *) loc_ptr;
|
372
|
+
loc_ptr = loc_ptr + 1;
|
373
|
+
offset = offset + 1;
|
374
|
+
operand2 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
|
375
|
+
loc_ptr = loc_ptr + leb128_length;
|
376
|
+
offset = offset + leb128_length;
|
377
|
+
|
378
|
+
break;
|
379
|
+
|
380
|
+
case DW_OP_xderef_size:
|
381
|
+
operand1 = *(Dwarf_Small *) loc_ptr;
|
382
|
+
loc_ptr = loc_ptr + 1;
|
383
|
+
offset = offset + 1;
|
384
|
+
break;
|
385
|
+
|
386
|
+
case DW_OP_abs:
|
387
|
+
case DW_OP_and:
|
388
|
+
case DW_OP_div:
|
389
|
+
case DW_OP_minus:
|
390
|
+
case DW_OP_mod:
|
391
|
+
case DW_OP_mul:
|
392
|
+
case DW_OP_neg:
|
393
|
+
case DW_OP_not:
|
394
|
+
case DW_OP_or:
|
395
|
+
case DW_OP_plus:
|
396
|
+
break;
|
397
|
+
|
398
|
+
case DW_OP_plus_uconst:
|
399
|
+
operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
|
400
|
+
loc_ptr = loc_ptr + leb128_length;
|
401
|
+
offset = offset + leb128_length;
|
402
|
+
break;
|
403
|
+
|
404
|
+
case DW_OP_shl:
|
405
|
+
case DW_OP_shr:
|
406
|
+
case DW_OP_shra:
|
407
|
+
case DW_OP_xor:
|
408
|
+
break;
|
409
|
+
|
410
|
+
case DW_OP_le:
|
411
|
+
case DW_OP_ge:
|
412
|
+
case DW_OP_eq:
|
413
|
+
case DW_OP_lt:
|
414
|
+
case DW_OP_gt:
|
415
|
+
case DW_OP_ne:
|
416
|
+
break;
|
417
|
+
|
418
|
+
case DW_OP_skip:
|
419
|
+
case DW_OP_bra:
|
420
|
+
READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2);
|
421
|
+
loc_ptr = loc_ptr + 2;
|
422
|
+
offset = offset + 2;
|
423
|
+
break;
|
424
|
+
|
425
|
+
case DW_OP_piece:
|
426
|
+
operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
|
427
|
+
loc_ptr = loc_ptr + leb128_length;
|
428
|
+
offset = offset + leb128_length;
|
429
|
+
break;
|
430
|
+
|
431
|
+
case DW_OP_nop:
|
432
|
+
break;
|
433
|
+
case DW_OP_push_object_address: /* DWARF3 */
|
434
|
+
break;
|
435
|
+
case DW_OP_call2: /* DWARF3 */
|
436
|
+
READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2);
|
437
|
+
loc_ptr = loc_ptr + 2;
|
438
|
+
offset = offset + 2;
|
439
|
+
break;
|
440
|
+
|
441
|
+
case DW_OP_call4: /* DWARF3 */
|
442
|
+
READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 4);
|
443
|
+
loc_ptr = loc_ptr + 4;
|
444
|
+
offset = offset + 4;
|
445
|
+
break;
|
446
|
+
case DW_OP_call_ref: /* DWARF3 */
|
447
|
+
READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr,
|
448
|
+
offset_size);
|
449
|
+
loc_ptr = loc_ptr + offset_size;
|
450
|
+
offset = offset + offset_size;
|
451
|
+
break;
|
452
|
+
|
453
|
+
case DW_OP_form_tls_address: /* DWARF3f */
|
454
|
+
break;
|
455
|
+
case DW_OP_call_frame_cfa: /* DWARF3f */
|
456
|
+
break;
|
457
|
+
case DW_OP_bit_piece: /* DWARF3f */
|
458
|
+
/* uleb size in bits followed by uleb offset in bits */
|
459
|
+
operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
|
460
|
+
loc_ptr = loc_ptr + leb128_length;
|
461
|
+
offset = offset + leb128_length;
|
462
|
+
|
463
|
+
operand2 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
|
464
|
+
loc_ptr = loc_ptr + leb128_length;
|
465
|
+
offset = offset + leb128_length;
|
466
|
+
break;
|
467
|
+
|
468
|
+
/* The operator means: push the currently computed
|
469
|
+
(by the operations encountered so far in this
|
470
|
+
expression) onto the expression stack as the offset
|
471
|
+
in thread-local-storage of the variable. */
|
472
|
+
case DW_OP_GNU_push_tls_address: /* 0xe0 */
|
473
|
+
/* Believed to have no operands. */
|
474
|
+
/* Unimplemented in gdb 7.5.1 ? */
|
475
|
+
break;
|
476
|
+
case DW_OP_deref_type: /* DWARF5 */
|
477
|
+
case DW_OP_GNU_deref_type: /* 0xf6 */
|
478
|
+
operand1 = *(Dwarf_Small *) loc_ptr;
|
479
|
+
loc_ptr = loc_ptr + 1;
|
480
|
+
offset = offset + 1;
|
481
|
+
|
482
|
+
/* die offset (uleb128). */
|
483
|
+
operand2 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
|
484
|
+
loc_ptr = loc_ptr + leb128_length;
|
485
|
+
offset = offset + leb128_length;
|
486
|
+
break;
|
487
|
+
|
488
|
+
case DW_OP_implicit_value: /* DWARF4 0xa0 */
|
489
|
+
/* uleb length of value bytes followed by that
|
490
|
+
number of bytes of the value. */
|
491
|
+
operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
|
492
|
+
loc_ptr = loc_ptr + leb128_length;
|
493
|
+
offset = offset + leb128_length;
|
494
|
+
|
495
|
+
/* Second operand is block of 'operand1' bytes of stuff. */
|
496
|
+
/* This using the second operand as a pointer
|
497
|
+
is quite ugly. */
|
498
|
+
/* This gets an ugly compiler warning. Sorry. */
|
499
|
+
operand2 = (Dwarf_Unsigned)loc_ptr;
|
500
|
+
offset = offset + operand1;
|
501
|
+
loc_ptr = loc_ptr + operand1;
|
502
|
+
break;
|
503
|
+
case DW_OP_stack_value: /* DWARF4 */
|
504
|
+
break;
|
505
|
+
case DW_OP_GNU_uninit: /* 0xf0 */
|
506
|
+
/* Unimplemented in gdb 7.5.1 */
|
507
|
+
/* Carolyn Tice: Follws a DW_OP_reg or DW_OP_regx
|
508
|
+
and marks the reg as being uninitialized. */
|
509
|
+
break;
|
510
|
+
case DW_OP_GNU_encoded_addr: { /* 0xf1 */
|
511
|
+
/* Richard Henderson: The operand is an absolute
|
512
|
+
address. The first byte of the value
|
513
|
+
is an encoding length: 0 2 4 or 8. If zero
|
514
|
+
it means the following is address-size.
|
515
|
+
The address then follows immediately for
|
516
|
+
that number of bytes. */
|
517
|
+
int length = 0;
|
518
|
+
int reares = read_encoded_addr(loc_ptr,dbg,&operand1,
|
519
|
+
&length,error);
|
520
|
+
if (reares != DW_DLV_OK) {
|
521
|
+
return reares;
|
522
|
+
}
|
523
|
+
loc_ptr += length;
|
524
|
+
offset += length;
|
525
|
+
}
|
526
|
+
break;
|
527
|
+
case DW_OP_implicit_pointer: /* DWARF5 */
|
528
|
+
case DW_OP_GNU_implicit_pointer:{ /* 0xf2 */
|
529
|
+
/* Jakub Jelinek: The value is an optimized-out
|
530
|
+
pointer value. Represented as
|
531
|
+
an offset_size DIE offset
|
532
|
+
(a simple unsigned integer) in DWARF3,4
|
533
|
+
followed by a signed leb128 offset.
|
534
|
+
For DWARF2, it is actually pointer size
|
535
|
+
(address size).
|
536
|
+
http://www.dwarfstd.org/ShowIssue.php?issue=100831.1 */
|
537
|
+
Dwarf_Small iplen = offset_size;
|
538
|
+
if (version_stamp == DW_CU_VERSION2 /* 2 */ ) {
|
539
|
+
iplen = address_size;
|
540
|
+
}
|
541
|
+
READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr,
|
542
|
+
iplen);
|
543
|
+
loc_ptr = loc_ptr + iplen;
|
544
|
+
offset = offset + iplen;
|
545
|
+
|
546
|
+
operand2 = _dwarf_decode_s_leb128(loc_ptr, &leb128_length);
|
547
|
+
loc_ptr = loc_ptr + leb128_length;
|
548
|
+
offset = offset + leb128_length;
|
549
|
+
}
|
550
|
+
|
551
|
+
break;
|
552
|
+
case DW_OP_entry_value: /* DWARF5 */
|
553
|
+
case DW_OP_GNU_entry_value: /* 0xf3 */
|
554
|
+
/* Jakub Jelinek: A register reused really soon,
|
555
|
+
but the value is unchanged. So to represent
|
556
|
+
that value we have a uleb128 size followed
|
557
|
+
by a DWARF expression block that size.
|
558
|
+
http://www.dwarfstd.org/ShowIssue.php?issue=100909.1 */
|
559
|
+
|
560
|
+
/* uleb length of value bytes followed by that
|
561
|
+
number of bytes of the value. */
|
562
|
+
operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
|
563
|
+
loc_ptr = loc_ptr + leb128_length;
|
564
|
+
offset = offset + leb128_length;
|
565
|
+
|
566
|
+
/* Second operand is block of 'operand1' bytes of stuff. */
|
567
|
+
/* This using the second operand as a pointer
|
568
|
+
is quite ugly. */
|
569
|
+
/* This gets an ugly compiler warning. Sorry. */
|
570
|
+
operand2 = (Dwarf_Unsigned)loc_ptr;
|
571
|
+
offset = offset + operand1;
|
572
|
+
loc_ptr = loc_ptr + operand1;
|
573
|
+
break;
|
574
|
+
case DW_OP_const_type: /* DWARF5 */
|
575
|
+
case DW_OP_GNU_const_type: /* 0xf4 */
|
576
|
+
{
|
577
|
+
/* die offset as uleb. */
|
578
|
+
operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
|
579
|
+
loc_ptr = loc_ptr + leb128_length;
|
580
|
+
offset = offset + leb128_length;
|
581
|
+
|
582
|
+
/* Next byte is size of following data block. */
|
583
|
+
operand2 = *loc_ptr;
|
584
|
+
loc_ptr = loc_ptr + 1;
|
585
|
+
offset = offset + 1;
|
586
|
+
|
587
|
+
/* Operand 3 points to a value in the block of size
|
588
|
+
just gotten as operand2. */
|
589
|
+
/* This gets an ugly compiler warning. Sorry. */
|
590
|
+
operand3 = (Dwarf_Unsigned) loc_ptr;
|
591
|
+
loc_ptr = loc_ptr + operand2;
|
592
|
+
offset = offset + operand2;
|
593
|
+
}
|
594
|
+
break;
|
595
|
+
|
596
|
+
case DW_OP_regval_type: /* DWARF5 */
|
597
|
+
case DW_OP_GNU_regval_type: /* 0xf5 */
|
598
|
+
/* reg num uleb*/
|
599
|
+
operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
|
600
|
+
loc_ptr = loc_ptr + leb128_length;
|
601
|
+
offset = offset + leb128_length;
|
602
|
+
/* cu die off uleb*/
|
603
|
+
operand2 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
|
604
|
+
loc_ptr = loc_ptr + leb128_length;
|
605
|
+
offset = offset + leb128_length;
|
606
|
+
break;
|
607
|
+
case DW_OP_convert: /* DWARF5 */
|
608
|
+
case DW_OP_GNU_convert: /* 0xf7 */
|
609
|
+
case DW_OP_reinterpret: /* DWARF5 */
|
610
|
+
case DW_OP_GNU_reinterpret: /* 0xf9 */
|
611
|
+
/* die offset or zero */
|
612
|
+
operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
|
613
|
+
loc_ptr = loc_ptr + leb128_length;
|
614
|
+
offset = offset + leb128_length;
|
615
|
+
break;
|
616
|
+
case DW_OP_GNU_parameter_ref : /* 0xfa */
|
617
|
+
/* 4 byte unsigned int */
|
618
|
+
READ_UNALIGNED(dbg, operand1, Dwarf_Unsigned, loc_ptr, 4);
|
619
|
+
loc_ptr = loc_ptr + 4;
|
620
|
+
offset = offset + 4;
|
621
|
+
break;
|
622
|
+
case DW_OP_addrx : /* DWARF5 */
|
623
|
+
case DW_OP_GNU_addr_index : /* 0xfb DebugFission */
|
624
|
+
/* Index into .debug_addr. The value in .debug_addr
|
625
|
+
is an address. */
|
626
|
+
operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
|
627
|
+
loc_ptr = loc_ptr + leb128_length;
|
628
|
+
offset = offset + leb128_length;
|
629
|
+
break;
|
630
|
+
case DW_OP_constx : /* DWARF5 */
|
631
|
+
case DW_OP_GNU_const_index : /* 0xfc DebugFission */
|
632
|
+
/* Index into .debug_addr. The value in .debug_addr
|
633
|
+
is a constant that fits in an address. */
|
634
|
+
operand1 = _dwarf_decode_u_leb128(loc_ptr, &leb128_length);
|
635
|
+
loc_ptr = loc_ptr + leb128_length;
|
636
|
+
offset = offset + leb128_length;
|
637
|
+
break;
|
638
|
+
default:
|
639
|
+
_dwarf_error(dbg, error, DW_DLE_LOC_EXPR_BAD);
|
640
|
+
return DW_DLV_ERROR;
|
641
|
+
}
|
642
|
+
|
643
|
+
/* If offset == loc_len this would be normal end-of-expression. */
|
644
|
+
if (offset > loc_len) {
|
645
|
+
/* We stepped past the end of the expression.
|
646
|
+
This has to be a compiler bug.
|
647
|
+
Operators missing their values cannot be detected
|
648
|
+
as such except at the end of an expression (like this).
|
649
|
+
The results would be wrong if returned.
|
650
|
+
*/
|
651
|
+
_dwarf_error(dbg, error, DW_DLE_LOC_BAD_TERMINATION);
|
652
|
+
return DW_DLV_ERROR;
|
653
|
+
}
|
654
|
+
curr_loc->lr_atom = atom;
|
655
|
+
curr_loc->lr_number = operand1;
|
656
|
+
curr_loc->lr_number2 = operand2;
|
657
|
+
curr_loc->lr_number3 = operand3;
|
658
|
+
*nextoffset_out = offset;
|
659
|
+
return DW_DLV_OK;
|
660
|
+
}
|
661
|
+
|
662
|
+
/* Given a Dwarf_Block that represents a location expression,
|
663
|
+
this function returns a pointer to a Dwarf_Locdesc struct
|
664
|
+
that has its ld_cents field set to the number of location
|
665
|
+
operators in the block, and its ld_s field pointing to a
|
666
|
+
contiguous block of Dwarf_Loc structs. However, the
|
667
|
+
ld_lopc and ld_hipc values are uninitialized. Returns
|
668
|
+
DW_DLV_ERROR on error.
|
669
|
+
This function assumes that the length of
|
670
|
+
the block is greater than 0. Zero length location expressions
|
671
|
+
to represent variables that have been optimized away are
|
672
|
+
handled in the calling function.
|
673
|
+
|
674
|
+
address_size, offset_size, and version_stamp are
|
675
|
+
per-CU, not per-object or per dbg.
|
676
|
+
We cannot use dbg directly to get those values.
|
677
|
+
|
678
|
+
Use for DWARF 2,3,4. Not for DWARF5.
|
679
|
+
|
680
|
+
*/
|
681
|
+
static int
|
682
|
+
_dwarf_get_locdesc(Dwarf_Debug dbg,
|
683
|
+
Dwarf_Block_c * loc_block,
|
684
|
+
Dwarf_Half address_size,
|
685
|
+
Dwarf_Half offset_size,
|
686
|
+
Dwarf_Small version_stamp,
|
687
|
+
Dwarf_Addr lowpc,
|
688
|
+
Dwarf_Addr highpc,
|
689
|
+
Dwarf_Locdesc ** locdesc_out,
|
690
|
+
Dwarf_Error * error)
|
691
|
+
{
|
692
|
+
/* Offset of current operator from start of block. */
|
693
|
+
Dwarf_Unsigned offset = 0;
|
694
|
+
|
695
|
+
/* Used to chain the Dwarf_Loc_Chain_s structs. */
|
696
|
+
Dwarf_Loc_Chain new_loc = NULL;
|
697
|
+
Dwarf_Loc_Chain prev_loc = NULL;
|
698
|
+
Dwarf_Loc_Chain head_loc = NULL;
|
699
|
+
|
700
|
+
/* Count of the number of location operators. */
|
701
|
+
Dwarf_Unsigned op_count = 0;
|
702
|
+
|
703
|
+
/* Contiguous block of Dwarf_Loc's for Dwarf_Locdesc. */
|
704
|
+
Dwarf_Loc *block_loc = 0;
|
705
|
+
|
706
|
+
/* Dwarf_Locdesc pointer to be returned. */
|
707
|
+
Dwarf_Locdesc *locdesc = 0;
|
708
|
+
|
709
|
+
Dwarf_Unsigned i = 0;
|
710
|
+
int res = 0;
|
711
|
+
|
712
|
+
/* ***** BEGIN CODE ***** */
|
713
|
+
|
714
|
+
offset = 0;
|
715
|
+
op_count = 0;
|
716
|
+
|
717
|
+
|
718
|
+
res = _dwarf_loc_block_sanity_check(dbg,loc_block,error);
|
719
|
+
if (res != DW_DLV_OK) {
|
720
|
+
return res;
|
721
|
+
}
|
722
|
+
/* OLD loop getting Loc operators. No DWARF5 */
|
723
|
+
while (offset <= loc_block->bl_len) {
|
724
|
+
Dwarf_Unsigned nextoffset = 0;
|
725
|
+
struct Dwarf_Loc_c_s temp_loc;
|
726
|
+
|
727
|
+
res = _dwarf_read_loc_expr_op(dbg,loc_block,
|
728
|
+
op_count,
|
729
|
+
version_stamp,
|
730
|
+
offset_size,
|
731
|
+
address_size,
|
732
|
+
offset,
|
733
|
+
&nextoffset,
|
734
|
+
&temp_loc,
|
735
|
+
error);
|
736
|
+
if (res == DW_DLV_ERROR) {
|
737
|
+
return res;
|
738
|
+
}
|
739
|
+
if (res == DW_DLV_NO_ENTRY) {
|
740
|
+
/* Normal end. */
|
741
|
+
break;
|
742
|
+
}
|
743
|
+
op_count++;
|
744
|
+
new_loc =
|
745
|
+
(Dwarf_Loc_Chain) _dwarf_get_alloc(dbg, DW_DLA_LOC_CHAIN, 1);
|
746
|
+
if (new_loc == NULL) {
|
747
|
+
/* Some memory may leak here. */
|
748
|
+
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
|
749
|
+
return DW_DLV_ERROR;
|
750
|
+
}
|
751
|
+
|
752
|
+
/* Copying only the fields needed by DWARF 2,3,4 */
|
753
|
+
new_loc->lc_atom = temp_loc.lr_atom;
|
754
|
+
new_loc->lc_opnumber= temp_loc.lr_opnumber;
|
755
|
+
new_loc->lc_number = temp_loc.lr_number;
|
756
|
+
new_loc->lc_number2 = temp_loc.lr_number2;
|
757
|
+
new_loc->lc_offset = temp_loc.lr_offset;
|
758
|
+
offset = nextoffset;
|
759
|
+
|
760
|
+
if (head_loc == NULL)
|
761
|
+
head_loc = prev_loc = new_loc;
|
762
|
+
else {
|
763
|
+
prev_loc->lc_next = new_loc;
|
764
|
+
prev_loc = new_loc;
|
765
|
+
}
|
766
|
+
}
|
767
|
+
|
768
|
+
block_loc =
|
769
|
+
(Dwarf_Loc *) _dwarf_get_alloc(dbg, DW_DLA_LOC_BLOCK, op_count);
|
770
|
+
if (block_loc == NULL) {
|
771
|
+
/* Some memory does leak here. */
|
772
|
+
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
|
773
|
+
return DW_DLV_ERROR;
|
774
|
+
}
|
775
|
+
|
776
|
+
new_loc = head_loc;
|
777
|
+
for (i = 0; i < op_count; i++) {
|
778
|
+
/* Copying only the fields needed by DWARF 2,3,4 */
|
779
|
+
(block_loc + i)->lr_atom = new_loc->lc_atom;
|
780
|
+
(block_loc + i)->lr_number = new_loc->lc_number;
|
781
|
+
(block_loc + i)->lr_number2 = new_loc->lc_number2;
|
782
|
+
(block_loc + i)->lr_offset = new_loc->lc_offset;
|
783
|
+
prev_loc = new_loc;
|
784
|
+
new_loc = prev_loc->lc_next;
|
785
|
+
dwarf_dealloc(dbg, prev_loc, DW_DLA_LOC_CHAIN);
|
786
|
+
}
|
787
|
+
|
788
|
+
locdesc =
|
789
|
+
(Dwarf_Locdesc *) _dwarf_get_alloc(dbg, DW_DLA_LOCDESC, 1);
|
790
|
+
if (locdesc == NULL) {
|
791
|
+
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
|
792
|
+
return DW_DLV_ERROR;
|
793
|
+
}
|
794
|
+
|
795
|
+
locdesc->ld_cents = op_count;
|
796
|
+
locdesc->ld_s = block_loc;
|
797
|
+
locdesc->ld_from_loclist = loc_block->bl_from_loclist;
|
798
|
+
locdesc->ld_section_offset = loc_block->bl_section_offset;
|
799
|
+
locdesc->ld_lopc = lowpc;
|
800
|
+
locdesc->ld_hipc = highpc;
|
801
|
+
|
802
|
+
*locdesc_out = locdesc;
|
803
|
+
return DW_DLV_OK;
|
804
|
+
}
|
805
|
+
|
806
|
+
/* Using a loclist offset to get the in-memory
|
807
|
+
address of .debug_loc data to read, returns the loclist
|
808
|
+
'header' info in return_block.
|
809
|
+
*/
|
810
|
+
|
811
|
+
#define MAX_ADDR ((address_size == 8)?0xffffffffffffffffULL:0xffffffff)
|
812
|
+
|
813
|
+
|
814
|
+
static int
|
815
|
+
_dwarf_read_loc_section(Dwarf_Debug dbg,
|
816
|
+
Dwarf_Block_c * return_block,
|
817
|
+
Dwarf_Addr * lowpc, Dwarf_Addr * hipc,
|
818
|
+
Dwarf_Off sec_offset,
|
819
|
+
Dwarf_Half address_size,
|
820
|
+
Dwarf_Error * error)
|
821
|
+
{
|
822
|
+
Dwarf_Small *beg = dbg->de_debug_loc.dss_data + sec_offset;
|
823
|
+
|
824
|
+
/* start_addr and end_addr are actually offsets
|
825
|
+
of the applicable base address of the CU.
|
826
|
+
They are address-size. */
|
827
|
+
Dwarf_Addr start_addr = 0;
|
828
|
+
Dwarf_Addr end_addr = 0;
|
829
|
+
Dwarf_Half exprblock_size = 0;
|
830
|
+
Dwarf_Unsigned exprblock_off =
|
831
|
+
2 * address_size + sizeof(Dwarf_Half);
|
832
|
+
|
833
|
+
if (sec_offset >= dbg->de_debug_loc.dss_size) {
|
834
|
+
/* We're at the end. No more present. */
|
835
|
+
return DW_DLV_NO_ENTRY;
|
836
|
+
}
|
837
|
+
|
838
|
+
/* If it goes past end, error */
|
839
|
+
if (exprblock_off > dbg->de_debug_loc.dss_size) {
|
840
|
+
_dwarf_error(NULL, error, DW_DLE_DEBUG_LOC_SECTION_SHORT);
|
841
|
+
return DW_DLV_ERROR;
|
842
|
+
}
|
843
|
+
|
844
|
+
|
845
|
+
READ_UNALIGNED(dbg, start_addr, Dwarf_Addr, beg, address_size);
|
846
|
+
READ_UNALIGNED(dbg, end_addr, Dwarf_Addr,
|
847
|
+
beg + address_size, address_size);
|
848
|
+
if (start_addr == 0 && end_addr == 0) {
|
849
|
+
/* If start_addr and end_addr are 0, it's the end and no
|
850
|
+
exprblock_size field follows. */
|
851
|
+
exprblock_size = 0;
|
852
|
+
exprblock_off -= sizeof(Dwarf_Half);
|
853
|
+
} else if (start_addr == MAX_ADDR) {
|
854
|
+
/* End address is a base address, no exprblock_size field here
|
855
|
+
either */
|
856
|
+
exprblock_size = 0;
|
857
|
+
exprblock_off -= sizeof(Dwarf_Half);
|
858
|
+
} else {
|
859
|
+
READ_UNALIGNED(dbg, exprblock_size, Dwarf_Half,
|
860
|
+
beg + 2 * address_size, sizeof(Dwarf_Half));
|
861
|
+
/* exprblock_size can be zero, means no expression */
|
862
|
+
if ((sec_offset +exprblock_off + exprblock_size) >
|
863
|
+
dbg->de_debug_loc.dss_size) {
|
864
|
+
_dwarf_error(NULL, error, DW_DLE_DEBUG_LOC_SECTION_SHORT);
|
865
|
+
return DW_DLV_ERROR;
|
866
|
+
}
|
867
|
+
}
|
868
|
+
*lowpc = start_addr;
|
869
|
+
*hipc = end_addr;
|
870
|
+
|
871
|
+
return_block->bl_len = exprblock_size;
|
872
|
+
return_block->bl_from_loclist = 1;
|
873
|
+
return_block->bl_data = beg + exprblock_off;
|
874
|
+
return_block->bl_section_offset =
|
875
|
+
((Dwarf_Small *) return_block->bl_data) - dbg->de_debug_loc.dss_data;
|
876
|
+
return DW_DLV_OK;
|
877
|
+
}
|
878
|
+
|
879
|
+
static int
|
880
|
+
_dwarf_get_loclist_count(Dwarf_Debug dbg,
|
881
|
+
Dwarf_Off loclist_offset,
|
882
|
+
Dwarf_Half address_size,
|
883
|
+
int *loclist_count, Dwarf_Error * error)
|
884
|
+
{
|
885
|
+
int count = 0;
|
886
|
+
Dwarf_Off offset = loclist_offset;
|
887
|
+
|
888
|
+
|
889
|
+
for (;;) {
|
890
|
+
Dwarf_Block_c b;
|
891
|
+
Dwarf_Addr lowpc;
|
892
|
+
Dwarf_Addr highpc;
|
893
|
+
int res = _dwarf_read_loc_section(dbg, &b,
|
894
|
+
&lowpc, &highpc,
|
895
|
+
offset, address_size,error);
|
896
|
+
if (res != DW_DLV_OK) {
|
897
|
+
return res;
|
898
|
+
}
|
899
|
+
offset = b.bl_len + b.bl_section_offset;
|
900
|
+
if (lowpc == 0 && highpc == 0) {
|
901
|
+
break;
|
902
|
+
}
|
903
|
+
count++;
|
904
|
+
}
|
905
|
+
*loclist_count = count;
|
906
|
+
return DW_DLV_OK;
|
907
|
+
}
|
908
|
+
|
909
|
+
/* Helper routine to avoid code duplication.
|
910
|
+
*/
|
911
|
+
static int
|
912
|
+
_dwarf_setup_loc(Dwarf_Attribute attr,
|
913
|
+
Dwarf_Debug * dbg_ret,
|
914
|
+
Dwarf_CU_Context *cucontext_ret,
|
915
|
+
Dwarf_Half *form_ret,
|
916
|
+
Dwarf_Error *error)
|
917
|
+
{
|
918
|
+
Dwarf_Debug dbg = 0;
|
919
|
+
Dwarf_Half form = 0;
|
920
|
+
int blkres = DW_DLV_ERROR;
|
921
|
+
|
922
|
+
if (attr == NULL) {
|
923
|
+
_dwarf_error(NULL, error, DW_DLE_ATTR_NULL);
|
924
|
+
return (DW_DLV_ERROR);
|
925
|
+
}
|
926
|
+
if (attr->ar_cu_context == NULL) {
|
927
|
+
_dwarf_error(NULL, error, DW_DLE_ATTR_NO_CU_CONTEXT);
|
928
|
+
return (DW_DLV_ERROR);
|
929
|
+
}
|
930
|
+
*cucontext_ret = attr->ar_cu_context;
|
931
|
+
|
932
|
+
dbg = attr->ar_cu_context->cc_dbg;
|
933
|
+
if (dbg == NULL) {
|
934
|
+
_dwarf_error(NULL, error, DW_DLE_ATTR_DBG_NULL);
|
935
|
+
return (DW_DLV_ERROR);
|
936
|
+
}
|
937
|
+
*dbg_ret = dbg;
|
938
|
+
blkres = dwarf_whatform(attr, &form, error);
|
939
|
+
if (blkres != DW_DLV_OK) {
|
940
|
+
_dwarf_error(dbg, error, DW_DLE_LOC_EXPR_BAD);
|
941
|
+
return blkres;
|
942
|
+
}
|
943
|
+
*form_ret = form;
|
944
|
+
return DW_DLV_OK;
|
945
|
+
}
|
946
|
+
|
947
|
+
/* Helper routine to avoid code duplication.
|
948
|
+
*/
|
949
|
+
static int
|
950
|
+
_dwarf_get_loclist_header_start(Dwarf_Debug dbg,
|
951
|
+
Dwarf_Attribute attr,
|
952
|
+
Dwarf_Unsigned * loclist_offset,
|
953
|
+
Dwarf_Error * error)
|
954
|
+
{
|
955
|
+
int blkres = dwarf_global_formref(attr, loclist_offset, error);
|
956
|
+
if (blkres != DW_DLV_OK) {
|
957
|
+
return (blkres);
|
958
|
+
}
|
959
|
+
|
960
|
+
if (!dbg->de_debug_loc.dss_data) {
|
961
|
+
int secload = _dwarf_load_section(dbg, &dbg->de_debug_loc,error);
|
962
|
+
if (secload != DW_DLV_OK) {
|
963
|
+
return secload;
|
964
|
+
}
|
965
|
+
if (!dbg->de_debug_loc.dss_size) {
|
966
|
+
return (DW_DLV_NO_ENTRY);
|
967
|
+
}
|
968
|
+
}
|
969
|
+
{
|
970
|
+
int fisres = 0;
|
971
|
+
Dwarf_Unsigned fissoff = 0;
|
972
|
+
Dwarf_Unsigned size = 0;
|
973
|
+
fisres = _dwarf_get_fission_addition_die(attr->ar_die, DW_SECT_LOC,
|
974
|
+
&fissoff, &size,error);
|
975
|
+
if(fisres != DW_DLV_OK) {
|
976
|
+
return fisres;
|
977
|
+
}
|
978
|
+
*loclist_offset += fissoff;
|
979
|
+
}
|
980
|
+
return DW_DLV_OK;
|
981
|
+
}
|
982
|
+
|
983
|
+
/* When llbuf (see dwarf_loclist_n) is partially set up
|
984
|
+
and an error is encountered, tear it down as it
|
985
|
+
won't be used.
|
986
|
+
*/
|
987
|
+
static void
|
988
|
+
_dwarf_cleanup_llbuf(Dwarf_Debug dbg, Dwarf_Locdesc ** llbuf, int count)
|
989
|
+
{
|
990
|
+
int i;
|
991
|
+
for (i = 0; i < count; ++i) {
|
992
|
+
dwarf_dealloc(dbg, llbuf[i]->ld_s, DW_DLA_LOC_BLOCK);
|
993
|
+
dwarf_dealloc(dbg, llbuf[i], DW_DLA_LOCDESC);
|
994
|
+
}
|
995
|
+
dwarf_dealloc(dbg, llbuf, DW_DLA_LIST);
|
996
|
+
}
|
997
|
+
|
998
|
+
static int
|
999
|
+
context_is_cu_not_tu(Dwarf_CU_Context context,
|
1000
|
+
Dwarf_Bool *r,Dwarf_Error *err)
|
1001
|
+
{
|
1002
|
+
Dwarf_Debug dbg = 0;
|
1003
|
+
if(context->cc_unit_type == DW_UT_type) {
|
1004
|
+
*r =FALSE;
|
1005
|
+
return DW_DLV_OK;
|
1006
|
+
}
|
1007
|
+
if(context->cc_unit_type == DW_UT_compile) {
|
1008
|
+
*r = TRUE;
|
1009
|
+
return DW_DLV_OK;
|
1010
|
+
}
|
1011
|
+
if(context->cc_unit_type == DW_UT_partial) {
|
1012
|
+
*r = TRUE;
|
1013
|
+
return DW_DLV_OK;
|
1014
|
+
}
|
1015
|
+
/* This should be impossible */
|
1016
|
+
dbg = context->cc_dbg;
|
1017
|
+
_dwarf_error(dbg,err, DW_DLE_NO_TIED_FILE_AVAILABLE);
|
1018
|
+
return DW_DLV_ERROR;
|
1019
|
+
}
|
1020
|
+
|
1021
|
+
/* Handles simple location entries and loclists.
|
1022
|
+
Returns all the Locdesc's thru llbuf.
|
1023
|
+
|
1024
|
+
Will not work properly for DWARF5 and may not
|
1025
|
+
work for some recent versions of gcc or llvm emitting
|
1026
|
+
DWARF4 with location extensions.
|
1027
|
+
|
1028
|
+
Does not work for .debug_loc.dwo
|
1029
|
+
|
1030
|
+
Use dwarf_get_loclist_b() and associated functions.
|
1031
|
+
*/
|
1032
|
+
int
|
1033
|
+
dwarf_loclist_n(Dwarf_Attribute attr,
|
1034
|
+
Dwarf_Locdesc *** llbuf_out,
|
1035
|
+
Dwarf_Signed * listlen_out, Dwarf_Error * error)
|
1036
|
+
{
|
1037
|
+
Dwarf_Debug dbg;
|
1038
|
+
|
1039
|
+
/* Dwarf_Attribute that describes the DW_AT_location in die, if
|
1040
|
+
present. */
|
1041
|
+
Dwarf_Attribute loc_attr = attr;
|
1042
|
+
|
1043
|
+
/* Dwarf_Block that describes a single location expression. */
|
1044
|
+
Dwarf_Block_c loc_block;
|
1045
|
+
|
1046
|
+
/* A pointer to the current Dwarf_Locdesc read. */
|
1047
|
+
Dwarf_Locdesc *locdesc = 0;
|
1048
|
+
|
1049
|
+
Dwarf_Half form = 0;
|
1050
|
+
Dwarf_Addr lowpc = 0;
|
1051
|
+
Dwarf_Addr highpc = 0;
|
1052
|
+
Dwarf_Signed listlen = 0;
|
1053
|
+
Dwarf_Locdesc **llbuf = 0;
|
1054
|
+
Dwarf_CU_Context cucontext = 0;
|
1055
|
+
unsigned address_size = 0;
|
1056
|
+
int cuvstamp = 0;
|
1057
|
+
Dwarf_Bool is_cu = FALSE;
|
1058
|
+
|
1059
|
+
int blkres = DW_DLV_ERROR;
|
1060
|
+
int setup_res = DW_DLV_ERROR;
|
1061
|
+
|
1062
|
+
/* ***** BEGIN CODE ***** */
|
1063
|
+
setup_res = _dwarf_setup_loc(attr, &dbg,&cucontext, &form, error);
|
1064
|
+
if (setup_res != DW_DLV_OK) {
|
1065
|
+
return setup_res;
|
1066
|
+
}
|
1067
|
+
cuvstamp = cucontext->cc_version_stamp;
|
1068
|
+
address_size = cucontext->cc_address_size;
|
1069
|
+
/* If this is a form_block then it's a location expression. If it's
|
1070
|
+
DW_FORM_data4 or DW_FORM_data8 in DWARF2 or DWARF3
|
1071
|
+
(or in DWARF4 or 5 a DW_FORM_sec_offset) it's a loclist offset */
|
1072
|
+
if (cuvstamp == DW_CU_VERSION5) {
|
1073
|
+
/* Use a newer interface. */
|
1074
|
+
_dwarf_error(dbg, error, DW_DLE_LOCLIST_INTERFACE_ERROR);
|
1075
|
+
return (DW_DLV_ERROR);
|
1076
|
+
}
|
1077
|
+
if (((cuvstamp == DW_CU_VERSION2 || cuvstamp == DW_CU_VERSION3) &&
|
1078
|
+
(form == DW_FORM_data4 || form == DW_FORM_data8)) ||
|
1079
|
+
((cuvstamp == DW_CU_VERSION4) && form == DW_FORM_sec_offset)) {
|
1080
|
+
|
1081
|
+
setup_res = context_is_cu_not_tu(cucontext,&is_cu,error);
|
1082
|
+
if(setup_res != DW_DLV_OK) {
|
1083
|
+
return setup_res;
|
1084
|
+
}
|
1085
|
+
/* A reference to .debug_loc, with an offset in .debug_loc of a
|
1086
|
+
loclist */
|
1087
|
+
Dwarf_Unsigned loclist_offset = 0;
|
1088
|
+
int off_res = DW_DLV_ERROR;
|
1089
|
+
int count_res = DW_DLV_ERROR;
|
1090
|
+
int loclist_count = 0;
|
1091
|
+
int lli = 0;
|
1092
|
+
|
1093
|
+
off_res = _dwarf_get_loclist_header_start(dbg,
|
1094
|
+
attr, &loclist_offset, error);
|
1095
|
+
if (off_res != DW_DLV_OK) {
|
1096
|
+
return off_res;
|
1097
|
+
}
|
1098
|
+
count_res = _dwarf_get_loclist_count(dbg, loclist_offset,
|
1099
|
+
address_size, &loclist_count, error);
|
1100
|
+
listlen = loclist_count;
|
1101
|
+
if (count_res != DW_DLV_OK) {
|
1102
|
+
return count_res;
|
1103
|
+
}
|
1104
|
+
if (loclist_count == 0) {
|
1105
|
+
return DW_DLV_NO_ENTRY;
|
1106
|
+
}
|
1107
|
+
|
1108
|
+
llbuf = (Dwarf_Locdesc **)
|
1109
|
+
_dwarf_get_alloc(dbg, DW_DLA_LIST, loclist_count);
|
1110
|
+
if (!llbuf) {
|
1111
|
+
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
|
1112
|
+
return (DW_DLV_ERROR);
|
1113
|
+
}
|
1114
|
+
|
1115
|
+
for (lli = 0; lli < loclist_count; ++lli) {
|
1116
|
+
int lres = 0;
|
1117
|
+
blkres = _dwarf_read_loc_section(dbg, &loc_block,
|
1118
|
+
&lowpc,
|
1119
|
+
&highpc,
|
1120
|
+
loclist_offset,
|
1121
|
+
address_size,
|
1122
|
+
error);
|
1123
|
+
if (blkres != DW_DLV_OK) {
|
1124
|
+
_dwarf_cleanup_llbuf(dbg, llbuf, lli);
|
1125
|
+
return (blkres);
|
1126
|
+
}
|
1127
|
+
lres = _dwarf_get_locdesc(dbg, &loc_block,
|
1128
|
+
address_size,
|
1129
|
+
cucontext->cc_length_size,
|
1130
|
+
cucontext->cc_version_stamp,
|
1131
|
+
lowpc, highpc,
|
1132
|
+
&locdesc,
|
1133
|
+
error);
|
1134
|
+
if (lres != DW_DLV_OK) {
|
1135
|
+
_dwarf_cleanup_llbuf(dbg, llbuf, lli);
|
1136
|
+
/* low level error already set: let it be passed back */
|
1137
|
+
return lres;
|
1138
|
+
}
|
1139
|
+
llbuf[lli] = locdesc;
|
1140
|
+
|
1141
|
+
/* Now get to next loclist entry offset. */
|
1142
|
+
loclist_offset = loc_block.bl_section_offset +
|
1143
|
+
loc_block.bl_len;
|
1144
|
+
}
|
1145
|
+
} else {
|
1146
|
+
if( form == DW_FORM_exprloc) {
|
1147
|
+
blkres = dwarf_formexprloc(loc_attr,&loc_block.bl_len,
|
1148
|
+
&loc_block.bl_data,error);
|
1149
|
+
if(blkres != DW_DLV_OK) {
|
1150
|
+
return blkres;
|
1151
|
+
}
|
1152
|
+
loc_block.bl_from_loclist = 0;
|
1153
|
+
loc_block.bl_section_offset =
|
1154
|
+
(char *)loc_block.bl_data -
|
1155
|
+
(char *)dbg->de_debug_info.dss_data;
|
1156
|
+
} else {
|
1157
|
+
Dwarf_Block *tblock = 0;
|
1158
|
+
blkres = dwarf_formblock(loc_attr, &tblock, error);
|
1159
|
+
if (blkres != DW_DLV_OK) {
|
1160
|
+
return (blkres);
|
1161
|
+
}
|
1162
|
+
loc_block.bl_len = tblock->bl_len;;
|
1163
|
+
loc_block.bl_data = tblock->bl_data;
|
1164
|
+
loc_block.bl_from_loclist = tblock->bl_from_loclist;
|
1165
|
+
loc_block.bl_section_offset = tblock->bl_section_offset;
|
1166
|
+
loc_block.bl_locdesc_offset = 0; /* not relevent */
|
1167
|
+
/* We copied tblock contents to the stack var, so can dealloc
|
1168
|
+
tblock now. Avoids leaks. */
|
1169
|
+
dwarf_dealloc(dbg, tblock, DW_DLA_BLOCK);
|
1170
|
+
}
|
1171
|
+
listlen = 1; /* One by definition of a location entry. */
|
1172
|
+
lowpc = 0; /* HACK */
|
1173
|
+
highpc = (Dwarf_Unsigned) (-1LL); /* HACK */
|
1174
|
+
|
1175
|
+
/* An empty location description (block length 0) means the
|
1176
|
+
code generator emitted no variable, the variable was not
|
1177
|
+
generated, it was unused or perhaps never tested after being
|
1178
|
+
set. Dwarf2, section 2.4.1 In other words, it is not an
|
1179
|
+
error, and we don't test for block length 0 specially here. */
|
1180
|
+
blkres = _dwarf_get_locdesc(dbg, &loc_block,
|
1181
|
+
address_size,
|
1182
|
+
cucontext->cc_length_size,
|
1183
|
+
cucontext->cc_version_stamp,
|
1184
|
+
lowpc, highpc,
|
1185
|
+
&locdesc,
|
1186
|
+
error);
|
1187
|
+
if (blkres != DW_DLV_OK) {
|
1188
|
+
/* low level error already set: let it be passed back */
|
1189
|
+
return blkres;
|
1190
|
+
}
|
1191
|
+
llbuf = (Dwarf_Locdesc **)
|
1192
|
+
_dwarf_get_alloc(dbg, DW_DLA_LIST, listlen);
|
1193
|
+
if (!llbuf) {
|
1194
|
+
/* Free the locdesc we allocated but won't use. */
|
1195
|
+
dwarf_dealloc(dbg, locdesc, DW_DLA_LOCDESC);
|
1196
|
+
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
|
1197
|
+
return (DW_DLV_ERROR);
|
1198
|
+
}
|
1199
|
+
llbuf[0] = locdesc;
|
1200
|
+
}
|
1201
|
+
|
1202
|
+
*llbuf_out = llbuf;
|
1203
|
+
*listlen_out = listlen;
|
1204
|
+
return (DW_DLV_OK);
|
1205
|
+
}
|
1206
|
+
|
1207
|
+
/* Handles only a location expression.
|
1208
|
+
If called on a loclist, just returns one of those.
|
1209
|
+
Cannot not handle a real loclist.
|
1210
|
+
It returns the location expression as a loclist with
|
1211
|
+
a single entry.
|
1212
|
+
See dwarf_loclist_n() which handles any number
|
1213
|
+
of location list entries.
|
1214
|
+
|
1215
|
+
This is the original definition, and it simply
|
1216
|
+
does not work for loclists.
|
1217
|
+
Nor does it work on DWARF4 nor on some
|
1218
|
+
versions of gcc generating DWARF4.
|
1219
|
+
Kept for compatibility.
|
1220
|
+
*/
|
1221
|
+
int
|
1222
|
+
dwarf_loclist(Dwarf_Attribute attr,
|
1223
|
+
Dwarf_Locdesc ** llbuf,
|
1224
|
+
Dwarf_Signed * listlen, Dwarf_Error * error)
|
1225
|
+
{
|
1226
|
+
Dwarf_Debug dbg;
|
1227
|
+
|
1228
|
+
/* Dwarf_Attribute that describes the DW_AT_location in die, if
|
1229
|
+
present. */
|
1230
|
+
Dwarf_Attribute loc_attr = attr;
|
1231
|
+
|
1232
|
+
/* Dwarf_Block that describes a single location expression. */
|
1233
|
+
Dwarf_Block_c loc_block;
|
1234
|
+
|
1235
|
+
/* A pointer to the current Dwarf_Locdesc read. */
|
1236
|
+
Dwarf_Locdesc *locdesc = 0;
|
1237
|
+
|
1238
|
+
Dwarf_Half form = 0;
|
1239
|
+
Dwarf_Addr lowpc = 0;
|
1240
|
+
Dwarf_Addr highpc = 0;
|
1241
|
+
Dwarf_CU_Context cucontext = 0;
|
1242
|
+
unsigned address_size = 0;
|
1243
|
+
|
1244
|
+
int blkres = DW_DLV_ERROR;
|
1245
|
+
int setup_res = DW_DLV_ERROR;
|
1246
|
+
int cuvstamp = 0;
|
1247
|
+
|
1248
|
+
/* ***** BEGIN CODE ***** */
|
1249
|
+
setup_res = _dwarf_setup_loc(attr, &dbg, &cucontext, &form, error);
|
1250
|
+
if (setup_res != DW_DLV_OK) {
|
1251
|
+
return setup_res;
|
1252
|
+
}
|
1253
|
+
cuvstamp = cucontext->cc_version_stamp;
|
1254
|
+
address_size = cucontext->cc_address_size;
|
1255
|
+
/* If this is a form_block then it's a location expression. If it's
|
1256
|
+
DW_FORM_data4 or DW_FORM_data8 it's a loclist offset */
|
1257
|
+
if (((cuvstamp == DW_CU_VERSION2 ||
|
1258
|
+
cuvstamp == DW_CU_VERSION3) &&
|
1259
|
+
(form == DW_FORM_data4 || form == DW_FORM_data8)) ||
|
1260
|
+
((cuvstamp == DW_CU_VERSION4) &&
|
1261
|
+
form == DW_FORM_sec_offset))
|
1262
|
+
{
|
1263
|
+
|
1264
|
+
/* A reference to .debug_loc, with an offset in .debug_loc of a
|
1265
|
+
loclist. */
|
1266
|
+
Dwarf_Unsigned loclist_offset = 0;
|
1267
|
+
int off_res = DW_DLV_ERROR;
|
1268
|
+
|
1269
|
+
off_res = _dwarf_get_loclist_header_start(dbg,
|
1270
|
+
attr, &loclist_offset,
|
1271
|
+
error);
|
1272
|
+
if (off_res != DW_DLV_OK) {
|
1273
|
+
return off_res;
|
1274
|
+
}
|
1275
|
+
|
1276
|
+
/* With dwarf_loclist, just read a single entry */
|
1277
|
+
blkres = _dwarf_read_loc_section(dbg, &loc_block,
|
1278
|
+
&lowpc,
|
1279
|
+
&highpc,
|
1280
|
+
loclist_offset,
|
1281
|
+
address_size,
|
1282
|
+
error);
|
1283
|
+
if (blkres != DW_DLV_OK) {
|
1284
|
+
return (blkres);
|
1285
|
+
}
|
1286
|
+
} else {
|
1287
|
+
if( form == DW_FORM_exprloc) {
|
1288
|
+
blkres = dwarf_formexprloc(loc_attr,&loc_block.bl_len,
|
1289
|
+
&loc_block.bl_data,error);
|
1290
|
+
if(blkres != DW_DLV_OK) {
|
1291
|
+
return blkres;
|
1292
|
+
}
|
1293
|
+
loc_block.bl_from_loclist = 0;
|
1294
|
+
loc_block.bl_section_offset =
|
1295
|
+
(char *)loc_block.bl_data -
|
1296
|
+
(char *)dbg->de_debug_info.dss_data;
|
1297
|
+
} else {
|
1298
|
+
Dwarf_Block *tblock = 0;
|
1299
|
+
|
1300
|
+
/* If DWARF5 this will surely fail, get an error. */
|
1301
|
+
blkres = dwarf_formblock(loc_attr, &tblock, error);
|
1302
|
+
if (blkres != DW_DLV_OK) {
|
1303
|
+
return (blkres);
|
1304
|
+
}
|
1305
|
+
loc_block.bl_len = tblock->bl_len;;
|
1306
|
+
loc_block.bl_data = tblock->bl_data;
|
1307
|
+
loc_block.bl_from_loclist = tblock->bl_from_loclist;
|
1308
|
+
loc_block.bl_section_offset = tblock->bl_section_offset;
|
1309
|
+
/* We copied tblock contents to the stack var, so can dealloc
|
1310
|
+
tblock now. Avoids leaks. */
|
1311
|
+
dwarf_dealloc(dbg, tblock, DW_DLA_BLOCK);
|
1312
|
+
}
|
1313
|
+
lowpc = 0; /* HACK */
|
1314
|
+
highpc = (Dwarf_Unsigned) (-1LL); /* HACK */
|
1315
|
+
}
|
1316
|
+
|
1317
|
+
/* An empty location description (block length 0) means the code
|
1318
|
+
generator emitted no variable, the variable was not generated,
|
1319
|
+
it was unused or perhaps never tested after being set. Dwarf2,
|
1320
|
+
section 2.4.1 In other words, it is not an error, and we don't
|
1321
|
+
test for block length 0 specially here.
|
1322
|
+
See *dwarf_loclist_n() which handles the general case, this case
|
1323
|
+
handles only a single location expression. */
|
1324
|
+
blkres = _dwarf_get_locdesc(dbg, &loc_block,
|
1325
|
+
address_size,
|
1326
|
+
cucontext->cc_length_size,
|
1327
|
+
cucontext->cc_version_stamp,
|
1328
|
+
lowpc, highpc,
|
1329
|
+
&locdesc,
|
1330
|
+
error);
|
1331
|
+
if (blkres != DW_DLV_OK) {
|
1332
|
+
/* low level error already set: let it be passed back */
|
1333
|
+
return blkres;
|
1334
|
+
}
|
1335
|
+
|
1336
|
+
*llbuf = locdesc;
|
1337
|
+
*listlen = 1;
|
1338
|
+
return (DW_DLV_OK);
|
1339
|
+
}
|
1340
|
+
|
1341
|
+
|
1342
|
+
|
1343
|
+
/* Handles only a location expression.
|
1344
|
+
It returns the location expression as a loclist with
|
1345
|
+
a single entry.
|
1346
|
+
|
1347
|
+
Usable to access dwarf expressions from any source, but
|
1348
|
+
specifically from
|
1349
|
+
DW_CFA_def_cfa_expression
|
1350
|
+
DW_CFA_expression
|
1351
|
+
DW_CFA_val_expression
|
1352
|
+
|
1353
|
+
expression_in must point to a valid dwarf expression
|
1354
|
+
set of bytes of length expression_length. Not
|
1355
|
+
a DW_FORM_block*, just the expression bytes.
|
1356
|
+
|
1357
|
+
If the address_size != de_pointer_size this will not work
|
1358
|
+
right.
|
1359
|
+
See dwarf_loclist_from_expr_b() for a better interface.
|
1360
|
+
*/
|
1361
|
+
int
|
1362
|
+
dwarf_loclist_from_expr(Dwarf_Debug dbg,
|
1363
|
+
Dwarf_Ptr expression_in,
|
1364
|
+
Dwarf_Unsigned expression_length,
|
1365
|
+
Dwarf_Locdesc ** llbuf,
|
1366
|
+
Dwarf_Signed * listlen, Dwarf_Error * error)
|
1367
|
+
{
|
1368
|
+
int res = 0;
|
1369
|
+
Dwarf_Half addr_size = dbg->de_pointer_size;
|
1370
|
+
res = dwarf_loclist_from_expr_a(dbg,expression_in,
|
1371
|
+
expression_length, addr_size,llbuf,listlen,error);
|
1372
|
+
return res;
|
1373
|
+
}
|
1374
|
+
|
1375
|
+
/* New April 27 2009. Adding addr_size argument for the rare
|
1376
|
+
cases where an object has CUs with a different address_size.
|
1377
|
+
|
1378
|
+
As of 2012 we have yet another version, dwarf_loclist_from_expr_b()
|
1379
|
+
with the version_stamp and offset size (length size) passed in.
|
1380
|
+
*/
|
1381
|
+
int
|
1382
|
+
dwarf_loclist_from_expr_a(Dwarf_Debug dbg,
|
1383
|
+
Dwarf_Ptr expression_in,
|
1384
|
+
Dwarf_Unsigned expression_length,
|
1385
|
+
Dwarf_Half addr_size,
|
1386
|
+
Dwarf_Locdesc ** llbuf,
|
1387
|
+
Dwarf_Signed * listlen,
|
1388
|
+
Dwarf_Error * error)
|
1389
|
+
{
|
1390
|
+
int res;
|
1391
|
+
Dwarf_Debug_InfoTypes info_reading = &dbg->de_info_reading;
|
1392
|
+
Dwarf_CU_Context current_cu_context =
|
1393
|
+
info_reading->de_cu_context;
|
1394
|
+
Dwarf_Small version_stamp = DW_CU_VERSION2;
|
1395
|
+
Dwarf_Half offset_size = dbg->de_length_size;
|
1396
|
+
|
1397
|
+
if (current_cu_context) {
|
1398
|
+
/* This is ugly. It is not necessarily right. Due to
|
1399
|
+
oddity in DW_OP_GNU_implicit_pointer, see its
|
1400
|
+
implementation above.
|
1401
|
+
For correctness, use dwarf_loclist_from_expr_b()
|
1402
|
+
instead of dwarf_loclist_from_expr_a(). */
|
1403
|
+
version_stamp = current_cu_context->cc_version_stamp;
|
1404
|
+
offset_size = current_cu_context->cc_length_size;
|
1405
|
+
if (version_stamp < 2) {
|
1406
|
+
/* This is probably totally silly. */
|
1407
|
+
version_stamp = DW_CU_VERSION2;
|
1408
|
+
}
|
1409
|
+
}
|
1410
|
+
res = dwarf_loclist_from_expr_b(dbg,
|
1411
|
+
expression_in,
|
1412
|
+
expression_length,
|
1413
|
+
addr_size,
|
1414
|
+
offset_size,
|
1415
|
+
version_stamp, /* CU context DWARF version */
|
1416
|
+
llbuf,
|
1417
|
+
listlen,
|
1418
|
+
error);
|
1419
|
+
return res;
|
1420
|
+
}
|
1421
|
+
/* New November 13 2012. Adding
|
1422
|
+
DWARF version number argument.
|
1423
|
+
*/
|
1424
|
+
int
|
1425
|
+
dwarf_loclist_from_expr_b(Dwarf_Debug dbg,
|
1426
|
+
Dwarf_Ptr expression_in,
|
1427
|
+
Dwarf_Unsigned expression_length,
|
1428
|
+
Dwarf_Half addr_size,
|
1429
|
+
Dwarf_Half offset_size,
|
1430
|
+
Dwarf_Small dwarf_version,
|
1431
|
+
Dwarf_Locdesc ** llbuf,
|
1432
|
+
Dwarf_Signed * listlen,
|
1433
|
+
Dwarf_Error * error)
|
1434
|
+
{
|
1435
|
+
/* Dwarf_Block that describes a single location expression. */
|
1436
|
+
Dwarf_Block_c loc_block;
|
1437
|
+
|
1438
|
+
/* A pointer to the current Dwarf_Locdesc read. */
|
1439
|
+
Dwarf_Locdesc *locdesc = 0;
|
1440
|
+
Dwarf_Addr lowpc = 0;
|
1441
|
+
Dwarf_Addr highpc = (Dwarf_Unsigned) (-1LL);
|
1442
|
+
Dwarf_Small version_stamp = dwarf_version;
|
1443
|
+
int res = 0;
|
1444
|
+
|
1445
|
+
memset(&loc_block,0,sizeof(loc_block));
|
1446
|
+
loc_block.bl_len = expression_length;
|
1447
|
+
loc_block.bl_data = expression_in;
|
1448
|
+
loc_block.bl_from_loclist = 0; /* Not from loclist. */
|
1449
|
+
loc_block.bl_section_offset = 0; /* Fake. Not meaningful. */
|
1450
|
+
|
1451
|
+
/* An empty location description (block length 0) means the code
|
1452
|
+
generator emitted no variable, the variable was not generated,
|
1453
|
+
it was unused or perhaps never tested after being set. Dwarf2,
|
1454
|
+
section 2.4.1 In other words, it is not an error, and we don't
|
1455
|
+
test for block length 0 specially here. */
|
1456
|
+
/* We need the DWARF version to get a locdesc! */
|
1457
|
+
res = _dwarf_get_locdesc(dbg, &loc_block,
|
1458
|
+
addr_size,
|
1459
|
+
offset_size,
|
1460
|
+
version_stamp,
|
1461
|
+
lowpc, highpc,
|
1462
|
+
&locdesc,
|
1463
|
+
error);
|
1464
|
+
if (res != DW_DLV_OK) {
|
1465
|
+
/* low level error already set: let it be passed back */
|
1466
|
+
return (DW_DLV_ERROR);
|
1467
|
+
}
|
1468
|
+
|
1469
|
+
*llbuf = locdesc;
|
1470
|
+
*listlen = 1;
|
1471
|
+
return (DW_DLV_OK);
|
1472
|
+
}
|
1473
|
+
|
1474
|
+
/* Usable to read a single loclist or to read a block of them
|
1475
|
+
or to read an entire section's loclists.
|
1476
|
+
|
1477
|
+
It's BROKEN because it's not safe to read a loclist entry
|
1478
|
+
when we do not know the address size (in any object where
|
1479
|
+
address size can vary by compilation unit).
|
1480
|
+
|
1481
|
+
It also does not recognize split dwarf or DWARF4
|
1482
|
+
or DWARF5 adequately.
|
1483
|
+
*/
|
1484
|
+
|
1485
|
+
/*ARGSUSED*/ int
|
1486
|
+
dwarf_get_loclist_entry(Dwarf_Debug dbg,
|
1487
|
+
Dwarf_Unsigned offset,
|
1488
|
+
Dwarf_Addr * hipc_offset,
|
1489
|
+
Dwarf_Addr * lopc_offset,
|
1490
|
+
Dwarf_Ptr * data,
|
1491
|
+
Dwarf_Unsigned * entry_len,
|
1492
|
+
Dwarf_Unsigned * next_entry,
|
1493
|
+
Dwarf_Error * error)
|
1494
|
+
{
|
1495
|
+
Dwarf_Block_c b;
|
1496
|
+
Dwarf_Addr lowpc = 0;
|
1497
|
+
Dwarf_Addr highpc = 0;
|
1498
|
+
Dwarf_Half address_size = 0;
|
1499
|
+
int res = DW_DLV_ERROR;
|
1500
|
+
|
1501
|
+
if (!dbg->de_debug_loc.dss_data) {
|
1502
|
+
int secload = _dwarf_load_section(dbg, &dbg->de_debug_loc,error);
|
1503
|
+
if (secload != DW_DLV_OK) {
|
1504
|
+
return secload;
|
1505
|
+
}
|
1506
|
+
}
|
1507
|
+
|
1508
|
+
/* FIXME: address_size is not necessarily the same in every frame. */
|
1509
|
+
address_size = dbg->de_pointer_size;
|
1510
|
+
res = _dwarf_read_loc_section(dbg,
|
1511
|
+
&b, &lowpc, &highpc, offset,
|
1512
|
+
address_size,error);
|
1513
|
+
if (res != DW_DLV_OK) {
|
1514
|
+
return res;
|
1515
|
+
}
|
1516
|
+
*hipc_offset = highpc;
|
1517
|
+
*lopc_offset = lowpc;
|
1518
|
+
*entry_len = b.bl_len;
|
1519
|
+
*data = b.bl_data;
|
1520
|
+
*next_entry = b.bl_len + b.bl_section_offset;
|
1521
|
+
return DW_DLV_OK;
|
1522
|
+
}
|
1523
|
+
|
1524
|
+
/* Bring in the code for the October 2015 interfaces. */
|
1525
|
+
#include "dwarf_loc2.c"
|