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,53 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
|
4
|
+
Portions Copyright (C) 2011 David Anderson. 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
|
+
|
29
|
+
|
30
|
+
void _dwarf_error(Dwarf_Debug dbg, Dwarf_Error * error,
|
31
|
+
Dwarf_Sword errval);
|
32
|
+
|
33
|
+
struct Dwarf_Error_s {
|
34
|
+
Dwarf_Sword er_errval;
|
35
|
+
|
36
|
+
/* If non-zero the Dwarf_Error_s struct is not malloc'd.
|
37
|
+
To aid when malloc returns NULL.
|
38
|
+
If zero a normal dwarf_dealloc will work.
|
39
|
+
er_static_alloc only accessed by dwarf_alloc.c.
|
40
|
+
|
41
|
+
If er_static_alloc is 1 in a Dwarf_Error_s
|
42
|
+
struct (set by libdwarf) and client code accidentally
|
43
|
+
turns that 0 to zero through a wild
|
44
|
+
pointer reference (the field is hidden
|
45
|
+
from clients...) then chaos will
|
46
|
+
eventually follow.
|
47
|
+
*/
|
48
|
+
int er_static_alloc;
|
49
|
+
};
|
50
|
+
|
51
|
+
extern struct Dwarf_Error_s _dwarf_failsafe_error;
|
52
|
+
|
53
|
+
|
@@ -0,0 +1,1302 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
Copyright (C) 2000,2002,2004,2005 Silicon Graphics, Inc. All Rights Reserved.
|
4
|
+
Portions Copyright 2007-2010 Sun Microsystems, Inc. All rights reserved.
|
5
|
+
Portions Copyright 2008-2012 David Anderson. All rights reserved.
|
6
|
+
Portions Copyright 2010-2012 SN Systems Ltd. All rights reserved.
|
7
|
+
|
8
|
+
This program is free software; you can redistribute it and/or modify it
|
9
|
+
under the terms of version 2.1 of the GNU Lesser General Public License
|
10
|
+
as published by the Free Software Foundation.
|
11
|
+
|
12
|
+
This program is distributed in the hope that it would be useful, but
|
13
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
15
|
+
|
16
|
+
Further, this software is distributed without any warranty that it is
|
17
|
+
free of the rightful claim of any third person regarding infringement
|
18
|
+
or the like. Any license provided herein, whether implied or
|
19
|
+
otherwise, applies only to this software file. Patent licenses, if
|
20
|
+
any, provided herein do not apply to combinations of this program with
|
21
|
+
other software, or any other product whatsoever.
|
22
|
+
|
23
|
+
You should have received a copy of the GNU Lesser General Public
|
24
|
+
License along with this program; if not, write the Free Software
|
25
|
+
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
|
26
|
+
USA.
|
27
|
+
|
28
|
+
*/
|
29
|
+
|
30
|
+
#include "config.h"
|
31
|
+
#include "dwarf_incl.h"
|
32
|
+
#include <stdio.h>
|
33
|
+
#include "dwarf_die_deliv.h"
|
34
|
+
|
35
|
+
/* This code was repeated many times, now it
|
36
|
+
is all in one place. */
|
37
|
+
static int
|
38
|
+
get_attr_dbg(Dwarf_Debug *dbg,
|
39
|
+
Dwarf_CU_Context * cu_context,
|
40
|
+
Dwarf_Attribute attr,
|
41
|
+
Dwarf_Error *error)
|
42
|
+
{
|
43
|
+
Dwarf_CU_Context cup;
|
44
|
+
if (attr == NULL) {
|
45
|
+
_dwarf_error(NULL, error, DW_DLE_ATTR_NULL);
|
46
|
+
return (DW_DLV_ERROR);
|
47
|
+
}
|
48
|
+
|
49
|
+
cup = attr->ar_cu_context;
|
50
|
+
if (cup == NULL) {
|
51
|
+
_dwarf_error(NULL, error, DW_DLE_ATTR_NO_CU_CONTEXT);
|
52
|
+
return (DW_DLV_ERROR);
|
53
|
+
}
|
54
|
+
|
55
|
+
if (cup->cc_dbg == NULL) {
|
56
|
+
_dwarf_error(NULL, error, DW_DLE_ATTR_DBG_NULL);
|
57
|
+
return (DW_DLV_ERROR);
|
58
|
+
}
|
59
|
+
*cu_context = cup;
|
60
|
+
*dbg = cup->cc_dbg;
|
61
|
+
return DW_DLV_OK;
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
int
|
66
|
+
dwarf_hasform(Dwarf_Attribute attr,
|
67
|
+
Dwarf_Half form,
|
68
|
+
Dwarf_Bool * return_bool, Dwarf_Error * error)
|
69
|
+
{
|
70
|
+
Dwarf_Debug dbg = 0;
|
71
|
+
Dwarf_CU_Context cu_context = 0;
|
72
|
+
|
73
|
+
int res =get_attr_dbg(&dbg,&cu_context, attr,error);
|
74
|
+
if (res != DW_DLV_OK) {
|
75
|
+
return res;
|
76
|
+
}
|
77
|
+
*return_bool = (attr->ar_attribute_form == form);
|
78
|
+
return DW_DLV_OK;
|
79
|
+
}
|
80
|
+
|
81
|
+
/* Not often called, we do not worry about efficiency here.
|
82
|
+
The dwarf_whatform() call does the sanity checks for us.
|
83
|
+
*/
|
84
|
+
int
|
85
|
+
dwarf_whatform_direct(Dwarf_Attribute attr,
|
86
|
+
Dwarf_Half * return_form, Dwarf_Error * error)
|
87
|
+
{
|
88
|
+
int res = dwarf_whatform(attr, return_form, error);
|
89
|
+
|
90
|
+
if (res != DW_DLV_OK) {
|
91
|
+
return res;
|
92
|
+
}
|
93
|
+
|
94
|
+
*return_form = attr->ar_attribute_form_direct;
|
95
|
+
return (DW_DLV_OK);
|
96
|
+
}
|
97
|
+
|
98
|
+
|
99
|
+
/* This code was contributed some time ago
|
100
|
+
and the return
|
101
|
+
value is in the wrong form,
|
102
|
+
but we are not fixing it.
|
103
|
+
*/
|
104
|
+
void *
|
105
|
+
dwarf_uncompress_integer_block(
|
106
|
+
Dwarf_Debug dbg,
|
107
|
+
Dwarf_Bool unit_is_signed,
|
108
|
+
Dwarf_Small unit_length_in_bits,
|
109
|
+
void* input_block,
|
110
|
+
Dwarf_Unsigned input_length_in_bytes,
|
111
|
+
Dwarf_Unsigned* output_length_in_units_ptr,
|
112
|
+
Dwarf_Error* error
|
113
|
+
)
|
114
|
+
{
|
115
|
+
Dwarf_Unsigned output_length_in_units = 0;
|
116
|
+
void * output_block = 0;
|
117
|
+
unsigned i = 0;
|
118
|
+
char * ptr = 0;
|
119
|
+
int remain = 0;
|
120
|
+
Dwarf_sfixed * array = 0;
|
121
|
+
|
122
|
+
if (dbg == NULL) {
|
123
|
+
_dwarf_error(NULL, error, DW_DLE_DBG_NULL);
|
124
|
+
return((void *)DW_DLV_BADADDR);
|
125
|
+
}
|
126
|
+
|
127
|
+
if (unit_is_signed == false ||
|
128
|
+
unit_length_in_bits != 32 ||
|
129
|
+
input_block == NULL ||
|
130
|
+
input_length_in_bytes == 0 ||
|
131
|
+
output_length_in_units_ptr == NULL) {
|
132
|
+
|
133
|
+
_dwarf_error(NULL, error, DW_DLE_BADBITC);
|
134
|
+
return ((void *) DW_DLV_BADADDR);
|
135
|
+
}
|
136
|
+
|
137
|
+
/* At this point we assume the format is: signed 32 bit */
|
138
|
+
|
139
|
+
/* first uncompress everything to find the total size. */
|
140
|
+
|
141
|
+
output_length_in_units = 0;
|
142
|
+
remain = input_length_in_bytes;
|
143
|
+
ptr = input_block;
|
144
|
+
while (remain > 0) {
|
145
|
+
Dwarf_Word len = 0;
|
146
|
+
_dwarf_decode_s_leb128((unsigned char *)ptr, &len);
|
147
|
+
ptr += len;
|
148
|
+
remain -= len;
|
149
|
+
output_length_in_units++;
|
150
|
+
}
|
151
|
+
|
152
|
+
if (remain != 0) {
|
153
|
+
_dwarf_error(NULL, error, DW_DLE_ALLOC_FAIL);
|
154
|
+
return((void *)DW_DLV_BADADDR);
|
155
|
+
}
|
156
|
+
|
157
|
+
/* then alloc */
|
158
|
+
|
159
|
+
output_block = (void *)
|
160
|
+
_dwarf_get_alloc(dbg,
|
161
|
+
DW_DLA_STRING,
|
162
|
+
output_length_in_units * (unit_length_in_bits / 8));
|
163
|
+
if (output_block == NULL) {
|
164
|
+
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
|
165
|
+
return((void*)DW_DLV_BADADDR);
|
166
|
+
}
|
167
|
+
|
168
|
+
/* then uncompress again and copy into new buffer */
|
169
|
+
|
170
|
+
array = (Dwarf_sfixed *) output_block;
|
171
|
+
remain = input_length_in_bytes;
|
172
|
+
ptr = input_block;
|
173
|
+
for (i=0; i<output_length_in_units && remain>0; i++) {
|
174
|
+
Dwarf_Signed num;
|
175
|
+
Dwarf_Word len;
|
176
|
+
num = _dwarf_decode_s_leb128((unsigned char *)ptr, &len);
|
177
|
+
ptr += len;
|
178
|
+
remain -= len;
|
179
|
+
array[i] = num;
|
180
|
+
}
|
181
|
+
|
182
|
+
if (remain != 0) {
|
183
|
+
dwarf_dealloc(dbg, (unsigned char *)output_block, DW_DLA_STRING);
|
184
|
+
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
|
185
|
+
return((Dwarf_P_Attribute)DW_DLV_BADADDR);
|
186
|
+
}
|
187
|
+
|
188
|
+
*output_length_in_units_ptr = output_length_in_units;
|
189
|
+
return output_block;
|
190
|
+
}
|
191
|
+
|
192
|
+
void
|
193
|
+
dwarf_dealloc_uncompressed_block(Dwarf_Debug dbg, void * space)
|
194
|
+
{
|
195
|
+
dwarf_dealloc(dbg, space, DW_DLA_STRING);
|
196
|
+
}
|
197
|
+
|
198
|
+
|
199
|
+
int
|
200
|
+
dwarf_whatform(Dwarf_Attribute attr,
|
201
|
+
Dwarf_Half * return_form, Dwarf_Error * error)
|
202
|
+
{
|
203
|
+
Dwarf_CU_Context cu_context = 0;
|
204
|
+
Dwarf_Debug dbg = 0;
|
205
|
+
|
206
|
+
int res =get_attr_dbg(&dbg,&cu_context, attr,error);
|
207
|
+
if (res != DW_DLV_OK) {
|
208
|
+
return res;
|
209
|
+
}
|
210
|
+
*return_form = attr->ar_attribute_form;
|
211
|
+
return (DW_DLV_OK);
|
212
|
+
}
|
213
|
+
|
214
|
+
|
215
|
+
/*
|
216
|
+
This function is analogous to dwarf_whatform.
|
217
|
+
It returns the attribute in attr instead of
|
218
|
+
the form.
|
219
|
+
*/
|
220
|
+
int
|
221
|
+
dwarf_whatattr(Dwarf_Attribute attr,
|
222
|
+
Dwarf_Half * return_attr, Dwarf_Error * error)
|
223
|
+
{
|
224
|
+
Dwarf_CU_Context cu_context = 0;
|
225
|
+
Dwarf_Debug dbg = 0;
|
226
|
+
|
227
|
+
int res =get_attr_dbg(&dbg,&cu_context, attr,error);
|
228
|
+
if (res != DW_DLV_OK) {
|
229
|
+
return res;
|
230
|
+
}
|
231
|
+
*return_attr = (attr->ar_attribute);
|
232
|
+
return DW_DLV_OK;
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
/* Convert an offset within the local CU into a section-relative
|
237
|
+
debug_info (or debug_types) offset.
|
238
|
+
See dwarf_global_formref() and dwarf_formref()
|
239
|
+
for additional information on conversion rules.
|
240
|
+
*/
|
241
|
+
int
|
242
|
+
dwarf_convert_to_global_offset(Dwarf_Attribute attr,
|
243
|
+
Dwarf_Off offset, Dwarf_Off * ret_offset, Dwarf_Error * error)
|
244
|
+
{
|
245
|
+
Dwarf_Debug dbg = 0;
|
246
|
+
Dwarf_CU_Context cu_context = 0;
|
247
|
+
int res = 0;
|
248
|
+
|
249
|
+
res = get_attr_dbg(&dbg,&cu_context,attr,error);
|
250
|
+
if (res != DW_DLV_OK) {
|
251
|
+
return res;
|
252
|
+
}
|
253
|
+
switch (attr->ar_attribute_form) {
|
254
|
+
case DW_FORM_ref1:
|
255
|
+
case DW_FORM_ref2:
|
256
|
+
case DW_FORM_ref4:
|
257
|
+
case DW_FORM_ref8:
|
258
|
+
case DW_FORM_ref_udata:
|
259
|
+
/* It is a cu-local offset. Convert to section-global. */
|
260
|
+
/* It would be nice to put some code to check
|
261
|
+
legality of the offset */
|
262
|
+
/* cc_debug_offset always has any DWP Package File
|
263
|
+
offset included (when the cu_context created)
|
264
|
+
so there is no extra work for DWP.
|
265
|
+
Globalize the offset */
|
266
|
+
offset += cu_context->cc_debug_offset;
|
267
|
+
|
268
|
+
break;
|
269
|
+
|
270
|
+
case DW_FORM_ref_addr:
|
271
|
+
/* This offset is defined to be debug_info global already, so
|
272
|
+
use this value unaltered.
|
273
|
+
|
274
|
+
Since a DWP package file is not relocated there
|
275
|
+
is no way that this reference offset to an address in
|
276
|
+
any other CU can be correct for a DWP Package File offset
|
277
|
+
*/
|
278
|
+
break;
|
279
|
+
|
280
|
+
default:
|
281
|
+
_dwarf_error(dbg, error, DW_DLE_BAD_REF_FORM);
|
282
|
+
return (DW_DLV_ERROR);
|
283
|
+
}
|
284
|
+
|
285
|
+
*ret_offset = (offset);
|
286
|
+
return DW_DLV_OK;
|
287
|
+
}
|
288
|
+
|
289
|
+
|
290
|
+
/* A global offset cannot be returned by this interface:
|
291
|
+
see dwarf_global_formref().
|
292
|
+
|
293
|
+
DW_FORM_ref_addr is considered an incorrect form
|
294
|
+
for this call because DW_FORM_ref_addr is a global-offset into
|
295
|
+
the debug_info section.
|
296
|
+
|
297
|
+
For the same reason DW_FORM_data4/data8 are not returned
|
298
|
+
from this function.
|
299
|
+
|
300
|
+
For the same reason DW_FORM_sec_offset is not returned
|
301
|
+
from this function, DW_FORM_sec_offset is a global offset
|
302
|
+
(to various sections, not a CU relative offset.
|
303
|
+
|
304
|
+
DW_FORM_ref_addr has a value which was documented in
|
305
|
+
DWARF2 as address-size but which was always an offset
|
306
|
+
so should have always been offset size (wording
|
307
|
+
corrected in DWARF3).
|
308
|
+
The dwarfstd.org FAQ "How big is a DW_FORM_ref_addr?"
|
309
|
+
suggested all should use offset-size, but that suggestion
|
310
|
+
seems to have been ignored in favor of doing what the
|
311
|
+
DWARF2 and 3 standards actually say.
|
312
|
+
|
313
|
+
November, 2010: *ret_offset is always set now.
|
314
|
+
Even in case of error.
|
315
|
+
Set to zero for most errors, but for
|
316
|
+
DW_DLE_ATTR_FORM_OFFSET_BAD
|
317
|
+
*ret_offset is set to the bad offset.
|
318
|
+
|
319
|
+
DW_FORM_addrx
|
320
|
+
DW_FORM_strx
|
321
|
+
DW_FORM_GNU_addr_index
|
322
|
+
DW_FORM_GNU_str_index
|
323
|
+
are not references to .debug_info/.debug_types,
|
324
|
+
so they are not allowed here. */
|
325
|
+
|
326
|
+
|
327
|
+
int
|
328
|
+
dwarf_formref(Dwarf_Attribute attr,
|
329
|
+
Dwarf_Off * ret_offset,
|
330
|
+
Dwarf_Error * error)
|
331
|
+
{
|
332
|
+
Dwarf_Debug dbg = 0;
|
333
|
+
Dwarf_Unsigned offset = 0;
|
334
|
+
Dwarf_CU_Context cu_context = 0;
|
335
|
+
Dwarf_Unsigned maximumoffset = 0;
|
336
|
+
int res = DW_DLV_ERROR;
|
337
|
+
|
338
|
+
*ret_offset = 0;
|
339
|
+
res = get_attr_dbg(&dbg,&cu_context,attr,error);
|
340
|
+
if (res != DW_DLV_OK) {
|
341
|
+
return res;
|
342
|
+
}
|
343
|
+
switch (attr->ar_attribute_form) {
|
344
|
+
|
345
|
+
case DW_FORM_ref1:
|
346
|
+
offset = *(Dwarf_Small *) attr->ar_debug_ptr;
|
347
|
+
break;
|
348
|
+
|
349
|
+
case DW_FORM_ref2:
|
350
|
+
READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
|
351
|
+
attr->ar_debug_ptr, sizeof(Dwarf_Half));
|
352
|
+
break;
|
353
|
+
|
354
|
+
case DW_FORM_ref4:
|
355
|
+
READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
|
356
|
+
attr->ar_debug_ptr, sizeof(Dwarf_ufixed));
|
357
|
+
break;
|
358
|
+
|
359
|
+
case DW_FORM_ref8:
|
360
|
+
READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
|
361
|
+
attr->ar_debug_ptr, sizeof(Dwarf_Unsigned));
|
362
|
+
break;
|
363
|
+
|
364
|
+
case DW_FORM_ref_udata:
|
365
|
+
offset = _dwarf_decode_u_leb128(attr->ar_debug_ptr, NULL);
|
366
|
+
break;
|
367
|
+
case DW_FORM_ref_sig8:
|
368
|
+
/* We cannot handle this here.
|
369
|
+
The reference is to .debug_types
|
370
|
+
not a .debug_info CU local offset. */
|
371
|
+
_dwarf_error(dbg, error, DW_DLE_REF_SIG8_NOT_HANDLED);
|
372
|
+
return (DW_DLV_ERROR);
|
373
|
+
default:
|
374
|
+
_dwarf_error(dbg, error, DW_DLE_BAD_REF_FORM);
|
375
|
+
return (DW_DLV_ERROR);
|
376
|
+
}
|
377
|
+
|
378
|
+
/* Check that offset is within current cu portion of .debug_info. */
|
379
|
+
|
380
|
+
maximumoffset = cu_context->cc_length +
|
381
|
+
cu_context->cc_length_size +
|
382
|
+
cu_context->cc_extension_size;
|
383
|
+
if (offset >= maximumoffset) {
|
384
|
+
/* For the DW_TAG_compile_unit is legal to have the
|
385
|
+
DW_AT_sibling attribute outside the current cu portion of
|
386
|
+
.debug_info.
|
387
|
+
In other words, sibling points to the end of the CU.
|
388
|
+
It is used for precompiled headers.
|
389
|
+
The valid condition will be: 'offset == maximumoffset'. */
|
390
|
+
Dwarf_Half tag = 0;
|
391
|
+
if (DW_DLV_OK != dwarf_tag(attr->ar_die,&tag,error)) {
|
392
|
+
_dwarf_error(dbg, error, DW_DLE_DIE_BAD);
|
393
|
+
return (DW_DLV_ERROR);
|
394
|
+
}
|
395
|
+
|
396
|
+
if (DW_TAG_compile_unit != tag &&
|
397
|
+
DW_AT_sibling != attr->ar_attribute &&
|
398
|
+
offset > maximumoffset) {
|
399
|
+
_dwarf_error(dbg, error, DW_DLE_ATTR_FORM_OFFSET_BAD);
|
400
|
+
/* Return the incorrect offset for better error reporting */
|
401
|
+
*ret_offset = (offset);
|
402
|
+
return (DW_DLV_ERROR);
|
403
|
+
}
|
404
|
+
}
|
405
|
+
*ret_offset = (offset);
|
406
|
+
return DW_DLV_OK;
|
407
|
+
}
|
408
|
+
|
409
|
+
static int
|
410
|
+
_dwarf_formsig8_internal(Dwarf_Attribute attr,
|
411
|
+
int formexpected,
|
412
|
+
int formerrnum,
|
413
|
+
Dwarf_Sig8 * returned_sig_bytes,
|
414
|
+
Dwarf_Error* error)
|
415
|
+
{
|
416
|
+
Dwarf_Debug dbg = 0;
|
417
|
+
Dwarf_Unsigned field_end_offset = 0;
|
418
|
+
Dwarf_CU_Context cu_context = 0;
|
419
|
+
Dwarf_Small *dataptr = 0;
|
420
|
+
|
421
|
+
int res = get_attr_dbg(&dbg,&cu_context,attr,error);
|
422
|
+
if (res != DW_DLV_OK) {
|
423
|
+
return res;
|
424
|
+
}
|
425
|
+
|
426
|
+
if (attr->ar_attribute_form != formexpected ) {
|
427
|
+
_dwarf_error(dbg, error, formerrnum);
|
428
|
+
return (DW_DLV_ERROR);
|
429
|
+
}
|
430
|
+
|
431
|
+
dataptr = cu_context->cc_is_info? dbg->de_debug_info.dss_data:
|
432
|
+
dbg->de_debug_types.dss_data;
|
433
|
+
|
434
|
+
field_end_offset = attr->ar_debug_ptr + sizeof(Dwarf_Sig8) -
|
435
|
+
(dataptr + cu_context->cc_debug_offset);
|
436
|
+
/* Check that offset is within current cu portion of .debug_info. */
|
437
|
+
if (field_end_offset > cu_context->cc_length +
|
438
|
+
cu_context->cc_length_size + cu_context->cc_extension_size) {
|
439
|
+
_dwarf_error(dbg, error, DW_DLE_ATTR_FORM_OFFSET_BAD);
|
440
|
+
return (DW_DLV_ERROR);
|
441
|
+
}
|
442
|
+
|
443
|
+
memcpy(returned_sig_bytes, attr->ar_debug_ptr,
|
444
|
+
sizeof(Dwarf_Sig8));
|
445
|
+
return DW_DLV_OK;
|
446
|
+
}
|
447
|
+
|
448
|
+
int
|
449
|
+
dwarf_formsig8_const(Dwarf_Attribute attr,
|
450
|
+
Dwarf_Sig8 * returned_sig_bytes,
|
451
|
+
Dwarf_Error* error)
|
452
|
+
{
|
453
|
+
int res =_dwarf_formsig8_internal(attr, DW_FORM_data8,
|
454
|
+
DW_DLE_ATTR_FORM_NOT_DATA8,
|
455
|
+
returned_sig_bytes,error);
|
456
|
+
return res;
|
457
|
+
}
|
458
|
+
|
459
|
+
/* dwarf_formsig8 returns in the caller-provided 8 byte area
|
460
|
+
the 8 bytes of a DW_FORM_ref_sig8 (copying the bytes
|
461
|
+
directly to the caller). Not a string, an 8 byte
|
462
|
+
MD5 hash. This function is new in DWARF4 libdwarf.
|
463
|
+
*/
|
464
|
+
int
|
465
|
+
dwarf_formsig8(Dwarf_Attribute attr,
|
466
|
+
Dwarf_Sig8 * returned_sig_bytes,
|
467
|
+
Dwarf_Error* error)
|
468
|
+
{
|
469
|
+
int res = _dwarf_formsig8_internal(attr, DW_FORM_ref_sig8,
|
470
|
+
DW_DLE_BAD_REF_SIG8_FORM,
|
471
|
+
returned_sig_bytes,error);
|
472
|
+
return res;
|
473
|
+
}
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
|
478
|
+
/* Since this returns section-relative debug_info offsets,
|
479
|
+
this can represent all REFERENCE forms correctly
|
480
|
+
and allows all applicable forms.
|
481
|
+
|
482
|
+
DW_FORM_ref_addr has a value which was documented in
|
483
|
+
DWARF2 as address-size but which was always an offset
|
484
|
+
so should have always been offset size (wording
|
485
|
+
corrected in DWARF3).
|
486
|
+
gcc and Go and libdwarf producer code
|
487
|
+
define the length of the value of DW_FORM_ref_addr
|
488
|
+
per the version. So for V2 it is address-size and V3 and later
|
489
|
+
it is offset-size.
|
490
|
+
|
491
|
+
See the DWARF4 document for the 3 cases fitting
|
492
|
+
reference forms. The caller must determine which section the
|
493
|
+
reference 'points' to. The function added in November 2009,
|
494
|
+
dwarf_get_form_class(), helps in this regard. */
|
495
|
+
|
496
|
+
int
|
497
|
+
dwarf_global_formref(Dwarf_Attribute attr,
|
498
|
+
Dwarf_Off * ret_offset, Dwarf_Error * error)
|
499
|
+
{
|
500
|
+
Dwarf_Debug dbg = 0;
|
501
|
+
Dwarf_Unsigned offset = 0;
|
502
|
+
Dwarf_CU_Context cu_context = 0;
|
503
|
+
Dwarf_Half context_version = 0;
|
504
|
+
|
505
|
+
int res = get_attr_dbg(&dbg,&cu_context,attr,error);
|
506
|
+
if (res != DW_DLV_OK) {
|
507
|
+
return res;
|
508
|
+
}
|
509
|
+
context_version = cu_context->cc_version_stamp;
|
510
|
+
switch (attr->ar_attribute_form) {
|
511
|
+
|
512
|
+
case DW_FORM_ref1:
|
513
|
+
offset = *(Dwarf_Small *) attr->ar_debug_ptr;
|
514
|
+
goto fixoffset;
|
515
|
+
|
516
|
+
case DW_FORM_ref2:
|
517
|
+
READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
|
518
|
+
attr->ar_debug_ptr, sizeof(Dwarf_Half));
|
519
|
+
goto fixoffset;
|
520
|
+
|
521
|
+
case DW_FORM_ref4:
|
522
|
+
READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
|
523
|
+
attr->ar_debug_ptr, sizeof(Dwarf_ufixed));
|
524
|
+
goto fixoffset;
|
525
|
+
|
526
|
+
case DW_FORM_ref8:
|
527
|
+
READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
|
528
|
+
attr->ar_debug_ptr, sizeof(Dwarf_Unsigned));
|
529
|
+
goto fixoffset;
|
530
|
+
|
531
|
+
case DW_FORM_ref_udata:
|
532
|
+
{
|
533
|
+
offset = _dwarf_decode_u_leb128(attr->ar_debug_ptr, NULL);
|
534
|
+
|
535
|
+
fixoffset: /* we have a local offset, make it global */
|
536
|
+
|
537
|
+
/* check legality of offset */
|
538
|
+
if (offset >= cu_context->cc_length +
|
539
|
+
cu_context->cc_length_size +
|
540
|
+
cu_context->cc_extension_size) {
|
541
|
+
_dwarf_error(dbg, error, DW_DLE_ATTR_FORM_OFFSET_BAD);
|
542
|
+
return (DW_DLV_ERROR);
|
543
|
+
}
|
544
|
+
|
545
|
+
/* globalize the offset */
|
546
|
+
offset += cu_context->cc_debug_offset;
|
547
|
+
}
|
548
|
+
break;
|
549
|
+
|
550
|
+
/* The DWARF2 document did not make clear that
|
551
|
+
DW_FORM_data4( and 8) were references with
|
552
|
+
global offsets to some section.
|
553
|
+
That was first clearly documented in DWARF3.
|
554
|
+
In DWARF4 these two forms are no longer references. */
|
555
|
+
case DW_FORM_data4:
|
556
|
+
if (context_version == DW_CU_VERSION4) {
|
557
|
+
_dwarf_error(dbg, error, DW_DLE_NOT_REF_FORM);
|
558
|
+
return (DW_DLV_ERROR);
|
559
|
+
}
|
560
|
+
READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
|
561
|
+
attr->ar_debug_ptr, sizeof(Dwarf_ufixed));
|
562
|
+
/* The offset is global. */
|
563
|
+
break;
|
564
|
+
case DW_FORM_data8:
|
565
|
+
if (context_version == DW_CU_VERSION4) {
|
566
|
+
_dwarf_error(dbg, error, DW_DLE_NOT_REF_FORM);
|
567
|
+
return (DW_DLV_ERROR);
|
568
|
+
}
|
569
|
+
READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
|
570
|
+
attr->ar_debug_ptr, sizeof(Dwarf_Unsigned));
|
571
|
+
/* The offset is global. */
|
572
|
+
break;
|
573
|
+
case DW_FORM_ref_addr:
|
574
|
+
{
|
575
|
+
/* In Dwarf V2 DW_FORM_ref_addr was defined
|
576
|
+
as address-size even though it is a .debug_info
|
577
|
+
offset. Fixed in Dwarf V3 to be offset-size.
|
578
|
+
*/
|
579
|
+
unsigned length_size = 0;
|
580
|
+
if (context_version == 2) {
|
581
|
+
length_size = cu_context->cc_address_size;
|
582
|
+
} else {
|
583
|
+
length_size = cu_context->cc_length_size;
|
584
|
+
}
|
585
|
+
if (length_size == 4) {
|
586
|
+
READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
|
587
|
+
attr->ar_debug_ptr, sizeof(Dwarf_ufixed));
|
588
|
+
} else if (length_size == 8) {
|
589
|
+
READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
|
590
|
+
attr->ar_debug_ptr, sizeof(Dwarf_Unsigned));
|
591
|
+
} else {
|
592
|
+
_dwarf_error(dbg, error, DW_DLE_FORM_SEC_OFFSET_LENGTH_BAD);
|
593
|
+
return (DW_DLV_ERROR);
|
594
|
+
}
|
595
|
+
}
|
596
|
+
break;
|
597
|
+
case DW_FORM_sec_offset:
|
598
|
+
case DW_FORM_GNU_ref_alt: /* 2013 GNU extension */
|
599
|
+
case DW_FORM_GNU_strp_alt: /* 2013 GNU extension */
|
600
|
+
case DW_FORM_strp_sup: /* DWARF5 */
|
601
|
+
{
|
602
|
+
/* DW_FORM_sec_offset first exists in DWARF4.*/
|
603
|
+
/* It is up to the caller to know what the offset
|
604
|
+
of DW_FORM_sec_offset refers to,
|
605
|
+
the offset is not going to refer to .debug_info! */
|
606
|
+
unsigned length_size = cu_context->cc_length_size;
|
607
|
+
if (length_size == 4) {
|
608
|
+
READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
|
609
|
+
attr->ar_debug_ptr, sizeof(Dwarf_ufixed));
|
610
|
+
} else if (length_size == 8) {
|
611
|
+
READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
|
612
|
+
attr->ar_debug_ptr, sizeof(Dwarf_Unsigned));
|
613
|
+
} else {
|
614
|
+
_dwarf_error(dbg, error, DW_DLE_FORM_SEC_OFFSET_LENGTH_BAD);
|
615
|
+
return (DW_DLV_ERROR);
|
616
|
+
}
|
617
|
+
}
|
618
|
+
break;
|
619
|
+
case DW_FORM_ref_sig8: /* FIXME */
|
620
|
+
/* We cannot handle this yet.
|
621
|
+
The reference is to .debug_types, and
|
622
|
+
this function only returns an offset in
|
623
|
+
.debug_info at this point. */
|
624
|
+
_dwarf_error(dbg, error, DW_DLE_REF_SIG8_NOT_HANDLED);
|
625
|
+
return (DW_DLV_ERROR);
|
626
|
+
default:
|
627
|
+
_dwarf_error(dbg, error, DW_DLE_BAD_REF_FORM);
|
628
|
+
return (DW_DLV_ERROR);
|
629
|
+
}
|
630
|
+
|
631
|
+
/* We do not know what section the offset refers to, so
|
632
|
+
we have no way to check it for correctness. */
|
633
|
+
*ret_offset = offset;
|
634
|
+
return DW_DLV_OK;
|
635
|
+
}
|
636
|
+
|
637
|
+
/* Part of DebugFission. So a consumer can get the index when
|
638
|
+
the object with the actual debug_addr is
|
639
|
+
elsewhere. New May 2014*/
|
640
|
+
|
641
|
+
int
|
642
|
+
_dwarf_get_addr_index_itself(int theform,
|
643
|
+
Dwarf_Small *info_ptr,
|
644
|
+
Dwarf_Unsigned *val_out,
|
645
|
+
Dwarf_Error * error)
|
646
|
+
{
|
647
|
+
Dwarf_Unsigned index = 0;
|
648
|
+
Dwarf_Word uleblen = 0;
|
649
|
+
index = _dwarf_decode_u_leb128(info_ptr,&uleblen);
|
650
|
+
*val_out = index;
|
651
|
+
return DW_DLV_OK;
|
652
|
+
}
|
653
|
+
|
654
|
+
int
|
655
|
+
dwarf_get_debug_addr_index(Dwarf_Attribute attr,
|
656
|
+
Dwarf_Unsigned * return_index,
|
657
|
+
Dwarf_Error * error)
|
658
|
+
{
|
659
|
+
int theform = attr->ar_attribute_form;
|
660
|
+
if (theform == DW_FORM_GNU_addr_index ||
|
661
|
+
theform == DW_FORM_addrx) {
|
662
|
+
int res = 0;
|
663
|
+
Dwarf_Unsigned index = 0;
|
664
|
+
res = _dwarf_get_addr_index_itself(theform,
|
665
|
+
attr->ar_debug_ptr,&index,error);
|
666
|
+
*return_index = index;
|
667
|
+
return res;
|
668
|
+
}
|
669
|
+
|
670
|
+
{
|
671
|
+
Dwarf_CU_Context cu_context = 0;
|
672
|
+
Dwarf_Debug dbg = 0;
|
673
|
+
int res = get_attr_dbg(&dbg,&cu_context,attr,error);
|
674
|
+
if (res != DW_DLV_OK) {
|
675
|
+
return res;
|
676
|
+
}
|
677
|
+
_dwarf_error(dbg, error,
|
678
|
+
DW_DLE_ATTR_FORM_NOT_ADDR_INDEX);
|
679
|
+
return (DW_DLV_ERROR);
|
680
|
+
}
|
681
|
+
return DW_DLV_NO_ENTRY;
|
682
|
+
}
|
683
|
+
|
684
|
+
/* Part of DebugFission. So a dwarf dumper application
|
685
|
+
can get the index and print it for the user.
|
686
|
+
A convenience function. New May 2014*/
|
687
|
+
int
|
688
|
+
dwarf_get_debug_str_index(Dwarf_Attribute attr,
|
689
|
+
Dwarf_Unsigned *return_index,
|
690
|
+
Dwarf_Error *error)
|
691
|
+
{
|
692
|
+
int theform = attr->ar_attribute_form;
|
693
|
+
if (theform == DW_FORM_strx ||
|
694
|
+
theform == DW_FORM_GNU_str_index) {
|
695
|
+
Dwarf_Unsigned index = 0;
|
696
|
+
Dwarf_Word uleblen = 0;
|
697
|
+
Dwarf_Small *info_ptr = attr->ar_debug_ptr;
|
698
|
+
index = _dwarf_decode_u_leb128(info_ptr,&uleblen);
|
699
|
+
*return_index = index;
|
700
|
+
return DW_DLV_OK;
|
701
|
+
}
|
702
|
+
{
|
703
|
+
Dwarf_CU_Context cu_context = 0;
|
704
|
+
Dwarf_Debug dbg = 0;
|
705
|
+
int res = get_attr_dbg(&dbg,&cu_context,attr,error);
|
706
|
+
if (res != DW_DLV_OK) {
|
707
|
+
return res;
|
708
|
+
}
|
709
|
+
_dwarf_error(dbg, error, DW_DLE_ATTR_FORM_NOT_ADDR_INDEX);
|
710
|
+
}
|
711
|
+
return (DW_DLV_ERROR);
|
712
|
+
}
|
713
|
+
|
714
|
+
|
715
|
+
|
716
|
+
int
|
717
|
+
dwarf_formaddr(Dwarf_Attribute attr,
|
718
|
+
Dwarf_Addr * return_addr, Dwarf_Error * error)
|
719
|
+
{
|
720
|
+
Dwarf_Debug dbg = 0;
|
721
|
+
Dwarf_Addr ret_addr = 0;
|
722
|
+
Dwarf_CU_Context cu_context = 0;
|
723
|
+
Dwarf_Half attrform = 0;
|
724
|
+
|
725
|
+
int res = get_attr_dbg(&dbg,&cu_context,attr,error);
|
726
|
+
if (res != DW_DLV_OK) {
|
727
|
+
return res;
|
728
|
+
}
|
729
|
+
attrform = attr->ar_attribute_form;
|
730
|
+
if (attrform == DW_FORM_GNU_addr_index ||
|
731
|
+
attrform == DW_FORM_addrx) {
|
732
|
+
res = _dwarf_look_in_local_and_tied(
|
733
|
+
attrform,
|
734
|
+
cu_context,
|
735
|
+
attr->ar_debug_ptr,
|
736
|
+
return_addr,
|
737
|
+
error);
|
738
|
+
return res;
|
739
|
+
}
|
740
|
+
if (attrform == DW_FORM_addr
|
741
|
+
/* || attrform == DW_FORM_ref_addr Allowance of
|
742
|
+
DW_FORM_ref_addr was a mistake. The value returned in that
|
743
|
+
case is NOT an address it is a global debug_info offset (ie,
|
744
|
+
not CU-relative offset within the CU in debug_info). The
|
745
|
+
Dwarf document refers to it as an address (misleadingly) in
|
746
|
+
sec 6.5.4 where it describes the reference form. It is
|
747
|
+
address-sized so that the linker can easily update it, but
|
748
|
+
it is a reference inside the debug_info section. No longer
|
749
|
+
allowed. */
|
750
|
+
) {
|
751
|
+
|
752
|
+
READ_UNALIGNED(dbg, ret_addr, Dwarf_Addr,
|
753
|
+
attr->ar_debug_ptr,
|
754
|
+
cu_context->cc_address_size);
|
755
|
+
*return_addr = ret_addr;
|
756
|
+
return (DW_DLV_OK);
|
757
|
+
}
|
758
|
+
_dwarf_error(dbg, error, DW_DLE_ATTR_FORM_BAD);
|
759
|
+
return (DW_DLV_ERROR);
|
760
|
+
}
|
761
|
+
|
762
|
+
|
763
|
+
int
|
764
|
+
dwarf_formflag(Dwarf_Attribute attr,
|
765
|
+
Dwarf_Bool * ret_bool, Dwarf_Error * error)
|
766
|
+
{
|
767
|
+
Dwarf_CU_Context cu_context = 0;
|
768
|
+
|
769
|
+
if (attr == NULL) {
|
770
|
+
_dwarf_error(NULL, error, DW_DLE_ATTR_NULL);
|
771
|
+
return (DW_DLV_ERROR);
|
772
|
+
}
|
773
|
+
|
774
|
+
cu_context = attr->ar_cu_context;
|
775
|
+
if (cu_context == NULL) {
|
776
|
+
_dwarf_error(NULL, error, DW_DLE_ATTR_NO_CU_CONTEXT);
|
777
|
+
return (DW_DLV_ERROR);
|
778
|
+
}
|
779
|
+
|
780
|
+
if (cu_context->cc_dbg == NULL) {
|
781
|
+
_dwarf_error(NULL, error, DW_DLE_ATTR_DBG_NULL);
|
782
|
+
return (DW_DLV_ERROR);
|
783
|
+
}
|
784
|
+
if (attr->ar_attribute_form == DW_FORM_flag_present) {
|
785
|
+
/* Implicit means we don't read any data at all. Just
|
786
|
+
the existence of the Form does it. DWARF4. */
|
787
|
+
*ret_bool = 1;
|
788
|
+
return (DW_DLV_OK);
|
789
|
+
}
|
790
|
+
|
791
|
+
if (attr->ar_attribute_form == DW_FORM_flag) {
|
792
|
+
*ret_bool = *(Dwarf_Small *)(attr->ar_debug_ptr);
|
793
|
+
return (DW_DLV_OK);
|
794
|
+
}
|
795
|
+
_dwarf_error(cu_context->cc_dbg, error, DW_DLE_ATTR_FORM_BAD);
|
796
|
+
return (DW_DLV_ERROR);
|
797
|
+
}
|
798
|
+
|
799
|
+
/* If the form is DW_FORM_constx and the .debug_addr section
|
800
|
+
is missing, this returns DW_DLV_ERROR and the error number
|
801
|
+
in the Dwarf_Error is DW_DLE_MISSING_NEEDED_DEBUG_ADDR_SECTION.
|
802
|
+
When that arises, a consumer should call
|
803
|
+
dwarf_get_debug_addr_index() and use that on the appropriate
|
804
|
+
.debug_addr section in the executable or another object. */
|
805
|
+
int
|
806
|
+
dwarf_formudata(Dwarf_Attribute attr,
|
807
|
+
Dwarf_Unsigned * return_uval, Dwarf_Error * error)
|
808
|
+
{
|
809
|
+
Dwarf_Unsigned ret_value = 0;
|
810
|
+
Dwarf_Debug dbg = 0;
|
811
|
+
Dwarf_CU_Context cu_context = 0;
|
812
|
+
|
813
|
+
int res = get_attr_dbg(&dbg,&cu_context,attr,error);
|
814
|
+
if (res != DW_DLV_OK) {
|
815
|
+
return res;
|
816
|
+
}
|
817
|
+
switch (attr->ar_attribute_form) {
|
818
|
+
|
819
|
+
case DW_FORM_data1:
|
820
|
+
READ_UNALIGNED(dbg, ret_value, Dwarf_Unsigned,
|
821
|
+
attr->ar_debug_ptr, sizeof(Dwarf_Small));
|
822
|
+
*return_uval = ret_value;
|
823
|
+
return DW_DLV_OK;
|
824
|
+
|
825
|
+
/* READ_UNALIGNED does the right thing as it reads
|
826
|
+
the right number bits and generates host order.
|
827
|
+
So we can just assign to *return_uval. */
|
828
|
+
case DW_FORM_data2:{
|
829
|
+
READ_UNALIGNED(dbg, ret_value, Dwarf_Unsigned,
|
830
|
+
attr->ar_debug_ptr, sizeof(Dwarf_Half));
|
831
|
+
*return_uval = ret_value;
|
832
|
+
return DW_DLV_OK;
|
833
|
+
}
|
834
|
+
|
835
|
+
case DW_FORM_data4:{
|
836
|
+
READ_UNALIGNED(dbg, ret_value, Dwarf_Unsigned,
|
837
|
+
attr->ar_debug_ptr,
|
838
|
+
sizeof(Dwarf_ufixed));
|
839
|
+
*return_uval = ret_value;
|
840
|
+
return DW_DLV_OK;
|
841
|
+
}
|
842
|
+
|
843
|
+
case DW_FORM_data8:{
|
844
|
+
READ_UNALIGNED(dbg, ret_value, Dwarf_Unsigned,
|
845
|
+
attr->ar_debug_ptr,
|
846
|
+
sizeof(Dwarf_Unsigned));
|
847
|
+
*return_uval = ret_value;
|
848
|
+
return DW_DLV_OK;
|
849
|
+
}
|
850
|
+
break;
|
851
|
+
/* real udata */
|
852
|
+
case DW_FORM_udata:
|
853
|
+
ret_value =
|
854
|
+
(_dwarf_decode_u_leb128(attr->ar_debug_ptr, NULL));
|
855
|
+
*return_uval = ret_value;
|
856
|
+
return DW_DLV_OK;
|
857
|
+
|
858
|
+
|
859
|
+
/* IRIX bug 583450. We do not allow reading sdata from a udata
|
860
|
+
value. Caller can retry, calling sdata */
|
861
|
+
|
862
|
+
|
863
|
+
default:
|
864
|
+
break;
|
865
|
+
}
|
866
|
+
_dwarf_error(dbg, error, DW_DLE_ATTR_FORM_BAD);
|
867
|
+
return (DW_DLV_ERROR);
|
868
|
+
}
|
869
|
+
|
870
|
+
|
871
|
+
int
|
872
|
+
dwarf_formsdata(Dwarf_Attribute attr,
|
873
|
+
Dwarf_Signed * return_sval, Dwarf_Error * error)
|
874
|
+
{
|
875
|
+
Dwarf_Signed ret_value = 0;
|
876
|
+
Dwarf_Debug dbg = 0;
|
877
|
+
Dwarf_CU_Context cu_context = 0;
|
878
|
+
|
879
|
+
int res = get_attr_dbg(&dbg,&cu_context,attr,error);
|
880
|
+
if (res != DW_DLV_OK) {
|
881
|
+
return res;
|
882
|
+
}
|
883
|
+
switch (attr->ar_attribute_form) {
|
884
|
+
|
885
|
+
case DW_FORM_data1:
|
886
|
+
*return_sval = (*(Dwarf_Sbyte *) attr->ar_debug_ptr);
|
887
|
+
return DW_DLV_OK;
|
888
|
+
|
889
|
+
/* READ_UNALIGNED does not sign extend.
|
890
|
+
So we have to use a cast to get the
|
891
|
+
value sign extended in the right way for each case. */
|
892
|
+
case DW_FORM_data2:{
|
893
|
+
READ_UNALIGNED(dbg, ret_value, Dwarf_Signed,
|
894
|
+
attr->ar_debug_ptr,
|
895
|
+
sizeof(Dwarf_Shalf));
|
896
|
+
*return_sval = (Dwarf_Shalf) ret_value;
|
897
|
+
return DW_DLV_OK;
|
898
|
+
|
899
|
+
}
|
900
|
+
|
901
|
+
case DW_FORM_data4:{
|
902
|
+
READ_UNALIGNED(dbg, ret_value, Dwarf_Signed,
|
903
|
+
attr->ar_debug_ptr,
|
904
|
+
sizeof(Dwarf_sfixed));
|
905
|
+
*return_sval = (Dwarf_sfixed) ret_value;
|
906
|
+
return DW_DLV_OK;
|
907
|
+
}
|
908
|
+
|
909
|
+
case DW_FORM_data8:{
|
910
|
+
READ_UNALIGNED(dbg, ret_value, Dwarf_Signed,
|
911
|
+
attr->ar_debug_ptr,
|
912
|
+
sizeof(Dwarf_Signed));
|
913
|
+
*return_sval = (Dwarf_Signed) ret_value;
|
914
|
+
return DW_DLV_OK;
|
915
|
+
}
|
916
|
+
|
917
|
+
case DW_FORM_sdata:
|
918
|
+
ret_value =
|
919
|
+
(_dwarf_decode_s_leb128(attr->ar_debug_ptr, NULL));
|
920
|
+
*return_sval = ret_value;
|
921
|
+
return DW_DLV_OK;
|
922
|
+
|
923
|
+
/* IRIX bug 583450. We do not allow reading sdata from a udata
|
924
|
+
value. Caller can retry, calling udata */
|
925
|
+
|
926
|
+
default:
|
927
|
+
break;
|
928
|
+
}
|
929
|
+
_dwarf_error(dbg, error, DW_DLE_ATTR_FORM_BAD);
|
930
|
+
return DW_DLV_ERROR;
|
931
|
+
}
|
932
|
+
|
933
|
+
|
934
|
+
int
|
935
|
+
dwarf_formblock(Dwarf_Attribute attr,
|
936
|
+
Dwarf_Block ** return_block, Dwarf_Error * error)
|
937
|
+
{
|
938
|
+
Dwarf_CU_Context cu_context = 0;
|
939
|
+
Dwarf_Debug dbg = 0;
|
940
|
+
Dwarf_Unsigned length = 0;
|
941
|
+
Dwarf_Small *data = 0;
|
942
|
+
Dwarf_Word leb128_length = 0;
|
943
|
+
Dwarf_Block *ret_block = 0;
|
944
|
+
Dwarf_Small *dataptr = 0;
|
945
|
+
|
946
|
+
int res = get_attr_dbg(&dbg,&cu_context,attr,error);
|
947
|
+
if (res != DW_DLV_OK) {
|
948
|
+
return res;
|
949
|
+
}
|
950
|
+
switch (attr->ar_attribute_form) {
|
951
|
+
|
952
|
+
case DW_FORM_block1:
|
953
|
+
length = *(Dwarf_Small *) attr->ar_debug_ptr;
|
954
|
+
data = attr->ar_debug_ptr + sizeof(Dwarf_Small);
|
955
|
+
break;
|
956
|
+
|
957
|
+
case DW_FORM_block2:
|
958
|
+
READ_UNALIGNED(dbg, length, Dwarf_Unsigned,
|
959
|
+
attr->ar_debug_ptr, sizeof(Dwarf_Half));
|
960
|
+
data = attr->ar_debug_ptr + sizeof(Dwarf_Half);
|
961
|
+
break;
|
962
|
+
|
963
|
+
case DW_FORM_block4:
|
964
|
+
READ_UNALIGNED(dbg, length, Dwarf_Unsigned,
|
965
|
+
attr->ar_debug_ptr, sizeof(Dwarf_ufixed));
|
966
|
+
data = attr->ar_debug_ptr + sizeof(Dwarf_ufixed);
|
967
|
+
break;
|
968
|
+
|
969
|
+
case DW_FORM_block:
|
970
|
+
length = _dwarf_decode_u_leb128(attr->ar_debug_ptr,
|
971
|
+
&leb128_length);
|
972
|
+
data = attr->ar_debug_ptr + leb128_length;
|
973
|
+
break;
|
974
|
+
|
975
|
+
default:
|
976
|
+
_dwarf_error(cu_context->cc_dbg, error, DW_DLE_ATTR_FORM_BAD);
|
977
|
+
return (DW_DLV_ERROR);
|
978
|
+
}
|
979
|
+
|
980
|
+
/* Check that block lies within current cu in .debug_info. */
|
981
|
+
dataptr = cu_context->cc_is_info? dbg->de_debug_info.dss_data:
|
982
|
+
dbg->de_debug_types.dss_data;
|
983
|
+
|
984
|
+
if (attr->ar_debug_ptr + length >=
|
985
|
+
dataptr + cu_context->cc_debug_offset +
|
986
|
+
cu_context->cc_length + cu_context->cc_length_size +
|
987
|
+
cu_context->cc_extension_size) {
|
988
|
+
_dwarf_error(dbg, error, DW_DLE_ATTR_FORM_SIZE_BAD);
|
989
|
+
return (DW_DLV_ERROR);
|
990
|
+
}
|
991
|
+
|
992
|
+
ret_block = (Dwarf_Block *) _dwarf_get_alloc(dbg, DW_DLA_BLOCK, 1);
|
993
|
+
if (ret_block == NULL) {
|
994
|
+
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
|
995
|
+
return (DW_DLV_ERROR);
|
996
|
+
}
|
997
|
+
|
998
|
+
ret_block->bl_len = length;
|
999
|
+
ret_block->bl_data = (Dwarf_Ptr) data;
|
1000
|
+
ret_block->bl_from_loclist = 0;
|
1001
|
+
ret_block->bl_section_offset = data - dataptr;
|
1002
|
+
|
1003
|
+
|
1004
|
+
*return_block = ret_block;
|
1005
|
+
return (DW_DLV_OK);
|
1006
|
+
}
|
1007
|
+
|
1008
|
+
int
|
1009
|
+
_dwarf_extract_string_offset_via_str_offsets(Dwarf_Debug dbg,
|
1010
|
+
Dwarf_Small *info_data_ptr,
|
1011
|
+
Dwarf_Half attrnum,
|
1012
|
+
Dwarf_Half attrform,
|
1013
|
+
Dwarf_CU_Context cu_context,
|
1014
|
+
Dwarf_Unsigned *str_sect_offset_out,
|
1015
|
+
Dwarf_Error *error)
|
1016
|
+
{
|
1017
|
+
Dwarf_Unsigned offsettostr= 0;
|
1018
|
+
Dwarf_Unsigned offset_base = 0;
|
1019
|
+
Dwarf_Word leb_len = 0;
|
1020
|
+
Dwarf_Unsigned index_to_offset_entry = 0;
|
1021
|
+
Dwarf_Unsigned offsetintable = 0;
|
1022
|
+
Dwarf_Unsigned end_offsetintable = 0;
|
1023
|
+
int res = 0;
|
1024
|
+
|
1025
|
+
res = _dwarf_load_section(dbg, &dbg->de_debug_str_offsets,error);
|
1026
|
+
if (res != DW_DLV_OK) {
|
1027
|
+
return res;
|
1028
|
+
}
|
1029
|
+
index_to_offset_entry = (_dwarf_decode_u_leb128(info_data_ptr, &leb_len));
|
1030
|
+
/* DW_FORM_GNU_str_index has no 'base' value.
|
1031
|
+
DW_FORM_strx has a base value
|
1032
|
+
for the offset table */
|
1033
|
+
if( attrform == DW_FORM_strx) {
|
1034
|
+
res = _dwarf_get_string_base_attr_value(dbg,cu_context,
|
1035
|
+
&offset_base,error);
|
1036
|
+
if (res != DW_DLV_OK) {
|
1037
|
+
/* DW_DLV_NO_ENTRY could be acceptable when
|
1038
|
+
a producer knows that the base offset will be zero.
|
1039
|
+
Hence DW_AT_str_offsets_base missing.
|
1040
|
+
DWARF5 draft as of September 2015 allows the attribute
|
1041
|
+
to be missing (it's up to the compilation tools to
|
1042
|
+
make sure that has the correct effect).
|
1043
|
+
*/
|
1044
|
+
return res;
|
1045
|
+
}
|
1046
|
+
}
|
1047
|
+
|
1048
|
+
offsetintable = (index_to_offset_entry*cu_context->cc_length_size )
|
1049
|
+
+ offset_base;
|
1050
|
+
{
|
1051
|
+
Dwarf_Unsigned fissoff = 0;
|
1052
|
+
Dwarf_Unsigned size = 0;
|
1053
|
+
fissoff = _dwarf_get_dwp_extra_offset(&cu_context->cc_dwp_offsets,
|
1054
|
+
DW_SECT_STR_OFFSETS, &size);
|
1055
|
+
offsetintable += fissoff;
|
1056
|
+
}
|
1057
|
+
end_offsetintable = offsetintable + cu_context->cc_length_size;
|
1058
|
+
/* The offsets table is a series of offset-size entries.
|
1059
|
+
The == case in the test applies when we are at the last table
|
1060
|
+
entry, so == is not an error, hence only test >
|
1061
|
+
*/
|
1062
|
+
if (end_offsetintable > dbg->de_debug_str_offsets.dss_size ) {
|
1063
|
+
_dwarf_error(dbg, error, DW_DLE_ATTR_FORM_SIZE_BAD);
|
1064
|
+
return (DW_DLV_ERROR);
|
1065
|
+
}
|
1066
|
+
|
1067
|
+
/* Now read the string offset from the offset table. */
|
1068
|
+
READ_UNALIGNED(dbg,offsettostr,Dwarf_Unsigned,
|
1069
|
+
dbg->de_debug_str_offsets.dss_data + offsetintable,
|
1070
|
+
cu_context->cc_length_size);
|
1071
|
+
*str_sect_offset_out = offsettostr;
|
1072
|
+
return DW_DLV_OK;
|
1073
|
+
}
|
1074
|
+
|
1075
|
+
|
1076
|
+
/* Contrary to pre-2005 documentation,
|
1077
|
+
The string pointer returned thru return_str must
|
1078
|
+
never have dwarf_dealloc() applied to it.
|
1079
|
+
Documentation fixed July 2005.
|
1080
|
+
*/
|
1081
|
+
int
|
1082
|
+
dwarf_formstring(Dwarf_Attribute attr,
|
1083
|
+
char **return_str, Dwarf_Error * error)
|
1084
|
+
{
|
1085
|
+
Dwarf_CU_Context cu_context = 0;
|
1086
|
+
Dwarf_Debug dbg = 0;
|
1087
|
+
Dwarf_Unsigned offset = 0;
|
1088
|
+
int res = DW_DLV_ERROR;
|
1089
|
+
Dwarf_Small *secdataptr = 0;
|
1090
|
+
Dwarf_Small *secend = 0;
|
1091
|
+
Dwarf_Unsigned secdatalen = 0;
|
1092
|
+
Dwarf_Small *infoptr = attr->ar_debug_ptr;
|
1093
|
+
res = get_attr_dbg(&dbg,&cu_context,attr,error);
|
1094
|
+
if (res != DW_DLV_OK) {
|
1095
|
+
return res;
|
1096
|
+
}
|
1097
|
+
if (cu_context->cc_is_info) {
|
1098
|
+
secdataptr = (Dwarf_Small *)dbg->de_debug_info.dss_data;
|
1099
|
+
secdatalen = dbg->de_debug_info.dss_size;
|
1100
|
+
} else {
|
1101
|
+
secdataptr = (Dwarf_Small *)dbg->de_debug_types.dss_data;
|
1102
|
+
secdatalen = dbg->de_debug_types.dss_size;
|
1103
|
+
}
|
1104
|
+
if (attr->ar_attribute_form == DW_FORM_string) {
|
1105
|
+
secend = secdataptr + secdatalen;
|
1106
|
+
Dwarf_Small *begin = attr->ar_debug_ptr;
|
1107
|
+
Dwarf_Small *contextend = secdataptr +
|
1108
|
+
cu_context->cc_debug_offset +
|
1109
|
+
cu_context->cc_length +
|
1110
|
+
cu_context->cc_length_size +
|
1111
|
+
cu_context->cc_extension_size;
|
1112
|
+
if (contextend < secend) {
|
1113
|
+
secend = contextend;
|
1114
|
+
}
|
1115
|
+
|
1116
|
+
res= _dwarf_check_string_valid(dbg,secdataptr,begin, secend,error);
|
1117
|
+
if (res != DW_DLV_OK) {
|
1118
|
+
return res;
|
1119
|
+
}
|
1120
|
+
*return_str = (char *) (begin);
|
1121
|
+
return DW_DLV_OK;
|
1122
|
+
}
|
1123
|
+
if (attr->ar_attribute_form == DW_FORM_GNU_strp_alt ||
|
1124
|
+
attr->ar_attribute_form == DW_FORM_strp_sup) {
|
1125
|
+
/* See dwarfstd.org issue 120604.1
|
1126
|
+
This is the offset in the .debug_str section
|
1127
|
+
of another object file.
|
1128
|
+
The 'tied' file notion should apply. */
|
1129
|
+
Dwarf_Off offset = 0;
|
1130
|
+
res = dwarf_global_formref(attr, &offset,error);
|
1131
|
+
if (res != DW_DLV_OK) {
|
1132
|
+
return res;
|
1133
|
+
}
|
1134
|
+
res = _dwarf_get_string_from_tied(dbg, offset,
|
1135
|
+
return_str, error);
|
1136
|
+
if (dwarf_errno(*error) == DW_DLE_NO_TIED_FILE_AVAILABLE) {
|
1137
|
+
dwarf_dealloc(dbg,*error,DW_DLA_ERROR);
|
1138
|
+
*return_str = (char *)"<DW_FORM_GNU_strp_alt-no-tied-file>";
|
1139
|
+
return DW_DLV_OK;
|
1140
|
+
}
|
1141
|
+
return res;
|
1142
|
+
}
|
1143
|
+
if (attr->ar_attribute_form == DW_FORM_GNU_str_index ||
|
1144
|
+
attr->ar_attribute_form == DW_FORM_strx) {
|
1145
|
+
Dwarf_Unsigned offsettostr= 0;
|
1146
|
+
res = _dwarf_extract_string_offset_via_str_offsets(dbg,
|
1147
|
+
infoptr,
|
1148
|
+
attr->ar_attribute,
|
1149
|
+
attr->ar_attribute_form,
|
1150
|
+
cu_context,
|
1151
|
+
&offsettostr,
|
1152
|
+
error);
|
1153
|
+
if (res != DW_DLV_OK) {
|
1154
|
+
return res;
|
1155
|
+
}
|
1156
|
+
offset = offsettostr;
|
1157
|
+
/* FALL THRU */
|
1158
|
+
} else {
|
1159
|
+
if (attr->ar_attribute_form == DW_FORM_strp) {
|
1160
|
+
READ_UNALIGNED(dbg, offset, Dwarf_Unsigned,
|
1161
|
+
infoptr,
|
1162
|
+
cu_context->cc_length_size);
|
1163
|
+
}
|
1164
|
+
}
|
1165
|
+
if (attr->ar_attribute_form == DW_FORM_strp ||
|
1166
|
+
attr->ar_attribute_form == DW_FORM_GNU_str_index ||
|
1167
|
+
attr->ar_attribute_form == DW_FORM_strx) {
|
1168
|
+
/* The 'offset' into .debug_str is set. */
|
1169
|
+
Dwarf_Small *secend = 0;
|
1170
|
+
Dwarf_Small *secbegin = 0;
|
1171
|
+
Dwarf_Small *strbegin = 0;
|
1172
|
+
res = _dwarf_load_section(dbg, &dbg->de_debug_str,error);
|
1173
|
+
if (res != DW_DLV_OK) {
|
1174
|
+
return res;
|
1175
|
+
}
|
1176
|
+
if (offset >= dbg->de_debug_str.dss_size) {
|
1177
|
+
/* Badly damaged DWARF here. */
|
1178
|
+
_dwarf_error(dbg, error, DW_DLE_STRP_OFFSET_BAD);
|
1179
|
+
return (DW_DLV_ERROR);
|
1180
|
+
}
|
1181
|
+
secbegin = dbg->de_debug_str.dss_data;
|
1182
|
+
strbegin= dbg->de_debug_str.dss_data + offset;
|
1183
|
+
secend = dbg->de_debug_str.dss_data + dbg->de_debug_str.dss_size;
|
1184
|
+
|
1185
|
+
/* Ensure the offset lies within the .debug_str */
|
1186
|
+
if (offset >= dbg->de_debug_str.dss_size) {
|
1187
|
+
_dwarf_error(dbg, error, DW_DLE_DEBUG_STR_OFFSET_BAD);
|
1188
|
+
return (DW_DLV_ERROR);
|
1189
|
+
}
|
1190
|
+
res= _dwarf_check_string_valid(dbg,secbegin,strbegin, secend,error);
|
1191
|
+
if (res != DW_DLV_OK) {
|
1192
|
+
return res;
|
1193
|
+
}
|
1194
|
+
|
1195
|
+
*return_str = (char *) (dbg->de_debug_str.dss_data + offset);
|
1196
|
+
return DW_DLV_OK;
|
1197
|
+
}
|
1198
|
+
|
1199
|
+
_dwarf_error(dbg, error, DW_DLE_ATTR_FORM_BAD);
|
1200
|
+
return (DW_DLV_ERROR);
|
1201
|
+
}
|
1202
|
+
|
1203
|
+
int
|
1204
|
+
_dwarf_get_string_from_tied(Dwarf_Debug dbg,
|
1205
|
+
Dwarf_Unsigned offset,
|
1206
|
+
char **return_str,
|
1207
|
+
Dwarf_Error*error)
|
1208
|
+
{
|
1209
|
+
Dwarf_Debug tieddbg = 0;
|
1210
|
+
Dwarf_Small *secend = 0;
|
1211
|
+
Dwarf_Small *secbegin = 0;
|
1212
|
+
Dwarf_Small *strbegin = 0;
|
1213
|
+
int res = DW_DLV_ERROR;
|
1214
|
+
Dwarf_Error localerror = 0;
|
1215
|
+
|
1216
|
+
/* Attach errors to dbg, not tieddbg. */
|
1217
|
+
tieddbg = dbg->de_tied_data.td_tied_object;
|
1218
|
+
if (!tieddbg) {
|
1219
|
+
_dwarf_error(dbg, error, DW_DLE_NO_TIED_FILE_AVAILABLE);
|
1220
|
+
return DW_DLV_ERROR;
|
1221
|
+
}
|
1222
|
+
/* The 'offset' into .debug_str is set. */
|
1223
|
+
res = _dwarf_load_section(tieddbg, &tieddbg->de_debug_str,&localerror);
|
1224
|
+
if (res == DW_DLV_ERROR) {
|
1225
|
+
Dwarf_Unsigned lerrno = dwarf_errno(localerror);
|
1226
|
+
dwarf_dealloc(tieddbg,localerror,DW_DLA_ERROR);
|
1227
|
+
_dwarf_error(dbg,error,lerrno);
|
1228
|
+
return res;
|
1229
|
+
} else if (res == DW_DLV_NO_ENTRY) {
|
1230
|
+
return res;
|
1231
|
+
}
|
1232
|
+
if (offset >= tieddbg->de_debug_str.dss_size) {
|
1233
|
+
/* Badly damaged DWARF here. */
|
1234
|
+
_dwarf_error(dbg, error, DW_DLE_NO_TIED_STRING_AVAILABLE);
|
1235
|
+
return (DW_DLV_ERROR);
|
1236
|
+
}
|
1237
|
+
secbegin = tieddbg->de_debug_str.dss_data;
|
1238
|
+
strbegin= tieddbg->de_debug_str.dss_data + offset;
|
1239
|
+
secend = tieddbg->de_debug_str.dss_data +
|
1240
|
+
tieddbg->de_debug_str.dss_size;
|
1241
|
+
|
1242
|
+
/* Ensure the offset lies within the .debug_str */
|
1243
|
+
if (offset >= tieddbg->de_debug_str.dss_size) {
|
1244
|
+
_dwarf_error(dbg, error, DW_DLE_NO_TIED_STRING_AVAILABLE);
|
1245
|
+
return (DW_DLV_ERROR);
|
1246
|
+
}
|
1247
|
+
res= _dwarf_check_string_valid(tieddbg,secbegin,strbegin, secend,
|
1248
|
+
&localerror);
|
1249
|
+
if (res == DW_DLV_ERROR) {
|
1250
|
+
Dwarf_Unsigned lerrno = dwarf_errno(localerror);
|
1251
|
+
dwarf_dealloc(tieddbg,localerror,DW_DLA_ERROR);
|
1252
|
+
_dwarf_error(dbg,error,lerrno);
|
1253
|
+
return res;
|
1254
|
+
} else if (res == DW_DLV_NO_ENTRY) {
|
1255
|
+
return res;
|
1256
|
+
}
|
1257
|
+
*return_str = (char *) (tieddbg->de_debug_str.dss_data + offset);
|
1258
|
+
return DW_DLV_OK;
|
1259
|
+
}
|
1260
|
+
|
1261
|
+
|
1262
|
+
|
1263
|
+
|
1264
|
+
int
|
1265
|
+
dwarf_formexprloc(Dwarf_Attribute attr,
|
1266
|
+
Dwarf_Unsigned * return_exprlen,
|
1267
|
+
Dwarf_Ptr * block_ptr,
|
1268
|
+
Dwarf_Error * error)
|
1269
|
+
{
|
1270
|
+
Dwarf_Debug dbg = 0;
|
1271
|
+
Dwarf_CU_Context cu_context = 0;
|
1272
|
+
|
1273
|
+
int res = get_attr_dbg(&dbg,&cu_context,attr,error);
|
1274
|
+
if (res != DW_DLV_OK) {
|
1275
|
+
return res;
|
1276
|
+
}
|
1277
|
+
if (dbg == NULL) {
|
1278
|
+
_dwarf_error(NULL, error, DW_DLE_ATTR_DBG_NULL);
|
1279
|
+
return (DW_DLV_ERROR);
|
1280
|
+
}
|
1281
|
+
if (attr->ar_attribute_form == DW_FORM_exprloc ) {
|
1282
|
+
Dwarf_Die die = 0;
|
1283
|
+
Dwarf_Word leb_len = 0;
|
1284
|
+
Dwarf_Unsigned exprlen =
|
1285
|
+
(_dwarf_decode_u_leb128(attr->ar_debug_ptr, &leb_len));
|
1286
|
+
Dwarf_Small * addr = attr->ar_debug_ptr;
|
1287
|
+
/* Is the block entirely in the section, or is
|
1288
|
+
there bug somewhere? */
|
1289
|
+
die = attr->ar_die;
|
1290
|
+
if (_dwarf_reference_outside_section(die,
|
1291
|
+
(Dwarf_Small *)addr, ((Dwarf_Small *)addr)+exprlen +leb_len)) {
|
1292
|
+
_dwarf_error(dbg, error,DW_DLE_ATTR_OUTSIDE_SECTION);
|
1293
|
+
return DW_DLV_ERROR;
|
1294
|
+
}
|
1295
|
+
*return_exprlen = exprlen;
|
1296
|
+
*block_ptr = addr + leb_len;
|
1297
|
+
return DW_DLV_OK;
|
1298
|
+
|
1299
|
+
}
|
1300
|
+
_dwarf_error(dbg, error, DW_DLE_ATTR_EXPRLOC_FORM_BAD);
|
1301
|
+
return (DW_DLV_ERROR);
|
1302
|
+
}
|